1 //
2 // Copyright (C) 2014 The Android Open Source Project
3 //
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
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 #include "apmanager/dbus/config_dbus_adaptor.h"
18
19 #include <base/strings/stringprintf.h>
20 #include <dbus_bindings/org.chromium.apmanager.Manager.h>
21
22 #if !defined(__ANDROID__)
23 #include <chromeos/dbus/service_constants.h>
24 #else
25 #include <dbus/apmanager/dbus-constants.h>
26 #endif // __ANDROID__
27
28 #include "apmanager/config.h"
29 #include "apmanager/error.h"
30
31 using brillo::dbus_utils::ExportedObjectManager;
32 using brillo::ErrorPtr;
33 using org::chromium::apmanager::ConfigAdaptor;
34 using org::chromium::apmanager::ManagerAdaptor;
35 using std::string;
36
37 namespace apmanager {
38
ConfigDBusAdaptor(const scoped_refptr<dbus::Bus> & bus,ExportedObjectManager * object_manager,Config * config,int service_identifier)39 ConfigDBusAdaptor::ConfigDBusAdaptor(
40 const scoped_refptr<dbus::Bus>& bus,
41 ExportedObjectManager* object_manager,
42 Config* config,
43 int service_identifier)
44 : org::chromium::apmanager::ConfigAdaptor(this),
45 dbus_path_(
46 base::StringPrintf("%s/services/%d/config",
47 ManagerAdaptor::GetObjectPath().value().c_str(),
48 service_identifier)),
49 dbus_object_(object_manager, bus, dbus_path_),
50 config_(config) {
51 // Register D-Bus object.
52 RegisterWithDBusObject(&dbus_object_);
53 dbus_object_.RegisterAndBlock();
54 }
55
~ConfigDBusAdaptor()56 ConfigDBusAdaptor::~ConfigDBusAdaptor() {}
57
ValidateSsid(ErrorPtr * error,const string & value)58 bool ConfigDBusAdaptor::ValidateSsid(ErrorPtr* error, const string& value) {
59 Error internal_error;
60 config_->ValidateSsid(&internal_error, value);
61 return !internal_error.ToDBusError(error);
62 }
63
ValidateSecurityMode(ErrorPtr * error,const string & value)64 bool ConfigDBusAdaptor::ValidateSecurityMode(ErrorPtr* error,
65 const string& value) {
66 Error internal_error;
67 config_->ValidateSecurityMode(&internal_error, value);
68 return !internal_error.ToDBusError(error);
69 }
70
ValidatePassphrase(ErrorPtr * error,const string & value)71 bool ConfigDBusAdaptor::ValidatePassphrase(ErrorPtr* error,
72 const string& value) {
73 Error internal_error;
74 config_->ValidatePassphrase(&internal_error, value);
75 return !internal_error.ToDBusError(error);
76 }
77
ValidateHwMode(ErrorPtr * error,const string & value)78 bool ConfigDBusAdaptor::ValidateHwMode(ErrorPtr* error, const string& value) {
79 Error internal_error;
80 config_->ValidateHwMode(&internal_error, value);
81 return !internal_error.ToDBusError(error);
82 }
83
ValidateOperationMode(ErrorPtr * error,const string & value)84 bool ConfigDBusAdaptor::ValidateOperationMode(ErrorPtr* error,
85 const string& value) {
86 Error internal_error;
87 config_->ValidateOperationMode(&internal_error, value);
88 return !internal_error.ToDBusError(error);
89 }
90
ValidateChannel(ErrorPtr * error,const uint16_t & value)91 bool ConfigDBusAdaptor::ValidateChannel(ErrorPtr* error,
92 const uint16_t& value) {
93 Error internal_error;
94 config_->ValidateChannel(&internal_error, value);
95 return !internal_error.ToDBusError(error);
96 }
97
GetRpcObjectIdentifier()98 RPCObjectIdentifier ConfigDBusAdaptor::GetRpcObjectIdentifier() {
99 return dbus_path_;
100 }
101
SetSsid(const string & ssid)102 void ConfigDBusAdaptor::SetSsid(const string& ssid) {
103 ConfigAdaptor::SetSsid(ssid);
104 }
105
GetSsid()106 string ConfigDBusAdaptor::GetSsid() {
107 return ConfigAdaptor::GetSsid();
108 }
109
SetInterfaceName(const std::string & interface_name)110 void ConfigDBusAdaptor::SetInterfaceName(const std::string& interface_name) {
111 ConfigAdaptor::SetInterfaceName(interface_name);
112 }
113
GetInterfaceName()114 string ConfigDBusAdaptor::GetInterfaceName() {
115 return ConfigAdaptor::GetInterfaceName();
116 }
117
SetSecurityMode(const std::string & mode)118 void ConfigDBusAdaptor::SetSecurityMode(const std::string& mode) {
119 ConfigAdaptor::SetSecurityMode(mode);
120 }
121
GetSecurityMode()122 string ConfigDBusAdaptor::GetSecurityMode() {
123 return ConfigAdaptor::GetSecurityMode();
124 }
125
SetPassphrase(const std::string & passphrase)126 void ConfigDBusAdaptor::SetPassphrase(const std::string& passphrase) {
127 ConfigAdaptor::SetPassphrase(passphrase);
128 }
129
GetPassphrase()130 string ConfigDBusAdaptor::GetPassphrase() {
131 return ConfigAdaptor::GetPassphrase();
132 }
133
SetHwMode(const std::string & hw_mode)134 void ConfigDBusAdaptor::SetHwMode(const std::string& hw_mode) {
135 ConfigAdaptor::SetHwMode(hw_mode);
136 }
137
GetHwMode()138 string ConfigDBusAdaptor::GetHwMode() {
139 return ConfigAdaptor::GetHwMode();
140 }
141
SetOperationMode(const std::string & op_mode)142 void ConfigDBusAdaptor::SetOperationMode(const std::string& op_mode) {
143 ConfigAdaptor::SetOperationMode(op_mode);
144 }
145
GetOperationMode()146 string ConfigDBusAdaptor::GetOperationMode() {
147 return ConfigAdaptor::GetOperationMode();
148 }
149
SetChannel(uint16_t channel)150 void ConfigDBusAdaptor::SetChannel(uint16_t channel) {
151 ConfigAdaptor::SetChannel(channel);
152 }
153
GetChannel()154 uint16_t ConfigDBusAdaptor::GetChannel() {
155 return ConfigAdaptor::GetChannel();
156 }
157
SetHiddenNetwork(bool hidden_network)158 void ConfigDBusAdaptor::SetHiddenNetwork(bool hidden_network) {
159 ConfigAdaptor::SetHiddenNetwork(hidden_network);
160 }
161
GetHiddenNetwork()162 bool ConfigDBusAdaptor::GetHiddenNetwork() {
163 return ConfigAdaptor::GetHiddenNetwork();
164 }
165
SetBridgeInterface(const std::string & interface_name)166 void ConfigDBusAdaptor::SetBridgeInterface(const std::string& interface_name) {
167 ConfigAdaptor::SetBridgeInterface(interface_name);
168 }
169
GetBridgeInterface()170 string ConfigDBusAdaptor::GetBridgeInterface() {
171 return ConfigAdaptor::GetBridgeInterface();
172 }
173
SetServerAddressIndex(uint16_t index)174 void ConfigDBusAdaptor::SetServerAddressIndex(uint16_t index) {
175 ConfigAdaptor::SetServerAddressIndex(index);
176 }
177
GetServerAddressIndex()178 uint16_t ConfigDBusAdaptor::GetServerAddressIndex() {
179 return ConfigAdaptor::GetServerAddressIndex();
180 }
181
SetFullDeviceControl(bool full_control)182 void ConfigDBusAdaptor::SetFullDeviceControl(bool full_control) {
183 ConfigAdaptor::SetFullDeviceControl(full_control);
184 }
185
GetFullDeviceControl()186 bool ConfigDBusAdaptor::GetFullDeviceControl() {
187 return ConfigAdaptor::GetFullDeviceControl();
188 }
189
190 } // namespace apmanager
191