2 Copyright (C) 2012 Intel Corporation
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.
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.
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
19 #include "dbusinterfacemanager.h"
25 #include "listplusplus.h"
26 #include "automotivemanager.h"
29 #include "runningstatus.h"
30 #include "custompropertyinterface.h"
31 #include "uncategorizedproperty.h"
32 #include "environmentproperties.h"
33 #include "vehicleinfo.h"
34 #include "maintenance.h"
36 #include "drivingsafety.h"
37 #include "personalization.h"
39 std::map<std::string, std::map<Zone::Type, bool> > getUniqueSourcesList(AbstractRoutingEngine *re, PropertyList implementedProperties)
41 std::map<std::string, std::map<Zone::Type, bool>> uniqueSourcesList;
43 for(auto itr = implementedProperties.begin(); itr != implementedProperties.end(); itr++)
45 VehicleProperty::Property property = *itr;
46 std::list<std::string> sources = re->sourcesForProperty(property);
48 for(auto itr2 = sources.begin(); itr2 != sources.end(); itr2++)
50 std::string source = *itr2;
52 PropertyInfo info = re->getPropertyInfo(property,source);
54 std::map<Zone::Type, bool> uniqueZoneList;
56 if(uniqueSourcesList.find(source) != uniqueSourcesList.end())
58 uniqueZoneList = uniqueSourcesList[source];
61 std::list<Zone::Type> zoneList = info.zones();
65 uniqueZoneList[Zone::None] = true;
68 for(auto zoneItr = zoneList.begin(); zoneItr != zoneList.end(); zoneItr++)
70 uniqueZoneList[*zoneItr] = true;
73 uniqueSourcesList[source] = uniqueZoneList;
77 return uniqueSourcesList;
81 void exportProperty(AbstractRoutingEngine *re, GDBusConnection *connection)
83 T* t = new T(re, connection);
85 /// check if we need more than one instance:
87 PropertyList implementedProperties = t->wantsProperties();
89 std::map<std::string, std::map<Zone::Type, bool> > uniqueSourcesList = getUniqueSourcesList(re, implementedProperties);
93 for(auto itr = uniqueSourcesList.begin(); itr != uniqueSourcesList.end(); itr++)
95 std::map<Zone::Type, bool> zones = (*itr).second;
97 std::string source = (*itr).first;
99 std::string objectPath = "/" + source;
101 boost::algorithm::erase_all(objectPath, "-");
103 for(auto zoneItr = zones.begin(); zoneItr != zones.end(); zoneItr++)
105 Zone::Type zone = (*zoneItr).first;
106 T* t = new T(re, connection);
107 std::stringstream fullobjectPath;
108 fullobjectPath<< objectPath << "/" << zone << "/" <<t->objectName();
109 t->setObjectPath(fullobjectPath.str());
110 t->setSourceFilter(source);
111 t->setZoneFilter(zone);
112 t->supportedChanged(re->supported());
118 template <typename T>
119 void exportProperty(VehicleProperty::Property prop, AbstractRoutingEngine *re, GDBusConnection *connection)
121 T* t = new T(prop, re, connection);
123 /// check if we need more than one instance:
125 PropertyList implementedProperties = t->wantsProperties();
127 std::map<std::string, std::map<Zone::Type, bool> > uniqueSourcesList = getUniqueSourcesList(re, implementedProperties);
131 for(auto itr = uniqueSourcesList.begin(); itr != uniqueSourcesList.end(); itr++)
133 std::map<Zone::Type, bool> zones = (*itr).second;
135 std::string source = (*itr).first;
137 std::string objectPath = "/" + source;
139 boost::algorithm::erase_all(objectPath, "-");
141 for(auto zoneItr = zones.begin(); zoneItr != zones.end(); zoneItr++)
143 Zone::Type zone = (*zoneItr).first;
144 T* t = new T(prop, re, connection);
145 std::stringstream fullobjectPath;
146 fullobjectPath<< objectPath << "/" << zone << "/" <<t->objectName();
147 t->setObjectPath(fullobjectPath.str());
148 t->setSourceFilter(source);
149 t->setZoneFilter(zone);
150 t->supportedChanged(re->supported());
157 on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
159 DBusInterfaceManager* iface = static_cast<DBusInterfaceManager*>(user_data);
161 iface->connection = connection;
163 new AutomotiveManager(connection);
166 exportProperty<AccelerationProperty>(iface->re,connection);
167 exportProperty<VehicleSpeedProperty>(iface->re, connection);
168 exportProperty<TireProperty>(iface->re, connection);
169 exportProperty<EngineSpeedProperty>(iface->re, connection);
170 exportProperty<VehiclePowerModeProperty>(iface->re, connection);
171 exportProperty<TripMeterProperty>(iface->re, connection);
172 exportProperty<TransmissionProperty>(iface->re, connection);
173 exportProperty<CruiseControlProperty>(iface->re, connection);
174 exportProperty<WheelBrakeProperty>(iface->re, connection);
175 exportProperty<LightStatusProperty>(iface->re, connection);
176 exportProperty<HornProperty>(iface->re, connection);
177 exportProperty<FuelProperty>(iface->re, connection);
178 exportProperty<EngineOilProperty>(iface->re, connection);
179 exportProperty<ExteriorBrightnessProperty>(iface->re, connection);
180 exportProperty<Temperature>(iface->re, connection);
181 exportProperty<RainSensor>(iface->re, connection);
182 exportProperty<WindshieldWiper>(iface->re, connection);
183 exportProperty<HVACProperty>(iface->re, connection);
184 exportProperty<WindowStatusProperty>(iface->re, connection);
185 exportProperty<Sunroof>(iface->re, connection);
186 exportProperty<ConvertibleRoof>(iface->re, connection);
187 exportProperty<VehicleId>(iface->re, connection);
188 exportProperty<VehicleTypeProperty>(iface->re, connection);
189 exportProperty<FuelInfoProperty>(iface->re, connection);
190 exportProperty<SizeProperty>(iface->re, connection);
191 exportProperty<DoorsProperty>(iface->re, connection);
192 exportProperty<WheelInformationProperty>(iface->re, connection);
193 exportProperty<OdometerProperty>(iface->re, connection);
194 exportProperty<FluidProperty>(iface->re, connection);
195 exportProperty<BatteryProperty>(iface->re, connection);
196 exportProperty<SecurityAlertProperty>(iface->re, connection);
197 exportProperty<ParkingBrakeProperty>(iface->re, connection);
198 exportProperty<ParkingLightProperty>(iface->re, connection);
199 exportProperty<HazardLightProperty>(iface->re, connection);
200 exportProperty<LocationProperty>(iface->re, connection);
201 exportProperty<AntilockBrakingSystemProperty>(iface->re, connection);
202 exportProperty<TractionControlSystemProperty>(iface->re, connection);
203 exportProperty<VehicleTopSpeedLimitProperty>(iface->re, connection);
204 exportProperty<AirbagStatusProperty>(iface->re, connection);
205 exportProperty<DoorStatusProperty>(iface->re, connection);
206 exportProperty<SeatBeltStatusProperty>(iface->re, connection);
207 exportProperty<OccupantStatusProperty>(iface->re, connection);
208 exportProperty<ObstacleDistanceProperty>(iface->re, connection);
209 exportProperty<SeatPostionProperty>(iface->re, connection);
210 exportProperty<SteeringWheelPositionProperty>(iface->re, connection);
211 exportProperty<MirrorSettingProperty>(iface->re, connection);
213 iface->registerCustomTypes();
217 on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
223 on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data)
226 DebugOut(DebugOut::Error)<<"DBus: Lost bus name"<<endl;
229 DebugOut(DebugOut::Error)<<"DBus: Connection could not be established."<<endl;
230 throw std::runtime_error("Could not establish DBus connection.");
236 DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine* engine,std::map<std::string,std::string> config)
237 :AbstractSink(engine,config),re(engine), connection(nullptr)
239 DBusSink::dbusConfig = config;
240 ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM,
242 G_BUS_NAME_OWNER_FLAGS_NONE,
251 DBusInterfaceManager::~DBusInterfaceManager()
253 g_bus_unown_name(ownerId);
256 void DBusInterfaceManager::supportedChanged(const PropertyList &supportedProperties)
258 DebugOut()<<"supported Properties: "<<supportedProperties.size()<<endl;
264 registerCustomTypes();
267 void DBusInterfaceManager::registerCustomTypes()
269 PropertyList list = VehicleProperty::customProperties();
270 PropertyList implemented = AbstractDBusInterface::implementedProperties();
272 for (auto itr = list.begin(); itr != list.end(); itr++)
274 VehicleProperty::Property prop = *itr;
276 if(!contains(implemented, prop))
278 exportProperty<CustomPropertyInterface>(prop, re, connection);
282 /// Create objects for unimplemented properties:
284 implemented = AbstractDBusInterface::implementedProperties();
286 PropertyList capabilitiesList = VehicleProperty::capabilities();
288 for (auto itr = capabilitiesList.begin(); itr != capabilitiesList.end(); itr++)
290 VehicleProperty::Property prop = *itr;
292 if(!contains(implemented, prop))
294 exportProperty<UncategorizedPropertyInterface>(prop, re, connection);