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.
16 #include "net_nfc_debug_internal.h"
17 #include "net_nfc_util_gdbus_internal.h"
18 #include "net_nfc_server_controller.h"
19 #include "net_nfc_server_common.h"
20 #include "net_nfc_server_context.h"
21 #include "net_nfc_server_handover.h"
22 #include "net_nfc_server_process_handover.h"
24 static NetNfcGDbusHandover *handover_skeleton = NULL;
26 static void handover_request_thread_func(gpointer user_data)
28 net_nfc_error_e result;
29 HandoverRequestData *handover_data = user_data;
31 g_assert(handover_data != NULL);
32 g_assert(handover_data->handoverobj != NULL);
33 g_assert(handover_data->invocation != NULL);
35 result = net_nfc_server_handover_default_client_start(
36 GUINT_TO_POINTER(handover_data->handle), (void *)handover_data);
37 if (result != NET_NFC_OK)
39 net_nfc_gdbus_handover_complete_request(
40 handover_data->handoverobj,
41 handover_data->invocation,
43 NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN,
44 net_nfc_util_gdbus_buffer_to_variant(NULL, 0));
46 g_object_unref(handover_data->invocation);
47 g_object_unref(handover_data->handoverobj);
49 g_free(handover_data);
53 static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
54 GDBusMethodInvocation *invocation,
57 GVariant *smack_privilege,
61 HandoverRequestData *data;
63 NFC_INFO(">>> REQUEST from [%s]",
64 g_dbus_method_invocation_get_sender(invocation));
66 /* check privilege and update client context */
67 if (net_nfc_server_gdbus_check_privilege(invocation, smack_privilege,
68 "nfc-manager::p2p", "rw") == false)
70 NFC_ERR("permission denied, and finished request");
75 data = g_try_new0(HandoverRequestData,1);
78 NFC_ERR("Memory allocation failed");
79 g_dbus_method_invocation_return_dbus_error(invocation,
80 "org.tizen.NetNfcService.AllocationError",
81 "Can not allocate memory");
85 data->handoverobj = g_object_ref(hdover);
86 data->invocation = g_object_ref(invocation);
87 data->handle = arg_handle;
88 data->type = arg_type;
90 result = net_nfc_server_controller_async_queue_push(
91 handover_request_thread_func, data);
94 g_dbus_method_invocation_return_dbus_error(invocation,
95 "org.tizen.NetNfcService.Handover.ThreadError",
96 "can not push to controller thread");
98 g_object_unref(data->invocation);
99 g_object_unref(data->handoverobj);
107 gboolean net_nfc_server_handover_init(GDBusConnection *connection)
110 GError *error = NULL;
112 if (handover_skeleton)
113 g_object_unref(handover_skeleton);
115 handover_skeleton = net_nfc_gdbus_handover_skeleton_new();
117 g_signal_connect(handover_skeleton, "handle-request",
118 G_CALLBACK(handover_handle_request), NULL);
120 ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(handover_skeleton),
121 connection, "/org/tizen/NetNfcService/Handover", &error);
127 g_object_unref(handover_skeleton);
128 handover_skeleton = NULL;
136 void net_nfc_server_handover_deinit(void)
138 if (handover_skeleton)
140 g_object_unref(handover_skeleton);
141 handover_skeleton = NULL;