cmFileLockResult.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 "cmStandardIncludes.h"
  13. #if defined(_WIN32)
  14. # include <windows.h> // DWORD
  15. #endif
  16. /**
  17. * @brief Result of the locking/unlocking file.
  18. * @note See @c cmFileLock
  19. */
  20. class cmFileLockResult
  21. {
  22. public:
  23. #if defined(_WIN32)
  24. typedef DWORD Error;
  25. #else
  26. typedef int Error;
  27. #endif
  28. /**
  29. * @brief Successful lock/unlock.
  30. */
  31. static cmFileLockResult MakeOk();
  32. /**
  33. * @brief Lock/Unlock failed. Read error/GetLastError.
  34. */
  35. static cmFileLockResult MakeSystem();
  36. /**
  37. * @brief Lock/Unlock failed. Timeout reached.
  38. */
  39. static cmFileLockResult MakeTimeout();
  40. /**
  41. * @brief File already locked.
  42. */
  43. static cmFileLockResult MakeAlreadyLocked();
  44. /**
  45. * @brief Internal error.
  46. */
  47. static cmFileLockResult MakeInternal();
  48. /**
  49. * @brief Try to lock with function guard outside of the function
  50. */
  51. static cmFileLockResult MakeNoFunction();
  52. bool IsOk() const;
  53. std::string GetOutputMessage() const;
  54. private:
  55. enum ErrorType
  56. {
  57. OK,
  58. SYSTEM,
  59. TIMEOUT,
  60. ALREADY_LOCKED,
  61. INTERNAL,
  62. NO_FUNCTION
  63. };
  64. cmFileLockResult(ErrorType type, Error errorValue);
  65. ErrorType Type;
  66. Error ErrorValue;
  67. };
  68. #endif // cmFileLockResult_h