Open Lighting Architecture
Latest Git
|
A single threaded I/O event management system.
SelectServer is the core of the event driven system. It's responsible for invoking Callbacks when certain events occur.
The SelectServer has a number of different implementations depending on the platform. On systems with epoll, the flag --no-use-epoll will disable the use of epoll(), reverting to select(). The PollerInterface defines the contract between the SelectServer and the lower level, platform dependent Poller classes.
All methods except Execute() and Terminate() must be called from the thread that Run() was called in.
Classes | |
struct | Options |
Public Member Functions | |
SelectServer (ola::ExportMap *export_map=NULL, Clock *clock=NULL) | |
Create a new SelectServer. More... | |
SelectServer (const Options &options) | |
Create a new SelectServer. More... | |
~SelectServer () | |
Clean up. More... | |
bool | IsRunning () const |
Checks if the SelectServer is running. More... | |
const TimeStamp * | WakeUpTime () const |
The time when this SelectServer was woken up. More... | |
void | Terminate () |
Exit from the Run() loop. More... | |
void | SetDefaultInterval (const TimeInterval &block_interval) |
Set the duration to block for. More... | |
void | Run () |
Enter the event loop. More... | |
void | RunOnce () |
Do a single pass through the event loop. Does not block. | |
void | RunOnce (const TimeInterval &block_interval) |
Do a single pass through the event loop. More... | |
bool | AddReadDescriptor (ReadFileDescriptor *descriptor) |
Register a ReadFileDescriptor for read-events. More... | |
bool | AddReadDescriptor (ConnectedDescriptor *descriptor, bool delete_on_close=false) |
Register a ConnectedDescriptor for read-events. More... | |
void | RemoveReadDescriptor (ReadFileDescriptor *descriptor) |
Remove a ReadFileDescriptor for read-events. More... | |
void | RemoveReadDescriptor (ConnectedDescriptor *descriptor) |
Remove a ConnectedDescriptor for read-events. More... | |
bool | AddWriteDescriptor (WriteFileDescriptor *descriptor) |
Register a WriteFileDescriptor for write-events. More... | |
void | RemoveWriteDescriptor (WriteFileDescriptor *descriptor) |
Remove a WriteFileDescriptor for write-events. More... | |
ola::thread::timeout_id | RegisterRepeatingTimeout (unsigned int ms, ola::Callback0< bool > *callback) |
Execute a callback periodically. More... | |
ola::thread::timeout_id | RegisterRepeatingTimeout (const ola::TimeInterval &interval, ola::Callback0< bool > *callback) |
Execute a callback periodically. More... | |
ola::thread::timeout_id | RegisterSingleTimeout (unsigned int ms, ola::SingleUseCallback0< void > *callback) |
Execute a callback after a certain time interval. More... | |
ola::thread::timeout_id | RegisterSingleTimeout (const ola::TimeInterval &interval, ola::SingleUseCallback0< void > *callback) |
Execute a callback after a certain time interval. More... | |
void | RemoveTimeout (ola::thread::timeout_id id) |
Cancel an existing timeout. More... | |
void | RunInLoop (ola::Callback0< void > *callback) |
Execute a callback on every event loop. More... | |
void | Execute (ola::BaseCallback0< void > *callback) |
Execute the supplied callback at some point in the future. More... | |
void | DrainCallbacks () |
Run all callbacks until there are none left. | |
Friends | |
class | ::SelectServerTest |
ola::io::SelectServer::SelectServer | ( | ola::ExportMap * | export_map = NULL , |
Clock * | clock = NULL |
||
) |
Create a new SelectServer.
|
explicit |
Create a new SelectServer.
options | additional options. |
ola::io::SelectServer::~SelectServer | ( | ) |
Clean up.
The SelectServer should be terminated before it's deleted.
|
virtual |
Register a ReadFileDescriptor for read-events.
descriptor | the ReadFileDescriptor to add. |
When the descriptor is ready for reading, PerformRead() will be called.
Implements ola::io::SelectServerInterface.
|
virtual |
Register a ConnectedDescriptor for read-events.
descriptor | the ConnectedDescriptor to add. |
delete_on_close | if true, ownership of the ConnectedDescriptor is transferred to the SelectServer. |
When the descriptor is ready for reading, PerformRead() will be called. Prior to PerformRead(), IsClosed() is called. If this returns true, and delete_on_close was set, the descriptor will be deleted.
Implements ola::io::SelectServerInterface.
|
virtual |
Register a WriteFileDescriptor for write-events.
descriptor | the WriteFileDescriptor to add. |
When the descriptor is writeable, PerformWrite() is called.
Implements ola::io::SelectServerInterface.
|
virtual |
Execute the supplied callback at some point in the future.
callback | the callback to run. |
This method provides the following guarantees:
When queuing callbacks, you need to ensure that either:
To achieve the latter it's common to keep track of the number of outstanding callbacks and then call DrainCallbacks() in the destructor if the number of outstanding callbacks is non-0.
Implements ola::thread::ExecutorInterface.
|
inline |
Checks if the SelectServer is running.
|
virtual |
Execute a callback periodically.
period | the number of milliseconds between each execution of the callback. |
callback | the callback to run. Ownership is transferred. |
Returning false from the callback will cause it to be cancelled.
Implements ola::io::SelectServerInterface.
|
virtual |
Execute a callback periodically.
period | the time interval between each execution of the callback. |
callback | the callback to run. Ownership is transferred. |
Returning false from the callback will cause it to be cancelled.
Implements ola::io::SelectServerInterface.
|
virtual |
Execute a callback after a certain time interval.
delay | the number of milliseconds before the callback is executed. |
callback | the callback to run. Ownership is transferred. |
Implements ola::io::SelectServerInterface.
|
virtual |
Execute a callback after a certain time interval.
delay | the time interval to wait before the callback is executed. |
callback | the callback to run. Ownership is transferred. |
Implements ola::io::SelectServerInterface.
|
virtual |
Remove a ReadFileDescriptor for read-events.
descriptor | the descriptor to remove. |
Implements ola::io::SelectServerInterface.
|
virtual |
Remove a ConnectedDescriptor for read-events.
descriptor | the descriptor to remove. |
Implements ola::io::SelectServerInterface.
|
virtual |
Cancel an existing timeout.
id | the timeout_id returned by a call to RegisterRepeatingTimeout or RegisterSingleTimeout. |
Implements ola::io::SelectServerInterface.
|
virtual |
Remove a WriteFileDescriptor for write-events.
descriptor | the descriptor to remove. |
Implements ola::io::SelectServerInterface.
void ola::io::SelectServer::Run | ( | ) |
Enter the event loop.
Run() will return once Terminate() has been called.
void ola::io::SelectServer::RunInLoop | ( | ola::Callback0< void > * | callback | ) |
Execute a callback on every event loop.
callback | the Callback to execute. Ownership is transferrred to the SelectServer. |
Be very cautious about using this, it's almost certainly not what you want.
There is no way to remove a Callback added with this method.
void ola::io::SelectServer::RunOnce | ( | const TimeInterval & | block_interval | ) |
Do a single pass through the event loop.
block_interval | The maximum time to block if there is no I/O or timer events. |
void ola::io::SelectServer::SetDefaultInterval | ( | const TimeInterval & | block_interval | ) |
Set the duration to block for.
block_interval | the interval to block for. |
This controls the upper bound on the duration between callbacks added with RunInLoop().
void ola::io::SelectServer::Terminate | ( | ) |
Exit from the Run() loop.
Terminate() may be called from any thread.
|
virtual |
The time when this SelectServer was woken up.
If running within the same thread as the SelectServer, this is a efficient way to get the current time.
Implements ola::io::SelectServerInterface.