Back to index

unity  6.0.0
Public Types | Public Member Functions | Public Attributes | Protected Attributes | Private Member Functions
unity::glib::TimeoutSeconds Class Reference

glib::TimeoutSeconds is a wrapper to g_timeout and must be used to initialize a timeout that will be executed every seconds, whenever there are no higher priority events pending to the default main loop. More...

#include <GLibSource.h>

Inheritance diagram for unity::glib::TimeoutSeconds:
Inheritance graph
[legend]
Collaboration diagram for unity::glib::TimeoutSeconds:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Priority {
  HIGH = G_PRIORITY_HIGH, DEFAULT = G_PRIORITY_DEFAULT, HIGH_IDLE = G_PRIORITY_HIGH_IDLE, DEFAULT_IDLE = G_PRIORITY_DEFAULT_IDLE,
  LOW = G_PRIORITY_LOW
}
 This is an enum used for convenience, you can actually cast to this any integer: the bigger it is, the lower priority we have. More...
typedef std::shared_ptr< SourcePtr
typedef std::unique_ptr< SourceUniquePtr
typedef sigc::slot< bool > SourceCallback

Public Member Functions

 TimeoutSeconds (unsigned int seconds, Priority prio=Priority::DEFAULT)
 TimeoutSeconds (unsigned int seconds, SourceCallback cb, Priority prio=Priority::DEFAULT)
unsigned int Id () const
bool Run (SourceCallback callback)
 This Run a source using the function as Source's callback.
bool IsRunning () const
void Remove ()
 This removes a source, and stop it from being executed.
void SetPriority (Priority prio)
Priority GetPriority () const

Public Attributes

sigc::signal< void, unsigned int > removed
 The removed signal is emitted when the Source has been removed and so it can happen both when the Remove() method is called and when the callback function returns false.

Protected Attributes

GSource * source_

Private Member Functions

void Init (unsigned int seconds, Priority prio)

Detailed Description

glib::TimeoutSeconds is a wrapper to g_timeout and must be used to initialize a timeout that will be executed every seconds, whenever there are no higher priority events pending to the default main loop.

If the SourceCallback is defined on construction, then the Timeout is ran as soon as it is created, otherwise you must manually call the Run() method with the appropriate parameters.

Definition at line 152 of file GLibSource.h.


Member Typedef Documentation

typedef std::shared_ptr<Source> unity::glib::Source::Ptr [inherited]

Definition at line 56 of file GLibSource.h.

typedef sigc::slot<bool> unity::glib::Source::SourceCallback [inherited]

Definition at line 58 of file GLibSource.h.

typedef std::unique_ptr<Source> unity::glib::Source::UniquePtr [inherited]

Definition at line 57 of file GLibSource.h.


Member Enumeration Documentation

This is an enum used for convenience, you can actually cast to this any integer: the bigger it is, the lower priority we have.

Enumerator:
HIGH 
DEFAULT 
HIGH_IDLE 
DEFAULT_IDLE 
LOW 

Definition at line 64 of file GLibSource.h.

  {
    HIGH = G_PRIORITY_HIGH,                 // -100
    DEFAULT = G_PRIORITY_DEFAULT,           // 0
    HIGH_IDLE = G_PRIORITY_HIGH_IDLE,       // 100
    DEFAULT_IDLE = G_PRIORITY_DEFAULT_IDLE, // 200
    LOW = G_PRIORITY_LOW                    // 300
  };

Constructor & Destructor Documentation

unity::glib::TimeoutSeconds::TimeoutSeconds ( unsigned int  seconds,
Priority  prio = Priority::DEFAULT 
)

Definition at line 161 of file GLibSource.cpp.

{
  Init(seconds, prio);
}

Here is the call graph for this function:

unity::glib::TimeoutSeconds::TimeoutSeconds ( unsigned int  seconds,
SourceCallback  cb,
Priority  prio = Priority::DEFAULT 
)

Definition at line 155 of file GLibSource.cpp.

{
  Init(seconds, prio);
  Run(cb);
}

Here is the call graph for this function:


Member Function Documentation

Definition at line 64 of file GLibSource.cpp.

{
  int prio = 0;
  if (source_)
    prio = g_source_get_priority(source_);

  return static_cast<Priority>(prio);
}
unsigned int unity::glib::Source::Id ( ) const [inherited]

Definition at line 95 of file GLibSource.cpp.

{
  return source_id_;
}
void unity::glib::TimeoutSeconds::Init ( unsigned int  seconds,
Priority  prio 
) [private]

Definition at line 166 of file GLibSource.cpp.

{
  source_ = g_timeout_source_new_seconds(seconds);
  SetPriority(prio);
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool unity::glib::Source::IsRunning ( ) const [inherited]

Definition at line 87 of file GLibSource.cpp.

{
  if (!source_)
    return false;

  return (!g_source_is_destroyed(source_) && g_source_get_context(source_));
}

Here is the caller graph for this function:

void unity::glib::Source::Remove ( ) [inherited]

This removes a source, and stop it from being executed.

After that a source has been removed, it can't be ran again.

Definition at line 42 of file GLibSource.cpp.

{
  if (source_)
  {
    if (!g_source_is_destroyed(source_))
    {
      g_source_destroy(source_);
    }

    g_source_unref(source_);
    source_ = nullptr;
  }
}

Here is the caller graph for this function:

bool unity::glib::Source::Run ( SourceCallback  callback) [inherited]

This Run a source using the function as Source's callback.

The method will return false if the source is already running, true otherwise.

Definition at line 73 of file GLibSource.cpp.

{
  if (!source_ || source_id_ || IsRunning())
    return false;

  callback_ = callback;
  callback_data_ = new CallBackData(this);

  g_source_set_callback(source_, Callback, callback_data_, DestroyCallback);
  source_id_ = g_source_attach(source_, nullptr);

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void unity::glib::Source::SetPriority ( Priority  prio) [inherited]

Definition at line 56 of file GLibSource.cpp.

{
  if (!source_)
    return;

  g_source_set_priority(source_, prio);
}

Here is the caller graph for this function:


Member Data Documentation

sigc::signal<void, unsigned int> unity::glib::Source::removed [inherited]

The removed signal is emitted when the Source has been removed and so it can happen both when the Remove() method is called and when the callback function returns false.

Definition at line 97 of file GLibSource.h.

GSource* unity::glib::Source::source_ [protected, inherited]

Definition at line 102 of file GLibSource.h.


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