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
19 #include <vehicleproperty.h>
20 #include <listplusplus.h>
22 #include "ambpluginimpl.h"
24 //----------------------------------------------------------------------------
26 //----------------------------------------------------------------------------
28 AmbPluginImpl::AmbPluginImpl(AbstractRoutingEngine* re, const map<string, string>& config, AbstractSource& parent) :
35 void AmbPluginImpl::init()
39 void AmbPluginImpl::getPropertyAsync(AsyncPropertyReply *reply)
42 DebugOut(DebugOut::Error) << "AmbPluginImpl::getPropertyAsync - reply is null" << std::endl;
46 DebugOut() << "AmbPluginImpl::getPropertyAsync called for property: " << reply->property << endl;
48 reply->success = false;
49 reply->error = AsyncPropertyReply::InvalidOperation;
50 AbstractPropertyType *value = findPropertyType(reply->property, reply->zoneFilter);
53 reply->success = true;
54 reply->error = AsyncPropertyReply::NoError;
58 reply->completed(reply);
61 void AmbPluginImpl::getRangePropertyAsync(AsyncRangePropertyReply *reply)
64 DebugOut(DebugOut::Error) << "AmbPluginImpl::getRangePropertyAsync - reply is null" << std::endl;
68 DebugOut() << "AmbPluginImpl::getRangePropertyAsync not supported "<< std::endl;
69 reply->success = false;
70 reply->error = AsyncPropertyReply::InvalidOperation;
72 reply->completed(reply);
75 AsyncPropertyReply *AmbPluginImpl::setProperty(const AsyncSetPropertyRequest& request )
77 AsyncPropertyReply* reply = new AsyncPropertyReply(request);
78 reply->success = false;
79 reply->error = AsyncPropertyReply::InvalidOperation;
81 AbstractPropertyType *value = findPropertyType(request.property, request.zoneFilter);
82 if (value && request.value) {
83 DebugOut(2) << "updating property "<< request.property << " to: " << request.value->toString() << endl;
84 value->quickCopy(request.value);
85 routingEngine->updateProperty(value, uuid());
86 reply->success = true;
87 reply->error = AsyncPropertyReply::NoError;
92 reply->completed(reply);
99 void AmbPluginImpl::subscribeToPropertyChanges(const VehicleProperty::Property& property)
104 PropertyList AmbPluginImpl::supported() const
107 for(auto itPropMap = properties.begin(); itPropMap != properties.end(); ++itPropMap)
108 props.push_back(itPropMap->first);
112 int AmbPluginImpl::supportedOperations() const
114 return AbstractSource::Get | AbstractSource::Set;
117 void AmbPluginImpl::unsubscribeToPropertyChanges(const VehicleProperty::Property& property)
121 // if signal does not exits return nullptr(we do not know its datatype), if zone does not exists, add it
122 AbstractPropertyType* AmbPluginImpl::findPropertyType(const VehicleProperty::Property& propertyName, const Zone::Type& zone)
124 auto itPropMap = properties.find(propertyName);
125 if(itPropMap == properties.end())
128 for( auto it = itPropMap->second.begin(); it != itPropMap->second.end(); ++it ) {
129 if(it->first == zone)
130 return it->second.get();
136 std::shared_ptr<AbstractPropertyType> AmbPluginImpl::addPropertySupport(Zone::Type zone, std::function<AbstractPropertyType* (void)> typeFactory, std::string sourceUuid)
138 if(sourceUuid.empty())
140 std::shared_ptr<AbstractPropertyType> propertyType(typeFactory());
144 VehicleProperty::Property name(propertyType->name);
145 PropertyList registeredProperties(VehicleProperty::capabilities());
146 bool registeredType(false);
147 if(!contains(registeredProperties,name))
149 registeredType = VehicleProperty::registerProperty(name, typeFactory);
152 { // Property type wasn't registered by us. Is it predefined in AMB API or some other source plug-in has already registered it ???
153 std::shared_ptr<AbstractPropertyType> registeredPropertyType(VehicleProperty::getPropertyTypeForPropertyNameValue(name));
154 if(!registeredPropertyType)
156 propertyType.swap(registeredPropertyType);
158 propertyType->zone = zone;
159 propertyType->sourceUuid = sourceUuid;
160 propertyType->timestamp = amb::currentTime();
161 ZonePropertyType& zonePropType = properties[name];
162 zonePropType.insert(make_pair(zone, propertyType));
166 PropertyInfo AmbPluginImpl::getPropertyInfo(const VehicleProperty::Property & property)
168 auto it = properties.find(property);
169 if(it != properties.end()) {
170 Zone::ZoneList zones;
171 for(auto itZonePropType = it->second.begin(); itZonePropType != it->second.end(); ++itZonePropType)
172 zones.push_back(itZonePropType->first);
174 return PropertyInfo( 0, zones );
177 return PropertyInfo::invalid();
180 void AmbPluginImpl::propertyChanged(AbstractPropertyType* value)
184 void AmbPluginImpl::supportedChanged(const PropertyList& supportedProperties)