#include <list>
#include "timestamp.h"
#include <debugout.h>
-namespace Zone {
-enum Type {
- None = 0,
- Driver = 1,
- FrontMiddle = 1 << 1,
- Passenger = 1 << 2,
- LeftRear = 1 << 3,
- MiddleRear = 1 << 4,
- RightRear = 1 << 5
+#include <boost/algorithm/string.hpp>
+
+class Zone {
+
+public:
+
+ typedef int Type;
+
+ enum {
+ None = 0,
+ Front = 1,
+ Middle = 1 << 1,
+ Right = 1 << 2,
+ Left = 1 << 3,
+ Rear = 1 << 4,
+ Center = 1 << 5,
+ LeftSide = 1 << 6,
+ RightSide = 1 << 7,
+ FrontSide = 1 << 8,
+ BackSide = 1 << 9
+ };
+
+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;
+
};
-}
class AbstractPropertyType
{
public:
- //AbstractPropertyType(): timestamp(-1), sequence(-1), zone(Zone::None), index(0) {}
- AbstractPropertyType(std::string property): name(property), timestamp(-1), sequence(-1), zone(Zone::None), index(0) {}
+ /*!
+ * \brief The Priority enum describes prority of the property type.
+ */
+ enum Priority
+ {
+ Normal = 0,
+ Low,
+ High,
+ Instant
+ };
+
+ AbstractPropertyType(std::string property): name(property), timestamp(amb::currentTime()), sequence(-1), zone(Zone::None), priority(Normal)
+ {
+ void*(name);
+ }
+
+ virtual ~AbstractPropertyType() { }
virtual std::string toString() const = 0;
virtual AbstractPropertyType* copy() = 0;
+ /**
+ * @brief quickCopy is intended as a way to quickly copy the often changing bits from one abstract property to another
+ * It assumes that the properties are almost identical in name, source, and zone.
+ * @param other the property to copy from
+ */
+ virtual void quickCopy(AbstractPropertyType* other)
+ {
+ sequence = other->sequence;
+ mValue = other->anyValue();
+ timestamp = other->timestamp;
+ }
+
bool operator == (AbstractPropertyType &other)
{
std::string one = toString();
std::string two = other.toString();
- return one == two;
+ return one == two
+ && zone == other.zone
+ && sourceUuid == other.sourceUuid
+ && name == other.name;
+ }
+
+ bool operator != (AbstractPropertyType &other)
+ {
+ std::string one = toString();
+ std::string two = other.toString();
+ return one != two;
}
std::string name;
Zone::Type zone;
- int index;
+ /*!
+ * \brief priority is used to tell the routing engine how to prioritize routing the value to plugins.
+ * setting this value to AbstractPropertyType::Instant will tell the routing engine to immedietly
+ * route the value without any reliance on the mainloop. Instant priority is NOT thread safe.
+ * Default priority is AbstractPropertyType::Normal.
+ */
+ Priority priority;
void setValue(boost::any val)
{
public:
static const char* signature() { return "i"; }
- static char value(GVariant* v)
+ static int value(GVariant* v)
{
return g_variant_get_int32(v);
}
+
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_double(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_uint16(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_int16(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_byte(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_uint32(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
{
return g_variant_get_int64(v);
}
+ static std::string stringize(std::string v)
+ {
+ return v;
+ }
};
template <>
static uint64_t value(GVariant* v)
{
- g_variant_get_uint64(v);
+ return g_variant_get_uint64(v);
+ }
+ static std::string stringize(std::string v)
+ {
+ return v;
}
};
{
return g_variant_get_boolean(v);
}
+ static std::string stringize(std::string v)
+ {
+ if(v == "0" || v == "1")
+ return v;
+
+ boost::algorithm::to_lower(v);
+ return v == "true" ? "1":"0";
+ }
};
timestamp = other.timestamp;
sequence = other.sequence;
sourceUuid = other.sourceUuid;
- index = other.index;
name = other.name;
+ zone = other.zone;
+
}
BasicPropertyType & operator = (BasicPropertyType const & other)
timestamp = other.timestamp;
sequence = other.sequence;
sourceUuid = other.sourceUuid;
- index = other.index;
name = other.name;
+ zone = other.zone;
return *this;
}
else setValue(T());
}
- BasicPropertyType(std::string val)
+ BasicPropertyType(std::string propertyName)
+ :AbstractPropertyType(propertyName)
+ {
+ mValue = T();
+ }
+
+ /*BasicPropertyType(std::string val)
:AbstractPropertyType("")
{
if(!val.empty() && val != "")
serialize<T>(val);
}
else setValue(T());
- }
+ }*/
AbstractPropertyType* copy()
{
template <class N>
void serialize(std::string val, typename std::enable_if<!std::is_enum<N>::value, N>::type* = 0)
{
- std::stringstream stream(val);
+ std::stringstream stream(GVS<T>::stringize(val));
N someTemp;
stream>>someTemp;
setValue(someTemp);
StringPropertyType(std::string propertyName)
:AbstractPropertyType(propertyName)
{
-
+ setValue(std::string());
}
StringPropertyType(std::string propertyName, std::string val)
timestamp = other.timestamp;
sequence = other.sequence;
sourceUuid = other.sourceUuid;
- index = other.index;
name = other.name;
+ zone = other.zone;
}
StringPropertyType & operator = (StringPropertyType const & other)
timestamp = other.timestamp;
sequence = other.sequence;
sourceUuid = other.sourceUuid;
- index = other.index;
name = other.name;
+ zone = other.zone;
return *this;
}
timestamp = other.timestamp;
sequence = other.sequence;
sourceUuid = other.sourceUuid;
- index = other.index;
name = other.name;
+ zone = other.zone;
}
~ListPropertyType()
{
- for(auto itr = mList.begin(); itr != mList.end(); itr++)
- {
- delete *itr;
- }
+ clear();
}
/** append - appends a property to the list
void fromString(std::string str )
{
+ clear();
+
if(!str.length())
return;
std::string element;
while(std::getline(f,element,','))
{
- T *foo = new T(element);
- append (foo);
-
- delete foo;
+ T foo("", element);
+ append (&foo);
}
}
GVariant *var = t->toVariant();
GVariant *newvar = g_variant_new("v",var);
g_variant_builder_add_value(¶ms, newvar);
-
+
}
GVariant* var = g_variant_builder_end(¶ms);
void fromVariant(GVariant* v)
{
+ clear();
+
/// TODO: fill this in
gsize dictsize = g_variant_n_children(v);
for (int i=0;i<dictsize;i++)
std::list<AbstractPropertyType*> list() { return mList; }
private:
+
+ void clear()
+ {
+ for(auto itr = mList.begin(); itr != mList.end(); itr++)
+ {
+ delete *itr;
+ }
+ mList.clear();
+ }
+
void appendPriv(AbstractPropertyType* i)
{
mList.push_back(i);