add demo application

This commit is contained in:
2017-03-05 03:20:09 +03:00
parent 6646400027
commit 84b8632ae8
30 changed files with 906 additions and 123 deletions

View 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}")

View File

View File

View File

@ -0,0 +1,11 @@
[Administrator]
Username = root
Password = 0dd3e512642c97ca3f747f9a76e374fbda73f9292823c0313be9d78add7cdd8f72235af0c553dd26797e78e1854edee0ae002f8aba074b066dfce1af114e32f8
[Database]
Driver = QSQLITE
Hostname =
Password =
Path = /tmp/queued.db
Port =
Username =

View 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}")

View 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);
}
}

View 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 */

View 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;
}

View 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 */

View 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();
}

View File