Commit 87adf8f2 authored by gladish's avatar gladish

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

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