Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 4/6] media-api: Update documentation of MediaPlayer interface
From: Luiz Augusto von Dentz @ 2012-11-27 12:51 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354020685-17028-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 doc/media-api.txt | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)

diff --git a/doc/media-api.txt b/doc/media-api.txt
index b4f2fc6..a814b60 100644
--- a/doc/media-api.txt
+++ b/doc/media-api.txt
@@ -133,24 +133,12 @@ Object path	freely definable (Target role)
 		[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/playerX
 		(Controller role)
 
-Methods		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-		dict GetTrack()
+Methods		dict GetTrack()
 
 			Returns known metadata of the current track.
 
 			See TrackChanged for possible values.
 
-		void SetProperty(string property, variant value)
-
-			Changes the value of the specified property. Only
-			properties that are listed as read-write can be changed.
-
-			On success this will emit a PropertyChanged signal.
-
 		void Release()
 
 			This method gets called when the service daemon
@@ -159,12 +147,7 @@ Methods		dict GetProperties()
 			player, because when this method gets called it has
 			already been unregistered.
 
-Signals		PropertyChanged(string setting, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-		TrackChanged(dict metadata)
+Signals		TrackChanged(dict metadata)
 
 			This signal indicates that current track has changed.
 			All available metadata for the new track shall be set
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 3/6] media: Convert target MediaPlayer interface to use D-Bus Properties
From: Luiz Augusto von Dentz @ 2012-11-27 12:51 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354020685-17028-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 profiles/audio/media.c | 100 ++++++++++++++++++++++---------------------------
 1 file changed, 45 insertions(+), 55 deletions(-)

diff --git a/profiles/audio/media.c b/profiles/audio/media.c
index 588d61e..f2fba7b 100644
--- a/profiles/audio/media.c
+++ b/profiles/audio/media.c
@@ -96,7 +96,7 @@ struct media_player {
 	GHashTable		*settings;	/* Player settings */
 	GHashTable		*track;		/* Player current track */
 	guint			watch;
-	guint			property_watch;
+	guint			properties_watch;
 	guint			track_watch;
 	char			*status;
 	uint32_t		position;
@@ -916,7 +916,7 @@ static void media_player_free(gpointer data)
 	}
 
 	g_dbus_remove_watch(conn, mp->watch);
-	g_dbus_remove_watch(conn, mp->property_watch);
+	g_dbus_remove_watch(conn, mp->properties_watch);
 	g_dbus_remove_watch(conn, mp->track_watch);
 
 	if (mp->track)
@@ -980,6 +980,7 @@ static const char *get_setting(const char *key, void *user_data)
 static int set_setting(const char *key, const char *value, void *user_data)
 {
 	struct media_player *mp = user_data;
+	const char *iface = MEDIA_PLAYER_INTERFACE;
 	DBusMessage *msg;
 	DBusMessageIter iter, var;
 
@@ -989,14 +990,14 @@ static int set_setting(const char *key, const char *value, void *user_data)
 		return -EINVAL;
 
 	msg = dbus_message_new_method_call(mp->sender, mp->path,
-						MEDIA_PLAYER_INTERFACE,
-						"SetProperty");
+					DBUS_INTERFACE_PROPERTIES, "Set");
 	if (msg == NULL) {
 		error("Couldn't allocate D-Bus message");
 		return -ENOMEM;
 	}
 
 	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &iface);
 	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key);
 
 	dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT,
@@ -1218,29 +1219,55 @@ static gboolean set_player_property(struct media_player *mp, const char *key,
 	return TRUE;
 }
 
-static gboolean property_changed(DBusConnection *connection, DBusMessage *msg,
+static gboolean parse_player_properties(struct media_player *mp,
+							DBusMessageIter *iter)
+{
+	DBusMessageIter dict;
+	int ctype;
+
+	ctype = dbus_message_iter_get_arg_type(iter);
+	if (ctype != DBUS_TYPE_ARRAY)
+		return FALSE;
+
+	dbus_message_iter_recurse(iter, &dict);
+
+	while ((ctype = dbus_message_iter_get_arg_type(&dict)) !=
+							DBUS_TYPE_INVALID) {
+		DBusMessageIter entry;
+		const char *key;
+
+		if (ctype != DBUS_TYPE_DICT_ENTRY)
+			return FALSE;
+
+		dbus_message_iter_recurse(&dict, &entry);
+		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
+			return FALSE;
+
+		dbus_message_iter_get_basic(&entry, &key);
+		dbus_message_iter_next(&entry);
+
+		if (set_player_property(mp, key, &entry) == FALSE)
+			return FALSE;
+
+		dbus_message_iter_next(&dict);
+	}
+
+	return TRUE;
+}
+
+static gboolean properties_changed(DBusConnection *connection, DBusMessage *msg,
 							void *user_data)
 {
 	struct media_player *mp = user_data;
 	DBusMessageIter iter;
-	const char *property;
 
 	DBG("sender=%s path=%s", mp->sender, mp->path);
 
 	dbus_message_iter_init(msg, &iter);
 
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) {
-		error("Unexpected signature in %s.%s signal",
-					dbus_message_get_interface(msg),
-					dbus_message_get_member(msg));
-		return TRUE;
-	}
-
-	dbus_message_iter_get_basic(&iter, &property);
-
 	dbus_message_iter_next(&iter);
 
-	set_player_property(mp, property, &iter);
+	parse_player_properties(mp, &iter);
 
 	return TRUE;
 }
@@ -1407,10 +1434,9 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
 	mp->watch = g_dbus_add_disconnect_watch(conn, sender,
 						media_player_exit, mp,
 						NULL);
-	mp->property_watch = g_dbus_add_signal_watch(conn, sender,
+	mp->properties_watch = g_dbus_add_properties_watch(conn, sender,
 						path, MEDIA_PLAYER_INTERFACE,
-						"PropertyChanged",
-						property_changed,
+						properties_changed,
 						mp, NULL);
 	mp->track_watch = g_dbus_add_signal_watch(conn, sender,
 						path, MEDIA_PLAYER_INTERFACE,
@@ -1439,42 +1465,6 @@ static struct media_player *media_player_create(struct media_adapter *adapter,
 	return mp;
 }
 
-static gboolean parse_player_properties(struct media_player *mp,
-							DBusMessageIter *iter)
-{
-	DBusMessageIter dict;
-	int ctype;
-
-	ctype = dbus_message_iter_get_arg_type(iter);
-	if (ctype != DBUS_TYPE_ARRAY)
-		return FALSE;
-
-	dbus_message_iter_recurse(iter, &dict);
-
-	while ((ctype = dbus_message_iter_get_arg_type(&dict)) !=
-							DBUS_TYPE_INVALID) {
-		DBusMessageIter entry;
-		const char *key;
-
-		if (ctype != DBUS_TYPE_DICT_ENTRY)
-			return FALSE;
-
-		dbus_message_iter_recurse(&dict, &entry);
-		if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING)
-			return FALSE;
-
-		dbus_message_iter_get_basic(&entry, &key);
-		dbus_message_iter_next(&entry);
-
-		if (set_player_property(mp, key, &entry) == FALSE)
-			return FALSE;
-
-		dbus_message_iter_next(&dict);
-	}
-
-	return TRUE;
-}
-
 static DBusMessage *register_player(DBusConnection *conn, DBusMessage *msg,
 					void *data)
 {
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 2/6] audio: Convert controller MediaPlayer interface to use D-Bus Properties
From: Luiz Augusto von Dentz @ 2012-11-27 12:51 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354020685-17028-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 profiles/audio/player.c | 222 +++++++++++++++++++++++-------------------------
 1 file changed, 106 insertions(+), 116 deletions(-)

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index e83b761..34b1f20 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -50,7 +50,7 @@ struct player_callback {
 };
 
 struct pending_req {
-	DBusMessage *msg;
+	GDBusPendingPropertySet id;
 	const char *key;
 	const char *value;
 };
@@ -67,13 +67,6 @@ struct media_player {
 	GSList			*pending;
 };
 
-static void append_settings(void *key, void *value, void *user_data)
-{
-	DBusMessageIter *dict = user_data;
-
-	dict_append_entry(dict, key, DBUS_TYPE_STRING, &value);
-}
-
 static void append_metadata(void *key, void *value, void *user_data)
 {
 	DBusMessageIter *dict = user_data;
@@ -89,39 +82,6 @@ static void append_metadata(void *key, void *value, void *user_data)
 	dict_append_entry(dict, key, DBUS_TYPE_STRING, &value);
 }
 
-static DBusMessage *media_player_get_properties(DBusConnection *conn,
-						DBusMessage *msg, void *data)
-{
-	struct media_player *mp = data;
-	DBusMessage *reply;
-	DBusMessageIter iter, dict;
-	uint32_t position;
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
-
-	dbus_message_iter_init_append(reply, &iter);
-
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-					DBUS_TYPE_STRING_AS_STRING
-					DBUS_TYPE_VARIANT_AS_STRING
-					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
-					&dict);
-
-	position = media_player_get_position(mp);
-	dict_append_entry(&dict, "Position", DBUS_TYPE_UINT32, &position);
-
-	dict_append_entry(&dict, "Status", DBUS_TYPE_STRING, &mp->status);
-
-	g_hash_table_foreach(mp->settings, append_settings, &dict);
-
-	dbus_message_iter_close_container(&iter, &dict);
-
-	return reply;
-}
-
 static DBusMessage *media_player_get_track(DBusConnection *conn,
 						DBusMessage *msg, void *data)
 {
@@ -164,111 +124,142 @@ static struct pending_req *find_pending(struct media_player *mp,
 	return NULL;
 }
 
-static struct pending_req *pending_new(DBusMessage *msg, const char *key,
-							const char *value)
+static struct pending_req *pending_new(GDBusPendingPropertySet id,
+					const char *key, const char *value)
 {
 	struct pending_req *p;
 
 	p = g_new0(struct pending_req, 1);
-	p->msg = dbus_message_ref(msg);
+	p->id = id;
 	p->key = key;
 	p->value = value;
 
 	return p;
 }
 
-static DBusMessage *player_set_setting(struct media_player *mp,
-					DBusMessage *msg, const char *key,
-					const char *value)
+static gboolean get_position(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
 {
-	struct player_callback *cb = mp->cb;
-	struct pending_req *p;
+	struct media_player *mp = data;
 
-	if (cb == NULL || cb->cbs->set_setting == NULL)
-		return btd_error_not_supported(msg);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &mp->position);
 
-	p = find_pending(mp, key);
-	if (p != NULL)
-		return btd_error_in_progress(msg);
+	return TRUE;
+}
 
-	if (!cb->cbs->set_setting(mp, key, value, cb->user_data))
-		return btd_error_invalid_args(msg);
+static gboolean status_exists(const GDBusPropertyTable *property, void *data)
+{
+	struct media_player *mp = data;
+
+	return mp->status != NULL;
+}
 
-	p = pending_new(msg, key, value);
+static gboolean get_status(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct media_player *mp = data;
 
-	mp->pending = g_slist_append(mp->pending, p);
+	if (mp->status == NULL)
+		return FALSE;
 
-	return NULL;
+	DBG("%s", mp->status);
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &mp->status);
+
+	return TRUE;
 }
 
