From 18019a5e9da7085d2fda7cfd6bc74417f11bfe36 Mon Sep 17 00:00:00 2001 From: Clément Bénier Date: Thu, 13 Dec 2018 02:20:29 +0100 Subject: telephony-binding: handle vshl interface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - subscribe to vhsl controlphone - parse event Change-Id: I3be9a5a8c8e95516468e2f45c269ae0393f9df25 Signed-off-by: Clément Bénier --- binding/telephony-binding.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ conf.d/wgt/config.xml.in | 1 + 2 files changed, 69 insertions(+) diff --git a/binding/telephony-binding.c b/binding/telephony-binding.c index 50d3638..6ae079a 100644 --- a/binding/telephony-binding.c +++ b/binding/telephony-binding.c @@ -325,10 +325,24 @@ static const afb_verb_t verbs[]= { { } }; +static int phonecontrol_init(afb_api_t api) +{ + AFB_NOTICE("PHONECONTROL_INIT"); + struct json_object *events = json_object_new_object(); + struct json_object *array_events = json_object_new_array(); + json_object_array_add(array_events, json_object_new_string("dial")); + json_object_object_add(events, "actions", array_events); + + return afb_api_call_sync(api, "vshl", "phonecontrol/subscribe", events, NULL, NULL, NULL); +} + static int init(afb_api_t api) { AFB_NOTICE("Initializing telephony service"); + + phonecontrol_init(api); + AFB_NOTICE("ZZZZZZZZZZZ"); return ofono_init(api); } @@ -373,10 +387,64 @@ static void process_connection_event(afb_api_t api, struct json_object *object) } } +static void process_phonecontrol_event(afb_api_t api, struct json_object *object) +{ + struct json_object *val = NULL, *payload = NULL; + const char *action = NULL; + const char *number = NULL; + struct json_object *response = json_object_new_object(); + struct json_object *payload_response = json_object_new_object(); + + json_object_object_add(response, "action", json_object_new_string("call_activated")); + json_object_object_add(response, "payload", payload_response); + + json_object_object_get_ex(object, "action", &val); + if (!val) + return; + action = json_object_get_string(val); + if (g_strcmp0("dial", action)) + return; + + json_object_object_get_ex(object, "payload", &payload); + if (!payload) + return; + + json_object_object_get_ex(payload, "callid", &val); + if (!val) + return; + json_object_object_add(payload_response, "callid", val); + json_object_object_get_ex(payload, "value", &val); + if (!val) + return; + number = json_object_get_string(val); + + AFB_DEBUG("dial: %s...\n", number); + if(!vcm) { + AFB_ERROR("No vcm initialised"); + return; + } + afb_api_call_sync(api, "vshl", "phonecontrol/publish", response, NULL, NULL, NULL); + if (voice_call) { + json_object_object_add(response, "action", json_object_new_string("call_failed")); + afb_api_call_sync(api, "vshl", "phonecontrol/publish", response, NULL, NULL, NULL); + AFB_ERROR("dial: cannot dial with active call"); + return; + } + + if (!ofono_voicecallmanager_dial(vcm, (gchar *)number, "")) { + json_object_object_add(response, "action", json_object_new_string("call_failed")); + afb_api_call_sync(api, "vshl", "phonecontrol/publish", response, NULL, NULL, NULL); + AFB_ERROR("dial fail"); + return; + } +} + static void onevent(afb_api_t api, const char *event, struct json_object *object) { if (!g_ascii_strcasecmp(event, "Bluetooth-Manager/device_changes")) process_connection_event(api, object); + else if (!g_ascii_strcasecmp(event, "vshl/phonecontrol/dial")) + process_phonecontrol_event(api, object); else AFB_ERROR("Unsupported event: %s\n", event); } diff --git a/conf.d/wgt/config.xml.in b/conf.d/wgt/config.xml.in index 1c8b8f2..ad44550 100644 --- a/conf.d/wgt/config.xml.in +++ b/conf.d/wgt/config.xml.in @@ -19,6 +19,7 @@ + -- cgit 1.2.3-korg