Commit 94dcadbe authored by gladish's avatar gladish

Started adding Signal and Method dispatching

parent 5b9e0062
......@@ -112,9 +112,17 @@ QStatus AdapterLib::MockAdapter::SetPropertyValue(
QStatus AdapterLib::MockAdapter::CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method,
shared_ptr<Bridge::IAdapterIoRequest>* req)
Bridge::IAdapterIoRequest** req)
{
return ER_NOT_IMPLEMENTED;
shared_ptr<MockAdapterMethod> m = dynamic_pointer_cast<MockAdapterMethod>(method);
if (!m)
return ER_BAD_ARG_1;
shared_ptr<MockAdapterDevice> device = m->GetParent();
if (!device)
return ER_INVALID_ADDRESS;
return device->DispatchMethod(m, req);
}
......@@ -142,7 +150,8 @@ void AdapterLib::MockAdapter::CreateMockDevices()
for (vector::const_iterator begin = devices.begin(), end = devices.end();
begin != end; ++begin)
{
shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, shared_from_this()));
shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, *this));
// TODO
}
}
......
......@@ -50,7 +50,7 @@ namespace AdapterLib
virtual QStatus CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method,
shared_ptr<Bridge::IAdapterIoRequest>* req);
Bridge::IAdapterIoRequest** req);
virtual QStatus RegisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
......
......@@ -4,7 +4,7 @@ using namespace AdapterLib;
MockAdapterDevice::MockAdapterDevice(
MockDeviceDescriptor const& desc,
shared_ptr<Bridge::IAdapter> const& parent)
Bridge::IAdapter const& parent)
: m_name(desc.Name)
, m_parent(parent)
, m_vendor(desc.VendorName)
......@@ -27,14 +27,96 @@ MockAdapterDevice::MockAdapterDevice(
void MockAdapterDevice::CreateSignals()
{
Bridge::AdapterValueVector params;
m_signalPrototypes.push_back(shared_ptr<MockAdapterSignal>(new MockAdapterSignal(
Bridge::kChangeOfValueSignal, *this, params)));
// TODO: This is incomplete, re-visit once signal emit is worked on
}
void MockAdapterDevice::CreateMethods()
{
shared_ptr<MockAdapterMethod> m(new MockAdapterMethod(kDeviceResetMethod, this));
shared_ptr<MockAdapterDevice> self = shared_from_this();
shared_ptr<MockAdapterMethod> m(new MockAdapterMethod(kDeviceResetMethod, self));
m->AddInputParam(shared_ptr<Bridge::IAdapterValue>(
new MockAdapterValue(kDeviceResetPropertyHandle, *this)));
m_methods.push_back(m);
}
QStatus MockAdapterDevice::DispatchMethod(
shared_ptr<MockAdapterMethod>& method,
Bridge::IAdapterIoRequest** req)
{
if (req)
*req = NULL;
QStatus st = ER_OK;
if (method->GetName() == kDeviceResetMethod)
st = Reset(method);
return st;
}
QStatus MockAdapterDevice::SendSignal(
std::string const& signalName,
shared_ptr<MockAdapterProperty> const& prop,
shared_ptr<MockAdapterValue> const& attr)
{
if (!prop)
return ER_BAD_ARG_2;
if (!attr)
return ER_BAD_ARG_3;
QStatus st = ER_FAIL;
shared_ptr<MockAdapterSignal> signal;
typedef Bridge::AdapterSignalVector::const_iterator iterator;
for (iterator begin = m_signalPrototypes.begin(), end = m_signalPrototypes.end();
((begin != end) && !signal); ++begin)
{
if ((*begin)->GetName() == signalName)
{
// TODO: clone
signal = dynamic_pointer_cast<MockAdapterSignal>(*begin);
DSB_ASSERT(signal != NULL);
}
}
if (!signal)
return st;
// TODO: Continue here
if (signal->GetName() == Bridge::kChangeOfValueSignal)
{
}
return st;
}
QStatus MockAdapterDevice::Reset(shared_ptr<MockAdapterMethod>& method)
{
QStatus st = ER_OK;
Bridge::AdapterValueVector const& inParams = method->GetInputParams();
if (inParams.size() == 0)
{
// reset device
}
else if (inParams.size() == 1)
{
// reset property by name
shared_ptr<Bridge::IAdapterValue> arg1 = inParams[0];
if (!arg1)
return ER_BAD_ARG_1;
}
method->SetResult(ER_OK);
return st;
}
std::string MockAdapterDevice::GetName()
{
return m_name;
......@@ -70,19 +152,19 @@ std::string MockAdapterDevice::GetDescription()
return m_description;
}
Bridge::AdapterPropertyVector MockAdapterDevice::GetProperties()
Bridge::AdapterPropertyVector const& MockAdapterDevice::GetProperties() const
{
return m_properties;
}
Bridge::AdapterMethodVector MockAdapterDevice::GetMethods()
Bridge::AdapterMethodVector const& MockAdapterDevice::GetMethods() const
{
return m_methods;
}
Bridge::AdapterSignalVector MockAdapterDevice::GetSignals()
Bridge::AdapterSignalVector const& MockAdapterDevice::GetSignals() const
{
return m_signals;
return m_signalPrototypes;
}
MockAdapterProperty::MockAdapterProperty(MockPropertyDescriptor const& desc)
......@@ -103,13 +185,15 @@ Bridge::AdapterValueVector MockAdapterProperty::GetAttributes()
// MockAdapterMethod
MockAdapterMethod::MockAdapterMethod(std::string const& name, MockAdapterDevice* parent)
MockAdapterMethod::MockAdapterMethod(
std::string const& name,
weak_ptr<MockAdapterDevice> const& parent)
: m_name(name)
, m_parent(parent)
{
}
std::string MockAdapterMethod::GetName()
std::string MockAdapterMethod::GetName() const
{
return m_name;
}
......@@ -119,12 +203,12 @@ std::string MockAdapterMethod::GetDescription()
return m_description;
}
Bridge::AdapterValueVector MockAdapterMethod::GetInputParams()
Bridge::AdapterValueVector const& MockAdapterMethod::GetInputParams() const
{
return m_inputParams;
}
Bridge::AdapterValueVector MockAdapterMethod::GetOutputParams()
Bridge::AdapterValueVector const& MockAdapterMethod::GetOutputParams() const
{
return m_outputParams;
}
......@@ -139,9 +223,69 @@ void MockAdapterMethod::SetOutputParams(Bridge::AdapterValueVector const& params
m_outputParams = params;
}
int32_t MockAdapterMethod::GetResult()
void MockAdapterMethod::AddInputParam(shared_ptr<Bridge::IAdapterValue> const& p)
{
m_inputParams.push_back(p);
}
void MockAdapterMethod::AddOutputParam(shared_ptr<Bridge::IAdapterValue> const& p)
{
m_outputParams.push_back(p);
}
QStatus MockAdapterMethod::GetResult()
{
return m_result;
}
void MockAdapterMethod::SetResult(QStatus st)
{
m_result = st;
}
MockAdapterValue::MockAdapterValue(
std::string const& name,
MockAdapterDevice const& parent)
: m_name(name)
, m_parent(parent)
{
}
std::string MockAdapterValue::GetName()
{
return m_name;
}
ajn::MsgArg MockAdapterValue::GetData()
{
return m_data;
}
void MockAdapterValue::SetData(ajn::MsgArg const& msg)
{
m_data = msg;
}
MockAdapterSignal::MockAdapterSignal(
std::string const& name,
Bridge::IAdapterDevice const& parent,
Bridge::AdapterValueVector const& params)
: m_name(name)
, m_parent(parent)
, m_params(params)
{
}
std::string MockAdapterSignal::GetName() const
{
return m_name;
}
Bridge::AdapterValueVector const& MockAdapterSignal::GetParams() const
{
return 0;
return m_params;
}
......@@ -11,28 +11,56 @@ namespace AdapterLib
class MockAdapterDevice;
class MockAdapterSignal : public Bridge::IAdapterSignal
{
public:
MockAdapterSignal(
std::string const& name,
Bridge::IAdapterDevice const& dev,
Bridge::AdapterValueVector const& params);
virtual std::string GetName() const;
virtual Bridge::AdapterValueVector const& GetParams() const;
private:
std::string m_name;
Bridge::IAdapterDevice const& m_parent;
Bridge::AdapterValueVector m_params;
};
class MockAdapterMethod : public Bridge::IAdapterMethod
{
friend class MockAdapter;
public:
MockAdapterMethod(std::string const& name, MockAdapterDevice* parent);
MockAdapterMethod(std::string const& name, weak_ptr<MockAdapterDevice> const& parent);
virtual std::string GetName();
virtual std::string GetName() const;
virtual std::string GetDescription();
virtual Bridge::AdapterValueVector GetInputParams();
virtual Bridge::AdapterValueVector GetOutputParams();
virtual Bridge::AdapterValueVector const& GetInputParams() const;
virtual Bridge::AdapterValueVector const& GetOutputParams() const;
virtual void SetInputParams(Bridge::AdapterValueVector const& params);
virtual void SetOutputParams(Bridge::AdapterValueVector const& params);
virtual int32_t GetResult();
void AddInputParam(shared_ptr<Bridge::IAdapterValue> const& p);
void AddOutputParam(shared_ptr<Bridge::IAdapterValue> const& p);
virtual QStatus GetResult();
void SetResult(QStatus st);
private:
shared_ptr<MockAdapterDevice> GetParent() const
{ return m_parent.lock(); }
private:
std::string m_name;
std::string m_description;
Bridge::AdapterValueVector m_inputParams;
Bridge::AdapterValueVector m_outputParams;
MockAdapterDevice* m_parent;
weak_ptr<MockAdapterDevice> m_parent;
QStatus m_result;
};
class MockAdapterProperty : public Bridge::IAdapterProperty
......@@ -48,12 +76,29 @@ namespace AdapterLib
Bridge::AdapterValueVector m_attributes;
};
class MockAdapterDevice : public Bridge::IAdapterDevice
class MockAdapterValue : public Bridge::IAdapterValue
{
public:
MockAdapterValue(
std::string const& name,
MockAdapterDevice const& parent);
virtual std::string GetName();
virtual ajn::MsgArg GetData();
virtual void SetData(ajn::MsgArg const& msg);
private:
std::string m_name;
ajn::MsgArg m_data;
MockAdapterDevice const& m_parent;
};
class MockAdapterDevice : public Bridge::IAdapterDevice, public enable_shared_from_this<MockAdapterDevice>
{
public:
MockAdapterDevice(
MockDeviceDescriptor const& desc,
shared_ptr<Bridge::IAdapter> const& parent);
Bridge::IAdapter const& parent);
virtual std::string GetName();
virtual std::string GetVendor();
......@@ -63,17 +108,28 @@ namespace AdapterLib
virtual std::string GetSerialNumber();
virtual std::string GetDescription();
virtual Bridge::AdapterPropertyVector GetProperties();
virtual Bridge::AdapterMethodVector GetMethods();
virtual Bridge::AdapterSignalVector GetSignals();
virtual Bridge::AdapterPropertyVector const& GetProperties() const;
virtual Bridge::AdapterMethodVector const& GetMethods() const;
virtual Bridge::AdapterSignalVector const& GetSignals() const;
QStatus DispatchMethod(
shared_ptr<MockAdapterMethod>& method,
Bridge::IAdapterIoRequest** req);
QStatus SendSignal(
std::string const& signalName,
shared_ptr<MockAdapterProperty> const& prop,
shared_ptr<MockAdapterValue> const& attr);
private:
void CreateMethods();
void CreateSignals();
QStatus Reset(shared_ptr<MockAdapterMethod>& method);
private:
std::string m_name;
shared_ptr<Bridge::IAdapter> m_parent;
Bridge::IAdapter const& m_parent;
std::string m_vendor;
std::string m_model;
std::string m_version;
......@@ -82,7 +138,7 @@ namespace AdapterLib
std::string m_description;
Bridge::AdapterPropertyVector m_properties;
Bridge::AdapterMethodVector m_methods;
Bridge::AdapterSignalVector m_signals;
Bridge::AdapterSignalVector m_signalPrototypes;
};
};
......@@ -10,6 +10,14 @@
namespace Bridge
{
std::string const kDeviceArrivalSignal = "Device_Arrival";
std::string const kDeviceArravalHandle = "Device_Handle";
std::string const kDeviceRemovalSignal = "Device_Removal";
std::string const kDeviceRemovalDeviceHandle = "Device_Handle";
std::string const kChangeOfValueSignal = "Change_Of_Value";
std::string const kCovPropertyHandle = "Property_Handle";
std::string const kCovAttributeHandle = "Attribute_Handle";
class IAdapterValue;
class IAdapterProperty;
class IAdapterMethod;
......@@ -43,16 +51,16 @@ namespace Bridge
{
public:
virtual ~IAdapterMethod() { }
virtual std::string GetName() = 0;
virtual std::string GetName() const = 0;
virtual std::string GetDescription() = 0;
virtual AdapterValueVector GetInputParams() = 0;
virtual AdapterValueVector GetOutputParams() = 0;
virtual AdapterValueVector const& GetInputParams() const = 0;
virtual AdapterValueVector const& GetOutputParams() const = 0;
virtual void SetInputParams(AdapterValueVector const& params) = 0;
virtual void SetOutputParams(AdapterValueVector const& params) = 0;
virtual int32_t GetResult() = 0;
virtual QStatus GetResult() = 0;
};
class IAdapterSignal
......@@ -60,7 +68,7 @@ namespace Bridge
public:
virtual ~IAdapterSignal() { }
virtual std::string GetName() const = 0;
virtual AdapterValueVector GetParams() const = 0;
virtual AdapterValueVector const& GetParams() const = 0;
};
class IAdapterSignalListener
......@@ -82,9 +90,9 @@ namespace Bridge
virtual std::string GetSerialNumber() = 0;
virtual std::string GetDescription() = 0;
virtual AdapterPropertyVector GetProperties() = 0;
virtual AdapterMethodVector GetMethods() = 0;
virtual AdapterSignalVector GetSignals() = 0;
virtual AdapterPropertyVector const& GetProperties() const = 0;
virtual AdapterMethodVector const& GetMethods() const = 0;
virtual AdapterSignalVector const& GetSignals() const = 0;
};
class IAdapterIoRequest
......@@ -145,7 +153,7 @@ namespace Bridge
virtual QStatus CallMethod(
shared_ptr<IAdapterMethod>& method,
shared_ptr<IAdapterIoRequest>* req) = 0;
IAdapterIoRequest** req) = 0;
virtual QStatus RegisterSignalListener(
shared_ptr<IAdapterSignal> const& signal,
......
......@@ -6,13 +6,17 @@ using std::shared_ptr;
using std::weak_ptr;
using std::enable_shared_from_this;
using std::dynamic_pointer_cast;
#include <assert.h>
#define DSB_ASSERT(X) assert((X))
#else
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::weak_ptr;
using std::tr1::enable_shared_from_this;
using std::tr1::dynamic_pointer_cast;
#define DSB_ASSERT(X)
#endif
class AllJoynBusObject;
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