-static DBusMessage *media_player_set_property(DBusConnection *conn,
-						DBusMessage *msg, void *data)
+static gboolean setting_exists(const GDBusPropertyTable *property, void *data)
 {
 	struct media_player *mp = data;
-	DBusMessageIter iter;
-	DBusMessageIter var;
-	const char *key, *value, *curval;
 
-	if (!dbus_message_iter_init(msg, &iter))
-		return btd_error_invalid_args(msg);
+	return g_hash_table_contains(mp->settings, property->name);
+}
 
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING)
-		return btd_error_invalid_args(msg);
+static gboolean get_setting(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct media_player *mp = data;
+	const char *value;
 
-	dbus_message_iter_get_basic(&iter, &key);
-	dbus_message_iter_next(&iter);
+	value = g_hash_table_lookup(mp->settings, property->name);
+	if (value == NULL)
+		return FALSE;
 
-	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT)
-		return btd_error_invalid_args(msg);
+	DBG("%s %s", property->name, value);
 
-	dbus_message_iter_recurse(&iter, &var);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
-	if (dbus_message_iter_get_arg_type(&var) != DBUS_TYPE_STRING)
-		return btd_error_invalid_args(msg);
+	return TRUE;
+}
 
-	dbus_message_iter_get_basic(&var, &value);
+static void player_set_setting(struct media_player *mp,
+					GDBusPendingPropertySet id,
+					const char *key, const char *value)
+{
+	struct player_callback *cb = mp->cb;
+	struct pending_req *p;
 
-	if (g_strcmp0(key, "Equalizer") != 0 &&
-				g_strcmp0(key, "Repeat") != 0 &&
-				g_strcmp0(key, "Shuffle") != 0 &&
-				g_strcmp0(key, "Scan") != 0)
-		return btd_error_invalid_args(msg);
+	if (cb == NULL || cb->cbs->set_setting == NULL)
+		return g_dbus_pending_property_error(id,
+					ERROR_INTERFACE ".NotSupported",
+					"Operation is not supported");
 
-	curval = g_hash_table_lookup(mp->settings, key);
-	if (g_strcmp0(curval, value) == 0)
-		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+	p = find_pending(mp, key);
+	if (p != NULL)
+		return g_dbus_pending_property_error(id,
+					ERROR_INTERFACE ".InProgress",
+					"Operation already in progress");
 
-	return player_set_setting(mp, msg, key, value);
+	if (!cb->cbs->set_setting(mp, key, value, cb->user_data))
+		return g_dbus_pending_property_error(id,
+					ERROR_INTERFACE ".InvalidArguments",
+					"Invalid arguments in method call");
+
+	p = pending_new(id, key, value);
+
+	mp->pending = g_slist_append(mp->pending, p);
+}
+
+static void set_setting(const GDBusPropertyTable *property,
+			DBusMessageIter *iter, GDBusPendingPropertySet id,
+			void *data)
+{
+	struct media_player *mp = data;
+	const char *value;
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
+		return g_dbus_pending_property_error(id,
+					ERROR_INTERFACE ".InvalidArguments",
+					"Invalid arguments in method call");
+
+	dbus_message_iter_get_basic(iter, &value);
+
+	player_set_setting(mp, id, property->name, value);
 }
 
 static const GDBusMethodTable media_player_methods[] = {
-	{ GDBUS_METHOD("GetProperties",
-			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-			media_player_get_properties) },
 	{ GDBUS_METHOD("GetTrack",
 			NULL, GDBUS_ARGS({ "metadata", "a{sv}" }),
 			media_player_get_track) },
-	{ GDBUS_ASYNC_METHOD("SetProperty",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" }),
-			NULL, media_player_set_property) },
 	{ }
 };
 
 static const GDBusSignalTable media_player_signals[] = {
-	{ GDBUS_SIGNAL("PropertyChanged",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
 	{ GDBUS_SIGNAL("TrackChanged",
 			GDBUS_ARGS({ "metadata", "a{sv}" })) },
 	{ }
 };
 
-static void pending_free(void *data)
-{
-	struct pending_req *p = data;
-
-	dbus_message_unref(p->msg);
-	g_free(p);
-}
+static const GDBusPropertyTable media_player_properties[] = {
+	{ "Position", "u", get_position },
+	{ "Status", "s", get_status, NULL, status_exists },
+	{ "Equalizer", "s", get_setting, set_setting, setting_exists },
+	{ "Repeat", "s", get_setting, set_setting, setting_exists },
+	{ "Shuffle", "s", get_setting, set_setting, setting_exists },
+	{ "Scan", "s", get_setting, set_setting, setting_exists },
+	{ }
+};
 
 void media_player_destroy(struct media_player *mp)
 {
@@ -286,7 +277,7 @@ void media_player_destroy(struct media_player *mp)
 	if (mp->process_id > 0)
 		g_source_remove(mp->process_id);
 
-	g_slist_free_full(mp->pending, pending_free);
+	g_slist_free_full(mp->pending, g_free);
 
 	g_timer_destroy(mp->progress);
 	g_free(mp->cb);
@@ -311,7 +302,7 @@ struct media_player *media_player_controller_create(const char *path)
 					mp->path, MEDIA_PLAYER_INTERFACE,
 					media_player_methods,
 					media_player_signals,
-					NULL, mp, NULL)) {
+					media_player_properties, mp, NULL)) {
 		error("D-Bus failed to register %s path", mp->path);
 		media_player_destroy(mp);
 		return NULL;
@@ -345,8 +336,8 @@ void media_player_set_position(struct media_player *mp, uint32_t position)
 	mp->position = position;
 	g_timer_start(mp->progress);
 
-	emit_property_changed(mp->path, MEDIA_PLAYER_INTERFACE, "Position",
-					DBUS_TYPE_UINT32, &mp->position);
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
+					MEDIA_PLAYER_INTERFACE, "Position");
 }
 
 void media_player_set_setting(struct media_player *mp, const char *key,
@@ -354,7 +345,6 @@ void media_player_set_setting(struct media_player *mp, const char *key,
 {
 	char *curval;
 	struct pending_req *p;
-	DBusMessage *reply;
 
 	DBG("%s: %s", key, value);
 
@@ -363,7 +353,8 @@ void media_player_set_setting(struct media_player *mp, const char *key,
 		if (p == NULL)
 			return;
 
-		reply = btd_error_failed(p->msg, value);
+		g_dbus_pending_property_error(p->id, ERROR_INTERFACE ".Failed",
+									value);
 		goto send;
 	}
 
@@ -372,9 +363,8 @@ void media_player_set_setting(struct media_player *mp, const char *key,
 		goto done;
 
 	g_hash_table_replace(mp->settings, g_strdup(key), g_strdup(value));
-
-	emit_property_changed(mp->path, MEDIA_PLAYER_INTERFACE, key,
-					DBUS_TYPE_STRING, &value);
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
+					MEDIA_PLAYER_INTERFACE, key);
 
 done:
 	p = find_pending(mp, key);
@@ -382,15 +372,15 @@ done:
 		return;
 
 	if (strcasecmp(value, p->value) == 0)
-		reply = g_dbus_create_reply(p->msg, DBUS_TYPE_INVALID);
+		g_dbus_pending_property_success(p->id);
 	else
-		reply = btd_error_not_supported(p->msg);
+		g_dbus_pending_property_error(p->id,
+					ERROR_INTERFACE ".NotSupported",
+					"Operation is not supported");
 
 send:
-	g_dbus_send_message(btd_get_dbus_connection(), reply);
-
 	mp->pending = g_slist_remove(mp->pending, p);
-	pending_free(p);
+	g_free(p);
 
 	return;
 }
@@ -410,8 +400,8 @@ void media_player_set_status(struct media_player *mp, const char *status)
 	g_free(mp->status);
 	mp->status = g_strdup(status);
 
-	emit_property_changed(mp->path, MEDIA_PLAYER_INTERFACE, "Status",
-					DBUS_TYPE_STRING, &status);
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
+					MEDIA_PLAYER_INTERFACE, "Status");
 
 	mp->position = media_player_get_position(mp);
 	g_timer_start(mp->progress);
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 1/6] gdbus: Add g_dbus_add_properties_watch function
From: Luiz Augusto von Dentz @ 2012-11-27 12:51 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Convenient function to create watches for D-Bus properties.
---
 gdbus/gdbus.h |  5 +++++
 gdbus/watch.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/gdbus/gdbus.h b/gdbus/gdbus.h
index ba49621..8b6dfe5 100644
--- a/gdbus/gdbus.h
+++ b/gdbus/gdbus.h
@@ -243,6 +243,11 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
 				const char *interface, const char *member,
 				GDBusSignalFunction function, void *user_data,
 				GDBusDestroyFunction destroy);
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy);
 gboolean g_dbus_remove_watch(DBusConnection *connection, guint tag);
 void g_dbus_remove_all_watches(DBusConnection *connection);
 
diff --git a/gdbus/watch.c b/gdbus/watch.c
index 1cd1211..9e4f994 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -752,6 +752,34 @@ guint g_dbus_add_signal_watch(DBusConnection *connection,
 	return cb->id;
 }
 
+guint g_dbus_add_properties_watch(DBusConnection *connection,
+				const char *sender, const char *path,
+				const char *interface,
+				GDBusSignalFunction function, void *user_data,
+				GDBusDestroyFunction destroy)
+{
+	struct filter_data *data;
+	struct filter_callback *cb;
+
+	data = filter_data_get(connection, signal_filter, sender, path,
+				DBUS_INTERFACE_PROPERTIES, "PropertiesChanged",
+				interface);
+	if (data == NULL)
+		return 0;
+
+	cb = filter_data_add_callback(data, NULL, NULL, function, destroy,
+					user_data);
+	if (cb == NULL)
+		return 0;
+
+	if (data->name != NULL && data->name_watch == 0)
+		data->name_watch = g_dbus_add_service_watch(connection,
+							data->name, NULL,
+							NULL, NULL, NULL);
+
+	return cb->id;
+}
+
 gboolean g_dbus_remove_watch(DBusConnection *connection, guint id)
 {
 	struct filter_data *data;
-- 
1.7.11.7


^ permalink raw reply related

* Re: eSCO latency configuration
From: Johan Hedberg @ 2012-11-27 11:12 UTC (permalink / raw)
  To: Arnaud Mouiche; +Cc: linux-bluetooth
In-Reply-To: <4E64AD1D.6000609@invoxia.com>

Hi Arnaud,

On Mon, Sep 05, 2011, Arnaud Mouiche wrote:
> What could be a way to add the feature without breaking any API
> 1) use the MTU of the socket or hdev ?
> 2) add hdev entry for sco latency (which can be configured with
> hciconfig like voice settings)
> 3) something else ...
> or
> 4) no one cares about latency...
> 
> PS: the same way, the retransmit effort is not configurable today.

I'm assuming this is for HFP or HSP? At least I'm not aware of other
significant profiles using (e)SCO. Since the HFP specification defines a
set of recommended parameter combinations I don't think we necessarily
need any user-space facing interface for this (with the exception of the
mSBC/CVSD codec selection which is needed for HFP 1.6).

