blob: 8aabfe001169879f64d0f08dab0878a9bb7f6568 [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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
6#define SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
Paul Stewart0153cf02014-06-02 11:53:36 -07007
Ben Chancd477322014-10-17 14:19:30 -07008#include <memory>
Paul Stewart0153cf02014-06-02 11:53:36 -07009#include <string>
10#include <vector>
11
Paul Stewart0153cf02014-06-02 11:53:36 -070012#include <base/callback.h>
Ben Chancc67c522014-09-03 07:19:18 -070013#include <base/macros.h>
Paul Stewart0153cf02014-06-02 11:53:36 -070014
15#include "shill/accessor_interface.h"
16
17namespace shill {
18
19class PropertyObserverInterface;
20class ServiceAdaptorInterface;
21
22// A collection of property observers used by objects to deliver
23// property change notifications. This object holds an un-owned
24// pointer to the ServiceAdaptor to which notifications should be
25// posted. This pointer must be valid for the lifetime of this
26// property change notifier.
27class ServicePropertyChangeNotifier {
28 public:
Paul Stewart1a212a62015-06-16 13:13:10 -070029 explicit ServicePropertyChangeNotifier(ServiceAdaptorInterface* adaptor);
Paul Stewart0153cf02014-06-02 11:53:36 -070030 virtual ~ServicePropertyChangeNotifier();
31
Paul Stewart1a212a62015-06-16 13:13:10 -070032 virtual void AddBoolPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070033 BoolAccessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070034 virtual void AddUint8PropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070035 Uint8Accessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070036 virtual void AddUint16PropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070037 Uint16Accessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070038 virtual void AddUint16sPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070039 Uint16sAccessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070040 virtual void AddUintPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070041 Uint32Accessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070042 virtual void AddIntPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070043 Int32Accessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070044 virtual void AddRpcIdentifierPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070045 RpcIdentifierAccessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070046 virtual void AddStringPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070047 StringAccessor accessor);
Paul Stewart1a212a62015-06-16 13:13:10 -070048 virtual void AddStringmapPropertyObserver(const std::string& name,
Paul Stewart0153cf02014-06-02 11:53:36 -070049 StringmapAccessor accessor);
50 virtual void UpdatePropertyObservers();
51
52 private:
53 // Redirects templated calls to a value reference to a by-copy version.
Paul Stewart1a212a62015-06-16 13:13:10 -070054 void BoolPropertyUpdater(const std::string& name, const bool& value);
55 void Uint8PropertyUpdater(const std::string& name, const uint8_t& value);
56 void Uint16PropertyUpdater(const std::string& name, const uint16_t& value);
57 void Uint32PropertyUpdater(const std::string& name, const uint32_t& value);
58 void Int32PropertyUpdater(const std::string& name, const int32_t& value);
Paul Stewart0153cf02014-06-02 11:53:36 -070059
Paul Stewart1a212a62015-06-16 13:13:10 -070060 ServiceAdaptorInterface* rpc_adaptor_;
Ben Chancd477322014-10-17 14:19:30 -070061 std::vector<std::unique_ptr<PropertyObserverInterface>> property_observers_;
Paul Stewart0153cf02014-06-02 11:53:36 -070062
63 DISALLOW_COPY_AND_ASSIGN(ServicePropertyChangeNotifier);
64};
65
66} // namespace shill
67
Ben Chanc45688b2014-07-02 23:50:45 -070068#endif // SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_