Commit 2f3b73bb authored by gladish's avatar gladish
Browse files

Added signal listener reg/unreg

parent 94dcadbe
......@@ -2,12 +2,21 @@
#include "Adapters/MockAdapter/MockDevices.h"
#include "Adapters/MockAdapter/MockAdapterDevice.h"
namespace
{
Bridge::IAdapter::RegistrationHandle nextHandle = 0;
Bridge::IAdapter::RegistrationHandle GetNextRegistrationHandle()
{
return ++nextHandle;
}
}
AdapterLib::MockAdapter::MockAdapter()
: m_vendor("Acme")
, m_adapterName("DSB Mock Adapter")
, m_exposedAdapterPrefix("com." + m_vendor)
, m_exposedApplicationGuid("C27BC425-0058-4829-8775-441B5D8740C0")
, m_exposedApplicationName("DeviceSystemBridge")
, m_exposedApplicationGuid("C27BC425-0058-4829-8775-441B5D8740C0")
{
// TODO: get m_exposedApplicatioName and Prefix from config
}
......@@ -127,18 +136,36 @@ QStatus AdapterLib::MockAdapter::CallMethod(
QStatus AdapterLib::MockAdapter::RegisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
std::string const& signalName,
shared_ptr<Bridge::IAdapterSignalListener> const& listener,
void* argp)
void* argp,
Bridge::IAdapter::RegistrationHandle& handle)
{
return ER_NOT_IMPLEMENTED;
RegisteredSignal reg;
reg.Listener = listener;
reg.Context = argp;
reg.RegHandle = GetNextRegistrationHandle();
m_signalListeners.insert(SignalMap::value_type(signalName, reg));
handle = reg.RegHandle;
return ER_OK;
}
QStatus AdapterLib::MockAdapter::UnregisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener)
QStatus AdapterLib::MockAdapter::UnregisterSignalListener(Bridge::IAdapter::RegistrationHandle const& h)
{
QStatus st = ER_FAIL;
for (SignalMap::iterator begin = m_signalListeners.begin(), end = m_signalListeners.end();
begin != end; ++begin)
{
if (begin->second.RegHandle == h)
{
m_signalListeners.erase(begin);
st = ER_OK;
break;
}
}
return st;
return ER_NOT_IMPLEMENTED;
}
......@@ -150,7 +177,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, *this));
shared_ptr<MockAdapter> self = shared_from_this();
shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, self));
// TODO
}
}
......@@ -159,4 +187,11 @@ void AdapterLib::MockAdapter::CreateSignals()
{
}
QStatus AdapterLib::MockAdapter::NotifySignalListeners(shared_ptr<MockAdapterSignal> const& signal)
{
QStatus st = ER_OK;
return st;
}
......@@ -3,11 +3,14 @@
#include "Bridge/IAdapter.h"
#include "Common/defines.h"
#include <map>
namespace AdapterLib
{
class MockAdapterDevice;
class MockAdapterSignal;
class MockAdapter : public Bridge::IAdapter, public enable_shared_from_this<Bridge::IAdapter>
class MockAdapter : public Bridge::IAdapter, public enable_shared_from_this<MockAdapter>
{
public:
MockAdapter();
......@@ -53,13 +56,14 @@ namespace AdapterLib
Bridge::IAdapterIoRequest** req);
virtual QStatus RegisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
std::string const& signalName,
shared_ptr<Bridge::IAdapterSignalListener> const& listener,
void* argp);
void* argp,
Bridge::IAdapter::RegistrationHandle& handle);
virtual QStatus UnregisterSignalListener(Bridge::IAdapter::RegistrationHandle const& h);
virtual QStatus UnregisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener);
QStatus NotifySignalListeners(shared_ptr<MockAdapterSignal> const& signal);
private:
void CreateMockDevices();
......@@ -74,6 +78,16 @@ namespace AdapterLib
std::string m_exposedApplicationGuid;
std::vector< shared_ptr<MockAdapterDevice> > m_devices;
struct RegisteredSignal
{
shared_ptr<Bridge::IAdapterSignalListener> Listener;
void* Context;
Bridge::IAdapter::RegistrationHandle RegHandle;
};
typedef std::multimap<std::string, RegisteredSignal> SignalMap;
SignalMap m_signalListeners;
};
}
#include "Adapters/MockAdapter/MockAdapterDevice.h"
#include "Adapters/MockAdapter/MockAdapter.h"
using namespace AdapterLib;
MockAdapterDevice::MockAdapterDevice(
MockDeviceDescriptor const& desc,
Bridge::IAdapter const& parent)
MockAdapterDevice::MockAdapterDevice(MockDeviceDescriptor const& desc, shared_ptr<MockAdapter> const& parent)
: m_name(desc.Name)
, m_parent(parent)
, m_vendor(desc.VendorName)
......@@ -61,16 +60,19 @@ QStatus MockAdapterDevice::DispatchMethod(
QStatus MockAdapterDevice::SendSignal(
std::string const& signalName,
shared_ptr<MockAdapterProperty> const& prop,
shared_ptr<MockAdapterValue> const& attr)
shared_ptr<MockAdapterValue> const& value)
{
if (!prop)
return ER_BAD_ARG_2;
if (!attr)
if (!value)
return ER_BAD_ARG_3;
QStatus st = ER_FAIL;
shared_ptr<MockAdapterSignal> signal;
shared_ptr<MockAdapter> parent = m_parent.lock();
if (!parent)
return ER_FAIL;
typedef Bridge::AdapterSignalVector::const_iterator iterator;
for (iterator begin = m_signalPrototypes.begin(), end = m_signalPrototypes.end();
......@@ -78,20 +80,33 @@ QStatus MockAdapterDevice::SendSignal(
{
if ((*begin)->GetName() == signalName)
{
// TODO: clone
signal = dynamic_pointer_cast<MockAdapterSignal>(*begin);
DSB_ASSERT(signal != NULL);
if (signal)
signal = signal->Clone();
}
}
if (!signal)
return st;
// TODO: Continue here
if (signal->GetName() == Bridge::kChangeOfValueSignal)
{
Bridge::AdapterValueVector params;
shared_ptr<MockAdapterValue> p(new MockAdapterValue("PropertyName", *this));
p->SetData(ajn::MsgArg("s", prop->GetName().c_str(), NULL));
shared_ptr<MockAdapterValue> v(new MockAdapterValue("PropertyValue", *this));
v->SetData(value->GetData());
params.push_back(p);
params.push_back(v);
}
if (signal)
parent->NotifySignalListeners(signal);
return st;
}
......@@ -277,6 +292,15 @@ MockAdapterSignal::MockAdapterSignal(
{
}
shared_ptr<MockAdapterSignal> MockAdapterSignal::Clone()
{
shared_ptr<MockAdapterSignal> clone(new MockAdapterSignal(
m_name,
m_parent,
m_params));
return clone;
}
std::string MockAdapterSignal::GetName() const
{
......
......@@ -9,6 +9,7 @@ namespace AdapterLib
std::string const kDeviceResetPropertyHandle = "Property_Handle";
std::string const kDsbMethodReturnValue = "Return_Value";
class MockAdapter;
class MockAdapterDevice;
class MockAdapterSignal : public Bridge::IAdapterSignal
......@@ -22,6 +23,10 @@ namespace AdapterLib
virtual std::string GetName() const;
virtual Bridge::AdapterValueVector const& GetParams() const;
void SetParams(Bridge::AdapterValueVector const& params);
shared_ptr<MockAdapterSignal> Clone();
private:
std::string m_name;
Bridge::IAdapterDevice const& m_parent;
......@@ -96,9 +101,7 @@ namespace AdapterLib
class MockAdapterDevice : public Bridge::IAdapterDevice, public enable_shared_from_this<MockAdapterDevice>
{
public:
MockAdapterDevice(
MockDeviceDescriptor const& desc,
Bridge::IAdapter const& parent);
MockAdapterDevice(MockDeviceDescriptor const& desc, shared_ptr<MockAdapter> const& parent);
virtual std::string GetName();
virtual std::string GetVendor();
......@@ -129,7 +132,7 @@ namespace AdapterLib
private:
std::string m_name;
Bridge::IAdapter const& m_parent;
weak_ptr<MockAdapter> m_parent;
std::string m_vendor;
std::string m_model;
std::string m_version;
......
......@@ -115,6 +115,8 @@ namespace Bridge
protected:
IAdapter() { }
public:
typedef int32_t RegistrationHandle;
virtual ~IAdapter() { }
virtual std::string GetVendor() = 0;
virtual std::string GetAdapterName() = 0;
......@@ -156,13 +158,12 @@ namespace Bridge
IAdapterIoRequest** req) = 0;
virtual QStatus RegisterSignalListener(
shared_ptr<IAdapterSignal> const& signal,
std::string const& signalName,
shared_ptr<IAdapterSignalListener> const& listener,
void* argp) = 0;
void* argp,
RegistrationHandle& handle) = 0;
virtual QStatus UnregisterSignalListener(
shared_ptr<IAdapterSignal> const& signal,
shared_ptr<IAdapterSignalListener> const& listener) = 0;
virtual QStatus UnregisterSignalListener(RegistrationHandle const& h) = 0;
};
}
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