Instead, the kernel could simply start with the S3 settings and fall
back to S2 and finally S1 if failures are encountered during the
connection setup. For mSBC the starting point would be T2 with a
fallback to T1 in case of failure. Do you agree that this would be an
acceptable solution?

Johan

^ permalink raw reply

* Re: [PATCH 7/7] event: Store link key infos in new keys file
From: Johan Hedberg @ 2012-11-27 11:03 UTC (permalink / raw)
  To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1354006193-7199-7-git-send-email-frederic.danis@linux.intel.com>

Hi Frederic,

On Tue, Nov 27, 2012, Frédéric Danis wrote:
> ---
>  src/event.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++------------
>  1 file changed, 47 insertions(+), 12 deletions(-)

After these patches there's the following leak:

==23252== 32,808 bytes in 1 blocks are definitely lost in loss record 210 of 210
==23252==    at 0x4A0883C: malloc (vg_replace_malloc.c:270)
==23252==    by 0x565E25F: __alloc_dir (opendir.c:199)
==23252==    by 0x175382: load_devices (adapter.c:2005)
==23252==    by 0x178E50: adapter_init (adapter.c:2896)
==23252==    by 0x17391E: btd_manager_register_adapter (manager.c:334)
==23252==    by 0x1883E1: mgmt_event.part.36 (mgmt.c:1081)
==23252==    by 0x4C78A74: g_main_context_dispatch (gmain.c:2715)
==23252==    by 0x4C78DA7: g_main_context_iterate.isra.24 (gmain.c:3290)
==23252==    by 0x4C791A1: g_main_loop_run (gmain.c:3484)
==23252==    by 0x121640: main (main.c:544)

That seems to be simple missing closedir() call. Didn't I already tell
you to always use valgrind?

Another problem with these is that I'm getting over a hundred unexpected
device objects which I didn't have before. It seems that this is because
you convert the classes file into the device storage instead of the
cache. It might be due to some other info as well though.

Johan

^ permalink raw reply

* [PATCH 7/7] event: Store link key infos in new keys file
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/event.c |   59 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 47 insertions(+), 12 deletions(-)

diff --git a/src/event.c b/src/event.c
index 7fc8f02..59da740 100644
--- a/src/event.c
+++ b/src/event.c
@@ -354,33 +354,68 @@ static int store_longtermkey(bdaddr_t *local, bdaddr_t *peer,
 	return err;
 }
 
+static void store_link_key(struct btd_adapter *adapter,
+				struct btd_device *device, uint8_t *key,
+				uint8_t type, uint8_t pin_length)
+{
+	char adapter_addr[18];
+	char device_addr[18];
+	char filename[PATH_MAX + 1];
+	GKeyFile *key_file;
+	char key_str[35];
+	char *str;
+	int i;
+	gsize length = 0;
+
+	ba2str(adapter_get_address(adapter), adapter_addr);
+	ba2str(device_get_address(device), device_addr);
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/keys", adapter_addr,
+								device_addr);
+	filename[PATH_MAX] = '\0';
+
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
+
+	key_str[0] = '0';
+	key_str[1] = 'x';
+	for (i = 0; i < 16; i++)
+		sprintf(key_str + 2 + (i * 2), "%2.2X", key[i]);
+
+	g_key_file_set_string(key_file, "LinkKey", "Key", key_str);
+
+	g_key_file_set_integer(key_file, "LinkKey", "Type", type);
+	g_key_file_set_integer(key_file, "LinkKey", "PINLength", pin_length);
+
+	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+	str = g_key_file_to_data(key_file, &length, NULL);
+	g_file_set_contents(filename, str, length, NULL);
+	g_free(str);
+
+	g_key_file_free(key_file);
+}
+
 int btd_event_link_key_notify(bdaddr_t *local, bdaddr_t *peer,
 				uint8_t *key, uint8_t key_type,
 				uint8_t pin_length)
 {
 	struct btd_adapter *adapter;
 	struct btd_device *device;
-	uint8_t peer_type;
-	int ret;
 
 	if (!get_adapter_and_device(local, peer, &adapter, &device, TRUE))
 		return -ENODEV;
 
 	DBG("storing link key of type 0x%02x", key_type);
 
-	peer_type = device_get_addr_type(device);
+	store_link_key(adapter, device, key, key_type, pin_length);
 
-	ret = write_link_key(local, peer, peer_type, key, key_type,
-								pin_length);
+	device_set_bonded(device, TRUE);
 
-	if (ret == 0) {
-		device_set_bonded(device, TRUE);
-
-		if (device_is_temporary(device))
-			device_set_temporary(device, FALSE);
-	}
+	if (device_is_temporary(device))
+		device_set_temporary(device, FALSE);
 
-	return ret;
+	return 0;
 }
 
 int btd_event_ltk_notify(bdaddr_t *local, bdaddr_t *peer, uint8_t bdaddr_type,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 6/7] adapter: Upload link keys from new storage
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

Remove read_link_key() from device_create, this moves to load_devices.
---
 src/adapter.c |  109 +++++++++++++++++++++++++--------------------------------
 src/device.c  |    6 ----
 2 files changed, 48 insertions(+), 67 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 32d3930..d473508 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -1765,31 +1765,35 @@ static int str2buf(const char *str, uint8_t *buf, size_t blen)
 	return 0;
 }
 
-static struct link_key_info *get_key_info(const char *addr, const char *value)
+static struct link_key_info *get_key_info(const char *local,
+						const char *peer)
 {
-	struct link_key_info *info;
-	char tmp[3];
-	long int l;
+	struct link_key_info *info = NULL;
+	char filename[PATH_MAX + 1];
+	GKeyFile *key_file;
+	char *str;
 
-	if (strlen(value) < 36) {
-		error("Unexpectedly short (%zu) link key line", strlen(value));
-		return NULL;
-	}
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/keys", local, peer);
 
-	info = g_new0(struct link_key_info, 1);
+	key_file = g_key_file_new();
+	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
-	str2ba(addr, &info->bdaddr);
+	str = g_key_file_get_string(key_file, "LinkKey", "Key", NULL);
+	if (!str || strlen(str) != 34)
+		goto failed;
 
-	str2buf(value, info->key, sizeof(info->key));
+	info = g_new0(struct link_key_info, 1);
+
+	str2ba(peer, &info->bdaddr);
+	str2buf(&str[2], info->key, sizeof(info->key));
 
-	memcpy(tmp, value + 33, 2);
-	info->type = (uint8_t) strtol(tmp, NULL, 10);
+	info->type = g_key_file_get_integer(key_file, "LinkKey", "Type", NULL);
+	info->pin_len = g_key_file_get_integer(key_file, "LinkKey", "PINLength",
+						NULL);
 
-	memcpy(tmp, value + 35, 2);
-	l = strtol(tmp, NULL, 10);
-	if (l < 0)
-		l = 0;
-	info->pin_len = l;
+failed:
+	g_free(str);
+	g_key_file_free(key_file);
 
 	return info;
 }
@@ -1830,34 +1834,6 @@ static struct smp_ltk_info *get_ltk_info(const char *addr, uint8_t bdaddr_type,
 	return ltk;
 }
 
-static void create_stored_device_from_linkkeys(char *key, char *value,
-							void *user_data)
-{
-	char address[18];
-	uint8_t bdaddr_type;
-	struct adapter_keys *keys = user_data;
-	struct btd_adapter *adapter = keys->adapter;
-	struct btd_device *device;
-	struct link_key_info *info;
-
-	if (sscanf(key, "%17s#%hhu", address, &bdaddr_type) < 2)
-		bdaddr_type = BDADDR_BREDR;
-
-	info = get_key_info(address, value);
-	if (info)
-		keys->keys = g_slist_append(keys->keys, info);
-
-	if (g_slist_find_custom(adapter->devices, address,
-					(GCompareFunc) device_address_cmp))
-		return;
-
-	device = device_create(adapter, address, bdaddr_type);
-	if (device) {
-		device_set_temporary(device, FALSE);
-		adapter->devices = g_slist_append(adapter->devices, device);
-	}
-}
-
 static void create_stored_device_from_ltks(char *key, char *value,
 							void *user_data)
 {
@@ -2010,18 +1986,6 @@ static void load_devices(struct btd_adapter *adapter)
 	textfile_foreach(filename, create_stored_device_from_primaries,
 								adapter);
 
-	create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "linkkeys");
-	textfile_foreach(filename, create_stored_device_from_linkkeys, &keys);
-
-	err = mgmt_load_link_keys(adapter->dev_id, keys.keys,
-							main_opts.debug_keys);
-	if (err < 0)
-		error("Unable to load link keys: %s (%d)",
-							strerror(-err), -err);
-
-	g_slist_free_full(keys.keys, g_free);
-	keys.keys = NULL;
-
 	create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "longtermkeys");
 	textfile_foreach(filename, create_stored_device_from_ltks, &keys);
 
@@ -2046,13 +2010,22 @@ static void load_devices(struct btd_adapter *adapter)
 
 	while ((entry = readdir(dir)) != NULL) {
 		struct btd_device *device;
+		struct link_key_info *key_info;
+		GSList *l;
 
 		if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
 			continue;
 
-		if (g_slist_find_custom(adapter->devices, entry->d_name,
-					(GCompareFunc) device_address_cmp))
-			continue;
+		key_info = get_key_info(srcaddr, entry->d_name);
+		if (key_info)
+			keys.keys = g_slist_append(keys.keys, key_info);
+
+		l = g_slist_find_custom(adapter->devices, entry->d_name,
+					(GCompareFunc) device_address_cmp);
+		if (l) {
+			device = l->data;
+			goto device_exist;
+		}
 
 		device = device_create(adapter, entry->d_name, BDADDR_BREDR);
 		if (!device)
@@ -2060,7 +2033,21 @@ static void load_devices(struct btd_adapter *adapter)
 
 		device_set_temporary(device, FALSE);
 		adapter->devices = g_slist_append(adapter->devices, device);
+
+device_exist:
+		if (key_info) {
+			device_set_paired(device, TRUE);
+			device_set_bonded(device, TRUE);
+		}
 	}
+
+	err = mgmt_load_link_keys(adapter->dev_id, keys.keys,
+							main_opts.debug_keys);
+	if (err < 0)
+		error("Unable to load link keys: %s (%d)",
+							strerror(-err), -err);
+
+	g_slist_free_full(keys.keys, g_free);
 }
 
 int btd_adapter_block_address(struct btd_adapter *adapter,
diff --git a/src/device.c b/src/device.c
index 6b64c5d..d6780ee 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1897,12 +1897,6 @@ struct btd_device *device_create(struct btd_adapter *adapter,
 
 	load_info(device, srcaddr, address);
 
-	if (read_link_key(src, &device->bdaddr, device->bdaddr_type, NULL,
-								NULL) == 0) {
-		device_set_paired(device, TRUE);
-		device_set_bonded(device, TRUE);
-	}
-
 	if (device_is_le(device) && has_longtermkeys(src, &device->bdaddr,
 							device->bdaddr_type)) {
 		device_set_paired(device, TRUE);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 5/7] device: Remove keys file in device_remove_stored()
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/device.c |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/device.c b/src/device.c
index a99ca34..6b64c5d 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2014,6 +2014,11 @@ static void device_remove_stored(struct btd_device *device)
 	filename[PATH_MAX] = '\0';
 	remove(filename);
 
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/keys", adapter_addr,
+			device_addr);
+	filename[PATH_MAX] = '\0';
+	remove(filename);
+
 	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s", adapter_addr,
 			device_addr);
 	filename[PATH_MAX] = '\0';
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 4/7] adapter: Convert storage linkkeys file
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 9d6554a..32d3930 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2618,6 +2618,34 @@ static void convert_did_entry(GKeyFile *key_file, void *value)
 	g_key_file_set_integer(key_file, "DeviceID", "Version", val);
 }
 
