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::IPCGSource Struct Reference

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
 
IPCGSourceoperator= (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
 

Detailed Description

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:

  • waiting till the managed object (Client or Service) is destroyed before IPCGSource stops operating. For now programmer has to ensure this.

Member Typedef Documentation

typedef std::function<void(FileDescriptor fd, short pollEvent)> cargo::ipc::IPCGSource::HandlerCallback
typedef std::unique_lock<std::recursive_mutex> cargo::ipc::IPCGSource::Lock
private
typedef std::shared_ptr<IPCGSource> cargo::ipc::IPCGSource::Pointer

Constructor & Destructor Documentation

cargo::ipc::IPCGSource::~IPCGSource ( )
cargo::ipc::IPCGSource::IPCGSource ( )
delete
cargo::ipc::IPCGSource::IPCGSource ( const IPCGSource )
delete
cargo::ipc::IPCGSource::IPCGSource ( const HandlerCallback handlerCallback)
private

Member Function Documentation

void cargo::ipc::IPCGSource::addFD ( const FileDescriptor  peerFD)

New file descriptor to listen on.

Parameters
peerFDfile descriptor
guint cargo::ipc::IPCGSource::attach ( GMainContext *  context = nullptr)

Attach to the glib's GMainContext.

Parameters
contextwhere to connect
Returns
result of the g_source_attach call
void cargo::ipc::IPCGSource::callHandler ( )

Locks the internal state mutex and calls the handler callback for each fd.

gboolean cargo::ipc::IPCGSource::check ( GSource *  source)
staticprivate

GSourceFuncs' callback.

IPCGSource::Pointer cargo::ipc::IPCGSource::create ( const HandlerCallback handlerCallback)
static

Creates the IPCGSource class in the memory allocated by glib.

Calls IPCGSource's constructor

Parameters
handlerCallbackevent handling callback
Returns
pointer to the IPCGSource
void cargo::ipc::IPCGSource::detach ( )

After this method quits handlerCallback will not be called.

gboolean cargo::ipc::IPCGSource::dispatch ( GSource *  source,
GSourceFunc  callbacks,
gpointer  userData 
)
staticprivate

GSourceFuncs' callback.

void cargo::ipc::IPCGSource::finalize ( GSource *  source)
staticprivate

GSourceFuncs' callback.

gboolean cargo::ipc::IPCGSource::onHandlerCall ( gpointer  userData)
static

Callback for the dispatch function.

IPCGSource& cargo::ipc::IPCGSource::operator= ( const IPCGSource )
delete
gboolean cargo::ipc::IPCGSource::prepare ( GSource *  source,
gint *  timeout 
)
staticprivate

GSourceFuncs' callback.

void cargo::ipc::IPCGSource::removeFD ( const FileDescriptor  peerFD)

Removes the file descriptor from the GSource.

Parameters
peerFDfile descriptor

Member Data Documentation

std::list<GPollFD> cargo::ipc::IPCGSource::mGPollFDs
private
GSource cargo::ipc::IPCGSource::mGSource
private
utils::CallbackGuard cargo::ipc::IPCGSource::mGuard
private
HandlerCallback cargo::ipc::IPCGSource::mHandlerCallback
private
std::recursive_mutex cargo::ipc::IPCGSource::mStateMutex
private

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