Merge "Revise driver load routine" into tizen
[platform/core/connectivity/net-config.git] / src / neterror.c
1 /*
2  * Network Configuration Module
3  *
4  * Copyright (c) 2000 - 2012 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 #include <glib.h>
21
22 #include "netdbus.h"
23 #include "neterror.h"
24 #include "log.h"
25
26 #define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error"
27 #define CONNMAN_AGENT_ERROR_INTERFACE "net.connman.Agent.Error"
28
29 GQuark netconfig_error_quark(void)
30 {
31         static GQuark quark = 0;
32
33         if (!quark)
34                 quark = g_quark_from_static_string("netconfig_error");
35
36         return quark;
37 }
38
39 GQuark netconfig_connman_agent_error_quark(void)
40 {
41         static GQuark quark = 0;
42
43         if (!quark)
44                 quark = g_quark_from_static_string("netconfig_connman_agent_error");
45
46         return quark;
47 }
48
49 void netconfig_error_no_profile(GDBusMethodInvocation *context)
50 {
51         ERR("dbus method return error");
52         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
53                         NETCONFIG_ERROR_NO_PROFILE,
54                         NETCONFIG_ERROR_INTERFACE ".NoProfile");
55 }
56
57 void netconfig_error_inprogress(GDBusMethodInvocation *context)
58 {
59         ERR("dbus method return error");
60         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
61                         NETCONFIG_ERROR_INPROGRESS,
62                         NETCONFIG_ERROR_INTERFACE ".InProgress");
63 }
64
65 void netconfig_error_already_exists(GDBusMethodInvocation *context)
66 {
67         ERR("dbus method return error");
68         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
69                         NETCONFIG_ERROR_ALREADYEXISTS,
70                         NETCONFIG_ERROR_INTERFACE ".AlreadyExists");
71 }
72
73 void netconfig_error_invalid_parameter(GDBusMethodInvocation *context)
74 {
75         ERR("dbus method return error");
76         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
77                         NETCONFIG_ERROR_INVALID_PARAMETER,
78                         NETCONFIG_ERROR_INTERFACE ".InvalidParameter");
79 }
80
81 void netconfig_error_permission_denied(GDBusMethodInvocation *context)
82 {
83         ERR("dbus method return error");
84         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
85                         NETCONFIG_ERROR_PERMISSION_DENIED,
86                         NETCONFIG_ERROR_INTERFACE ".PermissionDenied");
87 }
88
89 void netconfig_error_wifi_driver_failed(GDBusMethodInvocation *context)
90 {
91         ERR("dbus method return error");
92         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
93                         NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
94                         NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed");
95 }
96
97 void netconfig_error_wifi_direct_failed(GDBusMethodInvocation *context)
98 {
99         ERR("dbus method return error");
100         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
101                         NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
102                         NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed");
103 }
104
105 EXPORT_SYM void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context)
106 {
107         ERR("dbus method return error");
108         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
109                         NETCONFIG_ERROR_FAILED_GET_IMSI,
110                         NETCONFIG_ERROR_INTERFACE".FailGetSimImsi");
111 }
112
113 EXPORT_SYM void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context)
114 {
115         ERR("dbus method return error");
116         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
117                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH,
118                         NETCONFIG_ERROR_INTERFACE".FailReqSimAuth");
119 }
120
121 EXPORT_SYM void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context)
122 {
123         ERR("dbus method return error");
124         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
125                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM,
126                         NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam");
127 }
128
129 EXPORT_SYM void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context)
130 {
131         ERR("dbus method return error");
132         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
133                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA,
134                         NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData");
135 }
136
137 EXPORT_SYM void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context)
138 {
139         ERR("dbus method return error");
140         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
141                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY,
142                         NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay");
143 }
144
145 void netconfig_error_fail_save_congifuration(GDBusMethodInvocation *context)
146 {
147         ERR("dbus method return error");
148         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
149                         NETCONFIG_ERROR_INTERNAL,
150                         NETCONFIG_ERROR_INTERFACE".FailSaveConfiguration");
151 }
152
153 void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context)
154 {
155         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
156                         NETCONFIG_ERROR_INTERNAL,
157                         NETCONFIG_ERROR_INTERFACE".FailGetEthernetCableState");
158 }
159
160 void netconfig_error_fail_preferred_ipv6_address(GDBusMethodInvocation *context)
161 {
162         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
163                         NETCONFIG_ERROR_INTERNAL,
164                         NETCONFIG_ERROR_INTERFACE".FailGetPreferredIpv6Address");
165 }
166
167 #include <glib/gprintf.h>
168 void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message)
169 {
170         gchar *msg = NULL;
171
172         ERR("dbus method return error");
173
174         msg = g_strdup_printf("%s.%s", NETCONFIG_ERROR_INTERFACE, message);
175         g_dbus_method_invocation_return_error(context, netconfig_error_quark(), error, "%s", msg);
176
177         g_free(msg);
178 }
179
180 void netconfig_error_init(void)
181 {
182         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
183                         NETCONFIG_ERROR_INTERNAL,
184                         "net.netconfig.Error.Internal");
185
186         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
187                         NETCONFIG_ERROR_NO_SERVICE,
188                         "net.netconfig.Error.NoService");
189
190         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
191                         NETCONFIG_ERROR_NO_PROFILE,
192                         "net.netconfig.Error.NoProfile");
193
194         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
195                         NETCONFIG_ERROR_WRONG_PROFILE,
196                         "net.netconfig.Error.WrongProfile");
197
198         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
199                         NETCONFIG_ERROR_INPROGRESS,
200                         "net.netconfig.Error.InProgress");
201
202         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
203                         NETCONFIG_ERROR_ALREADYEXISTS,
204                         "net.netconfig.Error.AlreadyExists");
205
206         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
207                         NETCONFIG_ERROR_INVALID_PARAMETER,
208                         "net.netconfig.Error.InvalidParameter");
209
210         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
211                         NETCONFIG_ERROR_PERMISSION_DENIED,
212                         "net.netconfig.Error.PermissionDenied");
213
214         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
215                         NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
216                         "net.netconfig.Error.WifiDriverFailed");
217
218         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
219                         NETCONFIG_ERROR_FAILED_GET_IMSI,
220                         "net.netconfig.Error.FailGetSimImsi");
221
222         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
223                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH,
224                         "net.netconfig.Error.FailReqSimAuthWrongParam");
225
226         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
227                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM,
228                         "net.netconfig.Error.FailReqSimAuthWrongParam");
229
230         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
231                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA,
232                         "net.netconfig.Error.FailGetSimAuthWrongData");
233
234         g_dbus_error_register_error(NETCONFIG_ERROR_QUARK,
235                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY,
236                         "net.netconfig.Error.FailGetSimAuthDelay");
237 }