From 592d07a32dc4ee114822e80fa516ee152ddfd58d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Fri, 19 Oct 2018 16:32:44 +0200 Subject: [PATCH] smaller fixups --- common/include/villas/config.h.in | 5 +- common/include/villas/cpuset.hpp | 5 +- common/include/villas/exceptions.hpp | 10 ++-- common/lib/CMakeLists.txt | 4 +- common/lib/kernel/rt.cpp | 6 ++- common/lib/memory_manager.cpp | 2 +- common/lib/terminal.cpp | 75 ++++++++++++++++++++++++++++ 7 files changed, 92 insertions(+), 15 deletions(-) create mode 100644 common/lib/terminal.cpp diff --git a/common/include/villas/config.h.in b/common/include/villas/config.h.in index e1f4cfc23..e891e2b67 100644 --- a/common/include/villas/config.h.in +++ b/common/include/villas/config.h.in @@ -26,10 +26,6 @@ #pragma once -#ifndef V - #define V 2 -#endif - #define PROJECT_VERSION_STR "@CMAKE_PROJECT_VERSION_STR@" #define PROJECT_VERSION "@CMAKE_PROJECT_VERSION@" #define PROJECT_MAJOR_VERSION @CMAKE_PROJECT_MAJOR_VERSION@ @@ -52,6 +48,7 @@ #cmakedefine LIBCONFIG_FOUND /* Paths */ +#define PREFIX "@CMAKE_INSTALL_PREFIX@" #define PLUGIN_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/plugins" #define WEB_PATH "@CMAKE_INSTALL_PREFIX@/share/villas/node/web" #define SYSFS_PATH "/sys" diff --git a/common/include/villas/cpuset.hpp b/common/include/villas/cpuset.hpp index a1d787a05..4206cfe11 100644 --- a/common/include/villas/cpuset.hpp +++ b/common/include/villas/cpuset.hpp @@ -191,10 +191,7 @@ public: } }; -#endif - } // namespace villas } // namespace utils - -#include +#endif diff --git a/common/include/villas/exceptions.hpp b/common/include/villas/exceptions.hpp index 4b82bded2..7430b2a21 100644 --- a/common/include/villas/exceptions.hpp +++ b/common/include/villas/exceptions.hpp @@ -74,9 +74,11 @@ public: template JsonError(const json_error_t &err, const std::string &what, Args&&... args) : std::runtime_error(fmt::format(what, std::forward(args)...)) - { } + { + (void) err; + } - virtual const char * what() + virtual const char * what() const noexcept { return fmt::format("{}: {} in {}:{}:{}", std::runtime_error::what(), @@ -100,14 +102,14 @@ public: setting(s) { } - std::string docUri() + std::string docUri() const { std::string baseUri = "https://villas.fein-aachen.org/doc/jump?"; return baseUri + id; } - virtual const char * what() + virtual const char * what() const noexcept { std::stringstream ss; diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt index 52e7a5c98..24906cbc7 100644 --- a/common/lib/CMakeLists.txt +++ b/common/lib/CMakeLists.txt @@ -30,7 +30,8 @@ add_library(villas-common SHARED hash_table.c hist.c kernel/kernel.c - kernel/rt.c + kernel/kernel.cpp + kernel/rt.cpp list.c log.cpp log_legacy.cpp @@ -44,6 +45,7 @@ add_library(villas-common SHARED utils.c utils.cpp cpuset.cpp + terminal.cpp version.cpp ) diff --git a/common/lib/kernel/rt.cpp b/common/lib/kernel/rt.cpp index b3a06915e..0f94aa472 100644 --- a/common/lib/kernel/rt.cpp +++ b/common/lib/kernel/rt.cpp @@ -34,7 +34,9 @@ #include #include -using villas::utils::CpuSet; +#ifdef __linux__ + using villas::utils::CpuSet; +#endif /* __linux__ */ namespace villas { namespace kernel { @@ -67,6 +69,8 @@ int init(int priority, int affinity) lockMemory(); #else logger->warn("This platform is not optimized for real-time execution"); + (void) affinity; + (void) priority; #endif return 0; diff --git a/common/lib/memory_manager.cpp b/common/lib/memory_manager.cpp index 40affa547..297da052b 100644 --- a/common/lib/memory_manager.cpp +++ b/common/lib/memory_manager.cpp @@ -233,7 +233,7 @@ MemoryTranslation::operator+=(const MemoryTranslation& other) this->dst = other.dst; // the source stays the same and can only increase with merged translations - this->src = this->src; + //this->src = this->src; if(otherSrcIsSmaller) { // other mapping starts at lower addresses, so we actually arrive at diff --git a/common/lib/terminal.cpp b/common/lib/terminal.cpp new file mode 100644 index 000000000..ff2c5c0b5 --- /dev/null +++ b/common/lib/terminal.cpp @@ -0,0 +1,75 @@ +/** Terminal handling. + * + * @author Steffen Vogel + * @copyright 2018, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLAScommon + * + * 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 + * 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 . + *********************************************************************************/ + +#include + +#include +#include +#include + +using namespace villas; + +struct winsize Terminal::window; + +Terminal::Terminal() +{ + int ret; + + isTty = isatty(fileno(stdin)); + + if (isTty) { + struct sigaction sa_resize; + sa_resize.sa_flags = SA_SIGINFO; + sa_resize.sa_sigaction = resize; + + sigemptyset(&sa_resize.sa_mask); + + ret = sigaction(SIGWINCH, &sa_resize, NULL); + if (ret) + throw new SystemError("Failed to register signal handler"); + + /* Try to get initial terminal dimensions */ + ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); + if (ret) + throw new SystemError("Failed to get terminal dimensions"); + } + + /* Fallback if for some reason we can not determine a prober window size */ + if (window.ws_col == 0) + window.ws_col = 150; + + if (window.ws_row == 0) + window.ws_row = 50; +} + +void Terminal::resize(int, siginfo_t *, void *) +{ + int ret; + + ret = ioctl(STDERR_FILENO, TIOCGWINSZ, &window); + if (ret) + throw new SystemError("Failed to get terminal dimensions"); + + auto logger = logging.get("terminal"); + + logger->debug("New terminal size: {}x{}", window.ws_row, window.ws_col); +};