diff options
| author | Marcel Holtmann <marcel@holtmann.org> | 2008-06-08 22:57:11 +0000 | 
|---|---|---|
| committer | Marcel Holtmann <marcel@holtmann.org> | 2008-06-08 22:57:11 +0000 | 
| commit | 5243ac4fd278b0176ece84cbcec537a92a9c7290 (patch) | |
| tree | 912b65f15a18410d84563ef95f0595d5b3504121 | |
| parent | f22b20c3d40bd7571944af6a4946f756dc39f812 (diff) | |
Update probe/remove callback and implement serial API
| -rw-r--r-- | audio/main.c | 16 | ||||
| -rw-r--r-- | hcid/device.c | 8 | ||||
| -rw-r--r-- | hcid/device.h | 11 | ||||
| -rw-r--r-- | input/main.c | 14 | ||||
| -rw-r--r-- | network/main.c | 14 | ||||
| -rw-r--r-- | serial/main.c | 46 | ||||
| -rw-r--r-- | serial/manager.c | 19 | ||||
| -rw-r--r-- | serial/manager.h | 5 | 
8 files changed, 85 insertions, 48 deletions
| diff --git a/audio/main.c b/audio/main.c index 9b780aa0..86efce27 100644 --- a/audio/main.c +++ b/audio/main.c @@ -42,16 +42,16 @@  static DBusConnection *conn; -static int headset_probe(const char *path) +static int headset_probe(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path);  	return 0;  } -static void headset_remove(const char *path) +static void headset_remove(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path);  }  static struct btd_device_driver headset_driver = { @@ -61,16 +61,16 @@ static struct btd_device_driver headset_driver = {  	.remove	= headset_remove,  }; -static int a2dp_probe(const char *path) +static int a2dp_probe(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path);  	return 0;  } -static void a2dp_remove(const char *path) +static void a2dp_remove(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path);  }  static struct btd_device_driver a2dp_driver = { diff --git a/hcid/device.c b/hcid/device.c index e01bf7d2..b040df91 100644 --- a/hcid/device.c +++ b/hcid/device.c @@ -1086,6 +1086,10 @@ struct device *device_create(DBusConnection *conn, struct adapter *adapter,  	device->adapter = adapter;  	device->uuids = uuids; +	device->dev.path = device->path; +	str2ba(device->address, &device->dev.dst); +	str2ba(adapter->address, &device->dev.src); +  	return device;  } @@ -1100,7 +1104,7 @@ void device_remove(DBusConnection *conn, struct device *device)  	for (list = device->drivers; list; list = list->next) {  		driver = (struct btd_device_driver *) list->data; -		driver->remove(device->path); +		driver->remove(&device->dev);  	}  	g_dbus_unregister_interface(conn, path, DEVICE_INTERFACE); @@ -1137,7 +1141,7 @@ void device_probe_drivers(struct device *device)  		if (do_probe == TRUE && !g_slist_find_custom(device->drivers,  					driver->name, (GCompareFunc) strcmp)) { -			err = driver->probe(device->path); +			err = driver->probe(&device->dev);  			if (err < 0)  				error("probe failed for driver %s",  							driver->name); diff --git a/hcid/device.h b/hcid/device.h index 38ad8030..420985fd 100644 --- a/hcid/device.h +++ b/hcid/device.h @@ -24,7 +24,14 @@  #define DEVICE_INTERFACE	"org.bluez.Device" +struct btd_device { +	char *path; +	bdaddr_t src; +	bdaddr_t dst; +}; +  struct device { +	struct btd_device dev;  	gchar		*address;  	gchar		*path;  	struct adapter	*adapter; @@ -47,8 +54,8 @@ void device_probe_drivers(struct device *device);  struct btd_device_driver {  	const char *name;  	const char **uuids; -	int (*probe) (const char *path); -	void (*remove) (const char *path); +	int (*probe) (struct btd_device *device); +	void (*remove) (struct btd_device *device);  };  int btd_register_device_driver(struct btd_device_driver *driver); diff --git a/input/main.c b/input/main.c index 6a667f51..9a27a2ef 100644 --- a/input/main.c +++ b/input/main.c @@ -75,23 +75,23 @@ static GDBusSignalTable input_signals[] = {  static DBusConnection *conn; -static int input_probe(const char *path) +static int input_probe(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	if (g_dbus_register_interface(conn, path, INPUT_INTERFACE, +	if (g_dbus_register_interface(conn, device->path, INPUT_INTERFACE,  					input_methods, input_signals, NULL, -							NULL, NULL) == FALSE) +							device, NULL) == FALSE)  		return -1;  	return 0;  } -static void input_remove(const char *path) +static void input_remove(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	g_dbus_unregister_interface(conn, path, INPUT_INTERFACE); +	g_dbus_unregister_interface(conn, device->path, INPUT_INTERFACE);  }  static struct btd_device_driver input_driver = { diff --git a/network/main.c b/network/main.c index edfd0757..8e18dd99 100644 --- a/network/main.c +++ b/network/main.c @@ -82,23 +82,23 @@ static GDBusSignalTable network_signals[] = {  static DBusConnection *conn; -static int network_probe(const char *path) +static int network_probe(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	if (g_dbus_register_interface(conn, path, NETWORK_INTERFACE, +	if (g_dbus_register_interface(conn, device->path, NETWORK_INTERFACE,  					network_methods, network_signals, NULL, -							NULL, NULL) == FALSE) +							device, NULL) == FALSE)  		return -1;  	return 0;  } -static void network_remove(const char *path) +static void network_remove(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	g_dbus_unregister_interface(conn, path, NETWORK_INTERFACE); +	g_dbus_unregister_interface(conn, device->path, NETWORK_INTERFACE);  }  static struct btd_device_driver network_driver = { diff --git a/serial/main.c b/serial/main.c index b042e2e7..60ce9d45 100644 --- a/serial/main.c +++ b/serial/main.c @@ -35,64 +35,84 @@  #include "plugin.h"  #include "device.h" +#include "adapter.h"  #include "logging.h"  #include "manager.h" +#include "port.h"  #define SERIAL_PORT_UUID	"00001101-0000-1000-8000-00805F9B34FB"  #define DIALUP_NET_UUID		"00001103-0000-1000-8000-00805F9B34FB" -#define SERIAL_INTERFACE "org.bluez.Serial" +#define SERIAL_INTERFACE     "org.bluez.Serial" +#define ERROR_INVALID_ARGS   "org.bluez.Error.InvalidArguments" +#define ERROR_DOES_NOT_EXIST "org.bluez.Error.DoesNotExist"  static DBusMessage *serial_connect(DBusConnection *conn,  					DBusMessage *msg, void *user_data)  { -	const char *target, *device = "/dev/rfcomm0"; +	struct btd_device *device = user_data; +	const char *target; +	char src[18], dst[18];  	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &target,  						DBUS_TYPE_INVALID) == FALSE)  		return NULL; -	return g_dbus_create_reply(msg, DBUS_TYPE_STRING, &device, -							DBUS_TYPE_INVALID); +	ba2str(&device->src, src); +	ba2str(&device->dst, dst); + +	service_connect(conn, msg, src, dst, target); + +	return NULL;  }  static DBusMessage *serial_disconnect(DBusConnection *conn,  					DBusMessage *msg, void *user_data)  { -	const char *device; +	const char *device, *sender; +	int err, id;  	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &device,  						DBUS_TYPE_INVALID) == FALSE)  		return NULL; +	sender = dbus_message_get_sender(msg); + +	if (sscanf(device, "/dev/rfcomm%d", &id) != 1) +		return g_dbus_create_error(msg, ERROR_INVALID_ARGS, NULL); + +	err = port_remove_listener(sender, device); +	if (err < 0) +		return g_dbus_create_error(msg, ERROR_DOES_NOT_EXIST, NULL); +  	return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);  }  static GDBusMethodTable serial_methods[] = { -	{ "Connect",    "s", "s", serial_connect    }, +	{ "Connect",    "s", "s", serial_connect, G_DBUS_METHOD_FLAG_ASYNC },  	{ "Disconnect", "s", "",  serial_disconnect },  	{ }  };  static DBusConnection *conn; -static int serial_probe(const char *path) +static int serial_probe(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	if (g_dbus_register_interface(conn, path, SERIAL_INTERFACE, +	if (g_dbus_register_interface(conn, device->path, SERIAL_INTERFACE,  						serial_methods, NULL, NULL, -							NULL, NULL) == FALSE) +							device, NULL) == FALSE)  		return -1;  	return 0;  } -static void serial_remove(const char *path) +static void serial_remove(struct btd_device *device)  { -	DBG("path %s", path); +	DBG("path %s", device->path); -	g_dbus_unregister_interface(conn, path, SERIAL_INTERFACE); +	g_dbus_unregister_interface(conn, device->path, SERIAL_INTERFACE);  }  static struct btd_device_driver serial_driver = { diff --git a/serial/manager.c b/serial/manager.c index f097b330..442c386e 100644 --- a/serial/manager.c +++ b/serial/manager.c @@ -1636,9 +1636,10 @@ static DBusMessage *connect_channel(DBusConnection *conn, DBusMessage *msg,  	return connect_pending(conn, msg, pc);  } -static DBusMessage *service_connect(DBusConnection *conn, DBusMessage *msg, -					const char *adapter, const char *address, -					const char *pattern, void *data) +DBusMessage *service_connect(DBusConnection *conn, DBusMessage *msg, +						const char *adapter, +						const char *address, +						const char *pattern)  {  	int dev_id;  	bdaddr_t src; @@ -1658,13 +1659,13 @@ static DBusMessage *service_connect(DBusConnection *conn, DBusMessage *msg,  	/* Friendly name or uuid128 */  	if (pattern2uuid(pattern, &uuid) == 0) -		return search_uuid(conn, msg, adp, address, pattern, &uuid, -				data); +		return search_uuid(conn, msg, adp, address, +						pattern, &uuid, NULL);  	/* RFCOMM Channel */  	if (pattern2long(pattern, &val) == 0) -		return connect_channel(conn, msg, adp, address, pattern, -					val, data); +		return connect_channel(conn, msg, adp, address, +							pattern, val, NULL);  	return invalid_arguments(msg, "Invalid Pattern");  } @@ -1680,7 +1681,7 @@ static DBusMessage *connect_service(DBusConnection *conn,  				DBUS_TYPE_INVALID))  		return NULL; -	return service_connect(conn, msg, NULL, address, pattern, data); +	return service_connect(conn, msg, NULL, address, pattern);  }  static DBusMessage *connect_service_from_adapter(DBusConnection *conn, @@ -1695,7 +1696,7 @@ static DBusMessage *connect_service_from_adapter(DBusConnection *conn,  				DBUS_TYPE_INVALID))  		return NULL; -	return service_connect(conn, msg, adapter, address, pattern, data); +	return service_connect(conn, msg, adapter, address, pattern);  }  static DBusMessage *disconnect_service(DBusConnection *conn, diff --git a/serial/manager.h b/serial/manager.h index b25c2686..fdcc8ab9 100644 --- a/serial/manager.h +++ b/serial/manager.h @@ -27,3 +27,8 @@  int serial_manager_init(DBusConnection *conn);  void serial_manager_exit(void);  int rfcomm_release(int16_t id); + +DBusMessage *service_connect(DBusConnection *conn, DBusMessage *msg, +						const char *adapter, +						const char *address, +						const char *pattern); | 
