cmFileLockResult.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmFileLockResult_h
  4. #define cmFileLockResult_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #if defined(_WIN32)
  8. #include <windows.h> // DWORD
  9. #endif
  10. /**
  11. * @brief Result of the locking/unlocking file.
  12. * @note See @c cmFileLock
  13. */
  14. class cmFileLockResult
  15. {
  16. public:
  17. #if defined(_WIN32)
  18. typedef DWORD Error;
  19. #else
  20. typedef int Error;
  21. #endif
  22. /**
  23. * @brief Successful lock/unlock.
  24. */
  25. static cmFileLockResult MakeOk();
  26. /**
  27. * @brief Lock/Unlock failed. Read error/GetLastError.
  28. */
  29. static cmFileLockResult MakeSystem();
  30. /**
  31. * @brief Lock/Unlock failed. Timeout reached.
  32. */
  33. static cmFileLockResult MakeTimeout();
  34. /**
  35. * @brief File already locked.
  36. */
  37. static cmFileLockResult MakeAlreadyLocked();
  38. /**
  39. * @brief Internal error.
  40. */
  41. static cmFileLockResult MakeInternal();
  42. /**
  43. * @brief Try to lock with function guard outside of the function
  44. */
  45. static cmFileLockResult MakeNoFunction();
  46. bool IsOk() const;
  47. std::string GetOutputMessage() const;
  48. private:
  49. enum ErrorType
  50. {
  51. OK,
  52. SYSTEM,
  53. TIMEOUT,
  54. ALREADY_LOCKED,
  55. INTERNAL,
  56. NO_FUNCTION
  57. };
  58. cmFileLockResult(ErrorType type, Error errorValue);
  59. ErrorType Type;
  60. Error ErrorValue;
  61. };
  62. #endif // cmFileLockResult_h