updated docs. added deleted callback
authorKevron Rees <tripzero.kev@gmail.com>
Tue, 7 Oct 2014 15:49:27 +0000 (08:49 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Tue, 7 Oct 2014 15:51:21 +0000 (08:51 -0700)
ambd/core.cpp
examples/bluemonkey/bluemonkeyconfig
lib/abstractpropertytype.h
lib/asyncqueue.hpp

index 9911cc1..277ba5a 100644 (file)
@@ -157,11 +157,29 @@ void Core::updateProperty(AbstractPropertyType *value, const string & uuid)
        if(value->priority == AbstractPropertyType::Instant)
                updateProperty(value);
        else if(value->priority == AbstractPropertyType::High)
+       {
+               value->destroyed.push_back([this](AbstractPropertyType* v)
+               {
+                       updatePropertyQueueHigh.remove(v);
+               });
                updatePropertyQueueHigh.append(value);
+       }
        else if(value->priority == AbstractPropertyType::Normal)
+       {
+               value->destroyed.push_back([this](AbstractPropertyType* v)
+               {
+                       updatePropertyQueue.remove(v);
+               });
                updatePropertyQueue.append(value);
+       }
        else if(value->priority == AbstractPropertyType::Low)
+       {
+               value->destroyed.push_back([this](AbstractPropertyType* v)
+               {
+                       updatePropertyQueueLow.remove(v);
+               });
                updatePropertyQueueLow.append(value);
+       }
 }
 
 void Core::updateProperty(AbstractPropertyType * value)
index fb0080c..97d3ddb 100644 (file)
@@ -1,9 +1,9 @@
 {
-  "mainloop" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/qtmainloopplugin.so",
+  "mainloop" : "/usr/local/lib/x86_64-linux-gnu/automotive-message-broker/automotive-message-broker/qtmainloopplugin.so",
 
   "sources" : [
     {
-      "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/bluemonkeyplugin.so",
+      "path" : "/usr/local/lib/x86_64-linux-gnu/automotive-message-broker/automotive-message-broker/bluemonkeyplugin.so",
       "config" : "/etc/ambd/bluemonkey/config.js"
     }
   ],
@@ -11,7 +11,7 @@
   "sinks" : [
 
     {
-      "path" : "/usr/lib/i386-linux-gnu/automotive-message-broker/automotive-message-broker/examplesinkplugin.so"
+      "path" : "/usr/local/lib/x86_64-linux-gnu/automotive-message-broker/automotive-message-broker/examplesinkplugin.so"
     }
   ]
 }
index decc456..b9e2a33 100644 (file)
@@ -24,6 +24,7 @@
 #include <stdexcept>
 #include <vector>
 #include <iostream>
+#include <memory>
 #include <boost/any.hpp>
 #include <boost/lexical_cast.hpp>
 #include <boost/utility.hpp>
@@ -74,27 +75,55 @@ public:
         */
        enum Priority
        {
-               Normal = 0,
-               Low,
-               High,
-               Instant
+               Normal = 0, /*!< normal priority.  This is default */
+               Low, /*!< Low priority. */
+               High, /*!< High priority*/
+               Instant /*!< Instant.  Using this priority is not thread safe.  This is typically used for
+                                *    Properties that need to be deterministic.
+                                */
        };
 
-       AbstractPropertyType(std::string property): name(property), timestamp(amb::currentTime()), sequence(-1), zone(Zone::None), priority(Normal)
+       AbstractPropertyType(std::string property)
+               : name(property), timestamp(amb::currentTime()), sequence(-1), zone(Zone::None), priority(Normal)
        {
                void*(name);
        }
 
-       virtual ~AbstractPropertyType() { }
+       virtual ~AbstractPropertyType()
+       {
+               for(auto i : destroyed)
+               {
+                       if(i) i(this);
+               }
+       }
 
+       /**
+        * @brief toString
+        * @return strigified value
+        */
        virtual std::string toString() const = 0;
 
+       /**
+        * @brief fromString converts from string value
+        */
        virtual void fromString(std::string)= 0;
 
+       /**
+        * @brief toVariant
+        * @return GVariant representation of value. Caller must unref the returned GVariant
+        */
        virtual GVariant* toVariant() = 0;
 
