start working on C++ implementation

This commit is contained in:
2017-02-20 03:09:21 +03:00
parent f745595174
commit 6bc4668271
28 changed files with 3140 additions and 1181 deletions

66
sources/.clang-format Normal file
View File

@ -0,0 +1,66 @@
---
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: true
AlignConsecutiveAssignments: false
AlignEscapedNewlinesLeft: false
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: false
BinPackArguments: true
BinPackParameters: true
BreakBeforeBinaryOperators: All
BreakBeforeBraces: Linux
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
IndentCaseLabels: false
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...

79
sources/CMakeLists.txt Normal file
View File

@ -0,0 +1,79 @@
cmake_minimum_required(VERSION 2.8.12)
# some fucking magic
cmake_policy(SET CMP0003 OLD)
cmake_policy(SET CMP0002 OLD)
cmake_policy(SET CMP0011 NEW)
cmake_policy(SET CMP0015 NEW)
if (POLICY CMP0063)
cmake_policy(SET CMP0063 OLD)
endif ()
project(awesomewidgets)
set(PROJECT_AUTHOR "Evgeniy Alekseev")
set(PROJECT_CONTACT "esalexeev@gmail.com")
set(PROJECT_LICENSE "MIT")
set(PROJECT_VERSION_MAJOR "0")
set(PROJECT_VERSION_MINOR "9")
set(PROJECT_VERSION_PATCH "0")
set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
# append git version if any
set(PROJECT_COMMIT_SHA "Commit hash" CACHE INTERNAL "")
include(checkgit.cmake)
string(TIMESTAMP CURRENT_DATE "%Y-%m-%d %H:%M" UTC)
string(TIMESTAMP CURRENT_YEAR "%Y")
message(STATUS "Project: ${PROJECT_NAME}")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "Build date: ${CURRENT_DATE}")
# components
option(BUILD_DEB_PACKAGE "Build deb package" OFF)
option(BUILD_RPM_PACKAGE "Build rpm package" OFF)
# build details
option(BUILD_FUTURE "Build with the features which will be marked as stable later" OFF)
option(BUILD_LOAD "Build with additional load" OFF)
option(BUILD_TESTING "Build with additional test abilities" OFF)
# flags
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "-Wall -Wno-cpp -std=c++11")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
# avoid newer gcc warnings
add_definitions(-D_DEFAULT_SOURCE)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "-Wall -std=c++11 -stdlib=libc++")
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_CXX_FLAGS_OPTIMIZATION "-Ofast -DNDEBUG")
# linker flags
set(CMAKE_EXE_LINKER_FLAGS "-lc++abi")
set(CMAKE_MODULE_LINKER_FLAGS "-lc++abi")
set(CMAKE_SHARED_LINKER_FLAGS "-lc++abi")
else ()
message(FATAL_ERROR "Unknown compiler")
endif ()
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif ()
set(PROJECT_TRDPARTY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty)
set(PROJECT_LIBRARY "queued")
set(PROJECT_LIBRARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_LIBRARY}")
include(libraries.cmake)
include(clang-format.cmake)
include(cppcheck.cmake)
include(paths.cmake)
get_directory_property(CMAKE_DEFINITIONS COMPILE_DEFINITIONS)
configure_file(${CMAKE_SOURCE_DIR}/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/version.h)
add_subdirectory(queued)
if (BUILD_TESTING)
enable_testing()
add_subdirectory(test)
endif ()

View File

