TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
FileWatcherCWrapper.cpp File Reference
#include <efsw/efsw.h>
#include <efsw/efsw.hpp>
#include <vector>
+ Include dependency graph for FileWatcherCWrapper.cpp:

Classes

class  Watcher_CAPI
 

Macros

#define TOBOOL(i)   ((i) == 0 ? false : true)
 

Functions

Watcher_CAPIfind_callback (efsw_watcher watcher, efsw_pfn_fileaction_callback fn)
 
Watcher_CAPIremove_callback (efsw_watcher watcher)
 
efsw_watcher efsw_create (int generic_mode)
 
void efsw_release (efsw_watcher watcher)
 Release the file-watcher and unwatch any directories. More...
 
const char * efsw_getlasterror ()
 Retreive last error occured by file-watcher. More...
 
efsw_watchid efsw_addwatch (efsw_watcher watcher, const char *directory, efsw_pfn_fileaction_callback callback_fn, int recursive, void *param)
 
void efsw_removewatch (efsw_watcher watcher, const char *directory)
 Remove a directory watch. This is a brute force search O(nlogn). More...
 
void efsw_removewatch_byid (efsw_watcher watcher, efsw_watchid watchid)
 Remove a directory watch. This is a map lookup O(logn). More...
 
void efsw_watch (efsw_watcher watcher)
 Starts watching ( in other thread ) More...
 
void efsw_follow_symlinks (efsw_watcher watcher, int enable)
 
int efsw_follow_symlinks_isenabled (efsw_watcher watcher)
 
void efsw_allow_outofscopelinks (efsw_watcher watcher, int allow)
 
int efsw_outofscopelinks_isallowed (efsw_watcher watcher)
 

Variables

static std::vector
< Watcher_CAPI * > 
g_callbacks
 

Macro Definition Documentation

#define TOBOOL (   i)    ((i) == 0 ? false : true)

Function Documentation

efsw_watchid efsw_addwatch ( efsw_watcher  watcher,
const char *  directory,
efsw_pfn_fileaction_callback  callback_fn,
int  recursive,
void *  param 
)

Add a directory watch. Same as the other addWatch, but doesn't have recursive option. For backwards compatibility. On error returns WatchID with Error type.

86 {
87  Watcher_CAPI* callback = find_callback(watcher, callback_fn);
88 
89  if (callback == NULL) {
90  callback = new Watcher_CAPI(watcher, callback_fn, param);
91  g_callbacks.push_back(callback);
92  }
93 
94  return ((efsw::FileWatcher*)watcher)->addWatch(std::string(directory), callback,
95  TOBOOL(recursive));
96 }
static std::vector< Watcher_CAPI * > g_callbacks
Definition: FileWatcherCWrapper.cpp:33
Definition: FileWatcherCWrapper.cpp:8
#define TOBOOL(i)
Definition: FileWatcherCWrapper.cpp:5
arena_t NULL
Definition: jemalloc_internal.h:624
Watcher_CAPI * find_callback(efsw_watcher watcher, efsw_pfn_fileaction_callback fn)
Definition: FileWatcherCWrapper.cpp:35

+ Here is the call graph for this function:

void efsw_allow_outofscopelinks ( efsw_watcher  watcher,
int  allow 
)

When enable this it will allow symlinks to watch recursively out of the pointed directory. follorSymlinks must be enabled to this work. For example, added symlink to /home/folder, and the symlink points to /, this by default is not allowed, it's only allowed to symlink anything from /home/ and deeper. This is to avoid great levels of recursion. Enabling this could lead in infinite recursion, and crash the watcher ( it will try not to avoid this ). Buy enabling out of scope links, it will allow this behavior. allowOutOfScopeLinks are disabled by default.

124 {
125  ((efsw::FileWatcher*)watcher)->allowOutOfScopeLinks(TOBOOL(allow));
126 }
#define TOBOOL(i)
Definition: FileWatcherCWrapper.cpp:5
efsw_watcher efsw_create ( int  generic_mode)

Creates a new file-watcher

