Remove unnecessary setting
[platform/core/connectivity/nfc-manager-neard.git] / daemon / net_nfc_server_handover.c
1 /*
2  * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *                               http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
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"
23
24 static NetNfcGDbusHandover *handover_skeleton = NULL;
25
26 static void handover_request_thread_func(gpointer user_data)
27 {
28         net_nfc_error_e result;
29         HandoverRequestData *handover_data = user_data;
30
31         g_assert(handover_data != NULL);
32         g_assert(handover_data->handoverobj != NULL);
33         g_assert(handover_data->invocation != NULL);
34
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)
38         {
39                 net_nfc_gdbus_handover_complete_request(
40                                 handover_data->handoverobj,
41                                 handover_data->invocation,
42                                 result,
43                                 NET_NFC_CONN_HANDOVER_CARRIER_UNKNOWN,
44                                 net_nfc_util_gdbus_buffer_to_variant(NULL, 0));
45
46                 g_object_unref(handover_data->invocation);
47                 g_object_unref(handover_data->handoverobj);
48
49                 g_free(handover_data);
50         }
51 }
52
53 static gboolean handover_handle_request(NetNfcGDbusHandover *hdover,
54                 GDBusMethodInvocation *invocation,
55                 guint32 arg_handle,
56                 gint32 arg_type,
57                 GVariant *smack_privilege,
58                 gpointer user_data)
59 {
60         gboolean result;
61         HandoverRequestData *data;
62
63         NFC_INFO(">>> REQUEST from [%s]",
64                         g_dbus_method_invocation_get_sender(invocation));
65
66         /* check privilege and update client context */
67         if (net_nfc_server_gdbus_check_privilege(invocation, smack_privilege,
68                                 "nfc-manager::p2p", "rw") == false)
69         {
70                 NFC_ERR("permission denied, and finished request");
71
72                 return FALSE;
73         }
74
75         data = g_try_new0(HandoverRequestData,1);
76         if(NULL == data)
77         {
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");
82                 return FALSE;
83         }
84
85         data->handoverobj = g_object_ref(hdover);
86         data->invocation = g_object_ref(invocation);
87         data->handle = arg_handle;
88         data->type = arg_type;
89
90         result = net_nfc_server_controller_async_queue_push(
91                         handover_request_thread_func, data);
92         if (FALSE == result)
93         {
94                 g_dbus_method_invocation_return_dbus_error(invocation,
95                                 "org.tizen.NetNfcService.Handover.ThreadError",
96                                 "can not push to controller thread");
97
98                 g_object_unref(data->invocation);
99                 g_object_unref(data->handoverobj);
100
101                 g_free(data);
102         }
103
104         return result;
105 }
106
107 gboolean net_nfc_server_handover_init(GDBusConnection *connection)
108 {
109         gboolean ret;
110         GError *error = NULL;
111
112         if (handover_skeleton)
113                 g_object_unref(handover_skeleton);
114
115         handover_skeleton = net_nfc_gdbus_handover_skeleton_new();
116
117         g_signal_connect(handover_skeleton, "handle-request",
118                         G_CALLBACK(handover_handle_request), NULL);
119
120         ret = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(handover_skeleton),
121                                 connection, "/org/tizen/NetNfcService/Handover", &error);
122
123         if (FALSE == ret)
124         {
125                 g_error_free(error);
126
127                 g_object_unref(handover_skeleton);
128                 handover_skeleton = NULL;
129
130                 return FALSE;
131         }
132
133         return TRUE;
134 }
135
136 void net_nfc_server_handover_deinit(void)
137 {
138         if (handover_skeleton)
139         {
140                 g_object_unref(handover_skeleton);
141                 handover_skeleton = NULL;
142         }
143 }