@ -1,92 +0,0 @@
#!/bin/bash
# queued is a simple daemon for starting jobs to queue of calculations
# Copyright (C) 2013 Evgeniy Alekseev
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see http://www.gnu.org/licenses
# or write to the Free Software Foundation,Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301 USA
# functions
error_mes() {
case "$1" in
"config" ) echo "[EE] Configuration file is not set";;
"notfound" ) echo "[EE] File '$2' not found";;
"number" ) echo "[EE] '$2' is not a number";;
"priority" ) echo "[EE] Priority is not set";;
"unknown" ) echo "[EE] Unknown error";;
"user" ) echo "[EE] User is not set";;
esac
exit 1
}
func_help() {
echo -e "Script to add job for queued"
echo -e "\nUsage: add_queued [ -c /etc/queued.conf ] [ -p NUM ] [ -u USER ] [ -h | --help ] /path/to/script"
echo -e "\nParameters:"
echo -e " -c PATH - path to configuration file. Default is '/etc/queued.conf'"
echo -e " -p NUM - job priority"
echo -e " -u USER - username"
echo -e " -h --help - show this help and exit"
exit 0
}
isnum() {
(t=$(( 0$1+0 ))) 2>/dev/null
}
CONF_FILE="/etc/queued.conf"
# parametrs parsing
until [ -z $1 ]; do
case "$1" in
"-h" | "--help" ) func_help;;
"-c" ) [ -z "$2" ] && error_mes "config" || CONF_FILE="$2" && shift;;
"-p" ) [ -z "$2" ] && error_mes "priority" || JOB_PRIORITY="$2" && shift;;
"-u" ) [ -z "$2" ] && error_mes "user" || JOB_USER="$2" && shift;;
* ) JOB_SCRIPT="$1";;
esac
shift
done
# default values
WORKDIR="/var/lib/queued/work"
echo "[II] Reading configuration from '$CONF_FILE'"
[ -e "$CONF_FILE" ] || error_mes "notfound" "$CONF_FILE"
for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done
# error check
if [ ! -d "$WORKDIR" ]; then
[ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR"
echo "[II] Creating directory '$WORKDIR'"
mkdir -m777 -p "$WORKDIR" || error_mes "unknown"
fi
if [ ! -z "$JOB_PRIORITY" ]; then
isnum "$JOB_PRIORITY" || error_mes "number" "$JOB_PRIORITY"
fi
[ -z "$JOB_SCRIPT" ] && error_mes "notfound" "$JOB_SCRIPT"
[ -e "$JOB_SCRIPT" ] || error_mes "notfound" "$JOB_SCRIPT"
# work block
if [ -e "$WORKDIR/$(basename "$JOB_SCRIPT")" ]; then
echo "[WW] File '$WORKDIR/$(basename "$JOB_SCRIPT")' already exists. Creating backup"
mv "$WORKDIR/$(basename "$JOB_SCRIPT")" "$WORKDIR/$(basename "$JOB_SCRIPT")-$(date +%Y%m%d-%N)" || error_mes "unknown"
fi
echo "[II] Copying '$JOB_SCRIPT' to '$WORKDIR'"
cp --archive "$JOB_SCRIPT" "$WORKDIR" || error_mes "unknown"
if [ ! -z "$JOB_PRIORITY" ]; then
echo "$JOB_PRIORITY" > "$WORKDIR/$(basename "$JOB_SCRIPT").pr" || error_mes "unknown"
fi
if [ ! -z "$JOB_USER" ]; then
echo "$JOB_USER" > "$WORKDIR/$(basename "$JOB_SCRIPT").user" || error_mes "unknown"
fi
exit 0

View File

@ -1,32 +0,0 @@
.TH add_queued 1 "December 24, 2013" "version 1.2.0" "USER COMMANDS"
.SH NAME
add_queued
.SH SYNOPSIS
.B add_queued
[ -c /etc/queued.conf ] [ -p NUM ] [ -u USER ] [ -h | --help ] /path/to/script
.SH DESCRIPTION
.B add_queued
is a script to add job for
.BR queued (1)
.SH OPTIONS
.TP
/path/to/script
Path to the job script
.TP
-c /etc/queued.conf
Full path to configuration file. Default is
.B /etc/queued.conf.
.TP
-p NUM
priority of the job
.TP
-u USER
username for the job running
.TP
-h, --help
Show help and exit.
.SH SEE ALSO
.BR queued (1)
.BR queued.conf (5)
.SH AUTHOR
Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>

11
sources/checkgit.cmake Normal file
View File

@ -0,0 +1,11 @@
exec_program(
"git"
${CMAKE_CURRENT_SOURCE_DIR}
ARGS "log" "-1" "--format=\"%h\""
OUTPUT_VARIABLE COMMIT_SHA
RETURN_VALUE GIT_RETURN
)
if (${GIT_RETURN} EQUAL "0")
set(PROJECT_COMMIT_SHA "${COMMIT_SHA}")
endif ()

View File

@ -0,0 +1,19 @@
# additional target to perform clang-format run, requires clang-format
set(CLANGFORMAT_EXECUTABLE "/usr/bin/clang-format" CACHE STRING "Path to clang-format executable")
# get all project files
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h *.h.in)
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
string(FIND ${SOURCE_FILE} ${PROJECT_TRDPARTY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
endif ()
endforeach ()
add_custom_target(
clangformat
COMMAND ${CLANGFORMAT_EXECUTABLE}
-style=file
-i
${ALL_SOURCE_FILES}
)

25
sources/cppcheck.cmake Normal file
View File

@ -0,0 +1,25 @@
# additional target to perform cppcheck run, requires cppcheck
set(CPPCHECK_EXECUTABLE "/usr/bin/cppcheck" CACHE STRING "Path to cppcheck executable")
# get all project files
# HACK this workaround is required to avoid qml files checking ^_^
file(GLOB_RECURSE ALL_SOURCE_FILES *.cpp *.h)
foreach (SOURCE_FILE ${ALL_SOURCE_FILES})
string(FIND ${SOURCE_FILE} ${PROJECT_TRDPARTY_DIR} PROJECT_TRDPARTY_DIR_FOUND)
if (NOT ${PROJECT_TRDPARTY_DIR_FOUND} EQUAL -1)
list(REMOVE_ITEM ALL_SOURCE_FILES ${SOURCE_FILE})
endif ()
endforeach ()
add_custom_target(
cppcheck
COMMAND ${CPPCHECK_EXECUTABLE}
--enable=warning,performance,portability,information,missingInclude
--std=c++11
--language=c++
--library=qt.cfg
--template="[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)"
--verbose
--quiet
${ALL_SOURCE_FILES}
)

12
sources/libraries.cmake Normal file
View File

@ -0,0 +1,12 @@
# main qt libraries
find_package(Qt5 5.6.0 REQUIRED COMPONENTS Core DBus Test)
add_definitions(
${Qt5Core_DEFINITIONS} ${Qt5DBus_DEFINITIONS}
)
set(Qt_INCLUDE
${Qt5Core_INCLUDE_DIRS} ${Qt5DBus_INCLUDE_DIRS}
)
set(Qt_LIBRARIES
${Qt5Core_LIBRARIES} ${Qt5DBus_LIBRARIES}
)

5
sources/paths.cmake Normal file
View File

@ -0,0 +1,5 @@
# paths
set(BIN_INSTALL_DIR "bin" CACHE STRING "Installation directory for executables")
set(DATA_INSTALL_DIR "share" CACHE STRING "Installation directory for data")
set(INCLUDE_INSTALL_DIR "include" CACHE STRING "Installation directory for headers")
set(LIB_INSTALL_DIR "lib" CACHE STRING "Installation directory for libraries")

View File

@ -1,165 +0,0 @@
#!/bin/bash
# queued is a simple daemon for starting jobs to queue of calculations
# Copyright (C) 2013 Evgeniy Alekseev
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see http://www.gnu.org/licenses
# or write to the Free Software Foundation,Inc., 51 Franklin Street,
# Fifth Floor, Boston, MA 02110-1301 USA
# functions
error_mes() {
case "$1" in
"config" ) echo "[EE] Configuration file is not set";;
"file" ) echo "[EE] '$2' is a file";;
"flag" ) echo "[EE] Unknown flag";;
"number" ) echo "[EE] '$2' is not a number";;
"unknown" ) echo "[EE] Unknown error";;
esac
exit 1
}
func_help() {
echo -e "Simple daemon written on BASH for starting jobs to queue of calculations"
echo -e "\nUsage: queued [ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]"
echo -e "\nParametrs:"
echo -e " -c PATH - path to configuration file. Default is '/etc/queued.conf'"
echo -e "\n -v --version - show version and exit"
echo -e " -h --help - show this help and exit"
exit 0
}
func_ver() {
echo -e " queued "
echo -e "Simple daemon for starting jobs to queue of calculations"
echo -e "Version : 1.2.0 License : GPLv3"
echo -e "Author : Evgeniy Alexeev aka arcanis"
echo -e "E-mail : esalexeev (at) gmail.com"
exit 0
}
isnum() {
(t=$(( 0$1+0 ))) 2>/dev/null
}
start_job() {
echo "[II] Running job '$CURJOB' (priority '$CURJOB_PRIOR') as '$CURJOB_USER'"
su -c "/bin/sh "$JOBDIR/$(basename "$CURJOB")" &> "$JOBDIR/$(basename "$CURJOB")".log" $CURJOB_USER &
}
CONF_FILE="/etc/queued.conf"
# parametrs parsing
until [ -z $1 ]; do
case "$1" in
"-h" | "--help" ) func_help;;
"-v" | "--version" ) func_ver;;
"-c" ) [ -z "$2" ] && error_mes "config" || CONF_FILE="$2" && shift;;
* ) error_mes "flag";;
esac
shift
done
# default values
JOBDIR="/var/lib/queued/job"
PRIORITY=0
QUEUEFILE="/var/lib/queued/queue"
SLEEPTIME=5
STARTASUSER="root"
WORKDIR="/var/lib/queued/work"
echo "[II] Reading configuration from '$CONF_FILE'"
[ -e "$CONF_FILE" ] || error_mes "config"
for VAR in "$(cat "$CONF_FILE")"; do eval "$VAR"; done
# prepare
# creating directories if doesn't exist
if [ ! -d "$JOBDIR/done" ]; then
[ -e "$JOBDIR/done" ] && error_mes "file" "$JOBDIR/done"
echo "[II] Creating directory '$JOBDIR/done'"
mkdir -m777 -p "$JOBDIR/done" || error_mes "unknown"
fi
if [ ! -d "$WORKDIR" ]; then
[ -e "$WORKDIR" ] && error_mes "file" "$WORKDIR"
echo "[II] Creating directory '$WORKDIR'"
mkdir -m777 -p "$WORKDIR" || error_mes "unknown"
fi
if [ ! -d "$(dirname "$QUEUEFILE")" ]; then
[ -e "$(dirname "$QUEUEFILE")" ] && error_mes "file" "$(dirname "$QUEUEFILE")"
echo "[II] Creating directory '$(dirname "$QUEUEFILE")'"
mkdir -m777 -p "$(dirname "$QUEUEFILE")" || error_mes "unknown"
echo "[II] Creating file '$QUEUEFILE'"
touch "$QUEUEFILE" || error_mes "unknown"
chmod 777 "$QUEUEFILE"
fi
# check priority
isnum "$PRIORITY" || error_mes "number" "$PRIORITY"
# check sleep time
isnum "$SLEEPTIME" && SLEEPTIME=$(($SLEEPTIME*60)) || error_mes "number" "$SLEEPTIME"
# work block
# change cwd
cd /
< /dev/null > /dev/null 2>&1 &
# forking
(
while true; do
# check files
echo "[II] Checking new files"
for FILE in $(ls "$WORKDIR/"); do
[ -d "$WORKDIR/$FILE" ] && continue
FILE_EXT="${FILE##*.}"
[ "$FILE_EXT" = "pr" ] && continue
[ "$FILE_EXT" = "user" ] && continue
[ -e "$QUEUEFILE" ] && grep --quiet "$WORKDIR/$FILE" "$QUEUEFILE" && continue
echo "[II] Adding file '$FILE' to list"
if [ -e "$WORKDIR/$FILE".pr ]; then
CURJOB_PRIOR=$(cat "$WORKDIR/$FILE".pr)
isnum "$CURJOB_PRIOR" || CURJOB_PRIOR="$PRIORITY"
else
CURJOB_PRIOR="$PRIORITY"
fi
echo "[II] Setting priority to '$CURJOB_PRIOR'"
echo "$CURJOB_PRIOR==$WORKDIR/$FILE" >> "$QUEUEFILE"
done
# check running job
CALC=0
for FILE in $(ls "$JOBDIR/"); do
[ -d "$JOBDIR/$FILE" ] && continue
(ps aux | grep "$JOBDIR/$FILE" | grep --quiet --invert-match "grep") && CALC=$(($CALC+1))
done
# running job
if [[ "$CALC" = "0" ]]; then
CURJOB_PRIOR=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $1}')
CURJOB=$(head -1 "$QUEUEFILE" | awk -F "==" '{print $2}')
for JOB in $(cat "$QUEUEFILE"); do
if [[ "$(echo "$JOB" | awk -F "==" '{print $1}')" > "$CURJOB_PRIOR" ]]; then
CURJOB_PRIOR=$(echo "$JOB" | awk -F "==" '{print $1}')
CURJOB=$(echo "$JOB" | awk -F "==" '{print $2}')
fi
done
[ -e "$CURJOB".user ] && CURJOB_USER="$(cat "$CURJOB".user)" || CURJOB_USER="$STARTASUSER"
sed '/'"$(basename "$CURJOB")"'/d' -i "$QUEUEFILE"
if [ -z "$CURJOB" ]; then
echo "[II] You haven't job"
else
mv "$CURJOB"* "$JOBDIR/" && start_job || echo "[WW] Missing files for job '$CURJOB'"
fi
else
echo "[II] You have a running job"
fi
# wait
sleep $SLEEPTIME
done
) &

