struct btd_service in core
Subsystems (2)
cover struct btd_service in core
From: Mikel Astiz <[email protected]>
This RFC proposes a somewhat intrusive change in the core with the adoption of struct btd_service, with the following main goals:
1. Support for multiple instances of the same UUID.
2. Better support for connection-handling plugins/components (e.g. automotive).
3. Exposure of remote services in D-Bus (not implemented here).
4. Improve code readability and reduce profile-implementation code size.
There's a lot of changes and many points open for discussion, so before working further (splitting, testing) I'd like to have some upstream feedback.
As a suggestion for a first review, I'd say the most relevant patches are 01/11, 06/11 and 11/11.
Cheers,
Mikel
Mikel Astiz (11):
core: Add btd_service to represent device services
device: Use btd_service to represent profiles
device: Replace connected_profiles with btd_service
device: Find services instead of profiles
device: Replace pending profile list with services
profile: Use btd_service for probing profiles
audio: Hold a reference to btd_service
network: Hold a reference to btd_service
input: Hold a reference to btd_service
service: Add callbacks to track state changes
profile: Use btd_service for connect/disconnect
Makefile.am | 1 + Makefile.plugins | 4 +- profiles/audio/control.c | 52 ++++++-- profiles/audio/control.h | 7 +- profiles/audio/manager.c | 80 ++++------- profiles/audio/manager.h | 7 - profiles/audio/sink.c | 24 ++-- profiles/audio/sink.h | 4 +- profiles/audio/source.c | 25 ++-- profiles/audio/source.h | 5 +- profiles/cyclingspeed/cyclingspeed.c | 9 +- profiles/deviceinfo/deviceinfo.c | 11 +- profiles/gatt/gas.c | 10 +- profiles/health/hdp_manager.c | 10 +- profiles/heartrate/heartrate.c | 10 +- profiles/input/device.c | 95 +++++++------ profiles/input/device.h | 13 +- profiles/input/hog.c | 8 +- profiles/input/manager.c | 51 +------ profiles/input/manager.h | 25 ---- profiles/network/connection.c | 77 +++++------ profiles/network/connection.h | 8 +- profiles/network/manager.c | 123 ++--------------- profiles/network/manager.h | 25 ---- profiles/proximity/manager.c | 28 ++-- profiles/proximity/reporter.c | 8 +- profiles/proximity/reporter.h | 5 +- profiles/sap/manager.c | 1 + profiles/scanparam/scan.c | 9 +- profiles/thermometer/thermometer.c | 11 +- src/device.c | 230 +++++++++++++++++++++----------- src/device.h | 5 - src/profile.c | 40 +++--- src/profile.h | 14 +- src/service.c | 250 +++++++++++++++++++++++++++++++++++ src/service.h | 61 +++++++++ 36 files changed, 793 insertions(+), 553 deletions(-) delete mode 100644 profiles/input/manager.h delete mode 100644 profiles/network/manager.h create mode 100644 src/service.c create mode 100644 src/service.h
Signature · 1 line
1.8.1.4
RFC 1/11 core: Add btd_service to represent device services
From: Mikel Astiz <[email protected]>
Add object to centralize all data corresponding to a service provided by a remote device as well as the possible states for such a service.
--- Makefile.am | 1 + src/service.c | 202 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/service.h | 53 +++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 src/service.c create mode 100644 src/service.h
Makefile.am +1 -0
@@ -142,6 +142,7 @@ src_bluetoothd_SOURCES = $(gdbus_sources) $(builtin_sources) \ src/error.h src/error.c \ src/adapter.h src/adapter.c \ src/profile.h src/profile.c \ + src/service.h src/service.c \ src/device.h src/device.c src/attio.h \ src/dbus-common.c src/dbus-common.h \ src/eir.h src/eir.c \
src/service.c new file +202 -0
202 lines not on this page · raw message
src/service.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.8.1.4
RFC 2/11 device: Use btd_service to represent profiles
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Maintain a list of btd_service pointers instead of btd_profile pointers, for services that have been probed for this device.
This list will reference count the btd_service instances.
--- src/device.c | 76 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 53 insertions(+), 23 deletions(-)
src/device.c +53 -23
@@ -56,6 +56,7 @@#include "attio.h" #include "device.h" #include "profile.h" +#include "service.h" #include "dbus-common.h" #include "error.h" #include "glib-helper.h"
@@ -167,7 +168,7 @@ struct btd_device {struct btd_adapter *adapter;GSList *uuids;GSList *primaries;/* List of primary services */ -GSList *profiles;/* Probed profiles */ +GSList *services;/* List of btd_service */ GSList *pending;/* Pending profiles */ GSList *watches;/* List of disconnect_data */ gboolean temporary;
@@ -217,6 +218,17 @@ static int device_browse_primary(struct btd_device *device, DBusMessage *msg,static int device_browse_sdp (struct btd_device *device,DBusMessage *msg,gboolean reverse); +static gint service_profile_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a; +struct btd_profile *profile = (gpointer ) b; + +if (service_get_profile (service) == profile) +return 0 ; +else +return 1 ; +} +static gboolean store_device_info_cb (gpointer user_data) {struct btd_device *device = user_data;
@@ -870,12 +882,14 @@ static gboolean dev_property_get_adapter(const GDBusPropertyTable *property,return TRUE; } -static void profile_remove (gpointer data,gpointer user_data) +static void service_remove (struct btd_service *service) { -struct btd_profile *profile = data; -struct btd_device *device = user_data; +struct btd_profile *profile =service_get_profile (service); +struct btd_device *device =service_get_device (service); +service_unavailable (service); profile->device_remove (profile, device); +btd_service_unref (service); }static gboolean do_disconnect (gpointer user_data)
@@ -900,9 +914,8 @@ int device_block(struct btd_device *device, gboolean update_only)if (device->connected)do_disconnect (device); -g_slist_foreach (device->profiles, profile_remove, device); -g_slist_free (device->profiles); - device->profiles =NULL ; +g_slist_free_full (device->services, (GDestroyNotify ) service_remove); + device->services =NULL ;if (!update_only) err = btd_adapter_block_address(device->adapter,
@@ -1156,8 +1169,9 @@ static struct btd_profile *find_connectable_profile(struct btd_device *dev, {GSList *l; -for (l = dev->profiles; l !=NULL ; l =g_slist_next (l)) { -struct btd_profile *p = l->data; +for (l = dev->services; l !=NULL ; l =g_slist_next (l)) { +struct btd_service *service = l->data; +struct btd_profile *p =service_get_profile (service);if (!p->connect || !p->remote_uuid)continue ;
@@ -1179,6 +1193,7 @@ static gint profile_prio_cmp(gconstpointer a, gconstpointer b)static DBusMessage *connect_profiles (struct btd_device *dev,DBusMessage *msg,const char *uuid) { +struct btd_service *service;struct btd_profile *p;GSList *l;int err;
@@ -1208,8 +1223,9 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg, goto start_connect; } -for (l = dev->profiles; l !=NULL ; l =g_slist_next (l)) { - p = l->data; +for (l = dev->services; l !=NULL ; l =g_slist_next (l)) { + service = l->data; + p =service_get_profile (service);if (!p->auto_connect)continue ;
@@ -2245,9 +2261,8 @@ void device_remove(struct btd_device *device, gboolean remove_stored)if (remove_stored)device_remove_stored (device); -g_slist_foreach (device->profiles, profile_remove, device); -g_slist_free (device->profiles); - device->profiles =NULL ; +g_slist_free_full (device->services, (GDestroyNotify ) service_remove); + device->services =NULL ;btd_device_unref (device); }
@@ -2323,6 +2338,7 @@ static void dev_probe(struct btd_profile *p, void *user_data) {struct probe_data *d = user_data;GSList *probe_uuids; +struct btd_service *service;int err;if (p->device_probe ==NULL )
@@ -2333,14 +2349,18 @@ static void dev_probe(struct btd_profile *p, void *user_data) probe_uuids =g_slist_append (NULL , (char *) p->remote_uuid); + service =service_create (d->dev, p); + err = p->device_probe (p, d->dev, probe_uuids);if (err <0 ) {error ("%s profile probe failed for %s" , p->name, d->addr); +btd_service_unref (service);g_slist_free (probe_uuids);return ; } - d->dev->profiles =g_slist_append (d->dev->profiles, p); +service_probed (service); + d->dev->services =g_slist_append (d->dev->services, service);g_slist_free (probe_uuids); }
@@ -2348,6 +2368,7 @@ void device_probe_profile(gpointer a, gpointer b) {struct btd_device *device = a;struct btd_profile *profile = b; +struct btd_service *service;GSList *probe_uuids;char addr[18 ];int err;
@@ -2362,14 +2383,18 @@ void device_probe_profile(gpointer a, gpointer b)ba2str (&device->bdaddr, addr); + service =service_create (device, profile); + err = profile->device_probe (profile, device, probe_uuids);if (err <0 ) {error ("%s profile probe failed for %s" , profile->name, addr); +btd_service_unref (service);g_slist_free (probe_uuids);return ; } - device->profiles =g_slist_append (device->profiles, profile); +service_probed (service); + device->services =g_slist_append (device->services, service);g_slist_free (probe_uuids);if (!profile->auto_connect || !device->general_connect)
@@ -2385,15 +2410,19 @@ void device_remove_profile(gpointer a, gpointer b) {struct btd_device *device = a;struct btd_profile *profile = b; +struct btd_service *service; +GSList *l; -if (!g_slist_find (device->profiles, profile)) + l =g_slist_find_custom (device->services, profile, service_profile_cmp); +if (l ==NULL )return ; device->connected_profiles =g_slist_remove (device->connected_profiles, profile); - device->profiles =g_slist_remove (device->profiles, profile); - profile->device_remove (profile, device); + service = l->data; + device->services =g_slist_delete_link (device->services, l); +service_remove (service); }void device_probe_profiles (struct btd_device *device,GSList *uuids)
@@ -2442,15 +2471,16 @@ static void device_remove_profiles(struct btd_device *device, GSList *uuids) device->uuids =NULL ;store_device_info (device); -for (l = device->profiles; l !=NULL ; l = next) { -struct btd_profile *profile = l->data; +for (l = device->services; l !=NULL ; l = next) { +struct btd_service *service = l->data; +struct btd_profile *profile =service_get_profile (service); next = l->next;if (device_match_profile (device, profile, device->uuids))continue ; - profile->device_remove (profile, device); - device->profiles =g_slist_remove (device->profiles, profile); + device->services =g_slist_delete_link (device->services, l); +service_remove (service); } }
Signature · 1 line
1.8.1.4
RFC 3/11 device: Replace connected_profiles with btd_service
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
The service state can provide enough information not to maintain such a connected_profiles list. Therefore, avoid duplicated information and remove the list.
--- src/device.c | 82 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 25 deletions(-)
src/device.c +57 -25
@@ -186,7 +186,6 @@ struct btd_device {guint attachid;/* Attrib server attach */ gboolean connected; -GSList *connected_profiles;sdp_list_t *tmp_records;
@@ -229,6 +228,17 @@ static gint service_profile_cmp(gconstpointer a, gconstpointer b)return 1 ; } +static gint service_state_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a; +service_state_t state = (service_state_t )GPOINTER_TO_INT (b); + +if (service_get_state (service) == state) +return 0 ; +else +return 1 ; +} +static gboolean store_device_info_cb (gpointer user_data) {struct btd_device *device = user_data;
@@ -981,15 +991,24 @@ static void bonding_request_cancel(struct bonding_req *bonding)adapter_cancel_bonding (adapter, &device->bdaddr, device->bdaddr_type); } -static void dev_disconn_profile (gpointer a,gpointer b) +static void dev_disconn_service (gpointer a,gpointer b) { -struct btd_profile *profile = a; -struct btd_device *dev = b; +struct btd_service *service = a; +struct btd_profile *profile =service_get_profile (service); +struct btd_device *dev =service_get_device (service); +service_state_t state =service_get_state (service);if (!profile->disconnect)return ; - profile->disconnect (dev, profile); +if (state !=SERVICE_STATE_CONNECTING && + state !=SERVICE_STATE_CONNECTED ) +return ; + +if (profile->disconnect (dev, profile) !=0 ) +return ; + +service_disconnecting (service); }void device_request_disconnect (struct btd_device *device,DBusMessage *msg)
@@ -1015,10 +1034,7 @@ void device_request_disconnect(struct btd_device *device, DBusMessage *msg)if (device->disconn_timer)return ; -g_slist_foreach (device->connected_profiles, dev_disconn_profile, - device); -g_slist_free (device->connected_profiles); - device->connected_profiles =NULL ; +g_slist_foreach (device->services, dev_disconn_service,NULL );g_slist_free (device->pending); device->pending =NULL ;
@@ -1074,8 +1090,16 @@ static int connect_next(struct btd_device *dev) profile = dev->pending->data; err = profile->connect (dev, profile); -if (err ==0 ) +if (err ==0 ) { +GSList *l; + + l =g_slist_find_custom (dev->services, profile, + service_profile_cmp); +if (l !=NULL ) +service_connecting (l->data); +return 0 ; + }error ("Failed to connect %s: %s" , profile->name,strerror (-err));
@@ -1089,6 +1113,7 @@ void device_profile_connected(struct btd_device *dev, struct btd_profile *profile, int err) {struct btd_profile *pending; +GSList *l;DBG ("%s %s (%d)" , profile->name,strerror (-err), -err);
@@ -1098,10 +1123,9 @@ void device_profile_connected(struct btd_device *dev, pending = dev->pending->data; dev->pending =g_slist_remove (dev->pending, profile); -if (!err) - dev->connected_profiles = -g_slist_append (dev->connected_profiles, - profile); + l =g_slist_find_custom (dev->services, profile, service_profile_cmp); +if (l !=NULL ) +service_connecting_complete (l->data, err);/* Only continue connecting the next profile if it matches the first * pending, otherwise it will trigger another connect to the same
@@ -1122,7 +1146,11 @@ void device_profile_connected(struct btd_device *dev,DBG ("returning response to %s" ,dbus_message_get_sender (dev->connect)); -if (err && dev->connected_profiles ==NULL ) + l =g_slist_find_custom (dev->services, +GINT_TO_POINTER (SERVICE_STATE_CONNECTED ), + service_state_cmp); + +if (err && l ==NULL )g_dbus_send_message (dbus_conn,btd_error_failed (dev->connect,strerror (-err)));else
@@ -1233,7 +1261,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,if (g_slist_find (dev->pending, p))continue ; -if (g_slist_find (dev->connected_profiles, p)) +if (service_get_state (service) !=SERVICE_STATE_DISCONNECTED )continue ; dev->pending = g_slist_insert_sorted(dev->pending, p,
@@ -1302,8 +1330,11 @@ static DBusMessage *connect_profile(DBusConnection *conn, DBusMessage *msg,void device_profile_disconnected (struct btd_device *dev,struct btd_profile *profile,int err) { - dev->connected_profiles =g_slist_remove (dev->connected_profiles, - profile); +GSList *l; + + l =g_slist_find_custom (dev->services, profile, service_profile_cmp); +if (l !=NULL ) +service_disconnecting_complete (l->data, err);if (!dev->disconnect)return ;
@@ -1324,10 +1355,12 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg, void *user_data) {struct btd_device *dev = user_data; +struct btd_service *service;struct btd_profile *p;const char *pattern;char *uuid;int err; +GSList *l;if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &pattern,DBUS_TYPE_INVALID ))
@@ -1343,6 +1376,9 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,if (!p)return btd_error_invalid_args (msg); + l =g_slist_find_custom (dev->services, p, service_profile_cmp); + service = l->data; +if (!p->disconnect)return btd_error_not_supported (msg);
@@ -1350,6 +1386,8 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,if (err <0 )return btd_error_failed (msg,strerror (-err)); +service_disconnecting (service); + dev->disconnect =dbus_message_ref (msg);return NULL ;
@@ -2239,10 +2277,7 @@ void device_remove(struct btd_device *device, gboolean remove_stored)if (device->browse)browse_request_cancel (device->browse); -g_slist_foreach (device->connected_profiles, dev_disconn_profile, - device); -g_slist_free (device->connected_profiles); - device->connected_profiles =NULL ; +g_slist_foreach (device->services, dev_disconn_service,NULL );g_slist_free (device->pending); device->pending =NULL ;
@@ -2417,9 +2452,6 @@ void device_remove_profile(gpointer a, gpointer b)if (l ==NULL )return ; - device->connected_profiles =g_slist_remove (device->connected_profiles, - profile); - service = l->data; device->services =g_slist_delete_link (device->services, l);service_remove (service);
Signature · 1 line
1.8.1.4
RFC 4/11 device: Find services instead of profiles
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Trivially replace the former find_connectable_profile() with find_connectable_service().
--- src/device.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-)
src/device.c +8 -9
@@ -1192,7 +1192,7 @@ static int device_resolve_svc(struct btd_device *dev, DBusMessage *msg)return device_browse_primary (dev, msg, FALSE); } -static struct btd_profile *find_connectable_profile (struct btd_device *dev, +static struct btd_service *find_connectable_service (struct btd_device *dev,const char *uuid) {GSList *l;
@@ -1205,7 +1205,7 @@ static struct btd_profile *find_connectable_profile(struct btd_device *dev,continue ;if (strcasecmp (uuid, p->remote_uuid) ==0 ) -return p; +return service; }return NULL ;
@@ -1242,10 +1242,11 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg, }if (uuid) { - p =find_connectable_profile (dev, uuid); -if (!p) + service =find_connectable_service (dev, uuid); +if (!service)return btd_error_invalid_args (msg); + p =service_get_profile (service); dev->pending =g_slist_prepend (dev->pending, p); goto start_connect;
@@ -1360,7 +1361,6 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,const char *pattern;char *uuid;int err; -GSList *l;if (!dbus_message_get_args (msg,NULL ,DBUS_TYPE_STRING , &pattern,DBUS_TYPE_INVALID ))
@@ -1370,14 +1370,13 @@ static DBusMessage *disconnect_profile(DBusConnection *conn, DBusMessage *msg,if (uuid ==NULL )return btd_error_invalid_args (msg); - p =find_connectable_profile (dev, uuid); + service =find_connectable_service (dev, uuid);g_free (uuid); -if (!p) +if (!service)return btd_error_invalid_args (msg); - l =g_slist_find_custom (dev->services, p, service_profile_cmp); - service = l->data; + p =service_get_profile (service);if (!p->disconnect)return btd_error_not_supported (msg);
Signature · 1 line
1.8.1.4
RFC 5/11 device: Replace pending profile list with services
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Use btd_service pointers to represent the list of services pending for connection.
This list doesn't reference count the btd_service instances, since the pending services should be a subset of the available services, and thus they should already be referenced by device->services. This means special care must be taken to make sure any removed service is also removed from the pending list, as addressed in service_remove().
--- src/device.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-)
src/device.c +27 -19
@@ -169,7 +169,7 @@ struct btd_device {GSList *uuids;GSList *primaries;/* List of primary services */ GSList *services;/* List of btd_service */ -GSList *pending;/* Pending profiles */ +GSList *pending;/* Pending services */ GSList *watches;/* List of disconnect_data */ gboolean temporary;guint disconn_timer;
@@ -899,6 +899,7 @@ static void service_remove(struct btd_service *service)service_unavailable (service); profile->device_remove (profile, device); + device->pending =g_slist_remove (device->pending, service);btd_service_unref (service); }
@@ -1081,29 +1082,32 @@ static DBusMessage *disconnect(DBusConnection *conn, DBusMessage *msg,static int connect_next (struct btd_device *dev) { +struct btd_service *service;struct btd_profile *profile;int err = -ENOENT ;while (dev->pending) {int err; - profile = dev->pending->data; + service = dev->pending->data; + profile =service_get_profile (service); + +if (service_get_state (service) !=SERVICE_STATE_DISCONNECTED ) { + dev->pending =g_slist_delete_link (dev->pending, + dev->pending); +continue ; + } err = profile->connect (dev, profile);if (err ==0 ) { -GSList *l; - - l =g_slist_find_custom (dev->services, profile, - service_profile_cmp); -if (l !=NULL ) -service_connecting (l->data); - +service_connecting (service);return 0 ; }error ("Failed to connect %s: %s" , profile->name,strerror (-err)); - dev->pending =g_slist_remove (dev->pending, profile); + + dev->pending =g_slist_delete_link (dev->pending, dev->pending); }return err;
@@ -1121,7 +1125,9 @@ void device_profile_connected(struct btd_device *dev,return ; pending = dev->pending->data; - dev->pending =g_slist_remove (dev->pending, profile); + l =g_slist_find_custom (dev->pending, profile, service_profile_cmp); +if (l !=NULL ) + dev->pending =g_slist_delete_link (dev->pending, l); l =g_slist_find_custom (dev->services, profile, service_profile_cmp);if (l !=NULL )
@@ -1211,9 +1217,12 @@ static struct btd_service *find_connectable_service(struct btd_device *dev,return NULL ; } -static gint profile_prio_cmp (gconstpointer a,gconstpointer b) +static gint service_prio_cmp (gconstpointer a,gconstpointer b) { -const struct btd_profile *p1 = a, *p2 = b; +struct btd_service *s1 = (gpointer ) a; +struct btd_service *s2 = (gpointer ) b; +struct btd_profile *p1 =service_get_profile (s1); +struct btd_profile *p2 =service_get_profile (s2);return p2->priority - p1->priority; }
@@ -1246,8 +1255,7 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,if (!service)return btd_error_invalid_args (msg); - p =service_get_profile (service); - dev->pending =g_slist_prepend (dev->pending, p); + dev->pending =g_slist_prepend (dev->pending, service); goto start_connect; }
@@ -1259,14 +1267,14 @@ static DBusMessage *connect_profiles(struct btd_device *dev, DBusMessage *msg,if (!p->auto_connect)continue ; -if (g_slist_find (dev->pending, p)) +if (g_slist_find (dev->pending, service))continue ;if (service_get_state (service) !=SERVICE_STATE_DISCONNECTED )continue ; - dev->pending =g_slist_insert_sorted (dev->pending, p, - profile_prio_cmp); + dev->pending =g_slist_insert_sorted (dev->pending, service, + service_prio_cmp); }if (!dev->pending)
@@ -2434,7 +2442,7 @@ void device_probe_profile(gpointer a, gpointer b)if (!profile->auto_connect || !device->general_connect)return ; - device->pending =g_slist_append (device->pending, profile); + device->pending =g_slist_append (device->pending, service);if (g_slist_length (device->pending) ==1 )connect_next (device);
Signature · 1 line
1.8.1.4
RFC 6/11 profile: Use btd_service for probing profiles
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Change the profile probe mechanism in order to pass the btd_service instance representing the remote service. This object is bound to a btd_profile and a btd_device, thus replacing the previous parameters.
The probe callback is allowed to hold a reference to the btd_service by means of btd_service_ref(), which should be unreferenced during removal. In addition, the probe callback is allowed to set the user_data pointer associated to the btd_service by using service_set_user_data().
Keeping such a reference of the btd_service allows supporting multiple instances of the same UUID, since the reference can serve as a handle during the interactions between the profile implementation and the core.
--- profiles/audio/control.c | 8 ++++---- profiles/audio/control.h | 4 ++-- profiles/audio/manager.c | 21 ++++++++++++--------- profiles/cyclingspeed/cyclingspeed.c | 9 +++++---- profiles/deviceinfo/deviceinfo.c | 11 ++++++----- profiles/gatt/gas.c | 10 ++++++---- profiles/health/hdp_manager.c | 10 +++++++--- profiles/heartrate/heartrate.c | 10 ++++++---- profiles/input/hog.c | 8 +++++--- profiles/input/manager.c | 11 +++++++---- profiles/network/manager.c | 20 +++++++++++++------- profiles/proximity/manager.c | 28 ++++++++++++++++------------ profiles/proximity/reporter.c | 8 +++++--- profiles/proximity/reporter.h | 5 ++--- profiles/sap/manager.c | 1 + profiles/scanparam/scan.c | 9 ++++++--- profiles/thermometer/thermometer.c | 11 ++++++----- src/device.c | 11 +++-------- src/profile.c | 11 +++++++---- src/profile.h | 8 ++++---- 20 files changed, 123 insertions(+), 91 deletions(-)
profiles/audio/control.c +4 -4
@@ -262,13 +262,13 @@ void control_unregister(struct audio_device *dev) AUDIO_CONTROL_INTERFACE); } -void control_update (struct control *control,GSList *uuids) +void control_update (struct control *control,const char *uuid) { -if (g_slist_find_custom (uuids,AVRCP_TARGET_UUID , bt_uuid_strcmp)) +if (bt_uuid_strcmp (uuid,AVRCP_TARGET_UUID ) ==0 ) control->target = TRUE; } -struct control *control_init (struct audio_device *dev,GSList *uuids) +struct control *control_init (struct audio_device *dev,const char *uuid) {struct control *control;
@@ -285,7 +285,7 @@ struct control *control_init(struct audio_device *dev, GSList *uuids) control = g_new0(struct control, 1); -control_update (control, uuids); +control_update (control, uuid); control->avctp_id =avctp_add_state_cb (dev, state_changed);
profiles/audio/control.h +2 -2
@@ -24,8 +24,8 @@#define AUDIO_CONTROL_INTERFACE "org.bluez.MediaControl1" -struct control *control_init (struct audio_device *dev,GSList *uuids); -void control_update (struct control *control,GSList *uuids); +struct control *control_init (struct audio_device *dev,const char *uuid); +void control_update (struct control *control,const char *uuid);void control_unregister (struct audio_device *dev);gboolean control_is_active (struct audio_device *dev);
profiles/audio/manager.c +12 -9
@@ -53,6 +53,7 @@#include "../src/adapter.h" #include "../src/device.h" #include "../src/profile.h" +#include "../src/service.h" #include "log.h" #include "device.h"
@@ -89,8 +90,9 @@ static struct audio_device *manager_find_device(struct btd_device *device)return NULL ; } -static void audio_remove (struct btd_profile *p,struct btd_device *device) +static void audio_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct audio_device *dev; dev =manager_find_device (device);
@@ -101,9 +103,9 @@ static void audio_remove(struct btd_profile *p, struct btd_device *device)audio_device_unregister (dev); } -static int a2dp_source_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int a2dp_source_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct audio_device *audio_dev; audio_dev =get_audio_dev (device);
@@ -117,9 +119,9 @@ static int a2dp_source_probe(struct btd_profile *p, struct btd_device *device,return 0 ; } -static int a2dp_sink_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int a2dp_sink_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct audio_device *audio_dev; audio_dev =get_audio_dev (device);
@@ -133,9 +135,10 @@ static int a2dp_sink_probe(struct btd_profile *p, struct btd_device *device,return 0 ; } -static int avrcp_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int avrcp_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +struct btd_profile *p =service_get_profile (service);struct audio_device *audio_dev; audio_dev =get_audio_dev (device);
@@ -145,9 +148,9 @@ static int avrcp_probe(struct btd_profile *p, struct btd_device *device, }if (audio_dev->control) -control_update (audio_dev->control, uuids); +control_update (audio_dev->control, p->remote_uuid);else - audio_dev->control =control_init (audio_dev, uuids); + audio_dev->control =control_init (audio_dev, p->remote_uuid);if (audio_dev->sink &&sink_is_active (audio_dev))avrcp_connect (audio_dev);
profiles/cyclingspeed/cyclingspeed.c +5 -4
@@ -34,6 +34,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "dbus-common.h" #include "error.h" #include "attrib/gattrib.h"
@@ -1180,9 +1181,9 @@ static const GDBusMethodTable cyclingspeed_device_methods[] = { { } }; -static int csc_device_probe (struct btd_profile *p, -struct btd_device *device,GSList *uuids) +static int csc_device_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct btd_adapter *adapter;struct csc_adapter *cadapter;struct csc *csc;
@@ -1227,9 +1228,9 @@ static int csc_device_probe(struct btd_profile *p,return 0 ; } -static void csc_device_remove (struct btd_profile *p, -struct btd_device *device) +static void csc_device_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct btd_adapter *adapter;struct csc_adapter *cadapter;struct csc *csc;
profiles/deviceinfo/deviceinfo.c +6 -5
@@ -34,6 +34,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "attrib/gattrib.h" #include "attio.h" #include "attrib/att.h"
@@ -198,10 +199,9 @@ static void deviceinfo_unregister(struct btd_device *device)deviceinfo_free (d); } -static int deviceinfo_driver_probe (struct btd_profile *p, -struct btd_device *device, -GSList *uuids) +static int deviceinfo_driver_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *prim; prim =btd_device_get_primary (device,DEVICE_INFORMATION_UUID );
@@ -211,9 +211,10 @@ static int deviceinfo_driver_probe(struct btd_profile *p,return deviceinfo_register (device, prim); } -static void deviceinfo_driver_remove (struct btd_profile *p, -struct btd_device *device) +static void deviceinfo_driver_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +deviceinfo_unregister (device); }
profiles/gatt/gas.c +6 -4
@@ -39,6 +39,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "attrib/att.h" #include "attrib/gattrib.h" #include "attio.h"
@@ -407,9 +408,9 @@ static void gas_unregister(struct btd_device *device)gas_free (gas); } -static int gatt_driver_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int gatt_driver_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *gap, *gatt; gap =btd_device_get_primary (device,GAP_UUID );
@@ -423,9 +424,10 @@ static int gatt_driver_probe(struct btd_profile *p, struct btd_device *device,return gas_register (device, &gap->range, &gatt->range); } -static void gatt_driver_remove (struct btd_profile *p, -struct btd_device *device) +static void gatt_driver_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +gas_unregister (device); }
profiles/health/hdp_manager.c +7 -3
@@ -34,6 +34,7 @@#include <adapter.h> #include <device.h> #include <profile.h> +#include <service.h> #include <glib-helper.h> #include <log.h>
@@ -54,14 +55,17 @@ static void hdp_adapter_remove(struct btd_profile *p,hdp_adapter_unregister (adapter); } -static int hdp_driver_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int hdp_driver_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +return hdp_device_register (device); } -static void hdp_driver_remove (struct btd_profile *p,struct btd_device *device) +static void hdp_driver_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +hdp_device_unregister (device); }
profiles/heartrate/heartrate.c +6 -4
@@ -35,6 +35,7 @@#include "dbus-common.h" #include "device.h" #include "profile.h" +#include "service.h" #include "error.h" #include "attrib/gattrib.h" #include "attrib/att.h"
@@ -841,9 +842,9 @@ static void heartrate_adapter_remove(struct btd_profile *p,heartrate_adapter_unregister (adapter); } -static int heartrate_device_probe (struct btd_profile *p, -struct btd_device *device,GSList *uuids) +static int heartrate_device_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *prim; prim =btd_device_get_primary (device,HEART_RATE_UUID );
@@ -853,9 +854,10 @@ static int heartrate_device_probe(struct btd_profile *p,return heartrate_device_register (device, prim); } -static void heartrate_device_remove (struct btd_profile *p, -struct btd_device *device) +static void heartrate_device_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +heartrate_device_unregister (device); }
profiles/input/hog.c +5 -3
@@ -46,6 +46,7 @@#include "src/adapter.h" #include "src/device.h" #include "src/profile.h" +#include "src/service.h" #include "plugin.h" #include "suspend.h"
@@ -820,9 +821,9 @@ static void resume_callback(void)g_slist_foreach (devices, set_suspend,GINT_TO_POINTER (suspend)); } -static int hog_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int hog_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);const char *path =device_get_path (device);GSList *primaries, *l;
@@ -861,8 +862,9 @@ static void remove_device(gpointer a, gpointer b)hog_unregister_device (hogdev); } -static void hog_remove (struct btd_profile *p,struct btd_device *device) +static void hog_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service);const char *path =device_get_path (device);DBG ("path %s" , path);
profiles/input/manager.c +7 -4
@@ -39,6 +39,7 @@#include "../src/adapter.h" #include "../src/device.h" #include "../src/profile.h" +#include "../src/service.h" #include "device.h" #include "server.h"
@@ -55,11 +56,11 @@ static void input_remove(struct btd_device *device, const char *uuid)input_device_unregister (path, uuid); } -static int hid_device_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int hid_device_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);const char *path =device_get_path (device); -const sdp_record_t *rec =btd_device_get_record (device, uuids->data); +const sdp_record_t *rec =btd_device_get_record (device,HID_UUID );DBG ("path %s" , path);
@@ -70,8 +71,10 @@ static int hid_device_probe(struct btd_profile *p, struct btd_device *device, idle_timeout * 60); } -static void hid_device_remove (struct btd_profile *p,struct btd_device *device) +static void hid_device_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +input_remove (device,HID_UUID ); }
profiles/network/manager.c +13 -7
@@ -41,6 +41,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "manager.h" #include "common.h" #include "connection.h"
@@ -74,16 +75,19 @@ done: conf_security ? "true" : "false"); } -static int panu_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int panu_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +DBG ("path %s" ,device_get_path (device));return connection_register (device,BNEP_SVC_PANU ); } -static void network_remove (struct btd_profile *p,struct btd_device *device) +static void network_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +DBG ("path %s" ,device_get_path (device));connection_unregister (device);
@@ -118,9 +122,10 @@ static void panu_server_remove(struct btd_profile *p,server_unregister (adapter,BNEP_SVC_PANU ); } -static int gn_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int gn_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +DBG ("path %s" ,device_get_path (device));return connection_register (device,BNEP_SVC_GN );
@@ -155,9 +160,10 @@ static void gn_server_remove(struct btd_profile *p,server_unregister (adapter,BNEP_SVC_GN ); } -static int nap_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int nap_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +DBG ("path %s" ,device_get_path (device));return connection_register (device,BNEP_SVC_NAP );
profiles/proximity/manager.c +16 -12
@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "attrib/att.h" #include "attrib/gattrib.h" #include "attrib/gatt.h"
@@ -48,9 +49,9 @@ static struct enabled enabled = { .findme = TRUE, }; -static int monitor_linkloss_probe (struct btd_profile *p, -struct btd_device *device,GSList *uuids) +static int monitor_linkloss_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *linkloss; linkloss =btd_device_get_primary (device,LINK_LOSS_UUID );
@@ -60,9 +61,9 @@ static int monitor_linkloss_probe(struct btd_profile *p,return monitor_register_linkloss (device, &enabled, linkloss); } -static int monitor_immediate_probe (struct btd_profile *p, -struct btd_device *device,GSList *uuids) +static int monitor_immediate_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *immediate; immediate =btd_device_get_primary (device,IMMEDIATE_ALERT_UUID );
@@ -72,9 +73,9 @@ static int monitor_immediate_probe(struct btd_profile *p,return monitor_register_immediate (device, &enabled, immediate); } -static int monitor_txpower_probe (struct btd_profile *p, -struct btd_device *device,GSList *uuids) +static int monitor_txpower_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *txpower; txpower =btd_device_get_primary (device,TX_POWER_UUID );
@@ -84,21 +85,24 @@ static int monitor_txpower_probe(struct btd_profile *p,return monitor_register_txpower (device, &enabled, txpower); } -static void monitor_linkloss_remove (struct btd_profile *p, -struct btd_device *device) +static void monitor_linkloss_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +monitor_unregister_linkloss (device); } -static void monitor_immediate_remove (struct btd_profile *p, -struct btd_device *device) +static void monitor_immediate_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +monitor_unregister_immediate (device); } -static void monitor_txpower_remove (struct btd_profile *p, -struct btd_device *device) +static void monitor_txpower_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +monitor_unregister_txpower (device); }
profiles/proximity/reporter.c +5 -3
@@ -42,6 +42,7 @@#include "error.h" #include "device.h" #include "profile.h" +#include "service.h" #include "hcid.h" #include "attrib/gattrib.h" #include "attrib/att.h"
@@ -203,9 +204,9 @@ static void register_reporter_device(struct btd_device *device, radapter->devices =g_slist_prepend (radapter->devices, device); } -int reporter_device_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +int reporter_device_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct reporter_adapter *radapter;struct btd_adapter *adapter =device_get_adapter (device);
@@ -218,8 +219,9 @@ int reporter_device_probe(struct btd_profile *p, struct btd_device *device,return 0 ; } -void reporter_device_remove (struct btd_profile *p,struct btd_device *device) +void reporter_device_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct reporter_adapter *radapter;struct btd_adapter *adapter =device_get_adapter (device);
profiles/proximity/reporter.h +2 -3
@@ -36,9 +36,8 @@ enum { HIGH_ALERT = 0x02, }; -void reporter_device_remove (struct btd_profile *p,struct btd_device *device); -int reporter_device_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids); +void reporter_device_remove (struct btd_service *service); +int reporter_device_probe (struct btd_service *service);int reporter_adapter_probe (struct btd_profile *p,struct btd_adapter *adapter); void reporter_adapter_remove(struct btd_profile *p,
profiles/sap/manager.c +1 -0
@@ -28,6 +28,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "manager.h" #include "server.h"
profiles/scanparam/scan.c +6 -3
@@ -37,6 +37,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "attrib/att.h" #include "attrib/gattrib.h" #include "attrib/gatt.h"
@@ -266,9 +267,9 @@ static void scan_unregister(struct btd_device *device)g_free (scan); } -static int scan_param_probe (struct btd_profile *p,struct btd_device *device, -GSList *uuids) +static int scan_param_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *prim;DBG ("Probing Scan Parameters" );
@@ -280,8 +281,10 @@ static int scan_param_probe(struct btd_profile *p, struct btd_device *device,return scan_register (device, prim); } -static void scan_param_remove (struct btd_profile *p,struct btd_device *device) +static void scan_param_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +scan_unregister (device); }
profiles/thermometer/thermometer.c +6 -5
@@ -35,6 +35,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #include "error.h" #include "log.h" #include "attrib/gattrib.h"
@@ -1280,10 +1281,9 @@ static void thermometer_adapter_unregister(struct btd_adapter *adapter) THERMOMETER_MANAGER_INTERFACE); } -static int thermometer_device_probe (struct btd_profile *p, -struct btd_device *device, -GSList *uuids) +static int thermometer_device_probe (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct gatt_primary *tattr; tattr =btd_device_get_primary (device,HEALTH_THERMOMETER_UUID );
@@ -1293,9 +1293,10 @@ static int thermometer_device_probe(struct btd_profile *p,return thermometer_register (device, tattr); } -static void thermometer_device_remove (struct btd_profile *p, -struct btd_device *device) +static void thermometer_device_remove (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +thermometer_unregister (device); }
src/device.c +3 -8
@@ -898,7 +898,7 @@ static void service_remove(struct btd_service *service)struct btd_device *device =service_get_device (service);service_unavailable (service); - profile->device_remove (profile, device); + profile->device_remove (service); device->pending =g_slist_remove (device->pending, service);btd_service_unref (service); }
@@ -2379,7 +2379,6 @@ struct probe_data {static void dev_probe (struct btd_profile *p,void *user_data) {struct probe_data *d = user_data; -GSList *probe_uuids;struct btd_service *service;int err;
@@ -2389,21 +2388,17 @@ static void dev_probe(struct btd_profile *p, void *user_data)if (!device_match_profile (d->dev, p, d->uuids))return ; - probe_uuids =g_slist_append (NULL , (char *) p->remote_uuid); - service =service_create (d->dev, p); - err = p->device_probe (p, d->dev, probe_uuids); + err = p->device_probe (service);if (err <0 ) {error ("%s profile probe failed for %s" , p->name, d->addr);btd_service_unref (service); -g_slist_free (probe_uuids);return ; }service_probed (service); d->dev->services =g_slist_append (d->dev->services, service); -g_slist_free (probe_uuids); }void device_probe_profile (gpointer a,gpointer b)
@@ -2427,7 +2422,7 @@ void device_probe_profile(gpointer a, gpointer b) service =service_create (device, profile); - err = profile->device_probe (profile, device, probe_uuids); + err = profile->device_probe (service);if (err <0 ) {error ("%s profile probe failed for %s" , profile->name, addr);btd_service_unref (service);
src/profile.c +7 -4
@@ -50,6 +50,7 @@#include "adapter.h" #include "device.h" #include "profile.h" +#include "service.h" #define DUN_DEFAULT_CHANNEL 1#define SPP_DEFAULT_CHANNEL 3
@@ -1359,16 +1360,16 @@ static void ext_adapter_remove(struct btd_profile *p, } } -static int ext_device_probe (struct btd_profile *p,struct btd_device *dev, -GSList *uuids) +static int ext_device_probe (struct btd_service *service) { +struct btd_profile *p =service_get_profile (service);struct ext_profile *ext; ext =find_ext (p);if (!ext)return -ENOENT ; -DBG ("%s probed with %u UUIDs" , ext->name,g_slist_length (uuids)); +DBG ("%s probed with UUID %s" , ext->name, p->remote_uuid);return 0 ; }
@@ -1388,8 +1389,10 @@ static struct ext_io *find_connection(struct ext_profile *ext,return NULL ; } -static void ext_device_remove (struct btd_profile *p,struct btd_device *dev) +static void ext_device_remove (struct btd_service *service) { +struct btd_profile *p =service_get_profile (service); +struct btd_device *dev =service_get_device (service);struct ext_profile *ext;struct ext_io *conn;
src/profile.h +4 -4
@@ -25,6 +25,8 @@#define BTD_PROFILE_PRIORITY_MEDIUM 1#define BTD_PROFILE_PRIORITY_HIGH 2 +struct btd_service ; +struct btd_profile {const char *name;int priority;
@@ -34,10 +36,8 @@ struct btd_profile {bool auto_connect; -int (*device_probe) (struct btd_profile *p,struct btd_device *device, -GSList *uuids); -void (*device_remove) (struct btd_profile *p, -struct btd_device *device); +int (*device_probe) (struct btd_service *service); +void (*device_remove) (struct btd_service *service);int (*connect) (struct btd_device *device,struct btd_profile *profile);
Signature · 1 line
1.8.1.4
RFC 7/11 audio: Hold a reference to btd_service
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Profile implementations are expected to hold a reference to probed services, so update the audio profiles accordingly.
--- profiles/audio/control.c | 28 ++++++++++++++++++++++------ profiles/audio/control.h | 7 +++++-- profiles/audio/manager.c | 9 ++++----- profiles/audio/sink.c | 6 +++++- profiles/audio/sink.h | 4 +++- profiles/audio/source.c | 7 ++++++- profiles/audio/source.h | 5 ++++- 7 files changed, 49 insertions(+), 17 deletions(-)
profiles/audio/control.c +22 -6
@@ -48,6 +48,8 @@#include "lib/uuid.h" #include "../src/adapter.h" #include "../src/device.h" +#include "../src/profile.h" +#include "../src/service.h" #include "log.h" #include "error.h"
@@ -61,7 +63,8 @@struct control {struct avctp *session; -gboolean target; +struct btd_service *target; +struct btd_service *remote;unsigned int avctp_id; };
@@ -251,6 +254,12 @@ static void path_unregister(void *data)avctp_remove_state_cb (control->avctp_id); +if (control->target) +btd_service_unref (control->target); + +if (control->remote) +btd_service_unref (control->remote); +g_free (control); dev->control =NULL ; }
@@ -262,13 +271,20 @@ void control_unregister(struct audio_device *dev) AUDIO_CONTROL_INTERFACE); } -void control_update (struct control *control,const char *uuid) +void control_update (struct control *control,struct btd_service *service) { -if (bt_uuid_strcmp (uuid,AVRCP_TARGET_UUID ) ==0 ) - control->target = TRUE; +struct btd_profile *p =service_get_profile (service); +const char *uuid = p->remote_uuid; + +if (!control->target &&bt_uuid_strcmp (uuid,AVRCP_TARGET_UUID ) ==0 ) + control->target =btd_service_ref (service); +else if (!control->remote && +bt_uuid_strcmp (uuid,AVRCP_REMOTE_UUID ) ==0 ) + control->remote =btd_service_ref (service); } -struct control *control_init (struct audio_device *dev,const char *uuid) +struct control *control_init (struct audio_device *dev, +struct btd_service *service) {struct control *control;
@@ -285,7 +301,7 @@ struct control *control_init(struct audio_device *dev, const char *uuid) control = g_new0(struct control, 1); -control_update (control, uuid); +control_update (control, service); control->avctp_id =avctp_add_state_cb (dev, state_changed);
profiles/audio/control.h +5 -2
@@ -24,8 +24,11 @@#define AUDIO_CONTROL_INTERFACE "org.bluez.MediaControl1" -struct control *control_init (struct audio_device *dev,const char *uuid); -void control_update (struct control *control,const char *uuid); +struct btd_service ; + +struct control *control_init (struct audio_device *dev, +struct btd_service *service); +void control_update (struct control *control,struct btd_service *service);void control_unregister (struct audio_device *dev);gboolean control_is_active (struct audio_device *dev);
profiles/audio/manager.c +4 -5
@@ -114,7 +114,7 @@ static int a2dp_source_probe(struct btd_service *service)return -1 ; } - audio_dev->source =source_init (audio_dev); + audio_dev->source =source_init (audio_dev, service);return 0 ; }
@@ -130,7 +130,7 @@ static int a2dp_sink_probe(struct btd_service *service)return -1 ; } - audio_dev->sink =sink_init (audio_dev); + audio_dev->sink =sink_init (audio_dev, service);return 0 ; }
@@ -138,7 +138,6 @@ static int a2dp_sink_probe(struct btd_service *service)static int avrcp_probe (struct btd_service *service) {struct btd_device *device =service_get_device (service); -struct btd_profile *p =service_get_profile (service);struct audio_device *audio_dev; audio_dev =get_audio_dev (device);
@@ -148,9 +147,9 @@ static int avrcp_probe(struct btd_service *service) }if (audio_dev->control) -control_update (audio_dev->control, p->remote_uuid); +control_update (audio_dev->control, service);else - audio_dev->control =control_init (audio_dev, p->remote_uuid); + audio_dev->control =control_init (audio_dev, service);if (audio_dev->sink &&sink_is_active (audio_dev))avrcp_connect (audio_dev);
profiles/audio/sink.c +5 -1
@@ -41,6 +41,7 @@#include "../src/adapter.h" #include "../src/device.h" +#include "../src/service.h" #include "device.h" #include "avdtp.h"
@@ -55,6 +56,7 @@struct sink {struct audio_device *dev; +struct btd_service *service;struct avdtp *session;struct avdtp_stream *stream;unsigned int cb_id;
@@ -361,6 +363,7 @@ static void sink_free(struct audio_device *dev)g_source_remove (sink->retry_id);avdtp_remove_state_cb (sink->avdtp_callback_id); +btd_service_unref (sink->service);g_free (sink); dev->sink =NULL ;
@@ -372,7 +375,7 @@ void sink_unregister(struct audio_device *dev)sink_free (dev); } -struct sink *sink_init (struct audio_device *dev) +struct sink *sink_init (struct audio_device *dev,struct btd_service *service) {struct sink *sink;
@@ -381,6 +384,7 @@ struct sink *sink_init(struct audio_device *dev) sink = g_new0(struct sink, 1); sink->dev = dev; + sink->service =btd_service_ref (service); sink->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback);
profiles/audio/sink.h +3 -1
@@ -36,11 +36,13 @@ typedef void (*sink_state_cb) (struct audio_device *dev,sink_state_t new_state, void *user_data); +struct btd_service ; +unsigned int sink_add_state_cb (struct audio_device *dev,sink_state_cb cb,void *user_data);gboolean sink_remove_state_cb (unsigned int id); -struct sink *sink_init (struct audio_device *dev); +struct sink *sink_init (struct audio_device *dev,struct btd_service *service);void sink_unregister (struct audio_device *dev);gboolean sink_is_active (struct audio_device *dev);int sink_connect (struct audio_device *dev);
profiles/audio/source.c +6 -1
@@ -42,6 +42,7 @@#include "../src/adapter.h" #include "../src/device.h" +#include "../src/service.h" #include "device.h" #include "avdtp.h"
@@ -56,6 +57,7 @@struct source {struct audio_device *dev; +struct btd_service *service;struct avdtp *session;struct avdtp_stream *stream;unsigned int cb_id;
@@ -365,6 +367,7 @@ static void source_free(struct audio_device *dev)g_source_remove (source->retry_id);avdtp_remove_state_cb (source->avdtp_callback_id); +btd_service_unref (source->service);g_free (source); dev->source =NULL ;
@@ -377,7 +380,8 @@ void source_unregister(struct audio_device *dev)source_free (dev); } -struct source *source_init (struct audio_device *dev) +struct source *source_init (struct audio_device *dev, +struct btd_service *service) {struct source *source;
@@ -386,6 +390,7 @@ struct source *source_init(struct audio_device *dev) source = g_new0(struct source, 1); source->dev = dev; + source->service =btd_service_ref (service); source->avdtp_callback_id =avdtp_add_state_cb (dev, avdtp_state_callback);
profiles/audio/source.h +4 -1
@@ -37,11 +37,14 @@ typedef void (*source_state_cb) (struct audio_device *dev,source_state_t new_state, void *user_data); +struct btd_service ; +unsigned int source_add_state_cb (struct audio_device *dev,source_state_cb cb,void *user_data);gboolean source_remove_state_cb (unsigned int id); -struct source *source_init (struct audio_device *dev); +struct source *source_init (struct audio_device *dev, +struct btd_service *service);void source_unregister (struct audio_device *dev);int source_connect (struct audio_device *dev); gboolean source_new_stream(struct audio_device *dev, struct avdtp *session,
Signature · 1 line
1.8.1.4
RFC 8/11 network: Hold a reference to btd_service
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Profile implementations are expected to hold a reference to probed services, so update the network profiles accordingly.
--- profiles/network/connection.c | 38 ++++++++++++++++++++++++++-------- profiles/network/connection.h | 4 ++-- profiles/network/manager.c | 48 ++++++------------------------------------- 3 files changed, 37 insertions(+), 53 deletions(-)
profiles/network/connection.c +29 -9
@@ -43,6 +43,8 @@#include "dbus-common.h" #include "adapter.h" #include "device.h" +#include "profile.h" +#include "service.h" #include "error.h" #include "common.h"
@@ -65,6 +67,7 @@ struct network_peer { };struct network_conn { +struct btd_service *service;char dev[16 ];/* Interface name */ uint16_t id;/* Role: Service Class Identifier */ conn_state state;
@@ -83,6 +86,13 @@ struct __service_16 {static GSList *peers =NULL ; +static uint16_t get_service_id (struct btd_service *service) +{ +struct btd_profile *p =service_get_profile (service); + +return bnep_service_id (p->remote_uuid); +} +static struct network_peer *find_peer (GSList *list,struct btd_device *device) {for (; list; list = list->next) {
@@ -599,6 +609,7 @@ static void connection_free(void *data)if (nc->connect)dbus_message_unref (nc->connect); +btd_service_unref (nc->service);g_free (nc); }
@@ -639,13 +650,14 @@ static const GDBusPropertyTable connection_properties[] = { { } }; -void connection_unregister (struct btd_device *device) +void connection_unregister (struct btd_service *service) { -struct network_peer *peer; +struct btd_device *device =service_get_device (service); +struct network_conn *conn =service_get_user_data (service); +struct network_peer *peer = conn->peer; +uint16_t id =get_service_id (service); - peer =find_peer (peers, device); -if (!peer) -return ; +DBG ("%s id %u" ,device_get_path (device), id);g_slist_free_full (peer->connections, connection_free); peer->connections =NULL ;
@@ -682,12 +694,14 @@ static struct network_peer *create_peer(struct btd_device *device)return peer; } -int connection_register (struct btd_device *device,uint16_t id) +int connection_register (struct btd_service *service) { +struct btd_device *device =service_get_device (service);struct network_peer *peer;struct network_conn *nc; +uint16_t id =get_service_id (service); -DBG ("id %u" , id); +DBG ("%s id %u" ,device_get_path (device), id); peer =find_peer (peers, device);if (!peer) {
@@ -698,16 +712,22 @@ int connection_register(struct btd_device *device, uint16_t id) } nc =find_connection (peer->connections, id); -if (nc) -return 0 ; +if (nc) { +error ("Device %s has multiple connection instances of %d" , +device_get_path (device), id); +return -1 ; + } nc = g_new0(struct network_conn, 1); nc->id = id;memset (nc->dev,0 ,sizeof (nc->dev));strcpy (nc->dev,"bnep%d" ); + nc->service =btd_service_ref (service); nc->state =DISCONNECTED ; nc->peer = peer; +service_set_user_data (service, nc); +DBG ("id %u registered" , id); peer->connections =g_slist_append (peer->connections, nc);
profiles/network/connection.h +2 -2
@@ -21,7 +21,7 @@* */ -int connection_register (struct btd_device *device,uint16_t id); -void connection_unregister (struct btd_device *device); +int connection_register (struct btd_service *service); +void connection_unregister (struct btd_service *service);int connection_connect (struct btd_device *device,uint16_t id);int connection_disconnect (struct btd_device *device,uint16_t id);
profiles/network/manager.c +6 -42
84 lines not on this page · raw message
Signature · 1 line
1.8.1.4
RFC 9/11 input: Hold a reference to btd_service
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Profile implementations are expected to hold a reference to probed services, so update the input profiles accordingly.
--- profiles/input/device.c | 74 +++++++++++++++++++++++++----------------------- profiles/input/device.h | 8 +++--- profiles/input/manager.c | 41 ++++----------------------- 3 files changed, 48 insertions(+), 75 deletions(-)
profiles/input/device.c +38 -36
@@ -44,6 +44,7 @@#include "../src/adapter.h" #include "../src/device.h" #include "../src/profile.h" +#include "../src/service.h" #include "../src/storage.h" #include "../src/dbus-common.h"
@@ -55,9 +56,9 @@#include "sdp-client.h" struct input_device { +struct btd_service *service;struct btd_device *device;char *path; -char *uuid;bdaddr_t src;bdaddr_t dst;uint32_t handle;
@@ -66,7 +67,6 @@ struct input_device {guint ctrl_watch;guint intr_watch;guint sec_watch; -int timeout;struct hidp_connadd_req *req;guint dc_id;gboolean disable_sdp;
@@ -74,6 +74,12 @@ struct input_device { };static GSList *devices =NULL ; +static int idle_timeout =0 ; + +void input_set_idle_timeout (int timeout) +{ + idle_timeout = timeout; +}static struct input_device *find_device_by_path (GSList *list,const char *path) {
@@ -92,6 +98,7 @@ static void input_device_free(struct input_device *idev)if (idev->dc_id)device_remove_disconnect_watch (idev->device, idev->dc_id); +btd_service_unref (idev->service);btd_device_unref (idev->device);g_free (idev->name);g_free (idev->path);
@@ -111,8 +118,6 @@ static void input_device_free(struct input_device *idev)if (idev->ctrl_io)g_io_channel_unref (idev->ctrl_io); -g_free (idev->uuid); -g_free (idev); }
@@ -366,7 +371,7 @@ static int hidp_add_connection(struct input_device *idev) req->ctrl_sock =g_io_channel_unix_get_fd (idev->ctrl_io); req->intr_sock =g_io_channel_unix_get_fd (idev->intr_io); req->flags =0 ; - req->idle_to = idev->timeout; + req->idle_to = idle_timeout;ba2str (&idev->src, src_addr);ba2str (&idev->dst, dst_addr);
@@ -674,10 +679,21 @@ int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile)return 0 ; } -static struct input_device *input_device_new (struct btd_device *device, -const char *path,const uint32_t handle, -gboolean disable_sdp) +static gboolean is_device_sdp_disable (const sdp_record_t *rec) { +sdp_data_t *data; + + data =sdp_data_get (rec,SDP_ATTR_HID_SDP_DISABLE ); + +return data && data->val.uint8; +} + +static struct input_device *input_device_new (struct btd_service *service) +{ +struct btd_device *device =service_get_device (service); +const char *path =device_get_path (device); +struct btd_profile *p =service_get_profile (service); +const sdp_record_t *rec =btd_device_get_record (device, p->remote_uuid);struct btd_adapter *adapter =device_get_adapter (device);struct input_device *idev;char name[HCI_MAX_NAME_LENGTH +1 ];
@@ -685,10 +701,11 @@ static struct input_device *input_device_new(struct btd_device *device, idev = g_new0(struct input_device, 1);bacpy (&idev->src,adapter_get_address (adapter));bacpy (&idev->dst,device_get_address (device)); + idev->service =btd_service_ref (service); idev->device =btd_device_ref (device); idev->path =g_strdup (path); - idev->handle = handle; - idev->disable_sdp = disable_sdp; + idev->handle = rec->handle; + idev->disable_sdp =is_device_sdp_disable (rec);device_get_name (device, name,HCI_MAX_NAME_LENGTH );if (strlen (name) >0 )
@@ -697,19 +714,10 @@ static struct input_device *input_device_new(struct btd_device *device,return idev; } -static gboolean is_device_sdp_disable (const sdp_record_t *rec) -{ -sdp_data_t *data; - - data =sdp_data_get (rec,SDP_ATTR_HID_SDP_DISABLE ); - -return data && data->val.uint8; -} - -int input_device_register (struct btd_device *device, -const char *path,const char *uuid, -const sdp_record_t *rec,int timeout) +int input_device_register (struct btd_service *service) { +struct btd_device *device =service_get_device (service); +const char *path =device_get_path (device);struct input_device *idev;DBG ("%s" , path);
@@ -718,13 +726,11 @@ int input_device_register(struct btd_device *device,if (idev)return -EEXIST ; - idev =input_device_new (device, path, rec->handle, -is_device_sdp_disable (rec)); + idev =input_device_new (service);if (!idev)return -EINVAL ; - idev->timeout = timeout; - idev->uuid =g_strdup (uuid); +service_set_user_data (service, idev); devices =g_slist_append (devices, idev);
@@ -746,25 +752,21 @@ static struct input_device *find_device(const bdaddr_t *src,return NULL ; } -int input_device_unregister (const char *path,const char *uuid) +void input_device_unregister (struct btd_service *service) { -struct input_device *idev; +struct btd_device *device =service_get_device (service); +const char *path =device_get_path (device); +struct input_device *idev =service_get_user_data (service);DBG ("%s" , path); - idev =find_device_by_path (devices, path); -if (idev ==NULL ) -return -EINVAL ; -if (idev->ctrl_io) { -/* Pending connection running */ -return -EBUSY ; +/* FIXME: pending connection running */ +return ; } devices =g_slist_remove (devices, idev);input_device_free (idev); - -return 0 ; }static int input_device_connadd (struct input_device *idev)
profiles/input/device.h +4 -4
@@ -27,10 +27,10 @@struct input_device ;struct input_conn ; -int input_device_register (struct btd_device *device,const char *path, -const char *uuid,const sdp_record_t *rec, -int timeout); -int input_device_unregister (const char *path,const char *uuid); +void input_set_idle_timeout (int timeout); + +int input_device_register (struct btd_service *service); +void input_device_unregister (struct btd_service *service);int input_device_set_channel (const bdaddr_t *src,const bdaddr_t *dst,int psm,GIOChannel *io);
profiles/input/manager.c +6 -35
65 lines not on this page · raw message
Signature · 1 line
1.8.1.4
RFC 10/11 service: Add callbacks to track state changes
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Extend the btd_service API to support state observers.
--- src/service.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ src/service.h | 8 ++++++++ 2 files changed, 56 insertions(+)
src/service.c +48 -0
@@ -55,6 +55,12 @@ struct btd_service {int err; }; +struct service_state_callback { +service_state_cb cb; +void *user_data; +guint id; +}; +static char *str_state[] = {"SERVICE_STATE_UNAVAILABLE" ,"SERVICE_STATE_DISCONNECTED" ,
@@ -63,6 +69,8 @@ static char *str_state[] = { "SERVICE_STATE_DISCONNECTING", }; +static GSList *state_callbacks; +struct btd_device *service_get_device (struct btd_service *service) {return service->device;
@@ -98,6 +106,7 @@ static void service_set_state(struct btd_service *service, service_state_t state) {service_state_t old = service->state; +GSList *l;if (state == old)return ;
@@ -106,6 +115,45 @@ static void service_set_state(struct btd_service *service,DBG ("State changed %p: %s -> %s" , service, str_state[old], str_state[state]); + +for (l = state_callbacks; l !=NULL ; l =g_slist_next (l)) { +struct service_state_callback *cb = l->data; + + cb->cb (service, old, state, cb->user_data); + } +} + +guint service_add_state_cb (service_state_cb cb,void *user_data) +{ +struct service_state_callback *state_cb; +static guint id =0 ; + + state_cb = g_new(struct service_state_callback, 1); + state_cb->cb = cb; + state_cb->user_data = user_data; + state_cb->id = ++id; + + state_callbacks =g_slist_append (state_callbacks, state_cb); + +return state_cb->id; +} + +gboolean service_remove_state_cb (guint id) +{ +GSList *l; + +for (l = state_callbacks; l !=NULL ; l =g_slist_next (l)) { +struct service_state_callback *cb = l->data; + +if (cb && cb->id == id) { + state_callbacks =g_slist_remove_link (state_callbacks, + l); +g_free (cb); +return TRUE; + } + } + +return FALSE; } struct btd_service *service_create(struct btd_device *device,
src/service.h +8 -0
@@ -31,6 +31,11 @@ typedef enum {struct btd_service ; +typedef void (*service_state_cb ) (struct btd_service *service, +service_state_t old_state, +service_state_t new_state, +void *user_data); +struct btd_service *service_create (struct btd_device *device,struct btd_profile *profile);
@@ -41,6 +46,9 @@ struct btd_device *service_get_device(struct btd_service *service);struct btd_profile *service_get_profile (struct btd_service *service);service_state_t service_get_state (struct btd_service *service); +guint service_add_state_cb (service_state_cb cb,void *user_data); +gboolean service_remove_state_cb (guint id); +void service_set_user_data (struct btd_service *service,void *user_data);void *service_get_user_data (struct btd_service *service);int service_get_error (struct btd_service *service);
Signature · 1 line
1.8.1.4
RFC 11/11 profile: Use btd_service for connect/disconnect
In reply to Mikel AstizFrom: Mikel Astiz <[email protected]>
Change the btd_profile connect/disconnect callbacks to receive a btd_service pointer. This should make it possible to handle multiple instances of the same profile in a specific device.
The patch strongly influences how the profiles should interact with the core. The state transitions, previously reported using the device.h API (device_profile_connected() and device_profile__disconnected()), have now been replaced by the btd_service API.
The transitions will then be propagated to device.c by means of the conventional state-changed callback mechanism.
--- Makefile.plugins | 4 +-- profiles/audio/control.c | 24 +++++++++++-- profiles/audio/manager.c | 56 +++++++----------------------- profiles/audio/manager.h | 7 ---- profiles/audio/sink.c | 18 +++++----- profiles/audio/source.c | 18 +++++----- profiles/input/device.c | 21 +++++------- profiles/input/device.h | 5 ++- profiles/input/manager.c | 11 ------ profiles/input/manager.h | 25 -------------- profiles/network/connection.c | 39 ++++++--------------- profiles/network/connection.h | 4 +-- profiles/network/manager.c | 79 ++++--------------------------------------- profiles/network/manager.h | 25 -------------- src/device.c | 42 ++++++++++++++--------- src/device.h | 5 --- src/profile.c | 29 ++++++++++------ src/profile.h | 6 ++-- 18 files changed, 128 insertions(+), 290 deletions(-) delete mode 100644 profiles/input/manager.h delete mode 100644 profiles/network/manager.h
Makefile.plugins +2 -2
@@ -41,14 +41,14 @@ builtin_sources += profiles/audio/main.c \ profiles/audio/a2dp-codecs.h builtin_modules += network -builtin_sources += profiles/network/manager.h profiles/network/manager.c \ +builtin_sources += profiles/network/manager.c \ profiles/network/common.h profiles/network/common.c \ profiles/network/server.h profiles/network/server.c \ profiles/network/connection.h \ profiles/network/connection.c builtin_modules += input -builtin_sources += profiles/input/manager.h profiles/input/manager.c \ +builtin_sources += profiles/input/manager.c \ profiles/input/server.h profiles/input/server.c \ profiles/input/device.h profiles/input/device.c
profiles/audio/control.c +21 -3
@@ -68,6 +68,24 @@ struct control {unsigned int avctp_id; }; +static void control_connected (struct control *control,int err) +{ +if (control->target) +service_connecting_complete (control->target, err); + +if (control->remote) +service_connecting_complete (control->remote, err); +} + +static void control_disconnected (struct control *control,int err) +{ +if (control->target) +service_disconnecting_complete (control->target, err); + +if (control->remote) +service_disconnecting_complete (control->remote, err); +} +static void state_changed (struct audio_device *dev,avctp_state_t old_state,avctp_state_t new_state) {
@@ -80,11 +98,11 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state, control->session =NULL ;if (old_state !=AVCTP_STATE_CONNECTED ) { -audio_control_connected (dev->btd_dev, -EIO ); +control_connected (control, -EIO );break ; } -audio_control_disconnected (dev->btd_dev,0 ); +control_disconnected (control,0 );g_dbus_emit_property_changed (conn, path,AUDIO_CONTROL_INTERFACE ,"Connected" );
@@ -98,7 +116,7 @@ static void state_changed(struct audio_device *dev, avctp_state_t old_state,break ;case AVCTP_STATE_CONNECTED : -audio_control_connected (dev->btd_dev,0 ); +control_connected (control,0 );g_dbus_emit_property_changed (conn, path,AUDIO_CONTROL_INTERFACE ,"Connected" );
profiles/audio/manager.c +12 -44
104 lines not on this page · raw message
profiles/audio/manager.h +0 -7
@@ -29,13 +29,6 @@ struct enabled_interfaces {gboolean media_player; }; -void audio_sink_connected (struct btd_device *dev,int err); -void audio_sink_disconnected (struct btd_device *dev,int err); -void audio_source_connected (struct btd_device *dev,int err); -void audio_source_disconnected (struct btd_device *dev,int err); -void audio_control_connected (struct btd_device *dev,int err); -void audio_control_disconnected (struct btd_device *dev,int err); -int audio_manager_init (GKeyFile *config);void audio_manager_exit (void );
profiles/audio/sink.c +9 -9
@@ -149,7 +149,7 @@ static void stream_state_changed(struct avdtp_stream *stream,switch (new_state) {case AVDTP_STATE_IDLE : -audio_sink_disconnected (dev->btd_dev,0 ); +service_disconnecting_complete (sink->service,0 );if (sink->disconnect_id >0 ) {a2dp_cancel (dev, sink->disconnect_id);
@@ -194,7 +194,7 @@ static gboolean stream_setup_retry(gpointer user_data) err = -EIO ; } -audio_sink_connected (sink->dev->btd_dev, err); +service_connecting_complete (sink->service, err);if (sink->connect_id >0 ) {a2dp_cancel (sink->dev, sink->connect_id);
@@ -214,7 +214,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,if (stream) {DBG ("Stream successfully created" ); -audio_sink_connected (sink->dev->btd_dev,0 ); +service_connecting_complete (sink->service,0 );return ; }
@@ -228,7 +228,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep, sink); }else {DBG ("Stream setup failed : %s" ,avdtp_strerror (err)); -audio_sink_connected (sink->dev->btd_dev, -EIO ); +service_connecting_complete (sink->service, -EIO ); } }
@@ -248,7 +248,7 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,return ; failed: -audio_sink_connected (sink->dev->btd_dev, -EIO ); +service_connecting_complete (sink->service, -EIO );avdtp_unref (sink->session); sink->session =NULL ;
@@ -286,7 +286,7 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtpreturn ; failed: -audio_sink_connected (sink->dev->btd_dev, -EIO ); +service_connecting_complete (sink->service, -EIO );avdtp_unref (sink->session); sink->session =NULL ; }
@@ -348,13 +348,13 @@ static void sink_free(struct audio_device *dev)avdtp_unref (sink->session);if (sink->connect_id >0 ) { -audio_sink_connected (dev->btd_dev, -ECANCELED ); +service_connecting_complete (sink->service, -ECANCELED );a2dp_cancel (dev, sink->connect_id); sink->connect_id =0 ; }if (sink->disconnect_id >0 ) { -audio_sink_disconnected (dev->btd_dev, -ECANCELED ); +service_disconnecting_complete (sink->service, -ECANCELED );a2dp_cancel (dev, sink->disconnect_id); sink->disconnect_id =0 ; }
@@ -434,7 +434,7 @@ int sink_disconnect(struct audio_device *dev, gboolean shutdown)if (sink->connect_id >0 ) {a2dp_cancel (dev, sink->connect_id); sink->connect_id =0 ; -audio_sink_connected (dev->btd_dev, -ECANCELED ); +service_connecting_complete (sink->service, -ECANCELED );avdtp_unref (sink->session); sink->session =NULL ;
profiles/audio/source.c +9 -9
@@ -150,7 +150,7 @@ static void stream_state_changed(struct avdtp_stream *stream,switch (new_state) {case AVDTP_STATE_IDLE : -audio_source_disconnected (dev->btd_dev,0 ); +service_disconnecting_complete (source->service,0 );if (source->disconnect_id >0 ) {a2dp_cancel (dev, source->disconnect_id);
@@ -195,7 +195,7 @@ static gboolean stream_setup_retry(gpointer user_data) err = -EIO ; } -audio_source_connected (source->dev->btd_dev, err); +service_connecting_complete (source->service, err);if (source->connect_id >0 ) {a2dp_cancel (source->dev, source->connect_id);
@@ -215,7 +215,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep,if (stream) {DBG ("Stream successfully created" ); -audio_source_connected (source->dev->btd_dev,0 ); +service_connecting_complete (source->service,0 );return ; }
@@ -229,7 +229,7 @@ static void stream_setup_complete(struct avdtp *session, struct a2dp_sep *sep, source); }else {DBG ("Stream setup failed : %s" ,avdtp_strerror (err)); -audio_source_connected (source->dev->btd_dev, -EIO ); +service_connecting_complete (source->service, -EIO ); } }
@@ -252,7 +252,7 @@ static void select_complete(struct avdtp *session, struct a2dp_sep *sep,return ; failed: -audio_source_connected (source->dev->btd_dev, -EIO ); +service_connecting_complete (source->service, -EIO );avdtp_unref (source->session); source->session =NULL ;
@@ -290,7 +290,7 @@ static void discovery_complete(struct avdtp *session, GSList *seps, struct avdtpreturn ; failed: -audio_source_connected (source->dev->btd_dev, -EIO ); +service_connecting_complete (source->service, -EIO );avdtp_unref (source->session); source->session =NULL ; }
@@ -352,13 +352,13 @@ static void source_free(struct audio_device *dev)avdtp_unref (source->session);if (source->connect_id >0 ) { -audio_source_connected (dev->btd_dev, -ECANCELED ); +service_connecting_complete (source->service, -ECANCELED );a2dp_cancel (dev, source->connect_id); source->connect_id =0 ; }if (source->disconnect_id >0 ) { -audio_source_disconnected (dev->btd_dev, -ECANCELED ); +service_disconnecting_complete (source->service, -ECANCELED );a2dp_cancel (dev, source->disconnect_id); source->disconnect_id =0 ; }
@@ -431,7 +431,7 @@ int source_disconnect(struct audio_device *dev, gboolean shutdown)if (source->connect_id >0 ) {a2dp_cancel (dev, source->connect_id); source->connect_id =0 ; -audio_source_connected (dev->btd_dev, -ECANCELED ); +service_connecting_complete (source->service, -ECANCELED );avdtp_unref (source->session); source->session =NULL ;
profiles/input/device.c +8 -13
@@ -48,7 +48,6 @@#include "../src/storage.h" #include "../src/dbus-common.h" -#include "manager.h" #include "device.h" #include "error.h" #include <btio/btio.h>
@@ -534,7 +533,7 @@ static int input_device_connected(struct input_device *idev) idev->dc_id =device_add_disconnect_watch (idev->device, disconnect_cb, idev,NULL ); -input_manager_device_connected (idev->device,0 ); +service_connecting_complete (idev->service,0 );return 0 ; }
@@ -561,7 +560,7 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,return ; failed: -input_manager_device_connected (idev->device, err); +service_connecting_complete (idev->service, err);/* So we guarantee the interrupt channel is closed before the * control channel (if we only do unref GLib will close it only
@@ -613,7 +612,7 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,return ; failed: -input_manager_device_connected (idev->device, -EIO ); +service_connecting_complete (idev->service, -EIO );g_io_channel_unref (idev->ctrl_io); idev->ctrl_io =NULL ; }
@@ -644,13 +643,11 @@ static int dev_connect(struct input_device *idev)return -EIO ; } -int input_device_connect (struct btd_device *dev,struct btd_profile *profile) +int input_device_connect (struct btd_service *service) {struct input_device *idev; - idev =find_device_by_path (devices,device_get_path (dev)); -if (!idev) -return -ENOENT ; + idev =service_get_user_data (service);if (idev->ctrl_io)return -EBUSY ;
@@ -661,20 +658,18 @@ int input_device_connect(struct btd_device *dev, struct btd_profile *profile)return dev_connect (idev); } -int input_device_disconnect (struct btd_device *dev,struct btd_profile *profile) +int input_device_disconnect (struct btd_service *service) {struct input_device *idev;int err; - idev =find_device_by_path (devices,device_get_path (dev)); -if (!idev) -return -ENOENT ; + idev =service_get_user_data (service); err =connection_disconnect (idev,0 );if (err <0 )return err; -device_profile_disconnected (dev, profile,0 ); +service_disconnecting_complete (service,0 );return 0 ; }
profiles/input/device.h +2 -3
@@ -36,6 +36,5 @@ int input_device_set_channel(const bdaddr_t *src, const bdaddr_t *dst, int psm, GIOChannel *io);int input_device_close_channels (const bdaddr_t *src,const bdaddr_t *dst); -int input_device_connect (struct btd_device *dev,struct btd_profile *profile); -int input_device_disconnect (struct btd_device *dev, -struct btd_profile *profile); +int input_device_connect (struct btd_service *service); +int input_device_disconnect (struct btd_service *service);
profiles/input/manager.c +0 -11
@@ -43,7 +43,6 @@#include "device.h" #include "server.h" -#include "manager.h" static int hid_server_probe (struct btd_profile *p,struct btd_adapter *adapter) {
@@ -72,16 +71,6 @@ static struct btd_profile input_profile = { .adapter_remove = hid_server_remove, }; -void input_manager_device_connected (struct btd_device *dev,int err) -{ -device_profile_connected (dev, &input_profile, err); -} - -void input_manager_device_disconnected (struct btd_device *dev,int err) -{ -device_profile_disconnected (dev, &input_profile, err); -} -static GKeyFile *load_config_file (const char *file) {GKeyFile *keyfile;
profiles/input/manager.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* -* -* BlueZ - Bluetooth protocol stack for Linux -* -* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -* -*/ - -void input_manager_device_connected (struct btd_device *dev,int err); -void input_manager_device_disconnected (struct btd_device *dev,int err);
profiles/network/connection.c +11 -28
@@ -48,7 +48,6 @@#include "error.h" #include "common.h" -#include "manager.h" #include "connection.h" #define NETWORK_PEER_INTERFACE "org.bluez.Network1"
@@ -146,7 +145,7 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,device_remove_disconnect_watch (nc->peer->device, nc->dc_id); nc->dc_id =0 ; -network_disconnected (nc->peer->device, nc->id,0 ); +service_disconnecting_complete (nc->service,0 );info ("%s disconnected" , nc->dev);
@@ -183,7 +182,7 @@ static void cancel_connection(struct network_conn *nc, int err) nc->timeout_source =0 ; } -network_connected (nc->peer->device, nc->id, err); +service_connecting_complete (nc->service, err);if (nc->connect)local_connect_cb (nc, err);
@@ -291,7 +290,7 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,bnep_if_up (nc->dev); -network_connected (nc->peer->device, nc->id,0 ); +service_connecting_complete (nc->service,0 );if (nc->connect)local_connect_cb (nc,0 );
@@ -432,7 +431,7 @@ static DBusMessage *local_connect(DBusConnection *conn,if (nc && nc->connect)return btd_error_busy (msg); - err =connection_connect (peer->device, id); + err =connection_connect (nc->service);if (err <0 )return btd_error_failed (msg,strerror (-err));
@@ -446,24 +445,17 @@ static DBusMessage *local_connect(DBusConnection *conn, }/* Connect and initiate BNEP session */ -int connection_connect (struct btd_device *device,uint16_t id) +int connection_connect (struct btd_service *service) { -struct network_peer *peer; -struct network_conn *nc; +struct network_conn *nc =service_get_user_data (service); +struct network_peer *peer = nc->peer; +uint16_t id =get_service_id (service);GError *err =NULL ;const bdaddr_t *src;const bdaddr_t *dst;DBG ("id %u" , id); - peer =find_peer (peers, device); -if (!peer) -return -ENOENT ; - - nc =find_connection (peer->connections, id); -if (!nc) -return -ENOTSUP ; -if (nc->state !=DISCONNECTED )return -EALREADY ;
@@ -487,18 +479,9 @@ int connection_connect(struct btd_device *device, uint16_t id)return 0 ; } -int connection_disconnect (struct btd_device *device,uint16_t id) +int connection_disconnect (struct btd_service *service) { -struct network_peer *peer; -struct network_conn *nc; - - peer =find_peer (peers, device); -if (!peer) -return -ENOENT ; - - nc =find_connection (peer->connections, id); -if (!nc) -return -ENOTSUP ; +struct network_conn *nc =service_get_user_data (service);if (nc->state ==DISCONNECTED )return 0 ;
@@ -521,7 +504,7 @@ static DBusMessage *local_disconnect(DBusConnection *conn,if (nc->state ==DISCONNECTED )continue ; - err =connection_disconnect (peer->device, nc->id); + err =connection_disconnect (nc->service);if (err <0 )return btd_error_failed (msg,strerror (-err));
profiles/network/connection.h +2 -2
@@ -23,5 +23,5 @@int connection_register (struct btd_service *service);void connection_unregister (struct btd_service *service); -int connection_connect (struct btd_device *device,uint16_t id); -int connection_disconnect (struct btd_device *device,uint16_t id); +int connection_connect (struct btd_service *service); +int connection_disconnect (struct btd_service *service);
profiles/network/manager.c +6 -73
125 lines not on this page · raw message
profiles/network/manager.h deleted +0 -25
@@ -1,25 +0,0 @@ -/* -* -* BlueZ - Bluetooth protocol stack for Linux -* -* Copyright (C) 2004-2010 Marcel Holtmann <[email protected]> -* -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -* -*/ - -void network_connected (struct btd_device *dev,int id,int err); -void network_disconnected (struct btd_device *dev,int id,int err);
src/device.c +26 -16
110 lines not on this page · raw message
src/device.h +0 -5
@@ -122,10 +122,5 @@ bool device_remove_svc_complete_callback(struct btd_device *dev,struct btd_profile ; -void device_profile_connected (struct btd_device *dev, -struct btd_profile *profile,int err); -void device_profile_disconnected (struct btd_device *dev, -struct btd_profile *profile,int err); -void btd_device_init (void );void btd_device_cleanup (void );
src/profile.c +18 -11
@@ -553,6 +553,7 @@ struct ext_io {guint io_id;struct btd_adapter *adapter;struct btd_device *device; +struct btd_service *service;bool resolving;bool connected;
@@ -684,6 +685,9 @@ static void ext_io_destroy(gpointer p)if (ext_io->device)btd_device_unref (ext_io->device); +if (ext_io->service) +btd_service_unref (ext_io->service); +g_free (ext_io); }
@@ -708,7 +712,7 @@ static gboolean ext_io_disconnected(GIOChannel *io, GIOCondition cond,DBG ("%s disconnected from %s" , ext->name, addr); drop: -device_profile_disconnected (conn->device, &ext->p,0 ); +service_disconnecting_complete (conn->service,0 ); ext->conns =g_slist_remove (ext->conns, conn);ext_io_destroy (conn);return FALSE;
@@ -730,7 +734,7 @@ static void new_conn_reply(DBusPendingCall *call, void *user_data) conn->pending =NULL ;if (!dbus_error_is_set (&err)) { -device_profile_connected (conn->device, &ext->p,0 ); +service_connecting_complete (conn->service,0 ); conn->connected = true;return ; }
@@ -738,7 +742,7 @@ static void new_conn_reply(DBusPendingCall *call, void *user_data)error ("%s replied with an error: %s, %s" , ext->name, err.name, err.message); -device_profile_connected (conn->device, &ext->p, -ECONNREFUSED ); +service_connecting_complete (conn->service, -ECONNREFUSED );if (dbus_error_has_name (&err,DBUS_ERROR_NO_REPLY ))ext_cancel (ext);
@@ -765,14 +769,14 @@ static void disconn_reply(DBusPendingCall *call, void *user_data) conn->pending =NULL ;if (!dbus_error_is_set (&err)) { -device_profile_disconnected (conn->device, &ext->p,0 ); +service_disconnecting_complete (conn->service,0 ); goto disconnect; }error ("%s replied with an error: %s, %s" , ext->name, err.name, err.message); -device_profile_disconnected (conn->device, &ext->p, -ECONNREFUSED ); +service_disconnecting_complete (conn->service, -ECONNREFUSED );if (dbus_error_has_name (&err,DBUS_ERROR_NO_REPLY ))ext_cancel (ext);
@@ -948,8 +952,7 @@ static void ext_connect(GIOChannel *io, GError *err, gpointer user_data)return ; drop: -device_profile_connected (conn->device, &ext->p, - err ? -err->code : -EIO ); +service_connecting_complete (conn->service, err ? -err->code : -EIO );if (io_err)g_error_free (io_err); ext->conns =g_slist_remove (ext->conns, conn);
@@ -1531,7 +1534,7 @@ static void record_cb(sdp_list_t *recs, int err, gpointer user_data)return ; failed: -device_profile_connected (conn->device, &ext->p, err); +service_connecting_complete (conn->service, err); ext->conns =g_slist_remove (ext->conns, conn);ext_io_destroy (conn); }
@@ -1553,8 +1556,10 @@ static int resolve_service(struct ext_io *conn, const bdaddr_t *src,return err; } -static int ext_connect_dev (struct btd_device *dev,struct btd_profile *profile) +static int ext_connect_dev (struct btd_service *service) { +struct btd_device *dev =service_get_device (service); +struct btd_profile *profile =service_get_profile (service);struct btd_adapter *adapter;struct ext_io *conn;struct ext_profile *ext;
@@ -1588,6 +1593,7 @@ static int ext_connect_dev(struct btd_device *dev, struct btd_profile *profile) conn->adapter =btd_adapter_ref (adapter); conn->device =btd_device_ref (dev); + conn->service =btd_service_ref (service); ext->conns =g_slist_append (ext->conns, conn);
@@ -1630,9 +1636,10 @@ static int send_disconn_req(struct ext_profile *ext, struct ext_io *conn)return 0 ; } -static int ext_disconnect_dev (struct btd_device *dev, -struct btd_profile *profile) +static int ext_disconnect_dev (struct btd_service *service) { +struct btd_device *dev =service_get_device (service); +struct btd_profile *profile =service_get_profile (service);struct ext_profile *ext;struct ext_io *conn;int err;
src/profile.h +2 -4
@@ -39,10 +39,8 @@ struct btd_profile {int (*device_probe) (struct btd_service *service);void (*device_remove) (struct btd_service *service); -int (*connect) (struct btd_device *device, -struct btd_profile *profile); -int (*disconnect) (struct btd_device *device, -struct btd_profile *profile); +int (*connect) (struct btd_service *service); +int (*disconnect) (struct btd_service *service);int (*adapter_probe) (struct btd_profile *p,struct btd_adapter *adapter);
Signature · 1 line
1.8.1.4
Re: [RFC v0 01/11] core: Add btd_service to represent device services
In reply to Mikel AstizHi Mikel,
src/service.c line 64
Quoted 7 lines · Mikel Astiz
src/service.c new file +7
-0+static char *str_state[] = { +"SERVICE_STATE_UNAVAILABLE" , +"SERVICE_STATE_DISCONNECTED" , +"SERVICE_STATE_CONNECTING" , +"SERVICE_STATE_CONNECTED" , +"SERVICE_STATE_DISCONNECTING" , +};
I'd rather have a separate state2str function with a switch statement than this array that relies on matching the order of states in the state enum. Also, you seem to have forgotten the const specifier that should be used for strings like this (I'm pointing it out since it also applies to the return type of the state2str function).
Quoted 20 lines
src/service.c new file +20
-0+struct btd_device *service_get_device (struct btd_service *service) +{ +return service->device; +} + +struct btd_profile *service_get_profile (struct btd_service *service) +{ +return service->profile; +} + +void service_set_user_data (struct btd_service *service,void *user_data) +{ +assert (service->state ==SERVICE_STATE_UNAVAILABLE ); + service->user_data = user_data; +} + +void *service_get_user_data (struct btd_service *service) +{ +return service->user_data; +}
src/service.c line 95
Quoted 10 lines
src/service.c new file +10
-0+ +int service_get_error (struct btd_service *service) +{ +return service->err; +} + +service_state_t service_get_state (struct btd_service *service) +{ +return service->state; +}
Why are these functions not prefixed with btd_?
Quoted 41 lines
src/service.c new file +41
-0+void service_probed (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_UNAVAILABLE ); +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} + +void service_connecting (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_DISCONNECTED ); + service->err =0 ; +service_set_state (service,SERVICE_STATE_CONNECTING ); +} + +void service_connecting_complete (struct btd_service *service,int err) +{ +if (service->state !=SERVICE_STATE_DISCONNECTED && + service->state !=SERVICE_STATE_CONNECTING ) +return ; + + service->err = err; + +if (err ==0 ) +service_set_state (service,SERVICE_STATE_CONNECTED ); +else +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} + +void service_disconnecting (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_CONNECTING || + service->state ==SERVICE_STATE_CONNECTED ); + service->err =0 ; +service_set_state (service,SERVICE_STATE_DISCONNECTING ); +} + +void service_disconnecting_complete (struct btd_service *service,int err) +{ +if (service->state !=SERVICE_STATE_CONNECTED && + service->state !=SERVICE_STATE_DISCONNECTING ) +return ; +
src/service.c line 202
Quoted 10 lines
src/service.c new file +10
-0+ service->err = err; +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} + +void service_unavailable (struct btd_service *service) +{ + service->profile =NULL ; + service->err =0 ; +service_set_state (service,SERVICE_STATE_UNAVAILABLE ); +}
Why aren't these function names prefixed with btd_?
Johan
Re: [RFC v0 02/11] device: Use btd_service to represent profiles
In reply to Mikel AstizHi Mikel,
src/device.c static int device_browse_primary(struct btd_device *device, DBusMessage *msg, · line 224
Quoted 4 lines · Mikel Astiz
src/device.c +4
-0+static gint service_profile_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a; +struct btd_profile *profile = (gpointer ) b;
Instead of this explicit casting why not declare the local variables const too?
Johan
Re: [RFC v0 03/11] device: Replace connected_profiles with btd_service
In reply to Mikel AstizHi Mikel,
src/device.c static gint service_profile_cmp(gconstpointer a, gconstpointer b) · line 233
Quoted 3 lines · Mikel Astiz
src/device.c +3
-0+static gint service_state_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a;
Couldn't you just declare the local variable const to avoid the ugly cast?
src/device.c static gint service_profile_cmp(gconstpointer a, gconstpointer b) · line 234
Quoted 1 line
src/device.c +1
-0+service_state_t state = (service_state_t )GPOINTER_TO_INT (b);
I think it'd be cleaner to just have:
const service_state_t *state = b;
src/device.c static gint service_profile_cmp(gconstpointer a, gconstpointer b) · line 236
Quoted 1 line
src/device.c +1
-0+if (service_get_state (service) == state)
And this would then become:
if (service_get_state(service) == *state)
Btw, why isn't service_state_t prefixed with btd_?
Johan
Re: [RFC v0 05/11] device: Replace pending profile list with services
In reply to Mikel AstizHi Mikel,
src/device.c static struct btd_service *find_connectable_service(struct btd_device *dev, · line 1223
Quoted 5 lines · Mikel Astiz
src/device.c +3
-1+static gint service_prio_cmp (gconstpointer a,gconstpointer b) { -const struct btd_profile *p1 = a, *p2 = b; +struct btd_service *s1 = (gpointer ) a; +struct btd_service *s2 = (gpointer ) b;
Again, adding const specifiers here would help avoid the explicit casting.
Johan
Re: [RFC v0 01/11] core: Add btd_service to represent device services
In reply to Johan HedbergHi Johan,
Quoted 16 lines · Johan Hedberg
Hi Mikel,
src/service.c line 64
Quoted 7 lines · Mikel Astiz
src/service.c new file +7
-0+static char *str_state[] = { +"SERVICE_STATE_UNAVAILABLE" , +"SERVICE_STATE_DISCONNECTED" , +"SERVICE_STATE_CONNECTING" , +"SERVICE_STATE_CONNECTED" , +"SERVICE_STATE_DISCONNECTING" , +};I'd rather have a separate state2str function with a switch statement than this array that relies on matching the order of states in the state enum. Also, you seem to have forgotten the const specifier that should be used for strings like this (I'm pointing it out since it also applies to the return type of the state2str function).
Agreed.
Quoted 79 lines
Quoted 21 lines
src/service.c new file +20
-0+struct btd_device *service_get_device (struct btd_service *service) +{ +return service->device; +} + +struct btd_profile *service_get_profile (struct btd_service *service) +{ +return service->profile; +} + +void service_set_user_data (struct btd_service *service,void *user_data) +{ +assert (service->state ==SERVICE_STATE_UNAVAILABLE ); + service->user_data = user_data; +} + +void *service_get_user_data (struct btd_service *service) +{ +return service->user_data; +}src/service.c line 95
Quoted 10 lines
src/service.c new file +10
-0+ +int service_get_error (struct btd_service *service) +{ +return service->err; +} + +service_state_t service_get_state (struct btd_service *service) +{ +return service->state; +}Why are these functions not prefixed with
btd_?Quoted 45 lines
src/service.c new file +45
-0+void service_probed (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_UNAVAILABLE ); +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} + +void service_connecting (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_DISCONNECTED ); + service->err =0 ; +service_set_state (service,SERVICE_STATE_CONNECTING ); +} + +void service_connecting_complete (struct btd_service *service,int err) +{ +if (service->state !=SERVICE_STATE_DISCONNECTED && + service->state !=SERVICE_STATE_CONNECTING ) +return ; + + service->err = err; + +if (err ==0 ) +service_set_state (service,SERVICE_STATE_CONNECTED ); +else +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} + +void service_disconnecting (struct btd_service *service) +{ +assert (service->state ==SERVICE_STATE_CONNECTING || + service->state ==SERVICE_STATE_CONNECTED ); + service->err =0 ; +service_set_state (service,SERVICE_STATE_DISCONNECTING ); +} + +void service_disconnecting_complete (struct btd_service *service,int err) +{ +if (service->state !=SERVICE_STATE_CONNECTED && + service->state !=SERVICE_STATE_DISCONNECTING ) +return ; + + service->err = err; +service_set_state (service,SERVICE_STATE_DISCONNECTED ); +} +
Quoted 8 lines
src/service.c line 202
Quoted 6 lines
src/service.c new file +6
-0+void service_unavailable (struct btd_service *service) +{ + service->profile =NULL ; + service->err =0 ; +service_set_state (service,SERVICE_STATE_UNAVAILABLE ); +}Why aren't these function names prefixed with
btd_?
I had a look at some other existing headers such as device.h and didn't understand the criteria to add or not the prefix.
I'll add to it to all functions in the next revision.
Cheers,
Mikel
Re: [RFC v0 01/11] core: Add btd_service to represent device services
Hi Mikel,
Quoted 9 lines · Mikel Astiz
Quoted 8 lines
src/service.c line 202
Quoted 6 lines
src/service.c new file +6
-0+void service_unavailable (struct btd_service *service) +{ + service->profile =NULL ; + service->err =0 ; +service_set_state (service,SERVICE_STATE_UNAVAILABLE ); +}Why aren't these function names prefixed with
btd_?
Quoted 4 lines
I had a look at some other existing headers such as
device.hand didn't understand the criteria to add or not the prefix.I'll add to it to all functions in the next revision.
In principle any symbols that should be accessible from plugins should be prefixed with btd_. There are many cases which do not follow this in the old code, but we're trying to gradually fix it.
Johan
Re: [RFC v0 02/11] device: Use btd_service to represent profiles
In reply to Johan HedbergHi Johan,
Quoted 10 lines · Johan Hedberg
Hi Mikel,
src/device.c static int device_browse_primary(struct btd_device *device, DBusMessage *msg, · line 224
Quoted 4 lines · Mikel Astiz
src/device.c +4
-0+static gint service_profile_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a; +struct btd_profile *profile = (gpointer ) b;Instead of this explicit casting why not declare the local variables const too?
In order to do this (at least in the case of b) I'd have to add a const version of service_get_profile(). However, profile.h doesn't define any semantics for a const profile (and neither does device.h), so I would discourage adding a function such as:
struct btd_profile *service_get_profile(const struct btd_service *service);
I therefore though it wasn't worth making the API more complex in order to have such a comparison function. If you still want this, a possible alternative would be to extend the API with:
const struct btd_profile *service_get_profile_const(const struct btd_service *service);
const struct btd_device *service_get_device_const(const struct btd_service *service);
Cheers,
Mikel
Re: [RFC v0 03/11] device: Replace connected_profiles with btd_service
In reply to Johan HedbergHi Johan,
Quoted 14 lines · Johan Hedberg
Hi Mikel,
src/device.c static gint service_profile_cmp(gconstpointer a, gconstpointer b) · line 233
Quoted 3 lines · Mikel Astiz
src/device.c +3
-0+static gint service_state_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a;Couldn't you just declare the local variable const to avoid the ugly cast?
Quoted 1 line
+
service_state_tstate = (service_state_t)GPOINTER_TO_INT(b);I think it'd be cleaner to just have:
Quoted 7 lines
const service_state_t *state = b;Quoted 1 line
+ if (
service_get_state(service)== state)And this would then become:
if (service_get_state(service) == *state)
I don't think these are equivalent, unless the caller is also changed to use "&state" instead of "GINT_TO_POINTER(state)".
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Re: [RFC v0 03/11] device: Replace connected_profiles with btd_service
Hi Lizardo,
Quoted 14 lines · Anderson Lizardo
Quoted 14 lines · Mikel Astiz
src/device.c static gint service_profile_cmp(gconstpointer a, gconstpointer b) · line 233
Quoted 3 lines
src/device.c +3
-0+static gint service_state_cmp (gconstpointer a,gconstpointer b) +{ +struct btd_service *service = (gpointer ) a;Couldn't you just declare the local variable const to avoid the ugly cast?
Quoted 1 line
+
service_state_tstate = (service_state_t)GPOINTER_TO_INT(b);I think it'd be cleaner to just have:
const service_state_t *state = b;
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
+ if (
service_get_state(service)== state)And this would then become:
if (service_get_state(service) == *state)I don't think these are equivalent, unless the caller is also changed to use "&state" instead of "
GINT_TO_POINTER(state)".
You're right, and that's what I (incorrectly) thought the original code was doing.
Johan