Hi all

I want to accomplish the following tasks using the Dbus interface.

  1. I am using the two bluetooth adapters
    the first adapter is searching for the near by devices.

  2. The second adapter is used to find out the SDP records of the discoverd devices.


Here In my code I am using theDBusGProxy HCI0 object to search for the near by bluetooth devices, secondly HCI1 object is used to extract the channel number of the discoverd devices.

In summary
first adapter (HCI0) is continuously searching for the near by devices.
And second adapter (HCI1)is used to find out the Records of the discovered devices.
In my code it discovers the near by devices ,gives there channel number but crashes.

Here I am attaching the relevant and minimal code.
I  want to know whether is this the right way to proceed or there exists any other alternative.

{

GError *error = NULL;

/*function to extract the channel*/

int channel = get_remote_service_channel ( object,address,"OPP" );

g_print ("Channel returned is %d\n",channel);

}

static void discovery_started(DBusGProxy *object, gpointer user_data)

{

g_print("Signal: DiscoveryStarted()\n");

}

/* Function Defination  for extracting the channel */

gint

get_remote_service_channel (DBusGProxy *obj, const gchar *address, const gchar *uuid)

{

GError *error = NULL;

GArray *handle_array = NULL;

GArray *record_array = NULL;

sdp_record_t *sdp_record = NULL;

gint scanned;

sdp_list_t *protos = NULL;

gint channel = -1;

g_print ("hi i am here\n");

/* find services that match our UUID */

DBusGConnection * bus = NULL;

bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);

/*another HCI1 adapter used to extract the SDP Records*/

DBusGProxy* obj1 = dbus_g_proxy_new_for_name(bus, "org.bluez", "/org/bluez/hci1", "org.bluez.Adapter");

if (!dbus_g_proxy_call (obj1,

"GetRemoteServiceHandles", &error,

G_TYPE_STRING, address,

G_TYPE_STRING, uuid,

G_TYPE_INVALID,

DBUS_TYPE_G_UINT_ARRAY, &handle_array,

G_TYPE_INVALID)) {

g_warning (error->message);

g_error_free (error);

goto out;

}

if (!handle_array) {

goto out;

}

/* get service record for the first service handle */

if (!handle_array->data)

goto out;


if (!dbus_g_proxy_call (obj1,

"GetRemoteServiceRecord", &error, G_TYPE_STRING, address,

G_TYPE_UINT, *((guint32 *)handle_array->data), G_TYPE_INVALID,

DBUS_TYPE_G_UINT_ARRAY, &record_array, G_TYPE_INVALID)) {

g_warning (error->message);

g_error_free (error);

goto out;

}



Any help is appreciated.

Regards,

Rohit