Commit 66cd7a9b authored by gladish's avatar gladish

Filling some helper code.

parent 9e404d45
......@@ -298,7 +298,7 @@ std::string MockAdapterValue::GetName()
return m_name;
}
common::Variant MockAdapterValue::GetData()
common::Variant const& MockAdapterValue::GetData()
{
return m_data;
}
......
......@@ -94,7 +94,7 @@ namespace mock
MockAdapterValue(std::string const& name);
virtual std::string GetName();
virtual common::Variant GetData();
virtual common::Variant const& GetData();
virtual void SetData(common::Variant const& v);
private:
......
......@@ -17,7 +17,34 @@ bridge::AllJoynHelper::SetMsgArgFromAdapterObject(IAdapterValue const& adapterVa
QStatus
bridge::AllJoynHelper::GetAdapterValue(IAdapterValue& adapterValue, ajn::MsgArg const& msg)
{
return ER_NOT_IMPLEMENTED;
QStatus st;
std::string sig;
common::Variant const& val = adapterValue.GetData();
// TODO: why not just hard-code signatures? GetSignature is never used outside
// AllJoynHelper
st = GetSignature(val.GetType(), sig);
if (st != ER_OK)
return st;
switch (val.GetType())
{
case common::Variant::DataType::Boolean:
{
bool b;
st = msg.Get(sig.c_str(), &b);
if (st == ER_OK)
adapterValue.SetData(common::Variant(b));
}
break;
// TODO: reset of enumerations
default:
st = ER_NOT_IMPLEMENTED;
}
return st;
}
QStatus
......@@ -26,41 +53,177 @@ bridge::AllJoynHelper::GetAdapterObject(IAdapterValue& adapterValue, ajn::MsgArg
return ER_NOT_IMPLEMENTED;
}
// TODO:
// static QStatus GetSignature(_In_ Windows::Foundation::PropertyType propertyType, _Out_ std::string &signature);
QStatus
bridge::AllJoynHelper::GetSignature(common::Variant::DataType type, std::string& sig)
{
using namespace common;
#define setSignature(T, S) case Variant::DataType::T: sig = S; break
QStatus status = ER_OK;
switch (type)
{
setSignature(Boolean, "b");
setSignature(UInt8, "y");
setSignature(Int16, "n");
setSignature(UInt16, "q");
setSignature(Int32, "i");
setSignature(UInt32, "u");
setSignature(Int64, "x");
setSignature(UInt64, "t");
setSignature(Double, "d");
setSignature(String, "s");
// arrays
setSignature(BooleanArray,"ab");
setSignature(UInt8Array, "ay");
setSignature(Int16Array, "an");
setSignature(UInt16Array, "aq");
setSignature(Int32Array, "ai");
setSignature(UInt32Array, "au");
setSignature(Int64Array, "ax");
setSignature(UInt64Array, "at");
setSignature(DoubleArray, "ad");
setSignature(StringArray, "as");
default:
status = ER_NOT_IMPLEMENTED;
break;
}
#undef setSignature
return status;
}
void
bridge::AllJoynHelper::EncodeBusObjectName(std::string const& s, std::string &builtName)
bridge::AllJoynHelper::EncodeBusObjectName(std::string const& s, std::string &t)
{
t.clear();
for (char ch : s)
{
if (std::isalnum(ch))
t += ch;
else if (std::isspace(ch) || ch == '_')
t += '_';
else if (ch == '.' || ch == '/')
t += '/';
}
t = TrimChar(t, '/');
}
void
bridge::AllJoynHelper::EncodePropertyOrMethodOrSignalName(std::string const& s, std::string &builtName)
bridge::AllJoynHelper::EncodePropertyOrMethodOrSignalName(std::string const& s, std::string &t)
{
t.clear();
bool upperCaseNextChar = true;
bool is1stChar = true;
for (char ch : s)
{
if ((std::isalnum(ch) && !is1stChar) || (std::isalpha(ch) && is1stChar))
{
if (upperCaseNextChar && std::isalpha(ch) && std::islower(ch))
t += std::toupper(ch);
else
t += ch;
upperCaseNextChar = false;
is1stChar = false;
}
else
{
upperCaseNextChar = true;
}
}
}
void
bridge::AllJoynHelper::EncodeStringForInterfaceName(std::string const& s, std::string& encoded)
bridge::AllJoynHelper::EncodeStringForInterfaceName(std::string const& s, std::string& t)
{
t.clear();
for (char ch : s)
{
if (std::isalnum(ch) || ch == '.')
t += ch;
}
t = TrimChar(t, '.');
}
void
bridge::AllJoynHelper::EncodeStringForServiceName(std::string const& s, std::string &encoded)
bridge::AllJoynHelper::EncodeStringForServiceName(std::string const& s, std::string &t)
{
std::string temp;
t.clear();
for (char ch : s)
{
if (std::isalpha(ch))
temp += ch;
}
if (!temp.empty())
{
if (std::isdigit(temp[0]))
t += '_';
t += temp;
}
}
void
bridge::AllJoynHelper::EncodeStringForRootServiceName(std::string const& s, std::string &encoded)
bridge::AllJoynHelper::EncodeStringForRootServiceName(std::string const& s, std::string &t)
{
char curr = '\0';
t.clear();
for (char ch : s)
{
if (std::isalpha(ch) || ch == '.')
{
t += ch;
curr = ch;
}
else if (std::isdigit(ch))
{
if (curr == '.')
t += '_';
t += ch;
curr = ch;
}
}
t = TrimChar(t, '.');
}
void
bridge::AllJoynHelper::EncodeStringForAppName(std::string const& s, std::string &encodeString)
bridge::AllJoynHelper::EncodeStringForAppName(std::string const& s, std::string &t)
{
t.clear();
for (char ch : s)
{
if (std::isalnum(ch))
t += ch;
}
}
std::string
bridge::AllJoynHelper::TimeChar(std::string const& s, char c)
bridge::AllJoynHelper::TrimChar(std::string const& s, char c)
{
return std::string();
std::size_t left = s.find_first_not_of(c);
if (left == std::string::npos)
left = 0;
std::size_t right = s.find_last_not_of(c);
// TODO: error/bounds check
return s.substr(left, right - left + 1);
}
......@@ -28,8 +28,7 @@ namespace bridge
static QStatus GetAdapterObject(IAdapterValue& adapterValue, ajn::MsgArg const& msg, DeviceMain* deviceMain);
// TODO:
// static QStatus GetSignature(_In_ Windows::Foundation::PropertyType propertyType, _Out_ std::string &signature);
static QStatus GetSignature(common::Variant::DataType type, std::string& sig);
static void EncodeBusObjectName(std::string const& s, std::string &builtName);
static void EncodePropertyOrMethodOrSignalName(std::string const& s, std::string &builtName);
......@@ -37,7 +36,7 @@ namespace bridge
static void EncodeStringForServiceName(std::string const& s, std::string &encoded);
static void EncodeStringForRootServiceName(std::string const& s, std::string &encoded);
static void EncodeStringForAppName(std::string const& s, std::string &encodeString);
static std::string TimeChar(std::string const& s, char c);
static std::string TrimChar(std::string const& s, char c);
};
}
......@@ -37,7 +37,7 @@ namespace bridge
public:
virtual ~IAdapterValue() { }
virtual std::string GetName() = 0;
virtual common::Variant GetData() = 0;
virtual common::Variant const& GetData() = 0;
virtual void SetData(common::Variant const& msg) = 0;
};
......
......@@ -22,7 +22,19 @@ namespace common
Int64,
UInt64,
Double,
String
String,
// array types
BooleanArray,
UInt8Array,
Int16Array,
UInt16Array,
Int32Array,
UInt32Array,
Int64Array,
UInt64Array,
DoubleArray,
StringArray,
};
Variant() : m_type(DataType::Invalid) { m_data.v_uint64 = 0; }
......@@ -36,6 +48,11 @@ namespace common
Variant(uint64_t t) : m_type(DataType::UInt64) { m_data.v_uint64 = t; }
Variant(double d) : m_type(DataType::Double) { m_data.v_double = d; }
Variant(DataType t) : m_type(t)
{
memset(&m_data, 0, sizeof(m_data));
}
Variant(std::string const& s) : m_type(DataType::String)
{
if (s.size())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment