revise LOG macros
[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                 int state,
28                 gint focus_state,
29                 GVariant *smack_privilege,
30                 gpointer user_data);
31
32 static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
33                 GDBusMethodInvocation *invocation,
34                 GVariant *smack_privilege,
35                 gpointer user_data);
36
37 static gboolean popup_handle_set(NetNfcGDbusPopup *popup_manager,
38                 GDBusMethodInvocation *invocation,
39                 gint state,
40                 gint focus_state,
41                 GVariant *smack_privilege,
42                 gpointer user_data)
43 {
44         NFC_INFO(">>> REQUEST from [%s]",
45                         g_dbus_method_invocation_get_sender(invocation));
46
47         /* check privilege and update client context */
48         if (net_nfc_server_gdbus_check_privilege(invocation,
49                                 smack_privilege,
50                                 "nfc-manager",
51                                 "w") == false) {
52                 NFC_ERR("permission denied, and finished request");
53
54                 return FALSE;
55         }
56
57         net_nfc_server_gdbus_set_launch_state(
58                         g_dbus_method_invocation_get_sender(invocation),
59                         state, focus_state);
60
61         net_nfc_gdbus_popup_complete_set(popup_manager, invocation, NET_NFC_OK);
62
63         return TRUE;
64 }
65
66 static gboolean popup_handle_get(NetNfcGDbusPopup *popup_manager,
67                 GDBusMethodInvocation *invocation,
68                 GVariant *smack_privilege,
69                 gpointer user_data)
70 {
71         gboolean state;
72
73         NFC_INFO(">>> REQUEST from [%s]",
74                         g_dbus_method_invocation_get_sender(invocation));
75
76         /* check privilege and update client context */
77         if (net_nfc_server_gdbus_check_privilege(invocation,
78                                 smack_privilege,
79                                 "nfc-manager",
80                                 "r") == false) {
81                 NFC_ERR("permission denied, and finished request");
82
83                 return FALSE;
84         }
85
86         state = net_nfc_server_gdbus_get_launch_state(
87                         g_dbus_method_invocation_get_sender(invocation));
88
89         net_nfc_gdbus_popup_complete_get(popup_manager, invocation,
90                         NET_NFC_OK, state);
91
92         return TRUE;
93 }
94
95 gboolean net_nfc_server_system_handler_init(GDBusConnection *connection)
96 {
97         GError *error = NULL;
98         gboolean result;
99
100         if (popup_skeleton)
101                 g_object_unref(popup_skeleton);
102
103         popup_skeleton = net_nfc_gdbus_popup_skeleton_new();
104         if (popup_skeleton == NULL)
105         {
106                 NFC_ERR("Failed to allocate popup skeleton");
107
108                 return FALSE;
109         }
110
111         g_signal_connect(popup_skeleton,
112                         "handle-set",
113                         G_CALLBACK(popup_handle_set),
114                         NULL);
115
116         g_signal_connect(popup_skeleton,
117                         "handle-get",
118                         G_CALLBACK(popup_handle_get),
119                         NULL);
120
121         result = g_dbus_interface_skeleton_export(
122                         G_DBUS_INTERFACE_SKELETON(popup_skeleton),
123                         connection,
124                         "/org/tizen/NetNfcService/Popup",
125                         &error);
126         if (result == FALSE)
127         {
128                 NFC_ERR("Can not skeleton_export %s", error->message);
129
130                 g_error_free(error);
131
132                 net_nfc_server_system_handler_deinit();
133         }
134
135         return result;
136 }
137
138 void net_nfc_server_system_handler_deinit(void)
139 {
140         if (popup_skeleton)
141         {
142                 g_object_unref(popup_skeleton);
143                 popup_skeleton = NULL;
144         }
145 }