2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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://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.
19 #include <app_service.h>
22 #include "mf-s-beam.h"
26 #define S_BEAM_SEPERATOR "|"
36 static mf_sbeam_s *g_sbeam_data = NULL;
38 bool __mf_sbeam_is_on()
43 if (vconf_get_bool(VCONFKEY_NFC_SBEAM, &value) == 0) {
44 if (value == VCONFKEY_NFC_SBEAM_ON)
47 mf_debug("sbeam is off");
49 mf_error("vconf_get_int()");
56 __mf_sbeam_target_discovered_cb(nfc_discovered_type_e type, nfc_p2p_target_h target, void *user_data)
59 MF_CHECK(g_sbeam_data);
60 MF_CHECK(g_sbeam_data->enabled);
62 if (type == NFC_DISCOVERED_TYPE_ATTACHED && g_sbeam_data->callback)
64 mf_debug("NFC_DISCOVERED_TYPE_ATTACHED");
65 g_sbeam_data->callback(g_sbeam_data->user_data);
67 else if (type == NFC_DISCOVERED_TYPE_DETACHED)
69 mf_debug("NFC_DISCOVERED_TYPE_DETACHED");
75 __mf_sbeam_nfc_mgr_init()
77 MF_CHECK_FALSE(g_sbeam_data);
80 if (!g_sbeam_data->initialized) {
81 ret = nfc_manager_initialize(NULL, NULL);
82 if (ret == NFC_ERROR_NONE) {
83 mf_debug("NFC initializing is success. activating");
84 g_sbeam_data->initialized = true;
86 mf_error("nfc_manager_initialize().. [0x%x]");
91 ret = nfc_manager_set_p2p_target_discovered_cb(__mf_sbeam_target_discovered_cb, g_sbeam_data);
92 if (ret != NFC_ERROR_NONE) {
93 mf_debug("nfc_manager_set_p2p_target_discovered_cb()..[0x%x]", ret);
101 __mf_sbeam_nfc_mgr_deinit()
103 MF_CHECK_FALSE(g_sbeam_data);
106 if (g_sbeam_data->initialized) {
107 ret = nfc_manager_deinitialize();
108 if (ret != NFC_ERROR_NONE) {
109 mf_error("nfc_manager_deinitialize().. [0x%x]", ret);
112 g_sbeam_data->initialized = false;
119 __mf_sbeam_state_changed_cb(keynode_t *node, void *user_data)
122 mf_sbeam_s *sbeam_data = user_data;
123 MF_CHECK(sbeam_data);
125 if (__mf_sbeam_is_on() && sbeam_data->enabled)
126 __mf_sbeam_nfc_mgr_init();
128 __mf_sbeam_nfc_mgr_deinit();
135 g_sbeam_data = calloc(1, sizeof(mf_sbeam_s));
136 MF_CHECK_VAL(g_sbeam_data, false);
138 if (vconf_notify_key_changed(VCONFKEY_NFC_SBEAM, __mf_sbeam_state_changed_cb, g_sbeam_data) < 0) {
139 mf_error("fail to vconf_notify_key_changed()");
144 if (__mf_sbeam_is_on())
155 SAFE_FREE_CHAR(g_sbeam_data);
162 MF_CHECK_FALSE(g_sbeam_data);
164 g_sbeam_data->enabled = true;
166 return __mf_sbeam_nfc_mgr_init();
168 bool mf_sbeam_disable()
171 MF_CHECK_FALSE(g_sbeam_data);
173 g_sbeam_data->enabled = false;
175 return __mf_sbeam_nfc_mgr_deinit();
178 bool mf_sbeam_set_callback(Mf_Sbeam_Cb callback, void *user_data)
181 MF_CHECK_FALSE(g_sbeam_data);
183 g_sbeam_data->callback = callback;
184 g_sbeam_data->user_data = user_data;
189 bool mf_sbeam_share_files(Evas_Object *win, Eina_List *file_list)
194 service_h svc_handle;
195 ret = service_create(&svc_handle);
196 if (ret != SERVICE_ERROR_NONE) {
197 mf_error("service_create().. [0x%x]", ret);
201 ret = service_set_operation(svc_handle, "http://tizen.org/appcontrol/operation/nfc_sbeam_send");
202 if (ret != SERVICE_ERROR_NONE) {
203 mf_error("service_set_operation().. [0x%x]", ret);
207 ret = service_set_mime(svc_handle, "text/DirectShareFile");
208 if (ret != SERVICE_ERROR_NONE) {
209 mf_error("service_set_mime().. [0x%x]", ret);
212 ret = service_set_window(svc_handle, elm_win_xwindow_get(win));
213 if (ret != SERVICE_ERROR_NONE) {
214 mf_error("service_set_window().. [0x%x]", ret);
220 Eina_List *current = file_list;
222 GString *pNode = NULL;
225 EINA_LIST_FOREACH(current, l, pNode) {
228 uri = g_strconcat(pNode->str, NULL);
231 uri = g_strconcat(uri, S_BEAM_SEPERATOR, pNode->str, NULL);
238 mf_debug("files = [%s]", uri);
239 ret = service_set_uri(svc_handle, uri);
240 if (ret != SERVICE_ERROR_NONE) {
241 mf_error("service_set_uri().. [0x%x]", ret);
247 ret = service_send_launch_request(svc_handle, NULL, NULL);
248 if (ret != SERVICE_ERROR_NONE) {
249 mf_error("service_send_launch_request().. [0x%x]", ret);
253 service_destroy(svc_handle);
258 service_destroy(svc_handle);