From 53f6222d2ca009c86f301a630e4bf81d25c86feb Mon Sep 17 00:00:00 2001 From: Matt Porter Date: Fri, 19 May 2017 12:56:35 -0400 Subject: Refactor telephony binding voicecall object management Refactor the voicecall object lifecycle management in the telephony binding using g_object-derived handles. Instead of passing around and managing raw strings as a handle to a voicecall, we use the voicecall object itself returned from the new dbus proxy init. This simplifies memory management of these objects that are created and freed each time as calls are dialed/answered and terminated. It then simplifies the forthcoming call answering support. AGL-Bug: SPEC-600 Change-Id: I89efed1eb7927f4ffe2d1eaed295e0aa914efdcc Signed-off-by: Matt Porter --- telephony-binding/gdbus/ofono_voicecall.c | 18 +++++++++++++----- telephony-binding/gdbus/ofono_voicecall.h | 6 +++++- telephony-binding/telephony-binding.c | 27 ++++++++++++--------------- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/telephony-binding/gdbus/ofono_voicecall.c b/telephony-binding/gdbus/ofono_voicecall.c index 44b6cec..b602c89 100644 --- a/telephony-binding/gdbus/ofono_voicecall.c +++ b/telephony-binding/gdbus/ofono_voicecall.c @@ -16,13 +16,21 @@ #include "ofono_voicecall_interface.h" -void ofono_hangup(const gchar *op) +OrgOfonoVoiceCall *ofono_voicecall_new(gchar *op) { - GError *error = NULL; + return org_ofono_voice_call_proxy_new_for_bus_sync( + G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, + "org.ofono", op, NULL, NULL); +} - OrgOfonoVoiceCall *voice_call = org_ofono_voice_call_proxy_new_for_bus_sync( - G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, - "org.ofono", op, NULL, NULL); +void ofono_voicecall_free(OrgOfonoVoiceCall *voice_call) +{ + g_object_unref(G_OBJECT(voice_call)); +} + +void ofono_voicecall_hangup(OrgOfonoVoiceCall *voice_call) +{ + GError *error = NULL; org_ofono_voice_call_call_hangup_sync(voice_call, NULL, &error); } diff --git a/telephony-binding/gdbus/ofono_voicecall.h b/telephony-binding/gdbus/ofono_voicecall.h index efabc84..0e33dd5 100644 --- a/telephony-binding/gdbus/ofono_voicecall.h +++ b/telephony-binding/gdbus/ofono_voicecall.h @@ -16,4 +16,8 @@ #include -void ofono_hangup(gchar *); +#include "ofono_voicecall_interface.h" + +OrgOfonoVoiceCall *ofono_voicecall_new(gchar *); +void ofono_voicecall_free(OrgOfonoVoiceCall *); +void ofono_voicecall_hangup(OrgOfonoVoiceCall *); diff --git a/telephony-binding/telephony-binding.c b/telephony-binding/telephony-binding.c index bf618ce..134432c 100644 --- a/telephony-binding/telephony-binding.c +++ b/telephony-binding/telephony-binding.c @@ -18,7 +18,6 @@ #include #include -#include #include #include @@ -30,12 +29,11 @@ static const struct afb_binding_interface *interface; static OrgOfonoVoiceCallManager *vcm; -static gchar *incoming_call; -static gchar *voice_call; +static OrgOfonoVoiceCall *incoming_call, *voice_call; static void dial(struct afb_req request) { - struct json_object *query, *val, *ret; + struct json_object *query, *val; const char *number; query = afb_req_json(request); @@ -47,12 +45,8 @@ static void dial(struct afb_req request) afb_req_fail(request, "active call", NULL); } else { DEBUG(interface, "dial: %s...\n", number); - voice_call = ofono_voicecallmanager_dial(vcm, (gchar *)number, ""); - DEBUG(interface, "voice_call: %s\n", voice_call); - if (voice_call) { - ret = json_object_new_object(); - json_object_object_add(ret, "VoiceCall", json_object_new_string(voice_call)); - afb_req_success(request, ret, NULL); + if (ofono_voicecallmanager_dial(vcm, (gchar *)number, "")) { + afb_req_success(request, NULL, NULL); } else { ERROR(interface, "dial: failed to dial number\n"); afb_req_fail(request, "failed dial", NULL); @@ -67,10 +61,9 @@ static void dial(struct afb_req request) static void hangup(struct afb_req request) { if (voice_call) { - DEBUG(interface, "Hangup voice call: %s\n", voice_call); - ofono_hangup(voice_call); + DEBUG(interface, "Hangup voice call\n"); + ofono_voicecall_hangup(voice_call); afb_req_success(request, NULL, NULL); - voice_call = NULL; } else { ERROR(interface, "Hangup: no active call"); afb_req_fail(request, "failed hangup", NULL); @@ -85,7 +78,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(interface->daemon, "incomingCall", call_info); - incoming_call = strdup(op); + incoming_call = ofono_voicecall_new(op); } static void dialing_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar *colp) @@ -95,14 +88,18 @@ 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(interface->daemon, "dialingCall", call_info); + voice_call = ofono_voicecall_new(op); } static void terminated_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op) { if (incoming_call) { - free(incoming_call); + ofono_voicecall_free(incoming_call); incoming_call = NULL; + } else if (voice_call) { + ofono_voicecall_free(voice_call); } + voice_call = NULL; afb_daemon_broadcast_event(interface->daemon, "terminatedCall", NULL); } -- cgit 1.2.3-korg