2020-04-17 11:24:01 +03:00
|
|
|
# Patronum
|
2021-04-28 23:55:54 +03:00
|
|
|
|
2020-06-20 11:09:12 +03:00
|
|
|
This is extension libraries for control your daemons.
|
2020-04-17 11:29:38 +03:00
|
|
|
|
2020-04-17 21:55:54 +03:00
|
|
|
### Why is Patronum?
|
2021-04-28 23:55:54 +03:00
|
|
|
|
2020-04-17 21:55:54 +03:00
|
|
|
Becouse This library offers easy interface to control your demons likewise the magic of Harry Potter controls dementors
|
2020-04-17 12:02:33 +03:00
|
|
|
|
2020-04-17 11:29:38 +03:00
|
|
|
## Main features
|
|
|
|
|
2020-06-20 11:09:12 +03:00
|
|
|
* Support linux systemd daemons.
|
2020-04-17 11:29:38 +03:00
|
|
|
* Auto create a Service from your server or yor daemon utility.
|
|
|
|
* Auto create a Controller of your Service.
|
2020-04-17 12:02:33 +03:00
|
|
|
|
2020-04-19 00:22:55 +03:00
|
|
|
## Include
|
|
|
|
|
|
|
|
### For cmake projects
|
|
|
|
|
|
|
|
* cd yourRepo
|
|
|
|
* git submodule add https://github.com/QuasarApp/Patronum.git # add the repository of Patronum into your repo like submodule
|
|
|
|
* git submodule update --init --recursive
|
|
|
|
* Include in your CMakeLists.txt file the main CMakeLists.txt file of Patronum library
|
2021-04-28 23:55:54 +03:00
|
|
|
```cmake
|
2020-06-02 19:32:13 +03:00
|
|
|
add_subdirectory(Patronum)
|
2020-04-19 00:22:55 +03:00
|
|
|
```
|
|
|
|
* Rebuild yuor project
|
|
|
|
|
|
|
|
|
2020-09-15 18:20:51 +03:00
|
|
|
## Usage
|
2020-04-19 00:22:55 +03:00
|
|
|
|
2021-04-28 23:55:54 +03:00
|
|
|
### Service
|
|
|
|
|
|
|
|
```cpp
|
2020-04-19 00:22:55 +03:00
|
|
|
#include <patronum.h>
|
|
|
|
|
|
|
|
class MyserviceApp : public Patronum::Service<QCoreApplication>
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
MyserviceApp(int argc, char **argv):
|
2021-04-28 23:55:54 +03:00
|
|
|
Patronum::Service<QCoreApplication>(argc, argv) {
|
2020-04-19 00:22:55 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void start() {
|
|
|
|
// call on server started
|
|
|
|
}
|
|
|
|
|
|
|
|
void stop() {
|
|
|
|
// call on server stoped
|
|
|
|
}
|
|
|
|
|
2021-04-28 23:55:54 +03:00
|
|
|
bool HanoiService::handleReceive(const Patronum::Feature &data) {
|
|
|
|
|
|
|
|
if (data.cmd() == "ping") {
|
|
|
|
sendResuylt("Pong");
|
|
|
|
} else if (data.cmd() == "state") {
|
|
|
|
sendResuylt("application status");
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-19 00:22:55 +03:00
|
|
|
|
|
|
|
|
|
|
|
QList<Feature> supportedFeatures() {
|
2021-04-28 23:55:54 +03:00
|
|
|
QSet<Patronum::Feature> data;
|
|
|
|
|
|
|
|
data << Patronum::Feature("ping", "This is description of the ping command");
|
|
|
|
data << Patronum::Feature("state", "return state");
|
2020-04-19 00:22:55 +03:00
|
|
|
|
2021-04-28 23:55:54 +03:00
|
|
|
return data;
|
2020-04-19 00:22:55 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-04-28 23:55:54 +03:00
|
|
|
QCoreApplication::setApplicationName("MyServiceName"); // <--
|
|
|
|
QCoreApplication::setOrganizationName("MyCompany"); // <--
|
2020-04-19 00:22:55 +03:00
|
|
|
MyserviceApp app;
|
|
|
|
return app.exec();
|
|
|
|
}
|
|
|
|
```
|
2021-04-28 23:55:54 +03:00
|
|
|
|
2020-04-19 00:22:55 +03:00
|
|
|
### Controller
|
2021-04-28 23:55:54 +03:00
|
|
|
|
|
|
|
```cpp
|
2020-04-19 00:22:55 +03:00
|
|
|
#include <patronum.h>
|
|
|
|
|
|
|
|
class MyControllerApp : public Patronum::Controller
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
MyControllerApp():
|
2021-04-28 23:55:54 +03:00
|
|
|
Patronum::Controller() {
|
2020-04-19 00:22:55 +03:00
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
2021-04-28 17:53:18 +03:00
|
|
|
QCoreApplication::setApplicationName("MyServiceName"); // <--
|
|
|
|
QCoreApplication::setOrganizationName("MyCompany"); // <--
|
2020-05-09 13:43:35 +03:00
|
|
|
QCoreApplcication app
|
|
|
|
MyControllerApp controller;
|
|
|
|
controller.send(argc, argv);
|
|
|
|
return app.exec();
|
2020-04-19 00:22:55 +03:00
|
|
|
}
|
|
|
|
```
|