Add initial sources for gtest in unittest
[platform/core/connectivity/wifi-direct-manager.git] / src / wifi-direct-error.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 /**
21  * This file implements wifi direct manager dbus error functions.
22  *
23  * @file        wifi-direct-error.c
24  * @author      Nishant Chaprana (n.chaprana@samsung.com)
25  * @version     0.1
26  */
27
28 #include <glib.h>
29 #include "wifi-direct-error.h"
30 #include "wifi-direct-dbus.h"
31 #include "wifi-direct-log.h"
32
33 #define WFD_MANAGER_QUARK (g_quark_from_string("wifi-direct-error-quark"))
34
35 //LCOV_EXCL_START
36 static void wfd_error_invalid_parameter(GError **error)
37 {
38         *error = g_dbus_error_new_for_dbus_error(
39                 "net.wifidirect.Error.InvalidParameter",
40                 "net.wifidirect.Error.InvalidParameter");
41         /*
42         g_set_error(error,
43                         WFD_MANAGER_QUARK,
44                         WIFI_DIRECT_ERROR_INVALID_PARAMETER,
45                         WFD_MANAGER_ERROR_INTERFACE ".InvalidParameter");
46                         */
47 }
48
49 static void wfd_error_not_permitted(GError **error)
50 {
51         *error = g_dbus_error_new_for_dbus_error(
52                 "net.wifidirect.Error.NotPermitted",
53                 "net.wifidirect.Error.NotPermitted");
54 /*
55         g_set_error(error,
56                         WFD_MANAGER_QUARK,
57                         WIFI_DIRECT_ERROR_NOT_PERMITTED,
58                         WFD_MANAGER_ERROR_INTERFACE ".NotPermitted");
59                         */
60 }
61
62 static void wfd_error_operation_failed(GError **error)
63 {
64         *error = g_dbus_error_new_for_dbus_error(
65                 "net.wifidirect.Error.OperationFailed",
66                 "net.wifidirect.Error.OperationFailed");
67         /*
68         g_set_error(error,
69                         WFD_MANAGER_QUARK,
70                         WIFI_DIRECT_ERROR_OPERATION_FAILED,
71                         WFD_MANAGER_ERROR_INTERFACE ".OperationFailed");
72                         */
73 }
74
75 static void wfd_error_too_many_client(GError **error)
76 {
77         *error = g_dbus_error_new_for_dbus_error(
78                 "net.wifidirect.Error.TooManyClient",
79                 "net.wifidirect.Error.TooManyClient");
80 /*
81         g_set_error(error,
82                         WFD_MANAGER_QUARK,
83                         WIFI_DIRECT_ERROR_TOO_MANY_CLIENT,
84                         WFD_MANAGER_ERROR_INTERFACE ".TooManyClient");
85                         */
86 }
87
88 void wfd_error_set_gerror(wifi_direct_error_e error_code, GError **error)
89 {
90         switch (error_code) {
91         case WIFI_DIRECT_ERROR_INVALID_PARAMETER:
92                 wfd_error_invalid_parameter(error);
93                 break;
94         case WIFI_DIRECT_ERROR_NOT_PERMITTED:
95                 wfd_error_not_permitted(error);
96                 break;
97         case WIFI_DIRECT_ERROR_OPERATION_FAILED:
98                 wfd_error_operation_failed(error);
99                 break;
100         case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT:
101                 wfd_error_too_many_client(error);
102                 break;
103         default:
104                 WDS_LOGD("Error Not handled [%d]", error_code);
105                 wfd_error_operation_failed(error);
106         }
107 }
108 void wfd_error_register(void)
109 {
110         g_dbus_error_register_error(WFD_MANAGER_QUARK,
111                         WIFI_DIRECT_ERROR_INVALID_PARAMETER,
112                         "net.wifidirect.Error.InvalidParameter");
113
114
115         g_dbus_error_register_error(WFD_MANAGER_QUARK,
116                         WIFI_DIRECT_ERROR_NOT_PERMITTED,
117                         "net.wifidirect.Error.NotPermitted");
118
119
120         g_dbus_error_register_error(WFD_MANAGER_QUARK,
121                         WIFI_DIRECT_ERROR_OPERATION_FAILED,
122                         "net.wifidirect.Error.OperationFailed");
123
124
125         g_dbus_error_register_error(WFD_MANAGER_QUARK,
126                         WIFI_DIRECT_ERROR_TOO_MANY_CLIENT,
127                         "net.wifidirect.Error.TooManyClient");
128 }
129
130 void wfd_error_deregister(void)
131 {
132         g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
133                         WIFI_DIRECT_ERROR_INVALID_PARAMETER,
134                         "net.wifidirect.Error.InvalidParameter");
135
136
137         g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
138                         WIFI_DIRECT_ERROR_NOT_PERMITTED,
139                         "net.wifidirect.Error.NotPermitted");
140
141
142         g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
143                         WIFI_DIRECT_ERROR_OPERATION_FAILED,
144                         "net.wifidirect.Error.OperationFailed");
145
146
147         g_dbus_error_unregister_error(WFD_MANAGER_QUARK,
148                         WIFI_DIRECT_ERROR_TOO_MANY_CLIENT,
149                         "net.wifidirect.Error.TooManyClient");
150
151 }
152 //LCOV_EXCL_STOP