ONPOSIX
2.0
|
Abstract class to be notified when a descriptor becomes ready for read operations. More...
#include <AbstractDescriptorReader.hpp>
Public Member Functions | |
AbstractDescriptorReader (DescriptorsMonitor &dm) | |
Constructor. | |
virtual | ~AbstractDescriptorReader () |
virtual void | dataAvailable (PosixDescriptor &descriptor)=0 |
Method called when the descriptor becomes ready. | |
bool | monitorDescriptor (PosixDescriptor &descriptor) |
Method to start monitoring a descriptor. | |
bool | stopMonitorDescriptor (PosixDescriptor &descriptor) |
Method to stop monitoring a descriptor. |
Private Attributes | |
DescriptorsMonitor * | dm_ |
Monitor that will notify the readiness of descriptors. |
Abstract class to be notified when a descriptor becomes ready for read operations.
"Observer" class to monitor readiness of a PosixDescriptor. This class allows to create a subclass which is notified when a descriptor becomes ready for read operations. Inherit from this class if your class needs to monitor one or more (file or socket) descriptors for readiness to read operations. The constructor receives as argument a DescriptorsMonitor class, which is the class in charge of monitoring the status of all the given descriptors, and notifying (through a call to the dataAvailable() method) the readiness of a specific descriptor. This class, together with DescriptorsMonitor, implements the "Observer" design pattern.
Example of class notified when data are available reading from a file:
Definition at line 77 of file AbstractDescriptorReader.hpp.
|
inlineexplicit |
Constructor.
It just saves the pointer of the DescriptorsMonitor, that will be used to register at the monitor when monitorDescriptor() will be called.
reference | to the DescriptorsMonitor |
Definition at line 97 of file AbstractDescriptorReader.hpp.
|
inlinevirtual |
Definition at line 99 of file AbstractDescriptorReader.hpp.
|
pure virtual |
Method called when the descriptor becomes ready.
Once monitorDescriptor(int descriptor) has been called, this method will be automatically called by the DescriptorsMonitor whenever the descriptor becomes available.
Reference | to the descriptor that became ready for read operations (the inherited class may want to be called when more than one descriptor becomes ready). |
|
inline |
Method to start monitoring a descriptor.
This method is usually called inside the constructor of the inherited class and allows to start monitoring a specific descriptor.
Descriptor | that must be monitored |
Definition at line 124 of file AbstractDescriptorReader.hpp.
|
inline |
Method to stop monitoring a descriptor.
Descriptor | that must be monitored |
Definition at line 134 of file AbstractDescriptorReader.hpp.
|
private |
Monitor that will notify the readiness of descriptors.
This is the monitor which, once monitorDescriptor(int descriptor) has been called, will automatically call dataAvailable(int descriptor) whenever such a descriptor becomes available for read operations.
Definition at line 86 of file AbstractDescriptorReader.hpp.