summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Holtmann <marcel@holtmann.org>2008-05-14 21:49:07 +0000
committerMarcel Holtmann <marcel@holtmann.org>2008-05-14 21:49:07 +0000
commit2ce4523624b67b48da037beceffe5710144850ec (patch)
treed9b89144c590890b60ca2892244560305cd82775
parent021c7fa891b23d8623beebf3f9ee79a36a1ff174 (diff)
Add support for IdleTimeout config option
-rw-r--r--input/device.c21
-rw-r--r--input/main.c26
-rw-r--r--input/manager.c17
-rw-r--r--input/manager.h2
4 files changed, 54 insertions, 12 deletions
diff --git a/input/device.c b/input/device.c
index 1975be16..131e626d 100644
--- a/input/device.c
+++ b/input/device.c
@@ -67,6 +67,7 @@ struct device;
struct device {
bdaddr_t src;
bdaddr_t dst;
+ int timeout;
char *name;
uint8_t major;
uint8_t minor;
@@ -84,7 +85,8 @@ struct device {
GSList *devices = NULL;
-static struct device *device_new(bdaddr_t *src, bdaddr_t *dst, uint8_t subclass)
+static struct device *device_new(bdaddr_t *src, bdaddr_t *dst,
+ uint8_t subclass, int timeout)
{
struct device *idev;
uint32_t cls;
@@ -105,6 +107,7 @@ static struct device *device_new(bdaddr_t *src, bdaddr_t *dst, uint8_t subclass)
bacpy(&idev->src, src);
bacpy(&idev->dst, dst);
+ idev->timeout = timeout;
read_device_name(src, dst, &idev->name);
@@ -498,11 +501,11 @@ static guint create_watch(int sk, GIOFunc cb, struct device *idev)
}
static int hidp_connadd(bdaddr_t *src, bdaddr_t *dst,
- int ctrl_sk, int intr_sk, const char *name)
+ int ctrl_sk, int intr_sk, int timeout, const char *name)
{
struct hidp_connadd_req req;
char addr[18];
- int ctl, err, timeout = 30;
+ int ctl, err;
ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_HIDP);
if (ctl < 0) {
@@ -516,7 +519,7 @@ static int hidp_connadd(bdaddr_t *src, bdaddr_t *dst,
req.ctrl_sock = ctrl_sk;
req.intr_sock = intr_sk;
req.flags = 0;
- req.idle_to = timeout * 60;
+ req.idle_to = timeout;
err = get_stored_device_info(src, dst, &req);
if (err < 0) {
@@ -561,7 +564,8 @@ static void interrupt_connect_cb(GIOChannel *chan, int err, gpointer user_data)
idev->intr_sk = g_io_channel_unix_get_fd(chan);
err = hidp_connadd(&idev->src, &idev->dst,
- idev->ctrl_sk, idev->intr_sk, idev->name);
+ idev->ctrl_sk, idev->intr_sk,
+ idev->timeout, idev->name);
if (err < 0)
goto failed;
@@ -964,7 +968,7 @@ int input_device_register(DBusConnection *conn, bdaddr_t *src, bdaddr_t *dst,
const char *path;
int err;
- idev = device_new(src, dst, hid->subclass);
+ idev = device_new(src, dst, hid->subclass, hid->idle_to);
if (!idev)
return -EINVAL;
@@ -994,7 +998,7 @@ int fake_input_register(DBusConnection *conn, bdaddr_t *src,
const char *path;
int err;
- idev = device_new(src, dst, 0);
+ idev = device_new(src, dst, 0, 0);
if (!idev)
return -EINVAL;
@@ -1165,7 +1169,8 @@ int input_device_connadd(bdaddr_t *src, bdaddr_t *dst)
fake->priv = fake_hid;
err = fake_hid_connadd(fake, idev->intr_sk, fake_hid);
} else
- err = hidp_connadd(src, dst, idev->ctrl_sk, idev->intr_sk, idev->name);
+ err = hidp_connadd(src, dst, idev->ctrl_sk, idev->intr_sk,
+ idev->timeout, idev->name);
if (err < 0)
goto error;
diff --git a/input/main.c b/input/main.c
index b57286b2..6018cf7e 100644
--- a/input/main.c
+++ b/input/main.c
@@ -34,6 +34,7 @@
#include "plugin.h"
#include "dbus-service.h"
+#include "logging.h"
#include "manager.h"
#define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
@@ -45,17 +46,40 @@ static const char *uuids[] = {
static DBusConnection *conn;
+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;
+
conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
if (conn == NULL)
return -EIO;
- if (input_manager_init(conn) < 0) {
+ config = load_config_file(CONFIGDIR "/input.conf");
+
+ if (input_manager_init(conn, config) < 0) {
dbus_connection_unref(conn);
return -EIO;
}
+ g_key_file_free(config);
+
register_service("input", uuids);
return 0;
diff --git a/input/manager.c b/input/manager.c
index 618641f1..13ca178d 100644
--- a/input/manager.c
+++ b/input/manager.c
@@ -63,6 +63,8 @@ struct pending_req {
GIOChannel *ctrl_channel;
};
+static int idle_timeout = 0;
+
static GSList *device_paths = NULL; /* Input registered paths */
static DBusConnection *connection = NULL;
@@ -227,6 +229,8 @@ static void interrupt_connect_cb(GIOChannel *chan, int err, gpointer user_data)
g_io_channel_close(chan);
g_io_channel_unref(chan);
+ hidp.idle_to = idle_timeout * 60;
+
extract_hid_record(pr->hid_recs->data, &hidp);
if (pr->pnp_recs)
extract_pnp_record(pr->pnp_recs->data, &hidp);
@@ -753,9 +757,18 @@ static DBusSignalVTable manager_signals[] = {
{ NULL, NULL }
};
-int input_manager_init(DBusConnection *conn)
+int input_manager_init(DBusConnection *conn, GKeyFile *config)
{
- dbus_connection_set_exit_on_disconnect(conn, TRUE);
+ GError *err = NULL;
+
+ if (config) {
+ idle_timeout = g_key_file_get_integer(config, "General",
+ "IdleTimeout", &err);
+ if (err) {
+ debug("input.conf: %s", err->message);
+ g_error_free(err);
+ }
+ }
if (!dbus_connection_create_object_path(conn, INPUT_PATH,
NULL, manager_unregister)) {
diff --git a/input/manager.h b/input/manager.h
index cccff683..8f9d999e 100644
--- a/input/manager.h
+++ b/input/manager.h
@@ -24,5 +24,5 @@
#define INPUT_PATH "/org/bluez/input"
#define INPUT_MANAGER_INTERFACE "org.bluez.input.Manager"
-int input_manager_init(DBusConnection *conn);
+int input_manager_init(DBusConnection *conn, GKeyFile *config);
void input_manager_exit(void);