View File

@ -1,79 +0,0 @@
.TH queued 1 "December 24, 2013" "version 1.2.0" "USER COMMANDS"
.SH NAME
queued - daemon for starting jobs to queue of calculations
.SH SYNOPSIS
.B queued
[ -c /etc/queued.conf ] [ -v | --version ] [ -h | --help ]
.SH DESCRIPTION
.B queued
is a simple daemon written on BASH for starting jobs to queue of calculations in the background. To add a new job you may use
.BR add_queued (1).
.SH OPTIONS
.TP
-c /etc/queued.conf
Full path to configuration file. Default is
.B /etc/queued.conf.
.TP
-h, --help
Show help and exit.
.TP
-v, --version
Show version and exit.
.SH FILES
.TP
/usr/lib/systemd/system/queued.service
Systemd service file.
.TP
/etc/queued.conf
Configuration file.
.SH EXAMPLES
.TP
# systemctl start queued.service
Start daemon with parameters that are described in configuration file.
.TP
# systemctl enable queued.service
Enable daemon autostart.
.SH USAGE WITH SYSTEMD
If you need change path to configuration file, copy standart service file to /etc directory:
.PP
.nf
# cp /usr/lib/systemd/system/queued.service /etc/systemd/system/queued-my-profile.service
.fi
.PP
Then replace path to configuration file to your option. For example,
.PP
.B from:
.nf
ExecStart=/usr/bin/queued
.fi
.B to
.nf
ExecStart=/usr/bin/queued -c /path/to/new/queued.conf
.fi
.PP
Copy configuration file and edit it:
.PP
.nf
# cp /etc/queued.conf /path/to/new/queued.conf
# $EDITOR /path/to/new/queued.conf
.fi
.PP
Then start service:
.PP
.nf
# systemctl start queued-my-profile.service
.fi
.SH ERRORS
Use
.B journalctl
to determine errors:
.nf
[II] - information string
[WW] - warning
[EE] - error
.fi
.SH SEE ALSO
.BR add_queued (1)
.BR queued.conf (5)
.SH AUTHOR
Evgeniy Alexeev aka arcanis <\fIesalexeev@gmail.com\fR>

