summaryrefslogtreecommitdiff
path: root/profiles
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-12-11 11:08:57 +0200
committerJohan Hedberg <johan.hedberg@intel.com>2012-12-11 11:08:57 +0200
commit95b53a22a904f2883d58e9b09d168e4efc3afb0f (patch)
treef431d0fa869a04f47e6a84703bf01912eb57ebde /profiles
parentbef8a121edcda710c1c3ed2074a505557dd7d225 (diff)
downloadbluez-95b53a22a904f2883d58e9b09d168e4efc3afb0f.tar.gz
input: Fix profile connection status notifications
Diffstat (limited to 'profiles')
-rw-r--r--profiles/input/device.c49
-rw-r--r--profiles/input/main.c77
-rw-r--r--profiles/input/manager.c40
-rw-r--r--profiles/input/manager.h4
4 files changed, 48 insertions, 122 deletions
diff --git a/profiles/input/device.c b/profiles/input/device.c
index 9120a05e3..2d8077a86 100644
--- a/profiles/input/device.c
+++ b/profiles/input/device.c
@@ -47,19 +47,15 @@
#include "../src/storage.h"
#include "../src/dbus-common.h"
+#include "manager.h"
#include "device.h"
#include "error.h"
#include <btio/btio.h>
#include "sdp-client.h"
-struct pending_connect {
- struct btd_profile *profile;
-};
-
struct input_device {
struct btd_device *device;
- struct pending_connect *pending;
char *path;
char *uuid;
bdaddr_t src;
@@ -100,9 +96,6 @@ static void input_device_free(struct input_device *idev)
g_free(idev->name);
g_free(idev->path);
- if (idev->pending)
- g_free(idev->pending);
-
if (idev->ctrl_watch > 0)
g_source_remove(idev->ctrl_watch);
@@ -481,46 +474,25 @@ static int input_device_connected(struct input_device *idev)
idev->dc_id = device_add_disconnect_watch(idev->device, disconnect_cb,
idev, NULL);
- return 0;
-}
-
-static void connect_reply(struct input_device *idev, int err,
- const char *err_msg)
-{
- struct pending_connect *pending = idev->pending;
-
- if (!pending)
- return;
-
- idev->pending = NULL;
-
- if (err_msg)
- error("%s", err_msg);
+ input_manager_device_connected(idev->device, 0);
- device_profile_connected(idev->device, pending->profile, err);
- g_free(pending);
+ return 0;
}
static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
gpointer user_data)
{
struct input_device *idev = user_data;
- const char *err_msg;
int err;
if (conn_err) {
- err_msg = conn_err->message;
err = -EIO;
goto failed;
}
err = input_device_connected(idev);
- if (err < 0) {
- err_msg = strerror(-err);
+ if (err < 0)
goto failed;
- }
-
- connect_reply(idev, 0, NULL);
idev->intr_watch = g_io_add_watch(idev->intr_io,
G_IO_HUP | G_IO_ERR | G_IO_NVAL,
@@ -529,7 +501,7 @@ static void interrupt_connect_cb(GIOChannel *chan, GError *conn_err,
return;
failed:
- connect_reply(idev, err, err_msg);
+ input_manager_device_connected(idev->device, err);
/* So we guarantee the interrupt channel is closed before the
* control channel (if we only do unref GLib will close it only
@@ -555,7 +527,6 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
if (conn_err) {
error("%s", conn_err->message);
- connect_reply(idev, -EIO, conn_err->message);
goto failed;
}
@@ -569,7 +540,6 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
BT_IO_OPT_INVALID);
if (!io) {
error("%s", err->message);
- connect_reply(idev, -EIO, err->message);
g_error_free(err);
goto failed;
}
@@ -583,6 +553,7 @@ static void control_connect_cb(GIOChannel *chan, GError *conn_err,
return;
failed:
+ input_manager_device_connected(idev->device, -EIO);
g_io_channel_unref(idev->ctrl_io);
idev->ctrl_io = NULL;
}
@@ -608,7 +579,6 @@ static int dev_connect(struct input_device *idev)
return 0;
error("%s", err->message);
- connect_reply(idev, -EIO, err->message);
g_error_free(err);
return -EIO;
@@ -622,15 +592,12 @@ int input_device_connect(struct btd_device *dev, struct btd_profile *profile)
if (!idev)
return -ENOENT;
- if (idev->pending)
+ if (idev->ctrl_io)
return -EBUSY;
if (is_connected(idev))
return -EALREADY;
- idev->pending = g_new0(struct pending_connect, 1);
- idev->pending->profile = profile;
-
return dev_connect(idev);
}
@@ -734,7 +701,7 @@ int input_device_unregister(const char *path, const char *uuid)
if (idev == NULL)
return -EINVAL;
- if (idev->pending) {
+ if (idev->ctrl_io) {
/* Pending connection running */
return -EBUSY;
}
diff --git a/profiles/input/main.c b/profiles/input/main.c
deleted file mode 100644
index 29337d9cf..000000000
--- a/profiles/input/main.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- *
- * BlueZ - Bluetooth protocol stack for Linux
- *
- * Copyright (C) 2004-2010 Marcel Holtmann <marcel@holtmann.org>
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <errno.h>
-
-#include <bluetooth/bluetooth.h>
-
-#include <gdbus/gdbus.h>
-
-#include "plugin.h"
-#include "hcid.h"
-#include "log.h"
-#include "manager.h"
-
-static GKeyFile *load_config_file(const char *file)
-{
- GKeyFile *keyfile;
- GError *err = NULL;
-
- keyfile = g_key_file_new();
-
- if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
- error("Parsing %s failed: %s", file, err->message);
- g_error_free(err);
- g_key_file_free(keyfile);
- return NULL;
- }
-
- return keyfile;
-}
-
-static int input_init(void)
-{
- GKeyFile *config;
-
- config = load_config_file(CONFIGDIR "/input.conf");
-
- if (input_manager_init(config) < 0)
- return -EIO;
-
- if (config)
- g_key_file_free(config);
-
- return 0;
-}
-
-static void input_exit(void)
-{
- input_manager_exit();
-}
-
-BLUETOOTH_PLUGIN_DEFINE(input, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
- input_init, input_exit)
diff --git a/profiles/input/manager.c b/profiles/input/manager.c
index b8e89c340..622e24b54 100644
--- a/profiles/input/manager.c
+++ b/profiles/input/manager.c
@@ -34,6 +34,7 @@
#include <bluetooth/uuid.h>
#include "log.h"
+#include "plugin.h"
#include "../src/adapter.h"
#include "../src/device.h"
#include "../src/profile.h"
@@ -100,10 +101,39 @@ static struct btd_profile input_profile = {
.adapter_remove = hid_server_remove,
};
-int input_manager_init(GKeyFile *config)
+void input_manager_device_connected(struct btd_device *dev, int err)
{
+ device_profile_connected(dev, &input_profile, err);
+}
+
+void input_manager_device_disconnected(struct btd_device *dev, int err)
+{
+ device_profile_disconnected(dev, &input_profile, err);
+}
+
+static GKeyFile *load_config_file(const char *file)
+{
+ GKeyFile *keyfile;
+ GError *err = NULL;
+
+ keyfile = g_key_file_new();
+
+ if (!g_key_file_load_from_file(keyfile, file, 0, &err)) {
+ error("Parsing %s failed: %s", file, err->message);
+ g_error_free(err);
+ g_key_file_free(keyfile);
+ return NULL;
+ }
+
+ return keyfile;
+}
+
+static int input_init(void)
+{
+ GKeyFile *config;
GError *err = NULL;
+ config = load_config_file(CONFIGDIR "/input.conf");
if (config) {
idle_timeout = g_key_file_get_integer(config, "General",
"IdleTimeout", &err);
@@ -115,10 +145,16 @@ int input_manager_init(GKeyFile *config)
btd_profile_register(&input_profile);
+ if (config)
+ g_key_file_free(config);
+
return 0;
}
-void input_manager_exit(void)
+static void input_exit(void)
{
btd_profile_unregister(&input_profile);
}
+
+BLUETOOTH_PLUGIN_DEFINE(input, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+ input_init, input_exit)
diff --git a/profiles/input/manager.h b/profiles/input/manager.h
index 3f73253f0..3a050944f 100644
--- a/profiles/input/manager.h
+++ b/profiles/input/manager.h
@@ -21,5 +21,5 @@
*
*/
-int input_manager_init(GKeyFile *config);
-void input_manager_exit(void);
+void input_manager_device_connected(struct btd_device *dev, int err);
+void input_manager_device_disconnected(struct btd_device *dev, int err);