+static void convert_linkkey_entry(GKeyFile *key_file, void *value)
+{
+	char *type_str, *length_str, *str;
+	gint val;
+
+	type_str = strchr(value, ' ');
+	if (!type_str)
+		return;
+
+	*(type_str++) = 0;
+
+	length_str = strchr(type_str, ' ');
+	if (!length_str)
+		return;
+
+	*(length_str++) = 0;
+
+	str = g_strconcat("0x", value, NULL);
+	g_key_file_set_string(key_file, "LinkKey", "Key", str);
+	g_free(str);
+
+	val = strtol(type_str, NULL, 16);
+	g_key_file_set_integer(key_file, "LinkKey", "Type", val);
+
+	val = strtol(length_str, NULL, 16);
+	g_key_file_set_integer(key_file, "LinkKey", "PINLength", val);
+}
+
 static void convert_entry(char *key, char *value, void *user_data)
 {
 	struct device_converter *converter = user_data;
@@ -2707,6 +2735,9 @@ static void convert_device_storage(struct btd_adapter *adapter)
 
 	/* Convert device ids */
 	convert_file("did", address, "info", convert_did_entry);
+
+	/* Convert linkkeys */
+	convert_file("linkkeys", address, "keys", convert_linkkey_entry);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 3/7] adapter: Add destination file to convert_file()
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

In order to convert keys and longtermkeys, we will need to use
different target file names.
---
 src/adapter.c |   18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 3f184fc..9d6554a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2556,6 +2556,7 @@ static void convert_names_entry(char *key, char *value, void *user_data)
 struct device_converter {
 	char *address;
 	void (*cb)(GKeyFile *key_file, void *value);
+	char *filename;
 };
 
 static void convert_aliases_entry(GKeyFile *key_file, void *value)
@@ -2631,8 +2632,8 @@ static void convert_entry(char *key, char *value, void *user_data)
 	if (bachk(key) != 0)
 		return;
 
-	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/info",
-			converter->address, key);
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s/%s/%s",
+			converter->address, key, converter->filename);
 	filename[PATH_MAX] = '\0';
 	create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
@@ -2647,7 +2648,7 @@ static void convert_entry(char *key, char *value, void *user_data)
 	g_key_file_free(key_file);
 }
 
-static void convert_file(char *file, char *address,
+static void convert_file(char *file, char *address, char *dest_file,
 				void (*cb)(GKeyFile *key_file, void *value))
 {
 	char filename[PATH_MAX + 1];
@@ -2663,6 +2664,7 @@ static void convert_file(char *file, char *address,
 	} else {
 		converter.address = address;
 		converter.cb = cb;
+		converter.filename = dest_file;
 
 		textfile_foreach(filename, convert_entry, &converter);
 		textfile_put(filename, "converted", "yes");
@@ -2692,19 +2694,19 @@ static void convert_device_storage(struct btd_adapter *adapter)
 	free(str);
 
 	/* Convert aliases */
-	convert_file("aliases", address, convert_aliases_entry);
+	convert_file("aliases", address, "info", convert_aliases_entry);
 
 	/* Convert trusts */
-	convert_file("trusts", address, convert_trusts_entry);
+	convert_file("trusts", address, "info", convert_trusts_entry);
 
 	/* Convert classes */
-	convert_file("classes", address, convert_classes_entry);
+	convert_file("classes", address, "info", convert_classes_entry);
 
 	/* Convert blocked */
-	convert_file("blocked", address, convert_blocked_entry);
+	convert_file("blocked", address, "info", convert_blocked_entry);
 
 	/* Convert device ids */
-	convert_file("did", address, convert_did_entry);
+	convert_file("did", address, "info", convert_did_entry);
 }
 
 static void convert_config(struct btd_adapter *adapter, const char *filename,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 2/7] adapter: Load devices from new storage architecture
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1354006193-7199-1-git-send-email-frederic.danis@linux.intel.com>

---
 src/adapter.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 163360f..3f184fc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -34,6 +34,7 @@
 #include <stdbool.h>
 #include <sys/ioctl.h>
 #include <sys/file.h>
+#include <dirent.h>
 
 #include <bluetooth/bluetooth.h>
 #include <bluetooth/uuid.h>
@@ -1996,6 +1997,8 @@ static void load_devices(struct btd_adapter *adapter)
 	char srcaddr[18];
 	struct adapter_keys keys = { adapter, NULL };
 	int err;
+	DIR *dir;
+	struct dirent *entry;
 
 	ba2str(&adapter->bdaddr, srcaddr);
 
@@ -2031,6 +2034,33 @@ static void load_devices(struct btd_adapter *adapter)
 
 	create_name(filename, PATH_MAX, STORAGEDIR, srcaddr, "blocked");
 	textfile_foreach(filename, create_stored_device_from_blocked, adapter);
+
+	snprintf(filename, PATH_MAX, STORAGEDIR "/%s", srcaddr);
+	filename[PATH_MAX] = '\0';
+
+	dir = opendir(filename);
+	if (!dir) {
+		error("Unable to open adapter storage directory: %s", filename);
+		return;
+	}
+
+	while ((entry = readdir(dir)) != NULL) {
+		struct btd_device *device;
+
+		if (entry->d_type != DT_DIR || bachk(entry->d_name) < 0)
+			continue;
+
+		if (g_slist_find_custom(adapter->devices, entry->d_name,
+					(GCompareFunc) device_address_cmp))
+			continue;
+
+		device = device_create(adapter, entry->d_name, BDADDR_BREDR);
+		if (!device)
+			continue;
+
+		device_set_temporary(device, FALSE);
+		adapter->devices = g_slist_append(adapter->devices, device);
+	}
 }
 
 int btd_adapter_block_address(struct btd_adapter *adapter,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH 1/7] doc: Update settings-storage.txt
From: Frédéric Danis @ 2012-11-27  8:49 UTC (permalink / raw)
  To: linux-bluetooth

Link key and Long term key for a device should be saved in
keys file under storage device directory
---
 doc/settings-storage.txt |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index 3fdcb03..c0171e9 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -30,6 +30,7 @@ contains:
  - one directory per remote device, named by remote device address, which
    contains:
     - an info file
+    - a keys file
     - an attributes file containing attributes of remote LE services
 
 So the directory structure is:
@@ -42,9 +43,11 @@ So the directory structure is:
             ...
         ./<remote device address>/
             ./info
+            ./keys
             ./attributes
         ./<remote device address>/
             ./info
+            ./keys
             ./attributes
         ...
 
@@ -127,8 +130,8 @@ This general group contains:
 Info file format
 ================
 
-Info file may includes multiple groups (General, Device ID, Link key and
-Long term key) related to a remote device.
+Info file may includes multiple groups (General and Device ID) related to
+a remote device.
 
 [General] group contains:
 
@@ -165,6 +168,12 @@ Long term key) related to a remote device.
   Version		Integer		Device version
 
 
+Keys file format
+================
+
+Keys file may includes multiple groups (Link key and Long term key) related
+to a remote device.
+
 [LinkKey] group contains:
 
   Key			String		Key in hexadecimal format
-- 
1.7.9.5


^ permalink raw reply related

* Re: USB 2.0: No giveback comes for one submitted URB
From: Alan Stern @ 2012-11-26 16:11 UTC (permalink / raw)
  To: naveen yadav
  Cc: linux-kernel, linux-usb, marcel, padovan, linux-bluetooth,
	vivek bhagat
In-Reply-To: <CAJ8eaTxC1EiTwn-KSjW32WKi-4LsVt0YPrTn+xjtYEA9h0Dgdg@mail.gmail.com>

On Mon, 26 Nov 2012, naveen yadav wrote:

> Dear Alan,
> 
> Thanks for your reply ,
> 
> We check on 3.2.34 and 3.6.7 on X86 host machine. and result is same
> without connecting Bluetooth device.
> I am attaching log

Yes, very good.  But you still have to do what I mentioned in my
earlier email:

> On Thu, Nov 22, 2012 at 9:08 PM, Alan Stern <stern@rowland.harvard.edu> wrote:

> > Now you need to find out what other code has changed urb->use_count and
> > fix it.

Alan Stern


^ permalink raw reply

* Re: [PATCH BlueZ 01/11] audio: Remove AudioSink interface
From: Johan Hedberg @ 2012-11-26 14:43 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Mon, Nov 26, 2012, Luiz Augusto von Dentz wrote:
> This interface is no longer needed as Device interface can now connect
> the profiles and the state can be tracked using MediaTransport interface.
> ---
>  doc/audio-api.txt     |  53 -------------------
>  profiles/audio/sink.c | 141 ++------------------------------------------------
>  2 files changed, 3 insertions(+), 191 deletions(-)

All patches in this set have been applied. Thanks.

Johan

^ permalink raw reply

* [PATCH BlueZ 11/11] network: Fix invalid read on exit
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

Invalid read of size 1
   at 0x4A09D91: strcmp (mc_replace_strmem.c:729)
   by 0x4C6C768: g_str_equal (in /usr/lib64/libglib-2.0.so.0.3200.4)
   by 0x1446B7: connection_disconnect (connection.c:451)
   by 0x141DEA: disconnect_profile (manager.c:120)
   by 0x4C96C5C: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.3200.4)
   by 0x182B2D: device_remove (device.c:2034)
   by 0x178809: adapter_remove (adapter.c:2902)
   by 0x173902: manager_cleanup (manager.c:256)
   by 0x1217B9: main (main.c:550)
 Address 0x0 is not stack'd, malloc'd or (recently) free'd

In addition remove owner since it is no longer possible to track the
owner as this is done in the core.
---
 profiles/network/connection.c | 26 --------------------------
 1 file changed, 26 deletions(-)

diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 912e5b4..a7e45e6 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -70,8 +70,6 @@ struct network_conn {
 	uint16_t	id;		/* Role: Service Class Identifier */
 	conn_state	state;
 	GIOChannel	*io;
-	char		*owner;		/* Connection initiator D-Bus client */
-	guint		watch;		/* Disconnect watch */
 	guint		dc_id;
 	struct network_peer *peer;
 	guint		attempt_cnt;
@@ -124,10 +122,6 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
 					NETWORK_PEER_INTERFACE, "UUID");
 	device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
 	nc->dc_id = 0;
