summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--binding/telephony-binding.c104
1 files changed, 70 insertions, 34 deletions
diff --git a/binding/telephony-binding.c b/binding/telephony-binding.c
index 11fac26..50d3638 100644
--- a/binding/telephony-binding.c
+++ b/binding/telephony-binding.c
@@ -27,6 +27,8 @@
#include "ofono_voicecallmanager.h"
#include "ofono_voicecall.h"
+#define HFP_UUID "0000111f-0000-1000-8000-00805f9b34fb"
+
static OrgOfonoVoiceCallManager *vcm;
static OrgOfonoVoiceCall *incoming_call, *voice_call;
static afb_event_t call_state_changed_event;
@@ -201,21 +203,38 @@ static int ofono_init_default_modem(void)
static gboolean is_hfp_dev_and_init(struct json_object *dev)
{
- int ret;
- gboolean hfp = FALSE;
- struct json_object *name, *address, *hfp_connected;
- json_object_object_get_ex(dev, "Name", &name);
- json_object_object_get_ex(dev, "Address", &address);
- json_object_object_get_ex(dev, "HFPConnected", &hfp_connected);
- if (!strcmp(json_object_get_string(hfp_connected), "True")) {
- ret = ofono_manager_set_default_modem(json_object_get_string(address));
- if (ret == 0) {
- ofono_init_default_modem();
- hfp = TRUE;
- }
+ struct json_object *props = NULL, *val = NULL;
+ int i, connected = 0;
+
+ json_object_object_get_ex(dev, "properties", &props);
+ if (!props)
+ return FALSE;
+
+ json_object_object_get_ex(props, "connected", &val);
+ connected = json_object_get_boolean(val);
+ if (!val || !connected)
+ return FALSE;
+
+ json_object_object_get_ex(props, "uuids", &val);
+ for (i = 0; i < json_object_array_length(val); i++) {
+ const char *uuid = json_object_get_string(json_object_array_get_idx(val, i));
+ struct json_object *val1 = NULL;
+ int ret;
+
+ if (g_strcmp0(HFP_UUID, uuid))
+ continue;
+
+ json_object_object_get_ex(props, "address", &val1);
+
+ ret = ofono_manager_set_default_modem(json_object_get_string(val1));
+ if (ret != 0)
+ return FALSE;
+
+ ofono_init_default_modem();
+ return TRUE;
}
- return hfp;
+ return FALSE;
}
static void discovery_result_cb(void *closure, struct json_object *result,
@@ -226,7 +245,7 @@ static void discovery_result_cb(void *closure, struct json_object *result,
struct json_object *dev, *tmp;
int i;
- if (!json_object_object_get_ex(result, "list", &tmp))
+ if (!json_object_object_get_ex(result, "devices", &tmp))
return;
type = json_object_get_type(tmp);
@@ -245,11 +264,11 @@ static void ofono_hfp_init(afb_api_t api)
struct json_object *args;
args = json_object_new_object();
- json_object_object_add(args, "value", json_object_new_string("connection"));
+ json_object_object_add(args, "value", json_object_new_string("device_changes"));
afb_api_call_sync(api, "Bluetooth-Manager", "subscribe", args, NULL, NULL, NULL);
args = json_object_new_object();
- afb_api_call(api, "Bluetooth-Manager", "discovery_result", args, discovery_result_cb, NULL);
+ afb_api_call(api, "Bluetooth-Manager", "managed_objects", args, discovery_result_cb, NULL);
}
static int ofono_init(afb_api_t api)
@@ -315,33 +334,50 @@ static int init(afb_api_t api)
static void process_connection_event(afb_api_t api, struct json_object *object)
{
- struct json_object *args, *status_obj, *address_obj;
- const char *status, *address;
+ struct json_object *val = NULL, *props = NULL;
+ const char *action, *address;
+ int connected = 0;
- json_object_object_get_ex(object, "Status", &status_obj);
- status = json_object_get_string(status_obj);
+ json_object_object_get_ex(object, "action", &val);
+ if (!val)
+ return;
+ action = json_object_get_string(val);
+ if (g_strcmp0("changed", action))
+ return;
- if (!g_strcmp0(status, "connected")) {
- args = json_object_new_object();
+ json_object_object_get_ex(object, "properties", &props);
+ if (!props)
+ return;
- afb_api_call(api, "Bluetooth-Manager", "discovery_result",
+ json_object_object_get_ex(props, "connected", &val);
+ if (!val)
+ return;
+ connected = json_object_get_boolean(val);
+
+ if (connected) {
+ struct json_object *args = json_object_new_object();
+
+ afb_api_call(api, "Bluetooth-Manager", "managed_objects",
args, discovery_result_cb, NULL);
- } else if (!g_strcmp0(status, "disconnected")) {
- json_object_object_get_ex(object, "Address", &address_obj);
- address = json_object_get_string(address_obj);
- if (!g_strcmp0(address, ofono_manager_get_default_modem_address())) {
- ofono_manager_invalidate_default_modem();
- ofono_voicecallmanager_free(vcm);
- }
- } else
- AFB_ERROR("Unsupported connection status: %s\n", status);
+ return;
+ }
+
+ json_object_object_get_ex(props, "address", &val);
+ if (!val)
+ return;
+ address = json_object_get_string(val);
+
+ if (!g_strcmp0(address, ofono_manager_get_default_modem_address())) {
+ ofono_manager_invalidate_default_modem();
+ ofono_voicecallmanager_free(vcm);
+ }
}
static void onevent(afb_api_t api, const char *event, struct json_object *object)
{
- if (!g_strcmp0(event, "Bluetooth-Manager/connection"))
+ if (!g_ascii_strcasecmp(event, "Bluetooth-Manager/device_changes"))
process_connection_event(api, object);
- else
+ else
AFB_ERROR("Unsupported event: %s\n", event);
}