1 #include "varianttype.h"
2 #include "abstractroutingengine.h"
3 #include "abstractdbusinterface.h"
5 #include "listplusplus.h"
7 VariantType::VariantType(AbstractRoutingEngine* re, VehicleProperty::Property ambPropertyName, std::string propertyName, Access access)
8 :AbstractPropertyType(ambPropertyName), mInitialized(false), mAccess(access), mPropertyName(propertyName),
11 name = ambPropertyName;
13 setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(name));
16 void VariantType::initialize()
18 if(mInitialized) return;
19 AsyncPropertyRequest request;
20 request.property = name;
21 request.sourceUuidFilter = sourceUuid;
22 request.zoneFilter = zone;
24 using namespace std::placeholders;
25 request.completed = [this](AsyncPropertyReply* r)
27 auto reply = amb::make_unique(r);
29 setValue(reply->value->copy());
31 DebugOut(DebugOut::Error)<<"get request unsuccessful for "<<reply->property<<" : "<<reply->error<<endl;
36 /// do not request if not supported:
37 PropertyList proplist = routingEngine->supported();
39 if(contains(proplist, name))
40 routingEngine->getPropertyAsync(request);
43 GVariant *VariantType::toVariant()
47 setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(name));
52 return v->toVariant();
55 void VariantType::fromVariant(GVariant *val)
57 AbstractPropertyType *v = VehicleProperty::getPropertyTypeForPropertyNameValue(name);
60 AsyncSetPropertyRequest request;
61 request.property = name;
63 request.zoneFilter = zone;
64 request.completed = [&](AsyncPropertyReply* r)
66 auto reply = amb::make_unique(r);
67 /// TODO: throw dbus exception
70 DebugOut(DebugOut::Error)<<"SetProperty fail: "<<reply->error<<endl;
74 routingEngine->setProperty(request);