linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Johan Hedberg <johan.hedberg@gmail.com>
To: Bharat Panda <bharat.panda@samsung.com>
Cc: linux-bluetooth@vger.kernel.org, cpgs@samsung.com
Subject: Re: [PATCH ] tools: Add unregister gatt service
Date: Mon, 21 Jul 2014 12:43:55 +0300	[thread overview]
Message-ID: <20140721094355.GA29317@t440s.lan> (raw)
In-Reply-To: <1405934433-29723-1-git-send-email-bharat.panda@samsung.com>

Hi Bharat,

On Mon, Jul 21, 2014, Bharat Panda wrote:
> +static int id;
> +
>  struct characteristic {
>  	char *uuid;
>  	char *path;
> @@ -332,10 +334,10 @@ static gboolean register_characteristic(const char *chr_uuid,
>  
>  static char *register_service(const char *uuid)
>  {
> -	static int id = 1;

Making id public looks unnecessary to me since after the registration
you've got the path which you can pass to the unregistration procedure.

> +static void remove_services()
> +{
> +	char *service_path = g_strdup_printf("/service%d", id);;
> +
> +	services = g_slist_remove(services, service_path);

This makes even less sense to me. You allocate a new pointer
(service_path) and expect it to magically exist in the services list?
That's not how g_slist_remove works. It knows nothing about strings.
Instead you'd want to get hold of the original path string and remove
the right entry based on that.

> +	if (dbus_error_is_set(&derr)) {
> +		printf("UnRegisterService: %s\n", derr.message);

It's UnregisterService. Not UnRegisterService.

> +	printf("UnRegisterService: OK\n");

Same here.

> +static void unregister_external_service(gpointer a, gpointer b)
> +{
> +	DBusConnection *conn = b;
> +	const char *path = a;
> +	DBusMessage *msg;
> +	DBusPendingCall *call;
> +	DBusMessageIter iter;
> +
> +	msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
> +					GATT_MGR_IFACE, "UnregisterService");
> +	if (!msg) {
> +		printf("Couldn't allocate D-Bus message\n");
> +		return;
> +	}
> +
> +	dbus_message_iter_init_append(msg, &iter);
> +
> +	dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
> +
> +	if (!g_dbus_send_message_with_reply(conn, msg, &call, -1)) {
> +		dbus_message_unref(msg);
> +		return;
> +	}
> +
> +	dbus_message_unref(msg);
> +
> +	dbus_pending_call_set_notify(call, unregister_external_service_reply,
> +								NULL, NULL);
> +	dbus_pending_call_unref(call);
> +}
> +
>  static void register_external_service(gpointer a, gpointer b)
>  {
>  	DBusConnection *conn = b;
> @@ -432,6 +499,11 @@ static void connect_handler(DBusConnection *conn, void *user_data)
>  	g_slist_foreach(services, register_external_service, conn);
>  }
>  
> +static void disconnect_handler(DBusConnection *conn, void *user_data)
> +{
> +	g_slist_foreach(services, unregister_external_service, conn);
> +}
> +
>  static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
>  							gpointer user_data)
>  {
> @@ -524,6 +596,7 @@ int main(int argc, char *argv[])
>  	client = g_dbus_client_new(connection, "org.bluez", "/org/bluez");
>  
>  	g_dbus_client_set_connect_watch(client, connect_handler, NULL);
> +	g_dbus_client_set_disconnect_watch(client, disconnect_handler, NULL);

When exactly would disconnect_handler be called in practice? At least
one case seems to be if bluetoothd exits in which case it seems quite
wasteful to try to make any method calls to a non-existing service.
What other scenarios would disconnect_handler be called in?

Johan

  reply	other threads:[~2014-07-21  9:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21  9:20 [PATCH ] tools: Add unregister gatt service Bharat Panda
2014-07-21  9:43 ` Johan Hedberg [this message]
2014-07-21 11:46   ` Bharat Bhusan Panda
2014-07-22  8:00     ` Johan Hedberg
2014-07-24  9:08       ` Bharat Bhusan Panda

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140721094355.GA29317@t440s.lan \
    --to=johan.hedberg@gmail.com \
    --cc=bharat.panda@samsung.com \
    --cc=cpgs@samsung.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).