49ea9465695e301b06fd54d03e7afe1384376241
[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
25 #define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error"
26 #define CONNMAN_AGENT_ERROR_INTERFACE "net.connman.Agent.Error"
27
28 GQuark netconfig_error_quark(void)
29 {
30         static GQuark quark = 0;
31
32         if (!quark)
33                 quark = g_quark_from_static_string("netconfig_error");
34
35         return quark;
36 }
37
38 GQuark netconfig_connman_agent_error_quark(void)
39 {
40         static GQuark quark = 0;
41
42         if (!quark)
43                 quark = g_quark_from_static_string("netconfig_connman_agent_error");
44
45         return quark;
46 }
47
48 void netconfig_error_no_profile(GDBusMethodInvocation *context)
49 {
50         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
51                         NETCONFIG_ERROR_NO_PROFILE,
52                         NETCONFIG_ERROR_INTERFACE ".NoProfile");
53 }
54
55 void netconfig_error_inprogress(GDBusMethodInvocation *context)
56 {
57         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
58                         NETCONFIG_ERROR_INPROGRESS,
59                         NETCONFIG_ERROR_INTERFACE ".InProgress");
60 }
61
62 void netconfig_error_already_exists(GDBusMethodInvocation *context)
63 {
64         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
65                         NETCONFIG_ERROR_ALREADYEXISTS,
66                         NETCONFIG_ERROR_INTERFACE ".AlreadyExists");
67 }
68
69 void netconfig_error_invalid_parameter(GDBusMethodInvocation *context)
70 {
71         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
72                         NETCONFIG_ERROR_INVALID_PARAMETER,
73                         NETCONFIG_ERROR_INTERFACE ".InvalidParameter");
74 }
75
76 void netconfig_error_permission_denied(GDBusMethodInvocation *context)
77 {
78         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
79                         NETCONFIG_ERROR_PERMISSION_DENIED,
80                         NETCONFIG_ERROR_INTERFACE ".PermissionDenied");
81 }
82
83 void netconfig_error_wifi_driver_failed(GDBusMethodInvocation *context)
84 {
85         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
86                         NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
87                         NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed");
88 }
89
90 void netconfig_error_wifi_direct_failed(GDBusMethodInvocation *context)
91 {
92         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
93                         NETCONFIG_ERROR_WIFI_DRIVER_FAILURE,
94                         NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed");
95 }
96
97 void netconfig_error_fail_get_imsi(GDBusMethodInvocation *context)
98 {
99         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
100                         NETCONFIG_ERROR_FAILED_GET_IMSI,
101                         NETCONFIG_ERROR_INTERFACE".FailGetSimImsi");
102 }
103
104 void netconfig_error_fail_req_sim_auth(GDBusMethodInvocation *context)
105 {
106         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
107                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH,
108                         NETCONFIG_ERROR_INTERFACE".FailReqSimAuth");
109 }
110
111 void netconfig_error_fail_req_sim_auth_wrong_param(GDBusMethodInvocation *context)
112 {
113         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
114                         NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM,
115                         NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam");
116 }
117
118 void netconfig_error_fail_get_sim_auth_wrong_data(GDBusMethodInvocation *context)
119 {
120         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
121                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA,
122                         NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData");
123 }
124
125 void netconfig_error_fail_get_sim_auth_delay(GDBusMethodInvocation *context)
126 {
127         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
128                         NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY,
129                         NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay");
130 }
131
132 void netconfig_error_fail_save_congifuration(GDBusMethodInvocation *context)
133 {
134         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
135                         NETCONFIG_ERROR_INTERNAL,
136                         NETCONFIG_ERROR_INTERFACE".FailSaveConfiguration");
137 }
138
139 void netconfig_error_fail_ethernet_cable_state(GDBusMethodInvocation *context)
140 {
141         g_dbus_method_invocation_return_error(context, netconfig_error_quark(),
142                         NETCONFIG_ERROR_INTERNAL,
143                         NETCONFIG_ERROR_INTERFACE".FailGetEthernetCableState");
144 }
145
146 void netconfig_error_dbus_method_return(GDBusMethodInvocation *context, netconfig_error_e error, const gchar *message)
147 {
148         gchar *msg = NULL;
149
150         msg = g_strdup_printf("%s.%s", NETCONFIG_ERROR_INTERFACE, message);
151         g_dbus_method_invocation_return_error_literal(context, netconfig_error_quark(), error, msg);
152
153         g_free(msg);
154 }
155
156 void netconfig_error_init(void)
157 {
158         /* TODO: register GError domain to make error_name */
159         /*
160         dbus_g_error_domain_register(NETCONFIG_ERROR_QUARK,
161                         NETCONFIG_ERROR_INTERFACE,
162                         code_num_netconfig);
163
164         dbus_g_error_domain_register(NETCONFIG_CONNMAN_AGENT_ERROR_QUARK,
165                         CONNMAN_AGENT_ERROR_INTERFACE,
166                         code_num_connman);
167         */
168 }