it compiles
authorKevron Rees <tripzero.kev@gmail.com>
Tue, 28 Aug 2012 23:50:55 +0000 (16:50 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 28 Aug 2012 23:50:55 +0000 (16:50 -0700)
lib/abstractpropertytype.h
lib/vehicleproperty.cpp
lib/vehicleproperty.h
plugins/websocketsourceplugin/websocketsource.cpp
plugins/websocketsourceplugin/websocketsource.h

index 2ded031..86448c4 100644 (file)
@@ -22,6 +22,7 @@
 #include <string>
 #include <sstream>
 #include <boost/any.hpp>
+#include <boost/lexical_cast.hpp>
 
 class AbstractPropertyType
 {
@@ -69,6 +70,11 @@ public:
                setValue(val);
        }
 
+       BasicPropertyType(std::string val)
+       {
+               setValue(boost::lexical_cast<T,std::string>(val));
+       }
+
        std::string toString()
        {
                std::stringstream stream;
index 692eeba..7cebf2e 100644 (file)
@@ -18,6 +18,7 @@
 
 
 #include "vehicleproperty.h"
+#include <map>
 
 using namespace std;
 
@@ -66,3 +67,26 @@ std::list<VehicleProperty::Property> VehicleProperty::capabilities()
 
        return mProperties;
 }
+
+AbstractPropertyType VehicleProperty::getPropertyTypeForPropertyNameValue(VehicleProperty::Property name, std::string value)
+{
+       std::map<VehicleProperty::Property, AbstractPropertyType> theMap;
+
+       theMap[VehicleSpeed] = VehicleSpeedType(value);
+       theMap[EngineSpeed] = EngineSpeedType(value);
+       theMap[TransmissionShiftPosition] = TransmissionShiftPositionType(value);
+       theMap[TransmissionGearPosition] = TransmissionGearPositionType(value);
+       theMap[ThrottlePosition] = ThrottlePositionType(value);
+       theMap[WheelBrake] = WheelBrakeType(value);
+       theMap[SteeringWheelAngle] = SteeringWheelAngleType(value);
+       theMap[TurnSignal] = TurnSignalType(value);
+       theMap[ClutchStatus] = ClutchStatusType(value);
+       theMap[EngineOilPressure] = EngineOilPressureType(value);
+       theMap[EngineCoolantTemperature] = EngineCoolantTemperatureType(value);
+       theMap[AccelerationX] = AccelerationType(value);
+       theMap[AccelerationY] = AccelerationType(value);
+       theMap[AccelerationZ] = AccelerationType(value);
+       theMap[MassAirFlow] = MassAirFlowType(value);
+
+       return theMap[name];
+}
index 75921fc..20ecaa9 100644 (file)
@@ -104,7 +104,7 @@ public:
 
        /**< Acceleration on the 'x' axis in 1/1000 gravitational acceleration "g-force" */
        static const Property AccelerationX;
-       typedef BasicPropertyType<uint16_t> AcclerationType;
+       typedef BasicPropertyType<uint16_t> AccelerationType;
 
        /**< Acceleration on the 'y' axis in 1/1000 gravitational acceleration "g-force" */
        static const Property AccelerationY;
@@ -117,6 +117,8 @@ public:
        typedef BasicPropertyType<uint16_t> MassAirFlowType;
 
        static std::list<VehicleProperty::Property> capabilities();
+
+       static AbstractPropertyType getPropertyTypeForPropertyNameValue(Property name, std::string value);
     
 };
 
index cae3010..50f1869 100644 (file)
@@ -211,8 +211,7 @@ static int callback_http_only(libwebsocket_context *context,struct libwebsocket
                        //data.front()
                        try
                        {
-                               uint16_t val = boost::lexical_cast<uint16_t,string>(data.front());
-                               m_re->updateProperty(name,boost::any(val));
+                               m_re->updateProperty(name,VehicleProperty::getPropertyTypeForPropertyNameValue(name,data.front()));
                        }
                        catch (exception ex)
                        {
@@ -423,7 +422,7 @@ void WebSocketSource::getPropertyAsync(AsyncPropertyReply *reply)
        }*/
 }
 
-void WebSocketSource::setProperty(VehicleProperty::Property , boost::any )
+void WebSocketSource::setProperty(VehicleProperty::Property , AbstractPropertyType )
 {
 
 }
index b7d1967..10b926a 100644 (file)
@@ -36,7 +36,7 @@ public:
     string uuid();
        boost::any getProperty(VehicleProperty::Property property);
        void getPropertyAsync(AsyncPropertyReply *reply);
-       void setProperty(VehicleProperty::Property, boost::any);
+       void setProperty(VehicleProperty::Property, AbstractPropertyType);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
        PropertyList supported();
@@ -47,7 +47,7 @@ public:
        PropertyList activeRequests;
        PropertyList removeRequests;
        void setSupported(PropertyList list);
-       void propertyChanged(VehicleProperty::Property property, boost::any value, string uuid) {}
+       void propertyChanged(VehicleProperty::Property property, AbstractPropertyType value, string uuid) {}
        void supportedChanged(PropertyList) {}
        
        //void randomizeProperties();