Commit 118ed432216958bda82d2b90c9bcf2de6e124dad
1 parent
71c0c105
Exists in
master
Implementação do serviço (daemon) CacicD para linux e windows.
Showing
3 changed files
with
93 additions
and
23 deletions
Show diff stats
cacicD/cacicd.cpp
1 | 1 | #include "cacicd.h" |
2 | 2 | |
3 | -cacicD::cacicD() | |
3 | +cacicD::cacicD(int argc, char **argv) : QtService<QCoreApplication>(argc, argv, "CacicD") | |
4 | 4 | { |
5 | + try{ | |
6 | + setServiceDescription("Cacic Daemon"); | |
7 | + setServiceFlags(QtServiceBase::CannotBeStopped); | |
8 | + } catch (...){ | |
9 | + qCritical() << "Error desconhecido no construtor."; | |
10 | + } | |
11 | +} | |
12 | + | |
13 | +cacicD::~cacicD() | |
14 | +{ | |
15 | + try{ | |
16 | + | |
17 | + } catch (...){ | |
18 | + qCritical() << "Error desconhecido no desconstrutor."; | |
19 | + } | |
20 | +} | |
21 | + | |
22 | +void cacicD::start() | |
23 | +{ | |
24 | + try{ | |
25 | + QCoreApplication *app = application(); | |
26 | + qDebug() << "Serviço iniciado."; | |
27 | + qDebug() << app->applicationDirPath(); | |
28 | + | |
29 | + } catch (...){ | |
30 | + qCritical() << "Error desconhecido no desconstrutor."; | |
31 | + } | |
32 | +} | |
33 | + | |
34 | +void cacicD::pause() | |
35 | +{ | |
36 | + try{ | |
37 | + qDebug() << "Serviço pausado."; | |
38 | + } catch (...){ | |
39 | + qCritical() << "Error desconhecido ao pausar o serviço."; | |
40 | + } | |
41 | +} | |
42 | + | |
43 | +void cacicD::resume() | |
44 | +{ | |
45 | + try{ | |
46 | + qDebug() << "Serviço resumido."; | |
47 | + } catch (...){ | |
48 | + qCritical() << "Error desconhecido ao resumir o serviço."; | |
49 | + } | |
50 | +} | |
51 | + | |
52 | +void cacicD::stop() | |
53 | +{ | |
54 | + try{ | |
55 | + qDebug() << "Serviço parado."; | |
56 | + } catch (...){ | |
57 | + qCritical() << "Error desconhecido ao parar o serviço."; | |
58 | + } | |
5 | 59 | } | ... | ... |
cacicD/cacicd.h
1 | 1 | #ifndef CACICD_H |
2 | 2 | #define CACICD_H |
3 | 3 | |
4 | -class cacicD | |
4 | +#include <QCoreApplication> | |
5 | +#include <QObject> | |
6 | +#include <QDebug> | |
7 | +#include "qtservice.h" | |
8 | + | |
9 | + | |
10 | +class cacicD : public QtService<QCoreApplication> | |
5 | 11 | { |
6 | 12 | public: |
7 | - cacicD(); | |
13 | + /** | |
14 | + * @brief cacicD Construtor | |
15 | + * @param argc | |
16 | + * @param argv | |
17 | + */ | |
18 | + cacicD(int argc, char **argv); | |
19 | + /** | |
20 | + * @brief cacicD Desconstrutor | |
21 | + */ | |
22 | + ~cacicD(); | |
23 | + /** | |
24 | + * @brief inicia o serviço | |
25 | + */ | |
26 | + void start(); | |
27 | + /** | |
28 | + * @brief pausa o serviço | |
29 | + */ | |
30 | + void pause(); | |
31 | + /** | |
32 | + * @brief resume a execução do serviço | |
33 | + */ | |
34 | + void resume(); | |
35 | + /** | |
36 | + * @brief para a execução do serviço | |
37 | + */ | |
38 | + void stop(); | |
39 | + | |
40 | + | |
8 | 41 | }; |
9 | 42 | |
10 | 43 | #endif // CACICD_H | ... | ... |
cacicD/main.cpp
1 | 1 | #include <QCoreApplication> |
2 | -#include <QStringList> | |
3 | -#include <QDir> | |
4 | -#include <QSettings> | |
5 | -#include <qtservice/src/qtservice.h> | |
2 | +#include "cacicd.h" | |
6 | 3 | |
7 | 4 | int main(int argc, char **argv) |
8 | 5 | { |
9 | -#if !defined(Q_OS_WIN) | |
10 | - QSettings::setPath(QSettings::NativeFormat, QSettings::SystemScope, QDir::tempPath()); | |
11 | - qWarning("(Example uses dummy settings file: %s/QtSoftware.conf)", QDir::tempPath().toLatin1().constData()); | |
12 | -#endif | |
13 | - //int result = processArgs(argc, argv); | |
14 | - if (QString::fromLocal8Bit(argv[argc-1]) == QLatin1String("-w") || | |
15 | - QString::fromLocal8Bit(argv[argc-1]) == QLatin1String("-wait")) { | |
16 | - printf("\nPress Enter to continue..."); | |
17 | - QFile input; | |
18 | - input.open(stdin, QIODevice::ReadOnly); | |
19 | - input.readLine(); | |
20 | - printf("\n"); | |
21 | - } | |
22 | - //return result; | |
6 | + cacicD sevice(argc, argv); | |
7 | + return sevice.exec(); | |
23 | 8 | } |
24 | - | |
25 | - | ... | ... |