Commit 3cf2e6e0 authored by gladish's avatar gladish
Browse files

Fixed a few minor crashes. main.cpp runs wihtout error.

parent 87adf8f2
......@@ -2,6 +2,9 @@
#include "Adapters/MockAdapter/MockDevices.h"
#include "Adapters/MockAdapter/MockAdapterDevice.h"
#include <vector>
#include <algorithm>
namespace
{
Bridge::IAdapter::RegistrationHandle nextHandle = 0;
......@@ -23,8 +26,6 @@ AdapterLib::MockAdapter::MockAdapter()
AdapterLib::MockAdapter::~MockAdapter()
{
CreateMockDevices();
CreateSignals();
}
std::string AdapterLib::MockAdapter::GetVendor()
......@@ -65,7 +66,9 @@ Bridge::AdapterSignalVector AdapterLib::MockAdapter::GetSignals()
QStatus AdapterLib::MockAdapter::Initialize()
{
return ER_NOT_IMPLEMENTED;
CreateMockDevices();
CreateSignals();
return ER_OK;
}
......@@ -76,11 +79,17 @@ QStatus AdapterLib::MockAdapter::Shutdown()
QStatus AdapterLib::MockAdapter::EnumDevices(
Bridge::EnumDeviceOptions opts,
Bridge::EnumDeviceOptions /*opts*/,
Bridge::AdapterDeviceVector& deviceList,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
if (req)
*req = NULL;
deviceList.clear();
std::copy(m_devices.begin(), m_devices.end(), std::back_inserter(deviceList));
return ER_OK;
}
......@@ -88,7 +97,24 @@ QStatus AdapterLib::MockAdapter::GetProperty(
shared_ptr<Bridge::IAdapterProperty>& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
if (req)
*req = NULL;
shared_ptr<MockAdapterProperty> mockAdapterProperty = dynamic_pointer_cast<MockAdapterProperty>(prop);
if (!mockAdapterProperty)
return ER_BAD_ARG_1;
shared_ptr<MockAdapterDevice> device = mockAdapterProperty->GetParent();
if (!device)
return ER_INVALID_ADDRESS;
shared_ptr<MockAdapter> adapter = device->GetParent();
if (!adapter)
return ER_INVALID_ADDRESS;
// TODO: set prop with latest stuff
return ER_OK;
}
......@@ -96,7 +122,24 @@ QStatus AdapterLib::MockAdapter::SetProperty(
shared_ptr<Bridge::IAdapterProperty> const& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
if (req)
*req = NULL;
shared_ptr<MockAdapterProperty> mockAdapterProperty = dynamic_pointer_cast<MockAdapterProperty>(prop);
if (!mockAdapterProperty)
return ER_BAD_ARG_1;
shared_ptr<MockAdapterDevice> device = mockAdapterProperty->GetParent();
if (!device)
return ER_INVALID_ADDRESS;
shared_ptr<MockAdapter> adapter = device->GetParent();
if (!adapter)
return ER_INVALID_ADDRESS;
// TODO: set internal state from prop->GetData()
return ER_OK;
}
......@@ -106,7 +149,20 @@ QStatus AdapterLib::MockAdapter::GetPropertyValue(
shared_ptr<Bridge::IAdapterValue>& value,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
if (req)
*req = NULL;
shared_ptr<MockAdapterProperty> mockAdapterProperty = dynamic_pointer_cast<MockAdapterProperty>(prop);
if (!mockAdapterProperty)
return ER_BAD_ARG_1;
shared_ptr<MockAdapterValue> attr = mockAdapterProperty->GetAttributeByName(attributeName);
if (!attr)
return ER_INVALID_ADDRESS;
value = dynamic_pointer_cast<Bridge::IAdapterValue>(attr);
return ER_OK;
}
......@@ -115,7 +171,20 @@ QStatus AdapterLib::MockAdapter::SetPropertyValue(
shared_ptr<Bridge::IAdapterValue> const& value,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
if (req)
*req = NULL;
shared_ptr<MockAdapterProperty> mockAdapterProperty = dynamic_pointer_cast<MockAdapterProperty>(prop);
if (!mockAdapterProperty)
return ER_BAD_ARG_1;
shared_ptr<MockAdapterValue> attr = mockAdapterProperty->GetAttributeByName(value->GetName());
if (!attr)
return ER_INVALID_ADDRESS;
attr->SetData(value->GetData());
return ER_OK;
}
......@@ -164,27 +233,33 @@ QStatus AdapterLib::MockAdapter::UnregisterSignalListener(Bridge::IAdapter::Regi
}
}
return st;
return ER_NOT_IMPLEMENTED;
}
void AdapterLib::MockAdapter::CreateMockDevices()
{
shared_ptr<MockAdapter> self = dynamic_pointer_cast<MockAdapter>(shared_from_this());
typedef std::vector<AdapterLib::MockDeviceDescriptor> vector;
vector devices = AdapterLib::GetMockDevices();
for (vector::const_iterator begin = devices.begin(), end = devices.end();
begin != end; ++begin)
{
shared_ptr<MockAdapter> self = dynamic_pointer_cast<MockAdapter>(shared_from_this());
shared_ptr<MockAdapterDevice> dev(new MockAdapterDevice(*begin, self));
shared_ptr<MockAdapterDevice> dev = MockAdapterDevice::Create(*begin, self);
m_devices.push_back(dev);
}
}
void AdapterLib::MockAdapter::CreateSignals()
{
//shared_ptr<MockAdapterSignal> signal(new MockAdapterSignal());
shared_ptr<MockAdapterDevice> parent;
Bridge::AdapterValueVector values;
shared_ptr<MockAdapterValue> val(new MockAdapterValue(Bridge::kDeviceArravalHandle));
shared_ptr<MockAdapterSignal> signal(new MockAdapterSignal(Bridge::kDeviceArrivalSignal,
parent, values));
m_signals.push_back(signal);
}
QStatus AdapterLib::MockAdapter::NotifySignalListeners(shared_ptr<MockAdapterSignal> const& signal)
......
......@@ -78,6 +78,7 @@ namespace AdapterLib
std::string m_exposedApplicationGuid;
std::vector< shared_ptr<MockAdapterDevice> > m_devices;
std::vector< shared_ptr<MockAdapterSignal> > m_signals;
struct RegisteredSignal
{
......
......@@ -3,6 +3,28 @@
using namespace AdapterLib;
shared_ptr<MockAdapterDevice> MockAdapterDevice::Create(
MockDeviceDescriptor const& desc,
weak_ptr<MockAdapter> const& parent)
{
shared_ptr<MockAdapterDevice> device(new MockAdapterDevice(desc, parent));
for (int i = 0; i < kMockDeviceMaxProperties; ++i)
{
MockPropertyDescriptor const& descriptor = desc.PropertyDescriptors[i];
if (descriptor.Id == kLastDescriptorId)
break;
device->m_properties.push_back(shared_ptr<Bridge::IAdapterProperty>(
new MockAdapterProperty(descriptor, device)));
}
device->CreateMethods();
device->CreateSignals();
return device;
}
MockAdapterDevice::MockAdapterDevice(MockDeviceDescriptor const& desc, weak_ptr<MockAdapter> const& parent)
: m_name(desc.Name)
, m_parent(parent)
......@@ -13,22 +35,14 @@ MockAdapterDevice::MockAdapterDevice(MockDeviceDescriptor const& desc, weak_ptr<
, m_serialNumber(desc.SerialNumber)
, m_description(desc.Description)
{
for (int i = 0; i < kMockDeviceMaxProperties; ++i)
{
MockPropertyDescriptor const& d = desc.PropertyDescriptors[i];
if (d.Id == kLastDescriptorId)
break;
m_properties.push_back(shared_ptr<Bridge::IAdapterProperty>(
new MockAdapterProperty(d)));
}
}
void MockAdapterDevice::CreateSignals()
{
Bridge::AdapterValueVector params;
m_signalPrototypes.push_back(shared_ptr<MockAdapterSignal>(new MockAdapterSignal(
Bridge::kChangeOfValueSignal, shared_from_this(), params)));
Bridge::AdapterValueVector params;
m_signalPrototypes.push_back(shared_ptr<MockAdapterSignal>(new MockAdapterSignal(
Bridge::kChangeOfValueSignal, shared_from_this(), params)));
// TODO: This is incomplete, re-visit once signal emit is worked on
}
......@@ -38,8 +52,7 @@ void MockAdapterDevice::CreateMethods()
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->AddInputParam(shared_ptr<Bridge::IAdapterValue>(new MockAdapterValue(kDeviceResetPropertyHandle)));
m_methods.push_back(m);
}
......@@ -94,10 +107,12 @@ QStatus MockAdapterDevice::SendSignal(
{
Bridge::AdapterValueVector params;
shared_ptr<MockAdapterValue> p(new MockAdapterValue("PropertyName", *this));
shared_ptr<MockAdapterDevice> self = shared_from_this();
shared_ptr<MockAdapterValue> p(new MockAdapterValue("PropertyName"));
p->SetData(ajn::MsgArg("s", prop->GetName().c_str(), NULL));
shared_ptr<MockAdapterValue> v(new MockAdapterValue("PropertyValue", *this));
shared_ptr<MockAdapterValue> v(new MockAdapterValue("PropertyValue"));
v->SetData(value->GetData());
params.push_back(p);
......@@ -182,8 +197,10 @@ Bridge::AdapterSignalVector const& MockAdapterDevice::GetSignals() const
return m_signalPrototypes;
}
MockAdapterProperty::MockAdapterProperty(MockPropertyDescriptor const& desc)
MockAdapterProperty::MockAdapterProperty( MockPropertyDescriptor const& desc,
weak_ptr<MockAdapterDevice> const& parent)
: m_name(desc.Name)
, m_parent(parent)
{
}
......@@ -192,6 +209,18 @@ std::string MockAdapterProperty::GetName()
return m_name;
}
shared_ptr<MockAdapterValue> MockAdapterProperty::GetAttributeByName(std::string const& name)
{
typedef Bridge::AdapterValueVector::const_iterator iterator;
for (iterator begin = m_attributes.begin(), end = m_attributes.end(); begin != end; ++begin)
{
if ((*begin)->GetName() == name)
return dynamic_pointer_cast<MockAdapterValue>(*begin);
}
return shared_ptr<MockAdapterValue>();
}
Bridge::AdapterValueVector MockAdapterProperty::GetAttributes()
{
return m_attributes;
......@@ -258,11 +287,8 @@ void MockAdapterMethod::SetResult(QStatus st)
m_result = st;
}
MockAdapterValue::MockAdapterValue(
std::string const& name,
MockAdapterDevice const& parent)
MockAdapterValue::MockAdapterValue(std::string const& name)
: m_name(name)
, m_parent(parent)
{
}
......
......@@ -11,6 +11,7 @@ namespace AdapterLib
class MockAdapter;
class MockAdapterDevice;
class MockAdapterValue;
class MockAdapterSignal : public Bridge::IAdapterSignal
{
......@@ -23,8 +24,6 @@ namespace AdapterLib
virtual std::string GetName() const;
virtual Bridge::AdapterValueVector const& GetParams() const;
void SetParams(Bridge::AdapterValueVector const& params);
shared_ptr<MockAdapterSignal> Clone();
private:
......@@ -71,22 +70,26 @@ namespace AdapterLib
class MockAdapterProperty : public Bridge::IAdapterProperty
{
public:
MockAdapterProperty(MockPropertyDescriptor const& desc);
MockAdapterProperty(MockPropertyDescriptor const& desc, weak_ptr<MockAdapterDevice> const& parent);
virtual std::string GetName();
virtual Bridge::AdapterValueVector GetAttributes();
shared_ptr<MockAdapterDevice> GetParent()
{ return m_parent.lock(); }
shared_ptr<MockAdapterValue> GetAttributeByName(std::string const& name);
private:
std::string m_name;
Bridge::AdapterValueVector m_attributes;
weak_ptr<MockAdapterDevice> m_parent;
};
class MockAdapterValue : public Bridge::IAdapterValue
{
public:
MockAdapterValue(
std::string const& name,
MockAdapterDevice const& parent);
MockAdapterValue(std::string const& name);
virtual std::string GetName();
virtual ajn::MsgArg GetData();
......@@ -95,14 +98,15 @@ namespace AdapterLib
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, weak_ptr<MockAdapter> const& parent);
static shared_ptr<MockAdapterDevice> Create(
MockDeviceDescriptor const& desc,
weak_ptr<MockAdapter> const& parent);
virtual std::string GetName();
virtual std::string GetVendor();
virtual std::string GetModel();
......@@ -124,7 +128,12 @@ namespace AdapterLib
shared_ptr<MockAdapterProperty> const& prop,
shared_ptr<MockAdapterValue> const& attr);
shared_ptr<MockAdapter> GetParent() const
{ return m_parent.lock(); }
private:
MockAdapterDevice(MockDeviceDescriptor const& desc, weak_ptr<MockAdapter> const& parent);
void CreateMethods();
void CreateSignals();
......
......@@ -132,21 +132,16 @@ QStatus Bridge::DeviceSystemBridge::InitializeAdapter()
return m_adapter->Initialize();
}
QStatus Bridge::DeviceSystemBridge::InitializeDevices(bool isUpdate)
QStatus Bridge::DeviceSystemBridge::InitializeDevices(bool update)
{
AdapterDeviceVector deviceList;
shared_ptr<IAdapterIoRequest> request;
EnumDeviceOptions opts = EnumDeviceOptions::CacheOnly;
if (isUpdate)
if (update)
opts = EnumDeviceOptions::ForceRefresh;
QStatus st = m_adapter->EnumDevices(opts, deviceList, &request);
if (st == ER_OK)
{
if ((st = request->Wait(kWaitTimeoutForAdapterOperation)) != ER_OK)
DSBLOG_WARN("timeout waiting for EnumDevices to complete");
}
if (st != ER_OK)
goto Leave;
......
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