bluetooth: move find_adapter_cb to better place.
PATCH 1/5 bluetooth: move find_adapter_cb to better place.
--- plugins/bluetooth.c | 52 +++++++++++++++++++++++++------------------------- 1 files changed, 26 insertions(+), 26 deletions(-)
plugins/bluetooth.c +26 -26
@@ -633,6 +633,32 @@ static void add_record(gpointer data, gpointer user_data) DBUS_TYPE_INVALID); } +static void find_adapter_cb (DBusPendingCall *call,gpointer user_data) +{ +DBusMessage *reply =dbus_pending_call_steal_reply (call); +DBusError derr; +const char *path; + +dbus_error_init (&derr); + +if (dbus_set_error_from_message (&derr, reply)) { +ofono_error ("Replied with an error: %s, %s" , + derr.name, derr.message); +dbus_error_free (&derr); + goto done; + } + +dbus_message_get_args (reply,NULL ,DBUS_TYPE_OBJECT_PATH , &path, +DBUS_TYPE_INVALID ); + + adapter_any_path =g_strdup (path); + +g_slist_foreach (server_list, (GFunc ) add_record,NULL ); + +done: +dbus_message_unref (reply); +} +static gboolean adapter_added (DBusConnection *connection,DBusMessage *message,void *user_data) {
@@ -724,32 +750,6 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data)g_hash_table_foreach (uuid_hash, bluetooth_remove_all_modem,NULL ); } -static void find_adapter_cb (DBusPendingCall *call,gpointer user_data) -{ -DBusMessage *reply =dbus_pending_call_steal_reply (call); -DBusError derr; -const char *path; - -dbus_error_init (&derr); - -if (dbus_set_error_from_message (&derr, reply)) { -ofono_error ("Replied with an error: %s, %s" , - derr.name, derr.message); -dbus_error_free (&derr); - goto done; - } - -dbus_message_get_args (reply,NULL ,DBUS_TYPE_OBJECT_PATH , &path, -DBUS_TYPE_INVALID ); - - adapter_any_path =g_strdup (path); - -g_slist_foreach (server_list, (GFunc ) add_record,NULL ); - -done: -dbus_message_unref (reply); -} -static guint bluetooth_watch;static guint adapter_added_watch;static guint adapter_removed_watch;
Signature · 1 line
1.7.4
PATCH 2/5 bluetooth: add a bluetoothd connect watch
This fix a issue with sending DBus messages when bluetoothd is not up yet.
--- plugins/bluetooth.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
plugins/bluetooth.c +14 -10
@@ -742,6 +742,18 @@ static void bluetooth_remove_all_modem(gpointer key, gpointer value, profile->remove_all (); } +static void bluetooth_connect (DBusConnection *connection,void *user_data) +{ +bluetooth_send_with_reply ("/" ,BLUEZ_MANAGER_INTERFACE ,"GetProperties" , + manager_properties_cb,NULL ,NULL ,-1 , +DBUS_TYPE_INVALID ); + +bluetooth_send_with_reply ("/" ,BLUEZ_MANAGER_INTERFACE ,"FindAdapter" , + find_adapter_cb,NULL ,NULL ,-1 , +DBUS_TYPE_STRING , &adapter_any_name, +DBUS_TYPE_INVALID ); +} +static void bluetooth_disconnect (DBusConnection *connection,void *user_data) {if (uuid_hash ==NULL )
@@ -763,7 +775,8 @@ static void bluetooth_ref(void) connection =ofono_dbus_get_connection (); bluetooth_watch =g_dbus_add_service_watch (connection,BLUEZ_SERVICE , -NULL , bluetooth_disconnect,NULL ,NULL ); + bluetooth_connect, + bluetooth_disconnect,NULL ,NULL ); adapter_added_watch = g_dbus_add_signal_watch(connection, NULL, NULL, BLUEZ_MANAGER_INTERFACE,
@@ -791,15 +804,6 @@ static void bluetooth_ref(void) adapter_address_hash =g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -bluetooth_send_with_reply ("/" ,BLUEZ_MANAGER_INTERFACE ,"GetProperties" , - manager_properties_cb,NULL ,NULL ,-1 , -DBUS_TYPE_INVALID ); - -bluetooth_send_with_reply ("/" ,BLUEZ_MANAGER_INTERFACE ,"FindAdapter" , - find_adapter_cb,NULL ,NULL ,-1 , -DBUS_TYPE_STRING , &adapter_any_name, -DBUS_TYPE_INVALID ); - increment:g_atomic_int_inc (&bluetooth_refcount);
Signature · 1 line
1.7.4
PATCH 3/5 bluetooth: change how we report DBus errors
--- plugins/bluetooth.c | 33 ++++++++++++++++++++------------- 1 files changed, 20 insertions(+), 13 deletions(-)
plugins/bluetooth.c +20 -13
@@ -267,19 +267,16 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data)const char *device_addr =NULL ;const char *alias =NULL ;struct bluetooth_profile *profile; +struct DBusError derr; reply =dbus_pending_call_steal_reply (call); -if (dbus_message_is_error (reply,DBUS_ERROR_SERVICE_UNKNOWN )) { -DBG ("Bluetooth daemon is apparently not available." ); - goto done; - } - -if (dbus_message_get_type (reply) ==DBUS_MESSAGE_TYPE_ERROR ) { -if (!dbus_message_is_error (reply,DBUS_ERROR_UNKNOWN_METHOD )) -ofono_info ("Error from GetProperties reply: %s" , -dbus_message_get_error_name (reply)); +dbus_error_init (&derr); +if (dbus_set_error_from_message (&derr, reply)) { +ofono_error ("Device.GetProperties replied an error: %s, %s" , + derr.name, derr.message); +dbus_error_free (&derr); goto done; }
@@ -397,14 +394,19 @@ static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) {const char *path = user_data;DBusMessage *reply; +DBusError derr;GSList *device_list =NULL ;GSList *l;const char *addr; reply =dbus_pending_call_steal_reply (call); -if (dbus_message_is_error (reply,DBUS_ERROR_SERVICE_UNKNOWN )) { -DBG ("Bluetooth daemon is apparently not available." ); +dbus_error_init (&derr); + +if (dbus_set_error_from_message (&derr, reply)) { +ofono_error ("Adapter.GetProperties replied an error: %s, %s" , + derr.name, derr.message); +dbus_error_free (&derr); goto done; }
@@ -717,11 +719,16 @@ static void parse_adapters(DBusMessageIter *array, gpointer user_data)static void manager_properties_cb (DBusPendingCall *call,gpointer user_data) {DBusMessage *reply; +DBusError derr; reply =dbus_pending_call_steal_reply (call); -if (dbus_message_is_error (reply,DBUS_ERROR_SERVICE_UNKNOWN )) { -DBG ("Bluetooth daemon is apparently not available." ); +dbus_error_init (&derr); + +if (dbus_set_error_from_message (&derr, reply)) { +ofono_error ("Manager.GetProperties() replied an error: %s, %s" , + derr.name, derr.message); +dbus_error_free (&derr); goto done; }
Signature · 1 line
1.7.4
PATCH 4/5 bluetooth: fix crash by removing record
When bluetoothd is not running we should not call RemoveRecord()
--- plugins/bluetooth.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
plugins/bluetooth.c +12 -0
@@ -445,6 +445,9 @@ static void remove_record(struct server *server) {DBusMessage *msg; +if (server->handle ==0 ) +return ; + msg =dbus_message_new_method_call (BLUEZ_SERVICE , adapter_any_path,BLUEZ_SERVICE_INTERFACE ,"RemoveRecord" );
@@ -596,6 +599,13 @@ static void new_connection(GIOChannel *io, gpointer user_data) client_event, cbd); } +static void remove_service_handle (gpointer data,gpointer user_data) +{ +struct server *server = data; + + server->handle =0 ; +} +static void add_record_cb (DBusPendingCall *call,gpointer user_data) {struct server *server = user_data;
@@ -767,6 +777,8 @@ static void bluetooth_disconnect(DBusConnection *connection, void *user_data)return ;g_hash_table_foreach (uuid_hash, bluetooth_remove_all_modem,NULL ); + +g_slist_foreach (server_list, (GFunc ) remove_service_handle,NULL ); }static guint bluetooth_watch;
Signature · 1 line
1.7.4
PATCH 5/5 bluetooth: add DBG() messages
--- plugins/bluetooth.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
plugins/bluetooth.c +4 -0
@@ -280,6 +280,8 @@ static void device_properties_cb(DBusPendingCall *call, gpointer user_data) goto done; } +DBG ("" ); + bluetooth_parse_properties(reply, "UUIDs", has_uuid, &have_uuid, "Adapter", parse_string, &adapter, "Address", parse_string, &device_addr,
@@ -410,6 +412,8 @@ static void adapter_properties_cb(DBusPendingCall *call, gpointer user_data) goto done; } +DBG ("" ); + bluetooth_parse_properties(reply, "Devices", parse_devices, &device_list, "Address", parse_string, &addr,
Signature · 1 line
1.7.4
Hi Gustavo,
Quoted 2 lines
plugins/bluetooth.c | 52 +++++++++++++++++++++++++------------------------- 1 files changed, 26 insertions(+), 26 deletions(-)
patch has been applied.
Regards
Marcel
Re: [PATCH 2/5] bluetooth: add a bluetoothd connect watch
In reply to Gustavo F. PadovanHi Gustavo,
Quoted 4 lines
This fix a issue with sending DBus messages when bluetoothd is not up yet.
--- plugins/bluetooth.c | 24 ++++++++++++++---------- 1 files changed, 14 insertions(+), 10 deletions(-)
patch has been applied.
Regards
Marcel
Re: [PATCH 3/5] bluetooth: change how we report DBus errors
In reply to Gustavo F. PadovanHi Gustavo,
Quoted 2 lines
plugins/bluetooth.c | 33 ++++++++++++++++++++------------- 1 files changed, 20 insertions(+), 13 deletions(-)
patch has been applied.
Regards
Marcel
Re: [PATCH 4/5] bluetooth: fix crash by removing record
In reply to Gustavo F. PadovanHi Gustavo,
Quoted 4 lines
When bluetoothd is not running we should not call
RemoveRecord()--- plugins/bluetooth.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-)
patch has been applied.
Regards
Marcel
Re: [PATCH 5/5] bluetooth: add DBG() messages
In reply to Gustavo F. PadovanHi Gustavo,
Quoted 2 lines
plugins/bluetooth.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
patch has been applied.
Regards
Marcel