Qore FilePoller Module Reference  0.1.0
 All Classes Namespaces Functions Variables Groups Pages
FilePoller.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 /* FilePoller.qm Copyright (C) 2014 - 2016 Qore Technologies sro.
4 
5  Permission is hereby granted, free of charge, to any person obtaining a
6  copy of this software and associated documentation files (the "Software"),
7  to deal in the Software without restriction, including without limitation
8  the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  and/or sell copies of the Software, and to permit persons to whom the
10  Software is furnished to do so, subject to the following conditions:
11 
12  The above copyright notice and this permission notice shall be included in
13  all copies or substantial portions of the Software.
14 
15  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21  DEALINGS IN THE SOFTWARE.
22 */
23 
24 // make sure we have the required qore version
25 
26 
27 
28 
52 namespace FilePoller {
55  class FilePoller {
56 
57 public:
58  public :
59  const OrderAsc = 0;
60  const OrderDesc = 1;
61 
62  const SortNone = 0;
63  const SortName = 1;
64  const SortDate = 2;
65 
67  const Options = (
68  "log_info",
69  "log_detail",
70  "log_debug",
71  "poll_interval",
72  "reopt",
73  "sleep",
74  "sort_order",
75  "sort_type",
76  "start_thread",
77  );
78 
80  const RequiredKeys = (
81  "sleep",
82  "start_thread",
83  );
84 
85 public:
86 
87  private :
89  string path;
90 
92  string mask;
93 
95  int poll_interval = 10;
96 
98  bool runflag = False;
99 
101  bool fatal = False;
102 
104  int pollcnt = 0;
105 
107  int sort_type = SortName;
108 
110  int sort_order = OrderAsc;
111 
113  Mutex m();
114 
116  int tid;
117 
119  Counter sc();
120 
122  int reopt;
123 
125  *softint minage;
126 
128  *code log_info;
129 
131  *code log_detail;
132 
134  *code log_debug;
135 
138 
140  *code sleep;
141 
142 public:
143 
145 
166  constructor(string n_path, string n_mask, *hash n_opts);
167 
168 
170  destructor();
171 
172 
174 
189  list getFiles(int sort = FilePoller::SortNone, int order = FilePoller::OrderAsc);
190 
191 
193 
196  int start();
197 
198 
200 
208  stop();
209 
210 
212 
216  stopNoWait();
217 
218 
220 
227  waitStop();
228 
229 
231 
234  startInline();
235 
236 
238  bool runOnce();
239 
240 
242  private fileSleep(softint secs);
243 
244 
246  private run();
247 
248 
250  fileEvent(list files);
251 
252 
254 
266  abstract singleFileEvent(hash fih);
267 
269 
272  static checkPath(string path, string type, bool write = False);
273 
275  int getPollCount();
276 
277 
279  private logInfo(string fmt);
280 
281 
283  private logDetail(string fmt);
284 
285 
287  private logDebug(string fmt);
288 
289  };
290 };
291 // END
private logDebug(string fmt)
calls the "log_debug" closure or call reference with verbose debugging information ...
private run()
starts the polling operation
const Options
known constructor() options
Definition: FilePoller.qm.dox.h:67
const RequiredKeys
minimum required keys for all constructors
Definition: FilePoller.qm.dox.h:80
int poll_interval
poll interval in seconds
Definition: FilePoller.qm.dox.h:95
fileEvent(list files)
called for each poll event with a list of all files matched; calls singleFileEvent() on each file has...
destructor()
stops the polling operation if in progress and destroys the object
*code sleep
optional sleep closure
Definition: FilePoller.qm.dox.h:140
stop()
stops the polling operation, returns when the polling operation has been stopped
bool fatal
internal fatal error flag
Definition: FilePoller.qm.dox.h:101
string mask
file name mask
Definition: FilePoller.qm.dox.h:92
*code log_info
optional info log closure
Definition: FilePoller.qm.dox.h:128
private logDetail(string fmt)
calls the "log_detail" closure or call reference with detail information
list getFiles(int sort=FilePoller::SortNone, int order=FilePoller::OrderAsc)
returns a list of regular file hashes matching any file name mask set for the object ...
startInline()
starts the polling operation inline (not in a background thread)
any sort(any arg)
const False
int pollcnt
internal poll counter
Definition: FilePoller.qm.dox.h:104
list list(...)
Mutex m()
start mutex
private fileSleep(softint secs)
sleeps for the specificed number of seconds
int sort_type
file sort type
Definition: FilePoller.qm.dox.h:107
stopNoWait()
stops the polling operation, returns immediately
int getPollCount()
returns the current poll count
int sort_order
file sort order
Definition: FilePoller.qm.dox.h:110
abstract singleFileEvent(hash fih)
called for each matching file individually whenever matching files are polled with the list of matchi...
private logInfo(string fmt)
calls the "log_info" closure or call reference with important information
waitStop()
waits indefinitely for the polling operation to stop; if polling was not in progress then this method...
int tid
polling tid
Definition: FilePoller.qm.dox.h:116
string type(any arg)
file polling class
Definition: FilePoller.qm.dox.h:55
bool runflag
run flag
Definition: FilePoller.qm.dox.h:98
int start()
starts polling in the background; returns the thread ID of the polling thread
Counter sc()
stop counter
*softint minage
minimum file age in seconds before the file will be included in the list returned ...
Definition: FilePoller.qm.dox.h:125
static checkPath(string path, string type, bool write=False)
checks a path on the local file system
*code log_detail
optional detail log closure
Definition: FilePoller.qm.dox.h:131
*code log_debug
optional debug log closure
Definition: FilePoller.qm.dox.h:134
constructor(string n_path, string n_mask, *hash n_opts)
creates the object
hash hash(object obj)
*code start_thread
optional start thread closure
Definition: FilePoller.qm.dox.h:137
string path
path to monitor
Definition: FilePoller.qm.dox.h:89
int reopt
regex options
Definition: FilePoller.qm.dox.h:122
bool runOnce()
runs a single poll (useful for checking for errors inline before starting a background thread) ...