diff options
Diffstat (limited to 'binding/gdbus')
-rw-r--r-- | binding/gdbus/ofono_manager.c | 77 | ||||
-rw-r--r-- | binding/gdbus/ofono_manager.h | 4 |
2 files changed, 81 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 diff --git a/binding/gdbus/ofono_manager.h b/binding/gdbus/ofono_manager.h index 0556d4f..c7333d0 100644 --- a/binding/gdbus/ofono_manager.h +++ b/binding/gdbus/ofono_manager.h @@ -21,6 +21,9 @@ #define AFB_BINDING_VERSION 3 #include <afb/afb-binding.h> +#define OFONO_SERVICE "org.ofono" +#define OFONO_HANDSFREE_INTERFACE OFONO_SERVICE ".Handsfree" + int ofono_manager_init(void); void ofono_manager_invalidate_default_modem(void); int ofono_manager_set_default_modem(const char *); @@ -31,3 +34,4 @@ const gchar *ofono_manager_get_default_modem_type(void); gboolean ofono_manager_get_default_modem_powered(void); gboolean ofono_manager_get_default_modem_online(void); gboolean ofono_manager_get_default_modem_valid(void); +json_object *ofono_get_property(const char *path, const char *interface, const char *name, GError **error);
\ No newline at end of file |