Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
linphone-desktop
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
linphone-desktop
Commits
b05e003d
Commit
b05e003d
authored
Mar 14, 2018
by
Ronan Abhamon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(app): clean some pieces of code and improve build (cli, logger and paths)
parent
41d21d89
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
116 deletions
+129
-116
CMakeLists.txt
CMakeLists.txt
+2
-0
Cli.cpp
src/app/cli/Cli.cpp
+27
-26
Logger.cpp
src/app/logger/Logger.cpp
+24
-22
Logger.hpp
src/app/logger/Logger.hpp
+7
-1
Paths.cpp
src/app/paths/Paths.cpp
+69
-67
No files found.
CMakeLists.txt
View file @
b05e003d
...
...
@@ -331,6 +331,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN
# Build.
# ------------------------------------------------------------------------------
include_directories
(
src/
)
find_package
(
Qt5 COMPONENTS
${
QT5_PACKAGES
}
REQUIRED
)
find_package
(
Qt5 COMPONENTS
${
QT5_PACKAGES_OPTIONAL
}
QUIET
)
find_package
(
Qt5 COMPONENTS Test REQUIRED
)
...
...
src/app/cli/Cli.cpp
View file @
b05e003d
...
...
@@ -22,12 +22,13 @@
#include <iostream>
#include "
../../components/core/CoreManager
.hpp"
#include "
../../utils/Utils
.hpp"
#include "
../App
.hpp"
#include "
app/App
.hpp"
#include "
components/core/CoreManager
.hpp"
#include "
utils/Utils
.hpp"
#include "Cli.hpp"
#include "iostream"
// =============================================================================
using
namespace
std
;
...
...
@@ -52,7 +53,7 @@ static void cliJoinConference (QHash<QString, QString> &args) {
{
shared_ptr
<
linphone
::
Address
>
address
=
core
->
getPrimaryContactParsed
();
address
->
setDisplayName
(
::
Utils
::
appStringToCoreString
(
args
.
take
(
"display-name"
)));
address
->
setDisplayName
(
Utils
::
appStringToCoreString
(
args
.
take
(
"display-name"
)));
core
->
setPrimaryContact
(
address
->
asString
());
}
...
...
@@ -73,8 +74,8 @@ static void cliJoinConferenceAs (QHash<QString, QString> &args) {
const
shared_ptr
<
const
linphone
::
Address
>
currentSipAddress
=
proxyConfig
->
getIdentityAddress
();
const
shared_ptr
<
const
linphone
::
Address
>
askedSipAddress
=
linphone
::
Factory
::
get
()
->
createAddress
(
::
Utils
::
appStringToCoreString
(
fromSipAddress
)
);
Utils
::
appStringToCoreString
(
fromSipAddress
)
);
if
(
!
currentSipAddress
->
weakEqual
(
askedSipAddress
))
{
qWarning
()
<<
QStringLiteral
(
"Guest sip address `%1` doesn't match with default proxy config."
)
.
arg
(
fromSipAddress
);
...
...
@@ -90,7 +91,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
// Check identity.
{
shared_ptr
<
linphone
::
Address
>
address
=
core
->
interpretUrl
(
::
Utils
::
appStringToCoreString
(
args
[
"sip-address"
]));
shared_ptr
<
linphone
::
Address
>
address
=
core
->
interpretUrl
(
Utils
::
appStringToCoreString
(
args
[
"sip-address"
]));
if
(
!
address
||
address
->
getUsername
().
empty
())
{
qWarning
()
<<
QStringLiteral
(
"Unable to parse invalid sip address."
);
return
;
...
...
@@ -107,8 +108,8 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
const
string
identity
=
proxyConfig
->
getIdentityAddress
()
->
asStringUriOnly
();
if
(
sipAddress
!=
identity
)
{
qWarning
()
<<
QStringLiteral
(
"Received different sip address from identity : `%1 != %2`."
)
.
arg
(
::
Utils
::
coreStringToAppString
(
identity
))
.
arg
(
::
Utils
::
coreStringToAppString
(
sipAddress
));
.
arg
(
Utils
::
coreStringToAppString
(
identity
))
.
arg
(
Utils
::
coreStringToAppString
(
sipAddress
));
return
;
}
}
...
...
@@ -119,7 +120,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
App
*
app
=
App
::
getInstance
();
if
(
conference
)
{
if
(
conference
->
getId
()
==
::
Utils
::
appStringToCoreString
(
id
))
{
if
(
conference
->
getId
()
==
Utils
::
appStringToCoreString
(
id
))
{
qInfo
()
<<
QStringLiteral
(
"Conference `%1` already exists."
).
arg
(
id
);
// TODO: Set the view to the "waiting call view".
app
->
smartShowWindow
(
app
->
getCallsWindow
());
...
...
@@ -127,13 +128,13 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
}
qInfo
()
<<
QStringLiteral
(
"Remove existing conference with id: `%1`."
)
.
arg
(
::
Utils
::
coreStringToAppString
(
conference
->
getId
()));
.
arg
(
Utils
::
coreStringToAppString
(
conference
->
getId
()));
core
->
terminateConference
();
}
qInfo
()
<<
QStringLiteral
(
"Create conference with id: `%1`."
).
arg
(
id
);
conference
=
core
->
createConferenceWithParams
(
core
->
createConferenceParams
());
conference
->
setId
(
::
Utils
::
appStringToCoreString
(
id
));
conference
->
setId
(
Utils
::
appStringToCoreString
(
id
));
if
(
core
->
enterConference
()
==
-
1
)
{
qWarning
()
<<
QStringLiteral
(
"Unable to join created conference: `%1`."
).
arg
(
id
);
...
...
@@ -221,7 +222,7 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) {
out
+=
indentedWord
(
word
,
indentedTextCurPos
,
lineLength
,
padding
);
out
+=
"
\n
"
;
return
::
Utils
::
appStringToCoreString
(
out
);
return
Utils
::
appStringToCoreString
(
out
);
}
// =============================================================================
...
...
@@ -264,7 +265,7 @@ void Cli::Command::execute (QHash<QString, QString> &args) const {
(
*
mFunction
)(
args
);
else
{
Function
f
=
mFunction
;
::
Utils
::
connectOnce
(
coreManager
->
getHandlers
().
get
(),
&
CoreHandlers
::
coreStarted
,
coreManager
,
[
f
,
args
]
{
Utils
::
connectOnce
(
coreManager
->
getHandlers
().
get
(),
&
CoreHandlers
::
coreStarted
,
coreManager
,
[
f
,
args
]
{
QHash
<
QString
,
QString
>
fuckConst
=
args
;
(
*
f
)(
fuckConst
);
});
...
...
@@ -275,11 +276,11 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con
QHash
<
QString
,
QString
>
args
;
// TODO: check if there is too much headers.
for
(
const
auto
&
argName
:
mArgsScheme
.
keys
())
{
const
string
header
=
address
->
getHeader
(
::
Utils
::
appStringToCoreString
(
argName
));
const
string
header
=
address
->
getHeader
(
Utils
::
appStringToCoreString
(
argName
));
args
[
argName
]
=
QByteArray
::
fromBase64
(
QByteArray
(
header
.
c_str
(),
int
(
header
.
length
())));
}
address
->
clean
();
args
[
"sip-address"
]
=
::
Utils
::
coreStringToAppString
(
address
->
asStringUriOnly
());
args
[
"sip-address"
]
=
Utils
::
coreStringToAppString
(
address
->
asStringUriOnly
());
execute
(
args
);
}
...
...
@@ -315,17 +316,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\
QRegExp
Cli
::
mRegExpFunctionName
(
"^
\\
s*([a-z-]+)
\\
s*"
);
QMap
<
QString
,
Cli
::
Command
>
Cli
::
mCommands
=
{
createCommand
(
"show"
,
QT_TR_NOOP
(
"showFunctionDescription"
),
::
cliShow
),
createCommand
(
"call"
,
QT_TR_NOOP
(
"callFunctionDescription"
),
::
cliCall
,
{
createCommand
(
"show"
,
QT_TR_NOOP
(
"showFunctionDescription"
),
cliShow
),
createCommand
(
"call"
,
QT_TR_NOOP
(
"callFunctionDescription"
),
cliCall
,
{
{
"sip-address"
,
{}
}
}),
createCommand
(
"initiate-conference"
,
QT_TR_NOOP
(
"initiateConferenceFunctionDescription"
),
::
cliInitiateConference
,
{
createCommand
(
"initiate-conference"
,
QT_TR_NOOP
(
"initiateConferenceFunctionDescription"
),
cliInitiateConference
,
{
{
"sip-address"
,
{}
},
{
"conference-id"
,
{}
}
}),
createCommand
(
"join-conference"
,
QT_TR_NOOP
(
"joinConferenceFunctionDescription"
),
::
cliJoinConference
,
{
createCommand
(
"join-conference"
,
QT_TR_NOOP
(
"joinConferenceFunctionDescription"
),
cliJoinConference
,
{
{
"sip-address"
,
{}
},
{
"conference-id"
,
{}
},
{
"display-name"
,
{}
}
}),
createCommand
(
"join-conference-as"
,
QT_TR_NOOP
(
"joinConferenceAsFunctionDescription"
),
::
cliJoinConferenceAs
,
{
createCommand
(
"join-conference-as"
,
QT_TR_NOOP
(
"joinConferenceAsFunctionDescription"
),
cliJoinConferenceAs
,
{
{
"sip-address"
,
{}
},
{
"conference-id"
,
{}
},
{
"guest-sip-address"
,
{}
}
})
};
...
...
@@ -334,7 +335,7 @@ QMap<QString, Cli::Command> Cli::mCommands = {
void
Cli
::
executeCommand
(
const
QString
&
command
,
CommandFormat
*
format
)
{
shared_ptr
<
linphone
::
Address
>
address
=
linphone
::
Factory
::
get
()
->
createAddress
(
::
Utils
::
appStringToCoreString
(
command
)
Utils
::
appStringToCoreString
(
command
)
);
// Execute cli command.
...
...
@@ -362,13 +363,13 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) {
if
(
scheme
==
validScheme
)
goto
success
;
qWarning
()
<<
QStringLiteral
(
"Not a valid uri: `%1` Unsupported scheme: `%2`."
)
.
arg
(
command
).
arg
(
::
Utils
::
coreStringToAppString
(
scheme
));
.
arg
(
command
).
arg
(
Utils
::
coreStringToAppString
(
scheme
));
return
;
success:
const
QString
functionName
=
::
Utils
::
coreStringToAppString
(
address
->
getHeader
(
"method"
)).
isEmpty
()
const
QString
functionName
=
Utils
::
coreStringToAppString
(
address
->
getHeader
(
"method"
)).
isEmpty
()
?
QStringLiteral
(
"call"
)
:
::
Utils
::
coreStringToAppString
(
address
->
getHeader
(
"method"
));
:
Utils
::
coreStringToAppString
(
address
->
getHeader
(
"method"
));
if
(
!
functionName
.
isEmpty
()
&&
!
mCommands
.
contains
(
functionName
))
{
qWarning
()
<<
QStringLiteral
(
"This command doesn't exist: `%1`."
).
arg
(
functionName
);
...
...
src/app/logger/Logger.cpp
View file @
b05e003d
...
...
@@ -21,11 +21,12 @@
*/
#include <bctoolbox/logging.h>
#include <linphone++/linphone.hh>
#include <QDateTime>
#include <QThread>
#include "
../../
components/settings/SettingsModel.hpp"
#include "
../../
utils/Utils.hpp"
#include "components/settings/SettingsModel.hpp"
#include "utils/Utils.hpp"
#include "Logger.hpp"
...
...
@@ -45,15 +46,15 @@
#define RESET ""
#endif // if defined(__linux__) || defined(__APPLE__)
#define QT_DOMAIN "qt"
#define MAX_LOGS_COLLECTION_SIZE 10485760
/* 10MB. */
#define SRC_PATTERN "/linphone-desktop/src/"
// =============================================================================
using
namespace
std
;
// =============================================================================
namespace
{
constexpr
char
cQtDomain
[]
=
"qt"
;
constexpr
size_t
cMaxLogsCollectionSize
=
10485760
;
// 10MB.
constexpr
char
cSrcPattern
[]
=
"/linphone-desktop/src/"
;
}
QMutex
Logger
::
mMutex
;
...
...
@@ -81,24 +82,25 @@ private:
if
(
!
mLogger
->
isVerbose
())
return
;
using
LogLevel
=
linphone
::
LogLevel
;
const
char
*
format
;
switch
(
level
)
{
case
linphone
:
:
LogLevel
::
LogLevelDebug
:
case
LogLevel
:
:
LogLevelDebug
:
format
=
GREEN
"[%s][Debug]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
case
linphone
:
:
LogLevel
::
LogLevelTrace
:
case
LogLevel
:
:
LogLevelTrace
:
format
=
BLUE
"[%s][Trace]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
case
linphone
:
:
LogLevel
::
LogLevelMessage
:
case
LogLevel
:
:
LogLevelMessage
:
format
=
BLUE
"[%s][Info]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
case
linphone
:
:
LogLevel
::
LogLevelWarning
:
case
LogLevel
:
:
LogLevelWarning
:
format
=
RED
"[%s][Warning]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
case
linphone
:
:
LogLevel
::
LogLevelError
:
case
LogLevel
:
:
LogLevelError
:
format
=
RED
"[%s][Error]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
case
linphone
:
:
LogLevel
::
LogLevelFatal
:
case
LogLevel
:
:
LogLevelFatal
:
format
=
RED
"[%s][Fatal]"
YELLOW
"Core:%s: "
RESET
"%s
\n
"
;
break
;
}
...
...
@@ -106,12 +108,12 @@ private:
fprintf
(
stderr
,
format
,
::
getFormattedCurrentTime
().
constData
(),
getFormattedCurrentTime
().
constData
(),
domain
.
empty
()
?
domain
.
c_str
()
:
"linphone"
,
message
.
c_str
()
);
if
(
level
==
linphone
::
LogLevel
::
LogLevelFatal
)
if
(
level
==
LogLevel
::
LogLevelFatal
)
terminate
();
};
...
...
@@ -148,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
QByteArray
contextArr
;
{
const
char
*
file
=
context
.
file
;
const
char
*
pos
=
file
?
::
Utils
::
rstrstr
(
file
,
SRC_PATTERN
)
:
file
;
const
char
*
pos
=
file
?
Utils
::
rstrstr
(
file
,
cSrcPattern
)
:
file
;
contextArr
=
QStringLiteral
(
"%1:%2: "
)
.
arg
(
pos
?
pos
+
sizeof
(
SRC_PATTERN
)
-
1
:
file
)
.
arg
(
pos
?
pos
+
sizeof
(
cSrcPattern
)
-
1
:
file
)
.
arg
(
context
.
line
)
.
toLocal8Bit
();
contextStr
=
contextArr
.
constData
();
...
...
@@ -161,12 +163,12 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
#endif // ifdef QT_MESSAGELOGCONTEXT
QByteArray
localMsg
=
msg
.
toLocal8Bit
();
QByteArray
dateTime
=
::
getFormattedCurrentTime
();
QByteArray
dateTime
=
getFormattedCurrentTime
();
mMutex
.
lock
();
fprintf
(
stderr
,
format
,
dateTime
.
constData
(),
QThread
::
currentThread
(),
contextStr
,
localMsg
.
constData
());
bctbx_log
(
QT_DOMAIN
,
level
,
"QT: %s%s"
,
contextStr
,
localMsg
.
constData
());
bctbx_log
(
cQtDomain
,
level
,
"QT: %s%s"
,
contextStr
,
localMsg
.
constData
());
mMutex
.
unlock
();
...
...
@@ -201,8 +203,8 @@ void Logger::init (const shared_ptr<linphone::Config> &config) {
loggingService
->
setListener
(
make_shared
<
LinphoneLogger
>
(
mInstance
));
}
linphone
::
Core
::
setLogCollectionPath
(
::
Utils
::
appStringToCoreString
(
folder
));
linphone
::
Core
::
setLogCollectionMaxFileSize
(
MAX_LOGS_COLLECTION_SIZE
);
linphone
::
Core
::
setLogCollectionPath
(
Utils
::
appStringToCoreString
(
folder
));
linphone
::
Core
::
setLogCollectionMaxFileSize
(
cMaxLogsCollectionSize
);
mInstance
->
enable
(
SettingsModel
::
getLogsEnabled
(
config
));
}
src/app/logger/Logger.hpp
View file @
b05e003d
...
...
@@ -23,11 +23,17 @@
#ifndef LOGGER_H_
#define LOGGER_H_
#include <linphone++/linphone.hh>
#include <memory>
#include <QMutex>
// =============================================================================
namespace
linphone
{
class
Config
;
class
LoggingService
;
}
class
Logger
{
public:
~
Logger
()
=
default
;
...
...
src/app/paths/Paths.cpp
View file @
b05e003d
This diff is collapsed.
Click to expand it.
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