fix the d option

This commit is contained in:
Andrei Yankovich 2021-05-04 12:39:16 +03:00
parent 51bddbff8d
commit a7b22dac24
5 changed files with 26 additions and 8 deletions

View File

@ -58,10 +58,10 @@ void ServiceBase::handleReceiveData(const QSet<Feature> &data) {
}
if (commandList.size()) {
QStringList stringList;
QString stringList;
for (const auto&i : list) {
stringList += i.toString();
stringList += i.toString() + " ";
}
QVariantMap result;

View File

@ -60,6 +60,12 @@ public:
*/
virtual bool connectToTarget() = 0;
/**
* @brief isRunning This method shold be return true if the service is running else false.
* @return return true if the service is running else false.
*/
virtual bool isRunning() = 0;
State state() const;
protected:

View File

@ -7,6 +7,7 @@
#include "localsocket.h"
#include <QFile>
#include <QLocalServer>
#include <QLocalSocket>
#include <quasarapp.h>
@ -95,6 +96,10 @@ bool LocalSocket::connectToTarget() {
return m_socket->isValid();
}
bool LocalSocket::isRunning() {
return (m_server && m_server->isListening()) || QFile::exists(m_target);
}
void LocalSocket::handleStateChanged(QLocalSocket::LocalSocketState socketState) {
if (socketState == QLocalSocket::LocalSocketState::ConnectedState) {

View File

@ -34,14 +34,15 @@ public:
// ISocketWraper interface
public:
bool send(const QByteArray &data);
bool isValid() const;
bool listen();
bool connectToTarget();
bool send(const QByteArray &data) override;
bool isValid() const override;
bool listen() override;
bool connectToTarget() override;
bool isRunning() override;
signals:
void sigReceve(QByteArray data);
void sigStateChanged(State state);
void sigReceve(QByteArray data) override;
void sigStateChanged(State state) override;
private:
QLocalSocket *m_socket = nullptr;

View File

@ -120,6 +120,12 @@ bool ServicePrivate::start() {
}
bool ServicePrivate::startDeamon() {
if (_socket->isRunning()) {
QuasarAppUtils::Params::log("Failed to start a service because an another service alredy started",
QuasarAppUtils::Error);
return false;
}
QProcess proc;
proc.setProgram(QuasarAppUtils::Params::getCurrentExecutable());