-	if (nc->watch) {
-		g_dbus_remove_watch(nc->watch);
-		nc->watch = 0;
-	}
 
 	info("%s disconnected", nc->dev);
 
@@ -146,11 +140,6 @@ static void cancel_connection(struct network_conn *nc, int err)
 		nc->timeout_source = 0;
 	}
 
-	if (nc->watch) {
-		g_dbus_remove_watch(nc->watch);
-		nc->watch = 0;
-	}
-
 	if (nc->cb)
 		nc->cb(nc->peer->device, err, NULL, nc->cb_data);
 
@@ -170,11 +159,6 @@ static void connection_destroy(DBusConnection *conn, void *user_data)
 		bnep_kill_connection(device_get_address(nc->peer->device));
 	} else if (nc->io)
 		cancel_connection(nc, -EIO);
-
-	if (nc->owner) {
-		g_free(nc->owner);
-		nc->owner = NULL;
-	}
 }
 
 static void disconnect_cb(struct btd_device *device, gboolean removal,
@@ -416,16 +400,9 @@ int connection_connect(struct btd_device *device, uint16_t id,
 		return -EIO;
 
 	nc->state = CONNECTING;
-	nc->owner = g_strdup(owner);
 	nc->cb = cb;
 	nc->cb_data = data;
 
-	if (owner)
-		nc->watch = g_dbus_add_disconnect_watch(
-						btd_get_dbus_connection(),
-						owner, connection_destroy,
-						nc, NULL);
-
 	return 0;
 }
 
@@ -446,9 +423,6 @@ int connection_disconnect(struct btd_device *device, uint16_t id,
 	if (nc->state == DISCONNECTED)
 		return 0;
 
-	if (!g_str_equal(nc->owner, caller))
-		return -EPERM;
-
 	connection_destroy(NULL, nc);
 
 	return 0;
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 10/11] network: Fix always attempting to connect to PANU service
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

connection_connect takes the remote role as parameter not the local one.
---
 profiles/network/manager.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 06abe1b..06ef9fc 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -100,8 +100,7 @@ static int connect_profile(struct btd_device *dev, struct btd_profile *profile,
 	req->profile = profile;
 	req->cb = cb;
 
-	err = connection_connect(dev, BNEP_SVC_PANU, NULL, connect_profile_cb,
-									req);
+	err = connection_connect(dev, id, NULL, connect_profile_cb, req);
 	if (err < 0) {
 		g_free(req);
 		return err;
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 09/11] network: Fix trying to register NetworkServer interface multiple times
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This also removes the limitation of only accepting nap as UUID, now all
PAN UUID are supported including their friendly names.
---
 profiles/network/server.c | 64 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 20 deletions(-)

diff --git a/profiles/network/server.c b/profiles/network/server.c
index 1a485ca..2c3c72e 100644
--- a/profiles/network/server.c
+++ b/profiles/network/server.c
@@ -72,7 +72,6 @@ struct network_adapter {
 /* Main server structure */
 struct network_server {
 	bdaddr_t	src;		/* Bluetooth Local Address */
-	char		*iface;		/* DBus interface */
 	char		*name;		/* Server service name */
 	char		*bridge;	/* Bridge name */
 	uint32_t	record_id;	/* Service record id */
@@ -110,6 +109,22 @@ static struct network_server *find_server(GSList *list, uint16_t id)
 	return NULL;
 }
 
+static struct network_server *find_server_by_uuid(GSList *list,
+							const char *uuid)
+{
+	for (; list; list = list->next) {
+		struct network_server *ns = list->data;
+
+		if (strcasecmp(uuid, bnep_uuid(ns->id)) == 0)
+			return ns;
+
+		if (strcasecmp(uuid, bnep_name(ns->id)) == 0)
+			return ns;
+	}
+
+	return NULL;
+}
+
 static sdp_record_t *server_record_new(const char *name, uint16_t id)
 {
 	sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
@@ -624,7 +639,8 @@ static void server_disconnect(DBusConnection *conn, void *user_data)
 static DBusMessage *register_server(DBusConnection *conn,
 				DBusMessage *msg, void *data)
 {
-	struct network_server *ns = data;
+	struct network_adapter *na = data;
+	struct network_server *ns;
 	DBusMessage *reply;
 	const char *uuid, *bridge;
 
@@ -632,7 +648,8 @@ static DBusMessage *register_server(DBusConnection *conn,
 				DBUS_TYPE_STRING, &bridge, DBUS_TYPE_INVALID))
 		return btd_error_invalid_args(msg);
 
-	if (g_strcmp0(uuid, "nap"))
+	ns = find_server_by_uuid(na->servers, uuid);
+	if (ns == NULL)
 		return btd_error_failed(msg, "Invalid UUID");
 
 	if (ns->record_id)
@@ -693,8 +710,10 @@ static void adapter_free(struct network_adapter *na)
 	g_free(na);
 }
 
-static void server_free(struct network_server *ns)
+static void server_free(void *data)
 {
+	struct network_server *ns = data;
+
 	if (!ns)
 		return;
 
@@ -703,7 +722,6 @@ static void server_free(struct network_server *ns)
 	if (ns->record_id)
 		remove_record_from_server(ns->record_id);
 
-	g_free(ns->iface);
 	g_free(ns->name);
 	g_free(ns->bridge);
 
@@ -712,17 +730,12 @@ static void server_free(struct network_server *ns)
 
 static void path_unregister(void *data)
 {
-	struct network_server *ns = data;
-	struct network_adapter *na = ns->na;
+	struct network_adapter *na = data;
 
 	DBG("Unregistered interface %s on path %s",
-		ns->iface, adapter_get_path(na->adapter));
-
-	na->servers = g_slist_remove(na->servers, ns);
-	server_free(ns);
+		NETWORK_SERVER_INTERFACE, adapter_get_path(na->adapter));
 
-	if (na->servers)
-		return;
+	g_slist_free_full(na->servers, server_free);
 
 	adapters = g_slist_remove(adapters, na);
 	adapter_free(na);
@@ -786,29 +799,33 @@ int server_register(struct btd_adapter *adapter, uint16_t id)
 
 	ns = g_new0(struct network_server, 1);
 
-	ns->iface = g_strdup(NETWORK_SERVER_INTERFACE);
 	ns->name = g_strdup("Network service");
 
 	path = adapter_get_path(adapter);
 
+	if (g_slist_length(na->servers) > 0)
+		goto done;
+
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
-					path, ns->iface,
+					path, NETWORK_SERVER_INTERFACE,
 					server_methods, NULL, NULL,
-					ns, path_unregister)) {
+					na, path_unregister)) {
 		error("D-Bus failed to register %s interface",
-				ns->iface);
+						NETWORK_SERVER_INTERFACE);
 		server_free(ns);
 		return -1;
 	}
 
+	DBG("Registered interface %s on path %s", NETWORK_SERVER_INTERFACE,
+									path);
+
+done:
 	bacpy(&ns->src, adapter_get_address(adapter));
 	ns->id = id;
 	ns->na = na;
 	ns->record_id = 0;
 	na->servers = g_slist_append(na->servers, ns);
 
-	DBG("Registered interface %s on path %s", ns->iface, path);
-
 	return 0;
 }
 
@@ -825,8 +842,15 @@ int server_unregister(struct btd_adapter *adapter, uint16_t id)
 	if (!ns)
 		return -EINVAL;
 
+	na->servers = g_slist_remove(na->servers, ns);
+	server_free(ns);
+
+	if (g_slist_length(na->servers) > 0)
+		return 0;
+
 	g_dbus_unregister_interface(btd_get_dbus_connection(),
-					adapter_get_path(adapter), ns->iface);
+						adapter_get_path(adapter),
+						NETWORK_SERVER_INTERFACE);
 
 	return 0;
 }
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 08/11] network: Fix not responding to Device.ConnectProfile
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

The callback passed to connection_connect has to be used to respond when
the connection completes.
---
 profiles/network/connection.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 231164b..912e5b4 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -417,6 +417,8 @@ int connection_connect(struct btd_device *device, uint16_t id,
 
 	nc->state = CONNECTING;
 	nc->owner = g_strdup(owner);
+	nc->cb = cb;
+	nc->cb_data = data;
 
 	if (owner)
 		nc->watch = g_dbus_add_disconnect_watch(
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 07/11] network: Remove Network.Connect and Network.Disconnect
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

These method are no longer necessary as Device interface has similar
functionality.
---
 doc/network-api.txt           | 36 -------------------
 profiles/network/connection.c | 81 +------------------------------------------
 2 files changed, 1 insertion(+), 116 deletions(-)

diff --git a/doc/network-api.txt b/doc/network-api.txt
index 4dd3e58..b640b9a 100644
--- a/doc/network-api.txt
+++ b/doc/network-api.txt
@@ -11,42 +11,6 @@ Service		org.bluez
 Interface	org.bluez.Network
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
 
-Methods		string Connect(string uuid)
-
-			Connect to the network device and return the network
-			interface name. Examples of the interface name are
-			bnep0, bnep1 etc.
-
-			uuid can be either one of "gn", "panu" or "nap" (case
-			insensitive) or a traditional string representation of
-			UUID or a hexadecimal number.
-
-			The connection will be closed and network device
-			released either upon calling Disconnect() or when
-			the client disappears from the message bus.
-
-			Possible errors: org.bluez.Error.AlreadyConnected
-					 org.bluez.Error.ConnectionAttemptFailed
-
-		void Disconnect()
-
-			Disconnect from the network device.
-
-			To abort a connection attempt in case of errors or
-			timeouts in the client it is fine to call this method.
-
-			Possible errors: org.bluez.Error.Failed
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
 Properties	boolean Connected [readonly]
 
 			Indicates if the device is connected.
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index d9961f8..231164b 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -378,50 +378,6 @@ failed:
 	cancel_connection(nc, -EIO);
 }
 
-static void local_connect_cb(struct btd_device *device, int err,
-						const char *pdev, void *data)
-{
-	DBusMessage *msg = data;
-	DBusMessage *reply;
-
-	if (err < 0) {
-		reply = btd_error_failed(msg, strerror(-err));
-		g_dbus_send_message(btd_get_dbus_connection(), reply);
-		dbus_message_unref(msg);
-		return;
-	}
-
-	g_dbus_send_reply(btd_get_dbus_connection(), msg,
-						DBUS_TYPE_STRING, &pdev,
-						DBUS_TYPE_INVALID);
-
-	dbus_message_unref(msg);
-}
-
-static DBusMessage *local_connect(DBusConnection *conn,
-						DBusMessage *msg, void *data)
-{
-	struct network_peer *peer = data;
-	const char *svc;
-	uint16_t id;
-	int err;
-
-	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &svc,
-						DBUS_TYPE_INVALID) == FALSE)
-		return btd_error_invalid_args(msg);
-
-	id = bnep_service_id(svc);
-
-	err = connection_connect(peer->device, id, dbus_message_get_sender(msg),
-							local_connect_cb, msg);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	dbus_message_ref(msg);
-
-	return NULL;
-}
-
 /* Connect and initiate BNEP session */
 int connection_connect(struct btd_device *device, uint16_t id,
 					const char *owner,
@@ -496,30 +452,6 @@ int connection_disconnect(struct btd_device *device, uint16_t id,
 	return 0;
 }
 
-static DBusMessage *local_disconnect(DBusConnection *conn,
-					DBusMessage *msg, void *data)
-{
-	struct network_peer *peer = data;
-	const char *caller = dbus_message_get_sender(msg);
-	GSList *l;
-
-	for (l = peer->connections; l; l = l->next) {
-		struct network_conn *nc = l->data;
-		int err;
-
-		if (nc->state == DISCONNECTED)
-			continue;
-
-		err = connection_disconnect(peer->device, nc->id, caller);
-		if (err < 0)
-			return btd_error_failed(msg, strerror(-err));
-
-		return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-	}
-
-	return btd_error_not_connected(msg);
-}
-
 static gboolean
 network_property_get_connected(const GDBusPropertyTable *property,
 					DBusMessageIter *iter, void *data)
@@ -616,16 +548,6 @@ static void path_unregister(void *data)
 	peer_free(peer);
 }
 
