Allow changing the priority of a GMainContext (Eric Jonas)
This commit is contained in:
parent
1337c658a8
commit
534ee610d8
2 changed files with 22 additions and 9 deletions
|
@ -44,7 +44,7 @@ class DXXAPI BusTimeout : public Timeout
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BusTimeout( Timeout::Internal*, GMainContext* );
|
BusTimeout( Timeout::Internal*, GMainContext*, int );
|
||||||
|
|
||||||
~BusTimeout();
|
~BusTimeout();
|
||||||
|
|
||||||
|
@ -60,6 +60,7 @@ private:
|
||||||
|
|
||||||
GSource* _source;
|
GSource* _source;
|
||||||
GMainContext* _ctx;
|
GMainContext* _ctx;
|
||||||
|
int _priority;
|
||||||
|
|
||||||
friend class BusDispatcher;
|
friend class BusDispatcher;
|
||||||
};
|
};
|
||||||
|
@ -68,7 +69,7 @@ class DXXAPI BusWatch : public Watch
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
BusWatch( Watch::Internal*, GMainContext* );
|
BusWatch( Watch::Internal*, GMainContext*, int );
|
||||||
|
|
||||||
~BusWatch();
|
~BusWatch();
|
||||||
|
|
||||||
|
@ -84,6 +85,7 @@ private:
|
||||||
|
|
||||||
GSource* _source;
|
GSource* _source;
|
||||||
GMainContext* _ctx;
|
GMainContext* _ctx;
|
||||||
|
int _priority;
|
||||||
|
|
||||||
friend class BusDispatcher;
|
friend class BusDispatcher;
|
||||||
};
|
};
|
||||||
|
@ -91,7 +93,8 @@ friend class BusDispatcher;
|
||||||
class DXXAPI BusDispatcher : public Dispatcher
|
class DXXAPI BusDispatcher : public Dispatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BusDispatcher() : _ctx(NULL) {}
|
|
||||||
|
BusDispatcher() : _ctx(NULL), _priority(G_PRIORITY_DEFAULT) {}
|
||||||
|
|
||||||
void attach( GMainContext* );
|
void attach( GMainContext* );
|
||||||
|
|
||||||
|
@ -107,9 +110,12 @@ public:
|
||||||
|
|
||||||
void rem_watch( Watch* );
|
void rem_watch( Watch* );
|
||||||
|
|
||||||
|
void set_priority( int priority );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
GMainContext* _ctx;
|
GMainContext* _ctx;
|
||||||
|
int _priority;
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace Glib */
|
} /* namespace Glib */
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
|
|
||||||
using namespace DBus;
|
using namespace DBus;
|
||||||
|
|
||||||
Glib::BusTimeout::BusTimeout( Timeout::Internal* ti, GMainContext* ctx )
|
Glib::BusTimeout::BusTimeout( Timeout::Internal* ti, GMainContext* ctx, int priority )
|
||||||
: Timeout(ti), _ctx(ctx)
|
: Timeout(ti), _ctx(ctx), _priority(priority)
|
||||||
{
|
{
|
||||||
_enable();
|
_enable();
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,7 @@ gboolean Glib::BusTimeout::timeout_handler( gpointer data )
|
||||||
void Glib::BusTimeout::_enable()
|
void Glib::BusTimeout::_enable()
|
||||||
{
|
{
|
||||||
_source = g_timeout_source_new(Timeout::interval());
|
_source = g_timeout_source_new(Timeout::interval());
|
||||||
|
g_source_set_priority(_source, _priority);
|
||||||
g_source_set_callback(_source, timeout_handler, this, NULL);
|
g_source_set_callback(_source, timeout_handler, this, NULL);
|
||||||
g_source_attach(_source, _ctx);
|
g_source_attach(_source, _ctx);
|
||||||
}
|
}
|
||||||
|
@ -106,8 +107,8 @@ static GSourceFuncs watch_funcs = {
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
Glib::BusWatch::BusWatch( Watch::Internal* wi, GMainContext* ctx )
|
Glib::BusWatch::BusWatch( Watch::Internal* wi, GMainContext* ctx, int priority )
|
||||||
: Watch(wi), _ctx(ctx)
|
: Watch(wi), _ctx(ctx), _priority(priority)
|
||||||
{
|
{
|
||||||
_enable();
|
_enable();
|
||||||
}
|
}
|
||||||
|
@ -149,6 +150,7 @@ gboolean Glib::BusWatch::watch_handler( gpointer data )
|
||||||
void Glib::BusWatch::_enable()
|
void Glib::BusWatch::_enable()
|
||||||
{
|
{
|
||||||
_source = g_source_new(&watch_funcs, sizeof(BusSource));
|
_source = g_source_new(&watch_funcs, sizeof(BusSource));
|
||||||
|
g_source_set_priority(_source, _priority);
|
||||||
g_source_set_callback(_source, watch_handler, this, NULL);
|
g_source_set_callback(_source, watch_handler, this, NULL);
|
||||||
|
|
||||||
int flags = Watch::flags();
|
int flags = Watch::flags();
|
||||||
|
@ -186,7 +188,7 @@ void Glib::BusDispatcher::attach( GMainContext* ctx )
|
||||||
|
|
||||||
Timeout* Glib::BusDispatcher::add_timeout( Timeout::Internal* wi )
|
Timeout* Glib::BusDispatcher::add_timeout( Timeout::Internal* wi )
|
||||||
{
|
{
|
||||||
Timeout* t = new Glib::BusTimeout(wi, _ctx);
|
Timeout* t = new Glib::BusTimeout(wi, _ctx, _priority);
|
||||||
|
|
||||||
debug_log("glib: added timeout %p (%s)", t, t->enabled() ? "on":"off");
|
debug_log("glib: added timeout %p (%s)", t, t->enabled() ? "on":"off");
|
||||||
|
|
||||||
|
@ -202,7 +204,7 @@ void Glib::BusDispatcher::rem_timeout( Timeout* t )
|
||||||
|
|
||||||
Watch* Glib::BusDispatcher::add_watch( Watch::Internal* wi )
|
Watch* Glib::BusDispatcher::add_watch( Watch::Internal* wi )
|
||||||
{
|
{
|
||||||
Watch* w = new Glib::BusWatch(wi, _ctx);
|
Watch* w = new Glib::BusWatch(wi, _ctx, _priority);
|
||||||
|
|
||||||
debug_log("glib: added watch %p (%s) fd=%d flags=%d",
|
debug_log("glib: added watch %p (%s) fd=%d flags=%d",
|
||||||
w, w->enabled() ? "on":"off", w->descriptor(), w->flags()
|
w, w->enabled() ? "on":"off", w->descriptor(), w->flags()
|
||||||
|
@ -216,3 +218,8 @@ void Glib::BusDispatcher::rem_watch( Watch* w )
|
||||||
|
|
||||||
delete w;
|
delete w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Glib::BusDispatcher::set_priority(int priority)
|
||||||
|
{
|
||||||
|
_priority = priority;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue