From 376fc2d59fc36fe625afbac93e25288ddb67e479 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 15 Jun 2012 11:04:43 -0700 Subject: [PATCH] some changes to abstract property --- docs/runningstatus.txt | 16 ++++++++-------- lib/abstractdbusinterface.cpp | 2 ++ lib/abstractdbusinterface.h | 2 +- lib/abstractproperty.cpp | 7 +++---- lib/abstractproperty.h | 24 ++++++++++++++++++++++-- lib/runningstatusinterface.cpp | 1 + lib/runningstatusinterface.h | 2 +- lib/vehiclespeed.cpp | 13 ++++++------- lib/vehiclespeed.h | 3 +-- 9 files changed, 45 insertions(+), 25 deletions(-) diff --git a/docs/runningstatus.txt b/docs/runningstatus.txt index b6fb902..154d70a 100644 --- a/docs/runningstatus.txt +++ b/docs/runningstatus.txt @@ -30,7 +30,7 @@ Properties byte VehiclePowerMode [readonly] byte TransmissionGearStatus [readonly] - Neautral = 0, + Neutral = 0, 1st = 1, 2nd = 2, 3rd = 3, @@ -89,37 +89,37 @@ Properties byte VehiclePowerMode [readonly] Remaining percentage of fuel. - uint16 FuelRange + uint16 FuelRange [readonly] Estimated fuel range with available fuel in km - struct{ byte, byte, byte } EngineOil + struct{ byte, byte, byte } EngineOil [readonly] Remaining Oil Percentage (byte) Engine Oil Temperature (byte) Engine Oil Pressure (byte) - struct{ byte, byte } EngineCoolant + struct{ byte, byte } EngineCoolant [readonly] Level (byte) Temperature (byte) - struct{ uint16, uint16, uint16 } Acceleration + struct{ uint16, uint16, uint16 } Acceleration [readonly] X, Y and Z acceleration in m/s*s - struct{ uint16, uint16, byte, uint32 } VehicleOdometry + struct{ uint16, uint16, byte, uint32 } VehicleOdometry [readonly] x_mm (uint16) y_mm (uint16) angle (byte) timestamp (in number of seconds since unix epoch: Jan 1, 1970) (uint32) - uint16 SteeringWheelAngle + uint16 SteeringWheelAngle [readonly] Angle of the steering wheel (0-360) - struct{ uint16, uint16 } WheelTickSensor + struct{ uint16, uint16 } WheelTickSensor [readonly] Left wheel rotation counter (uint16) Right wheel rotation counter (uint16) diff --git a/lib/abstractdbusinterface.cpp b/lib/abstractdbusinterface.cpp index 76007b0..d05d34a 100644 --- a/lib/abstractdbusinterface.cpp +++ b/lib/abstractdbusinterface.cpp @@ -21,6 +21,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include "abstractproperty.h" + unordered_map AbstractDBusInterface::interfaceMap; AbstractDBusInterface::AbstractDBusInterface(string interfaceName, string objectPath) diff --git a/lib/abstractdbusinterface.h b/lib/abstractdbusinterface.h index a360557..ff7a6e9 100644 --- a/lib/abstractdbusinterface.h +++ b/lib/abstractdbusinterface.h @@ -25,7 +25,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include -#include "abstractproperty.h" +class AbstractProperty; using namespace std; diff --git a/lib/abstractproperty.cpp b/lib/abstractproperty.cpp index 6514463..4ec6ecc 100644 --- a/lib/abstractproperty.cpp +++ b/lib/abstractproperty.cpp @@ -19,9 +19,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "abstractproperty.h" -AbstractProperty::AbstractProperty(string pn, string sig, Access access) - : mPropertyName(pn), mSignature(sig), mAccess(access) +AbstractProperty::AbstractProperty(string pn, string sig, Access access, AbstractDBusInterface* interface) + : mPropertyName(pn), mSignature(sig), mAccess(access), mInterface(interface) { - + interface->addProperty(this); } - diff --git a/lib/abstractproperty.h b/lib/abstractproperty.h index e8c5227..944c062 100644 --- a/lib/abstractproperty.h +++ b/lib/abstractproperty.h @@ -24,6 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include +#include "abstractdbusinterface.h" using namespace std; @@ -40,7 +41,7 @@ public: ReadWrite }; - AbstractProperty(string propertyName, string signature, Access access); + AbstractProperty(string propertyName, string signature, Access access, AbstractDBusInterface* interface); virtual void setSetterFunction(SetterFunc setterFunc) { @@ -61,15 +62,34 @@ public: { return mAccess; } - + virtual GVariant* toGVariant() = 0; virtual void fromGVariant(GVariant *value) = 0; +protected: ///methods: + + template + void setValue(T val) + { + mValue = val; + mInterface->updateValue(this); + } + + template + T value() + { + return boost::any_cast(mValue); + } + protected: + + boost::any mValue; string mPropertyName; string mSignature; SetterFunc mSetterFunc; Access mAccess; + + AbstractDBusInterface* mInterface; }; #endif // ABSTRACTPROPERTY_H diff --git a/lib/runningstatusinterface.cpp b/lib/runningstatusinterface.cpp index 8107e76..7371d8b 100644 --- a/lib/runningstatusinterface.cpp +++ b/lib/runningstatusinterface.cpp @@ -20,6 +20,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include #include "debugout.h" +#include "abstractproperty.h" using namespace std; diff --git a/lib/runningstatusinterface.h b/lib/runningstatusinterface.h index 7617967..6726840 100644 --- a/lib/runningstatusinterface.h +++ b/lib/runningstatusinterface.h @@ -26,7 +26,7 @@ class RunningStatusInterface : public AbstractDBusInterface { public: static RunningStatusInterface* iface(); - + protected: RunningStatusInterface(); diff --git a/lib/vehiclespeed.cpp b/lib/vehiclespeed.cpp index 5253a68..96df2a2 100644 --- a/lib/vehiclespeed.cpp +++ b/lib/vehiclespeed.cpp @@ -22,29 +22,28 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include -VehicleSpeedProperty::VehicleSpeedProperty(): AbstractProperty("VehicleSpeed", "q", AbstractProperty::Read) +VehicleSpeedProperty::VehicleSpeedProperty(): AbstractProperty("VehicleSpeed", "q", AbstractProperty::Read, RunningStatusInterface::iface()) { - RunningStatusInterface::iface()->addProperty(this); + } void VehicleSpeedProperty::setValue(uint16_t val) { - mValue = val; - RunningStatusInterface::iface()->updateValue(this); + AbstractProperty::setValue(val); } uint16_t VehicleSpeedProperty::value() { - return mValue; + return AbstractProperty::value(); } GVariant* VehicleSpeedProperty::toGVariant() { - return g_variant_new_uint16(mValue); + return g_variant_new_uint16(value()); } void VehicleSpeedProperty::fromGVariant(GVariant *value) { - mValue = (uint16_t)g_variant_get_uint16(value); + setValue((uint16_t)g_variant_get_uint16(value)); } diff --git a/lib/vehiclespeed.h b/lib/vehiclespeed.h index 5f36c7a..88ff01c 100644 --- a/lib/vehiclespeed.h +++ b/lib/vehiclespeed.h @@ -33,8 +33,7 @@ public: GVariant* toGVariant(); void fromGVariant(GVariant *value); -private: - uint16_t mValue; + }; #endif // VEHICLESPEED_H -- 2.7.4