diff options
author | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2024-02-15 19:16:55 +0100 |
---|---|---|
committer | Michał Łyszczek <michal.lyszczek@bofc.pl> | 2024-02-15 19:16:55 +0100 |
commit | 5a005d4114970125970a18f0cd137bebe2357b9e (patch) | |
tree | 7cccde8ee61462244d1ec9f31b33eeb19bb23cdc | |
parent | 89610453d5ad9011aeaf5acf0298f5ca7e1f13ee (diff) | |
download | psmq-master.tar.gz psmq-master.tar.bz2 psmq-master.zip |
Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r-- | zephyr/CMakeLists.txt | 49 | ||||
-rw-r--r-- | zephyr/Kconfig | 41 | ||||
-rw-r--r-- | zephyr/module.yml | 2 | ||||
-rw-r--r-- | zephyr/psmq_shell.c | 95 |
4 files changed, 160 insertions, 27 deletions
diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index d830b0a..aeb5fdf 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -3,14 +3,51 @@ if(CONFIG_PSMQ) - set(PSMQ_DIR ${ZEPHYR_CURRENT_MODULE_DIR}) +set(PSMQ_DIR ${ZEPHYR_CURRENT_MODULE_DIR}) - zephyr_library() +zephyr_library() - zephyr_include_directories(${PSMQ_DIR}/lib) +zephyr_include_directories( + ${PSMQ_DIR} + ${PSMQ_DIR}/inc + ${PSMQ_DIR}/src + + ${ZEPHYR_BASE}/include + ${ZEPHYR_BASE}/include/zephyr/posix +) + +set(PSMQ_MSG_MAX ${CONFIG_PSMQ_MSG_MAX}) +configure_file(${PSMQ_DIR}/inc/psmq.h.in ${PSMQ_DIR}/inc/psmq.h @ONLY) + +# mandatory files +zephyr_library_sources( + ${PSMQ_DIR}/lib/psmq.c + ${PSMQ_DIR}/src/broker.c + ${PSMQ_DIR}/src/cfg.c + ${PSMQ_DIR}/src/globals.c + ${PSMQ_DIR}/src/topic-list.c + ${PSMQ_DIR}/src/utils.c + ${PSMQ_DIR}/src/psmqd.c +) + +zephyr_library_sources_ifdef(CONFIG_PSMQ_TOOLS_SUB + ${PSMQ_DIR}/src/psmq-sub.c + ${PSMQ_DIR}/zephyr/psmq_shell.c +) + +zephyr_library_sources_ifdef(CONFIG_PSMQ_TOOLS_PUB + ${PSMQ_DIR}/src/psmq-pub.c + ${PSMQ_DIR}/zephyr/psmq_shell.c +) + +zephyr_library_compile_definitions(PSMQ_MAX_CLIENTS=${CONFIG_PSMQ_MAX_CLIENTS}) +zephyr_library_compile_definitions(PSMQ_LIBRARY=0) +zephyr_library_compile_definitions(PSMQ_STANDALONE=0) +zephyr_library_compile_definitions(PSMQ_NO_OPTERR=0) +zephyr_library_compile_definitions(PSMQ_NO_SIGNALS=1) +zephyr_library_compile_definitions(STDIN_FILENO=0) +zephyr_library_compile_definitions(PACKAGE_STRING="psmq v0.2.1") +zephyr_library_compile_definitions(PACKAGE_VERSION="v0.2.1") - zephyr_library_sources( - ${PSMQ_DIR}/src/broker.c - ) endif() diff --git a/zephyr/Kconfig b/zephyr/Kconfig index f0cb557..7814b44 100644 --- a/zephyr/Kconfig +++ b/zephyr/Kconfig @@ -4,13 +4,13 @@ config ZEPHYR_PSMQ_MODULE bool -comment "psmq requires POSIX_MQUEUE" - depends on !POSIX_MQUEUE - -menuconfig PSMQ +config PSMQ bool "psmq" default n - depends on POSIX_MQUEUE + select GETOPT + select POSIX_MQUEUE + select POSIX_CLOCK + select PTHREAD_IPC ---help--- psmq is tool set which allows IPC communication in publish/subscribe way created on top of posix messege queue. Full documentation is available @@ -50,6 +50,14 @@ config PSMQ_MSG_MAX number of bytes that are sent because only actual data is sent over mqueue. +config PSMQ_DEBUG_LOGS + bool "Enable debug logs" + default n + ---help--- + Enable debug logs for all psmq related functions. This may be + helpful finding out why messages do not reach its destination. + Useless on production builds or when psmq works as expected. + config PSMQD_PRIORITY int "psmqd broker task priority" default 100 @@ -59,26 +67,18 @@ config PSMQD_STACKSIZE default 2048 config PSMQ_TOOLS_PUB - bool "Enable psmq_pub tool" + bool "Enable psmq_pub shell tool" + select SHELL + select SHELL_GETOPT default n ---help--- Enables program which allows to publish message over psmq directly from command line. -if PSMQ_TOOLS_PUB - -config PSMQ_PUB_PRIORITY - int "psmq_pub broker task priority" - default 100 - -config PSMQ_PUB_STACKSIZE - int "psmq_pub broker stack size" - default 1024 - -endif # PSMQ_TOOLS_PUB - config PSMQ_TOOLS_SUB - bool "Enable psmq_sub tool" + bool "Enable psmq_sub shell tool" + select SHELL + select SHELL_GETOPT default n ---help--- Enables program which allows to listen to published messages on @@ -93,7 +93,8 @@ config PSMQ_SUB_PRIORITY config PSMQ_SUB_STACKSIZE int "psmq_sub broker stack size" - default 1024 + default 2048 endif # PSMQ_TOOLS_SUB + endif # SYSTEM_PSMQ diff --git a/zephyr/module.yml b/zephyr/module.yml index a6dc8d4..f250647 100644 --- a/zephyr/module.yml +++ b/zephyr/module.yml @@ -1,4 +1,4 @@ name: psmq build: - cmake: . + cmake: zephyr/. kconfig: zephyr/Kconfig diff --git a/zephyr/psmq_shell.c b/zephyr/psmq_shell.c new file mode 100644 index 0000000..28d9f63 --- /dev/null +++ b/zephyr/psmq_shell.c @@ -0,0 +1,95 @@ +/* ========================================================================== + Licensed under BSD 2clause license See LICENSE file for more information + Author: Michał Łyszczek <michal.lyszczek@bofc.pl> + ========================================================================== */ + +#include <zephyr/shell/shell.h> +#include <stdlib.h> +#include <string.h> + +int psmq_sub_main(int argc, char *argv[]); +int psmq_pub_main(int argc, char *argv[]); + +static int start_psmq_pub(const struct shell *shell, int argc, char *argv[]) +{ + return psmq_pub_main(argc, argv); +} + +void psmq_sub_main_thread(void *arg1, void *arg2, void *arg3) +{ + (void)arg3; + + int *argc; + char **argv; + + argc = arg1; + argv = arg2; + + psmq_sub_main(*argc, argv); + for (int i = 0; i != *argc; i++) + free(argv[i]); + free(argv); + free(argc); +} + +K_THREAD_STACK_DEFINE(g_psmq_sub_stack, CONFIG_PSMQ_SUB_STACKSIZE); +struct k_thread thread_data; +static int start_psmq_sub(const struct shell *shell, int argc, char *argv[]) +{ + char **argv_copy; + int *argc_copy; + + + argc_copy = malloc(sizeof(*argc_copy)); + *argc_copy = argc; + + argv_copy = malloc(argc * sizeof(*argv_copy)); + for (int i = 0; i != argc; i++) + argv_copy[i] = strdup(argv[i]); + + k_thread_create(&thread_data, g_psmq_sub_stack, + K_THREAD_STACK_SIZEOF(g_psmq_sub_stack), + psmq_sub_main_thread, + argc_copy, argv_copy, NULL, + CONFIG_PSMQ_SUB_PRIORITY, 0, K_NO_WAIT); +} + +SHELL_STATIC_SUBCMD_SET_CREATE( + g_psmq_cmds, +#if CONFIG_PSMQ_TOOLS_SUB + SHELL_CMD_ARG(sub, NULL, +"listen to subscribed messages over psmq\n" +"\n" +"usage: \n" +"\tpsmq sub [-h | -v]\n" +"\tpsmq sub <-t topic> <[-t topic]>\n" +"\n" +"\t-h shows help and exit\n" +"\t-v shows version and exit\n" +"\t-t <topic> topic to subscribe to, can be used multiple times\n" +, start_psmq_sub, 1, 10), +#endif +#if CONFIG_PSMQ_TOOLS_PUB + SHELL_CMD_ARG(pub, NULL, +"publish message over psmq\n" +"\n" +"usage: \n" +"\tpsmq pub [-h | -v]\n" +"\tpsmq pub -t <topic> <-m <message> | -e> \n" +"\n" +"\n" +"\t-h print this help and exit\n" +"\t-v print version and exit\n" +"\t-t <topic> topic on which message should be published\n" +"\t-m <message> message to publish\n" +"\t-e publish message without payload on topic\n" +"\n" +"When message is read from stdin, program will send each line as separate\n" +"message on passed topic until EOF is encoutered\n" + , start_psmq_pub, 1, 10), +#endif + SHELL_SUBCMD_SET_END +); + + +SHELL_CMD_REGISTER(psmq, &g_psmq_cmds, "psmq", NULL); |