Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
liblinphone
Commits
30cd7658
Commit
30cd7658
authored
Aug 10, 2017
by
Ronan
Browse files
feat(core): provide a cpp logger
parent
d150c267
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
144 additions
and
10 deletions
+144
-10
src/CMakeLists.txt
src/CMakeLists.txt
+3
-1
src/cpim/parser/cpim-parser.cpp
src/cpim/parser/cpim-parser.cpp
+9
-9
src/logger/logger.cpp
src/logger/logger.cpp
+74
-0
src/logger/logger.h
src/logger/logger.h
+58
-0
No files found.
src/CMakeLists.txt
View file @
30cd7658
...
...
@@ -29,8 +29,9 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES
cpim/message/cpim-message.h
cpim/parser/cpim-grammar.h
cpim/parser/cpim-parser.h
object/object
.h
logger/logger
.h
object/object-p.h
object/object.h
object/singleton.h
utils/general.h
utils/utils.h
...
...
@@ -43,6 +44,7 @@ set(LINPHONE_CXX_OBJECTS_SOURCE_FILES
cpim/message/cpim-message.cpp
cpim/parser/cpim-grammar.cpp
cpim/parser/cpim-parser.cpp
logger/logger.cpp
object/object.cpp
utils/utils.cpp
)
...
...
src/cpim/parser/cpim-parser.cpp
View file @
30cd7658
...
...
@@ -21,9 +21,8 @@
#include <belr/abnf.h>
#include <belr/grammarbuilder.h>
#include "linphone/core.h"
#include "cpim-grammar.h"
#include "logger/logger.h"
#include "object/object-p.h"
#include "utils/utils.h"
...
...
@@ -100,7 +99,7 @@ namespace LinphonePrivate {
if
(
force
)
header
->
force
(
mValue
);
else
if
(
!
header
->
setValue
(
mValue
))
{
ms_fatal
(
"Unable to set value on core header: `
%s` => `%s`."
,
mName
.
c_str
(),
mValue
.
c_str
())
;
lWarning
()
<<
"Unable to set value on core header: `
"
<<
mName
<<
"` => `"
<<
mValue
<<
"`."
;
return
nullptr
;
}
...
...
@@ -120,7 +119,8 @@ namespace LinphonePrivate {
if
(
force
)
header
->
force
(
mValue
,
language
);
else
if
(
!
header
->
setValue
(
mValue
)
||
(
!
language
.
empty
()
&&
!
header
->
setLanguage
(
language
)))
{
ms_fatal
(
"Unable to set value on subject header: `%s` => `%s`, `%s`."
,
mName
.
c_str
(),
mValue
.
c_str
(),
language
.
c_str
());
lWarning
()
<<
"Unable to set value on subject header: `"
<<
mName
<<
"` => `"
<<
mValue
<<
"`, `"
<<
language
<<
"`."
;
return
nullptr
;
}
...
...
@@ -167,7 +167,7 @@ namespace LinphonePrivate {
shared_ptr
<
Message
>
createMessage
()
const
{
size_t
size
=
mHeaders
->
size
();
if
(
size
!=
2
)
{
ms_fatal
(
"Bad headers lists size."
)
;
lWarning
()
<<
"Bad headers lists size."
;
return
nullptr
;
}
...
...
@@ -178,7 +178,7 @@ namespace LinphonePrivate {
[](
const
shared_ptr
<
const
HeaderNode
>
&
headerNode
)
{
return
Utils
::
iequals
(
headerNode
->
getName
(),
"content-type"
)
&&
headerNode
->
getValue
()
==
"Message/CPIM"
;
})
==
cpimHeaders
->
cend
())
{
ms_fatal
(
"No MIME `Content-Type` found!"
)
;
lWarning
()
<<
"No MIME `Content-Type` found!"
;
return
nullptr
;
}
...
...
@@ -219,7 +219,7 @@ Cpim::Parser::Parser () : Singleton(*new ParserPrivate) {
d
->
grammar
=
builder
.
createFromAbnf
(
getGrammar
(),
make_shared
<
belr
::
CoreRules
>
());
if
(
!
d
->
grammar
)
ms_f
atal
(
"Unable to build CPIM grammar."
)
;
lF
atal
(
)
<<
"Unable to build CPIM grammar."
;
}
// -----------------------------------------------------------------------------
...
...
@@ -255,13 +255,13 @@ shared_ptr<Cpim::Message> Cpim::Parser::parseMessage (const string &input) {
size_t
parsedSize
;
shared_ptr
<
Node
>
node
=
parser
.
parseInput
(
"Message"
,
input
,
&
parsedSize
);
if
(
!
node
)
{
ms_fatal
(
"Unable to parse message."
)
;
lWarning
()
<<
"Unable to parse message."
;
return
nullptr
;
}
shared_ptr
<
MessageNode
>
messageNode
=
dynamic_pointer_cast
<
MessageNode
>
(
node
);
if
(
!
messageNode
)
{
ms_fatal
(
"Unable to cast belr result to message node."
)
;
lWarning
()
<<
"Unable to cast belr result to message node."
;
return
nullptr
;
}
...
...
src/logger/logger.cpp
0 → 100644
View file @
30cd7658
/*
* logger.cpp
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "linphone/core.h"
#include "object/object-p.h"
#include "logger.h"
using
namespace
std
;
using
namespace
LinphonePrivate
;
// =============================================================================
namespace
LinphonePrivate
{
class
LoggerPrivate
:
public
ObjectPrivate
{
public:
Logger
::
Level
level
;
ostringstream
os
;
};
}
// -----------------------------------------------------------------------------
Logger
::
Logger
(
Level
level
)
:
Object
(
*
new
LoggerPrivate
)
{
L_D
(
Logger
);
d
->
level
=
level
;
}
Logger
::~
Logger
()
{
L_D
(
Logger
);
d
->
os
<<
endl
;
const
string
str
=
d
->
os
.
str
();
switch
(
d
->
level
)
{
case
Debug
:
ms_debug
(
"%s"
,
str
.
c_str
());
break
;
case
Info
:
ms_message
(
"%s"
,
str
.
c_str
());
break
;
case
Warning
:
ms_warning
(
"%s"
,
str
.
c_str
());
break
;
case
Error
:
ms_error
(
"%s"
,
str
.
c_str
());
break
;
case
Fatal
:
ms_fatal
(
"%s"
,
str
.
c_str
());
break
;
}
}
ostringstream
&
Logger
::
getOutput
()
{
L_D
(
Logger
);
return
d
->
os
;
}
src/logger/logger.h
0 → 100644
View file @
30cd7658
/*
* logger.h
* Copyright (C) 2017 Belledonne Communications SARL
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _LOGGER_H_
#define _LOGGER_H_
#include <sstream>
#include "object/object.h"
// =============================================================================
namespace
LinphonePrivate
{
class
LoggerPrivate
;
class
LINPHONE_PUBLIC
Logger
:
public
Object
{
public:
enum
Level
{
Debug
,
Info
,
Warning
,
Error
,
Fatal
};
Logger
(
Level
level
);
~
Logger
();
std
::
ostringstream
&
getOutput
();
private:
L_DECLARE_PRIVATE
(
Logger
);
L_DISABLE_COPY
(
Logger
);
};
}
#define lDebug() LinphonePrivate::Logger(Logger::Debug).getOutput()
#define lInfo() LinphonePrivate::Logger(Logger::Info).getOutput()
#define lWarning() LinphonePrivate::Logger(Logger::Warning).getOutput()
#define lError() LinphonePrivate::Logger(Logger::Error).getOutput()
#define lFatal() LinphonePrivate::Logger(Logger::Fatal).getOutput()
#endif // ifndef _LOGGER_H_
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