interprocess_sync_file.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright (C) 2012 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __INTERPROCESS_SYNC_FILE_H__
  15. #define __INTERPROCESS_SYNC_FILE_H__
  16. #include "util/interprocess_sync.h"
  17. #include "exceptions/exceptions.h"
  18. namespace isc {
  19. namespace util {
  20. ///
  21. /// \brief Exception that is thrown if it's not possible to open the
  22. /// lock file.
  23. ///
  24. class InterprocessSyncFileError : public Exception {
  25. public:
  26. InterprocessSyncFileError(const char* file, size_t line,
  27. const char* what) :
  28. isc::Exception(file, line, what) {}
  29. };
  30. class InterprocessSyncFile : public InterprocessSync {
  31. public:
  32. /// \brief Constructor
  33. InterprocessSyncFile(const std::string& component_name) :
  34. InterprocessSync(component_name), fd_(-1)
  35. {}
  36. /// \brief Destructor
  37. virtual ~InterprocessSyncFile();
  38. protected:
  39. bool lock();
  40. bool tryLock();
  41. bool unlock();
  42. private:
  43. bool do_lock(int cmd, short l_type);
  44. int fd_;
  45. };
  46. } // namespace util
  47. } // namespace isc
  48. #endif // __INTERPROCESS_SYNC_FILE_H__