Compare commits
5 Commits
28f3471036
...
9f1d23ad8e
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f1d23ad8e | |||
| 7cd2f7a310 | |||
| 7209eec012 | |||
| 992f59904a | |||
| 9dbd7210cb |
@@ -3,7 +3,7 @@ cmake_policy(SET CMP0017 NEW) # need include() with .cmake
|
|||||||
project(PIP)
|
project(PIP)
|
||||||
set(PIP_MAJOR 4)
|
set(PIP_MAJOR 4)
|
||||||
set(PIP_MINOR 3)
|
set(PIP_MINOR 3)
|
||||||
set(PIP_REVISION 0)
|
set(PIP_REVISION 1)
|
||||||
set(PIP_SUFFIX )
|
set(PIP_SUFFIX )
|
||||||
set(PIP_COMPANY SHS)
|
set(PIP_COMPANY SHS)
|
||||||
set(PIP_DOMAIN org.SHS)
|
set(PIP_DOMAIN org.SHS)
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
#define PIAPPLICATIONMODULE_H
|
#define PIAPPLICATIONMODULE_H
|
||||||
|
|
||||||
#include "picli.h"
|
#include "picli.h"
|
||||||
|
#include "pilog.h"
|
||||||
#include "pisingleapplication.h"
|
#include "pisingleapplication.h"
|
||||||
#include "pisystemmonitor.h"
|
#include "pisystemmonitor.h"
|
||||||
|
|
||||||
|
|||||||
@@ -30,44 +30,10 @@
|
|||||||
//! \~english \section PILog_sec0 Synopsis
|
//! \~english \section PILog_sec0 Synopsis
|
||||||
//! \~russian \section PILog_sec0 Краткий обзор
|
//! \~russian \section PILog_sec0 Краткий обзор
|
||||||
//! \~english
|
//! \~english
|
||||||
//! This class provide handy parsing of command-line arguments. First you should add
|
//! This class provides log with optional file and console output.
|
||||||
//! arguments to %PICLI with function \a addArgument(). Then you can check if there
|
|
||||||
//! is some argument in application command-line with function \a hasArgument(),
|
|
||||||
//! or obtain argument value by \a argumentValue().
|
|
||||||
//!
|
//!
|
||||||
//! \~russian
|
//! \~russian
|
||||||
//! Этот класс предоставляет удобный механизм для разбора аргументов командной строки.
|
//! Этот класс предоставляет лог с опциональным выводом в файл и консоль.
|
||||||
//! Сперва необходимо добавить аргументы в %PICLI с помощью методов \a addArgument().
|
|
||||||
//! Далее можно проверять аргументы на наличие в командной строке методом \a hasArgument(),
|
|
||||||
//! а также получать их значения при помощи \a argumentValue().
|
|
||||||
//!
|
|
||||||
//! \~english \section PICLI_sec1 Example
|
|
||||||
//! \~russian \section PICLI_sec1 Пример
|
|
||||||
//! \~\code
|
|
||||||
//! int main(int argc, char ** argv) {
|
|
||||||
//! PICLI cli(argc, argv);
|
|
||||||
//! cli.addArgument("console");
|
|
||||||
//! cli.addArgument("debug");
|
|
||||||
//! cli.addArgument("Value", "v", "value", true);
|
|
||||||
//! if (cli.hasArgument("console"))
|
|
||||||
//! piCout << "console active";
|
|
||||||
//! if (cli.hasArgument("debug"))
|
|
||||||
//! piCout << "debug active";
|
|
||||||
//! piCout << "Value =" << cli.argumentValue("Value");
|
|
||||||
//! return 0;
|
|
||||||
//! }
|
|
||||||
//! \endcode
|
|
||||||
//!
|
|
||||||
//! \~english These executions are similar:
|
|
||||||
//! \~russian Эти вызовы будут идентичны:
|
|
||||||
//!
|
|
||||||
//! \~\code
|
|
||||||
//! a.out -cd -v 10
|
|
||||||
//! a.out --value 10 -dc
|
|
||||||
//! a.out -c -v 10 -d
|
|
||||||
//! a.out --console -d -v 10
|
|
||||||
//! a.out --debug -c --value 10
|
|
||||||
//! \endcode
|
|
||||||
//!
|
//!
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -41,82 +41,107 @@ public:
|
|||||||
PILog();
|
PILog();
|
||||||
~PILog();
|
~PILog();
|
||||||
|
|
||||||
|
//! \~english Message category
|
||||||
|
//! \~russian Категория сообщения
|
||||||
enum class Level {
|
enum class Level {
|
||||||
Error,
|
Error /** \~english Error \~russian Ошибка */,
|
||||||
Warning,
|
Warning /** \~english Warning \~russian Предупреждение */,
|
||||||
Info,
|
Info /** \~english Information \~russian Информация */,
|
||||||
Debug,
|
Debug /** \~english Debug \~russian Отладка */,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//! \~english Output channel
|
||||||
|
//! \~russian Канал вывода
|
||||||
enum Output {
|
enum Output {
|
||||||
File = 0x1,
|
File /** \~english File \~russian Файл */ = 0x1,
|
||||||
Console = 0x2,
|
Console /** \~english Console \~russian Консоль */ = 0x2,
|
||||||
All = 0xFF,
|
All /** \~english All \~russian Все */ = 0xFF,
|
||||||
};
|
};
|
||||||
|
|
||||||
//! \~english Set output target \"o\" to \"on\".
|
//! \~english Set output channel \"o\" to \"on\".
|
||||||
|
//! \~russian Установить канал вывода \"o\" в \"on\".
|
||||||
void setOutput(Output o, bool on = true) { output.setFlag(o, on); }
|
void setOutput(Output o, bool on = true) { output.setFlag(o, on); }
|
||||||
|
|
||||||
//! \~english Returns prefix for filename.
|
//! \~english Returns prefix for filename.
|
||||||
|
//! \~russian Возвращает префикс имени файла.
|
||||||
PIString logName() const { return log_name; }
|
PIString logName() const { return log_name; }
|
||||||
|
|
||||||
//! \~english Set prefix for filename. Should be set \b before \a setDir()!
|
//! \~english Set prefix for filename. Should be set \b before \a setDir()!
|
||||||
|
//! \~russian Устанавливает префикс имени файла. Должен быть установлен \b до вызова \a setDir()!
|
||||||
void setLogName(const PIString & n) { log_name = n; }
|
void setLogName(const PIString & n) { log_name = n; }
|
||||||
|
|
||||||
//! \~english Returns if color for console output enabled.
|
//! \~english Returns if color for console output enabled.
|
||||||
|
//! \~russian Возвращает использовать ли цвет для вывода в консоль.
|
||||||
bool colorConsole() const { return color_console; }
|
bool colorConsole() const { return color_console; }
|
||||||
|
|
||||||
//! \~english Set color for console output enabled. True by default.
|
//! \~english Set color for console output enabled. True by default.
|
||||||
|
//! \~russian Устанавливает использовать ли цвет для вывода в консоль. Включено по умолчанию.
|
||||||
void setColorConsole(bool yes) { color_console = yes; }
|
void setColorConsole(bool yes) { color_console = yes; }
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns directory for log files.
|
//! \~english Returns directory for log files.
|
||||||
|
//! \~russian Возвращает директорию для файлов.
|
||||||
PIString dir() const { return log_dir; }
|
PIString dir() const { return log_dir; }
|
||||||
|
|
||||||
//! \~english Set directory for log files. Should be set \b after \a setApplicationName()!
|
//! \~english Set directory for log files. Should be set \b after \a setApplicationName()!
|
||||||
|
//! \~russian Устанавливает директорию для файлов. Должна быть установлена \b после вызова \a setApplicationName()!
|
||||||
void setDir(const PIString & d);
|
void setDir(const PIString & d);
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns lifetime for file.
|
//! \~english Returns lifetime for file.
|
||||||
|
//! \~russian Возвращает время жизни файла.
|
||||||
PISystemTime fileSplitTime() const { return split_time; }
|
PISystemTime fileSplitTime() const { return split_time; }
|
||||||
|
|
||||||
//! \~english Set lifetime for file. Each "st" interval new file will be created.
|
//! \~english Set lifetime for file. Each "st" interval new file will be created.
|
||||||
|
//! \~russian Устанавливает время жизни файла. Каждый интервал "st" будет создан новый файл.
|
||||||
void setFileSplitTime(PISystemTime st) { split_time = st; }
|
void setFileSplitTime(PISystemTime st) { split_time = st; }
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns timestamp format for line.
|
//! \~english Returns timestamp format for line.
|
||||||
|
//! \~russian Возвращает формат метки времени для строки.
|
||||||
PIString timestampFormat() const { return timestamp_format; }
|
PIString timestampFormat() const { return timestamp_format; }
|
||||||
|
|
||||||
//! \~english Set timestamp format for line. Default is "yyyy-MM-dd hh:mm:ss.zzz".
|
//! \~english Set timestamp format for line. Default is "yyyy-MM-dd hh:mm:ss.zzz".
|
||||||
|
//! \~russian Устанавливает формат метки времени для строки. По умолчанию "yyyy-MM-dd hh:mm:ss.zzz".
|
||||||
void setTimestampFormat(const PIString & f) { timestamp_format = f; }
|
void setTimestampFormat(const PIString & f) { timestamp_format = f; }
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns line format.
|
//! \~english Returns line format.
|
||||||
|
//! \~russian Возвращает формат строки.
|
||||||
PIString lineFormat() const { return line_format; }
|
PIString lineFormat() const { return line_format; }
|
||||||
|
|
||||||
//! \~english Set line format. "t" is timestamp, "c" is category and "m" is message. Default is "t - c: m".
|
//! \~english Set line format. "t" is timestamp, "c" is category and "m" is message. Default is "t - c: m".
|
||||||
|
//! \~russian Устанавливает формат строки. "t" - метка времени, "c" - категория и "m" - сообщение. По умолчанию "t - c: m".
|
||||||
void setLineFormat(const PIString & f);
|
void setLineFormat(const PIString & f);
|
||||||
|
|
||||||
|
|
||||||
//! \~english Returns maximum level.
|
//! \~english Returns maximum level.
|
||||||
|
//! \~russian Возвращает максимальную категорию.
|
||||||
Level level() const { return max_level; }
|
Level level() const { return max_level; }
|
||||||
|
|
||||||
//! \~english Set maximum level. All levels greater than \"l\" will be ignored. Default if \a Level::Debug.
|
//! \~english Set maximum level. All levels greater than \"l\" will be ignored. Default is \a Level::Debug.
|
||||||
|
//! \~russian Устанавливает максимальную категорию. Все сообщения с большей категорией, чем \"l\", будут игнорироваться. По умолчанию \a
|
||||||
|
//! Level::Debug.
|
||||||
void setLevel(Level l);
|
void setLevel(Level l);
|
||||||
|
|
||||||
//! \~english Returns PICout for Level::Error level.
|
//! \~english Returns \a PICout for \a Level::Error level.
|
||||||
|
//! \~russian Возвращает \a PICout для категории \a Level::Error.
|
||||||
PICout error(PIObject * context = nullptr);
|
PICout error(PIObject * context = nullptr);
|
||||||
|
|
||||||
//! \~english Returns PICout for Level::Warning level.
|
//! \~english Returns \a PICout for \a Level::Warning level.
|
||||||
|
//! \~russian Возвращает \a PICout для категории \a Level::Warning.
|
||||||
PICout warning(PIObject * context = nullptr);
|
PICout warning(PIObject * context = nullptr);
|
||||||
|
|
||||||
//! \~english Returns PICout for Level::Info level.
|
//! \~english Returns \a PICout for \a Level::Info level.
|
||||||
|
//! \~russian Возвращает \a PICout для категории \a Level::Info.
|
||||||
PICout info(PIObject * context = nullptr);
|
PICout info(PIObject * context = nullptr);
|
||||||
|
|
||||||
//! \~english Returns PICout for Level::Debug level.
|
//! \~english Returns \a PICout for \a Level::Debug level.
|
||||||
|
//! \~russian Возвращает \a PICout для категории \a Level::Debug.
|
||||||
PICout debug(PIObject * context = nullptr);
|
PICout debug(PIObject * context = nullptr);
|
||||||
|
|
||||||
//! \~english Write all queued lines and stop. Also called in destructor.
|
//! \~english Write all queued lines and stop. Also called in destructor.
|
||||||
|
//! \~russian Записывает все строки из очереди и останавливается. Также вызывается в деструкторе.
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
57
libs/main/client_server/piclientservermodule.h
Normal file
57
libs/main/client_server/piclientservermodule.h
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
PIP - Platform Independent Primitives
|
||||||
|
Module includes
|
||||||
|
Ivan Pelipenko peri4ko@yandex.ru, Andrey Bychkov work.a.b@yandex.ru
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Lesser 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 Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
//! \defgroup ClientServer ClientServer
|
||||||
|
//! \~\brief
|
||||||
|
//! \~english TCP Client-Server
|
||||||
|
//! \~russian TCP Клиент-Сервер
|
||||||
|
//!
|
||||||
|
//! \~\details
|
||||||
|
//! \~english \section cmake_module_ClientServer Building with CMake
|
||||||
|
//! \~russian \section cmake_module_ClientServer Сборка с использованием CMake
|
||||||
|
//!
|
||||||
|
//! \~\code
|
||||||
|
//! find_package(PIP REQUIRED)
|
||||||
|
//! target_link_libraries([target] PIP::ClientServer)
|
||||||
|
//! \endcode
|
||||||
|
//!
|
||||||
|
//! \~english \par Common
|
||||||
|
//! \~russian \par Общее
|
||||||
|
//!
|
||||||
|
//! \~english
|
||||||
|
//! These files provides server with clients dispatching for server-side and client for client-side.
|
||||||
|
//!
|
||||||
|
//! \~russian
|
||||||
|
//! Эти файлы предоставляют сервер с диспетчеризацией клиентов для серверной стороны и клиента для клиентской стороны.
|
||||||
|
//!
|
||||||
|
//! \~\authors
|
||||||
|
//! \~english
|
||||||
|
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||||||
|
//! Andrey Bychkov work.a.b@yandex.ru;
|
||||||
|
//! \~russian
|
||||||
|
//! Иван Пелипенко peri4ko@yandex.ru;
|
||||||
|
//! Андрей Бычков work.a.b@yandex.ru;
|
||||||
|
//!
|
||||||
|
|
||||||
|
#ifndef PICLIENTSERVERMODULE_H
|
||||||
|
#define PICLIENTSERVERMODULE_H
|
||||||
|
|
||||||
|
#include "piclientserver_client.h"
|
||||||
|
#include "piclientserver_server.h"
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -343,6 +343,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
static const PIString s_typedef = PIStringAscii("typedef");
|
static const PIString s_typedef = PIStringAscii("typedef");
|
||||||
static const PIString s_namespace = PIStringAscii("namespace");
|
static const PIString s_namespace = PIStringAscii("namespace");
|
||||||
static const PIString s_template = PIStringAscii("template");
|
static const PIString s_template = PIStringAscii("template");
|
||||||
|
static const PIString s_L = PIStringAscii("$L");
|
||||||
|
|
||||||
bool mlc = false, cc = false;
|
bool mlc = false, cc = false;
|
||||||
int mls = 0, ole = -1, /*ccs = 0,*/ end = 0;
|
int mls = 0, ole = -1, /*ccs = 0,*/ end = 0;
|
||||||
@@ -365,8 +366,9 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
}
|
}
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
if (c == '\\' && fc[i - 1].toAscii() != '\\') {
|
if (c == '\\' && fc[i - 1].toAscii() != '\\') {
|
||||||
fc.cutMid(i, 2);
|
fc.cutMid(i, 1);
|
||||||
--i;
|
fc.replace(i, 1, s_L);
|
||||||
|
++i;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (cc) continue;
|
if (cc) continue;
|
||||||
@@ -390,6 +392,7 @@ bool PICodeParser::parseFileContent(PIString & fc, bool main) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
pfc = procMacros(fc);
|
pfc = procMacros(fc);
|
||||||
|
pfc.removeAll(s_L);
|
||||||
|
|
||||||
if (main) return true;
|
if (main) return true;
|
||||||
|
|
||||||
@@ -1248,6 +1251,7 @@ PIString PICodeParser::procMacros(PIString fc) {
|
|||||||
static const PIString s_elif = PIStringAscii("elif");
|
static const PIString s_elif = PIStringAscii("elif");
|
||||||
static const PIString s_else = PIStringAscii("else");
|
static const PIString s_else = PIStringAscii("else");
|
||||||
static const PIString s_endif = PIStringAscii("endif");
|
static const PIString s_endif = PIStringAscii("endif");
|
||||||
|
static const PIString s_L = PIStringAscii("$L");
|
||||||
if (fc.isEmpty()) return PIString();
|
if (fc.isEmpty()) return PIString();
|
||||||
int ifcnt = 0;
|
int ifcnt = 0;
|
||||||
bool grab = false, skip = false, cond_ok = false;
|
bool grab = false, skip = false, cond_ok = false;
|
||||||
@@ -1337,7 +1341,9 @@ bool PICodeParser::parseDirective(PIString d) {
|
|||||||
static const PIString s_define = PIStringAscii("define");
|
static const PIString s_define = PIStringAscii("define");
|
||||||
static const PIString s_undef = PIStringAscii("undef");
|
static const PIString s_undef = PIStringAscii("undef");
|
||||||
static const PIString s_PIMETA = PIStringAscii("PIMETA");
|
static const PIString s_PIMETA = PIStringAscii("PIMETA");
|
||||||
|
static const PIString s_L = PIStringAscii("$L");
|
||||||
if (d.isEmpty()) return true;
|
if (d.isEmpty()) return true;
|
||||||
|
d.replaceAll(s_L, '\n');
|
||||||
PIString dname = d.takeCWord();
|
PIString dname = d.takeCWord();
|
||||||
// piCout << "parseDirective" << d;
|
// piCout << "parseDirective" << d;
|
||||||
if (dname == s_include) {
|
if (dname == s_include) {
|
||||||
|
|||||||
@@ -37,6 +37,10 @@
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
class PISet: public PIMap<T, uchar> {
|
class PISet: public PIMap<T, uchar> {
|
||||||
typedef PIMap<T, uchar> _CSet;
|
typedef PIMap<T, uchar> _CSet;
|
||||||
|
template<typename P, typename T1>
|
||||||
|
friend PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<T1> & v);
|
||||||
|
template<typename P, typename T1>
|
||||||
|
friend PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<T1> & v);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Contructs an empty set
|
//! Contructs an empty set
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "pibitarray.h"
|
#include "pibitarray.h"
|
||||||
#include "pimap.h"
|
#include "pimap.h"
|
||||||
#include "pimemoryblock.h"
|
#include "pimemoryblock.h"
|
||||||
|
#include "piset.h"
|
||||||
#include "pivector2d.h"
|
#include "pivector2d.h"
|
||||||
|
|
||||||
#define PIP_BINARY_STREAM
|
#define PIP_BINARY_STREAM
|
||||||
@@ -655,6 +656,46 @@ inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PIMap<Key, T> & v)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Store operator
|
||||||
|
//! \~russian Оператор сохранения
|
||||||
|
template<typename P, typename Key>
|
||||||
|
inline PIBinaryStream<P> & operator<<(PIBinaryStream<P> & s, const PISet<Key> & v) {
|
||||||
|
s.binaryStreamAppend((int)v.pim_index.size_s());
|
||||||
|
for (uint i = 0; i < v.size(); ++i) {
|
||||||
|
s.binaryStreamAppend((int)v.pim_index[i].index);
|
||||||
|
s << v.pim_index[i].key;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//! \~english Restore operator
|
||||||
|
//! \~russian Оператор извлечения
|
||||||
|
template<typename P, typename Key>
|
||||||
|
inline PIBinaryStream<P> & operator>>(PIBinaryStream<P> & s, PISet<Key> & v) {
|
||||||
|
int sz = s.binaryStreamTakeInt();
|
||||||
|
if (s.wasReadError()) {
|
||||||
|
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
|
||||||
|
v.clear();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
v.pim_index.resize(sz);
|
||||||
|
v.pim_content.resize(sz, 0);
|
||||||
|
int ind = 0;
|
||||||
|
for (int i = 0; i < sz; ++i) {
|
||||||
|
ind = s.binaryStreamTakeInt();
|
||||||
|
s >> v.pim_index[i].key;
|
||||||
|
if (s.wasReadError()) {
|
||||||
|
fprintf(stderr, "error with PISet<%s>\n", __PIP_TYPENAME__(Key));
|
||||||
|
v.clear();
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
v.pim_index[i].index = ind;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// non-defined complex types
|
// non-defined complex types
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user