updated documentation

This commit is contained in:
Filip Bucek 2019-11-06 08:57:42 +01:00
parent f22fbc771a
commit 9fbf448eeb
12 changed files with 160 additions and 30 deletions

19
.vscode/c_cpp_properties.json vendored Normal file
View File

@ -0,0 +1,19 @@
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${HOME}/Qt/5.12.4/clang_64/lib/QtCore.framework/Headers/5.12.4",
"${HOME}/Qt/5.12.4/clang_64/lib/**"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}

View File

@ -6,9 +6,12 @@ GENERATE_LATEX = NO
XML_PROGRAMLISTING = YES
# Project settings
PROJECT_NAME = "core-sdk"
INPUT = "../src"
OUTPUT_DIRECTORY = ../../../build/doc/core-sdk
PROJECT_NAME = core-sdk
INPUT = ../src \
pages
FILE_PATTERNS += *.md
USE_MDFILE_AS_MAINPAGE = pages/mainpage.md
OUTPUT_DIRECTORY = ../build/doc/
FULL_PATH_NAMES = NO
# Attributes settings

2
doc/pages/mainpage.md Normal file
View File

@ -0,0 +1,2 @@
# Core SDK documentation

View File

@ -11,7 +11,8 @@ DIR_NAME="${CURRENT_DIR##*/}"
FAIL=0
SOURCE_DIR=$CURRENT_DIR"/.."
BUILD_DIR=$SOURCE_DIR"/../../build"
BUILD_DIR=$SOURCE_DIR"/build"
DOC_DIR=$BUILD_DIR"/doc"
main() {
doc "$@"
@ -20,8 +21,7 @@ main() {
function doc() {
info "Generation documentation"
mkdir -p $BUILD_DIR
cd $BUILD_DIR/..
cd ..
cd $BUILD_DIR
if [ ! -d "m.css" ] ; then
info "Cloning m.css"; git clone git://github.com/mosra/m.css;
fi
@ -31,11 +31,11 @@ function doc() {
pip3 install jinja2 Pygments
info "Generating doxygen"
if [ "$1" == "clean" ]; then rm -fr $BUILD_DIR/doc/$DIR_NAME; fi
if [ "$1" == "clean" ]; then rm -fr $DOC_DIR; fi
./doxygen.py --debug $SOURCE_DIR/doc/Doxyfile-mcss
if [ "$1" == "open" ]; then
open $BUILD_DIR/doc/core-sdk/html/index.html
open $DOC_DIR/html/index.html
fi
}

19
src/core/core.cpp Normal file
View File

@ -0,0 +1,19 @@
#include "core.h"
#include "logger.h"
namespace core {
void installLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg) {
core::Logger::outputMessage(type, context, msg);
}
void initAppLogger() {
auto res = qInstallMessageHandler(core::Logger::outputMessage);
if (res)
qCInfo(sdkcore) << "user message handler qInstallMessageHandler installed sucessfully";
else
qCWarning(sdkcore) << "failed to install message handler qInstallMessageHandler";
}
} // namespace core

36
src/core/core.h Normal file
View File

@ -0,0 +1,36 @@
#pragma once
/** @page "Core SDK"
@m_class{m-block m-success} @par How to get the answer
@parblock
It's simple:
@m_class{m-code-figure} @parblock
@code{.cpp}
// this is the code
printf("The answer to the universe and everything is %d.", 5*9);
@endcode
@code{.shell-session}
The answer to the universe and everything is 42.
@endcode
@endparblock
@endparblock
*/
// Qt
#include <QtCore>
// c++
#include <memory>
namespace core {
/** internal application logger handler */
void installLogger(QtMsgType type, const QMessageLogContext &context, const QString &msg);
/** Install logger to application */
void initAppLogger();
}

View File

@ -3,6 +3,7 @@ CONFIG += c++14
#SRC_DIR = $$PWD
message($$PWD)
SOURCES += \
$$PWD/core.cpp \
$$PWD/databasemanager.cpp \
$$PWD/logger.cpp \
$$PWD/loggermessage.cpp \
@ -10,6 +11,7 @@ SOURCES += \
$$PWD/request.cpp \
HEADERS += \
$$PWD/core.h \
$$PWD/databasemanager.h \
$$PWD/logger.h \
$$PWD/loggermessage.h \

View File

@ -1,7 +1,8 @@
#include "logger.h"
#include "loggermessage.h"
#include <QtCore>
#include <QLoggingCategory>
#include <QFileInfo>
Q_LOGGING_CATEGORY(sdkcore, "sdk.core");
Q_LOGGING_CATEGORY(sdknetwork, "sdk.network");
@ -12,10 +13,7 @@ namespace core {
Logger* Logger::sConsumer = nullptr;
//bool Logger::sShowFunction = false;
/**
* @brief Used to have user specific consumer of logger messages
* @param consumer - inv::Logger
*/
void Logger::setConsumer(Logger *consumer)
{
sConsumer = consumer;
@ -73,7 +71,7 @@ void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, co
}
if (sConsumer) {
LoggerMessage logmsg(shortFile,context.line,context.function,textType,context.category,msg, QLatin1String(""));
sConsumer->insertMessage(logmsg); // emiting message
sConsumer->pushMessage(logmsg); // emiting message
}
// Output message
@ -92,7 +90,8 @@ void Logger::outputMessage(QtMsgType type, const QMessageLogContext &context, co
abort();
}
void Logger::insertMessage(const LoggerMessage& logmsg)
/** Passing data to consumer */
void Logger::pushMessage(const LoggerMessage& logmsg)
{
emit sConsumer->messageReceived(logmsg);
QMutexLocker locker(&sConsumer->mMutex);

View File

@ -14,19 +14,70 @@ Q_DECLARE_LOGGING_CATEGORY(sdkcompress)
namespace core {
/** @see http://stackoverflow.com/questions/8337300/c11-how-do-i-implement-convenient-logging-without-a-singleton */
/**
* # Loggger
*
* Class for logging qDebug qWarning qInfo and qCritical messages
*
*
* ## Basic usage
*
* @code
* int main() {
* core::initAppLogger(); // <-- then Logger::outputMessage will handle all messages
* // Log messge Filtering
* QStringList filters;
* filters << "qt.*=false";
* filters << "sdk.core.*=true";
* QLoggingCategory::setFilterRules(filters.join(QStringLiteral("\n")));
* }
* @endcode
*
* @see https://doc.qt.io/qt-5/qdebug.html
* @see https://doc.qt.io/qt-5/qloggingcategory.html
*
*/
class Logger : public QObject
{
Q_OBJECT
public:
// Static methods
// User defined consumer ( messages will be sent there using insertMessage )
static Logger* sConsumer;
static void setConsumer(Logger *consumer);
static void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg);
// static void message(const char *file, int line, const char *function, const QString &type, const QString &group, const QString &msg, const QString &detail = QString());
// Public methods
/// Default constructor
explicit Logger(QObject *parent = nullptr);
void insertMessage(const LoggerMessage& logmsg);
/**
* @brief User specific consumer of logger messages
* @param consumer - sublass of core::Loger
*
* @code
* #include "core.h"
* int main() {
* core::initAppLogger();
* core::Logger logger;
* core::Logger::setConsumer(&logger);
* }
* @endcode
*
*/
static void setConsumer(Logger *consumer);
/** Only Message handler for Qt
*
* @code
* #include "core.h"
* int main() {
* core::initAppLogger();
* }
* @endcode
*/
static void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg);
/** Pusing messges from installed message handler */
virtual void pushMessage(const LoggerMessage& logmsg);
QList<core::LoggerMessage> getNewMessages(int currentCount);

View File

@ -26,7 +26,7 @@ RequestManager::RequestManager(QObject *parent)
* @brief Soap::downloadRequest
* @param soapRequest
*/
void RequestManager::downloadRequest(const std::shared_ptr<Request>& request)
void RequestManager::processRequest(const std::shared_ptr<Request>& request)
{
QNetworkReply *reply = mNetworkAccessManager.post(request->networkRequest(), request->requestData());
mRequestMap.insert(reply, request);

View File

@ -19,9 +19,8 @@ class RequestManager : public QObject
public:
explicit RequestManager(QObject *parent = nullptr);
void downloadRequest(const std::shared_ptr<Request>& request);
void processRequest(const std::shared_ptr<Request>& request);
// QByteArray data() const;
private:
Q_SLOT void sslErrors(const QList<QSslError> &sslErrors);
@ -34,8 +33,6 @@ signals:
private:
QNetworkAccessManager mNetworkAccessManager;
//QNetworkReply *mCurrentReply = nullptr;
// QByteArray mData;
QMap<QNetworkReply*, std::shared_ptr<Request>> mRequestMap;
};

View File

@ -1,8 +1,13 @@
#include "core.h"
#include <QCoreApplication>
#include <QCommandLineParser>
int main(int argc, char *argv[])
{
core::initAppLogger();
QCoreApplication app(argc, argv);
QCoreApplication::setApplicationName("colnod-connector");
QCoreApplication::setApplicationVersion("1.0");
@ -14,7 +19,4 @@ int main(int argc, char *argv[])
QCommandLineOption dryModeOption("dryMode", "ColnodAPI", "Read-only mode, prints changes which would normally be made");
parser.addOption(dryModeOption);
parser.process(app);
// Synchronizaiton
return QCoreApplication::exec();
}