0e3113d4f68995228dadbc584ef165d38fb6c00d
[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 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 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 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 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 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 #include <glib/gprintf.h>
161 void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message)
162 {
163         gchar *msg = NULL;
164
165         ERR("dbus method return error");
166
167         msg = g_strdup_printf("%s.%s", NETCONFIG_ERROR_INTERFACE, message);
168         g_dbus_method_invocation_return_error(context, netconfig_error_quark(), error, "%s", msg);
169
170         g_free(msg);
171 }
172
173 void netconfig_error_init(void)
174 {
175         /* TODO: register GError domain to make error_name */
176         /*
177         dbus_g_error_domain_register(NETCONFIG_ERROR_QUARK,
178                         NETCONFIG_ERROR_INTERFACE,
179                         code_num_netconfig);
180
181         dbus_g_error_domain_register(NETCONFIG_CONNMAN_AGENT_ERROR_QUARK,
182                         CONNMAN_AGENT_ERROR_INTERFACE,
183                         code_num_connman);
184         */
185 }