9cdf65f810643a24e4ba6c61e2e0da5beb8a500b
[platform/core/connectivity/nfc-manager-neard.git] / daemon / net_nfc_server_system_handler.c
1 /*
2  * Copyright (c) 2012, 2013 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  *     http://floralicense.org/license/
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_gdbus.h"
18 #include "net_nfc_server_common.h"
19 #include "net_nfc_server_context.h"
20 #include "net_nfc_server_system_handler.h"
21
22
23 static NetNfcGDbusPopup *popup_skeleton = NULL;
24
25 static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
26                 GDBusMethodInvocation *invocation,
27                 gint state,
28                 gint focus_state,
29                 GVariant *smack_privilege,
30                 gpointer user_data)
31 {
32         bool ret;
33         NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation));
34
35         /* check privilege and update client context */
36         ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege,
37                                 "nfc-manager", "w");
38         if (false == ret)
39         {
40                 NFC_ERR("permission denied, and finished request");
41
42                 return FALSE;
43         }
44
45         net_nfc_server_gdbus_set_launch_state(g_dbus_method_invocation_get_sender(invocation),
46                         state, focus_state);
47
48         net_nfc_gdbus_popup_complete_set(popup_manager, invocation, NET_NFC_OK);
49
50         return TRUE;
51 }
52
53 static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
54                 GDBusMethodInvocation *invocation, GVariant *smack_privilege, gpointer user_data)
55 {
56         bool ret;
57         gboolean state;
58
59         NFC_INFO(">>> REQUEST from [%s]", g_dbus_method_invocation_get_sender(invocation));
60
61         /* check privilege and update client context */
62         ret = net_nfc_server_gdbus_check_privilege(invocation, smack_privilege,
63                                 "nfc-manager", "r");
64         if (false == ret)
65         {
66                 NFC_ERR("permission denied, and finished request");
67
68                 return FALSE;
69         }
70
71         state = net_nfc_server_gdbus_get_launch_state(
72                         g_dbus_method_invocation_get_sender(invocation));
73
74         net_nfc_gdbus_popup_complete_get(popup_manager, invocation, NET_NFC_OK, state);
75
76         return TRUE;
77 }
78
79 gboolean net_nfc_server_system_handler_init(GDBusConnection *connection)
80 {
81         gboolean result;
82         GError *error = NULL;
83
84         if (popup_skeleton)
85                 g_object_unref(popup_skeleton);
86
87         popup_skeleton = net_nfc_gdbus_popup_skeleton_new();
88         if (NULL == popup_skeleton)
89         {
90                 NFC_ERR("Failed to allocate popup skeleton");
91
92                 return FALSE;
93         }
94
95         g_signal_connect(popup_skeleton, "handle-set", G_CALLBACK(popup_handle_set), NULL);
96
97         g_signal_connect(popup_skeleton, "handle-get", G_CALLBACK(popup_handle_get), NULL);
98
99         result = g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(popup_skeleton),
100                         connection, "/org/tizen/NetNfcService/Popup", &error);
101         if (FALSE == result)
102         {
103                 NFC_ERR("Can not skeleton_export %s", error->message);
104
105                 g_error_free(error);
106
107                 net_nfc_server_system_handler_deinit();
108         }
109
110         return result;
111 }
112
113 void net_nfc_server_system_handler_deinit(void)
114 {
115         if (popup_skeleton)
116         {
117                 g_object_unref(popup_skeleton);
118                 popup_skeleton = NULL;
119         }
120 }