Cannot get GetDevices ( ) method to work.

Mikkel Kamstrup Erlandsen mikkel.kamstrup at canonical.com
Thu Oct 6 00:25:05 PDT 2011


On 10/05/2011 10:38 PM, Iraq Ja wrote:
> When I run the code I get the following output:
> Line: 48 FailSegmentation fault
> Segmentation fault corresponds to line 58:
> g_printerr(" 1 %S\n", error->message);

There are quite a few issues in your code snippet Iraq - Maybe the 
number of warnings from gcc should have ticked you off? ;-)

  - As Will also mentions %S is not good, I think it means a wchar_t* 
which is a C++ism. You want %s everywhere.

  - In your error branch you can not print name_list_ptr because there 
was an error and for all you know dbus-glib can have filled it with garbage.

  - The way to initialize a GPtrArray is not with an arbitrary malloc(), 
but with g_ptr_array_new() (or some of it's alternative constructors). 
That said, you actually don't need to initialize it for this particular 
use case as I believe dbus-glib will do that for you.

  - You also need to compile against the glib-2.0 package, and include 
stdlib.h for the exit() function

  - Pass the address of name_list_ptr to the proxy call, not the pointer 
directly.

I applied these fixes to your code and attached it, but I seem to be 
hitting a bug in dbus-glib because it now prints:

   ** ERROR **: Error calling GetDevices: Unregistered object at path 
'/org/freedesktop/NetworkManager/Devices/0'

And indeed the object path '/org/freedesktop/NetworkManager/Devices/0' 
is in the results as dbus-monitor tells me, but it appears that 
dbus-glib I should have known that ahead of time and registered it or 
something ;-)

Disclaimer: The attached code is not fully fixed up, it's very much a 
rough fixup of your original snippet.

Hope it helps. Cheers,
Mikkel


> On Wed, Oct 5, 2011 at 7:10 PM, Thiago Macieira<thiago at kde.org>  wrote:
>> On Wednesday, 5 de October de 2011 18:45:52 Iraq Ja wrote:
>>> Hi,
>>>
>>> In my program attached, the method call (line 50):
>>>
>>>
>>>      if (dbus_g_proxy_call(proxy, "GetDevices",&error, G_TYPE_INVALID,
>>> DBUS_TYPE_G_OBJECT_ARRAY, name_list_ptr, G_TYPE_INVALID))
>>>      {
>>>                printf("Success\n");
>>>                g_printerr("List: %S \n", name_list_ptr);
>>>      }
>>>      else
>>>      {
>>>        printf("Fail\n");
>>>                g_printerr(" 1 %S\n", error->message);
>>>                g_printerr(" 1 %S\n", name_list_ptr);
>>>        exit(1);
>>>      }
>>>
>>> does not return true, I think I've done everything correct as far as
>>> the parameters to dbus_g_proxy_call(), and setting everything up, but
>>> for whatever reason it won't return true.
>> If it doesn't return true, it prints an error message. What was it?
>>
>> --
>> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
>>    Software Architect - Intel Open Source Technology Center
>>       PGP/GPG: 0x6EF45358; fingerprint:
>>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
>>
>> _______________________________________________
>> dbus mailing list
>> dbus at lists.freedesktop.org
>> http://lists.freedesktop.org/mailman/listinfo/dbus
>>
>>
> _______________________________________________
> dbus mailing list
> dbus at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dbus



More information about the dbus mailing list