apps/system/psmq: New package. psmq is publish subscribe message queue. It's a set of programs and libraries to implement publish/subscribe way of inter-process communication on top of POSIX message queue.

This commit is contained in:
Michał Łyszczek 2019-02-18 17:47:34 -06:00 committed by Gregory Nutt
parent 9c05f6540b
commit 716caf2f61
4 changed files with 306 additions and 0 deletions

12
system/psmq/.gitignore vendored Normal file
View File

@ -0,0 +1,12 @@
/psmq-*
/Make.dep
/.depend
/.built
/*.asm
/*.rel
/*.lst
/*.sym
/*.adb
/*.lib
/*.src
/*.obj

111
system/psmq/Kconfig Normal file
View File

@ -0,0 +1,111 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
comment "psmq requires posix mqueue and SYSTEM_EMBEDLOG"
depends on DISABLE_MQUEUE || !SYSTEM_EMBEDLOG
menuconfig SYSTEM_PSMQ
bool "psmq"
default n
depends on !DISABLE_MQUEUE && SYSTEM_EMBEDLOG
select SYSTEM_EMBEDLOG
---help---
psmq is tool set which allows IPC communication in publish/subscribe way
created on top of posix messege queue. Full documentation is available
at: https://psmq.kurwinet.pl (despite the domain, it is in english).
Library is licensed under BSD 2-clause license. See LICENSE file in
the downloaded code for license details.
if SYSTEM_PSMQ
config PSMQ_MAX_CLIENTS
int "Max number of clients"
default 8
---help---
This defines how many clients single broker process will
support. Broker will return error for clients that want to
register to it and there are already max clients connected. psmqd
will alocate client array with static storage duration that is
about 12 bytes (may vary depending on architecture) for each
client.
config PSMQ_PAYLOAD_MAX
int "Max size of payload"
default 8
---help---
Defines maximum size of payload that can be sent via psmq.
Both PSMQ_TOPIC_MAX and PSMQ_PAYLOAD_MAX have direct impact on size
of internal message structures that are copied each time message
is sent. If you set PSMQ_PAYLOAD_MAX to, let's say 20, and you are
sending message with payload that takes only 2 byte, then 20 bytes
will get copied anyway. Same rule applies to topics.
config PSMQ_TOPIC_MAX
int "Max length of topic"
default 15
---help---
Defines maximum length any topic can be. That includes first ´/´
character, but does not include terminating null character. So
if this is set to 3, then topics "/0", "/01" will be valid, but
"/012" will be too long.
Library will use PSMQ_TOPIC_MAX + 1 as an array size for topic.
This means, to prevent unecessary paddings, use values like 7, or 15
or 31.
config PSMQD_PRIORITY
int "psmqd broker task priority"
default 100
config PSMQD_STACKSIZE
int "psmqd broker stack size"
default 2048
config PSMQ_TOOLS_PUB
bool "Enable psmq_pub tool"
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 2048
endif # PSMQ_TOOLS_PUB
config PSMQ_TOOLS_SUB
bool "Enable psmq_sub tool"
default n
---help---
Enables program which allows to listen to published messages on
chosen topics. It also has capabilities to log these messages to
a chosen file.
if PSMQ_TOOLS_SUB
config PSMQ_SUB_PROGNAME
string "psmq_sub program name"
default "psmq_sub"
depends on BUILD_KERNEL
config PSMQ_SUB_PRIORITY
int "psmq_sub broker task priority"
default 100
config PSMQ_SUB_STACKSIZE
int "psmq_sub broker stack size"
default 2048
endif # PSMQ_TOOLS_SUB
endif # SYSTEM_PSMQ

38
system/psmq/Make.defs Normal file
View File

@ -0,0 +1,38 @@
############################################################################
# apps/system/psmq/Make.defs
#
# Copyright (C) 2019 Michał Łyszczek. All rights reserved.
# Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
ifeq ($(CONFIG_SYSTEM_PSMQ),y)
CONFIGURED_APPS += system/psmq
endif

145
system/psmq/Makefile Normal file
View File

@ -0,0 +1,145 @@
############################################################################
# apps/system/psmq/Makefile
#
# Copyright (C) 2019 Michał Łyszczek. All rights reserved.
# Author: Michał Łyszczek <michal.lyszczek@bofc.pl>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
-include $(TOPDIR)/Make.defs
WGET = wget
CP = cp -R
UNPACK = tar -xzf
PACKEXT = .tar.gz
NXTOOLSDIR = $(APPDIR)/tools
PSMQ_URL = https://distfiles.kurwinet.pl/psmq
PSMQ_VERSION = 0.1.0
PSMQ_SRC_SHA256 = 52dce7d6fcbf84243e11afdb953eea6a6eb405fd81c8e71bc556bb63090e1284
PSMQ_EXT = tar.gz
PSMQ_SOURCES = psmq-$(PSMQ_VERSION)
PSMQ_TARBALL = $(PSMQ_SOURCES).$(PSMQ_EXT)
CFLAGS += -I$(APPDIR)/include/system
CFLAGS += -I$(APPDIR)/system/psmq/$(PSMQ_SOURCES)
# mandatory source files to compile
CSRCS = $(PSMQ_SOURCES)/lib/psmq.c \
$(PSMQ_SOURCES)/src/broker.c \
$(PSMQ_SOURCES)/src/cfg.c \
$(PSMQ_SOURCES)/src/globals.c \
$(PSMQ_SOURCES)/src/psmqd.c \
$(PSMQ_SOURCES)/src/topic-list.c
# optional source files to compile depending on Kconfig options
ifeq ($(CONFIG_PSMQ_TOOLS_PUB),y)
CSRCS += $(PSMQ_SOURCES)/src/psmq-pub.c
endif
ifeq ($(CONFIG_PSMQ_TOOLS_SUB),y)
CSRCS += $(PSMQ_SOURCES)/src/psmq-sub.c
endif
# compile-time options from Kconfig
CFLAGS += -DPSMQ_MAX_CLIENTS=$(CONFIG_PSMQ_MAX_CLIENTS)
CFLAGS += -DPSMQ_PAYLOAD_MAX=$(CONFIG_PSMQ_PAYLOAD_MAX)
CFLAGS += -DPSMQ_TOPIC_MAX=$(CONFIG_PSMQ_TOPIC_MAX)
# build psmq as library and disable standalone applications (apps will
# still be compiled but into shared library rather than standalone application
CFLAGS += -DPSMQ_LIBRARY=1
CFLAGS += -DPSMQ_STANDALONE=0
# psmq cannot be damonized in nuttx
CFLAGS += -DPSMQ_ENABLE_DAEMON=0
# nuttx has no opterr variable
CFLAGS += -DPSMQ_NO_OPTERR=1
# nuttx does not really support signals, so disable them. There will be no way
# to gently kill programs.
CFLAGS += -DPSMQ_NO_SIGNALS=1
# package string needed by tools when passing '-v' option
CFLAGS += -DPACKAGE_STRING="\"psmq $(PSMQ_VERSION)\""
CFLAGS += -DPACKAGE_VERSION=\"$(PSMQ_VERSION)\"
# register psmqd broker daemon application
PRIORITY = $(CONFIG_PSMQD_PRIORITY)
STACKSIZE = $(CONFIG_PSMQD_STACKSIZE)
APPNAME = psmqd
PROGNAME = psmqd$(EXEEXT)
# register psmq_pub application if it was enabled
ifeq ($(CONFIG_PSMQ_TOOLS_PUB),y)
PRIORITY += $(CONFIG_PSMQ_PUB_PRIORITY)
STACKSIZE += $(CONFIG_PSMQ_PUB_STACKSIZE)
APPNAME += psmq_pub
PROGNAME += psmq_pub$(EXEEXT)
endif
# register psmq_sub application if it was enabled
ifeq ($(CONFIG_PSMQ_TOOLS_SUB),y)
PRIORITY += $(CONFIG_PSMQ_SUB_PRIORITY)
STACKSIZE += $(CONFIG_PSMQ_SUB_STACKSIZE)
APPNAME += psmq_sub
PROGNAME += psmq_sub$(EXEEXT)
endif
# download and build psmq
$(PSMQ_TARBALL):
@echo "Downloading: $@"
$(Q) $(WGET) -O $@ $(PSMQ_URL)/$@
$(Q) $(NXTOOLSDIR)/check-hash.sh sha256 $(PSMQ_SRC_SHA256) $@
$(Q) touch $@
$(PSMQ_SOURCES): $(PSMQ_TARBALL)
@echo "Unpacking $< -> $@"
$(Q) $(call DELDIR, $@)
$(Q) $(UNPACK) $<
$(Q) touch $@
create_includes:
$(Q) $(CP) $(PSMQ_SOURCES)/inc/psmq.h $(APPDIR)/include/system
context:: $(PSMQ_SOURCES)
$(Q) $(MAKE) create_includes
clean::
$(Q) $(call DELFILE, $(APPDIR)/include/system/psmq.h)
$(Q) $(foreach COBJ, $(COBJS), $(call DELFILE, $(COBJ)))
distclean::
$(Q) $(call DELDIR, $(PSMQ_SOURCES))
$(Q) $(call DELDIR, $(PSMQ_TARBALL))
include $(APPDIR)/Application.mk