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 "shill/service_property_change_notifier.h"
18
19 #include <string>
20
21 #include <base/bind.h>
22
23 #include "shill/adaptor_interfaces.h"
24 #include "shill/property_observer.h"
25
26 using base::Bind;
27 using std::string;
28
29 namespace shill {
30
ServicePropertyChangeNotifier(ServiceAdaptorInterface * adaptor)31 ServicePropertyChangeNotifier::ServicePropertyChangeNotifier(
32 ServiceAdaptorInterface* adaptor) : rpc_adaptor_(adaptor) {}
33
~ServicePropertyChangeNotifier()34 ServicePropertyChangeNotifier::~ServicePropertyChangeNotifier() {}
35
AddBoolPropertyObserver(const string & name,BoolAccessor accessor)36 void ServicePropertyChangeNotifier::AddBoolPropertyObserver(
37 const string& name, BoolAccessor accessor) {
38 property_observers_.emplace_back(
39 new PropertyObserver<bool>(
40 accessor,
41 Bind(&ServicePropertyChangeNotifier::BoolPropertyUpdater,
42 base::Unretained(this),
43 name)));
44 }
45
AddUint8PropertyObserver(const string & name,Uint8Accessor accessor)46 void ServicePropertyChangeNotifier::AddUint8PropertyObserver(
47 const string& name, Uint8Accessor accessor) {
48 property_observers_.emplace_back(
49 new PropertyObserver<uint8_t>(
50 accessor,
51 Bind(&ServicePropertyChangeNotifier::Uint8PropertyUpdater,
52 base::Unretained(this),
53 name)));
54 }
55
AddUint16PropertyObserver(const string & name,Uint16Accessor accessor)56 void ServicePropertyChangeNotifier::AddUint16PropertyObserver(
57 const string& name, Uint16Accessor accessor) {
58 property_observers_.emplace_back(
59 new PropertyObserver<uint16_t>(
60 accessor,
61 Bind(&ServicePropertyChangeNotifier::Uint16PropertyUpdater,
62 base::Unretained(this),
63 name)));
64 }
65
AddUint16sPropertyObserver(const string & name,Uint16sAccessor accessor)66 void ServicePropertyChangeNotifier::AddUint16sPropertyObserver(
67 const string& name, Uint16sAccessor accessor) {
68 property_observers_.emplace_back(
69 new PropertyObserver<Uint16s>(
70 accessor,
71 Bind(&ServiceAdaptorInterface::EmitUint16sChanged,
72 base::Unretained(rpc_adaptor_),
73 name)));
74 }
75
AddUintPropertyObserver(const string & name,Uint32Accessor accessor)76 void ServicePropertyChangeNotifier::AddUintPropertyObserver(
77 const string& name, Uint32Accessor accessor) {
78 property_observers_.emplace_back(
79 new PropertyObserver<uint32_t>(
80 accessor,
81 Bind(&ServicePropertyChangeNotifier::Uint32PropertyUpdater,
82 base::Unretained(this),
83 name)));
84 }
85
AddIntPropertyObserver(const string & name,Int32Accessor accessor)86 void ServicePropertyChangeNotifier::AddIntPropertyObserver(
87 const string& name, Int32Accessor accessor) {
88 property_observers_.emplace_back(
89 new PropertyObserver<int32_t>(
90 accessor,
91 Bind(&ServicePropertyChangeNotifier::Int32PropertyUpdater,
92 base::Unretained(this),
93 name)));
94 }
95
AddRpcIdentifierPropertyObserver(const string & name,RpcIdentifierAccessor accessor)96 void ServicePropertyChangeNotifier::AddRpcIdentifierPropertyObserver(
97 const string& name, RpcIdentifierAccessor accessor) {
98 property_observers_.emplace_back(
99 new PropertyObserver<string>(
100 accessor,
101 Bind(&ServiceAdaptorInterface::EmitRpcIdentifierChanged,
102 base::Unretained(rpc_adaptor_),
103 name)));
104 }
105
AddStringPropertyObserver(const string & name,StringAccessor accessor)106 void ServicePropertyChangeNotifier::AddStringPropertyObserver(
107 const string& name, StringAccessor accessor) {
108 property_observers_.emplace_back(
109 new PropertyObserver<string>(
110 accessor,
111 Bind(&ServiceAdaptorInterface::EmitStringChanged,
112 base::Unretained(rpc_adaptor_),
113 name)));
114 }
115
AddStringmapPropertyObserver(const string & name,StringmapAccessor accessor)116 void ServicePropertyChangeNotifier::AddStringmapPropertyObserver(
117 const string& name, StringmapAccessor accessor) {
118 property_observers_.emplace_back(
119 new PropertyObserver<Stringmap>(
120 accessor,
121 Bind(&ServiceAdaptorInterface::EmitStringmapChanged,
122 base::Unretained(rpc_adaptor_),
123 name)));
124 }
125
UpdatePropertyObservers()126 void ServicePropertyChangeNotifier::UpdatePropertyObservers() {
127 for (const auto& observer : property_observers_) {
128 observer->Update();
129 }
130 }
131
BoolPropertyUpdater(const string & name,const bool & value)132 void ServicePropertyChangeNotifier::BoolPropertyUpdater(const string& name,
133 const bool& value) {
134 rpc_adaptor_->EmitBoolChanged(name, value);
135 }
136
Uint8PropertyUpdater(const string & name,const uint8_t & value)137 void ServicePropertyChangeNotifier::Uint8PropertyUpdater(const string& name,
138 const uint8_t& value) {
139 rpc_adaptor_->EmitUint8Changed(name, value);
140 }
141
Uint16PropertyUpdater(const string & name,const uint16_t & value)142 void ServicePropertyChangeNotifier::Uint16PropertyUpdater(
143 const string& name, const uint16_t& value) {
144 rpc_adaptor_->EmitUint16Changed(name, value);
145 }
146
Uint32PropertyUpdater(const string & name,const uint32_t & value)147 void ServicePropertyChangeNotifier::Uint32PropertyUpdater(
148 const string& name, const uint32_t& value) {
149 rpc_adaptor_->EmitUintChanged(name, value);
150 }
151
Int32PropertyUpdater(const string & name,const int32_t & value)152 void ServicePropertyChangeNotifier::Int32PropertyUpdater(const string& name,
153 const int32_t& value) {
154 rpc_adaptor_->EmitIntChanged(name, value);
155 }
156
157 } // namespace shill
158