diff options
author | Kevron Rees <kevron_m_rees@linux.intel.com> | 2012-10-10 16:43:45 -0700 |
---|---|---|
committer | Kevron Rees <kevron_m_rees@linux.intel.com> | 2012-10-10 16:43:45 -0700 |
commit | d47172ce9c634248da1c8ddf900d2e44ae24a614 (patch) | |
tree | e845ff273499c02b074cd260bc9d39ec08f60dd3 | |
parent | 0b8411a7e5f35431b43b7f614662abf92aba07e9 (diff) | |
download | automotive-message-broker-d47172ce9c634248da1c8ddf900d2e44ae24a614.tar.gz |
made adding properties more straightforward
-rw-r--r-- | lib/vehicleproperty.cpp | 121 | ||||
-rw-r--r-- | lib/vehicleproperty.h | 16 | ||||
-rw-r--r-- | plugins/dbus/properties.h | 11 |
3 files changed, 76 insertions, 72 deletions
diff --git a/lib/vehicleproperty.cpp b/lib/vehicleproperty.cpp index aa074a79..0abbc372 100644 --- a/lib/vehicleproperty.cpp +++ b/lib/vehicleproperty.cpp @@ -20,6 +20,12 @@ #include "vehicleproperty.h" #include <map> +#define REGISTERPROPERTY(property, defaultValue) \ + registerProperty(property, []() { return new property ## Type(defaultValue); }); + +#define REGISTERPROPERTYWITHTYPE(property, type, defaultValue) \ + registerProperty(property, []() { return new type(defaultValue); }); + using namespace std; std::map<VehicleProperty::Property, VehicleProperty::PropertyTypeFactoryCallback> VehicleProperty::registeredPropertyFactoryMap; @@ -52,94 +58,64 @@ const VehicleProperty::Property VehicleProperty::TirePressureLeftFront = "TirePr const VehicleProperty::Property VehicleProperty::TirePressureRightFront = "TirePressureRightFront"; const VehicleProperty::Property VehicleProperty::TirePressureLeftRear = "TirePressureLeftRear"; const VehicleProperty::Property VehicleProperty::TirePressureRightRear = "TirePressureRightRear"; +const VehicleProperty::Property VehicleProperty::VehiclePowerMode = "VehiclePowerMode"; + +std::list<VehicleProperty::Property> VehicleProperty::mCapabilities; 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); }); + 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(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); }); + registerProperty(BatteryVoltage, [](){ return new BatteryVoltageType(0); }); + registerProperty(InteriorTemperature, [](){ return new InteriorTemperatureType(0); }); + registerProperty(EngineOilTemperature, [](){ return new EngineOilTemperatureType(0); }); + registerProperty(VIN, [](){ return new VINType(""); }); + registerProperty(WMI, [](){ return new WMIType(""); }); + REGISTERPROPERTYWITHTYPE(TirePressureLeftFront, TirePressureType, 0); + REGISTERPROPERTYWITHTYPE(TirePressureRightFront, TirePressureType, 0); + REGISTERPROPERTYWITHTYPE(TirePressureLeftRear, TirePressureType, 0); + REGISTERPROPERTYWITHTYPE(TirePressureRightRear, TirePressureType, 0); + registerProperty( VehiclePowerMode,[](){ return new VehiclePowerModeType(Power::Off); } ); } std::list<VehicleProperty::Property> VehicleProperty::capabilities() { - PropertyList mProperties; - - mProperties.push_back(VehicleSpeed); - mProperties.push_back(EngineSpeed); - mProperties.push_back(TransmissionShiftPosition); - mProperties.push_back(TransmissionGearPosition); - mProperties.push_back(ThrottlePosition); - mProperties.push_back(WheelBrake); - mProperties.push_back(SteeringWheelAngle); - mProperties.push_back(TurnSignal); - mProperties.push_back(ClutchStatus); - mProperties.push_back(EngineOilPressure); - mProperties.push_back(EngineCoolantTemperature); - mProperties.push_back(AccelerationX); - mProperties.push_back(AccelerationY); - mProperties.push_back(AccelerationZ); - mProperties.push_back(MassAirFlow); - mProperties.push_back(ButtonEvent); - mProperties.push_back(AirIntakeTemperature); - mProperties.push_back(BatteryVoltage); - mProperties.push_back(InteriorTemperature); - mProperties.push_back(EngineOilTemperature); - mProperties.push_back(MachineGunTurretStatus); - mProperties.push_back(VIN); - mProperties.push_back(WMI); - mProperties.push_back(TirePressureLeftFront); - mProperties.push_back(TirePressureRightFront); - mProperties.push_back(TirePressureLeftRear); - mProperties.push_back(TirePressureRightRear); - - return mProperties; + return mCapabilities; } AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value) { - if(name == VehicleSpeed ) return new VehicleSpeedType(value); - else if(name == EngineSpeed) return new EngineSpeedType(value); - else if(name == TransmissionShiftPosition) return new TransmissionShiftPositionType(value); - else if(name == TransmissionGearPosition) return new TransmissionGearPositionType(value); - else if(name == ThrottlePosition) return new ThrottlePositionType(value); - else if(name == WheelBrake) return new WheelBrakeType(value); - else if(name == SteeringWheelAngle) return new SteeringWheelAngleType(value); - else if(name == TurnSignal) return new TurnSignalType(value); - else if(name == ClutchStatus) return new ClutchStatusType(value); - else if(name == EngineOilPressure) return new EngineOilPressureType(value); - else if(name == EngineCoolantTemperature) return new EngineCoolantTemperatureType(value); - else if(name == AccelerationX) return new AccelerationType(value); - else if(name == AccelerationY) return new AccelerationType(value); - else if(name == AccelerationZ) return new AccelerationType(value); - else if(name == MassAirFlow) return new MassAirFlowType(value); - else if(name == ButtonEvent) return new ButtonEventType(value); - else if(name == AirIntakeTemperature) return new AirIntakeTemperatureType(value); - else if(name == BatteryVoltage) return new BatteryVoltageType(value); - else if(name == InteriorTemperature) return new InteriorTemperatureType(value); - else if(name == EngineOilTemperature) return new EngineOilTemperatureType(value); - else if(name == VIN) return new VINType(value); - else if(name == WMI) return new WMIType(value); - else if(name == TirePressureLeftFront) return new TirePressureType(value); - else if(name == TirePressureRightFront) return new TirePressureType(value); - else if(name == TirePressureLeftRear) return new TirePressureType(value); - else if(name == TirePressureRightRear) return new TirePressureType(value); - - else + if(registeredPropertyFactoryMap.count(name) > 0) { - if(registeredPropertyFactoryMap.count(name) > 0) + VehicleProperty::PropertyTypeFactoryCallback cb = registeredPropertyFactoryMap[name]; + if ( cb != NULL ) { - VehicleProperty::PropertyTypeFactoryCallback cb = registeredPropertyFactoryMap[name]; - if ( cb != NULL ) - { - AbstractPropertyType* type = cb(); - if(type == NULL) - throw std::runtime_error("Cannot return NULL in a PropertyTypeFactory"); + AbstractPropertyType* type = cb(); + if(type == NULL) + throw std::runtime_error("Cannot return NULL in a PropertyTypeFactory"); - type->fromString(value); - - return type; - } + type->fromString(value); + return type; } + } return nullptr; @@ -148,4 +124,7 @@ AbstractPropertyType* VehicleProperty::getPropertyTypeForPropertyNameValue(Vehic void VehicleProperty::registerProperty(VehicleProperty::Property name, VehicleProperty::PropertyTypeFactoryCallback factory) { registeredPropertyFactoryMap[name] = factory; + mCapabilities.push_back(name); } + +VehicleProperty vehiclePropertyConstruct; diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h index 1be0af96..3b70d40f 100644 --- a/lib/vehicleproperty.h +++ b/lib/vehicleproperty.h @@ -31,6 +31,7 @@ namespace ButtonEvents { enum ButtonEventType { + NoButton = 0, PlayButton = 1, SkipButton = 1 << 1, PrevButton = 1 << 2, @@ -79,6 +80,16 @@ enum TransmissionPositions }; } +namespace Power { +enum PowerModes +{ + Off = 0, + Accessory1 = 1, + Accessory2 = 2, + Run = 3 +}; +} + class VehicleProperty { @@ -206,6 +217,9 @@ public: static const Property TirePressureRightRear; typedef BasicPropertyType<uint16_t> TirePressureType; + static const Property VehiclePowerMode; + typedef BasicPropertyType<Power::PowerModes> VehiclePowerModeType; + static std::list<VehicleProperty::Property> capabilities(); @@ -221,7 +235,7 @@ public: private: static std::map<Property, PropertyTypeFactoryCallback> registeredPropertyFactoryMap; - + static std::list<VehicleProperty::Property> mCapabilities; }; typedef std::list<VehicleProperty::Property> PropertyList; diff --git a/plugins/dbus/properties.h b/plugins/dbus/properties.h index ccb02231..dd1c5d99 100644 --- a/plugins/dbus/properties.h +++ b/plugins/dbus/properties.h @@ -50,6 +50,17 @@ public: } }; +class VehiclePowerModeProperty: public DBusSink +{ +public: + VehiclePowerModeProperty(AbstractRoutingEngine* re, GDBusConnection* connection) + :DBusSink("org.automotive.tirePressure","/org/automotive/maintainance/tirePressure", re, connection, map<string, string>()) + { + wantProperty<uint16_t>(VehicleProperty::VehiclePowerMode, "VehiclePowerMode","b",AbstractProperty::Read); + supportedChanged(re->supported()); + } +}; + #endif |