dbus-glib - passing structs as arguments
Steve Kreyer
steve.kreyer at web.de
Tue Apr 21 14:17:51 PDT 2009
Hi Stanislav,
the function I suggested was only a place holder for the generated
wrapper function of the dbus-binding-tool. You need to generate a header
file for your application out of the XML interface specification. An
example can look like the following:
<?xml version="1.0" encoding="UTF-8" ?>
<node name="/org/dbus/example">
<interface name="org.dbus.example.Foo">
<annotation name="org.freedesktop.DBus.GLib.CSymbol"
value="foo_bar" />
<method name="bar">
<arg type="(ss)" name="bar" direction="in" />
</method>
</interface>
</node>
So if you take this interface specification and use it as input for the
following command:
dbus-binding-tool --mode=glib-client --prefix= cliebt.xml > client.h
you will end up in a file called client.h which you have to include and
which consists of necessary helper functions:
gboolean
org_dbus_example_Foo_bar (DBusGProxy *proxy, const GValueArray*
IN_param, GError **error); /* use for synchronous calls */
and
DBusGProxyCall*
org_dbus_example_Foo_bar_async (DBusGProxy *proxy, const GValueArray*
IN_param, org_dbus_example_Foo_bar_reply callback, gpointer userdata) /*
use for asynchronous calls */
This step is also document in the tutorial:
http://dbus.freedesktop.org/doc/dbus-tutorial.html#glib-generated-bindings
Kind Regards,
Steve
Stanislav Popov wrote:
> Hi Steve,
> Thanks for you reply!
>
> I see that dbus-glib includes dbus-glib-binding tool.
> I was not able to find this function
> dbus_binding_tool_generated_method() ?
>
> Where can I find it?
> Which header files should I include in my application?
>
> Thanks and Regards,
> Stanislav
>
> Steve Kreyer wrote:
>> Hi,
>>
>> to my knowledge structs are represented by the dbus-glib-binding via the
>> type GValueArray.
>>
>> Why using dbus_g_proxy_call directly? Theres a little tool which
>> generates you dbus_g_proxy_call invocations in the right way. It is
>> called dbus-binding-tool. You feed it with your XML interface
>> specification and it generates for you easy-to-use wrapper functions
>> around dbus_g_proxy_call for synchronous and asynchronous method calls.
>>
>> All you have to do is to allocate the GValueArray and pass it to the
>> generated function in your application:
>>
>> GError *error = NULL;
>> GValueArray *dbus_struct;
>> GValue dbus_struct_member = {0};
>>
>> dbus_struct = g_value_array_new(0);
>>
>> g_value_init (&dbus_struct_member, G_TYPE_STRING);
>>
>> g_value_set_string (&dbus_struct_member, "value of first member");
>> g_value_array_append (dbus_struct, &dbus_struct_member);
>>
>> g_value_set_string (&dbus_struct_member, "value of second member");
>> g_value_array_append (dbus_struct, &dbus_struct_member);
>>
>> dbus_binding_tool_generated_method (proxy, dbus_struct, &error);
>>
>> HTH,
>> Steve
>>
>> Stanislav Popov wrote:
>>
>>> Hi all,
>>> I read D-Bus Tutorial and many other documents!
>>>
>>> I have only one problem.
>>> I am using dbus-glib and I am trying to invoke a method with parameters.
>>> I would like to pass structures to dbus_g_proxy_call() function.
>>> For example I have (ss) type.
>>>
>>> I tried |DBUS_TYPE_STRUCT which is mentioned in |D-Bus Tutorial| but it
>>> seems it is not working with GLIB.
>>> I got:
>>> |
>>>
>>> 1.
>>> (process:835): GLib-GObject-WARNING **: gtype.c:3312: type id
>>> `115' is invalid
>>> 2.
>>>
>>> 3.
>>> (process:835): GLib-GObject-WARNING **: can't peek value table for
>>> type `<unknown>' which is not currently referenced
>>> 4.
>>> Segmentation fault
>>>
>>>
>>> So I did the following:
>>>
>>> #define G_STRUCT_STR_STR (dbus_g_type_get_struct("GValueArray",
>>> G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID))
>>>
>>> GValue *value;
>>>
>>> value = g_new0 (GValue, 1);
>>> g_value_init (value, G_STRUCT_STR_STR);
>>> g_value_take_boxed (value, dbus_g_type_specialized_construct
>>> (G_STRUCT_STR_STR));
>>>
>>> dbus_g_type_struct_set (value, 0, "192.168.0.1", 1, "1234", G_MAXUINT);
>>> .....
>>>
>>> dbus_g_proxy_call (proxy, "SetInfo", &error, G_STRUCT_STR_STR, value,
>>> G_TYPE_INVALID, G_TYPE_INVALID))
>>>
>>> ------
>>> but I got Segmentation Fault on dbus_g_proxy_call().
>>>
>>> Where am I wrong?
>>>
>>> Can you help me, please?
>>>
>>> Thanks in advance,
>>> Stanislav
>>> _______________________________________________
>>> dbus mailing list
>>> dbus at lists.freedesktop.org
>>> http://lists.freedesktop.org/mailman/listinfo/dbus
>>>
>>>
>>>
>>
>>
>
More information about the dbus
mailing list