summaryrefslogtreecommitdiffstats
path: root/binding/gdbus/ofono_manager.c
diff options
context:
space:
mode:
Diffstat (limited to 'binding/gdbus/ofono_manager.c')
-rw-r--r--binding/gdbus/ofono_manager.c77
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