e_dbus/bluez: add start/stop discovery methods
[framework/uifw/edbus.git] / src / lib / bluez / e_bluez_adapter.c
1 #include "e_bluez_private.h"
2
3 /**
4  * Register new agent for handling user requests.
5  *
6  * Call method RegisterAgent(object) on server in order to
7  * register new agent for handling user requests.
8  *
9  * @param element adapter's element
10  * @param object_path object to be registered.
11  * @param capability input/output agent capabilities
12  * @param cb function to call when server replies or some error happens.
13  * @param data data to give to cb when it is called.
14  *
15  * @return 1 on success, 0 otherwise.
16  */
17 bool
18 e_bluez_adapter_agent_register(E_Bluez_Element *element, const char *object_path, const char *capability, E_DBus_Method_Return_Cb cb, const void *data)
19 {
20    const char name[] = "RegisterAgent";
21
22    EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0);
23
24    return e_bluez_element_call_with_path_and_string
25      (element, name, object_path, capability, NULL,
26       &element->_pending.agent_register, cb, data);
27 }
28
29 /**
30  * Unregister an existing agent.
31  *
32  * Call method UnregisterAgent(object) on server in order to
33  * unregister an existing agent.
34  *
35  * @param element adapter's element
36  * @param object_path agent to be unregistered.
37  * @param cb function to call when server replies or some error happens.
38  * @param data data to give to cb when it is called.
39  *
40  * @return 1 on success, 0 otherwise.
41  */
42 bool
43 e_bluez_adapter_agent_unregister(E_Bluez_Element *element, const char *object_path, E_DBus_Method_Return_Cb cb, const void *data)
44 {
45    const char name[] = "UnregisterAgent";
46
47    EINA_SAFETY_ON_NULL_RETURN_VAL(object_path, 0);
48
49    return e_bluez_element_call_with_path
50      (element, name, object_path, NULL,
51       &element->_pending.agent_unregister, cb, data);
52 }
53
54 /**
55  * Get property "Address" value.
56  *
57  * If this property isn't found then 0 is returned.
58  * If zero is returned, then this call failed and parameter-returned
59  * values shall be considered invalid.
60  *
61  * @param address where to store the property value, must be a pointer
62  *        to string (const char **), it will not be allocated or
63  *        copied and references will be valid until element changes,
64  *        so copy it if you want to use it later.
65  *
66  * @return 1 on success, 0 otherwise.
67  */
68 bool
69 e_bluez_adapter_address_get(E_Bluez_Element *element, const char **address)
70 {
71    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
72    EINA_SAFETY_ON_NULL_RETURN_VAL(address, 0);
73
74    return e_bluez_element_property_get_stringshared
75      (element, e_bluez_prop_address, NULL, address);
76 }
77
78 /**
79  * Get property "Powered" value.
80  *
81  * If this property isn't found then 0 is returned.
82  * If zero is returned, then this call failed and parameter-returned
83  * values shall be considered invalid.
84  *
85  * @param offline where to store the property value, must be a pointer
86  *        to booleans (bool *).
87  *
88  * @return 1 on success, 0 otherwise.
89  * @see e_connman_manager_offline_mode_set()
90  */
91 bool
92 e_bluez_adapter_powered_get(E_Bluez_Element *element, bool *powered)
93 {
94    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
95    EINA_SAFETY_ON_NULL_RETURN_VAL(powered, 0);
96
97    return e_bluez_element_property_get_stringshared
98      (element, e_bluez_prop_powered, NULL, powered);
99 }
100
101 /**
102  * Call method SetProperty("Powered", powered) at the given element on server.
103  *
104  *
105  * @param powered value to set.
106  * @param cb function to call when server replies or some error happens.
107  * @param data data to give to cb when it is called.
108  *
109  * @return 1 on success, 0 otherwise.
110  */
111 bool
112 e_bluez_adapter_powered_set(E_Bluez_Element *element, bool powered, E_DBus_Method_Return_Cb cb, const void *data)
113 {
114    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
115    return e_bluez_element_property_set_full
116      (element, e_bluez_prop_powered, DBUS_TYPE_BOOLEAN,
117       &powered, cb, data);
118 }
119
120 /**
121  * Start Discovery of Bluetooth Devices
122  *
123  * call StartDiscovery()
124  *
125  * @param element the adapter's element.
126  * @param cb function to call when server replies or some error happens.
127  * @param data data to give to cb when it is called.
128  *
129  * @return 1 on success, 0 otherwise.
130  */
131 bool
132 e_bluez_adapter_start_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data)
133 {
134    const char name[] = "StartDiscovery";
135
136    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
137
138    return e_bluez_element_call_full(element, name, NULL,
139                    &element->_pending.start_discovery, cb, data);
140 }
141
142 /**
143  * Stop Discovery of Bluetooth Devices
144  *
145  * call StopDiscovery()
146  *
147  * @param element the adapter's element.
148  * @param cb function to call when server replies or some error happens.
149  * @param data data to give to cb when it is called.
150  *
151  * @return 1 on success, 0 otherwise.
152  */
153 bool
154 e_bluez_adapter_stop_discovery(E_Bluez_Element *element, E_DBus_Method_Return_Cb cb, const void *data)
155 {
156    const char name[] = "StopDiscovery";
157
158    EINA_SAFETY_ON_NULL_RETURN_VAL(element, 0);
159
160    return e_bluez_element_call_full(element, name, NULL,
161                    &element->_pending.stop_discovery, cb, data);
162 }