#include <FileEventWatcher.hpp>
Inheritance diagram for H::FileEventWatcher:
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
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 |
boost::shared_ptr< FileWatchee > FileEventWatcher::addUnixSocketToWatch | ( | std::string | FileName, | |
std::string | DeviceName | |||
) |
Add a unix socket to the watch group.
FileName | Absolute path of the file to watch | |
DeviceName | Device name |
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByFileDescriptor | ( | int | fd | ) |
Get a Watchee by file descriptor.
fd | File Desriptor of the desired watchee |
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByPath | ( | std::string | FileName | ) |
Get a Watchee by file name.
FileName | File name of watchee to get |
boost::shared_ptr< FileWatchee > FileEventWatcher::getWatcheeByWatchDescriptor | ( | int | wd | ) |
Get a Watchee by watch descriptor.
wd | Watch Desriptor of the desired watchee |
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 |
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 |
void FileEventWatcher::onFileEventDisconnect | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) | [virtual] |
Event triggered when a device is disconnected.
pWatchee | The Watchee that triggered the event |
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 |
void FileEventWatcher::onFileEventRegister | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) | [virtual] |
Event triggered when a new device is registered.
pWatchee | The Watchee that triggered the event |
void FileEventWatcher::removeWatchee | ( | boost::shared_ptr< FileWatchee > | pWatchee | ) |
Remove a Watchee from the list.
pWatchee | The watchee to remove |
void FileEventWatcher::shutdown | ( | ) |
Disable event watching.
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
void FileEventWatcher::watchForFileEvents | ( | ) |
Watch for events on already specified files.
Note: Blocking