Commit 87adf8f2 authored by gladish's avatar gladish
Browse files

Fixed build. Still undecisive about shared_ptr, weak_ptr, and general c++ refs.

parent 2f3b73bb
...@@ -121,7 +121,7 @@ QStatus AdapterLib::MockAdapter::SetPropertyValue( ...@@ -121,7 +121,7 @@ QStatus AdapterLib::MockAdapter::SetPropertyValue(
QStatus AdapterLib::MockAdapter::CallMethod( QStatus AdapterLib::MockAdapter::CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method, shared_ptr<Bridge::IAdapterMethod>& method,
Bridge::IAdapterIoRequest** req) shared_ptr<Bridge::IAdapterIoRequest>* req)
{ {
shared_ptr<MockAdapterMethod> m = dynamic_pointer_cast<MockAdapterMethod>(method); shared_ptr<MockAdapterMethod> m = dynamic_pointer_cast<MockAdapterMethod>(method);
if (!m) if (!m)
...@@ -150,7 +150,6 @@ QStatus AdapterLib::MockAdapter::RegisterSignalListener( ...@@ -150,7 +150,6 @@ QStatus AdapterLib::MockAdapter::RegisterSignalListener(
return ER_OK; return ER_OK;
} }
QStatus AdapterLib::MockAdapter::UnregisterSignalListener(Bridge::IAdapter::RegistrationHandle const& h) QStatus AdapterLib::MockAdapter::UnregisterSignalListener(Bridge::IAdapter::RegistrationHandle const& h)
{ {
QStatus st = ER_FAIL; QStatus st = ER_FAIL;
...@@ -177,21 +176,32 @@ void AdapterLib::MockAdapter::CreateMockDevices() ...@@ -177,21 +176,32 @@ void AdapterLib::MockAdapter::CreateMockDevices()
for (vector::const_iterator begin = devices.begin(), end = devices.end(); for (vector::const_iterator begin = devices.begin(), end = devices.end();
begin != end; ++begin) begin != end; ++begin)
{ {
shared_ptr<MockAdapter> self = shared_from_this(); shared_ptr<MockAdapter> self = dynamic_pointer_cast<MockAdapter>(shared_from_this());
shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, self)); shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, self));
// TODO m_devices.push_back(dev);
} }
} }
void AdapterLib::MockAdapter::CreateSignals() void AdapterLib::MockAdapter::CreateSignals()
{ {
//shared_ptr<MockAdapterSignal> signal(new MockAdapterSignal());
} }
QStatus AdapterLib::MockAdapter::NotifySignalListeners(shared_ptr<MockAdapterSignal> const& signal) QStatus AdapterLib::MockAdapter::NotifySignalListeners(shared_ptr<MockAdapterSignal> const& signal)
{ {
QStatus st = ER_OK; QStatus st = ER_FAIL;
return st; if (!signal)
} return st;
std::pair< SignalMap::iterator, SignalMap::iterator > range =
m_signalListeners.equal_range(signal->GetName());
for (SignalMap::iterator begin = range.first, end = range.second; begin != end; ++begin)
{
RegisteredSignal& handler = begin->second;
handler.Listener->AdapterSignalHandler(*signal, handler.Context);
}
return st;
}
...@@ -10,7 +10,7 @@ namespace AdapterLib ...@@ -10,7 +10,7 @@ namespace AdapterLib
class MockAdapterDevice; class MockAdapterDevice;
class MockAdapterSignal; class MockAdapterSignal;
class MockAdapter : public Bridge::IAdapter, public enable_shared_from_this<MockAdapter> class MockAdapter : public Bridge::IAdapter, public enable_shared_from_this<Bridge::IAdapter>
{ {
public: public:
MockAdapter(); MockAdapter();
...@@ -53,7 +53,7 @@ namespace AdapterLib ...@@ -53,7 +53,7 @@ namespace AdapterLib
virtual QStatus CallMethod( virtual QStatus CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method, shared_ptr<Bridge::IAdapterMethod>& method,
Bridge::IAdapterIoRequest** req); shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus RegisterSignalListener( virtual QStatus RegisterSignalListener(
std::string const& signalName, std::string const& signalName,
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
using namespace AdapterLib; using namespace AdapterLib;
MockAdapterDevice::MockAdapterDevice(MockDeviceDescriptor const& desc, shared_ptr<MockAdapter> const& parent) MockAdapterDevice::MockAdapterDevice(MockDeviceDescriptor const& desc, weak_ptr<MockAdapter> const& parent)
: m_name(desc.Name) : m_name(desc.Name)
, m_parent(parent) , m_parent(parent)
, m_vendor(desc.VendorName) , m_vendor(desc.VendorName)
...@@ -28,7 +28,7 @@ void MockAdapterDevice::CreateSignals() ...@@ -28,7 +28,7 @@ void MockAdapterDevice::CreateSignals()
{ {
Bridge::AdapterValueVector params; Bridge::AdapterValueVector params;
m_signalPrototypes.push_back(shared_ptr<MockAdapterSignal>(new MockAdapterSignal( m_signalPrototypes.push_back(shared_ptr<MockAdapterSignal>(new MockAdapterSignal(
Bridge::kChangeOfValueSignal, *this, params))); Bridge::kChangeOfValueSignal, shared_from_this(), params)));
// TODO: This is incomplete, re-visit once signal emit is worked on // TODO: This is incomplete, re-visit once signal emit is worked on
} }
...@@ -45,7 +45,7 @@ void MockAdapterDevice::CreateMethods() ...@@ -45,7 +45,7 @@ void MockAdapterDevice::CreateMethods()
QStatus MockAdapterDevice::DispatchMethod( QStatus MockAdapterDevice::DispatchMethod(
shared_ptr<MockAdapterMethod>& method, shared_ptr<MockAdapterMethod>& method,
Bridge::IAdapterIoRequest** req) shared_ptr<Bridge::IAdapterIoRequest>* req)
{ {
if (req) if (req)
*req = NULL; *req = NULL;
...@@ -284,7 +284,7 @@ void MockAdapterValue::SetData(ajn::MsgArg const& msg) ...@@ -284,7 +284,7 @@ void MockAdapterValue::SetData(ajn::MsgArg const& msg)
MockAdapterSignal::MockAdapterSignal( MockAdapterSignal::MockAdapterSignal(
std::string const& name, std::string const& name,
Bridge::IAdapterDevice const& parent, weak_ptr<MockAdapterDevice> const& parent,
Bridge::AdapterValueVector const& params) Bridge::AdapterValueVector const& params)
: m_name(name) : m_name(name)
, m_parent(parent) , m_parent(parent)
......
...@@ -17,7 +17,7 @@ namespace AdapterLib ...@@ -17,7 +17,7 @@ namespace AdapterLib
public: public:
MockAdapterSignal( MockAdapterSignal(
std::string const& name, std::string const& name,
Bridge::IAdapterDevice const& dev, weak_ptr<MockAdapterDevice> const& parent,
Bridge::AdapterValueVector const& params); Bridge::AdapterValueVector const& params);
virtual std::string GetName() const; virtual std::string GetName() const;
...@@ -29,7 +29,7 @@ namespace AdapterLib ...@@ -29,7 +29,7 @@ namespace AdapterLib
private: private:
std::string m_name; std::string m_name;
Bridge::IAdapterDevice const& m_parent; weak_ptr<MockAdapterDevice> m_parent;
Bridge::AdapterValueVector m_params; Bridge::AdapterValueVector m_params;
}; };
...@@ -101,7 +101,7 @@ namespace AdapterLib ...@@ -101,7 +101,7 @@ namespace AdapterLib
class MockAdapterDevice : public Bridge::IAdapterDevice, public enable_shared_from_this<MockAdapterDevice> class MockAdapterDevice : public Bridge::IAdapterDevice, public enable_shared_from_this<MockAdapterDevice>
{ {
public: public:
MockAdapterDevice(MockDeviceDescriptor const& desc, shared_ptr<MockAdapter> const& parent); MockAdapterDevice(MockDeviceDescriptor const& desc, weak_ptr<MockAdapter> const& parent);
virtual std::string GetName(); virtual std::string GetName();
virtual std::string GetVendor(); virtual std::string GetVendor();
...@@ -117,7 +117,7 @@ namespace AdapterLib ...@@ -117,7 +117,7 @@ namespace AdapterLib
QStatus DispatchMethod( QStatus DispatchMethod(
shared_ptr<MockAdapterMethod>& method, shared_ptr<MockAdapterMethod>& method,
Bridge::IAdapterIoRequest** req); shared_ptr<Bridge::IAdapterIoRequest>* req);
QStatus SendSignal( QStatus SendSignal(
std::string const& signalName, std::string const& signalName,
......
...@@ -199,25 +199,34 @@ QStatus Bridge::DeviceSystemBridge::RegisterAdapterSignalHandlers(bool isRegiste ...@@ -199,25 +199,34 @@ QStatus Bridge::DeviceSystemBridge::RegisterAdapterSignalHandlers(bool isRegiste
{ {
QStatus ret = ER_OK; QStatus ret = ER_OK;
shared_ptr<IAdapterSignalListener> listener = shared_ptr<IAdapterSignalListener> listener = dynamic_pointer_cast<IAdapterSignalListener>(g_Instance);
dynamic_pointer_cast<IAdapterSignalListener>(g_Instance);
AdapterSignalVector signals = m_adapter->GetSignals(); if (isRegister)
for (AdapterSignalVector::const_iterator itr = signals.begin(); itr != signals.end(); ++itr)
{ {
if (isRegister) AdapterSignalVector signals = m_adapter->GetSignals();
for (AdapterSignalVector::const_iterator itr = signals.begin(); itr != signals.end(); ++itr)
{ {
QStatus st = m_adapter->RegisterSignalListener(*itr, listener, NULL); Bridge::IAdapter::RegistrationHandle handle;
if (st != ER_OK) QStatus st = m_adapter->RegisterSignalListener((*itr)->GetName(), listener, NULL, handle);
{ if (st != ER_OK)
DSBLOG_WARN("failed to register signal listener on adapter: 0x%x", st); {
if (ret == ER_OK) DSBLOG_WARN("failed to register signal listener on adapter: 0x%x", st);
ret = st; if (ret == ER_OK)
ret = st;
}
else
{
m_registeredSignalListeners.push_back(handle);
}
} }
} }
else else
{
typedef std::vector<IAdapter::RegistrationHandle>::const_iterator iterator;
for (iterator begin = m_registeredSignalListeners.begin(), end = m_registeredSignalListeners.end();
begin != end; ++begin)
{ {
QStatus st = m_adapter->UnregisterSignalListener(*itr, listener); QStatus st = m_adapter->UnregisterSignalListener(*begin);
if (st != ER_OK) if (st != ER_OK)
{ {
DSBLOG_WARN("failed to unregister signal listener on adapter: 0x%x", st); DSBLOG_WARN("failed to unregister signal listener on adapter: 0x%x", st);
......
...@@ -73,6 +73,7 @@ namespace Bridge ...@@ -73,6 +73,7 @@ namespace Bridge
shared_ptr<IAdapter> m_adapter; shared_ptr<IAdapter> m_adapter;
BridgeDeviceList m_deviceList; BridgeDeviceList m_deviceList;
shared_ptr<AdapterSignalListener> m_adapterSignaListener; shared_ptr<AdapterSignalListener> m_adapterSignaListener;
std::vector<IAdapter::RegistrationHandle> m_registeredSignalListeners;
}; };
} }
...@@ -155,7 +155,7 @@ namespace Bridge ...@@ -155,7 +155,7 @@ namespace Bridge
virtual QStatus CallMethod( virtual QStatus CallMethod(
shared_ptr<IAdapterMethod>& method, shared_ptr<IAdapterMethod>& method,
IAdapterIoRequest** req) = 0; shared_ptr<IAdapterIoRequest>* req) = 0;
virtual QStatus RegisterSignalListener( virtual QStatus RegisterSignalListener(
std::string const& signalName, std::string const& signalName,
......
...@@ -7,7 +7,6 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \ ...@@ -7,7 +7,6 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \
Adapters/MockAdapter/MockAdapter.cpp \ Adapters/MockAdapter/MockAdapter.cpp \
Adapters/MockAdapter/MockDevices.cpp \ Adapters/MockAdapter/MockDevices.cpp \
Adapters/MockAdapter/MockAdapterDevice.cpp \ Adapters/MockAdapter/MockAdapterDevice.cpp \
Adapters/ZigBeeAdapter/ZigBeeAdapter.cpp \
main.cpp main.cpp
LIBXML_INC=/usr/include/libxml2 LIBXML_INC=/usr/include/libxml2
...@@ -22,8 +21,7 @@ OBJS=$(DEV_PROVIDER_OBJS) ...@@ -22,8 +21,7 @@ OBJS=$(DEV_PROVIDER_OBJS)
all: moc-adapter all: moc-adapter
clean: clean:
$(RM) MockAdapter core DeviceProviders/*.o Bridge/*.o Common/*.o Adapters/MockAdapter/*.o \ $(RM) MockAdapter core DeviceProviders/*.o Bridge/*.o Common/*.o Adapters/MockAdapter/*.o
Adapters/ZigBee/*.o
moc-adapter: $(OBJS) moc-adapter: $(OBJS)
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
#include "Bridge/Bridge.h" #include "Bridge/Bridge.h"
#include "Bridge/IAdapter.h" #include "Bridge/IAdapter.h"
#include "Common/Log.h" #include "Common/Log.h"
#include "Adapters/MockAdapter/MockAdapter.h"
#include "Adapters/ZigBeeAdapter/ZigBeeAdapter.h"
namespace namespace
{ {
...@@ -45,7 +44,7 @@ int main(int /*argc*/, char* /*argv*/ []) ...@@ -45,7 +44,7 @@ int main(int /*argc*/, char* /*argv*/ [])
QStatus st = ER_OK; QStatus st = ER_OK;
// TODO: should be unique_ptr and ownership give to bridge // TODO: should be unique_ptr and ownership give to bridge
shared_ptr<Bridge::IAdapter> adapter(new AdapterLib::ZigBeeAdapter()); shared_ptr<Bridge::IAdapter> adapter(new AdapterLib::MockAdapter());
shared_ptr<Bridge::DeviceSystemBridge> bridge(new Bridge::DeviceSystemBridge(adapter)); shared_ptr<Bridge::DeviceSystemBridge> bridge(new Bridge::DeviceSystemBridge(adapter));
st = bridge->Initialize(); st = bridge->Initialize();
......
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