glibmm 2.56.0

Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Glib::Source Class Referenceabstract
The Main Event Loop

`#include <glibmm/main.h>`

Inheritance diagram for Glib::Source:
[legend]

## Public Types
using | CppObjectType = Glib::Source
using | BaseObjectType = GSource

## Public Member Functions
| Source (const Source&)=delete
Source& | operator= (const Source&)=delete
unsigned int | attach (const Glib::RefPtr< MainContext >& context)
| Adds a Source to a context so that it will be executed within that context. More...
unsigned int | attach ()
| Adds a Source to a context so that it will be executed within that context. More...
void | destroy ()
| Removes a source from its MainContext, if any, and marks it as destroyed. More...
void | set_priority (int priority)
| Sets the priority of a source. More...
int | get_priority () const
| Gets the priority of a source. More...
void | set_can_recurse (bool can_recurse)
| Sets whether a source can be called recursively. More...
bool | get_can_recurse () const
| Checks whether a source is allowed to be called recursively. More...
unsigned int | get_id () const
| Returns the numeric ID for a particular source. More...
Glib::RefPtr< MainContext > | get_context ()
| Gets the MainContext with which the source is associated. More...
GSource* | gobj ()
const GSource* | gobj () const
GSource* | gobj_copy () const
void | reference () const
void | unreference () const

## Static Public Member Functions
static Glib::RefPtr< Source > | create ()

## Protected Member Functions
| Source ()
| Construct an object that uses the virtual functions prepare(), check() and dispatch(). More...
| Source (GSource* cast_item, GSourceFunc callback_func)
| Wrap an existing GSource object and install the given callback function. More...
virtual | ~Source () noexcept
sigc::connection | connect_generic (const sigc::slot_base& slot)
void | add_poll (PollFD& poll_fd)
| Adds a file descriptor to the set of file descriptors polled for this source. More...
void | remove_poll (PollFD& poll_fd)
| Removes a file descriptor from the set of file descriptors polled for this source. More...
void | get_current_time (Glib::TimeVal& current_time)
| Gets the "current time" to be used when checking this source. More...
gint64 | get_time () const
| Gets the time to be used when checking this source. More...
virtual bool | prepare (int& timeout)=0
virtual bool | check ()=0
virtual bool | dispatch (sigc::slot_base* slot)=0

## Member Typedef Documentation

## ◆ BaseObjectType

using Glib::Source::BaseObjectType = GSource

## ◆ CppObjectType

using Glib::Source::CppObjectType = Glib::Source

## Constructor & Destructor Documentation

## ◆ Source() [1/3]

Glib::Source::Source | ( | const Source& |  | ) |
| delete

## ◆ Source() [2/3]

Glib::Source::Source | ( |  | ) |
| protected

Construct an object that uses the virtual functions prepare(), check() and dispatch().

## ◆ Source() [3/3]

Glib::Source::Source | ( | GSource * | cast_item,
|  | GSourceFunc | callback_func
| ) |  |
| protected

Wrap an existing GSource object and install the given callback function.

The constructed object doesn't use the virtual functions prepare(), check() and dispatch(). This constructor is for use by derived types that need to wrap a GSource object. The callback function can be a static member function. But beware - depending on the actual implementation of the GSource's virtual functions the expected type of the callback function can differ from GSourceFunc.

## ◆ ~Source()

virtual Glib::Source::~Source | ( |  | ) |
| protected virtual noexcept

## Member Function Documentation

## ◆ add_poll()

void Glib::Source::add_poll | ( | PollFD& | poll_fd | ) |
| protected

Adds a file descriptor to the set of file descriptors polled for this source.

The event source's check function will typically test the revents field in the PollFD and return true if events need to be processed.

Parameters

  poll_fd | A PollFD object holding information about a file descriptor to watch.

## ◆ attach() [1/2]

unsigned int Glib::Source::attach | ( | const Glib::RefPtr< MainContext >& | context | ) |

Adds a Source to a context so that it will be executed within that context.

Parameters

  context | A MainContext.

Returns
  The ID for the source within the MainContext.

## ◆ attach() [2/2]

unsigned int Glib::Source::attach | ( |  | ) |

Adds a Source to a context so that it will be executed within that context.

The default context will be used.

Returns
  The ID for the source within the MainContext.

## ◆ check()