+       /**
+        * @brief fromVariant converts GVariant value into compatible native value.  Caller owns
+        * GVariant argument.
+        */
        virtual void fromVariant(GVariant*) = 0;
 
+       /**
+        * @brief copy
+        * @return a copy of the AbstractPropertyType
+        */
        virtual AbstractPropertyType* copy() = 0;
 
        /**
@@ -126,14 +155,33 @@ public:
                return one != two;
        }
 
+       /**
+        * @brief name Property name. @see VehicleProperty for built-in supported property names
+        */
        std::string name;
 
+       /**
+        * @brief timestamp.  Timestamp when the value was last updated by the system. This is updated automatically
+        * any time setValue() is called
+        * @see amb::currentTime()
+        * @see setValue()
+        */
        double timestamp;
 
+       /**
+        * @brief sequence internal counter.  Useful as a unique indentifier.  values is -1 if not used (default).
+        */
        int32_t sequence;
 
+       /**
+        * @brief sourceUuid  uuid of the source that produced this property.  This is set by the routingengine
+        * if left unmodified.
+        */
        std::string sourceUuid;
 
+       /**
+        * @brief zone that the property is situated in.
+        */
        Zone::Type zone;
 
        /*!
@@ -144,23 +192,40 @@ public:
         */
        Priority priority;
 
+       /**
+        * @brief setValue
+        * @param val boost::any value.  NOTE: boost::any does not accept type coercion.  Types must match exactly
+        * with native type. (ie, don't use "int" if the native type is "uint")
+        */
        virtual void setValue(boost::any val)
        {
                mValue = val;
                timestamp = amb::currentTime();
        }
 
+       /**
+        * \brief value() native value.  Does not use type coercion.  Will throw if types do not match.
+        */
        template <typename T>
        T value() const
        {
                return boost::any_cast<T>(mValue);
        }
 
+       /**
+        * @brief anyValue
+        * @return boost::any value
+        */
        boost::any anyValue()
        {
                return mValue;
        }
 
+       /**
+        * @brief destroyed is called if this property is destroyed.
+        */
+       std::vector<std::function<void(AbstractPropertyType*)>> destroyed;
+
 protected:
 
        boost::any mValue;
@@ -319,7 +384,13 @@ public:
        }
 };
 
-
+/**
+ * \brief BasicPropertyType is a typed property type.  Most internal types are derived from this class
+ * \example
+ * std::unique_ptr<BasicPropertyType<int>> boostPSI = new BasicPropertyType<int>("BoostPSI",5);
+ * boostPSI->priority = AbstractPropertyType::Instant; //set instant because we clean up right after.
+ * routingEngine->updateProperty(boostPSI.get(), sourceUuid());
+ */
 template <typename T>
 class BasicPropertyType: public AbstractPropertyType
 {
@@ -406,16 +477,6 @@ public:
                mValue = T();
        }
 
-       /*BasicPropertyType(std::string val)
-               :AbstractPropertyType("")
-       {
-               if(!val.empty() && val != "")
-               {
-                       serialize<T>(val);
-               }
-               else setValue(T());
-       }*/
-
        AbstractPropertyType* copy()
        {
                return new BasicPropertyType<T>(*this);
@@ -448,6 +509,11 @@ public:
                setValue(deserializeVariant<T>(v));
        }
 
+       /**
+        * @brief basicValue
+        * @return Typed version of value.  Slightly more useful than @see AbstractPropertyType::value()
+        */
+
        T basicValue()
        {
                return value<T>();
index ce2c1f7..f7881e4 100644 (file)
@@ -19,6 +19,7 @@
 #include <glib.h>
 
 #include <abstractpropertytype.h>
+#include "listplusplus.h"
 
 #include <mutex>
 #include <unordered_set>
@@ -66,6 +67,12 @@ public:
                mQueue.insert(item);
        }
 
+       void remove(T item)
+       {
+               std::lock_guard<std::mutex> lock(mutex);
+               removeOne(&mQueue, item);
+       }
+
 protected:
        std::mutex mutex;
        std::unordered_set<T,std::hash<T>, Pred> mQueue;