1 #ifndef QTSERVICE_SERVICE_H 2 #define QTSERVICE_SERVICE_H 6 #include <QtCore/qobject.h> 7 #include <QtCore/qcoreapplication.h> 8 #include <QtCore/qdir.h> 9 #include <QtCore/qscopedpointer.h> 10 #include <QtCore/qvector.h> 11 #include <QtCore/qhash.h> 12 #include <QtCore/qvariant.h> 14 #include "QtService/qtservice_global.h" 15 #include "QtService/qtservice_helpertypes.h" 19 # define QT_SERVICE_POST_ENUM_DEPRECATED 21 # define QT_SERVICE_POST_ENUM_DEPRECATED Q_DECL_DEPRECATED 23 # define QT_SERVICE_POST_USING_DEPRECATED Q_DECL_DEPRECATED 25 # define QT_SERVICE_POST_ENUM_DEPRECATED 26 # define QT_SERVICE_POST_USING_DEPRECATED 42 Q_PROPERTY(
QString backend READ backend CONSTANT)
44 Q_PROPERTY(
QDir runtimeDir READ runtimeDir CONSTANT)
47 Q_PROPERTY(
bool terminalActive READ isTerminalActive WRITE setTerminalActive NOTIFY terminalActiveChanged)
49 Q_PROPERTY(
TerminalMode terminalMode READ terminalMode WRITE setTerminalMode NOTIFY terminalModeChanged)
51 Q_PROPERTY(
bool globalTerminal READ isGlobalTerminal WRITE setGlobalTerminal NOTIFY globalTerminalChanged)
53 Q_PROPERTY(
bool startWithTerminal READ startWithTerminal WRITE setStartWithTerminal NOTIFY startWithTerminalChanged)
65 Synchronous QT_SERVICE_POST_ENUM_DEPRECATED = OperationCompleted,
66 Asynchronous QT_SERVICE_POST_ENUM_DEPRECATED = OperationPending
69 using CommandMode QT_SERVICE_POST_USING_DEPRECATED = CommandResult;
73 #pragma deprecated(CommandMode) 74 #pragma deprecated(Synchronous) 75 #pragma deprecated(Asynchronous) 88 explicit Service(
int &argc,
char **argv,
int = QCoreApplication::ApplicationFlags);
100 Q_INVOKABLE
int getSocket();
105 QDir runtimeDir()
const;
107 bool isTerminalActive()
const;
109 TerminalMode terminalMode()
const;
111 bool isGlobalTerminal()
const;
113 bool startWithTerminal()
const;
122 void setTerminalActive(
bool terminalActive);
124 void setTerminalMode(TerminalMode terminalMode);
126 void setGlobalTerminal(
bool globalTerminal);
128 void setStartWithTerminal(
bool startWithTerminal);
132 void started(
bool success);
134 Q_DECL_DEPRECATED
void started();
136 void stopped(
int exitCode = EXIT_SUCCESS);
138 void reloaded(
bool success);
140 Q_DECL_DEPRECATED
void reloaded();
142 void paused(
bool success);
144 Q_DECL_DEPRECATED
void paused();
146 void resumed(
bool success);
148 Q_DECL_DEPRECATED
void resumed();
151 void terminalActiveChanged(
bool terminalActive, QPrivateSignal);
153 void terminalModeChanged(TerminalMode terminalMode, QPrivateSignal);
155 void globalTerminalChanged(
bool globalTerminal, QPrivateSignal);
157 void startWithTerminalChanged(
bool startWithTerminal, QPrivateSignal);
161 virtual void terminalConnected(
Terminal *terminal);
165 virtual bool preStart();
168 virtual CommandResult onStart() = 0;
170 virtual CommandResult onStop(
int &exitCode);
172 virtual CommandResult onReload();
174 virtual CommandResult onPause();
176 virtual CommandResult onResume();
182 virtual bool verifyCommand(
const QStringList &arguments);
185 void addCallback(
const QByteArray &kind,
const std::function<
QVariant(QVariantList)> &fn);
187 template <
typename TFunction>
188 void addCallback(
const QByteArray &kind,
const TFunction &fn);
190 template <
typename TClass,
typename TReturn,
typename... TArgs>
191 void addCallback(
const QByteArray &kind, TReturn(TClass::*fn)(TArgs...), std::enable_if_t<std::is_base_of<QtService::Service, TClass>::value,
void*> =
nullptr);
195 friend class QtService::ServicePrivate;
196 friend class QtService::TerminalClient;
201 template<
typename TFunction>
204 addCallback(kind, __helpertypes::pack_function(fn));
207 template<
typename TClass,
typename TReturn,
typename... TArgs>
210 auto self =
static_cast<TClass*
>(
this);
211 addCallback(kind, [
self, fn](TArgs... args) -> TReturn {
212 return (self->*fn)(args...);
219 #define qService QtService::Service::instance() 222 #endif // QTSERVICE_SERVICE_H CommandResult
Indicates whether a service command has finished or needs to run asynchronously.
TerminalMode
The modes a terminal can be in.
The terminal can only receive data from the service. Useful for machine-to-machine communication...
void addCallback(const QByteArray &kind, const std::function< QVariant(QVariantList)> &fn)
Adds a callback to be called by onCallback for the given kind.
The main interface to implement to create a service.
The command executed successfully, but the service should still exit. Only usable from onStart() ...
The primary namespace of the QtService library.
Represents a connection to a console terminal connected to the service.
The interface that needs to be implemented to provide the backend for the service engine...
The command failed synchronously. The system may exit the service afterwards.
The command was successfully completed synchronously.
The terminal can read and write as much as it wants. Useful for machine-to-machine communication...
The command is beeing proccessed asynchronously and the service will emit the corresponding signal on...
The terminal can only send data to the service. Useful for machine-to-machine communication.