From 6f79dc6f211242dcc6495025f03aa4b7056579a4 Mon Sep 17 00:00:00 2001 From: Kevron Rees Date: Fri, 7 Jun 2013 22:18:19 -0700 Subject: [PATCH] fixed fromString when bool is T --- examples/bluemonkey/bluemonkeyconfig | 3 ++- lib/abstractpropertytype.h | 42 ++++++++++++++++++++++++++++++- lib/vehicleproperty.h | 4 +-- plugins/bluemonkey/bluemonkey.cpp | 7 +++++- plugins/database/databasesink.cpp | 48 ++++++++++++++++++------------------ plugins/database/databasesink.h | 18 +++++++------- 6 files changed, 84 insertions(+), 38 deletions(-) diff --git a/examples/bluemonkey/bluemonkeyconfig b/examples/bluemonkey/bluemonkeyconfig index 02243e5..6d862a9 100644 --- a/examples/bluemonkey/bluemonkeyconfig +++ b/examples/bluemonkey/bluemonkeyconfig @@ -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": [ diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h index 610cba2..a2ef5ec 100644 --- a/lib/abstractpropertytype.h +++ b/lib/abstractpropertytype.h @@ -32,6 +32,8 @@ #include #include "timestamp.h" #include +#include + 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 void serialize(std::string val, typename std::enable_if::value, N>::type* = 0) { - std::stringstream stream(val); + std::stringstream stream(GVS::stringize(val)); N someTemp; stream>>someTemp; setValue(someTemp); diff --git a/lib/vehicleproperty.h b/lib/vehicleproperty.h index e81b636..0ae9fae 100644 --- a/lib/vehicleproperty.h +++ b/lib/vehicleproperty.h @@ -285,8 +285,8 @@ enum AirflowDirection #define PROPERTYTYPEBASIC1(property, valueType) \ class property ## Type : public BasicPropertyType { \ - 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) \ diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp index fa3f357..09b41f0 100644 --- a/plugins/bluemonkey/bluemonkey.cpp +++ b/plugins/bluemonkey/bluemonkey.cpp @@ -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; diff --git a/plugins/database/databasesink.cpp b/plugins/database/databasesink.cpp index 93195b3..33ce930 100644 --- a/plugins/database/databasesink.cpp +++ b/plugins/database/databasesink.cpp @@ -146,9 +146,9 @@ DatabaseSink::DatabaseSink(AbstractRoutingEngine *engine, mapsubscribeToProperty(*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 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 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()) { setPlayback(false); startDb(); reply->success = true; - BasicPropertyType temp(true); - routingEngine->updateProperty(DatabaseLoggingProperty,&temp,uuid()); + DatabaseLoggingType temp(true); + routingEngine->updateProperty(DatabaseLogging,&temp,uuid()); } else { stopDb(); reply->success = true; - BasicPropertyType 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()) { setLogging(false); startPlayback(); - BasicPropertyType 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 temp(playback); + DatabasePlaybackType temp(playback); - routingEngine->updateProperty(DatabasePlaybackProperty, &temp, uuid()); + routingEngine->updateProperty(DatabasePlayback, &temp, uuid()); } reply->success = true; diff --git a/plugins/database/databasesink.h b/plugins/database/databasesink.h index f28a20b..117d135 100644 --- a/plugins/database/databasesink.h +++ b/plugins/database/databasesink.h @@ -28,9 +28,9 @@ #include -#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 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");}); } }; -- 2.7.4