INotify.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. {
  9. /// @addtogroup util_file
  10. /// @{
  11. /// A wrapper on top of inotify. Check for filesystem updates.
  12. class INotify
  13. {
  14. public:
  15. INotify() = default;
  16. // Non-copyable
  17. INotify(const INotify&) = delete;
  18. ~INotify()
  19. {
  20. destroyInternal();
  21. m_path.destroy(m_alloc);
  22. }
  23. // Non-copyable
  24. INotify& operator=(const INotify&) = delete;
  25. /// @param path Path to file or directory.
  26. ANKI_USE_RESULT Error init(GenericMemoryPoolAllocator<U8> alloc, CString path)
  27. {
  28. m_alloc = alloc;
  29. m_path.create(alloc, path);
  30. return initInternal();
  31. }
  32. /// Check if the file was modified in any way.
  33. ANKI_USE_RESULT Error pollEvents(Bool& modified);
  34. private:
  35. GenericMemoryPoolAllocator<U8> m_alloc;
  36. String m_path;
  37. #if ANKI_POSIX
  38. int m_fd = -1;
  39. int m_watch = -1;
  40. #endif
  41. void destroyInternal();
  42. ANKI_USE_RESULT Error initInternal();
  43. };
  44. /// @}
  45. } // end namespace anki