e_connman0_7x: phase-2 - remove the old library and create the new one.
[framework/uifw/edbus.git] / src / lib / connman0_7x / e_connman_manager.c
1 #include "e_connman_private.h"
2
3 /**
4  * Get the element manager.
5  *
6  * @return element pointer if found, NULL otherwise.
7  */
8 E_Connman_Element *
9 e_connman_manager_get(void)
10 {
11    return e_connman_element_get(manager_path);
12 }
13
14 /**
15  * Register new agent for handling user requests.
16  *
17  * Call method RegisterAgent(object) on server in order to
18  * register new agent for handling user requests.
19  *
20  * @param object_path object to be registered.
21  * @param cb function to call when server replies or some error happens.
22  * @param data data to give to cb when it is called.
23  *
24  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
25  */
26 Eina_Bool
27 e_connman_manager_agent_register(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data)
28 {
29    const char name[] = "RegisterAgent";
30    E_Connman_Element *element;
31
32    EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, EINA_FALSE);
33
34    element = e_connman_manager_get();
35    if (!element)
36       return EINA_FALSE;
37
38    return e_connman_element_call_with_path
39              (element, name, object_path, NULL,
40              &element->_pending.agent_register, cb, data);
41 }
42
43 /**
44  * Unregister an existing agent.
45  *
46  * Call method UnregisterAgent(object) on server in order to
47  * unregister an existing agent.
48  *
49  * @param object_path agent to be unregistered.
50  * @param cb function to call when server replies or some error happens.
51  * @param data data to give to cb when it is called.
52  *
53  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
54  */
55 Eina_Bool
56 e_connman_manager_agent_unregister(const char *object_path, E_DBus_Method_Return_Cb cb, const void *data)
57 {
58    const char name[] = "UnregisterAgent";
59    E_Connman_Element *element;
60
61    EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, EINA_FALSE);
62
63    element = e_connman_manager_get();
64    if (!element)
65       return EINA_FALSE;
66
67    return e_connman_element_call_with_path
68              (element, name, object_path, NULL,
69              &element->_pending.agent_unregister, cb, data);
70 }
71
72 /**
73  * Get property "State" value.
74  *
75  * If this property isn't found then @c EINA_FALSE is returned.
76  * If @c EINA_FALSE is returned, then this call failed and parameter-returned
77  * values shall be considered invalid.
78  *
79  * The global connection state of a system. Possible
80  * values are "online" if at least one connection exists
81  * and "offline" if no service is connected.
82  *
83  * In certain situations the state might change to
84  * the value "connected". This can only be seen if
85  * previously no connection was present.
86  *
87  * @param state where to store the property value, must be a pointer
88  *        to string (const char **), it will not be allocated or
89  *        copied and references will be valid until element changes,
90  *        so copy it if you want to use it later.
91  *
92  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
93  */
94 Eina_Bool
95 e_connman_manager_state_get(const char **state)
96 {
97    E_Connman_Element *element;
98
99    EINA_SAFETY_ON_NULL_RETURN_VAL(state, EINA_FALSE);
100
101    element = e_connman_manager_get();
102    if (!element)
103       return EINA_FALSE;
104
105    return e_connman_element_property_get_stringshared
106              (element, e_connman_prop_state, NULL, state);
107 }
108
109 /**
110  * Get property "OfflineMode" value.
111  *
112  * If this property isn't found then @c EINA_FALSE is returned.
113  * If @c EINA_FALSE is returned, then this call failed and parameter-returned
114  * values shall be considered invalid.
115  *
116  * The offline mode indicates the global setting for switching all radios on or
117  * off. Changing offline mode to true results in powering down all devices that
118  * use radio technology. When leaving offline mode the individual policy of each
119  * technology decides to switch the radio back on or not.
120  *
121  * During offline mode, it is still possible to switch certain technologies
122  * manually back on. For example the limited usage of WiFi or Bluetooth
123  * technologies might be allowed in some situations.
124  *
125  * @param offline where to store the property value, must be a pointer
126  *        to Eina_Bool (Eina_Bool *).
127  *
128  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
129  * @see e_connman_manager_offline_mode_set()
130  */
131 Eina_Bool
132 e_connman_manager_offline_mode_get(Eina_Bool *offline)
133 {
134    E_Connman_Element *element;
135
136    EINA_SAFETY_ON_NULL_RETURN_VAL(offline, EINA_FALSE);
137
138    element = e_connman_manager_get();
139    if (!element)
140       return EINA_FALSE;
141
142    return e_connman_element_property_get_stringshared
143              (element, e_connman_prop_offline_mode, NULL, offline);
144 }
145
146 /**
147  * Call method SetProperty("OfflineMode", offline) at the given element on server.
148  *
149  * This is a server call, not local, so it may fail and in that case
150  * no property is updated locally. If the value was set the event
151  * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop.
152  *
153  * The offline mode indicates the global setting for switching all radios on or
154  * off. Changing offline mode to true results in powering down all devices that
155  * use radio technology. When leaving offline mode the individual policy of each
156  * technology decides to switch the radio back on or not.
157  *
158  * During offline mode, it is still possible to switch certain technologies
159  * manually back on. For example the limited usage of WiFi or Bluetooth
160  * technologies might be allowed in some situations.
161  *
162  * @param offline value to set.
163  * @param cb function to call when server replies or some error happens.
164  * @param data data to give to cb when it is called.
165  *
166  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
167  * @see e_connman_manager_offline_mode_get()
168  */
169 Eina_Bool
170 e_connman_manager_offline_mode_set(Eina_Bool offline, E_DBus_Method_Return_Cb cb, const void *data)
171 {
172    E_Connman_Element *element = e_connman_manager_get();
173    if (!element)
174       return EINA_FALSE;
175
176    return e_connman_element_property_set_full
177              (element, e_connman_prop_offline_mode, DBUS_TYPE_BOOLEAN,
178              &offline, cb, data);
179 }
180
181 /**
182  * Get array of profile elements.
183  *
184  * @param count return the number of elements in array.
185  * @param p_elements array with all elements, these are not referenced
186  *        and in no particular order, just set if return is @c EINA_TRUE.  The
187  *        array itself is allocated using malloc() and should be freed
188  *        after usage is done.
189  *
190  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
191  */
192 Eina_Bool
193 e_connman_manager_profiles_get(unsigned int *count, E_Connman_Element ***p_elements)
194 {
195    E_Connman_Element *element;
196
197    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
198    EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, EINA_FALSE);
199
200    element = e_connman_manager_get();
201    if (!element)
202       return EINA_FALSE;
203
204    return e_connman_element_objects_array_get_stringshared
205              (element, e_connman_prop_profiles, count, p_elements);
206 }
207
208 /**
209  * Get array of services elements.
210  *
211  * List of service object paths. The list is sorted
212  * internally to have the service with the default
213  * route always first and then the favorite services
214  * followed by scan results.
215  *
216  * This list represents the available services for the
217  * current selected profile. If the profile gets changed
218  * then this list will be updated.
219  *
220  * The same list is available via the profile object
221  * itself. It is just provided here for convenience of
222  * applications only dealing with the current active
223  * profile.
224  *
225  * @param count return the number of elements in array.
226  * @param p_elements array with all elements, these are not referenced
227  *        and in no particular order, just set if return is @c EINA_TRUE.  The
228  *        array itself is allocated using malloc() and should be freed
229  *        after usage is done.
230  *
231  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
232  */
233 Eina_Bool
234 e_connman_manager_services_get(unsigned int *count, E_Connman_Element ***p_elements)
235 {
236    E_Connman_Element *element;
237
238    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
239    EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, EINA_FALSE);
240
241    element = e_connman_manager_get();
242    if (!element)
243       return EINA_FALSE;
244
245    return e_connman_element_objects_array_get_stringshared
246              (element, e_connman_prop_services, count, p_elements);
247 }
248
249 /**
250  * Get array of technology elements.
251  *
252  * @param count return the number of elements in array.
253  * @param p_elements array with all elements, these are not referenced
254  *        and in no particular order, just set if return is @c EINA_TRUE.  The
255  *        array itself is allocated using malloc() and should be freed
256  *        after usage is done.
257  *
258  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
259  */
260 Eina_Bool
261 e_connman_manager_technologies_get(unsigned int *count, E_Connman_Element ***p_elements)
262 {
263    E_Connman_Element *element;
264
265    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
266    EINA_SAFETY_ON_NULL_RETURN_VAL(p_elements, EINA_FALSE);
267
268    element = e_connman_manager_get();
269    if (!element)
270       return EINA_FALSE;
271
272    return e_connman_element_objects_array_get_stringshared
273              (element, e_connman_prop_technologies, count, p_elements);
274 }
275
276 /**
277  * Request to trigger a scan for given technology.
278  *
279  * Call method RequestScan(type) on server in order to find new services for
280  * such technology type.
281  *
282  * The empty string for type means all technolgies.
283  *
284  * @param type technology type to scan. Empty or NULL for all technologies.
285  * @param cb function to call when server replies or some error happens.
286  * @param data data to give to cb when it is called.
287  *
288  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
289  */
290 Eina_Bool
291 e_connman_manager_request_scan(const char *type, E_DBus_Method_Return_Cb cb, const void *data)
292 {
293    const char name[] = "RequestScan";
294    E_Connman_Element *element;
295
296    if (!type)
297       type = "";
298
299    element = e_connman_manager_get();
300    if (!element)
301       return EINA_FALSE;
302
303    return e_connman_element_call_with_string
304              (element, name, type, NULL,
305              &element->_pending.request_scan, cb, data);
306 }
307
308 /**
309  * Enable specified type of technology.
310  *
311  * Call method EnableTechnology(type) on server.
312  *
313  * @param type technology type to enable.
314  * @param cb function to call when server replies or some error happens.
315  * @param data data to give to cb when it is called.
316  *
317  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
318  */
319 Eina_Bool
320 e_connman_manager_technology_enable(const char *type, E_DBus_Method_Return_Cb cb, const void *data)
321 {
322    const char name[] = "EnableTechnology";
323    E_Connman_Element *element;
324
325    EINA_SAFETY_ON_NULL_RETURN_VAL(type, EINA_FALSE);
326
327    element = e_connman_manager_get();
328    if (!element)
329       return EINA_FALSE;
330
331    return e_connman_element_call_with_string
332              (element, name, type, NULL,
333              &element->_pending.technology_enable, cb, data);
334 }
335
336 /**
337  * Disable specified type of technology.
338  *
339  * Call method DisableTechnology(type) on server.
340  *
341  * @param type technology type to disable.
342  * @param cb function to call when server replies or some error happens.
343  * @param data data to give to cb when it is called.
344  *
345  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
346  */
347 Eina_Bool
348 e_connman_manager_technology_disable(const char *type, E_DBus_Method_Return_Cb cb, const void *data)
349 {
350    const char name[] = "DisableTechnology";
351    E_Connman_Element *element;
352
353    EINA_SAFETY_ON_NULL_RETURN_VAL(type, EINA_FALSE);
354
355    element = e_connman_manager_get();
356    if (!element)
357       return EINA_FALSE;
358
359    return e_connman_element_call_with_string
360              (element, name, type, NULL,
361              &element->_pending.technology_disable, cb, data);
362 }
363
364 /**
365  * Get property "DefaultTechnology" value.
366  *
367  * If this property isn't found then @c EINA_FALSE is returned.
368  * If @c EINA_FALSE is returned, then this call failed and parameter-returned
369  * values shall be considered invalid.
370  *
371  * The current connected technology which holds the default route.
372  *
373  * @param type where to store the property value, must be a pointer
374  *        to string (const char **), it will not be allocated or
375  *        copied and references will be valid until element changes,
376  *        so copy it if you want to use it later.
377  *
378  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
379  */
380 Eina_Bool
381 e_connman_manager_technology_default_get(const char **type)
382 {
383    E_Connman_Element *element;
384
385    EINA_SAFETY_ON_NULL_RETURN_VAL(type, EINA_FALSE);
386
387    element = e_connman_manager_get();
388    if (!element)
389       return EINA_FALSE;
390
391    return e_connman_element_property_get_stringshared
392              (element, e_connman_prop_technology_default, NULL, type);
393 }
394
395 /**
396  * Remove specified profile.
397  *
398  * Call method RemoveProfile(profile) on server.
399  *
400  * It is not possible to remove the current active profile. To remove
401  * the active profile a different one must be selected via
402  * ActiveProfile property first.
403  *
404  * At minimum one profile must be available all the time.
405  *
406  * @param profile element to remove, must be of type profile.
407  * @param cb function to call when server replies or some error happens.
408  * @param data data to give to cb when it is called.
409  *
410  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
411  */
412 Eina_Bool
413 e_connman_manager_profile_remove(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data)
414 {
415    E_Connman_Element *element;
416    const char name[] = "RemoveProfile";
417
418    EINA_SAFETY_ON_NULL_RETURN_VAL(profile, EINA_FALSE);
419    EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, EINA_FALSE);
420
421    if (!e_connman_element_is_profile(profile))
422       return EINA_FALSE;
423
424    element = e_connman_manager_get();
425    if (!element)
426       return EINA_FALSE;
427
428    return e_connman_element_call_with_path
429              (element, name, profile->path, NULL,
430              &element->_pending.profile_remove, cb, data);
431 }
432
433 /**
434  * Get property "ActiveProfile" value.
435  *
436  * If this property isn't found then @c EINA_FALSE is returned.
437  * If @c EINA_FALSE is returned, then this call failed and parameter-returned
438  * values shall be considered invalid.
439  *
440  * @param element where to store the element, just changed if return is @c EINA_TRUE
441  *
442  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
443  *
444  * @see e_connman_manager_profile_active_set()
445  */
446 Eina_Bool
447 e_connman_manager_profile_active_get(E_Connman_Element **profile)
448 {
449    E_Connman_Element *element;
450    char *profile_path;
451
452    EINA_SAFETY_ON_NULL_RETURN_VAL(profile, EINA_FALSE);
453
454    element = e_connman_manager_get();
455    if (!element)
456       return EINA_FALSE;
457
458    if (!e_connman_element_property_get_stringshared
459           (element, e_connman_prop_profile_active, NULL, &profile_path))
460       return EINA_FALSE;
461
462    *profile = e_connman_element_get(profile_path);
463    return EINA_TRUE;
464 }
465
466 /**
467  * Call method SetProperty("ActiveProfile", profile) at the given
468  * element on server.
469  *
470  * This is a server call, not local, so it may fail and in that case
471  * no property is updated locally. If the value was set the event
472  * E_CONNMAN_EVENT_ELEMENT_UPDATED will be added to main loop.
473  *
474  * @param profile object to set.
475  * @param cb function to call when server replies or some error happens.
476  * @param data data to give to cb when it is called.
477  *
478  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
479  * @see e_connman_manager_profile_active_get()
480  */
481 Eina_Bool
482 e_connman_manager_profile_active_set(const E_Connman_Element *profile, E_DBus_Method_Return_Cb cb, const void *data)
483 {
484    E_Connman_Element *element;
485
486    EINA_SAFETY_ON_NULL_RETURN_VAL(profile, EINA_FALSE);
487    EINA_SAFETY_ON_NULL_RETURN_VAL(profile->path, EINA_FALSE);
488
489    if (!e_connman_element_is_profile(profile))
490       return EINA_FALSE;
491
492    element = e_connman_manager_get();
493    if (!element)
494       return EINA_FALSE;
495
496    return e_connman_element_property_set_full
497              (element, e_connman_prop_profile_active, DBUS_TYPE_OBJECT_PATH,
498              profile->path, cb, data);
499 }
500
501 /**
502  * Get array of strings representing the available technologies.
503  *
504  * @param count return the number of elements in array.
505  * @param p_strings array with pointers to internal strings. These
506  *        strings are not copied in any way, and they are granted to
507  *        be eina_stringshare instances, so one can use
508  *        eina_stringshare_ref() if he wants to save memory and cpu to
509  *        get an extra reference. The array itself is allocated using
510  *        malloc() and should be freed after usage is done. This
511  *        pointer is just set if return is @c EINA_TRUE.
512  *
513  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
514  */
515 Eina_Bool
516 e_connman_manager_technologies_available_get(unsigned int *count, const char ***p_strings)
517 {
518    E_Connman_Element *element;
519
520    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
521    EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, EINA_FALSE);
522
523    element = e_connman_manager_get();
524    if (!element)
525       return EINA_FALSE;
526
527    return e_connman_element_strings_array_get_stringshared
528              (element, e_connman_prop_technologies_available, count, p_strings);
529 }
530
531 /**
532  * Get array of strings representing the enabled technologies.
533  *
534  * @param count return the number of elements in array.
535  * @param p_strings array with pointers to internal strings. These
536  *        strings are not copied in any way, and they are granted to
537  *        be eina_stringshare instances, so one can use
538  *        eina_stringshare_ref() if he wants to save memory and cpu to
539  *        get an extra reference. The array itself is allocated using
540  *        malloc() and should be freed after usage is done. This
541  *        pointer is just set if return is @c EINA_TRUE.
542  *
543  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
544  */
545 Eina_Bool
546 e_connman_manager_technologies_enabled_get(unsigned int *count, const char ***p_strings)
547 {
548    E_Connman_Element *element;
549
550    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
551    EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, EINA_FALSE);
552
553    element = e_connman_manager_get();
554    if (!element)
555       return EINA_FALSE;
556
557    return e_connman_element_strings_array_get_stringshared
558              (element, e_connman_prop_technologies_enabled, count, p_strings);
559 }
560
561 /**
562  * Get array of strings representing the connected technologies.
563  *
564  * @param count return the number of elements in array.
565  * @param p_strings array with pointers to internal strings. These
566  *        strings are not copied in any way, and they are granted to
567  *        be eina_stringshare instances, so one can use
568  *        eina_stringshare_ref() if he wants to save memory and cpu to
569  *        get an extra reference. The array itself is allocated using
570  *        malloc() and should be freed after usage is done. This
571  *        pointer is just set if return is @c EINA_TRUE.
572  *
573  * @return @c EINA_TRUE on success, @c EINA_FALSE otherwise.
574  */
575 Eina_Bool
576 e_connman_manager_technologies_connected_get(unsigned int *count, const char ***p_strings)
577 {
578    E_Connman_Element *element;
579
580    EINA_SAFETY_ON_NULL_RETURN_VAL(count, EINA_FALSE);
581    EINA_SAFETY_ON_NULL_RETURN_VAL(p_strings, EINA_FALSE);
582
583    element = e_connman_manager_get();
584    if (!element)
585       return EINA_FALSE;
586
587    return e_connman_element_strings_array_get_stringshared
588              (element, e_connman_prop_technologies_connected, count, p_strings);
589 }
590