#include <boost/lexical_cast.hpp>
#include <boost/utility.hpp>
#include <type_traits>
+#include <glibmm/variant.h>
#include "timestamp.h"
class AbstractPropertyType
virtual void fromString(std::string)= 0;
+ virtual Glib::VariantBase* toVariant() = 0;
+
+ virtual void fromVariant(Glib::VariantBase*) = 0;
+
virtual AbstractPropertyType* copy() = 0;
double timestamp;
return stream.str();
}
+ Glib::VariantBase* toVariant()
+ {
+ serializeVariant<T>(value<T>());
+
+ return &mVariant;
+ }
+
+ void fromVariant(Glib::VariantBase *v)
+ {
+ setValue(deserializeVariant<T>(v));
+ }
+
private:
+ Glib::VariantBase mVariant;
+
template <class N>
void serialize(std::string val, typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
{
stream>>someTemp;
setValue(someTemp);
}
+
+ template <class N>
+ void serializeVariant(T val, typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
+ {
+ mVariant = Glib::VariantBase(Glib::Variant<gint16>::create((int)val).gobj());
+ }
+
+ template <class N>
+ void serializeVariant(T val, typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
+ {
+ //mVariant = Glib::Variant<int>::create(0);
+ mVariant = Glib::Variant<T>::create(val);
+ }
+
+ template <class N>
+ T deserializeVariant(Glib::VariantBase* v, typename std::enable_if<std::is_enum<N>::value, N>::type* = 0)
+ {
+ return (T)((Glib::Variant<int>::cast_dynamic<Glib::Variant<int> >(*v)).get());
+ }
+
+ template <class N>
+ T deserializeVariant(Glib::VariantBase* v, typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
+ {
+ return Glib::VariantBase::cast_dynamic<Glib::Variant<T> >(*v).get();
+ }
+
+
};
class StringPropertyType: public AbstractPropertyType
return value<std::string>();
}
+ Glib::VariantBase* toVariant()
+ {
+ mVariant = Glib::Variant<std::string>::create(toString());
+
+ return &mVariant;
+ }
+
+ void fromVariant(Glib::VariantBase *v)
+ {
+ setValue(std::string(v->print()));
+ }
+
+private:
+
+ Glib::Variant<std::string> mVariant;
};
#endif
#define REGISTERPROPERTY(property, defaultValue) \
- registerProperty(property, []() { return new property ## Type(defaultValue); });
+ registerPropertyPriv(property, []() { return new property ## Type(defaultValue); });
#define REGISTERPROPERTYWITHTYPE(property, type, defaultValue) \
- registerProperty(property, []() { return new type(defaultValue); });
+ registerPropertyPriv(property, []() { return new type(defaultValue); });
using namespace std;
const VehicleProperty::Property VehicleProperty::EngineOilRemaining = "EngineOilRemaining";
std::list<VehicleProperty::Property> VehicleProperty::mCapabilities;
+std::list<VehicleProperty::Property> VehicleProperty::mCustomProperties;
VehicleProperty::VehicleProperty()
{
- registerProperty( VehicleSpeed, [](){ return new VehicleSpeedType(0); });
- registerProperty(EngineSpeed, [](){ return new EngineSpeedType(0); });
- registerProperty(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
- registerProperty(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
+ registerPropertyPriv( VehicleSpeed, [](){ return new VehicleSpeedType(0); });
+ registerPropertyPriv(EngineSpeed, [](){ return new EngineSpeedType(0); });
+ registerPropertyPriv(TransmissionShiftPosition, [](){ return new TransmissionShiftPositionType(Transmission::Neutral); });
+ registerPropertyPriv(TransmissionGearPosition, [](){ return new TransmissionGearPositionType(Transmission::Neutral); });
REGISTERPROPERTY(TransmissionMode,Transmission::Normal);
- registerProperty(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
- registerProperty(WheelBrake, [](){ return new WheelBrakeType(false); });
- registerProperty(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
- registerProperty(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
- registerProperty(ClutchStatus, [](){ return new ClutchStatusType(false); });
- registerProperty(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
- registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
+ registerPropertyPriv(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
+ registerPropertyPriv(WheelBrake, [](){ return new WheelBrakeType(false); });
+ registerPropertyPriv(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
+ registerPropertyPriv(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
+ registerPropertyPriv(ClutchStatus, [](){ return new ClutchStatusType(false); });
+ registerPropertyPriv(EngineOilPressure, [](){ return new EngineOilPressureType(0); });
+ registerPropertyPriv(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); });
REGISTERPROPERTY(EngineOilRemaining,0);
- registerProperty(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
- registerProperty(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
- registerProperty(AccelerationX, [](){ return new AccelerationType(0); });
- registerProperty(AccelerationY, [](){ return new AccelerationType(0); });
- registerProperty(AccelerationZ, [](){ return new AccelerationType(0); });
- registerProperty(MassAirFlow, [](){ return new MassAirFlowType(0); });
- registerProperty(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
+ registerPropertyPriv(EngineCoolantTemperature, [](){ return new EngineCoolantTemperatureType(0); });
+ registerPropertyPriv(MachineGunTurretStatus, [](){ return new MachineGunTurretStatusType(false); });
+ registerPropertyPriv(AccelerationX, [](){ return new AccelerationType(0); });
+ registerPropertyPriv(AccelerationY, [](){ return new AccelerationType(0); });
+ registerPropertyPriv(AccelerationZ, [](){ return new AccelerationType(0); });
+ registerPropertyPriv(MassAirFlow, [](){ return new MassAirFlowType(0); });
+ registerPropertyPriv(ButtonEvent, [](){ return new ButtonEventType(ButtonEvents::NoButton); });
REGISTERPROPERTY(AirIntakeTemperature,0)
- registerProperty(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
- registerProperty(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
- registerProperty(VIN, [](){ return new VINType(""); });
- registerProperty(WMI, [](){ return new WMIType(""); });
+ registerPropertyPriv(BatteryVoltage, [](){ return new BatteryVoltageType(0); });
+ registerPropertyPriv(InteriorTemperature, [](){ return new InteriorTemperatureType(0); });
+ registerPropertyPriv(VIN, [](){ return new VINType(""); });
+ registerPropertyPriv(WMI, [](){ return new WMIType(""); });
REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0);
REGISTERPROPERTYWITHTYPE(TirePressureRightFront, TirePressureType, 0);
REGISTERPROPERTYWITHTYPE(TirePressureLeftRear, TirePressureType, 0);
REGISTERPROPERTYWITHTYPE(TireTemperatureRightFront,TireTemperatureType,0);
REGISTERPROPERTYWITHTYPE(TireTemperatureLeftRear,TireTemperatureType,0);
REGISTERPROPERTYWITHTYPE(TireTemperatureRightRear,TireTemperatureType,0);
- registerProperty( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } );
+ registerPropertyPriv( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } );
REGISTERPROPERTYWITHTYPE(TripMeterA,TripMeterType,0);
REGISTERPROPERTYWITHTYPE(TripMeterB,TripMeterType,0);
REGISTERPROPERTYWITHTYPE(TripMeterC,TripMeterType,0);
return mCapabilities;
}
+std::list<VehicleProperty::Property> VehicleProperty::customProperties()
+{
+ return mCustomProperties;
+}
+
AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value)
{
if(registeredPropertyFactoryMap.count(name) > 0)
bool VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
{
+
+ mCustomProperties.push_back(name);
+
+ return registerPropertyPriv(name, factory);
+}
+
+bool VehicleProperty::registerPropertyPriv(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory)
+{
if(ListPlusPlus<Property>(&mCapabilities).contains(name))
{
DebugOut(0)<<__FUNCTION__<<" ERROR: property '"<<name<<"'' already registered."<<endl;
mCapabilities.push_back(name);
return true;
+
}
VehicleProperty vehiclePropertyConstruct;
static const Property TirePressureRightFront;
static const Property TirePressureLeftRear;
static const Property TirePressureRightRear;
- typedef BasicPropertyType<float> TirePressureType;
+ typedef BasicPropertyType<double> TirePressureType;
/**< Tire temperature in degrees C */
static const Property TireTemperatureLeftFront;
static const Property TireTemperatureRightFront;
static const Property TireTemperatureLeftRear;
static const Property TireTemperatureRightRear;
- typedef BasicPropertyType<float> TireTemperatureType;
+ typedef BasicPropertyType<double> TireTemperatureType;
/**< Vehicle Power Mode.
*@see Power::PowerModes
typedef BasicPropertyType<uint16_t> FuelAverageEconomyType;
static std::list<VehicleProperty::Property> capabilities();
+ static std::list<VehicleProperty::Property> customProperties();
/*! getPropertyTypeForPropertyNameValue returns an AbstractPropertyType* for the property name
* with the value specified by 'value'. Ownership of the returned AbstractPropertyType* is
*/
static bool registerProperty(Property name, PropertyTypeFactoryCallback factory);
+
+
private:
+ static bool registerPropertyPriv(Property name, PropertyTypeFactoryCallback factory);
static std::map<Property, PropertyTypeFactoryCallback> registeredPropertyFactoryMap;
static std::list<VehicleProperty::Property> mCapabilities;
+ static std::list<VehicleProperty::Property> mCustomProperties;
};
typedef std::list<VehicleProperty::Property> PropertyList;
pkg_check_modules(gio REQUIRED gio-2.0)
-set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h)
-set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp)
+set(dbussinkplugin_headers dbusplugin.h abstractproperty.h abstractdbusinterface.h dbusinterfacemanager.h basicproperty.h properties.h varianttype.h custompropertyinterface.h)
+set(dbussinkplugin_sources dbusplugin.cpp abstractproperty.cpp abstractdbusinterface.cpp dbusinterfacemanager.cpp basicproperty.cpp properties.cpp varianttype.cpp custompropertyinterface.cpp)
add_library(dbussinkplugin MODULE ${dbussinkplugin_sources})
set_target_properties(dbussinkplugin PROPERTIES PREFIX "")
GError *error = NULL;
GVariant **params = g_new(GVariant*,2);
- params[0] = g_variant_new("v",property->toGVariant());
+ GVariant *val = g_variant_ref(property->toGVariant());
+ params[0] = g_variant_new("v",val);
params[1] = g_variant_new("d",property->timestamp());
GVariant *tuple_variant = g_variant_new_tuple(params,2);
{
GVariant* value = interfaceMap[interfaceName]->getProperty(propertyName);
return value;
+
}
debugOut("No interface for" + string(interfaceName));
return nullptr;
#include "abstractdbusinterface.h"
AbstractProperty::AbstractProperty(string pn, string sig, Access access, AbstractDBusInterface* interface)
- : mPropertyName(pn), mSignature(sig), mAccess(access), mInterface(interface), mTimestamp(0)
+ : mPropertyName(pn), mSignature(sig), mAccess(access), mInterface(interface), mTimestamp(0),mValue(NULL)
{
}
return mTimestamp;
}
- void setValue(boost::any val, double timestmp)
+ virtual void setValue(AbstractPropertyType* val)
{
- mValue = val;
- mTimestamp = timestmp;
+ mValue = val->copy();
+ mAnyValue = val->anyValue();
+ mTimestamp = val->timestamp;
updateValue();
}
template<typename T>
void setValue(T val)
{
- mValue = val;
+ mAnyValue = val;
updateValue();
}
+
+
template<typename T>
- T value()
+ T anyValue()
+ {
+ return boost::any_cast<T>(mAnyValue);
+ }
+
+ AbstractPropertyType* value()
{
- return boost::any_cast<T>(mValue);
+ return mValue;
}
protected: ///methods:
protected:
- boost::any mValue;
+ boost::any mAnyValue;
string mPropertyName;
string mSignature;
SetterFunc mSetterFunc;
Access mAccess;
double mTimestamp;
-
+ AbstractPropertyType* mValue;
AbstractDBusInterface* mInterface;
};
T value()
{
- return AbstractProperty::value<T>();
+ return AbstractProperty::anyValue<T>();
}
virtual GVariant* toGVariant()
--- /dev/null
+#include "custompropertyinterface.h"
+#include "vehicleproperty.h"
+#include "varianttype.h"
+
+CustomPropertyInterface::CustomPropertyInterface(AbstractRoutingEngine *re, GDBusConnection *connection)
+ :DBusSink("org.automotive.custom","/org/automotive/custom", re, connection, map<string, string>())
+{
+ PropertyList list = VehicleProperty::customProperties();
+ for (auto itr = list.begin(); itr != list.end(); itr++)
+ {
+ VehicleProperty::Property prop = *itr;
+
+ propertyDBusMap[prop] = new VariantType(re, prop, VariantType::ReadWrite, this);
+ }
+
+ supportedChanged(re->supported());
+}
--- /dev/null
+#ifndef CUSTOMPROPERTYINTERFACE_H_
+#define CUSTOMPROPERTYINTERFACE_H_
+
+#include "dbusplugin.h"
+
+class CustomPropertyInterface: DBusSink
+{
+public:
+ CustomPropertyInterface(AbstractRoutingEngine* re, GDBusConnection* connection);
+};
+
+
+#endif
///properties:
#include "accelerationproperty.h"
#include "properties.h"
+#include "custompropertyinterface.h"
+
#define ConstructProperty(property) \
new property(iface->re, connection);
ConstructProperty(HornProperty);
ConstructProperty(FuelProperty);
ConstructProperty(EngineOilProperty);
+ ConstructProperty(CustomPropertyInterface);
+
}
static void
return;
AbstractProperty* prop = propertyDBusMap[property];
- prop->setValue(value->anyValue(),value->timestamp);
+ prop->setValue(value);
}
std::string DBusSink::uuid()
--- /dev/null
+#include "varianttype.h"
+
+VariantType::VariantType(AbstractRoutingEngine* re, std::string propertyName, Access access, AbstractDBusInterface *interface)
+ :AbstractProperty(propertyName, "v", access, interface)
+{
+//VehicleProperty::getPropertyTypeForPropertyNameValue(propertyName,"")->toVariant()->get_type_string()
+}
+
+GVariant *VariantType::toGVariant()
+{
+ if(!value())
+ return g_variant_new("v",g_variant_new_int16(0));
+
+ return value()->toVariant()->gobj();
+}
+
+void VariantType::fromGVariant(GVariant *value)
+{
+
+}
--- /dev/null
+#ifndef _VARIANT_TYPE_H_
+#define _VARIANT_TYPE_H_
+
+#include "abstractproperty.h"
+#include "abstractroutingengine.h"
+
+class VariantType: public AbstractProperty
+{
+public:
+
+ VariantType(AbstractRoutingEngine* re,string propertyName, Access access, AbstractDBusInterface* interface);
+ GVariant* toGVariant();
+ void fromGVariant(GVariant *value);
+
+private:
+ AbstractRoutingEngine* routingEngine;
+};
+
+#endif
//std::list<ObdPid*> Obd2Amb::supportedPidsList;
Obd2Amb *obd2AmbInstance = new Obd2Amb;
-
+VehicleProperty::Property Obd2Connected = "Obd2Connected";
int calledPersecond = 0;
bool sendElmCommand(obdLib *obd,std::string command)
StatusMessage *reply = (StatusMessage*)retval;
if (reply->statusStr == "disconnected")
{
- //TODO: This is where we update Obd2Connected property
- //src->updateProperty("Obd2Connected",true);
+
+ BasicPropertyType<bool> val(false);
+ src->updateProperty(Obd2Connected,&val);
}
else if (reply->statusStr == "connected")
{
- //TODO: This is where we update Obd2Connected property
+ BasicPropertyType<bool> val(true);
+ src->updateProperty(Obd2Connected,&val);
}
}
while(gpointer retval = g_async_queue_try_pop(src->responseQueue))
}
OBD2Source::OBD2Source(AbstractRoutingEngine *re, map<string, string> config)
- : AbstractSource(re, config), Obd2Connect("Obd2Connect")
+ : AbstractSource(re, config)
{
- VehicleProperty::registerProperty(Obd2Connect,[](){ return new Obd2ConnectType(false); });
+ VehicleProperty::registerProperty(Obd2Connected,[](){ return new Obd2ConnectType(false); });
clientConnected = false;
m_re = re;
m_supportedProperties.push_back((*itr)->property);
}
- m_supportedProperties.push_back(Obd2Connect);
+ m_supportedProperties.push_back(Obd2Connected);
re->setSupported(supported(), this);
/*if (openPort(std::string("/dev/pts/7"),115200))
private:
PropertyList m_supportedProperties;
GMutex *threadQueueMutex;
- VehicleProperty::Property Obd2Connect;
typedef BasicPropertyType<bool> Obd2ConnectType;
};