summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Porter <mporter@konsulko.com>2017-08-08 09:05:14 -0400
committerMatt Porter <mporter@konsulko.com>2017-08-08 09:29:57 -0400
commite598975c8374effa043eb83dcae1c08749f3ea91 (patch)
tree0312c5c04060a1baabf51b9a976ca67234a50e95
parent597ed5434f369ab614fa2ce543aab3f49101b5f1 (diff)
telephony-binding: convert to v2 binding
Convert the telephony-binding to the v2 binding format. Also move to AFB_ message macros and remove propagation of the interface struct. Bug-AGL: SPEC-814 Change-Id: Ic9ce86f59af01ce00cece4e29cd5fe36afa7d74c Signed-off-by: Matt Porter <mporter@konsulko.com>
-rw-r--r--telephony-binding/export.map2
-rw-r--r--telephony-binding/gdbus/ofono_manager.c20
-rw-r--r--telephony-binding/gdbus/ofono_manager.h2
-rw-r--r--telephony-binding/gdbus/ofono_voicecall.c11
-rw-r--r--telephony-binding/gdbus/ofono_voicecall.h3
-rw-r--r--telephony-binding/gdbus/ofono_voicecallmanager.c22
-rw-r--r--telephony-binding/gdbus/ofono_voicecallmanager.h3
-rw-r--r--telephony-binding/telephony-binding.c93
8 files changed, 71 insertions, 85 deletions
diff --git a/telephony-binding/export.map b/telephony-binding/export.map
index 52c1b4a..eea0d7b 100644
--- a/telephony-binding/export.map
+++ b/telephony-binding/export.map
@@ -1 +1 @@
-{ global: afbBindingV1*; local: *; };
+{ global: afbBindingV2*; local: *; };
diff --git a/telephony-binding/gdbus/ofono_manager.c b/telephony-binding/gdbus/ofono_manager.c
index bb99a43..49a2452 100644
--- a/telephony-binding/gdbus/ofono_manager.c
+++ b/telephony-binding/gdbus/ofono_manager.c
@@ -18,6 +18,7 @@
#include <string.h>
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include "ofono_manager.h"
@@ -34,9 +35,8 @@ struct ofono_manager_modem
static OrgOfonoManager *manager;
static struct ofono_manager_modem default_modem;
-static const struct afb_binding_interface *interface;
-int ofono_manager_init(const struct afb_binding_interface *iface)
+int ofono_manager_init()
{
GVariant *out_arg = NULL, *next, *value;
GError *error = NULL;
@@ -44,10 +44,8 @@ int ofono_manager_init(const struct afb_binding_interface *iface)
GVariantIter *iter, *iter2 = NULL;
int ret = 0;
- interface = iface;
-
if (manager) {
- ERROR(interface, "Ofono Manager already initialized\n");
+ AFB_ERROR("Ofono Manager already initialized\n");
return -1;
}
@@ -56,7 +54,7 @@ int ofono_manager_init(const struct afb_binding_interface *iface)
"org.ofono", "/", NULL, NULL);
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
return -1;
}
@@ -91,7 +89,7 @@ int ofono_manager_init(const struct afb_binding_interface *iface)
const gchar *ofono_manager_get_default_modem_path(void)
{
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
}
return default_modem.path;
@@ -100,7 +98,7 @@ const gchar *ofono_manager_get_default_modem_path(void)
const gchar *ofono_manager_get_default_modem_name(void)
{
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
}
return default_modem.name;
@@ -109,7 +107,7 @@ const gchar *ofono_manager_get_default_modem_name(void)
const gchar *ofono_manager_get_default_modem_type(void)
{
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
}
return default_modem.type;
@@ -118,7 +116,7 @@ const gchar *ofono_manager_get_default_modem_type(void)
gboolean ofono_manager_get_default_modem_powered(void)
{
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
}
return default_modem.powered;
@@ -127,7 +125,7 @@ gboolean ofono_manager_get_default_modem_powered(void)
gboolean ofono_manager_get_default_modem_online(void)
{
if (!manager) {
- ERROR(interface, "Ofono Manager not initialized\n");
+ AFB_ERROR("Ofono Manager not initialized\n");
}
return default_modem.online;
diff --git a/telephony-binding/gdbus/ofono_manager.h b/telephony-binding/gdbus/ofono_manager.h
index 6454246..9df9b3c 100644
--- a/telephony-binding/gdbus/ofono_manager.h
+++ b/telephony-binding/gdbus/ofono_manager.h
@@ -20,7 +20,7 @@
#include <afb/afb-binding.h>
#include <afb/afb-service-itf.h>
-int ofono_manager_init(const struct afb_binding_interface *iface);
+int ofono_manager_init(void);
const gchar *ofono_manager_get_default_modem_path(void);
const gchar *ofono_manager_get_default_modem_name(void);
const gchar *ofono_manager_get_default_modem_type(void);
diff --git a/telephony-binding/gdbus/ofono_voicecall.c b/telephony-binding/gdbus/ofono_voicecall.c
index 585bf5f..cdc0da9 100644
--- a/telephony-binding/gdbus/ofono_voicecall.c
+++ b/telephony-binding/gdbus/ofono_voicecall.c
@@ -19,12 +19,11 @@
#include <string.h>
#include <unistd.h>
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include "ofono_voicecall_interface.h"
-const struct afb_binding_interface *interface;
-
static void property_changed(OrgOfonoVoiceCall *voice_call,
gchar *property,
GVariant *value)
@@ -39,13 +38,11 @@ static void property_changed(OrgOfonoVoiceCall *voice_call,
}
}
-OrgOfonoVoiceCall *ofono_voicecall_new(const struct afb_binding_interface *iface,
- gchar *op,
+OrgOfonoVoiceCall *ofono_voicecall_new(gchar *op,
void (*call_state_changed)(OrgOfonoVoiceCall *,gchar *))
{
OrgOfonoVoiceCall *voice_call;
- interface = iface;
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);
@@ -63,11 +60,11 @@ OrgOfonoVoiceCall *ofono_voicecall_new(const struct afb_binding_interface *iface
G_TYPE_STRING);
if (g_signal_connect(G_OBJECT(voice_call), "call-state-changed", G_CALLBACK(call_state_changed), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal call-state-changed\n");
+ AFB_ERROR("Failed to connect to signal call-state-changed\n");
}
if (g_signal_connect(voice_call, "property-changed", G_CALLBACK(property_changed), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal call-added\n");
+ AFB_ERROR("Failed to connect to signal call-added\n");
}
}
diff --git a/telephony-binding/gdbus/ofono_voicecall.h b/telephony-binding/gdbus/ofono_voicecall.h
index 0c2e749..dd3ff6d 100644
--- a/telephony-binding/gdbus/ofono_voicecall.h
+++ b/telephony-binding/gdbus/ofono_voicecall.h
@@ -19,8 +19,7 @@
#include "ofono_voicecall_interface.h"
OrgOfonoVoiceCall *
-ofono_voicecall_new(const struct afb_binding_interface *,
- gchar *,
+ofono_voicecall_new(gchar *,
void (*)(OrgOfonoVoiceCall *,gchar *));
void ofono_voicecall_free(OrgOfonoVoiceCall *);
void ofono_voicecall_answer(OrgOfonoVoiceCall *);
diff --git a/telephony-binding/gdbus/ofono_voicecallmanager.c b/telephony-binding/gdbus/ofono_voicecallmanager.c
index aab4f69..76cf409 100644
--- a/telephony-binding/gdbus/ofono_voicecallmanager.c
+++ b/telephony-binding/gdbus/ofono_voicecallmanager.c
@@ -18,12 +18,11 @@
#include <string.h>
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include "ofono_voicecallmanager_interface.h"
-static const struct afb_binding_interface *interface;
-
static void call_added(OrgOfonoVoiceCallManager *manager,
gchar *op,
GVariant *properties)
@@ -58,14 +57,11 @@ static void call_removed(OrgOfonoVoiceCallManager *manager,
const OrgOfonoVoiceCallManager
-*ofono_voicecallmanager_init(const struct afb_binding_interface *iface,
- const gchar *op,
+*ofono_voicecallmanager_init(const gchar *op,
void (*incoming_call)(OrgOfonoVoiceCallManager *manager,gchar *,gchar *),
void (*dialing_call)(OrgOfonoVoiceCallManager *manager,gchar *,gchar *),
void (*terminated_call)(OrgOfonoVoiceCallManager *manager,gchar *))
{
- interface = iface;
-
OrgOfonoVoiceCallManager *manager = org_ofono_voice_call_manager_proxy_new_for_bus_sync(
G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
"org.ofono", op, NULL, NULL);
@@ -106,23 +102,23 @@ const OrgOfonoVoiceCallManager
G_TYPE_STRING);
if (g_signal_connect(G_OBJECT(manager), "incoming-call", G_CALLBACK(incoming_call), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal incoming-call\n");
+ AFB_ERROR("Failed to connect to signal incoming-call\n");
}
if (g_signal_connect(G_OBJECT(manager), "dialing-call", G_CALLBACK(dialing_call), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal dialing-call\n");
+ AFB_ERROR("Failed to connect to signal dialing-call\n");
}
if (g_signal_connect(G_OBJECT(manager), "terminated-call", G_CALLBACK(terminated_call), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal terminated-call\n");
+ AFB_ERROR("Failed to connect to signal terminated-call\n");
}
if (g_signal_connect(manager, "call-added", G_CALLBACK(call_added), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal call-added\n");
+ AFB_ERROR("Failed to connect to signal call-added\n");
}
if (g_signal_connect(manager, "call-removed", G_CALLBACK(call_removed), NULL) <= 0) {
- ERROR(interface, "Failed to connect to signal call-removed\n");
+ AFB_ERROR("Failed to connect to signal call-removed\n");
}
return manager;
@@ -136,7 +132,7 @@ gchar *ofono_voicecallmanager_dial(OrgOfonoVoiceCallManager *manager,
GError *error = NULL;
if (!manager) {
- ERROR(interface, "Ofono VoiceCallmanager uninitialized\n");
+ AFB_ERROR("Ofono VoiceCallmanager uninitialized\n");
return NULL;
}
@@ -152,7 +148,7 @@ void ofono_voicecallmanager_hangup_all(OrgOfonoVoiceCallManager *manager)
GError *error = NULL;
if (!manager) {
- ERROR(interface, "Ofono VoiceCallmanager uninitialized\n");
+ AFB_ERROR("Ofono VoiceCallmanager uninitialized\n");
return;
}
diff --git a/telephony-binding/gdbus/ofono_voicecallmanager.h b/telephony-binding/gdbus/ofono_voicecallmanager.h
index 19ec509..7477e7c 100644
--- a/telephony-binding/gdbus/ofono_voicecallmanager.h
+++ b/telephony-binding/gdbus/ofono_voicecallmanager.h
@@ -19,8 +19,7 @@
#include "ofono_voicecallmanager_interface.h"
OrgOfonoVoiceCallManager
-*ofono_voicecallmanager_init(const struct afb_binding_interface *,
- const gchar *,
+*ofono_voicecallmanager_init(const gchar *,
void(*)(OrgOfonoVoiceCallManager *, gchar *, gchar *),
void(*)(OrgOfonoVoiceCallManager *, gchar *, gchar *),
void(*)(OrgOfonoVoiceCallManager *, gchar *));
diff --git a/telephony-binding/telephony-binding.c b/telephony-binding/telephony-binding.c
index d58aeab..b1c39f1 100644
--- a/telephony-binding/telephony-binding.c
+++ b/telephony-binding/telephony-binding.c
@@ -19,6 +19,7 @@
#include <glib.h>
#include <json-c/json.h>
+#define AFB_BINDING_VERSION 2
#include <afb/afb-binding.h>
#include <afb/afb-service-itf.h>
@@ -26,8 +27,6 @@
#include "ofono_voicecallmanager.h"
#include "ofono_voicecall.h"
-static const struct afb_binding_interface *interface;
-
static OrgOfonoVoiceCallManager *vcm;
static OrgOfonoVoiceCall *incoming_call, *voice_call;
@@ -41,19 +40,19 @@ static void dial(struct afb_req request)
if (json_object_is_type(val, json_type_string)) {
number = json_object_get_string(val);
if (voice_call) {
- ERROR(interface, "dial: cannot dial with active call");
+ AFB_ERROR("dial: cannot dial with active call");
afb_req_fail(request, "active call", NULL);
} else {
- DEBUG(interface, "dial: %s...\n", number);
+ AFB_DEBUG("dial: %s...\n", number);
if (ofono_voicecallmanager_dial(vcm, (gchar *)number, "")) {
afb_req_success(request, NULL, NULL);
} else {
- ERROR(interface, "dial: failed to dial number\n");
+ AFB_ERROR("dial: failed to dial number\n");
afb_req_fail(request, "failed dial", NULL);
}
}
} else {
- ERROR(interface, "dial: no phone number parameter\n");
+ AFB_ERROR("dial: no phone number parameter\n");
afb_req_fail(request, "no number", NULL);
}
}
@@ -61,15 +60,15 @@ static void dial(struct afb_req request)
static void hangup(struct afb_req request)
{
if (voice_call) {
- DEBUG(interface, "Hangup voice call\n");
+ AFB_DEBUG("Hangup voice call\n");
ofono_voicecall_hangup(voice_call);
afb_req_success(request, NULL, NULL);
} else if (incoming_call) {
- DEBUG(interface, "Reject incoming call\n");
+ AFB_DEBUG("Reject incoming call\n");
ofono_voicecall_hangup(incoming_call);
afb_req_success(request, NULL, NULL);
} else {
- ERROR(interface, "Hangup: no active call");
+ AFB_ERROR("Hangup: no active call");
afb_req_fail(request, "failed hangup", NULL);
}
}
@@ -77,11 +76,11 @@ static void hangup(struct afb_req request)
static void answer(struct afb_req request)
{
if (incoming_call) {
- DEBUG(interface, "Answer voice call\n");
+ AFB_DEBUG("Answer voice call\n");
voice_call = incoming_call;
ofono_voicecall_answer(voice_call);
} else {
- ERROR(interface, "Answer: no incoming call");
+ AFB_ERROR("Answer: no incoming call");
}
}
@@ -90,7 +89,7 @@ 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(interface->daemon, "callStateChanged", call_state);
+ afb_daemon_broadcast_event("callStateChanged", call_state);
}
static void incoming_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar *clip)
@@ -99,8 +98,8 @@ 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 = ofono_voicecall_new(interface, op, call_state_changed_cb);
+ afb_daemon_broadcast_event("incomingCall", call_info);
+ incoming_call = ofono_voicecall_new(op, call_state_changed_cb);
}
static void dialing_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op, gchar *colp)
@@ -109,8 +108,8 @@ 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(interface, op, call_state_changed_cb);
+ afb_daemon_broadcast_event("dialingCall", call_info);
+ voice_call = ofono_voicecall_new(op, call_state_changed_cb);
}
static void terminated_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op)
@@ -122,8 +121,7 @@ static void terminated_call_cb(OrgOfonoVoiceCallManager *manager, gchar *op)
ofono_voicecall_free(voice_call);
}
voice_call = NULL;
-
- afb_daemon_broadcast_event(interface->daemon, "terminatedCall", NULL);
+ afb_daemon_broadcast_event("terminatedCall", NULL);
}
static void *main_loop_thread(void *unused)
@@ -141,72 +139,71 @@ static int ofono_init(void)
/* Start the main loop thread */
pthread_create(&tid, NULL, main_loop_thread, NULL);
- ret = ofono_manager_init(interface);
+ ret = ofono_manager_init();
if (ret == 0) {
const gchar *modem_path = ofono_manager_get_default_modem_path();
if (modem_path) {
- DEBUG(interface, "modem_path: %s\n", modem_path);
- vcm = ofono_voicecallmanager_init(interface, modem_path,
+ AFB_DEBUG("modem_path: %s\n", modem_path);
+ vcm = ofono_voicecallmanager_init(modem_path,
incoming_call_cb,
dialing_call_cb,
terminated_call_cb);
if (!vcm) {
- ERROR(interface, "[telephony] failed to initialize voice call manager\n");
+ AFB_ERROR("failed to initialize voice call manager\n");
ret = -1;
}
} else {
- ERROR(interface, "[telephony] default modem not set\n");
+ AFB_ERROR("default modem not set\n");
ret = -1;
}
} else {
- ERROR(interface, "[telephony] failed to initialize ofono manager: " \
+ AFB_ERROR("failed to initialize ofono manager: " \
"HFP device not connected or Bluetooth disabled\n");
}
return ret;
}
-static const struct afb_verb_desc_v1 verbs[]= {
+static const struct afb_verb_v2 verbs[]= {
{
- .name = "dial",
- .session = AFB_SESSION_NONE,
+ .verb = "dial",
.callback = dial,
- .info = "Dial phone"
+ .auth = NULL,
+ .session = AFB_SESSION_NONE,
},
{
- .name = "hangup",
- .session = AFB_SESSION_NONE,
+ .verb = "hangup",
.callback = hangup,
- .info = "Hangup phone"
+ .auth = NULL,
+ .session = AFB_SESSION_NONE,
},
{
- .name = "answer",
- .session = AFB_SESSION_NONE,
+ .verb = "answer",
.callback = answer,
- .info = "Answer phone"
+ .auth = NULL,
+ .session = AFB_SESSION_NONE,
},
{NULL}
};
-static const struct afb_binding binding_desc = {
- .type = AFB_BINDING_VERSION_1,
- .v1 = {
- .info = "telephony service",
- .prefix = "telephony",
- .verbs = verbs
- }
-};
-
-const struct afb_binding *afbBindingV1Register (const struct afb_binding_interface *itf)
+static int preinit()
{
- interface = itf;
+ AFB_NOTICE("Pre-init telephony service");
- return &binding_desc;
+ return 0;
}
-int afbBindingV1ServiceInit(struct afb_service service)
+static int init()
{
- DEBUG(interface, "Initializing telephony service\n");
+ AFB_NOTICE("Initializing telephony service");
return ofono_init();
}
+
+const struct afb_binding_v2 afbBindingV2 = {
+ .api = "telephony",
+ .specification = NULL,
+ .verbs = verbs,
+ .preinit = preinit,
+ .init = init,
+};