diff --git a/docs/creating_plugins.md b/docs/creating_plugins.md index bc56a98c..83490711 100644 --- a/docs/creating_plugins.md +++ b/docs/creating_plugins.md @@ -28,18 +28,18 @@ called by the UDA server. The entry function must look like: -`int entryFunction(IDAM_PLUGIN_INTERFACE*)` +`int entryFunction(UDA_PLUGIN_INTERFACE*)` Then function can have any name — the name is specified in the plugin configuration -file, see below. The `IDAM_PLUGIN_INTERFACE` is a structure defined in `uda/plugins.h` +file, see below. The `UDA_PLUGIN_INTERFACE` is a structure defined in `uda/plugins.h` and provides a mechanism for the plugin to interact with the UDA server — reading the function arguments, returning the resultant data, etc. The returned `int` value specifies the return state of the plugin call — zero for success or non-zero for an error state -(the actual error is returned via the `IDAM_PLUGIN_INTERFACE`). +(the actual error is returned via the `UDA_PLUGIN_INTERFACE`). ## Accessing function name and arguments -The function being called is provided in the `IDAM_PLUGIN_INTERFACE` structure passed into +The function being called is provided in the `UDA_PLUGIN_INTERFACE` structure passed into entry function as a C-string (`const char*`) via: `plugin_interface->request->function` diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt index fe418b81..b2fb0088 100755 --- a/source/CMakeLists.txt +++ b/source/CMakeLists.txt @@ -79,16 +79,13 @@ set( HEADERS include/clientMDS.h include/export.h include/genStructs.h - include/initStructs.h include/legacy.h - include/pluginStructs.h include/struct.h include/udaDefines.h include/udaErrors.h include/udaGetAPI.h include/udaPlugin.h include/udaPutAPI.h - include/udaStructs.h include/udaTypes.h ) install( FILES uda.h ${CMAKE_BINARY_DIR}/source/version.h DESTINATION include/uda ) diff --git a/source/c_api/accAPI.cpp b/source/c_api/accAPI.cpp index aa4c1862..3ce3c07f 100644 --- a/source/c_api/accAPI.cpp +++ b/source/c_api/accAPI.cpp @@ -4,7 +4,6 @@ #include #ifdef __GNUC__ -# include # include #else # include @@ -20,7 +19,7 @@ #include "clientserver/protocol.h" #include "clientserver/stringUtils.h" #include "clientserver/xdrlib.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "struct.h" #include "version.h" @@ -35,194 +34,15 @@ # include #endif -static std::vector data_blocks = {}; +USERDEFINEDTYPE* getIdamUserDefinedType(int handle); +USERDEFINEDTYPELIST* getIdamUserDefinedTypeList(int handle); +LOGMALLOCLIST* getIdamLogMallocList(int handle); //---------------------------- Mutex locking for thread safety ------------------------- // State variable sets should be collected and managed for each individual thread! static int idamThreadLastHandle = -1; -#ifndef NOPTHREADS - -typedef struct { - int id; // Thread identifier assigned by the application - int socket; // Either a shared or private server socket connection - int lastHandle; - ENVIRONMENT environment; // State - CLIENT_BLOCK client_block; - SERVER_BLOCK server_block; -} IDAMSTATE; - -# ifdef __GNUC__ -typedef pthread_t thread_t; -typedef pthread_mutex_t lock_t; - -static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -# else -typedef HANDLE lock_t; -typedef HANDLE thread_t; - -static HANDLE lock; -# endif - -// STATE management - -static IDAMSTATE idamState[UDA_NUM_CLIENT_THREADS]; // Threads are managed by the application, not IDAM -static thread_t threadList[UDA_NUM_CLIENT_THREADS]; -static int threadCount = 0; - -int getIdamMaxThreadCount() -{ - return UDA_NUM_CLIENT_THREADS; -} - -/** - * Search the set of registered threads for the State ID - * @param id - * @return - */ -int getThreadId(thread_t id) -{ - for (int i = 0; i < threadCount; i++) { -# ifdef __GNUC__ - if (pthread_equal(id, threadList[i])) { - return i; - } -# else - if (GetThreadId(id) == GetThreadId(threadList[i])) { - return i; - } -# endif - } - return -1; -} - -// Lock the thread and set the previous STATE -void lockIdamThread(CLIENT_FLAGS* client_flags) -{ - static unsigned int mutex_initialised = 0; - - if (!mutex_initialised) { -# ifndef __GNUC__ - lock = CreateMutex(nullptr, FALSE, nullptr); -# endif - } - - // Apply the lock first -# ifdef __GNUC__ - pthread_mutex_lock(&lock); -# else - WaitForSingleObject(lock, INFINITE); -# endif - - // Identify the Current Thread - -# ifdef __GNUC__ - thread_t threadId = pthread_self(); -# else - thread_t threadId = GetCurrentThread(); -# endif - - // Initialise the thread's state - - if (!mutex_initialised) { - mutex_initialised = 1; - for (int i = 0; i < UDA_NUM_CLIENT_THREADS; i++) { // Initialise the STATE array - idamState[i].id = i; - idamState[i].socket = -1; - idamState[i].lastHandle = -1; - // initEnvironment(&(idamState[i].environment)); - initClientBlock(&(idamState[i].client_block), 0, ""); - initServerBlock(&(idamState[i].server_block), 0); - threadList[i] = 0; // and the thread identifiers - } - } - - // Retain unique thread IDs - - int id = getThreadId(threadId); - - if (threadCount < UDA_NUM_CLIENT_THREADS && id == -1) { - // Preserve the thread ID if not registered - threadList[++threadCount - 1] = threadId; - } - - // Assign State for the current thread if previously registered - - if (id >= 0) { - putIdamServerSocket(idamState[id].socket); - // putIdamClientEnvironment(&idamState[id].environment); - putIdamThreadClientBlock(&idamState[id].client_block); - putIdamThreadServerBlock(&idamState[id].server_block); - client_flags->flags = idamState[id].client_block.clientFlags; - putIdamThreadLastHandle(idamState[id].lastHandle); - } else { - putIdamThreadLastHandle(-1); - } -} - -/** - * Unlock the thread and save the current STATE - */ -void unlockUdaThread(CLIENT_FLAGS* client_flags) -{ -# ifdef __GNUC__ - thread_t threadId = pthread_self(); -# else - thread_t threadId = GetCurrentThread(); -# endif - int id = getThreadId(threadId); // Must be registered - if (id >= 0) { - idamState[id].socket = getIdamServerSocket(); - // idamState[id].environment = *getIdamClientEnvironment(); - idamState[id].client_block = getIdamThreadClientBlock(); - idamState[id].server_block = getIdamThreadServerBlock(); - idamState[id].client_block.clientFlags = client_flags->flags; - idamState[id].lastHandle = getIdamThreadLastHandle(); - } -# ifdef __GNUC__ - pthread_mutex_unlock(&lock); -# else - ReleaseMutex(lock); -# endif -} - -/** - * Free thread resources - */ -void freeIdamThread(CLIENT_FLAGS* client_flags) -{ - lockIdamThread(client_flags); -# ifdef __GNUC__ - thread_t threadId = pthread_self(); -# else - thread_t threadId = GetCurrentThread(); -# endif - int id = getThreadId(threadId); - threadCount--; - if (id >= 0) { - for (int i = id; i < threadCount; i++) { - threadList[i] = threadList[i + 1]; // Shuffle state - idamState[i] = idamState[i + 1]; - idamState[i].id = i; - } - idamState[threadCount].id = threadCount; - idamState[threadCount].socket = -1; - idamState[threadCount].lastHandle = -1; - // initEnvironment(&(idamState[threadCount].environment)); - initClientBlock(&(idamState[threadCount].client_block), 0, ""); - initServerBlock(&(idamState[threadCount].server_block), 0); - threadList[threadCount] = 0; - } - unlockUdaThread(client_flags); -} - -#else -void lockIdamThread() {} -void unlockIdamThread() {} -void freeIdamThread() {} -#endif // NOPTHREADS - int getIdamThreadLastHandle() { return idamThreadLastHandle; @@ -236,85 +56,7 @@ void putIdamThreadLastHandle(int handle) //-------------------------------------------------------------------------------------- // C Accessor Routines -void acc_freeDataBlocks() -{ - data_blocks.clear(); - putIdamThreadLastHandle(-1); -} - -DATA_BLOCK* acc_getCurrentDataBlock(CLIENT_FLAGS* client_flags) -{ - if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && - getIdamThreadLastHandle() >= 0) { - return &data_blocks[getIdamThreadLastHandle()]; - } - return &data_blocks.back(); -} - -int acc_getCurrentDataBlockIndex(CLIENT_FLAGS* client_flags) -{ - if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && - getIdamThreadLastHandle() >= 0) { - return getIdamThreadLastHandle(); - } - return data_blocks.size() - 1; -} - -int acc_growIdamDataBlocks(CLIENT_FLAGS* client_flags) -{ - if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && - getIdamThreadLastHandle() >= 0) { - return 0; - } - - data_blocks.push_back({}); - initDataBlock(&data_blocks.back()); - data_blocks.back().handle = data_blocks.size() - 1; - - putIdamThreadLastHandle(data_blocks.size() - 1); - - return 0; -} - -static int findNewHandleIndex() -{ - for (int i = 0; i < (int)data_blocks.size(); i++) { - if (data_blocks[i].handle == -1) { - return i; - } - } - return -1; -} - -int acc_getIdamNewDataHandle(CLIENT_FLAGS* client_flags) -{ - int newHandleIndex = -1; - - if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && - (newHandleIndex = getIdamThreadLastHandle()) >= 0) { - if (client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) { - udaFree(newHandleIndex); - } else { - // Application has responsibility for freeing heap in the Data Block - initDataBlock(&data_blocks[newHandleIndex]); - } - data_blocks[newHandleIndex].handle = newHandleIndex; - return newHandleIndex; - } - - if ((newHandleIndex = findNewHandleIndex()) < 0) { // Search for an unused handle or issue a new one - newHandleIndex = data_blocks.size(); - data_blocks.push_back({}); - initDataBlock(&data_blocks[newHandleIndex]); - data_blocks[newHandleIndex].handle = newHandleIndex; - } else { - initDataBlock(&data_blocks[newHandleIndex]); - data_blocks[newHandleIndex].handle = newHandleIndex; - } - putIdamThreadLastHandle(newHandleIndex); - return newHandleIndex; -} //-------------------------------------------------------------- /* Notes: @@ -364,33 +106,6 @@ void resetIdamPrivateFlag(unsigned int flag) *private_flags &= !flag; } -//-------------------------------------------------------------- -// Client Flags - -//! Set a client_flags->flags property -/** Set a/multiple specific bit/s in the client_flags->flags property sent to the UDA server. - * - * @param flag The bit/s to be set to 1. - * @return Void. - */ - -void setIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) -{ - client_flags->flags = client_flags->flags | flag; -} - -//! Reset a client_flags->flags property -/** Reset a/multiple specific bit/s in the client_flags->flags property sent to the UDA server. - * - * @param flag The bit/s to be set to 0. - * @return Void. - */ - -void resetIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) -{ - client_flags->flags &= !flag; -} - //-------------------------------------------------------------- // Set Server Properties @@ -419,8 +134,10 @@ void resetIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) * @param property the name of the property to set true or a name value pair. * @return Void. */ -void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags) +void setIdamProperty(const char* property) { + auto client_flags = udaClientFlags(); + // User settings for Client and Server behaviour char name[56]; @@ -519,8 +236,10 @@ void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags) * @param property the name of the property. * @return Void. */ -int getIdamProperty(const char* property, const CLIENT_FLAGS* client_flags) +int getIdamProperty(const char* property) { + auto client_flags = udaClientFlags(); + // User settings for Client and Server behaviour if (property[0] == 'g') { @@ -595,8 +314,10 @@ int getIdamProperty(const char* property, const CLIENT_FLAGS* client_flags) * @return Void. */ -void resetIdamProperty(const char* property, CLIENT_FLAGS* client_flags) +void resetIdamProperty(const char* property) { + auto client_flags = udaClientFlags(); + // User settings for Client and Server behaviour if (property[0] == 'g') { @@ -665,8 +386,10 @@ void resetIdamProperty(const char* property, CLIENT_FLAGS* client_flags) /** * @return Void. */ -void resetIdamProperties(CLIENT_FLAGS* client_flags) +void resetIdamProperties() { + auto client_flags = udaClientFlags(); + // Reset on Both Client and Server client_flags->get_datadble = 0; @@ -696,10 +419,11 @@ void resetIdamProperties(CLIENT_FLAGS* client_flags) */ CLIENT_BLOCK* getIdamProperties(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return &data_blocks[handle].client_block; + return &data_block->client_block; } //! Return the client state associated with a specific data item @@ -745,45 +469,47 @@ int getIdamMemoryUsed() void putIdamErrorModel(int handle, int model, int param_n, const float* params) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { return; // No valid Model } - data_blocks[handle].error_model = model; // Model ID - data_blocks[handle].error_param_n = param_n; // Number of parameters + data_block->error_model = model; // Model ID + data_block->error_param_n = param_n; // Number of parameters if (param_n > MAXERRPARAMS) { - data_blocks[handle].error_param_n = MAXERRPARAMS; + data_block->error_param_n = MAXERRPARAMS; } - for (int i = 0; i < data_blocks[handle].error_param_n; i++) { - data_blocks[handle].errparams[i] = params[i]; + for (int i = 0; i < data_block->error_param_n; i++) { + data_block->errparams[i] = params[i]; } } void putIdamDimErrorModel(int handle, int ndim, int model, int param_n, const float* params) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - if (ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { + if (ndim < 0 || (unsigned int)ndim >= data_block->rank) { return; // No Dim } if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { return; // No valid Model } - data_blocks[handle].dims[ndim].error_model = model; // Model ID - data_blocks[handle].dims[ndim].error_param_n = param_n; // Number of parameters + data_block->dims[ndim].error_model = model; // Model ID + data_block->dims[ndim].error_param_n = param_n; // Number of parameters if (param_n > MAXERRPARAMS) { - data_blocks[handle].dims[ndim].error_param_n = MAXERRPARAMS; + data_block->dims[ndim].error_param_n = MAXERRPARAMS; } - for (int i = 0; i < data_blocks[handle].dims[ndim].error_param_n; i++) { - data_blocks[handle].dims[ndim].errparams[i] = params[i]; + for (int i = 0; i < data_block->dims[ndim].error_param_n; i++) { + data_block->dims[ndim].errparams[i] = params[i]; } } @@ -916,10 +642,11 @@ int getIdamServerSocket() int getIdamErrorCode(int handle) { // Error Code Returned from Server - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return getIdamServerErrorStackRecordCode(0); } else { - return data_blocks[handle].errcode; + return data_block->errcode; } } @@ -931,10 +658,11 @@ int getIdamErrorCode(int handle) const char* getIdamErrorMsg(int handle) { // Error Message returned from server - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return getIdamServerErrorStackRecordMsg(0); } else { - return data_blocks[handle].error_msg; + return data_block->error_msg; } } @@ -945,10 +673,11 @@ const char* getIdamErrorMsg(int handle) */ int getIdamSourceStatus(int handle) { // Source Status - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].source_status; + return data_block->source_status; } //! returns the data object quality status @@ -959,35 +688,28 @@ int getIdamSourceStatus(int handle) int getIdamSignalStatus(int handle) { // Signal Status - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].signal_status; + return data_block->signal_status; } int getIdamDataStatus(int handle) { // Data Status based on Standard Rule - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } if (getIdamSignalStatus(handle) == DEFAULT_STATUS) { // Signal Status Not Changed from Default - use Data Source Value - return data_blocks[handle].source_status; + return data_block->source_status; } else { - return data_blocks[handle].signal_status; + return data_block->signal_status; } } -//! returns the last data object handle issued -/** -\return handle. -*/ -int getIdamLastHandle(CLIENT_FLAGS* client_flags) -{ - return acc_getCurrentDataBlockIndex(client_flags); -} - //! returns the number of data items in the data object /** the number of array elements \param handle The data object handle @@ -996,10 +718,11 @@ int getIdamLastHandle(CLIENT_FLAGS* client_flags) int getIdamDataNum(int handle) { // Data Array Size - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].data_n; + return data_block->data_n; } //! returns the rank of the data object @@ -1010,10 +733,11 @@ int getIdamDataNum(int handle) int getIdamRank(int handle) { // Array Rank - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return (int)data_blocks[handle].rank; + return (int)data_block->rank; } //! Returns the position of the time coordinate dimension in the data object @@ -1024,10 +748,11 @@ is counted from left to right in c and from right to left in Fortran and IDL. \p int getIdamOrder(int handle) { // Time Dimension Order in Array - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return -1; } - return data_blocks[handle].order; + return data_block->order; } /** @@ -1038,10 +763,11 @@ int getIdamOrder(int handle) unsigned int getIdamCachePermission(int handle) { // Permission to cache? - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return UDA_PLUGIN_NOT_OK_TO_CACHE; } - return data_blocks[handle].cachePermission; + return data_block->cachePermission; } /** @@ -1052,10 +778,11 @@ unsigned int getIdamCachePermission(int handle) */ unsigned int getIdamTotalDataBlockSize(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].totalDataBlockSize; + return data_block->totalDataBlockSize; } //! returns the atomic or structure type id of the data object @@ -1065,34 +792,38 @@ unsigned int getIdamTotalDataBlockSize(int handle) */ int getIdamDataType(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return UDA_TYPE_UNKNOWN; } - return data_blocks[handle].data_type; + return data_block->data_type; } int getIdamDataOpaqueType(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return UDA_TYPE_UNKNOWN; } - return data_blocks[handle].opaque_type; + return data_block->opaque_type; } void* getIdamDataOpaqueBlock(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].opaque_block; + return data_block->opaque_block; } int getIdamDataOpaqueCount(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].opaque_count; + return data_block->opaque_count; } //! returns the atomic or structure type id of the error data object @@ -1102,10 +833,11 @@ int getIdamDataOpaqueCount(int handle) */ int getIdamErrorType(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return UDA_TYPE_UNKNOWN; } - return data_blocks[handle].error_type; + return data_block->error_type; } //! returns the atomic or structure type id of a named type @@ -1264,24 +996,26 @@ int getIdamDataTypeSize(int type) void getIdamErrorModel(int handle, int* model, int* param_n, float* params) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { *model = ERROR_MODEL_UNKNOWN; *param_n = 0; return; } - *model = data_blocks[handle].error_model; // Model ID - *param_n = data_blocks[handle].error_param_n; // Number of parameters - for (int i = 0; i < data_blocks[handle].error_param_n; i++) { - params[i] = data_blocks[handle].errparams[i]; + *model = data_block->error_model; // Model ID + *param_n = data_block->error_param_n; // Number of parameters + for (int i = 0; i < data_block->error_param_n; i++) { + params[i] = data_block->errparams[i]; } } int getIdamErrorAsymmetry(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return (int)data_blocks[handle].errasymmetry; + return (int)data_block->errasymmetry; } // Return the Internal Code for a named Error Model @@ -1331,55 +1065,60 @@ int getIdamErrorModelId(const char* model) char* acc_getSyntheticData(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].synthetic; + return data_block->synthetic; } char* acc_getSyntheticDimData(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].dims[ndim].synthetic; + return data_block->dims[ndim].synthetic; } void acc_setSyntheticData(int handle, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].synthetic = data; + data_block->synthetic = data; } void acc_setSyntheticDimData(int handle, int ndim, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].dims[ndim].synthetic = data; + data_block->dims[ndim].synthetic = data; } char* getIdamSyntheticData(int handle) { - CLIENT_FLAGS* client_flags = udaClientFlags(); + auto client_flags = udaClientFlags(); + auto data_block = getDataBlock(handle); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + if (data_block == nullptr) { return nullptr; } - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + if (status == MIN_STATUS && !data_block->client_block.get_bad && !client_flags->get_bad) { return nullptr; } - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return nullptr; } - if (!client_flags->get_synthetic || data_blocks[handle].error_model == ERROR_MODEL_UNKNOWN) { - return data_blocks[handle].data; + if (!client_flags->get_synthetic || data_block->error_model == ERROR_MODEL_UNKNOWN) { + return data_block->data; } generateIdamSyntheticData(handle); - return data_blocks[handle].synthetic; + return data_block->synthetic; } //! Returns a pointer to the requested data @@ -1390,20 +1129,21 @@ set. */ char* getIdamData(int handle) { - CLIENT_FLAGS* client_flags = udaClientFlags(); + auto client_flags = udaClientFlags(); + auto data_block = getDataBlock(handle); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + if (data_block == nullptr) { return nullptr; } - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + if (status == MIN_STATUS && !data_block->client_block.get_bad && !client_flags->get_bad) { return nullptr; } - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return nullptr; } if (!client_flags->get_synthetic) { - return data_blocks[handle].data; + return data_block->data; } else { return getIdamSyntheticData(handle); } @@ -1417,132 +1157,146 @@ char* getIdamData(int handle) */ void getIdamDataTdi(int handle, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - memcpy(data, (void*)data_blocks[handle].data, (int)data_blocks[handle].data_n); + memcpy(data, (void*)data_block->data, (int)data_block->data_n); } char* getIdamDataErrLo(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].errlo; + return data_block->errlo; } char* getIdamDataErrHi(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].errhi; + return data_block->errhi; } int getIdamDataErrAsymmetry(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].errasymmetry; + return data_block->errasymmetry; } void acc_setIdamDataErrAsymmetry(int handle, int asymmetry) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].errasymmetry = asymmetry; + data_block->errasymmetry = asymmetry; }; void acc_setIdamDataErrType(int handle, int type) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].error_type = type; + data_block->error_type = type; }; void acc_setIdamDataErrLo(int handle, char* errlo) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].errlo = errlo; + data_block->errlo = errlo; }; char* getIdamDimErrLo(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].dims[ndim].errlo; + return data_block->dims[ndim].errlo; } char* getIdamDimErrHi(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].dims[ndim].errhi; + return data_block->dims[ndim].errhi; } int getIdamDimErrAsymmetry(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - return data_blocks[handle].dims[ndim].errasymmetry; + return data_block->dims[ndim].errasymmetry; } void acc_setIdamDimErrAsymmetry(int handle, int ndim, int asymmetry) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].dims[ndim].errasymmetry = asymmetry; + data_block->dims[ndim].errasymmetry = asymmetry; }; void acc_setIdamDimErrType(int handle, int ndim, int type) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].dims[ndim].error_type = type; + data_block->dims[ndim].error_type = type; }; void acc_setIdamDimErrLo(int handle, int ndim, char* errlo) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - data_blocks[handle].dims[ndim].errlo = errlo; + data_block->dims[ndim].errlo = errlo; }; char* getIdamAsymmetricError(int handle, int above) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - if (data_blocks[handle].error_type != UDA_TYPE_UNKNOWN) { + if (data_block->error_type != UDA_TYPE_UNKNOWN) { if (above) { - return data_blocks[handle].errhi; // return the default error array + return data_block->errhi; // return the default error array } else { - if (!data_blocks[handle].errasymmetry) { - return data_blocks[handle].errhi; // return the default error array if symmetric errors + if (!data_block->errasymmetry) { + return data_block->errhi; // return the default error array if symmetric errors } else { - return data_blocks[handle].errlo; + return data_block->errlo; } // otherwise the data array must have been returned by the server or generated } } else { - if (data_blocks[handle].error_model != ERROR_MODEL_UNKNOWN) { + if (data_block->error_model != ERROR_MODEL_UNKNOWN) { generateIdamDataError(handle); // Create the errors from a model if the model exits if (above) { - return data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - return data_blocks[handle].errhi; + return data_block->errhi; + } else if (!data_block->errasymmetry) { + return data_block->errhi; } else { - return data_blocks[handle].errlo; + return data_block->errlo; } } else { @@ -1550,41 +1304,41 @@ char* getIdamAsymmetricError(int handle, int above) char* errlo = nullptr; // Asymmetric Error Component int ndata; - ndata = data_blocks[handle].data_n; - data_blocks[handle].error_type = - data_blocks[handle].data_type; // Error Type is Unknown so Assume Data's Data Type + ndata = data_block->data_n; + data_block->error_type = + data_block->data_type; // Error Type is Unknown so Assume Data's Data Type - if (allocArray(data_blocks[handle].error_type, ndata, &errhi) != 0) { + if (allocArray(data_block->error_type, ndata, &errhi) != 0) { // Allocate Heap for Regular Error Data UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Data Errors\n"); - data_blocks[handle].errhi = nullptr; + data_block->errhi = nullptr; } else { - data_blocks[handle].errhi = errhi; + data_block->errhi = errhi; } - if (data_blocks[handle].errasymmetry) { // Allocate Heap for the Asymmetric Error Data - if (allocArray(data_blocks[handle].error_type, ndata, &errlo) != 0) { + if (data_block->errasymmetry) { // Allocate Heap for the Asymmetric Error Data + if (allocArray(data_block->error_type, ndata, &errlo) != 0) { UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Asymmetric Errors\n"); UDA_LOG(UDA_LOG_ERROR, "Switching Asymmetry Off!\n"); - data_blocks[handle].errlo = nullptr; - data_blocks[handle].errasymmetry = 0; + data_block->errlo = nullptr; + data_block->errasymmetry = 0; } else { - data_blocks[handle].errlo = errlo; + data_block->errlo = errlo; } } // Generate and return Zeros if this data is requested unless Error is Modelled - switch (data_blocks[handle].data_type) { + switch (data_block->data_type) { case UDA_TYPE_FLOAT: { float *fh, *fl = nullptr; - fh = (float*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - fl = (float*)data_blocks[handle].errlo; + fh = (float*)data_block->errhi; + if (data_block->errasymmetry) { + fl = (float*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(fh + i) = (float)0.0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(fl + i) = (float)0.0; } } @@ -1592,13 +1346,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_DOUBLE: { double *dh, *dl = nullptr; - dh = (double*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - dl = (double*)data_blocks[handle].errlo; + dh = (double*)data_block->errhi; + if (data_block->errasymmetry) { + dl = (double*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(dh + i) = (double)0.0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(dl + i) = (double)0.0; } } @@ -1606,13 +1360,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_SHORT: { short *sh, *sl = nullptr; - sh = (short*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - sl = (short*)data_blocks[handle].errlo; + sh = (short*)data_block->errhi; + if (data_block->errasymmetry) { + sl = (short*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(sh + i) = (short)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(sl + i) = (short)0; } } @@ -1620,13 +1374,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_UNSIGNED_SHORT: { unsigned short *sh, *sl = nullptr; - sh = (unsigned short*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - sl = (unsigned short*)data_blocks[handle].errlo; + sh = (unsigned short*)data_block->errhi; + if (data_block->errasymmetry) { + sl = (unsigned short*)data_block->errlo; } for (int i = 0; i < ndata; i++) { sh[i] = (unsigned short)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { sl[i] = (unsigned short)0; } } @@ -1634,13 +1388,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_INT: { int *ih, *il = nullptr; - ih = (int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - il = (int*)data_blocks[handle].errlo; + ih = (int*)data_block->errhi; + if (data_block->errasymmetry) { + il = (int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(ih + i) = (int)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(il + i) = (int)0; } } @@ -1648,13 +1402,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_UNSIGNED_INT: { unsigned int *uh, *ul = nullptr; - uh = (unsigned int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - ul = (unsigned int*)data_blocks[handle].errlo; + uh = (unsigned int*)data_block->errhi; + if (data_block->errasymmetry) { + ul = (unsigned int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(uh + i) = (unsigned int)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(ul + i) = (unsigned int)0; } } @@ -1662,13 +1416,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_LONG: { long *lh, *ll = nullptr; - lh = (long*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - ll = (long*)data_blocks[handle].errlo; + lh = (long*)data_block->errhi; + if (data_block->errasymmetry) { + ll = (long*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(lh + i) = (long)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(ll + i) = (long)0; } } @@ -1676,13 +1430,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_UNSIGNED_LONG: { unsigned long *lh, *ll = nullptr; - lh = (unsigned long*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - ll = (unsigned long*)data_blocks[handle].errlo; + lh = (unsigned long*)data_block->errhi; + if (data_block->errasymmetry) { + ll = (unsigned long*)data_block->errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { ll[i] = (unsigned long)0; } } @@ -1690,13 +1444,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_LONG64: { long long int *lh, *ll = nullptr; - lh = (long long int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - ll = (long long int*)data_blocks[handle].errlo; + lh = (long long int*)data_block->errhi; + if (data_block->errasymmetry) { + ll = (long long int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { *(lh + i) = (long long int)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { *(ll + i) = (long long int)0; } } @@ -1704,13 +1458,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_UNSIGNED_LONG64: { unsigned long long int *lh, *ll = nullptr; - lh = (unsigned long long int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - ll = (unsigned long long int*)data_blocks[handle].errlo; + lh = (unsigned long long int*)data_block->errhi; + if (data_block->errasymmetry) { + ll = (unsigned long long int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long long int)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { ll[i] = (unsigned long long int)0; } } @@ -1718,13 +1472,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_CHAR: { char *ch, *cl = nullptr; - ch = data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - cl = data_blocks[handle].errlo; + ch = data_block->errhi; + if (data_block->errasymmetry) { + cl = data_block->errlo; } for (int i = 0; i < ndata; i++) { ch[i] = (char)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { cl[i] = (char)0; } } @@ -1732,13 +1486,13 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_UNSIGNED_CHAR: { unsigned char *ch, *cl = nullptr; - ch = (unsigned char*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - cl = (unsigned char*)data_blocks[handle].errlo; + ch = (unsigned char*)data_block->errhi; + if (data_block->errasymmetry) { + cl = (unsigned char*)data_block->errlo; } for (int i = 0; i < ndata; i++) { ch[i] = (unsigned char)0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { cl[i] = (unsigned char)0; } } @@ -1746,14 +1500,14 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_DCOMPLEX: { DCOMPLEX *ch, *cl = nullptr; - ch = (DCOMPLEX*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - cl = (DCOMPLEX*)data_blocks[handle].errlo; + ch = (DCOMPLEX*)data_block->errhi; + if (data_block->errasymmetry) { + cl = (DCOMPLEX*)data_block->errlo; } for (int i = 0; i < ndata; i++) { ch[i].real = (double)0.0; ch[i].imaginary = (double)0.0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { cl[i].real = (double)0.0; cl[i].imaginary = (double)0.0; } @@ -1762,14 +1516,14 @@ char* getIdamAsymmetricError(int handle, int above) } case UDA_TYPE_COMPLEX: { COMPLEX *ch, *cl = nullptr; - ch = (COMPLEX*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) { - cl = (COMPLEX*)data_blocks[handle].errlo; + ch = (COMPLEX*)data_block->errhi; + if (data_block->errasymmetry) { + cl = (COMPLEX*)data_block->errlo; } for (int i = 0; i < ndata; i++) { ch[i].real = (float)0.0; ch[i].imaginary = (float)0.0; - if (data_blocks[handle].errasymmetry) { + if (data_block->errasymmetry) { cl[i].real = (float)0.0; cl[i].imaginary = (float)0.0; } @@ -1779,11 +1533,11 @@ char* getIdamAsymmetricError(int handle, int above) } if (above) { - return data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - return data_blocks[handle].errhi; + return data_block->errhi; + } else if (!data_block->errasymmetry) { + return data_block->errhi; } else { - return data_blocks[handle].errlo; + return data_block->errlo; } } } @@ -1797,7 +1551,8 @@ char* getIdamAsymmetricError(int handle, int above) char* getIdamError(int handle) { int above = 1; - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } return getIdamAsymmetricError(handle, above); @@ -1814,29 +1569,30 @@ void getIdamDoubleData(int handle, double* fp) // **** The double array must be TWICE the size if the type is COMPLEX otherwise a seg fault will occur! - CLIENT_FLAGS* client_flags = udaClientFlags(); + auto data_block = getDataBlock(handle); + auto client_flags = udaClientFlags(); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + if (data_block == nullptr) { return; } - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + if (status == MIN_STATUS && !data_block->client_block.get_bad && !client_flags->get_bad) { return; } - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return; } - if (data_blocks[handle].data_type == UDA_TYPE_DOUBLE) { + if (data_block->data_type == UDA_TYPE_DOUBLE) { if (!client_flags->get_synthetic) { - memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(double)); + memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(double)); } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) { - memcpy((void*)fp, (void*)data_blocks[handle].synthetic, - (size_t)data_blocks[handle].data_n * sizeof(double)); + if (data_block->synthetic != nullptr) { + memcpy((void*)fp, (void*)data_block->synthetic, + (size_t)data_block->data_n * sizeof(double)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(double)); + memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(double)); } return; } @@ -1848,17 +1604,17 @@ void getIdamDoubleData(int handle, double* fp) ndata = getIdamDataNum(handle); if (!client_flags->get_synthetic) { - array = data_blocks[handle].data; + array = data_block->data; } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) { - array = data_blocks[handle].synthetic; + if (data_block->synthetic != nullptr) { + array = data_block->synthetic; } else { - array = data_blocks[handle].data; + array = data_block->data; } } - switch (data_blocks[handle].data_type) { + switch (data_block->data_type) { case UDA_TYPE_FLOAT: { auto dp = (float*)array; for (int i = 0; i < ndata; i++) { @@ -1981,29 +1737,30 @@ void getIdamFloatData(int handle, float* fp) // **** The float array must be TWICE the size if the type is COMPLEX otherwise a seg fault will occur! - CLIENT_FLAGS* client_flags = udaClientFlags(); + auto data_block = getDataBlock(handle); + auto client_flags = udaClientFlags(); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + if (data_block == nullptr) { return; } - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + if (status == MIN_STATUS && !data_block->client_block.get_bad && !client_flags->get_bad) { return; } - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + if (status != MIN_STATUS && (data_block->client_block.get_bad || client_flags->get_bad)) { return; } - if (data_blocks[handle].data_type == UDA_TYPE_FLOAT) { + if (data_block->data_type == UDA_TYPE_FLOAT) { if (!client_flags->get_synthetic) { - memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(float)); } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) { - memcpy((void*)fp, (void*)data_blocks[handle].synthetic, - (size_t)data_blocks[handle].data_n * sizeof(float)); + if (data_block->synthetic != nullptr) { + memcpy((void*)fp, (void*)data_block->synthetic, + (size_t)data_block->data_n * sizeof(float)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->data, (size_t)data_block->data_n * sizeof(float)); } return; } @@ -2015,17 +1772,17 @@ void getIdamFloatData(int handle, float* fp) ndata = getIdamDataNum(handle); if (!client_flags->get_synthetic) { - array = data_blocks[handle].data; + array = data_block->data; } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) { - array = data_blocks[handle].synthetic; + if (data_block->synthetic != nullptr) { + array = data_block->synthetic; } else { - array = data_blocks[handle].data; + array = data_block->data; } } - switch (data_blocks[handle].data_type) { + switch (data_block->data_type) { case UDA_TYPE_DOUBLE: { double* dp = (double*)array; for (int i = 0; i < ndata; i++) { @@ -2197,17 +1954,18 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) // **** The float array must be TWICE the size if the type is COMPLEX otherwise a seg fault will occur! - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - int ndata = data_blocks[handle].data_n; + int ndata = data_block->data_n; - if (data_blocks[handle].error_type == UDA_TYPE_UNKNOWN) { + if (data_block->error_type == UDA_TYPE_UNKNOWN) { getIdamAsymmetricError(handle, above); } // Create the Error Data prior to Casting - switch (data_blocks[handle].error_type) { + switch (data_block->error_type) { case UDA_TYPE_UNKNOWN: for (int i = 0; i < ndata; i++) { fp[i] = (float)0.0; // No Error Data @@ -2215,21 +1973,21 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) break; case UDA_TYPE_FLOAT: if (above) { - memcpy((void*)fp, (void*)data_blocks[handle].errhi, (size_t)data_blocks[handle].data_n * sizeof(float)); - } else if (!data_blocks[handle].errasymmetry) { - memcpy((void*)fp, (void*)data_blocks[handle].errhi, (size_t)data_blocks[handle].data_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->errhi, (size_t)data_block->data_n * sizeof(float)); + } else if (!data_block->errasymmetry) { + memcpy((void*)fp, (void*)data_block->errhi, (size_t)data_block->data_n * sizeof(float)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].errlo, (size_t)data_blocks[handle].data_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->errlo, (size_t)data_block->data_n * sizeof(float)); } break; case UDA_TYPE_DOUBLE: { double* dp; if (above) { - dp = (double*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - dp = (double*)data_blocks[handle].errhi; + dp = (double*)data_block->errhi; + } else if (!data_block->errasymmetry) { + dp = (double*)data_block->errhi; } else { - dp = (double*)data_blocks[handle].errlo; + dp = (double*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)dp[i]; @@ -2239,11 +1997,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_SHORT: { short* sp; if (above) { - sp = (short*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - sp = (short*)data_blocks[handle].errhi; + sp = (short*)data_block->errhi; + } else if (!data_block->errasymmetry) { + sp = (short*)data_block->errhi; } else { - sp = (short*)data_blocks[handle].errlo; + sp = (short*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)sp[i]; @@ -2253,11 +2011,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_UNSIGNED_SHORT: { unsigned short* sp; if (above) { - sp = (unsigned short*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - sp = (unsigned short*)data_blocks[handle].errhi; + sp = (unsigned short*)data_block->errhi; + } else if (!data_block->errasymmetry) { + sp = (unsigned short*)data_block->errhi; } else { - sp = (unsigned short*)data_blocks[handle].errlo; + sp = (unsigned short*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)sp[i]; @@ -2267,11 +2025,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_INT: { int* ip; if (above) { - ip = (int*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - ip = (int*)data_blocks[handle].errhi; + ip = (int*)data_block->errhi; + } else if (!data_block->errasymmetry) { + ip = (int*)data_block->errhi; } else { - ip = (int*)data_blocks[handle].errlo; + ip = (int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)ip[i]; @@ -2281,11 +2039,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_UNSIGNED_INT: { unsigned int* up; if (above) { - up = (unsigned int*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - up = (unsigned int*)data_blocks[handle].errhi; + up = (unsigned int*)data_block->errhi; + } else if (!data_block->errasymmetry) { + up = (unsigned int*)data_block->errhi; } else { - up = (unsigned int*)data_blocks[handle].errlo; + up = (unsigned int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)up[i]; @@ -2295,11 +2053,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_LONG: { long* lp; if (above) { - lp = (long*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - lp = (long*)data_blocks[handle].errhi; + lp = (long*)data_block->errhi; + } else if (!data_block->errasymmetry) { + lp = (long*)data_block->errhi; } else { - lp = (long*)data_blocks[handle].errlo; + lp = (long*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -2309,11 +2067,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_UNSIGNED_LONG: { unsigned long* lp; if (above) { - lp = (unsigned long*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - lp = (unsigned long*)data_blocks[handle].errhi; + lp = (unsigned long*)data_block->errhi; + } else if (!data_block->errasymmetry) { + lp = (unsigned long*)data_block->errhi; } else { - lp = (unsigned long*)data_blocks[handle].errlo; + lp = (unsigned long*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -2323,11 +2081,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_LONG64: { long long int* lp; if (above) { - lp = (long long int*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - lp = (long long int*)data_blocks[handle].errhi; + lp = (long long int*)data_block->errhi; + } else if (!data_block->errasymmetry) { + lp = (long long int*)data_block->errhi; } else { - lp = (long long int*)data_blocks[handle].errlo; + lp = (long long int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -2337,11 +2095,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_UNSIGNED_LONG64: { unsigned long long int* lp; if (above) { - lp = (unsigned long long int*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - lp = (unsigned long long int*)data_blocks[handle].errhi; + lp = (unsigned long long int*)data_block->errhi; + } else if (!data_block->errasymmetry) { + lp = (unsigned long long int*)data_block->errhi; } else { - lp = (unsigned long long int*)data_blocks[handle].errlo; + lp = (unsigned long long int*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -2351,11 +2109,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_CHAR: { char* cp; if (above) { - cp = data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - cp = data_blocks[handle].errhi; + cp = data_block->errhi; + } else if (!data_block->errasymmetry) { + cp = data_block->errhi; } else { - cp = data_blocks[handle].errlo; + cp = data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)cp[i]; @@ -2365,11 +2123,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) case UDA_TYPE_UNSIGNED_CHAR: { unsigned char* cp; if (above) { - cp = (unsigned char*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - cp = (unsigned char*)data_blocks[handle].errhi; + cp = (unsigned char*)data_block->errhi; + } else if (!data_block->errasymmetry) { + cp = (unsigned char*)data_block->errhi; } else { - cp = (unsigned char*)data_blocks[handle].errlo; + cp = (unsigned char*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)cp[i]; @@ -2380,11 +2138,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) int j = 0; DCOMPLEX* cp; if (above) { - cp = (DCOMPLEX*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - cp = (DCOMPLEX*)data_blocks[handle].errhi; + cp = (DCOMPLEX*)data_block->errhi; + } else if (!data_block->errasymmetry) { + cp = (DCOMPLEX*)data_block->errhi; } else { - cp = (DCOMPLEX*)data_blocks[handle].errlo; + cp = (DCOMPLEX*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[j++] = (float)cp[i].real; @@ -2396,11 +2154,11 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) int j = 0; COMPLEX* cp; if (above) { - cp = (COMPLEX*)data_blocks[handle].errhi; - } else if (!data_blocks[handle].errasymmetry) { - cp = (COMPLEX*)data_blocks[handle].errhi; + cp = (COMPLEX*)data_block->errhi; + } else if (!data_block->errasymmetry) { + cp = (COMPLEX*)data_block->errhi; } else { - cp = (COMPLEX*)data_blocks[handle].errlo; + cp = (COMPLEX*)data_block->errlo; } for (int i = 0; i < ndata; i++) { fp[j++] = (float)cp[i].real; @@ -2428,33 +2186,6 @@ void getIdamFloatError(int handle, float* fp) getIdamFloatAsymmetricError(handle, above, fp); } -//! Returns the DATA_BLOCK data structure - the data, dimension coordinates and associated meta data. -/** -\param handle The data object handle -\param db Returned \b DATA_BLOCK pointer -\return void -*/ -void getIdamDBlock(int handle, DATA_BLOCK* db) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return; - } - *db = data_blocks[handle]; -} - -//! Returns the DATA_BLOCK data structure - the data, dimension coordinates and associated meta data. -/** -\param handle The data object handle -\return DATA_BLOCK pointer -*/ -DATA_BLOCK* getIdamDataBlock(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - return &data_blocks[handle]; -} - //! Returns the data label of a data object /** \param handle The data object handle @@ -2462,10 +2193,11 @@ DATA_BLOCK* getIdamDataBlock(int handle) */ const char* getIdamDataLabel(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].data_label; + return data_block->data_label; } //! Returns the data label of a data object for use in MDS+ TDI functions @@ -2476,10 +2208,11 @@ const char* getIdamDataLabel(int handle) */ void getIdamDataLabelTdi(int handle, char* label) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - strcpy(label, data_blocks[handle].data_label); + strcpy(label, data_block->data_label); } //! Returns the data units of a data object @@ -2489,10 +2222,11 @@ void getIdamDataLabelTdi(int handle, char* label) */ const char* getIdamDataUnits(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].data_units; + return data_block->data_units; } //! Returns the data units of a data object for use in MDS+ TDI functions @@ -2503,10 +2237,11 @@ const char* getIdamDataUnits(int handle) */ void getIdamDataUnitsTdi(int handle, char* units) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - strcpy(units, data_blocks[handle].data_units); + strcpy(units, data_block->data_units); } //! Returns the description of a data object @@ -2516,10 +2251,11 @@ void getIdamDataUnitsTdi(int handle, char* units) */ const char* getIdamDataDesc(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return nullptr; } - return data_blocks[handle].data_desc; + return data_block->data_desc; } //! Returns the description of a data object for use in MDS+ TDI functions @@ -2530,10 +2266,11 @@ const char* getIdamDataDesc(int handle) */ void getIdamDataDescTdi(int handle, char* desc) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return; } - strcpy(desc, data_blocks[handle].data_desc); + strcpy(desc, data_block->data_desc); } // Dimension Coordinates @@ -2546,11 +2283,12 @@ void getIdamDataDescTdi(int handle, char* desc) */ int getIdamDimNum(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return 0; } - return data_blocks[handle].dims[ndim].dim_n; + return data_block->dims[ndim].dim_n; } //! Returns the coordinate dimension data type @@ -2561,11 +2299,12 @@ int getIdamDimNum(int handle, int ndim) */ int getIdamDimType(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return UDA_TYPE_UNKNOWN; } - return data_blocks[handle].dims[ndim].data_type; + return data_block->dims[ndim].data_type; } //! Returns the coordinate dimension error data type @@ -2576,11 +2315,12 @@ int getIdamDimType(int handle, int ndim) */ int getIdamDimErrorType(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return UDA_TYPE_UNKNOWN; } - return data_blocks[handle].dims[ndim].error_type; + return data_block->dims[ndim].error_type; } //! Returns whether or not coordinate error data are asymmetric. @@ -2591,42 +2331,45 @@ int getIdamDimErrorType(int handle, int ndim) */ int getIdamDimErrorAsymmetry(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return 0; } - return data_blocks[handle].dims[ndim].errasymmetry; + return data_block->dims[ndim].errasymmetry; } void getIdamDimErrorModel(int handle, int ndim, int* model, int* param_n, float* params) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { *model = ERROR_MODEL_UNKNOWN; *param_n = 0; return; } - *model = data_blocks[handle].dims[ndim].error_model; // Model ID - *param_n = data_blocks[handle].dims[ndim].error_param_n; // Number of parameters - for (int i = 0; i < data_blocks[handle].dims[ndim].error_param_n; i++) { - params[i] = data_blocks[handle].dims[ndim].errparams[i]; + *model = data_block->dims[ndim].error_model; // Model ID + *param_n = data_block->dims[ndim].error_param_n; // Number of parameters + for (int i = 0; i < data_block->dims[ndim].error_param_n; i++) { + params[i] = data_block->dims[ndim].errparams[i]; } - // *params = data_blocks[handle].dims[ndim].errparams; // Array of Model Parameters + // *params = data_block->dims[ndim].errparams; // Array of Model Parameters } char* getIdamSyntheticDimData(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - CLIENT_FLAGS* client_flags = udaClientFlags(); - if (!client_flags->get_synthetic || data_blocks[handle].dims[ndim].error_model == ERROR_MODEL_UNKNOWN) { - return data_blocks[handle].dims[ndim].dim; + auto client_flags = udaClientFlags(); + if (!client_flags->get_synthetic || data_block->dims[ndim].error_model == ERROR_MODEL_UNKNOWN) { + return data_block->dims[ndim].dim; } generateIdamSyntheticDimData(handle, ndim); - return data_blocks[handle].dims[ndim].synthetic; + return data_block->dims[ndim].synthetic; } ///! Returns a pointer to the requested coordinate data @@ -2637,13 +2380,14 @@ char* getIdamSyntheticDimData(int handle, int ndim) */ char* getIdamDimData(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - CLIENT_FLAGS* client_flags = udaClientFlags(); + auto client_flags = udaClientFlags(); if (!client_flags->get_synthetic) { - return data_blocks[handle].dims[ndim].dim; + return data_block->dims[ndim].dim; } return getIdamSyntheticDimData(handle, ndim); } @@ -2656,11 +2400,12 @@ char* getIdamDimData(int handle, int ndim) */ const char* getIdamDimLabel(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - return data_blocks[handle].dims[ndim].dim_label; + return data_block->dims[ndim].dim_label; } //! Returns the data units of a coordinate dimension /** @@ -2670,11 +2415,12 @@ const char* getIdamDimLabel(int handle, int ndim) */ const char* getIdamDimUnits(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - return data_blocks[handle].dims[ndim].dim_units; + return data_block->dims[ndim].dim_units; } //! Returns the data label of a coordinate dimension for use in MDS+ TDI functions @@ -2686,11 +2432,12 @@ const char* getIdamDimUnits(int handle, int ndim) */ void getIdamDimLabelTdi(int handle, int ndim, char* label) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return; } - strcpy(label, data_blocks[handle].dims[ndim].dim_label); + strcpy(label, data_block->dims[ndim].dim_label); } //! Returns the data units of a coordinate dimension for use in MDS+ TDI functions @@ -2702,11 +2449,12 @@ void getIdamDimLabelTdi(int handle, int ndim, char* label) */ void getIdamDimUnitsTdi(int handle, int ndim, char* units) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return; } - strcpy(units, data_blocks[handle].dims[ndim].dim_units); + strcpy(units, data_block->dims[ndim].dim_units); } //! Returns coordinate data cast to double precision @@ -2720,42 +2468,43 @@ void getIdamDoubleDimData(int handle, int ndim, double* fp) { // **** The double array must be TWICE the size if the type is COMPLEX otherwise a seg fault will occur! - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return; } - CLIENT_FLAGS* client_flags = udaClientFlags(); - if (data_blocks[handle].dims[ndim].data_type == UDA_TYPE_DOUBLE) { + auto client_flags = udaClientFlags(); + if (data_block->dims[ndim].data_type == UDA_TYPE_DOUBLE) { if (!client_flags->get_synthetic) { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(double)); + memcpy((void*)fp, (void*)data_block->dims[ndim].dim, + (size_t)data_block->dims[ndim].dim_n * sizeof(double)); } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].synthetic, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(double)); + if (data_block->dims[ndim].synthetic != nullptr) { + memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic, + (size_t)data_block->dims[ndim].dim_n * sizeof(double)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(double)); + memcpy((void*)fp, (void*)data_block->dims[ndim].dim, + (size_t)data_block->dims[ndim].dim_n * sizeof(double)); } return; } } else { char* array; - int ndata = data_blocks[handle].dims[ndim].dim_n; + int ndata = data_block->dims[ndim].dim_n; if (!client_flags->get_synthetic) { - array = data_blocks[handle].dims[ndim].dim; + array = data_block->dims[ndim].dim; } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) { - array = data_blocks[handle].dims[ndim].synthetic; + if (data_block->dims[ndim].synthetic != nullptr) { + array = data_block->dims[ndim].synthetic; } else { - array = data_blocks[handle].dims[ndim].dim; + array = data_block->dims[ndim].dim; } } - switch (data_blocks[handle].dims[ndim].data_type) { + switch (data_block->dims[ndim].data_type) { case UDA_TYPE_FLOAT: { auto dp = (float*)array; for (int i = 0; i < ndata; i++) { @@ -2877,42 +2626,43 @@ void getIdamFloatDimData(int handle, int ndim, float* fp) { // **** The float array must be TWICE the size if the type is COMPLEX otherwise a seg fault will occur! - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return; } - CLIENT_FLAGS* client_flags = udaClientFlags(); - if (data_blocks[handle].dims[ndim].data_type == UDA_TYPE_FLOAT) { + auto client_flags = udaClientFlags(); + if (data_block->dims[ndim].data_type == UDA_TYPE_FLOAT) { if (!client_flags->get_synthetic) { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->dims[ndim].dim, + (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].synthetic, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + if (data_block->dims[ndim].synthetic != nullptr) { + memcpy((void*)fp, (void*)data_block->dims[ndim].synthetic, + (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->dims[ndim].dim, + (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } return; } } else { char* array; - int ndata = data_blocks[handle].dims[ndim].dim_n; + int ndata = data_block->dims[ndim].dim_n; if (!client_flags->get_synthetic) { - array = data_blocks[handle].dims[ndim].dim; + array = data_block->dims[ndim].dim; } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) { - array = data_blocks[handle].dims[ndim].synthetic; + if (data_block->dims[ndim].synthetic != nullptr) { + array = data_block->dims[ndim].synthetic; } else { - array = data_blocks[handle].dims[ndim].dim; + array = data_block->dims[ndim].dim; } } - switch (data_blocks[handle].dims[ndim].data_type) { + switch (data_block->dims[ndim].data_type) { case UDA_TYPE_DOUBLE: { auto dp = (double*)array; for (int i = 0; i < ndata; i++) { @@ -3092,73 +2842,75 @@ void getIdamGenericDimData(int handle, int ndim, void* data) */ DIMS* getIdamDimBlock(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - return data_blocks[handle].dims + ndim; + return data_block->dims + ndim; } char* getIdamDimAsymmetricError(int handle, int ndim, int above) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } - if (data_blocks[handle].dims[ndim].error_type != UDA_TYPE_UNKNOWN) { + if (data_block->dims[ndim].error_type != UDA_TYPE_UNKNOWN) { if (above) { - return data_blocks[handle].dims[ndim].errhi; // return the default error array + return data_block->dims[ndim].errhi; // return the default error array } else { - if (!data_blocks[handle].dims[ndim].errasymmetry) { - return data_blocks[handle].dims[ndim].errhi; // return the default error array if symmetric errors + if (!data_block->dims[ndim].errasymmetry) { + return data_block->dims[ndim].errhi; // return the default error array if symmetric errors } else { - return data_blocks[handle].dims[ndim].errlo; + return data_block->dims[ndim].errlo; } // otherwise the data array must have been returned by the server } // or generated in a previous call } else { - if (data_blocks[handle].dims[ndim].error_model != ERROR_MODEL_UNKNOWN) { + if (data_block->dims[ndim].error_model != ERROR_MODEL_UNKNOWN) { generateIdamDimDataError(handle, ndim); - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - return data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + return data_block->dims[ndim].errhi; } else { - return data_blocks[handle].dims[ndim].errlo; + return data_block->dims[ndim].errlo; } } else { char* errhi = nullptr; char* errlo = nullptr; - int ndata = data_blocks[handle].dims[ndim].dim_n; - data_blocks[handle].dims[ndim].error_type = - data_blocks[handle].dims[ndim].data_type; // Error Type is Unknown so Assume Data's Data Type + int ndata = data_block->dims[ndim].dim_n; + data_block->dims[ndim].error_type = + data_block->dims[ndim].data_type; // Error Type is Unknown so Assume Data's Data Type - if (allocArray(data_blocks[handle].dims[ndim].error_type, ndata, &errhi) != 0) { + if (allocArray(data_block->dims[ndim].error_type, ndata, &errhi) != 0) { UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Dimensional Data Errors\n"); - data_blocks[handle].dims[ndim].errhi = nullptr; + data_block->dims[ndim].errhi = nullptr; } else { - data_blocks[handle].dims[ndim].errhi = errhi; + data_block->dims[ndim].errhi = errhi; } - if (data_blocks[handle].dims[ndim].errasymmetry) { // Allocate Heap for the Asymmetric Error Data - if (allocArray(data_blocks[handle].dims[ndim].error_type, ndata, &errlo) != 0) { + if (data_block->dims[ndim].errasymmetry) { // Allocate Heap for the Asymmetric Error Data + if (allocArray(data_block->dims[ndim].error_type, ndata, &errlo) != 0) { UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Dimensional Asymmetric Errors\n"); UDA_LOG(UDA_LOG_ERROR, "Switching Asymmetry Off!\n"); - data_blocks[handle].dims[ndim].errlo = errlo; - data_blocks[handle].dims[ndim].errasymmetry = 0; + data_block->dims[ndim].errlo = errlo; + data_block->dims[ndim].errasymmetry = 0; } else { - data_blocks[handle].dims[ndim].errlo = errlo; + data_block->dims[ndim].errlo = errlo; } } - switch (data_blocks[handle].dims[ndim].data_type) { + switch (data_block->dims[ndim].data_type) { case UDA_TYPE_FLOAT: { float* fl = nullptr; - auto fh = (float*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - fl = (float*)data_blocks[handle].dims[ndim].errlo; + auto fh = (float*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + fl = (float*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fh[i] = (float)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { fl[i] = (float)0.0; } } @@ -3166,13 +2918,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_DOUBLE: { double* dl = nullptr; - auto dh = (double*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - dl = (double*)data_blocks[handle].dims[ndim].errlo; + auto dh = (double*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + dl = (double*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { dh[i] = (double)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { dl[i] = (double)0.0; } } @@ -3180,13 +2932,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_SHORT: { short* sl = nullptr; - auto sh = (short*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - sl = (short*)data_blocks[handle].dims[ndim].errlo; + auto sh = (short*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + sl = (short*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { sh[i] = (short)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { sl[i] = (short)0; } } @@ -3194,13 +2946,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_UNSIGNED_SHORT: { unsigned short* sl = nullptr; - auto sh = (unsigned short*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - sl = (unsigned short*)data_blocks[handle].dims[ndim].errlo; + auto sh = (unsigned short*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + sl = (unsigned short*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { sh[i] = (unsigned short)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { sl[i] = (unsigned short)0; } } @@ -3208,13 +2960,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_INT: { int* il = nullptr; - auto ih = (int*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - il = (int*)data_blocks[handle].dims[ndim].errlo; + auto ih = (int*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + il = (int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { ih[i] = (int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { il[i] = (int)0; } } @@ -3222,13 +2974,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_UNSIGNED_INT: { unsigned int* ul = nullptr; - auto uh = (unsigned int*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - ul = (unsigned int*)data_blocks[handle].dims[ndim].errlo; + auto uh = (unsigned int*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + ul = (unsigned int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { uh[i] = (unsigned int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { ul[i] = (unsigned int)0; } } @@ -3236,13 +2988,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_LONG: { long* ll = nullptr; - auto lh = (long*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - ll = (long*)data_blocks[handle].dims[ndim].errlo; + auto lh = (long*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + ll = (long*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (long)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { ll[i] = (long)0; } } @@ -3250,13 +3002,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_UNSIGNED_LONG: { unsigned long* ll = nullptr; - auto lh = (unsigned long*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - ll = (unsigned long*)data_blocks[handle].dims[ndim].errlo; + auto lh = (unsigned long*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + ll = (unsigned long*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { ll[i] = (unsigned long)0; } } @@ -3264,13 +3016,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_LONG64: { long long int* ll = nullptr; - auto lh = (long long int*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - ll = (long long int*)data_blocks[handle].dims[ndim].errlo; + auto lh = (long long int*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + ll = (long long int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (long long int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { ll[i] = (long long int)0; } } @@ -3278,13 +3030,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_UNSIGNED_LONG64: { unsigned long long int* ll = nullptr; - auto lh = (unsigned long long int*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - ll = (unsigned long long int*)data_blocks[handle].dims[ndim].errlo; + auto lh = (unsigned long long int*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + ll = (unsigned long long int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long long int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { ll[i] = (unsigned long long int)0; } } @@ -3292,13 +3044,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_CHAR: { char* cl = nullptr; - auto ch = data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - cl = data_blocks[handle].dims[ndim].errlo; + auto ch = data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + cl = data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { *(ch + i) = ' '; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { *(cl + i) = ' '; } } @@ -3306,13 +3058,13 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_UNSIGNED_CHAR: { unsigned char* cl = nullptr; - auto ch = (unsigned char*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - cl = (unsigned char*)data_blocks[handle].dims[ndim].errlo; + auto ch = (unsigned char*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + cl = (unsigned char*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { ch[i] = (unsigned char)0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { cl[i] = (unsigned char)0; } } @@ -3320,14 +3072,14 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_DCOMPLEX: { DCOMPLEX* cl = nullptr; - auto ch = (DCOMPLEX*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - cl = (DCOMPLEX*)data_blocks[handle].dims[ndim].errlo; + auto ch = (DCOMPLEX*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + cl = (DCOMPLEX*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { ch[i].real = (double)0.0; ch[i].imaginary = (double)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { cl[i].real = (double)0.0; cl[i].imaginary = (double)0.0; } @@ -3336,14 +3088,14 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) } case UDA_TYPE_COMPLEX: { COMPLEX* cl = nullptr; - auto ch = (COMPLEX*)data_blocks[handle].dims[ndim].errhi; - if (data_blocks[handle].dims[ndim].errasymmetry) { - cl = (COMPLEX*)data_blocks[handle].dims[ndim].errlo; + auto ch = (COMPLEX*)data_block->dims[ndim].errhi; + if (data_block->dims[ndim].errasymmetry) { + cl = (COMPLEX*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { ch[i].real = (float)0.0; ch[i].imaginary = (float)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) { + if (data_block->dims[ndim].errasymmetry) { cl[i].real = (float)0.0; cl[i].imaginary = (float)0.0; } @@ -3351,7 +3103,7 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) break; } } - return data_blocks[handle].dims[ndim].errhi; // Errors are Symmetric at this point + return data_block->dims[ndim].errhi; // Errors are Symmetric at this point } } } @@ -3365,8 +3117,9 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) char* getIdamDimError(int handle, int ndim) { int above = 1; - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return nullptr; } return getIdamDimAsymmetricError(handle, ndim, above); @@ -3376,38 +3129,39 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) { // Copy Error Data cast as float to User Provided Array - if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || - (unsigned int)ndim >= data_blocks[handle].rank) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr || ndim < 0 || + (unsigned int)ndim >= data_block->rank) { return; } - int ndata = data_blocks[handle].dims[ndim].dim_n; + int ndata = data_block->dims[ndim].dim_n; - if (data_blocks[handle].dims[ndim].error_type == UDA_TYPE_UNKNOWN) { + if (data_block->dims[ndim].error_type == UDA_TYPE_UNKNOWN) { getIdamDimAsymmetricError(handle, ndim, above); } // Create the Error Data prior to Casting - switch (data_blocks[handle].dims[ndim].error_type) { + switch (data_block->dims[ndim].error_type) { case UDA_TYPE_UNKNOWN: for (int i = 0; i < ndata; i++) { fp[i] = (float)0.0; // No Error Data } break; case UDA_TYPE_FLOAT: - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].errhi, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + if (above || !data_block->dims[ndim].errasymmetry) { + memcpy((void*)fp, (void*)data_block->dims[ndim].errhi, + (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } else { - memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].errlo, - (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + memcpy((void*)fp, (void*)data_block->dims[ndim].errlo, + (size_t)data_block->dims[ndim].dim_n * sizeof(float)); } break; case UDA_TYPE_DOUBLE: { double* dp; // Return Zeros if this data is requested unless Error is Modelled - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - dp = (double*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + dp = (double*)data_block->dims[ndim].errhi; } else { - dp = (double*)data_blocks[handle].dims[ndim].errlo; + dp = (double*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)dp[i]; @@ -3416,10 +3170,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_SHORT: { short* sp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - sp = (short*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + sp = (short*)data_block->dims[ndim].errhi; } else { - sp = (short*)data_blocks[handle].dims[ndim].errlo; + sp = (short*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)sp[i]; @@ -3428,10 +3182,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_UNSIGNED_SHORT: { unsigned short* sp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - sp = (unsigned short*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + sp = (unsigned short*)data_block->dims[ndim].errhi; } else { - sp = (unsigned short*)data_blocks[handle].dims[ndim].errlo; + sp = (unsigned short*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)sp[i]; @@ -3440,10 +3194,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_INT: { int* ip; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - ip = (int*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + ip = (int*)data_block->dims[ndim].errhi; } else { - ip = (int*)data_blocks[handle].dims[ndim].errlo; + ip = (int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)ip[i]; @@ -3452,10 +3206,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_UNSIGNED_INT: { unsigned int* up; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - up = (unsigned int*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + up = (unsigned int*)data_block->dims[ndim].errhi; } else { - up = (unsigned int*)data_blocks[handle].dims[ndim].errlo; + up = (unsigned int*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)up[i]; @@ -3464,10 +3218,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_LONG: { long* lp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - lp = (long*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + lp = (long*)data_block->dims[ndim].errhi; } else { - lp = (long*)data_blocks[handle].dims[ndim].errlo; + lp = (long*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -3476,10 +3230,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_UNSIGNED_LONG: { unsigned long* lp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - lp = (unsigned long*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + lp = (unsigned long*)data_block->dims[ndim].errhi; } else { - lp = (unsigned long*)data_blocks[handle].dims[ndim].errlo; + lp = (unsigned long*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)lp[i]; @@ -3488,10 +3242,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_CHAR: { char* cp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - cp = data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + cp = data_block->dims[ndim].errhi; } else { - cp = data_blocks[handle].dims[ndim].errlo; + cp = data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)cp[i]; @@ -3500,10 +3254,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } case UDA_TYPE_UNSIGNED_CHAR: { unsigned char* cp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - cp = (unsigned char*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + cp = (unsigned char*)data_block->dims[ndim].errhi; } else { - cp = (unsigned char*)data_blocks[handle].dims[ndim].errlo; + cp = (unsigned char*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[i] = (float)cp[i]; @@ -3513,10 +3267,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) case UDA_TYPE_DCOMPLEX: { int j = 0; DCOMPLEX* cp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - cp = (DCOMPLEX*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + cp = (DCOMPLEX*)data_block->dims[ndim].errhi; } else { - cp = (DCOMPLEX*)data_blocks[handle].dims[ndim].errlo; + cp = (DCOMPLEX*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[j++] = (float)cp[i].real; @@ -3527,10 +3281,10 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) case UDA_TYPE_COMPLEX: { int j = 0; COMPLEX* cp; - if (above || !data_blocks[handle].dims[ndim].errasymmetry) { - cp = (COMPLEX*)data_blocks[handle].dims[ndim].errhi; + if (above || !data_block->dims[ndim].errasymmetry) { + cp = (COMPLEX*)data_block->dims[ndim].errhi; } else { - cp = (COMPLEX*)data_blocks[handle].dims[ndim].errlo; + cp = (COMPLEX*)data_block->dims[ndim].errlo; } for (int i = 0; i < ndata; i++) { fp[j++] = (float)cp[i].real; @@ -3554,100 +3308,9 @@ void getIdamFloatDimError(int handle, int ndim, float* fp) getIdamFloatDimAsymmetricError(handle, ndim, above, fp); } -//! Returns a pointer to the DATA_SYSTEM Meta Data structure -/** A copy of the \b Data_System database table record -\param handle The data object handle -\return DATA_SYSTEM pointer -*/ -DATA_SYSTEM* getIdamDataSystem(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - return data_blocks[handle].data_system; -} - -//! Returns a pointer to the SYSTEM_CONFIG Meta Data structure -/** A copy of the \b system_config database table record -\param handle The data object handle -\return SYSTEM_CONFIG pointer -*/ -SYSTEM_CONFIG* getIdamSystemConfig(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) {} - return nullptr; - return data_blocks[handle].system_config; -} - -//! Returns a pointer to the DATA_SOURCE Meta Data structure -/** A copy of the \b data_source database table record - the location of data -\param handle The data object handle -\return DATA_SOURCE pointer -*/ -DATA_SOURCE* getIdamDataSource(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - return data_blocks[handle].data_source; -} - -//! Returns a pointer to the SIGNAL Meta Data structure -/** A copy of the \b signal database table record -\param handle The data object handle -\return SIGNAL pointer -*/ -SIGNAL* getIdamSignal(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - return data_blocks[handle].signal_rec; -} - -//! Returns a pointer to the SIGNAL_DESC Meta Data structure -/** A copy of the \b signal_desc database table record - a description of the data signal/object -\param handle The data object handle -\return SIGNAL_DESC pointer -*/ -SIGNAL_DESC* getIdamSignalDesc(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - return data_blocks[handle].signal_desc; -} - -//! Returns a pointer to the File Format string returned in the DATA_SOURCE metadata record -/** Dependent on the server property \b get_meta -\param handle The data object handle -\return pointer to the data file format -*/ -const char* getIdamFileFormat(int handle) -{ - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - return nullptr; - } - DATA_SOURCE* data_source = getIdamDataSource(handle); - if (data_source == nullptr) { - return nullptr; - } - return data_source->format; -} - //----------------------------------------------------------------------------------------------------------- // Various Utilities -void initIdamDataBlock(DATA_BLOCK* str) -{ - initDataBlock(str); -} - -void initIdamRequestBlock(REQUEST_BLOCK* str) -{ - initRequestBlock(str); -} - int idamDataCheckSum(void* data, int data_n, int type) { int sum = 0; @@ -3787,31 +3450,33 @@ int idamDataCheckSum(void* data, int data_n, int type) int getIdamDataCheckSum(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - if (data_blocks[handle].errcode != 0) { + if (data_block->errcode != 0) { return 0; } return ( - idamDataCheckSum((void*)data_blocks[handle].data, data_blocks[handle].data_n, data_blocks[handle].data_type)); + idamDataCheckSum((void*)data_block->data, data_block->data_n, data_block->data_type)); } int getIdamDimDataCheckSum(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + auto data_block = getDataBlock(handle); + if (data_block == nullptr) { return 0; } - if (data_blocks[handle].errcode != 0) { + if (data_block->errcode != 0) { return 0; } - if (ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { + if (ndim < 0 || (unsigned int)ndim >= data_block->rank) { return 0; } - return (idamDataCheckSum((void*)data_blocks[handle].dims[ndim].dim, data_blocks[handle].dims[ndim].dim_n, - data_blocks[handle].dims[ndim].data_type)); + return (idamDataCheckSum((void*)data_block->dims[ndim].dim, data_block->dims[ndim].dim_n, + data_block->dims[ndim].data_type)); } //=========================================================================================================== @@ -3848,7 +3513,7 @@ void getIdamClientSerialisedDataBlock(int handle, void** object, size_t* objectS LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle); DATA_BLOCK_LIST data_block_list; data_block_list.count = 1; - data_block_list.data = getIdamDataBlock(handle); + data_block_list.data = getDataBlock(handle); protocol2(&xdrs, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_SEND, &token, logmalloclist, userdefinedtypelist, &data_block_list, protocolVersion, log_struct_list, private_flags, malloc_source); diff --git a/source/c_api/clientAPI.cpp b/source/c_api/clientAPI.cpp index 62452b69..b52a112b 100644 --- a/source/c_api/clientAPI.cpp +++ b/source/c_api/clientAPI.cpp @@ -8,7 +8,7 @@ #endif #include "clientserver/errorLog.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "client.h" diff --git a/source/c_api/clientMDS.cpp b/source/c_api/clientMDS.cpp index d7158bd4..4c5acb2b 100644 --- a/source/c_api/clientMDS.cpp +++ b/source/c_api/clientMDS.cpp @@ -1,7 +1,7 @@ #include "clientMDS.h" #include "clientserver/protocol.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "client.h" diff --git a/source/c_api/udaGetAPI.cpp b/source/c_api/udaGetAPI.cpp index edfbf2de..4383332e 100644 --- a/source/c_api/udaGetAPI.cpp +++ b/source/c_api/udaGetAPI.cpp @@ -16,7 +16,7 @@ #include "clientserver/errorLog.h" #include "clientserver/printStructs.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "accAPI.h" @@ -29,6 +29,195 @@ # include #endif +#ifndef NOPTHREADS + +# ifdef __GNUC__ +# include +# else +# include +# endif + +typedef struct { + int id; // Thread identifier assigned by the application + int socket; // Either a shared or private server socket connection + int lastHandle; + ENVIRONMENT environment; // State + CLIENT_BLOCK client_block; + SERVER_BLOCK server_block; +} IDAMSTATE; + +# ifdef __GNUC__ +typedef pthread_t thread_t; +typedef pthread_mutex_t lock_t; + +static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; +# else +typedef HANDLE lock_t; +typedef HANDLE thread_t; + +static HANDLE lock; +# endif + +// STATE management + +static IDAMSTATE idamState[UDA_NUM_CLIENT_THREADS]; // Threads are managed by the application, not IDAM +static thread_t threadList[UDA_NUM_CLIENT_THREADS]; +static int threadCount = 0; + +int getIdamMaxThreadCount() +{ + return UDA_NUM_CLIENT_THREADS; +} + +/** + * Search the set of registered threads for the State ID + * @param id + * @return + */ +int getThreadId(thread_t id) +{ + for (int i = 0; i < threadCount; i++) { +# ifdef __GNUC__ + if (pthread_equal(id, threadList[i])) { + return i; + } +# else + if (GetThreadId(id) == GetThreadId(threadList[i])) { + return i; + } +# endif + } + return -1; +} + +// Lock the thread and set the previous STATE +void lockIdamThread() +{ + static unsigned int mutex_initialised = 0; + + if (!mutex_initialised) { +# ifndef __GNUC__ + lock = CreateMutex(nullptr, FALSE, nullptr); +# endif + } + + // Apply the lock first +# ifdef __GNUC__ + pthread_mutex_lock(&lock); +# else + WaitForSingleObject(lock, INFINITE); +# endif + + // Identify the Current Thread + +# ifdef __GNUC__ + thread_t threadId = pthread_self(); +# else + thread_t threadId = GetCurrentThread(); +# endif + + // Initialise the thread's state + + if (!mutex_initialised) { + mutex_initialised = 1; + for (int i = 0; i < UDA_NUM_CLIENT_THREADS; i++) { // Initialise the STATE array + idamState[i].id = i; + idamState[i].socket = -1; + idamState[i].lastHandle = -1; + // initEnvironment(&(idamState[i].environment)); + initClientBlock(&(idamState[i].client_block), 0, ""); + initServerBlock(&(idamState[i].server_block), 0); + threadList[i] = 0; // and the thread identifiers + } + } + + // Retain unique thread IDs + + int id = getThreadId(threadId); + + if (threadCount < UDA_NUM_CLIENT_THREADS && id == -1) { + // Preserve the thread ID if not registered + threadList[++threadCount - 1] = threadId; + } + + // Assign State for the current thread if previously registered + + if (id >= 0) { + putIdamServerSocket(idamState[id].socket); + // putIdamClientEnvironment(&idamState[id].environment); + putIdamThreadClientBlock(&idamState[id].client_block); + putIdamThreadServerBlock(&idamState[id].server_block); + auto client_flags = udaClientFlags(); + client_flags->flags = idamState[id].client_block.clientFlags; + putIdamThreadLastHandle(idamState[id].lastHandle); + } else { + putIdamThreadLastHandle(-1); + } +} + +/** + * Unlock the thread and save the current STATE + */ +void unlockUdaThread() +{ +# ifdef __GNUC__ + thread_t threadId = pthread_self(); +# else + thread_t threadId = GetCurrentThread(); +# endif + int id = getThreadId(threadId); // Must be registered + if (id >= 0) { + idamState[id].socket = getIdamServerSocket(); + // idamState[id].environment = *getIdamClientEnvironment(); + idamState[id].client_block = getIdamThreadClientBlock(); + idamState[id].server_block = getIdamThreadServerBlock(); + auto client_flags = udaClientFlags(); + idamState[id].client_block.clientFlags = client_flags->flags; + idamState[id].lastHandle = getIdamThreadLastHandle(); + } +# ifdef __GNUC__ + pthread_mutex_unlock(&lock); +# else + ReleaseMutex(lock); +# endif +} + +/** + * Free thread resources + */ +void freeIdamThread() +{ + lockIdamThread(); +# ifdef __GNUC__ + thread_t threadId = pthread_self(); +# else + thread_t threadId = GetCurrentThread(); +# endif + int id = getThreadId(threadId); + threadCount--; + if (id >= 0) { + for (int i = id; i < threadCount; i++) { + threadList[i] = threadList[i + 1]; // Shuffle state + idamState[i] = idamState[i + 1]; + idamState[i].id = i; + } + idamState[threadCount].id = threadCount; + idamState[threadCount].socket = -1; + idamState[threadCount].lastHandle = -1; + // initEnvironment(&(idamState[threadCount].environment)); + initClientBlock(&(idamState[threadCount].client_block), 0, ""); + initServerBlock(&(idamState[threadCount].server_block), 0); + threadList[threadCount] = 0; + } + unlockUdaThread(); +} + +#else +void lockIdamThread() {} +void unlockIdamThread() {} +void freeIdamThread() {} +#endif // NOPTHREADS + //! the principal IDAM API /** All requests are passed via two string arguments. These take multiple forms or patterns.\n\n Data source patterns:\n\n @@ -146,7 +335,7 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c CLIENT_FLAGS* client_flags = udaClientFlags(); // Lock the thread - lockIdamThread(client_flags); + lockIdamThread(); if (host != nullptr) { putIdamServerHost(host); @@ -174,7 +363,7 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c static bool reopen_logs = true; if (udaStartup(0, client_flags, &reopen_logs) != 0) { - unlockUdaThread(client_flags); + unlockUdaThread(); return PROBLEM_OPENING_LOGS; } @@ -217,7 +406,7 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c UDA_LOG(UDA_LOG_ERROR, "Error identifying the Data Source [%s]\n", data_source); addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, "Error identifying the Data Source"); } - unlockUdaThread(client_flags); + unlockUdaThread(); return -err; } @@ -246,7 +435,7 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c freeClientRequestBlock(&request_block); // Unlock the thread - unlockUdaThread(client_flags); + unlockUdaThread(); return handle; } @@ -261,7 +450,7 @@ int idamGetBatchAPIWithHost(const char** signals, const char** sources, int coun CLIENT_FLAGS* client_flags = udaClientFlags(); // Lock the thread - lockIdamThread(client_flags); + lockIdamThread(); if (host != nullptr) { putIdamServerHost(host); @@ -288,7 +477,7 @@ int idamGetBatchAPIWithHost(const char** signals, const char** sources, int coun static bool reopen_logs = true; if (udaStartup(0, client_flags, &reopen_logs) != 0) { - unlockUdaThread(client_flags); + unlockUdaThread(); return PROBLEM_OPENING_LOGS; } @@ -331,7 +520,7 @@ int idamGetBatchAPIWithHost(const char** signals, const char** sources, int coun if (udaNumErrors() == 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, "Error identifying the Data Source"); } - unlockUdaThread(client_flags); + unlockUdaThread(); return -err; } @@ -356,6 +545,6 @@ int idamGetBatchAPIWithHost(const char** signals, const char** sources, int coun #endif // Unlock the thread - unlockUdaThread(client_flags); + unlockUdaThread(); return err; } diff --git a/source/c_api/udaPutAPI.cpp b/source/c_api/udaPutAPI.cpp index 437b08ec..d658e041 100644 --- a/source/c_api/udaPutAPI.cpp +++ b/source/c_api/udaPutAPI.cpp @@ -12,7 +12,7 @@ #include "clientserver/allocData.h" #include "clientserver/errorLog.h" #include "clientserver/printStructs.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "client/makeClientRequestBlock.h" diff --git a/source/cache/cache.cpp b/source/cache/cache.cpp index c558ff54..8a71ebf1 100644 --- a/source/cache/cache.cpp +++ b/source/cache/cache.cpp @@ -1,6 +1,6 @@ #include "cache.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include #include diff --git a/source/cache/cache.h b/source/cache/cache.h index bc5edbd0..5a6bee8c 100644 --- a/source/cache/cache.h +++ b/source/cache/cache.h @@ -3,7 +3,7 @@ #include "export.h" #include "genStructs.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include #ifdef __cplusplus diff --git a/source/cache/fileCache.h b/source/cache/fileCache.h index e10324dc..c1feb50a 100644 --- a/source/cache/fileCache.h +++ b/source/cache/fileCache.h @@ -3,7 +3,7 @@ #include "export.h" #include "genStructs.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/cache/memcache.hpp b/source/cache/memcache.hpp index fe8159e3..cf1352d8 100755 --- a/source/cache/memcache.hpp +++ b/source/cache/memcache.hpp @@ -1,7 +1,7 @@ #ifndef UDA_CACHE_MEMCACHE_H #define UDA_CACHE_MEMCACHE_H -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "genStructs.h" #include "export.h" diff --git a/source/client/connection.h b/source/client/connection.h index 0e2a13bb..676e25b1 100644 --- a/source/client/connection.h +++ b/source/client/connection.h @@ -4,7 +4,7 @@ # define UDA_CLIENT_CONNECTION_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" # include # include "closedown.h" diff --git a/source/client/getEnvironment.h b/source/client/getEnvironment.h index aa8a29b1..718dc381 100644 --- a/source/client/getEnvironment.h +++ b/source/client/getEnvironment.h @@ -2,7 +2,7 @@ #define UDA_CLIENT_GETENVIRONMENT_H #include "export.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #ifdef FATCLIENT # define printIdamClientEnvironment printIdamClientEnvironmentFat diff --git a/source/client/makeClientRequestBlock.cpp b/source/client/makeClientRequestBlock.cpp index 4b3b68c2..f46bec99 100644 --- a/source/client/makeClientRequestBlock.cpp +++ b/source/client/makeClientRequestBlock.cpp @@ -22,7 +22,7 @@ Interprets the API arguments and assembles a Request data structure. #include -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaErrors.h" #include #include diff --git a/source/client/makeClientRequestBlock.h b/source/client/makeClientRequestBlock.h index 54c43aff..9c50afcb 100644 --- a/source/client/makeClientRequestBlock.h +++ b/source/client/makeClientRequestBlock.h @@ -2,7 +2,7 @@ #define UDA_CLIENT_MAKECLIENTREQUESTBLOCK_H #include "export.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/client/udaClient.cpp b/source/client/udaClient.cpp index 5444a9ea..7e4058cb 100644 --- a/source/client/udaClient.cpp +++ b/source/client/udaClient.cpp @@ -5,7 +5,7 @@ #include #include -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include "udaErrors.h" #include "udaTypes.h" @@ -88,6 +88,121 @@ void setLogMallocList(LOGMALLOCLIST* logmalloclist_in) {} extern SOCKETLIST socket_list; #endif +static std::vector data_blocks = {}; + +int getCurrentDataBlockIndex() +{ + auto client_flags = udaClientFlags(); + if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && + getIdamThreadLastHandle() >= 0) { + return getIdamThreadLastHandle(); + } + return data_blocks.size() - 1; +} + +void freeDataBlocks() +{ + data_blocks.clear(); + putIdamThreadLastHandle(-1); +} + +int growDataBlocks() +{ + auto client_flags = udaClientFlags(); + if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && + getIdamThreadLastHandle() >= 0) { + return 0; + } + + data_blocks.push_back({}); + initDataBlock(&data_blocks.back()); + data_blocks.back().handle = data_blocks.size() - 1; + + putIdamThreadLastHandle(data_blocks.size() - 1); + + return 0; +} + +static int findNewHandleIndex() +{ + for (int i = 0; i < (int)data_blocks.size(); i++) { + if (data_blocks[i].handle == -1) { + return i; + } + } + return -1; +} + +int getNewDataHandle() +{ + auto client_flags = udaClientFlags(); + int newHandleIndex = -1; + + if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && + (newHandleIndex = getIdamThreadLastHandle()) >= 0) { + if (client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) { + udaFree(newHandleIndex); + } else { + // Application has responsibility for freeing heap in the Data Block + initDataBlock(&data_blocks[newHandleIndex]); + } + data_blocks[newHandleIndex].handle = newHandleIndex; + return newHandleIndex; + } + + if ((newHandleIndex = findNewHandleIndex()) < 0) { // Search for an unused handle or issue a new one + newHandleIndex = data_blocks.size(); + data_blocks.push_back({}); + initDataBlock(&data_blocks[newHandleIndex]); + data_blocks[newHandleIndex].handle = newHandleIndex; + } else { + initDataBlock(&data_blocks[newHandleIndex]); + data_blocks[newHandleIndex].handle = newHandleIndex; + } + + putIdamThreadLastHandle(newHandleIndex); + return newHandleIndex; +} + +DATA_BLOCK* getDataBlock(int handle) +{ + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } + return &data_blocks[handle]; +} + +int newDataHandle() +{ + int newHandleIndex = -1; + auto client_flags = udaClientFlags(); + + if ((client_flags->flags & CLIENTFLAG_REUSELASTHANDLE || client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) && + (newHandleIndex = getIdamThreadLastHandle()) >= 0) { + if (client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE) { + udaFree(newHandleIndex); + } else { + // Application has responsibility for freeing heap in the Data Block + initDataBlock(&data_blocks[newHandleIndex]); + } + data_blocks[newHandleIndex].handle = newHandleIndex; + return newHandleIndex; + } + + if ((newHandleIndex = findNewHandleIndex()) < 0) { // Search for an unused handle or issue a new one + newHandleIndex = data_blocks.size(); + data_blocks.push_back({}); + initDataBlock(&data_blocks[newHandleIndex]); + data_blocks[newHandleIndex].handle = newHandleIndex; + } else { + initDataBlock(&data_blocks[newHandleIndex]); + data_blocks[newHandleIndex].handle = newHandleIndex; + } + + putIdamThreadLastHandle(newHandleIndex); + return newHandleIndex; +} + void updateClientBlock(CLIENT_BLOCK* str, const CLIENT_FLAGS* client_flags, unsigned int private_flags) { // other structure elements are set when the structure is initialised @@ -129,7 +244,7 @@ int check_file_cache(const REQUEST_DATA* request_data, DATA_BLOCK** p_data_block if (data != nullptr) { // Success - int data_block_idx = acc_getIdamNewDataHandle(client_flags); + int data_block_idx = getNewDataHandle(); if (data_block_idx < 0) { // Error return -data_block_idx; @@ -167,7 +282,7 @@ int check_mem_cache(uda::cache::UdaCache* cache, REQUEST_DATA* request_data, DAT if (data != nullptr) { // Success - int data_block_idx = acc_getIdamNewDataHandle(client_flags); + int data_block_idx = getNewDataHandle(client_flags); if (data_block_idx < 0) { // Error return -data_block_idx; @@ -936,14 +1051,14 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) //------------------------------------------------------------------------------ // Allocate memory for the Data Block Structure // Re-use existing stale Data Blocks - int data_block_idx = acc_getIdamNewDataHandle(client_flags); + int data_block_idx = getNewDataHandle(); if (data_block_idx < 0) { // Error data_block_indices[i] = -data_block_idx; continue; } - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); // DATA_BLOCK* in_data; // if (request_block->requests[i].request == REQUEST_CACHED) { @@ -1005,13 +1120,13 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) DATA_BLOCK_LIST data_block_list0; initDataBlockList(&data_block_list0); - err = fatServer(client_block, &server_block, request_block, &data_block_list0); + err = 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]; - int data_block_idx = acc_getIdamNewDataHandle(client_flags); - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); // data blocks may have been realloc'ed + int data_block_idx = getNewDataHandle(); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); // data blocks may have been realloc'ed copyDataBlock(data_block, data_block0); if (err != 0 || server_block.idamerrorstack.nerrors > 0) { @@ -1069,7 +1184,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, "Data Status is BAD ... Data are Not Usable!"); - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); if (data_block->errcode == 0) { // Don't over-rule a server side error data_block->errcode = DATA_STATUS_BAD; @@ -1089,7 +1204,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Copy Most Significant Error Stack Message to the Data Block if a Handle was Issued for (auto data_block_idx : data_block_indices) { - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); if (data_block->errcode == 0 && server_block.idamerrorstack.nerrors > 0) { data_block->errcode = getIdamServerErrorStackRecordCode(0); @@ -1151,7 +1266,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, "Data Status is BAD ... Data are Not Usable!"); - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); if (data_block->errcode == 0) { // Don't over-rule a server side error data_block->errcode = DATA_STATUS_BAD; @@ -1161,7 +1276,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) } for (auto data_block_idx : data_block_indices) { - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); if (err != 0 && data_block->errcode == 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Unknown Error"); @@ -1181,7 +1296,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Copy Most Significant Error Stack Message to the Data Block if a Handle was Issued for (auto data_block_idx : data_block_indices) { - DATA_BLOCK* data_block = getIdamDataBlock(data_block_idx); + DATA_BLOCK* data_block = getDataBlock(data_block_idx); if (data_block->errcode == 0 && server_block.idamerrorstack.nerrors > 0) { data_block->errcode = getIdamServerErrorStackRecordCode(0); @@ -1228,7 +1343,7 @@ void udaFree(int handle) DIMS* ddims; int rank; - DATA_BLOCK* data_block = getIdamDataBlock(handle); + DATA_BLOCK* data_block = getDataBlock(handle); if (data_block == nullptr) { return; @@ -1433,17 +1548,11 @@ void udaFreeAll() uda::cache::free_cache(); #endif - CLIENT_FLAGS* client_flags = udaClientFlags(); - - for (int i = 0; i < acc_getCurrentDataBlockIndex(client_flags); ++i) { -#ifndef FATCLIENT - freeDataBlock(getIdamDataBlock(i)); -#else - freeDataBlock(getIdamDataBlock(i)); -#endif + for (int i = 0; i < getCurrentDataBlockIndex(); ++i) { + freeDataBlock(getDataBlock(i)); } - acc_freeDataBlocks(); + freeDataBlocks(); #ifndef FATCLIENT g_user_defined_type_list = nullptr; // malloc'd within protocolXML diff --git a/source/client/udaClient.h b/source/client/udaClient.h index 8f1bd07c..c85fb15e 100644 --- a/source/client/udaClient.h +++ b/source/client/udaClient.h @@ -5,7 +5,43 @@ # include "client.h" # include "genStructs.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" + +typedef struct ClientFlags { + int get_dimdble; // (Server Side) Return Dimensional Data in Double Precision + int get_timedble; // (Server Side) Server Side cast of time dimension to double precision if in compresed format + int get_scalar; // (Server Side) Reduce Rank from 1 to 0 (Scalar) if time data are all zero + int get_bytes; // (Server Side) Return IDA Data in native byte or integer array without IDA signal's + // calibration factor applied + int get_meta; // (Server Side) return All Meta Data + int get_asis; // (Server Side) Apply no XML based corrections to Data or Dimensions + int get_uncal; // (Server Side) Apply no XML based Calibrations to Data + int get_notoff; // (Server Side) Apply no XML based Timing Corrections to Data + int get_nodimdata; + + int get_datadble; // (Client Side) Return Data in Double Precision + int get_bad; // (Client Side) return data with BAD Status value + int get_synthetic; // (Client Side) Return Synthetic Data if available instead of Original data + + uint32_t flags; + + int user_timeout; + int alt_rank; +} CLIENT_FLAGS; + +DATA_BLOCK* getDataBlock(int handle); + +void putIdamThreadServerBlock(SERVER_BLOCK* str); + +void putIdamThreadClientBlock(CLIENT_BLOCK* str); + +SERVER_BLOCK getIdamThreadServerBlock(); + +CLIENT_BLOCK getIdamThreadClientBlock(); + +CLIENT_FLAGS* udaClientFlags(); + +unsigned int* udaPrivateFlags(); int idamClient(REQUEST_BLOCK* request_block, int* indices); diff --git a/source/client2/client.cpp b/source/client2/client.cpp index 65d96ee9..09cabf59 100644 --- a/source/client2/client.cpp +++ b/source/client2/client.cpp @@ -7,7 +7,7 @@ #include "exceptions.hpp" #include "make_request_block.hpp" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaDefines.h" #include "udaErrors.h" #include "udaTypes.h" @@ -35,7 +35,7 @@ void copy_data_block(DATA_BLOCK* str, DATA_BLOCK* in) initClientBlock(&str->client_block, 0, ""); } -void copy_client_block(CLIENT_BLOCK* str, const ClientFlags* client_flags) +void copy_client_block(CLIENT_BLOCK* str, const uda::client::ClientFlags* client_flags) { str->timeout = client_flags->user_timeout; str->clientFlags = client_flags->flags; @@ -75,7 +75,7 @@ int alloc_meta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, DATA_SO return err; } -void update_client_block(CLIENT_BLOCK& client_block, const ClientFlags& client_flags, unsigned int private_flags) +void update_client_block(CLIENT_BLOCK& client_block, const uda::client::ClientFlags& client_flags, unsigned int private_flags) { client_block.timeout = client_flags.user_timeout; client_block.clientFlags = client_flags.flags; @@ -1160,7 +1160,7 @@ void uda::client::Client::concat_errors(UDA_ERROR_STACK* error_stack) error_stack->nerrors = inew; } -const CLIENT_FLAGS* uda::client::Client::client_flags() +const uda::client::ClientFlags* uda::client::Client::client_flags() { return &client_flags_; } diff --git a/source/client2/client.hpp b/source/client2/client.hpp index 79d8708e..eaf0e842 100644 --- a/source/client2/client.hpp +++ b/source/client2/client.hpp @@ -9,7 +9,7 @@ #include #include -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include #include "connection.hpp" @@ -32,6 +32,28 @@ struct MetadataBlock { DATA_SYSTEM data_system; }; +typedef struct ClientFlags { + int get_dimdble; // (Server Side) Return Dimensional Data in Double Precision + int get_timedble; // (Server Side) Server Side cast of time dimension to double precision if in compresed format + int get_scalar; // (Server Side) Reduce Rank from 1 to 0 (Scalar) if time data are all zero + int get_bytes; // (Server Side) Return IDA Data in native byte or integer array without IDA signal's + // calibration factor applied + int get_meta; // (Server Side) return All Meta Data + int get_asis; // (Server Side) Apply no XML based corrections to Data or Dimensions + int get_uncal; // (Server Side) Apply no XML based Calibrations to Data + int get_notoff; // (Server Side) Apply no XML based Timing Corrections to Data + int get_nodimdata; + + int get_datadble; // (Client Side) Return Data in Double Precision + int get_bad; // (Client Side) return data with BAD Status value + int get_synthetic; // (Client Side) Return Synthetic Data if available instead of Original data + + uint32_t flags; + + int user_timeout; + int alt_rank; +} CLIENT_FLAGS; + class Client { public: diff --git a/source/client2/client_environment.hpp b/source/client2/client_environment.hpp index 7af45eb4..e5dabf02 100644 --- a/source/client2/client_environment.hpp +++ b/source/client2/client_environment.hpp @@ -3,7 +3,7 @@ #ifndef UDA_SOURCE_CLIENT2_CLIENT_ENVIRONMENT_H #define UDA_SOURCE_CLIENT2_CLIENT_ENVIRONMENT_H -#include "udaStructs.h" +#include "clientserver/udaStructs.h" namespace uda { namespace client { diff --git a/source/client2/connection.hpp b/source/client2/connection.hpp index de84db11..98b12baa 100755 --- a/source/client2/connection.hpp +++ b/source/client2/connection.hpp @@ -6,7 +6,7 @@ #include #include -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "export.h" #include "closedown.hpp" diff --git a/source/client2/handle.cpp b/source/client2/handle.cpp index f4045c51..24254f7c 100644 --- a/source/client2/handle.cpp +++ b/source/client2/handle.cpp @@ -1,8 +1,8 @@ #include "handle.hpp" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "udaTypes.h" #include "thread_client.hpp" diff --git a/source/client2/make_request_block.cpp b/source/client2/make_request_block.cpp index 212aa984..1727de05 100644 --- a/source/client2/make_request_block.cpp +++ b/source/client2/make_request_block.cpp @@ -4,7 +4,7 @@ #include #include -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaErrors.h" #include #include diff --git a/source/client2/make_request_block.hpp b/source/client2/make_request_block.hpp index 86f5a318..bba31a7d 100755 --- a/source/client2/make_request_block.hpp +++ b/source/client2/make_request_block.hpp @@ -3,7 +3,7 @@ #ifndef UDA_CLIENT_MAKECLIENTREQUESTBLOCK_H #define UDA_CLIENT_MAKECLIENTREQUESTBLOCK_H -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "export.h" namespace uda { diff --git a/source/clientserver/CMakeLists.txt b/source/clientserver/CMakeLists.txt index bd017731..f4bf47a2 100755 --- a/source/clientserver/CMakeLists.txt +++ b/source/clientserver/CMakeLists.txt @@ -46,7 +46,8 @@ set( SRC_FILES xdrlib.cpp nameValueSubstitution.cpp udaStructs.cpp -# utils.c + make_request_block.cpp + # utils.c ) set( HIERARCHICAL_SRC_FILES diff --git a/source/clientserver/copyStructs.cpp b/source/clientserver/copyStructs.cpp index b9b3fded..e779166d 100644 --- a/source/clientserver/copyStructs.cpp +++ b/source/clientserver/copyStructs.cpp @@ -1,6 +1,7 @@ #include "copyStructs.h" #include +#include void copyRequestData(REQUEST_DATA* out, REQUEST_DATA in) { @@ -26,44 +27,3 @@ void copyRequestBlock(REQUEST_BLOCK* out, REQUEST_BLOCK in) } } -void copyDataSource(DATA_SOURCE* out, DATA_SOURCE in) -{ - *out = in; - strcpy(out->source_alias, in.source_alias); - strcpy(out->pass_date, in.pass_date); - strcpy(out->archive, in.archive); - strcpy(out->device_name, in.device_name); - strcpy(out->format, in.format); - strcpy(out->path, in.path); - strcpy(out->filename, in.filename); - strcpy(out->server, in.server); - strcpy(out->userid, in.userid); - strcpy(out->reason_desc, in.reason_desc); - strcpy(out->status_desc, in.status_desc); - strcpy(out->run_desc, in.run_desc); - strcpy(out->modified, in.modified); - strcpy(out->creation, in.creation); - strcpy(out->xml, in.xml); - strcpy(out->xml_creation, in.xml_creation); -} - -void copyPluginInterface(IDAM_PLUGIN_INTERFACE* out, IDAM_PLUGIN_INTERFACE* in) -{ - out->interfaceVersion = in->interfaceVersion; - out->pluginVersion = in->pluginVersion; - out->sqlConnectionType = in->sqlConnectionType; - out->verbose = in->verbose; - out->housekeeping = in->housekeeping; - out->changePlugin = in->changePlugin; - out->dbgout = in->dbgout; - out->errout = in->errout; - out->data_block = in->data_block; - out->request_data = in->request_data; - out->client_block = in->client_block; - out->data_source = in->data_source; - out->signal_desc = in->signal_desc; - out->environment = in->environment; - out->sqlConnection = in->sqlConnection; - out->pluginList = in->pluginList; - out->userdefinedtypelist = in->userdefinedtypelist; -} diff --git a/source/clientserver/copyStructs.h b/source/clientserver/copyStructs.h index b00b2af5..7a37e173 100644 --- a/source/clientserver/copyStructs.h +++ b/source/clientserver/copyStructs.h @@ -1,20 +1,9 @@ #ifndef UDA_CLIENTSERVER_COPYSTRUCTS_H #define UDA_CLIENTSERVER_COPYSTRUCTS_H -#include "export.h" -#include "udaPlugin.h" #include "udaStructs.h" -#ifdef __cplusplus -extern "C" { -#endif - -LIBRARY_API void copyRequestBlock(REQUEST_BLOCK* out, REQUEST_BLOCK in); -LIBRARY_API void copyDataSource(DATA_SOURCE* out, DATA_SOURCE in); -LIBRARY_API void copyPluginInterface(IDAM_PLUGIN_INTERFACE* out, IDAM_PLUGIN_INTERFACE* in); - -#ifdef __cplusplus -} -#endif +void copyRequestData(REQUEST_DATA* out, REQUEST_DATA in); +void copyRequestBlock(REQUEST_BLOCK* out, REQUEST_BLOCK in); #endif // UDA_CLIENTSERVER_COPYSTRUCTS_H diff --git a/source/clientserver/errorLog.cpp b/source/clientserver/errorLog.cpp index 5c22337e..e1b8d019 100644 --- a/source/clientserver/errorLog.cpp +++ b/source/clientserver/errorLog.cpp @@ -3,16 +3,41 @@ #include #include +#include "client.h" #include #include static std::vector udaerrorstack; -int udaNumErrors() +int udaNumErrors(void) { return static_cast(udaerrorstack.size()); } +const char* udaGetErrorMessage(int err_num) +{ + if (err_num > (int)udaerrorstack.size() && err_num < (int)udaerrorstack.size()) { + return udaerrorstack[err_num].msg; + } + return "no error found"; +} + +int udaGetErrorCode(int err_num) +{ + if (err_num > (int)udaerrorstack.size() && err_num < (int)udaerrorstack.size()) { + return udaerrorstack[err_num].code; + } + return -1; +} + +const char* udaGetErrorLocation(int err_num) +{ + if (err_num > (int)udaerrorstack.size() && err_num < (int)udaerrorstack.size()) { + return udaerrorstack[err_num].location; + } + return "no error found"; +} + void udaErrorLog(CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, UDA_ERROR_STACK* error_stack) { UDA_ERROR* errors = nullptr; @@ -95,7 +120,7 @@ void printIdamErrorStack() // 1 => Code Error // 2 => Plugin Error -void addIdamError(int type, const char* location, int code, const char* msg) +UDA_ERROR createIdamError(int type, const char* location, int code, const char* msg) { UDA_ERROR error; @@ -127,7 +152,12 @@ void addIdamError(int type, const char* location, int code, const char* msg) } } - udaerrorstack.push_back(error); + return error; +} + +void addIdamError(int type, const char* location, int code, const char* msg) +{ + udaerrorstack.push_back(createIdamError(type, location, code, msg)); } // Concatenate Error Stack structures diff --git a/source/clientserver/errorLog.h b/source/clientserver/errorLog.h index 806199a7..78a79bed 100644 --- a/source/clientserver/errorLog.h +++ b/source/clientserver/errorLog.h @@ -1,7 +1,3 @@ -#ifndef UDA_CLIENTSERVER_ERRORLOG_H -#define UDA_CLIENTSERVER_ERRORLOG_H - -#include "export.h" #include "udaStructs.h" #include @@ -14,28 +10,18 @@ #define UDA_CODE_ERROR_TYPE 2 #define UDA_PLUGIN_ERROR_TYPE 3 -#ifdef __cplusplus -extern "C" { -#endif - -LIBRARY_API int udaNumErrors(void); -LIBRARY_API void udaErrorLog(CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, UDA_ERROR_STACK* error_stack); -LIBRARY_API void initUdaErrorStack(void); -LIBRARY_API void initErrorRecords(const UDA_ERROR_STACK* errorstack); -LIBRARY_API void printIdamErrorStack(void); -LIBRARY_API void addIdamError(int type, const char* location, int code, const char* msg); -LIBRARY_API void concatUdaError(UDA_ERROR_STACK* errorstackout); -LIBRARY_API void freeIdamErrorStack(UDA_ERROR_STACK* errorstack); -LIBRARY_API void closeUdaError(void); - -#ifdef __cplusplus -} -#endif +void udaErrorLog(CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, UDA_ERROR_STACK* error_stack); +void initUdaErrorStack(void); +void initErrorRecords(const UDA_ERROR_STACK* errorstack); +void printIdamErrorStack(void); +void addIdamError(int type, const char* location, int code, const char* msg); +UDA_ERROR createIdamError(int type, const char* location, int code, const char* msg); +void concatUdaError(UDA_ERROR_STACK* errorstackout); +void freeIdamErrorStack(UDA_ERROR_STACK* errorstack); +void closeUdaError(void); #define UDA_ADD_ERROR(ERR, MSG) addIdamError(UDA_CODE_ERROR_TYPE, __func__, ERR, MSG) #define UDA_ADD_SYS_ERROR(MSG) addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, MSG) #define UDA_THROW_ERROR(ERR, MSG) \ addIdamError(UDA_CODE_ERROR_TYPE, __func__, ERR, MSG); \ return ERR; - -#endif // UDA_CLIENTSERVER_ERRORLOG_H diff --git a/source/include/initStructs.h b/source/clientserver/initStructs.h similarity index 99% rename from source/include/initStructs.h rename to source/clientserver/initStructs.h index ba215cf6..5e08bc2d 100644 --- a/source/include/initStructs.h +++ b/source/clientserver/initStructs.h @@ -2,6 +2,7 @@ #define UDA_CLIENTSERVER_INITSTRUCTS_H #include "export.h" + #include "udaStructs.h" #ifdef __cplusplus diff --git a/source/clientserver/makeRequestBlock.cpp b/source/clientserver/makeRequestBlock.cpp index 68b0edca..42ba1d23 100644 --- a/source/clientserver/makeRequestBlock.cpp +++ b/source/clientserver/makeRequestBlock.cpp @@ -17,11 +17,14 @@ #include "errorLog.h" #include "parseXML.h" -#include "pluginStructs.h" +#include "plugins/pluginStructs.h" #include "stringUtils.h" #include "udaErrors.h" #include "udaStructs.h" +// TODO: remove this! +#include "server/serverPlugin.h" + #if !defined(__GNUC__) && defined(_WIN32) # include # define strcasecmp _stricmp @@ -35,7 +38,7 @@ static void extract_function_name(const char* str, REQUEST_DATA* request); -static int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIST pluginList, +static int source_file_format_test(const char* source, REQUEST_DATA* request, const PLUGINLIST* pluginList, const ENVIRONMENT* environment); static int extract_archive(REQUEST_DATA* request, int reduceSignal, const ENVIRONMENT* environment); @@ -44,6 +47,16 @@ static int generic_request_test(const char* source, REQUEST_DATA* request); static int extract_subset(REQUEST_DATA* request); +namespace uda { +struct NameValue { + std::string pair; + std::string name; + std::string value; +}; + +std::vector name_value_pairs(std::string_view input, bool strip); +} + static int find_plugin_id_by_format(const char* format, const PLUGINLIST* plugin_list) { for (int i = 0; i < plugin_list->count; i++) { @@ -54,7 +67,7 @@ static int find_plugin_id_by_format(const char* format, const PLUGINLIST* plugin return -1; } -int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONMENT* environment) +int makeRequestData(REQUEST_DATA* request, const PLUGINLIST* pluginList, const ENVIRONMENT* environment) { int ldelim; int err = 0; @@ -244,9 +257,9 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM #ifdef JETSERVER if (rc < 0) { strcpy(request->format, "PPF"); // Assume the Default Format (PPF?) - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(request->format, pluginList.plugin[i].format)) { - request->request = pluginList.plugin[i].request; + for (int i = 0; i < pluginList->count; i++) { + if (STR_IEQUALS(request->format, pluginList->plugin[i].format)) { + request->request = pluginList->plugin[i].request; break; } } @@ -294,10 +307,10 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM reduceSignal = false; extract_archive(request, reduceSignal, environment); - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(request->archive, pluginList.plugin[i].format)) { - request->request = pluginList.plugin[i].request; // Found! - strcpy(request->format, pluginList.plugin[i].format); + for (int i = 0; i < pluginList->count; i++) { + if (STR_IEQUALS(request->archive, pluginList->plugin[i].format)) { + request->request = pluginList->plugin[i].request; // Found! + strcpy(request->format, pluginList->plugin[i].format); break; } } @@ -317,17 +330,17 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // Test for known File formats, Server protocols or Libraries or Devices - 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) { - request->request = pluginList.plugin[i].request; // Found - strcpy(request->format, pluginList.plugin[i].format); - if (pluginList.plugin[i].plugin_class != + 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) { + 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 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_PLUGIN_CLASS_FUNCTION) { isFunction = true; extract_function_name(work, request); } @@ -340,8 +353,8 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM #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_PLUGIN_CLASS_FILE; + isServer = pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_SERVER; break; } else { @@ -350,17 +363,17 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // Substitute the Device name with the protocol and server details 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) { + // 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) { - snprintf(work, MAXMETA, "%s%s%s", pluginList.plugin[i].deviceProtocol, request->api_delim, - pluginList.plugin[i].deviceHost); + snprintf(work, MAXMETA, "%s%s%s", pluginList->plugin[i].deviceProtocol, request->api_delim, + pluginList->plugin[i].deviceHost); UDA_LOG(UDA_LOG_DEBUG, "work#1: %s\n", work); - if (pluginList.plugin[i].devicePort[0] != '\0') { + if (pluginList->plugin[i].devicePort[0] != '\0') { strcat(work, ":"); - strcat(work, pluginList.plugin[i].devicePort); + strcat(work, pluginList->plugin[i].devicePort); } UDA_LOG(UDA_LOG_DEBUG, "work#2: %s\n", work); UDA_LOG(UDA_LOG_DEBUG, "test: %s\n", test); @@ -560,12 +573,12 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM if (isFunction && err == 0) { // Test for known Function Libraries isFunction = false; - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(request->archive, pluginList.plugin[i].format)) { - request->request = pluginList.plugin[i].request; // Found - strcpy(request->format, pluginList.plugin[i].format); + for (int i = 0; i < pluginList->count; i++) { + 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 + (pluginList->plugin[i].plugin_class == UDA_PLUGIN_CLASS_FUNCTION); // Must be a known Library break; } } @@ -574,11 +587,11 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM UDA_LOG(UDA_LOG_DEBUG, "isFunction: %d\n", isFunction); if (!isFunction) { // Must be a default server-side function - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(pluginList.plugin[i].symbol, "SERVERSIDE") && - pluginList.plugin[i].library[0] == '\0') { + for (int i = 0; i < pluginList->count; i++) { + if (STR_IEQUALS(pluginList->plugin[i].symbol, "SERVERSIDE") && + pluginList->plugin[i].library[0] == '\0') { request->request = REQUEST_READ_SERVERSIDE; // Found - strcpy(request->format, pluginList.plugin[i].format); + strcpy(request->format, pluginList->plugin[i].format); isFunction = true; break; } @@ -602,15 +615,15 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // Exception is Serverside function 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 && - strcasecmp(pluginList.plugin[id].symbol, "serverside") != 0) { + int id = find_plugin_id_by_format(request->archive, pluginList); + if (id >= 0 && pluginList->plugin[id].plugin_class == 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 - strcpy(request->format, pluginList.plugin[id].format); + request->request = pluginList->plugin[id].request; // Found + strcpy(request->format, pluginList->plugin[id].format); UDA_LOG(UDA_LOG_DEBUG, "D request: %d\n", request->request); } else { - if (request->request != pluginList.plugin[id].request) { // Inconsistent + if (request->request != pluginList->plugin[id].request) { // Inconsistent // Let Source have priority over the Signal? UDA_LOG(UDA_LOG_DEBUG, "Inconsistent Plugin Libraries: Source selected over Signal\n"); } @@ -724,7 +737,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM return 0; } -int make_request_block(REQUEST_BLOCK* request_block, PLUGINLIST pluginList, const ENVIRONMENT* environment) +int make_request_block(REQUEST_BLOCK* request_block, const PLUGINLIST* pluginList, const ENVIRONMENT* environment) { int rc = 0; @@ -770,7 +783,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, PLUGINLIST pluginList, +int source_file_format_test(const char* source, REQUEST_DATA* request, const PLUGINLIST* pluginList, const ENVIRONMENT* environment) { int rc = 0; @@ -945,9 +958,9 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS // TO DO: make extensions a list of valid extensions to minimise plugin duplication int breakAgain = 0; - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(&test[1], pluginList.plugin[i].extension)) { - strcpy(request->format, pluginList.plugin[i].format); + for (int i = 0; i < pluginList->count; i++) { + if (STR_IEQUALS(&test[1], pluginList->plugin[i].extension)) { + strcpy(request->format, pluginList->plugin[i].format); breakAgain = 1; break; } @@ -1005,12 +1018,12 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS // Test for known registered plugins for the File's format - for (int i = 0; i < pluginList.count; i++) { - if (STR_IEQUALS(request->format, pluginList.plugin[i].format)) { + for (int i = 0; i < pluginList->count; i++) { + if (STR_IEQUALS(request->format, pluginList->plugin[i].format)) { rc = 1; 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 != + 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 } else { @@ -1521,6 +1534,55 @@ void parse_name_value(const char* pair, NAMEVALUE* nameValue, unsigned short str free(copy); } +uda::NameValue parse_name_value(std::string_view argument, bool strip) +{ + std::vector tokens; + boost::split(tokens, argument, boost::is_any_of("="), boost::token_compress_on); + + for (auto& token : tokens) { + boost::trim(token); + } + + uda::NameValue name_value = {}; + name_value.pair = argument; + + if (tokens.size() == 2) { + // argument is name=value + name_value.name = tokens[0]; + name_value.value = tokens[1]; + } else if (tokens.size() == 1) { + // argument is name or /name + if (boost::starts_with(tokens[0], "/")) { + name_value.name = tokens[0].substr(1); + } else { + name_value.name = tokens[0]; + } + } else { + throw std::runtime_error{"invalid token"}; + } + + if (strip) { + boost::trim_if(name_value.value, boost::is_any_of("'\"")); + } + + return name_value; +} + +std::vector uda::name_value_pairs(std::string_view input, bool strip) +{ + std::vector name_values; + + std::vector tokens; + boost::split(tokens, input, boost::is_any_of(","), boost::token_compress_on); + + name_values.reserve(tokens.size()); + for (const auto& token : tokens) { + name_values.push_back(parse_name_value(token, strip)); + } + + return name_values; +} + int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigned short strip) { // Ignore delimiter in anything enclosed in single or double quotes diff --git a/source/clientserver/makeRequestBlock.h b/source/clientserver/makeRequestBlock.h index 60f885a6..d0488fb3 100644 --- a/source/clientserver/makeRequestBlock.h +++ b/source/clientserver/makeRequestBlock.h @@ -1,23 +1,11 @@ -#ifndef UDA_CLIENSERVER_MAKEREQUESTBLOCK_H -#define UDA_CLIENSERVER_MAKEREQUESTBLOCK_H +#pragma once -#include "pluginStructs.h" - -#include "export.h" #include "udaStructs.h" -#ifdef __cplusplus -extern "C" { -#endif - -LIBRARY_API int make_request_block(REQUEST_BLOCK* request_block, PLUGINLIST pluginList, const ENVIRONMENT* environment); -LIBRARY_API int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONMENT* environment); -LIBRARY_API int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigned short strip); -LIBRARY_API void freeNameValueList(NAMEVALUELIST* nameValueList); -LIBRARY_API void expand_environment_variables(char* path); - -#ifdef __cplusplus -} -#endif +typedef struct PluginList PLUGINLIST; -#endif // UDA_CLIENSERVER_MAKEREQUESTBLOCK_H +int make_request_block(REQUEST_BLOCK* request_block, const PLUGINLIST* pluginList, const ENVIRONMENT* environment); +int makeRequestData(REQUEST_DATA* request, const PLUGINLIST* pluginList, const ENVIRONMENT* environment); +int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigned short strip); +void freeNameValueList(NAMEVALUELIST* nameValueList); +void expand_environment_variables(char* path); diff --git a/source/include/udaStructs.h b/source/clientserver/udaStructs.h similarity index 100% rename from source/include/udaStructs.h rename to source/clientserver/udaStructs.h diff --git a/source/include/accAPI.h b/source/include/accAPI.h index d6c0df5e..a3031b84 100644 --- a/source/include/accAPI.h +++ b/source/include/accAPI.h @@ -7,7 +7,6 @@ #include "client.h" #include "export.h" #include "genStructs.h" -#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -15,39 +14,21 @@ extern "C" { #define UDA_NUM_CLIENT_THREADS 30 -LIBRARY_API DATA_BLOCK* acc_getCurrentDataBlock(CLIENT_FLAGS* client_flags); - -LIBRARY_API int acc_getCurrentDataBlockIndex(CLIENT_FLAGS* client_flags); - -LIBRARY_API int acc_growIdamDataBlocks(CLIENT_FLAGS* client_flags); - -LIBRARY_API int acc_getIdamNewDataHandle(CLIENT_FLAGS* client_flags); - -LIBRARY_API void acc_freeDataBlocks(); - LIBRARY_API void setIdamPrivateFlag(unsigned int flag); LIBRARY_API void resetIdamPrivateFlag(unsigned int flag); -LIBRARY_API void setIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag); - -LIBRARY_API void resetIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag); - -LIBRARY_API void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags); - -LIBRARY_API int getIdamProperty(const char* property, const CLIENT_FLAGS* client_flags); - -LIBRARY_API void resetIdamProperty(const char* property, CLIENT_FLAGS* client_flags); +LIBRARY_API void setIdamClientFlag(unsigned int flag); -LIBRARY_API void resetIdamProperties(CLIENT_FLAGS* client_flags); +LIBRARY_API void resetIdamClientFlag(unsigned int flag); -LIBRARY_API CLIENT_BLOCK saveIdamProperties(const CLIENT_FLAGS* client_flags); +LIBRARY_API void setIdamProperty(const char* property); -LIBRARY_API void restoreIdamProperties(CLIENT_BLOCK cb, CLIENT_FLAGS* client_flags); +LIBRARY_API int getIdamProperty(const char* property); -LIBRARY_API CLIENT_BLOCK* getIdamProperties(int handle); +LIBRARY_API void resetIdamProperty(const char* property); -LIBRARY_API CLIENT_BLOCK* getIdamDataProperties(int handle); +LIBRARY_API void resetIdamProperties(); #ifndef __APPLE__ @@ -71,8 +52,6 @@ LIBRARY_API void putIdamServerSocket(int socket); LIBRARY_API void getIdamServer(const char** host, int* port, int* socket); -LIBRARY_API UDA_ERROR_STACK* getUdaServerErrorStack(); - LIBRARY_API int getIdamErrorCode(int handle); LIBRARY_API const char* getIdamErrorMsg(int handle); @@ -83,8 +62,6 @@ LIBRARY_API int getIdamSignalStatus(int handle); LIBRARY_API int getIdamDataStatus(int handle); -LIBRARY_API int getIdamLastHandle(CLIENT_FLAGS* client_flags); - LIBRARY_API int getIdamDataNum(int handle); LIBRARY_API int getIdamRank(int handle); @@ -169,10 +146,6 @@ LIBRARY_API void getIdamFloatAsymmetricError(int handle, int above, float* fp); LIBRARY_API void getIdamFloatError(int handle, float* fp); -LIBRARY_API void getIdamDBlock(int handle, DATA_BLOCK* db); - -LIBRARY_API DATA_BLOCK* getIdamDataBlock(int handle); - LIBRARY_API const char* getIdamDataLabel(int handle); LIBRARY_API void getIdamDataLabelTdi(int handle, char* label); @@ -213,8 +186,6 @@ LIBRARY_API void getIdamFloatDimData(int handle, int ndim, float* fp); LIBRARY_API void getIdamGenericDimData(int handle, int ndim, void* data); -LIBRARY_API DIMS* getIdamDimBlock(int handle, int ndim); - LIBRARY_API char* getIdamDimAsymmetricError(int handle, int ndim, int above); LIBRARY_API char* getIdamDimError(int handle, int ndim); @@ -223,62 +194,28 @@ LIBRARY_API void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, LIBRARY_API void getIdamFloatDimError(int handle, int ndim, float* fp); -LIBRARY_API DATA_SYSTEM* getIdamDataSystem(int handle); - -LIBRARY_API SYSTEM_CONFIG* getIdamSystemConfig(int handle); - -LIBRARY_API DATA_SOURCE* getIdamDataSource(int handle); - -LIBRARY_API SIGNAL* getIdamSignal(int handle); - -LIBRARY_API SIGNAL_DESC* getIdamSignalDesc(int handle); - -LIBRARY_API const char* getIdamFileFormat(int handle); - -LIBRARY_API void initIdamDataBlock(DATA_BLOCK* str); - -LIBRARY_API void initIdamRequestBlock(REQUEST_BLOCK* str); - LIBRARY_API int idamDataCheckSum(void* data, int data_n, int type); LIBRARY_API int getIdamDataCheckSum(int handle); LIBRARY_API int getIdamDimDataCheckSum(int handle, int ndim); -LIBRARY_API void lockIdamThread(CLIENT_FLAGS* client_flags); - -LIBRARY_API void unlockUdaThread(CLIENT_FLAGS* client_flags); - -LIBRARY_API void freeIdamThread(CLIENT_FLAGS* client_flags); - LIBRARY_API int getIdamThreadLastHandle(); LIBRARY_API void putIdamThreadLastHandle(int handle); LIBRARY_API int getIdamMaxThreadCount(); -LIBRARY_API SERVER_BLOCK getIdamThreadServerBlock(); - -LIBRARY_API CLIENT_BLOCK getIdamThreadClientBlock(); - -LIBRARY_API void putIdamThreadServerBlock(SERVER_BLOCK* str); - -LIBRARY_API void putIdamThreadClientBlock(CLIENT_BLOCK* str); - LIBRARY_API int setIdamDataTree(int handle); // Return a specific data tree +typedef struct NTree NTREE; + LIBRARY_API NTREE* getIdamDataTree(int handle); // Return a user defined data structure definition -LIBRARY_API USERDEFINEDTYPE* getIdamUserDefinedType(int handle); - -LIBRARY_API USERDEFINEDTYPELIST* getIdamUserDefinedTypeList(int handle); - -LIBRARY_API LOGMALLOCLIST* getIdamLogMallocList(int handle); - LIBRARY_API NTREE* findIdamNTreeStructureDefinition(NTREE* node, const char* target); #ifdef __cplusplus diff --git a/source/include/client.h b/source/include/client.h index a5525052..4102fb84 100644 --- a/source/include/client.h +++ b/source/include/client.h @@ -6,7 +6,6 @@ #include "export.h" #include "genStructs.h" -#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -35,35 +34,10 @@ extern "C" { #define MIN_STATUS (-1) // Deny Access to Data if this Status Value #define DATA_STATUS_BAD (-17000) // Error Code if Status is Bad -typedef struct ClientFlags { - int get_dimdble; // (Server Side) Return Dimensional Data in Double Precision - int get_timedble; // (Server Side) Server Side cast of time dimension to double precision if in compresed format - int get_scalar; // (Server Side) Reduce Rank from 1 to 0 (Scalar) if time data are all zero - int get_bytes; // (Server Side) Return IDA Data in native byte or integer array without IDA signal's - // calibration factor applied - int get_meta; // (Server Side) return All Meta Data - int get_asis; // (Server Side) Apply no XML based corrections to Data or Dimensions - int get_uncal; // (Server Side) Apply no XML based Calibrations to Data - int get_notoff; // (Server Side) Apply no XML based Timing Corrections to Data - int get_nodimdata; - - int get_datadble; // (Client Side) Return Data in Double Precision - int get_bad; // (Client Side) return data with BAD Status value - int get_synthetic; // (Client Side) Return Synthetic Data if available instead of Original data - - uint32_t flags; - - int user_timeout; - int alt_rank; -} CLIENT_FLAGS; - LIBRARY_API void udaFree(int handle); LIBRARY_API void udaFreeAll(); -LIBRARY_API CLIENT_FLAGS* udaClientFlags(); -LIBRARY_API unsigned int* udaPrivateFlags(); - /** * Get the version of the client c-library. */ @@ -108,6 +82,17 @@ LIBRARY_API const char* getIdamServerErrorStackRecordMsg(int record); LIBRARY_API void closeAllConnections(); +LIBRARY_API int udaNumErrors(void); +LIBRARY_API const char* udaGetErrorMessage(int err_num); +LIBRARY_API int udaGetErrorCode(int err_num); +LIBRARY_API const char* udaGetErrorLocation(int err_num); + +typedef struct LogMallocList LOGMALLOCLIST; +typedef struct UserDefinedTypeList USERDEFINEDTYPELIST; + +LIBRARY_API LOGMALLOCLIST* getIdamLogMallocList(int handle); +LIBRARY_API USERDEFINEDTYPELIST* getIdamUserDefinedTypeList(int handle); + #ifdef __cplusplus } #endif diff --git a/source/include/clientAPI.h b/source/include/clientAPI.h index 6fff9982..23722833 100644 --- a/source/include/clientAPI.h +++ b/source/include/clientAPI.h @@ -2,7 +2,6 @@ #define UDA_CLIENT_CLIENTAPI_H #include "export.h" -#include "udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/include/pluginStructs.h b/source/include/pluginStructs.h deleted file mode 100644 index 949278da..00000000 --- a/source/include/pluginStructs.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef UDA_PLUGINS_PLUGINSTRUCTS_H -#define UDA_PLUGINS_PLUGINSTRUCTS_H - -#include - -#include "export.h" -#include "genStructs.h" -#include "udaStructs.h" - -#ifdef __cplusplus -extern "C" { -#endif - -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 IdamPluginInterface { // 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; - DATA_BLOCK* data_block; - REQUEST_DATA* request_data; - CLIENT_BLOCK* client_block; - DATA_SOURCE* data_source; - SIGNAL_DESC* signal_desc; - const ENVIRONMENT* environment; // Server environment - LOGMALLOCLIST* logmalloclist; - USERDEFINEDTYPELIST* userdefinedtypelist; - void* sqlConnection; // Opaque structure - const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers - UDA_ERROR_STACK error_stack; -} IDAM_PLUGIN_INTERFACE; - -typedef int (*PLUGINFUNP)(IDAM_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; -}; - -#ifdef __cplusplus -} -#endif - -#endif // UDA_PLUGINS_PLUGINSTRUCTS_H diff --git a/source/include/udaPlugin.h b/source/include/udaPlugin.h index db062694..5409ff63 100644 --- a/source/include/udaPlugin.h +++ b/source/include/udaPlugin.h @@ -4,15 +4,18 @@ #include #include "export.h" -#include "pluginStructs.h" -#include "udaStructs.h" +#include "plugins/pluginStructs.h" #include "udaTypes.h" -#include #ifdef __cplusplus extern "C" { #endif +typedef struct UdaErrorStack UDA_ERROR_STACK; +typedef struct UdaPluginInterface UDA_PLUGIN_INTERFACE; +typedef struct CompoundField COMPOUNDFIELD; +typedef struct UserDefinedType USERDEFINEDTYPE; + #define MAXFUNCTIONNAME 256 // plugin State @@ -31,43 +34,72 @@ typedef void (*ADDIDAMERRORFUNP)(UDA_ERROR_STACK*, int, char*, int, char*); // W // Prototypes -LIBRARY_API int callPlugin(const PLUGINLIST* pluginlist, const char* request, - const IDAM_PLUGIN_INTERFACE* old_plugin_interface); +LIBRARY_API int callPlugin(UDA_PLUGIN_INTERFACE* plugin_interface, const char* request); + +LIBRARY_API int udaPluginIsExternal(UDA_PLUGIN_INTERFACE* plugin_interface); +LIBRARY_API int udaPluginCheckInterfaceVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int interface_version); +LIBRARY_API void udaPluginSetVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_version); +LIBRARY_API const char* udaPluginFunction(UDA_PLUGIN_INTERFACE* plugin_interface); + +LIBRARY_API void udaPluginLog(UDA_PLUGIN_INTERFACE* plugin_interface, const char* fmt, ...); + +LIBRARY_API void udaAddPluginError(UDA_PLUGIN_INTERFACE* plugin_interface, const char* location, int code, const char* msg); + +LIBRARY_API UDA_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request); + +LIBRARY_API void udaFreePluginInterface(UDA_PLUGIN_INTERFACE* plugin_interface); + +LIBRARY_API COMPOUNDFIELD* udaNewCompoundField(const char*, const char*, int*, int); -IDAM_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request); -void udaFreePluginInterface(IDAM_PLUGIN_INTERFACE* plugin_interface); +LIBRARY_API USERDEFINEDTYPE* udaNewUserType(const char*, const char*, int, int, char*, size_t, size_t, COMPOUNDFIELD**); -LIBRARY_API int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list); -LIBRARY_API int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list); -LIBRARY_API int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list); -LIBRARY_API int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list); -LIBRARY_API int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin_list); +LIBRARY_API int udaAddUserType(UDA_PLUGIN_INTERFACE*, USERDEFINEDTYPE* user_type); +LIBRARY_API int udaRegisterMalloc(UDA_PLUGIN_INTERFACE* plugin_interface, void* data, int, size_t, const char*); -LIBRARY_API int setReturnDataFloatArray(DATA_BLOCK* data_block, float* values, size_t rank, const size_t* shape, +LIBRARY_API int udaPluginPluginsCount(UDA_PLUGIN_INTERFACE* plugin_interface); +LIBRARY_API int udaPluginCheckPluginClass(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num, const char* plugin_class); +LIBRARY_API const char* udaPluginPluginFormat(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num); +LIBRARY_API const char* udaPluginPluginExtension(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num); +LIBRARY_API const char* udaPluginPluginDescription(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num); +LIBRARY_API const char* udaPluginPluginExample(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num); + +LIBRARY_API int setReturnDataLabel(UDA_PLUGIN_INTERFACE* plugin_interface, const char* label); +LIBRARY_API int setReturnDataUnits(UDA_PLUGIN_INTERFACE* plugin_interface, const char* units); + +LIBRARY_API int setReturnDataFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, float* values, size_t rank, const size_t* shape, const char* description); -LIBRARY_API int setReturnDataDoubleArray(DATA_BLOCK* data_block, double* values, size_t rank, const size_t* shape, +LIBRARY_API int setReturnDataDoubleArray(UDA_PLUGIN_INTERFACE* plugin_interface, double* values, size_t rank, const size_t* shape, const char* description); -LIBRARY_API int setReturnDataIntArray(DATA_BLOCK* data_block, int* values, size_t rank, const size_t* shape, +LIBRARY_API int setReturnDataIntArray(UDA_PLUGIN_INTERFACE* plugin_interface, int* values, size_t rank, const size_t* shape, const char* description); -LIBRARY_API int setReturnDataDoubleScalar(DATA_BLOCK* data_block, double value, const char* description); -LIBRARY_API int setReturnDataFloatScalar(DATA_BLOCK* data_block, float value, const char* description); -LIBRARY_API int setReturnDataIntScalar(DATA_BLOCK* data_block, int value, const char* description); -LIBRARY_API int setReturnDataLongScalar(DATA_BLOCK* data_block, long value, const char* description); -LIBRARY_API int setReturnDataShortScalar(DATA_BLOCK* data_block, short value, const char* description); -LIBRARY_API int setReturnDataString(DATA_BLOCK* data_block, const char* value, const char* description); - -LIBRARY_API int setReturnData(DATA_BLOCK* data_block, void* value, size_t size, UDA_TYPE type, int rank, +LIBRARY_API int setReturnDataDoubleScalar(UDA_PLUGIN_INTERFACE* plugin_interface, double value, const char* description); +LIBRARY_API int setReturnDataFloatScalar(UDA_PLUGIN_INTERFACE* plugin_interface, float value, const char* description); +LIBRARY_API int setReturnDataIntScalar(UDA_PLUGIN_INTERFACE* plugin_interface, int value, const char* description); +LIBRARY_API int setReturnDataLongScalar(UDA_PLUGIN_INTERFACE* plugin_interface, long value, const char* description); +LIBRARY_API int setReturnDataShortScalar(UDA_PLUGIN_INTERFACE* plugin_interface, short value, const char* description); +LIBRARY_API int setReturnDataString(UDA_PLUGIN_INTERFACE* plugin_interface, const char* value, const char* description); + +LIBRARY_API int setReturnData(UDA_PLUGIN_INTERFACE* plugin_interface, void* value, size_t size, UDA_TYPE type, int rank, const int* shape, const char* description); -LIBRARY_API bool findStringValue(const NAMEVALUELIST* namevaluelist, const char** value, const char* name); -LIBRARY_API bool findValue(const NAMEVALUELIST* namevaluelist, const char* name); -LIBRARY_API bool findIntValue(const NAMEVALUELIST* namevaluelist, int* value, const char* name); -LIBRARY_API bool findShortValue(const NAMEVALUELIST* namevaluelist, short* value, const char* name); -LIBRARY_API bool findCharValue(const NAMEVALUELIST* namevaluelist, char* value, const char* name); -LIBRARY_API bool findFloatValue(const NAMEVALUELIST* namevaluelist, float* values, const char* name); -LIBRARY_API bool findIntArray(const NAMEVALUELIST* namevaluelist, int** values, size_t* nvalues, const char* name); -LIBRARY_API bool findFloatArray(const NAMEVALUELIST* namevaluelist, float** values, size_t* nvalues, const char* name); -LIBRARY_API bool findDoubleArray(const NAMEVALUELIST* namevaluelist, double** values, size_t* nvalues, +LIBRARY_API int setReturnDimensionFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, int dim_n, float* data, size_t size, const char* label, const char* units); + +LIBRARY_API int setReturnErrorAsymmetry(UDA_PLUGIN_INTERFACE* plugin_interface, bool flag); +LIBRARY_API int setReturnErrorLow(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size); +LIBRARY_API int setReturnErrorHigh(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size); +LIBRARY_API int setReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order); + +LIBRARY_API int setReturnCompoundData(UDA_PLUGIN_INTERFACE* plugin_interface, char* data, const char* user_type); + +LIBRARY_API bool findStringValue(const UDA_PLUGIN_INTERFACE* plugin_interface, const char** value, const char* name); +LIBRARY_API bool findValue(const UDA_PLUGIN_INTERFACE* plugin_interface, const char* name); +LIBRARY_API bool findIntValue(const UDA_PLUGIN_INTERFACE* plugin_interface, int* value, const char* name); +LIBRARY_API bool findShortValue(const UDA_PLUGIN_INTERFACE* plugin_interface, short* value, const char* name); +LIBRARY_API bool findCharValue(const UDA_PLUGIN_INTERFACE* plugin_interface, char* value, const char* name); +LIBRARY_API bool findFloatValue(const UDA_PLUGIN_INTERFACE* plugin_interface, float* values, const char* name); +LIBRARY_API bool findIntArray(const UDA_PLUGIN_INTERFACE* plugin_interface, int** values, size_t* nvalues, const char* name); +LIBRARY_API bool findFloatArray(const UDA_PLUGIN_INTERFACE* plugin_interface, float** values, size_t* nvalues, const char* name); +LIBRARY_API bool findDoubleArray(const UDA_PLUGIN_INTERFACE* plugin_interface, double** values, size_t* nvalues, const char* name); #define QUOTE_(X) #X @@ -76,86 +108,84 @@ LIBRARY_API bool findDoubleArray(const NAMEVALUELIST* namevaluelist, double** va #define CONCAT(X, Y) CONCAT_(X, Y) #define UNIQUE_VAR(NAME) __func__##NAME##__ -#define RAISE_PLUGIN_ERROR_AND_EXIT(MSG, plugin_interface_ptr) \ +#define RAISE_PLUGIN_ERROR_AND_EXIT(PLUGIN_INTERFACE, MSG) \ { \ int UNIQUE_VAR(err) = 999; \ - UDA_LOG(UDA_LOG_ERROR, "%s\n", MSG); \ - addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ - concatUdaError(&plugin_interface_ptr->error_stack); \ + udaPluginLog("%s\n", MSG); \ + udaAddPluginError(__func__, UNIQUE_VAR(err), MSG); \ return UNIQUE_VAR(err); \ } -#define RAISE_PLUGIN_ERROR(MSG) \ +#define RAISE_PLUGIN_ERROR(PLUGIN_INTERFACE, MSG) \ { \ int UNIQUE_VAR(err) = 999; \ UDA_LOG(UDA_LOG_ERROR, "%s\n", MSG); \ - addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ + udaAddPluginError(PLUGIN_INTERFACE, __func__, UNIQUE_VAR(err), MSG); \ return UNIQUE_VAR(err); \ } -#define RAISE_PLUGIN_ERROR_F(MSG, FMT, ...) \ +#define RAISE_PLUGIN_ERROR_F(PLUGIN_INTERFACE, MSG, FMT, ...) \ { \ int UNIQUE_VAR(err) = 999; \ - UDA_LOG(UDA_LOG_ERROR, "%s\n", FMT, __VA_ARGS__); \ - addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ + udaPluginLog("%s\n", FMT, __VA_ARGS__); \ + udaAddPluginError(PLUGIN_INTERFACE, __func__, UNIQUE_VAR(err), MSG); \ return UNIQUE_VAR(err); \ } -#define RAISE_PLUGIN_ERROR_AND_EXIT_F(plugin_interface_ptr, MSG, FMT, ...) \ +#define RAISE_PLUGIN_ERROR_AND_EXIT_F(PLUGIN_INTERFACE, MSG, FMT, ...) \ { \ int UNIQUE_VAR(err) = 999; \ - UDA_LOG(UDA_LOG_ERROR, "%s\n", FMT, __VA_ARGS__); \ - addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ - concatUdaError(&plugin_interface_ptr->error_stack); \ + udaPluginLog("%s\n", FMT, __VA_ARGS__); \ + udaAddPluginError(PLUGIN_INTERFACE, __func__, UNIQUE_VAR(err), MSG); \ return UNIQUE_VAR(err); \ } -#define RAISE_PLUGIN_ERROR_EX(MSG, CODE) \ +#define RAISE_PLUGIN_ERROR_EX(PLUGIN_INTERFACE, MSG, CODE) \ int UNIQUE_VAR(err) = 999; \ - UDA_LOG(UDA_LOG_ERROR, "%s", MSG); \ - addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ - CODE; \ + udaPluginLog("%s", MSG); \ + udaAddPluginError(PLUGIN_INTERFACE, __func__, UNIQUE_VAR(err), MSG); \ + { CODE } \ return UNIQUE_VAR(err); -#define FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, TYPE) \ - if (!find##TYPE##Value(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE))) { \ +#define FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, TYPE) \ + if (!find##TYPE##Value(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE))) { \ RAISE_PLUGIN_ERROR("Required argument '" QUOTE(VARIABLE) "' not given"); \ } -#define FIND_REQUIRED_ARRAY(NAME_VALUE_LIST, VARIABLE, TYPE) \ - if (!find##TYPE##Array(&NAME_VALUE_LIST, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE))) { \ +#define FIND_REQUIRED_ARRAY(PLUGIN_INTERFACE, VARIABLE, TYPE) \ + if (!find##TYPE##Array(PLUGIN_INTERFACE, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE))) { \ RAISE_PLUGIN_ERROR("Required argument '" QUOTE(VARIABLE) "' not given"); \ } -#define FIND_REQUIRED_INT_VALUE(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, Int) -#define FIND_REQUIRED_SHORT_VALUE(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, Short) -#define FIND_REQUIRED_CHAR_VALUE(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, Char) -#define FIND_REQUIRED_FLOAT_VALUE(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, Float) -#define FIND_REQUIRED_STRING_VALUE(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, String) - -#define FIND_REQUIRED_INT_ARRAY(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_ARRAY(NAME_VALUE_LIST, VARIABLE, Int) -#define FIND_REQUIRED_FLOAT_ARRAY(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_ARRAY(NAME_VALUE_LIST, VARIABLE, Float) -#define FIND_REQUIRED_DOUBLE_ARRAY(NAME_VALUE_LIST, VARIABLE) FIND_REQUIRED_ARRAY(NAME_VALUE_LIST, VARIABLE, Double) - -#define FIND_INT_VALUE(NAME_VALUE_LIST, VARIABLE) findIntValue(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE)) -#define FIND_SHORT_VALUE(NAME_VALUE_LIST, VARIABLE) findShortValue(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE)) -#define FIND_CHAR_VALUE(NAME_VALUE_LIST, VARIABLE) findCharValue(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE)) -#define FIND_FLOAT_VALUE(NAME_VALUE_LIST, VARIABLE) findFloatValue(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE)) -#define FIND_STRING_VALUE(NAME_VALUE_LIST, VARIABLE) findStringValue(&NAME_VALUE_LIST, &VARIABLE, QUOTE(VARIABLE)) - -#define FIND_INT_ARRAY(NAME_VALUE_LIST, VARIABLE) \ - findIntArray(&NAME_VALUE_LIST, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) -#define FIND_FLOAT_ARRAY(NAME_VALUE_LIST, VARIABLE) \ - findFloatArray(&NAME_VALUE_LIST, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) -#define FIND_DOUBLE_ARRAY(NAME_VALUE_LIST, VARIABLE) \ - findDoubleArray(&NAME_VALUE_LIST, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) +#define FIND_REQUIRED_INT_VALUE(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, Int) +#define FIND_REQUIRED_SHORT_VALUE(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, Short) +#define FIND_REQUIRED_CHAR_VALUE(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, Char) +#define FIND_REQUIRED_FLOAT_VALUE(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, Float) +#define FIND_REQUIRED_STRING_VALUE(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_VALUE(PLUGIN_INTERFACE, VARIABLE, String) + +#define FIND_REQUIRED_INT_ARRAY(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_ARRAY(PLUGIN_INTERFACE, VARIABLE, Int) +#define FIND_REQUIRED_FLOAT_ARRAY(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_ARRAY(PLUGIN_INTERFACE, VARIABLE, Float) +#define FIND_REQUIRED_DOUBLE_ARRAY(PLUGIN_INTERFACE, VARIABLE) FIND_REQUIRED_ARRAY(PLUGIN_INTERFACE, VARIABLE, Double) + +#define FIND_INT_VALUE(PLUGIN_INTERFACE, VARIABLE) findIntValue(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE)) +#define FIND_SHORT_VALUE(PLUGIN_INTERFACE, VARIABLE) findShortValue(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE)) +#define FIND_CHAR_VALUE(PLUGIN_INTERFACE, VARIABLE) findCharValue(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE)) +#define FIND_FLOAT_VALUE(PLUGIN_INTERFACE, VARIABLE) findFloatValue(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE)) +#define FIND_STRING_VALUE(PLUGIN_INTERFACE, VARIABLE) findStringValue(PLUGIN_INTERFACE, &VARIABLE, QUOTE(VARIABLE)) + +#define FIND_INT_ARRAY(PLUGIN_INTERFACE, VARIABLE) \ + findIntArray(PLUGIN_INTERFACE, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) +#define FIND_FLOAT_ARRAY(PLUGIN_INTERFACE, VARIABLE) \ + findFloatArray(PLUGIN_INTERFACE, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) +#define FIND_DOUBLE_ARRAY(PLUGIN_INTERFACE, VARIABLE) \ + findDoubleArray(PLUGIN_INTERFACE, &VARIABLE, CONCAT(&n, VARIABLE), QUOTE(VARIABLE)) #define CALL_PLUGIN(PLUGIN_INTERFACE, FMT, ...) \ { \ char UNIQUE_VAR(request)[1024]; \ snprintf(UNIQUE_VAR(request), 1024, FMT, __VA_ARGS__); \ UNIQUE_VAR(request)[1023] = '\0'; \ - int UNIQUE_VAR(err) = callPlugin(PLUGIN_INTERFACE->pluginList, UNIQUE_VAR(request), PLUGIN_INTERFACE); \ + int UNIQUE_VAR(err) = callPlugin(PLUGIN_INTERFACE, UNIQUE_VAR(request)); \ if (UNIQUE_VAR(err)) { \ RAISE_PLUGIN_ERROR("Plugin call failed"); \ } \ diff --git a/source/include/udaPutAPI.h b/source/include/udaPutAPI.h index 654a2967..3500ad57 100644 --- a/source/include/udaPutAPI.h +++ b/source/include/udaPutAPI.h @@ -2,7 +2,9 @@ #define UDA_CLIENT_UDAPUTAPI_H #include "export.h" -#include "udaStructs.h" + +typedef struct PutDataBlockList PUTDATA_BLOCK_LIST; +typedef struct PutDataBlock PUTDATA_BLOCK; #ifdef FATCLIENT # define idamPutListAPI idamPutListAPIFat diff --git a/source/plugins/uda_plugin_base.hpp b/source/include/uda_plugin_base.hpp similarity index 60% rename from source/plugins/uda_plugin_base.hpp rename to source/include/uda_plugin_base.hpp index 34dd2c85..438189e6 100644 --- a/source/plugins/uda_plugin_base.hpp +++ b/source/include/uda_plugin_base.hpp @@ -5,9 +5,6 @@ #include -#include "pluginStructs.h" -#include "export.h" - #include #include #include @@ -16,19 +13,18 @@ #include #include "udaPlugin.h" -#include "logging/logging.h" class UDAPluginBase; -typedef int (*plugin_function_type)(IDAM_PLUGIN_INTERFACE*); +typedef int (*plugin_function_type)(UDA_PLUGIN_INTERFACE*); /** * Abstract base class to be used to provide helper functions to make it easier to create C++ plugins. */ class UDAPluginBase { public: - typedef int (UDAPluginBase::*plugin_member_type)(IDAM_PLUGIN_INTERFACE*); - LIBRARY_API int call(IDAM_PLUGIN_INTERFACE* plugin_interface); + typedef int (UDAPluginBase::*plugin_member_type)(UDA_PLUGIN_INTERFACE*); + LIBRARY_API int call(UDA_PLUGIN_INTERFACE* plugin_interface); protected: UDAPluginBase(std::string name, int version, std::string default_method, std::string help_file) @@ -48,7 +44,7 @@ class UDAPluginBase { register_method("maxinterfaceversion", &UDAPluginBase::max_interface_version); } - virtual void init(IDAM_PLUGIN_INTERFACE* plugin_interface) = 0; + virtual void init(UDA_PLUGIN_INTERFACE* plugin_interface) = 0; virtual void reset() = 0; LIBRARY_API void register_method(const std::string& name, plugin_member_type plugin_method); @@ -56,50 +52,50 @@ class UDAPluginBase { // Helper methods template - void debug(const std::string& message, Args... args) + void debug(UdaPluginInterface* plugin_interface, const std::string& message, Args... args) { auto msg = fmt::format(message, args...); - UDA_LOG(UDA_LOG_DEBUG, "%s", msg.c_str()); + udaPluginLog(plugin_interface, "%s", msg.c_str()); } template - void error(const std::string& message, Args... args) + void error(UdaPluginInterface* plugin_interface, const std::string& message, Args... args) { auto msg = fmt::format(message, args...); - UDA_LOG(UDA_LOG_ERROR, "%s", msg.c_str()); + udaPluginLog(plugin_interface, "%s", msg.c_str()); throw std::runtime_error{ msg.c_str() }; } - LIBRARY_API bool has_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name); + LIBRARY_API bool has_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name); template - boost::optional find_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name, bool required=false) + boost::optional find_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name, bool required=false) { const char* str; - bool found = findStringValue(&plugin_interface->request_data->nameValueList, &str, name.c_str()); + bool found = findStringValue(plugin_interface, &str, name.c_str()); if (found) { std::stringstream ss(str); T value; ss >> value; return value; } else if (required) { - error("Required argument '{}' not given", name); + error(plugin_interface, "Required argument '{}' not given", name); } return {}; } template - T find_required_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name) + T find_required_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name) { auto arg = find_arg(plugin_interface, name, true); return *arg; } template - boost::optional> find_array_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name, bool required=false) + boost::optional> find_array_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name, bool required=false) { const char* str; - bool found = findStringValue(&plugin_interface->request_data->nameValueList, &str, name.c_str()); + bool found = findStringValue(plugin_interface, &str, name.c_str()); if (found) { std::vector tokens; boost::split(tokens, str, boost::is_any_of(";")); @@ -111,29 +107,29 @@ class UDAPluginBase { values.push_back(n); } } else if (required) { - error("Required argument '{}' not given", name); + error(plugin_interface, "Required argument '{}' not given", name); } return {}; } template - std::vector find_required_array_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name) + std::vector find_required_array_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name) { auto arg = find_array_arg(plugin_interface, name, true); return *arg; } // Default method implementations - LIBRARY_API int help(IDAM_PLUGIN_INTERFACE* plugin_interface); - LIBRARY_API int version(IDAM_PLUGIN_INTERFACE* plugin_interface); - LIBRARY_API int build_date(IDAM_PLUGIN_INTERFACE* plugin_interface); - LIBRARY_API int default_method(IDAM_PLUGIN_INTERFACE* plugin_interface); - LIBRARY_API int max_interface_version(IDAM_PLUGIN_INTERFACE* plugin_interface); + LIBRARY_API int help(UDA_PLUGIN_INTERFACE* plugin_interface); + LIBRARY_API int version(UDA_PLUGIN_INTERFACE* plugin_interface); + LIBRARY_API int build_date(UDA_PLUGIN_INTERFACE* plugin_interface); + LIBRARY_API int default_method(UDA_PLUGIN_INTERFACE* plugin_interface); + LIBRARY_API int max_interface_version(UDA_PLUGIN_INTERFACE* plugin_interface); private: - void do_init(IDAM_PLUGIN_INTERFACE* plugin_interface); + void do_init(UDA_PLUGIN_INTERFACE* plugin_interface); void do_reset(); - static std::string get_function(IDAM_PLUGIN_INTERFACE* plugin_interface); + static std::string get_function(UDA_PLUGIN_INTERFACE* plugin_interface); bool init_; std::string name_; diff --git a/source/plugins/CMakeLists.txt b/source/plugins/CMakeLists.txt index c6c4b170..8093dcb6 100755 --- a/source/plugins/CMakeLists.txt +++ b/source/plugins/CMakeLists.txt @@ -55,7 +55,7 @@ else() add_subdirectory( help ) add_subdirectory( keyvalue ) add_subdirectory( template ) - add_subdirectory( testplugin ) +# add_subdirectory( testplugin ) add_subdirectory( uda ) add_subdirectory( viewport ) endif( DEFINED BUILD_PLUGINS ) diff --git a/source/plugins/bytes/bytesPlugin.cpp b/source/plugins/bytes/bytesPlugin.cpp index b713b245..9687f497 100644 --- a/source/plugins/bytes/bytesPlugin.cpp +++ b/source/plugins/bytes/bytesPlugin.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include "include/uda_plugin_base.hpp" #include @@ -14,8 +14,8 @@ class BytesPlugin : public UDAPluginBase { public: BytesPlugin(); - int read(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + int read(UDA_PLUGIN_INTERFACE* plugin_interface); + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} }; @@ -25,7 +25,7 @@ BytesPlugin::BytesPlugin() register_method("read", static_cast(&BytesPlugin::read)); } -int bytesPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +int bytesPlugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static BytesPlugin plugin = {}; return plugin.call(plugin_interface); @@ -33,13 +33,13 @@ int bytesPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------------------------- // Add functionality here .... -int BytesPlugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) +int BytesPlugin::read(UDA_PLUGIN_INTERFACE* plugin_interface) { auto path = find_required_arg(plugin_interface, "path"); char c_path[MAXPATH]; StringCopy(c_path, path.c_str(), MAXPATH); - debug("expand_environment_variables!"); + debug(plugin_interface, "expand_environment_variables!"); expand_environment_variables(c_path); return readBytes(c_path, plugin_interface); diff --git a/source/plugins/bytes/bytesPlugin.h b/source/plugins/bytes/bytesPlugin.h index 510eb18a..44a8bf08 100644 --- a/source/plugins/bytes/bytesPlugin.h +++ b/source/plugins/bytes/bytesPlugin.h @@ -12,7 +12,7 @@ extern "C" { #define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! #define THISPLUGIN_DEFAULT_METHOD "help" -LIBRARY_API int bytesPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +LIBRARY_API int bytesPlugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/bytes/readBytesNonOptimally.cpp b/source/plugins/bytes/readBytesNonOptimally.cpp index 9ab770bf..239ce9e8 100644 --- a/source/plugins/bytes/readBytesNonOptimally.cpp +++ b/source/plugins/bytes/readBytesNonOptimally.cpp @@ -2,13 +2,9 @@ #include #include - -#include "initStructs.h" -#include "udaTypes.h" -#include -#include -#include -#include +#include +#include +#include #define BYTEFILEDOESNOTEXIST 100001 #define BYTEFILEATTRIBUTEERROR 100002 @@ -18,33 +14,94 @@ #define BYTEFILEMD5ERROR 100006 #define BYTEFILEMD5DIFF 100007 -int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) +namespace { +int is_legal_file_path(const char *str) { + // Basic check that the filename complies with good naming practice - some protection against malign embedded code! + // Test against the Portable Filename Character Set A-Z, a-z, 0-9, , and and + // Include and back-slash for windows filenames only, forward-slash for the path seperator and $ for + // environment variables + + // The API source argument can also be a server based source containing a ':' character + // The delimiter characters separating the device or format name from the source should have been split off of the + // path + // + + const char *tst = str; + while (*tst != '\0') { + if ((*tst >= '0' && *tst <= '9') || (*tst >= 'A' && *tst <= 'Z') || (*tst >= 'a' && *tst <= 'z')) { + tst++; + continue; + } + + if (strchr("_-+./$:", *tst) != nullptr) { + tst++; + continue; + } + +#ifdef _WIN32 + if (*tst == ' ' || *tst == '\\') { + tst++; + continue; + } +#endif + return 0; // Error - not compliant! + } + return 1; +} +} + +std::string hash_sum(char* bp, int size) { - int err = 0; + EVP_MD_CTX* context = EVP_MD_CTX_new(); + std::string hash_string; + + if (context != nullptr) { + if (EVP_DigestInit_ex(context, EVP_sha256(), nullptr)) { + if (EVP_DigestUpdate(context, bp, size)) { + unsigned char hash[EVP_MAX_MD_SIZE]; + unsigned int length = 0; + + if (EVP_DigestFinal_ex(context, hash, &length)) { + std::stringstream ss; + ss << std::hex << std::setw(2) << std::setfill('0'); + for (unsigned int i = 0; i < length; ++i) { + ss << (int) hash[i]; + } + hash_string = ss.str(); + } + } + } + + EVP_MD_CTX_free(context); + } + + return hash_string; +} + +int readBytes(const std::string& path, UDA_PLUGIN_INTERFACE* plugin_interface) +{ + int err; char md5file[2 * MD5_SIZE + 1] = ""; char md5check[2 * MD5_SIZE + 1] = ""; - const ENVIRONMENT* environment = plugin_interface->environment; - DATA_BLOCK* data_block = plugin_interface->data_block; - //---------------------------------------------------------------------- // Block Access to External Users - if (environment->external_user) { + if (udaPluginIsExternal(plugin_interface)) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "readBytes", err, "This Service is Disabled"); - UDA_LOG(UDA_LOG_DEBUG, "Disabled Service - Requested File: %s \n", path.c_str()); + udaAddPluginError(plugin_interface, __func__, err, "This Service is Disabled"); + udaPluginLog(plugin_interface, "Disabled Service - Requested File: %s \n", path.c_str()); return err; } //---------------------------------------------------------------------- // Test the filepath - if (!IsLegalFilePath(path.c_str())) { + if (!is_legal_file_path(path.c_str())) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "readBytes", err, "The directory path has incorrect syntax"); - UDA_LOG(UDA_LOG_DEBUG, "The directory path has incorrect syntax [%s] \n", path.c_str()); + udaAddPluginError(plugin_interface, __func__, err, "The directory path has incorrect syntax"); + udaPluginLog(plugin_interface, "The directory path has incorrect syntax [%s] \n", path.c_str()); return err; } @@ -53,7 +110,7 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) err = 0; - UDA_LOG(UDA_LOG_DEBUG, "File Name : %s \n", path.c_str()); + udaPluginLog(plugin_interface, "File Name : %s \n", path.c_str()); //---------------------------------------------------------------------- // File Attributes @@ -71,88 +128,47 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) if (fh == nullptr || ferror(fh) || serrno != 0) { err = BYTEFILEOPENERROR; if (serrno != 0) { - addIdamError(UDA_SYSTEM_ERROR_TYPE, "readBytes", serrno, ""); + udaAddPluginError(plugin_interface, __func__, serrno, ""); } - addIdamError(UDA_CODE_ERROR_TYPE, "readBytes", err, "Unable to Open the File for Read Access"); + udaAddPluginError(plugin_interface, __func__, err, "Unable to Open the File for Read Access"); if (fh != nullptr) { fclose(fh); } return err; } - //---------------------------------------------------------------------- - // Error Trap Loop - - do { - - // Read File (Consider using memory mapped I/O & new type to avoid heap free at end if this is too slow!) + // Read File (Consider using memory mapped I/O & new type to avoid heap free at end if this is too slow!) - int nchar = 0; - int offset = 0; - int bufsize = 100 * 1024; - data_block->data_n = bufsize; // 1 less than no. bytes read: Last Byte is an EOF - - char* bp = nullptr; - while (!feof(fh)) { - if ((bp = (char*)realloc(bp, (size_t)data_block->data_n)) == nullptr) { - err = BYTEFILEHEAPERROR; - addIdamError(UDA_CODE_ERROR_TYPE, "readBytes", err, "Unable to Allocate Heap Memory for the File"); - break; - } - int nread = (int)fread(bp + offset, sizeof(char), (size_t)bufsize, fh); - nchar = nchar + nread; - offset = nchar; - data_block->data_n = nchar + bufsize + 1; - } + size_t nchar = 0; + int offset = 0; + size_t bufsize = 100 * 1024; - if (err != 0) { + char* bp = nullptr; + while (!feof(fh)) { + if ((bp = (char*)realloc(bp, bufsize)) == nullptr) { + err = BYTEFILEHEAPERROR; + udaAddPluginError(plugin_interface, __func__, err, "Unable to Allocate Heap Memory for the File"); break; } + int nread = (int)fread(bp + offset, sizeof(char), bufsize, fh); + nchar = nchar + nread; + offset = nchar; + } - // nchar--; // Remove EOF Character from end of Byte Block - data_block->data_n = nchar; - data_block->data = bp; - - //---------------------------------------------------------------------- - // MD5 Checksum - - md5Sum(bp, data_block->data_n, md5check); - - strcpy(data_block->data_desc, md5check); // Pass back the Checksum to the Client - - UDA_LOG(UDA_LOG_DEBUG, "File Size : %d \n", nchar); - UDA_LOG(UDA_LOG_DEBUG, "File Checksum : %s \n", md5file); - UDA_LOG(UDA_LOG_DEBUG, "Read Checksum : %s \n", md5check); - - // MD5 Difference? - - //---------------------------------------------------------------------- - // Fetch Dimensional Data - - data_block->rank = 1; - data_block->dims = (DIMS*)malloc(sizeof(DIMS)); - initDimBlock(data_block->dims); - - data_block->dims[0].data_type = UDA_TYPE_UNSIGNED_INT; - data_block->dims[0].dim_n = data_block->data_n; - data_block->dims[0].compressed = 1; - data_block->dims[0].dim0 = 0.0; - data_block->dims[0].diff = 1.0; - data_block->dims[0].method = 0; - - data_block->order = -1; // No Dimensions - data_block->data_type = UDA_TYPE_CHAR; + fclose(fh); - } while (0); + if (err != 0) { + return err; + } - //---------------------------------------------------------------------- - // Housekeeping + auto sum = hash_sum(bp, nchar); - // if (err != 0) { - // freeDataBlock(data_block); - // } + int shape[] = { (int)nchar }; + setReturnData(plugin_interface, bp, nchar, UDA_TYPE_CHAR, 1, shape, sum.c_str()); - fclose(fh); // Close the File + udaPluginLog(plugin_interface, "File Size : %d \n", nchar); + udaPluginLog(plugin_interface, "File Checksum : %s \n", md5file); + udaPluginLog(plugin_interface, "Read Checksum : %s \n", md5check); return err; } diff --git a/source/plugins/bytes/readBytesNonOptimally.h b/source/plugins/bytes/readBytesNonOptimally.h index 567b6613..3cf8260f 100644 --- a/source/plugins/bytes/readBytesNonOptimally.h +++ b/source/plugins/bytes/readBytesNonOptimally.h @@ -1,12 +1,18 @@ #ifndef UDA_PLUGIN_READBYTESNONOPTIMALLY_H #define UDA_PLUGIN_READBYTESNONOPTIMALLY_H -#include "export.h" -#include "udaStructs.h" +#include "udaPlugin.h" -#include "pluginStructs.h" #include -int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface); +#ifdef __cplusplus +extern "C" { +#endif + +int readBytes(const std::string &path, UDA_PLUGIN_INTERFACE *plugin_interface); + +#ifdef __cplusplus +} +#endif #endif // UDA_PLUGIN_READBYTESNONOPTIMALLY_H diff --git a/source/plugins/hdf5/hdf5plugin.cpp b/source/plugins/hdf5/hdf5plugin.cpp index d18c0646..be2d4f50 100644 --- a/source/plugins/hdf5/hdf5plugin.cpp +++ b/source/plugins/hdf5/hdf5plugin.cpp @@ -1,6 +1,6 @@ #include "hdf5plugin.h" -#include +#include "include/uda_plugin_base.hpp" #include "readHDF58.h" @@ -8,16 +8,16 @@ class HDF5Plugin : public UDAPluginBase { public: HDF5Plugin(); - int read(IDAM_PLUGIN_INTERFACE* plugin_interface); - int hello(IDAM_PLUGIN_INTERFACE* plugin_interface) + int read(UDA_PLUGIN_INTERFACE* plugin_interface); + int hello(UDA_PLUGIN_INTERFACE* plugin_interface) { return setReturnDataString(plugin_interface->data_block, "hello!", nullptr); } - static int foo(IDAM_PLUGIN_INTERFACE* plugin_interface) + static int foo(UDA_PLUGIN_INTERFACE* plugin_interface) { return setReturnDataString(plugin_interface->data_block, "foo!", nullptr); } - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} }; @@ -31,7 +31,7 @@ HDF5Plugin::HDF5Plugin() : UDAPluginBase("HDF5", 1, "read", "") /** * Entry function */ -extern int hdf5Plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +extern int hdf5Plugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static HDF5Plugin plugin = {}; return plugin.call(plugin_interface); @@ -40,7 +40,7 @@ extern int hdf5Plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------------------------- // Read data from a HDF5 File -int HDF5Plugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) +int HDF5Plugin::read(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_SOURCE* data_source = plugin_interface->data_source; SIGNAL_DESC* signal_desc = plugin_interface->signal_desc; diff --git a/source/plugins/hdf5/hdf5plugin.h b/source/plugins/hdf5/hdf5plugin.h index 03aff1b5..eee303ae 100644 --- a/source/plugins/hdf5/hdf5plugin.h +++ b/source/plugins/hdf5/hdf5plugin.h @@ -21,7 +21,7 @@ extern "C" { extern UDA_PLUGIN_FILE_LIST pluginFileList; -LIBRARY_API int hdf5Plugin(IDAM_PLUGIN_INTERFACE* plugin_interface); +LIBRARY_API int hdf5Plugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/hdf5/readHDF58.cpp b/source/plugins/hdf5/readHDF58.cpp index d4fda92a..21e01451 100644 --- a/source/plugins/hdf5/readHDF58.cpp +++ b/source/plugins/hdf5/readHDF58.cpp @@ -44,7 +44,7 @@ void H5Fclose(int fh) #else -# include "initStructs.h" +# include "clientserver/initStructs.h" # include "udaTypes.h" # include # include diff --git a/source/plugins/hdf5/readHDF58.h b/source/plugins/hdf5/readHDF58.h index 245d32d0..302081e9 100644 --- a/source/plugins/hdf5/readHDF58.h +++ b/source/plugins/hdf5/readHDF58.h @@ -2,7 +2,7 @@ #define UDA_PLUGIN_READHDF58_H #include "export.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/plugins/help/help_plugin.cpp b/source/plugins/help/help_plugin.cpp index ffe73848..8d5f6a5b 100644 --- a/source/plugins/help/help_plugin.cpp +++ b/source/plugins/help/help_plugin.cpp @@ -1,20 +1,17 @@ #include "help_plugin.h" +#include #include -#include -#include "accessors.h" -#include "initStructs.h" -#include "struct.h" -#include +#include "uda_plugin_base.hpp" class HelpPlugin : public UDAPluginBase { public: HelpPlugin(); - int ping(IDAM_PLUGIN_INTERFACE* plugin_interface); - int services(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + int ping(UDA_PLUGIN_INTERFACE* plugin_interface); + int services(UDA_PLUGIN_INTERFACE* plugin_interface); + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} }; @@ -25,13 +22,13 @@ HelpPlugin::HelpPlugin() register_method("services", static_cast(&HelpPlugin::services)); } -int helpPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +int helpPlugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static HelpPlugin plugin = {}; return plugin.call(plugin_interface); } -int HelpPlugin::ping(IDAM_PLUGIN_INTERFACE* plugin_interface) +int HelpPlugin::ping(UDA_PLUGIN_INTERFACE* plugin_interface) { //---------------------------------------------------------------------------------------- @@ -47,65 +44,31 @@ int HelpPlugin::ping(IDAM_PLUGIN_INTERFACE* plugin_interface) }; typedef struct HELP_PING HELP_PING; - USERDEFINEDTYPE usertype; - COMPOUNDFIELD field; - - initUserDefinedType(&usertype); // New structure definition - initCompoundField(&field); - - strcpy(usertype.name, "HELP_PING"); - strcpy(usertype.source, "idamServerHelp"); - usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data - usertype.image = nullptr; - usertype.size = sizeof(HELP_PING); // Structure size - usertype.idamclass = UDA_TYPE_COMPOUND; - int offset = 0; - defineField(&field, "seconds", "Server time in seconds from the epoch start", &offset, SCALARUINT); - addCompoundField(&usertype, field); - defineField(&field, "microseconds", "Server inter-second time in microseconds", &offset, SCALARUINT); - addCompoundField(&usertype, field); + COMPOUNDFIELD* field1 = udaNewCompoundField("seconds", "Server time in seconds from the epoch start", &offset, SCALARUINT); + COMPOUNDFIELD* field2 = udaNewCompoundField("microseconds", "Server inter-second time in microseconds", &offset, SCALARUINT); + + COMPOUNDFIELD* fields[] = { field1, field2 }; + USERDEFINEDTYPE* user_type = udaNewUserType("HELP_PING", "idamServerHelp", 0, 0, nullptr, sizeof(HELP_PING), 2, fields); - USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; - addUserDefinedType(userdefinedtypelist, usertype); + udaAddUserType(plugin_interface, user_type); // assign the returned data structure auto data = (HELP_PING*)malloc(sizeof(HELP_PING)); - addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(HELP_PING), "HELP_PING"); // Register + udaRegisterMalloc(plugin_interface, (void*)data, 1, sizeof(HELP_PING), "HELP_PING"); data->seconds = (unsigned int)serverTime.tv_sec; data->microseconds = (unsigned int)serverTime.tv_usec; // return to the client - - DATA_BLOCK* data_block = plugin_interface->data_block; - initDataBlock(data_block); - - data_block->data_type = UDA_TYPE_COMPOUND; - data_block->rank = 0; - data_block->data_n = 1; - data_block->data = (char*)data; - - strcpy(data_block->data_desc, "Local UDA server time"); - strcpy(data_block->data_label, "servertime"); - strcpy(data_block->data_units, ""); - - data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; - data_block->opaque_count = 1; - data_block->opaque_block = (void*)findUserDefinedType(userdefinedtypelist, "HELP_PING", 0); + setReturnCompoundData(plugin_interface, (char*)data, "HELP_PING"); return 0; } -int HelpPlugin::services(IDAM_PLUGIN_INTERFACE* plugin_interface) +int HelpPlugin::services(UDA_PLUGIN_INTERFACE* plugin_interface) { - //====================================================================================== - // Plugin functionality - int count; - unsigned short target; - const char* line = "\n------------------------------------------------------\n"; // Document is a single block of chars @@ -113,19 +76,8 @@ int HelpPlugin::services(IDAM_PLUGIN_INTERFACE* plugin_interface) std::string doc; // Total Number of registered plugins available - - const ENVIRONMENT* environment = plugin_interface->environment; - - const PLUGINLIST* pluginList = plugin_interface->pluginList; - - count = 0; - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - count++; - } - } + + int count = udaPluginPluginsCount(plugin_interface); doc = fmt::format("\nTotal number of registered plugins available: {}\n", count); @@ -134,122 +86,62 @@ int HelpPlugin::services(IDAM_PLUGIN_INTERFACE* plugin_interface) doc += line; switch (j) { case 0: { - target = UDA_PLUGIN_CLASS_FILE; - - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user)) && - pluginList->plugin[i].format[0] != '\0' && pluginList->plugin[i].extension[0] != '\0') { - count++; - } - } - - doc += fmt::format("\nNumber of plugins for data file formats: {}\n\n", count); - - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user)) && - pluginList->plugin[i].format[0] != '\0' && pluginList->plugin[i].extension[0] != '\0') { - doc += fmt::format("File format:\t\t{}\n", pluginList->plugin[i].format); - doc += fmt::format("Filename extension:\t{}\n", pluginList->plugin[i].extension); - doc += fmt::format("Description:\t\t{}\n", pluginList->plugin[i].desc); - doc += fmt::format("Example API call:\t{}\n\n", pluginList->plugin[i].example); + doc += fmt::format("\nPlugins for data file formats: \n\n"); + + for (int i = 0; i < count; i++) { + if (udaPluginCheckPluginClass(plugin_interface, i, "file")) { + doc += fmt::format("File format:\t\t{}\n", udaPluginPluginFormat(plugin_interface, i)); + doc += fmt::format("Filename extension:\t{}\n", udaPluginPluginExtension(plugin_interface, i)); + doc += fmt::format("Description:\t\t{}\n", udaPluginPluginDescription(plugin_interface, i)); + doc += fmt::format("Example API call:\t{}\n\n", udaPluginPluginExample(plugin_interface, i)); } } break; } case 1: { - target = UDA_PLUGIN_CLASS_FUNCTION; - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - count++; - } - } - doc += fmt::format("\nNumber of plugins for Libraries: {}\n\n", count); - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - doc += fmt::format("Library name:\t\t{}\n", pluginList->plugin[i].format); - doc += fmt::format("Description:\t\t{}\n", pluginList->plugin[i].desc); - doc += fmt::format("Example API call:\t{}\n\n", pluginList->plugin[i].example); + doc += fmt::format("\nPlugins for functions:\n\n"); + + for (int i = 0; i < count; i++) { + if (udaPluginCheckPluginClass(plugin_interface, i, "function")) { + doc += fmt::format("Library name:\t\t{}\n", udaPluginPluginFormat(plugin_interface, i)); + doc += fmt::format("Description:\t\t{}\n", udaPluginPluginDescription(plugin_interface, i)); + doc += fmt::format("Example API call:\t{}\n\n", udaPluginPluginExample(plugin_interface, i)); } } break; } case 2: { - target = UDA_PLUGIN_CLASS_SERVER; - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - count++; - } - } - doc += fmt::format("\nNumber of plugins for Data Servers: {}\n\n", count); - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - doc += fmt::format("Server name:\t\t{}\n", pluginList->plugin[i].format); - doc += fmt::format("Description:\t\t{}\n", pluginList->plugin[i].desc); - doc += fmt::format("Example API call:\t{}\n\n", pluginList->plugin[i].example); + doc += fmt::format("\nPlugins for Data Servers\n\n"); + + for (int i = 0; i < count; i++) { + if (udaPluginCheckPluginClass(plugin_interface, i, "server")) { + doc += fmt::format("Server name:\t\t{}\n", udaPluginPluginFormat(plugin_interface, i)); + doc += fmt::format("Description:\t\t{}\n", udaPluginPluginDescription(plugin_interface, i)); + doc += fmt::format("Example API call:\t{}\n\n", udaPluginPluginExample(plugin_interface, i)); } } break; } case 3: { - target = UDA_PLUGIN_CLASS_DEVICE; - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - count++; - } - } - doc += fmt::format("\nNumber of plugins for External Devices: {}\n\n", count); - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - doc += fmt::format("External device name:\t{}\n", pluginList->plugin[i].format); - doc += fmt::format("Description:\t\t{}\n", pluginList->plugin[i].desc); - doc += fmt::format("Example API call:\t{}\n\n", pluginList->plugin[i].example); + doc += fmt::format("\nPlugins for External Devices:\n\n"); + + for (int i = 0; i < count; i++) { + if (udaPluginCheckPluginClass(plugin_interface, i, "device")) { + doc += fmt::format("External device name:\t{}\n", udaPluginPluginFormat(plugin_interface, i)); + doc += fmt::format("Description:\t\t{}\n", udaPluginPluginDescription(plugin_interface, i)); + doc += fmt::format("Example API call:\t{}\n\n", udaPluginPluginExample(plugin_interface, i)); } } break; } case 4: { - target = UDA_PLUGIN_CLASS_OTHER; - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - count++; - } - } - doc += fmt::format("\nNumber of plugins for Other data services: {}\n\n", count); - for (int i = 0; i < pluginList->count; i++) { - if (pluginList->plugin[i].plugin_class == target && - pluginList->plugin[i].status == UDA_PLUGIN_OPERATIONAL && - (pluginList->plugin[i].is_private == UDA_PLUGIN_PUBLIC || - (pluginList->plugin[i].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user))) { - doc += fmt::format("Data service name:\t{}\n", pluginList->plugin[i].format); - doc += fmt::format("Description:\t\t{}\n", pluginList->plugin[i].desc); - doc += fmt::format("Example API call:\t{}\n\n", pluginList->plugin[i].example); + doc += fmt::format("\nNumber of plugins for Other data services:\n\n"); + + for (int i = 0; i < count; i++) { + if (udaPluginCheckPluginClass(plugin_interface, i, "other")) { + doc += fmt::format("Data service name:\t{}\n", udaPluginPluginFormat(plugin_interface, i)); + doc += fmt::format("Description:\t\t{}\n", udaPluginPluginDescription(plugin_interface, i)); + doc += fmt::format("Example API call:\t{}\n\n", udaPluginPluginExample(plugin_interface, i)); } } break; @@ -259,5 +151,5 @@ int HelpPlugin::services(IDAM_PLUGIN_INTERFACE* plugin_interface) doc += "\n\n"; - return setReturnDataString(plugin_interface->data_block, doc.c_str(), "Description of UDA data access services"); + return setReturnDataString(plugin_interface, doc.c_str(), "Description of UDA data access services"); } diff --git a/source/plugins/help/help_plugin.h b/source/plugins/help/help_plugin.h index 26b8d597..2c07f369 100644 --- a/source/plugins/help/help_plugin.h +++ b/source/plugins/help/help_plugin.h @@ -2,7 +2,7 @@ #define UDA_PLUGIN_IDAMSERVERHELP_H #include "export.h" -#include "pluginStructs.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { @@ -12,7 +12,7 @@ extern "C" { #define THISPLUGIN_MAX_INTERFACE_VERSION 1 #define THISPLUGIN_DEFAULT_METHOD "help" -LIBRARY_API int helpPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +LIBRARY_API int helpPlugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/keyvalue/keyvaluePlugin.cpp b/source/plugins/keyvalue/keyvaluePlugin.cpp index 97e4c471..e74d2523 100644 --- a/source/plugins/keyvalue/keyvaluePlugin.cpp +++ b/source/plugins/keyvalue/keyvaluePlugin.cpp @@ -3,9 +3,9 @@ #include #include -#include +#include "include/uda_plugin_base.hpp" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaPlugin.h" #include "udaTypes.h" #include @@ -19,10 +19,10 @@ class Plugin : public UDAPluginBase { public: Plugin(); - int write(IDAM_PLUGIN_INTERFACE* plugin_interface); - int read(IDAM_PLUGIN_INTERFACE* plugin_interface); - int del(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override; + int write(UDA_PLUGIN_INTERFACE* plugin_interface); + int read(UDA_PLUGIN_INTERFACE* plugin_interface); + int del(UDA_PLUGIN_INTERFACE* plugin_interface); + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override; void reset() override; private: @@ -43,13 +43,13 @@ Plugin::Plugin() } // namespace keyvalue } // namespace uda -int keyValue(IDAM_PLUGIN_INTERFACE* plugin_interface) +int keyValue(UDA_PLUGIN_INTERFACE* plugin_interface) { static uda::keyvalue::Plugin plugin = {}; return plugin.call(plugin_interface); } -void uda::keyvalue::Plugin::init(IDAM_PLUGIN_INTERFACE* plugin_interface) +void uda::keyvalue::Plugin::init(UDA_PLUGIN_INTERFACE* plugin_interface) { options_ = leveldb_options_create(); leveldb_options_set_create_if_missing(options_, 1); @@ -57,7 +57,7 @@ void uda::keyvalue::Plugin::init(IDAM_PLUGIN_INTERFACE* plugin_interface) char* err = nullptr; db_ = leveldb_open(options_, "idam_ks", &err); if (err != nullptr) { - error(err); + error(plugin_interface, err); } woptions_ = leveldb_writeoptions_create(); @@ -79,45 +79,47 @@ void uda::keyvalue::Plugin::reset() options_ = nullptr; } -int uda::keyvalue::Plugin::write(IDAM_PLUGIN_INTERFACE* plugin_interface) +int uda::keyvalue::Plugin::write(UDA_PLUGIN_INTERFACE* plugin_interface) { auto key = find_required_arg(plugin_interface, "key"); auto value = find_required_arg(plugin_interface, "value"); char* env = getenv("UDA_PLUGIN_KEYVALUE_STORE"); if (env == nullptr) { - error("Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); + error(plugin_interface, "Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); } if (STR_EQUALS(env, "LEVELDB")) { - debug("Writing key {} to LevelDB keystore", key); + debug(plugin_interface, "Writing key {} to LevelDB keystore", key); } else { - error("Unknown keyvalue store requested"); + error(plugin_interface, "Unknown keyvalue store requested"); } char* err = nullptr; leveldb_put(db_, woptions_, key.c_str(), key.size(), value.c_str(), value.size(), &err); if (err != nullptr) { - RAISE_PLUGIN_ERROR_EX(err, { leveldb_free(err); }); + debug(plugin_interface, err); + leveldb_free(err); + throw std::runtime_error{ err }; } return 0; } -int uda::keyvalue::Plugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) +int uda::keyvalue::Plugin::read(UDA_PLUGIN_INTERFACE* plugin_interface) { auto key = find_required_arg(plugin_interface, "key"); char* env = getenv("UDA_PLUGIN_KEYVALUE_STORE"); if (env == nullptr) { - error("Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); + error(plugin_interface, "Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); } if (STR_EQUALS(env, "LEVELDB")) { - debug("Writing key {} to LevelDB keystore", key); + debug(plugin_interface, "Writing key {} to LevelDB keystore", key); } else { - error("Unknown keyvalue store requested"); + error(plugin_interface, "Unknown keyvalue store requested"); } char* err = nullptr; @@ -126,28 +128,29 @@ int uda::keyvalue::Plugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) char* value = leveldb_get(db_, roptions_, key.c_str(), key.size(), &value_len, &err); if (err != nullptr) { - RAISE_PLUGIN_ERROR_EX(err, { leveldb_free(err); }); + debug(plugin_interface, err); + throw std::runtime_error{ err }; } - plugin_interface->data_block->data = value; - plugin_interface->data_block->data_n = value_len; + int shape[] = { (int)value_len }; + setReturnData(plugin_interface, value, value_len, UDA_TYPE_CHAR, 1, shape, nullptr); return 0; } -int uda::keyvalue::Plugin::del(IDAM_PLUGIN_INTERFACE* plugin_interface) +int uda::keyvalue::Plugin::del(UDA_PLUGIN_INTERFACE* plugin_interface) { auto key = find_required_arg(plugin_interface, "key"); char* env = getenv("UDA_PLUGIN_KEYVALUE_STORE"); if (env == nullptr) { - error("Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); + error(plugin_interface, "Environmental variable IDAM_PLUGIN_KEYVALUE_STORE not found"); } if (STR_EQUALS(env, "LEVELDB")) { - debug("Writing key {} to LevelDB keystore", key); + debug(plugin_interface, "Writing key {} to LevelDB keystore", key); } else { - error("Unknown keyvalue store requested"); + error(plugin_interface, "Unknown keyvalue store requested"); } char* err = nullptr; @@ -157,7 +160,7 @@ int uda::keyvalue::Plugin::del(IDAM_PLUGIN_INTERFACE* plugin_interface) if (err != nullptr) { std::string message = err; leveldb_free(err); - error(message); + error(plugin_interface, message); } return 0; diff --git a/source/plugins/keyvalue/keyvaluePlugin.h b/source/plugins/keyvalue/keyvaluePlugin.h index 425cdd8f..a1a3e8e6 100644 --- a/source/plugins/keyvalue/keyvaluePlugin.h +++ b/source/plugins/keyvalue/keyvaluePlugin.h @@ -2,7 +2,7 @@ #define UDA_PLUGIN_KEYVALUEPLUGIN_H #include "export.h" -#include "pluginStructs.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { @@ -12,7 +12,7 @@ extern "C" { #define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! #define THISPLUGIN_DEFAULT_METHOD "help" -LIBRARY_API int keyValue(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +LIBRARY_API int keyValue(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/pluginStructs.h b/source/plugins/pluginStructs.h new file mode 100644 index 00000000..7467e188 --- /dev/null +++ b/source/plugins/pluginStructs.h @@ -0,0 +1,21 @@ +#ifndef UDA_PLUGINS_PLUGINSTRUCTS_H +#define UDA_PLUGINS_PLUGINSTRUCTS_H + +#include + +#include "export.h" +#include "genStructs.h" + +#include "clientserver/udaStructs.h" + +#ifdef __cplusplus +extern "C" { +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif // UDA_PLUGINS_PLUGINSTRUCTS_H diff --git a/source/plugins/pluginUtils.cpp b/source/plugins/pluginUtils.cpp deleted file mode 100644 index beb16c92..00000000 --- a/source/plugins/pluginUtils.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "pluginUtils.h" - -#include -#include -#include -#ifdef __GNUC__ -# include -#endif - -#include "client.h" -#include "initStructs.h" -#include "struct.h" -#include "udaErrors.h" -#include -#include -#include -#include -#include -#include -#include diff --git a/source/plugins/pluginUtils.h b/source/plugins/pluginUtils.h deleted file mode 100755 index fadcc7a5..00000000 --- a/source/plugins/pluginUtils.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef UDA_PLUGINS_PLUGINUTILS_H -#define UDA_PLUGINS_PLUGINUTILS_H - -#endif // UDA_PLUGINS_PLUGINUTILS_H diff --git a/source/plugins/template/templatePlugin.cpp b/source/plugins/template/templatePlugin.cpp index 1487abe1..1016b4fc 100644 --- a/source/plugins/template/templatePlugin.cpp +++ b/source/plugins/template/templatePlugin.cpp @@ -1,7 +1,7 @@ /*--------------------------------------------------------------- * v1 UDA Plugin Template: Standardised plugin design template, just add ... * - * Input Arguments: IDAM_PLUGIN_INTERFACE *idam_plugin_interface + * Input Arguments: UDA_PLUGIN_INTERFACE *plugin_interface * * Returns: 0 if the plugin functionality was successful * otherwise a Error Code is returned @@ -20,9 +20,9 @@ *---------------------------------------------------------------------------------------------------------------*/ #include "templatePlugin.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include -#include +#include "include/uda_plugin_base.hpp" #include @@ -30,8 +30,8 @@ class TemplatePlugin : public UDAPluginBase { public: TemplatePlugin(); - int function(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + int function(UDA_PLUGIN_INTERFACE* plugin_interface); + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} }; @@ -42,7 +42,7 @@ TemplatePlugin::TemplatePlugin() register_method("function", static_cast(&TemplatePlugin::function)); } -int templatePlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +int templatePlugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static TemplatePlugin plugin = {}; return plugin.call(plugin_interface); @@ -66,10 +66,8 @@ template std::string to_string(const std::vector& array) //---------------------------------------------------------------------------------------- // Add functionality here .... -int TemplatePlugin::function(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TemplatePlugin::function(UDA_PLUGIN_INTERFACE* plugin_interface) { - DATA_BLOCK* data_block = plugin_interface->data_block; - auto required = find_required_arg(plugin_interface, "required"); auto array = find_required_array_arg(plugin_interface, "array"); auto optional = find_arg(plugin_interface, "optional"); @@ -78,10 +76,9 @@ int TemplatePlugin::function(IDAM_PLUGIN_INTERFACE* plugin_interface) std::string result = fmt::format("Passed args: required={}, array=[{}], optional={}", required, to_string(array), optional_str); - setReturnDataString(data_block, result.c_str(), "result of TemplatePlugin::function"); - - strcpy(data_block->data_label, ""); - strcpy(data_block->data_units, ""); + setReturnDataString(plugin_interface, result.c_str(), "result of TemplatePlugin::function"); + setReturnDataLabel(plugin_interface, ""); + setReturnDataUnits(plugin_interface, ""); return 0; } diff --git a/source/plugins/template/templatePlugin.h b/source/plugins/template/templatePlugin.h index 21a226c9..83ff23b5 100644 --- a/source/plugins/template/templatePlugin.h +++ b/source/plugins/template/templatePlugin.h @@ -12,7 +12,7 @@ extern "C" { #define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! #define THISPLUGIN_DEFAULT_METHOD "help" -LIBRARY_API int templatePlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +LIBRARY_API int templatePlugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/testplugin/testplugin.cpp b/source/plugins/testplugin/testplugin.cpp index ea2ceb0e..2060ee7e 100644 --- a/source/plugins/testplugin/testplugin.cpp +++ b/source/plugins/testplugin/testplugin.cpp @@ -5,12 +5,12 @@ #include #include "accessors.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include #include #include -#include +#include "include/uda_plugin_base.hpp" #include #include @@ -47,65 +47,65 @@ class TestPlugin : public UDAPluginBase { public: TestPlugin(); - int test0(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test2(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test4(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test5(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test6(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test7(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test8(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test9(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test9A(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test10(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test11(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test12(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test13(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test14(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test15(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test16(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test18(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test19(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test20(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test21(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test22(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test23(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test24(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test25(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test26(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test27(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test28(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test30(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test31(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test32(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test33(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test34(IDAM_PLUGIN_INTERFACE* plugin_interface); + int test0(UDA_PLUGIN_INTERFACE* plugin_interface); + int test2(UDA_PLUGIN_INTERFACE* plugin_interface); + int test4(UDA_PLUGIN_INTERFACE* plugin_interface); + int test5(UDA_PLUGIN_INTERFACE* plugin_interface); + int test6(UDA_PLUGIN_INTERFACE* plugin_interface); + int test7(UDA_PLUGIN_INTERFACE* plugin_interface); + int test8(UDA_PLUGIN_INTERFACE* plugin_interface); + int test9(UDA_PLUGIN_INTERFACE* plugin_interface); + int test9A(UDA_PLUGIN_INTERFACE* plugin_interface); + int test10(UDA_PLUGIN_INTERFACE* plugin_interface); + int test11(UDA_PLUGIN_INTERFACE* plugin_interface); + int test12(UDA_PLUGIN_INTERFACE* plugin_interface); + int test13(UDA_PLUGIN_INTERFACE* plugin_interface); + int test14(UDA_PLUGIN_INTERFACE* plugin_interface); + int test15(UDA_PLUGIN_INTERFACE* plugin_interface); + int test16(UDA_PLUGIN_INTERFACE* plugin_interface); + int test18(UDA_PLUGIN_INTERFACE* plugin_interface); + int test19(UDA_PLUGIN_INTERFACE* plugin_interface); + int test20(UDA_PLUGIN_INTERFACE* plugin_interface); + int test21(UDA_PLUGIN_INTERFACE* plugin_interface); + int test22(UDA_PLUGIN_INTERFACE* plugin_interface); + int test23(UDA_PLUGIN_INTERFACE* plugin_interface); + int test24(UDA_PLUGIN_INTERFACE* plugin_interface); + int test25(UDA_PLUGIN_INTERFACE* plugin_interface); + int test26(UDA_PLUGIN_INTERFACE* plugin_interface); + int test27(UDA_PLUGIN_INTERFACE* plugin_interface); + int test28(UDA_PLUGIN_INTERFACE* plugin_interface); + int test30(UDA_PLUGIN_INTERFACE* plugin_interface); + int test31(UDA_PLUGIN_INTERFACE* plugin_interface); + int test32(UDA_PLUGIN_INTERFACE* plugin_interface); + int test33(UDA_PLUGIN_INTERFACE* plugin_interface); + int test34(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef PUTDATAENABLED - int test40(IDAM_PLUGIN_INTERFACE* plugin_interface); + int test40(UDA_PLUGIN_INTERFACE* plugin_interface); #endif // PUTDATAENABLED - int test50(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test60(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test61(IDAM_PLUGIN_INTERFACE* plugin_interface); - int test62(IDAM_PLUGIN_INTERFACE* plugin_interface); - int plugin(IDAM_PLUGIN_INTERFACE* plugin_interface); - int errortest(IDAM_PLUGIN_INTERFACE* plugin_interface); - int scalartest(IDAM_PLUGIN_INTERFACE* plugin_interface); - int array1dtest(IDAM_PLUGIN_INTERFACE* plugin_interface); - int call_plugin_test(IDAM_PLUGIN_INTERFACE* plugin_interface); - int call_plugin_test_index(IDAM_PLUGIN_INTERFACE* plugin_interface); - int call_plugin_test_slice(IDAM_PLUGIN_INTERFACE* plugin_interface); - int call_plugin_test_stride(IDAM_PLUGIN_INTERFACE* plugin_interface); - int emptytest(IDAM_PLUGIN_INTERFACE* plugin_interface); + int test50(UDA_PLUGIN_INTERFACE* plugin_interface); + int test60(UDA_PLUGIN_INTERFACE* plugin_interface); + int test61(UDA_PLUGIN_INTERFACE* plugin_interface); + int test62(UDA_PLUGIN_INTERFACE* plugin_interface); + int plugin(UDA_PLUGIN_INTERFACE* plugin_interface); + int errortest(UDA_PLUGIN_INTERFACE* plugin_interface); + int scalartest(UDA_PLUGIN_INTERFACE* plugin_interface); + int array1dtest(UDA_PLUGIN_INTERFACE* plugin_interface); + int call_plugin_test(UDA_PLUGIN_INTERFACE* plugin_interface); + int call_plugin_test_index(UDA_PLUGIN_INTERFACE* plugin_interface); + int call_plugin_test_slice(UDA_PLUGIN_INTERFACE* plugin_interface); + int call_plugin_test_stride(UDA_PLUGIN_INTERFACE* plugin_interface); + int emptytest(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef CAPNP_ENABLED - int capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface); - int nested_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface); - int long_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface); - int large_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface); + int capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface); + int nested_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface); + int long_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface); + int large_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface); #endif // CAPNP_ENABLED #ifdef TESTUDT - int testudt(IDAM_PLUGIN_INTERFACE* plugin_interface); + int testudt(UDA_PLUGIN_INTERFACE* plugin_interface); #endif // TESTUDT - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} }; @@ -176,7 +176,7 @@ TestPlugin::TestPlugin() #endif // TESTUDT } -extern int testPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +extern int testPlugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static TestPlugin plugin = {}; return plugin.call(plugin_interface); @@ -196,7 +196,7 @@ void testError2() addIdamError(UDA_CODE_ERROR_TYPE, "testplugin", err, "Test #2 of Error State Management"); } -int TestPlugin::test0(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test0(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; REQUEST_DATA* request = plugin_interface->request_data; @@ -237,7 +237,7 @@ int TestPlugin::test0(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test2(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test2(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; REQUEST_DATA* request = plugin_interface->request_data; @@ -341,7 +341,7 @@ int TestPlugin::test2(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test4(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test4(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -412,7 +412,7 @@ int TestPlugin::test4(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test5(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test5(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -486,7 +486,7 @@ int TestPlugin::test5(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test6(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test6(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -558,7 +558,7 @@ int TestPlugin::test6(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test7(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test7(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -640,7 +640,7 @@ int TestPlugin::test7(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test8(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -724,7 +724,7 @@ int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test9(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test9(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -801,7 +801,7 @@ int TestPlugin::test9(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test9A(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test9A(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -908,7 +908,7 @@ int TestPlugin::test9A(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test10(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test10(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -931,7 +931,7 @@ int TestPlugin::test10(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test11(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test11(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1001,7 +1001,7 @@ int TestPlugin::test11(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test12(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test12(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1073,7 +1073,7 @@ int TestPlugin::test12(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test13(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test13(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1149,7 +1149,7 @@ int TestPlugin::test13(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test14(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test14(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1223,7 +1223,7 @@ int TestPlugin::test14(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test15(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1299,7 +1299,7 @@ int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test16(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1382,7 +1382,7 @@ int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test18(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test18(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1469,7 +1469,7 @@ int TestPlugin::test18(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test19(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1618,7 +1618,7 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test20(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test20(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1641,7 +1641,7 @@ int TestPlugin::test20(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test21(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test21(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1711,7 +1711,7 @@ int TestPlugin::test21(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test22(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test22(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1783,7 +1783,7 @@ int TestPlugin::test22(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test23(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1859,7 +1859,7 @@ int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test24(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test24(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -1933,7 +1933,7 @@ int TestPlugin::test24(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test25(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2009,7 +2009,7 @@ int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test26(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2093,7 +2093,7 @@ int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test27(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2191,7 +2191,7 @@ int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test28(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2294,7 +2294,7 @@ int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test30(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test30(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2358,7 +2358,7 @@ int TestPlugin::test30(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test31(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test31(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2437,7 +2437,7 @@ int TestPlugin::test31(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test32(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2552,7 +2552,7 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test33(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2674,7 +2674,7 @@ int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test34(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -2821,7 +2821,7 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) // Echo passed data back as an array of structures // The library won't build if the server version is not OK for this functionality // If the client cannot pass putdata blocks then no data will appear here to process. -int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test40(UDA_PLUGIN_INTERFACE* plugin_interface) { typedef struct Test40 { unsigned int dataCount; @@ -2975,7 +2975,7 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) // Shot number passed via request_block->exp_number // Placeholder values passed via request_block->tpass -int TestPlugin::test50(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test50(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; REQUEST_DATA* request = plugin_interface->request_data; @@ -3037,7 +3037,7 @@ typedef struct EnumList60 { int* arraydata_shape; } ENUMLIST60; -int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test60(UDA_PLUGIN_INTERFACE* plugin_interface) { auto enumlist = (ENUMLIST60*)malloc(sizeof(ENUMLIST60)); strcpy(enumlist->name, "TEST60 ENUM of type unsigned short"); @@ -3231,7 +3231,7 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test61(UDA_PLUGIN_INTERFACE* plugin_interface) { auto enumlist = (ENUMLIST60*)malloc(sizeof(ENUMLIST60)); strcpy(enumlist->name, "TEST61 ENUM of type unsigned long long"); @@ -3399,7 +3399,7 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::test62(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::test62(UDA_PLUGIN_INTERFACE* plugin_interface) { auto* enumlist = (ENUMLIST*)malloc(sizeof(ENUMLIST)); strcpy(enumlist->name, "TEST62 ENUM of type unsigned long long"); @@ -3473,13 +3473,13 @@ int TestPlugin::test62(IDAM_PLUGIN_INTERFACE* plugin_interface) // If the housekeeping action is requested, this must be also applied to all plugins called. // A list must be maintained to register these plugin calls to manage housekeeping. // Calls to plugins must also respect access policy and user authentication policy -int TestPlugin::plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::plugin(UDA_PLUGIN_INTERFACE* plugin_interface) { REQUEST_DATA* request = plugin_interface->request_data; int err = 0; - IDAM_PLUGIN_INTERFACE next_plugin_interface; + UDA_PLUGIN_INTERFACE next_plugin_interface; REQUEST_DATA next_request = {0}; const PLUGINLIST* pluginList = plugin_interface->pluginList; @@ -3537,7 +3537,7 @@ int TestPlugin::plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) // To maintain consistency with existing legacy code, use a local structure with a global scope (plugin library only) // A final necessary step is to concatenate this local structure with the server structure before returning. // When testing the plugin, errors are doubled (tripled!) up as both stacks are the same. -int TestPlugin::errortest(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::errortest(UDA_PLUGIN_INTERFACE* plugin_interface) { int err = 0; int test = 0; @@ -3571,7 +3571,7 @@ int TestPlugin::errortest(IDAM_PLUGIN_INTERFACE* plugin_interface) UDA_THROW_ERROR(9990 + test, "Test of Error State Management"); } -int TestPlugin::scalartest(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::scalartest(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -3586,7 +3586,7 @@ int TestPlugin::scalartest(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::array1dtest(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::array1dtest(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; @@ -3613,35 +3613,35 @@ int TestPlugin::array1dtest(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::emptytest(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::emptytest(UDA_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); return 0; } -int TestPlugin::call_plugin_test(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::call_plugin_test(UDA_PLUGIN_INTERFACE* plugin_interface) { return callPlugin(plugin_interface->pluginList, "TESTPLUGIN::array1dtest()", plugin_interface); } -int TestPlugin::call_plugin_test_index(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::call_plugin_test_index(UDA_PLUGIN_INTERFACE* plugin_interface) { return callPlugin(plugin_interface->pluginList, "TESTPLUGIN::array1dtest()[25]", plugin_interface); } -int TestPlugin::call_plugin_test_slice(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::call_plugin_test_slice(UDA_PLUGIN_INTERFACE* plugin_interface) { return callPlugin(plugin_interface->pluginList, "TESTPLUGIN::array1dtest()[10:20]", plugin_interface); } -int TestPlugin::call_plugin_test_stride(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::call_plugin_test_stride(UDA_PLUGIN_INTERFACE* plugin_interface) { return callPlugin(plugin_interface->pluginList, "TESTPLUGIN::array1dtest()[::2]", plugin_interface); } #ifdef CAPNP_ENABLED -int TestPlugin::capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface) { auto tree = uda_capnp_new_tree(); auto root = uda_capnp_get_root(tree); @@ -3684,7 +3684,7 @@ int TestPlugin::capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::nested_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::nested_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface) { auto tree = uda_capnp_new_tree(); auto root = uda_capnp_get_root(tree); @@ -3740,7 +3740,7 @@ int TestPlugin::nested_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::long_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::long_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface) { auto tree = uda_capnp_new_tree(); auto root = uda_capnp_get_root(tree); @@ -3779,7 +3779,7 @@ int TestPlugin::long_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) return 0; } -int TestPlugin::large_capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::large_capnp_test(UDA_PLUGIN_INTERFACE* plugin_interface) { auto tree = uda_capnp_new_tree(); auto root = uda_capnp_get_root(tree); @@ -3964,7 +3964,7 @@ int tcp_connect(SYSSOCKET* ssock, int port) // UDP has better performance but data packets may get lost - it is not reliable // UDT is an application level protocol, based on UDP, that is reliable and has the performance of UDP // The IDAM server acts as a UDT client and the IDAM client acts as the UDT server! -int TestPlugin::testudt(IDAM_PLUGIN_INTERFACE* plugin_interface) +int TestPlugin::testudt(UDA_PLUGIN_INTERFACE* plugin_interface) { // Start a mini server loop and create a separate communiation channel with the client bye-passing the TCP socket diff --git a/source/plugins/testplugin/testplugin.h b/source/plugins/testplugin/testplugin.h index b2a2022a..7c818c27 100644 --- a/source/plugins/testplugin/testplugin.h +++ b/source/plugins/testplugin/testplugin.h @@ -8,7 +8,7 @@ extern "C" { #endif -int testPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +int testPlugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/testplugin/teststructs.cpp b/source/plugins/testplugin/teststructs.cpp index 9999a12d..68f7e506 100644 --- a/source/plugins/testplugin/teststructs.cpp +++ b/source/plugins/testplugin/teststructs.cpp @@ -3,7 +3,7 @@ #include "struct.h" #include -void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) +void init_structure_definitions(UDA_PLUGIN_INTERFACE* plugin_interface) { USERDEFINEDTYPE* old; @@ -104,7 +104,7 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) field.alignment = getalignmentof(field.type); addCompoundField(&usertype, field); // Single Structure element - USERDEFINEDTYPELIST* userdefinedtypelist = idam_plugin_interface->userdefinedtypelist; + USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); UDA_LOG(UDA_LOG_DEBUG, "Type TEST9 defined\n"); diff --git a/source/plugins/testplugin/teststructs.h b/source/plugins/testplugin/teststructs.h index 606ef388..f15c2eef 100644 --- a/source/plugins/testplugin/teststructs.h +++ b/source/plugins/testplugin/teststructs.h @@ -1,7 +1,7 @@ #ifndef UDA_PLUGIN_TESTPLUGIN_TESTSTRUCTS_H #define UDA_PLUGIN_TESTPLUGIN_TESTSTRUCTS_H -#include "pluginStructs.h" +#include "udaPlugin.h" typedef struct Test9 { char v1[56]; // single fixed length string @@ -20,6 +20,6 @@ typedef struct Test9A { TEST9 v6; // Sub Structure with String types } TEST9A; -void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +void init_structure_definitions(UDA_PLUGIN_INTERFACE* plugin_interface); #endif // UDA_PLUGIN_TESTPLUGIN_TESTSTRUCTS_H diff --git a/source/plugins/uda/uda_plugin.cpp b/source/plugins/uda/uda_plugin.cpp index ccd93db8..9d6044cd 100644 --- a/source/plugins/uda/uda_plugin.cpp +++ b/source/plugins/uda/uda_plugin.cpp @@ -3,17 +3,28 @@ #include #include "accAPI.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaGetAPI.h" #include "udaPlugin.h" #include #include #include -#include +#include "include/uda_plugin_base.hpp" +#include "server/serverPlugin.h" #include #include +namespace { +void setIdamClientFlag(CLIENT_FLAGS *client_flags, unsigned int flag) { + client_flags->flags = client_flags->flags | flag; +} + +void resetIdamClientFlag(CLIENT_FLAGS *client_flags, unsigned int flag) { + client_flags->flags &= !flag; +} +} + namespace uda::plugins::uda { @@ -22,9 +33,9 @@ class Plugin : public UDAPluginBase public: Plugin(); - int get(IDAM_PLUGIN_INTERFACE* plugin_interface); + int get(UDA_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override { old_host_ = getIdamServerHost(); old_port_ = getIdamServerPort(); @@ -45,13 +56,13 @@ Plugin::Plugin() } // namespace uda::plugins::uda -extern int UDAPlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) +extern int UDAPlugin(UDA_PLUGIN_INTERFACE* plugin_interface) { static uda::plugins::uda::Plugin plugin = {}; return plugin.call(plugin_interface); } -int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) +int uda::plugins::uda::Plugin::get(UDA_PLUGIN_INTERFACE* plugin_interface) { int err = 0; @@ -164,7 +175,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) // Source URL may be an nullptr string pathway = 4; } else { - error("Execution pathway not recognised: Unable to execute the request!"); + error(plugin_interface, "Execution pathway not recognised: Unable to execute the request!"); } //---------------------------------------------------------------------- @@ -188,38 +199,38 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) auto client_flags = udaClientFlags(); if (client_block->get_nodimdata) { - setIdamProperty("get_nodimdata", client_flags); + setIdamProperty("get_nodimdata"); } if (client_block->get_timedble) { - setIdamProperty("get_timedble", client_flags); + setIdamProperty("get_timedble"); } if (client_block->get_dimdble) { - setIdamProperty("get_dimdble", client_flags); + setIdamProperty("get_dimdble"); } if (client_block->get_datadble) { - setIdamProperty("get_datadble", client_flags); + setIdamProperty("get_datadble"); } if (client_block->get_bad) { - setIdamProperty("get_bad", client_flags); + setIdamProperty("get_bad"); } if (client_block->get_meta) { - setIdamProperty("get_meta", client_flags); + setIdamProperty("get_meta"); } if (client_block->get_asis) { - setIdamProperty("get_asis", client_flags); + setIdamProperty("get_asis"); } if (client_block->get_uncal) { - setIdamProperty("get_uncal", client_flags); + setIdamProperty("get_uncal"); } if (client_block->get_notoff) { - setIdamProperty("get_notoff", client_flags); + setIdamProperty("get_notoff"); } if (client_block->get_scalar) { - setIdamProperty("get_scalar", client_flags); + setIdamProperty("get_scalar"); } if (client_block->get_bytes) { - setIdamProperty("get_bytes", client_flags); + setIdamProperty("get_bytes"); } // Timeout ... @@ -278,7 +289,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the formats 'server:port' or 'server " + error(plugin_interface, "The Server Port must be an Integer Number passed using the formats 'server:port' or 'server " "port'"); } } else { @@ -288,14 +299,14 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } } else { - error("No Server has been specified!"); + error(plugin_interface, "No Server has been specified!"); } - debug("UDA Server Host for UDA Plugin {}\n", data_source->server); - debug("UDA Server Port for UDA Plugin {}\n", newPort); - debug("Calling idamGetAPI API (Database based Request)\n"); - debug("Signal: {}\n", signal.c_str()); - debug("Source: {}\n", source.c_str()); + debug(plugin_interface, "UDA Server Host for UDA Plugin {}\n", data_source->server); + debug(plugin_interface, "UDA Server Port for UDA Plugin {}\n", newPort); + debug(plugin_interface, "Calling idamGetAPI API (Database based Request)\n"); + debug(plugin_interface, "Signal: {}\n", signal.c_str()); + debug(plugin_interface, "Source: {}\n", source.c_str()); handle = idamGetAPI(signal.c_str(), source.c_str()); @@ -315,7 +326,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) p[0] = '\0'; // Break the String (work) strcpy(source, p + 1); // Extract the Source URL Argument } else { - error("The Remote Server Data Source specified does not comply with the naming model: " + error(plugin_interface, "The Remote Server Data Source specified does not comply with the naming model: " "serverHost:port/sourceURL"); } } else { @@ -324,7 +335,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) p[0] = '\0'; // Break the String (work) strcpy(source, p + 1); // Extract the Source URL Argument } else { - error("The Remote Server Data Source specified does not comply with the naming model: " + error(plugin_interface, "The Remote Server Data Source specified does not comply with the naming model: " "serverHost:port/sourceURL"); } } @@ -354,7 +365,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server " + error(plugin_interface, "The Server Port must be an Integer Number passed using the format 'server:port' or 'server " "port'"); } } else { @@ -364,11 +375,11 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } - debug("UDA Server Host for UDA Plugin {}\n", request->server); - debug("UDA Server Port for UDA Plugin {}\n", newPort); - debug("Calling idamGetAPI API (Device redirect or server protocol based Request)\n"); - debug("Signal: {}\n", request->signal); - debug("Source: {}\n", source); + debug(plugin_interface, "UDA Server Host for UDA Plugin {}\n", request->server); + debug(plugin_interface, "UDA Server Port for UDA Plugin {}\n", newPort); + debug(plugin_interface, "Calling idamGetAPI API (Device redirect or server protocol based Request)\n"); + debug(plugin_interface, "Signal: {}\n", request->signal); + debug(plugin_interface, "Source: {}\n", source); handle = idamGetAPI(request->signal, source); @@ -378,15 +389,15 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) // Function library const char* host = nullptr; - bool isHost = findStringValue(&request->nameValueList, &host, "host"); + bool isHost = findStringValue(plugin_interface, &host, "host"); const char* signal = nullptr; - bool isSignal = findStringValue(&request->nameValueList, &signal, "signal"); + bool isSignal = findStringValue(plugin_interface, &signal, "signal"); const char* source = nullptr; - bool isSource = findStringValue(&request->nameValueList, &source, "source"); + bool isSource = findStringValue(plugin_interface, &source, "source"); - bool isPort = findIntValue(&request->nameValueList, &newPort, "port"); + bool isPort = findIntValue(plugin_interface, &newPort, "port"); // Set host and port @@ -399,20 +410,20 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) putIdamServerPort(newPort); } - debug("UDA Server Host for UDA Plugin {}\n", host); - debug("UDA Server Port for UDA Plugin {}\n", newPort); - debug("Calling idamGetAPI API (plugin library method based Request)\n"); + debug(plugin_interface, "UDA Server Host for UDA Plugin {}\n", host); + debug(plugin_interface, "UDA Server Port for UDA Plugin {}\n", newPort); + debug(plugin_interface, "Calling idamGetAPI API (plugin library method based Request)\n"); if (isSignal && isSource) { - debug("Signal: {}\n", signal); - debug("idamAPIPlugin; Source: {}\n", source); + debug(plugin_interface, "Signal: {}\n", signal); + debug(plugin_interface, "idamAPIPlugin; Source: {}\n", source); handle = idamGetAPI(signal, source); } else if (isSignal) { - debug("Signal: {}\n", signal); - debug("idamAPIPlugin; Source: {}\n", request->source); + debug(plugin_interface, "Signal: {}\n", signal); + debug(plugin_interface, "idamAPIPlugin; Source: {}\n", request->source); handle = idamGetAPI(signal, request->source); } else { - error("A data object (signal) has not been specified!"); + error(plugin_interface, "A data object (signal) has not been specified!"); } } else if (pathway == 4) { @@ -452,7 +463,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server " + error(plugin_interface, "The Server Port must be an Integer Number passed using the format 'server:port' or 'server " "port'"); } } else { @@ -463,11 +474,11 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } - debug("UDA Server Host for UDA Plugin {}\n", request->server); - debug("UDA Server Port for UDA Plugin {}\n", newPort); - debug("Calling idamGetAPI API (Server protocol based Request)\n"); - debug("Signal: {}\n", request->signal); - debug("Source: {}\n", source); + debug(plugin_interface, "UDA Server Host for UDA Plugin {}\n", request->server); + debug(plugin_interface, "UDA Server Port for UDA Plugin {}\n", newPort); + debug(plugin_interface, "Calling idamGetAPI API (Server protocol based Request)\n"); + debug(plugin_interface, "Signal: {}\n", request->signal); + debug(plugin_interface, "Source: {}\n", source); handle = idamGetAPI(request->signal, source); } @@ -478,12 +489,12 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------- // Test for Errors: Close Socket and Free heap - debug("Returned from idamGetAPI API: handle = {}, error code = {}\n", handle, getIdamErrorCode(handle)); + debug(plugin_interface, "Returned from idamGetAPI API: handle = {}, error code = {}\n", handle, getIdamErrorCode(handle)); if (handle < 0) { - error(getIdamServerErrorStackRecordMsg(0)); + error(plugin_interface, getIdamServerErrorStackRecordMsg(0)); } else if ((err = getIdamErrorCode(handle)) != 0) { - error(getIdamErrorMsg(handle)); + error(plugin_interface, getIdamErrorMsg(handle)); } //---------------------------------------------------------------------- @@ -501,7 +512,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (getIdamClientVersion() >= 7) { // This should contain everything! - *data_block = *getIdamDataBlock(handle); + *data_block = *getDataBlock(handle); } else { // use abstraction functions // Straight structure mapping causes potential problems when the client library uses different versions @@ -513,7 +524,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) DATA_BLOCK db; initDataBlock(&db); - auto odb = (OLD_DATA_BLOCK*)getIdamDataBlock(handle); + auto odb = (OLD_DATA_BLOCK*)getDataBlock(handle); db.handle = odb->handle; db.errcode = odb->errcode; @@ -565,7 +576,7 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) *signal_desc = *(data_block->signal_desc); } - debug("Exit\n"); + debug(plugin_interface, "Exit\n"); //---------------------------------------------------------------------- // If the Data are Hierarchical, then necessary to forward the xdr file diff --git a/source/plugins/uda/uda_plugin.h b/source/plugins/uda/uda_plugin.h index 72cf965c..c0dfd368 100644 --- a/source/plugins/uda/uda_plugin.h +++ b/source/plugins/uda/uda_plugin.h @@ -2,7 +2,7 @@ #define UDA_PLUGIN_UDA_PLUGIN_H #include "export.h" -#include "pluginStructs.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { @@ -12,7 +12,7 @@ extern "C" { #define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! #define THISPLUGIN_DEFAULT_METHOD "help" -int UDAPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +int UDAPlugin(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/udaPlugin.cpp b/source/plugins/udaPlugin.cpp index 3b2e4bbd..6f855606 100644 --- a/source/plugins/udaPlugin.cpp +++ b/source/plugins/udaPlugin.cpp @@ -1,27 +1,29 @@ #include "udaPlugin.h" + #include "server/initPluginList.h" #include "server/serverPlugin.h" #include "server/serverSubsetData.h" #include "struct.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "udaTypes.h" +#include "accessors.h" #include #include #include #include -IDAM_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) +UDA_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) { - auto plugin_interface = (IDAM_PLUGIN_INTERFACE*)calloc(1, sizeof(IDAM_PLUGIN_INTERFACE)); + auto plugin_interface = (UDA_PLUGIN_INTERFACE*)calloc(1, sizeof(UDA_PLUGIN_INTERFACE)); auto environment = getServerEnvironment(); auto plugin_list = (PLUGINLIST*)calloc(1, sizeof(PLUGINLIST)); initPluginList(plugin_list, environment); auto request_data = (REQUEST_DATA*)calloc(1, sizeof(REQUEST_DATA)); - makeRequestData(request_data, *plugin_list, environment); + makeRequestData(request_data, plugin_list, environment); auto user_defined_type_list = (USERDEFINEDTYPELIST*)calloc(1, sizeof(USERDEFINEDTYPELIST)); auto log_malloc_list = (LOGMALLOCLIST*)calloc(1, sizeof(LOGMALLOCLIST)); @@ -42,7 +44,7 @@ IDAM_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) return plugin_interface; } -void udaFreePluginInterface(IDAM_PLUGIN_INTERFACE* plugin_interface) +void udaFreePluginInterface(UDA_PLUGIN_INTERFACE* plugin_interface) { free(plugin_interface->request_data); freeUserDefinedTypeList(plugin_interface->userdefinedtypelist); @@ -55,15 +57,16 @@ void udaFreePluginInterface(IDAM_PLUGIN_INTERFACE* plugin_interface) free(plugin_interface); } -int initPlugin(const IDAM_PLUGIN_INTERFACE* plugin_interface) +int initPlugin(const UDA_PLUGIN_INTERFACE* plugin_interface) { udaSetLogLevel((LOG_LEVEL)plugin_interface->environment->loglevel); return 0; } -int setReturnDataFloatArray(DATA_BLOCK* data_block, float* values, size_t rank, const size_t* shape, +int setReturnDataFloatArray(UDA_PLUGIN_INTERFACE* plugin_interface, float* values, size_t rank, const size_t* shape, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); if (description != nullptr) { @@ -99,9 +102,10 @@ int setReturnDataFloatArray(DATA_BLOCK* data_block, float* values, size_t rank, return 0; } -int setReturnDataDoubleArray(DATA_BLOCK* data_block, double* values, size_t rank, const size_t* shape, +int setReturnDataDoubleArray(UDA_PLUGIN_INTERFACE* plugin_interface, double* values, size_t rank, const size_t* shape, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); if (description != nullptr) { @@ -137,9 +141,10 @@ int setReturnDataDoubleArray(DATA_BLOCK* data_block, double* values, size_t rank return 0; } -int setReturnDataIntArray(DATA_BLOCK* data_block, int* values, size_t rank, const size_t* shape, +int setReturnDataIntArray(UDA_PLUGIN_INTERFACE* plugin_interface, int* values, size_t rank, const size_t* shape, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); if (description != nullptr) { @@ -175,8 +180,9 @@ int setReturnDataIntArray(DATA_BLOCK* data_block, int* values, size_t rank, cons return 0; } -int setReturnDataDoubleScalar(DATA_BLOCK* data_block, double value, const char* description) +int setReturnDataDoubleScalar(UDA_PLUGIN_INTERFACE* plugin_interface, double value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); auto data = (double*)malloc(sizeof(double)); @@ -195,8 +201,9 @@ int setReturnDataDoubleScalar(DATA_BLOCK* data_block, double value, const char* return 0; } -int setReturnDataFloatScalar(DATA_BLOCK* data_block, float value, const char* description) +int setReturnDataFloatScalar(UDA_PLUGIN_INTERFACE* plugin_interface, float value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); auto data = (float*)malloc(sizeof(float)); @@ -215,8 +222,9 @@ int setReturnDataFloatScalar(DATA_BLOCK* data_block, float value, const char* de return 0; } -int setReturnDataIntScalar(DATA_BLOCK* data_block, int value, const char* description) +int setReturnDataIntScalar(UDA_PLUGIN_INTERFACE* plugin_interface, int value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); int* data = (int*)malloc(sizeof(int)); @@ -235,8 +243,9 @@ int setReturnDataIntScalar(DATA_BLOCK* data_block, int value, const char* descri return 0; } -int setReturnDataLongScalar(DATA_BLOCK* data_block, long value, const char* description) +int setReturnDataLongScalar(UDA_PLUGIN_INTERFACE* plugin_interface, long value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); long* data = (long*)malloc(sizeof(long)); @@ -255,8 +264,9 @@ int setReturnDataLongScalar(DATA_BLOCK* data_block, long value, const char* desc return 0; } -int setReturnDataShortScalar(DATA_BLOCK* data_block, short value, const char* description) +int setReturnDataShortScalar(UDA_PLUGIN_INTERFACE* plugin_interface, short value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); auto data = (short*)malloc(sizeof(short)); @@ -275,8 +285,9 @@ int setReturnDataShortScalar(DATA_BLOCK* data_block, short value, const char* de return 0; } -int setReturnDataString(DATA_BLOCK* data_block, const char* value, const char* description) +int setReturnDataString(UDA_PLUGIN_INTERFACE* plugin_interface, const char* value, const char* description) { + DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); data_block->data_type = UDA_TYPE_STRING; @@ -306,9 +317,10 @@ int setReturnDataString(DATA_BLOCK* data_block, const char* value, const char* d return 0; } -int setReturnData(DATA_BLOCK* data_block, void* value, size_t size, UDA_TYPE type, int rank, const int* shape, +int setReturnData(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; initDataBlock(data_block); data_block->data_type = type; @@ -342,87 +354,6 @@ int setReturnData(DATA_BLOCK* data_block, void* value, size_t size, UDA_TYPE typ return 0; } -/** - * Find the Plugin identity: return the reference id or -1 if not found. - * @param request - * @param plugin_list - * @return - */ -int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list) -{ - for (int i = 0; i < plugin_list->count; i++) { - if (plugin_list->plugin[i].request == request) { - return i; - } - } - return -1; -} - -/** - * Find the Plugin identity: return the reference id or -1 if not found. - * @param format - * @param plugin_list - * @return - */ -int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list) -{ - for (int i = 0; i < plugin_list->count; i++) { - if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { - return i; - } - } - return -1; -} - -/** - * Find the Plugin identity: return the reference id or -1 if not found. - * @param device - * @param plugin_list - * @return - */ -int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list) -{ - for (int i = 0; i < plugin_list->count; i++) { - if (plugin_list->plugin[i].plugin_class == UDA_PLUGIN_CLASS_DEVICE && - STR_IEQUALS(plugin_list->plugin[i].format, device)) { - return i; - } - } - return -1; -} - -/** - * Find the Plugin Request: return the request or REQUEST_READ_UNKNOWN if not found. - * @param format - * @param plugin_list - * @return - */ -int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list) -{ - for (int i = 0; i < plugin_list->count; i++) { - if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { - return plugin_list->plugin[i].request; - } - } - return REQUEST_READ_UNKNOWN; -} - -/** - * Find the Plugin Request: return the request or REQUEST_READ_UNKNOWN if not found. - * @param extension - * @param plugin_list - * @return - */ -int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin_list) -{ - for (int i = 0; i < plugin_list->count; i++) { - if (STR_IEQUALS(plugin_list->plugin[i].extension, extension)) { - return plugin_list->plugin[i].request; - } - } - return REQUEST_READ_UNKNOWN; -} - /** * Look for an argument with the given name in the provided NAMEVALUELIST and return it's associated value. * @@ -433,8 +364,10 @@ int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin * @param name * @return */ -bool findStringValue(const NAMEVALUELIST* namevaluelist, const char** value, const char* name) +bool findStringValue(const UDA_PLUGIN_INTERFACE* plugin_interface, const char** value, const char* name) { + auto namevaluelist = &plugin_interface->request_data->nameValueList; + char** names = SplitString(name, "|"); *value = nullptr; @@ -464,10 +397,10 @@ bool findStringValue(const NAMEVALUELIST* namevaluelist, const char** value, con * @param name * @return */ -bool findIntValue(const NAMEVALUELIST* namevaluelist, int* value, const char* name) +bool findIntValue(const UDA_PLUGIN_INTERFACE* plugin_interface, int* value, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { *value = atoi(str); } @@ -484,10 +417,10 @@ bool findIntValue(const NAMEVALUELIST* namevaluelist, int* value, const char* na * @param name * @return */ -bool findShortValue(const NAMEVALUELIST* namevaluelist, short* value, const char* name) +bool findShortValue(const UDA_PLUGIN_INTERFACE* plugin_interface, short* value, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { *value = (short)atoi(str); } @@ -504,10 +437,10 @@ bool findShortValue(const NAMEVALUELIST* namevaluelist, short* value, const char * @param name * @return */ -bool findCharValue(const NAMEVALUELIST* namevaluelist, char* value, const char* name) +bool findCharValue(const UDA_PLUGIN_INTERFACE* plugin_interface, char* value, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { *value = (char)atoi(str); } @@ -524,20 +457,20 @@ bool findCharValue(const NAMEVALUELIST* namevaluelist, char* value, const char* * @param name * @return */ -bool findFloatValue(const NAMEVALUELIST* namevaluelist, float* value, const char* name) +bool findFloatValue(const UDA_PLUGIN_INTERFACE* plugin_interface, float* value, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { *value = strtof(str, nullptr); } return found; } -bool findIntArray(const NAMEVALUELIST* namevaluelist, int** values, size_t* nvalues, const char* name) +bool findIntArray(const UDA_PLUGIN_INTERFACE* plugin_interface, int** values, size_t* nvalues, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { char** tokens = SplitString(str, ";"); size_t n; @@ -555,10 +488,10 @@ bool findIntArray(const NAMEVALUELIST* namevaluelist, int** values, size_t* nval return found; } -bool findFloatArray(const NAMEVALUELIST* namevaluelist, float** values, size_t* nvalues, const char* name) +bool findFloatArray(const UDA_PLUGIN_INTERFACE* plugin_interface, float** values, size_t* nvalues, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { char** tokens = SplitString(str, ";"); size_t n; @@ -576,10 +509,10 @@ bool findFloatArray(const NAMEVALUELIST* namevaluelist, float** values, size_t* return found; } -bool findDoubleArray(const NAMEVALUELIST* namevaluelist, double** values, size_t* nvalues, const char* name) +bool findDoubleArray(const UDA_PLUGIN_INTERFACE* plugin_interface, double** values, size_t* nvalues, const char* name) { const char* str; - bool found = findStringValue(namevaluelist, &str, name); + bool found = findStringValue(plugin_interface, &str, name); if (found) { char** tokens = SplitString(str, ";"); size_t n; @@ -597,8 +530,9 @@ bool findDoubleArray(const NAMEVALUELIST* namevaluelist, double** values, size_t return found; } -bool findValue(const NAMEVALUELIST* namevaluelist, const char* name) +bool findValue(const UDA_PLUGIN_INTERFACE* plugin_interface, const char* name) { + auto namevaluelist = &plugin_interface->request_data->nameValueList; char** names = SplitString(name, "|"); bool found = false; @@ -617,38 +551,269 @@ bool findValue(const NAMEVALUELIST* namevaluelist, const char* name) return found; } -int callPlugin(const PLUGINLIST* pluginlist, const char* signal, const IDAM_PLUGIN_INTERFACE* old_plugin_interface) +int callPlugin(UDA_PLUGIN_INTERFACE* plugin_interface, const char* request) { - IDAM_PLUGIN_INTERFACE idam_plugin_interface = *old_plugin_interface; - REQUEST_DATA request = *old_plugin_interface->request_data; - idam_plugin_interface.request_data = &request; + UDA_PLUGIN_INTERFACE new_plugin_interface = *plugin_interface; + REQUEST_DATA request_data = *plugin_interface->request_data; + new_plugin_interface.request_data = &request_data; - request.source[0] = '\0'; - strcpy(request.signal, signal); - makeRequestData(&request, *pluginlist, old_plugin_interface->environment); + request_data.source[0] = '\0'; + strcpy(request_data.signal, request); + makeRequestData(&request_data, plugin_interface->pluginList, plugin_interface->environment); - request.request = findPluginRequestByFormat(request.format, pluginlist); - if (request.request == REQUEST_READ_UNKNOWN) { - RAISE_PLUGIN_ERROR("Plugin not found!"); + request_data.request = findPluginRequestByFormat(request_data.format, plugin_interface->pluginList); + if (request_data.request == REQUEST_READ_UNKNOWN) { + RAISE_PLUGIN_ERROR(plugin_interface, "Plugin not found!"); } int err = 0; - int id = findPluginIdByRequest(request.request, pluginlist); - PLUGIN_DATA* plugin = &(pluginlist->plugin[id]); + int id = findPluginIdByRequest(request_data.request, plugin_interface->pluginList); + PLUGIN_DATA* plugin = &(plugin_interface->pluginList->plugin[id]); if (id >= 0 && plugin->idamPlugin != nullptr) { - err = plugin->idamPlugin(&idam_plugin_interface); // Call the data reader + err = plugin->idamPlugin(&new_plugin_interface); // Call the data reader } else { - RAISE_PLUGIN_ERROR("Data Access is not available for this data request!"); + RAISE_PLUGIN_ERROR(plugin_interface, "Data Access is not available for this data request!"); } // Apply subsettinng - if (request.datasubset.nbound > 0) { + if (request_data.datasubset.nbound > 0) { ACTION action = {}; initAction(&action); action.actionType = UDA_SUBSET_TYPE; - action.subset = request.datasubset; - err = serverSubsetData(idam_plugin_interface.data_block, action, idam_plugin_interface.logmalloclist); + action.subset = request_data.datasubset; + err = serverSubsetData(new_plugin_interface.data_block, action, new_plugin_interface.logmalloclist); } return err; } + +int setReturnCompoundData(UDA_PLUGIN_INTERFACE *plugin_interface, char* data, const char *user_type) { + DATA_BLOCK* data_block = plugin_interface->data_block; + initDataBlock(data_block); + + data_block->data_type = UDA_TYPE_COMPOUND; + data_block->rank = 0; + data_block->data_n = 1; + data_block->data = data; + + strcpy(data_block->data_desc, "Local UDA server time"); + strcpy(data_block->data_label, "servertime"); + strcpy(data_block->data_units, ""); + + data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; + data_block->opaque_count = 1; + data_block->opaque_block = (void*)findUserDefinedType(plugin_interface->userdefinedtypelist, user_type, 0); + + return 0; +} + +COMPOUNDFIELD* udaNewCompoundField(const char* name, const char* description, int* offset, int type) +{ + COMPOUNDFIELD* field = (COMPOUNDFIELD*)malloc(sizeof(COMPOUNDFIELD)); + defineField(field, name, description, offset, type); + return field; +} + +USERDEFINEDTYPE* udaNewUserType(const char* name, const char* source, int ref_id, int image_count, char* image, size_t size, size_t num_fields, COMPOUNDFIELD** fields) +{ + USERDEFINEDTYPE* user_type = (USERDEFINEDTYPE*)malloc(sizeof(USERDEFINEDTYPE)); + + strcpy(user_type->name, name); + strcpy(user_type->source, source); + user_type->ref_id = ref_id; + user_type->imagecount = image_count; // No Structure Image data + user_type->image = image; + user_type->size = size; // Structure size + user_type->idamclass = UDA_TYPE_COMPOUND; + + for (size_t i = 0; i < num_fields; ++i) { + COMPOUNDFIELD* field = fields[i]; + addCompoundField(user_type, *field); + } + + return user_type; +} + +int udaAddUserType(UDA_PLUGIN_INTERFACE* plugin_interface, USERDEFINEDTYPE* user_type) +{ + USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; + addUserDefinedType(userdefinedtypelist, *user_type); + + return 0; +} + +int udaRegisterMalloc(UDA_PLUGIN_INTERFACE* plugin_interface, void* data, int count, size_t size, const char* type) +{ + addMalloc(plugin_interface->logmalloclist, data, count, size, type); + + return 0; +} + +int udaPluginPluginsCount(UDA_PLUGIN_INTERFACE* plugin_interface) +{ + return plugin_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; + + bool is_valid = plugin_list->plugin[plugin_num].plugin_class == plugin_class && + plugin_list->plugin[plugin_num].status == UDA_PLUGIN_OPERATIONAL && + (plugin_list->plugin[plugin_num].is_private == UDA_PLUGIN_PUBLIC || + (plugin_list->plugin[plugin_num].is_private == UDA_PLUGIN_PRIVATE && !environment->external_user)); + + if (plugin_class == UDA_PLUGIN_CLASS_FILE) { + is_valid |= (plugin_list->plugin[plugin_num].format[0] != '\0' && plugin_list->plugin[plugin_num].extension[0] != '\0'); + } + + return is_valid; +} + +} + +int udaPluginCheckPluginClass(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num, const char* plugin_class) +{ + std::string plugin_class_string = plugin_class; + + if (plugin_class_string == "file") { + return check_plugin_class(plugin_interface, plugin_num, UDA_PLUGIN_CLASS_FILE); + } else if (plugin_class_string == "function") { + return check_plugin_class(plugin_interface, plugin_num, UDA_PLUGIN_CLASS_FUNCTION); + } else if (plugin_class_string == "server") { + return check_plugin_class(plugin_interface, plugin_num, UDA_PLUGIN_CLASS_SERVER); + } else if (plugin_class_string == "device") { + return check_plugin_class(plugin_interface, plugin_num, UDA_PLUGIN_CLASS_DEVICE); + } else if (plugin_class_string == "other") { + return check_plugin_class(plugin_interface, plugin_num, UDA_PLUGIN_CLASS_OTHER); + } + + return 0; +} + +const char* udaPluginPluginFormat(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) +{ + return plugin_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; +} + +const char* udaPluginPluginDescription(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_num) +{ + return plugin_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; +} + +void udaPluginLog(UDA_PLUGIN_INTERFACE* plugin_interface, const char* fmt, ...) +{ + va_list args; + va_start(args, fmt); + + udaLog(UDA_LOG_DEBUG, fmt, args); + + va_end(args); +} + +void udaAddPluginError(UDA_PLUGIN_INTERFACE* plugin_interface, const char* location, int code, const char* msg) +{ + 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] = createIdamError(UDA_CODE_ERROR_TYPE, location, code, msg); +} + +int udaPluginIsExternal(UDA_PLUGIN_INTERFACE* plugin_interface) +{ + return plugin_interface->environment->external_user; +} + +int udaPluginCheckInterfaceVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int interface_version) +{ + return plugin_interface->interfaceVersion > interface_version; +} + +void udaPluginSetVersion(UDA_PLUGIN_INTERFACE* plugin_interface, int plugin_version) +{ + plugin_interface->pluginVersion = plugin_version; +} + +const char* udaPluginFunction(UDA_PLUGIN_INTERFACE* plugin_interface) +{ + return plugin_interface->request_data->function; +} + +int setReturnDataLabel(UDA_PLUGIN_INTERFACE* plugin_interface, const char* label) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + strcpy(data_block->data_label, label); + return 0; +} + +int setReturnDataUnits(UDA_PLUGIN_INTERFACE* plugin_interface, const char* units) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + strcpy(data_block->data_units, units); + return 0; +} + +int setReturnErrorAsymmetry(UDA_PLUGIN_INTERFACE* plugin_interface, bool flag) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + data_block->errasymmetry = flag; + return 0; +} + +char* memdup(const void* mem, size_t size) +{ + char* out = (char*)malloc(size); + + if (out != nullptr) { + memcpy(out, mem, size); + } + + return out; +} + +int setReturnErrorLow(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + data_block->errlo = memdup(data, size); + return 0; +} + +int setReturnErrorHigh(UDA_PLUGIN_INTERFACE* plugin_interface, float* data, size_t size) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + data_block->errhi = memdup(data, size); + return 0; +} + +int setReturnDataOrder(UDA_PLUGIN_INTERFACE* plugin_interface, int order) +{ + DATA_BLOCK* data_block = plugin_interface->data_block; + data_block->order = order; + return 0; +} + +int setReturnDimensionFloatArray(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; + + data_block->dims[0].data_type = UDA_TYPE_FLOAT; + data_block->dims[0].dim_n = dim_n; + data_block->dims[0].compressed = 0; + strcpy(data_block->dims[0].dim_label, label); + strcpy(data_block->dims[0].dim_units, units); + + data_block->data = memdup(data, size); + return 0; +} \ No newline at end of file diff --git a/source/plugins/uda_plugin_base.cpp b/source/plugins/uda_plugin_base.cpp index 1907bc13..72be65f1 100644 --- a/source/plugins/uda_plugin_base.cpp +++ b/source/plugins/uda_plugin_base.cpp @@ -7,14 +7,14 @@ #include #include -int UDAPluginBase::call(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::call(UDA_PLUGIN_INTERFACE* plugin_interface) { try { - if (plugin_interface->interfaceVersion > interface_version_) { - RAISE_PLUGIN_ERROR("Plugin Interface Version Unknown to this plugin: Unable to execute the request!"); + if (udaPluginCheckInterfaceVersion(plugin_interface, interface_version_)) { + error(plugin_interface, "Plugin Interface Version Unknown to this plugin: Unable to execute the request!"); } - plugin_interface->pluginVersion = version_; + udaPluginSetVersion(plugin_interface, version_); do_reset(); do_init(plugin_interface); @@ -25,7 +25,7 @@ int UDAPluginBase::call(IDAM_PLUGIN_INTERFACE* plugin_interface) std::string function = get_function(plugin_interface); - int rc; + int rc = 0; if (function_map_.find(function) != function_map_.end()) { rc = function_map_.at(function)(plugin_interface); @@ -33,29 +33,21 @@ int UDAPluginBase::call(IDAM_PLUGIN_INTERFACE* plugin_interface) auto fn = method_map_.at(function); rc = (this->*fn)(plugin_interface); } else { - UDA_LOG(UDA_LOG_ERROR, "Unknown function requested %s\n", function.c_str()); - addIdamError(UDA_CODE_ERROR_TYPE, "UDAPluginBase::call", 999, "Unknown function requested"); - concatUdaError(&plugin_interface->error_stack); - return 999; + error(plugin_interface, "Unknown function requested"); } - - concatUdaError(&plugin_interface->error_stack); return rc; } catch (std::exception& ex) { - UDA_LOG(UDA_LOG_ERROR, "Exception: %s\n", ex.what()); - addIdamError(UDA_CODE_ERROR_TYPE, "UDAPluginBase::call", 999, ex.what()); - concatUdaError(&plugin_interface->error_stack); - return 999; + debug(plugin_interface, ex.what()); + return 1; } } -std::string UDAPluginBase::get_function(IDAM_PLUGIN_INTERFACE* plugin_interface) +std::string UDAPluginBase::get_function(UDA_PLUGIN_INTERFACE* plugin_interface) { - REQUEST_DATA* request = plugin_interface->request_data; - return boost::to_lower_copy(request->function); + return boost::to_lower_copy(udaPluginFunction(plugin_interface)); } -void UDAPluginBase::do_init(IDAM_PLUGIN_INTERFACE* plugin_interface) +void UDAPluginBase::do_init(UDA_PLUGIN_INTERFACE* plugin_interface) { std::string function = get_function(plugin_interface); if (!init_ || (function == "init" || function == "initialise")) { @@ -75,19 +67,19 @@ void UDAPluginBase::do_reset() init_ = false; } -int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::help(UDA_PLUGIN_INTERFACE* plugin_interface) { std::string desc = name_ + ": help = description of this plugin"; if (help_file_.empty()) { const char* help = "No help available"; - return setReturnDataString(plugin_interface->data_block, help, desc.c_str()); + return setReturnDataString(plugin_interface, help, desc.c_str()); } auto path = boost::filesystem::path(help_file_); if (!boost::filesystem::exists(path)) { auto help = fmt::format("help file {} does not exist", path.string()); - return setReturnDataString(plugin_interface->data_block, help.c_str(), desc.c_str()); + return setReturnDataString(plugin_interface, help.c_str(), desc.c_str()); } std::ifstream help_file{path.string()}; @@ -95,27 +87,27 @@ int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE* plugin_interface) buffer << help_file.rdbuf(); auto help = buffer.str(); - return setReturnDataString(plugin_interface->data_block, help.c_str(), desc.c_str()); + return setReturnDataString(plugin_interface, help.c_str(), desc.c_str()); } -int UDAPluginBase::version(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::version(UDA_PLUGIN_INTERFACE* plugin_interface) { - return setReturnDataIntScalar(plugin_interface->data_block, version_, "Plugin version number"); + return setReturnDataIntScalar(plugin_interface, version_, "Plugin version number"); } -int UDAPluginBase::build_date(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::build_date(UDA_PLUGIN_INTERFACE* plugin_interface) { - return setReturnDataString(plugin_interface->data_block, __DATE__, "Plugin build date"); + return setReturnDataString(plugin_interface, __DATE__, "Plugin build date"); } -int UDAPluginBase::default_method(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::default_method(UDA_PLUGIN_INTERFACE* plugin_interface) { - return setReturnDataString(plugin_interface->data_block, default_method_.c_str(), "Plugin default method"); + return setReturnDataString(plugin_interface, default_method_.c_str(), "Plugin default method"); } -int UDAPluginBase::max_interface_version(IDAM_PLUGIN_INTERFACE* plugin_interface) +int UDAPluginBase::max_interface_version(UDA_PLUGIN_INTERFACE* plugin_interface) { - return setReturnDataIntScalar(plugin_interface->data_block, interface_version_, "Maximum Interface Version"); + return setReturnDataIntScalar(plugin_interface, interface_version_, "Maximum Interface Version"); } void UDAPluginBase::register_method(const std::string& name, plugin_member_type plugin_method) @@ -128,8 +120,8 @@ void UDAPluginBase::register_function(const std::string& name, plugin_function_t function_map_[name] = plugin_function; } -bool UDAPluginBase::has_arg(IDAM_PLUGIN_INTERFACE* plugin_interface, const std::string& name) +bool UDAPluginBase::has_arg(UDA_PLUGIN_INTERFACE* plugin_interface, const std::string& name) { const char* str; - return findStringValue(&plugin_interface->request_data->nameValueList, &str, name.c_str()); + return findStringValue(plugin_interface, &str, name.c_str()); } diff --git a/source/plugins/viewport/viewport.cpp b/source/plugins/viewport/viewport.cpp index e0e218e3..12e5e6ee 100644 --- a/source/plugins/viewport/viewport.cpp +++ b/source/plugins/viewport/viewport.cpp @@ -2,7 +2,7 @@ * v1 IDAM Plugin viewPort: re-bin data to visualise with a rectangular viewport defined by horizonal * and vertical pixel ranges * - * Input Arguments: IDAM_PLUGIN_INTERFACE *plugin_interface + * Input Arguments: UDA_PLUGIN_INTERFACE *plugin_interface * * Returns: 0 if the plugin functionality was successful * otherwise a Error Code is returned @@ -19,10 +19,10 @@ #endif #include "accAPI.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaGetAPI.h" #include -#include +#include "include/uda_plugin_base.hpp" #include #include @@ -37,8 +37,8 @@ class ViewportPlugin : public UDAPluginBase { public: ViewportPlugin(); - int get(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} + int get(UDA_PLUGIN_INTERFACE* plugin_interface); + void init(UDA_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} private: @@ -59,17 +59,6 @@ void reduceOrderedData(float* values, int* count, float* startValue, float* endV void getVerticalPixelValues(float* values, int count, int pixel_height, float* startValue, float* endValue, float** verticalPixelValues, float* delta); -char* memdup(const void* mem, size_t size) -{ - char* out = (char*)malloc(size); - - if (out != nullptr) { - memcpy(out, mem, size); - } - - return out; -} - int ViewportPlugin::find_handle(const std::string& signal, const std::string& source) { for (const auto& entry : cache_) { @@ -80,13 +69,13 @@ int ViewportPlugin::find_handle(const std::string& signal, const std::string& so return -1; } -extern int viewport(IDAM_PLUGIN_INTERFACE* plugin_interface) +extern int viewport(UDA_PLUGIN_INTERFACE* plugin_interface) { static ViewportPlugin plugin = {}; return plugin.call(plugin_interface); } -int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) +int ViewportPlugin::get(UDA_PLUGIN_INTERFACE* plugin_interface) { // Context based Tests: required - pixel_width, pixel_height, Signal, Source @@ -111,7 +100,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (handle < 0) { if ((handle = idamGetAPI(signal.c_str(), source.c_str())) < 0 || getIdamErrorCode(handle) != 0) { - error(getIdamErrorMsg(handle)); + error(plugin_interface, getIdamErrorMsg(handle)); } cache_.emplace_back(CacheEntry{handle, signal, source}); @@ -132,7 +121,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) getIdamFloatDimData(handle, 0, coords.data()); if (test) { - debug("Running Viewport Test {}\n", *test); + debug(plugin_interface, "Running Viewport Test {}\n", *test); switch (*test) { case 1: { // Do nothing @@ -298,7 +287,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (pixel_width && pixel_height) { // Map to pixels if the device coordinate viewport is defined - debug("Viewport: Mapping data to device pixel coordinate range (width, height) = {}, {}\n", *pixel_width, + debug(plugin_interface, "Viewport: Mapping data to device pixel coordinate range (width, height) = {}, {}\n", *pixel_width, *pixel_height); int* column = nullptr; @@ -353,9 +342,9 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) colCount = colCount + fctot[i]; } - debug("Column Totals: {}\n", colCount); + debug(plugin_interface, "Column Totals: {}\n", colCount); for (int i = 0; i < *pixel_width; i++) { - debug("[{}] {}\n", i, fctot[i]); + debug(plugin_interface, "[{}] {}\n", i, fctot[i]); } // Which pixel row bin do each un-ordered data point fall into? @@ -390,9 +379,9 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) rowCount = rowCount + frtot[i]; } - debug("Row Totals: {}\n", rowCount); + debug(plugin_interface, "Row Totals: {}\n", rowCount); for (int i = 0; i < *pixel_height; i++) { - debug("[{}] {}\n", i, frtot[i]); + debug(plugin_interface, "[{}] {}\n", i, frtot[i]); } free(column); @@ -421,7 +410,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (range && mean) { if (i == 0) { - debug("Mean returned\n"); + debug(plugin_interface, "Mean returned\n"); } for (int j = 0; j < pixel_height; j++) { if (freq[i][j] > 0) { @@ -436,7 +425,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } else if (!range && mode) { - debug("Mode returned\n"); + debug(plugin_interface, "Mode returned\n"); int fmax = 0; int fmaxID = -1; for (int j = 0; j < pixel_height; j++) { @@ -452,7 +441,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } else if (!range && median) { if (i == 0) { - debug("Median returned\n"); + debug(plugin_interface, "Median returned\n"); } integral[0] = freq[i][0]; @@ -510,7 +499,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (range) { if (i == 0) { - debug("Range returned\n"); + debug(plugin_interface, "Range returned\n"); } data[i] = 0.5 * (err_lo[i] + err_hi[i]); good_count++; @@ -518,14 +507,14 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) free(freq[i]); - debug("[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); + debug(plugin_interface, "[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); } // end of loop over pixel_width - debug("good_count = {}\n", good_count); - debug("pixel_width = {}\n", *pixel_width); + debug(plugin_interface, "good_count = {}\n", good_count); + debug(plugin_interface, "pixel_width = {}\n", *pixel_width); for (int i = 0; i < pixelWidth2; i++) { - debug("[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); + debug(plugin_interface, "[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); } // Free allocated heap @@ -540,7 +529,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) // Remove pixel columns without data if (good_count < pixel_width) { - debug("Removing pixel columns without data [{}, {}]\n", good_count, *pixel_width); + debug(plugin_interface, "Removing pixel columns without data [{}, {}]\n", good_count, *pixel_width); std::vector new_data(static_cast(good_count)); std::vector new_err_hi(static_cast(good_count)); @@ -572,42 +561,22 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } // Return viewport data - DATA_BLOCK* data_block = plugin_interface->data_block; - initDataBlock(data_block); + size_t shape[] = { (size_t)pixelWidth2 }; + setReturnDataFloatArray(plugin_interface, data.data(), 1, shape, getIdamDataDesc(handle)); + setReturnDataLabel(plugin_interface, getIdamDataLabel(handle)); + setReturnDataUnits(plugin_interface, getIdamDataUnits(handle)); - data_block->rank = 1; - data_block->dims = (DIMS*)malloc(data_block->rank * sizeof(DIMS)); - for (unsigned int i = 0; i < data_block->rank; i++) { - initDimBlock(&data_block->dims[i]); - } - - data_block->data_n = pixelWidth2; - data_block->data_type = UDA_TYPE_FLOAT; - strcpy(data_block->data_desc, getIdamDataDesc(handle)); - strcpy(data_block->data_label, getIdamDataLabel(handle)); - strcpy(data_block->data_units, getIdamDataUnits(handle)); - - data_block->dims[0].dim = memdup(horizontal_pixel_values.data(), horizontal_pixel_values.size()); - - data_block->dims[0].data_type = UDA_TYPE_FLOAT; - data_block->dims[0].dim_n = pixelWidth2; - data_block->dims[0].compressed = 0; - strcpy(data_block->dims[0].dim_label, getIdamDimLabel(handle, 0)); - strcpy(data_block->dims[0].dim_units, getIdamDimUnits(handle, 0)); - - data_block->data = memdup(data.data(), data.size()); + setReturnDimensionFloatArray(plugin_interface, 0, horizontal_pixel_values.data(), pixelWidth2, getIdamDimLabel(handle, 0), getIdamDimUnits(handle, 0)); if (!range) { - data_block->errasymmetry = 1; - data_block->errlo = memdup(err_lo.data(), err_lo.size()); + setReturnErrorAsymmetry(plugin_interface, true); + setReturnErrorLow(plugin_interface, err_lo.data(), err_lo.size()); } - data_block->errhi = memdup(err_hi.data(), err_hi.size()); - data_block->error_type = UDA_TYPE_FLOAT; - - data_block->order = order; + setReturnErrorHigh(plugin_interface, err_hi.data(), err_hi.size()); + setReturnDataOrder(plugin_interface, order); } else { - error("A viewport for rank > 1 data has not been implemented!"); + error(plugin_interface, "A viewport for rank > 1 data has not been implemented!"); } return 0; diff --git a/source/plugins/viewport/viewport.h b/source/plugins/viewport/viewport.h index fb386fc1..9c4e1507 100644 --- a/source/plugins/viewport/viewport.h +++ b/source/plugins/viewport/viewport.h @@ -16,7 +16,7 @@ extern "C" { #define MAXSIGNALNAME 256 #define FREEHANDLEBLOCK 4 -int viewport(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); +int viewport(UDA_PLUGIN_INTERFACE* plugin_interface); #ifdef __cplusplus } diff --git a/source/security/authenticationUtils.h b/source/security/authenticationUtils.h index 307d06cf..3015b9e4 100644 --- a/source/security/authenticationUtils.h +++ b/source/security/authenticationUtils.h @@ -2,7 +2,7 @@ #define UDA_SECURITY_AUTHENTICATIONUTILS_H #include "export.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/security/clientAuthentication.h b/source/security/clientAuthentication.h index 1af78d05..0a70717b 100644 --- a/source/security/clientAuthentication.h +++ b/source/security/clientAuthentication.h @@ -3,7 +3,7 @@ #include "export.h" #include "genStructs.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "security.h" diff --git a/source/security/serverAuthentication.h b/source/security/serverAuthentication.h index 39b6a29c..2264fbcb 100644 --- a/source/security/serverAuthentication.h +++ b/source/security/serverAuthentication.h @@ -3,7 +3,7 @@ #include "export.h" #include "genStructs.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "security.h" diff --git a/source/server/applyXML.h b/source/server/applyXML.h index 3e827fa7..12ef3f52 100644 --- a/source/server/applyXML.h +++ b/source/server/applyXML.h @@ -4,7 +4,7 @@ # define UDA_SERVER_APPLYXML_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" # include int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, ACTIONS* actions_desc, diff --git a/source/server/fatServer.cpp b/source/server/fatServer.cpp index be90d1b7..f0bd57e1 100644 --- a/source/server/fatServer.cpp +++ b/source/server/fatServer.cpp @@ -2,7 +2,7 @@ #include #include -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "struct.h" #include @@ -67,23 +67,23 @@ void setLogMallocList(LOGMALLOCLIST* logmalloclist_in) } #endif -static int startupFatServer(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduserdefinedtypelist); +static int startup_fat_server(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduserdefinedtypelist); -static int doFatServerClosedown(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, ACTIONS* actions_desc, +static int do_fat_server_closedown(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, ACTIONS* actions_desc, ACTIONS* actions_sig, DATA_BLOCK_LIST* data_blocks0); -static int handleRequestFat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0, CLIENT_BLOCK* client_block, +static int handle_request_fat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, METADATA_BLOCK* metadata_block, DATA_BLOCK_LIST* data_block, ACTIONS* actions_desc, ACTIONS* actions_sig); -static int fatClientReturn(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DATA_BLOCK_LIST* data_blocks0, +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); //-------------------------------------------------------------------------------------- // Server Entry point -int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, +int fat_server(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, DATA_BLOCK_LIST* data_blocks0) { assert(data_blocks0 != nullptr); @@ -127,20 +127,20 @@ int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLO log_malloc_list = (LOGMALLOCLIST*)malloc(sizeof(LOGMALLOCLIST)); initLogMallocList(log_malloc_list); - int err = startupFatServer(server_block, parseduserdefinedtypelist); + int err = startup_fat_server(server_block, parseduserdefinedtypelist); if (err != 0) { return err; } copyUserDefinedTypeList(&user_defined_type_list, &parseduserdefinedtypelist); - err = handleRequestFat(&request_block, request_block0, &client_block, server_block, &metadata_block, &data_blocks, + err = handle_request_fat(&request_block, request_block0, &client_block, server_block, &metadata_block, &data_blocks, &actions_desc, &actions_sig); if (err != 0) { return err; } - err = fatClientReturn(server_block, &data_blocks, data_blocks0, &request_block, &client_block, &metadata_block, + err = fat_client_return(server_block, &data_blocks, data_blocks0, &request_block, &client_block, &metadata_block, &log_struct_list, &io_data); if (err != 0) { return err; @@ -148,7 +148,7 @@ int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLO udaAccessLog(FALSE, client_block, request_block, *server_block, total_datablock_size); - err = doFatServerClosedown(server_block, &data_blocks, &actions_desc, &actions_sig, data_blocks0); + err = do_fat_server_closedown(server_block, &data_blocks, &actions_desc, &actions_sig, data_blocks0); freeUserDefinedTypeList(user_defined_type_list); free(user_defined_type_list); @@ -174,7 +174,7 @@ int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLO * Client deletes stale files automatically on startup. * @return */ -static int processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, IoData* io_data) +static int process_hierarchical_data(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, IoData* io_data) { int err = 0; @@ -199,18 +199,18 @@ static int processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_st UDA_THROW_ERROR(999, "Unable to Open a Temporary XDR File for Writing"); } - XDR xdrServerOutput; - xdrstdio_create(&xdrServerOutput, xdrfile, XDR_ENCODE); + XDR xdr_server_output; + xdrstdio_create(&xdr_server_output, xdrfile, XDR_ENCODE); // Write data to the temporary file int protocol_id = UDA_PROTOCOL_STRUCTURES; - protocolXML(&xdrServerOutput, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, data_block, + protocolXML(&xdr_server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, data_block, protocol_version, log_struct_list, io_data, private_flags, malloc_source, serverCreateXDRStream); // Close the stream and file - xdr_destroy(&xdrServerOutput); + xdr_destroy(&xdr_server_output); fclose(xdrfile); // Free Heap @@ -224,19 +224,19 @@ static int processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_st UDA_THROW_ERROR(999, "Unable to Open a Temporary XDR File for Reading"); } - XDR xdrServerInput; - xdrstdio_create(&xdrServerInput, xdrfile, XDR_DECODE); + XDR xdr_server_input; + xdrstdio_create(&xdr_server_input, xdrfile, XDR_DECODE); // Read data from the temporary file protocol_id = UDA_PROTOCOL_STRUCTURES; - err = protocolXML(&xdrServerInput, protocol_id, XDR_RECEIVE, nullptr, log_malloc_list, user_defined_type_list, + err = protocolXML(&xdr_server_input, protocol_id, XDR_RECEIVE, nullptr, log_malloc_list, user_defined_type_list, data_block, protocol_version, log_struct_list, io_data, private_flags, malloc_source, serverCreateXDRStream); // Close the stream and file - xdr_destroy(&xdrServerInput); + xdr_destroy(&xdr_server_input); fclose(xdrfile); // Remove the Temporary File @@ -246,7 +246,7 @@ static int processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_st return err; } -int fatClientReturn(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DATA_BLOCK_LIST* data_blocks0, +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) { @@ -267,7 +267,7 @@ int fatClientReturn(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DA for (int i = 0; i < data_blocks->count; ++i) { auto data_block = &data_blocks->data[i]; if (data_block->opaque_type == UDA_OPAQUE_TYPE_STRUCTURES) { - processHierarchicalData(data_block, log_struct_list, io_data); + process_hierarchical_data(data_block, log_struct_list, io_data); } } @@ -276,7 +276,7 @@ int fatClientReturn(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, DA return err; } -int handleRequestFat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0, CLIENT_BLOCK* client_block, +int handle_request_fat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, METADATA_BLOCK* metadata_block, DATA_BLOCK_LIST* data_blocks, ACTIONS* actions_desc, ACTIONS* actions_sig) { @@ -381,7 +381,7 @@ int handleRequestFat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0 return err; } -int doFatServerClosedown(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, ACTIONS* actions_desc, +int do_fat_server_closedown(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blocks, ACTIONS* actions_desc, ACTIONS* actions_sig, DATA_BLOCK_LIST* data_blocks0) { //---------------------------------------------------------------------------- @@ -407,7 +407,7 @@ int doFatServerClosedown(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block return 0; } -int startupFatServer(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduserdefinedtypelist) +int startup_fat_server(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduserdefinedtypelist) { static int socket_list_initialised = 0; static int plugin_list_initialised = 0; diff --git a/source/server/getPluginAddress.cpp b/source/server/getPluginAddress.cpp index 541757b6..0db3b5f6 100644 --- a/source/server/getPluginAddress.cpp +++ b/source/server/getPluginAddress.cpp @@ -53,7 +53,7 @@ int getPluginAddress(void** pluginHandle, const char* library, const char* symbo // Find the address of the required plugin function - int (*fptr)(IDAM_PLUGIN_INTERFACE*); + int (*fptr)(UDA_PLUGIN_INTERFACE*); *(void**)(&fptr) = dlsym(*pluginHandle, symbol); char* errstr = dlerror(); diff --git a/source/server/getPluginAddress.h b/source/server/getPluginAddress.h index 84002b9c..baec3fd8 100644 --- a/source/server/getPluginAddress.h +++ b/source/server/getPluginAddress.h @@ -1,11 +1,5 @@ #pragma once -#ifndef UDA_GETPLUGIN_ADDRESS_H -# define UDA_GETPLUGIN_ADDRESS_H - -# include "export.h" -# include "udaPlugin.h" +#include "serverPlugin.h" int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp); - -#endif // UDA_GETPLUGIN_ADDRESS_H diff --git a/source/server/getServerEnvironment.h b/source/server/getServerEnvironment.h index 69f68cbe..c16f7c35 100644 --- a/source/server/getServerEnvironment.h +++ b/source/server/getServerEnvironment.h @@ -4,7 +4,7 @@ # define UDA_SERVER_GETSERVERENVIRONMENT_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" void printServerEnvironment(const ENVIRONMENT* environment); ENVIRONMENT* getServerEnvironment(); diff --git a/source/server/initPluginList.h b/source/server/initPluginList.h index 0711b1bb..276b83b7 100644 --- a/source/server/initPluginList.h +++ b/source/server/initPluginList.h @@ -1,12 +1,6 @@ #pragma once -#ifndef UDA_SERVER_INITPLUGINLIST_H -# define UDA_SERVER_INITPLUGINLIST_H - -# include "export.h" -# include "pluginStructs.h" -# include "udaStructs.h" +#include "serverPlugin.h" +#include "clientserver/udaStructs.h" void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment); - -#endif // UDA_SERVER_INITPLUGINLIST_H diff --git a/source/server/makeServerRequestBlock.cpp b/source/server/makeServerRequestBlock.cpp index 54258266..8d252018 100644 --- a/source/server/makeServerRequestBlock.cpp +++ b/source/server/makeServerRequestBlock.cpp @@ -1,6 +1,6 @@ #include "makeServerRequestBlock.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include #include "getServerEnvironment.h" @@ -9,12 +9,12 @@ int makeServerRequestBlock(REQUEST_BLOCK* request_block, PLUGINLIST pluginList) { - return make_request_block(request_block, pluginList, getServerEnvironment()); + return make_request_block(request_block, &pluginList, getServerEnvironment()); } int makeServerRequestData(REQUEST_DATA* request, PLUGINLIST pluginList) { - return makeRequestData(request, pluginList, getServerEnvironment()); + return makeRequestData(request, &pluginList, getServerEnvironment()); } #endif diff --git a/source/server/makeServerRequestBlock.h b/source/server/makeServerRequestBlock.h index 6155db4e..54154ca2 100644 --- a/source/server/makeServerRequestBlock.h +++ b/source/server/makeServerRequestBlock.h @@ -1,17 +1,11 @@ #pragma once -#ifndef UDA_SERVER_MAKESERVERREQUESTBLOCK_H -# define UDA_SERVER_MAKESERVERREQUESTBLOCK_H +#if defined(SERVERBUILD) || defined(FATCLIENT) -# include "export.h" -# include "udaPlugin.h" -# include "udaStructs.h" - -# if defined(SERVERBUILD) || defined(FATCLIENT) +# include "clientserver/udaStructs.h" +# include "serverPlugin.h" int makeServerRequestBlock(REQUEST_BLOCK* request_block, PLUGINLIST pluginList); int makeServerRequestData(REQUEST_DATA* request, PLUGINLIST pluginList); -# endif - -#endif // UDA_SERVER_MAKESERVERREQUESTBLOCK_H +#endif diff --git a/source/server/serverGetData.cpp b/source/server/serverGetData.cpp index 87ad231a..345323bd 100644 --- a/source/server/serverGetData.cpp +++ b/source/server/serverGetData.cpp @@ -7,7 +7,7 @@ # define strncasecmp _strnicmp #endif -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "struct.h" #include @@ -1112,7 +1112,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data // Test for known File formats and Server protocols { - IDAM_PLUGIN_INTERFACE idam_plugin_interface; + UDA_PLUGIN_INTERFACE plugin_interface; UDA_LOG(UDA_LOG_DEBUG, "creating the plugin interface structure\n"); @@ -1120,24 +1120,24 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data initDataBlock(data_block); - idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.pluginVersion = 0; - idam_plugin_interface.sqlConnectionType = 0; - idam_plugin_interface.data_block = data_block; - idam_plugin_interface.client_block = &client_block; - idam_plugin_interface.request_data = request; - idam_plugin_interface.data_source = data_source; - idam_plugin_interface.signal_desc = signal_desc; - idam_plugin_interface.environment = environment; - idam_plugin_interface.sqlConnection = nullptr; - idam_plugin_interface.verbose = 0; - idam_plugin_interface.housekeeping = 0; - idam_plugin_interface.changePlugin = 0; - idam_plugin_interface.pluginList = pluginlist; - idam_plugin_interface.userdefinedtypelist = userdefinedtypelist; - idam_plugin_interface.logmalloclist = logmalloclist; - idam_plugin_interface.error_stack.nerrors = 0; - idam_plugin_interface.error_stack.idamerror = nullptr; + plugin_interface.interfaceVersion = 1; + plugin_interface.pluginVersion = 0; + plugin_interface.sqlConnectionType = 0; + plugin_interface.data_block = data_block; + plugin_interface.client_block = &client_block; + plugin_interface.request_data = request; + plugin_interface.data_source = data_source; + plugin_interface.signal_desc = signal_desc; + plugin_interface.environment = environment; + plugin_interface.sqlConnection = nullptr; + plugin_interface.verbose = 0; + plugin_interface.housekeeping = 0; + plugin_interface.changePlugin = 0; + plugin_interface.pluginList = pluginlist; + plugin_interface.userdefinedtypelist = userdefinedtypelist; + plugin_interface.logmalloclist = logmalloclist; + plugin_interface.error_stack.nerrors = 0; + plugin_interface.error_stack.idamerror = nullptr; int plugin_id; @@ -1180,12 +1180,12 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data #endif // Call the plugin - int err = pluginlist->plugin[id].idamPlugin(&idam_plugin_interface); - for (unsigned int i = 0; i < idam_plugin_interface.error_stack.nerrors; ++i) { - auto error = &idam_plugin_interface.error_stack.idamerror[i]; + int err = pluginlist->plugin[id].idamPlugin(&plugin_interface); + for (unsigned int i = 0; i < plugin_interface.error_stack.nerrors; ++i) { + auto error = &plugin_interface.error_stack.idamerror[i]; addIdamError(error->type, error->location, error->code, error->msg); } - freeIdamErrorStack(&idam_plugin_interface.error_stack); + freeIdamErrorStack(&plugin_interface.error_stack); #ifndef FATCLIENT // Reset Redirected Output @@ -1216,7 +1216,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data } } - if (!idam_plugin_interface.changePlugin) { + if (!plugin_interface.changePlugin) { // job done! data_block->source_status = data_source->status; diff --git a/source/server/serverGetData.h b/source/server/serverGetData.h index 30ae204e..b9bd6489 100644 --- a/source/server/serverGetData.h +++ b/source/server/serverGetData.h @@ -1,18 +1,12 @@ #pragma once -#ifndef UDA_SERVER_SERVERGETDATA_H -# define UDA_SERVER_SERVERGETDATA_H - -# include "export.h" -# include "genStructs.h" -# include "pluginStructs.h" -# include "udaStructs.h" -# include -# include +#include "genStructs.h" +#include "clientserver/udaStructs.h" +#include "serverPlugin.h" +#include +#include 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); - -#endif // UDA_SERVER_SERVERGETDATA_H diff --git a/source/server/serverLegacyPlugin.h b/source/server/serverLegacyPlugin.h index ab32f426..a46a4f9a 100644 --- a/source/server/serverLegacyPlugin.h +++ b/source/server/serverLegacyPlugin.h @@ -4,7 +4,7 @@ # define UDA_SERVER_SERVERLEGACYPLUGIN_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc); diff --git a/source/server/serverMain.cpp b/source/server/serverMain.cpp index aa0d0e80..e9f22f12 100644 --- a/source/server/serverMain.cpp +++ b/source/server/serverMain.cpp @@ -21,7 +21,7 @@ int main(int argc, char** argv) CLIENT_BLOCK client_block = {0}; - int rc = udaServer(client_block); + int rc = uda_server(client_block); return rc; } diff --git a/source/server/serverPlugin.cpp b/source/server/serverPlugin.cpp index a840bd2d..8a381af2 100644 --- a/source/server/serverPlugin.cpp +++ b/source/server/serverPlugin.cpp @@ -16,7 +16,7 @@ # define dup2 _dup2 #endif -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include #include @@ -30,6 +30,87 @@ #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 +/** + * Find the Plugin identity: return the reference id or -1 if not found. + * @param request + * @param plugin_list + * @return + */ +int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list) +{ + for (int i = 0; i < plugin_list->count; i++) { + if (plugin_list->plugin[i].request == request) { + return i; + } + } + return -1; +} + +/** + * Find the Plugin identity: return the reference id or -1 if not found. + * @param format + * @param plugin_list + * @return + */ +int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list) +{ + for (int i = 0; i < plugin_list->count; i++) { + if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { + return i; + } + } + return -1; +} + +/** + * Find the Plugin identity: return the reference id or -1 if not found. + * @param device + * @param plugin_list + * @return + */ +int findPluginIdByDevice(const char* device, const PLUGINLIST* plugin_list) +{ + for (int i = 0; i < plugin_list->count; i++) { + if (plugin_list->plugin[i].plugin_class == UDA_PLUGIN_CLASS_DEVICE && + STR_IEQUALS(plugin_list->plugin[i].format, device)) { + return i; + } + } + return -1; +} + +/** + * Find the Plugin Request: return the request or REQUEST_READ_UNKNOWN if not found. + * @param format + * @param plugin_list + * @return + */ +int findPluginRequestByFormat(const char* format, const PLUGINLIST* plugin_list) +{ + for (int i = 0; i < plugin_list->count; i++) { + if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { + return plugin_list->plugin[i].request; + } + } + return REQUEST_READ_UNKNOWN; +} + +/** + * Find the Plugin Request: return the request or REQUEST_READ_UNKNOWN if not found. + * @param extension + * @param plugin_list + * @return + */ +int findPluginRequestByExtension(const char* extension, const PLUGINLIST* plugin_list) +{ + for (int i = 0; i < plugin_list->count; i++) { + if (STR_IEQUALS(plugin_list->plugin[i].extension, extension)) { + return plugin_list->plugin[i].request; + } + } + return REQUEST_READ_UNKNOWN; +} + void allocPluginList(int count, PLUGINLIST* plugin_list) { if (count >= plugin_list->mcount) { @@ -42,16 +123,16 @@ void allocPluginList(int count, PLUGINLIST* plugin_list) void resetPlugins(const PLUGINLIST* plugin_list) { REQUEST_DATA request_block; - IDAM_PLUGIN_INTERFACE idam_plugin_interface; + UDA_PLUGIN_INTERFACE plugin_interface; initRequestData(&request_block); strcpy(request_block.function, "reset"); - idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.housekeeping = 1; // Force a full reset - idam_plugin_interface.request_data = &request_block; + plugin_interface.interfaceVersion = 1; + plugin_interface.housekeeping = 1; // Force a full reset + 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(&idam_plugin_interface); // Call the housekeeping method + plugin_list->plugin[i].idamPlugin(&plugin_interface); // Call the housekeeping method } } } @@ -261,7 +342,7 @@ int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC //---------------------------------------------------------------------------------------------- // Decode the API Arguments: determine appropriate data reader plug-in - if ((err = makeRequestData(request, *plugin_list, environment)) != 0) { + if ((err = makeRequestData(request, plugin_list, environment)) != 0) { return err; } @@ -403,11 +484,11 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque UDA_LOG(UDA_LOG_DEBUG, "Provenance Plugin signal: %s\n", request.signal); - makeRequestData(&request, *plugin_list, environment); + makeRequestData(&request, plugin_list, environment); int err, rc, reset; DATA_BLOCK data_block; - IDAM_PLUGIN_INTERFACE idam_plugin_interface; + UDA_PLUGIN_INTERFACE plugin_interface; // Initialise the Data Block @@ -427,21 +508,21 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque LOGMALLOCLIST logmalloclist; initLogMallocList(&logmalloclist); - idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.pluginVersion = 0; - idam_plugin_interface.data_block = &data_block; - idam_plugin_interface.client_block = client_block; - idam_plugin_interface.request_data = &request; - idam_plugin_interface.data_source = data_source; - idam_plugin_interface.signal_desc = signal_desc; - idam_plugin_interface.environment = environment; - idam_plugin_interface.housekeeping = 0; - idam_plugin_interface.changePlugin = 0; - idam_plugin_interface.pluginList = plugin_list; - idam_plugin_interface.userdefinedtypelist = &userdefinedtypelist; - idam_plugin_interface.logmalloclist = &logmalloclist; - idam_plugin_interface.error_stack.nerrors = 0; - idam_plugin_interface.error_stack.idamerror = nullptr; + plugin_interface.interfaceVersion = 1; + plugin_interface.pluginVersion = 0; + plugin_interface.data_block = &data_block; + plugin_interface.client_block = client_block; + plugin_interface.request_data = &request; + plugin_interface.data_source = data_source; + plugin_interface.signal_desc = signal_desc; + plugin_interface.environment = environment; + plugin_interface.housekeeping = 0; + plugin_interface.changePlugin = 0; + plugin_interface.pluginList = plugin_list; + plugin_interface.userdefinedtypelist = &userdefinedtypelist; + plugin_interface.logmalloclist = &logmalloclist; + plugin_interface.error_stack.nerrors = 0; + plugin_interface.error_stack.idamerror = nullptr; // Redirect Output to temporary file if no file handles passed @@ -454,7 +535,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque UDA_LOG(UDA_LOG_DEBUG, "entering the provenance plugin\n"); - err = plugin_list->plugin[plugin_id].idamPlugin(&idam_plugin_interface); + err = plugin_list->plugin[plugin_id].idamPlugin(&plugin_interface); UDA_LOG(UDA_LOG_DEBUG, "returned from the provenance plugin\n"); @@ -561,7 +642,7 @@ int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUES const ENVIRONMENT* environment) { int err, reset, rc; - IDAM_PLUGIN_INTERFACE idam_plugin_interface; + UDA_PLUGIN_INTERFACE plugin_interface; // Check the Interface Compliance @@ -579,21 +660,21 @@ int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUES LOGMALLOCLIST logmalloclist; initLogMallocList(&logmalloclist); - idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.pluginVersion = 0; - idam_plugin_interface.data_block = &data_block; - idam_plugin_interface.client_block = nullptr; - idam_plugin_interface.request_data = request_block; - idam_plugin_interface.data_source = data_source; - idam_plugin_interface.signal_desc = signal_desc; - idam_plugin_interface.environment = environment; - idam_plugin_interface.housekeeping = 0; - idam_plugin_interface.changePlugin = 0; - idam_plugin_interface.pluginList = plugin_list; - idam_plugin_interface.userdefinedtypelist = &userdefinedtypelist; - idam_plugin_interface.logmalloclist = &logmalloclist; - idam_plugin_interface.error_stack.nerrors = 0; - idam_plugin_interface.error_stack.idamerror = nullptr; + plugin_interface.interfaceVersion = 1; + plugin_interface.pluginVersion = 0; + plugin_interface.data_block = &data_block; + plugin_interface.client_block = nullptr; + plugin_interface.request_data = request_block; + plugin_interface.data_source = data_source; + plugin_interface.signal_desc = signal_desc; + plugin_interface.environment = environment; + plugin_interface.housekeeping = 0; + plugin_interface.changePlugin = 0; + plugin_interface.pluginList = plugin_list; + plugin_interface.userdefinedtypelist = &userdefinedtypelist; + plugin_interface.logmalloclist = &logmalloclist; + plugin_interface.error_stack.nerrors = 0; + plugin_interface.error_stack.idamerror = nullptr; // Redirect Output to temporary file if no file handles passed @@ -604,7 +685,7 @@ int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUES // Call the plugin (Error handling is managed within) - err = plugin_list->plugin[plugin_id].idamPlugin(&idam_plugin_interface); + err = plugin_list->plugin[plugin_id].idamPlugin(&plugin_interface); // Reset Redirected Output diff --git a/source/server/serverPlugin.h b/source/server/serverPlugin.h index 333a9138..f5d183d5 100644 --- a/source/server/serverPlugin.h +++ b/source/server/serverPlugin.h @@ -1,33 +1,96 @@ #ifndef UDA_SERVER_SERVERPLUGIN_H #define UDA_SERVER_SERVERPLUGIN_H -#include "export.h" #include "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 -#ifdef __cplusplus -extern "C" { -#endif +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 +}; -LIBRARY_API void allocPluginList(int count, PLUGINLIST* plugin_list); -LIBRARY_API void freePluginList(PLUGINLIST* plugin_list); -LIBRARY_API void initPluginData(PLUGIN_DATA* plugin); -LIBRARY_API int udaServerRedirectStdStreams(int reset); -LIBRARY_API int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, +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; + DATA_BLOCK* data_block; + REQUEST_DATA* request_data; + CLIENT_BLOCK* client_block; + DATA_SOURCE* data_source; + SIGNAL_DESC* signal_desc; + const ENVIRONMENT* environment; // Server environment + LOGMALLOCLIST* logmalloclist; + USERDEFINEDTYPELIST* userdefinedtypelist; + void* sqlConnection; // Opaque structure + const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers + 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); +int udaServerRedirectStdStreams(int reset); +int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, const PLUGINLIST* plugin_list, const ENVIRONMENT* environment); -LIBRARY_API int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_request, +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); -LIBRARY_API int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* environment); -LIBRARY_API int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUEST_DATA* request_block, +int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* environment); +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); -#ifdef __cplusplus -} -#endif - #endif // UDA_SERVER_SERVERPLUGIN_H diff --git a/source/server/serverProcessing.h b/source/server/serverProcessing.h index 2b4b2c1b..d4176a11 100644 --- a/source/server/serverProcessing.h +++ b/source/server/serverProcessing.h @@ -4,7 +4,7 @@ # define UDA_SERVER_SERVERPROCESSING_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" int serverProcessing(CLIENT_BLOCK client_block, DATA_BLOCK* data_block); diff --git a/source/server/serverSubsetData.cpp b/source/server/serverSubsetData.cpp index 10f197d4..63c4cef5 100644 --- a/source/server/serverSubsetData.cpp +++ b/source/server/serverSubsetData.cpp @@ -22,7 +22,7 @@ # define strncasecmp _strnicmp #endif -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include "udaTypes.h" #include diff --git a/source/server/serverSubsetData.h b/source/server/serverSubsetData.h index 7e6873ac..6bd5c8cf 100644 --- a/source/server/serverSubsetData.h +++ b/source/server/serverSubsetData.h @@ -1,24 +1,10 @@ #pragma once -#ifndef UDA_SERVER_SERVERSUBSETDATA_H -# define UDA_SERVER_SERVERSUBSETDATA_H +#include "genStructs.h" +#include "clientserver/udaStructs.h" +#include +#include "serverPlugin.h" -# include "export.h" -# include "genStructs.h" -# include "pluginStructs.h" -# include "udaStructs.h" -# include - -# ifdef __cplusplus -extern "C" { -# endif - -LIBRARY_API int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST* logmalloclist); -LIBRARY_API int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, +int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST* logmalloclist); +int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, const PLUGINLIST* plugin_list); - -# ifdef __cplusplus -} -# endif - -#endif // UDA_SERVER_SERVERSUBSETDATA_H diff --git a/source/server/udaLegacyServer.cpp b/source/server/udaLegacyServer.cpp index a8d98691..b8e3134a 100644 --- a/source/server/udaLegacyServer.cpp +++ b/source/server/udaLegacyServer.cpp @@ -5,7 +5,7 @@ #include "udaLegacyServer.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include "udaTypes.h" #include diff --git a/source/server/udaLegacyServer.h b/source/server/udaLegacyServer.h index fa019b01..6ebf8eee 100644 --- a/source/server/udaLegacyServer.h +++ b/source/server/udaLegacyServer.h @@ -1,13 +1,11 @@ #pragma once -#ifndef UDA_SERVER_UDALEGACYSERVER_H -# define UDA_SERVER_UDALEGACYSERVER_H - -# include "export.h" -# include "genStructs.h" -# include "pluginStructs.h" -# include "udaStructs.h" -# include +#include "export.h" +#include "genStructs.h" +#include "plugins/pluginStructs.h" +#include "clientserver/udaStructs.h" +#include +#include "serverPlugin.h" /** * UDA Legacy Data Server (protocol versions <= 6) @@ -16,4 +14,3 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL USERDEFINEDTYPELIST* userdefinedtypelist, SOCKETLIST* socket_list, int protocolVersion, XDR* server_input, XDR* server_output, unsigned int private_flags, int malloc_source); -#endif // UDA_SERVER_UDALEGACYSERVER_H diff --git a/source/server/udaServer.cpp b/source/server/udaServer.cpp index 2dda093a..f7faec99 100644 --- a/source/server/udaServer.cpp +++ b/source/server/udaServer.cpp @@ -8,7 +8,7 @@ #include -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include "udaErrors.h" #include @@ -43,7 +43,18 @@ //-------------------------------------------------------------------------------------- // static globals -constexpr int server_version = 9; +// 0b FF FF FF FF +// major minor bug dirty + +// 3.0.1.15 +// 00000011 00000000 00000001 00000111 + +#define UDA_MAJOR_VERSION(X) (int)((X >> 24) & 0x000F) +#define UDA_MINOR_VERSION(X) (int)((X >> 16) & 0x000F) +#define UDA_BUGFIX_VERSION(X) (int)((X >> 8) & 0x000F) +#define UDA_DELTA_VERSION(X) (int)((X >> 0) & 0x000F) + +constexpr int SERVER_VERSION = 9; static int protocol_version = 9; static int legacy_server_version = 6; @@ -56,7 +67,7 @@ USERDEFINEDTYPELIST parsed_user_defined_type_list; // Initial set of User Define // Total amount sent for the last data request -static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) +static 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; @@ -69,38 +80,39 @@ typedef struct MetadataBlock { DATA_SYSTEM data_system; } METADATA_BLOCK; -static int startupServer(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, IoData* io_data); -static int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, +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, DATA_BLOCK_LIST* data_block_list, int* fatal, int* server_closedown, uda::cache::UdaCache* cache, LOGSTRUCTLIST* log_struct_list, XDR* server_input, const unsigned int* total_datablock_size, int server_tot_block_time, int* server_timeout); -static int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, +static int do_server_loop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, METADATA_BLOCK* metadata_block, ACTIONS* actions_desc, ACTIONS* actions_sig, int* fatal, uda::cache::UdaCache* cache, LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output, unsigned int* total_datablock_size, int server_tot_block_time, int* server_timeout); -static int reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, - int trap1Err, METADATA_BLOCK* metadata_block, LOGSTRUCTLIST* log_struct_list, - XDR* server_input, XDR* server_output, unsigned int* total_datablock_size); +static int +report_to_client(SERVER_BLOCK *server_block, DATA_BLOCK_LIST *data_block_list, CLIENT_BLOCK *client_block, int trap1Err, + METADATA_BLOCK *metadata_block, LOGSTRUCTLIST *log_struct_list, XDR *server_output, + unsigned int *total_datablock_size); -static int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, +static int do_server_closedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, int server_tot_block_time, int server_timeout); #ifdef SECURITYENABLED static int authenticateClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block); #else -static int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* server_closedown, +static int handshake_client(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* server_closedown, LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output); #endif //-------------------------------------------------------------------------------------- // Server Entry point -int udaServer(CLIENT_BLOCK client_block) +int uda_server(CLIENT_BLOCK client_block) { int err = 0; METADATA_BLOCK metadata_block; @@ -130,7 +142,7 @@ int udaServer(CLIENT_BLOCK client_block) // Reinitialised after each logging action initUdaErrorStack(); - initServerBlock(&server_block, server_version); + initServerBlock(&server_block, SERVER_VERSION); initActions(&actions_desc); // There may be a Sequence of Actions to Apply initActions(&actions_sig); initRequestBlock(&request_block); @@ -139,7 +151,7 @@ int udaServer(CLIENT_BLOCK client_block) static unsigned int total_datablock_size = 0; - if ((err = startupServer(&server_block, server_input, server_output, &io_data)) != 0) { + if ((err = startup_server(&server_block, server_input, server_output, &io_data)) != 0) { return err; } @@ -148,7 +160,7 @@ int udaServer(CLIENT_BLOCK client_block) #else int server_closedown = 0; err = - handshakeClient(&client_block, &server_block, &server_closedown, &log_struct_list, server_input, server_output); + handshake_client(&client_block, &server_block, &server_closedown, &log_struct_list, server_input, server_output); #endif DATA_BLOCK_LIST data_block_list; @@ -157,19 +169,20 @@ int udaServer(CLIENT_BLOCK client_block) if (!err && !server_closedown) { int fatal = 0; - doServerLoop(&request_block, &data_block_list, &client_block, &server_block, &metadata_block, &actions_desc, + do_server_loop(&request_block, &data_block_list, &client_block, &server_block, &metadata_block, &actions_desc, &actions_sig, &fatal, cache, &log_struct_list, server_input, server_output, &total_datablock_size, server_tot_block_time, &server_timeout); } - err = doServerClosedown(&client_block, &request_block, &data_block_list, server_tot_block_time, server_timeout); + err = do_server_closedown(&client_block, &request_block, &data_block_list, server_tot_block_time, server_timeout); return err; } -int reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, - int trap1Err, METADATA_BLOCK* metadata_block, LOGSTRUCTLIST* log_struct_list, XDR* server_input, - XDR* server_output, unsigned int* total_datablock_size) +int +report_to_client(SERVER_BLOCK *server_block, DATA_BLOCK_LIST *data_block_list, CLIENT_BLOCK *client_block, int trap1Err, + METADATA_BLOCK *metadata_block, LOGSTRUCTLIST *log_struct_list, XDR *server_output, + unsigned int *total_datablock_size) { //---------------------------------------------------------------------------- // Gather Server Error State @@ -365,7 +378,7 @@ int reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, return err; } -int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, +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, DATA_BLOCK_LIST* data_block_list, int* fatal, int* server_closedown, uda::cache::UdaCache* cache, LOGSTRUCTLIST* log_struct_list, XDR* server_input, const unsigned int* total_datablock_size, @@ -420,8 +433,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV // This defines the set of elements within data structures passed between client and server // Must be the same on both sides of the socket - protocol_version = server_version; - if (client_block->version < server_version) { + protocol_version = SERVER_VERSION; + if (client_block->version < SERVER_VERSION) { protocol_version = client_block->version; } @@ -446,7 +459,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV // Test the client version is compatible with this server version - if (protocol_version > server_version) { + if (protocol_version > SERVER_VERSION) { UDA_THROW_ERROR(999, "Protocol Error: Client API Version is Newer than the Server Version"); } @@ -710,7 +723,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV for (int i = 0; i < request_block->num_requests; ++i) { auto request = &request_block->requests[i]; if (protocol_version >= 6) { - if ((err = udaServerPlugin(request, &metadata_block->data_source, &metadata_block->signal_desc, &pluginList, + if ((err = udaServerPlugin(request, &metadata_block->data_source, &metadata_block->signal_desc, &plugin_list, getServerEnvironment())) != 0) { return err; } @@ -741,7 +754,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV int depth = 0; err = udaGetData(&depth, request, *client_block, data_block, &metadata_block->data_source, &metadata_block->signal_rec, &metadata_block->signal_desc, actions_desc, actions_sig, - &pluginList, log_malloc_list, user_defined_type_list, &socket_list, protocol_version); + &plugin_list, log_malloc_list, user_defined_type_list, &socket_list, protocol_version); cache_write(cache, request, data_block, log_malloc_list, user_defined_type_list, environment, 8, CLIENTFLAG_CACHE, log_struct_list, private_flags, malloc_source); @@ -827,7 +840,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV return err; } -int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, +int do_server_loop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, METADATA_BLOCK* metadata_block, ACTIONS* actions_desc, ACTIONS* actions_sig, int* fatal, uda::cache::UdaCache* cache, LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output, unsigned int* total_datablock_size, int server_tot_block_time, @@ -851,7 +864,7 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, initLogMallocList(log_malloc_list); int server_closedown = 0; - err = handleRequest(request_block, client_block, server_block, metadata_block, actions_desc, actions_sig, + err = handle_request(request_block, client_block, server_block, metadata_block, actions_desc, actions_sig, data_block_list, fatal, &server_closedown, cache, log_struct_list, server_input, total_datablock_size, server_tot_block_time, server_timeout); @@ -861,8 +874,8 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, UDA_LOG(UDA_LOG_DEBUG, "Handle Request Error: %d [%d]\n", err, *fatal); - err = reportToClient(server_block, data_block_list, client_block, err, metadata_block, log_struct_list, - server_input, server_output, total_datablock_size); + err = report_to_client(server_block, data_block_list, client_block, err, metadata_block, log_struct_list, + server_output, total_datablock_size); UDA_LOG(UDA_LOG_DEBUG, "Data structures sent to client\n"); UDA_LOG(UDA_LOG_DEBUG, "Report To Client Error: %d [%d]\n", err, *fatal); @@ -911,7 +924,7 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, closeUdaError(); UDA_LOG(UDA_LOG_DEBUG, "initServerBlock\n"); - initServerBlock(server_block, server_version); + initServerBlock(server_block, SERVER_VERSION); //---------------------------------------------------------------------------- // Server Wait Loop @@ -921,7 +934,7 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, return err; } -int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, +int do_server_closedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, int server_tot_block_time, int server_timeout) { //---------------------------------------------------------------------------- @@ -951,7 +964,7 @@ int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, //---------------------------------------------------------------------------- // Free Plugin List and Close all open library entries - freePluginList(&pluginList); + freePluginList(&plugin_list); freeMallocLogList(log_malloc_list); free(log_malloc_list); @@ -1032,7 +1045,7 @@ int authenticateClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block) } #endif -int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* server_closedown, +int handshake_client(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* server_closedown, LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output) { // Exchange version details - once only @@ -1110,14 +1123,14 @@ int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* if (client_block->version <= legacy_server_version) { UDA_LOG(UDA_LOG_DEBUG, "Diverting to the Legacy Server\n"); UDA_LOG(UDA_LOG_DEBUG, "Client protocol %d\n", client_block->version); - return legacyServer(*client_block, &pluginList, log_malloc_list, user_defined_type_list, &socket_list, + return legacyServer(*client_block, &plugin_list, log_malloc_list, user_defined_type_list, &socket_list, protocol_version, server_input, server_output, 0, malloc_source); } return err; } -int startupServer(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, IoData* io_data) { static int socket_list_initialised = 0; static int plugin_list_initialised = 0; @@ -1194,13 +1207,13 @@ int startupServer(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_o // Initialise the Data Reader Plugin list if (!plugin_list_initialised) { - pluginList.count = 0; - initPluginList(&pluginList, getServerEnvironment()); + plugin_list.count = 0; + initPluginList(&plugin_list, getServerEnvironment()); plugin_list_initialised = 1; UDA_LOG(UDA_LOG_INFO, "List of Plugins available\n"); - for (int i = 0; i < pluginList.count; i++) { - UDA_LOG(UDA_LOG_INFO, "[%d] %d %s\n", i, pluginList.plugin[i].request, pluginList.plugin[i].format); + for (int i = 0; i < plugin_list.count; i++) { + UDA_LOG(UDA_LOG_INFO, "[%d] %d %s\n", i, plugin_list.plugin[i].request, plugin_list.plugin[i].format); } } diff --git a/source/server/udaServer.h b/source/server/udaServer.h index f73737a5..48f222c6 100644 --- a/source/server/udaServer.h +++ b/source/server/udaServer.h @@ -1,16 +1,12 @@ #pragma once -#ifndef UDA_SERVER_UDASERVER_H -# define UDA_SERVER_UDASERVER_H - # include "export.h" # include "genStructs.h" -# include "pluginStructs.h" +# include "plugins/pluginStructs.h" # include -LIBRARY_API int udaServer(CLIENT_BLOCK client_block); +int uda_server(CLIENT_BLOCK client_block); -LIBRARY_API int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, +int fat_server(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, DATA_BLOCK_LIST* data_blocks0); -#endif // UDA_SERVER_UDASERVER_H diff --git a/source/server2/apply_XML.hpp b/source/server2/apply_XML.hpp index b11124e0..19c26fdb 100755 --- a/source/server2/apply_XML.hpp +++ b/source/server2/apply_XML.hpp @@ -4,7 +4,7 @@ #define UDA_SERVER_APPLYXML_H #include -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "export.h" namespace uda { diff --git a/source/server2/get_data.cpp b/source/server2/get_data.cpp index 075d830f..5bd8c9e1 100644 --- a/source/server2/get_data.cpp +++ b/source/server2/get_data.cpp @@ -4,7 +4,7 @@ #include "clientserver/nameValueSubstitution.h" #include "clientserver/printStructs.h" #include "clientserver/stringUtils.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "make_server_request_block.hpp" #include "server_plugin.h" @@ -1082,7 +1082,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) // Test for known File formats and Server protocols { - IDAM_PLUGIN_INTERFACE plugin_interface; + UDA_PLUGIN_INTERFACE plugin_interface; UDA_LOG(UDA_LOG_DEBUG, "creating the plugin interface structure\n"); diff --git a/source/server2/get_data.hpp b/source/server2/get_data.hpp index 19df932c..cbeec8be 100644 --- a/source/server2/get_data.hpp +++ b/source/server2/get_data.hpp @@ -3,7 +3,7 @@ #ifndef UDA_SERVER_GET_DATA_HPP #define UDA_SERVER_GET_DATA_HPP -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "clientserver/parseXML.h" #include "plugins.hpp" diff --git a/source/server2/get_plugin_address.cpp b/source/server2/get_plugin_address.cpp index c7bc1d36..ced8fd33 100644 --- a/source/server2/get_plugin_address.cpp +++ b/source/server2/get_plugin_address.cpp @@ -53,7 +53,7 @@ int uda::get_plugin_address(void** pluginHandle, const char* library, const char // Find the address of the required plugin function - int (*fptr)(IDAM_PLUGIN_INTERFACE*); + int (*fptr)(UDA_PLUGIN_INTERFACE*); *(void**)(&fptr) = dlsym(*pluginHandle, symbol); char* errstr = dlerror(); diff --git a/source/server2/get_plugin_address.hpp b/source/server2/get_plugin_address.hpp index 712b3481..bffd8f5c 100755 --- a/source/server2/get_plugin_address.hpp +++ b/source/server2/get_plugin_address.hpp @@ -1,15 +1,11 @@ #pragma once -#ifndef UDA_GETPLUGIN_ADDRESS_HPP -#define UDA_GETPLUGIN_ADDRESS_HPP - #include "udaPlugin.h" -#include "export.h" + +typedef int (*PLUGINFUNP)(UDA_PLUGIN_INTERFACE*); // Plugin function type namespace uda { int get_plugin_address(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp); } - -#endif // UDA_GETPLUGIN_ADDRESS_HPP diff --git a/source/server2/make_server_request_block.cpp b/source/server2/make_server_request_block.cpp index dcd2b31d..37254c96 100644 --- a/source/server2/make_server_request_block.cpp +++ b/source/server2/make_server_request_block.cpp @@ -1,6 +1,6 @@ #include "make_server_request_block.hpp" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include #include "plugins.hpp" @@ -12,14 +12,14 @@ int uda::makeServerRequestBlock(RequestBlock* request_block, const uda::Plugins& const server::Environment& environment) { auto plugin_list = plugins.as_plugin_list(); - return make_request_block(request_block, plugin_list, environment.p_env()); + return make_request_block(request_block, &plugin_list, environment.p_env()); } int uda::makeServerRequestData(RequestData* request, const uda::Plugins& plugins, const server::Environment& environment) { auto plugin_list = plugins.as_plugin_list(); - return makeRequestData(request, plugin_list, environment.p_env()); + return makeRequestData(request, &plugin_list, environment.p_env()); } #endif diff --git a/source/server2/make_server_request_block.hpp b/source/server2/make_server_request_block.hpp index e554c371..9466400a 100755 --- a/source/server2/make_server_request_block.hpp +++ b/source/server2/make_server_request_block.hpp @@ -4,7 +4,7 @@ #define UDA_SERVER_MAKESERVERREQUESTBLOCK_HPP #include "udaPlugin.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "export.h" #include "plugins.hpp" diff --git a/source/server2/plugins.cpp b/source/server2/plugins.cpp index 7507bf75..d7277bbf 100644 --- a/source/server2/plugins.cpp +++ b/source/server2/plugins.cpp @@ -17,7 +17,7 @@ namespace { -void init_plugin_data(PLUGIN_DATA* plugin) +void init_plugin_data(PluginData* plugin) { plugin->format[0] = '\0'; plugin->library[0] = '\0'; diff --git a/source/server2/plugins.hpp b/source/server2/plugins.hpp index 6fc66751..439e8233 100644 --- a/source/server2/plugins.hpp +++ b/source/server2/plugins.hpp @@ -6,7 +6,49 @@ #include #include -#include "pluginStructs.h" +#include "udaDefines.h" +#include "udaPlugin.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 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; namespace uda { @@ -16,7 +58,7 @@ class Plugins { void close(); - [[nodiscard]] PluginList as_plugin_list() const; + [[nodiscard]] PLUGINLIST as_plugin_list() const; [[nodiscard]] boost::optional find_by_format(const char* format) const; [[nodiscard]] boost::optional find_by_request(int request) const; diff --git a/source/server2/server.cpp b/source/server2/server.cpp index 278d5dce..de6d7eb5 100644 --- a/source/server2/server.cpp +++ b/source/server2/server.cpp @@ -8,7 +8,7 @@ #include "clientserver/printStructs.h" #include "clientserver/protocol.h" #include "clientserver/xdrlib.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/accessLog.h" #include "logging/logging.h" #include "server_environment.hpp" diff --git a/source/server2/server_environment.hpp b/source/server2/server_environment.hpp index 747b4ba9..1721b3bc 100755 --- a/source/server2/server_environment.hpp +++ b/source/server2/server_environment.hpp @@ -3,7 +3,7 @@ #ifndef UDA_SERVER_GETSERVERENVIRONMENT_HPP #define UDA_SERVER_GETSERVERENVIRONMENT_HPP -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "export.h" namespace uda { diff --git a/source/server2/server_plugin.cpp b/source/server2/server_plugin.cpp index 0bf7bab7..9610604c 100644 --- a/source/server2/server_plugin.cpp +++ b/source/server2/server_plugin.cpp @@ -18,7 +18,7 @@ # define dup2 _dup2 #endif -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "logging/logging.h" #include "struct.h" #include @@ -178,7 +178,8 @@ int uda::serverPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DE //---------------------------------------------------------------------------------------------- // Decode the API Arguments: determine appropriate data reader plug-in - if ((err = makeRequestData(request, plugins.as_plugin_list(), environment)) != 0) { + auto plugin_list = plugins.as_plugin_list(); + if ((err = makeRequestData(request, &plugin_list, environment)) != 0) { return err; } @@ -318,11 +319,12 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque UDA_LOG(UDA_LOG_DEBUG, "Provenance Plugin signal: %s\n", request.signal); - makeRequestData(&request, plugins.as_plugin_list(), environment.p_env()); + auto plugin_list = plugins.as_plugin_list(); + makeRequestData(&request, &plugin_list, environment.p_env()); int err, rc, reset; DataBlock data_block = {}; - IdamPluginInterface plugin_interface = {}; + UdaPluginInterface plugin_interface = {}; // Initialise the Data Block @@ -342,7 +344,6 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque LOGMALLOCLIST logmalloclist; initLogMallocList(&logmalloclist); - auto plugin_list = plugins.as_plugin_list(); plugin_interface.interfaceVersion = 1; plugin_interface.pluginVersion = 0; plugin_interface.data_block = &data_block; @@ -473,7 +474,7 @@ int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_blo uda::MetadataBlock& metadata) { int err, reset, rc; - IdamPluginInterface idam_plugin_interface = {}; + UdaPluginInterface plugin_interface = {}; // Check the Interface Compliance @@ -492,21 +493,21 @@ int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_blo initLogMallocList(&logmalloclist); auto plugin_list = plugins.as_plugin_list(); - idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.pluginVersion = 0; - idam_plugin_interface.data_block = &data_block; - idam_plugin_interface.client_block = nullptr; - idam_plugin_interface.request_data = request_block; - idam_plugin_interface.data_source = &metadata.data_source; - idam_plugin_interface.signal_desc = &metadata.signal_desc; - idam_plugin_interface.environment = environment.p_env(); - idam_plugin_interface.housekeeping = 0; - idam_plugin_interface.changePlugin = 0; - idam_plugin_interface.pluginList = &plugin_list; - idam_plugin_interface.userdefinedtypelist = &userdefinedtypelist; - idam_plugin_interface.logmalloclist = &logmalloclist; - idam_plugin_interface.error_stack.nerrors = 0; - idam_plugin_interface.error_stack.idamerror = nullptr; + plugin_interface.interfaceVersion = 1; + plugin_interface.pluginVersion = 0; + plugin_interface.data_block = &data_block; + plugin_interface.client_block = nullptr; + plugin_interface.request_data = request_block; + plugin_interface.data_source = &metadata.data_source; + plugin_interface.signal_desc = &metadata.signal_desc; + plugin_interface.environment = environment.p_env(); + plugin_interface.housekeeping = 0; + plugin_interface.changePlugin = 0; + plugin_interface.pluginList = &plugin_list; + plugin_interface.userdefinedtypelist = &userdefinedtypelist; + plugin_interface.logmalloclist = &logmalloclist; + plugin_interface.error_stack.nerrors = 0; + plugin_interface.error_stack.idamerror = nullptr; // Redirect Output to temporary file if no file handles passed @@ -517,7 +518,7 @@ int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_blo // Call the plugin (Error handling is managed within) - err = plugin.idamPlugin(&idam_plugin_interface); + err = plugin.idamPlugin(&plugin_interface); // Reset Redirected Output diff --git a/source/server2/server_plugin.h b/source/server2/server_plugin.h index 98703e32..735866c9 100644 --- a/source/server2/server_plugin.h +++ b/source/server2/server_plugin.h @@ -10,6 +10,28 @@ #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 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; + DATA_BLOCK* data_block; + REQUEST_DATA* request_data; + CLIENT_BLOCK* client_block; + DATA_SOURCE* data_source; + SIGNAL_DESC* signal_desc; + const ENVIRONMENT* environment; // Server environment + LOGMALLOCLIST* logmalloclist; + USERDEFINEDTYPELIST* userdefinedtypelist; + void* sqlConnection; // Opaque structure + const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers + UDA_ERROR_STACK error_stack; +} UDA_PLUGIN_INTERFACE; + namespace uda { diff --git a/source/server2/server_processing.h b/source/server2/server_processing.h index 188b0bfc..6d200309 100644 --- a/source/server2/server_processing.h +++ b/source/server2/server_processing.h @@ -4,7 +4,7 @@ # define UDA_SERVER_SERVERPROCESSING_H # include "export.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" namespace uda { diff --git a/source/server2/server_subset_data.cpp b/source/server2/server_subset_data.cpp index 460f47f0..42dce29e 100644 --- a/source/server2/server_subset_data.cpp +++ b/source/server2/server_subset_data.cpp @@ -17,7 +17,7 @@ # define strncasecmp _strnicmp #endif -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "struct.h" #include "udaTypes.h" #include diff --git a/source/server2/server_subset_data.h b/source/server2/server_subset_data.h index 12c004a8..b65d374e 100644 --- a/source/server2/server_subset_data.h +++ b/source/server2/server_subset_data.h @@ -5,7 +5,7 @@ # include "export.h" # include "genStructs.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" # include namespace uda diff --git a/source/server2/xdr_protocol.hpp b/source/server2/xdr_protocol.hpp index d1956c61..751d4f31 100644 --- a/source/server2/xdr_protocol.hpp +++ b/source/server2/xdr_protocol.hpp @@ -7,7 +7,7 @@ #include #include "udaDefines.h" -#include "udaStructs.h" +#include "clientserver/udaStructs.h" #include "genStructs.h" #include "cache/memcache.hpp" #include "server_environment.hpp" diff --git a/source/uda.h b/source/uda.h index cefcfb65..d5939dbd 100644 --- a/source/uda.h +++ b/source/uda.h @@ -8,12 +8,12 @@ # include "clientAPI.h" # include "clientMDS.h" # include "genStructs.h" -# include "initStructs.h" +# include "clientserver/initStructs.h" # include "struct.h" # include "udaGetAPI.h" # include "udaPlugin.h" # include "udaPutAPI.h" -# include "udaStructs.h" +# include "clientserver/udaStructs.h" # include "udaTypes.h" # include "version.h" diff --git a/source/wrappers/c++/client.cpp b/source/wrappers/c++/client.cpp index e3d40c27..1fce64b1 100644 --- a/source/wrappers/c++/client.cpp +++ b/source/wrappers/c++/client.cpp @@ -6,7 +6,7 @@ #include "accAPI.h" #include "client.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include "udaGetAPI.h" #include "udaPutAPI.h" #include "udaTypes.h" @@ -74,8 +74,7 @@ void uda::Client::setProperty(Property prop, bool value) throw UDAException("Unknown property"); } - CLIENT_FLAGS* client_flags = udaClientFlags(); - value ? setIdamProperty(name.c_str(), client_flags) : resetIdamProperty(name.c_str(), client_flags); + value ? setIdamProperty(name.c_str()) : resetIdamProperty(name.c_str()); } void uda::Client::setProperty(Property prop, int value) @@ -102,11 +101,11 @@ void uda::Client::setProperty(Property prop, int value) case PROP_TIMEOUT: name = (boost::format("timeout=%1%") % value).str(); - setIdamProperty(name.c_str(), udaClientFlags()); + setIdamProperty(name.c_str()); break; case PROP_ALTRANK: name = (boost::format("altrank=%1%") % value).str(); - setIdamProperty(name.c_str(), udaClientFlags()); + setIdamProperty(name.c_str()); break; default: @@ -121,42 +120,41 @@ void uda::Client::close() int uda::Client::property(Property prop) { - auto client_flags = udaClientFlags(); switch (prop) { case PROP_DATADBLE: - return getIdamProperty("get_datadble", client_flags); + return getIdamProperty("get_datadble"); case PROP_DIMDBLE: - return getIdamProperty("get_dimdble", client_flags); + return getIdamProperty("get_dimdble"); case PROP_TIMEDBLE: - return getIdamProperty("get_timedble", client_flags); + return getIdamProperty("get_timedble"); case PROP_BYTES: - return getIdamProperty("get_bytes", client_flags); + return getIdamProperty("get_bytes"); case PROP_BAD: - return getIdamProperty("get_bad", client_flags); + return getIdamProperty("get_bad"); case PROP_META: - return getIdamProperty("get_meta", client_flags); + return getIdamProperty("get_meta"); case PROP_ASIS: - return getIdamProperty("get_asis", client_flags); + return getIdamProperty("get_asis"); case PROP_UNCAL: - return getIdamProperty("get_uncal", client_flags); + return getIdamProperty("get_uncal"); case PROP_NOTOFF: - return getIdamProperty("get_notoff", client_flags); + return getIdamProperty("get_notoff"); case PROP_SYNTHETIC: - return getIdamProperty("get_synthetic", client_flags); + return getIdamProperty("get_synthetic"); case PROP_SCALAR: - return getIdamProperty("get_scalar", client_flags); + return getIdamProperty("get_scalar"); case PROP_NODIMDATA: - return getIdamProperty("get_nodimdata", client_flags); + return getIdamProperty("get_nodimdata"); case PROP_VERBOSE: - return getIdamProperty("verbose", client_flags); + return getIdamProperty("verbose"); case PROP_DEBUG: - return getIdamProperty("debug", client_flags); + return getIdamProperty("debug"); case PROP_ALTDATA: - return getIdamProperty("altdata", client_flags); + return getIdamProperty("altdata"); case PROP_TIMEOUT: - return getIdamProperty("timeout", client_flags); + return getIdamProperty("timeout"); case PROP_ALTRANK: - return getIdamProperty("altrank", client_flags); + return getIdamProperty("altrank"); default: throw UDAException("Unknown property"); @@ -185,15 +183,15 @@ int uda::Client::serverPort() [[noreturn]] void generate_exception() { - UDA_ERROR_STACK* errorstack = getUdaServerErrorStack(); + int num_errors = udaNumErrors(); std::vector backtrace; - int code = errorstack->nerrors > 0 ? errorstack->idamerror[0].code : 0; - std::string msg = errorstack->nerrors > 0 ? errorstack->idamerror[0].msg : ""; + int code = num_errors > 0 ? udaGetErrorCode(0) : 0; + std::string msg = num_errors > 0 ? udaGetErrorMessage(0) : ""; - backtrace.reserve(errorstack->nerrors); - for (unsigned int i = 0; i < errorstack->nerrors; ++i) { - backtrace.push_back(std::string("[") + errorstack->idamerror[i].location + - "]: " + errorstack->idamerror[i].msg); + backtrace.reserve(num_errors); + for (int i = 0; i < num_errors; ++i) { + backtrace.push_back(std::string("[") + udaGetErrorLocation(i) + + "]: " + udaGetErrorMessage(i)); } if ((code > 0 && code < 25) || (code > 60 && code < 66)) { diff --git a/source/wrappers/c++/result.cpp b/source/wrappers/c++/result.cpp index 79adba61..659311a1 100644 --- a/source/wrappers/c++/result.cpp +++ b/source/wrappers/c++/result.cpp @@ -71,18 +71,19 @@ uda::Result::Result(int handle) rank_(handle >= 0 ? static_cast(getIdamRank(handle)) : 0), size_(handle >= 0 ? static_cast(getIdamDataNum(handle)) : 0) { - if (handle >= 0 && (bool)getIdamProperties(handle)->get_meta) { - SIGNAL_DESC* signal_desc = getIdamSignalDesc(handle); - meta_["signal_name"] = signal_desc->signal_name; - meta_["signal_alias"] = signal_desc->signal_alias; - - DATA_SOURCE* source = getIdamDataSource(handle); - meta_["path"] = source->path; - meta_["filename"] = source->filename; - meta_["format"] = source->format; - meta_["exp_number"] = std::to_string(source->exp_number); - meta_["pass"] = std::to_string(source->pass); - meta_["pass_date"] = source->pass_date; + if (handle >= 0 && (bool)getIdamProperty("get_meta")) { + // TODO: fix reading all meta fields +// SIGNAL_DESC* signal_desc = getIdamSignalDesc(handle); +// meta_["signal_name"] = signal_desc->signal_name; +// meta_["signal_alias"] = signal_desc->signal_alias; +// +// DATA_SOURCE* source = getIdamDataSource(handle); +// meta_["path"] = source->path; +// meta_["filename"] = source->filename; +// meta_["format"] = source->format; +// meta_["exp_number"] = std::to_string(source->exp_number); +// meta_["pass"] = std::to_string(source->pass); +// meta_["pass_date"] = source->pass_date; } istree_ = (setIdamDataTree(handle) != 0); } diff --git a/test/plugins/test2_testplugin.cpp b/test/plugins/test2_testplugin.cpp index 39e98381..b2823947 100755 --- a/test/plugins/test2_testplugin.cpp +++ b/test/plugins/test2_testplugin.cpp @@ -2,7 +2,7 @@ #include "catch.hpp" #include "udaTypes.h" -#include "initStructs.h" +#include "clientserver/initStructs.h" #include #include #include "struct.h"