My Project
FileSystemWatcher.h
1 #pragma once
2 
3 #if !defined(PARAENGINE_MOBILE)
4 
5 #include "dir_monitor/basic_dir_monitor.hpp"
6 #include <boost/thread.hpp>
7 #include <queue>
8 
9 namespace ParaEngine
10 {
11 
18  {
19  public:
22  typedef boost::signals2::signal<void(const DirMonitorEvent&)> FileSystemEvent_t;
23  typedef boost::signals2::connection FileSystemEvent_Connection_t;
24 
25  CFileSystemWatcher(const std::string& filename);
28 
29  public:
33  void Destroy();
34 
36  bool add_directory(const std::string &dirname);
37 
39  bool remove_directory(const std::string &dirname);
40 
45  int DispatchEvents();
46 
48  void SetDispatchInMainThread(bool bMainThread);
49 
52 
54  FileSystemEvent_Connection_t AddEventCallback(FileSystemEvent_t::slot_type callback);
55 
56  const std::string& GetName() const;
57  void SetName(const std::string& val);
58  private:
59  void FileHandler(const boost::system::error_code &ec, const boost::asio::dir_monitor_event &ev);
60 
62  std::queue < DirMonitorEvent > m_msg_queue;
63 
64  void* m_monitor_imp;
65 
67  ParaEngine::mutex m_mutex;
68 
70  FileSystemEvent_t m_file_event;
71 
73  std::string m_name;
74 
76  bool m_bDispatchInMainThread;
77  };
79 
82  {
83  public:
84  typedef std::map<std::string, CFileSystemWatcherPtr > file_watcher_map_t;
85 
87  virtual ~CFileSystemWatcherService();
88 
89  static CFileSystemWatcherService* GetInstance();
90 
92  void Clear();
93 
97  CFileSystemWatcherPtr GetDirWatcher(const std::string& name);
98 
102  void DeleteDirWatcher(const std::string& name);
103 
109  int DispatchEvents();
110 
112  boost::asio::io_service& GetIOService() {return *(m_io_service.get());}
113 
115  bool IsStarted() {return m_bIsStarted;}
116 
118  bool Start();
119  protected:
120  int fileWatcherThreadMain();
121  private:
122  file_watcher_map_t m_file_watchers;
123 
125  boost::scoped_ptr<boost::asio::io_service::work> m_io_service_work;
127  bool m_bIsStarted;
128  };
129 
130 }
131 #else
132 namespace ParaEngine
133 {
134  // empty implementation
135  class CFileSystemWatcher
136  {
137  public:
138  };
139 }
140 #endif
Definition: basic_dir_monitor.hpp:16
bool remove_directory(const std::string &dirname)
remove a directory to monitor.
Definition: FileSystemWatcher.cpp:258
different physics engine has different winding order.
Definition: EventBinding.h:32
bool IsStarted()
whether it is started.
Definition: FileSystemWatcher.h:115
int DispatchEvents()
this allows us to process queued messages in main thread&#39;s frame move.
Definition: FileSystemWatcher.cpp:214
Definition: class.hpp:124
event_type
Definition: basic_dir_monitor.hpp:18
Definition: PERef.h:11
boost::asio::io_service & GetIOService()
get io service object.
Definition: FileSystemWatcher.h:112
monitoring file changes.
Definition: FileSystemWatcher.h:17
bool IsDispatchInMainThread()
if true(default), we will dispatch all callback event in the main thread.
Definition: FileSystemWatcher.cpp:209
FileSystemEvent_Connection_t AddEventCallback(FileSystemEvent_t::slot_type callback)
add an event call back, please note that the event callback may be called from the main thread or the...
Definition: FileSystemWatcher.cpp:237
void Destroy()
must be called before you wait for worker thread to exit.
Definition: FileSystemWatcher.cpp:284
file system watcher service.
Definition: FileSystemWatcher.h:81
void SetDispatchInMainThread(bool bMainThread)
if true(default), we will dispatch all callback event in the main thread.
Definition: FileSystemWatcher.cpp:204
cross platform mutex
Definition: mutex.h:95
bool add_directory(const std::string &dirname)
add a directory to monitor.
Definition: FileSystemWatcher.cpp:242