4
0
mirror of https://github.com/QuasarApp/Patronum.git synced 2025-05-04 19:19:34 +00:00

98 lines
2.0 KiB
Markdown
Raw Normal View History

2020-04-17 11:24:01 +03:00
# Patronum
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?
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
``` cmake
2020-06-02 19:32:13 +03:00
add_subdirectory(Patronum)
2020-04-19 00:22:55 +03:00
```
* Rebuild yuor project
2020-06-19 14:29:06 +03:00
2020-09-15 18:20:51 +03:00
## Usage
2020-04-19 00:22:55 +03:00
### Service
``` cpp
#include <patronum.h>
class MyserviceApp : public Patronum::Service<QCoreApplication>
{
public:
MyserviceApp(int argc, char **argv):
Patronum::Service<QCoreApplication>(argc, argv, "MyService") {
}
void start() {
// call on server started
}
void stop() {
// call on server stoped
}
void handleReceive(const QList<Feature> &data) {
for (auto i : data) {
if (i.cmd == "Ping") {
sendResuylt(QVariantMap{{"Pong", "From server"}})
}
}
};
QList<Feature> supportedFeatures() {
QList<Feature> res;
2021-04-28 17:53:18 +03:00
Feature Ping = {"Ping", "This is description of the ping command"}
2020-04-19 00:22:55 +03:00
return res << Ping;
}
};
int main(int argc, char **argv) {
MyserviceApp app;
return app.exec();
}
```
### Controller
``` cpp
#include <patronum.h>
class MyControllerApp : public Patronum::Controller
{
public:
MyControllerApp():
Patronum::Controller("MyService") {
}
};
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
}
```