mirror of
https://github.com/arcan1s/queued.git
synced 2025-07-06 10:25:50 +00:00
add demo application
This commit is contained in:
13
sources/queued-daemon/CMakeLists.txt
Normal file
13
sources/queued-daemon/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# set project name
|
||||
set (SUBPROJECT "queued-daemon")
|
||||
message (STATUS "Subproject ${SUBPROJECT}")
|
||||
|
||||
add_subdirectory ("src")
|
||||
# build man
|
||||
file (GLOB SUBPROJECT_MAN_IN "*.1")
|
||||
file (RELATIVE_PATH SUBPROJECT_MAN "${CMAKE_SOURCE_DIR}" "${SUBPROJECT_MAN_IN}")
|
||||
configure_file ("${SUBPROJECT_MAN_IN}" "${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_MAN}")
|
||||
|
||||
install (FILES "${CMAKE_CURRENT_BINARY_DIR}/${SUBPROJECT_MAN}" DESTINATION "${DATA_INSTALL_DIR}/man/man1")
|
||||
install (FILES "bash-completions" DESTINATION "${DATA_INSTALL_DIR}/bash-completion/completions" RENAME "${SUBPROJECT}")
|
||||
install (FILES "zsh-completions" DESTINATION "${DATA_INSTALL_DIR}/zsh/site-functions" RENAME "_${SUBPROJECT}")
|
0
sources/queued-daemon/bash-completions
Normal file
0
sources/queued-daemon/bash-completions
Normal file
0
sources/queued-daemon/queued-daemon.1
Normal file
0
sources/queued-daemon/queued-daemon.1
Normal file
11
sources/queued-daemon/queued.ini.example
Normal file
11
sources/queued-daemon/queued.ini.example
Normal file
@ -0,0 +1,11 @@
|
||||
[Administrator]
|
||||
Username = root
|
||||
Password = 0dd3e512642c97ca3f747f9a76e374fbda73f9292823c0313be9d78add7cdd8f72235af0c553dd26797e78e1854edee0ae002f8aba074b066dfce1af114e32f8
|
||||
|
||||
[Database]
|
||||
Driver = QSQLITE
|
||||
Hostname =
|
||||
Password =
|
||||
Path = /tmp/queued.db
|
||||
Port =
|
||||
Username =
|
18
sources/queued-daemon/src/CMakeLists.txt
Normal file
18
sources/queued-daemon/src/CMakeLists.txt
Normal file
@ -0,0 +1,18 @@
|
||||
# set files
|
||||
file (GLOB_RECURSE SUBPROJECT_SOURCES "*.cpp")
|
||||
file (GLOB_RECURSE SUBPROJECT_HEADERS "*.h")
|
||||
|
||||
# include_path
|
||||
include_directories ("${PROJECT_LIBRARY_DIR}/include"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
"${CMAKE_BINARY_DIR}"
|
||||
"${PROJECT_TRDPARTY_DIR}"
|
||||
"${Qt_INCLUDE}")
|
||||
|
||||
qt5_wrap_cpp (SUBPROJECT_MOC_SOURCES "${SUBPROJECT_HEADERS}")
|
||||
|
||||
add_executable ("${SUBPROJECT}" "${SUBPROJECT_HEADERS}" "${SUBPROJECT_SOURCES}"
|
||||
"${SUBPROJECT_MOC_SOURCES}")
|
||||
target_link_libraries ("${SUBPROJECT}" "${PROJECT_LIBRARY}" "${Qt_LIBRARIES}")
|
||||
# install properties
|
||||
install (TARGETS "${SUBPROJECT}" DESTINATION "${BIN_INSTALL_DIR}")
|
87
sources/queued-daemon/src/QueuedApplication.cpp
Normal file
87
sources/queued-daemon/src/QueuedApplication.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
|
||||
#include "QueuedApplication.h"
|
||||
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include "queued/Queued.h"
|
||||
|
||||
#include "QueuedApplicationInterface.h"
|
||||
|
||||
|
||||
QueuedApplication::QueuedApplication(QObject *parent, const QVariantHash &args)
|
||||
: QObject(parent)
|
||||
, m_configuration(args)
|
||||
{
|
||||
qSetMessagePattern(QueuedDebug::LOG_FORMAT);
|
||||
qCDebug(LOG_APP) << __PRETTY_FUNCTION__;
|
||||
for (auto &metadata : QueuedDebug::getBuildData())
|
||||
qCDebug(LOG_APP) << metadata;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
QueuedApplication::~QueuedApplication()
|
||||
{
|
||||
qCDebug(LOG_APP) << __PRETTY_FUNCTION__;
|
||||
|
||||
deinit();
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::deinit()
|
||||
{
|
||||
QDBusConnection::sessionBus().unregisterObject(
|
||||
QueuedConfig::DBUS_APPLICATION_PATH);
|
||||
|
||||
if (m_core)
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::init()
|
||||
{
|
||||
deinit();
|
||||
|
||||
initCore();
|
||||
initDBus();
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::initCore()
|
||||
{
|
||||
m_core = new QueuedCore(this);
|
||||
// init objects
|
||||
m_core->init(m_configuration[QString("config")].toString());
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplication::initDBus()
|
||||
{
|
||||
QDBusConnection bus = QDBusConnection::systemBus();
|
||||
|
||||
if (!bus.registerObject(QueuedConfig::DBUS_APPLICATION_PATH,
|
||||
new QueuedApplicationInterface(this),
|
||||
QDBusConnection::ExportAllContents)) {
|
||||
QString message = QString("Could not register application object %1")
|
||||
.arg(bus.lastError().message());
|
||||
qCCritical(LOG_DBUS) << message;
|
||||
throw QueuedDBusException(message);
|
||||
}
|
||||
}
|
47
sources/queued-daemon/src/QueuedApplication.h
Normal file
47
sources/queued-daemon/src/QueuedApplication.h
Normal file
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDAPPLICATION_H
|
||||
#define QUEUEDAPPLICATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
|
||||
class QueuedCore;
|
||||
|
||||
class QueuedApplication : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit QueuedApplication(QObject *parent, const QVariantHash &args);
|
||||
virtual ~QueuedApplication();
|
||||
void deinit();
|
||||
void init();
|
||||
|
||||
private:
|
||||
// backend
|
||||
void initDBus();
|
||||
void initCore();
|
||||
// library
|
||||
QueuedCore *m_core = nullptr;
|
||||
// configuration
|
||||
QVariantHash m_configuration;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDAPPLICATION_H */
|
61
sources/queued-daemon/src/QueuedApplicationInterface.cpp
Normal file
61
sources/queued-daemon/src/QueuedApplicationInterface.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
|
||||
#include "QueuedApplicationInterface.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "queued/Queued.h"
|
||||
|
||||
#include "QueuedApplication.h"
|
||||
|
||||
|
||||
QueuedApplicationInterface::QueuedApplicationInterface(
|
||||
QueuedApplication *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
, m_application(parent)
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
QueuedApplicationInterface::~QueuedApplicationInterface()
|
||||
{
|
||||
qCDebug(LOG_DBUS) << __PRETTY_FUNCTION__;
|
||||
}
|
||||
|
||||
|
||||
bool QueuedApplicationInterface::Active() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void QueuedApplicationInterface::Close() const
|
||||
{
|
||||
return QCoreApplication::exit(0);
|
||||
}
|
||||
|
||||
|
||||
QStringList QueuedApplicationInterface::UIDs() const
|
||||
{
|
||||
QStringList uids;
|
||||
uids.append(QString::number(getuid()));
|
||||
uids.append(QString::number(geteuid()));
|
||||
|
||||
return uids;
|
||||
}
|
46
sources/queued-daemon/src/QueuedApplicationInterface.h
Normal file
46
sources/queued-daemon/src/QueuedApplicationInterface.h
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef QUEUEDAPPLICATIONINTERFACE_H
|
||||
#define QUEUEDAPPLICATIONINTERFACE_H
|
||||
|
||||
#include <QDBusAbstractAdaptor>
|
||||
|
||||
#include "QueuedConfig.h"
|
||||
|
||||
|
||||
class QueuedApplication;
|
||||
|
||||
class QueuedApplicationInterface : public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", DBUS_SERVICE_NAME)
|
||||
|
||||
public:
|
||||
explicit QueuedApplicationInterface(QueuedApplication *parent);
|
||||
virtual ~QueuedApplicationInterface();
|
||||
|
||||
public slots:
|
||||
bool Active() const;
|
||||
Q_NOREPLY void Close() const;
|
||||
QStringList UIDs() const;
|
||||
|
||||
private:
|
||||
QueuedApplication *m_application = nullptr;
|
||||
};
|
||||
|
||||
|
||||
#endif /* QUEUEDAPPLICATIONINTERFACE_H */
|
85
sources/queued-daemon/src/main.cpp
Normal file
85
sources/queued-daemon/src/main.cpp
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright (c) 2016 Evgeniy Alekseev
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
*
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*/
|
||||
|
||||
|
||||
#include <QCommandLineParser>
|
||||
#include <QCoreApplication>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusMessage>
|
||||
|
||||
#include <queued/Queued.h>
|
||||
|
||||
#include "QueuedApplication.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
bool existingSessionOperation(const QString &operation)
|
||||
{
|
||||
QVariantList arguments = QueuedCoreAdaptor::sendRequest(
|
||||
QueuedConfig::DBUS_SERVICE, QueuedConfig::DBUS_APPLICATION_PATH,
|
||||
QueuedConfig::DBUS_SERVICE, operation, QVariantList());
|
||||
|
||||
return (!arguments.isEmpty() && arguments.at(0).type() == QVariant::Bool
|
||||
&& arguments[0].toBool());
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
// daemon(0, 0);
|
||||
|
||||
QCoreApplication app(argc, argv);
|
||||
app.setApplicationName(NAME);
|
||||
app.setApplicationVersion(VERSION);
|
||||
|
||||
// parser
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(
|
||||
"Daemon for starting jobs to queue of calculations");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
|
||||
// configuration option
|
||||
QCommandLineOption configOption(QStringList() << "c"
|
||||
<< "config",
|
||||
"Read initial configuration from file",
|
||||
"config", QueuedSettings::defaultPath());
|
||||
parser.addOption(configOption);
|
||||
|
||||
// debug mode
|
||||
QCommandLineOption debugOption(QStringList() << "d"
|
||||
<< "debug",
|
||||
"Print debug information");
|
||||
parser.addOption(debugOption);
|
||||
|
||||
parser.process(app);
|
||||
|
||||
// check if exists
|
||||
if (existingSessionOperation(QString("Active"))) {
|
||||
qCWarning(LOG_APP) << "Another session is active";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// enable debug
|
||||
if (parser.isSet(debugOption))
|
||||
QueuedDebug::enableDebug();
|
||||
|
||||
// build initial options hash
|
||||
QVariantHash arguments = {{"config", parser.value(configOption)}};
|
||||
|
||||
// start application
|
||||
QueuedApplication instance(nullptr, arguments);
|
||||
return app.exec();
|
||||
}
|
0
sources/queued-daemon/zsh-completions
Normal file
0
sources/queued-daemon/zsh-completions
Normal file
Reference in New Issue
Block a user