virtual bool Glib::Source::check | ( |  | ) |
| protected pure virtual

Implemented in Glib::IOSource, Glib::IdleSource, and Glib::TimeoutSource.

## ◆ connect_generic()

sigc::connection Glib::Source::connect_generic | ( | const sigc::slot_base & | slot | ) |
| protected

## ◆ create()

static Glib::RefPtr<Source> Glib::Source::create | ( |  | ) |
| static

## ◆ destroy()

void Glib::Source::destroy | ( |  | ) |

Removes a source from its MainContext, if any, and marks it as destroyed.

The source cannot be subsequently added to another context.

## ◆ dispatch()

virtual bool Glib::Source::dispatch | ( | sigc::slot_base * | slot | ) |
| protected pure virtual

Implemented in Glib::IOSource, Glib::IdleSource, and Glib::TimeoutSource.

## ◆ get_can_recurse()

bool Glib::Source::get_can_recurse | ( |  | ) | const

Checks whether a source is allowed to be called recursively.

see set_can_recurse().

Returns
  Whether recursion is allowed.

## ◆ get_context()

Glib::RefPtr<MainContext> Glib::Source::get_context | ( |  | ) |

Gets the MainContext with which the source is associated.

Calling this function on a destroyed source is an error.

Returns
  The MainContext with which the source is associated, or a null RefPtr if the context has not yet been added to a source.

## ◆ get_current_time()

void Glib::Source::get_current_time | ( | Glib::TimeVal& | current_time | ) |
| protected

Gets the "current time" to be used when checking this source.

Parameters

  [out] | current_time | Glib::TimeVal in which to store current time.

Deprecated:
  Use get_time() instead.

## ◆ get_id()

unsigned int Glib::Source::get_id | ( |  | ) | const

Returns the numeric ID for a particular source.

The ID of a source is unique within a particular main loop context. The reverse mapping from ID to source is done by MainContext::find_source_by_id().

Returns
  The ID for the source.

## ◆ get_priority()

int Glib::Source::get_priority | ( |  | ) | const

Gets the priority of a source.

Returns
  The priority of the source.

## ◆ get_time()

gint64 Glib::Source::get_time | ( |  | ) | const
| protected

Gets the time to be used when checking this source.

The advantage of calling this function over calling g_get_monotonic_time() directly is that when checking multiple sources, GLib can cache a single value instead of having to repeatedly get the system monotonic time.

The time here is the system monotonic time, if available, or some other reasonable alternative otherwise. See g_get_monotonic_time().

Returns
  The monotonic time in microseconds.

Since glibmm 2.28:

## ◆ gobj() [1/2]

GSource* Glib::Source::gobj | ( |  | ) |
| inline

## ◆ gobj() [2/2]

const GSource* Glib::Source::gobj | ( |  | ) | const
| inline

## ◆ gobj_copy()

GSource* Glib::Source::gobj_copy | ( |  | ) | const

## ◆ operator=()

Source& Glib::Source::operator= | ( | const Source& |  | ) |
| delete

## ◆ prepare()

virtual bool Glib::Source::prepare | ( | int & | timeout | ) |
| protected pure virtual

Implemented in Glib::IOSource, Glib::IdleSource, and Glib::TimeoutSource.

## ◆ reference()

void Glib::Source::reference | ( |  | ) | const

## ◆ remove_poll()

void Glib::Source::remove_poll | ( | PollFD& | poll_fd | ) |
| protected

Removes a file descriptor from the set of file descriptors polled for this source.

Parameters

  poll_fd | A PollFD object previously passed to add_poll().

## ◆ set_can_recurse()

void Glib::Source::set_can_recurse | ( | bool | can_recurse | ) |

Sets whether a source can be called recursively.

If can_recurse is true, then while the source is being dispatched then this source will be processed normally. Otherwise, all processing of this source is blocked until the dispatch function returns.

Parameters

  can_recurse | Whether recursion is allowed for this source.

## ◆ set_priority()

void Glib::Source::set_priority | ( | int | priority | ) |

Sets the priority of a source.

While the main loop is being run, a source will be dispatched if it is ready to be dispatched and no sources at a higher (numerically smaller) priority are ready to be dispatched.

Parameters

  priority | The new priority.

## ◆ unreference()

void Glib::Source::unreference | ( |  | ) | const