linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH BlueZ 1/3] tools/gatt-service: Fix using RegisterService
Date: Thu, 11 Feb 2016 16:14:25 +0200	[thread overview]
Message-ID: <CABBYNZJq5SY0uShnJ=itxLJdt9rfk_6CBcWO=4NG6awdLJ_hLw@mail.gmail.com> (raw)
In-Reply-To: <1455191081-24550-1-git-send-email-luiz.dentz@gmail.com>

Hi,

On Thu, Feb 11, 2016 at 1:44 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> RegisterService no longer exists as it was replaced with
> RegisterApplication, also the path being used is wrong since GattManager
> interface is available per adapter path.
> ---
>  tools/gatt-service.c | 63 +++++++++++++++++++++++-----------------------------
>  1 file changed, 28 insertions(+), 35 deletions(-)
>
> diff --git a/tools/gatt-service.c b/tools/gatt-service.c
> index 9baa9e1..74f934e 100644
> --- a/tools/gatt-service.c
> +++ b/tools/gatt-service.c
> @@ -372,63 +372,55 @@ static void create_services()
>         printf("Registered service: %s\n", service_path);
>  }
>
> -static void register_external_service_reply(DBusPendingCall *call,
> -                                                       void *user_data)
> +static void register_app_reply(DBusMessage *reply, void *user_data)
>  {
> -       DBusMessage *reply = dbus_pending_call_steal_reply(call);
>         DBusError derr;
>
>         dbus_error_init(&derr);
>         dbus_set_error_from_message(&derr, reply);
>
>         if (dbus_error_is_set(&derr))
> -               printf("RegisterService: %s\n", derr.message);
> +               printf("RegisterApplication: %s\n", derr.message);
>         else
> -               printf("RegisterService: OK\n");
> +               printf("RegisterApplication: OK\n");
>
> -       dbus_message_unref(reply);
>         dbus_error_free(&derr);
>  }
>
> -static void register_external_service(gpointer a, gpointer b)
> +static void register_app_setup(DBusMessageIter *iter, void *user_data)
>  {
> -       DBusConnection *conn = b;
> -       const char *path = a;
> -       DBusMessage *msg;
> -       DBusPendingCall *call;
> -       DBusMessageIter iter, dict;
> -
> -       msg = dbus_message_new_method_call("org.bluez", "/org/bluez",
> -                                       GATT_MGR_IFACE, "RegisterService");
> -       if (!msg) {
> -               printf("Couldn't allocate D-Bus message\n");
> -               return;
> -       }
> +       const char *path = "/";
> +       DBusMessageIter dict;
>
> -       dbus_message_iter_init_append(msg, &iter);
> +       dbus_message_iter_append_basic(iter, DBUS_TYPE_OBJECT_PATH, &path);
>
> -       dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path);
> -
> -       dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
> +       dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{sv}", &dict);
>
>         /* TODO: Add options dictionary */
>
> -       dbus_message_iter_close_container(&iter, &dict);
> +       dbus_message_iter_close_container(iter, &dict);
> +}
>
> -       if (!g_dbus_send_message_with_reply(conn, msg, &call, -1)) {
> -               dbus_message_unref(msg);
> +static void register_app(GDBusProxy *proxy)
> +{
> +       if (!g_dbus_proxy_method_call(proxy, "RegisterApplication",
> +                                       register_app_setup, register_app_reply,
> +                                       NULL, NULL)) {
> +               printf("Unable to call RegisterApplication\n");
>                 return;
>         }
> -
> -       dbus_pending_call_set_notify(call, register_external_service_reply,
> -                                                               NULL, NULL);
> -
> -       dbus_pending_call_unref(call);
>  }
>
> -static void connect_handler(DBusConnection *conn, void *user_data)
> +static void proxy_added_cb(GDBusProxy *proxy, void *user_data)
>  {
> -       g_slist_foreach(services, register_external_service, conn);
> +       const char *iface;
> +
> +       iface = g_dbus_proxy_get_interface(proxy);
> +
> +       if (g_strcmp0(iface, GATT_MGR_IFACE))
> +               return;
> +
> +       register_app(proxy);
>  }
>
>  static gboolean signal_handler(GIOChannel *channel, GIOCondition cond,
> @@ -520,9 +512,10 @@ int main(int argc, char *argv[])
>
>         create_services();
>
> -       client = g_dbus_client_new(connection, "org.bluez", "/org/bluez");
> +       client = g_dbus_client_new(connection, "org.bluez", "/");
>
> -       g_dbus_client_set_connect_watch(client, connect_handler, NULL);
> +       g_dbus_client_set_proxy_handlers(client, proxy_added_cb, NULL, NULL,
> +                                                                       NULL);
>
>         g_main_loop_run(main_loop);
>
> --
> 2.5.0

Applied.


-- 
Luiz Augusto von Dentz

      parent reply	other threads:[~2016-02-11 14:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-11 11:44 [PATCH BlueZ 1/3] tools/gatt-service: Fix using RegisterService Luiz Augusto von Dentz
2016-02-11 11:44 ` [PATCH BlueZ 2/3] tools/gatt-service: Add missing properties Luiz Augusto von Dentz
2016-02-11 11:44 ` [PATCH BlueZ 3/3] tools/gatt-service: Add missing methods Luiz Augusto von Dentz
2016-02-11 14:14 ` Luiz Augusto von Dentz [this message]

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='CABBYNZJq5SY0uShnJ=itxLJdt9rfk_6CBcWO=4NG6awdLJ_hLw@mail.gmail.com' \
    --to=luiz.dentz@gmail.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).