diff --git a/source/authentication/udaServerSSL.cpp b/source/authentication/udaServerSSL.cpp index 89a9f8f3..45e146d8 100644 --- a/source/authentication/udaServerSSL.cpp +++ b/source/authentication/udaServerSSL.cpp @@ -20,6 +20,7 @@ # define X509STRINGSIZE 256 using namespace uda::client_server; +using namespace uda::server; /* Note on initialisation: @@ -416,7 +417,7 @@ int writeUdaServerSSL(void* iohandle, const char* buf, int count) fd_set wfds; // File Descriptor Set for Writing to the Socket struct timeval tv = {}; - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); // Block till it's possible to write to the socket or timeout @@ -493,7 +494,7 @@ int readUdaServerSSL(void* iohandle, char* buf, int count) // Wait till it's possible to read from the socket // Set the blocking period before a timeout - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); setSelectParms(g_sslSocket, &rfds, &tv, io_data->server_tot_block_time); tvc = tv; diff --git a/source/client/closedown.cpp b/source/client/closedown.cpp index 8585c56f..0432da4c 100644 --- a/source/client/closedown.cpp +++ b/source/client/closedown.cpp @@ -15,6 +15,7 @@ #ifdef FATCLIENT # include "server/closeServerSockets.h" # include "server/udaServer.h" +using namespace uda::server; #else # include "connection.h" # include "getEnvironment.h" diff --git a/source/client/udaClient.cpp b/source/client/udaClient.cpp index 6029f7ed..9169b886 100644 --- a/source/client/udaClient.cpp +++ b/source/client/udaClient.cpp @@ -1122,7 +1122,7 @@ int uda::client::idamClient(REQUEST_BLOCK* request_block, int* indices) DATA_BLOCK_LIST data_block_list0; initDataBlockList(&data_block_list0); - err = fat_server(client_block, &server_block, request_block, &data_block_list0); + err = uda::server::fat_server(client_block, &server_block, request_block, &data_block_list0); for (int i = 0; i < data_block_list0.count; ++i) { DATA_BLOCK* data_block0 = &data_block_list0.data[i]; diff --git a/source/clientserver/makeRequestBlock.cpp b/source/clientserver/makeRequestBlock.cpp index 56cfde50..6c8c7f65 100644 --- a/source/clientserver/makeRequestBlock.cpp +++ b/source/clientserver/makeRequestBlock.cpp @@ -40,8 +40,8 @@ using namespace uda::client_server; static void extract_function_name(const char* str, REQUEST_DATA* request); -static int source_file_format_test(const char* source, REQUEST_DATA* request, const PLUGINLIST* pluginList, - const ENVIRONMENT* environment); +static int source_file_format_test(const char* source, REQUEST_DATA* request, + const uda::plugins::PluginList* pluginList, const ENVIRONMENT* environment); static int extract_archive(REQUEST_DATA* request, int reduceSignal, const ENVIRONMENT* environment); @@ -60,7 +60,7 @@ struct NameValue { std::vector name_value_pairs(std::string_view input, bool strip); } // namespace uda -static int find_plugin_id_by_format(const char* format, const PLUGINLIST* plugin_list) +static int find_plugin_id_by_format(const char* format, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { @@ -70,7 +70,7 @@ static int find_plugin_id_by_format(const char* format, const PLUGINLIST* plugin return -1; } -int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* pluginList, +int uda::client_server::makeRequestData(REQUEST_DATA* request, const uda::plugins::PluginList* pluginList, const ENVIRONMENT* environment) { int ldelim; @@ -336,15 +336,15 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* for (int i = 0; i < pluginList->count; i++) { if (STR_IEQUALS(work2, pluginList->plugin[i].format)) { - if (pluginList->plugin[i].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { + if (pluginList->plugin[i].plugin_class != uda::plugins::UDA_PLUGIN_CLASS_DEVICE) { request->request = pluginList->plugin[i].request; // Found strcpy(request->format, pluginList->plugin[i].format); if (pluginList->plugin[i].plugin_class != - UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client + uda::plugins::UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client strcpy(request->path, test + ldelim); // Complete String following :: delimiter strcpy(request->file, ""); // Clean the filename - if (pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_FUNCTION) { + if (pluginList->plugin[i].plugin_class == uda::plugins::UDA_PLUGIN_CLASS_FUNCTION) { isFunction = true; extract_function_name(work, request); } @@ -357,8 +357,8 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* #endif strcpy(request->file, base); // Final token } - isFile = pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_FILE; - isServer = pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_SERVER; + isFile = pluginList->plugin[i].plugin_class == uda::plugins::UDA_PLUGIN_CLASS_FILE; + isServer = pluginList->plugin[i].plugin_class == uda::plugins::UDA_PLUGIN_CLASS_SERVER; break; } else { @@ -369,7 +369,7 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* static int depth = 0; // int id = findPluginRequestByFormat(pluginList->plugin[i].deviceProtocol, &pluginList); int id = find_plugin_id_by_format(pluginList->plugin[i].deviceProtocol, pluginList); - if (id >= 0 && pluginList->plugin[id].plugin_class == UDA_PLUGIN_CLASS_SERVER) { + if (id >= 0 && pluginList->plugin[id].plugin_class == uda::plugins::UDA_PLUGIN_CLASS_SERVER) { snprintf(work, MAXMETA, "%s%s%s", pluginList->plugin[i].deviceProtocol, request->api_delim, pluginList->plugin[i].deviceHost); @@ -581,8 +581,8 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* if (STR_IEQUALS(request->archive, pluginList->plugin[i].format)) { request->request = pluginList->plugin[i].request; // Found strcpy(request->format, pluginList->plugin[i].format); - isFunction = - (pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_FUNCTION); // Must be a known Library + isFunction = (pluginList->plugin[i].plugin_class == + uda::plugins::UDA_PLUGIN_CLASS_FUNCTION); // Must be a known Library break; } } @@ -620,7 +620,7 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* if (isFunction && strcasecmp(request->archive, environment->api_archive) != 0) { int id = find_plugin_id_by_format(request->archive, pluginList); - if (id >= 0 && pluginList->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION && + if (id >= 0 && pluginList->plugin[id].plugin_class == uda::plugins::UDA_PLUGIN_CLASS_FUNCTION && strcasecmp(pluginList->plugin[id].symbol, "serverside") != 0) { if (request->request == REQUEST_READ_GENERIC || request->request == REQUEST_READ_UNKNOWN) { request->request = pluginList->plugin[id].request; // Found @@ -741,7 +741,7 @@ int uda::client_server::makeRequestData(REQUEST_DATA* request, const PLUGINLIST* return 0; } -int uda::client_server::make_request_block(REQUEST_BLOCK* request_block, const PLUGINLIST* pluginList, +int uda::client_server::make_request_block(REQUEST_BLOCK* request_block, const uda::plugins::PluginList* pluginList, const ENVIRONMENT* environment) { int rc = 0; @@ -788,7 +788,7 @@ void extract_function_name(const char* str, REQUEST_DATA* request) /** * returns true if a format was identified, false otherwise. */ -int source_file_format_test(const char* source, REQUEST_DATA* request, const PLUGINLIST* pluginList, +int source_file_format_test(const char* source, REQUEST_DATA* request, const uda::plugins::PluginList* pluginList, const ENVIRONMENT* environment) { int rc = 0; @@ -1029,8 +1029,8 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, const PLU UDA_LOG(UDA_LOG_DEBUG, "Format identified, selecting specific plugin for %s\n", request->format); request->request = pluginList->plugin[i].request; // Found if (pluginList->plugin[i].plugin_class != - UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client - strcpy(request->file, ""); // Clean the filename + uda::plugins::UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client + strcpy(request->file, ""); // Clean the filename } else { #ifndef __GNUC__ char base[1024] = {0}; diff --git a/source/clientserver/makeRequestBlock.h b/source/clientserver/makeRequestBlock.h index d91aaeb8..12596cd2 100644 --- a/source/clientserver/makeRequestBlock.h +++ b/source/clientserver/makeRequestBlock.h @@ -1,5 +1,6 @@ #pragma once +#include "plugins/udaPlugin.h" #include "udaStructs.h" typedef struct PluginList PLUGINLIST; @@ -7,9 +8,10 @@ typedef struct PluginList PLUGINLIST; namespace uda::client_server { -int make_request_block(REQUEST_BLOCK* request_block, const PLUGINLIST* pluginList, const ENVIRONMENT* environment); +int make_request_block(REQUEST_BLOCK* request_block, const uda::plugins::PluginList* pluginList, + const ENVIRONMENT* environment); -int makeRequestData(REQUEST_DATA* request, const PLUGINLIST* pluginList, const ENVIRONMENT* environment); +int makeRequestData(REQUEST_DATA* request, const uda::plugins::PluginList* pluginList, const ENVIRONMENT* environment); int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigned short strip); diff --git a/source/clientserver/make_request_block.cpp b/source/clientserver/make_request_block.cpp index 417adeb3..4ff8679e 100644 --- a/source/clientserver/make_request_block.cpp +++ b/source/clientserver/make_request_block.cpp @@ -9,6 +9,7 @@ #include using namespace uda::client_server; +using namespace uda::plugins; static const boost::regex SOURCE_RE( R"(^(?(?:[a-z]+::)*)(((?[0-9]+)(\/(?[0-9a-z]+))?)|(?\/[a-z0-9\/\.]+)|((?[a-z]+)\((?.*)\)))$)", diff --git a/source/clientserver/protocol.cpp b/source/clientserver/protocol.cpp index d003aea5..ccb7a306 100644 --- a/source/clientserver/protocol.cpp +++ b/source/clientserver/protocol.cpp @@ -41,6 +41,29 @@ using namespace uda::client_server; +void uda::client_server::setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) +{ + FD_ZERO(rfds); // Initialise the File Descriptor set + FD_SET(fd, rfds); // Identify the Socket in the FD set + tv->tv_sec = 0; + tv->tv_usec = MIN_BLOCK_TIME; // minimum wait microsecs (1ms) + *server_tot_block_time = 0; +} + +void uda::client_server::updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time) +{ + FD_ZERO(rfds); + FD_SET(fd, rfds); + if (server_tot_block_time < MAXBLOCK) { + // (ms) For the First blocking period have rapid response (clientserver/udaDefines.h == 1000) + tv->tv_sec = 0; + tv->tv_usec = MIN_BLOCK_TIME; // minimum wait (1ms) + } else { + tv->tv_sec = 0; + tv->tv_usec = MAX_BLOCK_TIME; // maximum wait (10ms) + } +} + int uda::client_server::protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, IoData* io_data, unsigned int private_flags, diff --git a/source/clientserver/protocol.h b/source/clientserver/protocol.h index 9af19f0b..a6312561 100644 --- a/source/clientserver/protocol.h +++ b/source/clientserver/protocol.h @@ -49,7 +49,8 @@ #define UDA_PROTOCOL_LIMITER 113 #define UDA_PROTOCOL_OPAQUE_STOP 200 -struct IoData; +#define MIN_BLOCK_TIME 1000 +#define MAX_BLOCK_TIME 10000 //--------------------------------------------------------------------------------------------------- // Client Server XDR data Streams (DON'T CHANGE ORDER or Legacy client won't work!) @@ -57,6 +58,13 @@ struct IoData; namespace uda::client_server { +struct IoData { +}; + +void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time); + +void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time); + int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, IoData* io_data, unsigned int private_flags, int malloc_source); diff --git a/source/clientserver/protocolXML.h b/source/clientserver/protocolXML.h index f2c3610a..f1e7a2ec 100644 --- a/source/clientserver/protocolXML.h +++ b/source/clientserver/protocolXML.h @@ -10,16 +10,16 @@ # define protocolXML protocolXMLFat #endif -struct IoData; - -using CreateXDRStreams = std::pair (*)(IoData*); - namespace uda::client_server { +struct IoData; + +using CreateXDRStreams = std::pair (*)(uda::client_server::IoData*); + int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, IoData* io_data, unsigned int private_flags, int malloc_source, CreateXDRStreams create_xdr_streams); -} +} // namespace uda::client_server diff --git a/source/include/uda/types.h b/source/include/uda/types.h index 274691f1..9eabe91b 100644 --- a/source/include/uda/types.h +++ b/source/include/uda/types.h @@ -106,7 +106,7 @@ typedef struct LogStructList LOGSTRUCTLIST; typedef struct CompoundField COMPOUNDFIELD; typedef struct UserDefinedType USERDEFINEDTYPE; typedef struct UserDefinedTypeList USERDEFINEDTYPELIST; -typedef struct UdaPluginInterface UDA_PLUGIN_INTERFACE; +typedef struct CUdaPluginInterface UDA_PLUGIN_INTERFACE; typedef struct CompoundField COMPOUNDFIELD; typedef struct UserDefinedType USERDEFINEDTYPE; diff --git a/source/include/uda/uda_plugin_base.hpp b/source/include/uda/uda_plugin_base.hpp index 269d718a..0c2b9ac3 100644 --- a/source/include/uda/uda_plugin_base.hpp +++ b/source/include/uda/uda_plugin_base.hpp @@ -54,14 +54,14 @@ class UDAPluginBase { // Helper methods template - void debug(UdaPluginInterface* plugin_interface, const std::string& message, Args... args) + void debug(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& message, Args... args) { auto msg = fmt::format(message, args...); udaPluginLog(plugin_interface, "%s", msg.c_str()); } template - void error(UdaPluginInterface* plugin_interface, const std::string& message, Args... args) + void error(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& message, Args... args) { auto msg = fmt::format(message, args...); udaPluginLog(plugin_interface, "%s", msg.c_str()); diff --git a/source/plugins/uda/uda_plugin.cpp b/source/plugins/uda/uda_plugin.cpp index 764d022c..c337d206 100644 --- a/source/plugins/uda/uda_plugin.cpp +++ b/source/plugins/uda/uda_plugin.cpp @@ -152,9 +152,10 @@ int uda::plugins::uda::Plugin::get(UDA_PLUGIN_INTERFACE* plugin_interface) int pathway = 0; - DATA_SOURCE* data_source = plugin_interface->data_source; - SIGNAL_DESC* signal_desc = plugin_interface->signal_desc; - REQUEST_DATA* request = plugin_interface->request_data; + auto interface = static_cast<::uda::plugins::UdaPluginInterface*>(plugin_interface); + DATA_SOURCE* data_source = interface->data_source; + SIGNAL_DESC* signal_desc = interface->signal_desc; + REQUEST_DATA* request = interface->request_data; if (data_source->source_id > 0 && signal_desc->signal_desc_id > 0) { pathway = 1; @@ -186,7 +187,7 @@ int uda::plugins::uda::Plugin::get(UDA_PLUGIN_INTERFACE* plugin_interface) // Set Properties - CLIENT_BLOCK* client_block = plugin_interface->client_block; + CLIENT_BLOCK* client_block = interface->client_block; if (client_block->get_nodimdata) { udaSetProperty("get_nodimdata"); @@ -504,7 +505,7 @@ int uda::plugins::uda::Plugin::get(UDA_PLUGIN_INTERFACE* plugin_interface) // Check the originals have no XML action definitions before replacement // Why should a plugin have this concern? - DATA_BLOCK* data_block = plugin_interface->data_block; + DATA_BLOCK* data_block = interface->data_block; if (udaGetClientVersion() >= 7) { // This should contain everything! diff --git a/source/plugins/udaPlugin.cpp b/source/plugins/udaPlugin.cpp index f419f31f..3f5608ec 100644 --- a/source/plugins/udaPlugin.cpp +++ b/source/plugins/udaPlugin.cpp @@ -1,8 +1,9 @@ -#include "uda/plugins.h" +#include "udaPlugin.h" #include #include #include +#include #include #include #include @@ -21,12 +22,14 @@ #include "structures/struct.h" using namespace uda::client_server; +using namespace uda::server; +using namespace uda::plugins; UDA_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) { - auto plugin_interface = (UDA_PLUGIN_INTERFACE*)calloc(1, sizeof(UDA_PLUGIN_INTERFACE)); + auto plugin_interface = (uda::plugins::UdaPluginInterface*)calloc(1, sizeof(uda::plugins::UdaPluginInterface)); auto environment = getServerEnvironment(); - auto plugin_list = (PLUGINLIST*)calloc(1, sizeof(PLUGINLIST)); + auto plugin_list = (uda::plugins::PluginList*)calloc(1, sizeof(uda::plugins::PluginList)); initPluginList(plugin_list, environment); @@ -54,26 +57,29 @@ UDA_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) void udaFreePluginInterface(UDA_PLUGIN_INTERFACE* plugin_interface) { - free(plugin_interface->request_data); - udaFreeUserDefinedTypeList(plugin_interface->userdefinedtypelist); - free(plugin_interface->userdefinedtypelist); - udaFreeMallocLogList(plugin_interface->logmalloclist); - free(plugin_interface->logmalloclist); - freePluginList((PLUGINLIST*)plugin_interface->pluginList); - free((PLUGINLIST*)plugin_interface->pluginList); - free((ENVIRONMENT*)plugin_interface->environment); + auto interface = static_cast(plugin_interface); + free(interface->request_data); + udaFreeUserDefinedTypeList(interface->userdefinedtypelist); + free(interface->userdefinedtypelist); + udaFreeMallocLogList(interface->logmalloclist); + free(interface->logmalloclist); + freePluginList((uda::plugins::PluginList*)interface->pluginList); + free((PLUGINLIST*)interface->pluginList); + free((ENVIRONMENT*)interface->environment); free(plugin_interface); } int initPlugin(const UDA_PLUGIN_INTERFACE* plugin_interface) { - udaSetLogLevel((LOG_LEVEL)plugin_interface->environment->loglevel); + auto interface = static_cast(plugin_interface); + udaSetLogLevel((LOG_LEVEL)interface->environment->loglevel); return 0; } template int setReturnDataScalar(UDA_PLUGIN_INTERFACE* plugin_interface, T value, const char* description) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); auto data = (T*)malloc(sizeof(T)); @@ -96,7 +102,8 @@ template int setReturnDataArray(UDA_PLUGIN_INTERFACE* plugin_interface, const T* values, size_t rank, const size_t* shape, const char* description) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); if (description != nullptr) { @@ -159,7 +166,8 @@ UDA_IMPL_SET_RETURN_FUNCS(ULong, unsigned long) int udaPluginReturnDataStringScalar(UDA_PLUGIN_INTERFACE* plugin_interface, const char* value, const char* description) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); data_block->data_type = UDA_TYPE_STRING; @@ -192,7 +200,8 @@ int udaPluginReturnDataStringScalar(UDA_PLUGIN_INTERFACE* plugin_interface, cons int udaPluginReturnData(UDA_PLUGIN_INTERFACE* plugin_interface, void* value, size_t size, UDA_TYPE type, int rank, const int* shape, const char* description) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); data_block->data_type = type; @@ -226,15 +235,17 @@ int udaPluginReturnData(UDA_PLUGIN_INTERFACE* plugin_interface, void* value, siz return 0; } -LIBRARY_API int udaPluginArgumentCount(const UDA_PLUGIN_INTERFACE* plugin_interface) +int udaPluginArgumentCount(const UDA_PLUGIN_INTERFACE* plugin_interface) { - return plugin_interface->request_data->nameValueList.listSize; + auto interface = static_cast(plugin_interface); + return interface->request_data->nameValueList.listSize; } -LIBRARY_API const char* udaPluginArgument(const UDA_PLUGIN_INTERFACE* plugin_interface, int num) +const char* udaPluginArgument(const UDA_PLUGIN_INTERFACE* plugin_interface, int num) { - if (num > 0 && num < plugin_interface->request_data->nameValueList.pairCount) { - return plugin_interface->request_data->nameValueList.nameValue[num].name; + auto interface = static_cast(plugin_interface); + if (num > 0 && num < interface->request_data->nameValueList.pairCount) { + return interface->request_data->nameValueList.nameValue[num].name; } return nullptr; } @@ -251,7 +262,8 @@ LIBRARY_API const char* udaPluginArgument(const UDA_PLUGIN_INTERFACE* plugin_int */ bool udaPluginFindStringArg(const UDA_PLUGIN_INTERFACE* plugin_interface, const char** value, const char* name) { - auto namevaluelist = &plugin_interface->request_data->nameValueList; + auto interface = static_cast(plugin_interface); + auto namevaluelist = &interface->request_data->nameValueList; char** names = SplitString(name, "|"); *value = nullptr; @@ -327,7 +339,8 @@ UDA_IMPL_FIND_FUNCS(ULong, unsigned long) bool udaPluginFindArg(const UDA_PLUGIN_INTERFACE* plugin_interface, const char* name) { - auto namevaluelist = &plugin_interface->request_data->nameValueList; + auto interface = static_cast(plugin_interface); + auto namevaluelist = &interface->request_data->nameValueList; char** names = SplitString(name, "|"); bool found = false; @@ -353,23 +366,24 @@ int udaCallPlugin(UDA_PLUGIN_INTERFACE* plugin_interface, const char* request) int udaCallPlugin2(UDA_PLUGIN_INTERFACE* plugin_interface, const char* request, const char* source) { - UDA_PLUGIN_INTERFACE new_plugin_interface = *plugin_interface; - REQUEST_DATA request_data = *plugin_interface->request_data; + auto interface = static_cast(plugin_interface); + uda::plugins::UdaPluginInterface new_plugin_interface = *interface; + REQUEST_DATA request_data = *interface->request_data; new_plugin_interface.request_data = &request_data; strcpy(request_data.signal, request); strcpy(request_data.source, source); - makeRequestData(&request_data, plugin_interface->pluginList, plugin_interface->environment); + makeRequestData(&request_data, interface->pluginList, interface->environment); - request_data.request = findPluginRequestByFormat(request_data.format, plugin_interface->pluginList); + request_data.request = findPluginRequestByFormat(request_data.format, interface->pluginList); if (request_data.request == REQUEST_READ_UNKNOWN) { UDA_RAISE_PLUGIN_ERROR(plugin_interface, "Plugin not found!"); } int err = 0; - int id = findPluginIdByRequest(request_data.request, plugin_interface->pluginList); - PLUGIN_DATA* plugin = &(plugin_interface->pluginList->plugin[id]); + int id = findPluginIdByRequest(request_data.request, interface->pluginList); + uda::plugins::PluginData* plugin = &(interface->pluginList->plugin[id]); if (id >= 0 && plugin->idamPlugin != nullptr) { err = plugin->idamPlugin(&new_plugin_interface); // Call the data reader } else { @@ -391,7 +405,8 @@ int udaCallPlugin2(UDA_PLUGIN_INTERFACE* plugin_interface, const char* request, int udaPluginReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* data, const char* user_type, const char* description) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); data_block->data_type = UDA_TYPE_COMPOUND; @@ -405,7 +420,7 @@ int udaPluginReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* da data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; data_block->opaque_count = 1; - data_block->opaque_block = (void*)udaFindUserDefinedType(plugin_interface->userdefinedtypelist, user_type, 0); + data_block->opaque_block = (void*)udaFindUserDefinedType(interface->userdefinedtypelist, user_type, 0); if (description != nullptr) { strncpy(data_block->data_desc, description, STRING_LENGTH); @@ -418,7 +433,8 @@ int udaPluginReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* da int udaPluginReturnCompoundArrayData(UDA_PLUGIN_INTERFACE* plugin_interface, char* data, const char* user_type, const char* description, int rank, int* shape) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; initDataBlock(data_block); int count = 1; @@ -449,7 +465,7 @@ int udaPluginReturnCompoundArrayData(UDA_PLUGIN_INTERFACE* plugin_interface, cha data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; data_block->opaque_count = 1; - data_block->opaque_block = (void*)udaFindUserDefinedType(plugin_interface->userdefinedtypelist, user_type, 0); + data_block->opaque_block = (void*)udaFindUserDefinedType(interface->userdefinedtypelist, user_type, 0); if (description != nullptr) { strncpy(data_block->data_desc, description, STRING_LENGTH); @@ -521,7 +537,8 @@ USERDEFINEDTYPE* udaNewUserType(const char* name, const char* source, int ref_id int udaAddUserType(UDA_PLUGIN_INTERFACE* plugin_interface, USERDEFINEDTYPE* user_type) { - USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; + auto interface = static_cast(plugin_interface); + USERDEFINEDTYPELIST* userdefinedtypelist = interface->userdefinedtypelist; udaAddUserDefinedType(userdefinedtypelist, *user_type); return 0; @@ -529,7 +546,8 @@ int udaAddUserType(UDA_PLUGIN_INTERFACE* plugin_interface, USERDEFINEDTYPE* user int udaRegisterMalloc(UDA_PLUGIN_INTERFACE* plugin_interface, void* data, int count, size_t size, const char* type) { - udaAddMalloc(plugin_interface->logmalloclist, data, count, size, type); + auto interface = static_cast(plugin_interface); + udaAddMalloc(interface->logmalloclist, data, count, size, type); return 0; } @@ -537,22 +555,25 @@ int udaRegisterMalloc(UDA_PLUGIN_INTERFACE* plugin_interface, void* data, int co int udaRegisterMallocArray(UDA_PLUGIN_INTERFACE* plugin_interface, void* data, int count, size_t size, const char* type, int rank, int* shape) { - udaAddMalloc2(plugin_interface->logmalloclist, data, count, size, type, rank, shape); + auto interface = static_cast(plugin_interface); + udaAddMalloc2(interface->logmalloclist, data, count, size, type, rank, shape); return 0; } int udaPluginPluginsCount(UDA_PLUGIN_INTERFACE* plugin_interface) { - return plugin_interface->pluginList->count; + auto interface = static_cast(plugin_interface); + return interface->pluginList->count; } namespace { int check_plugin_class(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num, int plugin_class) { - auto plugin_list = plugin_interface->pluginList; - auto environment = plugin_interface->environment; + auto interface = static_cast(plugin_interface); + auto plugin_list = interface->pluginList; + auto environment = interface->environment; bool is_valid = plugin_list->plugin[plugin_num].plugin_class == plugin_class && plugin_list->plugin[plugin_num].status == UDA_PLUGIN_OPERATIONAL && @@ -590,22 +611,26 @@ int udaPluginCheckPluginClass(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin const char* udaPluginPluginFormat(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) { - return plugin_interface->pluginList->plugin[plugin_num].format; + auto interface = static_cast(plugin_interface); + return interface->pluginList->plugin[plugin_num].format; } const char* udaPluginPluginExtension(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) { - return plugin_interface->pluginList->plugin[plugin_num].extension; + auto interface = static_cast(plugin_interface); + return interface->pluginList->plugin[plugin_num].extension; } const char* udaPluginPluginDescription(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) { - return plugin_interface->pluginList->plugin[plugin_num].desc; + auto interface = static_cast(plugin_interface); + return interface->pluginList->plugin[plugin_num].desc; } const char* udaPluginPluginExample(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) { - return plugin_interface->pluginList->plugin[plugin_num].example; + auto interface = static_cast(plugin_interface); + return interface->pluginList->plugin[plugin_num].example; } void udaPluginLog(UDA_PLUGIN_INTERFACE* plugin_interface, const char* fmt, ...) @@ -620,51 +645,59 @@ void udaPluginLog(UDA_PLUGIN_INTERFACE* plugin_interface, const char* fmt, ...) void udaAddPluginError(UDA_PLUGIN_INTERFACE* plugin_interface, const char* location, int code, const char* msg) { + auto interface = static_cast(plugin_interface); udaLog(UDA_LOG_ERROR, msg); - plugin_interface->error_stack.nerrors += 1; - plugin_interface->error_stack.idamerror = (UDA_ERROR*)realloc( - plugin_interface->error_stack.idamerror, plugin_interface->error_stack.nerrors * sizeof(UDA_ERROR)); - plugin_interface->error_stack.idamerror[plugin_interface->error_stack.nerrors - 1] = + interface->error_stack.nerrors += 1; + interface->error_stack.idamerror = + (UDA_ERROR*)realloc(interface->error_stack.idamerror, interface->error_stack.nerrors * sizeof(UDA_ERROR)); + interface->error_stack.idamerror[interface->error_stack.nerrors - 1] = create_error(UDA_CODE_ERROR_TYPE, location, code, msg); } int udaPluginIsExternal(UDA_PLUGIN_INTERFACE* plugin_interface) { - return plugin_interface->environment->external_user; + auto interface = static_cast(plugin_interface); + return interface->environment->external_user; } int udaPluginCheckInterfaceVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int interface_version) { - return plugin_interface->interfaceVersion > interface_version; + auto interface = static_cast(plugin_interface); + return interface->interfaceVersion > interface_version; } void udaPluginSetVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_version) { - plugin_interface->pluginVersion = plugin_version; + auto interface = static_cast(plugin_interface); + interface->pluginVersion = plugin_version; } const char* udaPluginFunction(UDA_PLUGIN_INTERFACE* plugin_interface) { - return plugin_interface->request_data->function; + auto interface = static_cast(plugin_interface); + return interface->request_data->function; } int udaPluginReturnDataLabel(UDA_PLUGIN_INTERFACE* plugin_interface, const char* label) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; strcpy(data_block->data_label, label); return 0; } int udaPluginReturnDataUnits(UDA_PLUGIN_INTERFACE* plugin_interface, const char* units) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; strcpy(data_block->data_units, units); return 0; } int udaPluginReturnErrorAsymmetry(UDA_PLUGIN_INTERFACE* plugin_interface, bool flag) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; data_block->errasymmetry = flag; return 0; } @@ -682,21 +715,24 @@ char* memdup(const void* mem, size_t size) int udaPluginReturnErrorLow(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; data_block->errlo = memdup(data, size); return 0; } int udaPluginReturnErrorHigh(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; data_block->errhi = memdup(data, size); return 0; } int udaPluginReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; data_block->order = order; return 0; } @@ -704,7 +740,8 @@ int udaPluginReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order) int udaPluginReturnDimensionFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, int dim_n, float* data, size_t size, const char* label, const char* units) { - DATA_BLOCK* data_block = plugin_interface->data_block; + auto interface = static_cast(plugin_interface); + DATA_BLOCK* data_block = interface->data_block; data_block->dims[0].data_type = UDA_TYPE_FLOAT; data_block->dims[0].dim_n = dim_n; diff --git a/source/plugins/udaPlugin.h b/source/plugins/udaPlugin.h new file mode 100644 index 00000000..3c3a276f --- /dev/null +++ b/source/plugins/udaPlugin.h @@ -0,0 +1,75 @@ +#pragma once + +#include "clientserver/udaStructs.h" +#include + +typedef struct CUdaPluginInterface { +} UDA_PLUGIN_INTERFACE; + +namespace uda::plugins +{ + +enum pluginClass { + UDA_PLUGIN_CLASS_UNKNOWN, + UDA_PLUGIN_CLASS_FILE, // File format access + UDA_PLUGIN_CLASS_SERVER, // Server protocol access + UDA_PLUGIN_CLASS_FUNCTION, // Server-side function transformation + UDA_PLUGIN_CLASS_DEVICE, // Server to Server chaining, i.e. Pass the request to an external server + UDA_PLUGIN_CLASS_OTHER +}; + +typedef int (*PLUGINFUNP)(UDA_PLUGIN_INTERFACE*); // Plugin function type + +typedef struct PluginData { + char format[STRING_LENGTH]; // File format, or Function library or Server protocol or External Device name + char library[STRING_LENGTH]; // external plugin shared library name (must be on Server library search path) + char symbol[STRING_LENGTH]; // external plugin symbol name + char method[STRING_LENGTH]; // Method to use for Data Readers (FILE Plugin Class) + char extension[STRING_LENGTH]; // File Extension (Not Case sensitive) + char deviceProtocol[STRING_LENGTH]; // Server protocol substitute for Device name + char deviceHost[STRING_LENGTH]; // Server Host substitute for Device name + char devicePort[STRING_LENGTH]; // Server Port substitute for Device name + char desc[STRING_LENGTH]; // Description of the plugin + char example[STRING_LENGTH]; // Examples of Use + int request; // unique request ID + unsigned short plugin_class; // the plugin class: File, Server, Function, Device + unsigned short external; // Flag the plugin is accessed via a separate shared library + unsigned short status; // Plugin operational: external library opened or internal + unsigned short is_private; // The service is private and can NOT be used by external clients + unsigned short cachePermission; // The server's internal state may be dependent on previous calls + // so the returned data are not suitable for caching on the client. + // This is used to inform the client how to manage the returned data + unsigned short interfaceVersion; // Maximum interface version the plugin is compliant with (Minimum is 1) + void* pluginHandle; // Plugin Library handle + PLUGINFUNP idamPlugin; // Plugin function address +} PLUGIN_DATA; + +struct PluginList { + int count; // the number of plugins + int mcount; // malloc count allocated + PLUGIN_DATA* plugin; +}; + +struct UdaPluginInterface : UDA_PLUGIN_INTERFACE { // Standard Plugin interface + unsigned short interfaceVersion; // Interface Version + unsigned short pluginVersion; // Plugin Version + unsigned short sqlConnectionType; // Which SQL is the server connected to + unsigned short verbose; // Spare! Use (errout!=NULL) instead *** Deprecated + unsigned short housekeeping; // Housekeeping Directive + unsigned short changePlugin; // Use a different Plugin to access the data + FILE* dbgout; + FILE* errout; + uda::client_server::DATA_BLOCK* data_block; + uda::client_server::REQUEST_DATA* request_data; + uda::client_server::CLIENT_BLOCK* client_block; + uda::client_server::DATA_SOURCE* data_source; + uda::client_server::SIGNAL_DESC* signal_desc; + const uda::client_server::ENVIRONMENT* environment; // Server environment + LOGMALLOCLIST* logmalloclist; + USERDEFINEDTYPELIST* userdefinedtypelist; + void* sqlConnection; // Opaque structure + const PluginList* pluginList; // List of data readers, filters, models, and servers + uda::client_server::UDA_ERROR_STACK error_stack; +}; + +} // namespace uda::plugins \ No newline at end of file diff --git a/source/server/applyXML.cpp b/source/server/applyXML.cpp index 23cf9c88..ed8e3097 100644 --- a/source/server/applyXML.cpp +++ b/source/server/applyXML.cpp @@ -21,9 +21,10 @@ #include "logging/logging.h" #include -int serverParseSignalXML(uda::client_server::DATA_SOURCE data_source, uda::client_server::SIGNAL signal, - uda::client_server::SIGNAL_DESC signal_desc, uda::client_server::ACTIONS* actions_desc, - uda::client_server::ACTIONS* actions_sig) +int uda::server::serverParseSignalXML(uda::client_server::DATA_SOURCE data_source, uda::client_server::SIGNAL signal, + uda::client_server::SIGNAL_DESC signal_desc, + uda::client_server::ACTIONS* actions_desc, + uda::client_server::ACTIONS* actions_sig) { // return -1 if No Qualifying Actionable XML otherwise return 0 @@ -274,9 +275,10 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv } } -void serverApplySignalXML(uda::client_server::CLIENT_BLOCK client_block, uda::client_server::DATA_SOURCE* data_source, - uda::client_server::SIGNAL* signal, uda::client_server::SIGNAL_DESC* signal_desc, - uda::client_server::DATA_BLOCK* data_block, uda::client_server::ACTIONS actions) +void uda::server::serverApplySignalXML(uda::client_server::CLIENT_BLOCK client_block, + uda::client_server::DATA_SOURCE* data_source, uda::client_server::SIGNAL* signal, + uda::client_server::SIGNAL_DESC* signal_desc, + uda::client_server::DATA_BLOCK* data_block, uda::client_server::ACTIONS actions) { int ndata, dimid; @@ -1528,7 +1530,8 @@ void serverApplySignalXML(uda::client_server::CLIENT_BLOCK client_block, uda::cl // Combine the set of Actions from both sources with Signal XML having Priority of Signal_Desc XML -void serverDeselectSignalXML(uda::client_server::ACTIONS* actions_desc, uda::client_server::ACTIONS* actions_sig) +void uda::server::serverDeselectSignalXML(uda::client_server::ACTIONS* actions_desc, + uda::client_server::ACTIONS* actions_sig) { int type; diff --git a/source/server/applyXML.h b/source/server/applyXML.h index 9f1124ce..b0f87540 100644 --- a/source/server/applyXML.h +++ b/source/server/applyXML.h @@ -1,10 +1,10 @@ #pragma once -#ifndef UDA_SERVER_APPLYXML_H -# define UDA_SERVER_APPLYXML_H +#include "clientserver/parseXML.h" +#include "clientserver/udaStructs.h" -# include "clientserver/parseXML.h" -# include "clientserver/udaStructs.h" +namespace uda::server +{ int serverParseSignalXML(uda::client_server::DATA_SOURCE data_source, uda::client_server::SIGNAL signal, uda::client_server::SIGNAL_DESC signal_desc, uda::client_server::ACTIONS* actions_desc, @@ -16,4 +16,4 @@ void serverApplySignalXML(uda::client_server::CLIENT_BLOCK client_block, uda::cl void serverDeselectSignalXML(uda::client_server::ACTIONS* actions_desc, uda::client_server::ACTIONS* actions_sig); -#endif // UDA_SERVER_APPLYXML_H +} // namespace uda::server diff --git a/source/server/closeServerSockets.cpp b/source/server/closeServerSockets.cpp index 9bcdb81d..04fc212d 100644 --- a/source/server/closeServerSockets.cpp +++ b/source/server/closeServerSockets.cpp @@ -28,7 +28,7 @@ void closeNamedServerSocket(SOCKETLIST* socks, char* host, int port) } } -void closeServerSocket(SOCKETLIST* socks, int fh) +void uda::server::closeServerSocket(SOCKETLIST* socks, int fh) { for (int i = 0; i < socks->nsocks; i++) { if (socks->sockets[i].fh == fh) { @@ -42,7 +42,7 @@ void closeServerSocket(SOCKETLIST* socks, int fh) } } -void closeServerSockets(SOCKETLIST* socks) +void uda::server::closeServerSockets(SOCKETLIST* socks) { for (int i = 0; i < socks->nsocks; i++) { closeServerSocket(socks, socks->sockets[i].fh); diff --git a/source/server/closeServerSockets.h b/source/server/closeServerSockets.h index 8817ab32..b1b4b20c 100644 --- a/source/server/closeServerSockets.h +++ b/source/server/closeServerSockets.h @@ -1,11 +1,12 @@ #pragma once -#ifndef UDA_SERVER_CLOSESERVERSOCKETS_H -# define UDA_SERVER_CLOSESERVERSOCKETS_H +#include "clientserver/socketStructs.h" -# include "clientserver/socketStructs.h" +namespace uda::server +{ void closeServerSocket(uda::client_server::SOCKETLIST* socks, int fh); + void closeServerSockets(uda::client_server::SOCKETLIST* socks); -#endif // UDA_SERVER_CLOSESERVERSOCKETS_H +} // namespace uda::server diff --git a/source/server/createXDRStream.cpp b/source/server/createXDRStream.cpp index 5c3bdcc3..98080be0 100644 --- a/source/server/createXDRStream.cpp +++ b/source/server/createXDRStream.cpp @@ -8,7 +8,7 @@ # include #endif -std::pair serverCreateXDRStream(IoData* io_data) +std::pair uda::server::serverCreateXDRStream(uda::client_server::IoData* io_data) { static XDR server_input = {}; static XDR server_output = {}; diff --git a/source/server/createXDRStream.h b/source/server/createXDRStream.h index b4dfdbd5..0a7d425d 100644 --- a/source/server/createXDRStream.h +++ b/source/server/createXDRStream.h @@ -1,16 +1,18 @@ #pragma once -#ifndef UDA_SERVER_CREATEXDRSTREAM_H -# define UDA_SERVER_CREATEXDRSTREAM_H +#include "clientserver/protocol.h" -# include -# include +#include +#include -struct IoData { +namespace uda::server +{ + +struct IoData : uda::client_server::IoData { int* server_tot_block_time; int* server_timeout; }; -std::pair serverCreateXDRStream(IoData* io_data); +std::pair serverCreateXDRStream(uda::client_server::IoData* io_data); -#endif // UDA_SERVER_CREATEXDRSTREAM_H +} // namespace uda::server diff --git a/source/server/fatServer.cpp b/source/server/fatServer.cpp index 4228f53b..fe8b97df 100644 --- a/source/server/fatServer.cpp +++ b/source/server/fatServer.cpp @@ -1,3 +1,5 @@ +#include "udaServer.h" + #include #include #include @@ -28,9 +30,10 @@ void ncclose(int fh) {} #endif using namespace uda::client_server; +using namespace uda::server; -static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) -ENVIRONMENT environment; // Holds local environment variable values +static uda::plugins::PluginList pluginList; // List of all data reader plugins (internal and external shared libraries) +ENVIRONMENT environment; // Holds local environment variable values static USERDEFINEDTYPELIST* user_defined_type_list = nullptr; static LOGMALLOCLIST* log_malloc_list = nullptr; @@ -80,13 +83,13 @@ static int handle_request_fat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* reque static int fat_client_return(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DATA_BLOCK_LIST* data_blocks0, REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, METADATA_BLOCK* metadata_block, - LOGSTRUCTLIST* log_struct_list, IoData* io_data); + LOGSTRUCTLIST* log_struct_list, uda::server::IoData* io_data); //-------------------------------------------------------------------------------------- // Server Entry point -int fat_server(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, - DATA_BLOCK_LIST* data_blocks0) +int uda::server::fat_server(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, + DATA_BLOCK_LIST* data_blocks0) { assert(data_blocks0 != nullptr); @@ -176,7 +179,8 @@ int fat_server(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BL * Client deletes stale files automatically on startup. * @return */ -static int process_hierarchical_data(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, IoData* io_data) +static int process_hierarchical_data(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, + uda::server::IoData* io_data) { int err = 0; @@ -250,7 +254,7 @@ static int process_hierarchical_data(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_ int fat_client_return(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DATA_BLOCK_LIST* data_blocks0, REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, METADATA_BLOCK* metadata_block, - LOGSTRUCTLIST* log_struct_list, IoData* io_data) + LOGSTRUCTLIST* log_struct_list, uda::server::IoData* io_data) { //---------------------------------------------------------------------------- // Gather Server Error State diff --git a/source/server/getPluginAddress.cpp b/source/server/getPluginAddress.cpp index ce2d6e38..4a12d552 100644 --- a/source/server/getPluginAddress.cpp +++ b/source/server/getPluginAddress.cpp @@ -8,6 +8,7 @@ #include "logging/logging.h" using namespace uda::client_server; +using namespace uda::plugins; /** * Return the function address for plugin data readers located in external shared libraries @@ -18,7 +19,7 @@ using namespace uda::client_server; * @param pluginfunp the address of the library function * @return */ -int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp) +int uda::server::getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp) { *pluginfunp = (PLUGINFUNP) nullptr; diff --git a/source/server/getPluginAddress.h b/source/server/getPluginAddress.h index baec3fd8..b3d39f5b 100644 --- a/source/server/getPluginAddress.h +++ b/source/server/getPluginAddress.h @@ -2,4 +2,10 @@ #include "serverPlugin.h" -int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp); +namespace uda::server +{ + +int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, + uda::plugins::PLUGINFUNP* pluginfunp); + +} diff --git a/source/server/getServerEnvironment.cpp b/source/server/getServerEnvironment.cpp index 704ff3d1..6f27fd2b 100644 --- a/source/server/getServerEnvironment.cpp +++ b/source/server/getServerEnvironment.cpp @@ -7,7 +7,7 @@ // 2019-07-04 Herve Ancher (CEA): Add prefix "g_" to avoid conflict with internal MinGW varaible static uda::client_server::Environment g_environ; -void printServerEnvironment(const uda::client_server::Environment* environment) +void uda::server::printServerEnvironment(const uda::client_server::Environment* environment) { UDA_LOG(UDA_LOG_INFO, "Server Environment Variable values\n"); UDA_LOG(UDA_LOG_INFO, "Log Location : %s\n", environment->logdir); @@ -20,7 +20,7 @@ void printServerEnvironment(const uda::client_server::Environment* environment) UDA_LOG(UDA_LOG_INFO, "Private File Path Substitute: %s\n", environment->private_path_substitute); } -uda::client_server::Environment* getServerEnvironment() +uda::client_server::Environment* uda::server::getServerEnvironment() { char* env = nullptr; diff --git a/source/server/getServerEnvironment.h b/source/server/getServerEnvironment.h index 9ddba2ee..733fd48f 100644 --- a/source/server/getServerEnvironment.h +++ b/source/server/getServerEnvironment.h @@ -1,11 +1,12 @@ #pragma once -#ifndef UDA_SERVER_GETSERVERENVIRONMENT_H -# define UDA_SERVER_GETSERVERENVIRONMENT_H +#include "clientserver/udaStructs.h" -# include "clientserver/udaStructs.h" +namespace uda::server +{ void printServerEnvironment(const uda::client_server::Environment* environment); + uda::client_server::Environment* getServerEnvironment(); -#endif // UDA_SERVER_GETSERVERENVIRONMENT_H +} // namespace uda::server diff --git a/source/server/initPluginList.cpp b/source/server/initPluginList.cpp index cf7b8dad..9465d786 100644 --- a/source/server/initPluginList.cpp +++ b/source/server/initPluginList.cpp @@ -12,13 +12,14 @@ #include "getPluginAddress.h" using namespace uda::client_server; +using namespace uda::plugins; -void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) +void uda::server::initPluginList(uda::plugins::PluginList* plugin_list, ENVIRONMENT* environment) { // initialise the Plugin List and Allocate heap for the list plugin_list->count = 0; - plugin_list->plugin = (PLUGIN_DATA*)malloc(REQUEST_PLUGIN_MCOUNT * sizeof(PLUGIN_DATA)); + plugin_list->plugin = (uda::plugins::PluginData*)malloc(REQUEST_PLUGIN_MCOUNT * sizeof(uda::plugins::PluginData)); plugin_list->mcount = REQUEST_PLUGIN_MCOUNT; for (int i = 0; i < plugin_list->mcount; i++) { diff --git a/source/server/initPluginList.h b/source/server/initPluginList.h index 2f77dcde..7b4dd984 100644 --- a/source/server/initPluginList.h +++ b/source/server/initPluginList.h @@ -1,6 +1,12 @@ #pragma once #include "clientserver/udaStructs.h" +#include "plugins/udaPlugin.h" #include "serverPlugin.h" -void initPluginList(PLUGINLIST* plugin_list, uda::client_server::Environment* environment); +namespace uda::server +{ + +void initPluginList(uda::plugins::PluginList* plugin_list, uda::client_server::Environment* environment); + +} diff --git a/source/server/makeServerRequestBlock.cpp b/source/server/makeServerRequestBlock.cpp index e3f170a0..a2026020 100644 --- a/source/server/makeServerRequestBlock.cpp +++ b/source/server/makeServerRequestBlock.cpp @@ -9,12 +9,12 @@ using namespace uda::client_server; -int makeServerRequestBlock(REQUEST_BLOCK* request_block, PLUGINLIST pluginList) +int uda::server::makeServerRequestBlock(REQUEST_BLOCK* request_block, uda::plugins::PluginList pluginList) { return make_request_block(request_block, &pluginList, getServerEnvironment()); } -int makeServerRequestData(REQUEST_DATA* request, PLUGINLIST pluginList) +int uda::server::makeServerRequestData(REQUEST_DATA* request, uda::plugins::PluginList pluginList) { return makeRequestData(request, &pluginList, getServerEnvironment()); } diff --git a/source/server/makeServerRequestBlock.h b/source/server/makeServerRequestBlock.h index 20141d0d..47dea552 100644 --- a/source/server/makeServerRequestBlock.h +++ b/source/server/makeServerRequestBlock.h @@ -5,7 +5,13 @@ # include "clientserver/udaStructs.h" # include "serverPlugin.h" -int makeServerRequestBlock(uda::client_server::REQUEST_BLOCK* request_block, PLUGINLIST pluginList); -int makeServerRequestData(uda::client_server::REQUEST_DATA* request, PLUGINLIST pluginList); +namespace uda::server +{ + +int makeServerRequestBlock(uda::client_server::REQUEST_BLOCK* request_block, uda::plugins::PluginList pluginList); + +int makeServerRequestData(uda::client_server::REQUEST_DATA* request, uda::plugins::PluginList pluginList); + +} // namespace uda::server #endif diff --git a/source/server/serverGetData.cpp b/source/server/serverGetData.cpp index 58df61bb..d5760558 100644 --- a/source/server/serverGetData.cpp +++ b/source/server/serverGetData.cpp @@ -23,19 +23,21 @@ #include "uda/plugins.h" using namespace uda::client_server; +using namespace uda::server; static int swap_signal_error(DATA_BLOCK* data_block, DATA_BLOCK* data_block2, int asymmetry); static int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2); static int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2, int asymmetry); static int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, DATA_SOURCE* data_source, - SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const PLUGINLIST* pluginlist, + SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const uda::plugins::PluginList* pluginlist, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist); -int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, - DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, ACTIONS* actions_desc, - ACTIONS* actions_sig, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, SOCKETLIST* socket_list, int protocolVersion) +int uda::server::udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, + DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, + ACTIONS* actions_desc, ACTIONS* actions_sig, const uda::plugins::PluginList* pluginlist, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + SOCKETLIST* socket_list, int protocolVersion) { int isDerived = 0, compId = -1, serverside = 0; @@ -953,8 +955,8 @@ int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DAT } int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, DATA_SOURCE* data_source, - SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist) + SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const uda::plugins::PluginList* pluginlist, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist) { // If err = 0 then standard signal data read // If err > 0 then an error occured @@ -1114,7 +1116,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data // Test for known File formats and Server protocols { - UDA_PLUGIN_INTERFACE plugin_interface; + uda::plugins::UdaPluginInterface plugin_interface; UDA_LOG(UDA_LOG_DEBUG, "creating the plugin interface structure\n"); diff --git a/source/server/serverGetData.h b/source/server/serverGetData.h index c7331a8a..ef2b652f 100644 --- a/source/server/serverGetData.h +++ b/source/server/serverGetData.h @@ -6,10 +6,15 @@ #include "serverPlugin.h" #include "structures/genStructs.h" +namespace uda::server +{ + int udaGetData(int* depth, uda::client_server::REQUEST_DATA* request_data, uda::client_server::CLIENT_BLOCK client_block, uda::client_server::DATA_BLOCK* data_block, uda::client_server::DATA_SOURCE* data_source, uda::client_server::SIGNAL* signal_rec, uda::client_server::SIGNAL_DESC* signal_desc, uda::client_server::ACTIONS* actions_desc, - uda::client_server::ACTIONS* actions_sig, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, uda::client_server::SOCKETLIST* socket_list, - int protocolVersion); + uda::client_server::ACTIONS* actions_sig, const uda::plugins::PluginList* pluginlist, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + uda::client_server::SOCKETLIST* socket_list, int protocolVersion); + +} diff --git a/source/server/serverLegacyPlugin.cpp b/source/server/serverLegacyPlugin.cpp index 008f2b3a..c1ddf41f 100644 --- a/source/server/serverLegacyPlugin.cpp +++ b/source/server/serverLegacyPlugin.cpp @@ -14,8 +14,9 @@ #endif using namespace uda::client_server; +using namespace uda::server; -int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc) +int uda::server::udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc) { int err = 0; char* token = nullptr; diff --git a/source/server/serverLegacyPlugin.h b/source/server/serverLegacyPlugin.h index 9f1d1c9d..b38a1c55 100644 --- a/source/server/serverLegacyPlugin.h +++ b/source/server/serverLegacyPlugin.h @@ -1,11 +1,11 @@ #pragma once -#ifndef UDA_SERVER_SERVERLEGACYPLUGIN_H -# define UDA_SERVER_SERVERLEGACYPLUGIN_H +#include "clientserver/udaStructs.h" -# include "clientserver/udaStructs.h" +namespace uda::server +{ int udaServerLegacyPlugin(uda::client_server::REQUEST_DATA* request, uda::client_server::DATA_SOURCE* data_source, uda::client_server::SIGNAL_DESC* signal_desc); -#endif // UDA_SERVER_SERVERLEGACYPLUGIN_H +} diff --git a/source/server/serverMain.cpp b/source/server/serverMain.cpp index defb6b1d..0fb40cbb 100644 --- a/source/server/serverMain.cpp +++ b/source/server/serverMain.cpp @@ -21,7 +21,7 @@ int main(int argc, char** argv) uda::client_server::CLIENT_BLOCK client_block = {0}; - int rc = uda_server(client_block); + int rc = uda::server::uda_server(client_block); return rc; } diff --git a/source/server/serverPlugin.cpp b/source/server/serverPlugin.cpp index 910e2182..02a5a47d 100644 --- a/source/server/serverPlugin.cpp +++ b/source/server/serverPlugin.cpp @@ -31,6 +31,8 @@ #define REQUEST_PLUGIN_MSTEP 10 // Increase heap by 10 records once the maximum is exceeded using namespace uda::client_server; +using namespace uda::server; +using namespace uda::plugins; /** * Find the Plugin identity: return the reference id or -1 if not found. @@ -38,7 +40,7 @@ using namespace uda::client_server; * @param plugin_list * @return */ -int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list) +int uda::server::findPluginIdByRequest(int request, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (plugin_list->plugin[i].request == request) { @@ -54,7 +56,7 @@ int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list) * @param plugin_list * @return */ -int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list) +int uda::server::findPluginIdByFormat(const char* format, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { @@ -70,7 +72,7 @@ int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list) * @param plugin_list * @return */ -int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list) +int uda::server::findPluginIdByDevice(const char* device, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (plugin_list->plugin[i].plugin_class == UDA_PLUGIN_CLASS_DEVICE && @@ -87,7 +89,7 @@ int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list) * @param plugin_list * @return */ -int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list) +int uda::server::findPluginRequestByFormat(const char* format, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { @@ -103,7 +105,7 @@ int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list) * @param plugin_list * @return */ -int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin_list) +int uda::server::findPluginRequestByExtension(const char* extension, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { if (STR_IEQUALS(plugin_list->plugin[i].extension, extension)) { @@ -113,19 +115,19 @@ int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin return REQUEST_READ_UNKNOWN; } -void allocPluginList(int count, PLUGINLIST* plugin_list) +void uda::server::allocPluginList(int count, uda::plugins::PluginList* plugin_list) { if (count >= plugin_list->mcount) { plugin_list->mcount = plugin_list->mcount + REQUEST_PLUGIN_MSTEP; - plugin_list->plugin = - (PLUGIN_DATA*)realloc((void*)plugin_list->plugin, plugin_list->mcount * sizeof(PLUGIN_DATA)); + plugin_list->plugin = (uda::plugins::PluginData*)realloc( + (void*)plugin_list->plugin, plugin_list->mcount * sizeof(uda::plugins::PluginData)); } } -void resetPlugins(const PLUGINLIST* plugin_list) +void resetPlugins(const uda::plugins::PluginList* plugin_list) { REQUEST_DATA request_block; - UDA_PLUGIN_INTERFACE plugin_interface; + uda::plugins::UdaPluginInterface plugin_interface; initRequestData(&request_block); strcpy(request_block.function, "reset"); @@ -134,12 +136,13 @@ void resetPlugins(const PLUGINLIST* plugin_list) plugin_interface.request_data = &request_block; for (int i = 0; i < plugin_list->count; i++) { if (plugin_list->plugin[i].pluginHandle != nullptr) { - plugin_list->plugin[i].idamPlugin(&plugin_interface); // Call the housekeeping method + plugin_list->plugin[i].idamPlugin( + static_cast(&plugin_interface)); // Call the housekeeping method } } } -void freePluginList(PLUGINLIST* plugin_list) +void uda::server::freePluginList(uda::plugins::PluginList* plugin_list) { resetPlugins(plugin_list); for (int i = 0; i < plugin_list->count; i++) { @@ -153,7 +156,7 @@ void freePluginList(PLUGINLIST* plugin_list) plugin_list->mcount = 0; } -void initPluginData(PLUGIN_DATA* plugin) +void uda::server::initPluginData(uda::plugins::PluginData* plugin) { plugin->format[0] = '\0'; plugin->library[0] = '\0'; @@ -176,7 +179,7 @@ void initPluginData(PLUGIN_DATA* plugin) plugin->idamPlugin = nullptr; } -void printPluginList(FILE* fd, const PLUGINLIST* plugin_list) +void printPluginList(FILE* fd, const uda::plugins::PluginList* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { fprintf(fd, "Format : %s\n", plugin_list->plugin[i].format); @@ -198,7 +201,7 @@ void printPluginList(FILE* fd, const PLUGINLIST* plugin_list) } } -int udaServerRedirectStdStreams(int reset) +int uda::server::udaServerRedirectStdStreams(int reset) { // Any OS messages will corrupt xdr streams so re-divert IO from plugin libraries to a temporary file @@ -334,8 +337,8 @@ int udaServerRedirectStdStreams(int reset) // 5. open the library // 6. get plugin function address // 7. close the file -int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, - const PLUGINLIST* plugin_list, const ENVIRONMENT* environment) +int uda::server::udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, + const uda::plugins::PluginList* plugin_list, const ENVIRONMENT* environment) { int err = 0; @@ -402,9 +405,10 @@ int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC // changePlugin option disabled in this context // private malloc log and userdefinedtypelist -int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_request, DATA_SOURCE* data_source, - SIGNAL_DESC* signal_desc, const PLUGINLIST* plugin_list, const char* logRecord, - const ENVIRONMENT* environment) +int uda::server::udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_request, + DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, + const uda::plugins::PluginList* plugin_list, const char* logRecord, + const ENVIRONMENT* environment) { if (STR_EQUALS(client_block->DOI, "")) { @@ -490,7 +494,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque int err, rc, reset; DATA_BLOCK data_block; - UDA_PLUGIN_INTERFACE plugin_interface; + UdaPluginInterface plugin_interface; // Initialise the Data Block @@ -581,7 +585,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque //------------------------------------------------------------------------------------------------ // Identify the Plugin to use to resolve Generic Name mappings and return its ID -int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* environment) +int uda::server::udaServerMetaDataPluginId(const uda::plugins::PluginList* plugin_list, const ENVIRONMENT* environment) { static unsigned short noPluginRegistered = 0; static int plugin_id = -1; @@ -639,12 +643,12 @@ int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* //------------------------------------------------------------------------------------------------ // Execute the Generic Name mapping Plugin -int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUEST_DATA* request_block, - SIGNAL_DESC* signal_desc, SIGNAL* signal_rec, DATA_SOURCE* data_source, - const ENVIRONMENT* environment) +int uda::server::udaServerMetaDataPlugin(const uda::plugins::PluginList* plugin_list, int plugin_id, + REQUEST_DATA* request_block, SIGNAL_DESC* signal_desc, SIGNAL* signal_rec, + DATA_SOURCE* data_source, const ENVIRONMENT* environment) { int err, reset, rc; - UDA_PLUGIN_INTERFACE plugin_interface; + UdaPluginInterface plugin_interface; // Check the Interface Compliance diff --git a/source/server/serverPlugin.h b/source/server/serverPlugin.h index 5f971a01..1dacba2b 100644 --- a/source/server/serverPlugin.h +++ b/source/server/serverPlugin.h @@ -1,104 +1,53 @@ -#ifndef UDA_SERVER_SERVERPLUGIN_H -#define UDA_SERVER_SERVERPLUGIN_H +#pragma once #include #include #include "clientserver/udaStructs.h" +#include "plugins/udaPlugin.h" #define REQUEST_READ_START 1000 #define REQUEST_PLUGIN_MCOUNT 100 // Maximum initial number of plugins that can be registered #define REQUEST_PLUGIN_MSTEP 10 // Increase heap by 10 records once the maximum is exceeded -enum pluginClass { - UDA_PLUGIN_CLASS_UNKNOWN, - UDA_PLUGIN_CLASS_FILE, // File format access - UDA_PLUGIN_CLASS_SERVER, // Server protocol access - UDA_PLUGIN_CLASS_FUNCTION, // Server-side function transformation - UDA_PLUGIN_CLASS_DEVICE, // Server to Server chaining, i.e. Pass the request to an external server - UDA_PLUGIN_CLASS_OTHER -}; - -struct PluginList; // Forward declaration -typedef struct PluginList PLUGINLIST; - -typedef struct UdaPluginInterface { // Standard Plugin interface - unsigned short interfaceVersion; // Interface Version - unsigned short pluginVersion; // Plugin Version - unsigned short sqlConnectionType; // Which SQL is the server connected to - unsigned short verbose; // Spare! Use (errout!=NULL) instead *** Deprecated - unsigned short housekeeping; // Housekeeping Directive - unsigned short changePlugin; // Use a different Plugin to access the data - FILE* dbgout; - FILE* errout; - uda::client_server::DATA_BLOCK* data_block; - uda::client_server::REQUEST_DATA* request_data; - uda::client_server::CLIENT_BLOCK* client_block; - uda::client_server::DATA_SOURCE* data_source; - uda::client_server::SIGNAL_DESC* signal_desc; - const uda::client_server::ENVIRONMENT* environment; // Server environment - LOGMALLOCLIST* logmalloclist; - USERDEFINEDTYPELIST* userdefinedtypelist; - void* sqlConnection; // Opaque structure - const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers - uda::client_server::UDA_ERROR_STACK error_stack; -} UDA_PLUGIN_INTERFACE; - -typedef int (*PLUGINFUNP)(UDA_PLUGIN_INTERFACE*); // Plugin function type - -typedef struct PluginData { - char format[STRING_LENGTH]; // File format, or Function library or Server protocol or External Device name - char library[STRING_LENGTH]; // external plugin shared library name (must be on Server library search path) - char symbol[STRING_LENGTH]; // external plugin symbol name - char method[STRING_LENGTH]; // Method to use for Data Readers (FILE Plugin Class) - char extension[STRING_LENGTH]; // File Extension (Not Case sensitive) - char deviceProtocol[STRING_LENGTH]; // Server protocol substitute for Device name - char deviceHost[STRING_LENGTH]; // Server Host substitute for Device name - char devicePort[STRING_LENGTH]; // Server Port substitute for Device name - char desc[STRING_LENGTH]; // Description of the plugin - char example[STRING_LENGTH]; // Examples of Use - int request; // unique request ID - unsigned short plugin_class; // the plugin class: File, Server, Function, Device - unsigned short external; // Flag the plugin is accessed via a separate shared library - unsigned short status; // Plugin operational: external library opened or internal - unsigned short is_private; // The service is private and can NOT be used by external clients - unsigned short cachePermission; // The server's internal state may be dependent on previous calls - // so the returned data are not suitable for caching on the client. - // This is used to inform the client how to manage the returned data - unsigned short interfaceVersion; // Maximum interface version the plugin is compliant with (Minimum is 1) - void* pluginHandle; // Plugin Library handle - PLUGINFUNP idamPlugin; // Plugin function address -} PLUGIN_DATA; - -struct PluginList { - int count; // the number of plugins - int mcount; // malloc count allocated - PLUGIN_DATA* plugin; -}; - -int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list); -int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list); -int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list); -int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list); -int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin_list); - -void allocPluginList(int count, PLUGINLIST* plugin_list); -void freePluginList(PLUGINLIST* plugin_list); -void initPluginData(PLUGIN_DATA* plugin); +namespace uda::server +{ + +int findPluginIdByRequest(int request, const uda::plugins::PluginList* plugin_list); + +int findPluginIdByFormat(const char* format, const uda::plugins::PluginList* plugin_list); + +int findPluginIdByDevice(const char* device, const uda::plugins::PluginList* plugin_list); + +int findPluginRequestByFormat(const char* format, const uda::plugins::PluginList* plugin_list); + +int findPluginRequestByExtension(const char* extension, const uda::plugins::PluginList* plugin_list); + +void allocPluginList(int count, uda::plugins::PluginList* plugin_list); + +void freePluginList(uda::plugins::PluginList* plugin_list); + +void initPluginData(uda::plugins::PluginData* plugin); + int udaServerRedirectStdStreams(int reset); + int udaServerPlugin(uda::client_server::REQUEST_DATA* request, uda::client_server::DATA_SOURCE* data_source, - uda::client_server::SIGNAL_DESC* signal_desc, const PLUGINLIST* plugin_list, + uda::client_server::SIGNAL_DESC* signal_desc, const uda::plugins::PluginList* plugin_list, const uda::client_server::ENVIRONMENT* environment); + int udaProvenancePlugin(uda::client_server::CLIENT_BLOCK* client_block, uda::client_server::REQUEST_DATA* original_request, uda::client_server::DATA_SOURCE* data_source, uda::client_server::SIGNAL_DESC* signal_desc, - const PLUGINLIST* plugin_list, const char* logRecord, + const uda::plugins::PluginList* plugin_list, const char* logRecord, const uda::client_server::ENVIRONMENT* environment); -int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const uda::client_server::ENVIRONMENT* environment); -int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, + +int udaServerMetaDataPluginId(const uda::plugins::PluginList* plugin_list, + const uda::client_server::ENVIRONMENT* environment); + +int udaServerMetaDataPlugin(const uda::plugins::PluginList* plugin_list, int plugin_id, uda::client_server::REQUEST_DATA* request_block, uda::client_server::SIGNAL_DESC* signal_desc, uda::client_server::SIGNAL* signal_rec, uda::client_server::DATA_SOURCE* data_source, const uda::client_server::ENVIRONMENT* environment); -#endif // UDA_SERVER_SERVERPLUGIN_H +} // namespace uda::server diff --git a/source/server/serverProcessing.cpp b/source/server/serverProcessing.cpp index 1209c52a..ddd144a6 100644 --- a/source/server/serverProcessing.cpp +++ b/source/server/serverProcessing.cpp @@ -222,7 +222,8 @@ int cast_data(uda::client_server::DATA_BLOCK* data_block, const uda::client_serv * @param data_block * @return 1 if an error occurred, otherwise 0 */ -int serverProcessing(uda::client_server::CLIENT_BLOCK client_block, uda::client_server::DATA_BLOCK* data_block) +int uda::server::serverProcessing(uda::client_server::CLIENT_BLOCK client_block, + uda::client_server::DATA_BLOCK* data_block) { int rc = 0; diff --git a/source/server/serverProcessing.h b/source/server/serverProcessing.h index 702090ae..7ed8d7dc 100644 --- a/source/server/serverProcessing.h +++ b/source/server/serverProcessing.h @@ -1,10 +1,10 @@ #pragma once -#ifndef UDA_SERVER_SERVERPROCESSING_H -# define UDA_SERVER_SERVERPROCESSING_H +#include "clientserver/udaStructs.h" -# include "clientserver/udaStructs.h" +namespace uda::server +{ int serverProcessing(uda::client_server::CLIENT_BLOCK client_block, uda::client_server::DATA_BLOCK* data_block); -#endif // UDA_SERVER_SERVERPROCESSING_H +} diff --git a/source/server/serverStartup.cpp b/source/server/serverStartup.cpp index bfe41dfc..fe5ac371 100644 --- a/source/server/serverStartup.cpp +++ b/source/server/serverStartup.cpp @@ -10,8 +10,9 @@ #include "getServerEnvironment.h" using namespace uda::client_server; +using namespace uda::server; -int startup() +int uda::server::startup() { //---------------------------------------------------------------- // Read Environment Variable Values (Held in a Global Structure) diff --git a/source/server/serverStartup.h b/source/server/serverStartup.h index 5d3d077b..2ff00dd5 100644 --- a/source/server/serverStartup.h +++ b/source/server/serverStartup.h @@ -1,8 +1,8 @@ #pragma once -#ifndef UDA_SERVER_SERVERSTARTUP_H -# define UDA_SERVER_SERVERSTARTUP_H +namespace uda::server +{ int startup(); -#endif // UDA_SERVER_SERVERSTARTUP_H +} diff --git a/source/server/serverSubsetData.cpp b/source/server/serverSubsetData.cpp index 7534a315..c77677a9 100644 --- a/source/server/serverSubsetData.cpp +++ b/source/server/serverSubsetData.cpp @@ -32,6 +32,7 @@ #include using namespace uda::client_server; +using namespace uda::server; //---------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------- @@ -1371,7 +1372,7 @@ int apply_functions(SUBSET subset, DATA_BLOCK* data_block) UDA_THROW_ERROR(999, "Unknown function"); } -int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST* logmalloclist) +int uda::server::serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST* logmalloclist) { printAction(action); printDataBlock(*data_block); @@ -1447,7 +1448,8 @@ int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST // SS::SUBSET(\"xx\", [*, 3], member=\"name\", reform) // SS::SUBSET(\"xx\", [*, 3], member=\"name\", reform, function=\"minimum(dim_id=0)\" ) -int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, const PLUGINLIST* plugin_list) +int uda::server::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, + const uda::plugins::PluginList* plugin_list) { ACTION* action = nullptr; SUBSET* subsets = nullptr; diff --git a/source/server/serverSubsetData.h b/source/server/serverSubsetData.h index 39d1e0e3..056e6661 100644 --- a/source/server/serverSubsetData.h +++ b/source/server/serverSubsetData.h @@ -5,7 +5,13 @@ #include "serverPlugin.h" #include "structures/genStructs.h" +namespace uda::server +{ + int serverSubsetData(uda::client_server::DATA_BLOCK* data_block, const uda::client_server::ACTION& action, LOGMALLOCLIST* logmalloclist); + int serverParseServerSide(uda::client_server::REQUEST_DATA* request_block, - uda::client_server::ACTIONS* actions_serverside, const PLUGINLIST* plugin_list); + uda::client_server::ACTIONS* actions_serverside, const uda::plugins::PluginList* plugin_list); + +} // namespace uda::server diff --git a/source/server/sleepServer.cpp b/source/server/sleepServer.cpp index dd35c131..7ac08c03 100644 --- a/source/server/sleepServer.cpp +++ b/source/server/sleepServer.cpp @@ -15,9 +15,10 @@ using namespace uda::client_server; -int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, - int server_tot_block_time, int server_timeout, IoData* io_data, int private_flags, int malloc_source) +int uda::server::sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, + LOGSTRUCTLIST* log_struct_list, int server_tot_block_time, int server_timeout, + IoData* io_data, int private_flags, int malloc_source) { int protocol_id, next_protocol, err, rc; diff --git a/source/server/sleepServer.h b/source/server/sleepServer.h index d2be209a..ba8a4ac7 100644 --- a/source/server/sleepServer.h +++ b/source/server/sleepServer.h @@ -1,16 +1,16 @@ #pragma once -#ifndef UDA_SERVER_SLEEPSERVER_H -# define UDA_SERVER_SLEEPSERVER_H +#include -# include +#include "createXDRStream.h" +#include "structures/genStructs.h" -# include "structures/genStructs.h" - -struct IoData; +namespace uda::server +{ int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, - int server_tot_block_time, int server_timeout, IoData* io_data, int private_flags, int malloc_source); + int server_tot_block_time, int server_timeout, uda::server::IoData* io_data, int private_flags, + int malloc_source); -#endif // UDA_SERVER_SLEEPSERVER_H +} diff --git a/source/server/udaLegacyServer.cpp b/source/server/udaLegacyServer.cpp index bb0d434e..4a7dd747 100644 --- a/source/server/udaLegacyServer.cpp +++ b/source/server/udaLegacyServer.cpp @@ -33,14 +33,16 @@ int idamLegacyServer(CLIENT_BLOCK client_block) #else using namespace uda::client_server; +using namespace uda::server; constexpr int server_version = 8; // Legacy Server Entry point -int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, SOCKETLIST* socket_list, int protocolVersion, - XDR* server_input, XDR* server_output, unsigned int private_flags, int malloc_source) +int uda::server::legacyServer(CLIENT_BLOCK client_block, const uda::plugins::PluginList* pluginlist, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + SOCKETLIST* socket_list, int protocolVersion, XDR* server_input, XDR* server_output, + unsigned int private_flags, int malloc_source) { int rc, err = 0, depth, fatal = 0; @@ -68,7 +70,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL int server_tot_block_time = 0; int server_timeout = TIMEOUT; // user specified Server Lifetime - IoData io_data = {}; + uda::server::IoData io_data = {}; io_data.server_tot_block_time = &server_tot_block_time; io_data.server_timeout = &server_timeout; @@ -351,8 +353,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL for (int i = 0; i < request_block.num_requests; ++i) { auto request = &request_block.requests[i]; if (protocolVersion >= 6) { - if ((err = udaServerPlugin(request, &data_source, &signal_desc, pluginlist, - getServerEnvironment())) != 0) { + if ((err = uda::server::udaServerPlugin(request, &data_source, &signal_desc, pluginlist, + getServerEnvironment())) != 0) { break; } } else { diff --git a/source/server/udaLegacyServer.h b/source/server/udaLegacyServer.h index 73a78095..2fdbed47 100644 --- a/source/server/udaLegacyServer.h +++ b/source/server/udaLegacyServer.h @@ -5,10 +5,15 @@ #include "serverPlugin.h" #include "uda/types.h" +namespace uda::server +{ + /** * UDA Legacy Data Server (protocol versions <= 6) */ -int legacyServer(uda::client_server::CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, +int legacyServer(uda::client_server::CLIENT_BLOCK client_block, const uda::plugins::PluginList* pluginlist, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, uda::client_server::SOCKETLIST* socket_list, int protocolVersion, XDR* server_input, XDR* server_output, unsigned int private_flags, int malloc_source); + +} // namespace uda::server diff --git a/source/server/udaServer.cpp b/source/server/udaServer.cpp index 293d674d..39a7a281 100644 --- a/source/server/udaServer.cpp +++ b/source/server/udaServer.cpp @@ -1,3 +1,5 @@ +#include "udaServer.h" + #include #include #if defined(__GNUC__) @@ -41,6 +43,7 @@ #endif using namespace uda::client_server; +using namespace uda::server; //-------------------------------------------------------------------------------------- // static globals @@ -69,8 +72,8 @@ USERDEFINEDTYPELIST parsed_user_defined_type_list; // Initial set of User Define // Total amount sent for the last data request -static PLUGINLIST plugin_list; // List of all data reader plugins (internal and external shared libraries) -ENVIRONMENT environment; // Holds local environment variable values +static uda::plugins::PluginList plugin_list; // List of all data reader plugins (internal and external shared libraries) +ENVIRONMENT environment; // Holds local environment variable values static SOCKETLIST socket_list; @@ -82,7 +85,8 @@ typedef struct MetadataBlock { DATA_SYSTEM data_system; } METADATA_BLOCK; -static int startup_server(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_output, IoData* io_data); +static int startup_server(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_output, + uda::server::IoData* io_data); static int handle_request(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, METADATA_BLOCK* metadata_block, ACTIONS* actions_desc, ACTIONS* actions_sig, @@ -113,7 +117,7 @@ static int handshake_client(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_blo //-------------------------------------------------------------------------------------- // Server Entry point -int uda_server(CLIENT_BLOCK client_block) +int uda::server::uda_server(uda::client_server::CLIENT_BLOCK client_block) { int err = 0; METADATA_BLOCK metadata_block; @@ -1129,7 +1133,7 @@ int handshake_client(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int return err; } -int startup_server(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_output, IoData* io_data) +int startup_server(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_output, uda::server::IoData* io_data) { static int socket_list_initialised = 0; static int plugin_list_initialised = 0; diff --git a/source/server/udaServer.h b/source/server/udaServer.h index 4060faac..619fc1da 100644 --- a/source/server/udaServer.h +++ b/source/server/udaServer.h @@ -2,7 +2,12 @@ #include "clientserver/udaStructs.h" +namespace uda::server +{ + int uda_server(uda::client_server::CLIENT_BLOCK client_block); int fat_server(uda::client_server::CLIENT_BLOCK client_block, uda::client_server::SERVER_BLOCK* server_block, uda::client_server::REQUEST_BLOCK* request_block0, uda::client_server::DATA_BLOCK_LIST* data_blocks0); + +} // namespace uda::server diff --git a/source/server/writer.cpp b/source/server/writer.cpp index 32969fc7..bfe454b1 100644 --- a/source/server/writer.cpp +++ b/source/server/writer.cpp @@ -15,29 +15,6 @@ int serverSocket = 0; -void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) -{ - FD_ZERO(rfds); // Initialise the File Descriptor set - FD_SET(fd, rfds); // Identify the Socket in the FD set - tv->tv_sec = 0; - tv->tv_usec = MIN_BLOCK_TIME; // minimum wait microsecs (1ms) - *server_tot_block_time = 0; -} - -void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time) -{ - FD_ZERO(rfds); - FD_SET(fd, rfds); - if (server_tot_block_time < MAXBLOCK) { - // (ms) For the First blocking period have rapid response (clientserver/udaDefines.h == 1000) - tv->tv_sec = 0; - tv->tv_usec = MIN_BLOCK_TIME; // minimum wait (1ms) - } else { - tv->tv_sec = 0; - tv->tv_usec = MAX_BLOCK_TIME; // maximum wait (10ms) - } -} - /* //----------------------------------------------------------------------------------------- // This routine is only called when the Server expects to Read something from the Client @@ -62,14 +39,16 @@ void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_ //----------------------------------------------------------------------------------------- */ -int server_read(void* iohandle, char* buf, int count) +using namespace uda::client_server; + +int uda::server::server_read(void* iohandle, char* buf, int count) { int rc = 0; fd_set rfds; // File Descriptor Set for Reading from the Socket timeval tv = {}; timeval tvc = {}; - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); // Wait until there are data to be read from the socket @@ -102,7 +81,7 @@ int server_read(void* iohandle, char* buf, int count) return rc; } -int server_write(void* iohandle, char* buf, int count) +int uda::server::server_write(void* iohandle, char* buf, int count) { // This routine is only called when there is something to write back to the Client @@ -113,7 +92,7 @@ int server_write(void* iohandle, char* buf, int count) fd_set wfds; // File Descriptor Set for Writing to the Socket timeval tv = {}; - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); // Block IO until the Socket is ready to write to Client diff --git a/source/server/writer.h b/source/server/writer.h index 26fd745d..4dd74b51 100644 --- a/source/server/writer.h +++ b/source/server/writer.h @@ -1,24 +1,19 @@ #pragma once -#ifndef UDA_SERVER_WRITER_H -# define UDA_SERVER_WRITER_H +#if defined(__GNUC__) +# include +#endif +#include -# if defined(__GNUC__) -# include -# endif -# include +#ifdef _WIN32 +# include // must be included before connection.h to avoid macro redefinition in rpc/types.h +#else +# include +#endif -# ifdef _WIN32 -# include // must be included before connection.h to avoid macro redefinition in rpc/types.h -# else -# include -# endif +namespace uda::server +{ -# define MIN_BLOCK_TIME 1000 -# define MAX_BLOCK_TIME 10000 - -void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time); -void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time); int server_write(void* iohandle, char* buf, int count); /* @@ -46,4 +41,4 @@ int server_write(void* iohandle, char* buf, int count); */ int server_read(void* iohandle, char* buf, int count); -#endif // UDA_SERVER_WRITER_H +} // namespace uda::server diff --git a/source/server2/get_data.cpp b/source/server2/get_data.cpp index be0b75cf..61326688 100644 --- a/source/server2/get_data.cpp +++ b/source/server2/get_data.cpp @@ -16,6 +16,7 @@ #include using namespace uda::client_server; +using namespace uda::plugins; namespace { @@ -1087,7 +1088,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) // Test for known File formats and Server protocols { - UDA_PLUGIN_INTERFACE plugin_interface; + UdaPluginInterface plugin_interface; UDA_LOG(UDA_LOG_DEBUG, "creating the plugin interface structure\n"); diff --git a/source/server2/get_plugin_address.cpp b/source/server2/get_plugin_address.cpp index 84c00ad8..20a700d8 100644 --- a/source/server2/get_plugin_address.cpp +++ b/source/server2/get_plugin_address.cpp @@ -8,6 +8,7 @@ #include "logging/logging.h" using namespace uda::client_server; +using namespace uda::plugins; /** * Return the function address for plugin data readers located in external shared libraries diff --git a/source/server2/get_plugin_address.hpp b/source/server2/get_plugin_address.hpp index 45c1d410..c1427cd9 100644 --- a/source/server2/get_plugin_address.hpp +++ b/source/server2/get_plugin_address.hpp @@ -4,6 +4,6 @@ namespace uda { -int get_plugin_address(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp); +int get_plugin_address(void** pluginHandle, const char* library, const char* symbol, uda::plugins::PLUGINFUNP* pluginfunp); } diff --git a/source/server2/plugins.cpp b/source/server2/plugins.cpp index b443653e..643ac1ac 100644 --- a/source/server2/plugins.cpp +++ b/source/server2/plugins.cpp @@ -15,11 +15,12 @@ #define REQUEST_READ_START 1000 using namespace uda::client_server; +using namespace uda::plugins; namespace { -void init_plugin_data(PluginData* plugin) +void init_plugin_data(uda::plugins::PluginData* plugin) { plugin->format[0] = '\0'; plugin->library[0] = '\0'; @@ -42,7 +43,7 @@ void init_plugin_data(PluginData* plugin) plugin->idamPlugin = nullptr; } -int process_line(const std::string& line, PluginData& plugin) +int process_line(const std::string& line, uda::plugins::PluginData& plugin) { std::vector tokens; boost::split(tokens, line, boost::is_any_of(","), boost::token_compress_on); @@ -266,7 +267,7 @@ void uda::Plugins::process_config_file(std::ifstream& conf_file) cachePermission and publicUse may use one of the following values: "Y|N,1|0,T|F,True|False" */ - PluginData plugin = {}; + uda::plugins::PluginData plugin = {}; int rc = 0; static int offset = 0; @@ -405,17 +406,17 @@ void uda::Plugins::close() plugins_.clear(); } -PLUGINLIST uda::Plugins::as_plugin_list() const +uda::plugins::PluginList uda::Plugins::as_plugin_list() const { - PLUGINLIST plugin_list = {}; - plugin_list.plugin = (PluginData*)plugins_.data(); + uda::plugins::PluginList plugin_list = {}; + plugin_list.plugin = (uda::plugins::PluginData*)plugins_.data(); plugin_list.count = (int)plugins_.size(); plugin_list.mcount = (int)plugins_.size(); return plugin_list; } -boost::optional uda::Plugins::find_by_format(const char* format) const +boost::optional uda::Plugins::find_by_format(const char* format) const { for (auto& plugin : plugins_) { if (STR_IEQUALS(plugin.format, format)) { @@ -425,7 +426,7 @@ boost::optional uda::Plugins::find_by_format(const char* form return {}; } -boost::optional uda::Plugins::find_by_request(int request) const +boost::optional uda::Plugins::find_by_request(int request) const { for (auto& plugin : plugins_) { if (plugin.request == request) { diff --git a/source/server2/plugins.hpp b/source/server2/plugins.hpp index 4e3dbd93..57c8d63e 100644 --- a/source/server2/plugins.hpp +++ b/source/server2/plugins.hpp @@ -7,48 +7,8 @@ #include #include "clientserver/udaDefines.h" - -enum pluginClass { - UDA_PLUGIN_CLASS_UNKNOWN, - UDA_PLUGIN_CLASS_FILE, // File format access - UDA_PLUGIN_CLASS_SERVER, // Server protocol access - UDA_PLUGIN_CLASS_FUNCTION, // Server-side function transformation - UDA_PLUGIN_CLASS_DEVICE, // Server to Server chaining, i.e. Pass the request to an external server - UDA_PLUGIN_CLASS_OTHER -}; - -typedef struct UdaPluginInterface UDA_PLUGIN_INTERFACE; -typedef int (*PLUGINFUNP)(UDA_PLUGIN_INTERFACE*); // Plugin function type - -struct PluginData { - char format[STRING_LENGTH]; // File format, or Function library or Server protocol or External Device name - char library[STRING_LENGTH]; // external plugin shared library name (must be on Server library search path) - char symbol[STRING_LENGTH]; // external plugin symbol name - char method[STRING_LENGTH]; // Method to use for Data Readers (FILE Plugin Class) - char extension[STRING_LENGTH]; // File Extension (Not Case sensitive) - char deviceProtocol[STRING_LENGTH]; // Server protocol substitute for Device name - char deviceHost[STRING_LENGTH]; // Server Host substitute for Device name - char devicePort[STRING_LENGTH]; // Server Port substitute for Device name - char desc[STRING_LENGTH]; // Description of the plugin - char example[STRING_LENGTH]; // Examples of Use - int request; // unique request ID - unsigned short plugin_class; // the plugin class: File, Server, Function, Device - unsigned short external; // Flag the plugin is accessed via a separate shared library - unsigned short status; // Plugin operational: external library opened or internal - unsigned short is_private; // The service is private and can NOT be used by external clients - unsigned short cachePermission; // The server's internal state may be dependent on previous calls - // so the returned data are not suitable for caching on the client. - // This is used to inform the client how to manage the returned data - unsigned short interfaceVersion; // Maximum interface version the plugin is compliant with (Minimum is 1) - void* pluginHandle; // Plugin Library handle - PLUGINFUNP idamPlugin; // Plugin function address -}; - -typedef struct PluginList { - int count; // the number of plugins - int mcount; // malloc count allocated - PluginData* plugin; -} PLUGINLIST; +#include "clientserver/udaStructs.h" +#include "plugins/udaPlugin.h" namespace uda { @@ -58,13 +18,13 @@ class Plugins { void close(); - [[nodiscard]] PLUGINLIST as_plugin_list() const; + [[nodiscard]] uda::plugins::PluginList as_plugin_list() const; - [[nodiscard]] boost::optional find_by_format(const char* format) const; - [[nodiscard]] boost::optional find_by_request(int request) const; + [[nodiscard]] boost::optional find_by_format(const char* format) const; + [[nodiscard]] boost::optional find_by_request(int request) const; private: - std::vector plugins_; + std::vector plugins_; void init_serverside_functions(); diff --git a/source/server2/server_plugin.cpp b/source/server2/server_plugin.cpp index 7b7e2ec0..0c059039 100644 --- a/source/server2/server_plugin.cpp +++ b/source/server2/server_plugin.cpp @@ -33,6 +33,7 @@ #define REQUEST_PLUGIN_MSTEP 10 // Increase heap by 10 records once the maximum is exceeded using namespace uda::client_server; +using namespace uda::plugins; int uda::serverRedirectStdStreams(int reset) { @@ -251,7 +252,7 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque // Identify the Provenance Gathering plugin (must be a function library type plugin) static bool initialised = false; - static boost::optional plugin = {}; + static boost::optional plugin = {}; static int exec_method = 1; // The default method used to write efficiently to the backend SQL server char* env = nullptr; @@ -326,7 +327,7 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque int err, rc, reset; DataBlock data_block = {}; - UdaPluginInterface plugin_interface = {}; + uda::plugins::UdaPluginInterface plugin_interface = {}; // Initialise the Data Block @@ -373,7 +374,7 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque UDA_LOG(UDA_LOG_DEBUG, "entering the provenance plugin\n"); - err = plugin->idamPlugin(&plugin_interface); + err = plugin->idamPlugin(static_cast(&plugin_interface)); UDA_LOG(UDA_LOG_DEBUG, "returned from the provenance plugin\n"); @@ -417,10 +418,11 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque //------------------------------------------------------------------------------------------------ // Identify the Plugin to use to resolve Generic Name mappings and return its ID -boost::optional uda::find_metadata_plugin(const Plugins& plugins, const server::Environment& environment) +boost::optional uda::find_metadata_plugin(const Plugins& plugins, + const server::Environment& environment) { static bool no_plugin_registered = false; - static boost::optional plugin = {}; + static boost::optional plugin = {}; UDA_LOG(UDA_LOG_DEBUG, "Entered: no_plugin_registered state = %d\n", no_plugin_registered); @@ -471,12 +473,12 @@ boost::optional uda::find_metadata_plugin(const Plugins& plugins, co //------------------------------------------------------------------------------------------------ // Execute the Generic Name mapping Plugin -int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_block, +int uda::call_metadata_plugin(const uda::plugins::PluginData& plugin, RequestData* request_block, const server::Environment& environment, const uda::Plugins& plugins, uda::MetadataBlock& metadata) { int err, reset, rc; - UdaPluginInterface plugin_interface = {}; + uda::plugins::UdaPluginInterface plugin_interface = {}; // Check the Interface Compliance diff --git a/source/server2/server_plugin.h b/source/server2/server_plugin.h index 6397437e..74a4a646 100644 --- a/source/server2/server_plugin.h +++ b/source/server2/server_plugin.h @@ -3,38 +3,13 @@ #include "clientserver/udaStructs.h" #include "plugins.hpp" +#include "plugins/udaPlugin.h" #include "uda/types.h" #define REQUEST_READ_START 1000 #define REQUEST_PLUGIN_MCOUNT 100 // Maximum initial number of plugins that can be registered #define REQUEST_PLUGIN_MSTEP 10 // Increase heap by 10 records once the maximum is exceeded -typedef struct PluginList PLUGINLIST; - -typedef struct UdaPluginInterface { // Standard Plugin interface - unsigned short interfaceVersion; // Interface Version - unsigned short pluginVersion; // Plugin Version - unsigned short sqlConnectionType; // Which SQL is the server connected to - unsigned short verbose; // Spare! Use (errout!=NULL) instead *** Deprecated - unsigned short housekeeping; // Housekeeping Directive - unsigned short changePlugin; // Use a different Plugin to access the data - FILE* dbgout; - FILE* errout; - uda::client_server::DATA_BLOCK* data_block; - uda::client_server::REQUEST_DATA* request_data; - uda::client_server::CLIENT_BLOCK* client_block; - uda::client_server::DATA_SOURCE* data_source; - uda::client_server::SIGNAL_DESC* signal_desc; - const uda::client_server::ENVIRONMENT* environment; // Server environment - LOGMALLOCLIST* logmalloclist; - USERDEFINEDTYPELIST* userdefinedtypelist; - void* sqlConnection; // Opaque structure - const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers - uda::client_server::UDA_ERROR_STACK error_stack; -} UDA_PLUGIN_INTERFACE; - -struct PluginData; - namespace uda { @@ -56,11 +31,12 @@ int provenancePlugin(uda::client_server::ClientBlock* client_block, uda::client_ const Plugins& plugins, const char* logRecord, const server::Environment& environment, uda::MetadataBlock& metadata); -int call_metadata_plugin(const PluginData& plugin, uda::client_server::RequestData* request_block, +int call_metadata_plugin(const uda::plugins::PluginData& plugin, uda::client_server::RequestData* request_block, const server::Environment& environment, const uda::Plugins& plugins, uda::MetadataBlock& metadata); -boost::optional find_metadata_plugin(const Plugins& plugins, const server::Environment& environment); +boost::optional find_metadata_plugin(const Plugins& plugins, + const server::Environment& environment); } // namespace uda diff --git a/source/server2/xdr_protocol.cpp b/source/server2/xdr_protocol.cpp index 31d57654..461cca86 100644 --- a/source/server2/xdr_protocol.cpp +++ b/source/server2/xdr_protocol.cpp @@ -31,34 +31,8 @@ using namespace uda::client_server; -constexpr int MinBlockTime = 1000; -constexpr int MaxBlockTime = 10000; - int serverSocket = 0; -void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) -{ - FD_ZERO(rfds); // Initialise the File Descriptor set - FD_SET(fd, rfds); // Identify the Socket in the FD set - tv->tv_sec = 0; - tv->tv_usec = MinBlockTime; // minimum wait microsecs (1ms) - *server_tot_block_time = 0; -} - -void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time) -{ - FD_ZERO(rfds); - FD_SET(fd, rfds); - if (server_tot_block_time < MAXBLOCK) { - // (ms) For the First blocking period have rapid response (clientserver/udaDefines.h == 1000) - tv->tv_sec = 0; - tv->tv_usec = MinBlockTime; // minimum wait (1ms) - } else { - tv->tv_sec = 0; - tv->tv_usec = MaxBlockTime; // maximum wait (10ms) - } -} - int server_read(void* iohandle, char* buf, int count) { int rc = 0; @@ -66,7 +40,7 @@ int server_read(void* iohandle, char* buf, int count) timeval tv = {}; timeval tvc = {}; - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); // Wait until there are data to be read from the socket @@ -110,7 +84,7 @@ int server_write(void* iohandle, char* buf, int count) fd_set wfds; // File Descriptor Set for Writing to the Socket timeval tv = {}; - auto io_data = reinterpret_cast(iohandle); + auto io_data = reinterpret_cast(iohandle); // Block IO until the Socket is ready to write to Client diff --git a/source/server2/xdr_protocol.hpp b/source/server2/xdr_protocol.hpp index 5d91a503..b0409afd 100644 --- a/source/server2/xdr_protocol.hpp +++ b/source/server2/xdr_protocol.hpp @@ -11,14 +11,19 @@ #include "structures/genStructs.h" #include "cache/memcache.hpp" #include "server_environment.hpp" +#include "clientserver/protocol.h" -struct IoData +namespace uda { + +namespace server { + +struct IoData : uda::client_server::IoData { int* server_tot_block_time; int* server_timeout; }; -namespace uda { +} struct MetadataBlock; @@ -63,7 +68,7 @@ class XdrProtocol XDR server_output_; int server_tot_block_time_; int server_timeout_; - IoData io_data_; + uda::server::IoData io_data_; LogStructList log_struct_list_; int malloc_source_; int private_flags_;