pkg_check_modules(gio REQUIRED gio-2.0)
-set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h varianttype.h custompropertyinterface.h environmentproperties.h)
-set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp varianttype.cpp custompropertyinterface.cpp environmentproperties.cpp)
+set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h varianttype.h custompropertyinterface.h environmentproperties.h vehicleinfo.h)
+set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp varianttype.cpp custompropertyinterface.cpp environmentproperties.cpp vehicleinfo.cpp)
add_library(dbussinkplugin MODULE ${dbussinkplugin_sources})
set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
#include "abstractproperty.h"
#include "vehicleproperty.h"
#include "abstractroutingengine.h"
+#include <functional>
template <typename T>
class BasicProperty: public AbstractProperty
{
public:
BasicProperty(AbstractRoutingEngine* re, string ambPropertyName, string propertyName, string signature, Access access, AbstractDBusInterface *interface)
- :AbstractProperty(propertyName, signature, access, interface)
+ :AbstractProperty(propertyName, signature, access, interface), routingEngine(re)
{
mAmbPropertyName = ambPropertyName;
+ //set default value:
+ AbstractProperty::setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(ambPropertyName));
+
+ using namespace std::placeholders;
+
+ AsyncPropertyRequest request;
+ request.property = ambPropertyName;
+ request.completed = std::bind(&BasicProperty<T>::asyncReply,this,_1);
+ routingEngine->getPropertyAsync(request);
+
+ }
+
+ void asyncReply(AsyncPropertyReply* reply)
+ {
+ if(reply->success)
+ AbstractProperty::setValue(reply->value);
+
+ delete reply;
}
void setValue(T val)
AbstractRoutingEngine* routingEngine;
};
+
+class StringDBusProperty: public AbstractProperty
+{
+public:
+
+ StringDBusProperty(AbstractRoutingEngine* re, string ambPropertyName, string propertyName, string signature, Access access, AbstractDBusInterface *interface)
+ :AbstractProperty(propertyName, signature, access, interface), routingEngine(re), mAmbPropertyName(ambPropertyName)
+ {
+ //set default value:
+ AbstractProperty::setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(ambPropertyName));
+
+ AsyncPropertyRequest request;
+ request.property = ambPropertyName;
+ request.completed = [this](AsyncPropertyReply* reply)
+ {
+ AbstractProperty::setValue(reply->value);
+
+ delete reply;
+ };
+
+ routingEngine->getPropertyAsync(request);
+ }
+
+ void setValue(std::string val)
+ {
+ AbstractProperty::setValue<std::string>(val);
+ }
+
+ virtual GVariant* toGVariant()
+ {
+ return g_variant_new(signature().c_str(), value()->toString().c_str());
+ }
+
+ virtual void fromGVariant(GVariant *value)
+ {
+ char *val;
+ g_variant_get(value,signature().c_str(), &val);
+
+ AbstractPropertyType* apt = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName,val);
+
+ AsyncSetPropertyRequest request;
+ request.property = mAmbPropertyName;
+ request.value = apt;
+ request.completed = [apt](AsyncPropertyReply* reply)
+ {
+ if(!reply->success) {
+ //TODO: throw DBus exception
+ }
+ delete apt;
+ };
+
+ routingEngine->setProperty(request);
+ }
+
+private:
+ VehicleProperty::Property mAmbPropertyName;
+ AbstractRoutingEngine* routingEngine;
+};
+
#endif
#include "properties.h"
#include "custompropertyinterface.h"
#include "environmentproperties.h"
+#include "vehicleinfo.h"
#define ConstructProperty(property) \
new property(iface->re, connection);
ConstructProperty(FuelProperty);
ConstructProperty(EngineOilProperty);
ConstructProperty(ExteriorBrightnessProperty);
+ ConstructProperty(VehicleId);
PropertyList list = VehicleProperty::customProperties();
#include "abstractdbusinterface.h"
#include "basicproperty.h"
#include <map>
+#include <type_traits>
typedef std::map<VehicleProperty::Property, AbstractProperty*> PropertyDBusMap;
propertyDBusMap[property] = new BasicProperty<T>(routingEngine, property, propertyName, signature, access, this);
}
- /*virtual void setProperty(VehicleProperty::Property name, AbstractPropertyType* value)
+
+ void wantPropertyString(VehicleProperty::Property property, std::string propertyName, std::string signature, AbstractProperty::Access access)
{
- AsyncSetPropertyRequest request;
- request.property = name;
- request.value = value;
- request.completed = [](AsyncPropertyReply* reply) { delete reply; };
- routingEngine->setProperty(request);
- }*/
+ propertyDBusMap[property] = new StringDBusProperty(routingEngine, property, propertyName, signature, access, this);
+ }
PropertyDBusMap propertyDBusMap;
private:
TirePressureProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
:DBusSink("org.automotive.tirePressure","/org/automotive/maintainance/tirePressure", re, connection, map<string, string>())
{
- wantProperty<uint16_t>(VehicleProperty::TirePressureLeftFront,"LeftFront", "q", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TirePressureRightFront,"RightFront", "q", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TirePressureLeftRear,"LeftRear", "q", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TirePressureRightRear,"RightRear", "q", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TirePressureLeftFront,"LeftFront", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TirePressureRightFront,"RightFront", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TirePressureLeftRear,"LeftRear", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TirePressureRightRear,"RightRear", "d", AbstractProperty::Read);
supportedChanged(re->supported());
}
};
VehiclePowerModeProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
:DBusSink("org.automotive.vehiclePowerMode","/org/automotive/runningstatus/vehiclePowerMode", re, connection, map<string, string>())
{
- wantProperty<uint16_t>(VehicleProperty::VehiclePowerMode, "VehiclePowerMode","b",AbstractProperty::Read);
+ wantProperty<Power::PowerModes>(VehicleProperty::VehiclePowerMode, "VehiclePowerMode","b",AbstractProperty::Read);
supportedChanged(re->supported());
}
};
"ShiftPosition", "y", AbstractProperty::Read);
wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionGearPosition,
"GearPosition", "y", AbstractProperty::Read);
- wantProperty<Transmission::TransmissionPositions>(VehicleProperty::TransmissionMode,
+ wantProperty<Transmission::Mode>(VehicleProperty::TransmissionMode,
"Mode", "y", AbstractProperty::Read);
supportedChanged(re->supported());
TireTemperatureProperty(AbstractRoutingEngine* re, GDBusConnection* connection)
:DBusSink("org.automotive.tireTemperature","/org/automotive/maintainance/tireTemperature", re, connection, map<string, string>())
{
- wantProperty<uint16_t>(VehicleProperty::TireTemperatureLeftFront,"LeftFront", "i", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TireTemperatureRightFront,"RightFront", "i", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TireTemperatureLeftRear,"LeftRear", "i", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::TireTemperatureRightRear,"RightRear", "i", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TireTemperatureLeftFront,"LeftFront", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TireTemperatureRightFront,"RightFront", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TireTemperatureLeftRear,"LeftRear", "d", AbstractProperty::Read);
+ wantProperty<double>(VehicleProperty::TireTemperatureRightRear,"RightRear", "d", AbstractProperty::Read);
supportedChanged(re->supported());
}
};
:DBusSink("org.automotive.engineOil", "/org/automotive/runningstatus/engineOil", re, connection, map<string, string>())
{
wantProperty<uint16_t>(VehicleProperty::EngineOilRemaining, "Remaining", "y", AbstractProperty::Read);
- wantProperty<uint16_t>(VehicleProperty::EngineOilTemperature, "Temperature", "y", AbstractProperty::Read);
+ wantProperty<int>(VehicleProperty::EngineOilTemperature, "Temperature", "i", AbstractProperty::Read);
wantProperty<uint16_t>(VehicleProperty::EngineOilPressure, "Pressure", "y", AbstractProperty::Read);
supportedChanged(re->supported());
}
VariantType::VariantType(AbstractRoutingEngine* re, std::string signature, std::string propertyName, Access access, AbstractDBusInterface *interface)
:AbstractProperty(propertyName, signature, access, interface),routingEngine(re)
{
+ //set default value:
+ setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(propertyName));
+
AsyncPropertyRequest request;
request.property = mPropertyName;
- VariantType* foo = this;
-
- request.completed = [foo](AsyncPropertyReply* reply)
+ request.completed = [this](AsyncPropertyReply* reply)
{
- foo->setValue(reply->value);
+ setValue(reply->value);
};
re->getPropertyAsync(request);
--- /dev/null
+#include "vehicleinfo.h"
--- /dev/null
+#ifndef _VEHICLEINFO_H_
+#define _VEHICLEINFO_H_
+
+
+#include "dbusplugin.h"
+#include "abstractdbusinterface.h"
+#include "abstractroutingengine.h"
+
+
+class VehicleId: public DBusSink
+{
+public:
+ VehicleId(AbstractRoutingEngine* re, GDBusConnection* connection)
+ :DBusSink("org.automotive.vehicleId","/org/automotive/vehicleinfo/vehicleId", re, connection, map<string, string>())
+ {
+ wantPropertyString(VehicleProperty::WMI, "WMI", "s", AbstractProperty::Read);
+ wantPropertyString(VehicleProperty::VIN, "VIN", "s", AbstractProperty::Read);
+
+ supportedChanged(re->supported());
+ }
+};
+
+
+#endif
OBD2Source::OBD2Source(AbstractRoutingEngine *re, map<string, string> config)
: AbstractSource(re, config)
{
- VehicleProperty::registerProperty(Obd2Connected,[](){ return new Obd2ConnectType(false); });
+ bool success = VehicleProperty::registerProperty(Obd2Connected,[](){ return new Obd2ConnectType(false); });
+
+ if(!success)
+ {
+ ///ERROR!
+ }
+
clientConnected = false;
m_re = re;