mirror of
https://github.com/QuasarApp/Patronum.git
synced 2025-05-12 23:19:34 +00:00
fix internal controller of service
This commit is contained in:
parent
e79ee705f0
commit
682345f2a9
Patronum/src
Tests
@ -9,6 +9,7 @@ ServiceBase::ServiceBase(int argc, char *argv[], const QString &name) {
|
||||
QuasarAppUtils::Params::parseParams(argc, argv);
|
||||
d_ptr = new ServicePrivate(name, this);
|
||||
_serviceName = name;
|
||||
|
||||
}
|
||||
|
||||
ServiceBase::~ServiceBase() {
|
||||
@ -85,8 +86,9 @@ int ServiceBase::exec() {
|
||||
return static_cast<int>(ControllerError::ServiceUnavailable);
|
||||
}
|
||||
|
||||
d_ptr->listen();
|
||||
|
||||
if (!_core) {
|
||||
createApplication();
|
||||
return _core->exec();
|
||||
}
|
||||
|
||||
|
@ -13,13 +13,6 @@ Patronum::ServicePrivate::ServicePrivate(const QString &name, IService *service,
|
||||
QObject(parent) {
|
||||
_socket = new LocalSocket(name, this);
|
||||
|
||||
QTimer::singleShot(0, [this](){
|
||||
if (!_socket->listen()) {
|
||||
QuasarAppUtils::Params::log("Fail to create a terminal socket!");
|
||||
QCoreApplication::exit(1);
|
||||
};
|
||||
});
|
||||
|
||||
_service = service;
|
||||
|
||||
QObject::connect(_socket, &LocalSocket::sigReceve,
|
||||
@ -38,6 +31,15 @@ bool ServicePrivate::sendCmdResult(const QVariantMap &result) {
|
||||
return _socket->send(Package::createPackage(Command::FeatureResponce, result));
|
||||
}
|
||||
|
||||
void ServicePrivate::listen() const {
|
||||
QTimer::singleShot(0, [this](){
|
||||
if (!_socket->listen()) {
|
||||
QuasarAppUtils::Params::log("Fail to create a terminal socket!");
|
||||
QCoreApplication::exit(1);
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
bool ServicePrivate::hendleStandartCmd(QList<Feature> *cmds) {
|
||||
|
||||
if (!cmds)
|
||||
|
@ -18,6 +18,8 @@ public:
|
||||
bool sendCmdResult(const QVariantMap& result);
|
||||
bool parseDefaultCmds();
|
||||
|
||||
void listen() const;
|
||||
|
||||
private:
|
||||
LocalSocket *_socket = nullptr;
|
||||
IService *_service = nullptr;
|
||||
|
@ -1,13 +1,15 @@
|
||||
#include "defaultservice.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
char* arg[] = {
|
||||
const_cast<char*>("/"),
|
||||
const_cast<char*>("exec")
|
||||
};
|
||||
int argc = 2;
|
||||
|
||||
DefaultService::DefaultService():
|
||||
Patronum::Service<QCoreApplication>(2, arg, "TestPatronum") {
|
||||
|
||||
_core = new QCoreApplication(argc, arg);
|
||||
}
|
||||
|
||||
void DefaultService::onStart() {
|
||||
|
@ -65,7 +65,7 @@ void testPatronum::testRandomCommad() {
|
||||
void testPatronum::connectTest() {
|
||||
DefaultService serv;
|
||||
|
||||
QTimer::singleShot(0, [this]() {
|
||||
QTimer::singleShot(10, [this]() {
|
||||
testRandomCommad();
|
||||
testPing();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user