diff options
author | saman <mahmoudi.saman1@gmail.com> | 2020-11-07 09:58:01 +0330 |
---|---|---|
committer | saman <mahmoudi.saman1@gmail.com> | 2020-11-19 09:08:28 +0330 |
commit | 56fec224dc4dd73a631ac2c15c1a240fd8e92e81 (patch) | |
tree | 64293bd46878d2ad7052b8387d4f6f21c04acf82 /binding/gdbus/ofono_manager.c | |
parent | 5762ff51fce596eadbd57522a6ab2978147cd830 (diff) |
Getting battery level of connected phone device
Adding "get_battery_level" verb for getting battery level of connected phone device.
Is used ofono service and handsfree interface.
Bug-AGL: SPEC-3687
Signed-off-by: saman <mahmoudi.saman1@gmail.com>
Change-Id: I9713cb186195a170909e6511991cfc32380e12a1
Diffstat (limited to 'binding/gdbus/ofono_manager.c')
-rw-r--r-- | binding/gdbus/ofono_manager.c | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/binding/gdbus/ofono_manager.c b/binding/gdbus/ofono_manager.c index c0000dc..0eb63ea 100644 --- a/binding/gdbus/ofono_manager.c +++ b/binding/gdbus/ofono_manager.c @@ -182,3 +182,80 @@ gboolean ofono_manager_get_default_modem_valid(void) return default_modem.valid; } + +static json_object *gvariant_to_json(GVariant *value) +{ + const gchar *type = g_variant_get_type_string(value); + json_object *res = NULL; + json_object *obj = NULL; + switch (*type) { + case 'o': + case 's': + res = json_object_new_string(g_variant_get_string(value, NULL)); + break; + case 'b': + res = json_object_new_int(g_variant_get_boolean(value)); + break; + case 'u': + res = json_object_new_int64(g_variant_get_uint32(value)); + break; + case 'y': + res = json_object_new_int((int)g_variant_get_byte(value)); + break; + case 'a': + if(g_strcmp0(type, "as")) + break; + const gchar *arr_str; + GVariantIter i; + obj = json_object_new_array(); + g_variant_iter_init(&i, value); + while (g_variant_iter_next(&i, "s", &arr_str)) + json_object_array_add(obj, json_object_new_string(arr_str)); + res = obj; + default: + break; + } + return res; +} + +json_object * ofono_get_properties(GDBusConnection *conn, const char *path, const char *interface, GError **error) +{ + GVariant *reply = NULL; + GVariantIter *array; + GVariant *var = NULL; + const gchar *key = NULL; + json_object *jprop = NULL; + + reply = g_dbus_connection_call_sync(conn, + OFONO_SERVICE, path, interface, "GetProperties", + NULL, NULL, G_DBUS_CALL_FLAGS_NONE, + (120 * 1000), NULL, error); + if (!reply) + return NULL; + + g_variant_get(reply, "(a{sv})", &array); + jprop = json_object_new_object(); + while (g_variant_iter_loop(array, "{sv}", &key, &var)) { + json_object_object_add(jprop,key,gvariant_to_json(var)); + } + g_variant_iter_free(array); + g_variant_unref(reply); + return jprop; +} + +json_object *ofono_get_property(const char *path, const char *interface, const char *name, GError **error) +{ + GDBusConnection *conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, error); + json_object *jprop; + json_object *jret = json_object_new_object(); + jprop = ofono_get_properties(conn,path,interface,error); + json_object_object_foreach(jprop, key, jval) { + if (name) { + if (!g_strcmp0(key, name)) { + return jval; + } + } + json_object_object_add(jret,key,jval); + } + return jret; +}
\ No newline at end of file |