View File

@ -1,16 +0,0 @@
## Configuration file for queued
## Paths
# path to directory with source jobs
#WORKDIR=/var/lib/queued/work
# path to directory with running jobs
#JOBDIR=/var/lib/queued/job
# path to file with queue list
#QUEUEFILE=/var/lib/queued/queue
## Additional parametrs
# default priority
#PRIORITY=0
# time to sleep, minutes
#SLEEPTIME=5
# start as user
#STARTASUSER=root

View File

@ -1,44 +0,0 @@
.TH queued.conf 5
.SH NAME
queued.conf - queued configuration file
.SH SYNOPSIS
/etc/queued.conf
.SH DESCRIPTION
This file configures various parameters of
.BR queued (1).
.SH OPTIONS
.TP
.I WORKDIR=
Full path to directory with source jobs. Default is
.B /var/lib/queued/work.
This directory must contain source scripts
.B script-name
, a priority file (it is not necessary)
.B script-name.pr
and a file with username (it is not necessary too)
.B script-name.user.
.TP
.I JOBDIR=
Full path to directory with running jobs. Default is
.B /var/lib/queued/job.
All job files will be moved here.
.TP
.I QUEUEFILE=
Full path to file with queue list. Default is
.B /var/lib/queued/queue.
.TP
.I PRIORITY=
Default priority. Default is
.B 0.
The higher the value, the higher the priority of the task
.TP
.I SLEEPTIME=
Time interval in minutes. Default is
.B 5.
.TP
.I STARTASUSER=
Default user. Default is
.B root.
This user will own created files.
.SH SEE ALSO
.BR queued (1)

