1 #include "e_connman_private.h"
5 static E_DBus_Signal_Handler *cb_name_owner_changed = NULL;
6 static DBusPendingCall *pending_get_name_owner = NULL;
7 static unsigned int init_count = 0;
8 static char *unique_name = NULL;
10 static const char bus_name[] = "net.connman";
12 E_DBus_Connection *e_connman_conn = NULL;
14 EAPI int E_CONNMAN_EVENT_MANAGER_IN = 0;
15 EAPI int E_CONNMAN_EVENT_MANAGER_OUT = 0;
16 EAPI int E_CONNMAN_EVENT_ELEMENT_ADD = 0;
17 EAPI int E_CONNMAN_EVENT_ELEMENT_DEL = 0;
18 EAPI int E_CONNMAN_EVENT_ELEMENT_UPDATED = 0;
20 const char *e_connman_iface_manager = NULL;
21 const char *e_connman_iface_profile = NULL;
22 const char *e_connman_iface_service = NULL;
23 const char *e_connman_iface_connection = NULL;
24 const char *e_connman_iface_technology = NULL;
26 const char *e_connman_prop_available = NULL;
27 const char *e_connman_prop_connections = NULL;
28 const char *e_connman_prop_default = NULL;
29 const char *e_connman_prop_ipv4 = NULL;
30 const char *e_connman_prop_ipv4_configuration = NULL;
31 const char *e_connman_prop_ethernet = NULL;
32 const char *e_connman_prop_method = NULL;
33 const char *e_connman_prop_address = NULL;
34 const char *e_connman_prop_gateway = NULL;
35 const char *e_connman_prop_netmask = NULL;
36 const char *e_connman_prop_mtu = NULL;
37 const char *e_connman_prop_name = NULL;
38 const char *e_connman_prop_offline_mode = NULL;
39 const char *e_connman_prop_policy = NULL;
40 const char *e_connman_prop_priority = NULL;
41 const char *e_connman_prop_profiles = NULL;
42 const char *e_connman_prop_profile_active = NULL;
43 const char *e_connman_prop_services = NULL;
44 const char *e_connman_prop_technologies = NULL;
45 const char *e_connman_prop_remember = NULL;
46 const char *e_connman_prop_state = NULL;
47 const char *e_connman_prop_strength = NULL;
48 const char *e_connman_prop_type = NULL;
49 const char *e_connman_prop_error = NULL;
50 const char *e_connman_prop_mode = NULL;
51 const char *e_connman_prop_security = NULL;
52 const char *e_connman_prop_passphrase = NULL;
53 const char *e_connman_prop_passphrase_required = NULL;
54 const char *e_connman_prop_favorite = NULL;
55 const char *e_connman_prop_immutable = NULL;
56 const char *e_connman_prop_auto_connect = NULL;
57 const char *e_connman_prop_setup_required = NULL;
58 const char *e_connman_prop_apn = NULL;
59 const char *e_connman_prop_mcc = NULL;
60 const char *e_connman_prop_mnc = NULL;
61 const char *e_connman_prop_roaming = NULL;
62 const char *e_connman_prop_technology_default = NULL;
63 const char *e_connman_prop_technologies_available = NULL;
64 const char *e_connman_prop_technologies_enabled = NULL;
65 const char *e_connman_prop_technologies_connected = NULL;
67 int _e_dbus_connman_log_dom = -1;
70 e_connman_system_bus_name_get(void)
72 return unique_name ? unique_name : bus_name;
75 /***********************************************************************
77 ***********************************************************************/
80 * Synchronize elements with server.
82 * This will call Manager.GetProperties() on server, retrieve properties
83 * and some element paths and then request their properties.
85 * This call will add events E_CONNMAN_EVENT_ELEMENT_ADD and
86 * E_CONNMAN_EVENT_ELEMENT_UPDATED to the main loop.
88 * This will not remove stale elements.
90 * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
93 e_connman_manager_sync_elements(void)
95 E_Connman_Element *manager;
100 manager = e_connman_element_register(manager_path, e_connman_iface_manager);
102 e_connman_element_properties_sync(manager);
106 DBG("sync_manager: %s (%s)", unique_name, bus_name);
112 _e_connman_system_name_owner_exit(void)
114 e_connman_manager_clear_elements();
115 ecore_event_add(E_CONNMAN_EVENT_MANAGER_OUT, NULL, NULL, NULL);
122 _e_connman_system_name_owner_enter(const char *uid)
124 DBG("enter connman at %s (old was %s)", uid, unique_name);
125 if (unique_name && strcmp(unique_name, uid) == 0)
127 DBG("same unique_name for connman, ignore.");
132 _e_connman_system_name_owner_exit();
134 unique_name = strdup(uid);
136 ecore_event_add(E_CONNMAN_EVENT_MANAGER_IN, NULL, NULL, NULL);
137 e_connman_manager_sync_elements();
141 _e_connman_system_name_owner_changed(void *data __UNUSED__, DBusMessage *msg)
144 const char *name, *from, *to;
146 dbus_error_init(&err);
147 if (!dbus_message_get_args(msg, &err,
148 DBUS_TYPE_STRING, &name,
149 DBUS_TYPE_STRING, &from,
150 DBUS_TYPE_STRING, &to,
153 ERR("could not get NameOwnerChanged arguments: %s: %s",
154 err.name, err.message);
155 dbus_error_free(&err);
159 if (strcmp(name, bus_name) != 0)
162 DBG("NameOwnerChanged from=[%s] to=[%s]", from, to);
164 if (from[0] == '\0' && to[0] != '\0')
166 _e_connman_system_name_owner_enter(to);
168 else if (from[0] != '\0' && to[0] == '\0')
170 DBG("exit connman at %s", from);
171 if (strcmp(unique_name, from) != 0)
172 DBG("%s was not the known name %s, ignored.", from, unique_name);
174 _e_connman_system_name_owner_exit();
178 DBG("unknow change from %s to %s", from, to);
183 _e_connman_get_name_owner(void *data __UNUSED__, DBusMessage *msg, DBusError *err)
189 pending_get_name_owner = NULL;
191 if (!_dbus_callback_check_and_init(msg, &itr, err))
194 t = dbus_message_iter_get_arg_type(&itr);
195 if (!_dbus_iter_type_check(t, DBUS_TYPE_STRING))
198 dbus_message_iter_get_basic(&itr, &uid);
201 ERR("no name owner!");
205 _e_connman_system_name_owner_enter(uid);
210 * Initialize E Connection Manager (E_Connman) system.
212 * This will connect and watch net.connman.Manager and Element
213 * events and translate to Ecore main loop events, also provide a
214 * proxy for method invocation on server.
216 * Interesting events are:
217 * - E_CONNMAN_EVENT_MANAGER_IN: issued when connman is avaiable.
218 * - E_CONNMAN_EVENT_MANAGER_OUT: issued when connman connection is lost.
219 * - E_CONNMAN_EVENT_ELEMENT_ADD: element was added.
220 * - E_CONNMAN_EVENT_ELEMENT_DEL: element was deleted.
221 * - E_CONNMAN_EVENT_ELEMENT_UPDATED: element was updated (properties
224 * Manager IN/OUT events do not provide any event information, just
225 * tells you that system is usable or not. After manager is out, all
226 * elements will be removed, so after this event do not use the system anymore.
228 * Element events will give you an element object. After DEL event callback
229 * returns, that element will not be valid anymore.
232 e_connman_system_init(E_DBus_Connection *edbus_conn)
239 _e_dbus_connman_log_dom = eina_log_domain_register
240 ("e_dbus_connman", EINA_LOG_DEFAULT_COLOR);
242 if(_e_dbus_connman_log_dom < 0)
245 ("impossible to create a log domain for edbus_connman module");
249 if (E_CONNMAN_EVENT_MANAGER_IN == 0)
250 E_CONNMAN_EVENT_MANAGER_IN = ecore_event_type_new();
252 if (E_CONNMAN_EVENT_MANAGER_OUT == 0)
253 E_CONNMAN_EVENT_MANAGER_OUT = ecore_event_type_new();
255 if (E_CONNMAN_EVENT_ELEMENT_ADD == 0)
256 E_CONNMAN_EVENT_ELEMENT_ADD = ecore_event_type_new();
258 if (E_CONNMAN_EVENT_ELEMENT_DEL == 0)
259 E_CONNMAN_EVENT_ELEMENT_DEL = ecore_event_type_new();
261 if (E_CONNMAN_EVENT_ELEMENT_UPDATED == 0)
262 E_CONNMAN_EVENT_ELEMENT_UPDATED = ecore_event_type_new();
264 if (!e_connman_iface_manager)
265 e_connman_iface_manager = eina_stringshare_add("net.connman.Manager");
267 if (!e_connman_iface_profile)
268 e_connman_iface_profile = eina_stringshare_add("net.connman.Profile");
270 if (!e_connman_iface_service)
271 e_connman_iface_service = eina_stringshare_add("net.connman.Service");
273 if (!e_connman_iface_connection)
274 e_connman_iface_connection = eina_stringshare_add("net.connman.Connection");
276 if (!e_connman_iface_technology)
277 e_connman_iface_technology = eina_stringshare_add("net.connman.Technology");
279 if (!e_connman_prop_available)
280 e_connman_prop_available = eina_stringshare_add("Available");
282 if (!e_connman_prop_connections)
283 e_connman_prop_connections = eina_stringshare_add("Connections");
285 if (!e_connman_prop_default)
286 e_connman_prop_default = eina_stringshare_add("Default");
288 if (!e_connman_prop_ipv4)
289 e_connman_prop_ipv4 = eina_stringshare_add("IPv4");
291 if (!e_connman_prop_ipv4_configuration)
292 e_connman_prop_ipv4_configuration = eina_stringshare_add("IPv4.Configuration");
294 if (!e_connman_prop_ethernet)
295 e_connman_prop_ethernet = eina_stringshare_add("Ethernet");
297 if (!e_connman_prop_method)
298 e_connman_prop_method = eina_stringshare_add("Method");
300 if (!e_connman_prop_address)
301 e_connman_prop_address = eina_stringshare_add("Address");
303 if (!e_connman_prop_gateway)
304 e_connman_prop_gateway = eina_stringshare_add("Gateway");
306 if (!e_connman_prop_netmask)
307 e_connman_prop_netmask = eina_stringshare_add("Netmask");
309 if (!e_connman_prop_mtu)
310 e_connman_prop_mtu = eina_stringshare_add("MTU");
312 if (!e_connman_prop_name)
313 e_connman_prop_name = eina_stringshare_add("Name");
315 if (!e_connman_prop_offline_mode)
316 e_connman_prop_offline_mode = eina_stringshare_add("OfflineMode");
318 if (!e_connman_prop_policy)
319 e_connman_prop_policy = eina_stringshare_add("Policy");
321 if (!e_connman_prop_priority)
322 e_connman_prop_priority = eina_stringshare_add("Priority");
324 if (!e_connman_prop_profiles)
325 e_connman_prop_profiles = eina_stringshare_add("Profiles");
327 if (!e_connman_prop_profile_active)
328 e_connman_prop_profile_active = eina_stringshare_add("ActiveProfile");
330 if (!e_connman_prop_services)
331 e_connman_prop_services = eina_stringshare_add("Services");
333 if (!e_connman_prop_technologies)
334 e_connman_prop_technologies = eina_stringshare_add("Technologies");
336 if (!e_connman_prop_remember)
337 e_connman_prop_remember = eina_stringshare_add("Remember");
339 if (!e_connman_prop_state)
340 e_connman_prop_state = eina_stringshare_add("State");
342 if (!e_connman_prop_strength)
343 e_connman_prop_strength = eina_stringshare_add("Strength");
345 if (!e_connman_prop_type)
346 e_connman_prop_type = eina_stringshare_add("Type");
348 if (!e_connman_prop_error)
349 e_connman_prop_error = eina_stringshare_add("Error");
351 if (!e_connman_prop_mode)
352 e_connman_prop_mode = eina_stringshare_add("Mode");
354 if (!e_connman_prop_security)
355 e_connman_prop_security = eina_stringshare_add("Security");
357 if (!e_connman_prop_passphrase)
358 e_connman_prop_passphrase = eina_stringshare_add("Passphrase");
360 if (!e_connman_prop_passphrase_required)
361 e_connman_prop_passphrase_required = eina_stringshare_add("PassphraseRequired");
363 if (!e_connman_prop_favorite)
364 e_connman_prop_favorite = eina_stringshare_add("Favorite");
366 if (!e_connman_prop_immutable)
367 e_connman_prop_immutable = eina_stringshare_add("Immutable");
369 if (!e_connman_prop_auto_connect)
370 e_connman_prop_auto_connect = eina_stringshare_add("AutoConnect");
372 if (!e_connman_prop_setup_required)
373 e_connman_prop_setup_required = eina_stringshare_add("SetupRequired");
375 if (!e_connman_prop_apn)
376 e_connman_prop_apn = eina_stringshare_add("APN");
378 if (!e_connman_prop_mcc)
379 e_connman_prop_mcc = eina_stringshare_add("MCC");
381 if (!e_connman_prop_mnc)
382 e_connman_prop_mnc = eina_stringshare_add("MNC");
384 if (!e_connman_prop_roaming)
385 e_connman_prop_roaming = eina_stringshare_add("Roaming");
387 if (!e_connman_prop_technology_default)
388 e_connman_prop_technology_default = eina_stringshare_add("DefaultTechnology");
390 if (!e_connman_prop_technologies_available)
391 e_connman_prop_technologies_available = eina_stringshare_add("AvailableTechnologies");
393 if (!e_connman_prop_technologies_enabled)
394 e_connman_prop_technologies_enabled = eina_stringshare_add("EnabledTechnologies");
396 if (!e_connman_prop_technologies_connected)
397 e_connman_prop_technologies_connected = eina_stringshare_add("ConnectedTechnologies");
399 e_connman_conn = edbus_conn;
400 cb_name_owner_changed = e_dbus_signal_handler_add
401 (e_connman_conn, E_DBUS_FDO_BUS, E_DBUS_FDO_PATH, E_DBUS_FDO_INTERFACE, "NameOwnerChanged",
402 _e_connman_system_name_owner_changed, NULL);
404 if (pending_get_name_owner)
405 dbus_pending_call_cancel(pending_get_name_owner);
407 pending_get_name_owner = e_dbus_get_name_owner
408 (e_connman_conn, bus_name, _e_connman_get_name_owner, NULL);
410 e_connman_elements_init();
416 _stringshare_del(const char **str)
421 eina_stringshare_del(*str);
426 * Shutdown connman system.
428 * When count drops to 0 resources will be released and no calls should be
432 e_connman_system_shutdown(void)
436 ERR("connman system already shut down.");
444 _stringshare_del(&e_connman_iface_manager);
445 _stringshare_del(&e_connman_iface_profile);
446 _stringshare_del(&e_connman_iface_service);
447 _stringshare_del(&e_connman_iface_connection);
448 _stringshare_del(&e_connman_iface_technology);
450 _stringshare_del(&e_connman_prop_available);
451 _stringshare_del(&e_connman_prop_connections);
452 _stringshare_del(&e_connman_prop_default);
453 _stringshare_del(&e_connman_prop_ipv4);
454 _stringshare_del(&e_connman_prop_ipv4_configuration);
455 _stringshare_del(&e_connman_prop_ethernet);
456 _stringshare_del(&e_connman_prop_method);
457 _stringshare_del(&e_connman_prop_address);
458 _stringshare_del(&e_connman_prop_gateway);
459 _stringshare_del(&e_connman_prop_netmask);
460 _stringshare_del(&e_connman_prop_mtu);
461 _stringshare_del(&e_connman_prop_name);
462 _stringshare_del(&e_connman_prop_offline_mode);
463 _stringshare_del(&e_connman_prop_policy);
464 _stringshare_del(&e_connman_prop_priority);
465 _stringshare_del(&e_connman_prop_profiles);
466 _stringshare_del(&e_connman_prop_profile_active);
467 _stringshare_del(&e_connman_prop_services);
468 _stringshare_del(&e_connman_prop_technologies);
469 _stringshare_del(&e_connman_prop_remember);
470 _stringshare_del(&e_connman_prop_state);
471 _stringshare_del(&e_connman_prop_strength);
472 _stringshare_del(&e_connman_prop_type);
473 _stringshare_del(&e_connman_prop_error);
474 _stringshare_del(&e_connman_prop_mode);
475 _stringshare_del(&e_connman_prop_security);
476 _stringshare_del(&e_connman_prop_passphrase);
477 _stringshare_del(&e_connman_prop_passphrase_required);
478 _stringshare_del(&e_connman_prop_favorite);
479 _stringshare_del(&e_connman_prop_immutable);
480 _stringshare_del(&e_connman_prop_auto_connect);
481 _stringshare_del(&e_connman_prop_setup_required);
482 _stringshare_del(&e_connman_prop_apn);
483 _stringshare_del(&e_connman_prop_mcc);
484 _stringshare_del(&e_connman_prop_mnc);
485 _stringshare_del(&e_connman_prop_roaming);
486 _stringshare_del(&e_connman_prop_technology_default);
487 _stringshare_del(&e_connman_prop_technologies_available);
488 _stringshare_del(&e_connman_prop_technologies_enabled);
489 _stringshare_del(&e_connman_prop_technologies_connected);
491 if (pending_get_name_owner)
493 dbus_pending_call_cancel(pending_get_name_owner);
494 pending_get_name_owner = NULL;
497 if (cb_name_owner_changed)
499 e_dbus_signal_handler_del(e_connman_conn, cb_name_owner_changed);
500 cb_name_owner_changed = NULL;
504 _e_connman_system_name_owner_exit();
506 e_connman_elements_shutdown();
507 eina_log_domain_unregister(_e_dbus_connman_log_dom);
508 e_connman_conn = NULL;