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
68namespace FilePoller {
69
71const EVENT_FILE = "file-event";
72
74public hashdecl FilePollerFileEventInfo {
76 int dev;
77
79 int inode;
80
82
84 int mode;
85
87 int nlink;
88
90 int uid;
91
93 int gid;
94
96 int rdev;
97
99 int size;
100
102 date atime;
103
105 date mtime;
106
108 date ctime;
109
111
114
116
119
121
132 string type;
133
135 string perm;
136
138 string name;
139
141 string filepath;
142
144 *string link;
145};
146
149
150public:
152 const OrderAsc = 0;
154 const OrderDesc = 1;
155
157 const SortNone = 0;
159 const SortName = 1;
161 const SortDate = 2;
162
164 const Options = ...;
165
166
168 const RequiredKeys = ...;
169
170
171protected:
173 string path;
174
176 string mask;
177
179 int poll_interval = 10;
180
182 bool runflag = False;
183
185 bool fatal = False;
186
188 int pollcnt = 0;
189
191 int sort_type = SortName;
192
194 int sort_order = OrderAsc;
195
198
200 int tid;
201
204
206 int reopt;
207
209 *softint minage;
210
212 *code log_info;
213
216
219
222
224 *code sleep;
225
226public:
227
229
261 constructor(string n_path, string n_mask, *hash<auto> n_opts);
262
263
266
267
269
274 list<hash<FilePollerFileEventInfo>> getFiles(int sort = FilePoller::SortNone, int order = FilePoller::OrderAsc);
275
276
278
281 int start();
282
283
285
295
296
298
303
304
306
316
317
319
323
324
326 bool runOnce();
327
328
330protected:
331 fileSleep(softint secs);
332public:
333
334
336protected:
338public:
339
340
342
344 fileEvent(list<hash<FilePollerFileEventInfo>> files);
345
346
348
371 abstract singleFileEvent(hash<FilePollerFileEventInfo> event);
372
374
378 static checkPath(string path, string type, bool write = False);
379
382
383
385protected:
386 logInfo(string fmt);
387public:
388
389
391protected:
392 logDetail(string fmt);
393public:
394
395
397protected:
398 logDebug(string fmt);
399public:
400
401};
402
404
409
410public:
413 "path": <DataProviderOptionInfo>{
414 "type": AbstractDataProviderType::get(StringType),
415 "desc": "A path giving the location of the directory to poll",
416 "required": True,
417 },
418
419 "mask": <DataProviderOptionInfo>{
420 "type": AbstractDataProviderType::get(StringType),
421 "desc": "The glob mask to use; will be treated as a regex if `regex` is `true`",
422 "default_value": "*",
423 },
424
425 "poll_interval": <DataProviderOptionInfo>{
426 "type": AbstractDataProviderType::get(IntType),
427 "desc": "The interval in seconds between polling for files",
428 "default_value": 10,
429 },
430
431 "regex": <DataProviderOptionInfo>{
432 "type": AbstractDataProviderType::get(BoolType),
433 "desc": "If `true` then `mask` is treated as a regular expression instead of a glob pattern",
434 },
435
436 "reopt": <DataProviderOptionInfo>{
437 "type": AbstractDataProviderType::get(IntType),
438 "desc": "A bitfield of regular expression options (`1` = ignore case, `2` = treat EOL as a regular "
439 "character); ignored if `regex` is not `true`",
440 },
441
442 "minage": <DataProviderOptionInfo>{
443 "type": AbstractDataProviderType::get(IntType),
444 "desc": "An integer giving the minimum file age in seconds before the file will be polled; this is "
445 "meant to work around non-atomic file transfer operations",
446 },
447
448 "sort_desc": <DataProviderOptionInfo>{
449 "type": AbstractDataProviderType::get(BoolType),
450 "desc": "Sort descending; if not given then an ascending sort is assumed if a `sort_type` is given",
451 },
452
453 "sort_type": <DataProviderOptionInfo>{
454 "type": AbstractDataProviderType::get(StringType),
455 "desc": "Either `name` or `date` for the data to use for sorting",
456 },
457 };
458
459protected:
461 EmbeddedFilePoller poller;
462
463public:
464
466 constructor(*hash<auto> options);
467
468
469 destructor();
470
471
472 string getName();
473
474
476 *string getDesc();
477
478
480
484protected:
485 hash<string, hash<DataProviderMessageInfo>> getEventTypesImpl();
486public:
487
488};
489
491
498
499public:
501 const ProviderInfo = <DataProviderInfo>{
502 "type": "FilePollerDataProvider",
503 "supports_observable": True,
504 "constructor_options": ConstructorOptions,
505 };
506
508 constructor(*hash<auto> options) ;
509
510
511protected:
512 hash<DataProviderInfo> getStaticInfoImpl();
513public:
514
515};
516
518
525
526public:
528 const ProviderInfo = <DataProviderInfo>{
529 "type": "FileDelayedPollerDataProvider",
530 "supports_observable": True,
531 "constructor_options": ConstructorOptions,
532 };
533
535 constructor(*hash<auto> options) ;
536
537
539
542
543
544protected:
545 hash<DataProviderInfo> getStaticInfoImpl();
546public:
547
548};
549
551class FilePollerFileEventInfoDataType : public HashDataType {
552
553public:
556 "dev": "The device inode number the file is on",
557 "inode": "The inode of the file",
558 "mode": "The file protection mode; a bitfield of file permissions",
559 "nlink": "The number of hard links to this file",
560 "uid": "The UID of the owner of the file",
561 "gid": "The GID of the owner of the file",
562 "rdev": "The device type number",
563 "size": "the size of the file in bytes",
564 "atime": "the last accessed date/time of the file",
565 "mtime": "the last modified date/time of the file",
566 "ctime": "the created date/time of the file",
567 "blksize": "Block size; is zero if the file is zero length or if the platform's internal `stat()` (2) "
568 "function does not provide this info",
569 "blocks": "Blocks allocated for the file; is zero if the file is zero length or if the platform's "
570 "internal `stat()` (2) function does not provide this info",
571 "type": "the type of file; one of:\n- `REGULAR`\n- `DIRECTORY`\n- `SYMBOLIC-LINK`\n"
572 "- `BLOCK-DEVICE`\n- `CHARACTER-DEVICE`\n- `FIFO`\n- `SYMBOLIC-LINK`\n- `SOCKET`\n"
573 "- `UNKNOWN`",
574 "perm": "a string giving UNIX-style permissions for the file (ex: `-rwxr-xr-x`)",
575 "name": "the name of the file, link, or directory",
576 "filepath": "the remote filepath relative to SFILE root directory",
577 "link": "symbolic link target (if present)",
578 };
579
582
583};
584
586class FilePollerDataProviderFactory : public AbstractDataProviderFactory {
587
588public:
589protected:
591 static Class cls = new Class("FileDelayedPollerDataProvider");
592
594 const FactoryInfo = <DataProviderFactoryInfo>{
595 "name": "filepoller",
596 "desc": "File poller data provider factory",
597 "children_can_support_observers": True,
598 };
599
600public:
601
603
605protected:
606 hash<DataProviderFactoryInfo> getInfoImpl();
607public:
608
609
611
613protected:
614 hash<DataProviderInfo> getProviderInfoImpl();
615public:
616
617
619protected:
621public:
622
623};
624};
625
626// private namespace; not exported
627namespace Priv {
628class EmbeddedFilePoller : public FilePoller {
629
630public:
631protected:
633 Observable observable;
634
635public:
636
637 constructor(FilePollerDataProviderBase provider, string path, string mask, *hash<auto> options) ;
638
639
640 singleFileEvent(hash<auto> event);
641
642};
643}
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:524
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:528
Event-based data provider for file events.
Definition: FilePoller.qm.dox.h:408
*string getDesc()
Returns the data provider description.
EmbeddedFilePoller poller
The file poller itself.
Definition: FilePoller.qm.dox.h:461
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:412
The file poller data provider factory.
Definition: FilePoller.qm.dox.h:586
const FactoryInfo
Factory info.
Definition: FilePoller.qm.dox.h:594
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:591
hash< DataProviderInfo > getProviderInfoImpl()
Returns static provider information.
Event-based data provider for file polling events.
Definition: FilePoller.qm.dox.h:497
constructor(*hash< auto > options)
Creates the object from constructor options.
const ProviderInfo
Provider info.
Definition: FilePoller.qm.dox.h:501
File poller event data description.
Definition: FilePoller.qm.dox.h:551
const FieldDescriptions
Markdown descriptions for hashdecl members.
Definition: FilePoller.qm.dox.h:555
*softint minage
minimum file age in seconds before the file will be included in the list returned
Definition: FilePoller.qm.dox.h:209
*code log_info
optional info log closure
Definition: FilePoller.qm.dox.h:212
int reopt
regex options
Definition: FilePoller.qm.dox.h:206
int start()
starts polling in the background; returns the thread ID of the polling thread
const SortNone
no sorting
Definition: FilePoller.qm.dox.h:157
string path
path to monitor
Definition: FilePoller.qm.dox.h:173
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:218
int tid
polling tid
Definition: FilePoller.qm.dox.h:200
destructor()
stops the polling operation if in progress and destroys the object
*code log_detail
optional detail log closure
Definition: FilePoller.qm.dox.h:215
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:152
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:176
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:224
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:221
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:68
const EVENT_FILE
File event constant.
Definition: FilePoller.qm.dox.h:71
FilePoller file event hash.
Definition: FilePoller.qm.dox.h:74
date ctime
The created date/time of the file.
Definition: FilePoller.qm.dox.h:108
int nlink
The number of hard links to this file.
Definition: FilePoller.qm.dox.h:87
int mode
The file protection mode.
Definition: FilePoller.qm.dox.h:84
int inode
The inode of the file.
Definition: FilePoller.qm.dox.h:79
string type
the type of file
Definition: FilePoller.qm.dox.h:132
string name
The name of the file, link, or directory.
Definition: FilePoller.qm.dox.h:138
int dev
The device inode number the file is on.
Definition: FilePoller.qm.dox.h:76
int blocks
Blocks allocated for the file.
Definition: FilePoller.qm.dox.h:118
int uid
The UID of the owner of the file.
Definition: FilePoller.qm.dox.h:90
int blksize
Block size.
Definition: FilePoller.qm.dox.h:113
date atime
The last accessed date/time of the file.
Definition: FilePoller.qm.dox.h:102
int rdev
The device type number.
Definition: FilePoller.qm.dox.h:96
string perm
a string giving UNIX-style permissions for the file (ex: "-rwxr-xr-x")
Definition: FilePoller.qm.dox.h:135
int gid
The GID of the owner of the file.
Definition: FilePoller.qm.dox.h:93
int size
The size of the file in bytes.
Definition: FilePoller.qm.dox.h:99
*string link
symbolic link target (if present)
Definition: FilePoller.qm.dox.h:144
string filepath
The entire path of the file.
Definition: FilePoller.qm.dox.h:141
date mtime
The last modified date/time of the file.
Definition: FilePoller.qm.dox.h:105