aboutsummaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
authorsaman <mahmoudi.saman1@gmail.com>2020-12-24 10:56:32 +0330
committersaman <mahmoudi.saman1@gmail.com>2021-01-18 17:50:08 +0330
commitc1fb92c004eb2bda1f214a3012fc661bd1797d7e (patch)
tree420ca1abd8150d24cdeb5d0aad366daf97384984 /binding
parent067ffa5ef915499fed17a2ed67ad2fe689fdea81 (diff)
Adding two new events: signal, battery.koi_10.93.0koi/10.93.010.93.0
1) The signal event will be raised when the Strength of the network registration changes. 2) The battery event will be raised when the BatteryChargeLevel of the handsfree changes. Signed-off-by: saman <mahmoudi.saman1@gmail.com> Change-Id: I80061ece8a927a8cec1a4e379ff11c817377482c
Diffstat (limited to 'binding')
-rw-r--r--binding/telephony-binding.c85
1 files changed, 85 insertions, 0 deletions
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);