2 * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Flora License, Version 1.1 (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://floralicense.org/license/
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.
17 #include "net_nfc_typedef_internal.h"
18 #include "net_nfc_debug_internal.h"
19 #include "net_nfc_util_ndef_message.h"
20 #include "net_nfc_gdbus.h"
21 #include "net_nfc_client.h"
22 #include "net_nfc_client_util_internal.h"
23 #include "net_nfc_client_manager.h"
24 #include "net_nfc_client_system_handler.h"
27 #ifndef NET_NFC_EXPORT_API
28 #define NET_NFC_EXPORT_API __attribute__((visibility("default")))
33 static NetNfcGDbusPopup *popup_proxy = NULL;
34 static int popup_state = 0;
36 static void popup_set_active_callback(GObject *source_object,
40 static void popup_set_active_callback(GObject *source_object,
44 NetNfcCallback *func_data = (NetNfcCallback *)user_data;
45 net_nfc_error_e result;
48 g_assert(user_data != NULL);
50 if (net_nfc_gdbus_popup_call_set_finish(
51 NET_NFC_GDBUS_POPUP(source_object),
55 DEBUG_ERR_MSG("Can not finish popup_set_active: %s",
57 result = NET_NFC_IPC_FAIL;
62 if (func_data->callback != NULL) {
63 net_nfc_client_popup_set_state_callback callback =
64 (net_nfc_client_popup_set_state_callback)func_data->callback;
66 callback(result, func_data->user_data);
73 net_nfc_error_e net_nfc_client_sys_handler_set_state(int state,
74 net_nfc_client_popup_set_state_callback callback,
77 NetNfcCallback *func_data;
79 if (popup_proxy == NULL) {
80 if (net_nfc_client_sys_handler_init() != NET_NFC_OK) {
81 DEBUG_ERR_MSG("popup_proxy fail");
82 return NET_NFC_NOT_INITIALIZED;
86 /* prevent executing daemon when nfc is off */
87 if (net_nfc_client_manager_is_activated() == false)
88 return NET_NFC_NOT_ACTIVATED;
90 func_data = g_try_new0(NetNfcCallback, 1);
91 if (func_data == NULL)
92 return NET_NFC_ALLOC_FAIL;
94 func_data->callback = (gpointer)callback;
95 func_data->user_data = user_data;
97 net_nfc_gdbus_popup_call_set(popup_proxy,
101 popup_set_active_callback,
108 net_nfc_error_e net_nfc_client_sys_handler_set_state_sync(int state)
110 net_nfc_error_e result = NET_NFC_OK;
111 GError *error = NULL;
113 if (popup_proxy == NULL) {
114 if (net_nfc_client_sys_handler_init() != NET_NFC_OK) {
115 DEBUG_ERR_MSG("popup_proxy fail");
116 return NET_NFC_NOT_INITIALIZED;
120 /* prevent executing daemon when nfc is off */
121 if (net_nfc_client_manager_is_activated() == false)
122 return NET_NFC_NOT_ACTIVATED;
124 if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
130 DEBUG_ERR_MSG("can not call SetActive: %s",
132 result = NET_NFC_IPC_FAIL;
141 net_nfc_error_e net_nfc_client_sys_handler_set_state_force(int state,
142 net_nfc_client_popup_set_state_callback callback,
145 NetNfcCallback *func_data;
147 if (popup_proxy == NULL) {
148 if (net_nfc_client_sys_handler_init() != NET_NFC_OK) {
149 DEBUG_ERR_MSG("popup_proxy fail");
150 return NET_NFC_NOT_INITIALIZED;
154 /* prevent executing daemon when nfc is off */
155 if (net_nfc_client_manager_is_activated() == false)
156 return NET_NFC_NOT_ACTIVATED;
158 func_data = g_try_new0(NetNfcCallback, 1);
159 if (func_data == NULL)
160 return NET_NFC_ALLOC_FAIL;
162 func_data->callback = (gpointer)callback;
163 func_data->user_data = user_data;
165 net_nfc_gdbus_popup_call_set(popup_proxy,
169 popup_set_active_callback,
176 net_nfc_error_e net_nfc_client_sys_handler_set_state_force_sync(int state)
178 net_nfc_error_e result;
179 GError *error = NULL;
181 if (popup_proxy == NULL) {
182 if (net_nfc_client_sys_handler_init() != NET_NFC_OK) {
183 DEBUG_ERR_MSG("popup_proxy fail");
184 return NET_NFC_NOT_INITIALIZED;
188 /* prevent executing daemon when nfc is off */
189 if (net_nfc_client_manager_is_activated() == false)
190 return NET_NFC_NOT_ACTIVATED;
192 if (net_nfc_gdbus_popup_call_set_sync(popup_proxy,
198 DEBUG_ERR_MSG("can not call SetActive: %s",
200 result = NET_NFC_IPC_FAIL;
209 net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state(
212 popup_state = enable;
214 return net_nfc_client_sys_handler_set_state_sync(enable);
218 net_nfc_error_e net_nfc_client_sys_handler_set_launch_popup_state_force(
221 popup_state = enable;
223 return net_nfc_client_sys_handler_set_state_force_sync(enable);
227 net_nfc_error_e net_nfc_client_sys_handler_get_launch_popup_state(
230 net_nfc_error_e result = NET_NFC_OK;
231 gint out_state = NET_NFC_LAUNCH_APP_SELECT;
232 GError *error = NULL;
235 return NET_NFC_NULL_PARAMETER;
237 *state = NET_NFC_LAUNCH_APP_SELECT;
239 if (popup_proxy == NULL) {
240 if (net_nfc_client_sys_handler_init() != NET_NFC_OK) {
241 DEBUG_ERR_MSG("popup_proxy fail");
242 return NET_NFC_NOT_INITIALIZED;
246 /* prevent executing daemon when nfc is off */
247 if (net_nfc_client_manager_is_activated() == false)
248 return NET_NFC_NOT_ACTIVATED;
250 if (net_nfc_gdbus_popup_call_get_sync(popup_proxy,
258 DEBUG_ERR_MSG("net_nfc_gdbus_popup_call_get_sync failed: %s",
260 result = NET_NFC_IPC_FAIL;
268 net_nfc_error_e net_nfc_client_sys_handler_init(void)
270 GError *error = NULL;
273 DEBUG_CLIENT_MSG("Already initialized");
278 popup_proxy = net_nfc_gdbus_popup_proxy_new_for_bus_sync(
280 G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
281 "org.tizen.NetNfcService",
282 "/org/tizen/NetNfcService/Popup",
285 if (popup_proxy == NULL) {
286 DEBUG_ERR_MSG("Can not create proxy : %s", error->message);
289 return NET_NFC_OPERATION_FAIL;
295 void net_nfc_client_sys_handler_deinit(void)
298 g_object_unref(popup_proxy);