Commit baf22b2b authored by jacobgladish's avatar jacobgladish

Added first cut of invoking method.

parent ad6ea733
......@@ -51,6 +51,20 @@ namespace
QCC_RegisterOutputCallback(alljoynLogger, NULL);
}
}
shared_ptr<bridge::DeviceSystemBridge> gBridge;
}
shared_ptr<bridge::DeviceSystemBridge>
bridge::DeviceSystemBridge::GetInstance()
{
return gBridge;
}
void
bridge::DeviceSystemBridge::InitializeSingleton(shared_ptr<IAdapter> const& adapter)
{
gBridge.reset(new DeviceSystemBridge(adapter));
}
bridge::DeviceSystemBridge::DeviceSystemBridge(shared_ptr<IAdapter> const& adapter)
......
......@@ -19,10 +19,8 @@ namespace bridge
class DeviceSystemBridge : public enable_shared_from_this<DeviceSystemBridge>
{
public:
static DeviceSystemBridge& Instance();
// TODO: really should be scoped_ptr as onwership is transferred
DeviceSystemBridge(shared_ptr<IAdapter> const& adapter);
static shared_ptr<DeviceSystemBridge> GetInstance();
static void InitializeSingleton(shared_ptr<IAdapter> const& adapter);
virtual ~DeviceSystemBridge();
......@@ -41,6 +39,8 @@ namespace bridge
{ return m_deviceList; }
private:
DeviceSystemBridge(shared_ptr<IAdapter> const& adapter);
QStatus RegisterAdapterSignalHandlers(bool isRegister);
QStatus InitializeAdapter();
QStatus InitializeInternal();
......
#include "DeviceMethod.h"
#include "Common/Log.h"
#include "Bridge/AllJoynHelper.h"
#include "Bridge/Bridge.h"
namespace
{
......@@ -17,14 +19,89 @@ bridge::DeviceMethod::~DeviceMethod()
}
uint32_t
bridge::DeviceMethod::InvokeMethod(ajn::Message const&, ajn::MsgArg*, size_t)
bridge::DeviceMethod::InvokeMethod(ajn::Message& msg, ajn::MsgArg* outArgs, size_t* numOutArgs)
{
return 0;
int i = 0;
uint32_t adapterStatus = 0;
QStatus status = ER_OK;
shared_ptr<IAdapterIoRequest> request;
if (outArgs)
*outArgs = nullptr;
if (numOutArgs)
*numOutArgs = 0;
if (!m_adapterMethod->GetOutputParams().empty())
{
if (outArgs == nullptr)
adapterStatus = 1;
if (numOutArgs == nullptr)
adapterStatus = 2;
// TODO: I don't like all these goto's. Why not just use exception handling?
if (adapterStatus != 0)
goto leave;
// TODO: make sure this gets deleted [] by caller. Should we just use vector with
// shared_ptr<>?
outArgs = new ajn::MsgArg[m_adapterMethod->GetOutputParams().size()];
*numOutArgs = m_adapterMethod->GetOutputParams().size();
}
for (shared_ptr<IAdapterValue> const& param : m_adapterMethod->GetInputParams())
{
ajn::MsgArg const* inArg = msg->GetArg(i++);
if (inArg == nullptr)
{
adapterStatus = 1;
goto leave;
}
// TODO: this seems odd. The GetAdapterValue() populates the param argument with the
// data from the inArg. Why wouldn't we create a temporary based on the incoming
// ajn::Message? We need the description or prototype to do some validation. I would
// think the m_adapterMethod would be const. I guess DeviceMethod (this class) can
// only be used once and then must be discarded, or only used by one thread to
// completion at any given time
status = AllJoynHelper::GetAdapterValue(*param, *inArg);
if (status != ER_OK)
{
adapterStatus = 1;
goto leave;
}
}
// TODO: we're ingoring the return value here
bridge::DeviceSystemBridge::GetInstance()->GetAdapter()
->CallMethod(m_adapterMethod, &request);
// TODO: timeout should be configurable or passed in by caller
if (request)
request->Wait(2000);
i = 0;
for (shared_ptr<IAdapterValue> const& param : m_adapterMethod->GetOutputParams())
{
status = AllJoynHelper::SetMsgArg(*param, outArgs[i]);
// TODO: check status
}
leave:
if (adapterStatus != 0)
{
delete [] outArgs;
if (numOutArgs)
*numOutArgs = 0;
}
return adapterStatus;
}
QStatus
bridge::DeviceMethod::Initialize(shared_ptr<IAdapterMethod> const&)
{
DSBLOG_NOT_IMPLEMENTED();
return ER_NOT_IMPLEMENTED;
}
......
......@@ -18,7 +18,10 @@ namespace bridge
virtual ~DeviceMethod();
QStatus Initialize(shared_ptr<IAdapterMethod> const& adapterMethod);
uint32_t InvokeMethod(ajn::Message const& msg, ajn::MsgArg* outArgs, size_t numOutArgs);
// TODO: error code?
// TODO: should that first arg be constant?
uint32_t InvokeMethod(ajn::Message& msg, ajn::MsgArg* outArgs, size_t* numOutArgs);
inline std::string const& GetName() const
{ return m_exposedName; }
......@@ -28,11 +31,12 @@ namespace bridge
QStatus BuildSignature(AdapterValueVector const& valueList, std::string& sig, std::string& parameterNames);
private:
DeviceMain& m_parent;
std::string m_exposedName;
std::string m_inSignature;
std::string m_outSignature;
std::string m_parameterNames;
DeviceMain& m_parent;
std::string m_exposedName;
std::string m_inSignature;
std::string m_outSignature;
std::string m_parameterNames;
shared_ptr<IAdapterMethod> m_adapterMethod;
};
}
......
<?xml version="1.0" encoding="utf-8"?>
<BridgeConfig>
<Settings>
<Bridge>
<KEYX></KEYX>
</Bridge>
<Device>
<DefaultVisibility>true</DefaultVisibility>
<KEYX></KEYX>
<USERNAME></USERNAME>
<PASSWORD></PASSWORD>
<ECDHEECDSAPRIVATEKEY></ECDHEECDSAPRIVATEKEY>
<ECDHEECDSACERTCHAIN></ECDHEECDSACERTCHAIN>
</Device>
</Settings>
<AdapterDevices>
</AdapterDevices>
</BridgeConfig>
......@@ -10,6 +10,13 @@
namespace
{
DSB_DECLARE_LOGNAME(Main);
inline shared_ptr<bridge::DeviceSystemBridge> DSB()
{
shared_ptr<bridge::DeviceSystemBridge> b = bridge::DeviceSystemBridge::GetInstance();
assert(b.get() != nullptr);
return b;
}
}
int main(int /*argc*/, char* /*argv*/ [])
......@@ -46,17 +53,17 @@ int main(int /*argc*/, char* /*argv*/ [])
QStatus st = ER_OK;
shared_ptr<bridge::DeviceSystemBridge> bridge(new bridge::DeviceSystemBridge(
shared_ptr<bridge::IAdapter>(new adapters::mock::MockAdapter())));
bridge::DeviceSystemBridge::InitializeSingleton(
shared_ptr<bridge::IAdapter>(new adapters::mock::MockAdapter()));
st = bridge->Initialize();
st = DSB()->Initialize();
if (st != ER_OK)
{
DSBLOG_ERROR("failed to initialize bridge: %s", QCC_StatusText(st));
return 1;
}
shared_ptr<bridge::IAdapter> adapter = bridge->GetAdapter();
shared_ptr<bridge::IAdapter> adapter = DSB()->GetAdapter();
bridge::AdapterDeviceVector deviceList;
shared_ptr<bridge::IAdapterIoRequest> req;
......
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