Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
portabledsb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
External Wiki
External Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
App_Technologies
portabledsb
Commits
b2e696fd
Commit
b2e696fd
authored
Dec 19, 2015
by
Jacob Gladish
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1 from brendanlong/master
ConfigManager, Bridge, and Makefile improvements
parents
a7989893
8b338732
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
178 additions
and
68 deletions
+178
-68
Bridge/Bridge.cpp
Bridge/Bridge.cpp
+33
-9
Bridge/Bridge.h
Bridge/Bridge.h
+2
-0
Bridge/ConfigManager.cpp
Bridge/ConfigManager.cpp
+119
-28
Bridge/ConfigManager.h
Bridge/ConfigManager.h
+20
-27
Makefile
Makefile
+2
-3
main.cpp
main.cpp
+2
-1
No files found.
Bridge/Bridge.cpp
View file @
b2e696fd
...
...
@@ -10,7 +10,7 @@ namespace
int32_t
const
kWaitTimeoutForAdapterOperation
=
20000
;
//ms
std
::
string
const
kDeviceArrivalSignal
=
"Device_Arrival"
;
std
::
string
const
kDeviceArri
ave
DeviceHandle
=
"Device_Handle"
;
std
::
string
const
kDeviceArri
val
DeviceHandle
=
"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
)
{
...
...
Bridge/Bridge.h
View file @
b2e696fd
...
...
@@ -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
;
};
}
Bridge/ConfigManager.cpp
View file @
b2e696fd
#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
}
Bridge/ConfigManager.h
View file @
b2e696fd
...
...
@@ -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
;
};
};
Makefile
View file @
b2e696fd
...
...
@@ -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
...
...
main.cpp
View file @
b2e696fd
...
...
@@ -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
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment