diff options
Diffstat (limited to 'binding/telephony-binding.c')
-rw-r--r-- | binding/telephony-binding.c | 105 |
1 files changed, 44 insertions, 61 deletions
diff --git a/binding/telephony-binding.c b/binding/telephony-binding.c index f6db061..11fac26 100644 --- a/binding/telephony-binding.c +++ b/binding/telephony-binding.c @@ -20,7 +20,7 @@ #include <json-c/json.h> #include <string.h> -#define AFB_BINDING_VERSION 2 +#define AFB_BINDING_VERSION 3 #include <afb/afb-binding.h> #include "ofono_manager.h" @@ -29,12 +29,12 @@ static OrgOfonoVoiceCallManager *vcm; static OrgOfonoVoiceCall *incoming_call, *voice_call; -static struct afb_event call_state_changed_event; -static struct afb_event dialing_call_event; -static struct afb_event incoming_call_event; -static struct afb_event terminated_call_event; +static afb_event_t call_state_changed_event; +static afb_event_t dialing_call_event; +static afb_event_t incoming_call_event; +static afb_event_t terminated_call_event; -static void dial(struct afb_req request) +static void dial(afb_req_t request) { struct json_object *query, *val; const char *number; @@ -61,7 +61,7 @@ static void dial(struct afb_req request) } } -static void hangup(struct afb_req request) +static void hangup(afb_req_t request) { if (voice_call) { AFB_DEBUG("Hangup voice call\n"); @@ -77,7 +77,7 @@ static void hangup(struct afb_req request) } } -static void answer(struct afb_req request) +static void answer(afb_req_t request) { if (incoming_call) { AFB_DEBUG("Answer voice call\n"); @@ -88,7 +88,7 @@ static void answer(struct afb_req request) } } -static void subscribe(struct afb_req request) +static void subscribe(afb_req_t request) { const char *value = afb_req_value(request, "value"); if(value) { @@ -109,7 +109,7 @@ static void subscribe(struct afb_req request) afb_req_success(request, NULL, NULL); } -static void unsubscribe(struct afb_req request) +static void unsubscribe(afb_req_t request) { const char *value = afb_req_value(request, "value"); if(value) { @@ -218,48 +218,41 @@ static gboolean is_hfp_dev_and_init(struct json_object *dev) return hfp; } -static void discovery_result_cb(void *closure, int status, struct json_object *result) +static void discovery_result_cb(void *closure, struct json_object *result, + const char *error, const char *info, + afb_api_t api) { enum json_type type; - struct json_object *devs, *dev; + struct json_object *dev, *tmp; int i; - json_object_object_foreach(result, key, val) { - type = json_object_get_type(val); - switch (type) { - case json_type_array: - json_object_object_get_ex(result, key, &devs); - for (i = 0; i < json_object_array_length(devs); i++) { - dev = json_object_array_get_idx(devs, i); - if (is_hfp_dev_and_init(dev)) - break; - } - break; - case json_type_string: - case json_type_boolean: - case json_type_double: - case json_type_int: - case json_type_object: - case json_type_null: - default: - break; - } + if (!json_object_object_get_ex(result, "list", &tmp)) + return; + type = json_object_get_type(tmp); + + if (type != json_type_array) + return; + + for (i = 0; i < json_object_array_length(tmp); i++) { + dev = json_object_array_get_idx(tmp, i); + if (is_hfp_dev_and_init(dev)) + return; } } -static void ofono_hfp_init(void) +static void ofono_hfp_init(afb_api_t api) { - struct json_object *args, *response; + struct json_object *args; args = json_object_new_object(); - json_object_object_add(args , "value", json_object_new_string("connection")); - afb_service_call_sync("Bluetooth-Manager", "subscribe", args, &response); + json_object_object_add(args, "value", json_object_new_string("connection")); + afb_api_call_sync(api, "Bluetooth-Manager", "subscribe", args, NULL, NULL, NULL); args = json_object_new_object(); - afb_service_call("Bluetooth-Manager", "discovery_result", args, discovery_result_cb, &response); + afb_api_call(api, "Bluetooth-Manager", "discovery_result", args, discovery_result_cb, NULL); } -static int ofono_init(void) +static int ofono_init(afb_api_t api) { pthread_t tid; int ret = 0; @@ -281,7 +274,7 @@ static int ofono_init(void) ret = ofono_manager_init(); if (ret == 0) { ofono_manager_invalidate_default_modem(); - ofono_hfp_init(); + ofono_hfp_init(api); } else { AFB_ERROR("failed to initialize ofono manager"); } @@ -289,50 +282,40 @@ static int ofono_init(void) return ret; } -static const struct afb_verb_v2 verbs[]= { +static const afb_verb_t verbs[]= { { .verb = "dial", .callback = dial, - .auth = NULL, - .session = AFB_SESSION_NONE, }, { .verb = "hangup", .callback = hangup, - .auth = NULL, - .session = AFB_SESSION_NONE, }, { .verb = "answer", .callback = answer, - .auth = NULL, - .session = AFB_SESSION_NONE, }, { .verb = "subscribe", .callback = subscribe, - .auth = NULL, - .session = AFB_SESSION_NONE, }, { .verb = "unsubscribe", .callback = unsubscribe, - .auth = NULL, - .session = AFB_SESSION_NONE, }, - {NULL} + { } }; -static int init() +static int init(afb_api_t api) { AFB_NOTICE("Initializing telephony service"); - return ofono_init(); + return ofono_init(api); } -static void process_connection_event(struct json_object *object) +static void process_connection_event(afb_api_t api, struct json_object *object) { - struct json_object *args, *response, *status_obj, *address_obj; + struct json_object *args, *status_obj, *address_obj; const char *status, *address; json_object_object_get_ex(object, "Status", &status_obj); @@ -340,8 +323,9 @@ static void process_connection_event(struct json_object *object) if (!g_strcmp0(status, "connected")) { args = json_object_new_object(); - afb_service_call("Bluetooth-Manager", "discovery_result", - args, discovery_result_cb, &response); + + afb_api_call(api, "Bluetooth-Manager", "discovery_result", + 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); @@ -353,17 +337,16 @@ static void process_connection_event(struct json_object *object) AFB_ERROR("Unsupported connection status: %s\n", status); } -static void onevent(const char *event, struct json_object *object) +static void onevent(afb_api_t api, const char *event, struct json_object *object) { if (!g_strcmp0(event, "Bluetooth-Manager/connection")) - process_connection_event(object); + process_connection_event(api, object); else AFB_ERROR("Unsupported event: %s\n", event); } -const struct afb_binding_v2 afbBindingV2 = { +const afb_binding_t afbBindingV3 = { .api = "telephony", - .specification = NULL, .verbs = verbs, .init = init, .onevent = onevent, |