Parameters
generic_modeForce the use of the Generic file watcher
67 {
68  return (efsw_watcher)new efsw::FileWatcher(TOBOOL(generic_mode));
69 }
#define TOBOOL(i)
Definition: FileWatcherCWrapper.cpp:5
void * efsw_watcher
Type for watcher.
Definition: efsw.h:66
void efsw_follow_symlinks ( efsw_watcher  watcher,
int  enable 
)

Allow recursive watchers to follow symbolic links to other directories followSymlinks is disabled by default

114 {
115  ((efsw::FileWatcher*)watcher)->followSymlinks(TOBOOL(enable));
116 }
#define TOBOOL(i)
Definition: FileWatcherCWrapper.cpp:5
int efsw_follow_symlinks_isenabled ( efsw_watcher  watcher)
Returns
If can follow symbolic links to directorioes
119 {
120  return (int)((efsw::FileWatcher*)watcher)->followSymlinks();
121 }
const char* efsw_getlasterror ( )

Retreive last error occured by file-watcher.

78 {
79  static std::string log_str;
80  log_str = efsw::Errors::Log::getLastErrorLog();
81  return log_str.c_str();
82 }
int efsw_outofscopelinks_isallowed ( efsw_watcher  watcher)
Returns
Returns if out of scope links are allowed
129 {
130  return (int)((efsw::FileWatcher*)watcher)->allowOutOfScopeLinks();
131 }
void efsw_release ( efsw_watcher  watcher)

Release the file-watcher and unwatch any directories.

72 {
73  remove_callback(watcher);
74  delete (efsw::FileWatcher*)watcher;
75 }
Watcher_CAPI * remove_callback(efsw_watcher watcher)
Definition: FileWatcherCWrapper.cpp:48

+ Here is the call graph for this function:

void efsw_removewatch ( efsw_watcher  watcher,
const char *  directory 
)

Remove a directory watch. This is a brute force search O(nlogn).

99 {
100  ((efsw::FileWatcher*)watcher)->removeWatch(std::string(directory));
101 }
void efsw_removewatch_byid ( efsw_watcher  watcher,
efsw_watchid  watchid 
)

Remove a directory watch. This is a map lookup O(logn).

104 {
105  ((efsw::FileWatcher*)watcher)->removeWatch(watchid);
106 }
void efsw_watch ( efsw_watcher  watcher)

Starts watching ( in other thread )

109 {
110  ((efsw::FileWatcher*)watcher)->watch();
111 }
Watcher_CAPI* find_callback ( efsw_watcher  watcher,
efsw_pfn_fileaction_callback  fn 
)
36 {
37  for (std::vector<Watcher_CAPI*>::iterator i = g_callbacks.begin(); i != g_callbacks.end(); i++ )
38  {
39  Watcher_CAPI* callback = *i;
40 
41  if (callback->mFn == fn && callback->mWatcher == watcher)
42  return *i;
43  }
44 
45  return NULL;
46 }
efsw_pfn_fileaction_callback mFn
Definition: FileWatcherCWrapper.cpp:12
static std::vector< Watcher_CAPI * > g_callbacks
Definition: FileWatcherCWrapper.cpp:33
Definition: FileWatcherCWrapper.cpp:8
arena_t NULL
Definition: jemalloc_internal.h:624
efsw_watcher mWatcher
Definition: FileWatcherCWrapper.cpp:11

+ Here is the caller graph for this function:

Watcher_CAPI* remove_callback ( efsw_watcher  watcher)
49 {
50  std::vector<Watcher_CAPI*>::iterator i = g_callbacks.begin();
51 
52  while (i != g_callbacks.end()) {
53  Watcher_CAPI* callback = *i;
54 
55  if (callback->mWatcher == watcher)
56  i = g_callbacks.erase(i);
57  else
58  i++;
59  }
60 
61  return NULL;
62 }
static std::vector< Watcher_CAPI * > g_callbacks
Definition: FileWatcherCWrapper.cpp:33
Definition: FileWatcherCWrapper.cpp:8
arena_t NULL
Definition: jemalloc_internal.h:624
efsw_watcher mWatcher
Definition: FileWatcherCWrapper.cpp:11

+ Here is the caller graph for this function:

Variable Documentation

std::vector<Watcher_CAPI*> g_callbacks
static