Xfce Foundation Classes
Main Page | Index | Namespace List | Alphabetical List | Class List | File List

# Xfc::G::MainLoop Class Reference

A C++ interface for the GMainLoop. More...

`#include <xfc/glib/main.hh>`

Inheritance diagram for Xfc::G::MainLoop:

List of all members.

## Public Member Functions

Constructors

- MainLoop ()
    Construct a new main loop object using the default MainContext.
- MainLoop (MainContext &context)
    Construct a new main loop object using the specified MainContext.
- virtual ~MainLoop ()
    Destructor.

Accessors

- GMainLoop * g_main_loop () const
    Get a pointer to the GMainLoop object.
- operator GMainLoop * () const
    Conversion operator; Safely converts a G::MainLoop object into a GMainLoop pointer.
- bool is_running () const
    Checks to see if the main loop is currently being run via run().
- Pointer< MainContext > get_context () const
    Obtains the MainContext of loop.

Methods

- virtual void ref ()
    Increases the reference count on a main loop object by one.
- virtual void unref ()
    Decreases the reference count on a main loop object by one.
- void run ()
    Runs a main loop until quit() is called on the loop.
- void quit ()
    Stops a main loop from running, and any calls to run() for the loop will return.

## Static Public Member Functions

Accessors

- int depth ()
    Get the main loop recursion level in the current thread.

## Detailed Description

A C++ interface for the GMainLoop.

The main event loop manages all the available sources of events for GLib and GTK+ applications. These events can come from any number of different types of sources such as file descriptors (plain files, pipes or sockets) and timeouts. New types of event sources can also be added using G::Source::attach().

To allow multiple independent sets of sources to be handled in different threads, each source is associated with a MainContext. A MainContext can only be running in a single thread, but sources can be added to it and removed from it from other threads.

Each event source is assigned a priority. The default priority, G::PRIORITY_DEFAULT, is 0. Values less than 0 denote higher priorities. Values greater than 0 denote lower priorities. Events from high priority sources are always processed before events from lower priority sources.

Idle functions can also be added, and assigned a priority. These will be run whenever no events with a higher priority are ready to be processed.

MainLoop represents a single invocation of the main event loop. After constructing a MainLoop and adding the initial event sources, run() is called. This continuously checks for new events from each of the event sources and dispatches them. This continues until finally, the processing of an event from one of the sources leads to a call to quit() to exit the main loop, and run() returns.

It is possible to create new instances of MainLoop recursively. This is often used in GTK+ applications when showing modal dialog boxes. Note that event sources are associated with a particular MainContext, and will be checked and dispatched for all main loops associated with that MainContext.

## Constructor & Destructor Documentation

Xfc::G::MainLoop::MainLoop | ( | MainContext & | context | ) |

Construct a new main loop object using the specified MainContext.

Parameters:

  | context | A MainContext.

## Member Function Documentation

int Xfc::G::MainLoop::depth | ( |  | ) | `[static]`

Get the main loop recursion level in the current thread.

Returns:
  The main loop recursion level in the current thread.

When called from the toplevel, this method returns 0. When called from within a callback from G::MainContext::iteration() (or G::MainLoop::run(), etc.) it returns 1. When called from within a callback to a recursive call to G::MainContext::iteration(), it returns 2. And so forth.

Pointer<MainContext> Xfc::G::MainLoop::get_context | ( |  | ) | const

Obtains the MainContext of loop.

Returns:
  The MainContext of loop

bool Xfc::G::MainLoop::is_running | ( |  | ) | const

Checks to see if the main loop is currently being run via run().

Returns:
  true if the main loop is currently being run.

void Xfc::G::MainLoop::run | ( |  | ) |

| Runs a main loop until quit() is called on the loop. If this is called for the thread of the loop's MainContext, it will process events from the loop, otherwise it will simply wait.

virtual void Xfc::G::MainLoop::unref | ( |  | ) | `[virtual]`

Decreases the reference count on a main loop object by one.

When the reference count becomes zero for a heap object delete is called. Remember, as with all XFC Objects you must call unref() on a dynamically allocated MainLoop, not delete. If you use a smart you don't need to call unref(), the smart pointer will do that for you. You don't need to call unref() on a loop allocated on the stack unless you first called ref().

Reimplemented from Xfc::Trackable.

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

- libXFCcore/xfc/glib/main.hh

Xfce Foundation Classes

Copyright © 2004-2005 The XFC Development Team | XFC 4.3