From 17cf21bcf8a2e29d2cbcf0a313474d2a4ee44f5d Mon Sep 17 00:00:00 2001 From: Tadao Tanikawa Date: Fri, 20 Nov 2020 23:36:23 +0900 Subject: Re-organized sub-directory by category Since all the sub-directories were placed in the first level, created sub-directories, "hal", "module", and "service" for classification and relocated each component. Signed-off-by: Tadao Tanikawa Change-Id: Ifdf743ac0d1893bd8e445455cf0d2c199a011d5c --- .../client/NS_MessageQueue/cfg/depends.mk | 25 + .../client/NS_MessageQueue/include/ns_mq_anomaly.h | 35 ++ .../NS_MessageQueue/include/ns_mq_internal.h | 58 ++ .../client/NS_MessageQueue/include/ns_msg_queue.h | 295 ++++++++++ .../NS_MessageQueue/src/makefile_PosixBasedOS001 | 207 +++++++ .../client/NS_MessageQueue/src/ns_mq_string.c | 60 +++ .../client/NS_MessageQueue/src/ns_msg_queue.c | 596 +++++++++++++++++++++ 7 files changed, 1276 insertions(+) create mode 100755 service/native/framework_unified/client/NS_MessageQueue/cfg/depends.mk create mode 100755 service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_anomaly.h create mode 100755 service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_internal.h create mode 100755 service/native/framework_unified/client/NS_MessageQueue/include/ns_msg_queue.h create mode 100755 service/native/framework_unified/client/NS_MessageQueue/src/makefile_PosixBasedOS001 create mode 100755 service/native/framework_unified/client/NS_MessageQueue/src/ns_mq_string.c create mode 100755 service/native/framework_unified/client/NS_MessageQueue/src/ns_msg_queue.c (limited to 'service/native/framework_unified/client/NS_MessageQueue') diff --git a/service/native/framework_unified/client/NS_MessageQueue/cfg/depends.mk b/service/native/framework_unified/client/NS_MessageQueue/cfg/depends.mk new file mode 100755 index 0000000..93b9f97 --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/cfg/depends.mk @@ -0,0 +1,25 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Standard Dependency Makefile Version 2.0 +# +# Dependency file dictates not only what other modules the project is dependent on, but +# also where to get that dependent element which logically includes versioning or +# baselining information + +# Utilizing Base Domain Dependency File. Can override at any point +include $(PRJ_ROOT)/../NativeServices/cfg/depends.mk diff --git a/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_anomaly.h b/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_anomaly.h new file mode 100755 index 0000000..5b02e2b --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_anomaly.h @@ -0,0 +1,35 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_ANOMALY_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_ANOMALY_H_ + +#include + +typedef struct { + CHAR name[18]; + UI_32 maxMsg; +} mq_anomaly_t; + +mq_anomaly_t mq_anomaly_list[] = { + { "/NS_NPPService", 256 }, + { "/NS_NPPWriteWkr", 256 }, + { "/NS_NPPReadWkr", 256 }, + { "/NS_NPPIPWkr", 256 }, + { "/audio_app", 256 }, +}; + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_ANOMALY_H_ diff --git a/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_internal.h b/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_internal.h new file mode 100755 index 0000000..ca02218 --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/include/ns_mq_internal.h @@ -0,0 +1,58 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSMessageQueue +/// \brief API Header for Logger. +/// +/// Declares the external APIs to Logger. +/// +/////////////////////////////////////////////////////////////////////////////// + +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_INTERNAL_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_INTERNAL_H_ + +///////////////////////////////////////// +#include +///////////////////////////////////////// + + +/// \brief Struct that defines internal handle object +typedef struct tQHandle { + UI_32 check_code; + SI_32 fd; + PSTR q_name; + EQType q_type; + void *sendbuf; + + ///////////////////////////////////////// + pthread_t threadid; // thread id of child thread (may be NULL) + ///////////////////////////////////////// +} SQhandle; + +#define MQ_CHECK_CODE (0xC0D1F1ED) + +static inline BOOL mqCheckValidHandle(HANDLE hMessage) { + if (INVALID_HANDLE != hMessage) { + SQhandle *sndHndl = (SQhandle *)hMessage; // NOLINT (readability/nolint) + if (sndHndl->check_code == MQ_CHECK_CODE) { + return TRUE; + } + } + return FALSE; +} + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MQ_INTERNAL_H_ diff --git a/service/native/framework_unified/client/NS_MessageQueue/include/ns_msg_queue.h b/service/native/framework_unified/client/NS_MessageQueue/include/ns_msg_queue.h new file mode 100755 index 0000000..111b5be --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/include/ns_msg_queue.h @@ -0,0 +1,295 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file ns_msg_queue.h + * @brief \~english TestFramework provides interface for implementing functional test classes. + * + */ +/** @addtogroup BaseSystem + * @{ + */ +/** @addtogroup native_service + * @ingroup BaseSystem + * @{ + */ +/** @addtogroup framework_unified + * @ingroup native_service + * @{ + */ +#ifndef FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MSG_QUEUE_H_ +#define FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MSG_QUEUE_H_ + +#include + + +#ifdef __cplusplus +extern "C" { +#endif + +/// \brief Enum that defines the value Q Types +typedef enum eQType { + eQTypeReveiver, + eQTypeSender, + eQTypeInvld +} EQType; + +// PASA CCR IPC Framework API + +//////////////////////////////////////////////////////////////////////////////////////////// +/// OpenReceiver +/// The opens a handle to a Receiver message queue. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to receiver messages on +/// +/// \return HANDLE +/// handle - to a recevier's message queue +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE OpenReceiver(PCSTR name); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// OpenReceiverNotBlocked +/// The opens a handle to a Receiver message queue. Operations on this queue +/// are non-blocking if queue is empty or full. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to receiver messages on +/// +/// \return HANDLE +/// handle - to a recevier's message queue +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE OpenReceiverNotBlocked(PCSTR name); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// OpenSyncReceiver +/// The opens a handle to a response Receiver message queue. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to receiver messages on +/// +/// \return HANDLE +/// handle - to a recevier's message queue +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE openSyncReceiver(PCSTR name); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// OpenSender +/// The opens a handle for sending messages to another message queue. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to send messages too +/// +/// \return HANDLE +/// handle - senders message queue handle +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE OpenSender(PCSTR name); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// openSyncSender +/// The opens a handle for sending response to another message queue. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to send messages too +/// +/// \return HANDLE +/// handle - senders message queue handle +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE openSyncSender(PCSTR name); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// openSenderZc +/// The opens a handle for sending response to another message queue. +/// +/// \param [in] name +/// PCSTR - name of the message queue you want to send messages too +/// +/// \return HANDLE +/// handle - senders message queue handle +/// INVALID_HANDLE - Either message name is NULL or length is >= MAX_QUEUE_NAME_SIZE +/// INVALID_HANDLE - or an error occurred while opening a queue +//////////////////////////////////////////////////////////////////////////////////////////// +HANDLE openSenderZc(PCSTR name); + +///////////////////////////////////////// +#include +HANDLE OpenSenderChild(PCSTR name, pthread_t threadid); +///////////////////////////////////////// + +///////////////////////////////////////// +EFrameworkunifiedStatus JoinChild(HANDLE hChildApp); +///////////////////////////////////////// + +///////////////////////////////////////// +EFrameworkunifiedStatus GetChildThreadPriority(HANDLE hChildApp, PSI_32 threadPrio); +///////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SendMessage +/// The function sends a message to a queue. +/// +/// \param [in] hMessage +/// Handle - handle to the sendMessage, OpenSender +/// \param [in] length +/// UI_32 - length of the data to be sent +/// \param [in] data +/// const void* - pointer to the data that needs to be transmitted +/// +/// \return EFrameworkunifiedaStatus +/// status - status of the message(error) +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendMessage(HANDLE hMessage, UI_32 length, PVOID data); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// SendMessageWithPriority +/// The function sends a message to a queue. +/// +/// \param [in] hMessage +/// Handle - handle to the sendMessage, OpenSender +/// \param [in] length +/// UI_32 - length of the data to be sent +/// \param [in] data +/// const void* - pointer to the data that needs to be transmitted +/// \param [in] priority +/// EFrameworkunifiedMessagePriorties - priority at which the message should be sent at! +/// +/// \return EFrameworkunifiedaStatus +/// status - status of the message(error) +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus SendMessageWithPriority(HANDLE hMessage, UI_32 length, PVOID data, EFrameworkunifiedMessagePriorties priority); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// ReceiveMessage +/// The function blocks on a message queue waiting for data to be received. +/// +/// \param [in] hMessage +/// HANDLE - handle to the recvMessage, OpenReceiver +/// \param [in] length +/// UI_32 - length of the data buffer provided +/// \param [in] data +/// void* - pointer to the data to be received +/// +/// \return SI_32 +/// length read - indicates the number of bytes that were read from the queue (eFrameworkunifiedStatusErrOther) error +//////////////////////////////////////////////////////////////////////////////////////////// +SI_32 ReceiveMessage(HANDLE hMessage, UI_32 length, PVOID data); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CloseReceiver +/// The closes a connection to a Receiver message queue. +/// +/// \param [in] hMessage +/// HANDLE - handle to the recvMessage that will be closed +/// +/// \return EFrameworkunifiedaStatus +/// status - indicates if the close was successfully (eFrameworkunifiedStatusOK) or not (anything else) +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CloseReceiver(HANDLE handle); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// CloseReceiver +/// The closes a connection to a Receiver message queue. +/// +/// \param [in] hMessage +/// HANDLE - handle to the recvMessage that will be closed +/// +/// \return EFrameworkunifiedaStatus +/// status - indicates if the close was successfully (eFrameworkunifiedStatusOK) or not (anything else) +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus CloseSender(HANDLE handle); + + +//////////////////////////////////////////////////////////////////////////////////////////// +/// Flush +/// Flush all data on HANDLE's Receiver message queue. +/// +/// \param [in] hMessage +/// HANDLE - handle to the recvMessage queue that will be flushed +/// +/// \return void +//////////////////////////////////////////////////////////////////////////////////////////// +void Flush(HANDLE hMessage); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetQueueType +/// Get the handle's queue type. +/// +/// \param [in] hMessage +/// HANDLE - handle to the Message queue +/// +/// \return EQType +/// EQType - queue type of handle +//////////////////////////////////////////////////////////////////////////////////////////// +EQType GetQueueType(HANDLE hMessage); + +//////////////////////////////////////////////////////////////////////////////////////////// +// Function : TranslateError +// Translates global error variables into FW EFrameworkunifiedStatus +/// +/// \param [in] error +/// int - error variable +/// +/// \return EFrameworkunifiedStatus +/// EFrameworkunifiedStatus - frameworkunified error type +//////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus TranslateError(int error); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetQueueName +/// This gets the name of the message queue +/// +/// \param [in] hMessage +/// HANDLE - handle of the message queue +/// (handle created with McOpenReceiver or McOpenSender) +/// +/// \return PCSTR +/// name - name of the message queue if handle is valid else NULL +//////////////////////////////////////////////////////////////////////////////////////////// +PCSTR GetQueueName(HANDLE hMessage); + +//////////////////////////////////////////////////////////////////////////////////////////// +/// GetQueueFD +/// This gets the fd of the message queue +/// +/// \param [in] hMessage +/// HANDLE - handle of the message queue +/// (handle created with McOpenReceiver or McOpenSender) +/// +/// \return int +/// fd - fd of the message queue if handle is valid else -1 +//////////////////////////////////////////////////////////////////////////////////////////// +int GetQueueFD(HANDLE hMessage); + +#ifdef __cplusplus +} +#endif + +#endif // FRAMEWORK_UNIFIED_CLIENT_NS_MESSAGEQUEUE_INCLUDE_NS_MSG_QUEUE_H_ + +/** @}*/ +/** @}*/ +/** @}*/ diff --git a/service/native/framework_unified/client/NS_MessageQueue/src/makefile_PosixBasedOS001 b/service/native/framework_unified/client/NS_MessageQueue/src/makefile_PosixBasedOS001 new file mode 100755 index 0000000..054db6d --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/src/makefile_PosixBasedOS001 @@ -0,0 +1,207 @@ +# +# @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +# +# Standard Module Makefile version 2.0 +# + +# Name of the componet (team/domain prefix '_' component name) +COMPONENT_NAME = NS_MessageQueue + +ifndef PRJ_ROOT +export PRJ_ROOT = $(CURDIR)/../ +endif +include $(PRJ_ROOT)cfg/depends.mk + +# Name of the componet (team/domain prefix '_' component name) +# This must be the same as the RTC Component name and Eclipse Project Name +COMPONENT_NAME = NS_MessageQueue + + +# Additive Compile Flags (Flags from initiating make process will still apply) +DEFS += + +# Set local includes and then the reference includes (priority order determines search path) +# Default pattern are any configuration includes (which would be things like PosixBasedOS001), local (Team) component directories, +# dependencies includes (other teams) +# Local (current component references should be in the form of +# $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/directory +# Example your public include directory would be +# $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/inc +# Team references should only be to other's public includes such as +# $(CC_IFLAG)$(TEAM_ROOT)NS_MessageCenter/inc +# Global (non-team) references should be only to other's public includes such +# these are found in the depends include file and captured in the (DEPENDS_INCLUDES) variable +INCLUDES = \ + $(CFG_INCS) \ + $(CC_IFLAG)./ \ + $(DEPENDS_INCLUDES) \ + $(CC_IFLAG)$(TEAM_ROOT)$(COMPONENT_NAME)/inc + + +# Do the same if you need to include library paths as well +# Do an incremental in case additional library paths are defined +# at the top-level make. Use similar guidelines as for includes +# for example to include a team component library it would be +# $(TEAM_ROOT)NS_MessageCenter/lib/NS_MessageCenter/ +LIB_PATHS += \ + $(DEPENDS_LIB_PATHS) \ + + +# Define binary outputs. These can be libraries or executables. +# Name a variable for each deliverable. Suffixes should be +# EXEC - For Executables -> output to the bin directory +#TIME_EXEC = $(BIN_PATH)time +# LIB - For Static Libraries -> output to lib directory with specific naming +#MATH_LIB = $(LIB_PATH)$(LIB_PREFIX)math.$(LIB_EXT) +# SLIB - For Shared Objects +#FRMWRK_SLIB = $(SLIB_PATH)frmwrk.$(SO_EXT) +# LIB - Define the static library for Message Queue +# +# +ifdef DYNAMIC + COMPONENT_LIB = $(SLIB_PATH)$(LIB_PREFIX)$(COMPONENT_NAME)$(DEBUG_EXT).$(SO_EXT) +else + COMPONENT_LIB = $(LIB_PATH)$(LIB_PREFIX)$(COMPONENT_NAME)$(DEBUG_EXT).$(LIB_EXT) +endif + +## Sources Section + +# Define Library & Executable Sources (on a per deliverable basis) +# This includes sources located in subdirectories. + +# Define generic line that pulls all c, cc, cpp files +# since your in the src folder is pull only files from there +COMPONENT_SRCS = \ + $(wildcard *.c) \ + $(wildcard *.cpp) + +# Define sources that my not be local to your component +# here, you can define indivial files or wildcard from +# a different folder. +NON_LOCAL_SRCS = \ + + +# List of all sources to be built. Can be assembled from the other defintitions. +# This only defines sources for the current directory, so if there are subdirectories +# those are not included. (Those are found in simple subdirectory makefiles that only +# direct the building of sources, but no linking into a binary) +SOURCES = \ + $(COMPONENT_SRCS) \ + $(NON_LOCAL_SRCS) \ + + + +# +# Convert the source files to object files with correct folder location. +# +# +C_LANG_OBJECTS = $(addprefix $(BLD_PATH),$(addsuffix .$(OBJ_EXT),$(basename $(filter %.c ,$(SOURCES) ) ) ) ) +CPP_LANG_OBJECTS = $(addprefix $(BLD_PATH),$(addsuffix .$(OBJ_EXT),$(basename $(filter %.cpp %.cc %.cxx,$(SOURCES) ) ) ) ) + + +# List of all sources to be generated. Can be assembled from the other defintitions. +OBJECTS = \ + $(C_LANG_OBJECTS) \ + $(CPP_LANG_OBJECTS) + + + +# All headers that are dependencies. Wildcard is easy to pickup local headers. +# This is only to automate the rebuilding, all builds on the servers are cleans +# So this is not a huge deal when building on a component level. +HEADERS = \ + $(wildcard *.h) \ + $(wildcard $(TEAM_ROOT)$(COMPONENT_NAME)/inc/*.h) \ + $(wildcard $(TEAM_ROOT)NativeServices/inc/*.h) \ + + +LIBRARIES = \ + $(COMPONENT_LIB) \ + +# mqS is not available for x86 +ifneq ($(TARGET),x86) + # Link mqS only to PastModel003*1! + ifeq ($(PRODUCT_NAME),PastModel004) + STATIC_LIBS += mqS + LD_OFLAG := -Wl,-Bsymbolic $(LD_OFLAG) + endif +endif + +# Make targets +# Standard +all: banner module_dirs subdirs local library binary + +debug: + $(MAKE) TARGET=arm DEBUG=TRUE all + +base: banner module_dirs subdirs local + +# Standard Building of Source Files (Default builds for all objects defined above) +$(C_LANG_OBJECTS): $(SOURCES) $(HEADERS) + $(CC_CMD) + +$(CPP_LANG_OBJECTS): $(SOURCES) $(HEADERS) + $(CPP_CMD) + +local: $(OBJECTS) + +# Defines specific for each deliverable + +# For a static library +$(COMPONENT_LIB): $(OBJECTS) +ifdef DYNAMIC +# For a dynamic library + $(SLIB_CMD) + $(HIDE_ECHO_FLAG)$(OBJCPY) --only-keep-debug $(@) $(@).debug + $(HIDE_ECHO_FLAG)$(OBJCPY) --strip-all $(@) + $(HIDE_ECHO_FLAG)$(OBJCPY) --add-gnu-debuglink=$(@).debug $(@) +else +# For a static library + $(AR_CMD) +endif + +# Standard set of derived targets +library: base \ + $(LIBRARIES) + @echo "***** `date` Done building library: $(COMPONENT_NAME) ******" + +binary: base \ + $(BINARIES) + +# Subdirs should be to jump to subdirectories +# standard form is of +# $(MAKE) -C subdirectory_name $(MAKECMDGOALS) +subdirs: + +clean: + -rm -f $(BINARIES) + -rm -f $(LIBRARIES) + -rm -f $(OBJECTS) + -rm -f $(COMPONENT_LIB).map + -rm -f $(COMPONENT_LIB).debug + +-v: + + @echo "objs: --> $(OBJECTS)" + @echo "sources: --> $(SOURCES)" + @echo "headers: --> $(HEADERS)" + @echo "includes: --> $(INCLUDES)" + @echo "lib: --> $(LIBRARIES)" + @echo "bin: --> $(BINARIES)" + + +module_dirs: build_dirs diff --git a/service/native/framework_unified/client/NS_MessageQueue/src/ns_mq_string.c b/service/native/framework_unified/client/NS_MessageQueue/src/ns_mq_string.c new file mode 100755 index 0000000..8749a99 --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/src/ns_mq_string.c @@ -0,0 +1,60 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +size_t strlcpy(char *dst, const char *src, size_t siz) { + if (dst == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "dst is NULL"); + return 0; + } + if (src == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "src is NULL"); + return 0; + } + size_t ret = strlen(src); + + if (siz) { + size_t len = (ret >= siz) ? siz - 1 : ret; + memcpy(dst, src, len); + dst[len] = '\0'; + } + return ret; +} + +size_t strlcat(char *dst, const char *src, size_t siz) { + if (dst == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "dst is NULL"); + return 0; + } + if (src == NULL) { + FRAMEWORKUNIFIEDLOG(ZONE_NS_ERR, __func__, "src is NULL"); + return 0; + } + size_t dsiz = strlen(dst); + size_t len = strlen(src); + size_t res = dsiz + len; + + dst += dsiz; + siz -= dsiz; + if (len >= siz) { + len = siz - 1; + } + memcpy(dst, src, len); + dst[len] = '\0'; + return res; +} diff --git a/service/native/framework_unified/client/NS_MessageQueue/src/ns_msg_queue.c b/service/native/framework_unified/client/NS_MessageQueue/src/ns_msg_queue.c new file mode 100755 index 0000000..1990061 --- /dev/null +++ b/service/native/framework_unified/client/NS_MessageQueue/src/ns_msg_queue.c @@ -0,0 +1,596 @@ +/* + * @copyright Copyright (c) 2016-2020 TOYOTA MOTOR CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/////////////////////////////////////////////////////////////////////////////// +/// \ingroup tag_NSMessageQueue +/// \brief API Header for Zone Player Service APIs to be used by senders and +/// receivers. +/// +/// APIs to register/unregister notifications and add/remove recievers to the notifications. +/// +/////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include "ns_msg_queue.h" +#include +#include +#include +#include +#include "ns_mq_anomaly.h" + +#include +#include + +const UI_32 DEFAULT_MSG_PRIORITY = 10; +const UI_32 MAX_MESSAGES_STORED_IN_QUEUE = 256; +const UI_32 MAX_SYNC_RESPONSE_STORED_IN_QUEUE = 2; + +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Function : TranslateError +// Translates global error variables into FW EFrameworkunifiedStatus +//////////////////////////////////////////////////////////////////////////////////////////////////// +EFrameworkunifiedStatus TranslateError(int error) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + + switch (error) { + case EOK: + eStatus = eFrameworkunifiedStatusOK; + break; + case EBUSY: + eStatus = eFrameworkunifiedStatusThreadBusy; + break; + case EDEADLK: + eStatus = eFrameworkunifiedStatusThreadSelfJoin; + break; + case EFAULT: + eStatus = eFrameworkunifiedStatusFault; + break; + case EINVAL: + eStatus = eFrameworkunifiedStatusInvldParam; + break; + case ESRCH: + eStatus = eFrameworkunifiedStatusThreadNotExist; + break; + case EBADF: + eStatus = eFrameworkunifiedStatusErrNoEBADF; + break; + case EAGAIN: + eStatus = eFrameworkunifiedStatusErrNoEAGAIN; + break; + case EINTR: + eStatus = eFrameworkunifiedStatusErrNoEINTR; + break; + case EMSGSIZE: + eStatus = eFrameworkunifiedStatusInvldBufSize; + break; + case ENOTSUP: + eStatus = eFrameworkunifiedStatusNotImplemented; + break; + case EPERM: + eStatus = eFrameworkunifiedStatusAccessError; + break; + default: + eStatus = eFrameworkunifiedStatusFail; + break; + } + + return eStatus; +} + +static UI_8 GetNormalizedMqName(PSTR normalized_mqname , PCSTR name, size_t size) { + if ((NULL != name) && (NULL != normalized_mqname)) { + if (name[0] != '/') { + strlcpy(normalized_mqname, "/", size); + strlcat(normalized_mqname, name, size); + } else { + strlcpy(normalized_mqname, name, size); + } + + return 1; + } else { + return 0; + } +} + +HANDLE OpenReceiverNotBlocked(PCSTR name) { + HANDLE rtnHandle = INVALID_HANDLE; // invalid until made valid. + PSTR normalized_qname = NULL; + SI_32 q_fd = -1; // fd to mqueue + SQhandle *rcvHndl = NULL; + struct mq_attr mqattr; + size_t norm_qname_size = 0; + + // Check for invalid name + if (name == NULL) { + return INVALID_HANDLE; + } + + if (strlen(name) >= MAX_QUEUE_NAME_SIZE) { + return INVALID_HANDLE; + } + + norm_qname_size = strlen(name) + 2; + normalized_qname = (PSTR)malloc(norm_qname_size); + + if (0 != GetNormalizedMqName(normalized_qname, name, norm_qname_size)) { + if (strlen(normalized_qname) > LIMIT_QUEUE_NAME_SIZE) { + free(normalized_qname); + return INVALID_HANDLE; + } + + mqattr.mq_flags = 0; + mqattr.mq_maxmsg = (__syscall_slong_t)MAX_MESSAGES_STORED_IN_QUEUE; + mqattr.mq_msgsize = MAX_QUEUE_MSG_SIZE; + + q_fd = mq_open(normalized_qname, O_RDONLY | O_CREAT | O_NONBLOCK | O_CLOEXEC , 0666, &mqattr); + + if (q_fd != -1) { + rcvHndl = (SQhandle *)malloc(sizeof(SQhandle)); + if (rcvHndl != NULL) { + rcvHndl->check_code = MQ_CHECK_CODE; + rcvHndl->fd = q_fd; + rcvHndl->q_name = normalized_qname; + rcvHndl->q_type = eQTypeReveiver; + + ///////////////////////////////////////// + rcvHndl->threadid = 0; + ///////////////////////////////////////// + + // Set the return handle to rcvHndl + rtnHandle = rcvHndl; + } + } + } + + if (INVALID_HANDLE == rtnHandle) { + // couldn't connect the queue, + // release the memory to normalized queue name + if (normalized_qname != NULL) { + free(normalized_qname); + normalized_qname = NULL; // mb20110108 item 11 + } + } + + return rtnHandle; +} + +static HANDLE openReceiverInternal(PCSTR name, UI_32 mq_maxmsg, UI_32 mq_msgsize, BOOL is_internal) { + HANDLE rtnHandle = INVALID_HANDLE; // invalid until made valid. + PSTR normalized_qname = NULL; + SI_32 q_fd = -1; // fd to mqueue + SQhandle *rcvHndl = NULL; + struct mq_attr mqattr; + size_t norm_qname_size = 0; + + // Check for invalid name + if (name == NULL) { + return INVALID_HANDLE; + } + + if (strlen(name) >= MAX_QUEUE_NAME_SIZE) { + return INVALID_HANDLE; + } + + norm_qname_size = strlen(name) + 2; + normalized_qname = (PSTR)malloc(norm_qname_size); + + if (0 != GetNormalizedMqName(normalized_qname, name, norm_qname_size)) { + int i; + + if (!is_internal && strlen(normalized_qname) > LIMIT_QUEUE_NAME_SIZE) { + free(normalized_qname); + return INVALID_HANDLE; + } + + mqattr.mq_flags = 0; + mqattr.mq_maxmsg = (__syscall_slong_t)mq_maxmsg; + mqattr.mq_msgsize = (__syscall_slong_t)mq_msgsize; + + for (i = 0; i < (sizeof(mq_anomaly_list) / sizeof(mq_anomaly_list[0])); i++) { + if (strcmp(normalized_qname, mq_anomaly_list[i].name) == 0) { + mqattr.mq_maxmsg = (__syscall_slong_t)mq_anomaly_list[i].maxMsg; + break; + } + } + + + q_fd = mq_open(normalized_qname, O_RDONLY | O_CREAT | O_CLOEXEC, 0666, &mqattr); + + if (q_fd != -1) { + rcvHndl = (SQhandle *)malloc(sizeof(SQhandle)); + if (rcvHndl != NULL) { + rcvHndl->check_code = MQ_CHECK_CODE; + rcvHndl->fd = q_fd; + rcvHndl->q_name = normalized_qname; + rcvHndl->q_type = eQTypeReveiver; + + ///////////////////////////////////////// + rcvHndl->threadid = 0; + ///////////////////////////////////////// + + // Set the return handle to rcvHndl + rtnHandle = rcvHndl; + } + + } + } + + if (INVALID_HANDLE == rtnHandle) { + // couldn't connect the queue, + // release the memory to normalized queue name + if (normalized_qname != NULL) { + free(normalized_qname); + normalized_qname = NULL; // mb20110108 item 11 + } + } + + return rtnHandle; +} + +HANDLE OpenReceiver(PCSTR name) { + return openReceiverInternal(name, MAX_MESSAGES_STORED_IN_QUEUE, MAX_QUEUE_MSG_SIZE, FALSE); +} + +HANDLE openSyncReceiver(PCSTR name) { + return openReceiverInternal(name, MAX_SYNC_RESPONSE_STORED_IN_QUEUE , MAX_QUEUE_MSG_SIZE, TRUE); +} + +static HANDLE openSenderInternal(PCSTR name, UI_32 mq_maxmsg, UI_32 mq_msgsize, BOOL is_internal, BOOL zero_copy) { + HANDLE rtnHandle = INVALID_HANDLE; // invalid until made valid. + SI_32 q_fd = -1; // fd to queue + SQhandle *sndHndl = NULL; + PSTR normalized_qname = NULL; + size_t norm_qname_size = 0; + + struct mq_attr mqattr; + + // Check for invalid name + if (name == NULL) { + return rtnHandle; + } + + if (strlen(name) >= MAX_QUEUE_NAME_SIZE) { + return rtnHandle; + } + + norm_qname_size = strlen(name) + 2; + normalized_qname = (PSTR)malloc(norm_qname_size); + + if (NULL == normalized_qname) { + return rtnHandle; + } + + if (0 != GetNormalizedMqName(normalized_qname, name, norm_qname_size)) { + int i; + + + if (!is_internal && strlen(normalized_qname) > LIMIT_QUEUE_NAME_SIZE) { + free(normalized_qname); + return INVALID_HANDLE; + } + + mqattr.mq_flags = 0; + mqattr.mq_maxmsg = (__syscall_slong_t)mq_maxmsg; + mqattr.mq_msgsize = (__syscall_slong_t)mq_msgsize; + + for (i = 0; i < (sizeof(mq_anomaly_list) / sizeof(mq_anomaly_list[0])); i++) { + if (strcmp(normalized_qname, mq_anomaly_list[i].name) == 0) { + mqattr.mq_maxmsg = (__syscall_slong_t)mq_anomaly_list[i].maxMsg; + break; + } + } + + q_fd = mq_open(normalized_qname, O_WRONLY | O_CREAT | O_NONBLOCK | O_CLOEXEC, 0666, &mqattr); + + if (q_fd != -1) { + sndHndl = (SQhandle *)malloc(sizeof(SQhandle)); + if (NULL != sndHndl) { + sndHndl->check_code = MQ_CHECK_CODE; + sndHndl->fd = q_fd; + sndHndl->q_name = normalized_qname; + sndHndl->q_type = eQTypeSender; + + sndHndl->threadid = 0; + + + // Set the return handle to sndHndl + rtnHandle = sndHndl; + + if (zero_copy) { + sndHndl->sendbuf = malloc(MAX_QUEUE_MSG_SIZE); + if (sndHndl->sendbuf == NULL) { + // LCOV_EXCL_START 5: malloc's error case + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + free(sndHndl); + rtnHandle = INVALID_HANDLE; + // LCOV_EXCL_STOP + } + } else { + sndHndl->sendbuf = NULL; + } + } + } + } + + if (INVALID_HANDLE == rtnHandle) { + // couldn't connect the queue, + // release the memory to normalized queue name + if (normalized_qname != NULL) { + free(normalized_qname); + normalized_qname = NULL; // mb20110108 item 11 + } + if (q_fd != -1) { + mq_close(q_fd); + } + } + + return rtnHandle; // invalid until made valid. +} + +HANDLE OpenSender(PCSTR name) { + return openSenderInternal(name, MAX_MESSAGES_STORED_IN_QUEUE, MAX_QUEUE_MSG_SIZE, FALSE, FALSE); +} + + +HANDLE OpenSenderChild(PCSTR name, pthread_t threadid) { + HANDLE h = OpenSender(name); + if (INVALID_HANDLE != h) { + SQhandle *sq = (SQhandle *)h; + sq->threadid = threadid; + } + return h; +} + + +HANDLE openSyncSender(PCSTR name) { + return openSenderInternal(name, MAX_SYNC_RESPONSE_STORED_IN_QUEUE, MAX_QUEUE_MSG_SIZE, TRUE, FALSE); +} + +HANDLE openSenderZc(PCSTR name) { + return openSenderInternal(name, MAX_MESSAGES_STORED_IN_QUEUE, MAX_QUEUE_MSG_SIZE, FALSE, TRUE); +} + + +EFrameworkunifiedStatus JoinChild(HANDLE hChildApp) { + // mb20110108 Code re-structured per comments 24 & 25 + if (mqCheckValidHandle(hChildApp)) { + SQhandle *sq = (SQhandle *)hChildApp; + return TranslateError(pthread_join(sq->threadid, NULL)); + } else { + return eFrameworkunifiedStatusFail; + } +} + +EFrameworkunifiedStatus GetChildThreadPriority(HANDLE hChildApp, PSI_32 threadPrio) { + EFrameworkunifiedStatus eStatus = eFrameworkunifiedStatusFail; + // LCOV_EXCL_BR_START 6:GetChildThreadPriority is called by McGetChildThreadPriority, and hChildApp will check there. + if (mqCheckValidHandle(hChildApp)) { + // LCOV_EXCL_BR_STOP + SQhandle *sq = (SQhandle *)hChildApp; + SI_32 schedPolicy; // this is needed according to syntax of pthread_getschedparam. api not available to get prio directly. + struct sched_param schedParam; + eStatus = TranslateError(pthread_getschedparam(sq->threadid, &schedPolicy, &schedParam)); + + *threadPrio = schedParam.sched_priority; + } else { + // LCOV_EXCL_START 6:GetChildThreadPriority is called by McGetChildThreadPriority, and hChildApp will check there. + AGL_ASSERT_NOT_TESTED(); // LCOV_EXCL_LINE 200: test assert + eStatus = eFrameworkunifiedStatusInvldHandle; + // LCOV_EXCL_STOP + } + return eStatus; +} + +/// endhack... +///////////////////////////////////////// + +EFrameworkunifiedStatus SendMessage(HANDLE hMessage, UI_32 length, PVOID data) { + return SendMessageWithPriority(hMessage, length, data, eFrameworkunifiedMsgPrioNormal); +} + +EFrameworkunifiedStatus SendMessageWithPriority(HANDLE hMessage, UI_32 length, PVOID data, EFrameworkunifiedMessagePriorties priority) { + // define a Q handle structure + SQhandle *sndHndl = NULL; + + // mb20110108 Added per comments 27 & 28 + if (length > 0 && NULL == data) { + return eFrameworkunifiedStatusInvldBuf; + } + + // check handle for null case... + if (mqCheckValidHandle(hMessage) == FALSE) { + return eFrameworkunifiedStatusInvldHandle; + } + + sndHndl = (SQhandle *)hMessage; + + // check to see if this is a sender handle + if (sndHndl->q_type != eQTypeSender) { + return eFrameworkunifiedStatusInvldHndlType; + } + + if (-1 == mq_send((mqd_t)sndHndl->fd, (PCSTR)data, (size_t)length, (unsigned int)priority)) { + if (errno == EAGAIN) { + return eFrameworkunifiedStatusMsgQFull; + } else { + return TranslateError(errno); + } + } + return eFrameworkunifiedStatusOK; +} + +SI_32 ReceiveMessage(HANDLE hMessage, UI_32 length, PVOID data) { + // define a Q handle structure + SQhandle *rcvHndl = NULL; + + // check handle for null case... + if (mqCheckValidHandle(hMessage) == FALSE) { + errno = ENODATA; + return -1; + } + + rcvHndl = (SQhandle *)hMessage; + + // check to see if this is a receiver handle + if (rcvHndl->q_type != eQTypeReveiver) { + errno = ENODATA; + return -1; + } + + + return (SI_32)mq_receive((mqd_t)rcvHndl->fd, (char *)data, (size_t)length, NULL); +} + +EFrameworkunifiedStatus CloseReceiver(HANDLE handle) { + SQhandle *rcvHndl = NULL; + SI_32 q_fd; + + // check handle for null case... + if (mqCheckValidHandle(handle) == FALSE) { + return eFrameworkunifiedStatusInvldHandle; + } + + rcvHndl = (SQhandle *)handle; + + // check to see if this is a receiver handle + if (rcvHndl->q_type != eQTypeReveiver) { + return eFrameworkunifiedStatusInvldHndlType; + } + + rcvHndl->check_code = 0; + q_fd = rcvHndl->fd; + + if (NULL != rcvHndl->q_name) { + free(rcvHndl->q_name); // remove the memory to the name + rcvHndl->q_name = NULL; + } + free((void *)handle); // remove handle.. now.. + handle = INVALID_HANDLE; + + return ((-1 == mq_close((mqd_t)q_fd)) ? eFrameworkunifiedStatusInvldHandle : eFrameworkunifiedStatusOK); +} + +EFrameworkunifiedStatus CloseSender(HANDLE handle) { + SQhandle *sndHndl = NULL; + SI_32 q_fd; + + // check handle for null case... + if (mqCheckValidHandle(handle) == FALSE) { + return eFrameworkunifiedStatusInvldHandle; + } + + sndHndl = (SQhandle *)handle; + + // check to see if this is a sender handle + if (sndHndl->q_type != eQTypeSender) { + return eFrameworkunifiedStatusInvldHndlType; + } + + sndHndl->check_code = 0; + q_fd = sndHndl->fd; // copy the fd, need it to close the queues.... + + if (NULL != sndHndl->q_name) { + free(sndHndl->q_name); // remove the memory to the name + sndHndl->q_name = NULL; + } + if (NULL != sndHndl->sendbuf) { + free(sndHndl->sendbuf); + sndHndl->sendbuf = NULL; + } + free((void *)handle); // remove handle.. now.. + handle = INVALID_HANDLE; // invalidate handle so user doesn't reuse... + + return (-1 == mq_close((mqd_t)q_fd)) ? eFrameworkunifiedStatusInvldHandle : eFrameworkunifiedStatusOK; +} + +static UI_8 IsMessageAvailable(SI_32 fd) { + struct mq_attr sMqStatus; + if (-1 == mq_getattr(fd, &sMqStatus)) { + // Error Detected. + return 0; + } else { + if (0 < sMqStatus.mq_curmsgs) { + return 1; + } else { + return 0; + } + } +} + +void Flush(HANDLE hMessage) { + SQhandle *rcvHndl = NULL; + + if (mqCheckValidHandle(hMessage)) { + rcvHndl = (SQhandle *)hMessage; + + if (rcvHndl->q_type != eQTypeReveiver) { + return; + } + + // check there is anything on the queue before going into the loop.... + if (IsMessageAvailable(rcvHndl->fd)) { + CHAR l_pReceiveBuffer_o[MAX_QUEUE_MSG_SIZE]; + + // read till there isn't anything on the queue. + while (IsMessageAvailable(rcvHndl->fd)) { + mq_receive((mqd_t)rcvHndl->fd, l_pReceiveBuffer_o, (size_t)MAX_QUEUE_MSG_SIZE, NULL); + } + } + } +} + +EQType GetQueueType(HANDLE hMessage) { + EQType qType = eQTypeInvld; + + if (mqCheckValidHandle(hMessage)) { + SQhandle *handle = (SQhandle *)hMessage; + qType = handle->q_type; + } + + return qType; +} + +PCSTR GetQueueName(HANDLE hMessage) { + PCSTR name = NULL; + + if (mqCheckValidHandle(hMessage)) { + SQhandle *hMsgQ = (SQhandle *)hMessage; + + if (hMsgQ->q_type == eQTypeSender || + hMsgQ->q_type == eQTypeReveiver) { + name = hMsgQ->q_name; + } + } + + return name; +} + +int GetQueueFD(HANDLE hMessage) { + int fd = -1; + + if (mqCheckValidHandle(hMessage)) { + SQhandle *hMsgQ = (SQhandle *)hMessage; + + if (hMsgQ->q_type == eQTypeSender || + hMsgQ->q_type == eQTypeReveiver) { + fd = hMsgQ->fd; + } + } + + return fd; +} -- cgit 1.2.3-korg