1 //
2 // Copyright (C) 2014 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #ifndef SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
18 #define SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
19 
20 #include <memory>
21 #include <string>
22 #include <vector>
23 
24 #include <base/callback.h>
25 #include <base/macros.h>
26 
27 #include "shill/accessor_interface.h"
28 
29 namespace shill {
30 
31 class PropertyObserverInterface;
32 class ServiceAdaptorInterface;
33 
34 // A collection of property observers used by objects to deliver
35 // property change notifications.  This object holds an un-owned
36 // pointer to the ServiceAdaptor to which notifications should be
37 // posted.  This pointer must be valid for the lifetime of this
38 // property change notifier.
39 class ServicePropertyChangeNotifier {
40  public:
41   explicit ServicePropertyChangeNotifier(ServiceAdaptorInterface* adaptor);
42   virtual ~ServicePropertyChangeNotifier();
43 
44   virtual void AddBoolPropertyObserver(const std::string& name,
45                                        BoolAccessor accessor);
46   virtual void AddUint8PropertyObserver(const std::string& name,
47                                         Uint8Accessor accessor);
48   virtual void AddUint16PropertyObserver(const std::string& name,
49                                          Uint16Accessor accessor);
50   virtual void AddUint16sPropertyObserver(const std::string& name,
51                                           Uint16sAccessor accessor);
52   virtual void AddUintPropertyObserver(const std::string& name,
53                                        Uint32Accessor accessor);
54   virtual void AddIntPropertyObserver(const std::string& name,
55                                       Int32Accessor accessor);
56   virtual void AddRpcIdentifierPropertyObserver(const std::string& name,
57                                                 RpcIdentifierAccessor accessor);
58   virtual void AddStringPropertyObserver(const std::string& name,
59                                          StringAccessor accessor);
60   virtual void AddStringmapPropertyObserver(const std::string& name,
61                                             StringmapAccessor accessor);
62   virtual void UpdatePropertyObservers();
63 
64  private:
65   // Redirects templated calls to a value reference to a by-copy version.
66   void BoolPropertyUpdater(const std::string& name, const bool& value);
67   void Uint8PropertyUpdater(const std::string& name, const uint8_t& value);
68   void Uint16PropertyUpdater(const std::string& name, const uint16_t& value);
69   void Uint32PropertyUpdater(const std::string& name, const uint32_t& value);
70   void Int32PropertyUpdater(const std::string& name, const int32_t& value);
71 
72   ServiceAdaptorInterface* rpc_adaptor_;
73   std::vector<std::unique_ptr<PropertyObserverInterface>> property_observers_;
74 
75   DISALLOW_COPY_AND_ASSIGN(ServicePropertyChangeNotifier);
76 };
77 
78 }  // namespace shill
79 
80 #endif  // SHILL_SERVICE_PROPERTY_CHANGE_NOTIFIER_H_
81