summaryrefslogtreecommitdiff
path: root/profiles/network
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2012-09-03 14:11:36 +0300
committerJohan Hedberg <johan.hedberg@intel.com>2012-09-03 14:16:15 +0300
commit813b674bce1aab009e7f2d14d1825f603330563d (patch)
treecae198a1ee959b3cafd9f528e8c3ccacebbd77ae /profiles/network
parentc7c092bca3f13348f2f92e72999ee585f98e7974 (diff)
downloadbluez-813b674bce1aab009e7f2d14d1825f603330563d.tar.gz
Add profile abstraction (replaces btd_device drivers)
This patch removes the btd_device_driver concept and replaces it with btd_profile. The new construct also contains the necessary parts for adapter drivers, so btd_adapter_driver is only needed for non-profile related functionality (most of which is in plugins/*). The main purpose of this new construct is to facilitate a centralized connection creation mechanism for profiles, ultimately enabling the addition of a Device.Connect() method instead of requiring a UI to know to call e.g. Input.Connect or Audio.Connect. This feature will also be extended to externally implemented profiles once the internal implementation gets more stable, such as OBEX (obexd) and HFP (oFono). The new D-Bus interface will also partially restore functionality which was previously available through the Serial interface.
Diffstat (limited to 'profiles/network')
-rw-r--r--profiles/network/connection.c14
-rw-r--r--profiles/network/connection.h2
-rw-r--r--profiles/network/manager.c91
3 files changed, 27 insertions, 80 deletions
diff --git a/profiles/network/connection.c b/profiles/network/connection.c
index 40b360f94..dba448e80 100644
--- a/profiles/network/connection.c
+++ b/profiles/network/connection.c
@@ -26,6 +26,7 @@
#endif
#include <stdio.h>
+#include <stdbool.h>
#include <errno.h>
#include <unistd.h>
#include <netinet/in.h>
@@ -573,23 +574,16 @@ static const GDBusSignalTable connection_signals[] = {
{ }
};
-void connection_unregister(const char *path, uint16_t id)
+void connection_unregister(const char *path)
{
struct network_peer *peer;
- struct network_conn *nc;
peer = find_peer(peers, path);
if (!peer)
return;
- nc = find_connection(peer->connections, id);
- if (!nc)
- return;
-
- peer->connections = g_slist_remove(peer->connections, nc);
- connection_free(nc);
- if (peer->connections)
- return;
+ g_slist_free_full(peer->connections, connection_free);
+ peer->connections = NULL;
g_dbus_unregister_interface(connection, path, NETWORK_PEER_INTERFACE);
}
diff --git a/profiles/network/connection.h b/profiles/network/connection.h
index 5ea4147db..a5e0e613c 100644
--- a/profiles/network/connection.h
+++ b/profiles/network/connection.h
@@ -25,4 +25,4 @@ int connection_init(DBusConnection *conn);
void connection_exit(void);
int connection_register(struct btd_device *device, const char *path,
bdaddr_t *src, bdaddr_t *dst, uint16_t id);
-void connection_unregister(const char *path, uint16_t id);
+void connection_unregister(const char *path);
diff --git a/profiles/network/manager.c b/profiles/network/manager.c
index 7fcd8f08b..ac36406e9 100644
--- a/profiles/network/manager.c
+++ b/profiles/network/manager.c
@@ -25,6 +25,8 @@
#include <config.h>
#endif
+#include <stdbool.h>
+
#include <bluetooth/bluetooth.h>
#include <bluetooth/bnep.h>
#include <bluetooth/sdp.h>
@@ -72,7 +74,7 @@ done:
conf_security ? "true" : "false");
}
-static int network_probe(struct btd_device *device, GSList *uuids, uint16_t id)
+static int network_probe(struct btd_device *device, GSList *uuids)
{
struct btd_adapter *adapter = device_get_adapter(device);
const gchar *path = device_get_path(device);
@@ -83,46 +85,23 @@ static int network_probe(struct btd_device *device, GSList *uuids, uint16_t id)
adapter_get_address(adapter, &src);
device_get_address(device, &dst, NULL);
- return connection_register(device, path, &src, &dst, id);
+ if (g_slist_find_custom(uuids, PANU_UUID, bt_uuid_strcmp))
+ connection_register(device, path, &src, &dst, BNEP_SVC_PANU);
+ if (g_slist_find_custom(uuids, GN_UUID, bt_uuid_strcmp))
+ connection_register(device, path, &src, &dst, BNEP_SVC_GN);
+ if (g_slist_find_custom(uuids, NAP_UUID, bt_uuid_strcmp))
+ connection_register(device, path, &src, &dst, BNEP_SVC_NAP);
+
+ return 0;
}
-static void network_remove(struct btd_device *device, uint16_t id)
+static void network_remove(struct btd_device *device)
{
const gchar *path = device_get_path(device);
DBG("path %s", path);
- connection_unregister(path, id);
-}
-
-static int panu_probe(struct btd_device *device, GSList *uuids)
-{
- return network_probe(device, uuids, BNEP_SVC_PANU);
-}
-
-static void panu_remove(struct btd_device *device)
-{
- network_remove(device, BNEP_SVC_PANU);
-}
-
-static int gn_probe(struct btd_device *device, GSList *uuids)
-{
- return network_probe(device, uuids, BNEP_SVC_GN);
-}
-
-static void gn_remove(struct btd_device *device)
-{
- network_remove(device, BNEP_SVC_GN);
-}
-
-static int nap_probe(struct btd_device *device, GSList *uuids)
-{
- return network_probe(device, uuids, BNEP_SVC_NAP);
-}
-
-static void nap_remove(struct btd_device *device)
-{
- network_remove(device, BNEP_SVC_NAP);
+ connection_unregister(path);
}
static int network_server_probe(struct btd_adapter *adapter)
@@ -143,31 +122,14 @@ static void network_server_remove(struct btd_adapter *adapter)
server_unregister(adapter);
}
-static struct btd_device_driver network_panu_driver = {
- .name = "network-panu",
- .uuids = BTD_UUIDS(PANU_UUID),
- .probe = panu_probe,
- .remove = panu_remove,
-};
-
-static struct btd_device_driver network_gn_driver = {
- .name = "network-gn",
- .uuids = BTD_UUIDS(GN_UUID),
- .probe = gn_probe,
- .remove = gn_remove,
-};
+static struct btd_profile network_profile = {
+ .name = "network",
+ .remote_uuids = BTD_UUIDS(PANU_UUID, GN_UUID, NAP_UUID),
+ .device_probe = network_probe,
+ .device_remove = network_remove,
-static struct btd_device_driver network_nap_driver = {
- .name = "network-nap",
- .uuids = BTD_UUIDS(NAP_UUID),
- .probe = nap_probe,
- .remove = nap_remove,
-};
-
-static struct btd_adapter_driver network_server_driver = {
- .name = "network-server",
- .probe = network_server_probe,
- .remove = network_server_remove,
+ .adapter_probe = network_server_probe,
+ .adapter_remove = network_server_remove,
};
int network_manager_init(DBusConnection *conn)
@@ -189,16 +151,11 @@ int network_manager_init(DBusConnection *conn)
if (server_init(conn, conf_security) < 0)
return -1;
- /* Register network server if it doesn't exist */
- btd_register_adapter_driver(&network_server_driver);
+ btd_profile_register(&network_profile);
if (connection_init(conn) < 0)
return -1;
- btd_register_device_driver(&network_panu_driver);
- btd_register_device_driver(&network_gn_driver);
- btd_register_device_driver(&network_nap_driver);
-
connection = dbus_connection_ref(conn);
return 0;
@@ -208,13 +165,9 @@ void network_manager_exit(void)
{
server_exit();
- btd_unregister_device_driver(&network_panu_driver);
- btd_unregister_device_driver(&network_gn_driver);
- btd_unregister_device_driver(&network_nap_driver);
-
connection_exit();
- btd_unregister_adapter_driver(&network_server_driver);
+ btd_profile_unregister(&network_profile);
dbus_connection_unref(connection);
connection = NULL;