Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 1 | // Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "shill/service_property_change_notifier.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <base/bind.h> |
| 10 | |
| 11 | #include "shill/adaptor_interfaces.h" |
| 12 | #include "shill/property_observer.h" |
| 13 | |
| 14 | using base::Bind; |
| 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | ServicePropertyChangeNotifier::ServicePropertyChangeNotifier( |
| 20 | ServiceAdaptorInterface *adaptor) : rpc_adaptor_(adaptor) {} |
| 21 | |
| 22 | ServicePropertyChangeNotifier::~ServicePropertyChangeNotifier() {} |
| 23 | |
| 24 | void ServicePropertyChangeNotifier::AddBoolPropertyObserver( |
| 25 | const string &name, BoolAccessor accessor) { |
| 26 | property_observers_.emplace_back( |
| 27 | new PropertyObserver<bool>( |
| 28 | accessor, |
| 29 | Bind(&ServicePropertyChangeNotifier::BoolPropertyUpdater, |
| 30 | base::Unretained(this), |
| 31 | name))); |
| 32 | } |
| 33 | |
| 34 | void ServicePropertyChangeNotifier::AddUint8PropertyObserver( |
| 35 | const string &name, Uint8Accessor accessor) { |
| 36 | property_observers_.emplace_back( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 37 | new PropertyObserver<uint8_t>( |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 38 | accessor, |
| 39 | Bind(&ServicePropertyChangeNotifier::Uint8PropertyUpdater, |
| 40 | base::Unretained(this), |
| 41 | name))); |
| 42 | } |
| 43 | |
| 44 | void ServicePropertyChangeNotifier::AddUint16PropertyObserver( |
| 45 | const string &name, Uint16Accessor accessor) { |
| 46 | property_observers_.emplace_back( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 47 | new PropertyObserver<uint16_t>( |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 48 | accessor, |
| 49 | Bind(&ServicePropertyChangeNotifier::Uint16PropertyUpdater, |
| 50 | base::Unretained(this), |
| 51 | name))); |
| 52 | } |
| 53 | |
| 54 | void ServicePropertyChangeNotifier::AddUint16sPropertyObserver( |
| 55 | const string &name, Uint16sAccessor accessor) { |
| 56 | property_observers_.emplace_back( |
| 57 | new PropertyObserver<Uint16s>( |
| 58 | accessor, |
| 59 | Bind(&ServiceAdaptorInterface::EmitUint16sChanged, |
| 60 | base::Unretained(rpc_adaptor_), |
| 61 | name))); |
| 62 | } |
| 63 | |
| 64 | void ServicePropertyChangeNotifier::AddUintPropertyObserver( |
| 65 | const string &name, Uint32Accessor accessor) { |
| 66 | property_observers_.emplace_back( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 67 | new PropertyObserver<uint32_t>( |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 68 | accessor, |
| 69 | Bind(&ServicePropertyChangeNotifier::Uint32PropertyUpdater, |
| 70 | base::Unretained(this), |
| 71 | name))); |
| 72 | } |
| 73 | |
| 74 | void ServicePropertyChangeNotifier::AddIntPropertyObserver( |
| 75 | const string &name, Int32Accessor accessor) { |
| 76 | property_observers_.emplace_back( |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 77 | new PropertyObserver<int32_t>( |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 78 | accessor, |
| 79 | Bind(&ServicePropertyChangeNotifier::Int32PropertyUpdater, |
| 80 | base::Unretained(this), |
| 81 | name))); |
| 82 | } |
| 83 | |
| 84 | void ServicePropertyChangeNotifier::AddRpcIdentifierPropertyObserver( |
| 85 | const string &name, RpcIdentifierAccessor accessor) { |
| 86 | property_observers_.emplace_back( |
| 87 | new PropertyObserver<string>( |
| 88 | accessor, |
| 89 | Bind(&ServiceAdaptorInterface::EmitRpcIdentifierChanged, |
| 90 | base::Unretained(rpc_adaptor_), |
| 91 | name))); |
| 92 | } |
| 93 | |
| 94 | void ServicePropertyChangeNotifier::AddStringPropertyObserver( |
| 95 | const string &name, StringAccessor accessor) { |
| 96 | property_observers_.emplace_back( |
| 97 | new PropertyObserver<string>( |
| 98 | accessor, |
| 99 | Bind(&ServiceAdaptorInterface::EmitStringChanged, |
| 100 | base::Unretained(rpc_adaptor_), |
| 101 | name))); |
| 102 | } |
| 103 | |
| 104 | void ServicePropertyChangeNotifier::AddStringmapPropertyObserver( |
| 105 | const string &name, StringmapAccessor accessor) { |
| 106 | property_observers_.emplace_back( |
| 107 | new PropertyObserver<Stringmap>( |
| 108 | accessor, |
| 109 | Bind(&ServiceAdaptorInterface::EmitStringmapChanged, |
| 110 | base::Unretained(rpc_adaptor_), |
| 111 | name))); |
| 112 | } |
| 113 | |
| 114 | void ServicePropertyChangeNotifier::UpdatePropertyObservers() { |
| 115 | for (const auto &observer : property_observers_) { |
| 116 | observer->Update(); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void ServicePropertyChangeNotifier::BoolPropertyUpdater(const string &name, |
| 121 | const bool &value) { |
| 122 | rpc_adaptor_->EmitBoolChanged(name, value); |
| 123 | } |
| 124 | |
| 125 | void ServicePropertyChangeNotifier::Uint8PropertyUpdater(const string &name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 126 | const uint8_t &value) { |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 127 | rpc_adaptor_->EmitUint8Changed(name, value); |
| 128 | } |
| 129 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 130 | void ServicePropertyChangeNotifier::Uint16PropertyUpdater( |
| 131 | const string &name, const uint16_t &value) { |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 132 | rpc_adaptor_->EmitUint16Changed(name, value); |
| 133 | } |
| 134 | |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 135 | void ServicePropertyChangeNotifier::Uint32PropertyUpdater( |
| 136 | const string &name, const uint32_t &value) { |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 137 | rpc_adaptor_->EmitUintChanged(name, value); |
| 138 | } |
| 139 | |
| 140 | void ServicePropertyChangeNotifier::Int32PropertyUpdater(const string &name, |
Ben Chan | 7fab897 | 2014-08-10 17:14:46 -0700 | [diff] [blame] | 141 | const int32_t &value) { |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 142 | rpc_adaptor_->EmitIntChanged(name, value); |
| 143 | } |
| 144 | |
| 145 | } // namespace shill |