dbus-glib - passing structs as arguments

Stanislav Popov s.popov at rsc.bg
Tue Apr 21 02:24:00 PDT 2009


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
>>
>>   
>>     
>
>   

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freedesktop.org/archives/dbus/attachments/20090421/6be5dd4d/attachment.html 


More information about the dbus mailing list