// Copyright (c) 2011 The Chromium OS Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "shill/property_store.h" #include #include #include #include #include #include #include "shill/error.h" #include "shill/property_accessor.h" using std::map; using std::string; using std::vector; namespace shill { PropertyStore::PropertyStore() {} PropertyStore::~PropertyStore() {} bool PropertyStore::Contains(const std::string &prop) { return (bool_properties_.find(prop) != bool_properties_.end() || int16_properties_.find(prop) != int16_properties_.end() || int32_properties_.find(prop) != int32_properties_.end() || string_properties_.find(prop) != string_properties_.end() || stringmap_properties_.find(prop) != stringmap_properties_.end() || stringmaps_properties_.find(prop) != stringmaps_properties_.end() || strintpair_properties_.find(prop) != strintpair_properties_.end() || strings_properties_.find(prop) != strings_properties_.end() || uint8_properties_.find(prop) != uint8_properties_.end() || uint16_properties_.find(prop) != uint16_properties_.end() || uint32_properties_.find(prop) != uint32_properties_.end()); } bool PropertyStore::SetBoolProperty(const std::string& name, bool value, Error *error) { VLOG(2) << "Setting " << name << " as a bool."; bool set = (ContainsKey(bool_properties_, name) && bool_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W bool."); return set; } bool PropertyStore::SetInt16Property(const std::string& name, int16 value, Error *error) { VLOG(2) << "Setting " << name << " as an int16."; bool set = (ContainsKey(int16_properties_, name) && int16_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W int16."); return set; } bool PropertyStore::SetInt32Property(const std::string& name, int32 value, Error *error) { VLOG(2) << "Setting " << name << " as an int32."; bool set = (ContainsKey(int32_properties_, name) && int32_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W int32."); return set; } bool PropertyStore::SetStringProperty(const std::string& name, const std::string& value, Error *error) { VLOG(2) << "Setting " << name << " as a string."; bool set = (ContainsKey(string_properties_, name) && string_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W string."); return set; } bool PropertyStore::SetStringmapProperty( const std::string& name, const std::map& values, Error *error) { VLOG(2) << "Setting " << name << " as a string map."; bool set = (ContainsKey(stringmap_properties_, name) && stringmap_properties_[name]->Set(values)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W strmap."); return set; } bool PropertyStore::SetStringsProperty(const std::string& name, const std::vector& values, Error *error) { VLOG(2) << "Setting " << name << " as a string list."; bool set = (ContainsKey(strings_properties_, name) && strings_properties_[name]->Set(values)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W str list."); return set; } bool PropertyStore::SetUint8Property(const std::string& name, uint8 value, Error *error) { VLOG(2) << "Setting " << name << " as a uint8."; bool set = (ContainsKey(uint8_properties_, name) && uint8_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W uint8."); return set; } bool PropertyStore::SetUint16Property(const std::string& name, uint16 value, Error *error) { VLOG(2) << "Setting " << name << " as a uint16."; bool set = (ContainsKey(uint16_properties_, name) && uint16_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W uint16."); return set; } bool PropertyStore::SetUint32Property(const std::string& name, uint32 value, Error *error) { VLOG(2) << "Setting " << name << " as a uint32."; bool set = (ContainsKey(uint32_properties_, name) && uint32_properties_[name]->Set(value)); if (!set && error) error->Populate(Error::kInvalidArguments, name + " is not a R/W uint32."); return set; } PropertyConstIterator PropertyStore::GetBoolPropertiesIter() { return PropertyConstIterator(bool_properties_); } PropertyConstIterator PropertyStore::GetInt16PropertiesIter() { return PropertyConstIterator(int16_properties_); } PropertyConstIterator PropertyStore::GetInt32PropertiesIter() { return PropertyConstIterator(int32_properties_); } PropertyConstIterator PropertyStore::GetStringPropertiesIter() { return PropertyConstIterator(string_properties_); } PropertyConstIterator PropertyStore::GetStringmapPropertiesIter() { return PropertyConstIterator(stringmap_properties_); } PropertyConstIterator PropertyStore::GetStringsPropertiesIter() { return PropertyConstIterator(strings_properties_); } PropertyConstIterator PropertyStore::GetStrIntPairPropertiesIter() { return PropertyConstIterator(strintpair_properties_); } PropertyConstIterator PropertyStore::GetUint8PropertiesIter() { return PropertyConstIterator(uint8_properties_); } PropertyConstIterator PropertyStore::GetUint16PropertiesIter() { return PropertyConstIterator(uint16_properties_); } PropertyConstIterator PropertyStore::GetUint32PropertiesIter() { return PropertyConstIterator(uint32_properties_); } void PropertyStore::RegisterBool(const string &name, bool *prop) { bool_properties_[name] = BoolAccessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstBool(const string &name, const bool *prop) { bool_properties_[name] = BoolAccessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterInt16(const string &name, int16 *prop) { int16_properties_[name] = Int16Accessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstInt16(const string &name, const int16 *prop) { int16_properties_[name] = Int16Accessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterInt32(const string &name, int32 *prop) { int32_properties_[name] = Int32Accessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstInt32(const string &name, const int32 *prop) { int32_properties_[name] = Int32Accessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterString(const string &name, string *prop) { string_properties_[name] = StringAccessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstString(const string &name, const string *prop) { string_properties_[name] = StringAccessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterStringmap(const string &name, Stringmap *prop) { stringmap_properties_[name] = StringmapAccessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstStringmap(const string &name, const Stringmap *prop) { stringmap_properties_[name] = StringmapAccessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterStrings(const string &name, Strings *prop) { strings_properties_[name] = StringsAccessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstStrings(const string &name, const Strings *prop) { strings_properties_[name] = StringsAccessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterUint8(const string &name, uint8 *prop) { uint8_properties_[name] = Uint8Accessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstUint8(const string &name, const uint8 *prop) { uint8_properties_[name] = Uint8Accessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterUint16(const std::string &name, uint16 *prop) { uint16_properties_[name] = Uint16Accessor(new PropertyAccessor(prop)); } void PropertyStore::RegisterConstUint16(const string &name, const uint16 *prop) { uint16_properties_[name] = Uint16Accessor(new ConstPropertyAccessor(prop)); } void PropertyStore::RegisterDerivedBool(const std::string &name, const BoolAccessor &accessor) { bool_properties_[name] = accessor; } void PropertyStore::RegisterDerivedString(const std::string &name, const StringAccessor &accessor) { string_properties_[name] = accessor; } void PropertyStore::RegisterDerivedStrings(const std::string &name, const StringsAccessor &accessor) { strings_properties_[name] = accessor; } void PropertyStore::RegisterDerivedStringmaps(const std::string &name, const StringmapsAccessor &acc) { stringmaps_properties_[name] = acc; } void PropertyStore::RegisterDerivedStrIntPair(const std::string &name, const StrIntPairAccessor &acc) { strintpair_properties_[name] = acc; } } // namespace shill