Commit eb79b675 authored by jacobgladish's avatar jacobgladish

Some code cleanup. Trying to nail down adapter api.

parent b80bfeef
......@@ -74,7 +74,7 @@ bridge::AdapterSignalVector adapters::mock::MockAdapter::GetSignals()
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::Initialize(std::shared_ptr<bridge::IAdapterLog> const& log)
{
CreateMockDevices();
......@@ -84,7 +84,7 @@ adapters::mock::MockAdapter::Initialize(std::shared_ptr<bridge::IAdapterLog> con
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::Shutdown()
{
m_vendor.clear();
......@@ -101,7 +101,7 @@ adapters::mock::MockAdapter::Shutdown()
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::EnumDevices(
bridge::EnumDeviceOptions /*opts*/,
bridge::AdapterDeviceVector& deviceList,
......@@ -118,7 +118,7 @@ adapters::mock::MockAdapter::EnumDevices(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::GetProperty(
std::shared_ptr<bridge::IAdapterProperty>& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req)
......@@ -144,7 +144,7 @@ adapters::mock::MockAdapter::GetProperty(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::SetProperty(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req)
......@@ -170,7 +170,7 @@ adapters::mock::MockAdapter::SetProperty(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::GetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::string const& attributeName,
......@@ -194,7 +194,7 @@ adapters::mock::MockAdapter::GetPropertyValue(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::SetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterValue> const& value,
......@@ -217,7 +217,7 @@ adapters::mock::MockAdapter::SetPropertyValue(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::CallMethod(
std::shared_ptr<bridge::IAdapterMethod>& method,
std::shared_ptr<bridge::IAdapterIoRequest>* req)
......@@ -234,7 +234,7 @@ adapters::mock::MockAdapter::CallMethod(
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::RegisterSignalListener(
std::string const& signalName,
std::shared_ptr<bridge::IAdapterSignalListener> const& listener,
......@@ -250,10 +250,10 @@ adapters::mock::MockAdapter::RegisterSignalListener(
return ER_OK;
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::UnregisterSignalListener(bridge::IAdapter::RegistrationHandle const& h)
{
int32_t st = ER_FAIL;
bridge::AdapterStatus st = ER_FAIL;
for (SignalMap::iterator begin = m_signalListeners.begin(), end = m_signalListeners.end();
begin != end; ++begin)
{
......@@ -296,10 +296,10 @@ adapters::mock::MockAdapter::CreateSignals()
m_signals.push_back(signal);
}
int32_t
bridge::AdapterStatus
adapters::mock::MockAdapter::NotifySignalListeners(std::shared_ptr<MockAdapterSignal> const& signal)
{
int32_t st = ER_FAIL;
bridge::AdapterStatus st = ER_FAIL;
if (!signal)
return st;
......
#pragma once
#include "Bridge/IAdapter.h"
#include "Common/defines.h"
#include <map>
#include <memory>
......@@ -27,52 +26,52 @@ namespace mock
virtual common::Guid GetExposedApplicationGuid();
virtual bridge::AdapterSignalVector GetSignals();
virtual int32_t Initialize(std::shared_ptr<bridge::IAdapterLog> const& log);
virtual int32_t Shutdown();
virtual bridge::AdapterStatus Initialize(std::shared_ptr<bridge::IAdapterLog> const& log);
virtual bridge::AdapterStatus Shutdown();
virtual int32_t GetConfiguration(std::vector<uint8_t>* /*configData*/)
virtual bridge::AdapterStatus GetConfiguration(std::vector<uint8_t>* /*configData*/)
{ return 0; }
virtual int32_t SetConfiguration(std::vector<uint8_t> const& /*configData*/)
virtual bridge::AdapterStatus SetConfiguration(std::vector<uint8_t> const& /*configData*/)
{ return 0; }
virtual int32_t EnumDevices(
virtual bridge::AdapterStatus EnumDevices(
bridge::EnumDeviceOptions opts,
bridge::AdapterDeviceVector& deviceList,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t GetProperty(
virtual bridge::AdapterStatus GetProperty(
std::shared_ptr<bridge::IAdapterProperty>& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t SetProperty(
virtual bridge::AdapterStatus SetProperty(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t GetPropertyValue(
virtual bridge::AdapterStatus GetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::string const& attributeName,
std::shared_ptr<bridge::IAdapterValue>& value,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t SetPropertyValue(
virtual bridge::AdapterStatus SetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterValue> const& value,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t CallMethod(
virtual bridge::AdapterStatus CallMethod(
std::shared_ptr<bridge::IAdapterMethod>& method,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t RegisterSignalListener(
virtual bridge::AdapterStatus RegisterSignalListener(
std::string const& signalName,
std::shared_ptr<bridge::IAdapterSignalListener> const& listener,
void* argp,
bridge::IAdapter::RegistrationHandle& handle);
virtual int32_t UnregisterSignalListener(bridge::IAdapter::RegistrationHandle const& h);
virtual bridge::AdapterStatus UnregisterSignalListener(bridge::IAdapter::RegistrationHandle const& h);
int32_t NotifySignalListeners(std::shared_ptr<MockAdapterSignal> const& signal);
bridge::AdapterStatus NotifySignalListeners(std::shared_ptr<MockAdapterSignal> const& signal);
private:
void CreateMockDevices();
......
......@@ -61,19 +61,19 @@ adapter::zigbee::Adapter::GetSignals()
return bridge::AdapterSignalVector();
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::Initialize()
{
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::Shutdown()
{
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::EnumDevices(
bridge::EnumDeviceOptions,
bridge::AdapterDeviceVector&,
......@@ -82,7 +82,7 @@ adapter::zigbee::Adapter::EnumDevices(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::GetProperty(
std::shared_ptr<bridge::IAdapterProperty>&,
std::shared_ptr<bridge::IAdapterIoRequest>*)
......@@ -90,7 +90,7 @@ adapter::zigbee::Adapter::GetProperty(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::SetProperty(
std::shared_ptr<bridge::IAdapterProperty> const&,
std::shared_ptr<bridge::IAdapterIoRequest>*)
......@@ -98,7 +98,7 @@ adapter::zigbee::Adapter::SetProperty(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::GetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const&,
std::string const&,
......@@ -108,7 +108,7 @@ adapter::zigbee::Adapter::GetPropertyValue(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::SetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const&,
std::shared_ptr<bridge::IAdapterValue> const&,
......@@ -117,7 +117,7 @@ adapter::zigbee::Adapter::SetPropertyValue(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::CallMethod(
std::shared_ptr<bridge::IAdapterMethod>&,
std::shared_ptr<bridge::IAdapterIoRequest>*)
......@@ -125,7 +125,7 @@ adapter::zigbee::Adapter::CallMethod(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::RegisterSignalListener(
std::string const&,
std::shared_ptr<bridge::IAdapterSignalListener> const&,
......@@ -135,7 +135,7 @@ adapter::zigbee::Adapter::RegisterSignalListener(
return -1;
}
int32_t
bridge::AdapterStatus
adapter::zigbee::Adapter::UnregisterSignalListener(bridge::IAdapter::RegistrationHandle const&)
{
return -1;
......
......@@ -58,44 +58,44 @@ namespace zigbee
virtual common::Guid GetExposedApplicationGuid();
virtual bridge::AdapterSignalVector GetSignals();
virtual int32_t Initialize();
virtual int32_t Shutdown();
virtual bridge::AdapterStatus Initialize();
virtual bridge::AdapterStatus Shutdown();
virtual int32_t EnumDevices(
virtual bridge::AdapterStatus EnumDevices(
bridge::EnumDeviceOptions opts,
bridge::AdapterDeviceVector& deviceList,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t GetProperty(
virtual bridge::AdapterStatus GetProperty(
std::shared_ptr<bridge::IAdapterProperty>& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t SetProperty(
virtual bridge::AdapterStatus SetProperty(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t GetPropertyValue(
virtual bridge::AdapterStatus GetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::string const& attributeName,
std::shared_ptr<bridge::IAdapterValue>& value,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t SetPropertyValue(
virtual bridge::AdapterStatus SetPropertyValue(
std::shared_ptr<bridge::IAdapterProperty> const& prop,
std::shared_ptr<bridge::IAdapterValue> const& value,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t CallMethod(
virtual bridge::AdapterStatus CallMethod(
std::shared_ptr<bridge::IAdapterMethod>& method,
std::shared_ptr<bridge::IAdapterIoRequest>* req);
virtual int32_t RegisterSignalListener(
virtual bridge::AdapterStatus RegisterSignalListener(
std::string const& signalName,
std::shared_ptr<bridge::IAdapterSignalListener> const& listener,
void* argp,
bridge::IAdapter::RegistrationHandle& handle);
virtual int32_t UnregisterSignalListener(
virtual bridge::AdapterStatus UnregisterSignalListener(
bridge::IAdapter::RegistrationHandle const& h);
};
}
......
#pragma once
#include "Common/defines.h"
#include "Common/Guid.h"
#include <alljoyn/AboutData.h>
......
#pragma once
#include "Common/defines.h"
#include "Bridge/IAdapter.h"
#include "Bridge/ConfigManager.h"
......
#pragma once
#include "Common/defines.h"
#include "Bridge/BridgeConfig.h"
#include <alljoyn/BusAttachment.h>
......
#pragma once
#include "Common/defines.h"
#include "Common/Guid.h"
#include "Common/Variant.h"
#include <condition_variable>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <vector>
namespace bridge
{
typedef uint32_t AdapterStatus;
inline bool IsOk(AdapterStatus st)
{
return st == 0;
}
std::string const kDeviceArrivalSignal = "Device_Arrival";
std::string const kDeviceArravalHandle = "Device_Handle";
std::string const kDeviceRemovalSignal = "Device_Removal";
......@@ -155,10 +163,10 @@ namespace bridge
class IAdapterIoRequest
{
public:
virtual int32_t Status() = 0;;
virtual int32_t Wait(uint32_t timeoutMillis) = 0;
virtual ~IAdapterIoRequest() { }
virtual int32_t GetStatus() = 0;;
virtual int32_t Wait(uint32_t timeoutMillis = std::numeric_limits<uint32_t>::max()) = 0;
virtual int32_t Cancel() = 0;
virtual int32_t Release() = 0;
};
enum class EnumDeviceOptions
......@@ -172,6 +180,7 @@ namespace bridge
protected:
IAdapter() { }
public:
typedef int32_t RegistrationHandle;
virtual ~IAdapter() { }
......@@ -183,47 +192,47 @@ namespace bridge
virtual common::Guid GetExposedApplicationGuid() = 0;
virtual AdapterSignalVector GetSignals() = 0;
virtual int32_t SetConfiguration(std::vector<uint8_t> const& configData) = 0;
virtual int32_t GetConfiguration(std::vector<uint8_t>* configData) = 0;
virtual AdapterStatus SetConfiguration(std::vector<uint8_t> const& configData) = 0;
virtual AdapterStatus GetConfiguration(std::vector<uint8_t>* configData) = 0;
virtual int32_t Initialize(std::shared_ptr<IAdapterLog> const& log) = 0;
virtual int32_t Shutdown() = 0;
virtual AdapterStatus Initialize(std::shared_ptr<IAdapterLog> const& log) = 0;
virtual AdapterStatus Shutdown() = 0;
virtual int32_t EnumDevices(
virtual AdapterStatus EnumDevices(
EnumDeviceOptions opts,
AdapterDeviceVector& deviceList,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t GetProperty(
virtual AdapterStatus GetProperty(
std::shared_ptr<IAdapterProperty>& prop,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t SetProperty(
virtual AdapterStatus SetProperty(
std::shared_ptr<IAdapterProperty> const& prop,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t GetPropertyValue(
virtual AdapterStatus GetPropertyValue(
std::shared_ptr<IAdapterProperty> const& prop,
std::string const& attributeName,
std::shared_ptr<IAdapterValue>& value,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t SetPropertyValue(
virtual AdapterStatus SetPropertyValue(
std::shared_ptr<IAdapterProperty> const& prop,
std::shared_ptr<IAdapterValue> const& value,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t CallMethod(
virtual AdapterStatus CallMethod(
std::shared_ptr<IAdapterMethod>& method,
std::shared_ptr<IAdapterIoRequest>* req) = 0;
virtual int32_t RegisterSignalListener(
virtual AdapterStatus RegisterSignalListener(
std::string const& signalName,
std::shared_ptr<IAdapterSignalListener> const& listener,
void* argp,
RegistrationHandle& handle) = 0;
virtual int32_t UnregisterSignalListener(RegistrationHandle const& h) = 0;
virtual AdapterStatus UnregisterSignalListener(RegistrationHandle const& h) = 0;
};
......@@ -282,5 +291,72 @@ namespace bridge
std::string m_name;
common::Variant m_data;
};
class AdapterIoRequest : public IAdapterIoRequest
{
public:
AdapterIoRequest()
: m_status(0)
, m_canceled(false)
, m_completed(false)
{
}
virtual ~AdapterIoRequest()
{
}
virtual int32_t GetStatus()
{ return m_status; }
virtual int32_t Wait(uint32_t millis = std::numeric_limits<uint32_t>::max())
{
if (millis != std::numeric_limits<uint32_t>::max())
{
auto delay = std::chrono::system_clock::now() + std::chrono::milliseconds(millis);
std::unique_lock<std::mutex> lk(m_mutex);
if (m_cond.wait_until(lk, delay, [this] { return this->m_canceled || this->m_completed; }))
return 0;
else
return -1; // timedout
}
else
{
std::unique_lock<std::mutex> lk(m_mutex);
m_cond.wait(lk, [this] { return this->m_canceled || this->m_completed; });
}
return 0;
}
virtual int32_t Cancel()
{
std::unique_lock<std::mutex> lk(m_mutex);
m_canceled = true;
m_completed = true;
lk.unlock();
m_cond.notify_all();
return 0;
}
void SetComplete(int32_t status)
{
std::unique_lock<std::mutex> lk(m_mutex);
m_status = status;
m_canceled = false;
m_completed = true;
lk.unlock();
m_cond.notify_all();
}
private:
int32_t m_status;
bool m_canceled;
bool m_completed;
std::mutex m_mutex;
std::condition_variable m_cond;
};
}
......@@ -2,6 +2,3 @@
#include <assert.h>
#define DSB_ASSERT(X) assert((X))
class AllJoynBusObject;
#pragma once
#include "Common/Assert.h"
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include "defines.h"
namespace common
{
......
#pragma once
#include "Common/defines.h"
#include "DeviceProviders/AllJoynStatus.h"
#include <alljoyn/AboutListener.h>
......
#pragma once
#include "Common/defines.h"
#include <alljoyn/BusAttachment.h>
#include <alljoyn/ProxyBusObject.h>
#include <alljoyn/SessionListener.h>
......
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