diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..aed4290 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "Potronum/qt-solutions"] + path = Potronum/qt-solutions + url = https://github.com/QuasarApp/qt-solutions.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..29da090 --- /dev/null +++ b/CMakeLists.txt @@ -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() diff --git a/Patronum/CMakeLists.txt b/Patronum/CMakeLists.txt new file mode 100755 index 0000000..37def94 --- /dev/null +++ b/Patronum/CMakeLists.txt @@ -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) diff --git a/Patronum/src/Patronum_global.h b/Patronum/src/Patronum_global.h new file mode 100644 index 0000000..e663bdb --- /dev/null +++ b/Patronum/src/Patronum_global.h @@ -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 diff --git a/Patronum/src/controller.cpp b/Patronum/src/controller.cpp new file mode 100644 index 0000000..0a8faa7 --- /dev/null +++ b/Patronum/src/controller.cpp @@ -0,0 +1,10 @@ +#include "controller.h" +namespace Patronum { + +Controller::Controller(const QString &name): + QtServiceController(name) +{ + +} + +} diff --git a/Patronum/src/controller.h b/Patronum/src/controller.h new file mode 100644 index 0000000..85bc92f --- /dev/null +++ b/Patronum/src/controller.h @@ -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 diff --git a/Patronum/src/isocketwraper.cpp b/Patronum/src/isocketwraper.cpp new file mode 100644 index 0000000..2436ff0 --- /dev/null +++ b/Patronum/src/isocketwraper.cpp @@ -0,0 +1,9 @@ +#include "isocketwraper.h" + +namespace Patronum { + +State ISocketWraper::state() const { + return m_state; +} + +} diff --git a/Patronum/src/isocketwraper.h b/Patronum/src/isocketwraper.h new file mode 100644 index 0000000..20767da --- /dev/null +++ b/Patronum/src/isocketwraper.h @@ -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 diff --git a/Patronum/src/localsocket.cpp b/Patronum/src/localsocket.cpp new file mode 100644 index 0000000..35ca231 --- /dev/null +++ b/Patronum/src/localsocket.cpp @@ -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); +} +} diff --git a/Patronum/src/localsocket.h b/Patronum/src/localsocket.h new file mode 100644 index 0000000..0d54575 --- /dev/null +++ b/Patronum/src/localsocket.h @@ -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 diff --git a/Patronum/src/service.cpp b/Patronum/src/service.cpp new file mode 100644 index 0000000..6eb8bf9 --- /dev/null +++ b/Patronum/src/service.cpp @@ -0,0 +1,6 @@ +#include "service.h" + +namespace Patronum { + +} + diff --git a/Patronum/src/service.h b/Patronum/src/service.h new file mode 100644 index 0000000..9652f51 --- /dev/null +++ b/Patronum/src/service.h @@ -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 diff --git a/README.md b/README.md index 9444796..1867f39 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Patronum This is extension libraries for control your daemons based on QtServices from qt-solutions. -### Why is Patronum -Because this library offer easy interface for control your demons like the magic of Harry Potter offer control dementors. +### Why is Patronum? +Becouse This library offers easy interface to control your demons likewise the magic of Harry Potter controls dementors ## Main features