Patronum
Loading...
Searching...
No Matches
Patronum::Service< Application > Class Template Reference

The Service class it is class for create a services from daemons. More...

#include <PService.h>

Inheritance diagram for Patronum::Service< Application >:
Inheritance graph
Collaboration diagram for Patronum::Service< Application >:
Collaboration graph

Public Member Functions

 Service (int argc, char *argv[])
 Service This is main constructor of the service object.
 
 ~Service () override
 
- Public Member Functions inherited from Patronum::ServiceBase
 ServiceBase (int argc, char *argv[])
 ServiceBase This is main constructor of the service.
 
 ~ServiceBase () override
 
virtual int exec ()
 exec This is main method of the service. Use this like a QCoreApplication::exec.
 

Protected Member Functions

void createApplication () override
 createApplication default implementation create a Application object.
 
- Protected Member Functions inherited from Patronum::ServiceBase
void handleReceiveData (const QHash< QString, Feature > &data) override
 handleReceiveData - This method invoice when service receive new command from terminal of controller of this service.
 
QSet< FeaturesupportedFeatures () override
 supportedFeatures
 
bool sendResuylt (const QVariantMap &result)
 sendResuylt - Call this method for send responce from service to tour controller.
 
bool sendResuylt (const QString &result)
 sendResuylt This method send text responce to controller.
 
bool sendRawResuylt (const QByteArray &result)
 sendRawResuylt This method send raw text responce to controller.
 
bool onStart () override=0
 onStart Called when get start command from terminal. Override this method work correctly work of service.
 
void onStop () override
 onStop Called when get stop command from terminal. The default implementation of this method invoke a quit method of QCoreApplication.
 
void onResume () override
 onResume Called when get resume command from terminal. The Default implementation do nothing.
 
void onPause () override
 onPause Called when get pause command from terminal. The Default implementation do nothing.
 
Controllercontroller ()
 controller This method return the local controller object. If the controller object is not inited the this methd create a new object.
 
QCoreApplication * core ()
 core This method return a pointer to instance of the core application.
 
void setCore (QCoreApplication *core)
 setCore This method sets new object of the core application.
 
- Protected Member Functions inherited from Patronum::IService
 IService ()
 
virtual ~IService ()=default
 
virtual bool handleReceive (const Feature &data)=0
 handleReceive This method invoked when service receive a request from terminal. Override this method for work your service.
 

Detailed Description

template<class Application>
class Patronum::Service< Application >

The Service class it is class for create a services from daemons.

How to use :

  • just inherit from the Service class and override the methods you need.

Example

#include <patronum.h>
class MyserviceApp : public Patronum::Service<QCoreApplication>
{
public:
MyserviceApp(int argc, char **argv):
Patronum::Service<QCoreApplication>(argc, argv) {
}
void onStart() override {
// call on server started
}
void onStop() override {
// call on server stoped
}
bool handleReceive(const Patronum::Feature &data) override {
if (data.cmd() == "ping") {
sendResuylt("Pong");
} else if (data.cmd() == "state") {
sendResuylt("application status");
}
return true;
}
QSet<Patronum::Feature> supportedFeatures() override {
QSet<Patronum::Feature> data;
data << Patronum::Feature("ping", "This is description of the ping command");
data << Patronum::Feature("state", "return state");
return data;
}
};
int main(int argc, char **argv) {
QCoreApplication::setApplicationName("MyServiceName"); // <--
QCoreApplication::setOrganizationName("MyCompany"); // <--
MyserviceApp app;
return app.exec();
}
The Feature class it is atomic type for describe service command.
Definition PFeature.h:22
QString cmd() const
cmd This method return command of the feature.
Definition PFeature.cpp:22
The Service class it is class for create a services from daemons.
Definition PService.h:88
The Patronum namespace - It is main name space of Patronum Library. The Patronum library support the ...
Note
The Service class use own executable like a main path to service executable. If your application has custom dependencies and do not work without costom envirement then you need to add P_RUN_FILE or CQT_RUN_FILE variavle with full path into the your wraper or launcher file. Order of the search executable file of the service
  1. P_RUN_FILE variable
  2. CQT_RUN_FILE variable
  3. Absalute path to executable.

Definition at line 87 of file PService.h.

Constructor & Destructor Documentation

◆ Service()

template<class Application >
Patronum::Service< Application >::Service ( int  argc,
char *  argv[] 
)
inline

Service This is main constructor of the service object.

Parameters
argcThis is count of input arguments.
argvThis is raw C array with input arguments.
nameThis is name of your service.
Note
If you create a console client for youe service then you need to sets some service name as a this.

Definition at line 97 of file PService.h.

◆ ~Service()

template<class Application >
Patronum::Service< Application >::~Service ( )
inlineoverride

Definition at line 105 of file PService.h.

Member Function Documentation

◆ createApplication()

template<class Application >
void Patronum::Service< Application >::createApplication ( )
inlineoverrideprotectedvirtual

createApplication default implementation create a Application object.

Implements Patronum::ServiceBase.

Definition at line 113 of file PService.h.

Here is the call graph for this function:

The documentation for this class was generated from the following file: