summaryrefslogtreecommitdiffstats
path: root/telephony-binding
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 /telephony-binding
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>
Diffstat (limited to 'telephony-binding')
-rw-r--r--telephony-binding/telephony-binding.c72
1 files changed, 68 insertions, 4 deletions
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}
};