summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevron Rees <kevron.m.rees@intel.com>2014-12-08 11:46:58 -0800
committerKevron Rees <kevron.m.rees@intel.com>2014-12-08 11:46:58 -0800
commit2375bd8ca3f45877b0b63c33c4a57dfcd0b6b126 (patch)
tree9efc730d37e95ab57e19ad4c6688127b45f2ed6a
parentfdfc5cfbf57d82c99e0e5c447611eb1be37b90e2 (diff)
downloadautomotive-message-broker-2375bd8ca3f45877b0b63c33c4a57dfcd0b6b126.tar.gz
bluemonkey support list types
-rw-r--r--lib/abstractpropertytype.h21
-rw-r--r--plugins/bluemonkey/bluemonkey.cpp58
-rw-r--r--plugins/bluemonkey/config.js6
-rw-r--r--plugins/common/ambpluginimpl.cpp5
4 files changed, 59 insertions, 31 deletions
diff --git a/lib/abstractpropertytype.h b/lib/abstractpropertytype.h
index e00531b4..0157b530 100644
--- a/lib/abstractpropertytype.h
+++ b/lib/abstractpropertytype.h
@@ -696,7 +696,7 @@ public:
}
};
-template <class T>
+template <class T = AbstractPropertyType>
class ListPropertyType: public AbstractPropertyType
{
public:
@@ -758,6 +758,18 @@ public:
return new ListPropertyType(*this);
}
+ void quickCopy(AbstractPropertyType* other)
+ {
+ AbstractPropertyType::quickCopy(other);
+ ListPropertyType<T>* v = static_cast<ListPropertyType<T>*>(other);
+ if(!v)
+ {
+ DebugOut(DebugOut::Error) << "ListPropertyType Quick Copy failed" << endl;
+ return;
+ }
+ mList = v->list();
+ }
+
std::string toString() const
{
std::string str = "[";
@@ -785,13 +797,11 @@ public:
if(!str.length())
return;
- if(str[0] != '[' && str[str.length()-1] != ']')
+ if(str[0] == '[' && str[str.length()-1] == ']')
{
- return;
+ str = str.substr(1,str.length() - 2);
}
- str = str.substr(1,str.length() - 2);
-
std::vector<std::string> elements;
std::istringstream f(str);
@@ -802,6 +812,7 @@ public:
T foo("", element);
append (foo);
}
+ timestamp = amb::currentTime();
}
diff --git a/plugins/bluemonkey/bluemonkey.cpp b/plugins/bluemonkey/bluemonkey.cpp
index be37a648..556bb5f6 100644
--- a/plugins/bluemonkey/bluemonkey.cpp
+++ b/plugins/bluemonkey/bluemonkey.cpp
@@ -81,9 +81,9 @@ QVariant gvariantToQVariant(GVariant *value)
{
gsize dictsize = g_variant_n_children(value);
QVariantList list;
- for (int i=0;i<dictsize;i++)
+ for (int i=0; i<dictsize; i++)
{
- GVariant *childvariant = g_variant_get_child_value(value,i);
+ GVariant *childvariant = g_variant_get_child_value(value, i);
GVariant *innervariant = g_variant_get_variant(childvariant);
list.append(gvariantToQVariant(innervariant));
}
@@ -95,6 +95,38 @@ QVariant gvariantToQVariant(GVariant *value)
}
+AbstractPropertyType* qVariantToAbstractPropertyType(QString name, QVariant var)
+{
+ if(!var.isValid())
+ return nullptr;
+
+ if(var.type() == QVariant::UInt)
+ return new BasicPropertyType<uint>(name.toStdString(), var.toUInt());
+ else if(var.type() == QVariant::Double)
+ return new BasicPropertyType<double>(name.toStdString(), var.toDouble());
+ else if(var.type() == QVariant::Bool)
+ return new BasicPropertyType<bool>(name.toStdString(), var.toBool());
+ else if(var.type() == QVariant::Int)
+ return new BasicPropertyType<int>(name.toStdString(), var.toInt());
+ else if(var.type() == QVariant::String)
+ return new StringPropertyType(name.toStdString(), var.toString().toStdString());
+ else if(var.type() == QVariant::List && var.toList().count())
+ {
+ QVariant subVariant = var.toList().at(0);
+ if(subVariant.type() == QVariant::UInt)
+ return new ListPropertyType<BasicPropertyType<uint>>(name.toStdString(), subVariant.toUInt());
+ else if(subVariant.type() == QVariant::Double)
+ return new ListPropertyType<BasicPropertyType<double>>(name.toStdString(), subVariant.toDouble());
+ else if(subVariant.type() == QVariant::Bool)
+ return new ListPropertyType<BasicPropertyType<bool>>(name.toStdString(), subVariant.toBool());
+ else if(subVariant.type() == QVariant::Int)
+ return new ListPropertyType<BasicPropertyType<int>>(name.toStdString(), subVariant.toInt());
+ else if(subVariant.type() == QVariant::String)
+ return new ListPropertyType<StringPropertyType>(name.toStdString(), subVariant.toString().toStdString());
+ }
+ return nullptr;
+}
+
BluemonkeySink::BluemonkeySink(AbstractRoutingEngine* e, map<string, string> config, AbstractSource &parent): QObject(0), AmbPluginImpl(e, config, parent), engine(nullptr), mSilentMode(false)
{
QTimer::singleShot(1,this,SLOT(reloadEngine()));
@@ -346,23 +378,11 @@ void BluemonkeySink::createCustomProperty(QString name, QJSValue defaultValue, i
{
QVariant var = defaultValue.toVariant();
- auto create = [defaultValue, name, var]() -> AbstractPropertyType*
- {
- if(!var.isValid())
- return nullptr;
-
- if(var.type() == QVariant::UInt)
- return new BasicPropertyType<uint>(name.toStdString(), var.toUInt());
- else if(var.type() == QVariant::Double)
- return new BasicPropertyType<double>(name.toStdString(), var.toDouble());
- else if(var.type() == QVariant::Bool)
- return new BasicPropertyType<bool>(name.toStdString(), var.toBool());
- else if(var.type() == QVariant::Int)
- return new BasicPropertyType<int>(name.toStdString(), var.toInt());
- else if(var.type() == QVariant::String)
- return new StringPropertyType(name.toStdString(), var.toString().toStdString());
+ DebugOut() << "Variant value for: " << name.toStdString() << " is " << defaultValue.toString().toStdString() << endl;
- return nullptr;
+ auto create = [name, var]() -> AbstractPropertyType*
+ {
+ return qVariantToAbstractPropertyType(name, var);
};
addPropertySupport(zone, create);
@@ -370,7 +390,7 @@ void BluemonkeySink::createCustomProperty(QString name, QJSValue defaultValue, i
AsyncSetPropertyRequest request;
request.property = name.toStdString();
request.zoneFilter = zone;
- request.value = VehicleProperty::getPropertyTypeForPropertyNameValue(name.toStdString(), var.toString().toStdString());
+ request.value = VehicleProperty::getPropertyTypeForPropertyNameValue(name.toStdString(), defaultValue.toString().toStdString());
routingEngine->updateSupported(supported(), PropertyList(), &source);
routingEngine->setProperty(request);
diff --git a/plugins/bluemonkey/config.js b/plugins/bluemonkey/config.js
index 8d6795a9..410c275f 100644
--- a/plugins/bluemonkey/config.js
+++ b/plugins/bluemonkey/config.js
@@ -98,7 +98,7 @@ bluemonkey.createCustomProperty("TirePressureLow", false);
bluemonkey.createCustomProperty("TireTemperature", 20);
bluemonkey.createCustomProperty("ActiveNoiseControlMode", false);
-bluemonkey.createCustomProperty("AvailableSounds", [""]);
+bluemonkey.createCustomProperty("AvailableSounds", ["LightSpeed", "v8"]);
bluemonkey.createCustomProperty("EngineSoundEnhancementMode", "");
bluemonkey.createCustomProperty("SeatPositionBackCushion", 0);
@@ -161,8 +161,8 @@ bluemonkey.createCustomProperty("OccupantName", "Kevron", Zone.Front | Zone.Left
bluemonkey.createCustomProperty("OccupantName", "Irene", Zone.Front | Zone.Right);
bluemonkey.createCustomProperty("OccupantName", "Miggie", Zone.Rear | Zone.Right);
bluemonkey.createCustomProperty("OccupantName", "Emma", Zone.Rear | Zone.Left);
-bluemonkey.createCustomProperty("OccupantIdentificationType", "camera", Zone.Rear | Zone.Left);
-bluemonkey.createCustomProperty("OccupantIdentificationType", "Bluetooth", Zone.Rear | Zone.Left);
+bluemonkey.createCustomProperty("OccupantIdentificationType", "camera", Zone.Front | Zone.Left);
+bluemonkey.createCustomProperty("OccupantIdentificationType", "Bluetooth", Zone.Front | Zone.Right);
bluemonkey.createCustomProperty("OccupantIdentificationType", "pin", Zone.Rear | Zone.Right);
bluemonkey.createCustomProperty("OccupantIdentificationType", "pin", Zone.Rear | Zone.Left);
diff --git a/plugins/common/ambpluginimpl.cpp b/plugins/common/ambpluginimpl.cpp
index 9865d8f3..ec678f7b 100644
--- a/plugins/common/ambpluginimpl.cpp
+++ b/plugins/common/ambpluginimpl.cpp
@@ -81,11 +81,8 @@ AsyncPropertyReply *AmbPluginImpl::setProperty(const AsyncSetPropertyRequest& re
AbstractPropertyType *value = findPropertyType(request.property, request.zoneFilter);
if (value && request.value) {
DebugOut(2) << "updating property "<< request.property << " to: " << request.value->toString() << endl;
- value->fromString(request.value->toString());
- DebugOut(2) << "New value of property "<< request.property << " is: " << value->toString() << endl;
- value->timestamp = amb::currentTime();
+ value->quickCopy(request.value);
routingEngine->updateProperty(value, uuid());
-
reply->success = true;
reply->error = AsyncPropertyReply::NoError;
}