removed many deprecated interfaces. made variant type an abstractproperty
[profile/ivi/automotive-message-broker.git] / plugins / dbus / 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 "dbusinterfacemanager.h"
24 #include "debugout.h"
25 #include "listplusplus.h"
26
27 extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, map<string, string> config)
28 {
29         return new DBusSinkManager(routingengine, config);
30 }
31
32 DBusSink::DBusSink(string propertyName, AbstractRoutingEngine* engine, GDBusConnection* connection, map<string, string> config = map<string, string>())
33         :AbstractDBusInterface("org.automotive."+propertyName, propertyName, connection),
34           AbstractSink(engine, config)
35 {
36         AbstractDBusInterface::re = engine;
37
38         int timeout = 60;
39
40         if(config.find("frequency") != config.end())
41         {
42                 int t = boost::lexical_cast<int>(config["frequency"]);
43
44                 timeout = 1000 / t;
45         }
46
47         setTimeout(timeout);
48 }
49
50 void DBusSink::supportedChanged(const PropertyList &supportedProperties)
51 {
52         startRegistration();
53
54         for(auto itr : propertyDBusMap)
55         {
56                 if(contains(supportedProperties, itr->ambPropertyName()))
57                 {
58                         PropertyInfo info = re->getPropertyInfo(itr->ambPropertyName(), mSourceFilter);
59
60                         if (!info.isValid() || !contains(info.zones(), zoneFilter))
61                         {
62                                 continue;
63                         }
64
65                         VariantType* prop = itr;
66                         prop->setSourceFilter(mSourceFilter);
67                         prop->setZoneFilter(zoneFilter);
68                         prop->initialize();
69                         VehicleProperty::Property p = itr->ambPropertyName();
70                         routingEngine->subscribeToProperty(p, mSourceFilter, this);
71                         addProperty(prop);
72                         supported = true;
73                         mTime = amb::currentTime();
74                 }
75         }
76 }
77
78 void DBusSink::propertyChanged(AbstractPropertyType *value)
79 {
80         VehicleProperty::Property property = value->name;
81
82         if( value->zone != zoneFilter)
83                 return;
84
85         for(auto i : propertyDBusMap)
86         {
87                 if(i->ambPropertyName() == property)
88                 {
89                         AbstractProperty* prop = i;
90                         mTime = value->timestamp;
91                         prop->updateValue(value);
92                         updateValue(prop);
93                 }
94         }
95 }
96
97 const string DBusSink::uuid()
98 {
99         return "c2e6cafa-eef5-4b8a-99a0-0f2c9be1057d";
100 }
101
102 DBusSinkManager::DBusSinkManager(AbstractRoutingEngine *engine, map<string, string> config) :
103         AbstractSinkManager(engine, config),
104         manager(nullptr)
105 {
106         manager = new DBusInterfaceManager(engine, config);
107 }
108
109 DBusSinkManager::~DBusSinkManager()
110 {
111         if(manager){
112                 // delete manager; <-- currently AbstractSink* instances are deleted in Core::~Core()
113                 manager = nullptr;
114         }
115 }