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"
27 #include <unordered_set>
29 #include <dbusexport.h>
30 #include <ambplugin.h>
33 #include "runningstatus.h"
34 #include "custompropertyinterface.h"
35 #include "uncategorizedproperty.h"
36 #include "environmentproperties.h"
37 #include "vehicleinfo.h"
38 #include "maintenance.h"
40 #include "drivingsafety.h"
41 #include "personalization.h"
43 extern "C" void create(AbstractRoutingEngine* routingengine, map<string, string> config)
45 auto plugin = new AmbPlugin<DBusInterfaceManager>(routingengine, config);
50 on_bus_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
52 DBusInterfaceManager* iface = static_cast<DBusInterfaceManager*>(user_data);
54 iface->connection = std::shared_ptr<GDBusConnection>(connection, [=](GDBusConnection* conn){
55 amb::traits<GDBusConnection>::delete_functor functor;
59 iface->setValue(iface->dbusConnected, true);
61 new AutomotiveManager(connection);
63 iface->registerTypes();
67 on_name_acquired (GDBusConnection *connection, const gchar *name, gpointer user_data)
73 on_name_lost (GDBusConnection *connection, const gchar *name, gpointer user_data)
75 DebugOut(DebugOut::Error)<<"DBus: Lost bus name"<<endl;
77 DBusInterfaceManager* iface = static_cast<DBusInterfaceManager*>(user_data);
79 iface->setValue(iface->dbusConnected, false);
82 DebugOut(DebugOut::Error)<<"DBus: Connection could not be established."<<endl;
83 throw std::runtime_error("Could not establish DBus connection.");
89 DBusInterfaceManager::DBusInterfaceManager(AbstractRoutingEngine * engine, std::map<std::string,std::string> config, AbstractSource & parent)
90 :AmbPluginImpl(engine, config, parent), connection(nullptr)
92 DBusSink::dbusConfig = config;
93 dbusConnected = addPropertySupport(Zone::None, []() { return new BasicPropertyType<bool>(DBusConnected, false); });
95 ownerId = g_bus_own_name(G_BUS_TYPE_SYSTEM,
97 G_BUS_NAME_OWNER_FLAGS_NONE,
106 DBusInterfaceManager::~DBusInterfaceManager()
108 g_bus_unown_name(ownerId);
111 void DBusInterfaceManager::supportedChanged(const PropertyList &supportedProperties)
113 DebugOut()<<"supported Properties: "<<supportedProperties.size()<<endl;
122 void DBusInterfaceManager::registerTypes()
125 auto re = routingEngine;
127 auto exporter = amb::Exporter::instance();
129 exporter->connection = connection;
131 exporter->exportProperty<AccelerationProperty>(re);
132 exporter->exportProperty<VehicleSpeedProperty>(re);
133 exporter->exportProperty<TireProperty>(re);
134 exporter->exportProperty<EngineSpeedProperty>(re);
135 exporter->exportProperty<VehiclePowerModeProperty>(re);
136 exporter->exportProperty<TripMeterProperty>(re);
137 exporter->exportProperty<TransmissionProperty>(re);
138 exporter->exportProperty<CruiseControlProperty>(re);
139 exporter->exportProperty<BrakeOperation>(re);
140 exporter->exportProperty<LightStatusProperty>(re);
141 exporter->exportProperty<HornProperty>(re);
142 exporter->exportProperty<FuelProperty>(re);
143 exporter->exportProperty<EngineOilProperty>(re);
144 exporter->exportProperty<ExteriorBrightnessProperty>(re);
145 exporter->exportProperty<Temperature>(re);
146 exporter->exportProperty<RainSensor>(re);
147 exporter->exportProperty<ClimateControlProperty>(re);
148 exporter->exportProperty<WindowStatusProperty>(re);
149 exporter->exportProperty<DefrostProperty>(re);
150 exporter->exportProperty<Sunroof>(re);
151 exporter->exportProperty<ConvertibleRoof>(re);
152 exporter->exportProperty<VehicleId>(re);
153 exporter->exportProperty<VehicleTypeProperty>(re);
154 exporter->exportProperty<FuelInfoProperty>(re);
155 exporter->exportProperty<SizeProperty>(re);
156 exporter->exportProperty<DoorsProperty>(re);
157 exporter->exportProperty<WheelInformationProperty>(re);
158 exporter->exportProperty<OdometerProperty>(re);
159 exporter->exportProperty<FluidProperty>(re);
160 exporter->exportProperty<BatteryStatusProperty>(re);
161 exporter->exportProperty<ParkingBrakeProperty>(re);
162 exporter->exportProperty<HazardLightProperty>(re);
163 exporter->exportProperty<LocationProperty>(re);
164 exporter->exportProperty<AntilockBrakingSystemProperty>(re);
165 exporter->exportProperty<TractionControlSystemProperty>(re);
166 exporter->exportProperty<VehicleTopSpeedLimitProperty>(re);
167 exporter->exportProperty<AirbagStatusProperty>(re);
168 exporter->exportProperty<DoorStatusProperty>(re);
169 exporter->exportProperty<SeatBeltStatusProperty>(re);
170 exporter->exportProperty<OccupantStatusProperty>(re);
171 exporter->exportProperty<ObstacleDistanceProperty>(re);
172 exporter->exportProperty<SteeringWheelPositionProperty>(re);
173 exporter->exportProperty<SteeringWheel>(re);
174 exporter->exportProperty<ThrottlePosition>(re);
175 exporter->exportProperty<EngineCoolant>(re);
176 exporter->exportProperty<NightMode>(re);
177 exporter->exportProperty<DrivingMode>(re);
178 exporter->exportProperty<PowertrainTorque>(re);
179 exporter->exportProperty<AcceleratorPedalPosition>(re);
180 exporter->exportProperty<Chime>(re);
181 exporter->exportProperty<WheelTick>(re);
182 exporter->exportProperty<IgnitionTime>(re);
183 exporter->exportProperty<YawRate>(re);
184 exporter->exportProperty<TransmissionClutch>(re);
185 exporter->exportProperty<TransmissionOil>(re);
186 exporter->exportProperty<BrakeMaintenance>(re);
187 exporter->exportProperty<WasherFluid>(re);
188 exporter->exportProperty<MalfunctionIndicator>(re);
189 exporter->exportProperty<Diagnostics>(re);
190 exporter->exportProperty<MirrorProperty>(re);
191 exporter->exportProperty<SeatAdjustment>(re);
192 exporter->exportProperty<DriveMode>(re);
193 exporter->exportProperty<VehicleSound>(re);
194 exporter->exportProperty<ElectronicStabilityControl>(re);
195 exporter->exportProperty<ChildSafetyLock>(re);
196 exporter->exportProperty<SeatProperty>(re);
197 exporter->exportProperty<DoorProperty>(re);
198 exporter->exportProperty<WindshieldWiperStatus>(re);
199 exporter->exportProperty<SideWindowStatusProperty>(re);
200 exporter->exportProperty<AtmosphericPressure>(re);
201 exporter->exportProperty<LaneDepartureStatus>(re);
202 exporter->exportProperty<AlarmStatus>(re);
204 PropertyList list = VehicleProperty::customProperties();
205 PropertyList implemented = AbstractDBusInterface::implementedProperties();
207 for (auto prop : list)
209 if(!contains(implemented, prop))
211 exporter->exportProperty<CustomPropertyInterface>(prop, re);
215 /// Create objects for unimplemented properties:
217 implemented = AbstractDBusInterface::implementedProperties();
219 PropertyList capabilitiesList = VehicleProperty::capabilities();
221 for (auto itr = capabilitiesList.begin(); itr != capabilitiesList.end(); itr++)
223 VehicleProperty::Property prop = *itr;
225 if(!contains(implemented, prop))
227 exporter->exportProperty<UncategorizedPropertyInterface>(prop, re);