fixed websocketsource. possibly removed mem leak 13/2313/1
authorKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 17 Oct 2012 23:17:47 +0000 (16:17 -0700)
committerKevron Rees <kevron_m_rees@linux.intel.com>
Wed, 17 Oct 2012 23:17:47 +0000 (16:17 -0700)
14 files changed:
TODO
ambd/core.cpp
ambd/core.h
lib/abstractroutingengine.h
lib/abstractsource.h
lib/vehicleproperty.h
plugins/exampleplugin.cpp
plugins/exampleplugin.h
plugins/obd2plugin/obd2source.h
plugins/websocketsink/websocketsinkmanager.cpp
plugins/websocketsink/websocketsinkmanager.h
plugins/websocketsourceplugin/websocketsource.cpp
plugins/websocketsourceplugin/websocketsource.h
plugins/wheel/wheelplugin.h

diff --git a/TODO b/TODO
index c6db1a1..53c7aaa 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,5 +1,6 @@
 - bluetooth adapter setting in obd2source
 - test for memory leaks in websocket sink plugin
+- implement websocket source getProperty methods and setProperty
 - per-source property filtering in routing engine
 - historic data "get" interface in routing engine
 - sqlite database storage plugin
index 1059498..ff014b3 100644 (file)
@@ -188,6 +188,23 @@ AsyncPropertyReply *Core::getPropertyAsync(AsyncPropertyRequest request)
        return reply;
 }
 
+AsyncRangePropertyReply *Core::getRangePropertyAsync(AsyncRangePropertyRequest request)
+{
+       AsyncRangePropertyReply * reply = new AsyncRangePropertyReply(request);
+
+       for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
+       {
+               AbstractSource* src = (*itr);
+               PropertyList properties = src->supported();
+               if(ListPlusPlus<VehicleProperty::Property>(&properties).contains(request.property))
+               {
+                       src->getRangePropertyAsync(reply);
+               }
+       }
+
+       return reply;
+}
+
 void Core::setProperty(VehicleProperty::Property property, AbstractPropertyType *value)
 {
        for(SourceList::iterator itr = mSources.begin(); itr != mSources.end(); itr++)
index b03d84d..4f4b14a 100644 (file)
@@ -43,6 +43,7 @@ public:
        void registerSink(AbstractSink *self);
        void unregisterSink(AbstractSink *self);
        AsyncPropertyReply* getPropertyAsync(AsyncPropertyRequest request);
+       AsyncRangePropertyReply* getRangePropertyAsync(AsyncRangePropertyRequest request);
        void setProperty(VehicleProperty::Property,AbstractPropertyType*);
        void subscribeToProperty(VehicleProperty::Property, AbstractSink* self);
        void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self);
index 1d90a96..b01df5a 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <boost/any.hpp>
 #include <functional>
+#include <time.h>
 #include "vehicleproperty.h"
 #include "abstractpropertytype.h"
 
@@ -35,6 +36,26 @@ typedef std::function<void (AsyncPropertyReply*)> CompletedSignal;
 class AsyncPropertyRequest
 {
 public:
+       AsyncPropertyRequest()
+               :property(VehicleProperty::NoValue)
+       {
+
+       }
+
+       AsyncPropertyRequest(const AsyncPropertyRequest &request)
+       {
+               this->property = request.property;
+               this->completed = request.completed;
+       }
+
+       AsyncPropertyRequest & operator = (const AsyncPropertyRequest & other)
+       {
+               this->property = other.property;
+               this->completed = other.completed;
+
+               return *this;
+       }
+
        VehicleProperty::Property property;
        CompletedSignal completed;
 };
@@ -42,13 +63,54 @@ public:
 class AsyncPropertyReply: public AsyncPropertyRequest
 {
 public:
-       AsyncPropertyReply(AsyncPropertyRequest request)
+       AsyncPropertyReply(const AsyncPropertyRequest &request)
+               :AsyncPropertyRequest(request), value(NULL)
+       {
+
+       }
+
+       AbstractPropertyType* value;
+};
+
+class AsyncRangePropertyRequest: public AsyncPropertyRequest
+{
+public:
+       AsyncRangePropertyRequest()
+               :begin(0), end(0)
+       {
+
+       }
+
+       AsyncRangePropertyRequest(const AsyncPropertyRequest &request)
+               :AsyncPropertyRequest(request), begin(0), end(0)
        {
                this->property = request.property;
                this->completed = request.completed;
        }
 
-       AbstractPropertyType* value;
+       AsyncRangePropertyRequest(const AsyncRangePropertyRequest &request)
+               :AsyncPropertyRequest(request)
+       {
+               this->property = request.property;
+               this->completed = request.completed;
+               this->begin = request.begin;
+               this->end = request.end;
+       }
+
+       time_t begin;
+       time_t end;
+};
+
+class AsyncRangePropertyReply: public AsyncRangePropertyRequest
+{
+public:
+       AsyncRangePropertyReply(AsyncRangePropertyRequest request)
+               :AsyncRangePropertyRequest(request)
+       {
+
+       }
+
+       std::list<AbstractPropertyType*> values;
 };
 
 class AbstractRoutingEngine
