#include <FileEventWatcher.hpp>
Public Member Functions | |
boost::shared_ptr < FileWatchee > | addFileToWatch (std::string FileName, FileWatchType WatchType, std::string DefaultDeviceName="Unknown") |
Add a file to watch for events. | |
boost::shared_ptr < FileWatchee > | addUnixSocketToWatch (std::string FileName, std::string DeviceName) |
Add a unix socket to the watch group. | |
boost::shared_ptr < FileWatchee > | getWatcheeByFileDescriptor (int fd) |
Get a Watchee by file descriptor. | |
boost::shared_ptr < FileWatchee > | getWatcheeByPath (std::string Path) |
Get a Watchee by file name. | |
boost::shared_ptr < FileWatchee > | getWatcheeByWatchDescriptor (int wd) |
Get a Watchee by watch descriptor. | |
virtual void | onFileEventCreate (boost::shared_ptr< FileWatchee > pWatchee, std::string FullPath, std::string FileName) |
Event triggered when a new file is created. | |
virtual void | onFileEventDelete (boost::shared_ptr< FileWatchee > pWatchee, std::string FullPath, std::string FileName) |
Event triggered when a file is deleted. | |
virtual void | onFileEventDisconnect (boost::shared_ptr< FileWatchee > pWatchee) |
Event triggered when a device is disconnected. | |
virtual void | onFileEventRead (boost::shared_ptr< FileWatchee > pWatchee, DynamicBuffer< char > const &ReadBuffer) |
Event triggered when data is waiting on a device. | |
virtual void | onFileEventRegister (boost::shared_ptr< FileWatchee > pWatchee) |
Event triggered when a new device is registered. | |
virtual void | onFileEventWatchBegin () |
Event called when the class will begin watching for events (and blocking). | |
virtual void | onFileEventWatchEnd () |
Event called when the class has ended watching for events (and done blocking). | |
void | removeWatchee (boost::shared_ptr< FileWatchee > pWatchee) |
Remove a Watchee from the list. | |
void | shutdown () |
Disable event watching. | |
void | watchForFileEvents () |
Watch for events on already specified files. | |
FileEventWatcher () | |
Default Constructor. | |
virtual | ~FileEventWatcher () |
Destructor. |
This class uses the poll() mechanism to efficiently watch for file changes rather than using select() which does not scale well.
FileEventWatcher is essentially a wrapper for poll() which makes it easy to integrate into any program
Also use the linux kernel's inotify event to get information about directory changes (add / remove files, etc). Unfortunately inotify doesn't work with event node updates so poll is still required
Definition at line 165 of file FileEventWatcher.hpp.
FileEventWatcher::FileEventWatcher | ( | ) |
Default Constructor.
FileEventWatcher Default Constructor.
Definition at line 147 of file FileEventWatcher.cpp.
FileEventWatcher::~FileEventWatcher | ( | ) | [virtual] |
boost::shared_ptr< FileWatchee > FileEventWatcher::addFileToWatch | ( | std::string | FileName, | |
FileWatchType | WatchType, | |||
std::string | DefaultDeviceName = "Unknown" | |||
) |
Add a file to watch for events.
FileName | Absolute path of the file to watch | |
WatchType | Type of watch to perform on the file | |
DefaultDeviceName | Default device name if the device does not support having a name |
Definition at line 205 of file FileEventWatcher.cpp.
References cdbg, cdbg1, cdbg3, DEVICE_NAME_BUF_SIZE, getWatcheeByPath(), MAX_RETRIES, H::UtilTime::nanoSleep(), onFileEventRegister(), RETRY_FAIL_WAIT_NSECS, H::WATCH_IN, H::WATCH_INOUT, H::WATCH_INVALID, and H::WATCH_OUT.
boost::shared_ptr< FileWatchee > FileEventWatcher::addUnixSocketToWatch | ( | std::string | FileName, | |
std::string | DeviceName | |||
) |
Add a unix socket to the watch group.
Add a unix socket to watch for events.
FileName | Absolute path of the file to watch | |
DeviceName | Device name |
Definition at line 300 of file FileEventWatcher.cpp.
References cdbg1, onFileEventRegister(), and H::WATCH_IN.
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByFileDescriptor | ( | int | fd | ) |
Get a Watchee by file descriptor.
Get a Watchee by its file descriptor.
fd | File Desriptor of the desired watchee |
Definition at line 395 of file FileEventWatcher.cpp.
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByPath | ( | std::string | FileName | ) |
Get a Watchee by file name.
Get a Watchee by its file name.
FileName | File name of watchee to get |
Definition at line 404 of file FileEventWatcher.cpp.
Referenced by addFileToWatch().
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByWatchDescriptor | ( | int | wd | ) |
Get a Watchee by watch descriptor.
Get a Watchee by its watch descriptor.
wd | Watch Desriptor of the desired watchee |
Definition at line 425 of file FileEventWatcher.cpp.
void FileEventWatcher::onFileEventCreate | ( | boost::shared_ptr< FileWatchee > | pWatchee, | |
std::string | FullPath, | |||
std::string | FileName | |||
) | [virtual] |
Event triggered when a new file is created.
pWatchee | The Watchee that triggered the event | |
FullPath | The full (absolute) path of the new file | |
FileName | The file name (relative ) of the new file |
Definition at line 549 of file FileEventWatcher.cpp.
void FileEventWatcher::onFileEventDelete | ( | boost::shared_ptr< FileWatchee > | pWatchee, | |
std::string | FullPath, | |||
std::string | FileName | |||
) | [virtual] |
Event triggered when a file is deleted.
pWatchee | The Watchee that triggered the event | |
FullPath | The full (absolute) path of the new file | |
FileName | The file name (relative ) of the new file |
Definition at line 559 of file FileEventWatcher.cpp.
void FileEventWatcher::onFileEventDisconnect | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) | [virtual] |
Event triggered when a device is disconnected.
Event triggered when a file is disconnected.
pWatchee | The Watchee that triggered the event |
Definition at line 567 of file FileEventWatcher.cpp.
void FileEventWatcher::onFileEventRead | ( | boost::shared_ptr< FileWatchee > | pWatchee, | |
DynamicBuffer< char > const & | ReadBuffer | |||
) | [virtual] |
Event triggered when data is waiting on a device.
pWatchee | The Watchee that triggered the event | |
ReadBuffer | The data that was waiting on the device |
Definition at line 576 of file FileEventWatcher.cpp.
void FileEventWatcher::onFileEventRegister | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) | [virtual] |
Event triggered when a new device is registered.
pWatchee | The Watchee that triggered the event |
Definition at line 584 of file FileEventWatcher.cpp.
Referenced by addFileToWatch(), and addUnixSocketToWatch().
void FileEventWatcher::removeWatchee | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) |
Remove a Watchee from the list.
Remove a watchee from the watch list.
pWatchee | The watchee to remove |
Definition at line 621 of file FileEventWatcher.cpp.
References cdbg4.
void FileEventWatcher::shutdown | ( | ) |
Disable event watching.
Stop watching for file events.
This does not interrupt a current call to poll, so watchForFileEvents will only exit after this function is called, and then the next event is received
Definition at line 646 of file FileEventWatcher.cpp.
void FileEventWatcher::watchForFileEvents | ( | ) |
Watch for events on already specified files.
Watch for file events on already specified files.
Note: Blocking
Definition at line 655 of file FileEventWatcher.cpp.
References apply_func, cdbg, cdbg1, cdbg5, onFileEventWatchBegin(), onFileEventWatchEnd(), and POLL_TIMEOUT.