Commit b2e696fd authored by Jacob Gladish's avatar Jacob Gladish

Merge pull request #1 from brendanlong/master

ConfigManager, Bridge, and Makefile improvements
parents a7989893 8b338732
......@@ -10,7 +10,7 @@ namespace
int32_t const kWaitTimeoutForAdapterOperation = 20000; //ms
std::string const kDeviceArrivalSignal = "Device_Arrival";
std::string const kDeviceArriaveDeviceHandle = "Device_Handle";
std::string const kDeviceArrivalDeviceHandle = "Device_Handle";
std::string const kDeviceRemovalSignal = "Device_Removal";
std::string const kDeviceRemovalDeviceHandle = "Device_Handle";
......@@ -24,6 +24,7 @@ bridge::DeviceSystemBridge::DeviceSystemBridge(shared_ptr<IAdapter> const& adapt
: m_alljoynInitialized(false)
, m_adapter(adapter)
, m_adapterSignalListener(new AdapterSignalListener(*this))
, m_configManager(*this, *adapter)
{
}
......@@ -48,6 +49,7 @@ bridge::DeviceSystemBridge::Initialize()
DSBLOG_WARN("Failed to initialize AllJoyn: 0x%x", st);
goto Leave;
}
m_alljoynInitialized = true;
}
st = InitializeInternal();
......@@ -68,7 +70,7 @@ bridge::DeviceSystemBridge::InitializeInternal()
{
QStatus st = ER_OK;
// st = m_configManager.Initialize(this);
st = m_configManager.Initialize();
if (st != ER_OK)
goto Leave;
......@@ -79,6 +81,12 @@ bridge::DeviceSystemBridge::InitializeInternal()
goto Leave;
}
st = m_configManager.ConnectToAllJoyn();
if (st != ER_OK)
{
goto Leave;
}
st = InitializeDevices();
if (st != ER_OK)
{
......@@ -145,17 +153,30 @@ bridge::DeviceSystemBridge::InitializeDevices(bool update)
if (ret != 0)
goto Leave;
if (request)
{
ret = request->Wait(kWaitTimeoutForAdapterOperation);
if (ret != 0)
{
goto Leave;
}
}
typedef AdapterDeviceVector::iterator iterator;
for (iterator begin = deviceList.begin(), end = deviceList.end(); begin != end; ++begin)
{
// TODO: get configuration for device
// TODO: get configuration for device, only expose visible devices
if (update)
UpdateDevice(*begin, true);
ret = UpdateDevice(*begin, true);
else
ret = CreateDevice(*begin);
// unfinished
if (ret != 0)
DSBLOG_WARN("Failed to %s device: %d", update ? "update" : "create", ret);
}
// TODO: Save bridge configuration to XML
Leave:
return ret == 0 ? ER_OK : ER_FAIL;
}
......@@ -167,12 +188,14 @@ bridge::DeviceSystemBridge::OnAdapterSignal(IAdapterSignal const& signal, void*)
shared_ptr<IAdapterDevice> adapterDevice;
std::string const name = signal.GetName();
if (name == kDeviceArrivalSignal || name ==kDeviceArriaveDeviceHandle)
if (name == kDeviceArrivalSignal || name == kDeviceRemovalSignal)
{
AdapterValueVector params = signal.GetParams();
for (AdapterValueVector::const_iterator itr = params.begin(); itr != params.end(); ++itr)
{
if ((*itr)->GetName() == kDeviceArriaveDeviceHandle)
const shared_ptr<IAdapterValue>& param = (*itr);
const std::string& paramName = param->GetName();
if (paramName == kDeviceArrivalDeviceHandle || paramName == kDeviceRemovalDeviceHandle)
{
// TODO: figure out where this signal is generated and figure out how we're
// going to put an arbitrary pointer inside.
......@@ -187,6 +210,7 @@ bridge::DeviceSystemBridge::OnAdapterSignal(IAdapterSignal const& signal, void*)
if (name == kDeviceArrivalSignal)
{
CreateDevice(adapterDevice);
}
else if (name == kDeviceRemovalSignal)
{
......@@ -242,7 +266,7 @@ bridge::DeviceSystemBridge::RegisterAdapterSignalHandlers(bool isRegister)
QStatus
bridge::DeviceSystemBridge::ShutdownInternal()
{
// m_configManager.Shutdown();
m_configManager.Shutdown();
if (m_adapter)
{
......
......@@ -2,6 +2,7 @@
#include "Common/defines.h"
#include "Bridge/IAdapter.h"
#include "Bridge/ConfigManager.h"
#include <alljoyn/Status.h>
......@@ -85,6 +86,7 @@ namespace bridge
BridgeDeviceList m_deviceList;
shared_ptr<AdapterSignalListener> m_adapterSignalListener;
std::vector<IAdapter::RegistrationHandle> m_registeredSignalListeners;
ConfigManager m_configManager;
};
}
#include "Bridge/ConfigManager.h"
#include "Bridge/IAdapter.h"
#include "Common/Log.h"
using namespace bridge;
namespace
{
DSB_DECLARE_LOGNAME(ConfigManager);
// TODO: make this configurable;
std::string const kBridgeConfigFile = "BridgeConfig.xml";
int const kMaxConnectionAttempts = 60;
int const kReconnectDelay = 500;
int const kReconnectDelay = 500;
int const kDSBServicePort = 1000;
uint32_t const kSessionLinkTimeout = 30; // seconds
}
ConfigManager::ConfigManager()
: m_busAttachment(NULL)
ConfigManager::ConfigManager(DeviceSystemBridge& bridge, IAdapter& adapter)
: m_parent(bridge)
, m_adapter(adapter)
, m_sessionPort(kDSBServicePort)
{
}
......@@ -21,50 +28,134 @@ ConfigManager::~ConfigManager()
Shutdown();
}
int32_t
ConfigManager::Initialize(shared_ptr<DeviceSystemBridge> const& bridge)
QStatus
ConfigManager::Initialize()
{
m_parent = bridge;
m_bridgeConfig.FromFile(kBridgeConfigFile);
return 0;
return m_bridgeConfig.FromFile(kBridgeConfigFile);
}
int32_t
QStatus
ConfigManager::Shutdown()
{
ShutdownAllJoyn();
m_adapter.reset();
m_parent.reset();
return 0;
QStatus st = ShutdownAllJoyn();
return st;
}
int32_t
QStatus
ConfigManager::ShutdownAllJoyn()
{
return 0;
}
if (!m_busAttachment.get())
return ER_OK;
int32_t
ConfigManager::ConnectToAllJoyn(shared_ptr<IAdapter> const& adapter)
{
m_adapter = adapter;
if (!m_serviceName.empty())
{
m_busAttachment->CancelAdvertiseName(m_serviceName.c_str(), ajn::TRANSPORT_ANY);
}
m_busAttachment->UnbindSessionPort(m_sessionPort);
int ret = BuildServiceName();
if (ret != 0)
if (!m_serviceName.empty())
{
return -1;
m_busAttachment->ReleaseName(m_serviceName.c_str());
}
m_busAttachment->Disconnect();
// TODO: Destroy CSP interfaces
// TODO: remove authentication handler
// TODO: Shutdown About
m_busAttachment->Stop();
m_busAttachment->UnregisterBusListener(*this);
m_busAttachment->Join();
m_busAttachment.reset();
m_busAttachment.reset(new ajn::BusAttachment(m_adapter->GetExposedApplicationName().c_str(), true));
m_busAttachment->RegisterBusListener(m_busListener);
return ER_OK;
}
QStatus
ConfigManager::ConnectToAllJoyn()
{
QStatus st = BuildServiceName();
if (st != ER_OK)
return st;
m_busAttachment.reset(new ajn::BusAttachment(m_adapter.GetExposedApplicationName().c_str(), true));
m_busAttachment->RegisterBusListener(*this);
m_busAttachment->Start();
return 0;
// TODO: AllJoyn about object
// TODO: Initialize CSP bus objects
st = m_busAttachment->Connect();
if (st != ER_OK)
{
DSBLOG_WARN("Failed to connect to AllJoyn bus: %d", st);
return st;
}
st = m_busAttachment->RequestName(m_serviceName.c_str(), DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE);
if (st != ER_OK)
{
DSBLOG_WARN("Failed to get name %s on AllJoyn bus: %d", m_serviceName.c_str(), st);
return st;
}
ajn::SessionOpts sessionOpts(ajn::SessionOpts::TRAFFIC_MESSAGES, true, ajn::SessionOpts::PROXIMITY_ANY, ajn::TRANSPORT_ANY);
st = m_busAttachment->BindSessionPort(m_sessionPort, sessionOpts, *this);
if (!st)
{
DSBLOG_WARN("Failed to bind session port: %d", st);
return st;
}
st = m_busAttachment->AdvertiseName(m_serviceName.c_str(), sessionOpts.transports);
if (!st)
{
DSBLOG_WARN("Failed to advertise service name: %d", st);
return st;
}
// TODO: Announce
return ER_OK;
}
int32_t
QStatus
ConfigManager::BuildServiceName()
{
return 0;
return ER_NOT_IMPLEMENTED;
}
bool
ConfigManager::AcceptSessionJoiner(ajn::SessionPort port, const char *joiner, const ajn::SessionOpts&)
{
return port == m_sessionPort;
}
void
ConfigManager::SessionJoined(ajn::SessionPort port, ajn::SessionId id, const char *joiner)
{
m_busAttachment->EnableConcurrentCallbacks();
QStatus st = m_busAttachment->SetSessionListener(id, this);
if (st != ER_OK)
{
DSBLOG_WARN("Failed to set session listener: %d", st);
return;
}
uint32_t timeout = kSessionLinkTimeout;
st = m_busAttachment->SetLinkTimeout(id, timeout);
if (st != ER_OK)
{
DSBLOG_WARN("Failed to set session link timeout to %" PRIu32 ": %d", timeout, st);
return;
}
}
void
ConfigManager::SessionMemberRemoved(ajn::SessionId, const char *uniqueName)
{
// TODO: Reset auth access
// TODO: End CSP file transfer
}
......@@ -13,51 +13,44 @@ namespace bridge
class IAdapter;
class DeviceSystemBridge;
class ConfigManager
class ConfigManager : private ajn::BusListener, private ajn::SessionListener, private ajn::SessionPortListener
{
public:
ConfigManager();
ConfigManager(DeviceSystemBridge&, IAdapter&);
~ConfigManager();
int32_t Initialize(shared_ptr<DeviceSystemBridge> const& bridge);
int32_t ConnectToAllJoyn(shared_ptr<IAdapter> const& adapter);
int32_t Shutdown();
QStatus Initialize();
QStatus ConnectToAllJoyn();
QStatus Shutdown();
bool IsConfigurationAccessSecured();
bool IsDeviceAccessSecured();
bool GetObjectConfigItem(shared_ptr<IAdapter> const& adapter);
bool GetObjectConfigItem();
void ToFile();
shared_ptr<BridgeConfig> GetBridgeConfig();
private:
int32_t ShutdownAllJoyn();
int32_t InitializeCSPBusObjects();
int32_t BuildServiceName();
QStatus ShutdownAllJoyn();
QStatus InitializeCSPBusObjects();
QStatus BuildServiceName();
class BusListener : public ajn::BusListener
{
};
/* ajn::SessionPortListener */
virtual bool AcceptSessionJoiner(ajn::SessionPort, const char *joiner, const ajn::SessionOpts&);
virtual void SessionJoined(ajn::SessionPort, ajn::SessionId, const char *joiner);
class SessionListener : public ajn::SessionListener
{
};
class SessionPortListener : public ajn::SessionPortListener
{
};
/* ajn::SessionListener */
virtual void SessionMemberRemoved(ajn::SessionId, const char *uniqueName);
private:
shared_ptr<DeviceSystemBridge> m_parent;
shared_ptr<IAdapter> m_adapter;
std::auto_ptr<ajn::BusAttachment> m_busAttachment;
BusListener m_busListener;
SessionListener m_sessionListener;
SessionPortListener m_sessionPortListener;
std::string m_serviceName;
DeviceSystemBridge& m_parent;
IAdapter& m_adapter;
shared_ptr<ajn::BusAttachment> m_busAttachment;
std::string m_serviceName;
// BridgeAuthHandler
BridgeConfig m_bridgeConfig;
BridgeConfig m_bridgeConfig;
ajn::SessionPort m_sessionPort;
};
};
......@@ -18,10 +18,9 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \
Adapters/ZigBeeAdapter/ZigBeeAdapter.cpp \
main.cpp
LIBXML_INC=/usr/include/libxml2
LIBXML_INC?=/usr/include/libxml2
ALLJOYN_INSTALL_DIR=/Users/jgladi200/Work/alljoyn/alljoyn-15.09.00a-src/build/darwin/x86/debug/dist/cpp
#ALLJOYN_INSTALL_DIR=/home/gladish/work/alljoyn-15.09.00-src/build/linux/x86_64/debug/dist/cpp/
ALLJOYN_INSTALL_DIR?=/Users/jgladi200/Work/alljoyn/alljoyn-15.09.00a-src/build/darwin/x86/debug/dist/cpp
CXXFLAGS=-D QCC_OS_GROUP_POSIX -Wall -Wextra -Wno-missing-field-initializers -Wno-deprecated-declarations -g -std=c++0x -I. -I$(ALLJOYN_INSTALL_DIR)/inc -I$(LIBXML_INC)
CXXFLAGS+=-Wno-ignored-qualifiers
......
......@@ -66,7 +66,7 @@ int main(int /*argc*/, char* /*argv*/ [])
if (ret != 0)
{
std::cout << "EnumDevices:" << ret << std::endl;
exit(0);
return 1;
}
for (auto const& d : deviceList)
......@@ -77,6 +77,7 @@ int main(int /*argc*/, char* /*argv*/ [])
std::cout << std::endl;
}
getchar();
return 0;
}
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