@@ -62,6 +124,7 @@ public:
        virtual void registerSink(AbstractSink* self) = 0;
        virtual void  unregisterSink(AbstractSink* self) = 0;
        virtual AsyncPropertyReply *getPropertyAsync(AsyncPropertyRequest request) = 0;
+       virtual AsyncRangePropertyReply * getRangePropertyAsync(AsyncRangePropertyRequest request) = 0;
        virtual void setProperty(VehicleProperty::Property, AbstractPropertyType*) = 0;
        virtual void subscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
        virtual void unsubscribeToProperty(VehicleProperty::Property, AbstractSink* self) = 0;
index 70d55f5..d9a0ee3 100644 (file)
@@ -45,6 +45,7 @@ public:
        ///pure virtual methods:
 
        virtual void getPropertyAsync(AsyncPropertyReply *reply) = 0;
+       virtual void getRangePropertyAsync(AsyncRangePropertyReply *reply) = 0;
        virtual void setProperty(VehicleProperty::Property property, AbstractPropertyType* value) = 0;
        virtual void subscribeToPropertyChanges(VehicleProperty::Property property) = 0;
        virtual void unsubscribeToPropertyChanges(VehicleProperty::Property property) = 0;
index 57d3fd8..23813f9 100644 (file)
@@ -88,6 +88,12 @@ enum Mode {
 }
 
 namespace Power {
+/**< Vehicle Power Modes
+ * Off = Vehicle is off and key is in the "off" position.
+ * Accessory1 = Vehicle is off and key is in Accessory1 position.
+ * Accessory2 = Vehicle is off and key is in Accessory2 position.
+ * Run = Vehichle is running.  Key is in the running position.
+ */
 enum PowerModes
 {
        Off = 0,
@@ -227,6 +233,9 @@ public:
        static const Property TirePressureRightRear;
        typedef BasicPropertyType<uint16_t> TirePressureType;
 
+       /**< Vehicle Power Mode.
+        *@see Power::PowerModes
+        */
        static const Property VehiclePowerMode;
        typedef BasicPropertyType<Power::PowerModes> VehiclePowerModeType;
 
@@ -255,6 +264,8 @@ public:
        static const Property InteriorLightCenter;
        static const Property InteriorLightPassenger;
 
+
+
        static std::list<VehicleProperty::Property> capabilities();
 
        /*! getPropertyTypeForPropertyNameValue returns an AbstractPropertyType* for the property name
index ab6a718..923ccd8 100644 (file)
@@ -68,6 +68,9 @@ string ExampleSourcePlugin::uuid()
 void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
 {
        DebugOut()<<"ExampleSource: getPropertyAsync called for property: "<<reply->property<<endl;
+
+
+
        if(reply->property == VehicleProperty::VehicleSpeed)
        {
                VehicleProperty::VehicleSpeedType temp(velocity);
@@ -118,6 +121,11 @@ void ExampleSourcePlugin::getPropertyAsync(AsyncPropertyReply *reply)
        }
 }
 
+void ExampleSourcePlugin::getRangePropertyAsync(AsyncRangePropertyReply *reply)
+{
+
+}
+
 void ExampleSourcePlugin::setProperty(VehicleProperty::Property , AbstractPropertyType *)
 {
 
@@ -182,5 +190,5 @@ void ExampleSourcePlugin::randomizeProperties()
        routingEngine->updateProperty(VehicleProperty::TransmissionShiftPosition,&tsp);
        routingEngine->updateProperty(VehicleProperty::ThrottlePosition, &tp);
        routingEngine->updateProperty(VehicleProperty::EngineCoolantTemperature, &ec);
-       routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);
+       //routingEngine->updateProperty(VehicleProperty::MachineGunTurretStatus, &mgt);
 }
index 5187c5c..5bd2776 100644 (file)
@@ -32,6 +32,7 @@ public:
        
        string uuid();
        void getPropertyAsync(AsyncPropertyReply *reply);
+       void getRangePropertyAsync(AsyncRangePropertyReply *reply);
        void setProperty(VehicleProperty::Property, AbstractPropertyType*);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
index 9c97d35..ae9b1bb 100644 (file)
@@ -57,6 +57,7 @@ public:
        string uuid();
        int portHandle;
        void getPropertyAsync(AsyncPropertyReply *reply);
+       void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
        void setProperty(VehicleProperty::Property, AbstractPropertyType*);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
index 50f9125..9373b15 100644 (file)
@@ -228,19 +228,28 @@ extern "C" AbstractSinkManager * create(AbstractRoutingEngine* routingengine, ma
 }
 void WebSocketSinkManager::disconnectAll(libwebsocket* socket)
 {
+       std::list<WebSocketSink*> toDeleteList;
+
        for (auto i=m_sinkMap.begin(); i != m_sinkMap.end();i++)
        {
                if ((*i).second->socket() == socket)
                {
                        //This is the sink in question.
                        WebSocketSink* sink = (*i).second;
-                       delete sink;
-                       m_sinkMap.erase((*i).first);
-                       i--;
-                       //printf("Sink removed\n");
-                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Sink removed\n";
+                       if(!ListPlusPlus<WebSocketSink*>(&toDeleteList).contains(sink))
+                       {
+                               toDeleteList.push_back(sink);
+                       }
+                       m_sinkMap.erase(i);
+                       i=m_sinkMap.begin();
+                       DebugOut() << __SMALLFILE__ <<":"<< __LINE__ << "Sink removed"<<endl;
                }
        }
+
+       for(auto i=toDeleteList.begin();i!=toDeleteList.end();i++)
+       {
+               delete *i;
+       }
 }
 void WebSocketSinkManager::addPoll(int fd)
 {
index e94a362..e08d546 100644 (file)
@@ -39,7 +39,7 @@ public:
        void addPoll(int fd);
        void removePoll(int fd);
        void init();
-       map<std::string,WebSocketSink*> m_sinkMap;
+       map<std::string, WebSocketSink*> m_sinkMap;
        void setConfiguration(map<string, string> config);
        void setValue(string property,string value);
 private:
index b172621..16a4a45 100644 (file)
@@ -315,8 +315,9 @@ WebSocketSource::WebSocketSource(AbstractRoutingEngine *re, map<string, string>
        m_re = re;  
        context = libwebsocket_create_context(CONTEXT_PORT_NO_LISTEN, NULL,protocols, libwebsocket_internal_extensions,NULL, NULL, -1, -1, 0);
        
-       
+       setConfiguration(config);
        re->setSupported(supported(), this);
+
        //printf("websocketsource loaded!!!\n");
        
 }
@@ -333,17 +334,7 @@ string WebSocketSource::uuid()
 {
        return "d293f670-f0b3-11e1-aff1-0800200c9a66";
 }
-boost::any WebSocketSource::getProperty(VehicleProperty::Property property)
-{
-       if(property == VehicleProperty::VehicleSpeed)
-       {
-               //return velocity;
-       }
-       else if(property == VehicleProperty::EngineSpeed)
-       {
-               //return engineSpeed;
-       }
-}
+
 void WebSocketSource::subscribeToPropertyChanges(VehicleProperty::Property property)
 {
        //printf("Subscribed to property: %s\n",property.c_str());
@@ -367,34 +358,15 @@ void WebSocketSource::unsubscribeToPropertyChanges(VehicleProperty::Property pro
 
 void WebSocketSource::getPropertyAsync(AsyncPropertyReply *reply)
 {
-       /*if(reply->property == VehicleProperty::VehicleSpeed)
-       {
-               reply->value = velocity;
-               reply->completed(reply);
-       }
-       else if(reply->property == VehicleProperty::EngineSpeed)
-       {
-               reply->value = engineSpeed;
-               reply->completed(reply);
-       }
-       else if(reply->property == VehicleProperty::AccelerationX)
-       {
-               reply->value = accelerationX;
-               reply->completed(reply);
-       }
-       else if(reply->property == VehicleProperty::TransmissionShiftPosition)
-       {
-               reply->value = transmissionShiftPostion;
-               reply->completed(reply);
-       }
-       else if(reply->property == VehicleProperty::SteeringWheelAngle)
-       {
-               reply->value = steeringWheelAngle;
-               reply->completed(reply);
-       }*/
+       ///TODO: fill in
 }
 
-void WebSocketSource::setProperty(VehicleProperty::Property , AbstractPropertyType * )
+void WebSocketSource::getRangePropertyAsync(AsyncRangePropertyReply *reply)
 {
+       ///TODO: fill in
+}
 
+void WebSocketSource::setProperty(VehicleProperty::Property , AbstractPropertyType * )
+{
+       ///TODO: fill in
 }
index 3eacd70..b5eeb5c 100644 (file)
@@ -34,8 +34,8 @@ class WebSocketSource : public AbstractSource
 public:
        WebSocketSource(AbstractRoutingEngine* re, map<string, string> config);
     string uuid();
-       boost::any getProperty(VehicleProperty::Property property);
        void getPropertyAsync(AsyncPropertyReply *reply);
+       void getRangePropertyAsync(AsyncRangePropertyReply *reply);
        void setProperty(VehicleProperty::Property, AbstractPropertyType*);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);
@@ -50,7 +50,7 @@ public:
        void propertyChanged(VehicleProperty::Property property, AbstractPropertyType* value, string uuid) {}
        void supportedChanged(PropertyList) {}
        void setConfiguration(map<string, string> config);
-       //void randomizeProperties();
+
 private:
        PropertyList m_supportedProperties;
 
index 7b94c5f..5ac1528 100644 (file)
@@ -35,6 +35,7 @@ public:
        
        string uuid();
        void getPropertyAsync(AsyncPropertyReply *reply);
+       void getRangePropertyAsync(AsyncRangePropertyReply *reply){}
        void setProperty(VehicleProperty::Property, AbstractPropertyType*);
        void subscribeToPropertyChanges(VehicleProperty::Property property);
        void unsubscribeToPropertyChanges(VehicleProperty::Property property);