-static const GDBusMethodTable connection_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Connect",
-				GDBUS_ARGS({"uuid", "s"}),
-				GDBUS_ARGS({"interface", "s"}),
-				local_connect) },
-	{ GDBUS_METHOD("Disconnect",
-			NULL, NULL, local_disconnect) },
-	{ }
-};
-
 static const GDBusPropertyTable connection_properties[] = {
 	{ "Connected", "b", network_property_get_connected },
 	{ "Interface", "s", network_property_get_interface },
@@ -661,8 +583,7 @@ static struct network_peer *create_peer(struct btd_device *device)
 
 	if (g_dbus_register_interface(btd_get_dbus_connection(), path,
 					NETWORK_PEER_INTERFACE,
-					connection_methods,
-					NULL, connection_properties,
+					NULL, NULL, connection_properties,
 					peer, path_unregister) == FALSE) {
 		error("D-Bus failed to register %s interface",
 			NETWORK_PEER_INTERFACE);
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 06/11] network: Make use of D-Bus Properties interface
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

---
 profiles/network/connection.c | 133 +++++++++++++++++++++---------------------
 1 file changed, 68 insertions(+), 65 deletions(-)

diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 57451b9..d9961f8 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -113,19 +113,15 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
 				gpointer data)
 {
 	struct network_conn *nc = data;
-	gboolean connected = FALSE;
-	const char *property = "";
+	DBusConnection *conn = btd_get_dbus_connection();
 	const char *path = device_get_path(nc->peer->device);
 
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Connected",
-				DBUS_TYPE_BOOLEAN, &connected);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Interface",
-				DBUS_TYPE_STRING, &property);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "UUID",
-				DBUS_TYPE_STRING, &property);
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Connected");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Interface");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "UUID");
 	device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
 	nc->dc_id = 0;
 	if (nc->watch) {
@@ -200,9 +196,8 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	char pkt[BNEP_MTU];
 	ssize_t r;
 	int sk;
-	const char *pdev, *uuid;
-	gboolean connected;
 	const char *path;
+	DBusConnection *conn;
 
 	if (cond & G_IO_NVAL)
 		return FALSE;
@@ -265,24 +260,19 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	}
 
 	bnep_if_up(nc->dev);
-	pdev = nc->dev;
-	uuid = bnep_uuid(nc->id);
 
 	if (nc->cb)
-		nc->cb(nc->peer->device, 0, pdev, nc->cb_data);
+		nc->cb(nc->peer->device, 0, nc->dev, nc->cb_data);
 
+	conn = btd_get_dbus_connection();
 	path = device_get_path(nc->peer->device);
 
-	connected = TRUE;
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Connected",
-				DBUS_TYPE_BOOLEAN, &connected);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Interface",
-				DBUS_TYPE_STRING, &pdev);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "UUID",
-				DBUS_TYPE_STRING, &uuid);
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Connected");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Interface");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "UUID");
 
 	nc->state = CONNECTED;
 	nc->dc_id = device_add_disconnect_watch(nc->peer->device, disconnect_cb,
@@ -530,54 +520,69 @@ static DBusMessage *local_disconnect(DBusConnection *conn,
 	return btd_error_not_connected(msg);
 }
 
-static DBusMessage *local_get_properties(DBusConnection *conn,
-					DBusMessage *msg, void *data)
+static gboolean
+network_property_get_connected(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
 {
 	struct network_peer *peer = data;
-	struct network_conn *nc = NULL;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	DBusMessageIter dict;
-	dbus_bool_t connected;
-	const char *property;
+	dbus_bool_t value = FALSE;
 	GSList *l;
 
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
+	for (l = peer->connections; l; l = l->next) {
+		struct network_conn *tmp = l->data;
+
+		if (tmp->state == CONNECTED) {
+			value = TRUE;
+			break;
+		}
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
 
-	dbus_message_iter_init_append(reply, &iter);
+	return TRUE;
+}
 
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+static gboolean
+network_property_get_interface(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct network_peer *peer = data;
+	const char *value = "";
+	GSList *l;
 
-	/* Connected */
 	for (l = peer->connections; l; l = l->next) {
 		struct network_conn *tmp = l->data;
 
-		if (tmp->state != CONNECTED)
-			continue;
-
-		nc = tmp;
-		break;
+		if (tmp->state == CONNECTED) {
+			value = tmp->dev;
+			break;
+		}
 	}
 
-	connected = nc ? TRUE : FALSE;
-	dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &connected);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
-	/* Interface */
-	property = nc ? nc->dev : "";
-	dict_append_entry(&dict, "Interface", DBUS_TYPE_STRING, &property);
+	return TRUE;
+}
 
-	/* UUID */
-	property = nc ? bnep_uuid(nc->id) : "";
-	dict_append_entry(&dict, "UUID", DBUS_TYPE_STRING, &property);
+static gboolean network_property_get_uuid(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct network_peer *peer = data;
+	const char *value = "";
+	GSList *l;
+
+	for (l = peer->connections; l; l = l->next) {
+		struct network_conn *tmp = l->data;
+
+		if (tmp->state == CONNECTED) {
+			value = bnep_uuid(tmp->id);
+			break;
+		}
+	}
 
-	dbus_message_iter_close_container(&iter, &dict);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
-	return reply;
+	return TRUE;
 }
 
 static void connection_free(void *data)
@@ -618,15 +623,13 @@ static const GDBusMethodTable connection_methods[] = {
 				local_connect) },
 	{ GDBUS_METHOD("Disconnect",
 			NULL, NULL, local_disconnect) },
-	{ GDBUS_METHOD("GetProperties",
-			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-			local_get_properties) },
 	{ }
 };
 
-static const GDBusSignalTable connection_signals[] = {
-	{ GDBUS_SIGNAL("PropertyChanged",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+static const GDBusPropertyTable connection_properties[] = {
+	{ "Connected", "b", network_property_get_connected },
+	{ "Interface", "s", network_property_get_interface },
+	{ "UUID", "s", network_property_get_uuid },
 	{ }
 };
 
@@ -659,7 +662,7 @@ static struct network_peer *create_peer(struct btd_device *device)
 	if (g_dbus_register_interface(btd_get_dbus_connection(), path,
 					NETWORK_PEER_INTERFACE,
 					connection_methods,
-					connection_signals, NULL,
+					NULL, connection_properties,
 					peer, path_unregister) == FALSE) {
 		error("D-Bus failed to register %s interface",
 			NETWORK_PEER_INTERFACE);
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 05/11] input: Remove Input interface
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This interface is no longer needed as Device interface can now connect
the profiles.
---
 doc/input-api.txt       | 44 -----------------------
 profiles/input/device.c | 93 ++++---------------------------------------------
 2 files changed, 6 insertions(+), 131 deletions(-)
 delete mode 100644 doc/input-api.txt

diff --git a/doc/input-api.txt b/doc/input-api.txt
deleted file mode 100644
index 7c3a4b2..0000000
--- a/doc/input-api.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-BlueZ D-Bus Input API description
-*********************************
-
-Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
-
-
-Input hierarchy
-===============
-
-Service		org.bluez
-Interface	org.bluez.Input
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-Methods		void Connect()
-
-			Connect to the input device.
-
-			Possible errors: org.bluez.Error.AlreadyConnected
-					 org.bluez.Error.ConnectionAttemptFailed
-
-		void Disconnect()
-
-			Disconnect from the input device.
-
-			To abort a connection attempt in case of errors or
-			timeouts in the client it is fine to call this method.
-
-			Possible errors: org.bluez.Error.Failed
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-			Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-Properties	boolean Connected [readonly]
-
-			Indicates if the device is connected.
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 108be39..2871cc3 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -680,26 +680,6 @@ int input_device_connect(struct btd_device *dev, struct btd_profile *profile,
 	return dev_connect(idev);
 }
 
-static DBusMessage *local_connect(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct input_device *idev = data;
-
-	if (idev->pending)
-		return btd_error_in_progress(msg);
-
-	if (is_connected(idev))
-		return btd_error_already_connected(msg);
-
-	idev->pending = g_new0(struct pending_connect, 1);
-	idev->pending->local = true;
-	idev->pending->msg = dbus_message_ref(msg);
-
-	dev_connect(idev);
-
-	return NULL;
-}
-
 int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile,
 							btd_profile_cb cb)
 {
@@ -720,57 +700,6 @@ int input_device_disconnect(struct btd_device *dev, struct btd_profile *profile,
 	return 0;
 }
 
-static DBusMessage *local_disconnect(DBusConnection *conn,
-						DBusMessage *msg, void *data)
-{
-	struct input_device *idev = data;
-	int err;
-
-	err = connection_disconnect(idev, 0);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
-}
-
-static void device_unregister(void *data)
-{
-	struct input_device *idev = data;
-
-	DBG("Unregistered interface %s on path %s", INPUT_DEVICE_INTERFACE,
-								idev->path);
-
-	devices = g_slist_remove(devices, idev);
-	input_device_free(idev);
-}
-
-
-
-static gboolean input_device_property_get_connected(
-					const GDBusPropertyTable *property,
-					DBusMessageIter *iter, void *data)
-{
-	struct input_device *idev = data;
-	dbus_bool_t connected = is_connected(idev);
-
-	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &connected);
-
-	return TRUE;
-}
-
-static const GDBusMethodTable device_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Connect",
-				NULL, NULL, local_connect) },
-	{ GDBUS_METHOD("Disconnect",
-				NULL, NULL, local_disconnect) },
-	{ }
-};
-
-static const GDBusPropertyTable device_properties[] = {
-	{ "Connected", "b", input_device_property_get_connected },
-	{ }
-};
-
 static struct input_device *input_device_new(struct btd_device *device,
 				const char *path, const uint32_t handle,
 				gboolean disable_sdp)
