Commit 5b9e0062 authored by gladish's avatar gladish

Started to add MockAdapter

parent ddafd813
*.o
*.swp
#include "Adapters/MockAdapter/MockAdapter.h"
#include "Adapters/MockAdapter/MockDevices.h"
#include "Adapters/MockAdapter/MockAdapterDevice.h"
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")
{
// TODO: get m_exposedApplicatioName and Prefix from config
}
AdapterLib::MockAdapter::~MockAdapter()
{
CreateMockDevices();
CreateSignals();
}
std::string AdapterLib::MockAdapter::GetVendor()
{
return m_vendor;
}
std::string AdapterLib::MockAdapter::GetAdapterName()
{
return m_adapterName;
}
std::string AdapterLib::MockAdapter::GetVersion()
{
return m_version;
}
std::string AdapterLib::MockAdapter::GetExposedAdapterPrefix()
{
return m_exposedAdapterPrefix;
}
std::string AdapterLib::MockAdapter::GetExposedApplicationName()
{
return m_exposedApplicationName;
}
std::string AdapterLib::MockAdapter::GetExposedApplicationGuid()
{
return m_exposedApplicationGuid;
}
Bridge::AdapterSignalVector AdapterLib::MockAdapter::GetSignals()
{
return Bridge::AdapterSignalVector();
}
QStatus AdapterLib::MockAdapter::Initialize()
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::Shutdown()
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::EnumDevices(
Bridge::EnumDeviceOptions opts,
Bridge::AdapterDeviceVector& deviceList,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::GetProperty(
shared_ptr<Bridge::IAdapterProperty>& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::SetProperty(
shared_ptr<Bridge::IAdapterProperty> const& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::GetPropertyValue(
shared_ptr<Bridge::IAdapterProperty> const& prop,
std::string const& attributeName,
shared_ptr<Bridge::IAdapterValue>& value,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::SetPropertyValue(
shared_ptr<Bridge::IAdapterProperty> const& prop,
shared_ptr<Bridge::IAdapterValue> const& value,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method,
shared_ptr<Bridge::IAdapterIoRequest>* req)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::RegisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener,
void* argp)
{
return ER_NOT_IMPLEMENTED;
}
QStatus AdapterLib::MockAdapter::UnregisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener)
{
return ER_NOT_IMPLEMENTED;
}
void AdapterLib::MockAdapter::CreateMockDevices()
{
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<MockAdapterDevice> dev(new MockAdapterDevice(*begin, shared_from_this()));
}
}
void AdapterLib::MockAdapter::CreateSignals()
{
}
#pragma once
#include "Bridge/IAdapter.h"
#include "Common/defines.h"
namespace AdapterLib
{
class MockAdapterDevice;
class MockAdapter : public Bridge::IAdapter, public enable_shared_from_this<Bridge::IAdapter>
{
public:
MockAdapter();
virtual ~MockAdapter();
virtual std::string GetVendor();
virtual std::string GetAdapterName();
virtual std::string GetVersion();
virtual std::string GetExposedAdapterPrefix();
virtual std::string GetExposedApplicationName();
virtual std::string GetExposedApplicationGuid();
virtual Bridge::AdapterSignalVector GetSignals();
virtual QStatus Initialize();
virtual QStatus Shutdown();
virtual QStatus EnumDevices(
Bridge::EnumDeviceOptions opts,
Bridge::AdapterDeviceVector& deviceList,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus GetProperty(
shared_ptr<Bridge::IAdapterProperty>& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus SetProperty(
shared_ptr<Bridge::IAdapterProperty> const& prop,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus GetPropertyValue(
shared_ptr<Bridge::IAdapterProperty> const& prop,
std::string const& attributeName,
shared_ptr<Bridge::IAdapterValue>& value,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus SetPropertyValue(
shared_ptr<Bridge::IAdapterProperty> const& prop,
shared_ptr<Bridge::IAdapterValue> const& value,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus CallMethod(
shared_ptr<Bridge::IAdapterMethod>& method,
shared_ptr<Bridge::IAdapterIoRequest>* req);
virtual QStatus RegisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener,
void* argp);
virtual QStatus UnregisterSignalListener(
shared_ptr<Bridge::IAdapterSignal> const& signal,
shared_ptr<Bridge::IAdapterSignalListener> const& listener);
private:
void CreateMockDevices();
void CreateSignals();
private:
std::string m_vendor;
std::string m_adapterName;
std::string m_version;
std::string m_exposedAdapterPrefix;
std::string m_exposedApplicationName;
std::string m_exposedApplicationGuid;
std::vector< shared_ptr<MockAdapterDevice> > m_devices;
};
}
#include "Adapters/MockAdapter/MockAdapterDevice.h"
using namespace AdapterLib;
MockAdapterDevice::MockAdapterDevice(
MockDeviceDescriptor const& desc,
shared_ptr<Bridge::IAdapter> const& parent)
: m_name(desc.Name)
, m_parent(parent)
, m_vendor(desc.VendorName)
, m_model(desc.Model)
, m_version("never set") // TODO
, m_firmwareVersion(desc.Version)
, 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()
{
}
void MockAdapterDevice::CreateMethods()
{
shared_ptr<MockAdapterMethod> m(new MockAdapterMethod(kDeviceResetMethod, this));
m_methods.push_back(m);
}
std::string MockAdapterDevice::GetName()
{
return m_name;
}
std::string MockAdapterDevice::GetVendor()
{
return m_vendor;
}
std::string MockAdapterDevice::GetModel()
{
return m_model;
}
std::string MockAdapterDevice::GetVersion()
{
return m_version;
}
std::string MockAdapterDevice::GetFirmwareVersion()
{
return m_firmwareVersion;
}
std::string MockAdapterDevice::GetSerialNumber()
{
return m_serialNumber;
}
std::string MockAdapterDevice::GetDescription()
{
return m_description;
}
Bridge::AdapterPropertyVector MockAdapterDevice::GetProperties()
{
return m_properties;
}
Bridge::AdapterMethodVector MockAdapterDevice::GetMethods()
{
return m_methods;
}
Bridge::AdapterSignalVector MockAdapterDevice::GetSignals()
{
return m_signals;
}
MockAdapterProperty::MockAdapterProperty(MockPropertyDescriptor const& desc)
: m_name(desc.Name)
{
}
std::string MockAdapterProperty::GetName()
{
return m_name;
}
Bridge::AdapterValueVector MockAdapterProperty::GetAttributes()
{
return m_attributes;
}
// MockAdapterMethod
MockAdapterMethod::MockAdapterMethod(std::string const& name, MockAdapterDevice* parent)
: m_name(name)
, m_parent(parent)
{
}
std::string MockAdapterMethod::GetName()
{
return m_name;
}
std::string MockAdapterMethod::GetDescription()
{
return m_description;
}
Bridge::AdapterValueVector MockAdapterMethod::GetInputParams()
{
return m_inputParams;
}
Bridge::AdapterValueVector MockAdapterMethod::GetOutputParams()
{
return m_outputParams;
}
void MockAdapterMethod::SetInputParams(Bridge::AdapterValueVector const& params)
{
m_inputParams = params;
}
void MockAdapterMethod::SetOutputParams(Bridge::AdapterValueVector const& params)
{
m_outputParams = params;
}
int32_t MockAdapterMethod::GetResult()
{
return 0;
}
#pragma once
#include "Adapters/MockAdapter/MockDevices.h"
#include "Bridge/IAdapter.h"
namespace AdapterLib
{
std::string const kDeviceResetMethod = "Device_Reset";
std::string const kDeviceResetPropertyHandle = "Property_Handle";
std::string const kDsbMethodReturnValue = "Return_Value";
class MockAdapterDevice;
class MockAdapterMethod : public Bridge::IAdapterMethod
{
public:
MockAdapterMethod(std::string const& name, MockAdapterDevice* parent);
virtual std::string GetName();
virtual std::string GetDescription();
virtual Bridge::AdapterValueVector GetInputParams();
virtual Bridge::AdapterValueVector GetOutputParams();
virtual void SetInputParams(Bridge::AdapterValueVector const& params);
virtual void SetOutputParams(Bridge::AdapterValueVector const& params);
virtual int32_t GetResult();
private:
std::string m_name;
std::string m_description;
Bridge::AdapterValueVector m_inputParams;
Bridge::AdapterValueVector m_outputParams;
MockAdapterDevice* m_parent;
};
class MockAdapterProperty : public Bridge::IAdapterProperty
{
public:
MockAdapterProperty(MockPropertyDescriptor const& desc);
virtual std::string GetName();
virtual Bridge::AdapterValueVector GetAttributes();
private:
std::string m_name;
Bridge::AdapterValueVector m_attributes;
};
class MockAdapterDevice : public Bridge::IAdapterDevice
{
public:
MockAdapterDevice(
MockDeviceDescriptor const& desc,
shared_ptr<Bridge::IAdapter> const& parent);
virtual std::string GetName();
virtual std::string GetVendor();
virtual std::string GetModel();
virtual std::string GetVersion();
virtual std::string GetFirmwareVersion();
virtual std::string GetSerialNumber();
virtual std::string GetDescription();
virtual Bridge::AdapterPropertyVector GetProperties();
virtual Bridge::AdapterMethodVector GetMethods();
virtual Bridge::AdapterSignalVector GetSignals();
private:
void CreateMethods();
void CreateSignals();
private:
std::string m_name;
shared_ptr<Bridge::IAdapter> m_parent;
std::string m_vendor;
std::string m_model;
std::string m_version;
std::string m_firmwareVersion;
std::string m_serialNumber;
std::string m_description;
Bridge::AdapterPropertyVector m_properties;
Bridge::AdapterMethodVector m_methods;
Bridge::AdapterSignalVector m_signals;
};
};
#include "Adapters/MockAdapter/MockDevices.h"
namespace
{
using namespace AdapterLib;
const MockDeviceDescriptor kMockDevices[] =
{
// Device #1 - A light bulb
{
1, // Device ID
"Mock BACnet Switch", // Device name
"Microsoft", // Vendor
"2 X Switch", // Model
"001-001-001", // Serial
"1.1.1.1", // Version
"2 Gang Switch Pack", // Description
// Properties
{
// Property #1
{
1, // Property ID
MockPropertyType::BinaryOutput, // Property type
"Switch 1", // Name
MockPropertyAccess::ReadOnly, // Access
MockPropertyUnits::NoUnits, // Units
// Current value
{
ajn::ALLJOYN_BOOLEAN, // ValueType
"Room 1 Back Light", // Name
{ // Initial value
0, // SimpleType
{}, // Array of bytes
{""} // String
}
}
},
// Property #2
{
2, // Property ID
MockPropertyType::BinaryOutput, // Property type
"Switch 2", // Name
MockPropertyAccess::ReadWrite, // Access
MockPropertyUnits::NoUnits, // Units
// Current value
{
ajn::ALLJOYN_BOOLEAN, // ValueType
"Room 1 Main Light", // Name
{ // Initial value
0, // SimpleType
{}, // Array of bytes
{""} // String
},
}
},
{ kLastDescriptorId } // Last property
} // Properties[]
},
// Device #2 - A dimmable light bulb
{
2, // Device ID
"Mock BACnet Dimmable Switch", // Device name
"Microsoft", // Vendor
"Dim Control 725", // Model
"001-002-001", // Serial
"1.1.2.1", // Version
"Room2, Dimmable Light Switch", // Description
// Properties
{
// Property #1
{
1, // Property ID
MockPropertyType::BinaryOutput, // Property type
"Switch", // Name
MockPropertyAccess::ReadWrite, // Access
MockPropertyUnits::NoUnits, // Units
// Current value
{
ajn::ALLJOYN_BOOLEAN, // ValueType
"Living Room Light", // Name
{ // Initial value
0, // SimpleType
{}, // Array of bytes
{""} // String
},
}
},
// Property #2
{
2, // Property ID
MockPropertyType::AnalogOutput, // Property type
"Dim Control", // Name
MockPropertyAccess::ReadWrite, // Access
MockPropertyUnits::Percent, // Units
// Current Value
{
ajn::ALLJOYN_UINT32, // ValueType
"Living Room Dimmer", // Name
{ // Initial value
50, // SimpleType
{}, // Array of bytes
{""} // WCHAR string
},
}
},
{ kLastDescriptorId } // Last property
} // Properties[]
},
// Device #3 - A temperature sensor
{
3, // Device ID
"Mock BACnet Temperature Sensor", // Device name
"Microsoft", // Vendor
"Temperature Sensor 155", // Model
"001-003-001", // Serial
"1.1.3.1", // Version
"Temperature Sensor", // Description
// Properties
{
// Property #1
{
1, // Property ID
MockPropertyType::AnalogInput, // Property type
"Temperature", // Name
MockPropertyAccess::ReadOnly, // Access
MockPropertyUnits::DegressFahrenheit, // Units
// Current Value
{
ajn::ALLJOYN_DOUBLE, // ValueType
"Living Room Temperature", // Name
{ // Initial value
62.5, // SimpleType
{}, // Array of bytes
{""} // WCHAR string
},
}
},
{ kLastDescriptorId } // Last endpoint
}
},
};
}
std::vector<AdapterLib::MockDeviceDescriptor> AdapterLib::GetMockDevices()
{