Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
App_Technologies
portabledsb
Commits
505133a1
Commit
505133a1
authored
Jan 10, 2016
by
jacobgladish
Browse files
Added logger for Adapters.
parent
baf22b2b
Changes
9
Hide whitespace changes
Inline
Side-by-side
Adapters/MockAdapter/MockAdapter.cpp
View file @
505133a1
...
...
@@ -75,10 +75,11 @@ bridge::AdapterSignalVector adapters::mock::MockAdapter::GetSignals()
int32_t
adapters
::
mock
::
MockAdapter
::
Initialize
()
adapters
::
mock
::
MockAdapter
::
Initialize
(
shared_ptr
<
bridge
::
IAdapterLog
>
const
&
log
)
{
CreateMockDevices
();
CreateSignals
();
m_log
=
log
;
return
ER_OK
;
}
...
...
Adapters/MockAdapter/MockAdapter.h
View file @
505133a1
...
...
@@ -26,7 +26,7 @@ namespace mock
virtual
common
::
Guid
GetExposedApplicationGuid
();
virtual
bridge
::
AdapterSignalVector
GetSignals
();
virtual
int32_t
Initialize
();
virtual
int32_t
Initialize
(
shared_ptr
<
bridge
::
IAdapterLog
>
const
&
log
);
virtual
int32_t
Shutdown
();
virtual
int32_t
GetConfiguration
(
std
::
vector
<
uint8_t
>*
/*configData*/
)
...
...
@@ -84,6 +84,7 @@ namespace mock
std
::
string
m_exposedAdapterPrefix
;
std
::
string
m_exposedApplicationName
;
common
::
Guid
m_exposedApplicationGuid
;
shared_ptr
<
bridge
::
IAdapterLog
>
m_log
;
std
::
vector
<
shared_ptr
<
MockAdapterDevice
>
>
m_devices
;
std
::
vector
<
shared_ptr
<
MockAdapterSignal
>
>
m_signals
;
...
...
Bridge/Bridge.cpp
View file @
505133a1
#include "Bridge.h"
#include "Common/Log.h"
#include "Bridge/BridgeDevice.h"
#include "Bridge/Log.h"
#include <qcc/Debug.h>
#include <alljoyn/Init.h>
...
...
@@ -197,7 +199,9 @@ bridge::DeviceSystemBridge::InitializeAdapter()
DSBLOG_ERROR
(
"can't initialize null adapter"
);
return
ER_FAIL
;
}
int
ret
=
m_adapter
->
Initialize
();
shared_ptr
<
IAdapterLog
>
log
(
new
AdapterLog
(
"adapter"
));
int
ret
=
m_adapter
->
Initialize
(
log
);
return
ret
==
0
?
ER_OK
:
ER_FAIL
;
}
...
...
Bridge/IAdapter.h
View file @
505133a1
...
...
@@ -26,6 +26,7 @@ namespace bridge
class
IAdapterMethod
;
class
IAdapterSignal
;
class
IAdapterDevice
;
class
IAdapterLog
;
typedef
std
::
vector
<
shared_ptr
<
IAdapterValue
>
>
AdapterValueVector
;
typedef
std
::
vector
<
shared_ptr
<
IAdapterProperty
>
>
AdapterPropertyVector
;
...
...
@@ -49,6 +50,23 @@ namespace bridge
AlwaysWithNoValue
};
enum
class
AdapterLogLevel
{
Off
=
-
1
,
Debug
=
1
,
Info
=
2
,
Warn
=
3
,
Error
=
4
,
Fatal
=
5
};
class
IAdapterLog
{
public:
virtual
void
Write
(
AdapterLogLevel
level
,
char
const
*
file
,
int
line
,
char
const
*
format
,
...)
=
0
;
virtual
bool
IsLevelEnabled
(
AdapterLogLevel
level
)
=
0
;
};
class
IAdapterAttribute
{
public:
...
...
@@ -167,7 +185,7 @@ namespace bridge
virtual
int32_t
SetConfiguration
(
std
::
vector
<
uint8_t
>
const
&
configData
)
=
0
;
virtual
int32_t
GetConfiguration
(
std
::
vector
<
uint8_t
>*
configData
)
=
0
;
virtual
int32_t
Initialize
()
=
0
;
virtual
int32_t
Initialize
(
shared_ptr
<
IAdapterLog
>
const
&
log
)
=
0
;
virtual
int32_t
Shutdown
()
=
0
;
virtual
int32_t
EnumDevices
(
...
...
Bridge/Log.cpp
0 → 100644
View file @
505133a1
#include "Bridge/Log.h"
#include "Common/Log.h"
namespace
{
common
::
Logger
::
Level
toLogLevel
(
bridge
::
AdapterLogLevel
level
)
{
common
::
Logger
::
Level
l
=
common
::
Logger
::
DSB_LOGLEVEL_OFF
;
switch
(
level
)
{
case
bridge
::
AdapterLogLevel
::
Off
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_OFF
;
break
;
case
bridge
::
AdapterLogLevel
::
Debug
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_DEBUG
;
break
;
case
bridge
::
AdapterLogLevel
::
Info
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_INFO
;
break
;
case
bridge
::
AdapterLogLevel
::
Warn
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_WARN
;
break
;
case
bridge
::
AdapterLogLevel
::
Error
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_ERROR
;
break
;
case
bridge
::
AdapterLogLevel
::
Fatal
:
l
=
common
::
Logger
::
DSB_LOGLEVEL_FATAL
;
break
;
}
return
l
;
}
}
bridge
::
AdapterLog
::
AdapterLog
(
std
::
string
const
&
module
)
:
m_module
(
module
)
{
}
void
bridge
::
AdapterLog
::
Write
(
AdapterLogLevel
level
,
char
const
*
file
,
int
line
,
char
const
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
common
::
Logger
::
VaLog
(
m_module
.
c_str
(),
toLogLevel
(
level
),
file
,
line
,
format
,
args
);
va_end
(
args
);
}
bool
bridge
::
AdapterLog
::
IsLevelEnabled
(
AdapterLogLevel
level
)
{
common
::
Logger
::
Level
l
=
toLogLevel
(
level
);
return
common
::
Logger
::
IsLevelEnabled
(
m_module
.
c_str
(),
l
);
}
Bridge/Log.h
0 → 100644
View file @
505133a1
#pragma once
#include "Bridge/IAdapter.h"
namespace
bridge
{
class
AdapterLog
:
public
IAdapterLog
{
public:
AdapterLog
(
std
::
string
const
&
module
);
virtual
void
Write
(
AdapterLogLevel
level
,
char
const
*
file
,
int
line
,
char
const
*
format
,
...);
virtual
bool
IsLevelEnabled
(
AdapterLogLevel
level
);
private:
std
::
string
m_module
;
};
}
Common/Log.h
View file @
505133a1
...
...
@@ -28,7 +28,6 @@ namespace common
static
bool
IsLevelEnabled
(
const
char
*
module
,
Level
level
);
private:
static
void
VaLog
(
const
char
*
module
,
Level
level
,
const
char
*
file
,
int
line
,
const
char
*
format
,
va_list
args
);
};
}
...
...
Common/Mutex.h
deleted
100644 → 0
View file @
baf22b2b
#pragma once
#ifdef DSB_USE_STDTHREADS
#include <mutex>
#elif DSB_USE_POSIXTHREADS
#include <pthread.h>
#else
#error "Not implemented"
#endif
namespace
common
{
class
Mutex
{
public:
Mutex
();
inline
void
Lock
();
inline
void
Unlock
();
private:
Mutex
(
Mutex
const
&
/*rhs*/
)
{
}
Mutex
&
operator
=
(
Mutex
const
&
/*rhs*/
)
{
return
*
this
;
}
private:
#ifdef DSB_USE_STDTHREADS
std
::
mutex
m_mutex
;
#elif DSB_USE_POSIXTHREADS
pthread_mutex_t
m_mutex
;
#else
#error "Not implemented"
#endif
};
class
LockGuard
{
public:
LockGuard
(
Mutex
&
m
)
:
m_mutex
(
m
)
{
m_mutex
.
Lock
();
}
~
LockGuard
()
{
m_mutex
.
Unlock
();
}
private:
LockGuard
&
operator
=
(
LockGuard
const
&
/*rhs*/
)
{
return
*
this
;
}
private:
Mutex
&
m_mutex
;
};
#ifdef DSB_USE_STDTHREADS
inline
common
::
Mutex
::
Mutex
()
{
}
inline
void
common
::
Mutex
::
Lock
()
{
m_mutex
.
lock
();
}
inline
void
common
::
Mutex
::
Unlock
()
{
m_mutex
.
unlock
();
}
#elif DSB_USE_POSIXTHREADS
inline
common
::
Mutex
::
Mutex
()
{
pthread_mutex_init
(
&
m_mutex
,
NULL
);
}
inline
void
common
::
Mutex
::
Lock
()
{
pthread_mutex_lock
(
&
m_mutex
);
}
inline
void
common
::
Mutex
::
Unlock
()
{
phread_mutex_unlock
(
&
m_mutex
);
}
#else
#error "Not implemented"
#endif
}
Makefile
View file @
505133a1
...
...
@@ -10,6 +10,7 @@ SRCS=DeviceProviders/AllJoynProvider.cpp \
Bridge/DeviceMethod.cpp
\
Bridge/DeviceProperty.cpp
\
Bridge/DeviceSignal.cpp
\
Bridge/Log.cpp
\
Common/Log.cpp
\
Common/Variant.cpp
\
Common/Guid.cpp
\
...
...
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