blob: 57152757517ee49e8cc5ec19013828a8ff92a2e2 [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
8#include <string>
9#include <vector>
10
Paul Stewart0153cf02014-06-02 11:53:36 -070011#include <base/callback.h>
Ben Chancc67c522014-09-03 07:19:18 -070012#include <base/macros.h>
Paul Stewart0153cf02014-06-02 11:53:36 -070013#include <base/memory/scoped_ptr.h>
14
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:
Alex Vakulenko8a532292014-06-16 17:18:44 -070029 explicit ServicePropertyChangeNotifier(ServiceAdaptorInterface *adaptor);
Paul Stewart0153cf02014-06-02 11:53:36 -070030 virtual ~ServicePropertyChangeNotifier();
31
32 virtual void AddBoolPropertyObserver(const std::string &name,
33 BoolAccessor accessor);
34 virtual void AddUint8PropertyObserver(const std::string &name,
35 Uint8Accessor accessor);
36 virtual void AddUint16PropertyObserver(const std::string &name,
37 Uint16Accessor accessor);
38 virtual void AddUint16sPropertyObserver(const std::string &name,
39 Uint16sAccessor accessor);
40 virtual void AddUintPropertyObserver(const std::string &name,
41 Uint32Accessor accessor);
42 virtual void AddIntPropertyObserver(const std::string &name,
43 Int32Accessor accessor);
44 virtual void AddRpcIdentifierPropertyObserver(const std::string &name,
45 RpcIdentifierAccessor accessor);
46 virtual void AddStringPropertyObserver(const std::string &name,
47 StringAccessor accessor);
48 virtual void AddStringmapPropertyObserver(const std::string &name,
49 StringmapAccessor accessor);
50 virtual void UpdatePropertyObservers();
51
52 private:
53 // Redirects templated calls to a value reference to a by-copy version.
54 void BoolPropertyUpdater(const std::string &name, const bool &value);
Ben Chan7fab8972014-08-10 17:14:46 -070055 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
60 ServiceAdaptorInterface *rpc_adaptor_;
61 std::vector<scoped_ptr<PropertyObserverInterface>> property_observers_;
62
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_