1 // 2 // Copyright (C) 2015 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 "shill/dbus/chromeos_ipconfig_dbus_adaptor.h" 18 19 #include <string> 20 #include <vector> 21 22 #include <base/strings/stringprintf.h> 23 24 #include "shill/error.h" 25 #include "shill/ipconfig.h" 26 #include "shill/logging.h" 27 28 using base::StringPrintf; 29 using brillo::dbus_utils::AsyncEventSequencer; 30 using brillo::dbus_utils::ExportedObjectManager; 31 using std::string; 32 using std::vector; 33 34 namespace shill { 35 36 namespace Logging { 37 static auto kModuleLogScope = ScopeLogger::kDBus; 38 static string ObjectID(ChromeosIPConfigDBusAdaptor* i) { 39 return i->GetRpcIdentifier(); 40 } 41 } 42 43 // static 44 const char ChromeosIPConfigDBusAdaptor::kPath[] = "/ipconfig/"; 45 46 ChromeosIPConfigDBusAdaptor::ChromeosIPConfigDBusAdaptor( 47 const scoped_refptr<dbus::Bus>& bus, 48 IPConfig* config) 49 : org::chromium::flimflam::IPConfigAdaptor(this), 50 ChromeosDBusAdaptor(bus, 51 StringPrintf("%s%s_%u_%s", 52 kPath, 53 SanitizePathElement( 54 config->device_name()).c_str(), 55 config->serial(), 56 config->type().c_str())), 57 ipconfig_(config) { 58 // Register DBus object. 59 RegisterWithDBusObject(dbus_object()); 60 dbus_object()->RegisterAndBlock(); 61 } 62 63 ChromeosIPConfigDBusAdaptor::~ChromeosIPConfigDBusAdaptor() { 64 dbus_object()->UnregisterAsync(); 65 ipconfig_ = nullptr; 66 } 67 68 void ChromeosIPConfigDBusAdaptor::EmitBoolChanged(const string& name, 69 bool value) { 70 SLOG(this, 2) << __func__ << ": " << name; 71 SendPropertyChangedSignal(name, brillo::Any(value)); 72 } 73 74 void ChromeosIPConfigDBusAdaptor::EmitUintChanged(const string& name, 75 uint32_t value) { 76 SLOG(this, 2) << __func__ << ": " << name; 77 SendPropertyChangedSignal(name, brillo::Any(value)); 78 } 79 80 void ChromeosIPConfigDBusAdaptor::EmitIntChanged(const string& name, 81 int value) { 82 SLOG(this, 2) << __func__ << ": " << name; 83 SendPropertyChangedSignal(name, brillo::Any(value)); 84 } 85 86 void ChromeosIPConfigDBusAdaptor::EmitStringChanged(const string& name, 87 const string& value) { 88 SLOG(this, 2) << __func__ << ": " << name; 89 SendPropertyChangedSignal(name, brillo::Any(value)); 90 } 91 92 void ChromeosIPConfigDBusAdaptor::EmitStringsChanged( 93 const string& name, const vector<string>& value) { 94 SLOG(this, 2) << __func__ << ": " << name; 95 SendPropertyChangedSignal(name, brillo::Any(value)); 96 } 97 98 bool ChromeosIPConfigDBusAdaptor::GetProperties( 99 brillo::ErrorPtr* error, brillo::VariantDictionary* properties) { 100 SLOG(this, 2) << __func__; 101 return ChromeosDBusAdaptor::GetProperties(ipconfig_->store(), 102 properties, 103 error); 104 } 105 106 bool ChromeosIPConfigDBusAdaptor::SetProperty( 107 brillo::ErrorPtr* error, const string& name, const brillo::Any& value) { 108 SLOG(this, 2) << __func__ << ": " << name; 109 return ChromeosDBusAdaptor::SetProperty(ipconfig_->mutable_store(), 110 name, 111 value, 112 error); 113 } 114 115 bool ChromeosIPConfigDBusAdaptor::ClearProperty( 116 brillo::ErrorPtr* error, const string& name) { 117 SLOG(this, 2) << __func__ << ": " << name; 118 return ChromeosDBusAdaptor::ClearProperty(ipconfig_->mutable_store(), 119 name, 120 error); 121 } 122 123 bool ChromeosIPConfigDBusAdaptor::Remove(brillo::ErrorPtr* error) { 124 SLOG(this, 2) << __func__; 125 return !Error(Error::kNotSupported).ToChromeosError(error); 126 } 127 128 bool ChromeosIPConfigDBusAdaptor::Refresh(brillo::ErrorPtr* error) { 129 SLOG(this, 2) << __func__; 130 Error e; 131 ipconfig_->Refresh(&e); 132 return !e.ToChromeosError(error); 133 } 134 135 } // namespace shill 136