dbus plugin updates
[profile/ivi/automotive-message-broker.git] / plugins / dbus / abstractproperty.h
1 /*
2 Copyright (C) 2012 Intel Corporation
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #ifndef ABSTRACTPROPERTY_H
20 #define ABSTRACTPROPERTY_H
21
22 #include <string>
23 #include <functional>
24 #include <boost/any.hpp>
25 #include <glib.h>
26
27 #include "debugout.h"
28
29 class AbstractDBusInterface;
30
31 using namespace std;
32
33 typedef function<void (boost::any)> SetterFunc;
34
35 class AbstractProperty
36 {
37
38 public:
39
40         enum Access {
41                 Read,
42                 Write,
43                 ReadWrite
44         };
45
46         AbstractProperty(string propertyName, string signature, Access access, AbstractDBusInterface* interface);
47         
48         virtual void setSetterFunction(SetterFunc setterFunc)
49         {
50                 mSetterFunc = setterFunc;
51         }
52         
53         virtual string signature()
54         {
55                 return mSignature;
56         }
57         
58         virtual string name() 
59         {
60                 return mPropertyName;
61         }
62
63         virtual Access access()
64         {
65                 return mAccess;
66         }
67         
68         virtual GVariant* toGVariant() = 0;
69         virtual void fromGVariant(GVariant *value) = 0;
70
71         template<typename T>
72         void setValue(T val)
73         {
74                 mValue = val;
75                 updateValue();
76         }
77
78         template<typename T>
79         T value()
80         {
81                 return boost::any_cast<T>(mValue);
82         }
83         
84 protected: ///methods:
85
86         void updateValue();
87         
88 protected:
89         
90         boost::any mValue;
91         string mPropertyName;
92         string mSignature;
93         SetterFunc mSetterFunc;
94         Access mAccess;
95         
96         AbstractDBusInterface* mInterface;
97 };
98
99 #endif // ABSTRACTPROPERTY_H