2 * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0
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_internal.h"
20 #include "net_nfc_util_ndef_message.h"
21 #include "net_nfc_util_gdbus_internal.h"
22 #include "net_nfc_gdbus.h"
23 #include "net_nfc_data.h"
24 #include "net_nfc_client.h"
25 #include "net_nfc_client_manager.h"
26 #include "net_nfc_client_handover.h"
27 #include "net_nfc_neard.h"
30 static NetNfcGDbusHandover *handover_proxy = NULL;
32 API net_nfc_error_e net_nfc_client_handover_free_alternative_carrier_data(
33 net_nfc_connection_handover_info_s *info)
35 RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER);
37 if (info->data.buffer != NULL)
38 _net_nfc_util_free_mem(info->data.buffer);
40 _net_nfc_util_free_mem(info);
46 API net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_type(
47 net_nfc_connection_handover_info_s *info,
48 net_nfc_conn_handover_carrier_type_e *type)
50 RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER);
51 RETV_IF(NULL == type, NET_NFC_NULL_PARAMETER);
58 API net_nfc_error_e net_nfc_client_handover_get_alternative_carrier_data(
59 net_nfc_connection_handover_info_s *info, data_s **data)
61 RETV_IF(NULL == info, NET_NFC_NULL_PARAMETER);
62 RETV_IF(NULL == data, NET_NFC_NULL_PARAMETER);
64 return net_nfc_create_data(data, info->data.buffer, info->data.length);
68 API net_nfc_error_e net_nfc_client_p2p_connection_handover(
69 net_nfc_target_handle_s *handle,
70 net_nfc_conn_handover_carrier_type_e arg_type,
71 net_nfc_p2p_connection_handover_completed_cb callback,
74 /* prevent executing daemon when nfc is off */
75 RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE);
77 return net_nfc_neard_p2p_connection_handover(handle, arg_type, callback, cb_data);
81 API net_nfc_error_e net_nfc_client_p2p_connection_handover_sync(
82 net_nfc_target_handle_s *handle,
83 net_nfc_conn_handover_carrier_type_e arg_type,
84 net_nfc_conn_handover_carrier_type_e *out_carrier,
89 GVariant *out_data = NULL;
90 net_nfc_error_e out_result = NET_NFC_OK;
91 net_nfc_conn_handover_carrier_type_e out_type = NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN;
93 RETV_IF(NULL == handover_proxy, NET_NFC_NOT_INITIALIZED);
95 /* prevent executing daemon when nfc is off */
96 RETV_IF(net_nfc_client_manager_is_activated() == false, NET_NFC_INVALID_STATE);
98 ret = net_nfc_gdbus_handover_call_request_sync(handover_proxy,
99 GPOINTER_TO_UINT(handle),
101 net_nfc_client_gdbus_get_privilege(),
102 (gint32 *)&out_result,
111 *out_carrier = out_type;
114 *out_ac_data = net_nfc_util_gdbus_variant_to_data(out_data);
118 NFC_ERR("handover (sync call) failed: %s",error->message);
121 out_result = NET_NFC_IPC_FAIL;
128 net_nfc_error_e net_nfc_client_handover_init(void)
130 GError *error = NULL;
134 NFC_WARN("Already initialized");
138 handover_proxy = net_nfc_gdbus_handover_proxy_new_for_bus_sync(
140 G_DBUS_PROXY_FLAGS_NONE,
141 "org.tizen.NetNfcService",
142 "/org/tizen/NetNfcService/Handover",
146 if (NULL == handover_proxy)
148 NFC_ERR("Can not create proxy : %s", error->message);
150 return NET_NFC_UNKNOWN_ERROR;
157 void net_nfc_client_handover_deinit(void)
161 g_object_unref(handover_proxy);
162 handover_proxy = NULL;