2 Copyright (C) 2012 Intel Corporation
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include "varianttype.h"
21 #include "abstractdbusinterface.h"
22 #include <listplusplus.h>
24 VariantType::VariantType(AbstractRoutingEngine* re, VehicleProperty::Property ambPropertyName, std::string propertyName, Access access)
25 :mPropertyName(propertyName), mAccess(access), mValue(nullptr), mZoneFilter(Zone::None), mUpdateFrequency(0), mInitialized(false)
27 mAmbPropertyName = ambPropertyName;
30 setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName));
33 void VariantType::initialize()
35 if(mInitialized) return;
36 AsyncPropertyRequest request;
37 request.property = mAmbPropertyName;
38 request.sourceUuidFilter = mSourceFilter;
39 request.zoneFilter = mZoneFilter;
41 using namespace std::placeholders;
42 request.completed = [this](AsyncPropertyReply* r)
44 auto reply = amb::make_unique(r);
46 setValue(reply->value->copy());
48 DebugOut(DebugOut::Error)<<"get request unsuccessful for "<<reply->property<<" : "<<reply->error<<endl;
53 /// do not request if not supported:
54 PropertyList proplist = routingEngine->supported();
56 if(contains(proplist, mAmbPropertyName))
57 routingEngine->getPropertyAsync(request);
60 VariantType::~VariantType()
68 GVariant *VariantType::toVariant()
72 setValue(VehicleProperty::getPropertyTypeForPropertyNameValue(name()));
77 return v->toVariant();
80 void VariantType::fromVariant(GVariant *val)
82 AbstractPropertyType *v = VehicleProperty::getPropertyTypeForPropertyNameValue(name());
85 AsyncSetPropertyRequest request;
86 request.property = name();
88 request.zoneFilter = zoneFilter();
89 request.completed = [&](AsyncPropertyReply* r)
91 auto reply = amb::make_unique(r);
92 /// TODO: throw dbus exception
95 DebugOut(DebugOut::Error)<<"SetProperty fail: "<<reply->error<<endl;
99 routingEngine->setProperty(request);