removed many deprecated interfaces. made variant type an abstractproperty
[profile/ivi/automotive-message-broker.git] / plugins / common / dbusplugin.cpp
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 #include <boost/lexical_cast.hpp>
20
21 #include "dbusplugin.h"
22 #include "abstractroutingengine.h"
23 #include "debugout.h"
24 #include "listplusplus.h"
25
26 DBusSink::DBusSink(string propertyName, AbstractRoutingEngine* engine, GDBusConnection* connection, map<string, string> config = map<string, string>())
27         :AbstractDBusInterface("org.automotive."+propertyName, propertyName, connection),
28           AbstractSink(engine, config)
29 {
30         AbstractDBusInterface::re = engine;
31
32         int timeout = 60;
33
34         if(config.find("frequency") != config.end())
35         {
36                 int t = boost::lexical_cast<int>(config["frequency"]);
37
38                 timeout = 1000 / t;
39         }
40
41         setTimeout(timeout);
42 }
43
44 void DBusSink::supportedChanged(const PropertyList &supportedProperties)
45 {
46         startRegistration();
47
48         for(auto itr : propertyDBusMap)
49         {
50                 if(contains(supportedProperties, itr->ambPropertyName()))
51                 {
52                         PropertyInfo info = re->getPropertyInfo(itr->ambPropertyName(), mSourceFilter);
53
54                         if (!info.isValid() || !contains(info.zones(), zoneFilter))
55                         {
56                                 continue;
57                         }
58
59                         VariantType* prop = itr;
60                         prop->setSourceFilter(mSourceFilter);
61                         prop->setZoneFilter(zoneFilter);
62                         prop->initialize();
63                         VehicleProperty::Property p = itr->ambPropertyName();
64                         routingEngine->subscribeToProperty(p, mSourceFilter, this);
65                         addProperty(prop);
66                         supported = true;
67                         mTime = amb::currentTime();
68                 }
69         }
70 }
71
72 void DBusSink::propertyChanged(AbstractPropertyType *value)
73 {
74         VehicleProperty::Property property = value->name;
75
76         if( value->zone != zoneFilter)
77                 return;
78
79         for(auto i : propertyDBusMap)
80         {
81                 if(i->ambPropertyName() == property)
82                 {
83                         VariantType* prop = i;
84                         mTime = value->timestamp;
85                         prop->updateValue(value);
86                         updateValue(prop);
87                 }
88         }
89 }
90
91 const string DBusSink::uuid()
92 {
93         return "c2e6cafa-eef5-4b8a-99a0-0f2c9be1057d";
94 }