2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <gmock/gmock.h>
21 #include <gtest/gtest.h>
24 #include "network_state.h"
26 NetworkState::NetworkState()
31 NetworkState::~NetworkState()
36 error_e NetworkState::AddRoute(const char *ip, const char *mask, const char *interface,
37 const char *gateway, int family, bool *result)
39 GVariant *message = NULL;
40 error_e error = ERROR_NONE;
42 message = InvokeMethod(NETCONFIG_SERVICE,
43 NETCONFIG_NETWORK_PATH,
44 NETCONFIG_NETWORK_INTERFACE,
46 g_variant_new("(ssssi)", ip, mask, interface,
50 if (message == NULL) {
51 GLOGD("Failed to invoke dbus method");
55 g_variant_get(message, "(b)", result);
56 g_variant_unref(message);
61 error_e NetworkState::RemoveRoute(const char *ip, const char *mask, const char *interface,
62 const char *gateway, int family, bool *result)
64 GVariant *message = NULL;
65 error_e error = ERROR_NONE;
67 message = InvokeMethod(NETCONFIG_SERVICE,
68 NETCONFIG_NETWORK_PATH,
69 NETCONFIG_NETWORK_INTERFACE,
71 g_variant_new("(ssssi)", ip, mask, interface,
75 if (message == NULL) {
76 GLOGD("Failed to invoke dbus method");
80 g_variant_get(message, "(b)", result);
81 g_variant_unref(message);
85 error_e NetworkState::EthernetCableState(int *state)
87 GVariant *message = NULL;
88 error_e error = ERROR_NONE;
90 message = InvokeMethod(NETCONFIG_SERVICE,
91 NETCONFIG_NETWORK_PATH,
92 NETCONFIG_NETWORK_INTERFACE,
97 if (message == NULL) {
98 GLOGD("Failed to invoke dbus method");
102 g_variant_get(message, "(i)", state);
103 g_variant_unref(message);
108 error_e NetworkState::LaunchMdns(const char *name)
110 GVariant *message = NULL;
111 error_e error = ERROR_NONE;
113 message = InvokeMethod(NETCONFIG_SERVICE,
114 NETCONFIG_NETWORK_PATH,
115 NETCONFIG_NETWORK_INTERFACE,
117 g_variant_new("(s)", name),
120 if (message == NULL) {
121 GLOGD("Failed to invoke dbus method");
125 g_variant_unref(message);
129 error_e NetworkState::DevicePolicySetWifi(int state)
131 GVariant *message = NULL;
132 error_e error = ERROR_NONE;
134 message = InvokeMethod(NETCONFIG_SERVICE,
135 NETCONFIG_NETWORK_PATH,
136 NETCONFIG_NETWORK_INTERFACE,
137 DEVICE_POLICY_SET_WIFI,
138 g_variant_new("(i)", state),
141 if (message == NULL) {
142 GLOGD("Failed to invoke dbus method");
146 g_variant_unref(message);
150 error_e NetworkState::DevicePolicyGetWifi(int *state)
152 GVariant *message = NULL;
153 error_e error = ERROR_NONE;
155 message = InvokeMethod(NETCONFIG_SERVICE,
156 NETCONFIG_NETWORK_PATH,
157 NETCONFIG_NETWORK_INTERFACE,
158 DEVICE_POLICY_GET_WIFI,
162 if (message == NULL) {
163 GLOGD("Failed to invoke dbus method");
167 g_variant_get(message, "(i)", state);
168 g_variant_unref(message);
172 error_e NetworkState::DevicePolicySetWifiProfile(int state)
174 GVariant *message = NULL;
175 error_e error = ERROR_NONE;
177 message = InvokeMethod(NETCONFIG_SERVICE,
178 NETCONFIG_NETWORK_PATH,
179 NETCONFIG_NETWORK_INTERFACE,
180 DEVICE_POLICY_SET_WIFI_PROFILE,
181 g_variant_new("(i)", state),
184 if (message == NULL) {
185 GLOGD("Failed to invoke dbus method");
189 g_variant_unref(message);
193 error_e NetworkState::DevicePolicyGetWifiProfile(int *state)
195 GVariant *message = NULL;
196 error_e error = ERROR_NONE;
198 message = InvokeMethod(NETCONFIG_SERVICE,
199 NETCONFIG_NETWORK_PATH,
200 NETCONFIG_NETWORK_INTERFACE,
201 DEVICE_POLICY_GET_WIFI_PROFILE,
205 if (message == NULL) {
206 GLOGD("Failed to invoke dbus method");
210 g_variant_get(message, "(i)", state);
211 g_variant_unref(message);
215 error_e NetworkState::GetMeteredInfo(bool *state)
217 GVariant *message = NULL;
218 error_e error = ERROR_NONE;
220 message = InvokeMethod(NETCONFIG_SERVICE,
221 NETCONFIG_NETWORK_PATH,
222 NETCONFIG_NETWORK_INTERFACE,
227 if (message == NULL) {
228 GLOGD("Failed to invoke dbus method");
232 g_variant_get(message, "(b)", state);
233 g_variant_unref(message);
237 error_e NetworkState::PreferredIpv6Address(const char *profile, char *address)
239 GVariant *message = NULL;
240 error_e error = ERROR_NONE;
242 message = InvokeMethod(NETCONFIG_SERVICE,
243 NETCONFIG_NETWORK_PATH,
244 NETCONFIG_NETWORK_INTERFACE,
245 PREFERRED_IPV6_ADDRESS,
246 g_variant_new("(s)", profile),
249 if (message == NULL) {
250 GLOGD("Failed to invoke dbus method");
254 g_variant_get(message, "(s)", address);
255 g_variant_unref(message);
259 error_e NetworkState::GetTCPDumpState(bool *state)
261 GVariant *message = NULL;
262 error_e error = ERROR_NONE;
264 message = InvokeMethod(NETCONFIG_SERVICE,
265 NETCONFIG_NETWORK_PATH,
266 NETCONFIG_TCPDUMP_INTERFACE,
271 if (message == NULL) {
272 GLOGD("Failed to invoke dbus method");
276 g_variant_get(message, "(b)", state);
277 g_variant_unref(message);
281 error_e NetworkState::StartTCPDump()
283 GVariant *message = NULL;
284 error_e error = ERROR_NONE;
286 message = InvokeMethod(NETCONFIG_SERVICE,
287 NETCONFIG_NETWORK_PATH,
288 NETCONFIG_TCPDUMP_INTERFACE,
293 if (message == NULL) {
294 GLOGD("Failed to invoke dbus method");
298 g_variant_unref(message);
302 error_e NetworkState::StopTCPDump()
304 GVariant *message = NULL;
305 error_e error = ERROR_NONE;
307 message = InvokeMethod(NETCONFIG_SERVICE,
308 NETCONFIG_NETWORK_PATH,
309 NETCONFIG_TCPDUMP_INTERFACE,
314 if (message == NULL) {
315 GLOGD("Failed to invoke dbus method");
319 g_variant_unref(message);