diff --git a/common/include/villas/boxes.hpp b/common/include/villas/boxes.hpp new file mode 100644 index 000000000..2ad23ad0e --- /dev/null +++ b/common/include/villas/boxes.hpp @@ -0,0 +1,47 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * 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 . + *********************************************************************************/ + +#pragma once + +/* Alternate character set + * + * The suffixed of the BOX_ macro a constructed by + * combining the following letters in the written order: + * - U for a line facing upwards + * - D for a line facing downwards + * - L for a line facing leftwards + * - R for a line facing rightwards + * + * E.g. a cross can be constructed by combining all line fragments: + * BOX_UDLR + */ +#define BOX(chr) "\e(0" chr "\e(B" +#define BOX_LR BOX("\x71") /**< Boxdrawing: ─ */ +#define BOX_UD BOX("\x78") /**< Boxdrawing: │ */ +#define BOX_UDR BOX("\x74") /**< Boxdrawing: ├ */ +#define BOX_UDLR BOX("\x6E") /**< Boxdrawing: ┼ */ +#define BOX_UDL BOX("\x75") /**< Boxdrawing: ┤ */ +#define BOX_ULR BOX("\x76") /**< Boxdrawing: ┴ */ +#define BOX_UL BOX("\x6A") /**< Boxdrawing: ┘ */ +#define BOX_DLR BOX("\x77") /**< Boxdrawing: ┘ */ +#define BOX_DL BOX("\x6B") /**< Boxdrawing: ┘ */ diff --git a/common/include/villas/colors.hpp b/common/include/villas/colors.hpp new file mode 100644 index 000000000..916d3a22f --- /dev/null +++ b/common/include/villas/colors.hpp @@ -0,0 +1,40 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * 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 . + *********************************************************************************/ + +#pragma once + +/* CPP stringification */ +#define XSTR(x) STR(x) +#define STR(x) #x + +/* Some color escape codes for pretty log messages */ +#define CLR(clr, str) "\e[" XSTR(clr) "m" str "\e[0m" +#define CLR_GRY(str) CLR(30, str) /**< Print str in gray */ +#define CLR_RED(str) CLR(31, str) /**< Print str in red */ +#define CLR_GRN(str) CLR(32, str) /**< Print str in green */ +#define CLR_YEL(str) CLR(33, str) /**< Print str in yellow */ +#define CLR_BLU(str) CLR(34, str) /**< Print str in blue */ +#define CLR_MAG(str) CLR(35, str) /**< Print str in magenta */ +#define CLR_CYN(str) CLR(36, str) /**< Print str in cyan */ +#define CLR_WHT(str) CLR(37, str) /**< Print str in white */ +#define CLR_BLD(str) CLR( 1, str) /**< Print str in bold */ diff --git a/common/include/villas/copyright.hpp b/common/include/villas/copyright.hpp new file mode 100644 index 000000000..cfb843484 --- /dev/null +++ b/common/include/villas/copyright.hpp @@ -0,0 +1,34 @@ +/** Various helper functions. + * + * @file + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * 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 . + *********************************************************************************/ + +#pragma once + +namespace villas { + +/** Print copyright message to stdout. */ +void print_copyright(); + +/** Print version to stdout. */ +void print_version(); + +} // namespace villas diff --git a/common/include/villas/cpuset.hpp b/common/include/villas/cpuset.hpp index 7bfe8a36a..b7d46fe54 100644 --- a/common/include/villas/cpuset.hpp +++ b/common/include/villas/cpuset.hpp @@ -191,7 +191,7 @@ public: } }; -} // namespace villas } // namespace utils +} // namespace villas #endif diff --git a/common/include/villas/utils.h b/common/include/villas/utils.h index 6288954ec..866ee82f3 100644 --- a/common/include/villas/utils.h +++ b/common/include/villas/utils.h @@ -23,6 +23,10 @@ #pragma once +#ifdef __cplusplus +extern "C" { +#endif + #include #include #include @@ -33,10 +37,6 @@ #include #include -#ifdef __cplusplus -extern "C" { -#endif - extern pthread_t main_thread; #ifdef __GNUC__ diff --git a/common/include/villas/utils.hpp b/common/include/villas/utils.hpp index 7a81fbe81..e03a483d9 100644 --- a/common/include/villas/utils.hpp +++ b/common/include/villas/utils.hpp @@ -44,12 +44,6 @@ assertExcept(bool condition, const T& exception) throw exception; } -/** Print copyright message to stdout. */ -void print_copyright(); - -/** Print version to stdout. */ -void print_version(); - /** Register a exit callback for program termination: SIGINT, SIGKILL & SIGALRM. */ int signals_init(void (*cb)(int signal, siginfo_t *sinfo, void *ctx)); diff --git a/common/lib/CMakeLists.txt b/common/lib/CMakeLists.txt index c4f103d7e..b5b1fc254 100644 --- a/common/lib/CMakeLists.txt +++ b/common/lib/CMakeLists.txt @@ -46,6 +46,7 @@ add_library(villas-common SHARED cpuset.cpp terminal.cpp version.cpp + copyright.cpp common.c ) diff --git a/common/lib/copyright.cpp b/common/lib/copyright.cpp new file mode 100644 index 000000000..0c8a242db --- /dev/null +++ b/common/lib/copyright.cpp @@ -0,0 +1,40 @@ +/** General purpose helper functions. + * + * @author Steffen Vogel + * @copyright 2017, Institute for Automation of Complex Power Systems, EONERC + * @license GNU General Public License (version 3) + * + * VILLASnode + * + * 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 + +void villas::print_copyright() +{ + std::cout << PROJECT_NAME " " << CLR_BLU(PROJECT_BUILD_ID) + << " (built on " CLR_MAG(__DATE__) " " CLR_MAG(__TIME__) ")" << std::endl + << " Copyright 2014-2017, Institute for Automation of Complex Power Systems, EONERC" << std::endl + << " Steffen Vogel " << std::endl; +} + +void villas::print_version() +{ + std::cout << PROJECT_BUILD_ID << std::endl; +} diff --git a/common/lib/utils.cpp b/common/lib/utils.cpp index c766a14f5..c95aeffb3 100644 --- a/common/lib/utils.cpp +++ b/common/lib/utils.cpp @@ -60,19 +60,6 @@ tokenize(std::string s, std::string delimiter) return tokens; } -void print_copyright() -{ - std::cout << PROJECT_NAME " " << CLR_BLU(PROJECT_BUILD_ID) - << " (built on " CLR_MAG(__DATE__) " " CLR_MAG(__TIME__) ")" << std::endl - << " Copyright 2014-2017, Institute for Automation of Complex Power Systems, EONERC" << std::endl - << " Steffen Vogel " << std::endl; -} - -void print_version() -{ - std::cout << PROJECT_BUILD_ID << std::endl; -} - ssize_t read_random(char *buf, size_t len) { int fd;