#include "abstractpropertytype.h"
-
-void ListPropertyType::append(AbstractPropertyType *property)
-{
- mList.push_back(property->copy());
-}
-
-
-ListPropertyType::ListPropertyType()
-{
-
-}
-
-ListPropertyType::ListPropertyType(AbstractPropertyType *property)
-{
- append(property);
-}
-
-ListPropertyType::ListPropertyType(ListPropertyType &other)
-{
- std::list<AbstractPropertyType*> l = other.list();
- for(auto itr = l.begin(); itr != l.end(); itr++)
- {
- append(*itr);
- }
-}
-
-
-ListPropertyType::~ListPropertyType()
-{
-
-}
-
-
-uint ListPropertyType::count()
-{
- return mList.size();
-}
-
-
-AbstractPropertyType *ListPropertyType::copy()
-{
- return new ListPropertyType(*this);
-}
-
-
-std::string ListPropertyType::toString() const
-{
- std::string str = "[";
-
- for(auto itr = mList.begin(); itr != mList.end(); itr++)
- {
- if(str != "[")
- str += ",";
-
- AbstractPropertyType* t = *itr;
-
- str += t->toString();
- }
-
- str += "]";
-
- return str;
-}
-
-
-void ListPropertyType::fromString(std::string)
-{
- /// TODO: try to use VehicleProperty::getPropertyType... here
-}
-
-
-GVariant *ListPropertyType::toVariant()
-{
- GVariantBuilder params;
- g_variant_builder_init(¶ms, G_VARIANT_TYPE_ARRAY);
-
- for(auto itr = mList.begin(); itr != mList.end(); itr++)
- {
- AbstractPropertyType* t = *itr;
- g_variant_builder_add_value(¶ms, t->toVariant());
- }
-
- GVariant* var = g_variant_builder_end(¶ms);
- g_assert(var);
- return var;
-}
-
-
-void ListPropertyType::fromVariant(GVariant *v)
-{
-
-}
#include <string>
#include <sstream>
#include <stdexcept>
+#include <vector>
+#include <iostream>
#include <boost/any.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/utility.hpp>
GVariant* mVariant;
};
+template <class T>
class ListPropertyType: public AbstractPropertyType
{
public:
- ListPropertyType();
- ListPropertyType(AbstractPropertyType *property);
- ListPropertyType(ListPropertyType & other);
- ~ListPropertyType();
+ ListPropertyType():initialized(false){}
+ ListPropertyType(AbstractPropertyType *property):initialized(false)
+ {
+ appendPriv(property->copy());
+ }
+
+ ListPropertyType(ListPropertyType & other)
+ :initialized(false)
+ {
+ std::list<AbstractPropertyType*> l = other.list();
+ for(auto itr = l.begin(); itr != l.end(); itr++)
+ {
+ append(*itr);
+ }
+ }
+
+ ~ListPropertyType()
+ {
+ for(auto itr = mList.begin(); itr != mList.end(); itr++)
+ {
+ delete *itr;
+ }
+ }
+
+ /** append - appends a property to the list
+ * @arg property - property to be appended. Will be copied and owned by ListPropertyType.
+ * You are responsible for freeing property after append is called.
+ **/
+ void append(AbstractPropertyType* property)
+ {
+ if(!initialized)
+ {
+ for(auto itr = mList.begin(); itr != mList.end(); itr++)
+ {
+ AbstractPropertyType *p = *itr;
+ delete p;
+ }
+ mList.clear();
+ initialized = true;
+ }
- void append(AbstractPropertyType* property);
+ appendPriv(property->copy());
+ }
+
+ uint count()
+ {
+ return mList.size();
+ }
+
+ AbstractPropertyType* copy()
+ {
+ return new ListPropertyType(*this);
+ }
- uint count();
+ std::string toString() const
+ {
+ std::string str = "[";
+
+ for(auto itr = mList.begin(); itr != mList.end(); itr++)
+ {
+ if(str != "[")
+ str += ",";
- AbstractPropertyType* copy();
+ AbstractPropertyType* t = *itr;
- std::string toString() const;
- void fromString(std::string );
+ str += t->toString();
+ }
+
+ str += "]";
+ return str;
+ }
- GVariant* toVariant();
- void fromVariant(GVariant* v);
+
+ void fromString(std::string str )
+ {
+ if(!str.length())
+ return;
+
+ if(str[0] != '[' && str[str.length()-1] != ']')
+ {
+ return;
+ }
+
+ str = str.substr(1,str.length() - 2);
+
+ std::vector<std::string> elements;
+
+ std::istringstream f(str);
+
+ std::string element;
+ while(std::getline(f,element,','))
+ {
+ T *foo = new T(element);
+ append (foo);
+
+ delete foo;
+ }
+ }
+
+
+ GVariant* toVariant()
+ {
+
+ GVariantBuilder params;
+ g_variant_builder_init(¶ms, G_VARIANT_TYPE_ARRAY);
+
+ for(auto itr = mList.begin(); itr != mList.end(); itr++)
+ {
+ AbstractPropertyType* t = *itr;
+ g_variant_builder_add_value(¶ms, t->toVariant());
+ }
+
+ GVariant* var = g_variant_builder_end(¶ms);
+ g_assert(var);
+ return var;
+
+ }
+
+ void fromVariant(GVariant* v)
+ {
+
+ }
std::list<AbstractPropertyType*> list() { return mList; }
private:
+ void appendPriv(AbstractPropertyType* i)
+ {
+ mList.push_back(i);
+ }
+
+ bool initialized;
+
std::list<AbstractPropertyType*> mList;
};
f.precision(15);
f<<time;
- while(f.str().length() < 15)
+ while(f.str().length() <= 15)
{
f<<" ";
}
const VehicleProperty::Property VehicleProperty::TransmissionMode = "TransmissionMode";
const VehicleProperty::Property VehicleProperty::ThrottlePosition = "ThrottlePosition";
const VehicleProperty::Property VehicleProperty::WheelBrake = "WheelBrake";
+const VehicleProperty::Property VehicleProperty::WheelBrakePressure = "WheelBrakePressure";
const VehicleProperty::Property VehicleProperty::SteeringWheelAngle = "SteeringWheelAngle";
const VehicleProperty::Property VehicleProperty::TurnSignal = "TurnSignal";
const VehicleProperty::Property VehicleProperty::ClutchStatus = "ClutchStatus";
REGISTERPROPERTY(TransmissionMode,Transmission::Normal);
registerPropertyPriv(ThrottlePosition, [](){ return new ThrottlePositionType(0); });
registerPropertyPriv(WheelBrake, [](){ return new WheelBrakeType(false); });
+ REGISTERPROPERTY(WheelBrakePressure,0);
registerPropertyPriv(SteeringWheelAngle, [](){ return new SteeringWheelAngleType(0); });
registerPropertyPriv(TurnSignal, [](){ return new TurnSignalType(TurnSignals::Off); });
registerPropertyPriv(ClutchStatus, [](){ return new ClutchStatusType(false); });
static const Property WheelBrake;
typedef BasicPropertyType<bool> WheelBrakeType;
+ static const Property WheelBrakePressure;
+ typedef BasicPropertyType<uint16_t> WheelBrakePressureType;
+
/**< Steering wheel angle (0-359) */
static const Property SteeringWheelAngle;
typedef BasicPropertyType<uint16_t> SteeringWheelAngleType;
typedef BasicPropertyType<Vehicle::Type> VehicleTypeType;
static const Property DoorsPerRow;
- typedef ListPropertyType DoorsPerRowType;
+ typedef ListPropertyType<BasicPropertyType<uint16_t> > DoorsPerRowType;
static const Property TransmissionGearType;
typedef BasicPropertyType<Transmission::Type> TransmissionGearTypeType;
ConstructProperty(EngineOilProperty);
ConstructProperty(ExteriorBrightnessProperty);
ConstructProperty(VehicleId);
+ ConstructProperty(TransmissionInfoProperty);
+ ConstructProperty(VehicleTypeProperty);
+ ConstructProperty(FuelInfoProperty);
+ ConstructProperty(SizeProperty);
ConstructProperty(DoorsProperty);
+ ConstructProperty(WheelInformationProperty);
PropertyList list = VehicleProperty::customProperties();
{
VehicleProperty::VehicleSpeedType temp(velocity);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::EngineSpeed)
{
VehicleProperty::EngineSpeedType temp(engineSpeed);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::AccelerationX)
{
VehicleProperty::AccelerationType temp(accelerationX);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::TransmissionShiftPosition)
{
VehicleProperty::TransmissionShiftPositionType temp(transmissionShiftPostion);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::SteeringWheelAngle)
{
VehicleProperty::SteeringWheelAngleType temp(steeringWheelAngle);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::VIN)
{
VehicleProperty::VINType temp("ABC00000000000000");
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::WMI)
{
VehicleProperty::WMIType temp("abc");
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::BatteryVoltage)
{
VehicleProperty::BatteryVoltageType temp(12.6);
reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
else if(reply->property == VehicleProperty::ExteriorBrightness)
{
VehicleProperty::ExteriorBrightnessType temp(1000);
reply->value = &temp;
+ reply->success = true;
+ reply->completed(reply);
+ }
+ else if(reply->property == VehicleProperty::DoorsPerRow)
+ {
+ VehicleProperty::DoorsPerRowType temp;
+
+ BasicPropertyType<uint16_t> row1(2);
+ BasicPropertyType<uint16_t> row2(2);
+ BasicPropertyType<uint16_t> row3(1);
+
+ temp.append(&row1);
+ temp.append(&row2);
+ temp.append(&row3);
+
+ reply->value = &temp;
+ reply->success = true;
reply->completed(reply);
}
}
props.push_back(VehicleProperty::BatteryVoltage);
props.push_back(VehicleProperty::MachineGunTurretStatus);
props.push_back(VehicleProperty::ExteriorBrightness);
+ props.push_back(VehicleProperty::DoorsPerRow);
return props;
}
routingEngine->getPropertyAsync(batteryVoltageRequest);
+ AsyncPropertyRequest doorsPerRowRequest;
+ doorsPerRowRequest.property = VehicleProperty::DoorsPerRow;
+ doorsPerRowRequest.completed = [](AsyncPropertyReply* reply)
+ {
+ DebugOut(1)<<"Doors per row: "<<reply->value->toString()<<endl; delete reply;
+ };
+
+ routingEngine->getPropertyAsync(doorsPerRowRequest);
+
auto getRangedCb = [](gpointer data)
{
AbstractRoutingEngine* routingEngine = (AbstractRoutingEngine*)data;
}
velocityRequest.completed = [socket,id,property](AsyncPropertyReply* reply)
{
- printf("Got property:%s\n",reply->value->toString().c_str());
+ DebugOut()<<"Got property: "<<reply->value->toString().c_str()<<endl;
//uint16_t velocity = boost::any_cast<uint16_t>(reply->value);
stringstream s;
s.precision(15);