diff options
Diffstat (limited to 'NodeStateAccess')
25 files changed, 2844 insertions, 1815 deletions
diff --git a/NodeStateAccess/CMakeLists.txt b/NodeStateAccess/CMakeLists.txt new file mode 100644 index 0000000..896a545 --- /dev/null +++ b/NodeStateAccess/CMakeLists.txt @@ -0,0 +1,45 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Vignesh_Rajendran@mentor.com +# +# CMake file of NodeStateAccess +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) + +project(NodeStateAccess LANGUAGES CXX) + +file(GLOB SOURCE_FILES *.cpp) + +add_library(NodeStateAccess SHARED ${SOURCE_FILES}) + +target_compile_features(NodeStateAccess PRIVATE cxx_std_11) + +target_compile_options(NodeStateAccess PRIVATE -Werror -pthread) + +target_link_libraries(NodeStateAccess PRIVATE + ${COMMONAPI_LIBS} + ${DLT_LIBRARIES} + org.genivi.nodestatemanager.commonapi.core.stub + org.genivi.nodestatemanager.commonapi.someip.stub + pthread) + +install(TARGETS NodeStateAccess + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING + PATTERN "*.h" + PATTERN "*.hpp" + PATTERN "interfaces" EXCLUDE)
\ No newline at end of file diff --git a/NodeStateAccess/Makefile.am b/NodeStateAccess/Makefile.am deleted file mode 100644 index ea33d77..0000000 --- a/NodeStateAccess/Makefile.am +++ /dev/null @@ -1,61 +0,0 @@ -################################################################################ -# -# Copyright (C) 2012 Continental Automotive Systems, Inc. -# -# Author: Jean-Pierre.Bogler@continental-corporation.com -# -# Makefile template for the NodeStateAccess library -# -# Process this file with automake to produce a Makefile.in. -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. -# -############################################################################### - -lib_LTLIBRARIES = libNodeStateAccess.la - -libNodeStateAccess_la_SOURCES = NodeStateAccess.c \ - generated/NodeStateConsumer.c \ - generated/NodeStateLifecycleControl.c \ - generated/NodeStateLifecycleConsumer.c - -libNodeStateAccess_la_CFLAGS = -I$(top_srcdir)/NodeStateManager \ - -I generated \ - $(GIO_CFLAGS) \ - $(GIO_UNIX_CFLAGS) \ - $(GLIB_CFLAGS) \ - $(GOBJECT_CFLAGS) - -libNodeStateAccess_la_LIBDADD = $(GIO_LIBS) \ - $(GIO_UNIX_LIBS) \ - $(GLIB_LIBS) \ - $(GOBJECT_LIBS) - -libNodeStateAccess_la_LDFLAGS = -avoid-version - -# List generated headers here to assert that they are available when built is started -BUILT_SOURCES = generated/NodeStateConsumer.h \ - generated/NodeStateLifecycleControl.h \ - generated/NodeStateLifecycleConsumer.h - -# Delete all generated files on 'make clean' -CLEANFILES = generated/NodeStateConsumer.c \ - generated/NodeStateConsumer.h \ - generated/NodeStateLifecycleControl.c \ - generated/NodeStateLifecycleControl.h \ - generated/NodeStateLifecycleConsumer.c \ - generated/NodeStateLifecycleConsumer.h - -# Targets to create generated sources during the build -generated/NodeStateConsumer.c generated/NodeStateConsumer.h: model/org.genivi.NodeStateManager.Consumer.xml - gdbus-codegen --interface-prefix=org.genivi.NodeStateManager. --c-namespace=NodeState --generate-c-code=generated/NodeStateConsumer --generate-docbook=doc/NodeStateConsumer model/org.genivi.NodeStateManager.Consumer.xml - -generated/NodeStateLifecycleControl.c generated/NodeStateLifecycleControl.h: model/org.genivi.NodeStateManager.LifecycleControl.xml - gdbus-codegen --interface-prefix=org.genivi.NodeStateManager. --c-namespace=NodeState --generate-c-code=generated/NodeStateLifecycleControl --generate-docbook=doc/LifecycleControl model/org.genivi.NodeStateManager.LifecycleControl.xml - -generated/NodeStateLifecycleConsumer.c generated/NodeStateLifecycleConsumer.h: model/org.genivi.NodeStateManager.LifecycleConsumer.xml - gdbus-codegen --interface-prefix=org.genivi.NodeStateManager. --c-namespace=NodeState --generate-c-code=generated/NodeStateLifecycleConsumer --generate-docbook=doc/LifecycleConsumer model/org.genivi.NodeStateManager.LifecycleConsumer.xml - - diff --git a/NodeStateAccess/NodeStateAccess.c b/NodeStateAccess/NodeStateAccess.c deleted file mode 100644 index c167247..0000000 --- a/NodeStateAccess/NodeStateAccess.c +++ /dev/null @@ -1,1312 +0,0 @@ -/********************************************************************************************************************** -* -* Copyright (C) 2012 Continental Automotive Systems, Inc. -* -* Author: Jean-Pierre.Bogler@continental-corporation.com -* -* Interface between NodeStateManager and IPC -* -* This source file is a part of the NodeStateAccess library (NSMA). -* The architecture requires that the NodeStateManager (NSM) is independent from the D-Bus binding and code generated by -* "gdbus-codegen". Therefore, the D-Bus communication and generated D-Bus objects are handled inside of this library. -* The library offers the NSM an interface to use objects generated via gdbus-codgen. -* -* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. -* -**********************************************************************************************************************/ - - -/********************************************************************************************************************** -* -* Header includes -* -**********************************************************************************************************************/ - -/* generic includes for the NodeStateAccess library */ -#include "gio/gio.h" /* glib types */ -#include "NodeStateAccess.h" /* own header */ -#include "NodeStateTypes.h" /* Type defintions of the NSM */ -#include <glib-unix.h> /* Catch SIGTERM */ - -/* additional includes to use D-Bus */ -#include "string.h" /* memcpy, memset, etc. */ -#include "NodeStateConsumer.h" /* generated NodeStateConsumer object */ -#include "NodeStateLifecycleControl.h" /* generated LifecycleControl object */ -#include "NodeStateLifecycleConsumer.h" /* generated LifecycleConsumer object */ - - -/********************************************************************************************************************** -* -* Local variables -* -**********************************************************************************************************************/ - -/* Variables to handle main loop and bus connection */ -static GMainLoop *NSMA__pMainLoop = NULL; -static GDBusConnection *NSMA__pBusConnection = NULL; -static gboolean NSMA__boLoopEndByUser = FALSE; -static guint NSMA__u32ConnectionId = 0; -static gboolean NSMA__boInitialized = FALSE; - -/* Variables to handle life cycle client calls */ -static guint NSMA__u32TimerId = 0; -static NodeStateLifeCycleConsumer *NSMA__pCurrentLcConsumer = NULL; - -/* Variables for D-Bus objects */ -static NodeStateConsumer *NSMA__pNodeStateConsumerObj = NULL; -static NodeStateLifecycleControl *NSMA__pLifecycleControlObj = NULL; - -/* Structure with callback functions to the NSM */ -static NSMA_tstObjectCallbacks NSMA__stObjectCallbacks = {0}; - - -/********************************************************************************************************************** -* -* Prototypes for file local functions (see implementation for description) -* -**********************************************************************************************************************/ - -/* Internal D-Bus callbacks */ -static gboolean NSMA__boOnHandleSetBootMode (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32BootMode, - gpointer pUserData); -static gboolean NSMA__boOnHandleSetNodeState (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32NodeStateId, - gpointer pUserData); -static gboolean NSMA__boOnHandleSetApplicationMode (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32ApplicationModeId, - gpointer pUserData); -static gboolean NSMA__boOnHandleRequestNodeRestart (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32RestartReason, - const guint i32RestartType, - gpointer pUserData); -static gboolean NSMA__boOnHandleCheckLucRequired (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - gpointer pUserData); -static gboolean NSMA__boOnHandleRegisterSession (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - const gint i32SessionState, - gpointer pUserData); -static gboolean NSMA__boOnHandleUnRegisterSession (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - gpointer pUserData); -static gboolean NSMA__boOnHandleRegisterLifecycleClient (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar* sBusName, - const gchar* sObjName, - const guint u32ShutdownMode, - const guint u32TimeoutMs, - gpointer pUserData); -static gboolean NSMA__boOnHandleUnRegisterLifecycleClient(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar* sBusName, - const gchar* sObjName, - const guint u32ShutdownMode, - gpointer pUserData); -static gboolean NSMA__boOnHandleLifecycleRequestComplete (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const guint u32RequestId, - const gint i32Status, - gpointer pUserData); -static gboolean NSMA__boOnHandleGetApplicationMode (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData); -static gboolean NSMA__boOnHandleGetSessionState (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gint i32SeatId, - gpointer pUserData); -static gboolean NSMA__boOnHandleSetSessionState (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - const gint i32SessionState, - gpointer pUserData); -static gboolean NSMA__boOnHandleGetNodeState (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData); -static gboolean NSMA__boOnHandleSetAppHealthStatus (NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gchar *sAppName, - const gboolean boAppState, - gpointer pUserData); -static gboolean NSMA__boOnHandleGetAppHealthCount (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData); -static gboolean NSMA__boOnHandleGetInterfaceVersion (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData); - -/* Internal bus connection callbacks */ -static void NSMA__vOnBusAcquired (GDBusConnection *pConnection, const gchar* sName, gpointer pUserData); -static void NSMA__vOnNameAcquired(GDBusConnection *pConnection, const gchar* sName, gpointer pUserData); -static void NSMA__vOnNameLost (GDBusConnection *pConnection, const gchar* sName, gpointer pUserData); - -/* Linux signal callback */ -static gboolean NSMA__boOnHandleSigterm(gpointer pUserData); - -/* Internal callback for async. life cycle client returns */ -static void NSMA__vOnLifecycleRequestFinish(GObject *pSrcObject, GAsyncResult *pRes, gpointer pUserData); - - -/********************************************************************************************************************** -* -* Local (static) functions -* -**********************************************************************************************************************/ - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when the "boot mode" should be set. -* -* @param pLifecycleControl: Pointer to a LifecycleControl object -* @param pInvocation: Pointer to method invocation object -* @param i32BootMode: New boot mode -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSetBootMode(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32BootMode, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfSetBootModeCb(i32BootMode); - - node_state_lifecycle_control_complete_set_boot_mode(pLifecycleControl, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when the "node state" should be set. -* -* @param pLifecycleControl: Pointer to a LifecycleControl object -* @param pInvocation: Pointer to method invocation object -* @param i32NodeStateId: New node state -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSetNodeState(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32NodeStateId, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfSetNodeStateCb((NsmNodeState_e) i32NodeStateId); - - node_state_lifecycle_control_complete_set_node_state(pLifecycleControl, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when the "application mode" should be set. -* -* @param pLifecycleControl: Pointer to a LifecycleControl object -* @param pInvocation: Pointer to method invocation object -* @param i32ApplicationModeId: New application mode -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSetApplicationMode(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32ApplicationModeId, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfSetAppModeCb((NsmApplicationMode_e) i32ApplicationModeId); - - node_state_lifecycle_control_complete_set_application_mode(pLifecycleControl, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when the node should be reset. -* -* @param pLifecycleControl: Pointer to a LifecycleControl object -* @param pInvocation: Pointer to method invocation object -* @param i32RestartReason: Restart reason -* @param i32RestartType: Restart type -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleRequestNodeRestart(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gint i32RestartReason, - const guint u32RestartType, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfRequestNodeRestartCb((NsmRestartReason_e) i32RestartReason, u32RestartType); - - node_state_lifecycle_control_complete_request_node_restart(pLifecycleControl, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when a check for LUC is required. -* -* @param pLifecycleControl: Pointer to a LifecycleControl object -* @param pInvocation: Pointer to method invocation object -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleCheckLucRequired(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - gpointer pUserData) -{ - gboolean boLucRequired = FALSE; - - boLucRequired = NSMA__stObjectCallbacks.pfCheckLucRequiredCb(); - - node_state_lifecycle_control_complete_check_luc_required(pLifecycleControl, pInvocation, boLucRequired); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called when an application has become invalid or valid again. -* -* @param pLifecycleControl: Caller of the D-Bus interface -* @param pInvocation: Pointer to the interface invocation -* @param sAppName: Application which changed its state. -* @param boAppState: Indicates whether the application has become invalid or valid again. -* @param pUserData: Optionally user data (not used) -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSetAppHealthStatus(NodeStateLifecycleControl *pLifecycleControl, - GDBusMethodInvocation *pInvocation, - const gchar *sAppName, - const gboolean boAppState, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfSetAppHealthStatusCb(sAppName, boAppState); - - node_state_lifecycle_control_complete_set_app_health_status(pLifecycleControl, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when a new session should be registered. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to method invocation object -* @param sSessionName: Name of the new session -* @param i32SessionState: Initial state of the new session -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleRegisterSession(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - const gint i32SessionState, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfRegisterSessionCb(sSessionName, - sSessionOwner, - (NsmSeat_e) i32SeatId, - (NsmSessionState_e) i32SessionState); - - node_state_consumer_complete_register_session(pConsumer, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when a session should be unregistered. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to method invocation object -* @param sSessionName: Name of the new session -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleUnRegisterSession (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfUnRegisterSessionCb(sSessionName, sSessionOwner, (NsmSeat_e) i32SeatId); - - node_state_consumer_complete_un_register_session(pConsumer, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when a lifecycle client should be registered. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to method invocation object -* @param sBusName: Bus name of the remote application that hosts the lifecycle client interface -* @param sObjName: Object name of the lifecycle client -* @param u32ShutdownMode: Shutdown mode for which the client wants to be informed -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleRegisterLifecycleClient (NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sBusName, - const gchar *sObjName, - const guint u32ShutdownMode, - const guint u32TimeoutMs, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfRegisterLifecycleClientCb(sBusName, - sObjName, - u32ShutdownMode, - u32TimeoutMs); - - node_state_consumer_complete_register_shutdown_client(pConsumer, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop, when a lifecycle client should be unregistered or a shutdown -* mode should be removed. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to method invocation object -* @param sBusName: Bus name of the remote application that hosts the lifecycle client interface -* @param sObjName: Object name of the lifecycle client -* @param u32ShutdownMode: Shutdown mode for which the client wants to unregister -* @param pUserData: Optionally user data (not used) -* -* @return: TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleUnRegisterLifecycleClient(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sBusName, - const gchar *sObjName, - const guint u32ShutdownMode, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfUnRegisterLifecycleClientCb(sBusName, sObjName, u32ShutdownMode); - - node_state_consumer_complete_un_register_shutdown_client(pConsumer, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when the application mode needs to be retrieved. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to a method invocation object -* @param pUserData: Pointer to optional user data (not used) -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleGetApplicationMode(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - NsmApplicationMode_e enApplicationMode = NsmApplicationMode_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfGetAppModeCb(&enApplicationMode); - - node_state_consumer_complete_get_application_mode(pConsumer, - pInvocation, - (gint) enApplicationMode, - (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop a session state should be retrieved. -* -* @param pConsumer: Caller of the D-Bus interface -* @param pInvocation: Pointer to the interface invocation -* @param sSessionName: Name of the session whose state just be returned -* @param sSessionName: Owner of the session whose state just be returned -* @param i32SeatId: Seat of the session -* @param i32SessionState: New state of the session -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleGetSessionState(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gint i32SeatId, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - NsmSessionState_e enSessionState = NsmSessionState_Unregistered; - - enErrorStatus = NSMA__stObjectCallbacks.pfGetSessionStateCb(sSessionName, (NsmSeat_e) i32SeatId, &enSessionState); - - node_state_consumer_complete_get_session_state(pConsumer, pInvocation, (gint) enSessionState, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when a session state should be set. -* -* @param pConsumer: Caller of the D-Bus interface -* @param pInvocation: Pointer to the interface invocation -* @param sSessionName: Name of the session whose state just be set -* @param i32SeatId: Seat of the session -* @param i32SessionState: New state of the session -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSetSessionState(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const gchar *sSessionName, - const gchar *sSessionOwner, - const gint i32SeatId, - const gint i32SessionState, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfSetSessionStateCb(sSessionName, - sSessionOwner, - (NsmSeat_e) i32SeatId, - (NsmSessionState_e) i32SessionState); - - node_state_consumer_complete_set_session_state(pConsumer, pInvocation, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when the NodeState needs to be retrieved. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to a method invocation object -* @param pUserData: Pointer to optional user data (not used) -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleGetNodeState(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - NsmNodeState_e enNodeState = NsmNodeState_NotSet; - - enErrorStatus = NSMA__stObjectCallbacks.pfGetNodeStateCb(&enNodeState); - - node_state_consumer_complete_get_node_state(pConsumer, pInvocation, (gint) enNodeState, (gint) enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when the AppHealthCount (number of failed applications) needs to -* be retrieved. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to a method invocation object -* @param pUserData: Pointer to optional user data (not used) -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleGetAppHealthCount(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData) -{ - guint u32AppHealthCount = 0; - - u32AppHealthCount = NSMA__stObjectCallbacks.pfGetAppHealthCountCb(); - - node_state_consumer_complete_get_app_health_count(pConsumer, pInvocation, u32AppHealthCount); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when the interface version needs to be retrieved. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to a method invocation object -* @param pUserData: Pointer to optional user data (not used) -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleGetInterfaceVersion(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - gpointer pUserData) -{ - guint u32InterfaceVersion = 0; - - u32InterfaceVersion = NSMA__stObjectCallbacks.pfGetInterfaceVersionCb(); - - node_state_consumer_complete_get_interface_version(pConsumer, pInvocation, u32InterfaceVersion); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called when a connection to the D-Bus could be established. -* -* @param pConnection: Connection, which was acquired -* @param sName: Bus name -* @param pUserData: Optionally user data -* -* @return void -* -**********************************************************************************************************************/ -static void NSMA__vOnBusAcquired(GDBusConnection *pConnection, const gchar* sName, gpointer pUserData) -{ - /* Store the connection. Needed later, to create life cycle clients. */ - NSMA__pBusConnection = pConnection; - - /* Do not automatically exit the main loop when connection is lost. - * The program terminates nevertheless, but will give useful traces. - */ - g_dbus_connection_set_exit_on_close(NSMA__pBusConnection, FALSE); - - /* Register the callbacks */ - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-set-boot-mode", G_CALLBACK(NSMA__boOnHandleSetBootMode), NULL); - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-set-node-state", G_CALLBACK(NSMA__boOnHandleSetNodeState), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-get-node-state", G_CALLBACK(NSMA__boOnHandleGetNodeState), NULL); - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-set-application-mode", G_CALLBACK(NSMA__boOnHandleSetApplicationMode), NULL); - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-request-node-restart", G_CALLBACK(NSMA__boOnHandleRequestNodeRestart), NULL); - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-check-luc-required", G_CALLBACK(NSMA__boOnHandleCheckLucRequired), NULL); - (void) g_signal_connect(NSMA__pLifecycleControlObj, "handle-set-app-health-status", G_CALLBACK(NSMA__boOnHandleSetAppHealthStatus), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-register-session", G_CALLBACK(NSMA__boOnHandleRegisterSession), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-un-register-session", G_CALLBACK(NSMA__boOnHandleUnRegisterSession), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-register-shutdown-client", G_CALLBACK(NSMA__boOnHandleRegisterLifecycleClient), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-un-register-shutdown-client", G_CALLBACK(NSMA__boOnHandleUnRegisterLifecycleClient), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-get-application-mode", G_CALLBACK(NSMA__boOnHandleGetApplicationMode), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-get-session-state", G_CALLBACK(NSMA__boOnHandleGetSessionState), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-set-session-state", G_CALLBACK(NSMA__boOnHandleSetSessionState), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-get-app-health-count", G_CALLBACK(NSMA__boOnHandleGetAppHealthCount), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-get-interface-version", G_CALLBACK(NSMA__boOnHandleGetInterfaceVersion), NULL); - (void) g_signal_connect(NSMA__pNodeStateConsumerObj, "handle-lifecycle-request-complete", G_CALLBACK(NSMA__boOnHandleLifecycleRequestComplete), NULL); - - /* Export the interfaces */ - if(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(NSMA__pNodeStateConsumerObj), - NSMA__pBusConnection, - NSM_CONSUMER_OBJECT, - NULL) == TRUE) - { - if(g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(NSMA__pLifecycleControlObj), - NSMA__pBusConnection, - NSM_LIFECYCLE_OBJECT, - NULL) != TRUE) - { - /* Error: The LifecycleControl interface could not be exported */ - NSMA__boLoopEndByUser = FALSE; - g_main_loop_quit(NSMA__pMainLoop); - } - } - else - { - /* Error: The NodeStateConsumer interface could not be exported */ - NSMA__boLoopEndByUser = FALSE; - g_main_loop_quit(NSMA__pMainLoop); - } -} - - -/********************************************************************************************************************** -* -* The function is called when the "bus name" could be acquired on the D-Bus. -* -* @param pConnection: Connection over which the bus name was acquired -* @param sName: Acquired bus name -* @param pUserData: Optionally user data -* -* @return void -* -**********************************************************************************************************************/ -static void NSMA__vOnNameAcquired(GDBusConnection *pConnection, const gchar* sName, gpointer pUserData) -{ - /* There is nothing to do in this function, it is only need as callback function. */ -} - - -/********************************************************************************************************************** -* -* The function is called if either no connection to D-Bus could be established or the bus name could not be acquired. -* -* @param pConnection: Connection. If it is NULL, no D-Bus connection could be established. -* Otherwise the bus name was lost. -* @param sName: Bus name -* @param pUserData: Optionally user data -* -* @return void -* -**********************************************************************************************************************/ -static void NSMA__vOnNameLost(GDBusConnection *pConnection, const gchar* sName, gpointer pUserData) -{ - /* If this function was called, either the bus connection could not be established or the bus name could - * not be obtained. In both cases, stop the main loop. - */ - - NSMA__boLoopEndByUser = FALSE; - g_main_loop_quit(NSMA__pMainLoop); -} - - -/********************************************************************************************************************** -* -* The function is called when the async. call to a life cycle clients "LifecycleRequest" method timed out. -* -* @param pUserData: Optionally user data (not used) -* -* @return FALSE: Tell the loop to detach and destroy the time out source. -* -**********************************************************************************************************************/ -static gboolean NSMA__boHandleRequestTimeout(gpointer pUserData) -{ - NSMA__pCurrentLcConsumer = NULL; - NSMA__stObjectCallbacks.pfLcClientRequestFinish(NsmErrorStatus_Error); - - return FALSE; -} - - -/********************************************************************************************************************** -* -* The function is called when the async. call to a life cycle clients "LifecycleRequest" method delivered a value. -* If the returned error code is not "NsmErrorStatus_ResponsePending", the error code will be forwarded to the NSM. -* Otherwise, a timer will be started and the life cycle client will get another "default timeout" time, to call -* the completion function "NSMA__boOnHandleLifecycleRequestComplete". -* -* @param pSrcObject: Source object that delivered the async. value -* @param pRes: Result of the call. -* @param pUserData: Optionally user data (not used). -* -**********************************************************************************************************************/ -static void NSMA__vOnLifecycleRequestFinish(GObject *pSrcObject, GAsyncResult *pRes, gpointer pUserData) -{ - /* Function local variables. */ - NsmErrorStatus_e enErrorCode = NsmErrorStatus_NotSet; /* Error returned by lifecycle client */ - guint u32Timeout = 0; - - /* Pass proxy object and async. result to get the return value of the lifecycle client's method and D-Bus errors. */ - - /* Check if a D-Bus error occurred */ - if(node_state_life_cycle_consumer_call_lifecycle_request_finish(NODE_STATE_LIFE_CYCLE_CONSUMER(pSrcObject), - (gint*) &enErrorCode, - pRes, - NULL) == TRUE) - { - /* The returned value could be read, check it! */ - if(enErrorCode == NsmErrorStatus_ResponsePending) - { - /* The client returned response pending. Start timer to wait for final result. */ - u32Timeout = g_dbus_proxy_get_default_timeout(G_DBUS_PROXY(pSrcObject)); - NSMA__u32TimerId = g_timeout_add_full(G_PRIORITY_DEFAULT, u32Timeout, &NSMA__boHandleRequestTimeout, NULL, NULL); - } - else - { - /* The client returned a final value. Pass it to the NSM */ - NSMA__pCurrentLcConsumer = NULL; - NSMA__stObjectCallbacks.pfLcClientRequestFinish(enErrorCode); - } - } - else - { - /* The clients return value could not be read. Pass an error to the NSM. */ - NSMA__pCurrentLcConsumer = NULL; - NSMA__stObjectCallbacks.pfLcClientRequestFinish(NsmErrorStatus_Dbus); - } -} - - -/********************************************************************************************************************** -* -* The function is called from the g_main_loop when a life cycle client finished an "asynchronous" life cycle request. -* -* @param pConsumer: Pointer to a NodeStateConsumer object -* @param pInvocation: Pointer to a method invocation object -* @param u32RequestId: Request ID that has been passed to client when calling his LifecycleRequest method -* @param i32Status: Status/Return value of the client. -* -* @return TRUE: Tell D-Bus that method succeeded. -* FALSE: Let D-Bus send an error. -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleLifecycleRequestComplete(NodeStateConsumer *pConsumer, - GDBusMethodInvocation *pInvocation, - const guint u32RequestId, - const gint i32Status, - gpointer pUserData) -{ - NsmErrorStatus_e enErrorStatus = NsmErrorStatus_NotSet; - - /* Check if the client is the one, we are waiting for. */ - if(NSMA__pCurrentLcConsumer == (NodeStateLifeCycleConsumer*) u32RequestId) - { - enErrorStatus = NsmErrorStatus_Ok; - /* The client is the expected one. Pass the status to the NSM. */ - NSMA__stObjectCallbacks.pfLcClientRequestFinish((NsmErrorStatus_e) i32Status); - - /* Remove the timeout timer (the expected client returned) */ - g_source_remove(NSMA__u32TimerId); - } - else - { - enErrorStatus = NsmErrorStatus_Error; - } - - node_state_consumer_complete_lifecycle_request_complete(pConsumer, pInvocation, enErrorStatus); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* The function is called when the SIGTERM signal is received -* -* @param pUserData: Optional user data (not used) -* @return TRUE: Keep callback installed -* -**********************************************************************************************************************/ -static gboolean NSMA__boOnHandleSigterm(gpointer pUserData) -{ - NSMA__boLoopEndByUser = TRUE; - g_main_loop_quit(NSMA__pMainLoop); - - return TRUE; -} - - -/********************************************************************************************************************** -* -* Interfaces. Exported functions. See Header for detailed description. -* -**********************************************************************************************************************/ - -gboolean NSMA_boInit(const NSMA_tstObjectCallbacks *pstCallbacks) -{ - /* Initialize glib types */ - g_type_init(); - - /* Initialize file local variables */ - NSMA__pMainLoop = NULL; - NSMA__pBusConnection = NULL; - NSMA__u32ConnectionId = 0; - NSMA__boLoopEndByUser = FALSE; - NSMA__boInitialized = FALSE; - - NSMA__pCurrentLcConsumer = NULL; - - NSMA__pLifecycleControlObj = NULL; - NSMA__pNodeStateConsumerObj = NULL; - - memset(&NSMA__stObjectCallbacks, 0, sizeof(NSMA_tstObjectCallbacks)); - - /* Check if all callbacks for the NSM have been configured. */ - if( (pstCallbacks->pfSetBootModeCb != NULL) - && (pstCallbacks->pfSetNodeStateCb != NULL) - && (pstCallbacks->pfSetAppModeCb != NULL) - && (pstCallbacks->pfRequestNodeRestartCb != NULL) - && (pstCallbacks->pfSetAppHealthStatusCb != NULL) - && (pstCallbacks->pfCheckLucRequiredCb != NULL) - && (pstCallbacks->pfRegisterSessionCb != NULL) - && (pstCallbacks->pfUnRegisterSessionCb != NULL) - && (pstCallbacks->pfRegisterLifecycleClientCb != NULL) - && (pstCallbacks->pfUnRegisterLifecycleClientCb != NULL) - && (pstCallbacks->pfGetAppModeCb != NULL) - && (pstCallbacks->pfGetSessionStateCb != NULL) - && (pstCallbacks->pfGetNodeStateCb != NULL) - && (pstCallbacks->pfSetNodeStateCb != NULL) - && (pstCallbacks->pfSetSessionStateCb != NULL) - && (pstCallbacks->pfGetAppHealthCountCb != NULL) - && (pstCallbacks->pfGetInterfaceVersionCb != NULL) - && (pstCallbacks->pfLcClientRequestFinish != NULL)) - { - /* All callbacks are configured. */ - NSMA__boInitialized = TRUE; - - /* Store the passed callbacks. */ - memcpy(&NSMA__stObjectCallbacks, pstCallbacks, sizeof(NSMA_tstObjectCallbacks)); - - /* Create a new main loop */ - NSMA__pMainLoop = g_main_loop_new(NULL, FALSE); - - /* Create D-Bus skeleton objects */ - NSMA__pNodeStateConsumerObj = node_state_consumer_skeleton_new(); - NSMA__pLifecycleControlObj = node_state_lifecycle_control_skeleton_new(); - } - else - { - /* Error: Callbacks are configured incorrectly. */ - NSMA__boInitialized = FALSE; - } - - return NSMA__boInitialized; -} - - -gboolean NSMA_boWaitForEvents(void) -{ - /* Check if the library has been initialized (objects and callbacks are available) */ - if(NSMA__boInitialized == TRUE) - { - /* Start D-Bus connection sequence */ - NSMA__u32ConnectionId = g_bus_own_name((GBusType) NSM_BUS_TYPE, - NSM_BUS_NAME, - G_BUS_NAME_OWNER_FLAGS_NONE, - &NSMA__vOnBusAcquired, - &NSMA__vOnNameAcquired, - &NSMA__vOnNameLost, - NULL, - NULL); - - /* Add source to catch SIGTERM signal (#15) */ - g_unix_signal_add(15, &NSMA__boOnHandleSigterm, NULL); - - /* Run main loop to get D-Bus connection and export objects. The function will only return, - * if there was an internal error or it has been cancelled by the user. - */ - g_main_loop_run(NSMA__pMainLoop); - } - else - { - /* Error: The library has not been initialized. Callbacks and objects are invalid. */ - NSMA__boLoopEndByUser = FALSE; - } - - /* Return if function has been cancelled by user (TRUE) or because of an error (FALSE) */ - return NSMA__boLoopEndByUser; -} - - -gboolean NSMA_boSendNodeStateSignal(const NsmNodeState_e enNodeState) -{ - gboolean boRetVal = FALSE; - - /* Check if library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Send the signal */ - node_state_consumer_emit_node_state(NSMA__pNodeStateConsumerObj, (gint) enNodeState); - } - else - { - /* Error: Library not initialized (objects are invalid) */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSendSessionSignal(const NsmSession_s *pstSession) -{ - gboolean boRetVal = FALSE; - - /* Check if library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Send the signal */ - node_state_consumer_emit_session_state_changed(NSMA__pNodeStateConsumerObj, - pstSession->sName, - (gint) pstSession->enSeat, - (gint) pstSession->enState); - } - else - { - /* Error: Library not initialized (objects are invalid) */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSendApplicationModeSignal(const NsmApplicationMode_e enApplicationMode) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Send the signal */ - node_state_consumer_emit_node_application_mode(NSMA__pNodeStateConsumerObj, (gint) enApplicationMode); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSetBootMode(gint i32BootMode) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Set the properties value */ - node_state_consumer_set_boot_mode(NSMA__pNodeStateConsumerObj, i32BootMode); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boGetBootMode(gint *pi32BootMode) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Get the properties value */ - *pi32BootMode = node_state_consumer_get_boot_mode(NSMA__pNodeStateConsumerObj); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSetRunningReason(const NsmRunningReason_e enRunningReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Set the properties value */ - node_state_consumer_set_wake_up_reason(NSMA__pNodeStateConsumerObj, (gint) enRunningReason); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boGetRunningReason(NsmRunningReason_e *penRunningReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Get the properties value */ - *penRunningReason = (NsmRunningReason_e) node_state_consumer_get_wake_up_reason(NSMA__pNodeStateConsumerObj); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSetShutdownReason(const NsmShutdownReason_e enShutdownReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Set the properties value */ - node_state_consumer_set_shutdown_reason(NSMA__pNodeStateConsumerObj, (gint) enShutdownReason); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boGetShutdownReason(NsmShutdownReason_e *penShutdownReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Get the properties value */ - *penShutdownReason = (NsmShutdownReason_e) node_state_consumer_get_shutdown_reason(NSMA__pNodeStateConsumerObj); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boSetRestartReason(const NsmRestartReason_e enRestartReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Set the properties value */ - node_state_consumer_set_restart_reason(NSMA__pNodeStateConsumerObj, (gint) enRestartReason); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boGetRestartReason(NsmRestartReason_e *penRestartReason) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - boRetVal = TRUE; /* Get the properties value */ - *penRestartReason = (NsmRestartReason_e) node_state_consumer_get_restart_reason(NSMA__pNodeStateConsumerObj); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boQuitEventLoop(void) -{ - gboolean boRetVal = FALSE; - - /* Check if the library has been initialized (objects are available) */ - if(NSMA__boInitialized == TRUE) - { - NSMA__boLoopEndByUser = TRUE; - g_main_loop_quit(NSMA__pMainLoop); - } - else - { - /* Error: Library not initialized. Objects are invalid. */ - boRetVal = FALSE; - } - - return boRetVal; -} - - -gboolean NSMA_boFreeLcConsumerProxy(NSMA_tLcConsumerHandle hLcConsumer) -{ - g_object_unref(hLcConsumer); - - return TRUE; -} - - -NSMA_tLcConsumerHandle NSMA_hCreateLcConsumer(const gchar* sBusName, - const gchar* sObjName, - const guint u32TimeoutMs) -{ - NodeStateLifeCycleConsumer *pConsumerProxy = NULL; - - pConsumerProxy = node_state_life_cycle_consumer_proxy_new_sync(NSMA__pBusConnection, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES - | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, - sBusName, - sObjName, - NULL, - NULL); - - if(pConsumerProxy != NULL) - { - g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(pConsumerProxy), u32TimeoutMs); - } - - return (NSMA_tLcConsumerHandle) pConsumerProxy; -} - - - -gboolean NSMA_boCallLcClientRequest(NSMA_tLcConsumerHandle hLcClient, - guint u32ShutdownType) -{ - - NSMA__pCurrentLcConsumer = (NodeStateLifeCycleConsumer*) hLcClient; - - node_state_life_cycle_consumer_call_lifecycle_request(NSMA__pCurrentLcConsumer, - u32ShutdownType, - (guint) NSMA__pCurrentLcConsumer, - NULL, - &NSMA__vOnLifecycleRequestFinish, - NULL); - return TRUE; -} - - -gboolean NSMA_boSetLcClientTimeout(NSMA_tLcConsumerHandle hClient, guint u32TimeoutMs) -{ - g_dbus_proxy_set_default_timeout(G_DBUS_PROXY(hClient), u32TimeoutMs); - - return TRUE; -} - - -gboolean NSMA_boGetLcClientTimeout(NSMA_tLcConsumerHandle hClient, guint *pu32TimeoutMs) -{ - *pu32TimeoutMs = g_dbus_proxy_get_default_timeout(G_DBUS_PROXY(hClient)); - - return TRUE; -} - - -gboolean NSMA_boDeInit(void) -{ - NSMA__boInitialized = FALSE; - - g_bus_unown_name(NSMA__u32ConnectionId); - g_main_loop_unref(NSMA__pMainLoop); - - /* Release the (created) skeleton objects */ - if(NSMA__pNodeStateConsumerObj != NULL) - { - g_object_unref(NSMA__pNodeStateConsumerObj); - } - - if(NSMA__pLifecycleControlObj != NULL) - { - g_object_unref(NSMA__pLifecycleControlObj); - } - - return TRUE; -} diff --git a/NodeStateAccess/NodeStateAccess.cpp b/NodeStateAccess/NodeStateAccess.cpp new file mode 100644 index 0000000..efd2c62 --- /dev/null +++ b/NodeStateAccess/NodeStateAccess.cpp @@ -0,0 +1,624 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +/********************************************************************************************************************** + * + * Header includes + * + **********************************************************************************************************************/ + +/* generic includes for the NodeStateAccess library */ +#include "NodeStateAccess.h" /* own header */ +#include "NodeStateAccess.hpp" +#include "NodeStateTypes.h" /* Type defintions of the NSM */ + +#include <algorithm> +#include <csignal> +#include <cstdio> +#include <iostream> +#include <dlt.h> +#include <string.h> + +#ifdef COVERAGE_ENABLED +extern "C" void __gcov_flush(); +#endif + +#include "NodeStateConsumer_StubImpl.h" +#include "NodeStateLifecycleControl_StubImpl.h" +#include "SimpleTimer.h" + +#include <v1/org/genivi/nodestatemanager/ConsumerInstanceIds.hpp> +#include <v1/org/genivi/nodestatemanager/LifecycleControlInstanceIds.hpp> + +namespace GENIVI = v1::org::genivi; +using namespace GENIVI::nodestatemanager; + +// CommonAPI connection ID +const char* gConnectionID = "NSMimpl"; +const char* gCapiDomain = "local"; + +DLT_IMPORT_CONTEXT(NsmaContext); + +/********************************************************************************************************************** + * + * Local variables + * + **********************************************************************************************************************/ + +static gboolean NSMA__boLoopEndByUser = FALSE; +static gboolean NSMA__boInitialized = FALSE; + +/* Structure with callback functions to the NSM */ +static NSMA_tstObjectCallbacks NSMA__stObjectCallbacks = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; + +static std::shared_ptr<NodeStateConsumer_StubImpl> NSMA_consumerService = NULL; +static std::shared_ptr<NodeStateLifecycleControl_StubImpl> NSMA_lifecycleControlService = NULL; + +static std::unordered_map<std::size_t, std::shared_ptr<SimpleTimer>> NSMA_clParallelShutdownPendingReceivers; + +static std::shared_ptr<CommonAPI::Runtime> NSMA_runtime = NULL; + +static std::shared_ptr<SimpleTimer> NSMA_simpleTimer = NULL; + +static size_t NSMA_currentConsumer = 0; + +static std::mutex NSMA__mutexParallelShutdown; +static std::mutex NSMA__mutexWaitForEvents; +static std::mutex NSMA__mutex; +static std::condition_variable NSMA__condVarShutdown; + +/********************************************************************************************************************** + * + * Local (static) functions + * + **********************************************************************************************************************/ + +/********************************************************************************************************************** +* +* The function is called when the async. call to a life cycle clients "LifecycleRequest" method timed out. +* +**********************************************************************************************************************/ +static void NSMA__boHandleSequentialRequestTimeout() +{ + std::unique_lock<std::mutex> lock(NSMA__mutexParallelShutdown); + if (NULL != NSMA_consumerService) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Error! Sequential client has timed out! Client ID:"), DLT_UINT64(NSMA_currentConsumer)); + + size_t oldConsumer = NSMA_currentConsumer; + NSMA_currentConsumer = 0; + + lock.unlock(); + NSMA__stObjectCallbacks.pfLcClientRequestFinish(oldConsumer, TRUE, FALSE); + } +} + +/********************************************************************************************************************** +* +* The function is called when the async. call to a parallel life cycle clients "LifecycleRequest" method timed out. +* +**********************************************************************************************************************/ +static void NSMA__boHandleParallelRequestTimeout(std::size_t client) +{ + std::unique_lock<std::mutex> lock(NSMA__mutexParallelShutdown); + + /* Find timed out client in parallel shutdown receivers list */ + auto search = NSMA_clParallelShutdownPendingReceivers.find(client); + if(NULL != NSMA_consumerService && search != NSMA_clParallelShutdownPendingReceivers.end()) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Error! Parallel client has timed out! Client ID:"), DLT_UINT64(client)); + + /* Remove this client from the list of pending clients */ + NSMA_clParallelShutdownPendingReceivers.erase(search); + + lock.unlock(); + NSMA__stObjectCallbacks.pfLcClientRequestFinish(client, TRUE, FALSE); + } +} + +/********************************************************************************************************************** + * + * Interfaces. Exported functions. See Header for detailed description. + * + **********************************************************************************************************************/ +gboolean NSMA_boInit(const NSMA_tstObjectCallbacks *pstCallbacks) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + /* Initialize file local variables */ + NSMA__boInitialized = FALSE; + + memset(&NSMA__stObjectCallbacks, 0, sizeof(NSMA_tstObjectCallbacks)); + std::lock_guard<std::mutex> lock(NSMA__mutex); + + /* Check if all callbacks for the NSM have been configured. */ + if( pstCallbacks != NULL + && (pstCallbacks->pfSetBootModeCb != NULL) + && (pstCallbacks->pfRequestNodeRestartCb != NULL) + && (pstCallbacks->pfSetAppHealthStatusCb != NULL) + && (pstCallbacks->pfCheckLucRequiredCb != NULL) + && (pstCallbacks->pfRegisterSessionCb != NULL) + && (pstCallbacks->pfUnRegisterSessionCb != NULL) + && (pstCallbacks->pfRegisterLifecycleClientCb != NULL) + && (pstCallbacks->pfUnRegisterLifecycleClientCb != NULL) + && (pstCallbacks->pfGetSessionStateCb != NULL) + && (pstCallbacks->pfGetNodeStateCb != NULL) + && (pstCallbacks->pfSetNodeStateCb != NULL) + && (pstCallbacks->pfSetSessionStateCb != NULL) + && (pstCallbacks->pfGetAppHealthCountCb != NULL) + && (pstCallbacks->pfGetInterfaceVersionCb != NULL) + && (pstCallbacks->pfLcClientRequestFinish != NULL)) + { + /* Store the passed callbacks. */ + memcpy(&NSMA__stObjectCallbacks, pstCallbacks, sizeof(NSMA_tstObjectCallbacks)); + + if (NULL == (NSMA_runtime = CommonAPI::Runtime::get())) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Failed to get CAPI Runtime!")); + } + else if(NULL == (NSMA_consumerService = std::make_shared<NodeStateConsumer_StubImpl>(&NSMA__stObjectCallbacks))) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Failed to create NSMA_consumerService")); + } + else if (NULL == (NSMA_lifecycleControlService = std::make_shared<NodeStateLifecycleControl_StubImpl>(&NSMA__stObjectCallbacks))) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Failed to create NSMA_lifecycleControlService")); + } + else if (!NSMA_runtime->registerService(gCapiDomain, v1::org::genivi::nodestatemanager::Consumer_INSTANCES[0], NSMA_consumerService, gConnectionID)) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Failed to register NSMConsumer")); + } + else if (!NSMA_runtime->registerService(gCapiDomain, v1::org::genivi::nodestatemanager::LifecycleControl_INSTANCES[0], NSMA_lifecycleControlService, "LifecycleControl")) + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: Failed to register NSMLifecycleControl")); + } + else + { + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Successfully registered NSMA")); + /* All callbacks are configured. */ + NSMA__boInitialized = TRUE; + } + } + else + { + /* Error: Callbacks are configured incorrectly. */ + NSMA__boInitialized = FALSE; + } + + return NSMA__boInitialized; +} + +void signal_handler(int signal) +{ + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Received signal"), DLT_INT(signal)); + std::unique_lock<std::mutex> lock(NSMA__mutexWaitForEvents); + NSMA__boLoopEndByUser = TRUE; + lock.unlock(); + NSMA__condVarShutdown.notify_all(); +} + +gboolean NSMA_boWaitForEvents(void) +{ + std::signal(SIGTERM, signal_handler); + std::signal(SIGINT, signal_handler); + + std::unique_lock<std::mutex> lock(NSMA__mutexWaitForEvents); + while (FALSE == NSMA__boLoopEndByUser) + { + NSMTriggerWatchdog(NsmWatchdogState_Sleep); + NSMA__condVarShutdown.wait(lock); + NSMTriggerWatchdog(NsmWatchdogState_Active); + } + + /* Delete signal handlers */ + signal(SIGTERM, SIG_DFL); + signal(SIGINT, SIG_DFL); + lock.unlock(); + std::fflush(stdout); + std::fflush(stderr); + +#ifdef COVERAGE_ENABLED + __gcov_flush(); +#endif + + return TRUE; +} + +gboolean NSMA_boSendNodeStateSignal(const NsmNodeState_e enNodeState) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->fireNodeStateEvent(GENIVI::NodeStateManagerTypes::NsmNodeState_e((GENIVI::NodeStateManagerTypes::NsmNodeState_e::Literal) enNodeState)); + } + return boRetVal; +} + +gboolean NSMA_boSendSessionSignal(const NsmSession_s *pstSession) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->fireSessionStateChangedEvent(pstSession->sName, GENIVI::NodeStateManagerTypes::NsmSeat_e((GENIVI::NodeStateManagerTypes::NsmSeat_e::Literal)pstSession->enSeat), GENIVI::NodeStateManagerTypes::NsmSessionState_e((GENIVI::NodeStateManagerTypes::NsmSessionState_e::Literal)pstSession->enState)); + } + return boRetVal; +} + +gboolean NSMA_boSendApplicationModeSignal(const NsmApplicationMode_e enApplicationMode) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->fireNodeApplicationModeEvent(GENIVI::NodeStateManagerTypes::NsmApplicationMode_e((GENIVI::NodeStateManagerTypes::NsmApplicationMode_e::Literal) enApplicationMode)); + } + return boRetVal; +} + +gboolean NSMA_boSetBootMode(gint i32BootMode) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->setBootModeAttribute(i32BootMode); + } + return boRetVal; +} + +gboolean NSMA_boGetBootMode(gint *pi32BootMode) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + *pi32BootMode = NSMA_consumerService->getBootModeAttribute(); + } + return boRetVal; +} + +gboolean NSMA_boSetRunningReason(const NsmRunningReason_e enRunningReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->setWakeUpReasonAttribute(GENIVI::NodeStateManagerTypes::NsmRunningReason_e((GENIVI::NodeStateManagerTypes::NsmRunningReason_e::Literal) enRunningReason)); + } + return boRetVal; +} + +gboolean NSMA_boGetRunningReason(NsmRunningReason_e *penRunningReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + *penRunningReason = (NsmRunningReason_e)(int) NSMA_consumerService->getWakeUpReasonAttribute(); + } + return boRetVal; +} + +gboolean NSMA_boSetShutdownReason(const NsmShutdownReason_e enShutdownReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->setShutdownReasonAttribute(GENIVI::NodeStateManagerTypes::NsmShutdownReason_e((GENIVI::NodeStateManagerTypes::NsmShutdownReason_e::Literal) enShutdownReason)); + } + return boRetVal; +} + +gboolean NSMA_boGetShutdownReason(NsmShutdownReason_e *penShutdownReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + *penShutdownReason = (NsmShutdownReason_e)(int) NSMA_consumerService->getShutdownReasonAttribute(); + } + return boRetVal; +} + +gboolean NSMA_boSetRestartReason(const NsmRestartReason_e enRestartReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + NSMA_consumerService->setRestartReasonAttribute(GENIVI::NodeStateManagerTypes::NsmRestartReason_e((GENIVI::NodeStateManagerTypes::NsmRestartReason_e::Literal) enRestartReason)); + } + return boRetVal; +} + +gboolean NSMA_boGetRestartReason(NsmRestartReason_e *penRestartReason) +{ + std::lock_guard<std::mutex> lock(NSMA__mutex); + gboolean boRetVal = FALSE; + /* Check if library has been initialized (objects are available) */ + if (NSMA__boInitialized == TRUE) + { + boRetVal = TRUE; /* Send the signal */ + *penRestartReason = (NsmRestartReason_e)(int) NSMA_consumerService->getRestartReasonAttribute(); + } + return boRetVal; +} + +gboolean NSMA_boCallParallelLcClientsRequest(NSM__tstLifecycleClient *client, guint numClients, guint u32ShutdownType) +{ + gboolean retVal = FALSE; + guint i = 0; + + if (NULL != client && 0 < numClients) + { + std::lock_guard<std::mutex> lock(NSMA__mutexParallelShutdown); + std::shared_ptr<CommonAPI::ClientIdList> receiver = std::make_shared<CommonAPI::ClientIdList>(); + std::shared_ptr<CommonAPI::ClientIdList> availableClients(NSMA_consumerService->getSubscribersForShutdownEventsSelective()); + for (i = 0; i < numClients; i++) + { + for (const auto &clientIdIterator : *availableClients) + { + if (clientIdIterator->hashCode() == client[i].clientHash) + { + NSMA_clParallelShutdownPendingReceivers.insert({clientIdIterator->hashCode(), SimpleTimer::CreateTimer((int)client[i].timeout, 1, &NSMA__boHandleParallelRequestTimeout, clientIdIterator->hashCode())}); + receiver->insert(clientIdIterator); + if(u32ShutdownType == NSM_SHUTDOWNTYPE_RUNUP || u32ShutdownType == (NSM_SHUTDOWNTYPE_RUNUP | NSM_SHUTDOWNTYPE_PARALLEL)) + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client[i].clientHash), DLT_STRING("about parallel run up ("), DLT_UINT(u32ShutdownType), DLT_STRING(")!")); + else + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client[i].clientHash), DLT_STRING("about parallel shutdown ("), DLT_UINT(u32ShutdownType), DLT_STRING(")!")); + break; + } + } + } + NSMA_consumerService->fireShutdownEventsSelective(u32ShutdownType, receiver); + + retVal = TRUE; + } + return retVal; +} + +gboolean NSMA_boCallLcClientRequest(NSM__tstLifecycleClient *client, guint u32ShutdownType) +{ + gboolean retVal = FALSE; + + if (NULL != client) + { + std::lock_guard<std::mutex> lock(NSMA__mutexParallelShutdown); + std::shared_ptr<CommonAPI::ClientIdList> receivers = std::make_shared<CommonAPI::ClientIdList>(); + std::shared_ptr<CommonAPI::ClientIdList> availableClients = NSMA_consumerService->getSubscribersForShutdownEventsSelective(); + + for (const auto &clientIdIterator : *availableClients) + { + if (clientIdIterator->hashCode() == client->clientHash) + { + receivers->insert(clientIdIterator); + if(u32ShutdownType == NSM_SHUTDOWNTYPE_RUNUP) + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client->clientHash), DLT_STRING("about run up ("), DLT_UINT(u32ShutdownType), DLT_STRING(")!")); + else + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client->clientHash), DLT_STRING("about shutdown ("), DLT_UINT(u32ShutdownType), DLT_STRING(")!")); + break; + } + } + + /* Set current consumer. This way nsm can check if the correct consumer responds */ + NSMA_currentConsumer = client->clientHash; + + NSMA_stopLcClientTimeout(); + /* Start timer so HandleRequestTimeout will be called when this timer is not canceled within timeout ms */ + NSMA_simpleTimer = SimpleTimer::CreateTimer((int) client->timeout, 1, &NSMA__boHandleSequentialRequestTimeout); + + NSMA_consumerService->fireShutdownEventsSelective(u32ShutdownType, receivers); + + retVal = TRUE; + } + return retVal; +} + +gboolean NSMA_boCallLcClientRequestWithoutTimeout(NSM__tstLifecycleClient *client, guint u32ShutdownType) +{ + gboolean retVal = FALSE; + if (NULL != client) + { + std::lock_guard<std::mutex> lock(NSMA__mutexParallelShutdown); + std::shared_ptr<CommonAPI::ClientIdList> receivers = std::make_shared<CommonAPI::ClientIdList>(); + std::shared_ptr<CommonAPI::ClientIdList> availableClients = NSMA_consumerService->getSubscribersForShutdownEventsSelective(); + + for (const auto &clientIdIterator : *availableClients) + { + if (clientIdIterator->hashCode() == client->clientHash) + { + receivers->insert(clientIdIterator); + if(u32ShutdownType | NSM_SHUTDOWNTYPE_RUNUP) + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client->clientHash), DLT_STRING("about run up ("), DLT_UINT(u32ShutdownType), DLT_STRING(") without timeout!")); + else + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: Will inform client"), DLT_INT64(client->clientHash), DLT_STRING("about shutdown ("), DLT_UINT(u32ShutdownType), DLT_STRING(") without timeout!")); + break; + } + } + NSMA_consumerService->fireShutdownEventsSelective(u32ShutdownType, receivers); + retVal = TRUE; + } + return retVal; +} + +int32_t NSMA_ClientRequestFinish(const std::shared_ptr<CommonAPI::ClientId> client, int32_t status) +{ + int32_t errorCode = NsmErrorStatus_Error; + size_t clientID = client->hashCode(); + std::unique_lock<std::mutex> lock(NSMA__mutexParallelShutdown); + + /* Current sequential client */ + if (clientID == NSMA_currentConsumer) + { + NSMA_stopLcClientTimeout(); + NSMA_currentConsumer = 0; + errorCode = NsmErrorStatus_Ok; + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: LifecycleRequest successful for (sequential) client:"), DLT_INT64(clientID), DLT_STRING("Return Value:"), DLT_STRING(ERRORSTATUS_STRING[status])); + lock.unlock(); + NSMA__stObjectCallbacks.pfLcClientRequestFinish(clientID, FALSE, FALSE); + } + else /* Maybe parallel? */ + { + /* There should be exactly one client in parallelShutdownReceivers with matching ClientId */ + auto search = NSMA_clParallelShutdownPendingReceivers.find(clientID); + if (search != NSMA_clParallelShutdownPendingReceivers.end()) + { + /* Cancel timeout for one parallel shutdown client */ + search->second->cancelTimer(); + NSMA_clParallelShutdownPendingReceivers.erase(search); + errorCode = NsmErrorStatus_Ok; + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: LifecycleRequest successful for (parallel) client:"), DLT_INT64(clientID), DLT_STRING("Return Value:"), DLT_STRING(ERRORSTATUS_STRING[status])); + lock.unlock(); + NSMA__stObjectCallbacks.pfLcClientRequestFinish(clientID, FALSE, FALSE); + } + else + { + /* Maybe late client? */ + std::shared_ptr<CommonAPI::ClientIdList> availableClients(NSMA_consumerService->getSubscribersForShutdownEventsSelective()); + for (const auto &clientIdIterator : *availableClients) + { + if (clientIdIterator->hashCode() == clientID) + { + /* Client has been found but it was not the expected one -> as it is late? */ + errorCode = NsmErrorStatus_WrongClient; + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: LifecycleRequest returned too late for client:"), DLT_INT64(clientID), DLT_STRING("Return Value:"), DLT_STRING(ERRORSTATUS_STRING[status])); + lock.unlock(); + NSMA__stObjectCallbacks.pfLcClientRequestFinish(clientID, FALSE, TRUE); + break; + } + } + } + } + return errorCode; +} + +void NSMA_stopLcClientTimeout() +{ + if (NSMA_simpleTimer != NULL) + { + NSMA_simpleTimer->stopTimer(); + NSMA_simpleTimer = NULL; + } +} + +void NSMA_stopParallelLcClientTimeout() +{ + for (const auto clientIdIterator : NSMA_clParallelShutdownPendingReceivers) + { + clientIdIterator.second->stopTimer(); + } + NSMA_clParallelShutdownPendingReceivers.clear(); +} + +gboolean NSMA__ParallelClientHasPendingActiveCall(size_t clientID) +{ + gboolean retVal = FALSE; + if(clientID == 0) + { + retVal = !NSMA_clParallelShutdownPendingReceivers.empty(); + } + else + { + auto search = NSMA_clParallelShutdownPendingReceivers.find(clientID); + if (search != NSMA_clParallelShutdownPendingReceivers.end()) + { + retVal = TRUE; + } + } + return retVal; +} + +gboolean NSMA__SequentialClientHasPendingActiveCall() +{ + return (NSMA_currentConsumer != 0); +} + +gboolean NSMA_boDeleteLifecycleClient(NSM__tstLifecycleClient *client) +{ + gboolean retVal = FALSE; + std::lock_guard<std::mutex> lock(NSMA__mutexParallelShutdown); + if(client->clientHash == NSMA_currentConsumer) + { + NSMA_stopLcClientTimeout(); + } + else + { + auto search = NSMA_clParallelShutdownPendingReceivers.find(client->clientHash); + if (search != NSMA_clParallelShutdownPendingReceivers.end()) + { + /* Cancel timeout for one parallel shutdown client */ + search->second->cancelTimer(); + NSMA_clParallelShutdownPendingReceivers.erase(search); + } + } + return retVal; +} + +void NSMA_setLcCollectiveTimeout() +{ + std::lock_guard<std::mutex> lock(NSMA__mutexParallelShutdown); + + NSMA_stopLcClientTimeout(); + NSMA_currentConsumer = 0; + + for (const auto clientIdIterator : NSMA_clParallelShutdownPendingReceivers) + { + clientIdIterator.second->cancelTimer(); + } + NSMA_clParallelShutdownPendingReceivers.clear(); +} + +gboolean NSMA_boDeInit(void) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + gboolean retVal = TRUE; + NSMA__boInitialized = FALSE; + NSMA_stopLcClientTimeout(); + NSMA_stopParallelLcClientTimeout(); + for (const auto clientIdIterator : NSMA_clParallelShutdownPendingReceivers) + { + clientIdIterator.second->stopTimer(); + } + retVal &= NSMA_runtime->unregisterService(gCapiDomain, NodeStateConsumer_StubImpl::StubInterface::getInterface(), v1::org::genivi::nodestatemanager::Consumer_INSTANCES[0]); + retVal &= NSMA_runtime->unregisterService(gCapiDomain, NodeStateLifecycleControl_StubImpl::StubInterface::getInterface(), v1::org::genivi::nodestatemanager::LifecycleControl_INSTANCES[0]); + std::lock_guard<std::mutex> lock(NSMA__mutex); + NSMA_consumerService = NULL; + NSMA_lifecycleControlService = NULL; + return retVal; +} diff --git a/NodeStateAccess/NodeStateAccess.h b/NodeStateAccess/NodeStateAccess.h index f66861f..a7ccec2 100644 --- a/NodeStateAccess/NodeStateAccess.h +++ b/NodeStateAccess/NodeStateAccess.h @@ -1,28 +1,25 @@ -#ifndef NODESTATEACCESS_H_ -#define NODESTATEACCESS_H_ - /********************************************************************************************************************** -* -* Copyright (C) 2012 Continental Automotive Systems, Inc. -* -* Author: Jean-Pierre.Bogler@continental-corporation.com -* -* Interface between NodeStateManager and IPC -* -* This header file is a part of the NodeStateAccess library (NSMA). -* The architecture requires that the NodeStateManager (NSM) is independent from the D-Bus binding and code generated by -* "gdbus-codegen". Therefore, the D-Bus communication and generated D-Bus objects are handled inside of this library. -* The library offers the NSM an interface to use objects generated via gdbus-codgen. -* -* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. -* -* Date Author Reason -* 24.10.2012 Jean-Pierre Bogler CSP_WZ#1322: Initial creation -* -**********************************************************************************************************************/ + * + * Copyright (C) 2013 Continental Automotive Systems, Inc. + * 2017 BMW AG + * + * Author: Jean-Pierre.Bogler@continental-corporation.com + * + * Interface between NodeStateManager and IPC + + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ +#ifndef NODESTATEACCESS_H_ +#define NODESTATEACCESS_H_ /********************************************************************************************************************** * @@ -30,15 +27,27 @@ * **********************************************************************************************************************/ -#include "NodeStateTypes.h" /* NodeStateTypes to communicate with NSM */ -#include "gio/gio.h" /* glib types for easier ICP connection */ - +#include "NodeStateTypes.h" /* NodeStateManagerTypes to communicate with NSM */ +#include <gio/gio.h> /* glib types for easier ICP connection */ +#ifdef __cplusplus +extern "C" { +#endif /********************************************************************************************************************** * * TYPE * **********************************************************************************************************************/ +/* The type defines the structure for a lifecycle consumer client */ +typedef struct +{ + size_t clientHash; /* Identifier of the client base on capi client id */ + guint32 u32RegisteredMode; /* Bit array of shutdown modes */ + guint32 timeout; /* Timeout in ms of the client */ + gboolean boShutdown; /* Only "run up" clients which are shut down */ + gboolean boPendingCall; /* Client has a pending lifecycle call */ +} NSM__tstLifecycleClient; + /* Type definitions of callbacks that the NSM registers for the object interfaces */ typedef NsmErrorStatus_e (*NSMA_tpfSetBootModeCb) (const gint i32BootMode); @@ -56,12 +65,10 @@ typedef NsmErrorStatus_e (*NSMA_tpfRegisterSessionCb) (const gchar typedef NsmErrorStatus_e (*NSMA_tpfUnRegisterSessionCb) (const gchar *sSessionName, const gchar *sSessionOwner, const NsmSeat_e enSeatId); -typedef NsmErrorStatus_e (*NSMA_tpfRegisterLifecycleClientCb) (const gchar *sBusName, - const gchar *sObjName, +typedef NsmErrorStatus_e (*NSMA_tpfRegisterLifecycleClientCb) (const size_t clientHash, const guint u32ShutdownMode, const guint u32TimeoutMs); -typedef NsmErrorStatus_e (*NSMA_tpfUnRegisterLifecycleClientCb)(const gchar *sBusName, - const gchar *sObjName, +typedef NsmErrorStatus_e (*NSMA_tpfUnRegisterLifecycleClientCb)(const size_t clientHash, const guint u32ShutdownMode); typedef NsmErrorStatus_e (*NSMA_tpfGetAppModeCb) (NsmApplicationMode_e *penAppMode); typedef NsmErrorStatus_e (*NSMA_tpfGetSessionStateCb) (const gchar *sSessionName, @@ -77,15 +84,13 @@ typedef guint (*NSMA_tpfGetInterfaceVersionCb) (void); /* Type definition for the management of Lifecycle clients */ -typedef gpointer NSMA_tLcConsumerHandle; -typedef void (*NSMA_tpfLifecycleReqFinish)(const NsmErrorStatus_e enErrorStatus); +typedef void (*NSMA_tpfLifecycleReqFinish)(size_t clientID, gboolean timeout, gboolean late); /* Type definition to wrap all callbacks in a structure */ typedef struct { NSMA_tpfSetBootModeCb pfSetBootModeCb; NSMA_tpfSetNodeStateCb pfSetNodeStateCb; - NSMA_tpfSetAppModeCb pfSetAppModeCb; NSMA_tpfRequestNodeRestartCb pfRequestNodeRestartCb; NSMA_tpfSetAppHealthStatusCb pfSetAppHealthStatusCb; NSMA_tpfCheckLucRequiredCb pfCheckLucRequiredCb; @@ -93,7 +98,6 @@ typedef struct NSMA_tpfUnRegisterSessionCb pfUnRegisterSessionCb; NSMA_tpfRegisterLifecycleClientCb pfRegisterLifecycleClientCb; NSMA_tpfUnRegisterLifecycleClientCb pfUnRegisterLifecycleClientCb; - NSMA_tpfGetAppModeCb pfGetAppModeCb; NSMA_tpfGetSessionStateCb pfGetSessionStateCb; NSMA_tpfGetNodeStateCb pfGetNodeStateCb; NSMA_tpfSetSessionStateCb pfSetSessionStateCb; @@ -275,30 +279,70 @@ gboolean NSMA_boGetShutdownReason(NsmShutdownReason_e *penShutdownReason); /********************************************************************************************************************** * -* The function is used to create a LifecycleConsumer client. +* The function is used to inform a LifecycleConsumer about a shutdown or runup request +* +* @param hLcClient: Handle of the client (created with "NSMA_hCreateLcConsumer"). +* @param u32ShutdownType: Shutdown type. +* +* @return TRUE: Successfully called client +* FALSE: Error calling the client. +* +**********************************************************************************************************************/ +gboolean NSMA_boCallLcClientRequest(NSM__tstLifecycleClient *client, guint u32ShutdownType); + +/********************************************************************************************************************** +* +* The function is used to inform a LifecycleConsumer about a shutdown or runup request without timeout +* This is used when a late LifecycleConsumer has returned to inform him about the current state when it +* has been changed since the last call to this LifecycleConsumer * -* @param sBusName: Bus name of the client object. -* @param sObjName: Object name of the client object. -* @param u32TimeoutMs: Timeout for client calls in ms. +* @param hLcClient: Handle of the client (created with "NSMA_hCreateLcConsumer"). +* @param u32ShutdownType: Shutdown type. * -* @return Handle to the new life cycle consumer or NULL, if there was an error. +* @return TRUE: Successfully called client +* FALSE: Error calling the client. * **********************************************************************************************************************/ -NSMA_tLcConsumerHandle NSMA_hCreateLcConsumer(const gchar* sBusName, const gchar* sObjName, const guint u32TimeoutMs); +gboolean NSMA_boCallLcClientRequestWithoutTimeout(NSM__tstLifecycleClient *client, guint u32ShutdownType); /********************************************************************************************************************** * -* The function is used to call the "LifecycleRequest" method of a client. +* Returns true if a sequential client has a pending call that has not timed out * -* @param hLcClient: Handle of the client (created with "NSMA_hCreateLcConsumer"). +* @return TRUE: Pending call active +* FALSE: No pending call active +* +**********************************************************************************************************************/ +gboolean NSMA__SequentialClientHasPendingActiveCall(); + +/********************************************************************************************************************** +* +* Returns true if parallel client has a pending call that has not timed out +* +* @param clientID: ClientID to check for +* If clientID is 0 check if any parallel client has a pending call +* +* @return TRUE: Pending call active +* FALSE: No pending call active +* +**********************************************************************************************************************/ +gboolean NSMA__ParallelClientHasPendingActiveCall(size_t clientID); + +/********************************************************************************************************************** +* +* The function is used to inform multiple LifecycleConsumers about a shutdown or runup request. +* This is used for parallel shutdown. +* +* @param client: List of Handle of the client (created with "NSMA_hCreateLcConsumer"). +* @param numClients: Number of clients in client list. * @param u32ShutdownType: Shutdown type. * * @return TRUE: Successfully called client * FALSE: Error calling the client. * **********************************************************************************************************************/ -gboolean NSMA_boCallLcClientRequest(NSMA_tLcConsumerHandle hLcClient, guint u32ShutdownType); +gboolean NSMA_boCallParallelLcClientsRequest(NSM__tstLifecycleClient *client, guint numClients, guint u32ShutdownType); /********************************************************************************************************************** @@ -312,8 +356,21 @@ gboolean NSMA_boCallLcClientRequest(NSMA_tLcConsumerHandle hLcClient, guint u32S * FALSE: Error setting the clients timeout time. * **********************************************************************************************************************/ -gboolean NSMA_boSetLcClientTimeout(NSMA_tLcConsumerHandle hClient, guint u32TimeoutMs); +gboolean NSMA_boSetLcClientTimeout(NSM__tstLifecycleClient *client, guint u32TimeoutMs); + +/********************************************************************************************************************** +* +* The function is called to get the default timeout for calls to the life cycle client. +* +* @param hLcClient: Handle of the life cycle client. +* @param pu32TimeoutMs: Pointer where to store the timeout value in ms. +* +* @return TRUE: Successfully got timeout time for client. +* FALSE: Error getting the clients timeout time. +* +**********************************************************************************************************************/ +gboolean NSMA_boGetLcClientTimeout(NSM__tstLifecycleClient *client, guint *pu32TimeoutMs); /********************************************************************************************************************** * @@ -326,20 +383,36 @@ gboolean NSMA_boSetLcClientTimeout(NSMA_tLcConsumerHandle hClient, guint u32Time * FALSE: Error getting the clients timeout time. * **********************************************************************************************************************/ -gboolean NSMA_boGetLcClientTimeout(NSMA_tLcConsumerHandle hClient, guint *pu32TimeoutMs); +gboolean NSMA_boDeleteLifecycleClient(NSM__tstLifecycleClient *client); + + +/********************************************************************************************************************** +* +* The function is called to cancel the current LcCient Timeout. +* +**********************************************************************************************************************/ +void NSMA_cancelLcClientTimeout(); +/********************************************************************************************************************** +* +* The function is called to stop the current LcCient Timeout. +* +**********************************************************************************************************************/ +void NSMA_stopLcClientTimeout(); /********************************************************************************************************************** * -* The function is used to delete a "LifecycleRequest". +* The function is called to stop the current Parallel LcCient Timeout. * -* @param hLcClient: Handle of the client (created with "NSMA_hCreateLcConsumer"). +**********************************************************************************************************************/ +void NSMA_stopParallelLcClientTimeout(); + +/********************************************************************************************************************** * -* @return TRUE: Successfully freed clients memory. -* FALSE: Error freeing the clients memory. +* The function is called to cancel the current shutdown due to collective timeout. * **********************************************************************************************************************/ -gboolean NSMA_boFreeLcConsumerProxy(NSMA_tLcConsumerHandle hLcConsumer); +void NSMA_setLcCollectiveTimeout(); /********************************************************************************************************************** @@ -373,6 +446,8 @@ gboolean NSMA_boQuitEventLoop(void); * **********************************************************************************************************************/ gboolean NSMA_boDeInit(void); - +#ifdef __cplusplus +} +#endif #endif /* NODESTATEACCESS_H_ */ diff --git a/NodeStateAccess/NodeStateAccess.hpp b/NodeStateAccess/NodeStateAccess.hpp new file mode 100644 index 0000000..2a190b4 --- /dev/null +++ b/NodeStateAccess/NodeStateAccess.hpp @@ -0,0 +1,48 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#ifndef NODESTATEACCESS_HPP_ +#define NODESTATEACCESS_HPP_ + +/********************************************************************************************************************** +* +* HEADER FILE INCLUDES +* +**********************************************************************************************************************/ + +#include "NodeStateTypes.h" /* NodeStateManagerTypes to communicate with NSM */ +#include <gio/gio.h> /* glib types for easier ICP connection */ + +#include <CommonAPI/CommonAPI.hpp> + +/********************************************************************************************************************** +* +* The function is called after a (parallel) lifecycle client was informed about the changed life cycle. +* The return value of the last informed client will be evaluated and the next lifecycle client +* to inform will be determined and called. +* If there is no client left, the lifecycle sequence will be finished. +* +* @param pSrcObject: Source object (lifecycle client proxy) +* @param pRes: Result of asynchronous call +* @param pUserData: Pointer to the current lifecycle client object +* +* @return void +* +**********************************************************************************************************************/ +int32_t NSMA_ClientRequestFinish(const std::shared_ptr<CommonAPI::ClientId> client, int32_t status); + +#endif /* NODESTATEACCESS_HPP_ */ diff --git a/NodeStateAccess/NodeStateConsumer_StubImpl.cpp b/NodeStateAccess/NodeStateConsumer_StubImpl.cpp new file mode 100644 index 0000000..29f572e --- /dev/null +++ b/NodeStateAccess/NodeStateConsumer_StubImpl.cpp @@ -0,0 +1,177 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#include "NodeStateConsumer_StubImpl.h" +#include "Watchdog.hpp" + +#include <dlt.h> +#include <iostream> + +DLT_IMPORT_CONTEXT(NsmaContext); + +NodeStateConsumer_StubImpl::NodeStateConsumer_StubImpl(NSMA_tstObjectCallbacks* objectCallbacks) +{ + NSMA__stObjectCallbacks = objectCallbacks; + trySetBootModeAttribute(0); + setRestartReasonAttribute(GENIVI::NodeStateManagerTypes::NsmRestartReason_e::NsmRestartReason_NotSet); + setShutdownReasonAttribute(GENIVI::NodeStateManagerTypes::NsmShutdownReason_e::NsmShutdownReason_NotSet); + setWakeUpReasonAttribute(GENIVI::NodeStateManagerTypes::NsmRunningReason_e::NsmRunningReason_NotSet); +} + +void NodeStateConsumer_StubImpl::GetInterfaceVersion(const std::shared_ptr<CommonAPI::ClientId> _client, GetInterfaceVersionReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + CommonAPI::Version v = ConsumerStubDefault::getInterfaceVersion(_client); + _reply( (v.Major << 24) | (v.Minor << 16)); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::GetNodeState(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GetNodeStateReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: GetNodeState.")); + + NsmNodeState_e enNodeState = NsmNodeState_NotSet; + NsmErrorStatus_e nodeStateId = NSMA__stObjectCallbacks->pfGetNodeStateCb(&enNodeState); + _reply(GENIVI::NodeStateManagerTypes::NsmNodeState_e((GENIVI::NodeStateManagerTypes::NsmNodeState_e::Literal) enNodeState), + GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) nodeStateId)); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::SetSessionState(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GENIVI::NodeStateManagerTypes::NsmSessionState_e _SessionState, SetSessionStateReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: SetSessionState. SessionName:"), DLT_STRING(_SessionName.data()), + DLT_STRING("SessionOwner:"), DLT_STRING(_SessionOwner.data()), + DLT_STRING("SeatID:"), DLT_INT(_SeatID), + DLT_STRING("SessionState:"), DLT_INT(_SessionState)); + + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) + NSMA__stObjectCallbacks->pfSetSessionStateCb(_SessionName.c_str(), _SessionOwner.c_str(), (NsmSeat_e)(int) _SeatID, (NsmSessionState_e)(int) _SessionState))); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::GetSessionState(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, std::string _SessionName, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GetSessionStateReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: GetSessionState.")); + NsmSessionState_e enSessionState = NsmSessionState_Unregistered; + NsmErrorStatus_e errorCode = NSMA__stObjectCallbacks->pfGetSessionStateCb(_SessionName.c_str(), (NsmSeat_e)(int) _SeatID, &enSessionState); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: GetSessionState. Reply:"), DLT_INT(enSessionState), DLT_INT(errorCode)); + _reply(GENIVI::NodeStateManagerTypes::NsmSessionState_e((GENIVI::NodeStateManagerTypes::NsmSessionState_e::Literal)enSessionState), + GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)errorCode)); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: GetSessionState. Reply done")); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::RegisterShutdownClient(const std::shared_ptr<CommonAPI::ClientId> _client, uint32_t _ShutdownMode, uint32_t _TimeoutMs, RegisterShutdownClientReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: RegisterShutdownClient. ShutdownMode:"), DLT_UINT(_ShutdownMode), + DLT_STRING("TimeoutMs:"), DLT_INT(_TimeoutMs)); + std::unique_lock<std::mutex> lock(mMutex); + /* + * Pass NULL because client should already be registered by onShutdownEventsSelectiveSubscriptionChanged. + * Just update ShutdownMode and TimeoutMs + */ + NsmErrorStatus_e errorCode = NSMA__stObjectCallbacks->pfRegisterLifecycleClientCb(_client->hashCode(), _ShutdownMode, _TimeoutMs); + /* NSMA returns NsmErrorStatus_Last when client already registered -> this is the normal case here */ + errorCode = errorCode == NsmErrorStatus_Last ? NsmErrorStatus_Ok : errorCode; + + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) errorCode )); + lock.unlock(); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::UnRegisterShutdownClient(const std::shared_ptr<CommonAPI::ClientId> _client, uint32_t _ShutdownMode, UnRegisterShutdownClientReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: UnRegisterShutdownClient. ShutdownMode:"), DLT_UINT(_ShutdownMode)); + std::unique_lock<std::mutex> lock(mMutex); + NsmErrorStatus_e enRetVal = NSMA__stObjectCallbacks->pfUnRegisterLifecycleClientCb(_client->hashCode(), _ShutdownMode); + + if(enRetVal != NsmErrorStatus_Ok) + { + DLT_LOG(NsmaContext, DLT_LOG_WARN, DLT_STRING("NSM: Failed to unregister lifecycle consumer."), + DLT_STRING("Client hash:"), DLT_UINT64(_client->hashCode()), + DLT_STRING("Unregistered mode(s):"), DLT_INT(_ShutdownMode)); + } + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)enRetVal)); + lock.unlock(); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::RegisterSession(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GENIVI::NodeStateManagerTypes::NsmSessionState_e _SessionState, RegisterSessionReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: RegisterSession. SessionName:"), DLT_STRING(_SessionName.data()), + DLT_STRING("SessionOwner:"), DLT_STRING(_SessionOwner.data()), + DLT_STRING("SeatID:"), DLT_INT(_SeatID), + DLT_STRING("SessionState:"), DLT_INT(_SessionState)); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)NSMA__stObjectCallbacks->pfRegisterSessionCb(_SessionName.c_str(), _SessionOwner.c_str(), (NsmSeat_e)(int) _SeatID, (NsmSessionState_e)(int) _SessionState))); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::UnRegisterSession(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, UnRegisterSessionReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: UnRegisterSession. SessionName:"), DLT_STRING(_SessionName.data()), + DLT_STRING("SessionOwner:"), DLT_STRING(_SessionOwner.data()), + DLT_STRING("SeatID:"), DLT_INT(_SeatID)); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)NSMA__stObjectCallbacks->pfUnRegisterSessionCb(_SessionName.c_str(), _SessionOwner.c_str(), (NsmSeat_e)(int) _SeatID))); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::GetAppHealthCount(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GetAppHealthCountReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: GetAppHealthCount.")); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)NSMA__stObjectCallbacks->pfGetAppHealthCountCb())); + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::LifecycleRequestComplete(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmErrorStatus_e _Status, LifecycleRequestCompleteReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + size_t client = _client->hashCode(); + if(_Status >= NsmErrorStatus_NotSet && _Status <= NsmErrorStatus_Last) + { + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: LifecycleRequestComplete Client: "), DLT_INT64(client), DLT_STRING(" Return Value: "), DLT_STRING(ERRORSTATUS_STRING[_Status])); + std::lock_guard<std::mutex> lock(mMutex); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)NSMA_ClientRequestFinish(_client, _Status))); + } + else + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: LifecycleRequestComplete Client: "), DLT_INT64(client), DLT_STRING(" Invalid return value: "), DLT_INT(_Status)); + } + NSMUnregisterWatchdog(); +} + +void NodeStateConsumer_StubImpl::onShutdownEventsSelectiveSubscriptionChanged(const std::shared_ptr<CommonAPI::ClientId> _client, const CommonAPI::SelectiveBroadcastSubscriptionEvent _event) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + std::lock_guard<std::mutex> lock(mMutex); + if (_event == CommonAPI::SelectiveBroadcastSubscriptionEvent::SUBSCRIBED) + { + NSMA__stObjectCallbacks->pfRegisterLifecycleClientCb(_client->hashCode(), NSM_SHUTDOWNTYPE_NOT, 0); + } + else if (_event == CommonAPI::SelectiveBroadcastSubscriptionEvent::UNSUBSCRIBED) + { + NSMA__stObjectCallbacks->pfUnRegisterLifecycleClientCb(_client->hashCode(), NSM_SHUTDOWNTYPE_FAST | NSM_SHUTDOWNTYPE_NORMAL | NSM_SHUTDOWNTYPE_PARALLEL | NSM_SHUTDOWNTYPE_RUNUP); + } + NSMUnregisterWatchdog(); +} diff --git a/NodeStateAccess/NodeStateConsumer_StubImpl.h b/NodeStateAccess/NodeStateConsumer_StubImpl.h new file mode 100644 index 0000000..fd8b409 --- /dev/null +++ b/NodeStateAccess/NodeStateConsumer_StubImpl.h @@ -0,0 +1,60 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#ifndef NODESTATECONSUMERSTUBIMPL_H_ +#define NODESTATECONSUMERSTUBIMPL_H_ + +#include <CommonAPI/CommonAPI.hpp> +#include <v1/org/genivi/nodestatemanager/ConsumerStubDefault.hpp> +#include <v1/org/genivi/NodeStateManagerTypes.hpp> + +#include "NodeStateAccess.h" +#include "NodeStateAccess.hpp" + +namespace GENIVI = v1::org::genivi; +using namespace GENIVI::nodestatemanager; + +class NodeStateConsumer_StubImpl: public ConsumerStubDefault { + +public: + NodeStateConsumer_StubImpl(NSMA_tstObjectCallbacks* NSMA__stObjectCallbacks); + + /** + * The following functions implements the interfaces defined in fidl/NodeStateManager.fidl + * Please have a look at this fidl file for more information. + */ + virtual void GetNodeState(const std::shared_ptr<CommonAPI::ClientId> _client, GetNodeStateReply_t _reply); + virtual void SetSessionState(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GENIVI::NodeStateManagerTypes::NsmSessionState_e _SessionState, SetSessionStateReply_t _reply); + virtual void GetSessionState(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _SessionName, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GetSessionStateReply_t _reply); + virtual void RegisterShutdownClient(const std::shared_ptr<CommonAPI::ClientId> _client, uint32_t _ShutdownMode, uint32_t _TimeoutMs, RegisterShutdownClientReply_t _reply); + virtual void UnRegisterShutdownClient(const std::shared_ptr<CommonAPI::ClientId> _client, uint32_t _ShutdownMode, UnRegisterShutdownClientReply_t _reply); + virtual void RegisterSession(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, GENIVI::NodeStateManagerTypes::NsmSessionState_e _SessionState, RegisterSessionReply_t _reply); + virtual void UnRegisterSession(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _SessionName, std::string _SessionOwner, GENIVI::NodeStateManagerTypes::NsmSeat_e _SeatID, UnRegisterSessionReply_t _reply); + virtual void GetAppHealthCount(const std::shared_ptr<CommonAPI::ClientId> _client, GetAppHealthCountReply_t _reply); + virtual void GetInterfaceVersion(const std::shared_ptr<CommonAPI::ClientId> _client, GetInterfaceVersionReply_t _reply); + virtual void LifecycleRequestComplete(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmErrorStatus_e _Status, LifecycleRequestCompleteReply_t _reply); + + /** + * This function is called by CommonAPI when new clients register for ShutdownEvents + */ + virtual void onShutdownEventsSelectiveSubscriptionChanged(const std::shared_ptr<CommonAPI::ClientId> _client, const CommonAPI::SelectiveBroadcastSubscriptionEvent _event); +private: + NSMA_tstObjectCallbacks* NSMA__stObjectCallbacks = NULL; + std::mutex mMutex; +}; + +#endif /* NODESTATECONSUMERSTUBIMPL_H_ */ diff --git a/NodeStateAccess/NodeStateLifecycleControl_StubImpl.cpp b/NodeStateAccess/NodeStateLifecycleControl_StubImpl.cpp new file mode 100644 index 0000000..abf8b1a --- /dev/null +++ b/NodeStateAccess/NodeStateLifecycleControl_StubImpl.cpp @@ -0,0 +1,89 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#include "NodeStateLifecycleControl_StubImpl.h" +#include "Watchdog.hpp" + +#include <dlt.h> +#include <iostream> + +DLT_IMPORT_CONTEXT(NsmaContext); + +NodeStateLifecycleControl_StubImpl::NodeStateLifecycleControl_StubImpl(NSMA_tstObjectCallbacks* objectCallbacks) +{ + NSMA__stObjectCallbacks = objectCallbacks; +} + +NodeStateLifecycleControl_StubImpl::~NodeStateLifecycleControl_StubImpl() +{ +} + +void NodeStateLifecycleControl_StubImpl::RequestNodeRestart(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GENIVI::NodeStateManagerTypes::NsmRestartReason_e _RestartReason, uint32_t _RestartType, RequestNodeRestartReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + if (_RestartReason >= NsmRestartReason_NotSet && _RestartReason <= NsmRestartReason_Last) + { + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: RequestNodeRestart. RestartReason:"), DLT_UINT(_RestartReason), DLT_STRING(RESTARTREASON_STRING[_RestartReason]), + DLT_STRING("RestartType:"), DLT_UINT(_RestartType)); + GENIVI::NodeStateManagerTypes::NsmErrorStatus_e error = (GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal)NSMA__stObjectCallbacks->pfRequestNodeRestartCb((NsmRestartReason_e) (int) _RestartReason, _RestartType); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: RequestNodeRestart. Reply"), DLT_INT(error)); + _reply(error); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: RequestNodeRestart. Reply finished")); + } + else + { + DLT_LOG(NsmaContext, DLT_LOG_ERROR, DLT_STRING("NSMA: RequestNodeRestart. Invalid RestartReason:"), DLT_UINT(_RestartReason), DLT_STRING("RestartType:"), DLT_UINT(_RestartType)); + } + NSMUnregisterWatchdog(); +} + +void NodeStateLifecycleControl_StubImpl::SetNodeState(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, GENIVI::NodeStateManagerTypes::NsmNodeState_e _NodeStateId, SetNodeStateReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: SetNodeState. NodeStateId:"), DLT_UINT(_NodeStateId)); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) + NSMA__stObjectCallbacks->pfSetNodeStateCb((NsmNodeState_e)(int) _NodeStateId))); + NSMUnregisterWatchdog(); +} + +void NodeStateLifecycleControl_StubImpl::SetBootMode(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, int32_t _BootMode, SetBootModeReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: SetBootMode. BootMode"), DLT_UINT(_BootMode)); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) + NSMA__stObjectCallbacks->pfSetBootModeCb(_BootMode))); + NSMUnregisterWatchdog(); +} + +void NodeStateLifecycleControl_StubImpl::SetAppHealthStatus(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, std::string _AppName, bool _AppRunning, SetAppHealthStatusReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: SetAppHealthStatus. AppName:"), DLT_STRING(_AppName.data()), DLT_STRING("AppRunning:"), DLT_BOOL(_AppRunning)); + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) + NSMA__stObjectCallbacks->pfSetAppHealthStatusCb(_AppName.c_str(), _AppRunning))); + NSMUnregisterWatchdog(); +} + +void NodeStateLifecycleControl_StubImpl::CheckLucRequired(const std::shared_ptr<CommonAPI::ClientId> __attribute__((__unused__)) _client, CheckLucRequiredReply_t _reply) +{ + NSMTriggerWatchdog(NsmWatchdogState_Active); + DLT_LOG(NsmaContext, DLT_LOG_INFO, DLT_STRING("NSMA: CheckLucRequired.")); + + _reply(GENIVI::NodeStateManagerTypes::NsmErrorStatus_e((GENIVI::NodeStateManagerTypes::NsmErrorStatus_e::Literal) + NSMA__stObjectCallbacks->pfCheckLucRequiredCb())); + NSMUnregisterWatchdog(); +} diff --git a/NodeStateAccess/NodeStateLifecycleControl_StubImpl.h b/NodeStateAccess/NodeStateLifecycleControl_StubImpl.h new file mode 100644 index 0000000..0155305 --- /dev/null +++ b/NodeStateAccess/NodeStateLifecycleControl_StubImpl.h @@ -0,0 +1,48 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#ifndef NODESTATELIFECYCLECONTROLSTUBIMPL_H_ +#define NODESTATELIFECYCLECONTROLSTUBIMPL_H_ + +#include <CommonAPI/CommonAPI.hpp> +#include <v1/org/genivi/nodestatemanager/LifecycleControlStubDefault.hpp> + +#include "NodeStateAccess.h" + +namespace GENIVI = v1::org::genivi; +using namespace GENIVI::nodestatemanager; + +class NodeStateLifecycleControl_StubImpl: public LifecycleControlStubDefault { + +public: + NodeStateLifecycleControl_StubImpl(NSMA_tstObjectCallbacks* NSMA__stObjectCallbacks); + virtual ~NodeStateLifecycleControl_StubImpl(); + + /** + * The following functions implements the interfaces defined in fidl/NodeStateManager.fidl + * Please have a look at this fidl file for more information. + */ + virtual void RequestNodeRestart(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmRestartReason_e _RestartReason, uint32_t _RestartType, RequestNodeRestartReply_t _reply); + virtual void SetNodeState(const std::shared_ptr<CommonAPI::ClientId> _client, GENIVI::NodeStateManagerTypes::NsmNodeState_e _NodeStateId, SetNodeStateReply_t _reply); + virtual void SetBootMode(const std::shared_ptr<CommonAPI::ClientId> _client, int32_t _BootMode, SetBootModeReply_t _reply); + virtual void SetAppHealthStatus(const std::shared_ptr<CommonAPI::ClientId> _client, std::string _AppName, bool _AppRunning, SetAppHealthStatusReply_t _reply); + virtual void CheckLucRequired(const std::shared_ptr<CommonAPI::ClientId> _client, CheckLucRequiredReply_t _reply); +private: + NSMA_tstObjectCallbacks* NSMA__stObjectCallbacks = NULL; +}; + +#endif /* NODESTATELIFECYCLECONTROLSTUBIMPL_H_ */ diff --git a/NodeStateAccess/SimpleTimer.cpp b/NodeStateAccess/SimpleTimer.cpp new file mode 100644 index 0000000..5aea0b5 --- /dev/null +++ b/NodeStateAccess/SimpleTimer.cpp @@ -0,0 +1,56 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Implements a simple timer which calls a method after a specified timeout in ms. + * This timer can be canceled using "cancelTimer()" + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the D-Bus binding and code generated by + * "CommonAPI". Therefore, the D-Bus communication and generated CommonAPI objects are handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#include "SimpleTimer.h" +#include <unistd.h> + +void SimpleTimer::cancelTimer() +{ + std::unique_lock<std::mutex> lock(mMutex); + timerLock--; + if(timerLock <= 0) + { + mCondVar.notify_all(); + } + lock.unlock(); +} + +void SimpleTimer::stopTimer() +{ + std::unique_lock<std::mutex> lock(mMutex); + timerLock = 0; + mCondVar.notify_all(); + lock.unlock(); +} + +void SimpleTimer::joinTimer() +{ + std::unique_lock<std::mutex> lock(mMutex); + while(joined == false) + { + NSMTriggerWatchdog(NsmWatchdogState_Sleep); + mCondVarJoin.wait(lock); + NSMTriggerWatchdog(NsmWatchdogState_Active); + } + lock.unlock(); +} + +SimpleTimer::~SimpleTimer() +{ + joinTimer(); +} diff --git a/NodeStateAccess/SimpleTimer.h b/NodeStateAccess/SimpleTimer.h new file mode 100644 index 0000000..523f916 --- /dev/null +++ b/NodeStateAccess/SimpleTimer.h @@ -0,0 +1,105 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface between NodeStateManager and IPC + * + * This source file is a part of the NodeStateAccess library (NSMA). + * The architecture requires that the NodeStateManager (NSM) is independent from the CommonAPI binding. + * Therefore, the CommonAPI communication is handled inside of this library. + * The library offers the NSM an interface to use objects generated via CommonAPI. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +#ifndef NODESTATEACCESS_SIMPLETIMER_H_ +#define NODESTATEACCESS_SIMPLETIMER_H_ + +#include <functional> +#include <chrono> +#include <future> +#include <cstdio> +#include <iostream> +#include "Watchdog.hpp" + +class SimpleTimer +{ +private: + std::mutex mMutex; + std::condition_variable mCondVar; + std::condition_variable mCondVarJoin; + bool joined = false; +public: + std::shared_ptr<SimpleTimer> self; + volatile uint timerLock; + template<class callable, class ... arguments> + SimpleTimer(int timeOut, int timerLocks, callable&& f, arguments&&... args) + { + std::function<typename std::result_of<callable(arguments...)>::type()> task(std::bind(std::forward<callable>(f), std::forward<arguments>(args)...)); + timerLock = timerLocks; + + std::thread([this, timeOut, task]() + { + NSMTriggerWatchdog(NsmWatchdogState_Active); + std::unique_lock<std::mutex> lock(mMutex); + + while (timerLock > 0) + { + NSMTriggerWatchdog(NsmWatchdogState_Sleep); + if (std::cv_status::timeout == mCondVar.wait_until(lock, std::chrono::steady_clock::now() + std::chrono::milliseconds(timeOut))) + { + NSMTriggerWatchdog(NsmWatchdogState_Active); + break; + } + NSMTriggerWatchdog(NsmWatchdogState_Active); + } + + if(timerLock > 0) + { + lock.unlock(); + task(); + lock.lock(); + } + NSMUnregisterWatchdog(); + + joined = true; + mCondVarJoin.notify_all(); + lock.unlock(); + + /* Set own pointer to NULL - timer can be automatically deleted from now on */ + self = NULL; + }).detach(); + }; + + ~SimpleTimer(); + + /** + * SimpleTimer starts a thread which executes a callback after timeOut milliseconds. + * It is possible to cancel the execution of this callback by calling cancel. + * The constructor is hidden. This way it is ensured that all timers are created with new. + * After the timer has finished it will destroy itself. + */ + template<class callable, class ... arguments> + static std::shared_ptr<SimpleTimer> CreateTimer(int timeOut, int timerLocks, callable&& f, arguments&&... args) + { + std::shared_ptr<SimpleTimer> timer = std::make_shared<SimpleTimer>(timeOut, timerLocks, std::forward<callable>(f), std::forward<arguments>(args)...); + /* Save timer in timer itself so it will only be cleaned when thread has finished*/ + timer->self = timer; + return timer; + } + + /** + * This function decrements the timerLocks by one. timerLocks has been initialized in CreateTimer. + * When this locks have reached zero the timer is considered as canceled/deprecated + * and the specified task will not be executed anymore. + */ + void cancelTimer(); + void stopTimer(); + void joinTimer(); + +}; + +#endif /* NODESTATEACCESS_SIMPLETIMER_H_ */ diff --git a/NodeStateAccess/interfaces/CMakeLists.txt b/NodeStateAccess/interfaces/CMakeLists.txt new file mode 100644 index 0000000..53e677c --- /dev/null +++ b/NodeStateAccess/interfaces/CMakeLists.txt @@ -0,0 +1,335 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Sven_Hassler@mentor.com +# +# CMake file of NSM Interfaces +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +cmake_minimum_required(VERSION 3.7.2 FATAL_ERROR) + +project(NodeStateAccessInterfaces LANGUAGES CXX) + +include(GNUInstallDirs) +include(CMakePackageConfigHelpers) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_CXX_EXTENSIONS NO) + + +########################################### +# Options & settings +########################################### + +option(USE_INSTALLED_COMMONAPI "Set to OFF to use the local (build tree) version of CommonAPI" ON) + +set(SRC_GEN_DEST "src-gen" CACHE STRING "Path to the destination directory of the generated sources") +if(NOT IS_ABSOLUTE ${SRC_GEN_DEST}) + set(SRC_GEN_DEST "${CMAKE_CURRENT_BINARY_DIR}/${SRC_GEN_DEST}") +endif() + +# Core generator: +set(COMMONAPI_CORE_TOOL_GENERATOR "" CACHE STRING "CommonAPI-Core-Tools generator") +if("${COMMONAPI_CORE_TOOL_GENERATOR}" STREQUAL "") + message(FATAL_ERROR "The file path for the SomeIP generator needs to be specified! Use '-DCOMMONAPI_CORE_TOOL_GENERATOR=<path>'") + return() +else() + message("COMMONAPI_CORE_TOOL_GENERATOR specified: ${COMMONAPI_CORE_TOOL_GENERATOR}") +endif() + +# SomeIP generator: +set(COMMONAPI_SOMEIP_TOOL_GENERATOR "" CACHE STRING "CommonAPI-SomeIP-Tools generator") +if("${COMMONAPI_SOMEIP_TOOL_GENERATOR}" STREQUAL "") + message(FATAL_ERROR "The file path for the SomeIP generator needs to be specified! Use '-DCOMMONAPI_SOMEIP_TOOL_GENERATOR=<path>'") + return() +else() + message("COMMONAPI_SOMEIP_TOOL_GENERATOR specified: ${COMMONAPI_SOMEIP_TOOL_GENERATOR}") +endif() + + +########################################### +# Find required packages +########################################### + +if("${USE_INSTALLED_COMMONAPI}" STREQUAL "ON") + find_package(CommonAPI REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + find_package(CommonAPI-SomeIP REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) + find_package(vsomeip REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) +else() + find_package(CommonAPI REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + find_package(CommonAPI-SomeIP REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) + find_package(vsomeip REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) +endif() + +find_package(Java 1.8 EXACT REQUIRED COMPONENTS Development) + + +########################################### +# Generate code +########################################### + +set(INTERFACE_NAME "org.genivi.nodestatemanager") + +execute_process( + COMMAND + ${COMMONAPI_CORE_TOOL_GENERATOR} + --dest-common ${SRC_GEN_DEST}/${INTERFACE_NAME}/common/core/ + --dest-proxy ${SRC_GEN_DEST}/${INTERFACE_NAME}/proxy/core/ + --dest-stub ${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/core/ + --dest-skel ${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/core/ + --skel + ${CMAKE_CURRENT_SOURCE_DIR}/NodeStateManager.fdepl + + COMMAND + ${COMMONAPI_SOMEIP_TOOL_GENERATOR} + --dest-common ${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip/ + --dest-proxy ${SRC_GEN_DEST}/${INTERFACE_NAME}/proxy/someip/ + --dest-stub ${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/someip/ + ${CMAKE_CURRENT_SOURCE_DIR}/NodeStateManager.fdepl + + RESULTS_VARIABLE + ERRORS +) + +list(GET ERRORS 0 CORE_ERROR) +if(NOT ${CORE_ERROR} EQUAL 0) +message(FATAL_ERROR "Error calling core generators: ${CORE_ERROR}") +endif() + +list(GET ERRORS 1 SOMEIP_ERROR) +if(NOT ${SOMEIP_ERROR} EQUAL 0) + message(FATAL_ERROR "Error calling someip generators: ${SOMEIP_ERROR}") +endif() + + +########################################### +# Build libraries +########################################### + +# Core stub: +set(CORE_STUB_NAME "org.genivi.nodestatemanager.commonapi.core.stub") +file(GLOB_RECURSE CORE_STUB_SRCS + "${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/core/**/*.cpp" +) +set(CORE_STUB_INCLUDES + "${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/core/" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/core/" +) +set(CORE_STUB_INSTALL_INCLUDES + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/stub/core/" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/common/core/" +) +set(CORE_STUB_LINK_LIBRARIES + "CommonAPI" +) + +add_library(${CORE_STUB_NAME} SHARED ${CORE_STUB_SRCS}) +target_link_libraries(${CORE_STUB_NAME} PUBLIC ${CORE_STUB_LINK_LIBRARIES}) +target_include_directories( + ${CORE_STUB_NAME} PUBLIC + "$<BUILD_INTERFACE:${CORE_STUB_INCLUDES}>" + "$<INSTALL_INTERFACE:${CORE_STUB_INSTALL_INCLUDES}>" + ${COMMONAPI_INCLUDE_DIRS} +) + +# SomeIP stub: +set(SOMEIP_STUB_NAME "org.genivi.nodestatemanager.commonapi.someip.stub") +file(GLOB_RECURSE SOMEIP_STUB_SRCS + "${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/someip/**/*.cpp" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip/**/*.cpp" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip/**/*.cpp" +) +set(SOMEIP_STUB_INCLUDES + "${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/someip" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/stub/core" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/core" +) +set(SOMEIP_STUB_INSTALL_INCLUDES + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/stub/someip" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/stub/core" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/common/someip" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/common/core" +) +set(SOMEIP_STUB_LINK_LIBRARIES + "CommonAPI" + "CommonAPI-SomeIP" +) + +add_library(${SOMEIP_STUB_NAME} SHARED ${SOMEIP_STUB_SRCS}) +target_link_libraries(${SOMEIP_STUB_NAME} PUBLIC ${SOMEIP_STUB_LINK_LIBRARIES}) +target_include_directories( + ${SOMEIP_STUB_NAME} PUBLIC + ${COMMONAPI_INCLUDE_DIRS} + ${COMMONAPI_SOMEIP_INCLUDE_DIRS} + "$<BUILD_INTERFACE:${SOMEIP_STUB_INCLUDES}>" + "$<INSTALL_INTERFACE:${SOMEIP_STUB_INSTALL_INCLUDES}>" +) + +# SomeIP proxy: +set(SOMEIP_PROXY_NAME "org.genivi.nodestatemanager.commonapi.someip.proxy") +file(GLOB_RECURSE SOMEIP_PROXY_SRCS + "${SRC_GEN_DEST}/${INTERFACE_NAME}/proxy/someip/**/*.cpp" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip/**/*.cpp" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip/**/*.cpp" +) +set(SOMEIP_PROXY_INCLUDES + "${SRC_GEN_DEST}/${INTERFACE_NAME}/proxy/someip" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/proxy/core" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/someip" + "${SRC_GEN_DEST}/${INTERFACE_NAME}/common/core" +) +set(SOMEIP_PROXY_INSTALL_INCLUDES + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/proxy/someip" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/proxy/core" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/common/someip" + "${CMAKE_INSTALL_INCLUDEDIR}/${INTERFACE_NAME}/common/core" +) +set(SOMEIP_PROXY_LINK_LIBRARIES + "CommonAPI" + "CommonAPI-SomeIP" +) + +add_library(${SOMEIP_PROXY_NAME} SHARED ${SOMEIP_PROXY_SRCS}) +target_link_libraries(${SOMEIP_PROXY_NAME} PUBLIC ${SOMEIP_PROXY_LINK_LIBRARIES}) +target_include_directories( + ${SOMEIP_PROXY_NAME} PUBLIC + ${COMMONAPI_INCLUDE_DIRS} + ${COMMONAPI_SOMEIP_INCLUDE_DIRS} + "$<BUILD_INTERFACE:${SOMEIP_PROXY_INCLUDES}>" + "$<INSTALL_INTERFACE:${SOMEIP_PROXY_INSTALL_INCLUDES}>" +) + + +########################################### +# Install + +# Install libraries: +install( + TARGETS ${CORE_STUB_NAME} + EXPORT ${CORE_STUB_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install( + TARGETS ${SOMEIP_STUB_NAME} + EXPORT ${SOMEIP_STUB_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) +install( + TARGETS ${SOMEIP_PROXY_NAME} + EXPORT ${SOMEIP_PROXY_NAME}Targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} +) + +# Install includes: +install( + DIRECTORY ${CORE_STUB_INCLUDES} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${CORE_STUB_NAME}" + FILES_MATCHING PATTERN "*.hpp" +) + +install( + DIRECTORY ${SOMEIP_STUB_INCLUDES} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SOMEIP_STUB_NAME}" + FILES_MATCHING PATTERN "*.hpp" +) + +install( + DIRECTORY ${SOMEIP_PROXY_INCLUDES} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${SOMEIP_PROXY_NAME}" + FILES_MATCHING PATTERN "*.hpp" +) + +# Create and install package configuration files: +configure_package_config_file( + cmake/core_stub_config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${CORE_STUB_NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_STUB_NAME} +) +# install( +# FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_STUB_NAME}Config.cmake +# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_STUB_NAME} +# ) + +configure_package_config_file( + cmake/someip_stub_config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_STUB_NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_STUB_NAME} +) +# install( +# FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_STUB_NAME}Config.cmake +# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_STUB_NAME} +# ) + +configure_package_config_file( + cmake/someip_proxy_config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_PROXY_NAME}Config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_PROXY_NAME} +) +# install( +# FILES ${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_PROXY_NAME}Config.cmake +# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_PROXY_NAME} +# ) + +# Create and install target files: +export(EXPORT ${CORE_STUB_NAME}Targets) +install( + EXPORT ${CORE_STUB_NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_STUB_NAME} +) + +export(EXPORT ${SOMEIP_STUB_NAME}Targets) +install( + EXPORT ${SOMEIP_STUB_NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_STUB_NAME} +) + +export(EXPORT ${SOMEIP_PROXY_NAME}Targets) +install( + EXPORT ${SOMEIP_PROXY_NAME}Targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_PROXY_NAME} +) + +# Create and install version files: +write_basic_package_version_file( + ${CORE_STUB_NAME}ConfigVersion.cmake + VERSION 1.0 + COMPATIBILITY SameMajorVersion +) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${CORE_STUB_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${CORE_STUB_NAME} +) + +write_basic_package_version_file( + ${SOMEIP_STUB_NAME}ConfigVersion.cmake + VERSION 1.0 + COMPATIBILITY SameMajorVersion +) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_STUB_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_STUB_NAME} +) + +write_basic_package_version_file( + ${SOMEIP_PROXY_NAME}ConfigVersion.cmake + VERSION 1.0 + COMPATIBILITY SameMajorVersion +) +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${SOMEIP_PROXY_NAME}ConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${SOMEIP_PROXY_NAME} +) + +# Export the packages for use from the build-tree: +# (this registers the build-tree with the global CMake-registry) +export(PACKAGE ${CORE_STUB_NAME}) +export(PACKAGE ${SOMEIP_STUB_NAME}) +export(PACKAGE ${SOMEIP_PROXY_NAME}) diff --git a/NodeStateAccess/interfaces/NodeStateMachineTest.fdepl b/NodeStateAccess/interfaces/NodeStateMachineTest.fdepl new file mode 100644 index 0000000..e53799d --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateMachineTest.fdepl @@ -0,0 +1,34 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl" +import "NodeStateMachineTest.fidl" +import "NodeStateManagerTypes.fidl" +import "NodeStateManagerTypes.fdepl" + +define org.genivi.commonapi.someip.deployment for interface +org.genivi.nodestatemachinetest.Test { + SomeIpServiceID = 63744 + + method GetNsmData { + SomeIpMethodID = 1 + } + + method GetNsmInterfaceVersion { + SomeIpMethodID = 2 + } + + method SetNsmData { + SomeIpMethodID = 3 + } + +} diff --git a/NodeStateAccess/interfaces/NodeStateMachineTest.fidl b/NodeStateAccess/interfaces/NodeStateMachineTest.fidl new file mode 100644 index 0000000..63f1832 --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateMachineTest.fidl @@ -0,0 +1,51 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +package org.genivi.nodestatemachinetest +import org.genivi.* from "NodeStateManagerTypes.fidl" + +<** + @author : Monika Forstner +**> + +interface Test { + version { + major 1 + minor 0 + } + method GetNsmData { + in { + NodeStateManagerTypes.NsmDataType_e DataType + NodeStateManagerTypes.NsmDataTypeArray DataIn + UInt32 DataLen + } + out { + NodeStateManagerTypes.NsmDataTypeArray DataOut + Int32 ErrorCode + } + } + method GetNsmInterfaceVersion { + out { + UInt8 Version + } + } + method SetNsmData { + in { + NodeStateManagerTypes.NsmDataType_e DataType + NodeStateManagerTypes.NsmDataTypeArray Data + UInt32 DataLen + } + out { + Int32 ErrorCode + } + } +} diff --git a/NodeStateAccess/interfaces/NodeStateManager.fdepl b/NodeStateAccess/interfaces/NodeStateManager.fdepl new file mode 100644 index 0000000..1916025 --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateManager.fdepl @@ -0,0 +1,160 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl" +import "NodeStateManager.fidl" +import "NodeStateManagerTypes.fidl" +import "NodeStateManagerTypes.fdepl" + +define org.genivi.commonapi.someip.deployment for interface +org.genivi.nodestatemanager.Consumer { + SomeIpServiceID = 63745 + + attribute BootMode { + SomeIpGetterID = 1 + SomeIpSetterID = 2 + SomeIpNotifierID = 32769 + SomeIpEventGroups = { + 1 + } + } + + attribute RestartReason { + SomeIpGetterID = 3 + SomeIpSetterID = 4 + SomeIpNotifierID = 32770 + SomeIpEventGroups = { + 2 + } + } + + attribute ShutdownReason { + SomeIpGetterID = 5 + SomeIpSetterID = 6 + SomeIpNotifierID = 32771 + SomeIpEventGroups = { + 3 + } + } + + attribute WakeUpReason { + SomeIpGetterID = 7 + SomeIpSetterID = 8 + SomeIpNotifierID = 32772 + SomeIpEventGroups = { + 4 + } + } + + method GetNodeState { + SomeIpMethodID = 9 + } + + method SetSessionState { + SomeIpMethodID = 10 + } + + method GetSessionState { + SomeIpMethodID = 11 + } + + method GetApplicationMode { + SomeIpMethodID = 12 + } + + method RegisterShutdownClient { + SomeIpMethodID = 13 + } + + method UnRegisterShutdownClient { + SomeIpMethodID = 14 + } + + method RegisterSession { + SomeIpMethodID = 15 + } + + method UnRegisterSession { + SomeIpMethodID = 16 + } + + method GetAppHealthCount { + SomeIpMethodID = 17 + } + + method GetInterfaceVersion { + SomeIpMethodID = 18 + } + + method LifecycleRequestComplete { + SomeIpMethodID = 19 + } + + broadcast ShutdownEvents { + SomeIpEventID = 32773 + SomeIpEventGroups = { + 5 + } + } + + broadcast NodeApplicationMode { + SomeIpEventID = 32774 + SomeIpEventGroups = { + 6 + } + } + + broadcast NodeState { + SomeIpEventID = 32775 + SomeIpEventGroups = { + 7 + } + } + + broadcast SessionStateChanged { + SomeIpEventID = 32776 + SomeIpEventGroups = { + 8 + } + } + +} + +define org.genivi.commonapi.someip.deployment for interface +org.genivi.nodestatemanager.LifecycleControl { + SomeIpServiceID = 63746 + + method RequestNodeRestart { + SomeIpMethodID = 1 + } + + method SetApplicationMode { + SomeIpMethodID = 2 + } + + method SetNodeState { + SomeIpMethodID = 3 + } + + method SetBootMode { + SomeIpMethodID = 4 + } + + method SetAppHealthStatus { + SomeIpMethodID = 5 + } + + method CheckLucRequired { + SomeIpMethodID = 6 + } + +} diff --git a/NodeStateAccess/interfaces/NodeStateManager.fidl b/NodeStateAccess/interfaces/NodeStateManager.fidl new file mode 100644 index 0000000..0865989 --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateManager.fidl @@ -0,0 +1,482 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +package org.genivi.nodestatemanager +import org.genivi.* from "NodeStateManagerTypes.fidl" + +<** + @author : Alexander Wenzel +**> + +interface Consumer { + version { + major 1 + minor 0 + } + broadcast ShutdownEvents selective { + out { + UInt32 Mode + } + } + + <** + @description : and will include the current Node Application Mode as a parameter + **> + broadcast NodeApplicationMode { + out { + + <** + @description : This parameter will be based upon the NsmApplicationMode_e + **> + NodeStateManagerTypes.NsmApplicationMode_e ApplicationModeId + } + } + + <** + @description : include the current Node State as a parameter + **> + broadcast NodeState { + out { + + <** + @description : This parameter will be based upon the NsmNodeState_e + **> + NodeStateManagerTypes.NsmNodeState_e NodeStateId + } + } + + <** + @description : + through the use of the Session Name. + + The signal will include the session name and the new session state + **> + broadcast SessionStateChanged { + out { + + <** + @description : The Session name will be based upon either the pre-defined platform session names or using a newly added product defined session name + **> + String SessionName + + <** + @description : This parameter will be based upon the enum NsmSeat_e + **> + NodeStateManagerTypes.NsmSeat_e SeatID + + <** + @description : This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states + **> + NodeStateManagerTypes.NsmSessionState_e SessionState + } + } + + <** + @description : The method is used by other applications to get the NodeState without the need of registration to the signal + **> + method GetNodeState { + out { + + <** + @description : Will be based on the NsmNodeState_e + **> + NodeStateManagerTypes.NsmNodeState_e NodeStateId + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by applications to set the state of a session + **> + method SetSessionState { + in { + + <** + @description : This is a null terminated string that identifies the name of the session that should be updated + **> + String SessionName + + <** + @description : This parameter defines the name of the application that is setting the state of the session. This must be the applications systemd unit filename. + **> + String SessionOwner + + <** + @description : This parameter will be based upon the enum NsmSeat_e + **> + NodeStateManagerTypes.NsmSeat_e SeatID + + <** + @description : Will be based on the NsmSessionState_e but it will not be bounded by the values in that enum as extended session states are possible for new product sessions + **> + NodeStateManagerTypes.NsmSessionState_e SessionState + } + out { + + <** + @description : NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by applications to get the state of a session + **> + method GetSessionState { + in { + String SessionName + + <** + @description : This parameter will be based upon the enum NsmSeat_e + **> + NodeStateManagerTypes.NsmSeat_e SeatID + } + out { + + <** + @description : Will be based on the NsmSessionState_e but it will not be bounded by the values in that enum as extended session states are possible for new product sessions + **> + NodeStateManagerTypes.NsmSessionState_e SessionState + + <** + @description : NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by other applications to get the application mode. + **> + method GetApplicationMode { + out { + + <** + @description : Will be based on NsmApplicationMode_e + **> + NodeStateManagerTypes.NsmApplicationMode_e ApplicationModeId + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : object called NSMLifecycleRequest. This method will take one parameter which is the Lifecycle Request (i.e. normal shutdown, fast shutdown, runup). For an example of the required client interface please see the Boot Manager component who will be a client of the NSM + **> + method RegisterShutdownClient { + in { + + <** + @description : Shutdown mode for which client wants to be informed (i.e normal, fast etc) + **> + UInt32 ShutdownMode + + <** + @description : Max. Timeout to wait for response from shutdown client. + **> + UInt32 TimeoutMs + } + out { + + <** + @description : + Returned error code of the method. + NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by other applications to unregister themselves as shutdown client + **> + method UnRegisterShutdownClient { + in { + + <** + @description : Shutdown mode from which client wants to be unregistered + **> + UInt32 ShutdownMode + } + out { + + <** + @description : + Returned error code of the method. + NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by other applications to register a new session whose state should be observed and distributed by the NSM + **> + method RegisterSession { + in { + + <** + @description : Session name to be registered + **> + String SessionName + + <** + @description : This is the name of the application that is registering the new session (this must be the applications systemd unit filename) + **> + String SessionOwner + + <** + @description : This parameter will be based upon the enum NsmSeat_e + **> + NodeStateManagerTypes.NsmSeat_e SeatID + + <** + @description : Will be based on the NsmSessionState_e but it will not be bounded by the values in that enum as extended session states are possible for new product sessions + **> + NodeStateManagerTypes.NsmSessionState_e SessionState + } + out { + + <** + @description : + Returned error code of the method. + NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method is used by other applications to remove a new session from the session list hosted by NSM + **> + method UnRegisterSession { + in { + + <** + @description : Session name to be unregistered + **> + String SessionName + + <** + @description : This is the name of the application that originally registered the session. It will be validated that this value matches the stored value from the registration + **> + String SessionOwner + + <** + @description : This parameter will be based upon the enum NsmSeat_e + **> + NodeStateManagerTypes.NsmSeat_e SeatID + } + out { + + <** + @description : + Returned error code of the method. + NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : This method can be used to read the number of failed applications in the system + **> + method GetAppHealthCount { + out { + + <** + @description : Number of currently failing apps + **> + UInt32 Count + } + } + + <** + @description : + The method returns the version number of the Node State Manager. The number is organized in four bytes: + + Version: VVV.RRR.PPP.BBB + + <literallayout> + VVV => Version [1..255] + RRR => Release [0..255] + PPP => Patch [0..255] + BBB => Build [0..255] + </literallayout> + **> + method GetInterfaceVersion { + out { + + <** + @description : Unsigned integer that represents the version number of the Node State Manager. + **> + UInt32 Version + } + } + + <** + @description : The method is used by a client to notify the NSM that a LifecycleRequest has been completed + **> + method LifecycleRequestComplete { + in { + + <** + @description : Status of the request to be performed. This will be based on the enum NsmErrorStatus_e + **> + NodeStateManagerTypes.NsmErrorStatus_e Status + } + out { + + <** + @description : NsmErrorStatus_e value + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } attribute Int32 BootMode + + attribute NodeStateManagerTypes.NsmRestartReason_e RestartReason + + attribute NodeStateManagerTypes.NsmShutdownReason_e ShutdownReason + + attribute NodeStateManagerTypes.NsmRunningReason_e WakeUpReason + +} + +<** + @author : Alexander Wenzel +**> + +interface LifecycleControl { + version { + major 1 + minor 0 + } + + <** + @description : The method is used by other applications to request a restart of the node. + **> + method RequestNodeRestart { + in { + + <** + @description : The passed value will be based upon the enum NsmRestartReason_e. + **> + NodeStateManagerTypes.NsmRestartReason_e RestartReason + + <** + @description : + This parameter will define the type of shutdown that is requested as part of the restart process. The acceptable values for this parameter are + + NSM_SHUTDOWNTYPE_NORMAL + and + NSM_SHUTDOWNTYPE_FAST + **> + UInt32 RestartType + } + out { + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : application mode + **> + method SetApplicationMode { + in { + + <** + @description : This parameter will be based upon the NsmApplicationMode_e + **> + NodeStateManagerTypes.NsmApplicationMode_e ApplicationModeId + } + out { + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : registered consumers of the new state + **> + method SetNodeState { + in { + + <** + @description : The passed value will be based upon the enum NsmNodeState_e + **> + NodeStateManagerTypes.NsmNodeState_e NodeStateId + } + out { + + <** + @description : The passed value will be based upon the enum NsmErrorStatus_e + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : The method has been introduced, because the property ‘BootMode’ can only be read by other applications. Nevertheless there are some exceptions where the property should be set by a restricted set of applications which will be handled within this method + **> + method SetBootMode { + in { + + <** + @description : The passed value will not be boundary checked to allow for product extensions. The actual value that a client should use will be defined in another common header that is currently not available + + + **> + Int32 BootMode + } + out { + + <** + @description : Returned error code for set. + **> + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : will use this information to keep a count of the number of failed applications within the current lifecycle. Additionally it will unset any sessions that the failing application may have had active. It will also be possible for the product node state machine to make a decision on what to do with this information, i.e. even reset the node or reset the node if too many applications have failed + **> + method SetAppHealthStatus { + in { + + <** + @description : This parameter can be used to give the name of the application that has failed (this must be the applications systemd unit name) + **> + String AppName + + <** + @description : The AppRunning will define whether the application is currently running or not + **> + Boolean AppRunning + } + out { + NodeStateManagerTypes.NsmErrorStatus_e ErrorCode + } + } + + <** + @description : This is required whilst in certain Node Application Modes (i.e. Transport, Factory) we do not want the LUC Applications started. Internally the Node State Manager will need to call a product interface to get the mapping back for the current NAM. + **> + method CheckLucRequired { + out { + + <** + @description : This will be a simple TRUE or FALSE to define whether the LUC is wanted in the current Lifecycle + **> + Boolean LucWanted + } + } + +} diff --git a/NodeStateAccess/interfaces/NodeStateManagerTypes.fdepl b/NodeStateAccess/interfaces/NodeStateManagerTypes.fdepl new file mode 100644 index 0000000..e0e9acf --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateManagerTypes.fdepl @@ -0,0 +1,55 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +import "platform:/plugin/org.genivi.commonapi.someip/deployment/CommonAPI-SOMEIP_deployment_spec.fdepl" +import "NodeStateManagerTypes.fidl" + +define org.genivi.commonapi.someip.deployment for typeCollection +org.genivi.NodeStateManagerTypes { + + array NsmDataTypeArray { + } + + enumeration NsmApplicationMode_e { + } + + enumeration NsmCoreSessionName_e { + } + + enumeration NsmDataType_e { + } + + enumeration NsmErrorStatus_e { + } + + enumeration NsmNodeState_e { + } + + enumeration NsmRestartReason_e { + } + + enumeration NsmRunningReason_e { + } + + enumeration NsmSeat_e { + } + + enumeration NsmSessionState_e { + } + + enumeration NsmShutdownReason_e { + } + + enumeration NsmShutdownType_e { + } + +} diff --git a/NodeStateAccess/interfaces/NodeStateManagerTypes.fidl b/NodeStateAccess/interfaces/NodeStateManagerTypes.fidl new file mode 100644 index 0000000..d4aeaa2 --- /dev/null +++ b/NodeStateAccess/interfaces/NodeStateManagerTypes.fidl @@ -0,0 +1,268 @@ +/********************************************************************************************************************** + * + * Copyright (C) 2017 BMW AG + * + * Interface definition for NodeStateManager CommonAPI interface + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + **********************************************************************************************************************/ + +package org.genivi + +<** + @author : Alexander Wenzel +**> +typeCollection NodeStateManagerTypes { + version { + major 1 + minor 0 + } + array NsmDataTypeArray of UInt8 + + <** + @description : + The enumeration defines the different values for the application mode. + + Each possible value will indicate that a different level of functionality is expected to be provided in the current and subsequent lifecycles. + + This value will be used to define the "run level" that systemd should enable. + + The values shown in this list are those that are mandatory for the Platform but it will be possible for the product to extend the list as needed by rebuilding the Node State Manager + **> + enumeration NsmApplicationMode_e { + NsmApplicationMode_NotSet + NsmApplicationMode_Parking + NsmApplicationMode_Factory + NsmApplicationMode_Transport + NsmApplicationMode_Normal + NsmApplicationMode_Swl + NsmApplicationMode_Last + } + + <** + @description : + The constant string array defines the names of the sessions which are mandatory within the Platform. The strings defined here are used as first parameter for filtered registration to the signal ‘SessionStateChanged’. + + A separate method is provided for adding new sessions dynamically to the list of sessions monitored and distributed by the NSM + **> + enumeration NsmCoreSessionName_e { + + <** + @description : This session will be used by the Diagnosis SW to indicate the status of authenticated Diagnosis sessions. + **> + DiagnosisSession + + <** + @description : This is used by certain OEM's and will also need to be a wake-up reason as it defines we start to a point where we can control the HEVAC + **> + HEVACSession + + <** + @description : + This is an open session state that can be used differently for different products. + + Traditionally it is expected that this session state will be set by the HMI when they are completely running and all graphics have been rendered on the appropriate layer. + + This could for instance be used to determine when to enable the display or to switch from a Splashscreen to the real HMI to ensure that the user does not see the HMI before it is completely ready. + **> + HmiActiveSession + + <** + @description : This session will be true/active when there is Network Activity and the Head Unit is in a user perceived on state and therefore is directly reliant on the Network. + **> + NetworkActiveSession + + <** + @description : This session will be true/active when there is Network Activity but the Head Unit is in a user perceived off state and therefore is not directly using the Network + **> + NetworkPassiveSession + + <** + @description : This is a product decision but it is likely that the PDC active will overrule a Poor and non critical failure. + **> + PDCSession + + <** + @description : Permanent/Entertainment mode is normally active when the user has started the target via the Power On button and clamp state is not active. This mode would normally allow the target to run for a configurable period of time before an automatic shutdown will occur. + **> + PermanentModeSession + + <** + @description : Indicates that a phone call is in progress and would normally delay the NSM from delaying the system shutdown + **> + PhoneSession + + <** + @description : This is a product decision but it is likely that the RVC active will overrule a Poor and non critical failure + **> + RVCSession + + <** + @description : When SWL is in progress we would need to handle reboot requests and recovery requests differently + **> + SWLSession + + <** + @description : This session will be used by the Node Resource Manager to indicate that we are in a low memory state. Responsible applications can register for this event and reduce their memory overheads + **> + MemoryLowSession + } + + <** + @description : This enum defines the different data available within the NSM and will be used by the NSMc when requesting to read data + **> + enumeration NsmDataType_e { + NsmDataType_AppMode + NsmDataType_NodeState + NsmDataType_RestartReason + NsmDataType_SessionState + NsmDataType_ShutdownReason + NsmDataType_BootMode + NsmDataType_RunningReason + NsmDataType_RegisterSession + NsmDataType_UnRegisterSession + } + + <** + @description : + The enumeration defines the different error level used as return values + + The values shown in this list are those that are mandatory for the Platform but it will be possible for the product to extend the list as needed by rebuilding the Node State Manager + **> + enumeration NsmErrorStatus_e { + NsmErrorStatus_NotSet + NsmErrorStatus_Ok + NsmErrorStatus_Error + NsmErrorStatus_Dbus + NsmErrorStatus_Internal + NsmErrorStatus_Parameter + NsmErrorStatus_WrongSession + NsmErrorStatus_ResponsePending + NsmErrorStatus_WrongClient + NsmErrorStatus_Last + } + + <** + @description : + This enumeration defines the different node states. There is only one node state active at the same time. The NodeState system itself and other system components need to know the NodeState to decide whether certain actions can be performed in the current state. + + The values shown in this list are those that are mandatory for the Platform but it will be possible for the product to extend the list as needed by rebuilding the Node State Manager + **> + enumeration NsmNodeState_e { + NsmNodeState_NotSet + NsmNodeState_StartUp + NsmNodeState_BaseRunning + NsmNodeState_LucRunning + NsmNodeState_FullyRunning + NsmNodeState_FullyOperational + NsmNodeState_ShuttingDown + NsmNodeState_ShutdownDelay + NsmNodeState_FastShutdown + NsmNodeState_DegradedPower + NsmNodeState_Shutdown + NsmNodeState_Resume + NsmNodeState_Last + } + + <** + @description : + The enumeration defines the different restart reasons. + + The restart reason will only be updated by the Node State Manager during the system startup phase. The NSM will use the value that it stored persistently in the previous lifecycle when its interface RequestNodeRestart was called. + + The values shown in this list are those that are mandatory for the Platform but it will be possible for the product to extend the list as needed by rebuilding the Node State Manager + **> + enumeration NsmRestartReason_e { + NsmRestartReason_NotSet + NsmRestartReason_ApplicationFailure + NsmRestartReason_Diagnosis + NsmRestartReason_Swl + NsmRestartReason_User + NsmRestartReason_RemoteSwl + NsmRestartReason_FactoryTest + NsmRestartReason_Application + NsmRestartReason_OverTemperature + NsmRestartReason_Last + } + + enumeration NsmRunningReason_e { + NsmRunningReason_NotSet + NsmRunningReason_WakeupCan + NsmRunningReason_WakeupMediaEject + NsmRunningReason_WakeupMediaInsertion + NsmRunningReason_WakeupHevac + NsmRunningReason_WakeupPhone + NsmRunningReason_WakeupPowerOnButton + NsmRunningReason_StartupFstp + NsmRunningReason_StartupSwitchToPower + NsmRunningReason_RestartSwRequest + NsmRunningReason_RestartInternalHealth + NsmRunningReason_RestartExternalHealth + NsmRunningReason_RestartUnexpected + NsmRunningReason_RestartUser + NsmRunningReason_Unknown + NsmRunningReason_WakeupEthernet + NsmRunningReason_Bootloader + NsmRunningReason_RemoteUpdate + NsmRunningReason_SystemReset + NsmRunningReason_SystemHardReset + NsmRunningReason_WatchdogReset + NsmRunningReason_RseEject + NsmRunningReason_RseButtonLeft + NsmRunningReason_RseButtonRight + NsmRunningReason_PlatformEnd + } + + <** + @description : This can be used to identify, where needed, the car seat that is applicable for the data item being referenced + **> + enumeration NsmSeat_e { + NsmSeat_NotSet + NsmSeat_Driver + NsmSeat_CoDriver + NsmSeat_Rear1 + NsmSeat_Rear2 + NsmSeat_Rear3 + NsmSeat_Last + } + + <** + @description : The enumeration defines the currently foreseen session states + **> + enumeration NsmSessionState_e { + NsmSessionState_Unregistered + NsmSessionState_Inactive + NsmSessionState_Active + } + + <** + @description : + The enumeration defines the different shutdown reasons. + + The Node State Manager will update shutdown reason based on Lifecycle events in the system and will store it persistently for anyone interested in the value in the next lifecycle + + The values shown in this list are those that are mandatory for the Platform but it will be possible for the product to extend the list as needed by rebuilding the Node State Manager + **> + enumeration NsmShutdownReason_e { + NsmShutdownReason_NotSet + NsmShutdownReason_Normal + NsmShutdownReason_SupplyBad + NsmShutdownReason_SupplyPoor + NsmShutdownReason_ThermalBad + NsmShutdownReason_ThermalPoor + NsmShutdownReason_SwlNotActive + NsmShutdownReason_Last + } + + enumeration NsmShutdownType_e { + NsmShutdownTypeNot = 0 + NsmShutdownTypeNormal = 1 + NsmShutdownTypeFast = 2 + NsmShutdownTypeParallel = 4 + NsmShutdownTypeRunup = 8 + } + +} diff --git a/NodeStateAccess/interfaces/cmake/core_stub_config.cmake.in b/NodeStateAccess/interfaces/cmake/core_stub_config.cmake.in new file mode 100644 index 0000000..4b9c3a6 --- /dev/null +++ b/NodeStateAccess/interfaces/cmake/core_stub_config.cmake.in @@ -0,0 +1,27 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Sven_Hassler@mentor.com +# +# CMake file of NSM Interfaces +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +# Automatically find dependency packages when using this package: +include(CMakeFindDependencyMacro) + +foreach(DEPENDENCY @CORE_STUB_LINK_LIBRARIES@) + find_dependency(${DEPENDENCY} REQUIRED) +endforeach() + +# Include the target file: +get_filename_component(GLUE_LIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +if(NOT TARGET @CORE_STUB_NAME@) + include("${GLUE_LIB_CMAKE_DIR}/@CORE_STUB_NAME@Targets.cmake") +endif() diff --git a/NodeStateAccess/interfaces/cmake/someip_proxy_config.cmake.in b/NodeStateAccess/interfaces/cmake/someip_proxy_config.cmake.in new file mode 100644 index 0000000..3dca3d8 --- /dev/null +++ b/NodeStateAccess/interfaces/cmake/someip_proxy_config.cmake.in @@ -0,0 +1,27 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Sven_Hassler@mentor.com +# +# CMake file of NSM Interfaces +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +# Automatically find dependency packages when using this package: +include(CMakeFindDependencyMacro) + +foreach(DEPENDENCY @SOMEIP_PROXY_LINK_LIBRARIES@) + find_dependency(${DEPENDENCY} REQUIRED) +endforeach() + +# Include the target file: +get_filename_component(GLUE_LIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +if(NOT TARGET @SOMEIP_PROXY_NAME@) + include("${GLUE_LIB_CMAKE_DIR}/@SOMEIP_PROXY_NAME@Targets.cmake") +endif() diff --git a/NodeStateAccess/interfaces/cmake/someip_stub_config.cmake.in b/NodeStateAccess/interfaces/cmake/someip_stub_config.cmake.in new file mode 100644 index 0000000..f53dae2 --- /dev/null +++ b/NodeStateAccess/interfaces/cmake/someip_stub_config.cmake.in @@ -0,0 +1,27 @@ +####################################################################################################################### +# +# Copyright (C) 2020 Mentor Graphics (Deutschland) GmbH +# +# Author: Sven_Hassler@mentor.com +# +# CMake file of NSM Interfaces +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +####################################################################################################################### + +# Automatically find dependency packages when using this package: +include(CMakeFindDependencyMacro) + +foreach(DEPENDENCY @SOMEIP_STUB_LINK_LIBRARIES@) + find_dependency(${DEPENDENCY} REQUIRED) +endforeach() + +# Include the target file: +get_filename_component(GLUE_LIB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +if(NOT TARGET @SOMEIP_STUB_NAME@) + include("${GLUE_LIB_CMAKE_DIR}/@SOMEIP_STUB_NAME@Targets.cmake") +endif() diff --git a/NodeStateAccess/model/org.genivi.NodeStateManager.Consumer.xml b/NodeStateAccess/model/org.genivi.NodeStateManager.Consumer.xml deleted file mode 100644 index dea85d0..0000000 --- a/NodeStateAccess/model/org.genivi.NodeStateManager.Consumer.xml +++ /dev/null @@ -1,249 +0,0 @@ -<!--
-*
-* Copyright (C) 2012 Continental Automotive Systems, Inc.
-*
-* Author: Jean-Pierre.Bogler@continental-corporation.com
-*
-* Describes the "Consumer" interface of the NodeStateManager
-*
-* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/.
-*
-* Date Author Reason
-* 24.10.2012 Jean-Pierre Bogler Initial creation
-*
--->
-
-<node>
- <!--
- org.genivi.NodeStateManager.Consumer:
- @short_description: "Consumer" interface of the NodeStateManager.
-
- This interface contains functions which are not safety critical and can be accessed by "every" client without further restrictions.
- -->
- <interface name="org.genivi.NodeStateManager.Consumer">
- <!--
- RestartReason: This property informs clients about the reason for the last restart. The values are based upon the enummeration NsmRestartReason_e. Note: The value is only set once at start-up.
- -->
- <property name="RestartReason" type="i" access="read"/>
-
- <!--
- ShutdownReason: This property informs clients about the reason for the last shutdown. The values are based upon the enummeration NsmShutdownReason_e. Note: The value is only set once at start-up.
- -->
- <property name="ShutdownReason" type="i" access="read"/>
-
- <!--
- WakeUpReason: This property informs clients about the recent reason for waking up the target. The values are based upon the enummeration NsmWakeUpReason_e. Note: The value is only set once at start-up.
- -->
- <property name="WakeUpReason" type="i" access="read"/>
-
- <!--
- BootMode: This property informs clients about the recent BootMode of the target. The values will be defined by a third party header, which has not been delivered yet. The description needs to be updated as soon as the header is available.
- -->
- <property name="BootMode" type="i" access="read"/>
-
- <!--
- NodeState:
- @NodeState: Numeric value for the current NodeState, defined in NsmNodeState_e.
-
- Clients can register for notifications when the NodeState is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeState as a parameter.
- -->
- <signal name="NodeState">
- <arg name="NodeState" type="i"/>
- </signal>
-
- <!--
- NodeApplicationMode:
- @ApplicationModeId: Numeric value for the current ApplicationMode, defined in NsmAplicationMode_e.
-
- Clients can register for notifications when the NodeApplicationMode is updated inside the NodeStateManager. This signal is sent to registered clients and will include the current NodeApplicationMode as a parameter.
- -->
- <signal name="NodeApplicationMode">
- <arg name="ApplicationModeId" type="i"/>
- </signal>
-
- <!--
- SessionStateChanged:
- @SessionStateName: The SessionName will be based upon either the pre-defined platform SessionNames or using a newly added product defined session name.
- @SeatID: This parameter will be based upon the enum NsmSeat_e.
- @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
-
- This signal is sent to registered clients when a particular session is state is changed. The client can register for notification about a specific session through the use of the SessionName, as a "match rule".
- -->
- <signal name="SessionStateChanged">
- <arg name="SessionStateName" type="s"/>
- <arg name="SeatID" type="i"/>
- <arg name="SessionState" type="i"/>
- </signal>
-
- <!--
- GetNodeState:
- @NodeStateId: Will be based on the NsmNodeState_e.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to get the NodeState without the need of registration to the signal.
- -->
- <method name="GetNodeState">
- <arg name="NodeStateId" direction="out" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- SetSessionState:
- @SessionName: The SessionName will be based upon either the pre-defined platform SessionNames (see NSM content page) or using a newly added product defined session name.
- @SessionOwner: This parameter defines the name of the application that is setting the state of the session. This must be the applications systemd unit filename.
- @SeatID: This parameter will be based upon the enum NsmSeat_e
- @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by applications to set the state of a session.
- -->
- <method name="SetSessionState">
- <arg name="SessionName" direction="in" type="s"/>
- <arg name="SessionOwner" direction="in" type="s"/>
- <arg name="SeatID" direction="in" type="i"/>
- <arg name="SessionState" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- GetSessionState:
- @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
- @SeatID: This parameter will be based upon the enum NsmSeat_e.
- @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional SessionStates.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by applications to get the state of a session.
- -->
- <method name="GetSessionState">
- <arg name="SessionName" direction="in" type="s"/>
- <arg name="SeatID" direction="in" type="i"/>
- <arg name="SessionState" direction="out" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- GetApplicationMode:
- @ApplicationModeId: This parameter will be based upon the NsmNodeApplicationMode_e.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to get the application mode.
- -->
- <method name="GetApplicationMode">
- <arg name="ApplicationModeId" direction="out" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- RegisterShutdownClient:
- @BusName: Bus name of remote application.
- @ObjName: Object name of remote object that provides the shutdown interface.
- @ShutdownMode: Shutdown mode for which client wants to be informed (i.e normal, fast etc).
- @TimeoutMs: Max. Timeout to wait for response from shutdown client in ms.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to register themselves as shutdown client. Any client that registers must provide a method in their D-Bus object called "LifecycleRequest". This method will take one parameter which is the RequestType (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST). For an example of the required client interface please see the BootManager component who will be a client of the NSM.
- -->
- <method name="RegisterShutdownClient">
- <arg name="BusName" direction="in" type="s"/>
- <arg name="ObjName" direction="in" type="s"/>
- <arg name="ShutdownMode" direction="in" type="u"/>
- <arg name="TimeoutMs" direction="in" type="u"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- UnRegisterShutdownClient:
- @BusName: Bus name of remote application.
- @ObjName: Object name of remote object that provides the shutdown interface.
- @ShutdownMode: Shutdown mode for which client wants to unregister (NSM_SHUTDOWNTYPE_NORMAL, NSM_SHUTDOWNTYPE_FAST).
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to unregister themselves as shutdown client.
- -->
- <method name="UnRegisterShutdownClient">
- <arg name="BusName" direction="in" type="s"/>
- <arg name="ObjName" direction="in" type="s"/>
- <arg name="ShutdownMode" direction="in" type="u"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- RegisterSession:
- @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
- @SessionOwner: This is the name of the application that is registering the new session (this must be the applications systemd unit filename).
- @SeatID: This parameter will be based upon the enum NsmSeatId_e
- @SessionState: This parameter will be based upon the NsmSessionState_e but it will not be bounded by the values in that enumeration. The listed values are the default values that are mandatory for platform sessions, but product sessions may have additional session states.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to register a new session whose state should be observed and distributed by the NSM.
- -->
- <method name="RegisterSession">
- <arg name="SessionName" direction="in" type="s"/>
- <arg name="SessionOwner" direction="in" type="s"/>
- <arg name="SeatID" direction="in" type="i"/>
- <arg name="SessionState" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- UnRegisterSession:
- @SessionName: The SessionName will be based upon either the pre-defined platform session names (see NSM content page) or using a newly added product defined SessionName.
- @SessionOwner: This is the name of the application that originally registered the session. It will be validated that this value matches the stored value from the registration.
- @SeatID: This parameter will be based upon the enum NsmSeat_e.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to remove a new session from the session list hosted by NSM.
- -->
- <method name="UnRegisterSession">
- <arg name="SessionName" direction="in" type="s"/>
- <arg name="SessionOwner" direction="in" type="s"/>
- <arg name="SeatID" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- GetAppHealthCount:
- @Count: Return value passed to the caller. Number of applications that crashed or terminated accidentally.
-
- The method returns the number of applications that crashed or terminated accidentally, within the current life cycle. It can be used to observe the system state.
- -->
- <method name="GetAppHealthCount">
- <arg name="Count" direction="out" type="u"/>
- </method>
-
- <!--
- GetInterfaceVersion:
- @Version: Unsigned integer that represents the version number of the Node State Manager.
-
- The method returns the version number of the Node State Manager. The number is organized in four bytes:
-
- Version: VVV.RRR.PPP.BBB
-
- <literallayout>
- VVV => Version [1..255]
- RRR => Release [0..255]
- PPP => Patch [0..255]
- BBB => Build [0..255]
- </literallayout>
- -->
- <method name="GetInterfaceVersion">
- <arg name="Version" direction="out" type="u"/>
- </method>
-
- <!--
- LifecycleRequestComplete:
- @RequestId: The request Id of the called life cycle client. The value has been passed when "LifecycleRequest" was called.
- @Status: The result of the call to "LifecycleRequest". NsmErrorStatus_Ok: Request successfully processed. NsmErrorStatus_Error: An error occured while processing the "LifecycleRequest".
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The function has to be called by a "asynchrounous" lifecycle client, when he processed the "LifecycleRequest".
- -->
- <method name="LifecycleRequestComplete">
- <arg name="RequestId" direction="in" type="u"/>
- <arg name="Status" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
- </interface>
-</node>
diff --git a/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleConsumer.xml b/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleConsumer.xml deleted file mode 100644 index 4bc566f..0000000 --- a/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleConsumer.xml +++ /dev/null @@ -1,41 +0,0 @@ -<!-- -* -* Copyright (C) 2012 Continental Automotive Systems, Inc. -* -* Author: Jean-Pierre.Bogler@continental-corporation.com -* -* Describes the "LifecycleConsumer" interface, applications can -* implement to become a life cycle client of the NodeStateManager. -* -* This Source Code Form is subject to the terms of the Mozilla Public -* License, v. 2.0. If a copy of the MPL was not distributed with this -* file, You can obtain one at http://mozilla.org/MPL/2.0/. -* -* Date Author Reason -* 24.10.2012 Jean-Pierre Bogler Initial creation -* ---> - -<node> - <!-- - org.genivi.NodeStateManager.LifeCycleConsumer: - @short_description: Interface of a life cycle client. - - This interface contains functions, which need to be implemented by life cycle clients, to be able to receive life cycle requests. - --> - <interface name="org.genivi.NodeStateManager.LifeCycleConsumer"> - <!-- - LifecycleRequest: - @Request: The type of the life cycle request. Can be NSM_SHUTDOWNTYPE_RUNUP, NSM_SHUTDOWNTYPE_NORMAL or NSM_SHUTDOWNTYPE_FAST. - @RequestId: The Id of the client (current request). This Id needs to be passed to the NSM again via the interface "LifecycleRequestComplete", when the client has processed the "LifecycleRequest". - @ErrorCode: Client's return value, passed to the NodeStateManager. Based upon NsmErrorStatus_e. NsmErrorStatus_Ok: Request was successfully processed. NsmErrorStatus_ResponsePending: Processing of request started. LifecycleRequestComplete will be called to pass the status after completion. NsmErrorStatus_Error: An error occured, the request could not be processed. - - The method has to be implemented by every life cycle client and is called by the NodeStateManager, when the node is shutting down (fast or normal) or an ongoing shutdown is cancelled (run up). - --> - <method name="LifecycleRequest"> - <arg name="Request" direction="in" type="u"/> - <arg name="RequestId" direction="in" type="u"/> - <arg name="ErrorCode" direction="out" type="i"/> - </method> - </interface> -</node> diff --git a/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleControl.xml b/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleControl.xml deleted file mode 100644 index 9e1ddd0..0000000 --- a/NodeStateAccess/model/org.genivi.NodeStateManager.LifecycleControl.xml +++ /dev/null @@ -1,101 +0,0 @@ -<!--
-*
-* Copyright (C) 2012 Continental Automotive Systems, Inc.
-*
-* Author: Jean-Pierre.Bogler@continental-corporation.com
-*
-* Describes the "LifecycleControl" interface of the NodeStateManager.
-*
-* This Source Code Form is subject to the terms of the Mozilla Public
-* License, v. 2.0. If a copy of the MPL was not distributed with this
-* file, You can obtain one at http://mozilla.org/MPL/2.0/.
-*
-* Date Author Reason
-* 24.10.2012 Jean-Pierre Bogler Initial creation
-*
--->
-
-<node>
- <!--
- org.genivi.NodeStateManager.LifecycleControl:
- @short_description: "Control" interface of the NodeStateManager.
-
- This interface contains functions, which have direct influence on the system state and therefore have to be handled with care. The interface can only be used by certain clients, which need to be configured in the D-Bus configuration.
- -->
- <interface name="org.genivi.NodeStateManager.LifecycleControl">
- <!--
- RequestNodeRestart:
- @RestartReason: The passed value will be based upon the enum NsmRestartReason_e.
- @RestartType: This is the type of restart that is required, i.e. during Coding process it is normal for a fast shutdown to be requested whereas other Diagnosis restart requests would be normal. Possible values are NSM_SHUTDOWNTYPE_FAST and NSM_SHUTDOWNTYPE_NORMAL.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to request a restart of the node.
- -->
- <method name="RequestNodeRestart">
- <arg name="RestartReason" direction="in" type="i"/>
- <arg name="RestartType" direction="in" type="u"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- SetApplicationMode:
- @ApplicationModeId: This parameter will be based upon the NsmNodeApplicationMode_e.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to set the application mode.
- -->
- <method name="SetApplicationMode">
- <arg name="ApplicationModeId" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- SetNodeState:
- @NodeStateId: The passed value will be based upon the enum NsmNodeState_e.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method is used by other applications to set the NodeState. When this method is called to change the current NodeState a signal will be sent to notify registered consumers of the new state.
- -->
- <method name="SetNodeState">
- <arg name="NodeStateId" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- SetBootMode:
- @BootMode: New BootMode to be set. The values will be defined by a third party header, which has not been delivered yet. The description needs to be updated as soon as the header is available.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- The method has been introduced, because the property "BootMode" can only be read by other applications. Nevertheless there are some exceptions where the property should be set by a restricted set of applications which will be handled within this method.
- -->
- <method name="SetBootMode">
- <arg name="BootMode" direction="in" type="i"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- SetAppHealthStatus:
- @AppName: This parameter can be used to give the name of the application that has failed (this must be the applications systemd unit name).
- @AppRunning: The AppState will be FALSE for failed and TRUE for running.
- @ErrorCode: Return value passed to the caller, based upon NsmErrorStatus_e.
-
- This method will be used by the Node Health Monitor to report to the NSM if an application has failed and if it is running again. Internally the NSM will use this information to keep a count of the number of failed applications within the current lifecycle. Additionally it will unset any sessions that the failing application may have had active. It will also be possible for the product node state machine to make a decision on what to do with this information, i.e. even reset the node or reset the node if too many applications have failed.
- -->
- <method name="SetAppHealthStatus">
- <arg name="AppName" direction="in" type="s"/>
- <arg name="AppRunning" direction="in" type="b"/>
- <arg name="ErrorCode" direction="out" type="i"/>
- </method>
-
- <!--
- CheckLucRequired:
- @LucWanted: This will be a simple TRUE or FALSE to define whether the LUC is wanted in the current Lifecycle.
-
- This method will be called exclusivley by the Boot Manager to find out whether the LUC Applications should be started in the current Lifecycle. This is required whilst in certain Node Application Modes (i.e. Transport, Factory) we do not want the LUC Applications started.
- -->
- <method name="CheckLucRequired">
- <arg name="LucWanted" direction="out" type="b"/>
- </method>
-
- </interface>
-</node>
|