blob: 1339ea8ba465be314a725de735cccbdb2937b81d [file] [log] [blame]
Paul Stewart0153cf02014-06-02 11:53:36 -07001// 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
14using base::Bind;
15using std::string;
16
17namespace shill {
18
19ServicePropertyChangeNotifier::ServicePropertyChangeNotifier(
20 ServiceAdaptorInterface *adaptor) : rpc_adaptor_(adaptor) {}
21
22ServicePropertyChangeNotifier::~ServicePropertyChangeNotifier() {}
23
24void 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
34void ServicePropertyChangeNotifier::AddUint8PropertyObserver(
35 const string &name, Uint8Accessor accessor) {
36 property_observers_.emplace_back(
Ben Chan7fab8972014-08-10 17:14:46 -070037 new PropertyObserver<uint8_t>(
Paul Stewart0153cf02014-06-02 11:53:36 -070038 accessor,
39 Bind(&ServicePropertyChangeNotifier::Uint8PropertyUpdater,
40 base::Unretained(this),
41 name)));
42}
43
44void ServicePropertyChangeNotifier::AddUint16PropertyObserver(
45 const string &name, Uint16Accessor accessor) {
46 property_observers_.emplace_back(
Ben Chan7fab8972014-08-10 17:14:46 -070047 new PropertyObserver<uint16_t>(
Paul Stewart0153cf02014-06-02 11:53:36 -070048 accessor,
49 Bind(&ServicePropertyChangeNotifier::Uint16PropertyUpdater,
50 base::Unretained(this),
51 name)));
52}
53
54void 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
64void ServicePropertyChangeNotifier::AddUintPropertyObserver(
65 const string &name, Uint32Accessor accessor) {
66 property_observers_.emplace_back(
Ben Chan7fab8972014-08-10 17:14:46 -070067 new PropertyObserver<uint32_t>(
Paul Stewart0153cf02014-06-02 11:53:36 -070068 accessor,
69 Bind(&ServicePropertyChangeNotifier::Uint32PropertyUpdater,
70 base::Unretained(this),
71 name)));
72}
73
74void ServicePropertyChangeNotifier::AddIntPropertyObserver(
75 const string &name, Int32Accessor accessor) {
76 property_observers_.emplace_back(
Ben Chan7fab8972014-08-10 17:14:46 -070077 new PropertyObserver<int32_t>(
Paul Stewart0153cf02014-06-02 11:53:36 -070078 accessor,
79 Bind(&ServicePropertyChangeNotifier::Int32PropertyUpdater,
80 base::Unretained(this),
81 name)));
82}
83
84void 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
94void 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
104void 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
114void ServicePropertyChangeNotifier::UpdatePropertyObservers() {
115 for (const auto &observer : property_observers_) {
116 observer->Update();
117 }
118}
119
120void ServicePropertyChangeNotifier::BoolPropertyUpdater(const string &name,
121 const bool &value) {
122 rpc_adaptor_->EmitBoolChanged(name, value);
123}
124
125void ServicePropertyChangeNotifier::Uint8PropertyUpdater(const string &name,
Ben Chan7fab8972014-08-10 17:14:46 -0700126 const uint8_t &value) {
Paul Stewart0153cf02014-06-02 11:53:36 -0700127 rpc_adaptor_->EmitUint8Changed(name, value);
128}
129
Ben Chan7fab8972014-08-10 17:14:46 -0700130void ServicePropertyChangeNotifier::Uint16PropertyUpdater(
131 const string &name, const uint16_t &value) {
Paul Stewart0153cf02014-06-02 11:53:36 -0700132 rpc_adaptor_->EmitUint16Changed(name, value);
133}
134
Ben Chan7fab8972014-08-10 17:14:46 -0700135void ServicePropertyChangeNotifier::Uint32PropertyUpdater(
136 const string &name, const uint32_t &value) {
Paul Stewart0153cf02014-06-02 11:53:36 -0700137 rpc_adaptor_->EmitUintChanged(name, value);
138}
139
140void ServicePropertyChangeNotifier::Int32PropertyUpdater(const string &name,
Ben Chan7fab8972014-08-10 17:14:46 -0700141 const int32_t &value) {
Paul Stewart0153cf02014-06-02 11:53:36 -0700142 rpc_adaptor_->EmitIntChanged(name, value);
143}
144
145} // namespace shill