View File

@ -1,10 +0,0 @@
[Unit]
Description=Queue daemon
[Service]
Type=forking
ExecStart=/usr/bin/queued
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,11 @@
set (SUBPROJECT "queued")
message (STATUS "Subproject ${SUBPROJECT}")
add_subdirectory ("src")
# headers
install (DIRECTORY "include/${SUBPROJECT}" DESTINATION "${INCLUDE_INSTALL_DIR}")
install (FILES "${CMAKE_BINARY_DIR}/config.h" DESTINATION "${INCLUDE_INSTALL_DIR}/${SUBPROJECT}")
# documentation
if (BUILD_DOCS)
include ("docs.cmake")
endif ()

View File

@ -0,0 +1,8 @@
# doxygen documentation
find_package (Doxygen)
configure_file ("doxygen.conf.in" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf")
add_custom_target ("oxygen-docs" ALL COMMAND "${DOXYGEN_EXECUTABLE}" "${CMAKE_CURRENT_BINARY_DIR}/doxygen.conf")
# html docs
install (DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/docs/html" DESTINATION "${DATA_INSTALL_DIR}/doc/${SUBPROJECT}")

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* @file Queued.h
* Header of Queued library
* @author Evgeniy Alekseev
* @copyright MIT
* @bug https://github.com/arcan1s/queued/issues
*/
#ifndef QUEUED_H
#define QUEUED_H
#include "QueuedDebug.h"
#include "QueuedProcess.h"
#include "QueuedProcessManager.h"
#endif /* QUEUED_H */

View File

@ -0,0 +1,69 @@
/*
* 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.
*/
/**
* @file QueuedDebug.h
* Header of Queued library
* @author Evgeniy Alekseev
* @copyright MIT
* @bug https://github.com/arcan1s/queued/issues
*/
#ifndef QUEUEDDEBUG_H
#define QUEUEDDEBUG_H
#include <QLoggingCategory>
/**
* @brief control application logging category
*/
Q_DECLARE_LOGGING_CATEGORY(LOG_CTL)
/**
* @brief DBus logging category
*/
Q_DECLARE_LOGGING_CATEGORY(LOG_DBUS)
/**
* @brief library logging category
*/
Q_DECLARE_LOGGING_CATEGORY(LOG_LIB)
/**
* @brief plugin logging category
*/
Q_DECLARE_LOGGING_CATEGORY(LOG_PL)
/**
* @brief server logging category
*/
Q_DECLARE_LOGGING_CATEGORY(LOG_SERV)
namespace QueuedDebug
{
/**
* @brief default log format
*/
const char LOG_FORMAT[] = "[%{time "
"process}][%{if-debug}DD%{endif}%{if-info}II%{endif}%"
"{if-warning}WW%{endif}%{if-critical}CC%{endif}%{if-"
"fatal}FF%{endif}][%{category}][%{function}] "
"%{message}";
/**
* @brief additional method to get build details declared in version.h
*/
QStringList getBuildData();
}
#endif /* QUEUEDDEBUG_H */

View File

@ -0,0 +1,162 @@
/*
* 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.
*/
/**
* @file QueuedProcess.h
* Header of Queued library
* @author Evgeniy Alekseev
* @copyright MIT
* @bug https://github.com/arcan1s/queued/issues
*/
#ifndef QUEUEDPROCESS_H
#define QUEUEDPROCESS_H
#include <QProcess>
#include <QVariant>
/**
* @struct QueuedProcessDefinition
* @brief structure to define process
* @var cmd
* command line
* @var args
* command line arguments
* @var workingDirectory
* path to working directory
* @var uid
* UID of process
* @var gid
* GID of process
*/
typedef struct {
QString cmd;
QStringList args;
QString workingDirectory;
int uid;
int gid;
} QueuedProcessDefinitions;
/**
* @brief implementation over QProcess to run processes
*/
class QueuedProcess : public QProcess
{
Q_OBJECT
Q_PROPERTY(long long index READ index)
Q_PROPERTY(QString name READ name)
public:
/**
* @enum LimitType
* @brief available limit types
* @var LimitType::CPUThreads
* limit on CPU threads count
* @var LimitType::GPUThreads
* limit on GPU threads count
* @var LimitType::Memory
* limit on physical memory
* @var LimitType::GPUMemory
* limit on GPU memory
* @var LimitType::Storage
* limit on storage
*/
enum class LimitType {
CPUThreads = 1,
GPUThreads = 2,
Memory = 4,
GPUMemory = 8,
Storage = 16
};
/**
* @brief QueuedProcess class constructor
* @param parent pointer to parent item
* @param definitions definitions of process
* @param index index of process
*/
explicit QueuedProcess(QObject *parent,
const QueuedProcessDefinitions definitions,
const long long index);
/**
* @brief QueuedProcess class destructor
*/
virtual ~QueuedProcess();
/**
* @brief index of process
* @return assigned index of process
*/
long long index() const;
/**
* @brief name of process
* @return generated name of process
*/
QString name() const;
/**
* @brief remove limit
* @param _limitType limit type
*/
virtual void removeLimit(const LimitType _limitType);
/**
* @brief set limit
* @param _limitType limit type
* @param _value limit value
*/
virtual void setLimit(const LimitType _limitType,
const QVariant _value = QVariant());
/**
* @brief equal operator implementation
* @param _other other object
* @return true if objects are equal
*/
bool operator==(const QueuedProcess _other);
protected:
/**
* @brief additional method with sets rules for QProcess
*/
void setupChildProcess();
public slots:
/**
* @brief run process
*/
void run();
private:
/**
* @brief process definitions
*/
QueuedProcessDefinitions m_definitions;
/**
* @brief index of process
*/
long long m_index = -1;
/**
* @brief limits array
*/
QMap<LimitType, long long> m_limits;
/**
* @brief convert QString memory value to integer
* @param _value value to convert
* @param _status convertion status
* @return converted integer
*/
long long convertMemory(QString _value, bool &_status) const;
};
#endif /* QUEUEDPROCESS_H */

View File

@ -0,0 +1,116 @@
/*
* 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.
*/
/**
* @file QueuedProcessManager.h
* Header of Queued library
* @author Evgeniy Alekseev
* @copyright MIT
* @bug https://github.com/arcan1s/queued/issues
*/
#ifndef QUEUEDPROCESSMANAGER_H
#define QUEUEDPROCESSMANAGER_H
#include <QHash>
#include <QObject>
#include "queued/QueuedProcess.h"
typedef QHash<long long, QueuedProcess *> QueuedProcessMap;
/**
* @brief implementation over QProcess to run processes
*/
class QueuedProcessManager : public QObject
{
Q_OBJECT
Q_PROPERTY(OnExitAction onExit READ onExit)
public:
/**
* @enum OnExitAction
* @brief action with child process on destruction
* @var OnExitAction::Terminate
* send SIGTERM on exit
* @var OnExitAction::Kill
* send SIGKILL on exit
*/
enum class OnExitAction { Terminate, Kill };
/**
* @brief QueuedProcessManager class constructor
* @param parent pointer to parent item
* @param onExit default action on exit
*/
explicit QueuedProcessManager(QObject *parent, const OnExitAction onExit);
/**
* @brief QueuedProcessManager class destructor
*/
virtual ~QueuedProcessManager();
/**
* @brief add task
* @param _index task index
* @param _definitions process definitions
* @return pointer to created task
*/
QueuedProcess *add(const long long _index,
const QueuedProcessDefinitions _definitions);
/**
* @brief default action on exit
* @return default action from possible ones
*/
OnExitAction onExit() const;
/**
* @brief task
* @param _index task index
* @return task found by index or nullptr
*/
QueuedProcess *process(const long long _index);
/**
* @brief all tasks
* @return list of all tasks
*/
QueuedProcessMap processes();
/**
* @brief remove task from list
* @param _index task index
*/
void remove(const long long _index);
private slots:
/**
* @brief slot for catching finished tasks
* @param _exitCode exit code of finished task
* @param _exitStatus exit status of finished task
* @param _index index of finished task
*/
void taskFinished(const int _exitCode,
const QProcess::ExitStatus _exitStatus,
const long long _index);
private:
/**
* @brief action on exit
*/
OnExitAction m_onExit = OnExitAction::Kill;
/**
* @brief processes list
*/
QueuedProcessMap m_processes;
};
#endif /* QUEUEDPROCESS_H */

61
sources/version.h.in Normal file
View File

@ -0,0 +1,61 @@
#ifndef VERSION_H
#define VERSION_H
// information
const char NAME[] = "Queued";
const char VERSION[] = "@PROJECT_VERSION@";
const char COMMIT_SHA[] = "@PROJECT_COMMIT_SHA@";
const char AUTHOR[] = "@PROJECT_AUTHOR@";
const char EMAIL[] = "@PROJECT_CONTACT@";
const char LICENSE[] = "@PROJECT_LICENSE@";
const char TRDPARTY_LICENSE[] = "";
const char SPECIAL_THANKS[] = "";
// configuration
// use define here instead of normal const definition for moc
#cmakedefine BUILD_FUTURE
#cmakedefine BUILD_LOAD
#cmakedefine BUILD_TESTING
// links
const char HOMEPAGE[] = "https://arcanis.me/projects/queued";
const char REPOSITORY[] = "https://github.com/arcan1s/queued";
const char RELEASES[] = "https://github.com/arcan1s/queued/releases/tag/V.";
const char VERSION_API[]
= "https://api.github.com/repos/arcan1s/queued/releases";
const char BUGTRACKER[] = "https://github.com/arcan1s/queued/issues";
const char BUGTRACKER_API[] = "https://arcanis.me/repos/arcan1s/queued/issues";
// build information
const char BUILD_DATE[] = "@CURRENT_DATE@";
const char DATE[] = "2013-@CURRENT_YEAR@";
// cmake properties
const char CMAKE_BUILD_TYPE[] = "@CMAKE_BUILD_TYPE@";
const char CMAKE_CXX_COMPILER[] = "@CMAKE_CXX_COMPILER@";
const char CMAKE_CXX_FLAGS[] = "@CMAKE_CXX_FLAGS@";
const char CMAKE_CXX_FLAGS_DEBUG[] = "@CMAKE_CXX_FLAGS_DEBUG@";
const char CMAKE_CXX_FLAGS_RELEASE[] = "@CMAKE_CXX_FLAGS_RELEASE@";
const char CMAKE_CXX_FLAGS_OPTIMIZATION[] = "@CMAKE_CXX_FLAGS_OPTIMIZATION@";
const char CMAKE_DEFINITIONS[] = "@CMAKE_DEFINITIONS@";
const char CMAKE_INSTALL_PREFIX[] = "@CMAKE_INSTALL_PREFIX@";
const char CMAKE_MODULE_LINKER_FLAGS[] = "@CMAKE_MODULE_LINKER_FLAGS@";
const char CMAKE_SHARED_LINKER_FLAGS[] = "@CMAKE_SHARED_LINKER_FLAGS@";
// components
const char BUILD_DEB_PACKAGE[] = "@BUILD_DEB_PACKAGE@";
const char BUILD_RPM_PACKAGE[] = "@BUILD_RPM_PACKAGE@";
const char CLANGFORMAT_EXECUTABLE[] = "@CLANGFORMAT_EXECUTABLE@";
const char COVERITY_COMMENT[] = "@COVERITY_COMMENT@";
const char COVERITY_DIRECTORY[] = "@COVERITY_DIRECTORY@";
const char COVERITY_EMAIL[] = "@COVERITY_EMAIL@";
const char COVERITY_EXECUTABLE[] = "@COVERITY_EXECUTABLE@";
const char COVERITY_URL[] = "@COVERITY_URL@";
const char CPPCHECK_EXECUTABLE[] = "@CPPCHECK_EXECUTABLE@";
// additional functions
const char PROP_FUTURE[] = "@BUILD_FUTURE@";
const char PROP_LOAD[] = "@BUILD_LOAD@";
const char PROP_TEST[] = "@BUILD_TESTING@";
#endif /* VERSION_H */