mirror of
https://github.com/QuasarApp/Patronum.git
synced 2025-05-02 01:59:35 +00:00
added base calses for patronum
This commit is contained in:
parent
cc0e4abb36
commit
58f1664320
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
[submodule "Potronum/qt-solutions"]
|
||||||
|
path = Potronum/qt-solutions
|
||||||
|
url = https://github.com/QuasarApp/qt-solutions.git
|
18
CMakeLists.txt
Executable file
18
CMakeLists.txt
Executable file
@ -0,0 +1,18 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2018-2019 QuasarApp.
|
||||||
|
# Distributed under the lgplv3 software license, see the accompanying
|
||||||
|
# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
# of this license document, but changing it is not allowed.
|
||||||
|
#
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
project(Potronum)
|
||||||
|
|
||||||
|
|
||||||
|
include(Patronum/qt-solutions/CMake/ccache.cmake)
|
||||||
|
# Add sub directories
|
||||||
|
add_subdirectory(Patronum)
|
||||||
|
|
||||||
|
include(Patronum/qt-solutions/CMake/QuasarAppCITargets.cmake)
|
||||||
|
|
||||||
|
initAll()
|
36
Patronum/CMakeLists.txt
Executable file
36
Patronum/CMakeLists.txt
Executable file
@ -0,0 +1,36 @@
|
|||||||
|
#
|
||||||
|
# Copyright (C) 2018-2020 QuasarApp.
|
||||||
|
# Distributed under the lgplv3 software license, see the accompanying
|
||||||
|
# Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
# of this license document, but changing it is not allowed.
|
||||||
|
#
|
||||||
|
|
||||||
|
cmake_minimum_required(VERSION 3.1)
|
||||||
|
|
||||||
|
project(Patronum LANGUAGES CXX)
|
||||||
|
add_subdirectory(qt-solutions/qtservice)
|
||||||
|
|
||||||
|
include(qt-solutions/CMake/ProjectOut.cmake)
|
||||||
|
include(qt-solutions/CMake/ccache.cmake)
|
||||||
|
include(qt-solutions/CMake/Version.cmake)
|
||||||
|
|
||||||
|
|
||||||
|
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||||
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTORCC ON)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
add_definitions(-DPATRONUM_LIBRARY)
|
||||||
|
|
||||||
|
find_package(Qt5 COMPONENTS Core REQUIRED)
|
||||||
|
|
||||||
|
file(GLOB SOURCE_CPP
|
||||||
|
"src/*.cpp"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_library(${PROJECT_NAME} SHARED ${SOURCE_CPP})
|
||||||
|
target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt-Service)
|
||||||
|
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
|
||||||
|
|
||||||
|
setVersion(0 1 0)
|
13
Patronum/src/Patronum_global.h
Normal file
13
Patronum/src/Patronum_global.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#ifndef PATRONUM_GLOBAL_H
|
||||||
|
#define PATRONUM_GLOBAL_H
|
||||||
|
|
||||||
|
#include <QtCore/qglobal.h>
|
||||||
|
|
||||||
|
#if defined(PATRONUM_LIBRARY)
|
||||||
|
# define PATRONUM_LIBRARYSHARED_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define PATRONUM_LIBRARYSHARED_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#endif // PATRONUM_GLOBAL_H
|
10
Patronum/src/controller.cpp
Normal file
10
Patronum/src/controller.cpp
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "controller.h"
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
Controller::Controller(const QString &name):
|
||||||
|
QtServiceController(name)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
14
Patronum/src/controller.h
Normal file
14
Patronum/src/controller.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#ifndef CONTROLLER_H
|
||||||
|
#define CONTROLLER_H
|
||||||
|
#include "Patronum_global.h"
|
||||||
|
#include <qtservice.h>
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
class PATRONUM_LIBRARYSHARED_EXPORT Controller : public QtServiceController
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Controller(const QString & name);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif // CONTROLLER_H
|
9
Patronum/src/isocketwraper.cpp
Normal file
9
Patronum/src/isocketwraper.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "isocketwraper.h"
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
State ISocketWraper::state() const {
|
||||||
|
return m_state;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
62
Patronum/src/isocketwraper.h
Normal file
62
Patronum/src/isocketwraper.h
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
#ifndef SOCKETWRAPER_H
|
||||||
|
#define SOCKETWRAPER_H
|
||||||
|
|
||||||
|
#include <QByteArray>
|
||||||
|
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
enum class State: int {
|
||||||
|
Connected,
|
||||||
|
Disconeccted
|
||||||
|
};
|
||||||
|
|
||||||
|
class ISocketWraper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ISocketWraper(){};
|
||||||
|
/**
|
||||||
|
* @brief send - send data to service
|
||||||
|
* @param data
|
||||||
|
* @return true if operation finished seccussful
|
||||||
|
*/
|
||||||
|
virtual bool send(const QByteArray& data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sigReceve - this method is a prototype of received data signal
|
||||||
|
* @param data - received data
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual void sigReceve(QByteArray data) = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief sigStateChanged - this method is a prototype of chnage state signal
|
||||||
|
* @param state
|
||||||
|
*/
|
||||||
|
virtual void sigStateChanged(State state) = 0;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief isValid - check validation of socket
|
||||||
|
*/
|
||||||
|
virtual bool isValid() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief reconnect
|
||||||
|
* @return true if socket connected to host;
|
||||||
|
*/
|
||||||
|
virtual bool reconnect() = 0;
|
||||||
|
|
||||||
|
State state() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
State m_state = State::Disconeccted;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SOCKETWRAPER_H
|
49
Patronum/src/localsocket.cpp
Normal file
49
Patronum/src/localsocket.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "localsocket.h"
|
||||||
|
|
||||||
|
#include <QLocalSocket>
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
LocalSocket::LocalSocket(const QString &target) {
|
||||||
|
m_socket = new QLocalSocket(this);
|
||||||
|
m_socket->connectToServer(target);
|
||||||
|
|
||||||
|
connect(m_socket, &QLocalSocket::stateChanged,
|
||||||
|
this, &LocalSocket::handeStateChanged);
|
||||||
|
|
||||||
|
connect(m_socket, &QLocalSocket::readyRead,
|
||||||
|
this, &LocalSocket::handeReadyRead);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalSocket::send(const QByteArray &data) {
|
||||||
|
if (!isValid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_socket->write(data) == data.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalSocket::isValid() const {
|
||||||
|
return m_state == State::Connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LocalSocket::reconnect() {
|
||||||
|
m_socket->connectToServer();
|
||||||
|
return isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalSocket::handeStateChanged(QLocalSocket::LocalSocketState socketState) {
|
||||||
|
if (socketState == QLocalSocket::LocalSocketState::ConnectedState) {
|
||||||
|
m_state = State::Connected;
|
||||||
|
} else {
|
||||||
|
m_state = State::Disconeccted;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit sigStateChanged(m_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
void LocalSocket::handeReadyRead() {
|
||||||
|
auto data = m_socket->readAll();
|
||||||
|
emit sigReceve(data);
|
||||||
|
}
|
||||||
|
}
|
44
Patronum/src/localsocket.h
Normal file
44
Patronum/src/localsocket.h
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#ifndef LOCALSOCKET_H
|
||||||
|
#define LOCALSOCKET_H
|
||||||
|
|
||||||
|
#include "isocketwraper.h"
|
||||||
|
|
||||||
|
#include <QLocalSocket>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The LocalSocket class
|
||||||
|
* this socket work only with locale data.
|
||||||
|
*/
|
||||||
|
class LocalSocket : public QObject, public ISocketWraper
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief LocalSocket
|
||||||
|
* @param target - target it is localSocket name or ip:port
|
||||||
|
*/
|
||||||
|
LocalSocket(const QString& target);
|
||||||
|
|
||||||
|
// ISocketWraper interface
|
||||||
|
public:
|
||||||
|
bool send(const QByteArray &data);
|
||||||
|
bool isValid() const;
|
||||||
|
bool reconnect();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sigReceve(QByteArray data);
|
||||||
|
void sigStateChanged(State state);
|
||||||
|
|
||||||
|
private:
|
||||||
|
QLocalSocket *m_socket = nullptr;
|
||||||
|
private slots:
|
||||||
|
void handeStateChanged(QLocalSocket::LocalSocketState socketState);
|
||||||
|
void handeReadyRead();
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // LOCALSOCKET_H
|
6
Patronum/src/service.cpp
Normal file
6
Patronum/src/service.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "service.h"
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
17
Patronum/src/service.h
Normal file
17
Patronum/src/service.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#ifndef SERVICE_H
|
||||||
|
#define SERVICE_H
|
||||||
|
#include "Patronum_global.h"
|
||||||
|
#include <qtservice.h>
|
||||||
|
|
||||||
|
namespace Patronum {
|
||||||
|
template<class Application>
|
||||||
|
class PATRONUM_LIBRARYSHARED_EXPORT Service : public QtService<Application>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Service();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // SERVICE_H
|
@ -1,8 +1,8 @@
|
|||||||
# Patronum
|
# Patronum
|
||||||
This is extension libraries for control your daemons based on QtServices from qt-solutions.
|
This is extension libraries for control your daemons based on QtServices from qt-solutions.
|
||||||
|
|
||||||
### Why is Patronum
|
### Why is Patronum?
|
||||||
Because this library offer easy interface for control your demons like the magic of Harry Potter offer control dementors.
|
Becouse This library offers easy interface to control your demons likewise the magic of Harry Potter controls dementors
|
||||||
|
|
||||||
## Main features
|
## Main features
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user