summaryrefslogtreecommitdiff
path: root/service_property_change_notifier.h
blob: d60ee5e20fccc5301c66e26e9d0bb6a2bf3304a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// Copyright (C) 2014 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
#define SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_

#include <memory>
#include <string>
#include <vector>

#include <base/callback.h>
#include <base/macros.h>

#include "shill/accessor_interface.h"

namespace shill {

class PropertyObserverInterface;
class ServiceAdaptorInterface;

// A collection of property observers used by objects to deliver
// property change notifications.  This object holds an un-owned
// pointer to the ServiceAdaptor to which notifications should be
// posted.  This pointer must be valid for the lifetime of this
// property change notifier.
class ServicePropertyChangeNotifier {
 public:
  explicit ServicePropertyChangeNotifier(ServiceAdaptorInterface* adaptor);
  virtual ~ServicePropertyChangeNotifier();

  virtual void AddBoolPropertyObserver(const std::string& name,
                                       BoolAccessor accessor);
  virtual void AddUint8PropertyObserver(const std::string& name,
                                        Uint8Accessor accessor);
  virtual void AddUint16PropertyObserver(const std::string& name,
                                         Uint16Accessor accessor);
  virtual void AddUint16sPropertyObserver(const std::string& name,
                                          Uint16sAccessor accessor);
  virtual void AddUintPropertyObserver(const std::string& name,
                                       Uint32Accessor accessor);
  virtual void AddIntPropertyObserver(const std::string& name,
                                      Int32Accessor accessor);
  virtual void AddRpcIdentifierPropertyObserver(const std::string& name,
                                                RpcIdentifierAccessor accessor);
  virtual void AddStringPropertyObserver(const std::string& name,
                                         StringAccessor accessor);
  virtual void AddStringmapPropertyObserver(const std::string& name,
                                            StringmapAccessor accessor);
  virtual void UpdatePropertyObservers();

 private:
  // Redirects templated calls to a value reference to a by-copy version.
  void BoolPropertyUpdater(const std::string& name, const bool& value);
  void Uint8PropertyUpdater(const std::string& name, const uint8_t& value);
  void Uint16PropertyUpdater(const std::string& name, const uint16_t& value);
  void Uint32PropertyUpdater(const std::string& name, const uint32_t& value);
  void Int32PropertyUpdater(const std::string& name, const int32_t& value);

  ServiceAdaptorInterface* rpc_adaptor_;
  std::vector<std::unique_ptr<PropertyObserverInterface>> property_observers_;

  DISALLOW_COPY_AND_ASSIGN(ServicePropertyChangeNotifier);
};

}  // namespace shill

#endif  // SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_