From 8991954e3c2e6927118d3d749ea72cc3953ef3d1 Mon Sep 17 00:00:00 2001 From: Michael Zillgith Date: Thu, 23 Jan 2020 17:52:51 +0100 Subject: [PATCH] - removed header dependencies from API headers --- src/iec61850/inc_private/control.h | 1 + src/iec61850/server/impl/ied_server.c | 1 + src/mms/inc/mms_server.h | 145 --------------- src/mms/inc_private/mms_server_internal.h | 2 +- src/mms/inc_private/mms_server_libinternal.h | 177 +++++++++++++++++++ 5 files changed, 180 insertions(+), 146 deletions(-) create mode 100644 src/mms/inc_private/mms_server_libinternal.h diff --git a/src/iec61850/inc_private/control.h b/src/iec61850/inc_private/control.h index de643624..c8192a69 100644 --- a/src/iec61850/inc_private/control.h +++ b/src/iec61850/inc_private/control.h @@ -27,6 +27,7 @@ #include "iec61850_model.h" #include "iec61850_server.h" #include "mms_server_connection.h" +#include "mms_server_libinternal.h" #include "mms_device_model.h" #include "mms_mapping_internal.h" diff --git a/src/iec61850/server/impl/ied_server.c b/src/iec61850/server/impl/ied_server.c index 9d4bbd1f..4bbe92df 100644 --- a/src/iec61850/server/impl/ied_server.c +++ b/src/iec61850/server/impl/ied_server.c @@ -25,6 +25,7 @@ #include "mms_mapping.h" #include "mms_mapping_internal.h" #include "mms_value_internal.h" +#include "mms_server_libinternal.h" #include "control.h" #include "stack_config.h" #include "ied_server_private.h" diff --git a/src/mms/inc/mms_server.h b/src/mms/inc/mms_server.h index 6e9ee633..7e6118d0 100644 --- a/src/mms/inc/mms_server.h +++ b/src/mms/inc/mms_server.h @@ -32,7 +32,6 @@ extern "C" { #endif -#include "mms_device_model.h" #include "mms_value.h" #include "iso_connection_parameters.h" @@ -52,61 +51,12 @@ typedef enum { MMS_VMD_SPECIFIC } MmsVariableListType; -typedef MmsValue* (*MmsReadVariableHandler)(void* parameter, MmsDomain* domain, - char* variableId, MmsServerConnection connection); - -typedef MmsDataAccessError (*MmsReadAccessHandler) (void* parameter, MmsDomain* domain, - char* variableId, MmsServerConnection connection); - -typedef MmsDataAccessError (*MmsWriteVariableHandler)(void* parameter, - MmsDomain* domain, char* variableId, MmsValue* value, - MmsServerConnection connection); - -typedef void (*MmsConnectionHandler)(void* parameter, - MmsServerConnection connection, MmsServerEvent event); - -LIB61850_INTERNAL MmsServer -MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration); - -LIB61850_INTERNAL void -MmsServer_destroy(MmsServer self); - -LIB61850_INTERNAL void -MmsServer_installReadHandler(MmsServer self, MmsReadVariableHandler, - void* parameter); - -LIB61850_INTERNAL void -MmsServer_installReadAccessHandler(MmsServer self, MmsReadAccessHandler, void* parameter); - -LIB61850_INTERNAL void -MmsServer_installWriteHandler(MmsServer self, MmsWriteVariableHandler, - void* parameter); - LIB61850_INTERNAL void MmsServer_setLocalIpAddress(MmsServer self, const char* localIpAddress); LIB61850_INTERNAL bool MmsServer_isRunning(MmsServer self); -/** - * A connection handler will be invoked whenever a new client connection is opened or closed - */ -LIB61850_INTERNAL void -MmsServer_installConnectionHandler(MmsServer self, MmsConnectionHandler, - void* parameter); - -LIB61850_INTERNAL void -MmsServer_setClientAuthenticator(MmsServer self, AcseAuthenticator authenticator, void* authenticatorParameter); - -LIB61850_INTERNAL MmsDevice* -MmsServer_getDevice(MmsServer self); - -LIB61850_INTERNAL MmsValue* -MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, const char* itemId); - -LIB61850_INTERNAL bool -MmsServer_isLocked(MmsServer self); - /** * \brief callback handler that is called whenever a named variable list changes * @@ -295,103 +245,8 @@ MmsServer_setMaxDataSetEntries(MmsServer self, int maxDataSetEntries); LIB61850_INTERNAL void MmsServer_enableJournalService(MmsServer self, bool enable); -/** - * \brief lock the cached server data model - * - * NOTE: This method should never be called inside of a library callback function. In the context of - * a library callback the data model is always already locked! Calling this function inside of a - * library callback may lead to a deadlock condition. - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_lockModel(MmsServer self); -/** - * \brief unlock the cached server data model - * - * NOTE: This method should never be called inside of a library callback function. In the context of - * a library callback the data model is always already locked! - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_unlockModel(MmsServer self); - -LIB61850_INTERNAL void -MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId, - MmsValue* value); - -/*************************************************** - * Functions for multi-threaded operation mode - ***************************************************/ -/** - * \brief Start a new server thread and listen for incoming connections - * - * \param self the MmsServer instance to operate on - * \param tcpPort the TCP port the server is listening on. - */ -LIB61850_INTERNAL void -MmsServer_startListening(MmsServer self, int tcpPort); - -/** - * \brief Stop server thread an all open connection threads - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_stopListening(MmsServer self); - -/*************************************************** - * Functions for threadless operation mode - ***************************************************/ - -/** - * \brief Start a new server in non-threaded operation mode - * - * \param self the MmsServer instance to operate on - * \param tcpPort the TCP port the server is listening on. - */ -LIB61850_INTERNAL void -MmsServer_startListeningThreadless(MmsServer self, int tcpPort); - -/** - * \brief Wait for the server to come ready in non-threaded operation mode - * - * \param self the MmsServer instance to operate on - * \param timeoutMs maximum number of milliseconds to wait - * \return 1 if the server is ready, 0 if not or -1 on error - */ -LIB61850_INTERNAL int -MmsServer_waitReady(MmsServer self, unsigned int timeoutMs); - -/** - * \brief Handle client connections (for non-threaded operation mode) - * - * This function is listening for new client connections and handles incoming - * requests for existing client connections. - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_handleIncomingMessages(MmsServer self); - -/** - * \brief Handle MmsServer background task - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_handleBackgroundTasks(MmsServer self); - -/** - * \brief Stop the server (for non-threaded operation mode) - * - * \param self the MmsServer instance to operate on - */ -LIB61850_INTERNAL void -MmsServer_stopListeningThreadless(MmsServer self); /*************************************************** diff --git a/src/mms/inc_private/mms_server_internal.h b/src/mms/inc_private/mms_server_internal.h index 085614f3..23430d4d 100644 --- a/src/mms/inc_private/mms_server_internal.h +++ b/src/mms/inc_private/mms_server_internal.h @@ -32,7 +32,7 @@ #include "mms_device_model.h" #include "mms_common_internal.h" #include "stack_config.h" -#include "mms_server.h" +#include "mms_server_libinternal.h" #include "byte_buffer.h" diff --git a/src/mms/inc_private/mms_server_libinternal.h b/src/mms/inc_private/mms_server_libinternal.h new file mode 100644 index 00000000..6c03b9af --- /dev/null +++ b/src/mms/inc_private/mms_server_libinternal.h @@ -0,0 +1,177 @@ +/* + * mms_server_libinternal.h + * + * Copyright 2013-2020 Michael Zillgith + * + * This file is part of libIEC61850. + * + * libIEC61850 is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * libIEC61850 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with libIEC61850. If not, see . + * + * See COPYING file for the complete license text. + */ + +#ifndef MMS_SERVER_LIBINTERNAL_H_ +#define MMS_SERVER_LIBINTERNAL_H_ + +#include "mms_server.h" +#include "mms_device_model.h" + +typedef MmsValue* (*MmsReadVariableHandler)(void* parameter, MmsDomain* domain, + char* variableId, MmsServerConnection connection); + +typedef MmsDataAccessError (*MmsReadAccessHandler) (void* parameter, MmsDomain* domain, + char* variableId, MmsServerConnection connection); + +typedef MmsDataAccessError (*MmsWriteVariableHandler)(void* parameter, + MmsDomain* domain, char* variableId, MmsValue* value, + MmsServerConnection connection); + +typedef void (*MmsConnectionHandler)(void* parameter, + MmsServerConnection connection, MmsServerEvent event); + +LIB61850_INTERNAL MmsServer +MmsServer_create(MmsDevice* device, TLSConfiguration tlsConfiguration); + +LIB61850_INTERNAL void +MmsServer_destroy(MmsServer self); + +LIB61850_INTERNAL void +MmsServer_installReadHandler(MmsServer self, MmsReadVariableHandler, + void* parameter); + +LIB61850_INTERNAL void +MmsServer_installReadAccessHandler(MmsServer self, MmsReadAccessHandler, void* parameter); + +LIB61850_INTERNAL void +MmsServer_installWriteHandler(MmsServer self, MmsWriteVariableHandler, + void* parameter); + +/** + * A connection handler will be invoked whenever a new client connection is opened or closed + */ +LIB61850_INTERNAL void +MmsServer_installConnectionHandler(MmsServer self, MmsConnectionHandler, + void* parameter); + +LIB61850_INTERNAL void +MmsServer_setClientAuthenticator(MmsServer self, AcseAuthenticator authenticator, void* authenticatorParameter); + +LIB61850_INTERNAL MmsDevice* +MmsServer_getDevice(MmsServer self); + +LIB61850_INTERNAL MmsValue* +MmsServer_getValueFromCache(MmsServer self, MmsDomain* domain, const char* itemId); + +LIB61850_INTERNAL bool +MmsServer_isLocked(MmsServer self); + +/** + * \brief lock the cached server data model + * + * NOTE: This method should never be called inside of a library callback function. In the context of + * a library callback the data model is always already locked! Calling this function inside of a + * library callback may lead to a deadlock condition. + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_lockModel(MmsServer self); + +/** + * \brief unlock the cached server data model + * + * NOTE: This method should never be called inside of a library callback function. In the context of + * a library callback the data model is always already locked! + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_unlockModel(MmsServer self); + +LIB61850_INTERNAL void +MmsServer_insertIntoCache(MmsServer self, MmsDomain* domain, char* itemId, + MmsValue* value); + +/*************************************************** + * Functions for multi-threaded operation mode + ***************************************************/ + +/** + * \brief Start a new server thread and listen for incoming connections + * + * \param self the MmsServer instance to operate on + * \param tcpPort the TCP port the server is listening on. + */ +LIB61850_INTERNAL void +MmsServer_startListening(MmsServer self, int tcpPort); + +/** + * \brief Stop server thread an all open connection threads + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_stopListening(MmsServer self); + +/*************************************************** + * Functions for threadless operation mode + ***************************************************/ + +/** + * \brief Start a new server in non-threaded operation mode + * + * \param self the MmsServer instance to operate on + * \param tcpPort the TCP port the server is listening on. + */ +LIB61850_INTERNAL void +MmsServer_startListeningThreadless(MmsServer self, int tcpPort); + +/** + * \brief Wait for the server to come ready in non-threaded operation mode + * + * \param self the MmsServer instance to operate on + * \param timeoutMs maximum number of milliseconds to wait + * \return 1 if the server is ready, 0 if not or -1 on error + */ +LIB61850_INTERNAL int +MmsServer_waitReady(MmsServer self, unsigned int timeoutMs); + +/** + * \brief Handle client connections (for non-threaded operation mode) + * + * This function is listening for new client connections and handles incoming + * requests for existing client connections. + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_handleIncomingMessages(MmsServer self); + +/** + * \brief Handle MmsServer background task + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_handleBackgroundTasks(MmsServer self); + +/** + * \brief Stop the server (for non-threaded operation mode) + * + * \param self the MmsServer instance to operate on + */ +LIB61850_INTERNAL void +MmsServer_stopListeningThreadless(MmsServer self); + +#endif /* MMS_SERVER_LIBINTERNAL_H_ */