Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cFileChangeWatch.h
Go to the documentation of this file.
1 //
4 //
5 
6 #ifndef _INC_cFileChangeWatch_H
7 #define _INC_cFileChangeWatch_H
8 #ifndef NO_PRAGMA_ONCE
9 #pragma once
10 #endif
11 
12 #include "../GrayLibBase.h"
17 
18 namespace GrayLib
19 {
21  {
25 #ifdef _WIN32
26  FILE_CHANGE_SUBANON,
27 #endif
28  // FILE_CHANGE_SUBMANUAL, //!< list any/all changed sub directories under this. 2 handles. Assume changes are manually listed in '.changes' folder.
30  };
31 
33  {
36  friend class cFileChangeWatch;
37  private:
38  cStringF m_sDir;
39  FILE_CHANGE_TYPE m_eType;
40 #ifdef _WIN32
41  cOSHandle m_hWatch;
42 #elif defined(__linux__)
43  int m_hWatch;
44 #else
45 #error NOOS
46 #endif
47  protected:
48  cFileChangeElem(cStringF sDir, FILE_CHANGE_TYPE eType, HANDLE hWatch)
49  : m_sDir(sDir)
50  , m_eType(eType)
51  , m_hWatch(hWatch)
52  {
53  }
54  public:
55  cStringF get_Name() const // sort by name.
56  {
57  return m_sDir;
58  }
59  HASHCODE_t get_HashCode() const noexcept // override
60  {
61  return (INT_PTR)(HANDLE)m_hWatch;
62  }
63  };
64 
66  {
72 
73  private:
74 #ifdef __linux__
76  cOSHandle m_hINotify;
77 #endif
78  protected:
80 
81  private:
82  HRESULT addSubDirs(const FILECHAR_t* pszDir);
83  HRESULT removeSubDirs(cFileChangeElem* pElemParent);
84 
85  void removeAllFileChangeWatches0();
86  HRESULT removeFileChangeWatch0(cFileChangeElem* pElem);
87  HRESULT removeFileChangeWatch(cFileChangeElem* pElem);
88 
89  protected:
90  virtual cRefPtr<cFileChangeElem> createFileChangeWatch(cStringF sDir, FILE_CHANGE_TYPE eType, HANDLE hFileChange);
91 
92  public:
94  virtual ~cFileChangeWatch();
95 
96  bool isValidFileChangeWatch() const noexcept
97  {
99  return !m_aWatches.IsEmpty(); // FindFirstChangeNotification. can use WaitForMultipleObjects() etc on this.
100  }
101 
102  void removeAllFileChangeWatches();
103  bool hasFileChangeWatch(const FILECHAR_t* pszDir) const;
104  HRESULT addFileChangeWatch(const FILECHAR_t* pszDir, FILE_CHANGE_TYPE eType);
105  HRESULT removeFileChangeWatch(const FILECHAR_t* pszDir);
106 
107  HRESULT waitForFileChanges(TIMESYSD_t nWaitDelay = 0, OUT cArraySortString<FILECHAR_t>* pChangeList = nullptr);
108 
110  };
111 }
112 #endif // _INC_cFileChangeWatch_H
#define GRAYLIB_LINK
Definition: GrayLibBase.h:35
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
Definition: cFileChangeWatch.h:33
cFileChangeElem(cStringF sDir, FILE_CHANGE_TYPE eType, HANDLE hWatch)
Definition: cFileChangeWatch.h:48
cStringF get_Name() const
Definition: cFileChangeWatch.h:55
HASHCODE_t get_HashCode() const noexcept
Definition: cFileChangeWatch.h:59
Definition: cFileChangeWatch.h:66
bool isValidFileChangeWatch() const noexcept
Definition: cFileChangeWatch.h:96
UNITTEST_FRIEND(cFileChangeWatch)
cArraySortName< cFileChangeElem > m_aWatches
FindFirstChangeNotification. can use WaitForMultipleObjects() etc on this.
Definition: cFileChangeWatch.h:79
bool IsEmpty() const noexcept
Definition: cArray.h:145
Definition: cArraySortRef.h:60
Definition: cArraySortRef.h:199
Definition: cOSHandle.h:59
Definition: cRefPtr.h:22
Definition: cRefPtr.h:225
Definition: cMesh.h:22
FILE_CHANGE_TYPE
Definition: cFileChangeWatch.h:21
@ FILE_CHANGE_1
check just this file or directory for changes, 1 handle. any subdirectories with changes are ignored.
Definition: cFileChangeWatch.h:24
@ FILE_CHANGE_RECURSIVE
list any/all changed sub directories under this. recursive handles.
Definition: cFileChangeWatch.h:29
INT32 TIMESYSD_t
Time delta. signed milli-Seconds Span. cTimeSys::k_DMAX, cTimeSys::k_INF = MAILSLOT_WAIT_FOREVER.
Definition: cTimeSys.h:28
char FILECHAR_t
a UTF8 char in a file name. like TCHAR
Definition: FileName.h:22
UINT_PTR HASHCODE_t
could hold a pointer converted to a number? maybe 64 or 32 bit ? same as size_t.
Definition: GrayCore.h:116