aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--binding/telephony-binding.c85
2 files changed, 87 insertions, 0 deletions
diff --git a/README.md b/README.md
index d6cee02..0d3aac6 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ Telephony service allows respective clients access to the Handsfree Profile via
| incomingCall | Incoming call events | {"clip": "3305551212"} |
| terminatedCall | Terminated call event | *empty JSON response* |
| online | Connected status of Handsfree Profile | {"connected": true} |
+| battery | Connected status of Handsfree Profile | {"battery level": 2} |
+| signal | Connected status of Handsfree Profile | {"signal level": 20} |
### callStateChanged Event
diff --git a/binding/telephony-binding.c b/binding/telephony-binding.c
index b2dc073..5eb3dc2 100644
--- a/binding/telephony-binding.c
+++ b/binding/telephony-binding.c
@@ -36,6 +36,8 @@ static afb_event_t dialing_call_event;
static afb_event_t incoming_call_event;
static afb_event_t terminated_call_event;
static afb_event_t online_event;
+static afb_event_t battery_event;
+static afb_event_t signal_event;
static void dial(afb_req_t request)
{
@@ -171,6 +173,10 @@ static void subscribe(afb_req_t request)
afb_req_subscribe(request, incoming_call_event);
} else if (!strcasecmp(value, "terminatedCall")) {
afb_req_subscribe(request, terminated_call_event);
+ } else if (!strcasecmp(value, "battery")) {
+ afb_req_subscribe(request, battery_event);
+ } else if (!strcasecmp(value, "signal")) {
+ afb_req_subscribe(request, signal_event);
} else if (!strcasecmp(value, "online")) {
json_object *jresp = json_object_new_object();
@@ -337,6 +343,61 @@ static void ofono_modem_signal_callback(
g_free(address);
}
+static void ofono_handsfree_signal_callback(
+ GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ GVariant *var = NULL;
+ const gchar *key = NULL;
+
+ if (strncasecmp(object_path, "/hfp/org/bluez", 14))
+ return;
+
+ if (g_strcmp0(signal_name, "PropertyChanged"))
+ return;
+
+ g_variant_get(parameters, "(sv)", &key, &var);
+ if (g_strcmp0(key, "BatteryChargeLevel"))
+ return;
+
+ g_variant_get(parameters, "(sv)", &key, &var);
+
+ json_object *jresp = json_object_new_object();
+ json_object_object_add(jresp, "battery level", json_object_new_int((int)g_variant_get_byte(var)));
+ afb_event_push(battery_event, jresp);
+}
+
+static void ofono_networkregistration_signal_callback(
+ GDBusConnection *connection,
+ const gchar *sender_name,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ GVariant *var = NULL;
+ const gchar *key = NULL;
+
+ if (strncasecmp(object_path, "/hfp/org/bluez", 14))
+ return;
+
+ if (g_strcmp0(signal_name, "PropertyChanged"))
+ return;
+
+ g_variant_get(parameters, "(sv)", &key, &var);
+ if (g_strcmp0(key, "Strength"))
+ return;
+ json_object *jresp = json_object_new_object();
+ json_object_object_add(jresp, "signal level", json_object_new_int((int)g_variant_get_byte(var)));
+ afb_event_push(signal_event, jresp);
+}
+
static void ofono_event_init(void)
{
GError *error = NULL;
@@ -352,6 +413,28 @@ static void ofono_event_init(void)
ofono_modem_signal_callback,
NULL, /* user ptr */
NULL);
+
+ g_dbus_connection_signal_subscribe(conn,
+ NULL, /* sender */
+ OFONO_HANDSFREE_INTERFACE,
+ NULL, /* member */
+ NULL, /* object path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ ofono_handsfree_signal_callback,
+ NULL, /* user ptr */
+ NULL);
+
+ g_dbus_connection_signal_subscribe(conn,
+ NULL, /* sender */
+ OFONO_NetworkRegistration_INTERFACE,
+ NULL, /* member */
+ NULL, /* object path */
+ NULL, /* arg0 */
+ G_DBUS_SIGNAL_FLAGS_NONE,
+ ofono_networkregistration_signal_callback,
+ NULL, /* user ptr */
+ NULL);
}
@@ -374,6 +457,8 @@ static int ofono_init(afb_api_t api)
incoming_call_event = afb_daemon_make_event("incomingCall");
terminated_call_event = afb_daemon_make_event("terminatedCall");
online_event = afb_daemon_make_event("online");
+ battery_event = afb_daemon_make_event("battery");
+ signal_event = afb_daemon_make_event("signal");
/* Start the main loop thread */
pthread_create(&tid, NULL, main_loop_thread, NULL);