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