cmFileLockResult.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 Ruslan Baratov
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmFileLockResult_h
  11. #define cmFileLockResult_h
  12. #include <cmConfigure.h> // IWYU pragma: keep
  13. #include <string>
  14. #if defined(_WIN32)
  15. #include <windows.h> // DWORD
  16. #endif
  17. /**
  18. * @brief Result of the locking/unlocking file.
  19. * @note See @c cmFileLock
  20. */
  21. class cmFileLockResult
  22. {
  23. public:
  24. #if defined(_WIN32)
  25. typedef DWORD Error;
  26. #else
  27. typedef int Error;
  28. #endif
  29. /**
  30. * @brief Successful lock/unlock.
  31. */
  32. static cmFileLockResult MakeOk();
  33. /**
  34. * @brief Lock/Unlock failed. Read error/GetLastError.
  35. */
  36. static cmFileLockResult MakeSystem();
  37. /**
  38. * @brief Lock/Unlock failed. Timeout reached.
  39. */
  40. static cmFileLockResult MakeTimeout();
  41. /**
  42. * @brief File already locked.
  43. */
  44. static cmFileLockResult MakeAlreadyLocked();
  45. /**
  46. * @brief Internal error.
  47. */
  48. static cmFileLockResult MakeInternal();
  49. /**
  50. * @brief Try to lock with function guard outside of the function
  51. */
  52. static cmFileLockResult MakeNoFunction();
  53. bool IsOk() const;
  54. std::string GetOutputMessage() const;
  55. private:
  56. enum ErrorType
  57. {
  58. OK,
  59. SYSTEM,
  60. TIMEOUT,
  61. ALREADY_LOCKED,
  62. INTERNAL,
  63. NO_FUNCTION
  64. };
  65. cmFileLockResult(ErrorType type, Error errorValue);
  66. ErrorType Type;
  67. Error ErrorValue;
  68. };
  69. #endif // cmFileLockResult_h