fixed fromString when bool is T
authorKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 05:18:19 +0000 (22:18 -0700)
committerKevron Rees <tripzero.kev@gmail.com>
Sat, 8 Jun 2013 05:18:19 +0000 (22:18 -0700)
examples/bluemonkey/bluemonkeyconfig
lib/abstractpropertytype.h
lib/vehicleproperty.h
plugins/bluemonkey/bluemonkey.cpp
plugins/database/databasesink.cpp
plugins/database/databasesink.h

index 02243e5..6d862a9 100644 (file)
@@ -5,7 +5,8 @@
                {
                        "name" : "Database",
                         "path" : "/usr/lib/automotive-message-broker/databasesinkplugin.so",
-                        "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }"             
+                        "properties" : "{ 'properties' : ['VehicleSpeed','EngineSpeed'] }",
+                       "startOnLoad" : "true"          
                }
        ],
        "sinks": [
index 610cba2..a2ef5ec 100644 (file)
@@ -32,6 +32,8 @@
 #include <list>
 #include "timestamp.h"
 #include <debugout.h>
+#include <boost/algorithm/string.hpp>
+
 namespace Zone {
 enum Type {
        None = 0,
@@ -116,6 +118,11 @@ public:
        {
                return g_variant_get_int32(v);
        }
+
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -128,6 +135,10 @@ public:
        {
                return g_variant_get_double(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -140,6 +151,10 @@ public:
        {
                return g_variant_get_uint16(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -152,6 +167,10 @@ public:
        {
                return g_variant_get_int16(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -164,6 +183,10 @@ public:
        {
                return g_variant_get_byte(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -176,6 +199,10 @@ public:
        {
                return g_variant_get_uint32(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -188,6 +215,10 @@ public:
        {
                return g_variant_get_int64(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -200,6 +231,10 @@ public:
        {
                g_variant_get_uint64(v);
        }
+       static std::string stringize(std::string v)
+       {
+               return v;
+       }
 };
 
 template <>
@@ -212,6 +247,11 @@ public:
        {
                return g_variant_get_boolean(v);
        }
+       static std::string stringize(std::string v)
+       {
+               boost::algorithm::to_lower(v);
+               return v == "true" ? "1":"0";
+       }
 };
 
 
@@ -338,7 +378,7 @@ private:
        template <class N>
        void serialize(std::string  val,  typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
        {
-               std::stringstream stream(val);
+               std::stringstream stream(GVS<T>::stringize(val));
                N someTemp;
                stream>>someTemp;
                setValue(someTemp);
index e81b636..0ae9fae 100644 (file)
@@ -285,8 +285,8 @@ enum AirflowDirection
 
 #define PROPERTYTYPEBASIC1(property, valueType) \
        class property ## Type : public BasicPropertyType<valueType> { \
-       public: property ## Type(): BasicPropertyType("property") {} \
-       property ## Type(valueType val) : BasicPropertyType("property", val) {} \
+       public: property ## Type(): BasicPropertyType( #property) {} \
+       property ## Type(valueType val) : BasicPropertyType(#property, val) {} \
        };
 
 #define PROPERTYTYPENOVAL(property, propertyType, baseClass) \
index fa3f357..09b41f0 100644 (file)
@@ -219,8 +219,13 @@ void Property::setValue(QVariant v)
                mValue->fromString(json.toStdString());
        }
 
+
+
        else
-               mValue->fromString(v.toString().toStdString());
+       {
+               QString tempVal = v.toString();
+               mValue->fromString(tempVal.toStdString());
+       }
 
        AsyncSetPropertyRequest request;
        request.property = mValue->name;
index 93195b3..33ce930 100644 (file)
@@ -146,9 +146,9 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, map<std::string, std::
                engine->subscribeToProperty(*itr,this);
        }
 
-       mSupported.push_back(DatabaseFileProperty);
-       mSupported.push_back(DatabaseLoggingProperty);
-       mSupported.push_back(DatabasePlaybackProperty);
+       mSupported.push_back(DatabaseFile);
+       mSupported.push_back(DatabaseLogging);
+       mSupported.push_back(DatabasePlayback);
 
        routingEngine->setSupported(supported(), this);
 
@@ -331,7 +331,7 @@ void DatabaseSink::initDb()
 void DatabaseSink::setPlayback(bool v)
 {
        AsyncSetPropertyRequest request;
-       request.property = DatabasePlaybackProperty;
+       request.property = DatabasePlayback;
        request.value = new DatabasePlaybackType(v);
 
        setProperty(request);
@@ -340,7 +340,7 @@ void DatabaseSink::setPlayback(bool v)
 void DatabaseSink::setLogging(bool b)
 {
        AsyncSetPropertyRequest request;
-       request.property = DatabaseLoggingProperty;
+       request.property = DatabaseLogging;
        request.value = new DatabaseLoggingType(b);
 
        setProperty(request);
@@ -397,9 +397,9 @@ void DatabaseSink::getPropertyAsync(AsyncPropertyReply *reply)
 {
        reply->success = false;
 
-       if(reply->property == DatabaseFileProperty)
+       if(reply->property == DatabaseFile)
        {
-               DatabaseFilePropertyType temp(databaseName);
+               DatabaseFileType temp(databaseName);
                reply->value = &temp;
 
                reply->success = true;
@@ -407,9 +407,9 @@ void DatabaseSink::getPropertyAsync(AsyncPropertyReply *reply)
 
                return;
        }
-       else if(reply->property == DatabaseLoggingProperty)
+       else if(reply->property == DatabaseLogging)
        {
-               BasicPropertyType<bool> temp = shared;
+               DatabaseLoggingType temp = shared;
 
                reply->value = &temp;
                reply->success = true;
@@ -418,9 +418,9 @@ void DatabaseSink::getPropertyAsync(AsyncPropertyReply *reply)
                return;
        }
 
-       else if(reply->property == DatabasePlaybackProperty)
+       else if(reply->property == DatabasePlayback)
        {
-               BasicPropertyType<bool> temp = playback;
+               DatabasePlaybackType temp = playback;
                reply->value = &temp;
                reply->success = true;
                reply->completed(reply);
@@ -489,47 +489,47 @@ AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request)
        AsyncPropertyReply* reply = new AsyncPropertyReply(request);
        reply->success = false;
 
-       if(request.property == DatabaseLoggingProperty)
+       if(request.property == DatabaseLogging)
        {
                if(request.value->value<bool>())
                {
                        setPlayback(false);
                        startDb();
                        reply->success = true;
-                       BasicPropertyType<bool> temp(true);
-                       routingEngine->updateProperty(DatabaseLoggingProperty,&temp,uuid());
+                       DatabaseLoggingType temp(true);
+                       routingEngine->updateProperty(DatabaseLogging,&temp,uuid());
                }
                else
                {
                        stopDb();
                        reply->success = true;
-                       BasicPropertyType<bool> temp(false);
-                       routingEngine->updateProperty(DatabaseLoggingProperty,&temp,uuid());
+                       DatabaseLoggingType temp(false);
+                       routingEngine->updateProperty(DatabaseLogging,&temp,uuid());
                }
        }
 
-       else if(request.property == DatabaseFileProperty)
+       else if(request.property == DatabaseFile)
        {
                std::string fname = request.value->toString();
 
                databaseName = fname;
 
-               StringPropertyType temp(databaseName);
+               DatabaseFileType temp(databaseName);
 
-               routingEngine->updateProperty(DatabaseFileProperty,&temp,uuid());
+               routingEngine->updateProperty(DatabaseFile,&temp,uuid());
 
                reply->success = true;
        }
-       else if( request.property == DatabasePlaybackProperty)
+       else if( request.property == DatabasePlayback)
        {
                if(request.value->value<bool>())
                {
                        setLogging(false);
                        startPlayback();
 
-                       BasicPropertyType<bool> temp(playback);
+                       DatabasePlaybackType temp(playback);
 
-                       routingEngine->updateProperty(DatabasePlaybackProperty,&temp,uuid());
+                       routingEngine->updateProperty(DatabasePlayback,&temp,uuid());
                }
                else
                {
@@ -538,9 +538,9 @@ AsyncPropertyReply *DatabaseSink::setProperty(AsyncSetPropertyRequest request)
 
                        playback = false;
 
-                       BasicPropertyType<bool> temp(playback);
+                       DatabasePlaybackType temp(playback);
 
-                       routingEngine->updateProperty(DatabasePlaybackProperty, &temp, uuid());
+                       routingEngine->updateProperty(DatabasePlayback, &temp, uuid());
                }
 
                reply->success = true;
index f28a20b..117d135 100644 (file)
@@ -28,9 +28,9 @@
 
 #include <functional>
 
-#define DatabaseLoggingProperty "DatabaseLogging"
-#define DatabasePlaybackProperty "DatabasePlayback"
-#define DatabaseFileProperty "DatabaseFile"
+const std::string DatabaseLogging = "DatabaseLogging";
+const std::string DatabasePlayback = "DatabasePlayback";
+const std::string DatabaseFile = "DatabaseFile";
 
 template <typename T>
 class Queue
@@ -183,9 +183,9 @@ private:
        uint playbackMultiplier;
 };
 
-PROPERTYTYPEBASIC1(DatabaseLogging, bool)
-PROPERTYTYPEBASIC1(DatabasePlayback, bool)
-PROPERTYTYPE1(DatabaseFile, DatabaseFilePropertyType, StringPropertyType, std::string)
+PROPERTYTYPEBASIC(DatabaseLogging, bool)
+PROPERTYTYPEBASIC(DatabasePlayback, bool)
+PROPERTYTYPE(DatabaseFile, DatabaseFileType, StringPropertyType, std::string)
 
 
 class DatabaseSinkManager: public AbstractSinkManager
@@ -195,9 +195,9 @@ public:
        :AbstractSinkManager(engine, config)
        {
                new DatabaseSink(routingEngine, config);
-               VehicleProperty::registerProperty(DatabaseLoggingProperty, [](){return new DatabaseLoggingType(false);});
-               VehicleProperty::registerProperty(DatabasePlaybackProperty, [](){return new DatabasePlaybackType(false);});
-               VehicleProperty::registerProperty(DatabaseFileProperty, [](){return new DatabaseFilePropertyType("storage");});
+               VehicleProperty::registerProperty(DatabaseLogging, [](){return new DatabaseLoggingType(false);});
+               VehicleProperty::registerProperty(DatabasePlayback, [](){return new DatabasePlaybackType(false);});
+               VehicleProperty::registerProperty(DatabaseFile, [](){return new DatabaseFileType("storage");});
        }
 };