2 * Copyright (C) 2017 Konsulko Group
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <afb/afb-binding.h>
23 #include "ofono_manager.h"
24 #include "ofono_manager_interface.h"
26 struct ofono_manager_modem
35 static OrgOfonoManager *manager;
36 static struct ofono_manager_modem default_modem;
37 static const struct afb_binding_interface *interface;
39 int ofono_manager_init(const struct afb_binding_interface *iface)
41 GVariant *out_arg = NULL, *next, *value;
44 GVariantIter *iter, *iter2 = NULL;
50 ERROR(interface, "Ofono Manager already initialized\n");
54 manager = org_ofono_manager_proxy_new_for_bus_sync(
55 G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE,
56 "org.ofono", "/", NULL, NULL);
59 ERROR(interface, "Ofono Manager not initialized\n");
63 org_ofono_manager_call_get_modems_sync(manager, &out_arg, NULL, &error);
65 g_variant_get(out_arg, "a(oa{sv})", &iter);
66 next = g_variant_iter_next_value(iter);
68 g_variant_get(next, "(oa{sv})", &path, &iter2);
69 default_modem.path = path;
70 while (g_variant_iter_loop(iter2, "{sv}", &key, &value)) {
71 if (!strcmp(key, "Name"))
72 default_modem.name = g_variant_get_string(value, NULL);
73 else if (!strcmp(key, "Type"))
74 default_modem.type = g_variant_get_string(value, NULL);
75 else if (!strcmp(key, "Powered"))
76 default_modem.powered = g_variant_get_boolean(value);
77 else if (!strcmp(key, "Online"))
78 default_modem.online = g_variant_get_boolean(value);
91 const gchar *ofono_manager_get_default_modem_path(void)
94 ERROR(interface, "Ofono Manager not initialized\n");
97 return default_modem.path;
100 const gchar *ofono_manager_get_default_modem_name(void)
103 ERROR(interface, "Ofono Manager not initialized\n");
106 return default_modem.name;
109 const gchar *ofono_manager_get_default_modem_type(void)
112 ERROR(interface, "Ofono Manager not initialized\n");
115 return default_modem.type;
118 gboolean ofono_manager_get_default_modem_powered(void)
121 ERROR(interface, "Ofono Manager not initialized\n");
124 return default_modem.powered;
127 gboolean ofono_manager_get_default_modem_online(void)
130 ERROR(interface, "Ofono Manager not initialized\n");
133 return default_modem.online;