Class for connecting to the glib's loop. More...
#include <ipc-gsource.hpp>
Public Types | |
typedef std::function< void(FileDescriptor fd, short pollEvent)> | HandlerCallback |
typedef std::shared_ptr < IPCGSource > | Pointer |
Public Member Functions | |
~IPCGSource () | |
IPCGSource ()=delete | |
IPCGSource (const IPCGSource &)=delete | |
IPCGSource & | operator= (const IPCGSource &)=delete |
void | addFD (const FileDescriptor peerFD) |
New file descriptor to listen on. More... | |
void | removeFD (const FileDescriptor peerFD) |
Removes the file descriptor from the GSource. More... | |
guint | attach (GMainContext *context=nullptr) |
Attach to the glib's GMainContext. More... | |
void | detach () |
After this method quits handlerCallback will not be called. More... | |
void | callHandler () |
Locks the internal state mutex and calls the handler callback for each fd. More... | |
Static Public Member Functions | |
static Pointer | create (const HandlerCallback &handlerCallback) |
Creates the IPCGSource class in the memory allocated by glib. More... | |
static gboolean | onHandlerCall (gpointer userData) |
Callback for the dispatch function. More... | |
Private Types | |
typedef std::unique_lock < std::recursive_mutex > | Lock |
Private Member Functions | |
IPCGSource (const HandlerCallback &handlerCallback) | |
Static Private Member Functions | |
static gboolean | prepare (GSource *source, gint *timeout) |
GSourceFuncs' callback. More... | |
static gboolean | check (GSource *source) |
GSourceFuncs' callback. More... | |
static gboolean | dispatch (GSource *source, GSourceFunc callbacks, gpointer userData) |
GSourceFuncs' callback. More... | |
static void | finalize (GSource *source) |
GSourceFuncs' callback. More... | |
Private Attributes | |
GSource | mGSource |
HandlerCallback | mHandlerCallback |
std::list< GPollFD > | mGPollFDs |
utils::CallbackGuard | mGuard |
std::recursive_mutex | mStateMutex |
Class for connecting to the glib's loop.
Creates a dedicated GSource.
It's supposed to be constructed ONLY with the static create method and destructed in a glib callback.
TODO:
typedef std::function<void(FileDescriptor fd, short pollEvent)> cargo::ipc::IPCGSource::HandlerCallback |
|
private |
typedef std::shared_ptr<IPCGSource> cargo::ipc::IPCGSource::Pointer |
cargo::ipc::IPCGSource::~IPCGSource | ( | ) |
|
delete |
|
delete |
|
private |
void cargo::ipc::IPCGSource::addFD | ( | const FileDescriptor | peerFD | ) |
New file descriptor to listen on.
peerFD | file descriptor |
guint cargo::ipc::IPCGSource::attach | ( | GMainContext * | context = nullptr | ) |
Attach to the glib's GMainContext.
context | where to connect |
void cargo::ipc::IPCGSource::callHandler | ( | ) |
Locks the internal state mutex and calls the handler callback for each fd.
|
staticprivate |
GSourceFuncs' callback.
|
static |
Creates the IPCGSource class in the memory allocated by glib.
Calls IPCGSource's constructor
handlerCallback | event handling callback |
void cargo::ipc::IPCGSource::detach | ( | ) |
After this method quits handlerCallback will not be called.
|
staticprivate |
GSourceFuncs' callback.
|
staticprivate |
GSourceFuncs' callback.
|
static |
Callback for the dispatch function.
|
delete |
|
staticprivate |
GSourceFuncs' callback.
void cargo::ipc::IPCGSource::removeFD | ( | const FileDescriptor | peerFD | ) |
Removes the file descriptor from the GSource.
peerFD | file descriptor |
|
private |
|
private |
|
private |
|
private |
|
private |