diff options
author | Johan Hedberg <johan.hedberg@nokia.com> | 2007-05-04 15:32:26 +0000 |
---|---|---|
committer | Johan Hedberg <johan.hedberg@nokia.com> | 2007-05-04 15:32:26 +0000 |
commit | 994212593598a7c176342e616bc99aae45991244 (patch) | |
tree | b27993a278543aafe294543adec27b4fe85ff4ba /hcid | |
parent | 16dceb4c2f7a8ed91c88b1c1353b6bd5ccc68cbf (diff) |
Convert to using the generic D-Bus object handling
Diffstat (limited to 'hcid')
-rw-r--r-- | hcid/dbus-adapter.c | 238 | ||||
-rw-r--r-- | hcid/dbus-adapter.h | 2 | ||||
-rw-r--r-- | hcid/dbus-common.c | 43 | ||||
-rw-r--r-- | hcid/dbus-database.c | 36 | ||||
-rw-r--r-- | hcid/dbus-database.h | 2 | ||||
-rw-r--r-- | hcid/dbus-hci.c | 72 | ||||
-rw-r--r-- | hcid/dbus-manager.c | 54 | ||||
-rw-r--r-- | hcid/dbus-manager.h | 2 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.c | 93 | ||||
-rw-r--r-- | hcid/dbus-rfcomm.h | 2 | ||||
-rw-r--r-- | hcid/dbus-sdp.c | 3 | ||||
-rw-r--r-- | hcid/dbus-security.c | 41 | ||||
-rw-r--r-- | hcid/dbus-security.h | 2 | ||||
-rw-r--r-- | hcid/dbus-test.c | 40 | ||||
-rw-r--r-- | hcid/dbus-test.h | 2 |
15 files changed, 364 insertions, 268 deletions
diff --git a/hcid/dbus-adapter.c b/hcid/dbus-adapter.c index 0466404f..ee9be216 100644 --- a/hcid/dbus-adapter.c +++ b/hcid/dbus-adapter.c @@ -3088,89 +3088,169 @@ GSList *service_classes_str(uint32_t class) return l; } -static struct service_data dev_services[] = { - { "GetInfo", adapter_get_info }, - { "GetAddress", adapter_get_address }, - { "GetVersion", adapter_get_version }, - { "GetRevision", adapter_get_revision }, - { "GetManufacturer", adapter_get_manufacturer }, - { "GetCompany", adapter_get_company }, - { "GetMode", adapter_get_mode }, - { "SetMode", adapter_set_mode }, - { "GetDiscoverableTimeout", adapter_get_discoverable_to }, - { "SetDiscoverableTimeout", adapter_set_discoverable_to }, - { "IsConnectable", adapter_is_connectable }, - { "IsDiscoverable", adapter_is_discoverable }, - { "IsConnected", adapter_is_connected }, - { "ListConnections", adapter_list_connections }, - { "GetMajorClass", adapter_get_major_class }, - { "ListAvailableMinorClasses", adapter_list_minor_classes }, - { "GetMinorClass", adapter_get_minor_class }, - { "SetMinorClass", adapter_set_minor_class }, - { "GetServiceClasses", adapter_get_service_classes }, - { "GetName", adapter_get_name }, - { "SetName", adapter_set_name }, +static DBusMethodVTable adapter_methods[] = { + { "GetInfo", adapter_get_info, + "", "{}" }, + { "GetAddress", adapter_get_address, + "", "s" }, + { "GetVersion", adapter_get_version, + "", "s" }, + { "GetRevision", adapter_get_revision, + "", "s" }, + { "GetManufacturer", adapter_get_manufacturer, + "", "s" }, + { "GetCompany", adapter_get_company, + "", "s" }, + { "GetMode", adapter_get_mode, + "", "s" }, + { "SetMode", adapter_set_mode, + "s", "" }, + { "GetDiscoverableTimeout", adapter_get_discoverable_to, + "", "u" }, + { "SetDiscoverableTimeout", adapter_set_discoverable_to, + "u", "" }, + { "IsConnectable", adapter_is_connectable, + "", "b" }, + { "IsDiscoverable", adapter_is_discoverable, + "", "b" }, + { "IsConnected", adapter_is_connected, + "s", "b" }, + { "ListConnections", adapter_list_connections, + "", "as" }, + { "GetMajorClass", adapter_get_major_class, + "", "s" }, + { "ListAvailableMinorClasses", adapter_list_minor_classes, + "", "as" }, + { "GetMinorClass", adapter_get_minor_class, + "", "s" }, + { "SetMinorClass", adapter_set_minor_class, + "s", "" }, + { "GetServiceClasses", adapter_get_service_classes, + "", "as" }, + { "GetName", adapter_get_name, + "", "s" }, + { "SetName", adapter_set_name, + "s", "" }, - { "GetRemoteInfo", adapter_get_remote_info }, - { "GetRemoteServiceRecord", adapter_get_remote_svc }, - { "GetRemoteServiceRecordAsXML", adapter_get_remote_svc_xml }, - { "GetRemoteServiceHandles", adapter_get_remote_svc_handles }, - - { "GetRemoteVersion", adapter_get_remote_version }, - { "GetRemoteRevision", adapter_get_remote_revision }, - { "GetRemoteManufacturer", adapter_get_remote_manufacturer }, - { "GetRemoteCompany", adapter_get_remote_company }, - { "GetRemoteMajorClass", adapter_get_remote_major_class }, - { "GetRemoteMinorClass", adapter_get_remote_minor_class }, - { "GetRemoteServiceClasses", adapter_get_remote_service_cls }, - { "GetRemoteClass", adapter_get_remote_class }, - { "GetRemoteFeatures", adapter_get_remote_features }, - { "GetRemoteName", adapter_get_remote_name }, - { "GetRemoteAlias", adapter_get_remote_alias }, - { "SetRemoteAlias", adapter_set_remote_alias }, - { "ClearRemoteAlias", adapter_clear_remote_alias }, - - { "LastSeen", adapter_last_seen }, - { "LastUsed", adapter_last_used }, - - { "DisconnectRemoteDevice", adapter_dc_remote_device }, - - { "CreateBonding", adapter_create_bonding }, - { "CancelBondingProcess", adapter_cancel_bonding }, - { "RemoveBonding", adapter_remove_bonding }, - { "HasBonding", adapter_has_bonding }, - { "ListBondings", adapter_list_bondings }, - { "GetPinCodeLength", adapter_get_pin_code_length }, - { "GetEncryptionKeySize", adapter_get_encryption_key_size }, - - { "StartPeriodicDiscovery", adapter_start_periodic }, - { "StopPeriodicDiscovery", adapter_stop_periodic }, - { "IsPeriodicDiscovery", adapter_is_periodic }, - { "SetPeriodicDiscoveryNameResolving", adapter_set_pdiscov_resolve }, - { "GetPeriodicDiscoveryNameResolving", adapter_get_pdiscov_resolve }, - - { "DiscoverDevices", adapter_discover_devices }, - { "DiscoverDevicesWithoutNameResolving", adapter_discover_devices }, - { "CancelDiscovery", adapter_cancel_discovery }, - - { "ListRemoteDevices", adapter_list_remote_devices }, - { "ListRecentRemoteDevices", adapter_list_recent_remote_devices }, - - { "SetTrusted", adapter_set_trusted }, - { "IsTrusted", adapter_is_trusted }, - { "RemoveTrust", adapter_remove_trust }, + { "GetRemoteInfo", adapter_get_remote_info, + "s", "{}" }, + { "GetRemoteServiceRecord", adapter_get_remote_svc, + "su", "ay" }, + { "GetRemoteServiceRecordAsXML", adapter_get_remote_svc_xml, + "su", "s" }, + { "GetRemoteServiceHandles", adapter_get_remote_svc_handles, + "ss", "au" }, + + { "GetRemoteVersion", adapter_get_remote_version, + "s", "s" }, + { "GetRemoteRevision", adapter_get_remote_revision, + "s", "s" }, + { "GetRemoteManufacturer", adapter_get_remote_manufacturer, + "s", "s" }, + { "GetRemoteCompany", adapter_get_remote_company, + "s", "s" }, + { "GetRemoteMajorClass", adapter_get_remote_major_class, + "s", "s" }, + { "GetRemoteMinorClass", adapter_get_remote_minor_class, + "s", "s" }, + { "GetRemoteServiceClasses", adapter_get_remote_service_cls, + "s", "as" }, + { "GetRemoteClass", adapter_get_remote_class, + "s", "u" }, + { "GetRemoteFeatures", adapter_get_remote_features, + "s", "ay" }, + { "GetRemoteName", adapter_get_remote_name, + "s", "s" }, + { "GetRemoteAlias", adapter_get_remote_alias, + "s", "s" }, + { "SetRemoteAlias", adapter_set_remote_alias, + "ss", "" }, + { "ClearRemoteAlias", adapter_clear_remote_alias, + "s", "" }, + + { "LastSeen", adapter_last_seen, + "s", "s" }, + { "LastUsed", adapter_last_used, + "s", "s" }, + + { "DisconnectRemoteDevice", adapter_dc_remote_device, + "s", "" }, + + { "CreateBonding", adapter_create_bonding, + "s", "" }, + { "CancelBondingProcess", adapter_cancel_bonding, + "s", "" }, + { "RemoveBonding", adapter_remove_bonding, + "s", "" }, + { "HasBonding", adapter_has_bonding, + "s", "b" }, + { "ListBondings", adapter_list_bondings, + "", "as" }, + { "GetPinCodeLength", adapter_get_pin_code_length, + "s", "y" }, + { "GetEncryptionKeySize", adapter_get_encryption_key_size, + "s", "y" }, + + { "StartPeriodicDiscovery", adapter_start_periodic, + "", "" }, + { "StopPeriodicDiscovery", adapter_stop_periodic, + "", "" }, + { "IsPeriodicDiscovery", adapter_is_periodic, + "", "b" }, + { "SetPeriodicDiscoveryNameResolving", adapter_set_pdiscov_resolve, + "b", "" }, + { "GetPeriodicDiscoveryNameResolving", adapter_get_pdiscov_resolve, + "", "b" }, + + { "DiscoverDevices", adapter_discover_devices, + "", "" }, + { "DiscoverDevicesWithoutNameResolving", adapter_discover_devices, + "", "" }, + { "CancelDiscovery", adapter_cancel_discovery, + "", "" }, + + { "ListRemoteDevices", adapter_list_remote_devices, + "", "as" }, + { "ListRecentRemoteDevices", adapter_list_recent_remote_devices, + "", "as" }, + + { "SetTrusted", adapter_set_trusted, + "s", "" }, + { "IsTrusted", adapter_is_trusted, + "s", "b" }, + { "RemoveTrust", adapter_remove_trust, + "s", "" }, + + { NULL, NULL, NULL, NULL } +}; +static DBusSignalVTable adapter_signals[] = { + { "ModeChanged", "s" }, + { "DiscoverableTimeoutChanged", "u" }, + { "MinorClassChanged", "s" }, + { "NameChanged", "s" }, + { "DiscoveryStarted", "" }, + { "DiscoveryCompleted", "" }, + { "RemoteDeviceFound", "sun" }, + { "RemoteDeviceDisappeared", "s" }, + { "RemoteClassUpdated", "su" }, + { "RemoteNameUpdated", "ss" }, + { "RemoteNameFailed", "s" }, + { "RemoteNameRequested", "s" }, + { "RemoteAliasChanged", "ss" }, + { "RemoteAliasCleared", "s" }, + { "RemoteDeviceConnected", "s" }, + { "RemoteDeviceDisconnectRequested", "s" }, + { "RemoteDeviceDisconnected", "s" }, + { "BondingCreated", "s" }, + { "BondingRemoved", "s" }, { NULL, NULL } }; -DBusHandlerResult handle_adapter_method(DBusConnection *conn, DBusMessage *msg, void *data) +dbus_bool_t adapter_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - - handler = find_service_handler(dev_services, msg); - - if (handler) - return handler(conn, msg, data); - else - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, ADAPTER_INTERFACE, + adapter_methods, + adapter_signals, NULL); } + diff --git a/hcid/dbus-adapter.h b/hcid/dbus-adapter.h index 29a96546..6086787c 100644 --- a/hcid/dbus-adapter.h +++ b/hcid/dbus-adapter.h @@ -110,7 +110,7 @@ struct adapter { struct pending_dc_info *pending_dc; }; -DBusHandlerResult handle_adapter_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t adapter_init(DBusConnection *conn, const char *path); const char *major_class_str(uint32_t class); diff --git a/hcid/dbus-common.c b/hcid/dbus-common.c index cccf8da4..a7b733cf 100644 --- a/hcid/dbus-common.c +++ b/hcid/dbus-common.c @@ -50,11 +50,13 @@ #include "hcid.h" #include "dbus.h" +#include "dbus-helper.h" #include "dbus-error.h" #include "dbus-hci.h" #include "dbus-manager.h" #include "dbus-adapter.h" #include "dbus-service.h" +#include "dbus-database.h" #include "dbus-security.h" #include "dbus-test.h" #include "dbus-rfcomm.h" @@ -245,28 +247,6 @@ int check_address(const char *addr) return 0; } -DBusHandlerResult handle_method_call(DBusConnection *conn, DBusMessage *msg, void *data) -{ - const char *iface, *name; - - iface = dbus_message_get_interface(msg); - name = dbus_message_get_member(msg); - - if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && - !strcmp("Introspect", name)) - return simple_introspect(conn, msg, data); - else if (!strcmp(ADAPTER_INTERFACE, iface)) - return handle_adapter_method(conn, msg, data); - else if (!strcmp(SECURITY_INTERFACE, iface)) - return handle_security_method(conn, msg, data); - else if (!strcmp(TEST_INTERFACE, iface)) - return handle_test_method(conn, msg, data); - else if (!strcmp(RFCOMM_INTERFACE, iface)) - return handle_rfcomm_method(conn, msg, data); - else - return error_unknown_method(conn, msg); -} - void hcid_dbus_set_experimental(void) { experimental = 1; @@ -341,11 +321,6 @@ static void disconnect_callback(void *user_data) system_bus_reconnect, NULL); } -static const DBusObjectPathVTable manager_vtable = { - .message_function = &handle_manager_method, - .unregister_function = NULL -}; - void hcid_dbus_exit(void) { char **children; @@ -390,11 +365,17 @@ int hcid_dbus_init(void) if (!conn) return -1; - if (!dbus_connection_register_fallback(conn, BASE_PATH, - &manager_vtable, NULL)) { - error("D-Bus failed to register %s fallback", BASE_PATH); + if (!dbus_connection_create_object_path(conn, BASE_PATH, NULL, NULL)) + return -1; + + if (!manager_init(conn, BASE_PATH)) + return -1; + + if (!database_init(conn, BASE_PATH)) + return -1; + + if (!security_init(conn, BASE_PATH)) return -1; - } set_dbus_connection(conn); diff --git a/hcid/dbus-database.c b/hcid/dbus-database.c index 3e65b02d..0e1d2f7b 100644 --- a/hcid/dbus-database.c +++ b/hcid/dbus-database.c @@ -40,6 +40,7 @@ #include <dbus/dbus.h> #include "dbus.h" +#include "dbus-helper.h" #include "hcid.h" #include "sdpd.h" #include "sdp-xml.h" @@ -451,29 +452,24 @@ static DBusHandlerResult cancel_authorization_request(DBusConnection *conn, return cancel_authorize_request(conn, msg, service, address, path); } -static struct service_data database_services[] = { - { "AddServiceRecord", add_service_record }, - { "AddServiceRecordFromXML", add_service_record_from_xml }, - { "UpdateServiceRecord", update_service_record }, - { "RemoveServiceRecord", remove_service_record }, - { "RegisterService", register_service }, - { "UnregisterService", unregister_service }, - { "RequestAuthorization", request_authorization }, - { "CancelAuthorizationRequest", cancel_authorization_request }, - { NULL, NULL } +static DBusMethodVTable database_methods[] = { + { "AddServiceRecord", add_service_record, "ay", "u" }, + { "AddServiceRecordFromXML", add_service_record_from_xml, "s", "u" }, + { "UpdateServiceRecord", update_service_record, "uay", "" }, + { "RemoveServiceRecord", remove_service_record, "u", "" }, + { "RegisterService", register_service, "sss", "" }, + { "UnregisterService", unregister_service, "s", "" }, + { "RequestAuthorization", request_authorization, "ss", "" }, + { "CancelAuthorizationRequest", cancel_authorization_request, "ss", "" }, + { NULL, NULL, NULL, NULL } }; -DBusHandlerResult handle_database_method(DBusConnection *conn, - DBusMessage *msg, void *data) +dbus_bool_t database_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - - handler = find_service_handler(database_services, msg); - - if (handler) - return handler(conn, msg, data); - - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, + DATABASE_INTERFACE, + database_methods, + NULL, NULL); } void set_sdp_server_enable(void) diff --git a/hcid/dbus-database.h b/hcid/dbus-database.h index 235d88fd..8feb1e59 100644 --- a/hcid/dbus-database.h +++ b/hcid/dbus-database.h @@ -26,7 +26,7 @@ #define DATABASE_INTERFACE "org.bluez.Database" -DBusHandlerResult handle_database_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t database_init(DBusConnection *conn, const char *path); void set_sdp_server_enable(void); diff --git a/hcid/dbus-hci.c b/hcid/dbus-hci.c index e9a03b22..7848b3db 100644 --- a/hcid/dbus-hci.c +++ b/hcid/dbus-hci.c @@ -46,9 +46,11 @@ #include "hcid.h" #include "dbus.h" #include "textfile.h" +#include "dbus-helper.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-test.h" +#include "dbus-rfcomm.h" #include "dbus-security.h" #include "dbus-service.h" #include "dbus-manager.h" @@ -298,11 +300,6 @@ DBusMessage *dev_signal_factory(int devid, const char *prop_name, int first, * Virtual table that handle the object path hierarchy */ -static const DBusObjectPathVTable adapter_vtable = { - .message_function = &handle_method_call, - .unregister_function = NULL -}; - static void adapter_mode_changed(struct adapter *adapter, uint8_t mode) { DBusMessage *message; @@ -404,7 +401,7 @@ int unregister_adapter_path(const char *path) info("Unregister path: %s", path); - dbus_connection_get_object_path_data(connection, path, + dbus_connection_get_object_user_data(connection, path, (void *) &adapter); if (!adapter) @@ -473,7 +470,7 @@ int unregister_adapter_path(const char *path) g_free (adapter); unreg: - if (!dbus_connection_unregister_object_path (connection, path)) { + if (!dbus_connection_destroy_object_path(connection, path)) { error("D-Bus failed to unregister %s object", path); return -1; } @@ -507,13 +504,33 @@ int hcid_dbus_register_device(uint16_t id) adapter->dev_id = id; adapter->pdiscov_resolve_names = 1; - if (!dbus_connection_register_object_path(connection, path, - &adapter_vtable, adapter)) { + if (!dbus_connection_create_object_path(connection, path, adapter, + NULL)) { error("D-Bus failed to register %s object", path); g_free(adapter); return -1; } + if (!adapter_init(connection, path)) { + error("Adapter interface init failed"); + goto failed; + } + + if (!security_init(connection, path)) { + error("Security interface init failed"); + goto failed; + } + + if (!test_init(connection, path)) { + error("Test interface init failed"); + goto failed; + } + + if (!rfcomm_init(connection, path)) { + error("RFCOMM interface init failed"); + goto failed; + } + /* * Send the adapter added signal */ @@ -521,8 +538,7 @@ int hcid_dbus_register_device(uint16_t id) "AdapterAdded"); if (message == NULL) { error("Can't allocate D-Bus message"); - dbus_connection_unregister_object_path(connection, path); - return -1; + goto failed; } dbus_message_append_args(message, @@ -532,6 +548,12 @@ int hcid_dbus_register_device(uint16_t id) send_message_and_unref(connection, message); return 0; + +failed: + dbus_connection_destroy_object_path(connection, path); + g_free(adapter); + + return -1; } int hcid_dbus_unregister_device(uint16_t id) @@ -605,7 +627,7 @@ int hcid_dbus_start_device(uint16_t id) if (hci_test_bit(HCI_RAW, &di.flags)) return -1; - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); return -1; @@ -696,7 +718,7 @@ int hcid_dbus_stop_device(uint16_t id) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); return -1; @@ -796,7 +818,7 @@ void hcid_dbus_pending_pin_req_add(bdaddr_t *sba, bdaddr_t *dba) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); return; @@ -870,7 +892,7 @@ void hcid_dbus_bonding_process_complete(bdaddr_t *local, bdaddr_t *peer, snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); /* create the authentication reply */ - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; @@ -944,7 +966,7 @@ void hcid_dbus_inquiry_start(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, + if (dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { adapter->discov_active = 1; /* @@ -1119,7 +1141,7 @@ void hcid_dbus_inquiry_complete(bdaddr_t *local) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; @@ -1228,7 +1250,7 @@ void hcid_dbus_periodic_inquiry_start(bdaddr_t *local, uint8_t status) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (dbus_connection_get_object_path_data(connection, path, + if (dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { adapter->pdiscov_active = 1; @@ -1268,7 +1290,7 @@ void hcid_dbus_periodic_inquiry_exit(bdaddr_t *local, uint8_t status) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; @@ -1362,7 +1384,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class, snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; @@ -1511,7 +1533,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status, snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; @@ -1600,7 +1622,7 @@ void hcid_dbus_conn_complete(bdaddr_t *local, uint8_t status, uint16_t handle, snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto done; @@ -1667,7 +1689,7 @@ void hcid_dbus_disconn_complete(bdaddr_t *local, uint8_t status, snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; @@ -1908,7 +1930,7 @@ void hcid_dbus_setscan_enable_complete(bdaddr_t *local) goto failed; } - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; @@ -1954,7 +1976,7 @@ void hcid_dbus_pin_code_reply(bdaddr_t *local, void *ptr) snprintf(path, sizeof(path), "%s/hci%d", BASE_PATH, id); - if (!dbus_connection_get_object_path_data(connection, path, + if (!dbus_connection_get_object_user_data(connection, path, (void *) &adapter)) { error("Getting %s path data failed!", path); goto failed; diff --git a/hcid/dbus-manager.c b/hcid/dbus-manager.c index a24db32f..68c732f5 100644 --- a/hcid/dbus-manager.c +++ b/hcid/dbus-manager.c @@ -43,6 +43,7 @@ #include "hcid.h" #include "dbus.h" +#include "dbus-helper.h" #include "dbus-common.h" #include "dbus-error.h" #include "dbus-database.h" @@ -279,42 +280,31 @@ static DBusHandlerResult activate_service(DBusConnection *conn, return DBUS_HANDLER_RESULT_HANDLED; } -static struct service_data methods[] = { - { "InterfaceVersion", interface_version }, - { "DefaultAdapter", default_adapter }, - { "FindAdapter", find_adapter }, - { "ListAdapters", list_adapters }, - { "FindService", find_service }, - { "ListServices", list_services }, - { "ActivateService", activate_service }, +static DBusMethodVTable manager_methods[] = { + { "InterfaceVersion", interface_version, "", "u" }, + { "DefaultAdapter", default_adapter, "", "s" }, + { "FindAdapter", find_adapter, "s", "s" }, + { "ListAdapters", list_adapters, "", "as" }, + { "FindService", find_service, "s", "s" }, + { "ListServices", list_services, "", "as" }, + { "ActivateService", activate_service, "s", "s" }, + { NULL, NULL, NULL, NULL } +}; + +static DBusSignalVTable manager_signals[] = { + { "AdapterAdded", "s" }, + { "AdapterRemoved", "s" }, + { "DefaultAdapterChanged", "s" }, + { "ServiceAdded", "s" }, + { "ServiceRemoved", "s" }, { NULL, NULL } }; -DBusHandlerResult handle_manager_method(DBusConnection *conn, - DBusMessage *msg, void *data) +dbus_bool_t manager_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - const char *iface, *name; - - iface = dbus_message_get_interface(msg); - name = dbus_message_get_member(msg); - - if (!strcmp(DBUS_INTERFACE_INTROSPECTABLE, iface) && - !strcmp("Introspect", name)) { - return simple_introspect(conn, msg, data); - } else if (!strcmp(iface, MANAGER_INTERFACE)) { - handler = find_service_handler(methods, msg); - if (handler) - return handler(conn, msg, data); - else - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } else if (!strcmp(iface, DATABASE_INTERFACE)) { - return handle_database_method(conn, msg, data); - } else if (!strcmp(iface, SECURITY_INTERFACE)) { - return handle_security_method(conn, msg, data); - } - - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, MANAGER_INTERFACE, + manager_methods, + manager_signals, NULL); } int get_default_adapter(void) diff --git a/hcid/dbus-manager.h b/hcid/dbus-manager.h index 9909229d..87e8d4d5 100644 --- a/hcid/dbus-manager.h +++ b/hcid/dbus-manager.h @@ -26,7 +26,7 @@ #define MANAGER_INTERFACE "org.bluez.Manager" -DBusHandlerResult handle_manager_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t manager_init(DBusConnection *conn, const char *path); int get_default_adapter(void); diff --git a/hcid/dbus-rfcomm.c b/hcid/dbus-rfcomm.c index 405764c9..58df0bfc 100644 --- a/hcid/dbus-rfcomm.c +++ b/hcid/dbus-rfcomm.c @@ -46,8 +46,9 @@ #include <dbus/dbus.h> -#include "hcid.h" #include "dbus.h" +#include "dbus-helper.h" +#include "hcid.h" #include "dbus-common.h" #include "dbus-hci.h" #include "dbus-adapter.h" @@ -599,6 +600,9 @@ static DBusHandlerResult rfcomm_connect_req(DBusConnection *conn, const char *dst; int err; + if (!adapter->up) + return error_not_ready(conn, msg); + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, DBUS_TYPE_STRING, &string, @@ -639,6 +643,10 @@ static DBusHandlerResult rfcomm_cancel_connect_req(DBusConnection *conn, DBusMessage *reply; const char *string; const char *dst; + struct adapter *adapter = data; + + if (!adapter->up) + return error_not_ready(conn, msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, @@ -668,6 +676,9 @@ static DBusHandlerResult rfcomm_connect_by_ch_req(DBusConnection *conn, int err; struct adapter *adapter = data; + if (!adapter->up) + return error_not_ready(conn, msg); + hci_devba(adapter->dev_id, &bdaddr); if (!dbus_message_get_args(msg, NULL, @@ -692,6 +703,10 @@ static DBusHandlerResult rfcomm_cancel_connect_by_ch_req(DBusConnection *conn, uint8_t ch; DBusMessage *reply; struct pending_connect *pending; + struct adapter *adapter = data; + + if (!adapter->up) + return error_not_ready(conn, msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, @@ -719,6 +734,10 @@ static DBusHandlerResult rfcomm_disconnect_req(DBusConnection *conn, DBusMessage *reply; const char *name; int err; + struct adapter *adapter = data; + + if (!adapter->up) + return error_not_ready(conn, msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name, @@ -825,6 +844,9 @@ static DBusHandlerResult rfcomm_bind_req(DBusConnection *conn, const char *dst; int err; + if (!adapter->up) + return error_not_ready(conn, msg); + if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &dst, DBUS_TYPE_STRING, &string, @@ -868,6 +890,9 @@ static DBusHandlerResult rfcomm_bind_by_ch_req(DBusConnection *conn, struct adapter *adapter = data; struct rfcomm_node *node = NULL; + if (!adapter->up) + return error_not_ready(conn, msg); + hci_devba(adapter->dev_id, &bdaddr); if (!dbus_message_get_args(msg, NULL, @@ -910,6 +935,10 @@ static DBusHandlerResult rfcomm_release_req(DBusConnection *conn, const char *name; struct rfcomm_node *node; int err; + struct adapter *adapter = data; + + if (!adapter->up) + return error_not_ready(conn, msg); if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name, @@ -949,6 +978,9 @@ static DBusHandlerResult rfcomm_list_bindings_req(DBusConnection *conn, struct adapter *adapter = data; GSList *l; + if (!adapter->up) + return error_not_ready(conn, msg); + hci_devba(adapter->dev_id, &bdaddr); reply = dbus_message_new_method_return(msg); @@ -988,47 +1020,40 @@ static DBusHandlerResult rfcomm_list_bindings_req(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static struct service_data rfcomm_services[] = { - { "Connect", rfcomm_connect_req, }, - { "CancelConnect", rfcomm_cancel_connect_req, }, - { "ConnectByChannel", rfcomm_connect_by_ch_req, }, - { "CancelConnectByChannel", rfcomm_cancel_connect_by_ch_req, }, - { "Disconnect", rfcomm_disconnect_req, }, - { "Bind", rfcomm_bind_req, }, - { "BindByChannel", rfcomm_bind_by_ch_req, }, - { "Release", rfcomm_release_req, }, - { "ListBindings", rfcomm_list_bindings_req, }, - { NULL, NULL, } +static DBusMethodVTable rfcomm_methods[] = { + { "Connect", rfcomm_connect_req, + "ss", "s" }, + { "CancelConnect", rfcomm_cancel_connect_req, + "ss", "" }, + { "ConnectByChannel", rfcomm_connect_by_ch_req, + "sy", "s" }, + { "CancelConnectByChannel", rfcomm_cancel_connect_by_ch_req, + "sy", "" }, + { "Disconnect", rfcomm_disconnect_req, + "s", "" }, + { "Bind", rfcomm_bind_req, + "ss", "s" }, + { "BindByChannel", rfcomm_bind_by_ch_req, + "sy", "s" }, + { "Release", rfcomm_release_req, + "s", "" }, + { "ListBindings", rfcomm_list_bindings_req, + "", "as" }, + { NULL, NULL, NULL, NULL } }; -DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, - void *data) +dbus_bool_t rfcomm_init(DBusConnection *conn, const char *path) { - const struct adapter *adapter = data; - service_handler_func_t handler; - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - - if (!data) { - error("RFCOMM method called with NULL data pointer!"); - return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } - - if (!adapter->up) - return error_not_ready(conn, msg); + return TRUE; - /* Initialize the RFCOMM control socket if has not yet been done */ if (rfcomm_ctl < 0) { rfcomm_ctl = socket(AF_BLUETOOTH, SOCK_RAW, BTPROTO_RFCOMM); if (rfcomm_ctl < 0) - return error_failed(conn, msg, errno); + return FALSE; } - handler = find_service_handler(rfcomm_services, msg); - - if (handler) - return handler(conn, msg, data); - - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, RFCOMM_INTERFACE, + rfcomm_methods, + NULL, NULL); } diff --git a/hcid/dbus-rfcomm.h b/hcid/dbus-rfcomm.h index 1f6f209c..f7705ef8 100644 --- a/hcid/dbus-rfcomm.h +++ b/hcid/dbus-rfcomm.h @@ -26,6 +26,6 @@ #define RFCOMM_INTERFACE "org.bluez.RFCOMM" -DBusHandlerResult handle_rfcomm_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t rfcomm_init(DBusConnection *conn, const char *path); #endif /* __BLUEZ_DBUS_RFCOMM_H */ diff --git a/hcid/dbus-sdp.c b/hcid/dbus-sdp.c index 5a79a7b4..05eefcf7 100644 --- a/hcid/dbus-sdp.c +++ b/hcid/dbus-sdp.c @@ -49,6 +49,7 @@ #include <dbus/dbus.h> #include "dbus.h" +#include "dbus-helper.h" #include "hcid.h" #include "textfile.h" #include "dbus-hci.h" @@ -347,7 +348,7 @@ static const char *get_address_from_message(DBusConnection *conn, DBusMessage *m if (!path) return NULL; - if (dbus_connection_get_object_path_data(conn, path, (void *) &adapter) == FALSE) + if (dbus_connection_get_object_user_data(conn, path, (void *) &adapter) == FALSE) return NULL; return adapter->address; diff --git a/hcid/dbus-security.c b/hcid/dbus-security.c index df06f008..41782535 100644 --- a/hcid/dbus-security.c +++ b/hcid/dbus-security.c @@ -41,6 +41,7 @@ #include <dbus/dbus.h> #include "dbus.h" +#include "dbus-helper.h" #include "hcid.h" #include "dbus-common.h" #include "dbus-adapter.h" @@ -835,27 +836,27 @@ DBusHandlerResult cancel_authorize_request(DBusConnection *conn, service, address, path); } -static struct service_data sec_services[] = { - { "RegisterDefaultPasskeyAgent", register_default_passkey_agent }, - { "UnregisterDefaultPasskeyAgent", unregister_default_passkey_agent }, - { "RegisterPasskeyAgent", register_passkey_agent }, - { "UnregisterPasskeyAgent", unregister_passkey_agent }, - { "RegisterDefaultAuthorizationAgent", register_default_auth_agent }, - { "UnregisterDefaultAuthorizationAgent", unregister_default_auth_agent }, - { NULL, NULL } +static DBusMethodVTable security_methods[] = { + { "RegisterDefaultPasskeyAgent", register_default_passkey_agent, + "s", "" }, + { "UnregisterDefaultPasskeyAgent", unregister_default_passkey_agent, + "s", "" }, + { "RegisterPasskeyAgent", register_passkey_agent, + "ss", "" }, + { "UnregisterPasskeyAgent", unregister_passkey_agent, + "ss", "" }, + { "RegisterDefaultAuthorizationAgent", register_default_auth_agent, + "s", "" }, + { "UnregisterDefaultAuthorizationAgent", unregister_default_auth_agent, + "s", "" }, + { NULL, NULL, NULL, NULL } }; -DBusHandlerResult handle_security_method(DBusConnection *conn, - DBusMessage *msg, void *data) +dbus_bool_t security_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - - handler = find_service_handler(sec_services, msg); - - if (handler) - return handler(conn, msg, data); - - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, SECURITY_INTERFACE, + security_methods, + NULL, NULL); } static DBusPendingCall *agent_request(const char *path, bdaddr_t *bda, @@ -1039,7 +1040,7 @@ int handle_passkey_request(DBusConnection *conn, int dev, const char *path, char addr[18]; void *data; - dbus_connection_get_object_path_data(conn, path, &data); + dbus_connection_get_object_user_data(conn, path, &data); if (!data) goto done; @@ -1218,7 +1219,7 @@ int handle_confirm_request(DBusConnection *conn, int dev, const char *path, char addr[18]; void *data; - dbus_connection_get_object_path_data(conn, path, &data); + dbus_connection_get_object_user_data(conn, path, &data); if (!data) goto done; diff --git a/hcid/dbus-security.h b/hcid/dbus-security.h index f4f64bbe..1e19653f 100644 --- a/hcid/dbus-security.h +++ b/hcid/dbus-security.h @@ -29,7 +29,7 @@ #define SECURITY_INTERFACE "org.bluez.Security" -DBusHandlerResult handle_security_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t security_init(DBusConnection *conn, const char *path); int handle_passkey_request(DBusConnection *conn, int dev, const char *path, bdaddr_t *sba, bdaddr_t *dba); diff --git a/hcid/dbus-test.c b/hcid/dbus-test.c index 3d064c7f..206bc0fe 100644 --- a/hcid/dbus-test.c +++ b/hcid/dbus-test.c @@ -36,8 +36,9 @@ #include <dbus/dbus.h> -#include "hcid.h" #include "dbus.h" +#include "dbus-helper.h" +#include "hcid.h" #include "dbus-common.h" #include "dbus-hci.h" #include "dbus-adapter.h" @@ -140,7 +141,7 @@ static void audit_requestor_exited(const char *name, struct audit *audit) send_audit_status(audit, "AuditRemoteDeviceComplete"); - dbus_connection_get_object_path_data(audit->conn, + dbus_connection_get_object_user_data(audit->conn, audit->adapter_path, (void *) &adapter); if (adapter) @@ -351,7 +352,7 @@ static gboolean l2raw_connect_complete(GIOChannel *io, GIOCondition cond, struct return FALSE; } - dbus_connection_get_object_path_data(audit->conn, audit->adapter_path, + dbus_connection_get_object_user_data(audit->conn, audit->adapter_path, (void *) &adapter); if (adapter) bacpy(&adapter->agents_disabled, BDADDR_ANY); @@ -638,27 +639,26 @@ static DBusHandlerResult get_l2cap_mtu_size(DBusConnection *conn, return send_message_and_unref(conn, reply); } -static struct service_data methods[] = { - { "AuditRemoteDevice", audit_remote_device }, - { "CancelAuditRemoteDevice", cancel_audit_remote_device }, - { "GetL2capFeatureMask", get_l2cap_feature_mask }, - { "GetL2capMtuSize", get_l2cap_mtu_size }, - { NULL, NULL } +static DBusMethodVTable test_methods[] = { + { "AuditRemoteDevice", audit_remote_device, + "s", "" }, + { "CancelAuditRemoteDevice", cancel_audit_remote_device, + "s", "" }, + { "GetL2capFeatureMask", get_l2cap_feature_mask, + "s", "u" }, + { "GetL2capMtuSize", get_l2cap_mtu_size, + "s", "q" }, + { NULL, NULL, NULL, NULL } }; -DBusHandlerResult handle_test_method(DBusConnection *conn, DBusMessage *msg, void *data) +dbus_bool_t test_init(DBusConnection *conn, const char *path) { - service_handler_func_t handler; - if (!hcid_dbus_use_experimental()) - return error_unknown_method(conn, msg); - - handler = find_service_handler(methods, msg); - - if (handler) - return handler(conn, msg, data); + return TRUE; - return error_unknown_method(conn, msg); + return dbus_connection_register_interface(conn, path, TEST_INTERFACE, + test_methods, + NULL, NULL); } void process_audits_list(const char *adapter_path) @@ -681,7 +681,7 @@ void process_audits_list(const char *adapter_path) adapter = NULL; - dbus_connection_get_object_path_data(audit->conn, + dbus_connection_get_object_user_data(audit->conn, audit->adapter_path, (void *) &adapter); diff --git a/hcid/dbus-test.h b/hcid/dbus-test.h index 935662bf..455c9293 100644 --- a/hcid/dbus-test.h +++ b/hcid/dbus-test.h @@ -26,7 +26,7 @@ #define TEST_INTERFACE "org.bluez.Test" -DBusHandlerResult handle_test_method(DBusConnection *conn, DBusMessage *msg, void *data); +dbus_bool_t test_init(DBusConnection *conn, const char *path); void process_audits_list(const char *adapter_path); |