Qore FilePoller Module Reference 1.0
Loading...
Searching...
No Matches
FilePoller.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
2
3/* FilePoller.qm Copyright (C) 2014 - 2023 Qore Technologies s.r.o.
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
29
65namespace FilePoller {
66
68const EVENT_FILE = "file-event";
69
71public hashdecl FilePollerFileEventInfo {
73 int dev;
74
76 int inode;
77
79
81 int mode;
82
84 int nlink;
85
87 int uid;
88
90 int gid;
91
93 int rdev;
94
96 int size;
97
99 date atime;
100
102 date mtime;
103
105 date ctime;
106
108
111
113
116
118
129 string type;
130
132 string perm;
133
135 string name;
136
138 string filepath;
139
141 *string link;
142};
143
146
147public:
149 const OrderAsc = 0;
151 const OrderDesc = 1;
152
154 const SortNone = 0;
156 const SortName = 1;
158 const SortDate = 2;
159
161 const Options = ...;
162
163
165 const RequiredKeys = ...;
166
167
168protected:
170 string path;
171
173 string mask;
174
176 int poll_interval = 10;
177
179 bool runflag = False;
180
182 bool fatal = False;
183
185 int pollcnt = 0;
186
188 int sort_type = SortName;
189
191 int sort_order = OrderAsc;
192
195
197 int tid;
198
201
203 int reopt;
204
206 *softint minage;
207
209 *code log_info;
210
213
216
219
221 *code sleep;
222
223public:
224
226
258 constructor(string n_path, string n_mask, *hash<auto> n_opts);
259
260
263
264
266
271 list<hash<FilePollerFileEventInfo>> getFiles(int sort = FilePoller::SortNone, int order = FilePoller::OrderAsc);
272
273
275
278 int start();
279
280
282
292
293
295
300
301
303
313
314
316
320
321
323 bool runOnce();
324
325
327protected:
328 fileSleep(softint secs);
329public:
330
331
333protected:
335public:
336
337
339
341 fileEvent(list<hash<FilePollerFileEventInfo>> files);
342
343
345
368 abstract singleFileEvent(hash<FilePollerFileEventInfo> event);
369
371
375 static checkPath(string path, string type, bool write = False);
376
379
380
382protected:
383 logInfo(string fmt);
384public:
385
386
388protected:
389 logDetail(string fmt);
390public:
391
392
394protected:
395 logDebug(string fmt);
396public:
397
398};
399
401
406
407public:
410 "path": <DataProviderOptionInfo>{
411 "type": AbstractDataProviderType::get(StringType),
412 "desc": "A path giving the location of the directory to poll",
413 "required": True,
414 },
415
416 "mask": <DataProviderOptionInfo>{
417 "type": AbstractDataProviderType::get(StringType),
418 "desc": "The glob mask to use; will be treated as a regex if `regex` is `true`",
419 "default_value": "*",
420 },
421
422 "poll_interval": <DataProviderOptionInfo>{
423 "type": AbstractDataProviderType::get(IntType),
424 "desc": "The interval in seconds between polling for files",
425 "default_value": 10,
426 },
427
428 "regex": <DataProviderOptionInfo>{
429 "type": AbstractDataProviderType::get(BoolType),
430 "desc": "If `true` then `mask` is treated as a regular expression instead of a glob pattern",
431 },
432
433 "reopt": <DataProviderOptionInfo>{
434 "type": AbstractDataProviderType::get(IntType),
435 "desc": "A bitfield of regular expression options (`1` = ignore case, `2` = treat EOL as a regular "
436 "character); ignored if `regex` is not `true`",
437 },
438
439 "minage": <DataProviderOptionInfo>{
440 "type": AbstractDataProviderType::get(IntType),
441 "desc": "An integer giving the minimum file age in seconds before the file will be polled; this is "
442 "meant to work around non-atomic file transfer operations",
443 },
444
445 "sort_desc": <DataProviderOptionInfo>{
446 "type": AbstractDataProviderType::get(BoolType),
447 "desc": "Sort descending; if not given then an ascending sort is assumed if a `sort_type` is given",
448 },
449
450 "sort_type": <DataProviderOptionInfo>{
451 "type": AbstractDataProviderType::get(StringType),
452 "desc": "Either `name` or `date` for the data to use for sorting",
453 },
454 };
455
456protected:
458 EmbeddedFilePoller poller;
459
460public:
461
463 constructor(*hash<auto> options);
464
465
466 destructor();
467
468
469 string getName();
470
471
473 *string getDesc();
474
475
477
481protected:
482 hash<string, hash<DataProviderMessageInfo>> getEventTypesImpl();
483public:
484
485};
486
488
495
496public:
498 const ProviderInfo = <DataProviderInfo>{
499 "type": "FilePollerDataProvider",
500 "supports_observable": True,
501 "constructor_options": ConstructorOptions,
502 };
503
505 constructor(*hash<auto> options) ;
506
507
508protected:
509 hash<DataProviderInfo> getStaticInfoImpl();
510public:
511
512};
513
515
522
523public:
525 const ProviderInfo = <DataProviderInfo>{
526 "type": "FileDelayedPollerDataProvider",
527 "supports_observable": True,
528 "constructor_options": ConstructorOptions,
529 };
530
532 constructor(*hash<auto> options) ;
533
534
536
539
540
541protected:
542 hash<DataProviderInfo> getStaticInfoImpl();
543public:
544
545};
546
548class FilePollerFileEventInfoDataType : public HashDataType {
549
550public:
553 "dev": "The device inode number the file is on",
554 "inode": "The inode of the file",
555 "mode": "The file protection mode; a bitfield of file permissions",
556 "nlink": "The number of hard links to this file",
557 "uid": "The UID of the owner of the file",
558 "gid": "The GID of the owner of the file",
559 "rdev": "The device type number",
560 "size": "the size of the file in bytes",
561 "atime": "the last accessed date/time of the file",
562 "mtime": "the last modified date/time of the file",
563 "ctime": "the created date/time of the file",
564 "blksize": "Block size; is zero if the file is zero length or if the platform's internal `stat()` (2) "
565 "function does not provide this info",
566 "blocks": "Blocks allocated for the file; is zero if the file is zero length or if the platform's "
567 "internal `stat()` (2) function does not provide this info",
568 "type": "the type of file; one of:\n- `REGULAR`\n- `DIRECTORY`\n- `SYMBOLIC-LINK`\n"
569 "- `BLOCK-DEVICE`\n- `CHARACTER-DEVICE`\n- `FIFO`\n- `SYMBOLIC-LINK`\n- `SOCKET`\n"
570 "- `UNKNOWN`",
571 "perm": "a string giving UNIX-style permissions for the file (ex: `-rwxr-xr-x`)",
572 "name": "the name of the file, link, or directory",
573 "filepath": "the remote filepath relative to SFILE root directory",
574 "link": "symbolic link target (if present)",
575 };
576
579
580};
581
583class FilePollerDataProviderFactory : public AbstractDataProviderFactory {
584
585public:
586protected:
588 static Class cls = new Class("FilePollerDataProvider");
589
591 const FactoryInfo = <DataProviderFactoryInfo>{
592 "name": "filepoller",
593 "desc": "File poller data provider factory",
594 "children_can_support_observers": True,
595 };
596
597public:
598
600
602protected:
603 hash<DataProviderFactoryInfo> getInfoImpl();
604public:
605
606
608
610protected:
611 hash<DataProviderInfo> getProviderInfoImpl();
612public:
613
614
616protected:
618public:
619
620};
621};
622
623// private namespace; not exported
624namespace Priv {
625class EmbeddedFilePoller : public FilePoller {
626
627public:
628protected:
630 Observable observable;
631
632public:
633
634 constructor(FilePollerDataProviderBase provider, string path, string mask, *hash<auto> options)
635 ;
636
637
638 singleFileEvent(hash<auto> event);
639
640};
641}
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:521
constructor(*hash< auto > options)
Creates the object from constructor options.
observersReady()
Called when all observers have been added to the object.
const ProviderInfo
Provider info.
Definition: FilePoller.qm.dox.h:525
Event-based data provider for file events.
Definition: FilePoller.qm.dox.h:405
*string getDesc()
Returns the data provider description.
EmbeddedFilePoller poller
The file poller itself.
Definition: FilePoller.qm.dox.h:458
hash< string, hash< DataProviderMessageInfo > > getEventTypesImpl()
Returns a hash of all supported event types.
constructor(*hash< auto > options)
Creates the object from constructor options.
const ConstructorOptions
Constructor options.
Definition: FilePoller.qm.dox.h:409
The file poller data provider factory.
Definition: FilePoller.qm.dox.h:583
const FactoryInfo
Factory info.
Definition: FilePoller.qm.dox.h:591
hash< DataProviderFactoryInfo > getInfoImpl()
Returns static factory information without provider_info.
Class getClassImpl()
Returns the class for the data provider object.
static Class cls
Data provider type info.
Definition: FilePoller.qm.dox.h:588
hash< DataProviderInfo > getProviderInfoImpl()
Returns static provider information.
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:494
constructor(*hash< auto > options)
Creates the object from constructor options.
const ProviderInfo
Provider info.
Definition: FilePoller.qm.dox.h:498
File poller event data description.
Definition: FilePoller.qm.dox.h:548
const FieldDescriptions
Markdown descriptions for hashdecl members.
Definition: FilePoller.qm.dox.h:552
*softint minage
minimum file age in seconds before the file will be included in the list returned
Definition: FilePoller.qm.dox.h:206
*code log_info
optional info log closure
Definition: FilePoller.qm.dox.h:209
int reopt
regex options
Definition: FilePoller.qm.dox.h:203
int start()
starts polling in the background; returns the thread ID of the polling thread
const SortNone
no sorting
Definition: FilePoller.qm.dox.h:154
string path
path to monitor
Definition: FilePoller.qm.dox.h:170
constructor(string n_path, string n_mask, *hash< auto > n_opts)
creates the object
*code log_debug
optional debug log closure
Definition: FilePoller.qm.dox.h:215
int tid
polling tid
Definition: FilePoller.qm.dox.h:197
destructor()
stops the polling operation if in progress and destroys the object
*code log_detail
optional detail log closure
Definition: FilePoller.qm.dox.h:212
list< hash< FilePollerFileEventInfo > > 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
const OrderAsc
ascending sort order
Definition: FilePoller.qm.dox.h:149
int getPollCount()
returns the current poll count
waitStop()
Waits indefinitely for the polling operation to stop.
logDetail(string fmt)
calls "log_detail" with detail information; if set
abstract singleFileEvent(hash< FilePollerFileEventInfo > event)
called for each matching file individually when matching files are polled
logDebug(string fmt)
calls "log_debug" with verbose debugging information; if set
Qore::Thread::Counter sc()
stop counter
string mask
file name mask
Definition: FilePoller.qm.dox.h:173
run()
starts the polling operation
startInline()
starts the polling operation inline (not in a background thread)
stop()
stops the polling operation, returns when the polling operation has been stopped
bool runOnce()
runs a single poll (useful for checking for errors inline before starting a background thread)
*code sleep
optional sleep closure
Definition: FilePoller.qm.dox.h:221
logInfo(string fmt)
calls "log_info" with important information, if set
stopNoWait()
stops the polling operation, returns immediately
Qore::Thread::Mutex m()
start mutex
static checkPath(string path, string type, bool write=False)
checks a path on the local file system
*code start_thread
optional start thread closure
Definition: FilePoller.qm.dox.h:218
fileEvent(list< hash< FilePollerFileEventInfo > > files)
Called for each poll event with a list of all files matched.
fileSleep(softint secs)
sleeps for the specificed number of seconds
Main module namespace.
Definition: FilePoller.qm.dox.h:65
const EVENT_FILE
File event constant.
Definition: FilePoller.qm.dox.h:68
FilePoller file event hash.
Definition: FilePoller.qm.dox.h:71
date ctime
The created date/time of the file.
Definition: FilePoller.qm.dox.h:105
int nlink
The number of hard links to this file.
Definition: FilePoller.qm.dox.h:84
int mode
The file protection mode.
Definition: FilePoller.qm.dox.h:81
int inode
The inode of the file.
Definition: FilePoller.qm.dox.h:76
string type
the type of file
Definition: FilePoller.qm.dox.h:129
string name
The name of the file, link, or directory.
Definition: FilePoller.qm.dox.h:135
int dev
The device inode number the file is on.
Definition: FilePoller.qm.dox.h:73
int blocks
Blocks allocated for the file.
Definition: FilePoller.qm.dox.h:115
int uid
The UID of the owner of the file.
Definition: FilePoller.qm.dox.h:87
int blksize
Block size.
Definition: FilePoller.qm.dox.h:110
date atime
The last accessed date/time of the file.
Definition: FilePoller.qm.dox.h:99
int rdev
The device type number.
Definition: FilePoller.qm.dox.h:93
string perm
a string giving UNIX-style permissions for the file (ex: "-rwxr-xr-x")
Definition: FilePoller.qm.dox.h:132
int gid
The GID of the owner of the file.
Definition: FilePoller.qm.dox.h:90
int size
The size of the file in bytes.
Definition: FilePoller.qm.dox.h:96
*string link
symbolic link target (if present)
Definition: FilePoller.qm.dox.h:141
string filepath
The entire path of the file.
Definition: FilePoller.qm.dox.h:138
date mtime
The last modified date/time of the file.
Definition: FilePoller.qm.dox.h:102