@@ -791,20 +720,6 @@ static struct input_device *input_device_new(struct btd_device *device,
 	if (strlen(name) > 0)
 		idev->name = g_strdup(name);
 
-	if (g_dbus_register_interface(btd_get_dbus_connection(),
-					idev->path, INPUT_DEVICE_INTERFACE,
-					device_methods, NULL,
-					device_properties, idev,
-					device_unregister) == FALSE) {
-		error("Failed to register interface %s on path %s",
-			INPUT_DEVICE_INTERFACE, path);
-		input_device_free(idev);
-		return NULL;
-	}
-
-	DBG("Registered interface %s on path %s",
-			INPUT_DEVICE_INTERFACE, idev->path);
-
 	return idev;
 }
 
@@ -823,6 +738,8 @@ int input_device_register(struct btd_device *device,
 {
 	struct input_device *idev;
 
+	DBG("%s", path);
+
 	idev = find_device_by_path(devices, path);
 	if (idev)
 		return -EEXIST;
@@ -859,6 +776,8 @@ int input_device_unregister(const char *path, const char *uuid)
 {
 	struct input_device *idev;
 
+	DBG("%s", path);
+
 	idev = find_device_by_path(devices, path);
 	if (idev == NULL)
 		return -EINVAL;
@@ -868,8 +787,8 @@ int input_device_unregister(const char *path, const char *uuid)
 		return -EBUSY;
 	}
 
-	g_dbus_unregister_interface(btd_get_dbus_connection(),
-						path, INPUT_DEVICE_INTERFACE);
+	devices = g_slist_remove(devices, idev);
+	input_device_free(idev);
 
 	return 0;
 }
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 04/11] audio: Remove Control.Connect and Control.Disconnect
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

These method are no longer necessary as Device interface has similar
functionality.
---
 doc/control-api.txt      | 10 +---------
 profiles/audio/control.c | 47 -----------------------------------------------
 profiles/audio/device.c  |  6 ++++--
 3 files changed, 5 insertions(+), 58 deletions(-)

diff --git a/doc/control-api.txt b/doc/control-api.txt
index 0d25512..a16ee7d 100644
--- a/doc/control-api.txt
+++ b/doc/control-api.txt
@@ -12,15 +12,7 @@ Service		org.bluez
 Interface	org.bluez.Control
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
 
-Methods		void Connect()
-
-			Connect to remote device.
-
-		void Disconnect()
-
-			Disconnect from remote device.
-
-		void Play()
+Methods		void Play()
 
 			Resume playback.
 
diff --git a/profiles/audio/control.c b/profiles/audio/control.c
index 29cf3bb..0013f8d 100644
--- a/profiles/audio/control.c
+++ b/profiles/audio/control.c
@@ -153,38 +153,6 @@ int control_connect(struct audio_device *dev, audio_device_cb cb, void *data)
 	return 0;
 }
 
-static void generic_cb(struct audio_device *dev, int err, void *data)
-{
-	DBusMessage *msg = data;
-	DBusMessage *reply;
-
-	if (err < 0) {
-		reply = btd_error_failed(msg, strerror(-err));
-		g_dbus_send_message(btd_get_dbus_connection(), reply);
-		dbus_message_unref(msg);
-		return;
-	}
-
-	g_dbus_send_reply(btd_get_dbus_connection(), msg, DBUS_TYPE_INVALID);
-
-	dbus_message_unref(msg);
-}
-
-static DBusMessage *connect_control(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct audio_device *device = data;
-	int err;
-
-	err = control_connect(device, generic_cb, msg);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	dbus_message_ref(msg);
-
-	return NULL;
-}
-
 int control_disconnect(struct audio_device *dev, audio_device_cb cb,
 								void *data)
 {
@@ -208,19 +176,6 @@ int control_disconnect(struct audio_device *dev, audio_device_cb cb,
 
 }
 
-static DBusMessage *disconnect_control(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct audio_device *device = data;
-	int err;
-
-	err = control_disconnect(device, NULL, NULL);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	return dbus_message_new_method_return(msg);
-}
-
 static DBusMessage *key_pressed(DBusConnection *conn, DBusMessage *msg,
 						uint8_t op, void *data)
 {
@@ -296,8 +251,6 @@ static gboolean control_property_get_connected(
 }
 
 static const GDBusMethodTable control_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, connect_control) },
-	{ GDBUS_METHOD("Disconnect", NULL, NULL, disconnect_control) },
 	{ GDBUS_METHOD("Play", NULL, NULL, control_play) },
 	{ GDBUS_METHOD("Pause", NULL, NULL, control_pause) },
 	{ GDBUS_METHOD("Stop", NULL, NULL, control_stop) },
