a90d9ef405c5646d559704814e2c3ca2933d103b
[profile/ivi/automotive-message-broker.git] / plugins / dbus / varianttype.h
1 #ifndef _VARIANT_TYPE_H_
2 #define _VARIANT_TYPE_H_
3
4 #include "abstractpropertytype.h"
5 #include "abstractroutingengine.h"
6
7 class AbstractDBusInterface;
8
9 class VariantType: public AbstractPropertyType
10 {
11 public:
12
13         typedef function<void (boost::any)> SetterFunc;
14
15         enum Access {
16                 Read,
17                 Write,
18                 ReadWrite
19         };
20
21         VariantType(AbstractRoutingEngine* re, VehicleProperty::Property ambPropertyName, string propertyName, Access access);
22
23         void initialize();
24
25         GVariant* toVariant();
26         void fromVariant(GVariant *value);
27
28         bool operator == (VariantType & other)
29         {
30                 return (other.dbusName() == dbusName()
31                                 && other.ambPropertyName() == ambPropertyName()
32                                 && other.sourceFilter() == sourceFilter()
33                                 && other.zoneFilter() == zoneFilter());
34         }
35
36         virtual void setSetterFunction(SetterFunc setterFunc)
37         {
38                 mSetterFunc = setterFunc;
39         }
40
41         virtual std::string dbusName()
42         {
43                 return mPropertyName;
44         }
45
46         virtual std::string ambPropertyName()
47         {
48                 return name;
49         }
50
51         virtual Access access()
52         {
53                 return mAccess;
54         }
55
56         void setSourceFilter(std::string filter)
57         {
58                 sourceUuid = filter;
59         }
60         void setZoneFilter(Zone::Type z)
61         {
62                 zone = z;
63         }
64
65         std::string sourceFilter() { return sourceUuid; }
66         Zone::Type zoneFilter() { return zone; }
67
68         virtual void setValue(AbstractPropertyType* val)
69         {
70                 if(!val)
71                         return;
72
73                 mValue->quickCopy(val);
74
75                 if(mUpdateFrequency == 0)
76                 {
77                         PropertyInfo info = routingEngine->getPropertyInfo(mValue->name, mValue->sourceUuid);
78
79                         if(info.isValid())
80                                 mUpdateFrequency = info.updateFrequency();
81                         else
82                                 mUpdateFrequency = -1;
83                 }
84         }
85
86         virtual void updateValue(AbstractPropertyType* val)
87         {
88                 setValue(val);
89         }
90
91         int updateFrequency()
92         {
93                 return mUpdateFrequency;
94         }
95
96         AbstractPropertyType* value()
97         {
98                 return mValue;
99         }
100
101         std::string toString() const
102         {
103                 return "";
104         }
105
106         void fromString(std::string str)
107         {
108
109         }
110
111         AbstractPropertyType * copy()
112         {
113                 return new VariantType(routingEngine, name, mPropertyName, mAccess);
114         }
115
116 protected:
117         int mUpdateFrequency;
118         AbstractRoutingEngine* routingEngine;
119         string mPropertyName;
120         SetterFunc mSetterFunc;
121         Access mAccess;
122         AbstractPropertyType* mValue;
123         AbstractDBusInterface* mInterface;
124
125 private:
126         void asyncReply(AsyncPropertyReply*);
127         bool mInitialized;
128
129
130 };
131
132 typedef VariantType AbstractProperty;
133
134 #endif