ivi-main-loop
ivi::GLibEventDispatcher Class Reference

That class implements the EventDispatcher interface using glib's main loop functions. More...

#include <ivi-main-loop-glib.h>

Inheritance diagram for ivi::GLibEventDispatcher:
Collaboration diagram for ivi::GLibEventDispatcher:

Public Types

typedef GLibIdleEventSource IdleEventSourceType
 
typedef GLibTimeOutEventSource TimeOutEventSourceType
 
typedef GLibChannelWatchEventSource FileDescriptorWatchEventSourceType
 

Public Member Functions

 GLibEventDispatcher ()
 Construct an instance using GLib's default main context if we do not have any instance of GLibEventDispatcher using that context yet, otherwise we create a dedicated context. More...
 
 GLibEventDispatcher (GMainContext *context)
 Construct a glib event dispatcher using the given context. More...
 
IdleEventSourcenewIdleEventSource (const IdleEventSource::CallBackFunction &callBackFunction) finaloverride
 Create a new idle event source. More...
 
TimeOutEventSourcenewTimeOutEventSource (const TimeOutEventSource::CallBackFunction &callBackFunction, DurationInMilliseconds duration) finaloverride
 Create a new timeout event source. More...
 
ChannelWatchEventSourcenewChannelWatchEventSource (const ChannelWatchEventSource::CallBackFunction &callBackFunction, FileDescriptor filedescriptor, ChannelWatchEventSource::Event events) finaloverride
 Create a new channel watch event source. More...
 
void run () finaloverride
 Runs the main loop. More...
 
void quit () finaloverride
 Stops the main loop. More...
 
GMainContext * getGMainContext ()
 Return the glib main context reference. More...
 

Detailed Description

That class implements the EventDispatcher interface using glib's main loop functions.

Definition at line 119 of file ivi-main-loop-glib.h.

Constructor & Destructor Documentation

ivi::GLibEventDispatcher::GLibEventDispatcher ( )

Construct an instance using GLib's default main context if we do not have any instance of GLibEventDispatcher using that context yet, otherwise we create a dedicated context.

Definition at line 243 of file ivi-main-loop-glib.cpp.

244 {
245  if (!s_bDefaultContextAlreadyUsed) {
246  m_context = nullptr;
247  s_bDefaultContextAlreadyUsed = true;
248  } else {
249  m_context = g_main_context_new();
250  }
251 }
ivi::GLibEventDispatcher::GLibEventDispatcher ( GMainContext *  context)

Construct a glib event dispatcher using the given context.

Definition at line 253 of file ivi-main-loop-glib.cpp.

254 {
255  m_context = context;
256 }

Member Function Documentation

IdleEventSource * ivi::GLibEventDispatcher::newIdleEventSource ( const IdleEventSource::CallBackFunction &  callBackFunction)
finaloverridevirtual

Create a new idle event source.

Implements ivi::EventSourceFactory.

Definition at line 276 of file ivi-main-loop-glib.cpp.

277 {
278  return new GLibIdleEventSource(*this, callBackFunction);
279 }
TimeOutEventSource * ivi::GLibEventDispatcher::newTimeOutEventSource ( const TimeOutEventSource::CallBackFunction &  callBackFunction,
DurationInMilliseconds  duration 
)
finaloverridevirtual

Create a new timeout event source.

The initial duration can be provided here, but it can also be altered using the returned object

Implements ivi::EventSourceFactory.

Definition at line 281 of file ivi-main-loop-glib.cpp.

283 {
284  return new GLibTimeOutEventSource(*this, callBackFunction, duration);
285 }
ChannelWatchEventSource * ivi::GLibEventDispatcher::newChannelWatchEventSource ( const ChannelWatchEventSource::CallBackFunction &  callBackFunction,
FileDescriptor  fileDescriptor,
ChannelWatchEventSource::Event  events 
)
finaloverridevirtual

Create a new channel watch event source.

Implements ivi::EventSourceFactory.

Definition at line 287 of file ivi-main-loop-glib.cpp.

290 {
291  return new GLibChannelWatchEventSource(*this, callBackFunction, fileDescriptor, events);
292 }
void ivi::GLibEventDispatcher::run ( )
finaloverridevirtual

Runs the main loop.

That method does not return until the quit() method has been called.

Implements ivi::EventDispatcher.

Definition at line 258 of file ivi-main-loop-glib.cpp.

259 {
260  log_debug() << "run";
261 
262  m_mainLoop = g_main_loop_new(m_context, false);
263 
264  g_main_loop_run(m_mainLoop);
265 
266  g_main_loop_unref(m_mainLoop);
267  m_mainLoop = nullptr;
268 }
void ivi::GLibEventDispatcher::quit ( )
finaloverridevirtual

Stops the main loop.

Calling that method causes the main loop to stop handling any event and ensures that the run() method exits as soon as possible.

Implements ivi::EventDispatcher.

Definition at line 270 of file ivi-main-loop-glib.cpp.

271 {
272  log_debug() << "quit";
273  g_main_loop_quit(m_mainLoop);
274 }
GMainContext* ivi::GLibEventDispatcher::getGMainContext ( )
inline

Return the glib main context reference.

Definition at line 154 of file ivi-main-loop-glib.h.

Referenced by ivi::GLibIdleEventSource::enable(), ivi::GLibTimeOutEventSource::enable(), and ivi::GLibChannelWatchEventSource::enable().

155  {
156  return m_context;
157  }

Here is the caller graph for this function:


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