summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2017-08-08 09:17:37 -0400
committerMatt Ranostay <matt.ranostay@konsulko.com>2017-09-26 12:00:47 -0700
commit28f6028329b573001a16e2792f73a9efaafecf3f (patch)
treeac2b0122bd1ad330e6a471d37e399433a5200348
parentedae16e793b2ef2dd680821357128b5165b34b78 (diff)
add support for subscription-based eventsdab_4.0.3dab_4.0.2dab/4.0.3dab/4.0.24.0.34.0.2dab
Convert telephony-binding and phone app from broadcast events to subscribe/unsubscribe events. Bug-AGL: SPEC-815 SPEC-913 Change-Id: I6288db22332277e217b3f1a4e79a391cb63ebc16 Signed-off-by: Matt Porter <mporter@konsulko.com>
-rw-r--r--app/api/Telephony.qml13
-rw-r--r--telephony-binding/telephony-binding.c72
2 files changed, 77 insertions, 8 deletions
diff --git a/app/api/Telephony.qml b/app/api/Telephony.qml
index c7d9218..2db2d0b 100644
--- a/app/api/Telephony.qml
+++ b/app/api/Telephony.qml
@@ -58,6 +58,7 @@ WebSocket {
var payload = JSON.parse(JSON.stringify(json[2]))
var event = payload.event
var data = payload.data
+ console.debug("event: " + event)
if (event == "telephony/incomingCall") {
callClipColp = data.clip
callStatus = "incoming"
@@ -76,6 +77,10 @@ WebSocket {
onStatusChanged: {
switch (status) {
case WebSocket.Open:
+ sendSocketMessage("subscribe", { value: "callStateChanged" })
+ sendSocketMessage("subscribe", { value: "dialingCall" })
+ sendSocketMessage("subscribe", { value: "incomingCall" })
+ sendSocketMessage("subscribe", { value: "terminatedCall" })
break
case WebSocket.Error:
root.statusString = "WebSocket error: " + root.errorString
@@ -83,7 +88,7 @@ WebSocket {
}
}
- function sendSocketMesage(verb, parameter) {
+ function sendSocketMessage(verb, parameter) {
var requestJson = [ msgid.call, payloadLength, apiString + '/' + verb, parameter ]
verbs.push(verb)
sendTextMessage(JSON.stringify(requestJson))
@@ -91,16 +96,16 @@ WebSocket {
function dial(number) {
var parameterJson = { value: number }
- sendSocketMesage("dial", parameterJson)
+ sendSocketMessage("dial", parameterJson)
}
function answer() {
var parameterJson = 'None'
- sendSocketMesage("answer", parameterJson)
+ sendSocketMessage("answer", parameterJson)
}
function hangup() {
var parameterJson = 'None'
- sendSocketMesage("hangup", parameterJson)
+ sendSocketMessage("hangup", parameterJson)
}
}
diff --git a/telephony-binding/telephony-binding.c b/telephony-binding/telephony-binding.c
index b1c39f1..f0865ed 100644
--- a/telephony-binding/telephony-binding.c
+++ b/telephony-binding/telephony-binding.c
@@ -18,6 +18,7 @@
#include <glib.h>
#include <json-c/json.h>
+#include <string.h>
#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
@@ -29,6 +30,10 @@
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 void dial(struct afb_req request)
{
@@ -84,12 +89,54 @@ static void answer(struct afb_req request)
}
}
+static void subscribe(struct afb_req request)
+{
+ const char *value = afb_req_value(request, "value");
+ if(value) {
+ if (!strcasecmp(value, "callStateChanged")) {
+ afb_req_subscribe(request, call_state_changed_event);
+ } else if (!strcasecmp(value, "dialingCall")) {
+ afb_req_subscribe(request, dialing_call_event);
+ } else if (!strcasecmp(value, "incomingCall")) {
+ afb_req_subscribe(request, incoming_call_event);
+ } else if (!strcasecmp(value, "terminatedCall")) {
+ afb_req_subscribe(request, terminated_call_event);
+ } else {
+ afb_req_fail(request, "failed", "Invalid event");
+ return;
+ }
+ }
+
+ afb_req_success(request, NULL, NULL);
+}
+
+static void unsubscribe(struct afb_req request)
+{
+ const char *value = afb_req_value(request, "value");
+ if(value) {
+ if (!strcasecmp(value, "callStateChanged")) {
+ afb_req_unsubscribe(request, call_state_changed_event);
+ } else if (!strcasecmp(value, "dialingCall")) {
+ afb_req_unsubscribe(request, dialing_call_event);
+ } else if (!strcasecmp(value, "incomingCall")) {
+ afb_req_unsubscribe(request, incoming_call_event);
+ } else if (!strcasecmp(value, "terminatedCall")) {
+ afb_req_unsubscribe(request, terminated_call_event);
+ } else {
+ afb_req_fail(request, "failed", "Invalid event");
+ return;
+ }
+ }
+
+ afb_req_success(request, NULL, NULL);
+}
+
static void call_state_changed_cb(OrgOfonoVoiceCall *vc, gchar *state)
{
struct json_object *call_state;
call_state = json_object_new_object();
json_object_object_add(call_state, "state", json_object_new_string(state));
- afb_daemon_broadcast_event("callStateChanged", call_state);
+ afb_event_push(call_state_changed_event, call_state);
}
static void incoming_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar *clip)
@@ -98,7 +145,7 @@ static void incoming_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar
call_info = json_object_new_object();
json_object_object_add(call_info, "clip", json_object_new_string(clip));
- afb_daemon_broadcast_event("incomingCall", call_info);
+ afb_event_push(incoming_call_event, call_info);
incoming_call = ofono_voicecall_new(op, call_state_changed_cb);
}
@@ -108,7 +155,7 @@ static void dialing_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar
call_info = json_object_new_object();
json_object_object_add(call_info, "colp", json_object_new_string(colp));
- afb_daemon_broadcast_event("dialingCall", call_info);
+ afb_event_push(dialing_call_event, call_info);
voice_call = ofono_voicecall_new(op, call_state_changed_cb);
}
@@ -121,7 +168,7 @@ static void terminated_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op)
ofono_voicecall_free(voice_call);
}
voice_call = NULL;
- afb_daemon_broadcast_event("terminatedCall", NULL);
+ afb_event_push(terminated_call_event, NULL);
}
static void *main_loop_thread(void *unused)
@@ -136,6 +183,11 @@ static int ofono_init(void)
pthread_t tid;
int ret = 0;
+ call_state_changed_event = afb_daemon_make_event("callStateChanged");
+ dialing_call_event = afb_daemon_make_event("dialingCall");
+ incoming_call_event = afb_daemon_make_event("incomingCall");
+ terminated_call_event = afb_daemon_make_event("terminatedCall");
+
/* Start the main loop thread */
pthread_create(&tid, NULL, main_loop_thread, NULL);
@@ -183,6 +235,18 @@ static const struct afb_verb_v2 verbs[]= {
.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}
};