diff --git a/profiles/audio/device.c b/profiles/audio/device.c
index b14f75b..fef2bea 100644
--- a/profiles/audio/device.c
+++ b/profiles/audio/device.c
@@ -298,6 +298,8 @@ struct audio_device *audio_device_register(struct btd_device *device,
 {
 	struct audio_device *dev;
 
+	DBG("%s", device_get_path(device));
+
 	dev = g_new0(struct audio_device, 1);
 
 	dev->btd_dev = btd_device_ref(device);
@@ -306,8 +308,6 @@ struct audio_device *audio_device_register(struct btd_device *device,
 	dev->priv = g_new0(struct dev_priv, 1);
 	dev->priv->state = AUDIO_STATE_DISCONNECTED;
 
-	DBG("%s", device_get_path(dev->btd_dev));
-
 	if (sink_callback_id == 0)
 		sink_callback_id = sink_add_state_cb(device_sink_cb, NULL);
 
@@ -341,6 +341,8 @@ gboolean audio_device_is_active(struct audio_device *dev,
 
 void audio_device_unregister(struct audio_device *device)
 {
+	DBG("%s", device_get_path(device->btd_dev));
+
 	if (device->hs_preauth_id) {
 		g_source_remove(device->hs_preauth_id);
 		device->hs_preauth_id = 0;
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 03/11] audio: Remove Audio interface
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This interface is no longer needed as Device interface can now connect
the profiles and the state can be tracked using MediaTransport interface.
---
 doc/audio-api.txt       |  51 ---------------
 profiles/audio/device.c | 160 +-----------------------------------------------
 2 files changed, 2 insertions(+), 209 deletions(-)
 delete mode 100644 doc/audio-api.txt

diff --git a/doc/audio-api.txt b/doc/audio-api.txt
deleted file mode 100644
index 6fd8dfc..0000000
--- a/doc/audio-api.txt
+++ /dev/null
@@ -1,51 +0,0 @@
-BlueZ D-Bus Audio API description
-*********************************
-
-Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
-Copyright (C) 2005-2007  Johan Hedberg <johan.hedberg@nokia.com>
-Copyright (C) 2005-2006  Brad Midgley <bmidgley@xmission.com>
-
-Audio hierarchy
-===============
-
-Service		org.bluez
-Interface	org.bluez.Audio
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-This is a generic audio interface that abstracts the different audio profiles.
-
-Methods		void Connect()
-
-			Connect all supported audio profiles on the device.
-
-		void Disconnect()
-
-			Disconnect all audio profiles on the device
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-Signals		void PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-Properties	string State
-
-			Possible values: "disconnected", "connecting",
-			"connected"
-
-			"disconnected" -> "connecting"
-				Either an incoming or outgoing connection
-				attempt ongoing.
-
-			"connecting" -> "disconnected"
-				Connection attempt failed
-
-			"connecting" -> "connected"
-				Successfully connected
-
-			"connected" -> "disconnected"
-				Disconnected from the remote device
diff --git a/profiles/audio/device.c b/profiles/audio/device.c
index 4cce6ba..b14f75b 100644
--- a/profiles/audio/device.c
+++ b/profiles/audio/device.c
@@ -74,9 +74,6 @@ struct dev_priv {
 	sink_state_t sink_state;
 	avctp_state_t avctp_state;
 
-	DBusMessage *conn_req;
-	DBusMessage *dc_req;
-
 	guint control_timer;
 	guint avdtp_timer;
 	guint dc_id;
@@ -97,10 +94,6 @@ static void device_free(struct audio_device *dev)
 			g_source_remove(priv->control_timer);
 		if (priv->avdtp_timer)
 			g_source_remove(priv->avdtp_timer);
-		if (priv->dc_req)
-			dbus_message_unref(priv->dc_req);
-		if (priv->conn_req)
-			dbus_message_unref(priv->conn_req);
 		if (priv->dc_id)
 			device_remove_disconnect_watch(dev->btd_dev,
 							priv->dc_id);
@@ -198,10 +191,8 @@ static void disconnect_cb(struct btd_device *btd_dev, gboolean removal,
 
 static void device_set_state(struct audio_device *dev, audio_state_t new_state)
 {
-	DBusConnection *conn = btd_get_dbus_connection();
 	struct dev_priv *priv = dev->priv;
 	const char *state_str;
-	DBusMessage *reply = NULL;
 
 	state_str = state2str(new_state);
 	if (!state_str)
@@ -225,31 +216,8 @@ static void device_set_state(struct audio_device *dev, audio_state_t new_state)
 
 	dev->priv->state = new_state;
 
-	if (new_state == AUDIO_STATE_DISCONNECTED) {
-		if (priv->dc_req) {
-			reply = dbus_message_new_method_return(priv->dc_req);
-			dbus_message_unref(priv->dc_req);
-			priv->dc_req = NULL;
-			g_dbus_send_message(conn, reply);
-		}
+	if (new_state == AUDIO_STATE_DISCONNECTED)
 		priv->disconnecting = FALSE;
-	}
-
-	if (priv->conn_req && new_state != AUDIO_STATE_CONNECTING) {
-		if (new_state == AUDIO_STATE_CONNECTED)
-			reply = dbus_message_new_method_return(priv->conn_req);
-		else
-			reply = btd_error_failed(priv->conn_req,
-							"Connect Failed");
-
-		dbus_message_unref(priv->conn_req);
-		priv->conn_req = NULL;
-		g_dbus_send_message(conn, reply);
-	}
-
-	emit_property_changed(device_get_path(dev->btd_dev),
-				AUDIO_INTERFACE, "State",
-				DBUS_TYPE_STRING, &state_str);
 }
 
 static void device_avdtp_cb(struct audio_device *dev, struct avdtp *session,
@@ -324,115 +292,6 @@ static void device_avctp_cb(struct audio_device *dev,
 	}
 }
 
-static DBusMessage *dev_connect(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct audio_device *dev = data;
-	struct dev_priv *priv = dev->priv;
-
-	if (priv->state == AUDIO_STATE_CONNECTING)
-		return btd_error_in_progress(msg);
-	else if (priv->state == AUDIO_STATE_CONNECTED)
-		return btd_error_already_connected(msg);
-
-	dev->auto_connect = TRUE;
-
-	if (priv->state != AUDIO_STATE_CONNECTING && dev->sink) {
-		struct avdtp *session = avdtp_get(&dev->src, &dev->dst);
-
-		if (!session)
-			return btd_error_failed(msg,
-					"Failed to get AVDTP session");
-
-		sink_setup_stream(dev->sink, session);
-		avdtp_unref(session);
-	}
-
-	/* The previous calls should cause a call to the state callback to
-	 * indicate AUDIO_STATE_CONNECTING */
-	if (priv->state != AUDIO_STATE_CONNECTING)
-		return btd_error_failed(msg, "Connect Failed");
-
-	priv->conn_req = dbus_message_ref(msg);
-
-	return NULL;
-}
-
-static DBusMessage *dev_disconnect(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct audio_device *dev = data;
-	struct dev_priv *priv = dev->priv;
-
-	if (priv->state == AUDIO_STATE_DISCONNECTED)
-		return btd_error_not_connected(msg);
-
-	if (priv->dc_req)
-		return dbus_message_new_method_return(msg);
-
-	priv->dc_req = dbus_message_ref(msg);
-
-	if (dev->control) {
-		device_remove_control_timer(dev);
-		avrcp_disconnect(dev);
-	}
-
-	if (dev->sink && priv->sink_state != SINK_STATE_DISCONNECTED)
-		sink_disconnect(dev, TRUE, NULL, NULL);
-	else {
-		dbus_message_unref(priv->dc_req);
-		priv->dc_req = NULL;
-		return dbus_message_new_method_return(msg);
-	}
-
-	return NULL;
-}
-
-static DBusMessage *dev_get_properties(DBusConnection *conn, DBusMessage *msg,
-								void *data)
-{
-	struct audio_device *device = data;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	DBusMessageIter dict;
-	const char *state;
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
-
-	dbus_message_iter_init_append(reply, &iter);
-
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
-
-	/* State */
-	state = state2str(device->priv->state);
-	if (state)
-		dict_append_entry(&dict, "State", DBUS_TYPE_STRING, &state);
-
-	dbus_message_iter_close_container(&iter, &dict);
-
-	return reply;
-}
-
-static const GDBusMethodTable dev_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, dev_connect) },
-	{ GDBUS_METHOD("Disconnect", NULL, NULL, dev_disconnect) },
-	{ GDBUS_METHOD("GetProperties",
-		NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-		dev_get_properties) },
-	{ }
-};
-
-static const GDBusSignalTable dev_signals[] = {
-	{ GDBUS_SIGNAL("PropertyChanged",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
-	{ }
-};
-
 struct audio_device *audio_device_register(struct btd_device *device,
 							const bdaddr_t *src,
 							const bdaddr_t *dst)
@@ -447,18 +306,7 @@ struct audio_device *audio_device_register(struct btd_device *device,
 	dev->priv = g_new0(struct dev_priv, 1);
 	dev->priv->state = AUDIO_STATE_DISCONNECTED;
 
-	if (!g_dbus_register_interface(btd_get_dbus_connection(),
-					device_get_path(dev->btd_dev),
-					AUDIO_INTERFACE, dev_methods,
-					dev_signals, NULL, dev, NULL)) {
-		error("Unable to register %s on %s", AUDIO_INTERFACE,
-						device_get_path(dev->btd_dev));
-		device_free(dev);
-		return NULL;
-	}
-
-	DBG("Registered interface %s on path %s", AUDIO_INTERFACE,
-						device_get_path(dev->btd_dev));
+	DBG("%s", device_get_path(dev->btd_dev));
 
 	if (sink_callback_id == 0)
 		sink_callback_id = sink_add_state_cb(device_sink_cb, NULL);
@@ -507,9 +355,5 @@ void audio_device_unregister(struct audio_device *device)
 	if (device->control)
 		control_unregister(device);
 
-	g_dbus_unregister_interface(btd_get_dbus_connection(),
-					device_get_path(device->btd_dev),
-					AUDIO_INTERFACE);
-
 	device_free(device);
 }
-- 
1.7.11.7


^ permalink raw reply related

* [PATCH BlueZ 02/11] audio: Remove AudioSource interface
From: Luiz Augusto von Dentz @ 2012-11-26 13:09 UTC (permalink / raw)
  To: linux-bluetooth
In-Reply-To: <1353935362-8666-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This interface is no longer needed as Device interface can now connect
the profiles and the state can be tracked using MediaTransport interface.
---
 doc/audio-api.txt       |  54 ------------------
 profiles/audio/source.c | 146 ++++--------------------------------------------
 2 files changed, 11 insertions(+), 189 deletions(-)

diff --git a/doc/audio-api.txt b/doc/audio-api.txt
index 47ea4b6..6fd8dfc 100644
--- a/doc/audio-api.txt
+++ b/doc/audio-api.txt
@@ -49,57 +49,3 @@ Properties	string State
 
 			"connected" -> "disconnected"
 				Disconnected from the remote device
-
-
-AudioSource hierarchy
-=====================
-
-Service		org.bluez
-Interface	org.bluez.AudioSource
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-Methods		void Connect()
-
-			Connect and setup a stream to a A2DP source on the
-			remote device.
-
-		void Disconnect()
-
-			Disconnect from the remote device.
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-			Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-properties	string State [readonly]
-
-			Possible values: "disconnected", "connecting",
-			"connected", "playing"
-
-			"disconnected" -> "connecting"
-				Either an incoming or outgoing connection
-				attempt ongoing.
-
-			"connecting" -> "disconnected"
-				Connection attempt failed
-
-			"connecting" -> "connected"
-				Successfully connected
-
-			"connected" -> "playing"
-				Audio stream active
-
-			"playing" -> "connected"
-				Audio stream suspended
-
-			"connected" -> "disconnected"
-			"playing" -> "disconnected"
-				Disconnected from the remote device
diff --git a/profiles/audio/source.c b/profiles/audio/source.c
index 902b4d4..157a4e8 100644
--- a/profiles/audio/source.c
+++ b/profiles/audio/source.c
@@ -81,37 +81,23 @@ static GSList *source_callbacks = NULL;
 
 static unsigned int avdtp_callback_id = 0;
 
-static const char *state2str(source_state_t state)
-{
-	switch (state) {
-	case SOURCE_STATE_DISCONNECTED:
-		return "disconnected";
-	case SOURCE_STATE_CONNECTING:
-		return "connecting";
-	case SOURCE_STATE_CONNECTED:
-		return "connected";
-	case SOURCE_STATE_PLAYING:
-		return "playing";
-	default:
-		error("Invalid source state %d", state);
-		return NULL;
-	}
-}
+static char *str_state[] = {
+	"SOURCE_STATE_DISCONNECTED",
+	"SOURCE_STATE_CONNECTING",
+	"SOURCE_STATE_CONNECTED",
+	"SOURCE_STATE_PLAYING",
+};
 
 static void source_set_state(struct audio_device *dev, source_state_t new_state)
 {
 	struct source *source = dev->source;
-	const char *state_str;
 	source_state_t old_state = source->state;
 	GSList *l;
 
 	source->state = new_state;
 
-	state_str = state2str(new_state);
-	if (state_str)
-		emit_property_changed(device_get_path(dev->btd_dev),
-					AUDIO_SOURCE_INTERFACE, "State",
-					DBUS_TYPE_STRING, &state_str);
+	DBG("State changed %s: %s -> %s", device_get_path(dev->btd_dev),
+				str_state[old_state], str_state[new_state]);
 
 	for (l = source_callbacks; l != NULL; l = l->next) {
 		struct source_state_callback *cb = l->data;
@@ -356,38 +342,6 @@ gboolean source_setup_stream(struct source *source, struct avdtp *session)
 	return TRUE;
 }
 
-static void generic_cb(struct audio_device *dev, int err, void *data)
-{
-	DBusMessage *msg = data;
-	DBusMessage *reply;
-
-	if (err < 0) {
-		reply = btd_error_failed(msg, strerror(-err));
-		g_dbus_send_message(btd_get_dbus_connection(), reply);
-		dbus_message_unref(msg);
-		return;
-	}
-
-	g_dbus_send_reply(btd_get_dbus_connection(), msg, DBUS_TYPE_INVALID);
-
-	dbus_message_unref(msg);
-}
-
-static DBusMessage *connect_source(DBusConnection *conn,
-				DBusMessage *msg, void *data)
-{
-	struct audio_device *dev = data;
-	int err;
-
-	err = source_connect(dev, generic_cb, msg);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	dbus_message_ref(msg);
-
-	return NULL;
-}
-
 int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
 {
 	struct source *source = dev->source;
@@ -423,67 +377,6 @@ int source_connect(struct audio_device *dev, audio_device_cb cb, void *data)
 	return 0;
 }
 
-static DBusMessage *disconnect_source(DBusConnection *conn,
-					DBusMessage *msg, void *data)
-{
-	struct audio_device *dev = data;
-	int err;
-
-	err = source_disconnect(dev, FALSE, generic_cb, msg);
-	if (err < 0)
-		return btd_error_failed(msg, strerror(-err));
-
-	dbus_message_ref(msg);
-
-	return NULL;
-}
-
-static DBusMessage *source_get_properties(DBusConnection *conn,
-					DBusMessage *msg, void *data)
-{
-	struct audio_device *device = data;
-	struct source *source = device->source;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	DBusMessageIter dict;
-	const char *state;
-
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
-
-	dbus_message_iter_init_append(reply, &iter);
-
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
-
-	/* State */
-	state = state2str(source->state);
-	if (state)
-		dict_append_entry(&dict, "State", DBUS_TYPE_STRING, &state);
-
-	dbus_message_iter_close_container(&iter, &dict);
-
-	return reply;
-}
-
-static const GDBusMethodTable source_methods[] = {
-	{ GDBUS_ASYNC_METHOD("Connect", NULL, NULL, connect_source) },
-	{ GDBUS_ASYNC_METHOD("Disconnect", NULL, NULL, disconnect_source) },
-	{ GDBUS_METHOD("GetProperties",
-				NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-				source_get_properties) },
-	{ }
-};
-
-static const GDBusSignalTable source_signals[] = {
-	{ GDBUS_SIGNAL("PropertyChanged",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
-	{ }
-};
-
 static void source_free(struct audio_device *dev)
 {
 	struct source *source = dev->source;
@@ -508,35 +401,18 @@ static void source_free(struct audio_device *dev)
 	dev->source = NULL;
 }
 
-static void path_unregister(void *data)
+void source_unregister(struct audio_device *dev)
 {
-	struct audio_device *dev = data;
-
-	DBG("Unregistered interface %s on path %s",
-			AUDIO_SOURCE_INTERFACE, device_get_path(dev->btd_dev));
+	DBG("%s", device_get_path(dev->btd_dev));
 
 	source_free(dev);
 }
 
-void source_unregister(struct audio_device *dev)
-{
-	g_dbus_unregister_interface(btd_get_dbus_connection(),
-			device_get_path(dev->btd_dev), AUDIO_SOURCE_INTERFACE);
-}
-
 struct source *source_init(struct audio_device *dev)
 {
 	struct source *source;
 
-	if (!g_dbus_register_interface(btd_get_dbus_connection(),
-					device_get_path(dev->btd_dev),
-					AUDIO_SOURCE_INTERFACE,
-					source_methods, source_signals, NULL,
-					dev, path_unregister))
-		return NULL;
-
-	DBG("Registered interface %s on path %s",
-			AUDIO_SOURCE_INTERFACE, device_get_path(dev->btd_dev));
+	DBG("%s", device_get_path(dev->btd_dev));
 
 	if (avdtp_callback_id == 0)
 		avdtp_callback_id = avdtp_add_state_cb(avdtp_state_callback,
-- 
1.7.11.7


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox