Commit b05e003d authored by Ronan Abhamon's avatar Ronan Abhamon

feat(app): clean some pieces of code and improve build (cli, logger and paths)

parent 41d21d89
...@@ -331,6 +331,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN ...@@ -331,6 +331,8 @@ configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BIN
# Build. # Build.
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
include_directories(src/)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED) find_package(Qt5 COMPONENTS ${QT5_PACKAGES} REQUIRED)
find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET) find_package(Qt5 COMPONENTS ${QT5_PACKAGES_OPTIONAL} QUIET)
find_package(Qt5 COMPONENTS Test REQUIRED) find_package(Qt5 COMPONENTS Test REQUIRED)
......
...@@ -22,12 +22,13 @@ ...@@ -22,12 +22,13 @@
#include <iostream> #include <iostream>
#include "../../components/core/CoreManager.hpp" #include "app/App.hpp"
#include "../../utils/Utils.hpp" #include "components/core/CoreManager.hpp"
#include "../App.hpp" #include "utils/Utils.hpp"
#include "Cli.hpp" #include "Cli.hpp"
#include "iostream"
// =============================================================================
using namespace std; using namespace std;
...@@ -52,7 +53,7 @@ static void cliJoinConference (QHash<QString, QString> &args) { ...@@ -52,7 +53,7 @@ static void cliJoinConference (QHash<QString, QString> &args) {
{ {
shared_ptr<linphone::Address> address = core->getPrimaryContactParsed(); 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()); core->setPrimaryContact(address->asString());
} }
...@@ -73,7 +74,7 @@ static void cliJoinConferenceAs (QHash<QString, QString> &args) { ...@@ -73,7 +74,7 @@ static void cliJoinConferenceAs (QHash<QString, QString> &args) {
const shared_ptr<const linphone::Address> currentSipAddress = proxyConfig->getIdentityAddress(); const shared_ptr<const linphone::Address> currentSipAddress = proxyConfig->getIdentityAddress();
const shared_ptr<const linphone::Address> askedSipAddress = linphone::Factory::get()->createAddress( const shared_ptr<const linphone::Address> askedSipAddress = linphone::Factory::get()->createAddress(
::Utils::appStringToCoreString(fromSipAddress) Utils::appStringToCoreString(fromSipAddress)
); );
if (!currentSipAddress->weakEqual(askedSipAddress)) { if (!currentSipAddress->weakEqual(askedSipAddress)) {
qWarning() << QStringLiteral("Guest sip address `%1` doesn't match with default proxy config.") qWarning() << QStringLiteral("Guest sip address `%1` doesn't match with default proxy config.")
...@@ -90,7 +91,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -90,7 +91,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
// Check identity. // 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()) { if (!address || address->getUsername().empty()) {
qWarning() << QStringLiteral("Unable to parse invalid sip address."); qWarning() << QStringLiteral("Unable to parse invalid sip address.");
return; return;
...@@ -107,8 +108,8 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -107,8 +108,8 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
const string identity = proxyConfig->getIdentityAddress()->asStringUriOnly(); const string identity = proxyConfig->getIdentityAddress()->asStringUriOnly();
if (sipAddress != identity) { if (sipAddress != identity) {
qWarning() << QStringLiteral("Received different sip address from identity : `%1 != %2`.") qWarning() << QStringLiteral("Received different sip address from identity : `%1 != %2`.")
.arg(::Utils::coreStringToAppString(identity)) .arg(Utils::coreStringToAppString(identity))
.arg(::Utils::coreStringToAppString(sipAddress)); .arg(Utils::coreStringToAppString(sipAddress));
return; return;
} }
} }
...@@ -119,7 +120,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -119,7 +120,7 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
App *app = App::getInstance(); App *app = App::getInstance();
if (conference) { if (conference) {
if (conference->getId() == ::Utils::appStringToCoreString(id)) { if (conference->getId() == Utils::appStringToCoreString(id)) {
qInfo() << QStringLiteral("Conference `%1` already exists.").arg(id); qInfo() << QStringLiteral("Conference `%1` already exists.").arg(id);
// TODO: Set the view to the "waiting call view". // TODO: Set the view to the "waiting call view".
app->smartShowWindow(app->getCallsWindow()); app->smartShowWindow(app->getCallsWindow());
...@@ -127,13 +128,13 @@ static void cliInitiateConference (QHash<QString, QString> &args) { ...@@ -127,13 +128,13 @@ static void cliInitiateConference (QHash<QString, QString> &args) {
} }
qInfo() << QStringLiteral("Remove existing conference with id: `%1`.") qInfo() << QStringLiteral("Remove existing conference with id: `%1`.")
.arg(::Utils::coreStringToAppString(conference->getId())); .arg(Utils::coreStringToAppString(conference->getId()));
core->terminateConference(); core->terminateConference();
} }
qInfo() << QStringLiteral("Create conference with id: `%1`.").arg(id); qInfo() << QStringLiteral("Create conference with id: `%1`.").arg(id);
conference = core->createConferenceWithParams(core->createConferenceParams()); conference = core->createConferenceWithParams(core->createConferenceParams());
conference->setId(::Utils::appStringToCoreString(id)); conference->setId(Utils::appStringToCoreString(id));
if (core->enterConference() == -1) { if (core->enterConference() == -1) {
qWarning() << QStringLiteral("Unable to join created conference: `%1`.").arg(id); qWarning() << QStringLiteral("Unable to join created conference: `%1`.").arg(id);
...@@ -221,7 +222,7 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) { ...@@ -221,7 +222,7 @@ static string multilineIndent (const QString &str, int indentationNumber = 0) {
out += indentedWord(word, indentedTextCurPos, lineLength, padding); out += indentedWord(word, indentedTextCurPos, lineLength, padding);
out += "\n"; out += "\n";
return ::Utils::appStringToCoreString(out); return Utils::appStringToCoreString(out);
} }
// ============================================================================= // =============================================================================
...@@ -264,7 +265,7 @@ void Cli::Command::execute (QHash<QString, QString> &args) const { ...@@ -264,7 +265,7 @@ void Cli::Command::execute (QHash<QString, QString> &args) const {
(*mFunction)(args); (*mFunction)(args);
else { else {
Function f = mFunction; 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; QHash<QString, QString> fuckConst = args;
(*f)(fuckConst); (*f)(fuckConst);
}); });
...@@ -275,11 +276,11 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con ...@@ -275,11 +276,11 @@ void Cli::Command::executeUri (const shared_ptr<linphone::Address> &address) con
QHash<QString, QString> args; QHash<QString, QString> args;
// TODO: check if there is too much headers. // TODO: check if there is too much headers.
for (const auto &argName : mArgsScheme.keys()) { 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()))); args[argName] = QByteArray::fromBase64(QByteArray(header.c_str(), int(header.length())));
} }
address->clean(); address->clean();
args["sip-address"] = ::Utils::coreStringToAppString(address->asStringUriOnly()); args["sip-address"] = Utils::coreStringToAppString(address->asStringUriOnly());
execute(args); execute(args);
} }
...@@ -315,17 +316,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\ ...@@ -315,17 +316,17 @@ QRegExp Cli::mRegExpArgs("(?:(?:([\\w-]+)\\s*)=\\s*(?:\"([^\"\\\\]*(?:\\\\.[^\"\
QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*"); QRegExp Cli::mRegExpFunctionName("^\\s*([a-z-]+)\\s*");
QMap<QString, Cli::Command> Cli::mCommands = { QMap<QString, Cli::Command> Cli::mCommands = {
createCommand("show", QT_TR_NOOP("showFunctionDescription"), ::cliShow), createCommand("show", QT_TR_NOOP("showFunctionDescription"), cliShow),
createCommand("call", QT_TR_NOOP("callFunctionDescription"), ::cliCall, { createCommand("call", QT_TR_NOOP("callFunctionDescription"), cliCall, {
{ "sip-address", {} } { "sip-address", {} }
}), }),
createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), ::cliInitiateConference, { createCommand("initiate-conference", QT_TR_NOOP("initiateConferenceFunctionDescription"), cliInitiateConference, {
{ "sip-address", {} }, { "conference-id", {} } { "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", {} } { "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", {} } { "sip-address", {} }, { "conference-id", {} }, { "guest-sip-address", {} }
}) })
}; };
...@@ -334,7 +335,7 @@ QMap<QString, Cli::Command> Cli::mCommands = { ...@@ -334,7 +335,7 @@ QMap<QString, Cli::Command> Cli::mCommands = {
void Cli::executeCommand (const QString &command, CommandFormat *format) { void Cli::executeCommand (const QString &command, CommandFormat *format) {
shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress( shared_ptr<linphone::Address> address = linphone::Factory::get()->createAddress(
::Utils::appStringToCoreString(command) Utils::appStringToCoreString(command)
); );
// Execute cli command. // Execute cli command.
...@@ -362,13 +363,13 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) { ...@@ -362,13 +363,13 @@ void Cli::executeCommand (const QString &command, CommandFormat *format) {
if (scheme == validScheme) if (scheme == validScheme)
goto success; goto success;
qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.") qWarning() << QStringLiteral("Not a valid uri: `%1` Unsupported scheme: `%2`.")
.arg(command).arg(::Utils::coreStringToAppString(scheme)); .arg(command).arg(Utils::coreStringToAppString(scheme));
return; return;
success: success:
const QString functionName = ::Utils::coreStringToAppString(address->getHeader("method")).isEmpty() const QString functionName = Utils::coreStringToAppString(address->getHeader("method")).isEmpty()
? QStringLiteral("call") ? QStringLiteral("call")
: ::Utils::coreStringToAppString(address->getHeader("method")); : Utils::coreStringToAppString(address->getHeader("method"));
if (!functionName.isEmpty() && !mCommands.contains(functionName)) { if (!functionName.isEmpty() && !mCommands.contains(functionName)) {
qWarning() << QStringLiteral("This command doesn't exist: `%1`.").arg(functionName); qWarning() << QStringLiteral("This command doesn't exist: `%1`.").arg(functionName);
......
...@@ -21,11 +21,12 @@ ...@@ -21,11 +21,12 @@
*/ */
#include <bctoolbox/logging.h> #include <bctoolbox/logging.h>
#include <linphone++/linphone.hh>
#include <QDateTime> #include <QDateTime>
#include <QThread> #include <QThread>
#include "../../components/settings/SettingsModel.hpp" #include "components/settings/SettingsModel.hpp"
#include "../../utils/Utils.hpp" #include "utils/Utils.hpp"
#include "Logger.hpp" #include "Logger.hpp"
...@@ -45,15 +46,15 @@ ...@@ -45,15 +46,15 @@
#define RESET "" #define RESET ""
#endif // if defined(__linux__) || defined(__APPLE__) #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; using namespace std;
// ============================================================================= namespace {
constexpr char cQtDomain[] = "qt";
constexpr size_t cMaxLogsCollectionSize = 10485760; // 10MB.
constexpr char cSrcPattern[] = "/linphone-desktop/src/";
}
QMutex Logger::mMutex; QMutex Logger::mMutex;
...@@ -81,24 +82,25 @@ private: ...@@ -81,24 +82,25 @@ private:
if (!mLogger->isVerbose()) if (!mLogger->isVerbose())
return; return;
using LogLevel = linphone::LogLevel;
const char *format; const char *format;
switch (level) { switch (level) {
case linphone::LogLevel::LogLevelDebug: case LogLevel::LogLevelDebug:
format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n"; format = GREEN "[%s][Debug]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelTrace: case LogLevel::LogLevelTrace:
format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n"; format = BLUE "[%s][Trace]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelMessage: case LogLevel::LogLevelMessage:
format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n"; format = BLUE "[%s][Info]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelWarning: case LogLevel::LogLevelWarning:
format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Warning]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelError: case LogLevel::LogLevelError:
format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Error]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
case linphone::LogLevel::LogLevelFatal: case LogLevel::LogLevelFatal:
format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n"; format = RED "[%s][Fatal]" YELLOW "Core:%s: " RESET "%s\n";
break; break;
} }
...@@ -106,12 +108,12 @@ private: ...@@ -106,12 +108,12 @@ private:
fprintf( fprintf(
stderr, stderr,
format, format,
::getFormattedCurrentTime().constData(), getFormattedCurrentTime().constData(),
domain.empty() ? domain.c_str() : "linphone", domain.empty() ? domain.c_str() : "linphone",
message.c_str() message.c_str()
); );
if (level == linphone::LogLevel::LogLevelFatal) if (level == LogLevel::LogLevelFatal)
terminate(); terminate();
}; };
...@@ -148,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri ...@@ -148,10 +150,10 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
QByteArray contextArr; QByteArray contextArr;
{ {
const char *file = context.file; 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: ") contextArr = QStringLiteral("%1:%2: ")
.arg(pos ? pos + sizeof(SRC_PATTERN) - 1 : file) .arg(pos ? pos + sizeof(cSrcPattern) - 1 : file)
.arg(context.line) .arg(context.line)
.toLocal8Bit(); .toLocal8Bit();
contextStr = contextArr.constData(); contextStr = contextArr.constData();
...@@ -161,12 +163,12 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri ...@@ -161,12 +163,12 @@ void Logger::log (QtMsgType type, const QMessageLogContext &context, const QStri
#endif // ifdef QT_MESSAGELOGCONTEXT #endif // ifdef QT_MESSAGELOGCONTEXT
QByteArray localMsg = msg.toLocal8Bit(); QByteArray localMsg = msg.toLocal8Bit();
QByteArray dateTime = ::getFormattedCurrentTime(); QByteArray dateTime = getFormattedCurrentTime();
mMutex.lock(); mMutex.lock();
fprintf(stderr, format, dateTime.constData(), QThread::currentThread(), contextStr, localMsg.constData()); 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(); mMutex.unlock();
...@@ -201,8 +203,8 @@ void Logger::init (const shared_ptr<linphone::Config> &config) { ...@@ -201,8 +203,8 @@ void Logger::init (const shared_ptr<linphone::Config> &config) {
loggingService->setListener(make_shared<LinphoneLogger>(mInstance)); loggingService->setListener(make_shared<LinphoneLogger>(mInstance));
} }
linphone::Core::setLogCollectionPath(::Utils::appStringToCoreString(folder)); linphone::Core::setLogCollectionPath(Utils::appStringToCoreString(folder));
linphone::Core::setLogCollectionMaxFileSize(MAX_LOGS_COLLECTION_SIZE); linphone::Core::setLogCollectionMaxFileSize(cMaxLogsCollectionSize);
mInstance->enable(SettingsModel::getLogsEnabled(config)); mInstance->enable(SettingsModel::getLogsEnabled(config));
} }
...@@ -23,11 +23,17 @@ ...@@ -23,11 +23,17 @@
#ifndef LOGGER_H_ #ifndef LOGGER_H_
#define LOGGER_H_ #define LOGGER_H_
#include <linphone++/linphone.hh> #include <memory>
#include <QMutex> #include <QMutex>
// ============================================================================= // =============================================================================
namespace linphone {
class Config;
class LoggingService;
}
class Logger { class Logger {
public: public:
~Logger () = default; ~Logger () = default;
......
This diff is collapsed.
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