TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
efsw Namespace Reference

Namespaces

 Errors
 
 Platform
 

Functions

int getOSXReleaseNumber ()
 
bool operator== (const String &left, const String &right)
 
bool operator!= (const String &left, const String &right)
 
bool operator< (const String &left, const String &right)
 
bool operator> (const String &left, const String &right)
 
bool operator<= (const String &left, const String &right)
 
bool operator>= (const String &left, const String &right)
 
String operator+ (const String &left, const String &right)
 
int comparator (const void *ke1, const void *ke2)
 
void CALLBACK WatchCallback (DWORD dwErrorCode, DWORD dwNumberOfBytesTransfered, LPOVERLAPPED lpOverlapped)
 Unpacks events and passes them to a user defined callback. More...
 
bool RefreshWatch (WatcherStructWin32 *pWatch)
 Refreshes the directory monitoring. More...
 
void DestroyWatch (WatcherStructWin32 *pWatch)
 Stops monitoring a directory. More...
 
WatcherStructWin32 * CreateWatch (LPCWSTR szDirectory, bool recursive, DWORD NotifyFilter)
 Starts monitoring a directory. More...
 

Function Documentation

int efsw::comparator ( const void *  ke1,
const void *  ke2 
)
29 {
30  const KEvent * kev1 = reinterpret_cast<const KEvent*>( ke1 );
31  const KEvent * kev2 = reinterpret_cast<const KEvent*>( ke2 );
32 
33  if ( NULL != kev2->udata )
34  {
35  FileInfo * fi1 = reinterpret_cast<FileInfo*>( kev1->udata );
36  FileInfo * fi2 = reinterpret_cast<FileInfo*>( kev2->udata );
37 
38  return strcmp( fi1->Filepath.c_str(), fi2->Filepath.c_str() );
39  }
40 
41  return 1;
42 }
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

WatcherStructWin32* efsw::CreateWatch ( LPCWSTR  szDirectory,
bool  recursive,
DWORD  NotifyFilter 
)

Starts monitoring a directory.

109 {
110  WatcherStructWin32 * tWatch;
111  size_t ptrsize = sizeof(*tWatch);
112  tWatch = static_cast<WatcherStructWin32*>(HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptrsize));
113 
114  WatcherWin32 * pWatch = new WatcherWin32();
115  tWatch->Watch = pWatch;
116 
117  pWatch->DirHandle = CreateFileW(
118  szDirectory,
119  GENERIC_READ,
120  FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
121  NULL,
122  OPEN_EXISTING,
123  FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
124  NULL
125  );
126 
127  if (pWatch->DirHandle != INVALID_HANDLE_VALUE)
128  {
129  tWatch->Overlapped.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
130  pWatch->NotifyFilter = NotifyFilter;
131  pWatch->Recursive = recursive;
132 
133  if (RefreshWatch(tWatch))
134  {
135  return tWatch;
136  }
137  else
138  {
139  CloseHandle(tWatch->Overlapped.hEvent);
140  CloseHandle(pWatch->DirHandle);
141  }
142  }
143 
144  HeapFree(GetProcessHeap(), 0, tWatch);
145  return NULL;
146 }
arena_t NULL
Definition: jemalloc_internal.h:624
#define INVALID_HANDLE_VALUE
Definition: CascPort.h:169
bool RefreshWatch(WatcherStructWin32 *pWatch)
Refreshes the directory monitoring.
Definition: WatcherWin32.cpp:67

+ Here is the call graph for this function:

void efsw::DestroyWatch ( WatcherStructWin32 *  pWatch)

Stops monitoring a directory.

83 {
84  if (pWatch)
85  {
86  WatcherWin32 * tWatch = pWatch->Watch;
87 
88  tWatch->StopNow = true;
89 
90  CancelIo(tWatch->DirHandle);
91 
92  RefreshWatch(pWatch);
93 
94  if (!HasOverlappedIoCompleted(&pWatch->Overlapped))
95  {
96  SleepEx(5, TRUE);
97  }
98 
99  CloseHandle(pWatch->Overlapped.hEvent);
100  CloseHandle(pWatch->Watch->DirHandle);
101  efSAFE_DELETE_ARRAY( pWatch->Watch->DirName );
102  efSAFE_DELETE( pWatch->Watch );
103  HeapFree(GetProcessHeap(), 0, pWatch);
104  }
105 }
bool RefreshWatch(WatcherStructWin32 *pWatch)
Refreshes the directory monitoring.
Definition: WatcherWin32.cpp:67

+ Here is the call graph for this function:

int efsw::getOSXReleaseNumber ( )
15 {
16  static int osxR = -1;
17 
18  if ( -1 == osxR )
19  {
20  struct utsname os;
21 
22  if ( -1 != uname( &os ) ) {
23  std::string release( os.release );
24 
25  size_t pos = release.find_first_of( '.' );
26 
27  if ( pos != std::string::npos )
28  {
29  release = release.substr( 0, pos );
30  }
31 
32  int rel = 0;
33 
34  if ( String::fromString<int>( rel, release ) )
35  {
36  osxR = rel;
37  }
38  }
39  }
40 
41  return osxR;
42 }
bool efsw::operator!= ( const String &  left,
const String &  right 
)
781 {
782  return !(left == right);
783 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
String efsw::operator+ ( const String &  left,
const String &  right 
)
806 {
807  String string = left;
808  string += right;
809 
810  return string;
811 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487

+ Here is the call graph for this function:

bool efsw::operator< ( const String &  left,
const String &  right 
)
786 {
787  return left.mString < right.mString;
788 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
bool efsw::operator<= ( const String &  left,
const String &  right 
)
796 {
797  return !(right < left);
798 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487

+ Here is the call graph for this function:

bool efsw::operator== ( const String &  left,
const String &  right 
)
776 {
777  return left.mString == right.mString;
778 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
bool efsw::operator> ( const String &  left,
const String &  right 
)
791 {
792  return right < left;
793 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487

+ Here is the call graph for this function:

bool efsw::operator>= ( const String &  left,
const String &  right 
)
801 {
802  return !(left < right);
803 }
bool left(const int *a, const int *b, const int *c)
Definition: RecastContour.cpp:487
bool efsw::RefreshWatch ( WatcherStructWin32 *  pWatch)

Refreshes the directory monitoring.

68 {
69  return ReadDirectoryChangesW(
70  pWatch->Watch->DirHandle,
71  pWatch->Watch->mBuffer,
72  sizeof(pWatch->Watch->mBuffer),
73  pWatch->Watch->Recursive,
74  pWatch->Watch->NotifyFilter,
75  NULL,
76  &pWatch->Overlapped,
77  NULL
78  ) != 0;
79 }
arena_t NULL
Definition: jemalloc_internal.h:624

+ Here is the caller graph for this function:

void CALLBACK efsw::WatchCallback ( DWORD  dwErrorCode,
DWORD  dwNumberOfBytesTransfered,
LPOVERLAPPED  lpOverlapped 
)

Unpacks events and passes them to a user defined callback.

11 {
12  char szFile[MAX_PATH];
13  PFILE_NOTIFY_INFORMATION pNotify;
14  WatcherStructWin32 * tWatch = (WatcherStructWin32*) lpOverlapped;
15  WatcherWin32 * pWatch = tWatch->Watch;
16  size_t offset = 0;
17 
18  if (dwNumberOfBytesTransfered == 0)
19  {
20  RefreshWatch(tWatch); // If dwNumberOfBytesTransfered == 0, it means the buffer overflowed (too many changes between GetOverlappedResults calls). Those events are lost, but at least we can refresh so subsequent changes are seen again.
21  return;
22  }
23 
24  if (dwErrorCode == ERROR_SUCCESS)
25  {
26  do
27  {
28  bool skip = false;
29 
30  pNotify = (PFILE_NOTIFY_INFORMATION) &pWatch->mBuffer[offset];
31  offset += pNotify->NextEntryOffset;
32 
33  int count = WideCharToMultiByte(CP_UTF8, 0, pNotify->FileName,
34  pNotify->FileNameLength / sizeof(WCHAR),
35  szFile, MAX_PATH - 1, NULL, NULL);
36  szFile[count] = TEXT('\0');
37 
38  std::string nfile( szFile );
39 
40  if ( FILE_ACTION_MODIFIED == pNotify->Action )
41  {
42  FileInfo fifile( std::string( pWatch->DirName ) + nfile );
43 
44  if ( pWatch->LastModifiedEvent.file.ModificationTime == fifile.ModificationTime && pWatch->LastModifiedEvent.file.Size == fifile.Size && pWatch->LastModifiedEvent.fileName == nfile )
45  {
46  skip = true;
47  }
48 
49  pWatch->LastModifiedEvent.fileName = nfile;
50  pWatch->LastModifiedEvent.file = fifile;
51  }
52 
53  if ( !skip )
54  {
55  pWatch->Watch->handleAction(pWatch, nfile, pNotify->Action);
56  }
57  } while (pNotify->NextEntryOffset != 0);
58  }
59 
60  if (!pWatch->StopNow)
61  {
62  RefreshWatch(tWatch);
63  }
64 }
#define MAX_PATH
Definition: CascPort.h:160
arena_t NULL
Definition: jemalloc_internal.h:624
#define ERROR_SUCCESS
Definition: CascPort.h:204
bool RefreshWatch(WatcherStructWin32 *pWatch)
Refreshes the directory monitoring.
Definition: WatcherWin32.cpp:67

+ Here is the call graph for this function: