DBusG Properties HowTo?

Dan Saul daniel.saul at gmail.com
Fri Mar 26 18:39:59 PDT 2010


Thank you Colin, that makes sense -- and it all works now!

The following is not for you, but for those who are looking through the
mailing list archives for this in the future.

An example on how to do what Colin describes:

#ifndef G_VALUE_INIT
#define G_VALUE_INIT {0,{{0}}}
#endif

private gboolean query_pid_for_dbus_support_and_aid(self,const GPid
pid,gchar** OUT_new_aid, DBusGProxy** OUT_new_proxy_main, DBusGProxy**
OUT_new_proxy_prop)
{
gboolean ret = FALSE;
char* bus_name = NULL;
DBusGProxy* proxy_main = NULL;
DBusGProxy* proxy_prop = NULL;
GError* error = NULL;
GValue value = G_VALUE_INIT;
do
{
bus_name = g_strdup_printf("org.ude.application.pid_%d",pid);
proxy_main =
dbus_g_proxy_new_for_name_owner(selfp->dbus,bus_name,"/org/ude/application","org.ude.application",&error);
 if (NULL == proxy_main) {
ret = FALSE;
break;
}
 proxy_prop =
dbus_g_proxy_new_for_name_owner(selfp->dbus,bus_name,"/org/ude/application","org.freedesktop.DBus.Properties",&error);
if (NULL == proxy_prop) {
ret = FALSE;
g_print("!%s() could not get org.freedesktop.DBus.Properties proxy for pid
%d error:%s\n",__GOB_FUNCTION__,pid,error->message);
break;
}
 if (dbus_g_proxy_call(proxy_prop,
  "Get",
  &error,
  G_TYPE_STRING,
  "org.ude.application",
  G_TYPE_STRING,
  "ApplicationIdentifier",
  G_TYPE_INVALID,
  G_TYPE_VALUE,
  &value,
  G_TYPE_INVALID
  ))
{
// success
ret = TRUE;
 if (NULL != OUT_new_aid) {
*OUT_new_aid = g_value_dup_string(&value);
}
if (NULL != OUT_new_proxy_main) {
*OUT_new_proxy_main = g_object_ref(proxy_main);
}
if (NULL != OUT_new_proxy_prop) {
*OUT_new_proxy_prop = g_object_ref(proxy_prop);
}
}
else
{
ret = FALSE;
g_warning("%s() unable to call get on ApplicationIdentifier ABORTing
update!",__GOB_FUNCTION__);
break;
}
 }
while (0);
if (G_IS_VALUE(&value)) { g_value_unset (&value); }
if (NULL != bus_name) { g_free(bus_name); bus_name = NULL; }
if (NULL != proxy_main) { g_object_unref(proxy_main); proxy_main = NULL; }
if (NULL != proxy_prop) { g_object_unref(proxy_prop); proxy_prop = NULL; }
if (NULL != error) { g_error_free(error); error = NULL; }
return ret;
}

On Fri, Mar 26, 2010 at 8:19 AM, Colin Walters <walters at verbum.org> wrote:

> Hi,
>
> On Fri, Mar 26, 2010 at 1:22 AM, Dan Saul <daniel.saul at gmail.com> wrote:
> > Hi all,
> > Newbie question here. Using DbusG, how do I fetch a property?
>
> There's no shortcut or "sugar" for this in dbus-glib currently; you
> need to create a proxy for org.freedesktop.DBus.Properties like you
> would for any other interface , and call the "Get" method manually.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/dbus/attachments/20100326/76c848db/attachment.html>


More information about the dbus mailing list