#include "abstractpropertytype.h"
+const Zone::Type Zone::FrontRight = Zone::Type(Zone::Front | Zone::Right);
+const Zone::Type Zone::FrontLeft = Zone::Type(Zone::Front | Zone::Left);
+const Zone::Type Zone::MiddleRight = Zone::Type(Zone::Middle | Zone::Right);
+const Zone::Type Zone::MiddleLeft = Zone::Type(Zone::Middle | Zone::Left);
+const Zone::Type Zone::RearRight = Zone::Type(Zone::Rear | Zone::Right);
+const Zone::Type Zone::RearLeft = Zone::Type(Zone::Rear | Zone::Left);
BackSide = 1 << 9
};
-static const Zone::Type FrontRight = Zone::Type(Front | Right);
-static const Zone::Type FrontLeft = Zone::Type(Front | Left);
-static const Zone::Type MiddleRight = Zone::Type(Middle | Right);
-static const Zone::Type MiddleLeft = Zone::Type(Middle | Left);
-static const Zone::Type RearRight = Zone::Type(Rear | Right);
-static const Zone::Type RearLeft = Zone::Type(Rear | Left);
+static const Zone::Type FrontRight;
+static const Zone::Type FrontLeft;
+static const Zone::Type MiddleRight;
+static const Zone::Type MiddleLeft;
+static const Zone::Type RearRight;
+static const Zone::Type RearLeft;
typedef std::list<Zone::Type> ZoneList;
AsyncPropertyReply::AsyncPropertyReply(const AsyncPropertyRequest &request)
:AsyncPropertyRequest(request), value(NULL), success(false), timeoutSource(nullptr)
{
+ setTimeout();
+}
+
+AsyncPropertyReply::AsyncPropertyReply(const AsyncSetPropertyRequest &request)
+ :AsyncPropertyRequest(request), value(request.value), success(false), timeoutSource(nullptr)
+{
+ setTimeout();
+ value->zone = request.zoneFilter;
+}
+
+void AsyncPropertyReply::setTimeout()
+{
auto timeoutfunc = [](gpointer userData) {
AsyncPropertyReply* thisReply = static_cast<AsyncPropertyReply*>(userData);
if(thisReply->success == false)
class AbstractSource;
class AsyncPropertyReply;
class AsyncRangePropertyReply;
+class AsyncSetPropertyRequest;
typedef std::function<void (AsyncPropertyReply*)> GetPropertyCompletedSignal;
public:
AsyncPropertyReply(const AsyncPropertyRequest &request);
+ AsyncPropertyReply(const AsyncSetPropertyRequest &request);
+
virtual ~AsyncPropertyReply()
{
if(timeoutSource)
Error error;
private:
+ void setTimeout();
GSource* timeoutSource;
};
/*!
* \brief The AsyncSetPropertyRequest class is used by sinks to set a property to the 'value'. The source will reply
- * with a AsyncPropertyReply containing the new value or an error
+ * with a AsyncPropertyReply containing the new value or an error.
* \see AbstractRoutingEngine::setProperty
* \see AsyncPropertyReply
*/
}
- virtual ~AsyncSetPropertyRequest() { }
+ virtual ~AsyncSetPropertyRequest()
+ {
+
+ }
/*!
* \brief value the new value to set the property to.
void VariantType::fromGVariant(GVariant *val)
{
- AbstractPropertyType* v = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName);
+ AbstractPropertyType *v = VehicleProperty::getPropertyTypeForPropertyNameValue(mAmbPropertyName);
v->fromVariant( val );
AsyncSetPropertyRequest request;
request.property = mAmbPropertyName;
request.value = v;
- request.completed = [](AsyncPropertyReply* reply)
+ request.zoneFilter = mZoneFilter;
+ request.completed = [&](AsyncPropertyReply* reply)
{
/// TODO: throw dbus exception
if(!reply->success)
{
DebugOut(DebugOut::Error)<<"setProperty fail: "<<reply->error<<endl;
}
+ delete v;
delete reply;
};
addPropertySupport(VehicleProperty::MachineGunTurretStatus, Zone::None);
addPropertySupport(VehicleProperty::ExteriorBrightness, Zone::None);
addPropertySupport(VehicleProperty::DoorsPerRow, Zone::None);
- addPropertySupport(VehicleProperty::AirbagStatus, Zone::FrontLeft);
+ addPropertySupport(VehicleProperty::AirbagStatus, Zone::None);
Zone::ZoneList airbagZones;
airbagZones.push_back(Zone::FrontLeft | Zone::FrontSide);
propertyInfoMap[VehicleProperty::AirbagStatus] = airbagInfo;
+ addPropertySupport(VehicleProperty::AirConditioning, Zone::None);
+
+ Zone::ZoneList acZones;
+ acZones.push_back(Zone::FrontLeft);
+ acZones.push_back(Zone::Front | Zone::Right);
+
+ acStatus[Zone::Front | Zone::Left] = true;
+ acStatus[Zone::Front | Zone::Right] = false;
+
+ PropertyInfo acInfo(0,acZones);
+ propertyInfoMap[VehicleProperty::AirConditioning] = acInfo;
+
re->setSupported(supported(), this);
}
reply->completed(reply);
}
}
+ else if(reply->property == VehicleProperty::AirConditioning)
+ {
+ if(acStatus.find(reply->zoneFilter) == acStatus.end())
+ {
+ reply->success = false;
+ reply->error = AsyncPropertyReply::ZoneNotSupported;
+ reply->completed(reply);
+ }
+ else
+ {
+ VehicleProperty::AirConditioningType temp(acStatus[reply->zoneFilter]);
+ reply->success = true;
+ reply->value = &temp;
+ reply->completed(reply);
+ }
+ }
else
{
AsyncPropertyReply *ExampleSourcePlugin::setProperty(AsyncSetPropertyRequest request )
{
+ AsyncPropertyReply *reply = new AsyncPropertyReply(request);
+
+ if(reply->property == VehicleProperty::AirConditioning)
+ {
+ if(acStatus.find(reply->zoneFilter) == acStatus.end())
+ {
+ reply->success = false;
+ reply->error = AsyncPropertyReply::ZoneNotSupported;
+ reply->completed(reply);
+ }
+ else
+ {
+ acStatus[reply->zoneFilter] = reply->value->value<bool>();
+
+ ///we need to update subscribers of this change:
+ routingEngine->updateProperty(reply->value,uuid());
+
+ ///Now reply to the set request:
+ reply->success = true;
+ reply->completed(reply);
+ }
+ }
}
void ExampleSourcePlugin::subscribeToPropertyChanges(VehicleProperty::Property property)
std::map<VehicleProperty::Property, PropertyInfo> propertyInfoMap;
std::map<Zone::Type, Airbag::Status> airbagStatus;
+ std::map<Zone::Type, bool> acStatus;
PropertyList mRequests;
PropertyList mSupported;
uint16_t velocity;