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

# Xfc::G::Source Class Reference

A GSource C++ interface. More...

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

Inheritance diagram for Xfc::G::Source:

List of all members.

## Public Types

- typedef sigc::slot< bool > SourceSlot
    Signature of the callback slot passed to timeout, idle and custom sources.

## Public Member Functions

Constructors

- Source (GSource *source, bool owns_reference=true)
    Construct a source from an existing GSource object.
- virtual ~Source ()
    Destructor.

Accessors

- GSource * g_source () const
    Get a pointer to the GSource object.
- operator GSource * () const
    Conversion operator; Safely converts a G::Source object into a GSource pointer.
- int get_priority () const
    Gets the priority of the source.
- bool get_can_recurse () const
    Checks whether a source is allowed to be called recursively (see set_can_recurse()).
- unsigned int get_id () const
    Gets the numeric ID for a particular source.
- Pointer< MainContext > get_context () const
    Gets the main context with which the source is associated.
- void get_current_time (TimeVal &timeval)
    Gets the "current time" to be used when checking this source.
- bool is_attached (G::MainContext &context) const
    Determines whether context is attached to this source.

Methods

- virtual void ref ()
    Increase the source reference count by one.
- virtual void unref ()
    Decrease the source reference count by one.
- unsigned int attach (MainContext *context=0)
    Adds the source to context so that it will be executed within that context.
- void destroy ()
    Removes a source from its MainContext, if any, and marks it as destroyed.
- void set_priority (int priority)
    Sets the priority of the source.
- void set_can_recurse (bool can_recurse)
    Sets whether a source can be called recursively.

## Detailed Description

A GSource C++ interface.

A Source corresponds to a single source of input. When sources are created they aren't associated with any main context. Once attached, a source is permanently associated with a particular context and can't be moved to another context.

Source is the base class for the built-in ChildWatchSource, TimeoutSource, IdleSource and IOSource types. In most cases the built-in source types should be enough. When they aren't, or when you need something more powerful, you can create your own custom event source by subclassing G::CustomSource and overriding its pure virtual methods.

## Member Typedef Documentation

typedef sigc::slot<bool> Xfc::G::Source::SourceSlot

| Signature of the callback slot passed to timeout, idle and custom sources. Example: Method signature for SourceSlot.
                 bool method();
                 // return: The slot should return false if the source should be removed.

## Constructor & Destructor Documentation

Xfc::G::Source::Source | ( | GSource * | source,
|  | bool | owns_reference = `true`
| ) |

  | Construct a source from an existing GSource object. Parameters:
  | source | A pointer to a GSource.
  | owns_reference | Set true if the initial reference count is owned by this object.
The Source object takes over the ownership of the GSource and unreferences it when the destructor is called.

## Member Function Documentation

unsigned int Xfc::G::Source::attach | ( | MainContext * | context = `0` | ) |

  | Adds the source to context so that it will be executed within that context. Parameters:
  | context | A MainContext, or null to use the default context.
Returns: The ID for the source within the MainContext.

void Xfc::G::Source::destroy | ( |  | ) |

| Removes a source from its MainContext, if any, and marks it as destroyed. After calling this method the source cannot be subsequently added to another context.

bool Xfc::G::Source::get_can_recurse | ( |  | ) | const

| Checks whether a source is allowed to be called recursively (see set_can_recurse()). Returns: Whether recursion is allowed.

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

| Gets the main context with which the source is associated. Returns: The associated MainContext, or null if a context has not yet been added to the source. Calling this function on a destroyed source is an error.

void Xfc::G::Source::get_current_time | ( | TimeVal & | timeval | ) |

  | Gets the "current time" to be used when checking this source. Parameters:
  | timeval | A TimeVal object in which to store the current time.
The advantage of calling this function over calling G::get_current_time() directly is that when checking multiple sources, GLib can cache a single value instead of having to repeatedly get the system time.

unsigned int Xfc::G::Source::get_id | ( |  | ) | const

| Gets the numeric ID for a particular source. Returns: The ID for the source.

int Xfc::G::Source::get_priority | ( |  | ) | const

| Gets the priority of the source. Returns: The priority of the source.

bool Xfc::G::Source::is_attached | ( | G::MainContext & | context | ) | const

| Determines whether context is attached to this source. Returns: true if context is attached to this source.

void Xfc::G::Source::set_can_recurse | ( | bool | can_recurse | ) |

  | Sets whether a source can be called recursively. Parameters:
  | can_recurse | Whether recursion is allowed for this source.
If can_recurse is true, while the source is being dispatched the source will be processed normally. Otherwise, all processing of the source is blocked until the dispatch function returns.

void Xfc::G::Source::set_priority | ( | int | priority | ) |

  | Sets the priority of the source. Parameters:
  | priority | The new priority.
While the main loop is being run, the 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.

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

| Decrease the source reference count 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 IOChannel, 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 source 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