Commit b74fa4c7 authored by gladish's avatar gladish
Browse files

More work in Bridge/Config.

parent a11b0011
#include "AllJoynAbout.h"
#include "Common/Log.h"
namespace
{
Common::Guid const kDefaultAppGuid = Common::Guid::FromString("DA9C7763-C3E0-4B3B-B190-5BEF8DF96E4D");
char const* kDefaultLanguageForAbout = "en";
char const* kUnknownAdapter = "Unknown Device";
char const* kUnknownManufacturer = "Unknown";
char const* kUknownVersion = "0.0.0.0";
char const* kDefaultAppName = "Device System Bridge";
char const* kDefaultModel = "DSB";
char const* kDefaultDescription = "Device System Bridge";
int const kDsbServicePort = 27;
DSB_DECLARE_LOGNAME(AllJoynAbout);
}
using namespace Bridge;
AllJoynAbout::AllJoynAbout()
: m_isAnnounced(false)
{
}
AllJoynAbout::~AllJoynAbout()
{
Shutdown();
}
QStatus AllJoynAbout::Initialize(ajn::BusAttachment& bus)
{
m_aboutObj.reset(new ajn::AboutObj(bus, ajn::BusObject::UNANNOUNCED));
m_aboutData.reset(new ajn::AboutData(kDefaultLanguageForAbout));
return SetDefaultAboutData();
}
QStatus AllJoynAbout::Shutdown()
{
if (m_isAnnounced)
{
m_aboutObj->Unannounce();
m_isAnnounced = false;
}
if (m_aboutObj)
m_aboutObj.reset();
if (m_aboutData)
m_aboutData.reset();
return ER_OK;
}
QStatus AllJoynAbout::SetDefaultAboutData()
{
std::string deviceId;
std::string deviceName;
GetDeviceId(deviceId);
m_aboutData->SetDeviceId(deviceName.c_str());
SetDeviceName(kUnknownAdapter);
SetApplicationName(kDefaultAppName);
SetApplicationGuid(kDefaultAppGuid);
SetManufacturer(kUnknownManufacturer);
SetModel(kDefaultModel);
SetVersion(kUknownVersion);
SetDescription(kDefaultDescription);
if (!m_aboutData->IsValid(kDefaultLanguageForAbout))
{
DSBLOG_WARN("AboutData is invalid");
}
return ER_OK;
}
QStatus AllJoynAbout::GetDeviceId(std::string& deviceId)
{
deviceId.clear();
std::string tempId;
QStatus st = ER_OK;
if ((st = ReadDeviceId(tempId)) == ER_OK)
st = CreateAndSaveDeviceId(tempId);
if (st == ER_OK)
deviceId = tempId;
return st;
}
QStatus AllJoynAbout::ReadDeviceId(std::string& deviceId)
{
// TODO read from config
return ER_FAIL;
}
QStatus AllJoynAbout::CreateAndSaveDeviceId(std::string& deviceId)
{
Common::Guid guid = Common::Guid::Create();
deviceId = guid.ToString();
// TODO: need to persist this configuration
return ER_OK;
}
QStatus AllJoynAbout::SetManufacturer(char const* s)
{
return m_aboutData
? m_aboutData->SetManufacturer(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetDeviceName(char const* s)
{
return m_aboutData
? m_aboutData->SetDeviceName(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetVersion(char const* s)
{
return m_aboutData
? m_aboutData->SetSoftwareVersion(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetApplicationName(char const* s)
{
return m_aboutData
? m_aboutData->SetAppName(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetApplicationGuid(Common::Guid const& guid)
{
return m_aboutData
? m_aboutData->SetAppId(guid.ToString().c_str())
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetDeviceId(char const* s)
{
return m_aboutData
? m_aboutData->SetDeviceId(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetModel(char const* s)
{
return m_aboutData
? m_aboutData->SetModelNumber(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::SetDescription(char const* s)
{
return m_aboutData
? m_aboutData->SetDescription(s)
: ER_INVALID_ADDRESS;
}
QStatus AllJoynAbout::AddObject(ajn::BusObject& obj, ajn::InterfaceDescription const* ifc)
{
return obj.SetAnnounceFlag(ifc, ajn::BusObject::ANNOUNCED);
}
QStatus AllJoynAbout::RemoveObject(ajn::BusObject& obj, ajn::InterfaceDescription const* ifc)
{
return obj.SetAnnounceFlag(ifc, ajn::BusObject::UNANNOUNCED);
}
QStatus AllJoynAbout::Announce()
{
QStatus st = ER_INIT_FAILED;
if (m_aboutObj)
st = m_aboutObj->Announce(kDsbServicePort, *m_aboutData);
if (st == ER_OK)
m_isAnnounced = true;
return st;
}
#pragma once
#include "Common/defines.h"
#include "Common/Guid.h"
#include <alljoyn/AboutData.h>
#include <alljoyn/AboutObj.h>
#include <alljoyn/BusAttachment.h>
#include <alljoyn/InterfaceDescription.h>
#include <alljoyn/Status.h>
namespace Bridge
{
class AllJoynAbout
{
public:
AllJoynAbout();
~AllJoynAbout();
QStatus Initialize(ajn::BusAttachment& bus);
QStatus Shutdown();
QStatus Announce();
QStatus AddObject(ajn::BusObject& obj, ajn::InterfaceDescription const* ifc);
QStatus RemoveObject(ajn::BusObject& obj, ajn::InterfaceDescription const* ifc);
// TODO: are these really needed?
QStatus SetManufacturer(char const* s);
QStatus SetDeviceName(char const* s);
QStatus SetVersion(char const* s);
QStatus SetApplicationName(char const* s);
QStatus SetApplicationGuid(Common::Guid const& guid);
QStatus SetDeviceId(char const* s);
QStatus SetModel(char const* s);
QStatus SetDescription(char const* s);
private:
QStatus SetDefaultAboutData();
QStatus GetDeviceId(std::string& deviceId);
QStatus CreateAndSaveDeviceId(std::string& deviecId);
QStatus ReadDeviceId(std::string& deviceId);
private:
// unique_ptr
shared_ptr<ajn::AboutData> m_aboutData;
shared_ptr<ajn::AboutObj> m_aboutObj;
bool m_isAnnounced;
};
}
#include "Bridge/ConfigManager.h"
#include "Bridge/IAdapter.h"
using namespace Bridge;
namespace
{
// TODO: make this configurable;
std::string const kBridgeConfigFile = "BridgeConfig.xml";
int const kMaxConnectionAttempts = 60;
int const kReconnectDelay = 500;
}
ConfigManager::ConfigManager()
: m_busAttachment(NULL)
{
}
ConfigManager::~ConfigManager()
{
Shutdown();
}
int32_t ConfigManager::Initialize(shared_ptr<DeviceSystemBridge> const& bridge)
{
m_parent = bridge;
m_bridgeConfig.FromFile(kBridgeConfigFile);
return 0;
}
int32_t ConfigManager::Shutdown()
{
ShutdownAllJoyn();
m_adapter.reset();
m_parent.reset();
return 0;
}
int32_t ConfigManager::ShutdownAllJoyn()
{
return 0;
}
int32_t ConfigManager::ConnectToAllJoyn(shared_ptr<IAdapter> const& adapter)
{
m_adapter = adapter;
int ret = BuildServiceName();
if (ret != 0)
{
return -1;
}
m_busAttachment.reset();
m_busAttachment.reset(new ajn::BusAttachment(m_adapter->GetExposedApplicationName().c_str(), true));
m_busAttachment->RegisterBusListener(m_busListener);
m_busAttachment->Start();
return 0;
}
int32_t ConfigManager::BuildServiceName()
{
return 0;
}
#pragma once
#include "Common/defines.h"
#include "Bridge/BridgeConfig.h"
#include <alljoyn/BusAttachment.h>
#include <alljoyn/BusListener.h>
#include <alljoyn/SessionListener.h>
#include <alljoyn/SessionPortListener.h>
namespace Bridge
{
class IAdapter;
class DeviceSystemBridge;
class ConfigManager
{
public:
ConfigManager();
~ConfigManager();
int32_t Initialize(shared_ptr<DeviceSystemBridge> const& bridge);
int32_t ConnectToAllJoyn(shared_ptr<IAdapter> const& adapter);
int32_t Shutdown();
bool IsConfigurationAccessSecured();
bool IsDeviceAccessSecured();
bool GetObjectConfigItem(shared_ptr<IAdapter> const& adapter);
void ToFile();
shared_ptr<BridgeConfig> GetBridgeConfig();
private:
int32_t ShutdownAllJoyn();
int32_t InitializeCSPBusObjects();
int32_t BuildServiceName();
class BusListener : public ajn::BusListener
{
};
class SessionListener : public ajn::SessionListener
{
};
class SessionPortListener : public ajn::SessionPortListener
{
};
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;
// BridgeAuthHandler
BridgeConfig m_bridgeConfig;
};
};
......@@ -16,6 +16,10 @@ namespace Bridge
std::string const kCovPropertyHandle = "Property_Handle";
std::string const kCovAttributeHandle = "Attribute_Handle";
std::string const kDsbDeviceNotificationSignal = "DeviceNotificationSignal";
std::string const kDsbSendMsgToDeviceMethod = "SendMessageToDeviceSynchronous";
class IAdapterValue;
class IAdapterProperty;
class IAdapterMethod;
......
#pragma once
#include <string>
#include <uuid/uuid.h>
namespace Common
{
class Guid
{
public:
static Guid Create()
{
uuid_t uuid;
uuid_generate_random(uuid);
uuid_string_t s;
uuid_unparse(uuid, s);
return Guid(std::string(s));
}
static Guid FromString(char const* s)
{
return Guid(s);
}
std::string ToString() const
{ return m_uuid; }
private:
Guid(std::string const& uuid) : m_uuid(uuid) { }
private:
std::string m_uuid;
};
}
SRCS=DeviceProviders/AllJoynProvider.cpp \
DeviceProviders/AllJoynService.cpp \
Bridge/AllJoynAbout.cpp \
Bridge/Bridge.cpp \
Bridge/BridgeConfig.cpp \
Bridge/BridgeDevice.cpp \
Bridge/ConfigManager.cpp \
Common/Log.cpp \
Adapters/MockAdapter/MockAdapter.cpp \
Adapters/MockAdapter/MockDevices.cpp \
......
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