Qore FilePoller Module Reference 1.0.1
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
69namespace FilePoller {
70
72const EVENT_FILE = "file-event";
73
75public hashdecl FilePollerFileEventInfo {
77 int dev;
78
80 int inode;
81
83
85 int mode;
86
88 int nlink;
89
91 int uid;
92
94 int gid;
95
97 int rdev;
98
100 int size;
101
103 date atime;
104
106 date mtime;
107
109 date ctime;
110
112
115
117
120
122
133 string type;
134
136 string perm;
137
139 string name;
140
142 string filepath;
143
145 *string link;
146};
147
150
151public:
153 const OrderAsc = 0;
155 const OrderDesc = 1;
156
158 const SortNone = 0;
160 const SortName = 1;
162 const SortDate = 2;
163
165 const Options = ...;
166
167
169 const RequiredKeys = ...;
170
171
172protected:
174 string path;
175
177 string mask;
178
180 int poll_interval = 10;
181
183 bool runflag = False;
184
186 bool fatal = False;
187
189 int pollcnt = 0;
190
192 int sort_type = SortName;
193
195 int sort_order = OrderAsc;
196
199
201 int tid;
202
205
207 int reopt;
208
210 *softint minage;
211
213 *code log_info;
214
217
220
223
225 *code sleep;
226
227public:
228
230
262 constructor(string n_path, string n_mask, *hash<auto> n_opts);
263
264
267
268
270
275 list<hash<FilePollerFileEventInfo>> getFiles(int sort = FilePoller::SortNone, int order = FilePoller::OrderAsc);
276
277
279
282 int start();
283
284
286
296
297
299
304
305
307
317
318
320
324
325
327 bool runOnce();
328
329
331protected:
332 fileSleep(softint secs);
333public:
334
335
337protected:
339public:
340
341
343
345 fileEvent(list<hash<FilePollerFileEventInfo>> files);
346
347
349
372 abstract singleFileEvent(hash<FilePollerFileEventInfo> event);
373
375
379 static checkPath(string path, string type, bool write = False);
380
383
384
386protected:
387 logInfo(string fmt);
388public:
389
390
392protected:
393 logDetail(string fmt);
394public:
395
396
398protected:
399 logDebug(string fmt);
400public:
401
402};
403
405
410
411public:
414 "path": <DataProviderOptionInfo>{
415 "type": AbstractDataProviderType::get(StringType),
416 "desc": "A path giving the location of the directory to poll",
417 "required": True,
418 },
419
420 "mask": <DataProviderOptionInfo>{
421 "type": AbstractDataProviderType::get(StringType),
422 "desc": "The glob mask to use; will be treated as a regex if `regex` is `true`",
423 "default_value": "*",
424 },
425
426 "poll_interval": <DataProviderOptionInfo>{
427 "type": AbstractDataProviderType::get(IntType),
428 "desc": "The interval in seconds between polling for files",
429 "default_value": 10,
430 },
431
432 "regex": <DataProviderOptionInfo>{
433 "type": AbstractDataProviderType::get(BoolType),
434 "desc": "If `true` then `mask` is treated as a regular expression instead of a glob pattern",
435 },
436
437 "reopt": <DataProviderOptionInfo>{
438 "type": AbstractDataProviderType::get(IntType),
439 "desc": "A bitfield of regular expression options (`1` = ignore case, `2` = treat EOL as a regular "
440 "character); ignored if `regex` is not `true`",
441 },
442
443 "minage": <DataProviderOptionInfo>{
444 "type": AbstractDataProviderType::get(IntType),
445 "desc": "An integer giving the minimum file age in seconds before the file will be polled; this is "
446 "meant to work around non-atomic file transfer operations",
447 },
448
449 "sort_desc": <DataProviderOptionInfo>{
450 "type": AbstractDataProviderType::get(BoolType),
451 "desc": "Sort descending; if not given then an ascending sort is assumed if a `sort_type` is given",
452 },
453
454 "sort_type": <DataProviderOptionInfo>{
455 "type": AbstractDataProviderType::get(StringType),
456 "desc": "Either `name` or `date` for the data to use for sorting",
457 },
458 };
459
460protected:
462 EmbeddedFilePoller poller;
463
464public:
465
467 constructor(*hash<auto> options);
468
469
470 destructor();
471
472
473 string getName();
474
475
477 *string getDesc();
478
479
481
485protected:
486 hash<string, hash<DataProviderMessageInfo>> getEventTypesImpl();
487public:
488
489};
490
492
499
500public:
502 const ProviderInfo = <DataProviderInfo>{
503 "type": "FilePollerDataProvider",
504 "supports_observable": True,
505 "constructor_options": ConstructorOptions,
506 };
507
509 constructor(*hash<auto> options) ;
510
511
512protected:
513 hash<DataProviderInfo> getStaticInfoImpl();
514public:
515
516};
517
519
526
527public:
529 const ProviderInfo = <DataProviderInfo>{
530 "type": "FileDelayedPollerDataProvider",
531 "supports_observable": True,
532 "constructor_options": ConstructorOptions,
533 };
534
536 constructor(*hash<auto> options) ;
537
538
540
543
544
545protected:
546 hash<DataProviderInfo> getStaticInfoImpl();
547public:
548
549};
550
552class FilePollerFileEventInfoDataType : public HashDataType {
553
554public:
557 "dev": "The device inode number the file is on",
558 "inode": "The inode of the file",
559 "mode": "The file protection mode; a bitfield of file permissions",
560 "nlink": "The number of hard links to this file",
561 "uid": "The UID of the owner of the file",
562 "gid": "The GID of the owner of the file",
563 "rdev": "The device type number",
564 "size": "the size of the file in bytes",
565 "atime": "the last accessed date/time of the file",
566 "mtime": "the last modified date/time of the file",
567 "ctime": "the created date/time of the file",
568 "blksize": "Block size; is zero if the file is zero length or if the platform's internal `stat()` (2) "
569 "function does not provide this info",
570 "blocks": "Blocks allocated for the file; is zero if the file is zero length or if the platform's "
571 "internal `stat()` (2) function does not provide this info",
572 "type": "the type of file; one of:\n- `REGULAR`\n- `DIRECTORY`\n- `SYMBOLIC-LINK`\n"
573 "- `BLOCK-DEVICE`\n- `CHARACTER-DEVICE`\n- `FIFO`\n- `SYMBOLIC-LINK`\n- `SOCKET`\n"
574 "- `UNKNOWN`",
575 "perm": "a string giving UNIX-style permissions for the file (ex: `-rwxr-xr-x`)",
576 "name": "the name of the file, link, or directory",
577 "filepath": "the remote filepath relative to SFILE root directory",
578 "link": "symbolic link target (if present)",
579 };
580
583
584};
585
587class FilePollerDataProviderFactory : public AbstractDataProviderFactory {
588
589public:
590protected:
592 static Class cls = new Class("FileDelayedPollerDataProvider");
593
595 const FactoryInfo = <DataProviderFactoryInfo>{
596 "name": "filepoller",
597 "desc": "File poller data provider factory",
598 "children_can_support_observers": True,
599 };
600
601public:
602
604
606protected:
607 hash<DataProviderFactoryInfo> getInfoImpl();
608public:
609
610
612
614protected:
615 hash<DataProviderInfo> getProviderInfoImpl();
616public:
617
618
620protected:
622public:
623
624};
625};
626
627// private namespace; not exported
628namespace Priv {
629class EmbeddedFilePoller : public FilePoller {
630
631public:
632protected:
634 Observable observable;
635
636public:
637
638 constructor(FilePollerDataProviderBase provider, string path, string mask, *hash<auto> options)
639 ;
640
641
642 singleFileEvent(hash<auto> event);
643
644};
645}
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:525
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:529
Event-based data provider for file events.
Definition: FilePoller.qm.dox.h:409
*string getDesc()
Returns the data provider description.
EmbeddedFilePoller poller
The file poller itself.
Definition: FilePoller.qm.dox.h:462
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:413
The file poller data provider factory.
Definition: FilePoller.qm.dox.h:587
const FactoryInfo
Factory info.
Definition: FilePoller.qm.dox.h:595
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:592
hash< DataProviderInfo > getProviderInfoImpl()
Returns static provider information.
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:498
constructor(*hash< auto > options)
Creates the object from constructor options.
const ProviderInfo
Provider info.
Definition: FilePoller.qm.dox.h:502
File poller event data description.
Definition: FilePoller.qm.dox.h:552
const FieldDescriptions
Markdown descriptions for hashdecl members.
Definition: FilePoller.qm.dox.h:556
*softint minage
minimum file age in seconds before the file will be included in the list returned
Definition: FilePoller.qm.dox.h:210
*code log_info
optional info log closure
Definition: FilePoller.qm.dox.h:213
int reopt
regex options
Definition: FilePoller.qm.dox.h:207
int start()
starts polling in the background; returns the thread ID of the polling thread
const SortNone
no sorting
Definition: FilePoller.qm.dox.h:158
string path
path to monitor
Definition: FilePoller.qm.dox.h:174
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:219
int tid
polling tid
Definition: FilePoller.qm.dox.h:201
destructor()
stops the polling operation if in progress and destroys the object
*code log_detail
optional detail log closure
Definition: FilePoller.qm.dox.h:216
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:153
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:177
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:225
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:222
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:69
const EVENT_FILE
File event constant.
Definition: FilePoller.qm.dox.h:72
FilePoller file event hash.
Definition: FilePoller.qm.dox.h:75
date ctime
The created date/time of the file.
Definition: FilePoller.qm.dox.h:109
int nlink
The number of hard links to this file.
Definition: FilePoller.qm.dox.h:88
int mode
The file protection mode.
Definition: FilePoller.qm.dox.h:85
int inode
The inode of the file.
Definition: FilePoller.qm.dox.h:80
string type
the type of file
Definition: FilePoller.qm.dox.h:133
string name
The name of the file, link, or directory.
Definition: FilePoller.qm.dox.h:139
int dev
The device inode number the file is on.
Definition: FilePoller.qm.dox.h:77
int blocks
Blocks allocated for the file.
Definition: FilePoller.qm.dox.h:119
int uid
The UID of the owner of the file.
Definition: FilePoller.qm.dox.h:91
int blksize
Block size.
Definition: FilePoller.qm.dox.h:114
date atime
The last accessed date/time of the file.
Definition: FilePoller.qm.dox.h:103
int rdev
The device type number.
Definition: FilePoller.qm.dox.h:97
string perm
a string giving UNIX-style permissions for the file (ex: "-rwxr-xr-x")
Definition: FilePoller.qm.dox.h:136
int gid
The GID of the owner of the file.
Definition: FilePoller.qm.dox.h:94
int size
The size of the file in bytes.
Definition: FilePoller.qm.dox.h:100
*string link
symbolic link target (if present)
Definition: FilePoller.qm.dox.h:145
string filepath
The entire path of the file.
Definition: FilePoller.qm.dox.h:142
date mtime
The last modified date/time of the file.
Definition: FilePoller.qm.dox.h:106