INotify.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Util/String.h>
  7. namespace anki {
  8. /// @addtogroup util_file
  9. /// @{
  10. /// A wrapper on top of inotify. Check for filesystem updates.
  11. class INotify
  12. {
  13. public:
  14. INotify() = default;
  15. // Non-copyable
  16. INotify(const INotify&) = delete;
  17. ~INotify()
  18. {
  19. destroyInternal();
  20. m_path.destroy(m_alloc);
  21. }
  22. // Non-copyable
  23. INotify& operator=(const INotify&) = delete;
  24. /// @param path Path to file or directory.
  25. ANKI_USE_RESULT Error init(GenericMemoryPoolAllocator<U8> alloc, CString path)
  26. {
  27. m_alloc = alloc;
  28. m_path.create(alloc, path);
  29. return initInternal();
  30. }
  31. /// Check if the file was modified in any way.
  32. ANKI_USE_RESULT Error pollEvents(Bool& modified);
  33. private:
  34. GenericMemoryPoolAllocator<U8> m_alloc;
  35. String m_path;
  36. #if ANKI_POSIX
  37. int m_fd = -1;
  38. int m_watch = -1;
  39. #endif
  40. void destroyInternal();
  41. ANKI_USE_RESULT Error initInternal();
  42. };
  43. /// @}
  44. } // end namespace anki