From 7698599f130d1d56c4398b69b483664f4e07acf9 Mon Sep 17 00:00:00 2001 From: Petr Bena Date: Sat, 24 May 2014 19:13:28 +0200 Subject: [PATCH] first code --- stikkit/configuration.cpp | 3 +++ stikkit/configuration.hpp | 12 ++++++++++ stikkit/main.cpp | 12 ++++++++++ stikkit/stikkit.pro | 28 +++++++++++++++++++++++ stikkit/syslog.cpp | 47 ++++++++++++++++++++++++++++++++++++++ stikkit/syslog.hpp | 43 ++++++++++++++++++++++++++++++++++ stikkit/terminalparser.cpp | 5 ++++ stikkit/terminalparser.hpp | 10 ++++++++ stikkit/webquery.cpp | 5 ++++ stikkit/webquery.hpp | 10 ++++++++ 10 files changed, 175 insertions(+) create mode 100644 stikkit/configuration.cpp create mode 100644 stikkit/configuration.hpp create mode 100644 stikkit/main.cpp create mode 100644 stikkit/stikkit.pro create mode 100644 stikkit/syslog.cpp create mode 100644 stikkit/syslog.hpp create mode 100644 stikkit/terminalparser.cpp create mode 100644 stikkit/terminalparser.hpp create mode 100644 stikkit/webquery.cpp create mode 100644 stikkit/webquery.hpp diff --git a/stikkit/configuration.cpp b/stikkit/configuration.cpp new file mode 100644 index 0000000..018a00a --- /dev/null +++ b/stikkit/configuration.cpp @@ -0,0 +1,3 @@ +#include "configuration.hpp" + +unsigned int Configuration::Verbosity = 0; diff --git a/stikkit/configuration.hpp b/stikkit/configuration.hpp new file mode 100644 index 0000000..91329e8 --- /dev/null +++ b/stikkit/configuration.hpp @@ -0,0 +1,12 @@ +#ifndef CONFIGURATION_HPP +#define CONFIGURATION_HPP + +#include + +class Configuration +{ + public: + static unsigned int Verbosity; +}; + +#endif // CONFIGURATION_HPP diff --git a/stikkit/main.cpp b/stikkit/main.cpp new file mode 100644 index 0000000..fb24b24 --- /dev/null +++ b/stikkit/main.cpp @@ -0,0 +1,12 @@ +#include +#include "configuration.hpp" +#include "syslog.hpp" + +int main(int argc, char *argv[]) +{ + //QCoreApplication a(argc, argv); + + //return a.exec(); + Stikkit::Syslog::Log("hi"); + return 0; +} diff --git a/stikkit/stikkit.pro b/stikkit/stikkit.pro new file mode 100644 index 0000000..c77b88a --- /dev/null +++ b/stikkit/stikkit.pro @@ -0,0 +1,28 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-05-24T19:01:03 +# +#------------------------------------------------- + +QT += core + +QT -= gui + +TARGET = stikkit +CONFIG += console +CONFIG -= app_bundle + +TEMPLATE = app + + +SOURCES += main.cpp \ + syslog.cpp \ + webquery.cpp \ + configuration.cpp \ + terminalparser.cpp + +HEADERS += \ + syslog.hpp \ + webquery.hpp \ + configuration.hpp \ + terminalparser.hpp diff --git a/stikkit/syslog.cpp b/stikkit/syslog.cpp new file mode 100644 index 0000000..aed047d --- /dev/null +++ b/stikkit/syslog.cpp @@ -0,0 +1,47 @@ +//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. + +#include +#include +#include "syslog.hpp" +#include "configuration.hpp" + +using namespace Stikkit; + +void Syslog::Log(QString Message, StikkitLogType Type) +{ + QString d = QDateTime::currentDateTime().toString(); + QString message = d + " " + Message; + if (Type == StikkitLogType_Error) + { + std::cerr << message.toStdString() << std::endl; + } else + { + std::cout << message.toStdString() << std::endl; + } +} + +void Syslog::ErrorLog(QString Message) +{ + Syslog::Log("ERROR: " + Message, StikkitLogType_Error); +} + +void Syslog::WarningLog(QString Message) +{ + Syslog::Log("WARNING: " + Message, StikkitLogType_Warn); +} + +void Syslog::DebugLog(QString Message, unsigned int Verbosity) +{ + if (Configuration::Verbosity >= Verbosity) + { + Syslog::Log("DEBUG[" + QString::number(Verbosity) + "]: " + Message, StikkitLogType_Debug); + } +} diff --git a/stikkit/syslog.hpp b/stikkit/syslog.hpp new file mode 100644 index 0000000..cb3a24d --- /dev/null +++ b/stikkit/syslog.hpp @@ -0,0 +1,43 @@ +//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. + +#ifndef SYSLOG_HPP +#define SYSLOG_HPP + +#include +#include + +namespace Stikkit +{ + enum StikkitLogType + { + StikkitLogType_Normal, + StikkitLogType_Error, + StikkitLogType_Debug, + StikkitLogType_Warn + }; + + //! Provides a logging to various places + class Syslog + { + public: + //! Write text to terminal as well as ring log + /*! + * \param Message Message to log + */ + static void Log(QString Message, StikkitLogType Type = StikkitLogType_Normal); + static void ErrorLog(QString Message); + static void WarningLog(QString Message); + //! This log is only shown if verbosity is same or larger than requested verbosity + static void DebugLog(QString Message, unsigned int Verbosity = 1); + }; +} + +#endif // SYSLOG_HPP diff --git a/stikkit/terminalparser.cpp b/stikkit/terminalparser.cpp new file mode 100644 index 0000000..1d25570 --- /dev/null +++ b/stikkit/terminalparser.cpp @@ -0,0 +1,5 @@ +#include "terminalparser.hpp" + +terminalparser::terminalparser() +{ +} diff --git a/stikkit/terminalparser.hpp b/stikkit/terminalparser.hpp new file mode 100644 index 0000000..e015d1e --- /dev/null +++ b/stikkit/terminalparser.hpp @@ -0,0 +1,10 @@ +#ifndef TERMINALPARSER_HPP +#define TERMINALPARSER_HPP + +class terminalparser +{ + public: + terminalparser(); +}; + +#endif // TERMINALPARSER_HPP diff --git a/stikkit/webquery.cpp b/stikkit/webquery.cpp new file mode 100644 index 0000000..d1d87d2 --- /dev/null +++ b/stikkit/webquery.cpp @@ -0,0 +1,5 @@ +#include "webquery.hpp" + +WebQuery::WebQuery() +{ +} diff --git a/stikkit/webquery.hpp b/stikkit/webquery.hpp new file mode 100644 index 0000000..f3a1d50 --- /dev/null +++ b/stikkit/webquery.hpp @@ -0,0 +1,10 @@ +#ifndef WEBQUERY_HPP +#define WEBQUERY_HPP + +class WebQuery +{ + public: + WebQuery(); +}; + +#endif // WEBQUERY_HPP