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

Classes

class  UpdateListener
 Processes a file action. More...
 

Functions

void sigend (int signal)
 
efsw::WatchID handleWatchID (efsw::WatchID watchid)
 
int main (int argc, char **argv)
 

Variables

bool STOP = false
 

Function Documentation

efsw::WatchID handleWatchID ( efsw::WatchID  watchid)
40 {
41  switch ( watchid )
42  {
43  case efsw::Errors::FileNotFound:
44  case efsw::Errors::FileRepeated:
45  case efsw::Errors::FileOutOfScope:
46  case efsw::Errors::FileRemote:
47  case efsw::Errors::Unspecified:
48  {
49  std::cout << efsw::Errors::Log::getLastErrorLog().c_str() << std::endl;
50  break;
51  }
52  default:
53  {
54  std::cout << "Added WatchID: " << watchid << std::endl;
55  }
56  }
57 
58  return watchid;
59 }

+ Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

create the file watcher object

add a watch to the system

starts watching

adds another watch after started watching...

delete the watch

62 {
63  signal( SIGABRT , sigend );
64  signal( SIGINT , sigend );
65  signal( SIGTERM , sigend );
66 
67  std::cout << "Press ^C to exit demo" << std::endl;
68 
69  bool commonTest = true;
70  bool useGeneric = false;
71  std::string path;
72 
73  if ( argc >= 2 )
74  {
75  path = std::string( argv[1] );
76 
77  if ( efsw::FileSystem::isDirectory( path ) )
78  {
79  commonTest = false;
80  }
81 
82  if ( argc >= 3 )
83  {
84  if ( std::string( argv[2] ) == "true" )
85  {
86  useGeneric = true;
87  }
88  }
89  }
90 
91  UpdateListener * ul = new UpdateListener();
92 
94  efsw::FileWatcher fileWatcher( useGeneric );
95 
96  fileWatcher.followSymlinks( false );
97  fileWatcher.allowOutOfScopeLinks( false );
98 
99  if ( commonTest )
100  {
101  std::string CurPath( efsw::System::getProcessPath() );
102 
103  std::cout << "CurPath: " << CurPath.c_str() << std::endl;
104 
106  handleWatchID( fileWatcher.addWatch( CurPath + "test", ul, true ) );
107 
109  fileWatcher.watch();
110 
112  efsw::System::sleep( 100 );
113 
114  efsw::WatchID watchID = handleWatchID( fileWatcher.addWatch( CurPath + "test2", ul, true ) );
115 
117  if ( watchID > 0 )
118  {
119  efsw::System::sleep( 1000 );
120  fileWatcher.removeWatch( watchID );
121  }
122  }
123  else
124  {
125  efsw::WatchID err;
126 
127  if ( ( err = fileWatcher.addWatch( path, ul, true ) ) > 0 )
128  {
129  fileWatcher.watch();
130 
131  std::cout << "Watching directory: " << path.c_str() << std::endl;
132 
133  if ( useGeneric )
134  {
135  std::cout << "Using generic backend watcher" << std::endl;
136  }
137  }
138  else
139  {
140  std::cout << "Error trying to watch directory: " << path.c_str() << std::endl;
141  std::cout << efsw::Errors::Log::getLastErrorLog().c_str() << std::endl;
142  }
143  }
144 
145  while( !STOP )
146  {
147  efsw::System::sleep( 100 );
148  }
149 
150  return 0;
151 }
efsw::WatchID handleWatchID(efsw::WatchID watchid)
Definition: efsw-test.cpp:39
Processes a file action.
Definition: efsw-test.cpp:16
bool isDirectory(const std::string &filename)
Definition: fileutils.cpp:914
void sigend(int signal)
Definition: efsw-test.cpp:9
bool STOP
Definition: efsw-test.cpp:7

+ Here is the call graph for this function:

void sigend ( int  signal)
10 {
11  std::cout << std::endl << "Bye bye" << std::endl;
12  STOP = true;
13 }
bool STOP
Definition: efsw-test.cpp:7

+ Here is the caller graph for this function:

Variable Documentation

bool STOP = false