Home | History | Annotate | Download | only in shill
      1 //
      2 // Copyright (C) 2012 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/service_under_test.h"
     18 
     19 #include <string>
     20 
     21 #include "shill/mock_adaptors.h"
     22 #include "shill/property_accessor.h"
     23 
     24 using std::string;
     25 
     26 namespace shill {
     27 
     28 // static
     29 const char ServiceUnderTest::kKeyValueStoreProperty[] = "key_value_store";
     30 const char ServiceUnderTest::kRpcId[] = "/mock_device_rpc";
     31 const char ServiceUnderTest::kStringsProperty[] = "strings";
     32 const char ServiceUnderTest::kStorageId[] = "service";
     33 
     34 ServiceUnderTest::ServiceUnderTest(ControlInterface* control_interface,
     35                                    EventDispatcher* dispatcher,
     36                                    Metrics* metrics,
     37                                    Manager* manager)
     38     : Service(control_interface, dispatcher, metrics, manager,
     39               Technology::kUnknown) {
     40   mutable_store()->RegisterStrings(kStringsProperty, &strings_);
     41   mutable_store()->RegisterDerivedKeyValueStore(
     42       kKeyValueStoreProperty,
     43       KeyValueStoreAccessor(
     44           new CustomAccessor<ServiceUnderTest, KeyValueStore>(
     45               this, &ServiceUnderTest::GetKeyValueStore,
     46               &ServiceUnderTest::SetKeyValueStore)));
     47 }
     48 
     49 ServiceUnderTest::~ServiceUnderTest() {}
     50 
     51 string ServiceUnderTest::GetRpcIdentifier() const {
     52   return ServiceMockAdaptor::kRpcId;
     53 }
     54 
     55 string ServiceUnderTest::GetDeviceRpcId(Error* /*error*/) const {
     56   return kRpcId;
     57 }
     58 
     59 string ServiceUnderTest::GetStorageIdentifier() const { return kStorageId; }
     60 
     61 bool ServiceUnderTest::SetKeyValueStore(
     62     const KeyValueStore& value, Error* error) {
     63   key_value_store_.Clear();
     64   key_value_store_.CopyFrom(value);
     65   return true;
     66 }
     67 
     68 KeyValueStore ServiceUnderTest::GetKeyValueStore(Error* error) {
     69   return key_value_store_;
     70 }
     71 
     72 }  // namespace shill
     73