ivi-main-loop
ivi::GLibChannelWatchEventSource Class Reference
Inheritance diagram for ivi::GLibChannelWatchEventSource:
Collaboration diagram for ivi::GLibChannelWatchEventSource:

Public Types

enum  Event { Event::NONE, Event::READ_AVAILABLE, Event::WRITE_AVAILABLE, Event::HANG_UP }
 
typedef std::function< ReportStatus(Event)> CallBackFunction
 
enum  ReportStatus { ReportStatus::KEEP_ENABLED, ReportStatus::DISABLE }
 

Public Member Functions

 GLibChannelWatchEventSource (GLibEventDispatcher &mainLoop, CallBackFunction callBackFunction, FileDescriptor fileDescriptor, Event events)
 
void disable () override
 Disables the source. More...
 
void enable () override
 Enables the source. More...
 
bool isEnabled () const
 Returns true if the source is currently enabled, false otherwise. More...
 
virtual FileDescriptor getFileDescriptor () const
 

Protected Attributes

CallBackFunction m_callBack
 
FileDescriptor m_fileDescriptor
 

Detailed Description

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

Member Enumeration Documentation

Enumerator
NONE 

No event occurred.

READ_AVAILABLE 

Some data is available from the channel.

WRITE_AVAILABLE 

Some data can be written to the channel without blocking.

HANG_UP 

The channel has been close, which means no data can be read from the corresponding file descriptor.

Definition at line 122 of file ivi-main-loop-common.h.

123  {
124  /// No event occurred
125  NONE,
126 
127  /// Some data is available from the channel
128  READ_AVAILABLE = 1,
129 
130  /// Some data can be written to the channel without blocking
131  WRITE_AVAILABLE = 2,
132 
133  /// The channel has been close, which means no data can be read from the corresponding file descriptor
134  HANG_UP = 4
135  };
enum ivi::EventSource::ReportStatus
stronginherited
Enumerator
KEEP_ENABLED 

Returning that value from a source's callback function causes the source to remain enabled.

DISABLE 

Returning that value from a source's callback function causes the source to be disabled.

Definition at line 32 of file ivi-main-loop-common.h.

33  {
34  /// Returning that value from a source's callback function causes the source to remain enabled
35  KEEP_ENABLED,
36 
37  /// Returning that value from a source's callback function causes the source to be disabled
38  DISABLE
39  };

Member Function Documentation

void ivi::GLibChannelWatchEventSource::disable ( )
overridevirtual

Disables the source.

Implements ivi::EventSource.

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

178 {
179  if (inputSourceID != UNREGISTERED_SOURCE) {
180  g_source_remove(inputSourceID);
181  }
182  inputSourceID = UNREGISTERED_SOURCE;
183 }
void ivi::GLibChannelWatchEventSource::enable ( )
overridevirtual

Enables the source.

Implements ivi::EventSource.

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

References ivi::GLibEventDispatcher::getGMainContext(), and isEnabled().

218 {
219  if (!isEnabled()) {
220  m_channel = g_io_channel_unix_new(getFileDescriptor());
221  inputSourceID = g_io_add_watch_full_with_context(m_channel, G_PRIORITY_DEFAULT, toGIOCondition(m_events),
222  onSocketDataAvailableGLibCallback, this, nullptr, m_mainLoop.getGMainContext());
223  }
224 }
GMainContext * getGMainContext()
Return the glib main context reference.
bool isEnabled() const
Returns true if the source is currently enabled, false otherwise.

Here is the call graph for this function:

bool ivi::GLibChannelWatchEventSource::isEnabled ( ) const
inlinevirtual

Returns true if the source is currently enabled, false otherwise.

Implements ivi::EventSource.

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

Referenced by enable().

97  {
98  return (inputSourceID!=UNREGISTERED_SOURCE);
99  }

Here is the caller graph for this function:


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