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 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 5 | #ifndef SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_ |
| 6 | #define SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_ |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 7 | |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 8 | #include <memory> |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 12 | #include <base/callback.h> |
Ben Chan | cc67c52 | 2014-09-03 07:19:18 -0700 | [diff] [blame] | 13 | #include <base/macros.h> |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 14 | |
| 15 | #include "shill/accessor_interface.h" |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | class PropertyObserverInterface; |
| 20 | class 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. |
| 27 | class ServicePropertyChangeNotifier { |
| 28 | public: |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 29 | explicit ServicePropertyChangeNotifier(ServiceAdaptorInterface* adaptor); |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 30 | virtual ~ServicePropertyChangeNotifier(); |
| 31 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 32 | virtual void AddBoolPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 33 | BoolAccessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 34 | virtual void AddUint8PropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 35 | Uint8Accessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 36 | virtual void AddUint16PropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 37 | Uint16Accessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 38 | virtual void AddUint16sPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 39 | Uint16sAccessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 40 | virtual void AddUintPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 41 | Uint32Accessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 42 | virtual void AddIntPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 43 | Int32Accessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 44 | virtual void AddRpcIdentifierPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 45 | RpcIdentifierAccessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 46 | virtual void AddStringPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 47 | StringAccessor accessor); |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 48 | virtual void AddStringmapPropertyObserver(const std::string& name, |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 49 | StringmapAccessor accessor); |
| 50 | virtual void UpdatePropertyObservers(); |
| 51 | |
| 52 | private: |
| 53 | // Redirects templated calls to a value reference to a by-copy version. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 54 | 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 Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 59 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 60 | ServiceAdaptorInterface* rpc_adaptor_; |
Ben Chan | cd47732 | 2014-10-17 14:19:30 -0700 | [diff] [blame] | 61 | std::vector<std::unique_ptr<PropertyObserverInterface>> property_observers_; |
Paul Stewart | 0153cf0 | 2014-06-02 11:53:36 -0700 | [diff] [blame] | 62 | |
| 63 | DISALLOW_COPY_AND_ASSIGN(ServicePropertyChangeNotifier); |
| 64 | }; |
| 65 | |
| 66 | } // namespace shill |
| 67 | |
Ben Chan | c45688b | 2014-07-02 23:50:45 -0700 | [diff] [blame] | 68 | #endif // SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_ |