Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cargo::ipc::epoll::EventPoll Class Reference

This class waits on registered file descriptor for events. More...

#include <event-poll.hpp>

Public Types

typedef std::function< void(int
fd, Events events)> 
Callback
 Generic function type used as callback for epoll events. More...
 

Public Member Functions

 EventPoll ()
 Constructs the EventPoll and initializes the underlaying epoll mechanism. More...
 
 ~EventPoll ()
 
int getPollFD () const
 Returns epoll handle. More...
 
void addFD (const int fd, const Events events, Callback &&callback)
 Add descriptor and it's watched events. More...
 
void modifyFD (const int fd, const Events events)
 Modify watched events for descriptor. More...
 
void removeFD (const int fd)
 Remove descriptor from the watch list. More...
 
bool dispatchIteration (const int timeoutMs)
 Wait for events on descriptor on the watch list. More...
 

Private Types

typedef std::recursive_mutex Mutex
 

Private Member Functions

bool addFDInternal (const int fd, const Events events)
 
bool modifyFDInternal (const int fd, const Events events)
 
void removeFDInternal (const int fd)
 

Private Attributes

const int mPollFD
 
Mutex mMutex
 
std::unordered_map< int,
std::shared_ptr< Callback > > 
mCallbacks
 

Detailed Description

This class waits on registered file descriptor for events.

It uses epoll mechanism.

See Also
cargo::ipc::epoll::Events

Member Typedef Documentation

typedef std::function<void(int fd, Events events)> cargo::ipc::epoll::EventPoll::Callback

Generic function type used as callback for epoll events.

Parameters
fddescriptor that triggered the event
eventsevent mask that occured
See Also
cargo::ipc::epoll::Events
typedef std::recursive_mutex cargo::ipc::epoll::EventPoll::Mutex
private

Constructor & Destructor Documentation

cargo::ipc::epoll::EventPoll::EventPoll ( )

Constructs the EventPoll and initializes the underlaying epoll mechanism.

Exceptions
UtilsExceptionthrown if epoll initialization failed
cargo::ipc::epoll::EventPoll::~EventPoll ( )

Member Function Documentation

void cargo::ipc::epoll::EventPoll::addFD ( const int  fd,
const Events  events,
Callback &&  callback 
)

Add descriptor and it's watched events.

Parameters
fddescriptor to watch
eventsevents to associate with the descriptor
callbackcallback to call once the event occurs
Exceptions
UtilsExceptionthrown if descriptor already registered or add fail
See Also
cargo::ipc::epoll::Events
bool cargo::ipc::epoll::EventPoll::addFDInternal ( const int  fd,
const Events  events 
)
private
bool cargo::ipc::epoll::EventPoll::dispatchIteration ( const int  timeoutMs)

Wait for events on descriptor on the watch list.

Dispatch at most one signaled FD.

Parameters
timeoutMshow long should wait in case of no pending events (0 - return immediately, -1 - wait forever)
Exceptions
UtilsExceptionif epoll_wait fails
Returns
false on timeout
int cargo::ipc::epoll::EventPoll::getPollFD ( ) const

Returns epoll handle.

Returns
handle or -1 if not initialized
void cargo::ipc::epoll::EventPoll::modifyFD ( const int  fd,
const Events  events 
)

Modify watched events for descriptor.

Parameters
fdwatched descriptor, already registered
eventsevents to associate with the descriptor
Exceptions
UtilsExceptionif descriptor not found or epoll modify fail
See Also
cargo::ipc::epoll::Events
bool cargo::ipc::epoll::EventPoll::modifyFDInternal ( const int  fd,
const Events  events 
)
private
void cargo::ipc::epoll::EventPoll::removeFD ( const int  fd)

Remove descriptor from the watch list.

Parameters
fdwatched descriptor
void cargo::ipc::epoll::EventPoll::removeFDInternal ( const int  fd)
private

Member Data Documentation

std::unordered_map<int, std::shared_ptr<Callback> > cargo::ipc::epoll::EventPoll::mCallbacks
private
Mutex cargo::ipc::epoll::EventPoll::mMutex
private
const int cargo::ipc::epoll::EventPoll::mPollFD
private

The documentation for this class was generated from the following files: