diff --git a/.clang-format b/.clang-format index 153b9d47..fd792480 100644 --- a/.clang-format +++ b/.clang-format @@ -5,4 +5,10 @@ IndentWidth: 4 DerivePointerAlignment: false PointerAlignment: Left ColumnLimit: 120 -IndentCaseLabels: true \ No newline at end of file +IndentCaseLabels: true +AllowShortBlocksOnASingleLine: Empty +Cpp11BracedListStyle: true +InsertBraces: true +AllowShortFunctionsOnASingleLine: Inline +IndentPPDirectives: AfterHash +PPIndentWidth: 2 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 42748e6f..972b4443 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -158,6 +158,8 @@ endif() ######################################################################################################################## # Build options +include( StaticAnalyzers ) + option( CLIENT_ONLY "Only build UDA client" OFF ) option( SERVER_ONLY "Only build UDA server" OFF ) option( BUILD_SHARED_LIBS "Build shared libraries" OFF ) diff --git a/source/authentication/udaClientSSL.cpp b/source/authentication/udaClientSSL.cpp old mode 100755 new mode 100644 index f92bd978..387b43b9 --- a/source/authentication/udaClientSSL.cpp +++ b/source/authentication/udaClientSSL.cpp @@ -1,22 +1,22 @@ #if defined(SSLAUTHENTICATION) && !defined(SERVERBUILD) && !defined(FATCLIENT) -#include "udaClientSSL.h" +# include "udaClientSSL.h" -#include -#include -#include -#include +# include +# include +# include +# include -#include -#include -#include -#include +# include +# include +# include +# include -static bool g_sslDisabled = true; // Default state is not SSL authentication -static int g_sslProtocol = 0; // The default server host name has the SSL protocol name prefix or +static bool g_sslDisabled = true; // Default state is not SSL authentication +static int g_sslProtocol = 0; // The default server host name has the SSL protocol name prefix or static int g_sslSocket = -1; -static bool g_sslOK = false; // SSL Authentication has been passed sucessfully: default is NOT Passed -static bool g_sslInit = false; // Global initialisation of SSL completed +static bool g_sslOK = false; // SSL Authentication has been passed sucessfully: default is NOT Passed +static bool g_sslInit = false; // Global initialisation of SSL completed static SSL* g_ssl = nullptr; static SSL_CTX* g_ctx = nullptr; static const HostData* g_host = nullptr; @@ -44,7 +44,7 @@ void putUdaClientSSLSocket(int s) static void init_ssl_library() { if (g_sslInit) { - return; // Already initialised + return; // Already initialised } if (getenv("UDA_SSL_INITIALISED")) { g_sslInit = true; @@ -54,13 +54,13 @@ static void init_ssl_library() SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); -#ifdef _WIN32 +# ifdef _WIN32 if (getenv("UDA_SSL_INITIALISED") == nullptr) { _putenv_s("UDA_SSL_INITIALISED", "1"); } -#else +# else setenv("UDA_SSL_INITIALISED", "1", 0); -#endif +# endif g_sslInit = true; UDA_LOG(UDA_LOG_DEBUG, "SSL initialised\n"); } @@ -87,11 +87,11 @@ void closeUdaClientSSL() EVP_cleanup(); g_ssl = nullptr; g_ctx = nullptr; -#ifdef _WIN32 +# ifdef _WIN32 _putenv_s("UDA_SSL_INITIALISED", nullptr); -#else +# else unsetenv("UDA_SSL_INITIALISED"); -#endif +# endif g_sslInit = false; UDA_LOG(UDA_LOG_DEBUG, "SSL closed\n"); } @@ -159,17 +159,17 @@ SSL_CTX* createUdaClientSSLContext() return nullptr; } - // Disable SSLv2 for v3 and TSLv1 negotiation + // Disable SSLv2 for v3 and TSLv1 negotiation SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2); -/* -// Set the Cipher List - if (SSL_CTX_set_cipher_list(g_ctx, "AES128-SHA") <= 0) { - printf("Error setting the cipher list.\n"); - exit(0); - } -*/ + /* + // Set the Cipher List + if (SSL_CTX_set_cipher_list(g_ctx, "AES128-SHA") <= 0) { + printf("Error setting the cipher list.\n"); + exit(0); + } + */ UDA_LOG(UDA_LOG_DEBUG, "SSL Context created\n"); @@ -178,7 +178,7 @@ SSL_CTX* createUdaClientSSLContext() int configureUdaClientSSLContext(const HostData* host) { - //SSL_CTX_set_ecdh_auto(g_ctx, 1); + // SSL_CTX_set_ecdh_auto(g_ctx, 1); // Set the key and cert - these take priority over entries in the host configuration file @@ -309,7 +309,7 @@ int configureUdaClientSSLContext(const HostData* host) } work[count] = '\0'; UDA_LOG(UDA_LOG_DEBUG, "Client X509 not after : %s\n", work); - if ((rc = X509_cmp_time(after, ¤t_time)) <= 0) {// Not After is before Now! + if ((rc = X509_cmp_time(after, ¤t_time)) <= 0) { // Not After is before Now! X509_free(clientCert); UDA_LOG(UDA_LOG_DEBUG, "Current Time : %s\n", c_time_string); UDA_LOG(UDA_LOG_DEBUG, "Client X509 not after date is after the current date!\n"); @@ -411,8 +411,7 @@ int startUdaClientSSL() UDA_LOG(UDA_LOG_DEBUG, "Server certificate verified\n"); UDA_LOG(UDA_LOG_DEBUG, "X509 subject: %s\n", X509_NAME_oneline(X509_get_subject_name(peer), work, sizeof(work))); - UDA_LOG(UDA_LOG_DEBUG, "X509 issuer: %s\n", - X509_NAME_oneline(X509_get_issuer_name(peer), work, sizeof(work))); + UDA_LOG(UDA_LOG_DEBUG, "X509 issuer: %s\n", X509_NAME_oneline(X509_get_issuer_name(peer), work, sizeof(work))); // Verify Date validity @@ -430,7 +429,7 @@ int startUdaClientSSL() } work[count] = '\0'; UDA_LOG(UDA_LOG_DEBUG, "Server X509 not before: %s\n", work); - if ((rc = X509_cmp_time(before, ¤t_time)) >= 0) {// Not Before is after Now! + if ((rc = X509_cmp_time(before, ¤t_time)) >= 0) { // Not Before is after Now! X509_free(peer); UDA_LOG(UDA_LOG_DEBUG, "Current Time : %s\n", c_time_string); UDA_LOG(UDA_LOG_DEBUG, "Server X509 not before date is before the current date!\n"); @@ -447,7 +446,7 @@ int startUdaClientSSL() } work[count] = '\0'; UDA_LOG(UDA_LOG_DEBUG, "Server X509 not after : %s\n", work); - if ((rc = X509_cmp_time(after, ¤t_time)) <= 0) {// Not After is before Now! + if ((rc = X509_cmp_time(after, ¤t_time)) <= 0) { // Not After is before Now! X509_free(peer); UDA_LOG(UDA_LOG_DEBUG, "Current Time : %s\n", c_time_string); UDA_LOG(UDA_LOG_DEBUG, "Server X509 not after date is after the current date!\n"); @@ -485,7 +484,7 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) int rc, err = 0; - fd_set wfds; // File Descriptor Set for Writing to the Socket + fd_set wfds; // File Descriptor Set for Writing to the Socket struct timeval tv; // Block till it's possible to write to the socket or timeout @@ -493,7 +492,7 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) udaUpdateSelectParms(g_sslSocket, &wfds, &tv); while ((rc = select(g_sslSocket + 1, nullptr, &wfds, nullptr, &tv)) <= 0) { - if (rc < 0) { // Error + if (rc < 0) { // Error if (errno == EBADF) { UDA_LOG(UDA_LOG_DEBUG, "Socket is closed! Data access failed!.\n"); } else { @@ -502,7 +501,7 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) return -1; } -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if ((rc = fcntl(g_sslSocket, F_GETFL, &fopts)) < 0 || errno == EBADF) { // Is the socket closed? Check status flags @@ -510,7 +509,7 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) UDA_LOG(UDA_LOG_DEBUG, "Socket is closed!\n"); return -1; } -#endif +# endif udaUpdateSelectParms(g_sslSocket, &wfds, &tv); } @@ -521,7 +520,7 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) switch (SSL_get_error(getUdaClientSSL(), rc)) { case SSL_ERROR_NONE: - if (rc != count) { // Check the write is complete + if (rc != count) { // Check the write is complete err = 999; UDA_LOG(UDA_LOG_DEBUG, "Incomplete write to socket!\n"); addIdamError(UDA_CODE_ERROR_TYPE, "writeUdaClientSSL", err, "Incomplete write to socket!"); @@ -534,13 +533,13 @@ int writeUdaClientSSL(void* iohandle, char* buf, int count) err = 999; UDA_LOG(UDA_LOG_DEBUG, "Write to socket failed!\n"); addIdamError(UDA_CODE_ERROR_TYPE, "writeUdaClientSSL", err, "Write to socket failed!"); -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if ((rc = fcntl(g_sslSocket, F_GETFL, &fopts)) < 0 || - errno == EBADF) { // Is the socket closed? Check status flags + errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "Socket is closed!\n"); } -#endif +# endif return -1; } @@ -555,14 +554,13 @@ int readUdaClientSSL(void* iohandle, char* buf, int count) int maxloop = 0; - // Wait till it's possible to read from socket + // Wait till it's possible to read from socket udaUpdateSelectParms(g_sslSocket, &rfds, &tv); - while (((rc = select(g_sslSocket + 1, &rfds, nullptr, nullptr, &tv)) <= 0) - && maxloop++ < MAXLOOP) { + while (((rc = select(g_sslSocket + 1, &rfds, nullptr, nullptr, &tv)) <= 0) && maxloop++ < MAXLOOP) { - if (rc < 0) { // Error + if (rc < 0) { // Error int serrno = errno; addIdamError(UDA_SYSTEM_ERROR_TYPE, "readUdaClientSSL", errno, "Socket is Closed!"); if (serrno == EBADF) { @@ -573,78 +571,76 @@ int readUdaClientSSL(void* iohandle, char* buf, int count) err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, "Socket is Closed! Data request failed. Restarting connection."); - UDA_LOG(UDA_LOG_DEBUG, - "Socket is Closed! Data request failed. Restarting connection.\n"); + UDA_LOG(UDA_LOG_DEBUG, "Socket is Closed! Data request failed. Restarting connection.\n"); return -1; } -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if ((rc = fcntl(g_sslSocket, F_GETFL, &fopts)) < 0 || - errno == EBADF) { // Is the socket closed? Check status flags + errno == EBADF) { // Is the socket closed? Check status flags err = 999; UDA_LOG(UDA_LOG_DEBUG, "Socket is closed!\n"); return -1; } -#endif +# endif - udaUpdateSelectParms(g_sslSocket, &rfds, &tv); // Keep blocking and wait for data + udaUpdateSelectParms(g_sslSocket, &rfds, &tv); // Keep blocking and wait for data } -// First byte of encrypted data received but need the full record in buffer before SSL can decrypt + // First byte of encrypted data received but need the full record in buffer before SSL can decrypt int blocked; do { blocked = 0; rc = SSL_read(getUdaClientSSL(), buf, count); - switch (SSL_get_error(getUdaClientSSL(), rc)) { // check for SSL errors - case SSL_ERROR_NONE: // clean read + switch (SSL_get_error(getUdaClientSSL(), rc)) { // check for SSL errors + case SSL_ERROR_NONE: // clean read break; - case SSL_ERROR_ZERO_RETURN: // connection closed by server (not caught by select?) + case SSL_ERROR_ZERO_RETURN: // connection closed by server (not caught by select?) reportSSLErrorCode(rc); err = 999; UDA_LOG(UDA_LOG_DEBUG, "Server socket connection closed!\n"); - addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, - "Server socket connection closed!"); + addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, "Server socket connection closed!"); return -1; - case SSL_ERROR_WANT_READ: // the operation did not complete, try again + case SSL_ERROR_WANT_READ: // the operation did not complete, try again blocked = 1; break; - case SSL_ERROR_WANT_WRITE: //the operation did not complete, error + case SSL_ERROR_WANT_WRITE: // the operation did not complete, error reportSSLErrorCode(rc); err = 999; UDA_LOG(UDA_LOG_DEBUG, "A read operation failed!\n"); addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, "A read operation failed!"); return -1; - case SSL_ERROR_SYSCALL: //some I/O error occured - disconnect? + case SSL_ERROR_SYSCALL: // some I/O error occured - disconnect? reportSSLErrorCode(rc); err = 999; UDA_LOG(UDA_LOG_DEBUG, "Socket read I/O error!\n"); addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, "Socket read I/O error!"); return -1; - default: //some other error + default: // some other error reportSSLErrorCode(rc); err = 999; UDA_LOG(UDA_LOG_DEBUG, "Read from socket failed!\n"); addIdamError(UDA_CODE_ERROR_TYPE, "readUdaClientSSL", err, "Read from socket failed!"); -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if ((rc = fcntl(g_sslSocket, F_GETFL, &fopts)) < 0 || - errno == EBADF) { // Is the socket closed? Check status flags + errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "Socket is closed!\n"); } -#endif +# endif return -1; } - } while (SSL_pending(getUdaClientSSL()) && !blocked); // data remaining in buffer or re-read attempt + } while (SSL_pending(getUdaClientSSL()) && !blocked); // data remaining in buffer or re-read attempt return rc; } -#endif // !SERVERBUILD && SSLAUTHENTICATION +#endif // !SERVERBUILD && SSLAUTHENTICATION diff --git a/source/authentication/udaClientSSL.h b/source/authentication/udaClientSSL.h index af70bbf9..7483f46a 100644 --- a/source/authentication/udaClientSSL.h +++ b/source/authentication/udaClientSSL.h @@ -1,9 +1,9 @@ #pragma once #ifndef UDA_AUTHENTICATION_CLIENT_SSL_H -#define UDA_AUTHENTICATION_CLIENT_SSL_H +# define UDA_AUTHENTICATION_CLIENT_SSL_H -#if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) +# if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) // Create the SSL context and binding to the socket // 3 UDA protocol modes: TCP without SSL/TLS, TCP and UDP both with SSL/TLS @@ -13,20 +13,20 @@ // Server host addressed beginng with SSL:// are assumed to be using SSL authentication. The SSL:// prefix is removed to // make the connection. -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include -#define VERIFY_DEPTH 4 -#define X509STRINGSIZE 256 +# define VERIFY_DEPTH 4 +# define X509STRINGSIZE 256 -#include +# include -#include -#include +# include +# include bool getUdaClientSSLDisabled(); SSL* getUdaClientSSL(); @@ -39,6 +39,6 @@ int readUdaClientSSL(void* iohandle, char* buf, int count); int writeUdaClientSSL(void* iohandle, char* buf, int count); void putClientHost(const HostData* host); -#endif // SSLAUTHENTICATION +# endif // SSLAUTHENTICATION #endif // UDA_AUTHENTICATION_CLIENT_SSL_H diff --git a/source/authentication/udaServerSSL.cpp b/source/authentication/udaServerSSL.cpp index d5d3b340..ace473de 100644 --- a/source/authentication/udaServerSSL.cpp +++ b/source/authentication/udaServerSSL.cpp @@ -1,22 +1,22 @@ #if defined(SSLAUTHENTICATION) -#include "udaServerSSL.h" -#include "server/createXDRStream.h" +# include "udaServerSSL.h" +# include "server/createXDRStream.h" -#include -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include +# include -#include -#include -#include +# include +# include +# include -#define VERIFY_DEPTH 4 -#define X509STRINGSIZE 256 +# define VERIFY_DEPTH 4 +# define X509STRINGSIZE 256 /* Note on initialisation: @@ -41,9 +41,15 @@ static int configureUdaServerSSLContext(); static X509_CRL* loadUdaServerSSLCrl(const char* crlist); static int addUdaServerSSLCrlsStore(X509_STORE* st, STACK_OF(X509_CRL) * crls); -void putUdaServerSSLSocket(int socket) { g_sslSocket = socket; } +void putUdaServerSSLSocket(int socket) +{ + g_sslSocket = socket; +} -bool getUdaServerSSLDisabled() { return g_sslDisabled; } +bool getUdaServerSSLDisabled() +{ + return g_sslDisabled; +} void reportServerSSLErrorCode(int rc) { @@ -87,8 +93,9 @@ void reportServerSSLErrorCode(int rc) void initUdaServerSSL() { - if (g_sslInit) + if (g_sslInit) { return; // Already initialised + } if (getenv("UDA_SSL_INITIALISED")) { g_sslInit = true; UDA_LOG(UDA_LOG_DEBUG, "Prior SSL initialisation\n"); @@ -97,12 +104,12 @@ void initUdaServerSSL() SSL_library_init(); SSL_load_error_strings(); OpenSSL_add_ssl_algorithms(); -#ifdef _WIN32 +# ifdef _WIN32 _putenv_s("UDA_SSL_INITIALISED", "1"); -#else +# else // Ensure the library is not re-initialised by the UDA client library setenv("UDA_SSL_INITIALISED", "1", 0); -#endif +# endif g_sslInit = true; UDA_LOG(UDA_LOG_DEBUG, "SSL initialised\n"); } @@ -120,16 +127,17 @@ void closeUdaServerSSL() SSL_shutdown(g_ssl); SSL_free(g_ssl); } - if (g_ctx != nullptr) + if (g_ctx != nullptr) { SSL_CTX_free(g_ctx); + } EVP_cleanup(); g_ssl = nullptr; g_ctx = nullptr; -#ifdef _WIN32 +# ifdef _WIN32 _putenv_s("UDA_SSL_INITIALISED", NULL); -#else +# else unsetenv("UDA_SSL_INITIALISED"); -#endif +# endif g_sslInit = false; UDA_LOG(UDA_LOG_DEBUG, "SSL closed\n"); } @@ -385,14 +393,14 @@ int startUdaServerSSL() return 0; } -#ifdef UNUSED -#elif defined(__GNUC__) -#define UNUSED __attribute__((unused)) -#elif defined(__LCLINT__) -#define UNUSED /*@unused@*/ -#else -#define UNUSED -#endif +# ifdef UNUSED +# elif defined(__GNUC__) +# define UNUSED __attribute__((unused)) +# elif defined(__LCLINT__) +# define UNUSED /*@unused@*/ +# else +# define UNUSED +# endif int writeUdaServerSSL(void* iohandle, const char* buf, int count) { @@ -423,14 +431,14 @@ int writeUdaServerSSL(void* iohandle, const char* buf, int count) return -1; } -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if (fcntl(g_sslSocket, F_GETFL, &fopts) < 0 || errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "Client Socket is closed! Closing server down.\n"); return -1; } -#endif +# endif *io_data->server_tot_block_time += tv.tv_usec / 1000; @@ -461,13 +469,13 @@ int writeUdaServerSSL(void* iohandle, const char* buf, int count) reportServerSSLErrorCode(rc); UDA_LOG(UDA_LOG_DEBUG, "Write to socket failed!\n"); UDA_ADD_ERROR(999, "Write to socket failed!"); -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if (fcntl(g_sslSocket, F_GETFL, &fopts) < 0 || errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "Client Socket is closed! Closing server down.\n"); } -#endif +# endif return -1; } @@ -509,14 +517,14 @@ int readUdaServerSSL(void* iohandle, char* buf, int count) return -1; } -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if (fcntl(g_sslSocket, F_GETFL, &fopts) < 0 || errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "Client Socket is closed! Closing server down.\n"); return -1; } -#endif +# endif updateSelectParms(g_sslSocket, &rfds, &tv, *io_data->server_tot_block_time); // Keep blocking and wait for data tvc = tv; @@ -559,13 +567,13 @@ int readUdaServerSSL(void* iohandle, char* buf, int count) reportServerSSLErrorCode(rc); UDA_LOG(UDA_LOG_DEBUG, "Read from socket failed!\n"); UDA_ADD_ERROR(999, "Read from socket failed!"); -#ifndef _WIN32 +# ifndef _WIN32 int fopts = 0; if ((rc = fcntl(g_sslSocket, F_GETFL, &fopts)) < 0 || errno == EBADF) { // Is the socket closed? Check status flags UDA_LOG(UDA_LOG_DEBUG, "writeUdaServerSSL: Client Socket is closed! Closing server down.\n"); } -#endif +# endif return -1; } diff --git a/source/authentication/udaServerSSL.h b/source/authentication/udaServerSSL.h index 06e47c37..781b4bda 100644 --- a/source/authentication/udaServerSSL.h +++ b/source/authentication/udaServerSSL.h @@ -11,11 +11,11 @@ // Server host addressed beginng with SSL:// are assumed to be using SSL authentication. The SSL:// prefix is removed to // make the connection. -#include +# include -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif LIBRARY_API int startUdaServerSSL(); LIBRARY_API void closeUdaServerSSL(); @@ -24,9 +24,9 @@ LIBRARY_API int writeUdaServerSSL(void* iohandle, const char* buf, int count); LIBRARY_API void putUdaServerSSLSocket(int socket); LIBRARY_API bool getUdaServerSSLDisabled(); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif // SSLAUTHENTICATION diff --git a/source/bin/uda_cli.cpp b/source/bin/uda_cli.cpp index f3c9c100..21b181e5 100644 --- a/source/bin/uda_cli.cpp +++ b/source/bin/uda_cli.cpp @@ -1,22 +1,18 @@ -#include #include "udaTypes.h" #include +#include -#include -#include #include #include #include +#include +#include -struct CLIException : public uda::UDAException -{ - explicit CLIException(std::string what) noexcept - : uda::UDAException(std::move(what)) - {} +struct CLIException : public uda::UDAException { + explicit CLIException(std::string what) noexcept : uda::UDAException(std::move(what)) {} }; -template -std::ostream& operator<<(std::ostream& out, gsl::span span) +template std::ostream& operator<<(std::ostream& out, gsl::span span) { out << "["; const char* delim = ""; @@ -34,10 +30,9 @@ std::ostream& operator<<(std::ostream& out, gsl::span span) return out; } -template -std::ostream& operator<<(std::ostream& out, const std::vector& vec) +template std::ostream& operator<<(std::ostream& out, const std::vector& vec) { - auto span = gsl::span{ vec.data(), vec.size() }; + auto span = gsl::span{vec.data(), vec.size()}; out << span; return out; } @@ -54,14 +49,13 @@ bool replace(std::string& str, const std::string& from, const std::string& to) return true; } -template -void print_atomic_data(void* data, size_t rank, size_t count) +template void print_atomic_data(void* data, size_t rank, size_t count) { T* ptr = reinterpret_cast(data); if (rank == 0) { std::cout << ptr[0] << "\n"; } else { - auto span = gsl::span{ ptr, count }; + auto span = gsl::span{ptr, count}; std::cout << span << "\n"; } } @@ -82,7 +76,7 @@ void print_tree(const uda::TreeNode& node, const std::string& indent) std::vector shape; std::string type; - for (const auto& el: boost::combine(names, pointers, ranks, shapes, types)) { + for (const auto& el : boost::combine(names, pointers, ranks, shapes, types)) { boost::tie(name, pointer, rank, shape, type) = el; auto data = node.structureComponentData(name); @@ -130,13 +124,13 @@ void print_tree(const uda::TreeNode& node, const std::string& indent) } } - for (const auto& child: node.children()) { + for (const auto& child : node.children()) { print_tree(child, indent + " "); } } #ifdef CAPNP_ENABLED -template +template void print_capnp_data(NodeReader* node, const std::vector& shape, const std::string& indent) { auto num_slices = uda_capnp_read_num_slices(node); @@ -152,14 +146,14 @@ void print_capnp_data(NodeReader* node, const std::vector& shape, const auto count = uda_capnp_read_slice_size(node, 0); auto data = std::make_unique(count / sizeof(T)); uda_capnp_read_data(node, 0, reinterpret_cast(data.get())); - auto span = gsl::span{ data.get(), count / sizeof(T) }; + auto span = gsl::span{data.get(), count / sizeof(T)}; std::cout << indent << "data: " << span << "\n"; } else { for (size_t slice_num = 0; slice_num < num_slices; ++slice_num) { auto count = uda_capnp_read_slice_size(node, slice_num); auto data = std::make_unique(count / sizeof(T)); uda_capnp_read_data(node, slice_num, reinterpret_cast(data.get())); - auto span = gsl::span{ data.get(), count / sizeof(T) }; + auto span = gsl::span{data.get(), count / sizeof(T)}; std::cout << indent << "data [" << slice_num << "]: " << span << "\n"; } } @@ -374,25 +368,22 @@ void print_data(const uda::Data* data, int uda_type) } } -void conflicting_options(const boost::program_options::variables_map & vm, - const std::string & opt1, const std::string & opt2) +void conflicting_options(const boost::program_options::variables_map& vm, const std::string& opt1, + const std::string& opt2) { - if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) && !vm[opt2].defaulted()) - { - throw po::error(std::string("conflicting options '") + opt1 + "' and '" + opt2 + "'"); + if (vm.count(opt1) && !vm[opt1].defaulted() && vm.count(opt2) && !vm[opt2].defaulted()) { + throw po::error(std::string("conflicting options '") + opt1 + "' and '" + opt2 + "'"); } } int main(int argc, const char** argv) { po::options_description desc("Allowed options"); - desc.add_options() - ("help", po::bool_switch(), "produce help message") - ("host,h", po::value()->default_value("localhost"), "server host name") - ("port,p", po::value()->default_value(56565), "server port") - ("request", po::value(), "request") - ("source", po::value()->default_value(""), "source") - ("ping", po::bool_switch(), "ping the server"); + desc.add_options()("help", po::bool_switch(), "produce help message")( + "host,h", po::value()->default_value("localhost"), + "server host name")("port,p", po::value()->default_value(56565), "server port")( + "request", po::value(), "request")("source", po::value()->default_value(""), + "source")("ping", po::bool_switch(), "ping the server"); po::positional_options_description p; p.add("request", 1); diff --git a/source/c_api/accAPI.cpp b/source/c_api/accAPI.cpp old mode 100755 new mode 100644 index 0ed75a0c..aa4c1862 --- a/source/c_api/accAPI.cpp +++ b/source/c_api/accAPI.cpp @@ -14,15 +14,15 @@ # define strlwr _strlwr #endif -#include "logging/logging.h" -#include "initStructs.h" -#include "clientserver/stringUtils.h" +#include "accessors.h" #include "clientserver/allocData.h" -#include "clientserver/protocol.h" #include "clientserver/memstream.h" +#include "clientserver/protocol.h" +#include "clientserver/stringUtils.h" #include "clientserver/xdrlib.h" +#include "initStructs.h" +#include "logging/logging.h" #include "struct.h" -#include "accessors.h" #include "version.h" #include "client/generateErrors.h" @@ -45,29 +45,29 @@ 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 id; // Thread identifier assigned by the application + int socket; // Either a shared or private server socket connection int lastHandle; - ENVIRONMENT environment; // State + ENVIRONMENT environment; // State CLIENT_BLOCK client_block; SERVER_BLOCK server_block; } IDAMSTATE; -#ifdef __GNUC__ +# ifdef __GNUC__ typedef pthread_t thread_t; typedef pthread_mutex_t lock_t; static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER; -#else +# else typedef HANDLE lock_t; typedef HANDLE thread_t; static HANDLE lock; -#endif +# endif // STATE management -static IDAMSTATE idamState[UDA_NUM_CLIENT_THREADS]; // Threads are managed by the application, not IDAM +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; @@ -84,53 +84,57 @@ int getIdamMaxThreadCount() 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 +# 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 +// 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__ +# ifndef __GNUC__ lock = CreateMutex(nullptr, FALSE, nullptr); -#endif +# endif } // Apply the lock first -#ifdef __GNUC__ +# ifdef __GNUC__ pthread_mutex_lock(&lock); -#else +# else WaitForSingleObject(lock, INFINITE); -#endif +# endif // Identify the Current Thread -#ifdef __GNUC__ +# ifdef __GNUC__ thread_t threadId = pthread_self(); -#else +# else thread_t threadId = GetCurrentThread(); -#endif +# 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 + 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)); + // initEnvironment(&(idamState[i].environment)); initClientBlock(&(idamState[i].client_block), 0, ""); initServerBlock(&(idamState[i].server_block), 0); - threadList[i] = 0; // and the thread identifiers + threadList[i] = 0; // and the thread identifiers } } @@ -147,7 +151,7 @@ void lockIdamThread(CLIENT_FLAGS* client_flags) if (id >= 0) { putIdamServerSocket(idamState[id].socket); - //putIdamClientEnvironment(&idamState[id].environment); + // putIdamClientEnvironment(&idamState[id].environment); putIdamThreadClientBlock(&idamState[id].client_block); putIdamThreadServerBlock(&idamState[id].server_block); client_flags->flags = idamState[id].client_block.clientFlags; @@ -162,25 +166,25 @@ void lockIdamThread(CLIENT_FLAGS* client_flags) */ void unlockUdaThread(CLIENT_FLAGS* client_flags) { -#ifdef __GNUC__ +# ifdef __GNUC__ thread_t threadId = pthread_self(); -#else +# else thread_t threadId = GetCurrentThread(); -#endif - int id = getThreadId(threadId); // Must be registered +# endif + int id = getThreadId(threadId); // Must be registered if (id >= 0) { idamState[id].socket = getIdamServerSocket(); - //idamState[id].environment = *getIdamClientEnvironment(); + // 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__ +# ifdef __GNUC__ pthread_mutex_unlock(&lock); -#else +# else ReleaseMutex(lock); -#endif +# endif } /** @@ -189,23 +193,23 @@ void unlockUdaThread(CLIENT_FLAGS* client_flags) void freeIdamThread(CLIENT_FLAGS* client_flags) { lockIdamThread(client_flags); -#ifdef __GNUC__ +# ifdef __GNUC__ thread_t threadId = pthread_self(); -#else +# else thread_t threadId = GetCurrentThread(); -#endif +# endif int id = getThreadId(threadId); threadCount--; if (id >= 0) { for (int i = id; i < threadCount; i++) { - threadList[i] = threadList[i + 1]; // Shuffle state + 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)); + // initEnvironment(&(idamState[threadCount].environment)); initClientBlock(&(idamState[threadCount].client_block), 0, ""); initServerBlock(&(idamState[threadCount].server_block), 0); threadList[threadCount] = 0; @@ -337,10 +341,10 @@ Rank Ordering is as follows: //! Set a private_flags property /** Set a/multiple specific bit/s in the private_flags property sent between UDA servers. -* -* @param flag The bit/s to be set to 1. -* @return Void. -*/ + * + * @param flag The bit/s to be set to 1. + * @return Void. + */ void setIdamPrivateFlag(unsigned int flag) { unsigned int* private_flags = udaPrivateFlags(); @@ -349,10 +353,10 @@ void setIdamPrivateFlag(unsigned int flag) //! Reset a private_flags property /** Reset a/multiple specific bit/s in the private_flags property sent between UDA servers. -* -* @param flag The bit/s to be set to 0. -* @return Void. -*/ + * + * @param flag The bit/s to be set to 0. + * @return Void. + */ void resetIdamPrivateFlag(unsigned int flag) { @@ -365,10 +369,10 @@ void resetIdamPrivateFlag(unsigned int flag) //! 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. -*/ + * + * @param flag The bit/s to be set to 1. + * @return Void. + */ void setIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) { @@ -377,10 +381,10 @@ void setIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int 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. -*/ + * + * @param flag The bit/s to be set to 0. + * @return Void. + */ void resetIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) { @@ -391,30 +395,30 @@ void resetIdamClientFlag(CLIENT_FLAGS* client_flags, unsigned int flag) // Set Server Properties //! Set a named server property -/** Set a variety of data server properties using their name. These affect the data type returned and any server side processing of data. -* Not all data access plugins respond to these properties.\n -* -* \eget_datadble data are returned in double precision.\n -* \eget_dimdble all coordinate (dimension) data are returned in double precision.\n -* \eget_timedble the Time coordinate (dimension) data are returned in double precision.\n -* \eget_bytes\n -* \eget_bad\n -* \eget_meta return all SQL database records used to locate and correct the requested data\n -* \eget_asis do not apply server side correction to data\n -* \eget_uncal\n -* \eget_notoff do not apply any timing offset corrections\n -* \eget_synthetic\n -* \eget_scalar\n -* \eget_nodimdata do not return coordinate (dimension) data\n -* \etimeout=value name value pair to set the number of wait seconds before timing out the server connection\n -* \everbose \n -* \edebug create debug output from the client\n -* \ealtData use efit++ with legacy efm data signal names \n -* \ealtRank select different efit++ output file as the data source \n -* -* @param property the name of the property to set true or a name value pair. -* @return Void. -*/ +/** Set a variety of data server properties using their name. These affect the data type returned and any server side + * processing of data. Not all data access plugins respond to these properties.\n + * + * \eget_datadble data are returned in double precision.\n + * \eget_dimdble all coordinate (dimension) data are returned in double precision.\n + * \eget_timedble the Time coordinate (dimension) data are returned in double precision.\n + * \eget_bytes\n + * \eget_bad\n + * \eget_meta return all SQL database records used to locate and correct the requested data\n + * \eget_asis do not apply server side correction to data\n + * \eget_uncal\n + * \eget_notoff do not apply any timing offset corrections\n + * \eget_synthetic\n + * \eget_scalar\n + * \eget_nodimdata do not return coordinate (dimension) data\n + * \etimeout=value name value pair to set the number of wait seconds before timing out the server connection\n + * \everbose \n + * \edebug create debug output from the client\n + * \ealtData use efit++ with legacy efm data signal names \n + * \ealtRank select different efit++ output file as the data source \n + * + * @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) { // User settings for Client and Server behaviour @@ -423,18 +427,42 @@ void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags) char* value; if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) client_flags->get_datadble = 1; - if (STR_IEQUALS(property, "get_dimdble")) client_flags->get_dimdble = 1; - if (STR_IEQUALS(property, "get_timedble")) client_flags->get_timedble = 1; - if (STR_IEQUALS(property, "get_bytes")) client_flags->get_bytes = 1; - if (STR_IEQUALS(property, "get_bad")) client_flags->get_bad = 1; - if (STR_IEQUALS(property, "get_meta")) client_flags->get_meta = 1; - if (STR_IEQUALS(property, "get_asis")) client_flags->get_asis = 1; - if (STR_IEQUALS(property, "get_uncal")) client_flags->get_uncal = 1; - if (STR_IEQUALS(property, "get_notoff")) client_flags->get_notoff = 1; - if (STR_IEQUALS(property, "get_synthetic")) client_flags->get_synthetic = 1; - if (STR_IEQUALS(property, "get_scalar")) client_flags->get_scalar = 1; - if (STR_IEQUALS(property, "get_nodimdata")) client_flags->get_nodimdata = 1; + if (STR_IEQUALS(property, "get_datadble")) { + client_flags->get_datadble = 1; + } + if (STR_IEQUALS(property, "get_dimdble")) { + client_flags->get_dimdble = 1; + } + if (STR_IEQUALS(property, "get_timedble")) { + client_flags->get_timedble = 1; + } + if (STR_IEQUALS(property, "get_bytes")) { + client_flags->get_bytes = 1; + } + if (STR_IEQUALS(property, "get_bad")) { + client_flags->get_bad = 1; + } + if (STR_IEQUALS(property, "get_meta")) { + client_flags->get_meta = 1; + } + if (STR_IEQUALS(property, "get_asis")) { + client_flags->get_asis = 1; + } + if (STR_IEQUALS(property, "get_uncal")) { + client_flags->get_uncal = 1; + } + if (STR_IEQUALS(property, "get_notoff")) { + client_flags->get_notoff = 1; + } + if (STR_IEQUALS(property, "get_synthetic")) { + client_flags->get_synthetic = 1; + } + if (STR_IEQUALS(property, "get_scalar")) { + client_flags->get_scalar = 1; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + client_flags->get_nodimdata = 1; + } } else { if (property[0] == 't') { strncpy(name, property, 55); @@ -445,12 +473,20 @@ void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags) strlwr(name); if ((value = strstr(name, "timeout=")) != nullptr) { value = name + 8; - if (IsNumber(value)) client_flags->user_timeout = atoi(value); + if (IsNumber(value)) { + client_flags->user_timeout = atoi(value); + } } } else { - if (STR_IEQUALS(property, "verbose")) udaSetLogLevel(UDA_LOG_INFO); - if (STR_IEQUALS(property, "debug")) udaSetLogLevel(UDA_LOG_DEBUG); - if (STR_IEQUALS(property, "altData")) client_flags->flags = client_flags->flags | CLIENTFLAG_ALTDATA; + if (STR_IEQUALS(property, "verbose")) { + udaSetLogLevel(UDA_LOG_INFO); + } + if (STR_IEQUALS(property, "debug")) { + udaSetLogLevel(UDA_LOG_DEBUG); + } + if (STR_IEQUALS(property, "altData")) { + client_flags->flags = client_flags->flags | CLIENTFLAG_ALTDATA; + } if (!strncasecmp(property, "altRank", 7)) { strncpy(name, property, 55); name[55] = '\0'; @@ -460,91 +496,175 @@ void setIdamProperty(const char* property, CLIENT_FLAGS* client_flags) strlwr(name); if ((value = strcasestr(name, "altRank=")) != nullptr) { value = name + 8; - if (IsNumber(value)) client_flags->alt_rank = atoi(value); + if (IsNumber(value)) { + client_flags->alt_rank = atoi(value); + } } } } - if (STR_IEQUALS(property, "reuseLastHandle")) client_flags->flags = client_flags->flags | CLIENTFLAG_REUSELASTHANDLE; - if (STR_IEQUALS(property, "freeAndReuseLastHandle")) client_flags->flags = client_flags->flags | CLIENTFLAG_FREEREUSELASTHANDLE; - if (STR_IEQUALS(property, "fileCache")) client_flags->flags = client_flags->flags | CLIENTFLAG_FILECACHE; + if (STR_IEQUALS(property, "reuseLastHandle")) { + client_flags->flags = client_flags->flags | CLIENTFLAG_REUSELASTHANDLE; + } + if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { + client_flags->flags = client_flags->flags | CLIENTFLAG_FREEREUSELASTHANDLE; + } + if (STR_IEQUALS(property, "fileCache")) { + client_flags->flags = client_flags->flags | CLIENTFLAG_FILECACHE; + } } } //! Return the value of a named server property /** -* @param property the name of the property. -* @return Void. -*/ + * @param property the name of the property. + * @return Void. + */ int getIdamProperty(const char* property, const CLIENT_FLAGS* client_flags) { // User settings for Client and Server behaviour if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) return client_flags->get_datadble; - if (STR_IEQUALS(property, "get_dimdble")) return client_flags->get_dimdble; - if (STR_IEQUALS(property, "get_timedble")) return client_flags->get_timedble; - if (STR_IEQUALS(property, "get_bytes")) return client_flags->get_bytes; - if (STR_IEQUALS(property, "get_bad")) return client_flags->get_bad; - if (STR_IEQUALS(property, "get_meta")) return client_flags->get_meta; - if (STR_IEQUALS(property, "get_asis")) return client_flags->get_asis; - if (STR_IEQUALS(property, "get_uncal")) return client_flags->get_uncal; - if (STR_IEQUALS(property, "get_notoff")) return client_flags->get_notoff; - if (STR_IEQUALS(property, "get_synthetic")) return client_flags->get_synthetic; - if (STR_IEQUALS(property, "get_scalar")) return client_flags->get_scalar; - if (STR_IEQUALS(property, "get_nodimdata")) return client_flags->get_nodimdata; + if (STR_IEQUALS(property, "get_datadble")) { + return client_flags->get_datadble; + } + if (STR_IEQUALS(property, "get_dimdble")) { + return client_flags->get_dimdble; + } + if (STR_IEQUALS(property, "get_timedble")) { + return client_flags->get_timedble; + } + if (STR_IEQUALS(property, "get_bytes")) { + return client_flags->get_bytes; + } + if (STR_IEQUALS(property, "get_bad")) { + return client_flags->get_bad; + } + if (STR_IEQUALS(property, "get_meta")) { + return client_flags->get_meta; + } + if (STR_IEQUALS(property, "get_asis")) { + return client_flags->get_asis; + } + if (STR_IEQUALS(property, "get_uncal")) { + return client_flags->get_uncal; + } + if (STR_IEQUALS(property, "get_notoff")) { + return client_flags->get_notoff; + } + if (STR_IEQUALS(property, "get_synthetic")) { + return client_flags->get_synthetic; + } + if (STR_IEQUALS(property, "get_scalar")) { + return client_flags->get_scalar; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + return client_flags->get_nodimdata; + } } else { - if (STR_IEQUALS(property, "timeout")) return client_flags->user_timeout; - if (STR_IEQUALS(property, "altRank")) return client_flags->alt_rank; - if (STR_IEQUALS(property, "reuseLastHandle")) return (int)(client_flags->flags & CLIENTFLAG_REUSELASTHANDLE); - if (STR_IEQUALS(property, "freeAndReuseLastHandle")) return (int)(client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE); - if (STR_IEQUALS(property, "verbose")) return udaGetLogLevel() == UDA_LOG_INFO; - if (STR_IEQUALS(property, "debug")) return udaGetLogLevel() == UDA_LOG_DEBUG; - if (STR_IEQUALS(property, "altData")) return (int)(client_flags->flags & CLIENTFLAG_ALTDATA); - if (STR_IEQUALS(property, "fileCache")) return (int)(client_flags->flags & CLIENTFLAG_FILECACHE); + if (STR_IEQUALS(property, "timeout")) { + return client_flags->user_timeout; + } + if (STR_IEQUALS(property, "altRank")) { + return client_flags->alt_rank; + } + if (STR_IEQUALS(property, "reuseLastHandle")) { + return (int)(client_flags->flags & CLIENTFLAG_REUSELASTHANDLE); + } + if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { + return (int)(client_flags->flags & CLIENTFLAG_FREEREUSELASTHANDLE); + } + if (STR_IEQUALS(property, "verbose")) { + return udaGetLogLevel() == UDA_LOG_INFO; + } + if (STR_IEQUALS(property, "debug")) { + return udaGetLogLevel() == UDA_LOG_DEBUG; + } + if (STR_IEQUALS(property, "altData")) { + return (int)(client_flags->flags & CLIENTFLAG_ALTDATA); + } + if (STR_IEQUALS(property, "fileCache")) { + return (int)(client_flags->flags & CLIENTFLAG_FILECACHE); + } } return 0; } //! Reset a specific named data server property to its default value /** -* @param property the name of the property. -* @return Void. -*/ + * @param property the name of the property. + * @return Void. + */ void resetIdamProperty(const char* property, CLIENT_FLAGS* client_flags) { // User settings for Client and Server behaviour if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) client_flags->get_datadble = 0; - if (STR_IEQUALS(property, "get_dimdble")) client_flags->get_dimdble = 0; - if (STR_IEQUALS(property, "get_timedble")) client_flags->get_timedble = 0; - if (STR_IEQUALS(property, "get_bytes")) client_flags->get_bytes = 0; - if (STR_IEQUALS(property, "get_bad")) client_flags->get_bad = 0; - if (STR_IEQUALS(property, "get_meta")) client_flags->get_meta = 0; - if (STR_IEQUALS(property, "get_asis")) client_flags->get_asis = 0; - if (STR_IEQUALS(property, "get_uncal")) client_flags->get_uncal = 0; - if (STR_IEQUALS(property, "get_notoff")) client_flags->get_notoff = 0; - if (STR_IEQUALS(property, "get_synthetic")) client_flags->get_synthetic = 0; - if (STR_IEQUALS(property, "get_scalar")) client_flags->get_scalar = 0; - if (STR_IEQUALS(property, "get_nodimdata")) client_flags->get_nodimdata = 0; + if (STR_IEQUALS(property, "get_datadble")) { + client_flags->get_datadble = 0; + } + if (STR_IEQUALS(property, "get_dimdble")) { + client_flags->get_dimdble = 0; + } + if (STR_IEQUALS(property, "get_timedble")) { + client_flags->get_timedble = 0; + } + if (STR_IEQUALS(property, "get_bytes")) { + client_flags->get_bytes = 0; + } + if (STR_IEQUALS(property, "get_bad")) { + client_flags->get_bad = 0; + } + if (STR_IEQUALS(property, "get_meta")) { + client_flags->get_meta = 0; + } + if (STR_IEQUALS(property, "get_asis")) { + client_flags->get_asis = 0; + } + if (STR_IEQUALS(property, "get_uncal")) { + client_flags->get_uncal = 0; + } + if (STR_IEQUALS(property, "get_notoff")) { + client_flags->get_notoff = 0; + } + if (STR_IEQUALS(property, "get_synthetic")) { + client_flags->get_synthetic = 0; + } + if (STR_IEQUALS(property, "get_scalar")) { + client_flags->get_scalar = 0; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + client_flags->get_nodimdata = 0; + } } else { - if (STR_IEQUALS(property, "verbose")) udaSetLogLevel(UDA_LOG_NONE); - if (STR_IEQUALS(property, "debug")) udaSetLogLevel(UDA_LOG_NONE); - if (STR_IEQUALS(property, "altData")) client_flags->flags &= !CLIENTFLAG_ALTDATA; - if (STR_IEQUALS(property, "altRank")) client_flags->alt_rank = 0; - if (STR_IEQUALS(property, "reuseLastHandle")) client_flags->flags &= !CLIENTFLAG_REUSELASTHANDLE; + if (STR_IEQUALS(property, "verbose")) { + udaSetLogLevel(UDA_LOG_NONE); + } + if (STR_IEQUALS(property, "debug")) { + udaSetLogLevel(UDA_LOG_NONE); + } + if (STR_IEQUALS(property, "altData")) { + client_flags->flags &= !CLIENTFLAG_ALTDATA; + } + if (STR_IEQUALS(property, "altRank")) { + client_flags->alt_rank = 0; + } + if (STR_IEQUALS(property, "reuseLastHandle")) { + client_flags->flags &= !CLIENTFLAG_REUSELASTHANDLE; + } if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { client_flags->flags &= !CLIENTFLAG_FREEREUSELASTHANDLE; } - if (STR_IEQUALS(property, "fileCache")) client_flags->flags &= !CLIENTFLAG_FILECACHE; + if (STR_IEQUALS(property, "fileCache")) { + client_flags->flags &= !CLIENTFLAG_FILECACHE; + } } } //! Reset all data server properties to their default values /** -* @return Void. -*/ + * @return Void. + */ void resetIdamProperties(CLIENT_FLAGS* client_flags) { // Reset on Both Client and Server @@ -572,8 +692,8 @@ void resetIdamProperties(CLIENT_FLAGS* client_flags) //! Return the client state associated with a specific data item /** The client state information is at the time the data was accessed. -* @return CLIENT_BLOCK pointer to the data structure. -*/ + * @return CLIENT_BLOCK pointer to the data structure. + */ CLIENT_BLOCK* getIdamProperties(int handle) { if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { @@ -584,8 +704,8 @@ CLIENT_BLOCK* getIdamProperties(int handle) //! Return the client state associated with a specific data item /** The client state information is at the time the data was accessed. -* @return CLIENT_BLOCK pointer to the data structure. -*/ + * @return CLIENT_BLOCK pointer to the data structure. + */ CLIENT_BLOCK* getIdamDataProperties(int handle) { return getIdamProperties(handle); @@ -594,28 +714,28 @@ CLIENT_BLOCK* getIdamDataProperties(int handle) //-------------------------------------------------------------- //! Test for amount of Free heap memory and current usage /** When the UDA client is a server plugin, set the Client's Debug File handle to that of the Server. -* @return void -*/ + * @return void + */ #if !defined(__APPLE__) && !defined(_WIN32) int getIdamMemoryFree() { -#ifdef A64 +# ifdef A64 return 0; -#else +# else struct mallinfo stats = mallinfo(); - return (int) stats.fordblks; -#endif + return (int)stats.fordblks; +# endif } int getIdamMemoryUsed() { -#ifdef A64 +# ifdef A64 return 0; -#else +# else struct mallinfo stats = mallinfo(); - return (int) stats.uordblks; -#endif + return (int)stats.uordblks; +# endif } #endif @@ -628,12 +748,16 @@ void putIdamErrorModel(int handle, int model, int param_n, const float* params) if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { return; } - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return; // No valid Model + 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_blocks[handle].error_model = model; // Model ID + data_blocks[handle].error_param_n = param_n; // Number of parameters - if (param_n > MAXERRPARAMS) data_blocks[handle].error_param_n = MAXERRPARAMS; + if (param_n > MAXERRPARAMS) { + data_blocks[handle].error_param_n = MAXERRPARAMS; + } for (int i = 0; i < data_blocks[handle].error_param_n; i++) { data_blocks[handle].errparams[i] = params[i]; @@ -646,14 +770,18 @@ void putIdamDimErrorModel(int handle, int ndim, int model, int param_n, const fl return; } if (ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { - return; // No Dim + return; // No Dim + } + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return; // No valid Model } - 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_blocks[handle].dims[ndim].error_model = model; // Model ID + data_blocks[handle].dims[ndim].error_param_n = param_n; // Number of parameters - if (param_n > MAXERRPARAMS) data_blocks[handle].dims[ndim].error_param_n = MAXERRPARAMS; + if (param_n > MAXERRPARAMS) { + data_blocks[handle].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]; } @@ -661,48 +789,48 @@ void putIdamDimErrorModel(int handle, int ndim, int model, int param_n, const fl //! Set the UDA data server host name and port number /** This takes precedence over the environment variables UDA_HOST and UDA_PORT. -* @param host The name of the server host computer. -* @param port The port number the server is connected to. -* @return void -*/ + * @param host The name of the server host computer. + * @param port The port number the server is connected to. + * @return void + */ void putIdamServer(const char* host, int port) { ENVIRONMENT* environment = getIdamClientEnvironment(); - environment->server_port = port; // UDA server service port number - strcpy(environment->server_host, host); // UDA server's host name or IP address - environment->server_reconnect = 1; // Create a new Server instance - udaSetEnvHost(false); // Skip initialisation at Startup if these are called first + environment->server_port = port; // UDA server service port number + strcpy(environment->server_host, host); // UDA server's host name or IP address + environment->server_reconnect = 1; // Create a new Server instance + udaSetEnvHost(false); // Skip initialisation at Startup if these are called first udaSetEnvPort(false); } //! Set the UDA data server host name /** This takes precedence over the environment variables UDA_HOST. -* @param host The name of the server host computer. -* @return void -*/ + * @param host The name of the server host computer. + * @return void + */ void putIdamServerHost(const char* host) { ENVIRONMENT* environment = getIdamClientEnvironment(); std::string old_host = host; - strcpy(environment->server_host, host); // UDA server's host name or IP address + strcpy(environment->server_host, host); // UDA server's host name or IP address if (old_host != host) { - environment->server_reconnect = 1; // Create a new Server instance + environment->server_reconnect = 1; // Create a new Server instance } udaSetEnvHost(false); } //! Set the UDA data server port number /** This takes precedence over the environment variables UDA_PORT. -* @param port The port number the server is connected to. -* @return void -*/ + * @param port The port number the server is connected to. + * @return void + */ void putIdamServerPort(int port) { ENVIRONMENT* environment = getIdamClientEnvironment(); int old_port = port; - environment->server_port = port; // UDA server service port number + environment->server_port = port; // UDA server service port number if (old_port != port) { - environment->server_reconnect = 1; // Create a new Server instance + environment->server_reconnect = 1; // Create a new Server instance } udaSetEnvPort(false); } @@ -716,9 +844,9 @@ Select the server connection required. void putIdamServerSocket(int socket) { ENVIRONMENT* environment = getIdamClientEnvironment(); - if (environment->server_socket != socket) { // Change to a different socket - environment->server_socket = socket; // UDA server service socket number (Must be Open) - environment->server_change_socket = 1; // Connect to an Existing Server + if (environment->server_socket != socket) { // Change to a different socket + environment->server_socket = socket; // UDA server service socket number (Must be Open) + environment->server_change_socket = 1; // Connect to an Existing Server } } @@ -727,37 +855,37 @@ void putIdamServerSocket(int socket) //! Return the UDA data server host name, port number and socket connection id /** -* @param host A preallocated string that will contain the name of the server host computer. -* @param port Returned port number. -* @param socket Returned socket id number. -* @return void -*/ + * @param host A preallocated string that will contain the name of the server host computer. + * @param port Returned port number. + * @param socket Returned socket id number. + * @return void + */ void getIdamServer(const char** host, int* port, int* socket) -{ // Active ... +{ // Active ... ENVIRONMENT* environment = getIdamClientEnvironment(); - *socket = environment->server_socket; // UDA server service socket number - *port = environment->server_port; // UDA server service port number - *host = environment->server_host; // UDA server's host name or IP address + *socket = environment->server_socket; // UDA server service socket number + *port = environment->server_port; // UDA server service port number + *host = environment->server_host; // UDA server's host name or IP address } //! the UDA server connection host name /** -* @return the Name of the Host -*/ + * @return the Name of the Host + */ const char* getIdamServerHost() { ENVIRONMENT* environment = getIdamClientEnvironment(); - return environment->server_host; // Active UDA server's host name or IP address + return environment->server_host; // Active UDA server's host name or IP address } //! the UDA server connection port number /** -* @return the Name of the Host -*/ + * @return the Name of the Host + */ int getIdamServerPort() { ENVIRONMENT* environment = getIdamClientEnvironment(); - return environment->server_port; // Active UDA server service port number + return environment->server_port; // Active UDA server service port number } const char* udaGetBuildVersion() @@ -772,12 +900,12 @@ const char* udaGetBuildDate() //! the UDA server connection socket ID /** -* @return the connection socket ID -*/ + * @return the connection socket ID + */ int getIdamServerSocket() { ENVIRONMENT* environment = getIdamClientEnvironment(); - return environment->server_socket; // Active UDA server service socket number + return environment->server_socket; // Active UDA server service socket number } //! returns the data access error code @@ -816,8 +944,10 @@ const char* getIdamErrorMsg(int handle) \return Quality status. */ int getIdamSourceStatus(int handle) -{ // Source Status - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; +{ // Source Status + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].source_status; } @@ -829,14 +959,18 @@ int getIdamSourceStatus(int handle) int getIdamSignalStatus(int handle) { // Signal Status - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].signal_status; } int getIdamDataStatus(int handle) { // Data Status based on Standard Rule - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } if (getIdamSignalStatus(handle) == DEFAULT_STATUS) { // Signal Status Not Changed from Default - use Data Source Value return data_blocks[handle].source_status; @@ -862,7 +996,9 @@ int getIdamLastHandle(CLIENT_FLAGS* client_flags) int getIdamDataNum(int handle) { // Data Array Size - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].data_n; } @@ -874,20 +1010,23 @@ int getIdamDataNum(int handle) int getIdamRank(int handle) { // Array Rank - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return (int)data_blocks[handle].rank; } //! Returns the position of the time coordinate dimension in the data object -/** For example, a rank 3 array data[time][x][y] (in Fortran and IDL this is data(y,x,time)) has time order = 0 so order is -counted from left to right in c and from right to left in Fortran and IDL. -\param handle The data object handle +/** For example, a rank 3 array data[time][x][y] (in Fortran and IDL this is data(y,x,time)) has time order = 0 so order +is counted from left to right in c and from right to left in Fortran and IDL. \param handle The data object handle \return the time coordinate dimension position */ int getIdamOrder(int handle) { // Time Dimension Order in Array - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return -1; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return -1; + } return data_blocks[handle].order; } @@ -899,7 +1038,9 @@ int getIdamOrder(int handle) unsigned int getIdamCachePermission(int handle) { // Permission to cache? - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return UDA_PLUGIN_NOT_OK_TO_CACHE; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return UDA_PLUGIN_NOT_OK_TO_CACHE; + } return data_blocks[handle].cachePermission; } @@ -911,7 +1052,9 @@ unsigned int getIdamCachePermission(int handle) */ unsigned int getIdamTotalDataBlockSize(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].totalDataBlockSize; } @@ -973,37 +1116,95 @@ int getIdamErrorType(int handle) int getIdamDataTypeId(const char* type) { // Return the Internal Code for Data Types - if (STR_IEQUALS(type, "dcomplex")) return UDA_TYPE_DCOMPLEX; - if (STR_IEQUALS(type, "complex")) return UDA_TYPE_COMPLEX; - if (STR_IEQUALS(type, "double")) return UDA_TYPE_DOUBLE; - if (STR_IEQUALS(type, "float")) return UDA_TYPE_FLOAT; - if (STR_IEQUALS(type, "long64")) return UDA_TYPE_LONG64; - if (STR_IEQUALS(type, "long long")) return UDA_TYPE_LONG64; - if (STR_IEQUALS(type, "ulong64")) return UDA_TYPE_UNSIGNED_LONG64; - if (STR_IEQUALS(type, "unsigned long64")) return UDA_TYPE_UNSIGNED_LONG64; - if (STR_IEQUALS(type, "unsigned long long")) return UDA_TYPE_UNSIGNED_LONG64; - if (STR_IEQUALS(type, "long")) return UDA_TYPE_LONG; - if (STR_IEQUALS(type, "unsigned long")) return UDA_TYPE_UNSIGNED_LONG; - if (STR_IEQUALS(type, "int")) return UDA_TYPE_INT; - if (STR_IEQUALS(type, "integer")) return UDA_TYPE_INT; - if (STR_IEQUALS(type, "unsigned")) return UDA_TYPE_UNSIGNED_INT; - if (STR_IEQUALS(type, "unsigned int")) return UDA_TYPE_UNSIGNED_INT; - if (STR_IEQUALS(type, "unsigned integer")) return UDA_TYPE_UNSIGNED_INT; - if (STR_IEQUALS(type, "short")) return UDA_TYPE_SHORT; - if (STR_IEQUALS(type, "unsigned short")) return UDA_TYPE_UNSIGNED_SHORT; - if (STR_IEQUALS(type, "char")) return UDA_TYPE_CHAR; - if (STR_IEQUALS(type, "unsigned char")) return UDA_TYPE_UNSIGNED_CHAR; - if (STR_IEQUALS(type, "unknown")) return UDA_TYPE_UNKNOWN; - if (STR_IEQUALS(type, "undefined")) return UDA_TYPE_UNDEFINED; - - if (STR_IEQUALS(type, "vlen")) return UDA_TYPE_VLEN; - if (STR_IEQUALS(type, "compound")) return UDA_TYPE_COMPOUND; - if (STR_IEQUALS(type, "opaque")) return UDA_TYPE_OPAQUE; - if (STR_IEQUALS(type, "enum")) return UDA_TYPE_ENUM; - if (STR_IEQUALS(type, "string")) return UDA_TYPE_STRING; - if (STR_IEQUALS(type, "void")) return UDA_TYPE_VOID; - - if (STR_IEQUALS(type, "string *")) return UDA_TYPE_STRING; + if (STR_IEQUALS(type, "dcomplex")) { + return UDA_TYPE_DCOMPLEX; + } + if (STR_IEQUALS(type, "complex")) { + return UDA_TYPE_COMPLEX; + } + if (STR_IEQUALS(type, "double")) { + return UDA_TYPE_DOUBLE; + } + if (STR_IEQUALS(type, "float")) { + return UDA_TYPE_FLOAT; + } + if (STR_IEQUALS(type, "long64")) { + return UDA_TYPE_LONG64; + } + if (STR_IEQUALS(type, "long long")) { + return UDA_TYPE_LONG64; + } + if (STR_IEQUALS(type, "ulong64")) { + return UDA_TYPE_UNSIGNED_LONG64; + } + if (STR_IEQUALS(type, "unsigned long64")) { + return UDA_TYPE_UNSIGNED_LONG64; + } + if (STR_IEQUALS(type, "unsigned long long")) { + return UDA_TYPE_UNSIGNED_LONG64; + } + if (STR_IEQUALS(type, "long")) { + return UDA_TYPE_LONG; + } + if (STR_IEQUALS(type, "unsigned long")) { + return UDA_TYPE_UNSIGNED_LONG; + } + if (STR_IEQUALS(type, "int")) { + return UDA_TYPE_INT; + } + if (STR_IEQUALS(type, "integer")) { + return UDA_TYPE_INT; + } + if (STR_IEQUALS(type, "unsigned")) { + return UDA_TYPE_UNSIGNED_INT; + } + if (STR_IEQUALS(type, "unsigned int")) { + return UDA_TYPE_UNSIGNED_INT; + } + if (STR_IEQUALS(type, "unsigned integer")) { + return UDA_TYPE_UNSIGNED_INT; + } + if (STR_IEQUALS(type, "short")) { + return UDA_TYPE_SHORT; + } + if (STR_IEQUALS(type, "unsigned short")) { + return UDA_TYPE_UNSIGNED_SHORT; + } + if (STR_IEQUALS(type, "char")) { + return UDA_TYPE_CHAR; + } + if (STR_IEQUALS(type, "unsigned char")) { + return UDA_TYPE_UNSIGNED_CHAR; + } + if (STR_IEQUALS(type, "unknown")) { + return UDA_TYPE_UNKNOWN; + } + if (STR_IEQUALS(type, "undefined")) { + return UDA_TYPE_UNDEFINED; + } + + if (STR_IEQUALS(type, "vlen")) { + return UDA_TYPE_VLEN; + } + if (STR_IEQUALS(type, "compound")) { + return UDA_TYPE_COMPOUND; + } + if (STR_IEQUALS(type, "opaque")) { + return UDA_TYPE_OPAQUE; + } + if (STR_IEQUALS(type, "enum")) { + return UDA_TYPE_ENUM; + } + if (STR_IEQUALS(type, "string")) { + return UDA_TYPE_STRING; + } + if (STR_IEQUALS(type, "void")) { + return UDA_TYPE_VOID; + } + + if (STR_IEQUALS(type, "string *")) { + return UDA_TYPE_STRING; + } return UDA_TYPE_UNKNOWN; } @@ -1069,7 +1270,7 @@ void getIdamErrorModel(int handle, int* model, int* param_n, float* params) return; } *model = data_blocks[handle].error_model; // Model ID - *param_n = data_blocks[handle].error_param_n; // Number of parameters + *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]; } @@ -1077,7 +1278,9 @@ void getIdamErrorModel(int handle, int* model, int* param_n, float* params) int getIdamErrorAsymmetry(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return (int)data_blocks[handle].errasymmetry; } @@ -1088,23 +1291,35 @@ int getIdamErrorModelId(const char* model) for (int i = 1; i < ERROR_MODEL_UNDEFINED; i++) { switch (i) { case 1: - if (STR_IEQUALS(model, "default")) return ERROR_MODEL_DEFAULT; + if (STR_IEQUALS(model, "default")) { + return ERROR_MODEL_DEFAULT; + } break; case 2: - if (STR_IEQUALS(model, "default_asymmetric")) return ERROR_MODEL_DEFAULT_ASYMMETRIC; + if (STR_IEQUALS(model, "default_asymmetric")) { + return ERROR_MODEL_DEFAULT_ASYMMETRIC; + } break; #ifdef NO_GSL_LIB case 3: - if (STR_IEQUALS(model, "gaussian")) return ERROR_MODEL_GAUSSIAN; + if (STR_IEQUALS(model, "gaussian")) { + return ERROR_MODEL_GAUSSIAN; + } break; case 4: - if (STR_IEQUALS(model, "reseed")) return ERROR_MODEL_RESEED; + if (STR_IEQUALS(model, "reseed")) { + return ERROR_MODEL_RESEED; + } break; case 5: - if (STR_IEQUALS(model, "gaussian_shift")) return ERROR_MODEL_GAUSSIAN_SHIFT; + if (STR_IEQUALS(model, "gaussian_shift")) { + return ERROR_MODEL_GAUSSIAN_SHIFT; + } break; case 6: - if (STR_IEQUALS(model, "poisson")) return ERROR_MODEL_POISSON; + if (STR_IEQUALS(model, "poisson")) { + return ERROR_MODEL_POISSON; + } break; #endif default: @@ -1116,25 +1331,33 @@ int getIdamErrorModelId(const char* model) char* acc_getSyntheticData(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].synthetic; } char* acc_getSyntheticDimData(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].dims[ndim].synthetic; } void acc_setSyntheticData(int handle, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].synthetic = data; } void acc_setSyntheticDimData(int handle, int ndim, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].dims[ndim].synthetic = data; } @@ -1143,9 +1366,15 @@ char* getIdamSyntheticData(int handle) CLIENT_FLAGS* client_flags = udaClientFlags(); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; - if (status == MIN_STATUS && !data_blocks[handle].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)) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } + if (status == MIN_STATUS && !data_blocks[handle].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)) { + return nullptr; + } if (!client_flags->get_synthetic || data_blocks[handle].error_model == ERROR_MODEL_UNKNOWN) { return data_blocks[handle].data; } @@ -1156,16 +1385,23 @@ char* getIdamSyntheticData(int handle) //! Returns a pointer to the requested data /** The data may be synthetically generated. \param handle The data object handle -\return a pointer to the data - if the status is poor, a nullptr pointer is returned unless the \e get_bad property is set. +\return a pointer to the data - if the status is poor, a nullptr pointer is returned unless the \e get_bad property is +set. */ char* getIdamData(int handle) { CLIENT_FLAGS* client_flags = udaClientFlags(); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; - if (status == MIN_STATUS && !data_blocks[handle].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)) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } + if (status == MIN_STATUS && !data_blocks[handle].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)) { + return nullptr; + } if (!client_flags->get_synthetic) { return data_blocks[handle].data; } else { @@ -1181,98 +1417,126 @@ char* getIdamData(int handle) */ void getIdamDataTdi(int handle, char* data) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } memcpy(data, (void*)data_blocks[handle].data, (int)data_blocks[handle].data_n); } char* getIdamDataErrLo(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].errlo; } char* getIdamDataErrHi(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].errhi; } int getIdamDataErrAsymmetry(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].errasymmetry; } void acc_setIdamDataErrAsymmetry(int handle, int asymmetry) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].errasymmetry = asymmetry; }; void acc_setIdamDataErrType(int handle, int type) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].error_type = type; }; void acc_setIdamDataErrLo(int handle, char* errlo) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].errlo = errlo; }; char* getIdamDimErrLo(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].dims[ndim].errlo; } char* getIdamDimErrHi(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } return data_blocks[handle].dims[ndim].errhi; } int getIdamDimErrAsymmetry(int handle, int ndim) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return 0; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return 0; + } return data_blocks[handle].dims[ndim].errasymmetry; } void acc_setIdamDimErrAsymmetry(int handle, int ndim, int asymmetry) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].dims[ndim].errasymmetry = asymmetry; }; void acc_setIdamDimErrType(int handle, int ndim, int type) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].dims[ndim].error_type = type; }; void acc_setIdamDimErrLo(int handle, int ndim, char* errlo) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } data_blocks[handle].dims[ndim].errlo = errlo; }; char* getIdamAsymmetricError(int handle, int above) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return nullptr; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return nullptr; + } if (data_blocks[handle].error_type != UDA_TYPE_UNKNOWN) { if (above) { - return data_blocks[handle].errhi; // return the default error array + return data_blocks[handle].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 + return data_blocks[handle].errhi; // return the default error array if symmetric errors } else { return data_blocks[handle].errlo; - } // otherwise the data array must have been returned by the server or generated + } // otherwise the data array must have been returned by the server or generated } } else { if (data_blocks[handle].error_model != ERROR_MODEL_UNKNOWN) { - generateIdamDataError(handle); // Create the errors from a model if the model exits + 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) { @@ -1282,12 +1546,13 @@ char* getIdamAsymmetricError(int handle, int above) } } else { - char* errhi = nullptr; // Regular Error Component - char* errlo = nullptr; // Asymmetric Error Component + char* errhi = nullptr; // Regular Error Component + 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 + data_blocks[handle].error_type = + data_blocks[handle].data_type; // Error Type is Unknown so Assume Data's Data Type if (allocArray(data_blocks[handle].error_type, ndata, &errhi) != 0) { // Allocate Heap for Regular Error Data @@ -1297,7 +1562,7 @@ char* getIdamAsymmetricError(int handle, int above) data_blocks[handle].errhi = errhi; } - if (data_blocks[handle].errasymmetry) { // Allocate Heap for the Asymmetric Error Data + if (data_blocks[handle].errasymmetry) { // Allocate Heap for the Asymmetric Error Data if (allocArray(data_blocks[handle].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"); @@ -1312,129 +1577,179 @@ char* getIdamAsymmetricError(int handle, int above) switch (data_blocks[handle].data_type) { case UDA_TYPE_FLOAT: { - float* fh, * fl = nullptr; + float *fh, *fl = nullptr; fh = (float*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) fl = (float*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + fl = (float*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(fh + i) = (float)0.0; - if (data_blocks[handle].errasymmetry) *(fl + i) = (float)0.0; + if (data_blocks[handle].errasymmetry) { + *(fl + i) = (float)0.0; + } } break; } case UDA_TYPE_DOUBLE: { - double* dh, * dl = nullptr; + double *dh, *dl = nullptr; dh = (double*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) dl = (double*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + dl = (double*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(dh + i) = (double)0.0; - if (data_blocks[handle].errasymmetry) *(dl + i) = (double)0.0; + if (data_blocks[handle].errasymmetry) { + *(dl + i) = (double)0.0; + } } break; } case UDA_TYPE_SHORT: { - short* sh, * sl = nullptr; + short *sh, *sl = nullptr; sh = (short*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) sl = (short*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + sl = (short*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(sh + i) = (short)0; - if (data_blocks[handle].errasymmetry) *(sl + i) = (short)0; + if (data_blocks[handle].errasymmetry) { + *(sl + i) = (short)0; + } } break; } case UDA_TYPE_UNSIGNED_SHORT: { - unsigned short* sh, * sl = nullptr; + unsigned short *sh, *sl = nullptr; sh = (unsigned short*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) sl = (unsigned short*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + sl = (unsigned short*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { sh[i] = (unsigned short)0; - if (data_blocks[handle].errasymmetry) sl[i] = (unsigned short)0; + if (data_blocks[handle].errasymmetry) { + sl[i] = (unsigned short)0; + } } break; } case UDA_TYPE_INT: { - int* ih, * il = nullptr; + int *ih, *il = nullptr; ih = (int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) il = (int*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + il = (int*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(ih + i) = (int)0; - if (data_blocks[handle].errasymmetry) *(il + i) = (int)0; + if (data_blocks[handle].errasymmetry) { + *(il + i) = (int)0; + } } break; } case UDA_TYPE_UNSIGNED_INT: { - unsigned int* uh, * ul = nullptr; + unsigned int *uh, *ul = nullptr; uh = (unsigned int*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) ul = (unsigned int*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + ul = (unsigned int*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(uh + i) = (unsigned int)0; - if (data_blocks[handle].errasymmetry) *(ul + i) = (unsigned int)0; + if (data_blocks[handle].errasymmetry) { + *(ul + i) = (unsigned int)0; + } } break; } case UDA_TYPE_LONG: { - long* lh, * ll = nullptr; + long *lh, *ll = nullptr; lh = (long*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) ll = (long*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + ll = (long*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(lh + i) = (long)0; - if (data_blocks[handle].errasymmetry) *(ll + i) = (long)0; + if (data_blocks[handle].errasymmetry) { + *(ll + i) = (long)0; + } } break; } case UDA_TYPE_UNSIGNED_LONG: { - unsigned long* lh, * ll = nullptr; + unsigned long *lh, *ll = nullptr; lh = (unsigned long*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) ll = (unsigned long*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + ll = (unsigned long*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long)0; - if (data_blocks[handle].errasymmetry) ll[i] = (unsigned long)0; + if (data_blocks[handle].errasymmetry) { + ll[i] = (unsigned long)0; + } } break; } case UDA_TYPE_LONG64: { - long long int* lh, * ll = nullptr; + 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; + if (data_blocks[handle].errasymmetry) { + ll = (long long int*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { *(lh + i) = (long long int)0; - if (data_blocks[handle].errasymmetry) *(ll + i) = (long long int)0; + if (data_blocks[handle].errasymmetry) { + *(ll + i) = (long long int)0; + } } break; } 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; + 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; + } for (int i = 0; i < ndata; i++) { - lh[i] = (unsigned long long int) 0; - if (data_blocks[handle].errasymmetry) ll[i] = (unsigned long long int) 0; + lh[i] = (unsigned long long int)0; + if (data_blocks[handle].errasymmetry) { + ll[i] = (unsigned long long int)0; + } } break; } case UDA_TYPE_CHAR: { - char* ch, * cl = nullptr; + char *ch, *cl = nullptr; ch = data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) cl = data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + cl = data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { ch[i] = (char)0; - if (data_blocks[handle].errasymmetry) cl[i] = (char)0; + if (data_blocks[handle].errasymmetry) { + cl[i] = (char)0; + } } break; } case UDA_TYPE_UNSIGNED_CHAR: { - unsigned char* ch, * cl = nullptr; + unsigned char *ch, *cl = nullptr; ch = (unsigned char*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) cl = (unsigned char*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + cl = (unsigned char*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { ch[i] = (unsigned char)0; - if (data_blocks[handle].errasymmetry) cl[i] = (unsigned char)0; + if (data_blocks[handle].errasymmetry) { + cl[i] = (unsigned char)0; + } } break; } case UDA_TYPE_DCOMPLEX: { - DCOMPLEX* ch, * cl = nullptr; + DCOMPLEX *ch, *cl = nullptr; ch = (DCOMPLEX*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) cl = (DCOMPLEX*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + cl = (DCOMPLEX*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { ch[i].real = (double)0.0; ch[i].imaginary = (double)0.0; @@ -1446,9 +1761,11 @@ char* getIdamAsymmetricError(int handle, int above) break; } case UDA_TYPE_COMPLEX: { - COMPLEX* ch, * cl = nullptr; + COMPLEX *ch, *cl = nullptr; ch = (COMPLEX*)data_blocks[handle].errhi; - if (data_blocks[handle].errasymmetry) cl = (COMPLEX*)data_blocks[handle].errlo; + if (data_blocks[handle].errasymmetry) { + cl = (COMPLEX*)data_blocks[handle].errlo; + } for (int i = 0; i < ndata; i++) { ch[i].real = (float)0.0; ch[i].imaginary = (float)0.0; @@ -1487,11 +1804,9 @@ char* getIdamError(int handle) } //! Returns data cast to double precision -/** The copy buffer must be preallocated and sized for the data type. The data may be synthetically generated. If the status of the data is poor, no copy to the buffer occurs unless -the property \b get_bad is set. -\param handle The data object handle -\param fp A \b double pointer to a preallocated data buffer -\return void +/** The copy buffer must be preallocated and sized for the data type. The data may be synthetically generated. If the +status of the data is poor, no copy to the buffer occurs unless the property \b get_bad is set. \param handle The +data object handle \param fp A \b double pointer to a preallocated data buffer \return void */ void getIdamDoubleData(int handle, double* fp) { @@ -1502,21 +1817,27 @@ void getIdamDoubleData(int handle, double* fp) CLIENT_FLAGS* client_flags = udaClientFlags(); int status = getIdamDataStatus(handle); - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) return; - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) return; - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) return; + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { + return; + } + if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + return; + } + if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + return; + } if (data_blocks[handle].data_type == UDA_TYPE_DOUBLE) { - if (!client_flags->get_synthetic) + if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(double)); - else { + } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) + if (data_blocks[handle].synthetic != nullptr) { memcpy((void*)fp, (void*)data_blocks[handle].synthetic, (size_t)data_blocks[handle].data_n * sizeof(double)); - else - memcpy((void*)fp, (void*)data_blocks[handle].data, - (size_t)data_blocks[handle].data_n * sizeof(double)); + } else { + memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(double)); + } return; } } else { @@ -1540,61 +1861,85 @@ void getIdamDoubleData(int handle, double* fp) switch (data_blocks[handle].data_type) { case UDA_TYPE_FLOAT: { auto dp = (float*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)sp[i]; + } break; } case UDA_TYPE_INT: { int* ip = (int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int*) array; - for (int i = 0; i < ndata; i++) fp[i] = (double) lp[i]; + auto lp = (unsigned long long int*)array; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)cp[i]; + } break; } case UDA_TYPE_UNKNOWN: { - for (int i = 0; i < ndata; i++) fp[i] = (double)0.0; // No Data ! + for (int i = 0; i < ndata; i++) { + fp[i] = (double)0.0; // No Data ! + } break; } case UDA_TYPE_DCOMPLEX: { @@ -1616,21 +1961,19 @@ void getIdamDoubleData(int handle, double* fp) break; } default: - for (int i = 0; i < ndata; i++) fp[i] = (double)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)0.0; + } break; - } return; } } - //! Returns data cast to single precision -/** The copy buffer must be preallocated and sized for the data type. The data may be synthetically generated. If the status of the data is poor, no copy to the buffer occurs unless -the property \b get_bad is set. -\param handle The data object handle -\param fp A \b float pointer to a preallocated data buffer -\return void +/** The copy buffer must be preallocated and sized for the data type. The data may be synthetically generated. If the +status of the data is poor, no copy to the buffer occurs unless the property \b get_bad is set. \param handle The +data object handle \param fp A \b float pointer to a preallocated data buffer \return void */ void getIdamFloatData(int handle, float* fp) { @@ -1644,20 +1987,24 @@ void getIdamFloatData(int handle, float* fp) if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { return; } - if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) return; - if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) return; + if (status == MIN_STATUS && !data_blocks[handle].client_block.get_bad && !client_flags->get_bad) { + return; + } + if (status != MIN_STATUS && (data_blocks[handle].client_block.get_bad || client_flags->get_bad)) { + return; + } if (data_blocks[handle].data_type == UDA_TYPE_FLOAT) { - if (!client_flags->get_synthetic) + if (!client_flags->get_synthetic) { memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(float)); - else { + } else { generateIdamSyntheticData(handle); - if (data_blocks[handle].synthetic != nullptr) + if (data_blocks[handle].synthetic != nullptr) { memcpy((void*)fp, (void*)data_blocks[handle].synthetic, (size_t)data_blocks[handle].data_n * sizeof(float)); - else - memcpy((void*)fp, (void*)data_blocks[handle].data, - (size_t)data_blocks[handle].data_n * sizeof(float)); + } else { + memcpy((void*)fp, (void*)data_blocks[handle].data, (size_t)data_blocks[handle].data_n * sizeof(float)); + } return; } } else { @@ -1681,61 +2028,85 @@ void getIdamFloatData(int handle, float* fp) switch (data_blocks[handle].data_type) { case UDA_TYPE_DOUBLE: { double* dp = (double*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { int* ip = (int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int*) array; - for (int i = 0; i < ndata; i++) fp[i] = (float) lp[i]; + auto lp = (unsigned long long int*)array; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNKNOWN: { - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; // No Data ! + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; // No Data ! + } break; } case UDA_TYPE_DCOMPLEX: { @@ -1757,9 +2128,10 @@ void getIdamFloatData(int handle, float* fp) break; } default: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; + } break; - } return; } @@ -1819,7 +2191,6 @@ void getIdamGenericData(int handle, void* data) } } - void getIdamFloatAsymmetricError(int handle, int above, float* fp) { // Copy Error Data cast as float to User Provided Array @@ -1838,18 +2209,18 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) switch (data_blocks[handle].error_type) { case UDA_TYPE_UNKNOWN: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; // No Error Data + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; // No Error Data + } 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)); - else - memcpy((void*)fp, (void*)data_blocks[handle].errlo, - (size_t)data_blocks[handle].data_n * sizeof(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)); + } else { + memcpy((void*)fp, (void*)data_blocks[handle].errlo, (size_t)data_blocks[handle].data_n * sizeof(float)); + } break; case UDA_TYPE_DOUBLE: { double* dp; @@ -1860,7 +2231,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { dp = (double*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { @@ -1872,7 +2245,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { sp = (short*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { @@ -1884,7 +2259,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { sp = (unsigned short*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { @@ -1896,7 +2273,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { ip = (int*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { @@ -1908,7 +2287,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { up = (unsigned int*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { @@ -1920,7 +2301,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { lp = (long*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { @@ -1932,7 +2315,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { lp = (unsigned long*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { @@ -1944,18 +2329,23 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { lp = (long long int*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } 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; - else - lp = (unsigned long long int*) data_blocks[handle].errlo; - for (int i = 0; i < ndata; i++) fp[i] = (float) lp[i]; + 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; + } else { + lp = (unsigned long long int*)data_blocks[handle].errlo; + } + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { @@ -1967,7 +2357,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { cp = data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { @@ -1979,7 +2371,9 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) } else { cp = (unsigned char*)data_blocks[handle].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_DCOMPLEX: { @@ -2015,9 +2409,10 @@ void getIdamFloatAsymmetricError(int handle, int above, float* fp) break; } default: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; + } break; - } } @@ -2212,8 +2607,8 @@ void getIdamDimErrorModel(int handle, int ndim, int* model, int* param_n, float* *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 + *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]; } @@ -2247,7 +2642,9 @@ char* getIdamDimData(int handle, int ndim) return nullptr; } CLIENT_FLAGS* client_flags = udaClientFlags(); - if (!client_flags->get_synthetic) return data_blocks[handle].dims[ndim].dim; + if (!client_flags->get_synthetic) { + return data_blocks[handle].dims[ndim].dim; + } return getIdamSyntheticDimData(handle, ndim); } @@ -2329,17 +2726,18 @@ void getIdamDoubleDimData(int handle, int ndim, double* fp) } CLIENT_FLAGS* client_flags = udaClientFlags(); if (data_blocks[handle].dims[ndim].data_type == UDA_TYPE_DOUBLE) { - if (!client_flags->get_synthetic) + 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)); - else { + } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) + 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)); - else + } else { memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(double)); + } return; } } else { @@ -2360,57 +2758,79 @@ void getIdamDoubleDimData(int handle, int ndim, double* fp) switch (data_blocks[handle].dims[ndim].data_type) { case UDA_TYPE_FLOAT: { auto dp = (float*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)sp[i]; + } break; } case UDA_TYPE_INT: { int* ip = (int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int*) array; - for (int i = 0; i < ndata; i++) fp[i] = (double) lp[i]; + auto lp = (unsigned long long int*)array; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (double)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)cp[i]; + } break; } case UDA_TYPE_DCOMPLEX: { @@ -2432,12 +2852,15 @@ void getIdamDoubleDimData(int handle, int ndim, double* fp) break; } case UDA_TYPE_UNKNOWN: - for (int i = 0; i < ndata; i++) fp[i] = (double)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)0.0; + } break; default: - for (int i = 0; i < ndata; i++) fp[i] = (double)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (double)0.0; + } break; - } return; } @@ -2456,21 +2879,22 @@ void getIdamFloatDimData(int handle, int ndim, float* fp) if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { - return; + return; } CLIENT_FLAGS* client_flags = udaClientFlags(); if (data_blocks[handle].dims[ndim].data_type == UDA_TYPE_FLOAT) { - if (!client_flags->get_synthetic) + 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)); - else { + } else { generateIdamSyntheticDimData(handle, ndim); - if (data_blocks[handle].dims[ndim].synthetic != nullptr) + 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)); - else + } else { memcpy((void*)fp, (void*)data_blocks[handle].dims[ndim].dim, (size_t)data_blocks[handle].dims[ndim].dim_n * sizeof(float)); + } return; } } else { @@ -2491,57 +2915,79 @@ void getIdamFloatDimData(int handle, int ndim, float* fp) switch (data_blocks[handle].dims[ndim].data_type) { case UDA_TYPE_DOUBLE: { auto dp = (double*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int*) array; - for (int i = 0; i < ndata; i++) fp[i] = (float) lp[i]; + auto lp = (unsigned long long int*)array; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_DCOMPLEX: { @@ -2563,10 +3009,14 @@ void getIdamFloatDimData(int handle, int ndim, float* fp) break; } case UDA_TYPE_UNKNOWN: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; + } break; default: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)0.0; + } break; } return; @@ -2644,28 +3094,27 @@ DIMS* getIdamDimBlock(int handle, int ndim) { if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { - return nullptr; + return nullptr; } return data_blocks[handle].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) { - return nullptr; + return nullptr; } if (data_blocks[handle].dims[ndim].error_type != UDA_TYPE_UNKNOWN) { if (above) { - return data_blocks[handle].dims[ndim].errhi; // return the default error array + return data_blocks[handle].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 + return data_blocks[handle].dims[ndim].errhi; // return the default error array if symmetric errors } else { return data_blocks[handle].dims[ndim].errlo; - } // otherwise the data array must have been returned by the server - } // or generated in a previous call + } // 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) { generateIdamDimDataError(handle, ndim); @@ -2679,7 +3128,8 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) 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 + data_blocks[handle].dims[ndim].error_type = + data_blocks[handle].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) { UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Dimensional Data Errors\n"); @@ -2688,7 +3138,7 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) data_blocks[handle].dims[ndim].errhi = errhi; } - if (data_blocks[handle].dims[ndim].errasymmetry) { // Allocate Heap for the Asymmetric Error Data + 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) { UDA_LOG(UDA_LOG_ERROR, "Heap Allocation Problem with Dimensional Asymmetric Errors\n"); UDA_LOG(UDA_LOG_ERROR, "Switching Asymmetry Off!\n"); @@ -2703,127 +3153,177 @@ char* getIdamDimAsymmetricError(int handle, int ndim, int above) 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + fl = (float*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { fh[i] = (float)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) fl[i] = (float)0.0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + fl[i] = (float)0.0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + dl = (double*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { dh[i] = (double)0.0; - if (data_blocks[handle].dims[ndim].errasymmetry) dl[i] = (double)0.0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + dl[i] = (double)0.0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + sl = (short*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { sh[i] = (short)0; - if (data_blocks[handle].dims[ndim].errasymmetry) sl[i] = (short)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + sl[i] = (short)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + sl = (unsigned short*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { sh[i] = (unsigned short)0; - if (data_blocks[handle].dims[ndim].errasymmetry) sl[i] = (unsigned short)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + sl[i] = (unsigned short)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + il = (int*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { ih[i] = (int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) il[i] = (int)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + il[i] = (int)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ul = (unsigned int*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { uh[i] = (unsigned int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) ul[i] = (unsigned int)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ul[i] = (unsigned int)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll = (long*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { lh[i] = (long)0; - if (data_blocks[handle].dims[ndim].errasymmetry) ll[i] = (long)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll[i] = (long)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll = (unsigned long*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { lh[i] = (unsigned long)0; - if (data_blocks[handle].dims[ndim].errasymmetry) ll[i] = (unsigned long)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll[i] = (unsigned long)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll = (long long int*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { lh[i] = (long long int)0; - if (data_blocks[handle].dims[ndim].errasymmetry) ll[i] = (long long int)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll[i] = (long long int)0; + } } break; } 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_blocks[handle].dims[ndim].errhi; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll = (unsigned long long int*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { - lh[i] = (unsigned long long int) 0; - if (data_blocks[handle].dims[ndim].errasymmetry) ll[i] = (unsigned long long int) 0; + lh[i] = (unsigned long long int)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + ll[i] = (unsigned long long int)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + cl = data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { *(ch + i) = ' '; - if (data_blocks[handle].dims[ndim].errasymmetry) *(cl + i) = ' '; + if (data_blocks[handle].dims[ndim].errasymmetry) { + *(cl + i) = ' '; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + cl = (unsigned char*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { ch[i] = (unsigned char)0; - if (data_blocks[handle].dims[ndim].errasymmetry) cl[i] = (unsigned char)0; + if (data_blocks[handle].dims[ndim].errasymmetry) { + cl[i] = (unsigned char)0; + } } break; } 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + cl = (DCOMPLEX*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { ch[i].real = (double)0.0; ch[i].imaginary = (double)0.0; @@ -2837,7 +3337,9 @@ 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; + if (data_blocks[handle].dims[ndim].errasymmetry) { + cl = (COMPLEX*)data_blocks[handle].dims[ndim].errlo; + } for (int i = 0; i < ndata; i++) { ch[i].real = (float)0.0; ch[i].imaginary = (float)0.0; @@ -2849,7 +3351,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_blocks[handle].dims[ndim].errhi; // Errors are Symmetric at this point } } } @@ -2865,7 +3367,7 @@ 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) { - return nullptr; + return nullptr; } return getIdamDimAsymmetricError(handle, ndim, above); } @@ -2876,18 +3378,20 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) if (handle < 0 || (unsigned int)handle >= data_blocks.size() || ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { - return; + return; } int ndata = data_blocks[handle].dims[ndim].dim_n; if (data_blocks[handle].dims[ndim].error_type == UDA_TYPE_UNKNOWN) { getIdamDimAsymmetricError(handle, ndim, above); - } // Create the Error Data prior to Casting + } // Create the Error Data prior to Casting switch (data_blocks[handle].dims[ndim].error_type) { case UDA_TYPE_UNKNOWN: - for (int i = 0; i < ndata; i++) fp[i] = (float)0.0; // No Error Data + 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) { @@ -2899,13 +3403,15 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } break; case UDA_TYPE_DOUBLE: { - double* dp; // Return Zeros if this data is requested unless Error is Modelled + 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; } else { dp = (double*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)dp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { @@ -2915,7 +3421,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { sp = (short*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { @@ -2925,7 +3433,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { sp = (unsigned short*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)sp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { @@ -2935,7 +3445,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { ip = (int*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)ip[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { @@ -2945,7 +3457,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { up = (unsigned int*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)up[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { @@ -2955,7 +3469,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { lp = (long*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { @@ -2965,7 +3481,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { lp = (unsigned long*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)lp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { @@ -2975,7 +3493,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { cp = data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { @@ -2985,7 +3505,9 @@ void getIdamFloatDimAsymmetricError(int handle, int ndim, int above, float* fp) } else { cp = (unsigned char*)data_blocks[handle].dims[ndim].errlo; } - for (int i = 0; i < ndata; i++) fp[i] = (float)cp[i]; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)cp[i]; + } break; } case UDA_TYPE_DCOMPLEX: { @@ -3052,9 +3574,7 @@ DATA_SYSTEM* getIdamDataSystem(int handle) */ SYSTEM_CONFIG* getIdamSystemConfig(int handle) { - if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { - - } + if (handle < 0 || (unsigned int)handle >= data_blocks.size()) {} return nullptr; return data_blocks[handle].system_config; } @@ -3109,7 +3629,9 @@ const char* getIdamFileFormat(int handle) return nullptr; } DATA_SOURCE* data_source = getIdamDataSource(handle); - if (data_source == nullptr) return nullptr; + if (data_source == nullptr) { + return nullptr; + } return data_source->format; } @@ -3133,90 +3655,128 @@ int idamDataCheckSum(void* data, int data_n, int type) case UDA_TYPE_FLOAT: { float fsum = 0.0; auto dp = (float*)data; - for (int i = 0; i < data_n; i++) if (std::isfinite(dp[i])) fsum = fsum + dp[i]; + for (int i = 0; i < data_n; i++) { + if (std::isfinite(dp[i])) { + fsum = fsum + dp[i]; + } + } sum = (int)fsum; - if (sum == 0) sum = (int)(1000000.0 * fsum); // Rescale + if (sum == 0) { + sum = (int)(1000000.0 * fsum); // Rescale + } break; } case UDA_TYPE_DOUBLE: { double fsum = 0.0; auto dp = (double*)data; - for (int i = 0; i < data_n; i++) if (std::isfinite(dp[i])) fsum = fsum + dp[i]; + for (int i = 0; i < data_n; i++) { + if (std::isfinite(dp[i])) { + fsum = fsum + dp[i]; + } + } sum = (int)fsum; - if (sum == 0) sum = (int)(1000000.0 * fsum); // Rescale + if (sum == 0) { + sum = (int)(1000000.0 * fsum); // Rescale + } break; } case UDA_TYPE_COMPLEX: { float fsum = 0.0; auto dp = (COMPLEX*)data; - for (int i = 0; i < data_n; i++) + for (int i = 0; i < data_n; i++) { if (std::isfinite(dp[i].real) && std::isfinite(dp[i].imaginary)) { fsum = fsum + dp[i].real + dp[i].imaginary; } + } sum = (int)fsum; - if (sum == 0) sum = (int)(1000000.0 * fsum); // Rescale + if (sum == 0) { + sum = (int)(1000000.0 * fsum); // Rescale + } break; } case UDA_TYPE_DCOMPLEX: { double fsum = 0.0; auto dp = (DCOMPLEX*)data; - for (int i = 0; i < data_n; i++) + for (int i = 0; i < data_n; i++) { if (std::isfinite(dp[i].real) && std::isfinite(dp[i].imaginary)) { fsum = fsum + dp[i].real + dp[i].imaginary; } + } sum = (int)fsum; - if (sum == 0) sum = (int)(1000000.0 * fsum); // Rescale + if (sum == 0) { + sum = (int)(1000000.0 * fsum); // Rescale + } break; } case UDA_TYPE_CHAR: { char* dp = (char*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto dp = (short int*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_INT: { int* dp = (int*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_LONG: { auto dp = (long*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_LONG64: { auto dp = (long long int*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto dp = (unsigned char*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto dp = (unsigned short int*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto dp = (unsigned int*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto dp = (unsigned long*)data; - for (int i = 0; i < data_n; i++) sum = sum + (int)dp[i]; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto dp = (unsigned long long int*) data; - for (int i = 0; i < data_n; i++) sum = sum + (int) dp[i]; + auto dp = (unsigned long long int*)data; + for (int i = 0; i < data_n; i++) { + sum = sum + (int)dp[i]; + } break; } default: @@ -3230,10 +3790,12 @@ int getIdamDataCheckSum(int handle) if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { return 0; } - if (data_blocks[handle].errcode != 0) return 0; + if (data_blocks[handle].errcode != 0) { + return 0; + } - return (idamDataCheckSum((void*)data_blocks[handle].data, data_blocks[handle].data_n, - data_blocks[handle].data_type)); + return ( + idamDataCheckSum((void*)data_blocks[handle].data, data_blocks[handle].data_n, data_blocks[handle].data_type)); } int getIdamDimDataCheckSum(int handle, int ndim) @@ -3241,7 +3803,9 @@ int getIdamDimDataCheckSum(int handle, int ndim) if (handle < 0 || (unsigned int)handle >= data_blocks.size()) { return 0; } - if (data_blocks[handle].errcode != 0) return 0; + if (data_blocks[handle].errcode != 0) { + return 0; + } if (ndim < 0 || (unsigned int)ndim >= data_blocks[handle].rank) { return 0; } @@ -3257,8 +3821,8 @@ void getIdamClientSerialisedDataBlock(int handle, void** object, size_t* objectS int protocolVersion, LOGSTRUCTLIST* log_struct_list, int private_flags, int malloc_source) { - // Extract the serialised Data Block from Cache or serialise it if not cached (hash key in Data Block, empty if not cached) - // Use Case: extract data in object form for storage in external data object store, e.g. CEPH, HDF5 + // Extract the serialised Data Block from Cache or serialise it if not cached (hash key in Data Block, empty if not + // cached) Use Case: extract data in object form for storage in external data object store, e.g. CEPH, HDF5 /* * TODO * @@ -3299,7 +3863,7 @@ void getIdamClientSerialisedDataBlock(int handle, void** object, size_t* objectS fread(buffer, bufsize, 1, memfile); #endif - xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs + xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs fclose(memfile); // return the serialised data object and key @@ -3316,8 +3880,12 @@ void getIdamClientSerialisedDataBlock(int handle, void** object, size_t* objectS int setIdamDataTree(int handle) { - if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) return 0; // Return FALSE - if (getIdamData(handle) == nullptr) return 0; + if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) { + return 0; // Return FALSE + } + if (getIdamData(handle) == nullptr) { + return 0; + } udaSetFullNTree((NTREE*)getIdamData(handle)); void* opaque_block = getIdamDataOpaqueBlock(handle); @@ -3331,7 +3899,9 @@ int setIdamDataTree(int handle) NTREE* getIdamDataTree(int handle) { - if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) return nullptr; + if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) { + return nullptr; + } return (NTREE*)getIdamData(handle); } @@ -3339,21 +3909,27 @@ NTREE* getIdamDataTree(int handle) USERDEFINEDTYPE* getIdamUserDefinedType(int handle) { - if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) return nullptr; + if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) { + return nullptr; + } void* opaque_block = getIdamDataOpaqueBlock(handle); return ((GENERAL_BLOCK*)opaque_block)->userdefinedtype; } USERDEFINEDTYPELIST* getIdamUserDefinedTypeList(int handle) { - if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) return nullptr; + if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) { + return nullptr; + } void* opaque_block = getIdamDataOpaqueBlock(handle); return ((GENERAL_BLOCK*)opaque_block)->userdefinedtypelist; } LOGMALLOCLIST* getIdamLogMallocList(int handle) { - if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) return nullptr; + if (getIdamDataOpaqueType(handle) != UDA_OPAQUE_TYPE_STRUCTURES) { + return nullptr; + } void* opaque_block = getIdamDataOpaqueBlock(handle); return ((GENERAL_BLOCK*)opaque_block)->logmalloclist; } diff --git a/source/c_api/clientAPI.cpp b/source/c_api/clientAPI.cpp old mode 100755 new mode 100644 index 4f3aa1ed..62452b69 --- a/source/c_api/clientAPI.cpp +++ b/source/c_api/clientAPI.cpp @@ -7,13 +7,13 @@ # define strcasecmp _stricmp #endif -#include "logging/logging.h" -#include "initStructs.h" #include "clientserver/errorLog.h" +#include "initStructs.h" +#include "logging/logging.h" +#include "client.h" #include "client/makeClientRequestBlock.h" #include "client/startup.h" -#include "client.h" int idamClientAPI(const char* file, const char* signal, int pass, int exp_number) { @@ -26,7 +26,9 @@ int idamClientAPI(const char* file, const char* signal, int pass, int exp_number CLIENT_FLAGS* client_flags = udaClientFlags(); - if (udaStartup(0, client_flags, &reopen_logs) != 0) return PROBLEM_OPENING_LOGS; + if (udaStartup(0, client_flags, &reopen_logs) != 0) { + return PROBLEM_OPENING_LOGS; + } //------------------------------------------------------------------------- // Initialise the Client Data Request Structure @@ -46,10 +48,11 @@ int idamClientAPI(const char* file, const char* signal, int pass, int exp_number int err; char data_source[STRING_LENGTH + 1]; if (strlen(file) == 0) { - if (pass < 0) + if (pass < 0) { snprintf(data_source, STRING_LENGTH + 1, "%d", exp_number); - else + } else { snprintf(data_source, STRING_LENGTH + 1, "%d/%d", exp_number, pass); + } } else { strcpy(data_source, file); } @@ -75,16 +78,16 @@ int idamClientAPI(const char* file, const char* signal, int pass, int exp_number } /*--------------------------------------------------------------- -* Reads the Requested Data -* -* Input Arguments: 1) File Name -* 2) Signal Name -* 3) File Format -* 4) Plasma Pulse/Experiment Number -* -* Returns: -* -*--------------------------------------------------------------*/ + * Reads the Requested Data + * + * Input Arguments: 1) File Name + * 2) Signal Name + * 3) File Format + * 4) Plasma Pulse/Experiment Number + * + * Returns: + * + *--------------------------------------------------------------*/ int idamClientFileAPI(const char* file, const char* signal, const char* format) { @@ -97,7 +100,9 @@ int idamClientFileAPI(const char* file, const char* signal, const char* format) CLIENT_FLAGS* client_flags = udaClientFlags(); - if (udaStartup(0, client_flags, &reopen_logs) != 0) return PROBLEM_OPENING_LOGS; + if (udaStartup(0, client_flags, &reopen_logs) != 0) { + return PROBLEM_OPENING_LOGS; + } //------------------------------------------------------------------------- // Initialise the Client Data Request Structure diff --git a/source/c_api/clientMDS.cpp b/source/c_api/clientMDS.cpp old mode 100755 new mode 100644 index 97c38793..d7158bd4 --- a/source/c_api/clientMDS.cpp +++ b/source/c_api/clientMDS.cpp @@ -1,11 +1,11 @@ #include "clientMDS.h" -#include "logging/logging.h" -#include "initStructs.h" #include "clientserver/protocol.h" +#include "initStructs.h" +#include "logging/logging.h" -#include "client/startup.h" #include "client.h" +#include "client/startup.h" /** * Reads the Requested Data @@ -24,7 +24,9 @@ int idamClientMDS(const char* server, const char* tree, const char* node, int tr CLIENT_FLAGS* client_flags = udaClientFlags(); static bool reopen_logs = true; - if (udaStartup(0, client_flags, &reopen_logs) != 0) return PROBLEM_OPENING_LOGS; + if (udaStartup(0, client_flags, &reopen_logs) != 0) { + return PROBLEM_OPENING_LOGS; + } //------------------------------------------------------------------------- // Passed Args diff --git a/source/c_api/udaGetAPI.cpp b/source/c_api/udaGetAPI.cpp old mode 100755 new mode 100644 index 5a690519..edfbf2de --- a/source/c_api/udaGetAPI.cpp +++ b/source/c_api/udaGetAPI.cpp @@ -1,12 +1,12 @@ /*--------------------------------------------------------------- -* Reads the Requested Data -* -* Input Arguments: 1) Signal Name (Alias or Generic) -* 2) Data Source or Experiment Number -* -* Returns: -* -*--------------------------------------------------------------*/ + * Reads the Requested Data + * + * Input Arguments: 1) Signal Name (Alias or Generic) + * 2) Data Source or Experiment Number + * + * Returns: + * + *--------------------------------------------------------------*/ #include "udaGetAPI.h" @@ -14,19 +14,19 @@ # include #endif -#include "logging/logging.h" -#include "initStructs.h" #include "clientserver/errorLog.h" #include "clientserver/printStructs.h" +#include "initStructs.h" +#include "logging/logging.h" -#include "client/makeClientRequestBlock.h" -#include "client/startup.h" -#include "client.h" #include "accAPI.h" +#include "client.h" #include "client/getEnvironment.h" +#include "client/makeClientRequestBlock.h" +#include "client/startup.h" #ifdef MEMDEBUG -#include +# include #endif //! the principal IDAM API @@ -56,22 +56,23 @@ Data source patterns:\n\n row 2, cell 1 -FORMAT::/path/to/my/file - a private file with a specified format. The server must have read access permission. +FORMAT::/path/to/my/file - a private file with a specified format. The server must have read access +permission. row 2, cell 1 -FORMAT::./path/to/my/file - relative paths are resolved by the client and must be accessible on the network by the server. -FORMAT::../path/to/my/file +FORMAT::./path/to/my/file - relative paths are resolved by the client and must be accessible on the network +by the server. FORMAT::../path/to/my/file row 2, cell 1 -FORMAT::/scratch/path/to/my/file user file directories local to the client's workstation may have to be changed. This is -done automatically using the environment variables: .... +FORMAT::/scratch/path/to/my/file user file directories local to the client's workstation may have to be +changed. This is done automatically using the environment variables: .... row 2, cell 1 -FORMAT::pulse FORMAT must be the default FORMAT, e.g. IDA3. The IDAM server treats this file as a private file and has -built-in rules to locate the source file within the data archive. +FORMAT::pulse FORMAT must be the default FORMAT, e.g. IDA3. The IDAM server treats this file as a private +file and has built-in rules to locate the source file within the data archive. row 2, cell 1 @@ -86,9 +87,8 @@ built-in rules to locate the source file within the data archive. row 2, cell 1 -DEVICE::FORMAT::/path/to/my/file The request is passed to a different data server identified by the DEVICE. There it is -treated as a private file with the default file FORMAT. -/pulse/pass +DEVICE::FORMAT::/path/to/my/file The request is passed to a different data server identified by the DEVICE. +There it is treated as a private file with the default file FORMAT. /pulse/pass row 2, cell 1 @@ -121,14 +121,11 @@ treated as a private file within the data archive if FORMAT is the default file -\b PROTOCOL::server.host.name:port/U/R/L server access requests - always requires the delimiter string element in string\n -\n -\b function(arguments or name value pair list) server side processing of data\n -\b LIBRARY::function(arguments or name value pair list) function plugin library \n -\b DEVICE::function(arguments or name value pair list) Not allowed - use DEVICE::SERVERSIDE::function()\n -\n -\b DEVICE::FORMAT:: ... If the DEVICE is not the default device, then a server protocol is invoked to pass - the request forward (FORMAT:: ...)\n\n +\b PROTOCOL::server.host.name:port/U/R/L server access requests - always requires the delimiter string element in +string\n \n \b function(arguments or name value pair list) server side processing of data\n \b +LIBRARY::function(arguments or name value pair list) function plugin library \n \b DEVICE::function(arguments or +name value pair list) Not allowed - use DEVICE::SERVERSIDE::function()\n \n \b DEVICE::FORMAT:: ... If +the DEVICE is not the default device, then a server protocol is invoked to pass the request forward (FORMAT:: ...)\n\n Legacy exception: treat PPF and JPF formats as server protocols => no file path expansion required and ignored\n \n \b PPF::/ddaname/pulse/pass/userid or PPF::ddaname/pulse/pass/userid\n @@ -139,7 +136,8 @@ Legacy exception: treat PPF and JPF formats as server protocols => no file path * @param data_source identifies the location of data. * @return a reference ID handle used to identify the accessed data in subsequent API accessor function calls. */ -int idamGetAPI(const char* data_object, const char* data_source) { +int idamGetAPI(const char* data_object, const char* data_source) +{ return idamGetAPIWithHost(data_object, data_source, nullptr, 0); } @@ -186,14 +184,16 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c // Log all Arguments passed from Application #ifdef ARGSTACK - if(argstack == nullptr) { + if (argstack == nullptr) { char tempFile[] = "/tmp/idamStackXXXXXX"; mkstemp(tempFile); argstack = fopen(tempFile, environment.logmode); - if(argstack != nullptr) fprintf(argstack, "idamGetAPI\n"); + if (argstack != nullptr) { + fprintf(argstack, "idamGetAPI\n"); + } } - if(argstack != nullptr) { - fprintf(argstack,"[%s][%s]\n", data_object, data_source); + if (argstack != nullptr) { + fprintf(argstack, "[%s][%s]\n", data_object, data_source); fflush(argstack); } #endif @@ -227,7 +227,7 @@ int idamGetAPIWithHost(const char* data_object, const char* data_source, const c // Fetch Data #ifdef TESTSERVERCLIENT - unlockIdamThread(); + unlockIdamThread(); return -1; #endif @@ -255,7 +255,8 @@ int idamGetBatchAPI(const char** signals, const char** sources, int count, int* return idamGetBatchAPIWithHost(signals, sources, count, handles, nullptr, 0); } -int idamGetBatchAPIWithHost(const char** signals, const char** sources, int count, int* handles, const char* host, int port) +int idamGetBatchAPIWithHost(const char** signals, const char** sources, int count, int* handles, const char* host, + int port) { CLIENT_FLAGS* client_flags = udaClientFlags(); @@ -297,14 +298,16 @@ int idamGetBatchAPIWithHost(const char** signals, const char** sources, int coun // Log all Arguments passed from Application #ifdef ARGSTACK - if(argstack == nullptr) { + if (argstack == nullptr) { char tempFile[] = "/tmp/idamStackXXXXXX"; mkstemp(tempFile); argstack = fopen(tempFile, environment.logmode); - if(argstack != nullptr) fprintf(argstack, "idamGetAPI\n"); + if (argstack != nullptr) { + fprintf(argstack, "idamGetAPI\n"); + } } - if(argstack != nullptr) { - fprintf(argstack,"[%s][%s]\n", data_object, data_source); + if (argstack != nullptr) { + fprintf(argstack, "[%s][%s]\n", data_object, data_source); fflush(argstack); } #endif diff --git a/source/c_api/udaPutAPI.cpp b/source/c_api/udaPutAPI.cpp old mode 100755 new mode 100644 index 3eaaa431..437b08ec --- a/source/c_api/udaPutAPI.cpp +++ b/source/c_api/udaPutAPI.cpp @@ -1,19 +1,19 @@ /*--------------------------------------------------------------- -* Puts the passed Data to the serverside plugin -* -* Input Arguments: 1) plugin library call -* 2) the data passed to the plugin -* -* Returns: -*--------------------------------------------------------------*/ + * Puts the passed Data to the serverside plugin + * + * Input Arguments: 1) plugin library call + * 2) the data passed to the plugin + * + * Returns: + *--------------------------------------------------------------*/ #include "udaPutAPI.h" -#include "logging/logging.h" -#include "initStructs.h" +#include "clientserver/allocData.h" #include "clientserver/errorLog.h" #include "clientserver/printStructs.h" -#include "clientserver/allocData.h" +#include "initStructs.h" +#include "logging/logging.h" #include "client/makeClientRequestBlock.h" #include "client/udaClient.h" @@ -41,33 +41,33 @@ int idamPutListAPI(const char* putInstruction, PUTDATA_BLOCK_LIST* inPutDataBloc //------------------------------------------------------------------------- // Pass an empty structure rather than nullptr (Caller is responsible for freeing) - if (inPutDataBlockList != nullptr) + if (inPutDataBlockList != nullptr) { putDataBlockList = inPutDataBlockList; - else { + } else { putDataBlockList = &emptyPutDataBlockList; initPutDataBlockList(putDataBlockList); } -//------------------------------------------------------------------------- -// All client/server initialisation is controlled by the main API: idamGetAPI -// This needs to have been called at least once before a put! - *** temporary fix!!! -// This problem also causes the application malloclog and the userdefinedtypelist heaps to be overwritten. -// Copy and replace to preserve the application heap - -/* #ifndef FATCLIENT */ -/* if (!idamGetAPICalledOnce) { */ -/* LOGMALLOCLIST* oldlogmalloclist = logmalloclist; */ -/* USERDEFINEDTYPELIST* olduserdefinedtypelist = userdefinedtypelist; */ -/* logmalloclist = nullptr; */ -/* userdefinedtypelist = nullptr; */ -/* int h = idamGetAPI("help::ping()", ""); */ -/* udaFree(h); */ -/* idamGetAPICalledOnce = 1; */ -/* lastMallocIndex = 0; */ -/* logmalloclist = oldlogmalloclist; */ -/* userdefinedtypelist = olduserdefinedtypelist; */ -/* } */ -/* #endif */ + //------------------------------------------------------------------------- + // All client/server initialisation is controlled by the main API: idamGetAPI + // This needs to have been called at least once before a put! - *** temporary fix!!! + // This problem also causes the application malloclog and the userdefinedtypelist heaps to be overwritten. + // Copy and replace to preserve the application heap + + /* #ifndef FATCLIENT */ + /* if (!idamGetAPICalledOnce) { */ + /* LOGMALLOCLIST* oldlogmalloclist = logmalloclist; */ + /* USERDEFINEDTYPELIST* olduserdefinedtypelist = userdefinedtypelist; */ + /* logmalloclist = nullptr; */ + /* userdefinedtypelist = nullptr; */ + /* int h = idamGetAPI("help::ping()", ""); */ + /* udaFree(h); */ + /* idamGetAPICalledOnce = 1; */ + /* lastMallocIndex = 0; */ + /* logmalloclist = oldlogmalloclist; */ + /* userdefinedtypelist = olduserdefinedtypelist; */ + /* } */ + /* #endif */ //------------------------------------------------------------------------- // Initialise the Client Data Request Structure @@ -105,10 +105,8 @@ int idamPutListAPI(const char* putInstruction, PUTDATA_BLOCK_LIST* inPutDataBloc } return handle; - } - // Send a single data block to the server int idamPutAPI(const char* putInstruction, PUTDATA_BLOCK* inPutData) @@ -121,34 +119,34 @@ int idamPutAPI(const char* putInstruction, PUTDATA_BLOCK* inPutData) //------------------------------------------------------------------------- // Pass an empty structure rather than nullptr (Caller is responsible for freeing) - if (inPutData != nullptr) + if (inPutData != nullptr) { putData = inPutData; - else { + } else { putData = &emptyPutDataBlock; initIdamPutDataBlock(putData); } -//------------------------------------------------------------------------- -// All client/server initialisation is controlled by the main API: idamGetAPI -// This needs to have been called at least once before a put! - *** temporary fix!!! -// This problem also causes the application malloclog and the userdefinedtypelist heaps to be overwritten. -// Copy and replace to preserve the application heap - -/* #ifndef FATCLIENT */ -/* if (!idamGetAPICalledOnce) { */ -/* UDA_LOG(LOG_DEBUG, "!idamGetAPICalledOnce\n"); */ -/* LOGMALLOCLIST* oldlogmalloclist = logmalloclist; */ -/* USERDEFINEDTYPELIST* olduserdefinedtypelist = userdefinedtypelist; */ -/* logmalloclist = nullptr; */ -/* userdefinedtypelist = nullptr; */ -/* int h = idamGetAPI("help::ping()", ""); */ -/* udaFree(h); */ -/* idamGetAPICalledOnce = 1; */ -/* lastMallocIndex = 0; */ -/* logmalloclist = oldlogmalloclist; */ -/* userdefinedtypelist = olduserdefinedtypelist; */ -/* } */ -/* #endif */ + //------------------------------------------------------------------------- + // All client/server initialisation is controlled by the main API: idamGetAPI + // This needs to have been called at least once before a put! - *** temporary fix!!! + // This problem also causes the application malloclog and the userdefinedtypelist heaps to be overwritten. + // Copy and replace to preserve the application heap + + /* #ifndef FATCLIENT */ + /* if (!idamGetAPICalledOnce) { */ + /* UDA_LOG(LOG_DEBUG, "!idamGetAPICalledOnce\n"); */ + /* LOGMALLOCLIST* oldlogmalloclist = logmalloclist; */ + /* USERDEFINEDTYPELIST* olduserdefinedtypelist = userdefinedtypelist; */ + /* logmalloclist = nullptr; */ + /* userdefinedtypelist = nullptr; */ + /* int h = idamGetAPI("help::ping()", ""); */ + /* udaFree(h); */ + /* idamGetAPICalledOnce = 1; */ + /* lastMallocIndex = 0; */ + /* logmalloclist = oldlogmalloclist; */ + /* userdefinedtypelist = olduserdefinedtypelist; */ + /* } */ + /* #endif */ //------------------------------------------------------------------------- // Initialise the Client Data Request Structure @@ -189,7 +187,4 @@ int idamPutAPI(const char* putInstruction, PUTDATA_BLOCK* inPutData) freeClientPutDataBlockList(&request_block.requests[0].putDataBlockList); return handle; - } - - diff --git a/source/cache/cache.cpp b/source/cache/cache.cpp index ce004a58..c558ff54 100644 --- a/source/cache/cache.cpp +++ b/source/cache/cache.cpp @@ -1,8 +1,8 @@ #include "cache.h" -#include -#include #include "initStructs.h" +#include +#include void writeCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, const DATA_BLOCK* data_block, int protocolVersion, LOGSTRUCTLIST* log_struct_list, @@ -18,12 +18,12 @@ void writeCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* protocol2(&xdrs, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_SEND, &token, logmalloclist, userdefinedtypelist, &data_block_list, protocolVersion, log_struct_list, private_flags, malloc_source); - xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs + xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs } -DATA_BLOCK* -readCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +DATA_BLOCK* readCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, + int malloc_source) { XDR xdrs; xdrstdio_create(&xdrs, fp, XDR_DECODE); @@ -35,7 +35,7 @@ readCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userd protocol2(&xdrs, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_RECEIVE, &token, logmalloclist, userdefinedtypelist, &data_block_list, protocolVersion, log_struct_list, private_flags, malloc_source); - xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs + xdr_destroy(&xdrs); // Destroy before the file otherwise a segmentation error occurs return data_block_list.data; } \ No newline at end of file diff --git a/source/cache/cache.h b/source/cache/cache.h index 5ca81953..bc5edbd0 100644 --- a/source/cache/cache.h +++ b/source/cache/cache.h @@ -1,10 +1,10 @@ #ifndef UDA_CACHE_CACHE_H #define UDA_CACHE_CACHE_H -#include -#include "udaStructs.h" -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include "udaStructs.h" +#include #ifdef __cplusplus extern "C" { @@ -14,9 +14,9 @@ LIBRARY_API void writeCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFI const DATA_BLOCK* data_block, int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source); -LIBRARY_API DATA_BLOCK* -readCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source); +LIBRARY_API DATA_BLOCK* readCacheData(FILE* fp, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, + int malloc_source); #ifdef __cplusplus } diff --git a/source/cache/fileCache.cpp b/source/cache/fileCache.cpp old mode 100755 new mode 100644 index 10b98e12..c49d5588 --- a/source/cache/fileCache.cpp +++ b/source/cache/fileCache.cpp @@ -42,38 +42,33 @@ int udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request } #else -#include "cache.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -constexpr int CACHE_MAXCOUNT = 100; // Max Attempts at obtaining a database table lock -constexpr int CACHE_HOURSVALID = 0; -constexpr int CACHE_MAXDEADRECORDS = 10; -constexpr int CACHE_MAXRECORDS = 1000; // Including comment records -constexpr int CACHE_STATSLENGTH = 30; -constexpr int CACHE_MAXLOCKTIME = 100; // Maximum Grace period after time expiry when a file record is locked - -namespace { - -enum class LockActionType : short +# include "cache.h" + +# include +# include +# include +# include +# include +# include +# include + +# include +# include +# include + +constexpr int CACHE_MAXCOUNT = 100; // Max Attempts at obtaining a database table lock +constexpr int CACHE_HOURSVALID = 0; +constexpr int CACHE_MAXDEADRECORDS = 10; +constexpr int CACHE_MAXRECORDS = 1000; // Including comment records +constexpr int CACHE_STATSLENGTH = 30; +constexpr int CACHE_MAXLOCKTIME = 100; // Maximum Grace period after time expiry when a file record is locked + +namespace { - READ = F_RDLCK, - WRITE = F_WRLCK, - UNLOCK = F_UNLCK -}; -struct CacheStats -{ +enum class LockActionType : short { READ = F_RDLCK, WRITE = F_WRLCK, UNLOCK = F_UNLCK }; + +struct CacheStats { unsigned long recordCount; unsigned long deadCount; long endOffset; @@ -85,8 +80,7 @@ enum class EntryState { LOCKED = 2, }; -struct CacheEntry -{ +struct CacheEntry { size_t file_position = 0; EntryState state = EntryState::DEAD; std::string signal; @@ -97,7 +91,7 @@ struct CacheEntry unsigned long dbkey = 0; }; -} // anon namespace +} // namespace static int set_db_file_lock_state(FILE* db, LockActionType type); static bool is_cache_time_valid(unsigned long long timestamp); @@ -130,7 +124,7 @@ std::string get_file_path(const std::string& filename) FILE* open_db_file(bool create) { // Open the Database Table and apply an Exclusive lock - const char* table = getenv("UDA_CACHE_TABLE"); // List of cached files + const char* table = getenv("UDA_CACHE_TABLE"); // List of cached files if (table == nullptr) { return nullptr; } @@ -162,7 +156,7 @@ int set_db_file_lock_state(FILE* db, LockActionType type) lock.l_len = 0; // To the end of the file lock.l_type = static_cast(type); // Lock type to apply - int rc = fcntl(fd, F_SETLK, &lock); // Manage the Cache table lock + int rc = fcntl(fd, F_SETLK, &lock); // Manage the Cache table lock if (rc == 0) { // Lock managed OK @@ -171,8 +165,7 @@ int set_db_file_lock_state(FILE* db, LockActionType type) if (type == LockActionType::UNLOCK) { int err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "cache file lock not released indicating problem with cache"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "cache file lock not released indicating problem with cache"); return err; } @@ -196,7 +189,7 @@ int set_db_file_lock_state(FILE* db, LockActionType type) return err; } - return 0; // Lock obtained + return 0; // Lock obtained } // Time stamp test @@ -344,7 +337,7 @@ boost::optional purge_cache(FILE* db) } using pair_type = std::pair; - std::sort(table.begin(), table.end(), [](const pair_type& a, const pair_type& b){ return a.first < b.first; }); + std::sort(table.begin(), table.end(), [](const pair_type& a, const pair_type& b) { return a.first < b.first; }); while (table.size() > CACHE_MAXRECORDS) { std::vector tokens; @@ -379,9 +372,9 @@ boost::optional purge_cache(FILE* db) return stats; } -DATA_BLOCK* -udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +DATA_BLOCK* udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { auto maybe_entry = find_cache_entry(request); if (!maybe_entry) { @@ -390,9 +383,9 @@ udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, USER auto entry = maybe_entry.get(); - if (!is_cache_file_valid(entry.filename) - || (entry.state == EntryState::LIVE && !is_cache_time_valid(entry.timestamp)) - || (entry.state == EntryState::LOCKED && !is_cache_locked_time_valid(entry.timestamp))) { + if (!is_cache_file_valid(entry.filename) || + (entry.state == EntryState::LIVE && !is_cache_time_valid(entry.timestamp)) || + (entry.state == EntryState::LOCKED && !is_cache_locked_time_valid(entry.timestamp))) { set_entry_state(entry, EntryState::DEAD); return nullptr; } else { @@ -408,8 +401,8 @@ udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, USER UDA_THROW_ERROR(0, "Unable to Open the Cached Data File"); } - auto data_block = readCacheData(xdrfile, logmalloclist, userdefinedtypelist, protocolVersion, - log_struct_list, private_flags, malloc_source); + auto data_block = readCacheData(xdrfile, logmalloclist, userdefinedtypelist, protocolVersion, log_struct_list, + private_flags, malloc_source); fclose(xdrfile); @@ -494,7 +487,7 @@ int set_entry_state(const CacheEntry& entry, EntryState state) snprintf(buffer, 3, "%d%c", static_cast(state), delimiter[0]); fwrite(buffer, sizeof(char), 2, db); - rc = set_db_file_lock_state(db, LockActionType::UNLOCK); // release lock + rc = set_db_file_lock_state(db, LockActionType::UNLOCK); // release lock fclose(db); return rc; @@ -511,7 +504,7 @@ boost::optional find_cache_entry(const REQUEST_DATA* request) unsigned int key = generate_hash_key(request); - fseek(db, CACHE_STATSLENGTH, SEEK_SET); // Position at the start of record 2 + fseek(db, CACHE_STATSLENGTH, SEEK_SET); // Position at the start of record 2 boost::optional found_entry; @@ -531,8 +524,7 @@ boost::optional find_cache_entry(const REQUEST_DATA* request) continue; } - if (key == entry.dbkey - && (entry.signal == request->signal && entry.source == request->source)) { + if (key == entry.dbkey && (entry.signal == request->signal && entry.source == request->source)) { found_entry = entry; break; } @@ -564,13 +556,8 @@ int add_cache_record(const REQUEST_DATA* request, const char* filename) // Create the new record string std::stringstream ss; constexpr int properties = 0; - ss << static_cast(EntryState::LIVE) << delimiter - << key << delimiter - << timestamp << delimiter - << filename << delimiter - << properties << delimiter - << request->signal << delimiter - << request->source << '\n'; + ss << static_cast(EntryState::LIVE) << delimiter << key << delimiter << timestamp << delimiter << filename + << delimiter << properties << delimiter << request->signal << delimiter << request->source << '\n'; std::string record = ss.str(); // Append the new record to the database table @@ -583,7 +570,7 @@ int add_cache_record(const REQUEST_DATA* request, const char* filename) // Current table statistics auto maybe_stats = get_cache_stats(db); if (!maybe_stats) { - rc = set_db_file_lock_state(db, LockActionType::UNLOCK); // Free the Lock and File + rc = set_db_file_lock_state(db, LockActionType::UNLOCK); // Free the Lock and File UDA_THROW_ERROR(rc, "unable to get cache stats"); } CacheStats stats = maybe_stats.get(); @@ -636,8 +623,8 @@ int udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request UDA_THROW_ERROR(0, "unable to create the Cached Data File"); } - writeCacheData(xdrfile, logmalloclist, userdefinedtypelist, data_block, protocolVersion, - log_struct_list, private_flags, malloc_source); + writeCacheData(xdrfile, logmalloclist, userdefinedtypelist, data_block, protocolVersion, log_struct_list, + private_flags, malloc_source); fclose(xdrfile); @@ -707,9 +694,9 @@ int udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -//#ifdef HAVE_CONFIG_H -//#include "Config.h" -//#endif +// #ifdef HAVE_CONFIG_H +// #include "Config.h" +// #endif // #include "libiberty.h" @@ -747,73 +734,36 @@ int udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request For more information on CRC, see, e.g., http://www.ross.net/crc/download/crc_v3.txt. */ -static const unsigned int crc32_table[] = - { - 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, - 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, - 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, - 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, - 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, - 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, 0x675a1011, - 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, - 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, - 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, - 0xad2f2d84, 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, - 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, - 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, - 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, - 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, - 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, - 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, - 0x7897ab07, 0x7c56b6b0, 0x71159069, 0x75d48dde, - 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, - 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, 0x53dc6066, - 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, - 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, - 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, - 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, - 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, - 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, - 0xd5b88683, 0xd1799b34, 0xdc3abded, 0xd8fba05a, - 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, - 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, - 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, - 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, - 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, - 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, - 0xf12f560e, 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, - 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, - 0xd727bbb6, 0xd3e6a601, 0xdea580d8, 0xda649d6f, - 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, - 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, - 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, - 0x8832161a, 0x8cf30bad, 0x81b02d74, 0x857130c3, - 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, - 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, - 0x68860bfd, 0x6c47164a, 0x61043093, 0x65c52d24, - 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, - 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, - 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, - 0xc5a92679, 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, - 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, - 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, - 0x89b8fd09, 0x8d79e0be, 0x803ac667, 0x84fbdbd0, - 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, - 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, - 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 - }; +static const unsigned int crc32_table[] = { + 0x00000000, 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, 0x1a864db2, 0x1e475005, 0x2608edb8, + 0x22c9f00f, 0x2f8ad6d6, 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, 0x4c11db70, 0x48d0c6c7, + 0x4593e01e, 0x4152fda9, 0x5f15adac, 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, 0x639b0da6, + 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, + 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, + 0xa9ee3033, 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, 0xd9714b49, 0xc7361b4c, 0xc3f706fb, + 0xceb42022, 0xca753d95, 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, 0xe5ffeb43, 0xe8bccd9a, + 0xec7dd02d, 0x34867077, 0x30476dc0, 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, 0x2ac12072, + 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, + 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, + 0x571d7dd1, 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, 0xaca5c697, 0xa864db20, 0xa527fdf9, + 0xa1e6e04e, 0xbfa1b04b, 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, 0x832f1041, 0x87ee0df6, + 0x99a95df3, 0x9d684044, 0x902b669d, 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, 0xf3b06b3b, + 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, + 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, + 0x774bb0eb, 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, 0x58c1663d, 0x558240e4, 0x51435d53, + 0x251d3b9e, 0x21dc2629, 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, 0x3b5a6b9b, 0x0315d626, + 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, 0xf5ee4bb9, + 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, + 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, + 0xae3afba2, 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, 0x92b45ba8, 0x9675461f, 0x8832161a, + 0x8cf30bad, 0x81b02d74, 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, 0x4e8ee645, 0x4a4ffbf2, + 0x470cdd2b, 0x43cdc09c, 0x7b827d21, 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, 0x61043093, + 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, + 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, + 0xc1683bce, 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, 0xdbee767c, 0xe3a1cbc1, 0xe760d676, + 0xea23f0af, 0xeee2ed18, 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, 0x8d79e0be, 0x803ac667, + 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, 0xa2f33668, + 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4}; /* @@ -847,8 +797,7 @@ make it easy to compose the values of multiple blocks. */ -unsigned int -xcrc32(const unsigned char* buf, int len, unsigned int init) +unsigned int xcrc32(const unsigned char* buf, int len, unsigned int init) { unsigned int crc = init; while (len--) { diff --git a/source/cache/fileCache.h b/source/cache/fileCache.h old mode 100755 new mode 100644 index ad32d29a..e10324dc --- a/source/cache/fileCache.h +++ b/source/cache/fileCache.h @@ -1,22 +1,22 @@ #ifndef UDA_CACHE_FILECACHE_H #define UDA_CACHE_FILECACHE_H -#include "udaStructs.h" -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { #endif -LIBRARY_API DATA_BLOCK* -udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source); +LIBRARY_API DATA_BLOCK* udaFileCacheRead(const REQUEST_DATA* request, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source); -LIBRARY_API int -udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request_block, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, - unsigned int private_flags, int malloc_source); +LIBRARY_API int udaFileCacheWrite(const DATA_BLOCK* data_block, const REQUEST_BLOCK* request_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, + int malloc_source); #ifdef __cplusplus } diff --git a/source/cache/memcache.cpp b/source/cache/memcache.cpp old mode 100755 new mode 100644 index eebbccd8..4f3613e0 --- a/source/cache/memcache.cpp +++ b/source/cache/memcache.cpp @@ -1,73 +1,85 @@ #include "memcache.hpp" -#include #include +#include #include "cache.h" #ifdef NOLIBMEMCACHED -namespace uda { -namespace cache { +namespace uda +{ +namespace cache +{ struct UdaCache { int dummy_; }; -} } // namespace uda::cache +} // namespace cache +} // namespace uda uda::cache::UdaCache* uda::cache::open_cache() -{ return nullptr; } +{ + return nullptr; +} -void uda::cache::free_cache() -{} +void uda::cache::free_cache() {} int uda::cache::cache_write(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, DATA_BLOCK* data_block, - LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - ENVIRONMENT environment, int protocolVersion, uint32_t flags, - LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) -{ return 0; } + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + ENVIRONMENT environment, int protocolVersion, uint32_t flags, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +{ + return 0; +} -DATA_BLOCK* uda::cache::cache_read(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, ENVIRONMENT environment, int protocolVersion, - uint32_t flags, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) -{ return nullptr; } +DATA_BLOCK* uda::cache::cache_read(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + ENVIRONMENT environment, int protocolVersion, uint32_t flags, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +{ + return nullptr; +} #else -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include // needed for GCC 12.0 - do not delete -#include +# include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include -#define UDA_CACHE_HOST "localhost" // Override these with environment variables with the same name -#define UDA_CACHE_PORT 11211 -#define UDA_CACHE_EXPIRY 86400 //24*3600 // Lifetime of the object in Secs +# define UDA_CACHE_HOST "localhost" // Override these with environment variables with the same name +# define UDA_CACHE_PORT 11211 +# define UDA_CACHE_EXPIRY 86400 // 24*3600 // Lifetime of the object in Secs -#define MAX_ELEMENT_SHA1 20 +# define MAX_ELEMENT_SHA1 20 -namespace uda { -namespace cache { +namespace uda +{ +namespace cache +{ struct UdaCache { memcached_st memcache; }; -} -} +} // namespace cache +} // namespace uda -namespace { +namespace +{ -static uda::cache::UdaCache* global_cache = nullptr; // scope limited to this code module +static uda::cache::UdaCache* global_cache = nullptr; // scope limited to this code module /** * Use the requested signal and source with client specified properties to create a unique key. @@ -77,8 +89,8 @@ static uda::cache::UdaCache* global_cache = nullptr; // scope limited to this * There is a 250 character limit - use SHA1 hash if it exceeds 250. The local cache should only be used to record data * returned from a server after a GET method - Note: Put methods may be disguised in a GET call! */ -std::string -generate_cache_key(const REQUEST_DATA* request, ENVIRONMENT environment, uint32_t flags, unsigned int private_flags) +std::string generate_cache_key(const REQUEST_DATA* request, ENVIRONMENT environment, uint32_t flags, + unsigned int private_flags) { // Check Properties for permission and requested method if (!(flags & CLIENTFLAG_CACHE)) { @@ -87,12 +99,8 @@ generate_cache_key(const REQUEST_DATA* request, ENVIRONMENT environment, uint32_ const char* delimiter = "&&"; std::stringstream ss; - ss << request->signal << delimiter - << request->source << delimiter - << environment.server_host << delimiter - << environment.server_port << delimiter - << flags << delimiter - << private_flags; + ss << request->signal << delimiter << request->source << delimiter << environment.server_host << delimiter + << environment.server_port << delimiter << flags << delimiter << private_flags; auto key = ss.str(); std::transform(key.begin(), key.end(), key.begin(), [](const decltype(key)::value_type c) { @@ -140,7 +148,7 @@ int memcache_put(uda::cache::UdaCache* cache, const char* key, const char* buffe time_t life = time(nullptr); -#ifdef CACHEDEV +# ifdef CACHEDEV if (data_block->cacheExpiryTime > 0) { // Object expiration time is set by the server life += data_block->cacheExpiryTime; @@ -148,10 +156,10 @@ int memcache_put(uda::cache::UdaCache* cache, const char* key, const char* buffe // Add the default or client overridden lifetime for the object to the current time life += age_max; } -#else +# else // Add the default or client overridden lifetime for the object to the current time life += age_max; -#endif +# endif memcached_return_t rc = memcached_set(&cache->memcache, key, strlen(key), buffer, bufsize, life, (uint32_t)0); @@ -184,7 +192,7 @@ std::pair get_cache_value(uda::cache::UdaCache* cache, const char return {value, len}; } -} // anon namespace +} // namespace uda::cache::UdaCache* uda::cache::open_cache() { @@ -197,7 +205,7 @@ uda::cache::UdaCache* uda::cache::open_cache() memcached_return_t rc; memcached_server_st* servers; - const char* host = getenv("UDA_CACHE_HOST"); // Overrule the default settings + const char* host = getenv("UDA_CACHE_HOST"); // Overrule the default settings const char* port = getenv("UDA_CACHE_PORT"); if (host == nullptr && port == nullptr) { @@ -210,7 +218,7 @@ uda::cache::UdaCache* uda::cache::open_cache() servers = memcached_server_list_append(nullptr, UDA_CACHE_HOST, (in_port_t)atoi(port), &rc); } - //memcached_create(&cache->memcache); // Causes a segmentation Violation! + // memcached_create(&cache->memcache); // Causes a segmentation Violation! cache->memcache = *memcached_create(nullptr); rc = memcached_server_push(&cache->memcache, servers); @@ -223,7 +231,7 @@ uda::cache::UdaCache* uda::cache::open_cache() return nullptr; } - global_cache = cache; // Copy the pointer + global_cache = cache; // Copy the pointer init = true; return cache; } @@ -235,18 +243,17 @@ void uda::cache::free_cache() // Will be called by the idamFreeAll function global_cache = nullptr; } -int -uda::cache::cache_write(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, DATA_BLOCK* data_block, - LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - ENVIRONMENT environment, int protocolVersion, uint32_t flags, - LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +int uda::cache::cache_write(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, DATA_BLOCK* data_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + ENVIRONMENT environment, int protocolVersion, uint32_t flags, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { -#ifdef CACHEDEV +# ifdef CACHEDEV if (!data_block->cachePermission) { // Test permission for the Client to cache this structure. return -1; } -#endif +# endif int rc = 0; auto key = generate_cache_key(request_data, environment, flags, private_flags); @@ -261,8 +268,8 @@ uda::cache::cache_write(uda::cache::UdaCache* cache, const REQUEST_DATA* request FILE* memfile = open_memstream(&buffer, &bufsize); - writeCacheData(memfile, logmalloclist, userdefinedtypelist, data_block, protocolVersion, - log_struct_list, private_flags, malloc_source); + writeCacheData(memfile, logmalloclist, userdefinedtypelist, data_block, protocolVersion, log_struct_list, + private_flags, malloc_source); rc = memcache_put(cache, key.c_str(), buffer, bufsize); @@ -273,11 +280,9 @@ uda::cache::cache_write(uda::cache::UdaCache* cache, const REQUEST_DATA* request } DATA_BLOCK* uda::cache::cache_read(uda::cache::UdaCache* cache, const REQUEST_DATA* request_data, - LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, ENVIRONMENT environment, - int protocolVersion, - uint32_t flags, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, - int malloc_source) + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + ENVIRONMENT environment, int protocolVersion, uint32_t flags, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { auto key = generate_cache_key(request_data, environment, flags, private_flags); if (key.empty()) { @@ -299,8 +304,8 @@ DATA_BLOCK* uda::cache::cache_read(uda::cache::UdaCache* cache, const REQUEST_DA fwrite(value, sizeof(char), len, memfile); fseek(memfile, 0L, SEEK_SET); - auto data = readCacheData(memfile, logmalloclist, userdefinedtypelist, protocolVersion, - log_struct_list, private_flags, malloc_source); + auto data = readCacheData(memfile, logmalloclist, userdefinedtypelist, protocolVersion, log_struct_list, + private_flags, malloc_source); fclose(memfile); free(buffer); diff --git a/source/client/clientXDRStream.cpp b/source/client/clientXDRStream.cpp old mode 100755 new mode 100644 index 3fa6e781..861619eb --- a/source/client/clientXDRStream.cpp +++ b/source/client/clientXDRStream.cpp @@ -3,8 +3,8 @@ #include #include -#include #include "udaDefines.h" +#include #include "connection.h" @@ -24,62 +24,62 @@ std::pair clientCreateXDRStream() #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) if (getUdaClientSSLDisabled()) { - -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); -#else - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); -#endif - } else { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); -#else - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); +# else + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); +# endif + } else { +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); +# else + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); +# endif } #else -#if defined (__APPLE__) || defined(__TIRPC__) +# if defined(__APPLE__) || defined(__TIRPC__) xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); -#else + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); +# else xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, nullptr, - reinterpret_cast(clientReadin), - reinterpret_cast(clientWriteout)); -#endif + reinterpret_cast(clientReadin), + reinterpret_cast(clientWriteout)); +# endif #endif // SSLAUTHENTICATION diff --git a/source/client/clientXDRStream.h b/source/client/clientXDRStream.h old mode 100755 new mode 100644 index ba3e44bc..379a0aad --- a/source/client/clientXDRStream.h +++ b/source/client/clientXDRStream.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENT_CLIENTXDRSTREAM_H #define UDA_CLIENT_CLIENTXDRSTREAM_H -#include #include +#include #include "export.h" diff --git a/source/client/closedown.cpp b/source/client/closedown.cpp old mode 100755 new mode 100644 index 34dbc703..9cc595b8 --- a/source/client/closedown.cpp +++ b/source/client/closedown.cpp @@ -1,24 +1,24 @@ /*--------------------------------------------------------------- -* Close the Socket, XDR Streams, Open File Handles -* -* Argument: If 1 then full closedown otherwise only the -* Socket and XDR Streams. -* -* Returns: -* -*--------------------------------------------------------------*/ + * Close the Socket, XDR Streams, Open File Handles + * + * Argument: If 1 then full closedown otherwise only the + * Socket and XDR Streams. + * + * Returns: + * + *--------------------------------------------------------------*/ #include "closedown.h" -#include #include "client.h" #include +#include #ifdef FATCLIENT -# include # include +# include #else -# include "getEnvironment.h" # include "connection.h" +# include "getEnvironment.h" #endif #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) @@ -38,10 +38,10 @@ int closedown(ClosedownType type, SOCKETLIST* socket_list, XDR* client_input, XD if (type == ClosedownType::CLOSE_ALL) { udaCloseLogging(); - *reopen_logs = true; // In case the User calls the IDAM API again! + *reopen_logs = true; // In case the User calls the IDAM API again! } -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only if (client_input != nullptr) { if (client_input->x_ops != nullptr) { xdr_destroy(client_input); @@ -62,14 +62,14 @@ int closedown(ClosedownType type, SOCKETLIST* socket_list, XDR* client_input, XD udaSetEnvHost(true); udaSetEnvPort(true); -#else // <========================== Fat Client Code Only +#else // <========================== Fat Client Code Only if (type == ClosedownType::CLOSE_ALL) { - closeServerSockets(socket_list); // Close the Socket Connections to Other Data Servers + closeServerSockets(socket_list); // Close the Socket Connections to Other Data Servers } #endif // Close the host list - + udaClientFreeHostList(); // Close the SSL binding and context diff --git a/source/client/closedown.h b/source/client/closedown.h old mode 100755 new mode 100644 index 2d239c71..f307bf42 --- a/source/client/closedown.h +++ b/source/client/closedown.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENT_CLOSEDOWN_H #define UDA_CLIENT_CLOSEDOWN_H -#include #include "export.h" +#include #ifdef FATCLIENT # define closedown closedownFat @@ -17,8 +17,8 @@ enum class ClosedownType { CLOSE_ALL = 1, }; -LIBRARY_API int -closedown(ClosedownType type, SOCKETLIST* socket_list, XDR* client_input, XDR* client_output, bool* reopen_logs); +LIBRARY_API int closedown(ClosedownType type, SOCKETLIST* socket_list, XDR* client_input, XDR* client_output, + bool* reopen_logs); #ifdef __cplusplus } diff --git a/source/client/connection.cpp b/source/client/connection.cpp old mode 100755 new mode 100644 index 2b235245..70b22d16 --- a/source/client/connection.cpp +++ b/source/client/connection.cpp @@ -8,28 +8,28 @@ #include "connection.h" -#include +#include #include #include -#include +#include #include -#include +#include #if defined(__GNUC__) && !defined(__MINGW32__) # ifndef _WIN32 -# include -# include # include # include +# include # include +# include # endif -# include # include +# include #else # include # include # define strcasecmp _stricmp -# define sleep(DELAY) Sleep((DWORD)((DELAY)*1E3)) +# define sleep(DELAY) Sleep((DWORD)((DELAY) * 1E3)) # define close(SOCK) closesocket(SOCK) # ifndef __MINGW32__ # pragma comment(lib, "Ws2_32.lib") @@ -40,14 +40,14 @@ # endif #endif -#include -#include #include "client.h" #include +#include +#include #include -#include "updateSelectParms.h" #include "getEnvironment.h" +#include "updateSelectParms.h" #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) # include @@ -59,10 +59,10 @@ # define ALLOW_UNUSED_TYPE #endif -#define PORT_STRING 64 +#define PORT_STRING 64 static int client_socket = -1; -static SOCKETLIST client_socketlist; // List of open sockets +static SOCKETLIST client_socketlist; // List of open sockets int connectionOpen() { @@ -89,16 +89,17 @@ int reconnect(ENVIRONMENT* environment, XDR** client_input, XDR** client_output, // Instance a new server if the Client has changed the host and/or port number if (environment->server_reconnect) { - //RC + // RC int status; int fh; - if (getSocket(&client_socketlist, TYPE_UDA_SERVER, &status, environment->server_host, environment->server_port, &fh) == 0) { + if (getSocket(&client_socketlist, TYPE_UDA_SERVER, &status, environment->server_host, environment->server_port, + &fh) == 0) { environment->server_socket = fh; environment->server_change_socket = 1; } else { - time(tv_server_start); // Start a New Server AGE timer - client_socket = -1; // Flags no Socket is open - environment->server_change_socket = 0; // Client doesn't know the Socket ID so disable + time(tv_server_start); // Start a New Server AGE timer + client_socket = -1; // Flags no Socket is open + environment->server_change_socket = 0; // Client doesn't know the Socket ID so disable } } @@ -142,9 +143,9 @@ int reconnect(ENVIRONMENT* environment, XDR** client_input, XDR** client_output, void localhostInfo(int* ai_family) { char addr_buf[64]; - struct addrinfo* info = nullptr, * result = nullptr; + struct addrinfo *info = nullptr, *result = nullptr; getaddrinfo("localhost", nullptr, nullptr, &info); - result = info; // Take the first linked list member + result = info; // Take the first linked list member if (result->ai_family == AF_INET) { *ai_family = AF_INET; inet_ntop(AF_INET, &((struct sockaddr_in*)result->ai_addr)->sin_addr, addr_buf, sizeof(addr_buf)); @@ -154,14 +155,16 @@ void localhostInfo(int* ai_family) inet_ntop(AF_INET6, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, addr_buf, sizeof(addr_buf)); UDA_LOG(UDA_LOG_DEBUG, "localhost Information: IPv6 - %s\n", addr_buf); } - if (info) freeaddrinfo(info); + if (info) { + freeaddrinfo(info); + } } void setHints(struct addrinfo* hints, const char* hostname) { hints->ai_family = AF_UNSPEC; hints->ai_socktype = SOCK_STREAM; - hints->ai_flags = 0; //AI_CANONNAME | AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG ; + hints->ai_flags = 0; // AI_CANONNAME | AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG ; hints->ai_protocol = 0; hints->ai_canonname = nullptr; hints->ai_addr = nullptr; @@ -173,11 +176,13 @@ void setHints(struct addrinfo* hints, const char* hostname) // Localhost? Which IP family? (AF_UNSPEC gives an 'Unknown Error'!) - if (!strcmp(hostname, "localhost")) localhostInfo(&hints->ai_family); + if (!strcmp(hostname, "localhost")) { + localhostInfo(&hints->ai_family); + } // Is the address Numeric? Is it IPv6? - if (strchr(hostname, ':')) { // Appended port number should have been stripped off + if (strchr(hostname, ':')) { // Appended port number should have been stripped off hints->ai_family = AF_INET6; hints->ai_flags = hints->ai_flags | AI_NUMERICHOST; } else { @@ -200,9 +205,9 @@ void setHints(struct addrinfo* hints, const char* hostname) } } -int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_start, int user_timeout) +int createConnection(XDR* client_input, XDR* client_output, time_t* tv_server_start, int user_timeout) { - int window_size = DB_READ_BLOCK_SIZE; // 128K + int window_size = DB_READ_BLOCK_SIZE; // 128K int rc; static int max_socket_delay = -1; @@ -237,12 +242,12 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st putUdaClientSSLSocket(client_socket); #endif -#ifdef _WIN32 // Initialise WINSOCK Once only - static unsigned int initWinsock = 0; +#ifdef _WIN32 // Initialise WINSOCK Once only + static unsigned int initWinsock = 0; WORD sockVersion; WSADATA wsaData; if (!initWinsock) { - sockVersion = MAKEWORD(2, 2); // Select Winsock version 2.2 + sockVersion = MAKEWORD(2, 2); // Select Winsock version 2.2 WSAStartup(sockVersion, &wsaData); initWinsock = 1; } @@ -253,7 +258,8 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st const char* hostname = environment->server_host; char serviceport[PORT_STRING]; - // Check if the host_name is an alias for an IP address or domain name in the client configuration - replace if found + // Check if the host_name is an alias for an IP address or domain name in the client configuration - replace if + // found auto host = udaClientFindHostByAlias(hostname); if (host != nullptr) { @@ -264,7 +270,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st } hostname = host->host_name.c_str(); if (strcasecmp(environment->server_host, hostname) != 0) { - strcpy(environment->server_host, hostname); // Replace + strcpy(environment->server_host, hostname); // Replace } int port = host->port; if (port > 0 && environment->server_port != port) { @@ -288,7 +294,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) if (!strncasecmp(hostname, "SSL://", 6)) { // Should be stripped already if via the HOST client configuration file - strcpy(environment->server_host, &hostname[6]); // Replace + strcpy(environment->server_host, &hostname[6]); // Replace putUdaClientSSLProtocol(1); } else { if (host != nullptr && host->isSSL) { @@ -302,15 +308,19 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st // Resolve the Host and the IP protocol to be used (Hints not used) struct addrinfo* result = nullptr; - struct addrinfo hints = { 0 }; + struct addrinfo hints = {0}; setHints(&hints, hostname); errno = 0; // RC if ((rc = getaddrinfo(hostname, serviceport, &hints, &result)) != 0 || (errno != 0 && errno != ESRCH)) { if ((rc = getaddrinfo(hostname, serviceport, &hints, &result)) != 0) { addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, rc, (char*)gai_strerror(rc)); - if (rc == EAI_SYSTEM || errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); - if (result) freeaddrinfo(result); + if (rc == EAI_SYSTEM || errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); + } + if (result) { + freeaddrinfo(result); + } return -1; } @@ -335,7 +345,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st close(client_socket); } #else - closesocket(client_socket); + closesocket(client_socket); #endif client_socket = -1; freeaddrinfo(result); @@ -353,17 +363,19 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st int ps; ps = getpid(); - srand((unsigned int)ps); // Seed the random number generator with the process id + srand((unsigned int)ps); // Seed the random number generator with the process id unsigned int delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; // random delay sleep(delay); - errno = 0; // wait period - for (int i = 0; i < max_socket_attempts; i++) { // try again + errno = 0; // wait period + for (int i = 0; i < max_socket_attempts; i++) { // try again while ((rc = connect(client_socket, result->ai_addr, result->ai_addrlen)) && errno == EINTR) {} - if (rc == 0 && errno == 0) break; + if (rc == 0 && errno == 0) { + break; + } delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; - sleep(delay); // wait period + sleep(delay); // wait period } if (rc != 0 || errno != 0) { @@ -389,7 +401,8 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st #endif hostname = environment->server_host2; - // Check if the host_name is an alias for an IP address or name in the client configuration - replace if found + // Check if the host_name is an alias for an IP address or name in the client configuration - replace if + // found host = udaClientFindHostByAlias(hostname); if (host != nullptr) { @@ -406,7 +419,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st if (port > 0 && environment->server_port2 != port) { environment->server_port2 = port; } - } else if ((host = udaClientFindHostByName(hostname)) != nullptr) { // No alias found + } else if ((host = udaClientFindHostByName(hostname)) != nullptr) { // No alias found int port = host->port; if (port > 0 && environment->server_port2 != port) { environment->server_port2 = port; @@ -420,9 +433,9 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st // Does the host name contain the SSL protocol prefix? If so strip this off #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) - if (!strncasecmp(hostname, "SSL://", 6)){ + if (!strncasecmp(hostname, "SSL://", 6)) { // Should be stripped already if via the HOST client configuration file - strcpy(environment->server_host2, &hostname[6]); // Replace + strcpy(environment->server_host2, &hostname[6]); // Replace putUdaClientSSLProtocol(1); } else { if (host != nullptr && host->isSSL) { @@ -440,8 +453,12 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st errno = 0; if ((rc = getaddrinfo(hostname, serviceport, &hints, &result)) != 0 || errno != 0) { addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, rc, (char*)gai_strerror(rc)); - if (rc == EAI_SYSTEM || errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); - if (result) freeaddrinfo(result); + if (rc == EAI_SYSTEM || errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); + } + if (result) { + freeaddrinfo(result); + } return -1; } errno = 0; @@ -459,7 +476,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st close(client_socket); } #else - closesocket(client_socket); + closesocket(client_socket); #endif client_socket = -1; freeaddrinfo(result); @@ -469,7 +486,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st for (int i = 0; i < max_socket_attempts; i++) { while ((rc = connect(client_socket, result->ai_addr, result->ai_addrlen)) && errno == EINTR) {} if (rc == 0) { - int port = environment->server_port2; // Swap data so that accessor function reports correctly + int port = environment->server_port2; // Swap data so that accessor function reports correctly environment->server_port2 = environment->server_port; environment->server_port = port; std::string name = environment->server_host2; @@ -478,7 +495,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st break; } delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; - sleep(delay); // wait period + sleep(delay); // wait period } } @@ -494,15 +511,19 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st close(client_socket); } #else - closesocket(client_socket); + closesocket(client_socket); #endif client_socket = -1; - if (result) freeaddrinfo(result); + if (result) { + freeaddrinfo(result); + } return -1; } } - if (result) freeaddrinfo(result); + if (result) { + freeaddrinfo(result); + } // Set the receive and send buffer sizes @@ -532,7 +553,7 @@ int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_st client_socket); client_socketlist.sockets[getSocketRecordId(&client_socketlist, client_socket)].Input = client_input; client_socketlist.sockets[getSocketRecordId(&client_socketlist, client_socket)].Output = client_output; - client_socketlist.sockets[getSocketRecordId(&client_socketlist, client_socket)].user_timeout = user_timeout; + client_socketlist.sockets[getSocketRecordId(&client_socketlist, client_socket)].user_timeout = user_timeout; client_socketlist.sockets[getSocketRecordId(&client_socketlist, client_socket)].tv_server_start = *tv_server_start; environment->server_reconnect = 0; environment->server_change_socket = 0; @@ -566,7 +587,7 @@ void closeConnection(ClosedownType type) int clientWriteout(void* iohandle ALLOW_UNUSED_TYPE, char* buf, int count) { #ifndef _WIN32 - void (* OldSIGPIPEHandler)(int); + void (*OldSIGPIPEHandler)(int); #endif int rc = 0; size_t BytesSent = 0; @@ -623,13 +644,13 @@ int clientWriteout(void* iohandle ALLOW_UNUSED_TYPE, char* buf, int count) #ifndef _WIN32 while (((rc = (int)write(client_socket, buf, count)) == -1) && (errno == EINTR)) {} #else - while (((rc = send(client_socket, buf , count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} + while (((rc = send(client_socket, buf, count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} #endif BytesSent += rc; buf += rc; } -// Restore the original SIGPIPE handler set by the application + // Restore the original SIGPIPE handler set by the application #ifndef _WIN32 if (signal(SIGPIPE, OldSIGPIPEHandler) == SIG_ERR) { @@ -656,7 +677,7 @@ int clientReadin(void* iohandle ALLOW_UNUSED_TYPE, char* buf, int count) udaUpdateSelectParms(client_socket, &rfds, &tv); while ((select(client_socket + 1, &rfds, nullptr, nullptr, &tv) <= 0) && maxloop++ < MAXLOOP) { - udaUpdateSelectParms(client_socket, &rfds, &tv); // Keep trying ... + udaUpdateSelectParms(client_socket, &rfds, &tv); // Keep trying ... } // Read from it, checking for EINTR, as happens if called from IDL diff --git a/source/client/connection.h b/source/client/connection.h old mode 100755 new mode 100644 index 51ae955f..0e2a13bb --- a/source/client/connection.h +++ b/source/client/connection.h @@ -1,29 +1,29 @@ #pragma once #ifndef UDA_CLIENT_CONNECTION_H -#define UDA_CLIENT_CONNECTION_H +# define UDA_CLIENT_CONNECTION_H -#include -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" +# include -#include "closedown.h" +# include "closedown.h" -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif int connectionOpen(); int reconnect(ENVIRONMENT* environment, XDR** client_input, XDR** client_output, time_t* tv_server_start, - int* user_timeout); -int createConnection(XDR* client_input, XDR* client_output, time_t *tv_server_start, int user_timeout); + int* user_timeout); +int createConnection(XDR* client_input, XDR* client_output, time_t* tv_server_start, int user_timeout); void closeConnection(ClosedownType type); int clientWriteout(void* iohandle, char* buf, int count); int clientReadin(void* iohandle, char* buf, int count); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif // UDA_CLIENT_CONNECTION_H diff --git a/source/client/generateErrors.cpp b/source/client/generateErrors.cpp old mode 100755 new mode 100644 index 563c68ce..bf42fdf7 --- a/source/client/generateErrors.cpp +++ b/source/client/generateErrors.cpp @@ -1,23 +1,23 @@ /*--------------------------------------------------------------- -* IDAM Model Based Symmetric/Asymmetric Error Data Generation -* -* Input Arguments: -* Returns: -* -* -* -* Notes: -* -*--------------------------------------------------------------*/ + * IDAM Model Based Symmetric/Asymmetric Error Data Generation + * + * Input Arguments: + * Returns: + * + * + * + * Notes: + * + *--------------------------------------------------------------*/ #include "generateErrors.h" -#include #include +#include #include "udaTypes.h" -#include #include +#include #include "accAPI.h" @@ -31,12 +31,14 @@ int idamErrorModel(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, float* errhi, float* errlo) { - *asymmetry = 0; // No Error Asymmetry for most models + *asymmetry = 0; // No Error Asymmetry for most models switch (model) { case ERROR_MODEL_DEFAULT: - if (param_n != 2) return 1; + if (param_n != 2) { + return 1; + } for (int i = 0; i < data_n; i++) { errhi[i] = params[0] + params[1] * fabsf(data[i]); errlo[i] = errhi[i]; @@ -44,7 +46,9 @@ int idamErrorModel(int model, int param_n, float* params, int data_n, float* dat break; case ERROR_MODEL_DEFAULT_ASYMMETRIC: - if (param_n != 4) return 1; + if (param_n != 4) { + return 1; + } *asymmetry = 1; for (int i = 0; i < data_n; i++) { errhi[i] = params[0] + params[1] * fabsf(data[i]); @@ -80,44 +84,59 @@ int idamSyntheticModel(int model, int param_n, float* params, int data_n, float* #else float shift; - static gsl_rng *random=nullptr; + static gsl_rng* random = nullptr; - if (random == nullptr) { // Initialise the Random Number System + if (random == nullptr) { // Initialise the Random Number System gsl_rng_env_setup(); - random = gsl_rng_alloc (gsl_rng_default); - gsl_rng_set(random, (unsigned long int) ERROR_MODEL_SEED); // Seed the Random Number generator with the library default + random = gsl_rng_alloc(gsl_rng_default); + gsl_rng_set(random, + (unsigned long int)ERROR_MODEL_SEED); // Seed the Random Number generator with the library default } switch (model) { - case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution - if(param_n < 1 || param_n > 2) return 1; - if(param_n == 2) gsl_rng_set(random, (unsigned long int) params[1]); // Change the Seed before Sampling - for (int i = 0; i < data_n; i++) { - data[i] = data[i] + (float) gsl_ran_gaussian (random, (double) params[0]); // Random sample from PDF - } - break; + case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution + if (param_n < 1 || param_n > 2) { + return 1; + } + if (param_n == 2) { + gsl_rng_set(random, (unsigned long int)params[1]); // Change the Seed before Sampling + } + for (int i = 0; i < data_n; i++) { + data[i] = data[i] + (float)gsl_ran_gaussian(random, (double)params[0]); // Random sample from PDF + } + break; - case ERROR_MODEL_RESEED: // Change the Seed - if(param_n == 1) gsl_rng_set(random, (unsigned long int) params[0]); - break; + case ERROR_MODEL_RESEED: // Change the Seed + if (param_n == 1) { + gsl_rng_set(random, (unsigned long int)params[0]); + } + break; - case ERROR_MODEL_GAUSSIAN_SHIFT: - if(param_n < 1 || param_n > 2) return 1; - if(param_n == 2) gsl_rng_set(random, (unsigned long int) params[1]); // Change the Seed before Sampling - shift = (float) gsl_ran_gaussian (random, (double) params[0]); - for (int i = 0; i < data_n; i++) { - data[i] = data[i] + shift; // Random linear shift of data array - } - break; + case ERROR_MODEL_GAUSSIAN_SHIFT: + if (param_n < 1 || param_n > 2) { + return 1; + } + if (param_n == 2) { + gsl_rng_set(random, (unsigned long int)params[1]); // Change the Seed before Sampling + } + shift = (float)gsl_ran_gaussian(random, (double)params[0]); + for (int i = 0; i < data_n; i++) { + data[i] = data[i] + shift; // Random linear shift of data array + } + break; - case ERROR_MODEL_POISSON: - if(param_n < 0 || param_n > 1) return 1; - if(param_n == 1) gsl_rng_set(random, (unsigned long int) params[0]); // Change the Seed before Sampling - for (int i = 0; i < data_n; i++) { - data[i] = data[i] + (float) gsl_ran_poisson(random, (double)data[i]); // Randomly perturb data array - } - break; + case ERROR_MODEL_POISSON: + if (param_n < 0 || param_n > 1) { + return 1; + } + if (param_n == 1) { + gsl_rng_set(random, (unsigned long int)params[0]); // Change the Seed before Sampling + } + for (int i = 0; i < data_n; i++) { + data[i] = data[i] + (float)gsl_ran_poisson(random, (double)data[i]); // Randomly perturb data array + } + break; } return 0; @@ -133,7 +152,9 @@ int generateIdamSyntheticData(int handle) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (getIdamData(handle) == nullptr) return 0; + if (getIdamData(handle) == nullptr) { + return 0; + } int model; int param_n; @@ -141,9 +162,13 @@ int generateIdamSyntheticData(int handle) getIdamErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (getIdamDataNum(handle) <= 0) return 0; + if (getIdamDataNum(handle) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -163,62 +188,86 @@ int generateIdamSyntheticData(int handle) switch (getIdamDataType(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)dp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)ip[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)up[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)getIdamData(handle); + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)cp[i]; + } break; } @@ -233,8 +282,7 @@ int generateIdamSyntheticData(int handle) err = idamSyntheticModel(model, param_n, params, getIdamDataNum(handle), data); if (err != 0) { - addIdamError(UDA_CODE_ERROR_TYPE, "generateIdamSyntheticData", err, - "Unable to Generate Synthetic Data"); + addIdamError(UDA_CODE_ERROR_TYPE, "generateIdamSyntheticData", err, "Unable to Generate Synthetic Data"); free(data); return err; } @@ -254,65 +302,88 @@ int generateIdamSyntheticData(int handle) switch (getIdamDataType(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) fp[i] = data[i]; // Overwrite the Data + for (int i = 0; i < getIdamDataNum(handle); i++) { + fp[i] = data[i]; // Overwrite the Data + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) dp[i] = (double)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + dp[i] = (double)data[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) sp[i] = (short)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + sp[i] = (short)data[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) ip[i] = (int)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + ip[i] = (int)data[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) lp[i] = (long)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + lp[i] = (long)data[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) lp[i] = (long long int)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + lp[i] = (long long int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) sp[i] = (unsigned short)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + sp[i] = (unsigned short)data[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) up[i] = (unsigned int)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + up[i] = (unsigned int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) lp[i] = (unsigned long)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + lp[i] = (unsigned long)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) lp[i] = (unsigned long long int) data[i]; + auto lp = (unsigned long long int*)acc_getSyntheticData(handle); + for (int i = 0; i < getIdamDataNum(handle); i++) { + lp[i] = (unsigned long long int)data[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) cp[i] = (char)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + cp[i] = (char)data[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)acc_getSyntheticData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) cp[i] = (unsigned char)data[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + cp[i] = (unsigned char)data[i]; + } break; } - } //-------------------------------------------------------------------------------------------------------------- @@ -332,9 +403,13 @@ int generateIdamSyntheticDimData(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (getIdamData(handle) == nullptr) return 0; // No Data Block available + if (getIdamData(handle) == nullptr) { + return 0; // No Data Block available + } - if (ndim < 0 || ndim > getIdamRank(handle)) return 0; + if (ndim < 0 || ndim > getIdamRank(handle)) { + return 0; + } int model; int param_n; @@ -342,9 +417,13 @@ int generateIdamSyntheticDimData(int handle, int ndim) getIdamErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (getIdamDimNum(handle, ndim) <= 0) return 0; + if (getIdamDimNum(handle, ndim) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -366,62 +445,86 @@ int generateIdamSyntheticDimData(int handle, int ndim) switch (getIdamDataType(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)dp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)ip[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = (char*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)up[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)getIdamDimData(handle, ndim); + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -457,62 +560,86 @@ int generateIdamSyntheticDimData(int handle, int ndim) switch (getIdamDimType(handle, ndim)) { case UDA_TYPE_FLOAT: { auto fp = (float*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) fp[i] = data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + fp[i] = data[i]; + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) dp[i] = (double)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + dp[i] = (double)data[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) sp[i] = (short)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + sp[i] = (short)data[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) ip[i] = (int)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + ip[i] = (int)data[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) lp[i] = (long)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + lp[i] = (long)data[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) lp[i] = (long long int)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + lp[i] = (long long int)data[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) cp[i] = (char)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + cp[i] = (char)data[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) sp[i] = (unsigned short)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + sp[i] = (unsigned short)data[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) up[i] = (unsigned int)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + up[i] = (unsigned int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) lp[i] = (unsigned long)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + lp[i] = (unsigned long)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) lp[i] = (unsigned long long int) data[i]; + auto lp = (unsigned long long int*)acc_getSyntheticDimData(handle, ndim); + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + lp[i] = (unsigned long long int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)acc_getSyntheticDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) cp[i] = (unsigned char)data[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + cp[i] = (unsigned char)data[i]; + } break; } } @@ -534,7 +661,9 @@ int generateIdamDataError(int handle) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (getIdamData(handle) == nullptr) return 0; // No Data Block available + if (getIdamData(handle) == nullptr) { + return 0; // No Data Block available + } int model; int param_n; @@ -542,9 +671,13 @@ int generateIdamDataError(int handle) getIdamErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (getIdamDataNum(handle) <= 0) return 0; + if (getIdamDataNum(handle) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -560,69 +693,99 @@ int generateIdamDataError(int handle) char* errhi; char* errlo; - if ((data = (float*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) return 1; - if ((errhi = (char*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) return 1; - if ((errlo = (char*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) return 1; + if ((data = (float*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) { + return 1; + } + if ((errhi = (char*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) { + return 1; + } + if ((errlo = (char*)malloc(getIdamDataNum(handle) * sizeof(float))) == nullptr) { + return 1; + } switch (getIdamDataType(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)dp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)ip[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)up[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = (char*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)getIdamData(handle); + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)getIdamData(handle); - for (int i = 0; i < getIdamDataNum(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDataNum(handle); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -635,8 +798,8 @@ int generateIdamDataError(int handle) //-------------------------------------------------------------------------------------------------------------- // Generate Error Data - err = idamErrorModel(model, param_n, params, getIdamDataNum(handle), data, &asymmetry, (float*)errhi, - (float*)errlo); + err = + idamErrorModel(model, param_n, params, getIdamDataNum(handle), data, &asymmetry, (float*)errhi, (float*)errlo); if (err != 0) { free(data); @@ -652,7 +815,9 @@ int generateIdamDataError(int handle) acc_setIdamDataErrAsymmetry(handle, asymmetry); if (asymmetry && getIdamDataErrLo(handle) == nullptr) { - if ((err = allocArray(getIdamDataType(handle), getIdamDataNum(handle), &perrlo))) return err; + if ((err = allocArray(getIdamDataType(handle), getIdamDataNum(handle), &perrlo))) { + return err; + } acc_setIdamDataErrLo(handle, perrlo); } @@ -662,7 +827,9 @@ int generateIdamDataError(int handle) auto fel = (float*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { feh[i] = (float)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) fel[i] = (float)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + fel[i] = (float)errlo[i]; + } } break; } @@ -671,7 +838,9 @@ int generateIdamDataError(int handle) auto del = (double*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { deh[i] = (double)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) del[i] = (double)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + del[i] = (double)errlo[i]; + } } break; } @@ -680,7 +849,9 @@ int generateIdamDataError(int handle) auto iel = (int*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { ieh[i] = (int)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) iel[i] = (int)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + iel[i] = (int)errlo[i]; + } } break; } @@ -689,7 +860,9 @@ int generateIdamDataError(int handle) auto lel = (long*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { leh[i] = (long)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) lel[i] = (long)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + lel[i] = (long)errlo[i]; + } } break; } @@ -698,7 +871,9 @@ int generateIdamDataError(int handle) auto lel = (long long int*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { leh[i] = (long long int)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) lel[i] = (long long int)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + lel[i] = (long long int)errlo[i]; + } } break; } @@ -707,7 +882,9 @@ int generateIdamDataError(int handle) auto sel = (short*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { seh[i] = (short)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) sel[i] = (short)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + sel[i] = (short)errlo[i]; + } } break; } @@ -716,7 +893,9 @@ int generateIdamDataError(int handle) char* cel = getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { ceh[i] = errhi[i]; - if (getIdamDataErrAsymmetry(handle)) cel[i] = errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + cel[i] = errlo[i]; + } } break; } @@ -725,7 +904,9 @@ int generateIdamDataError(int handle) auto uel = (unsigned int*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { ueh[i] = (unsigned int)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) uel[i] = (unsigned int)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + uel[i] = (unsigned int)errlo[i]; + } } break; } @@ -734,16 +915,20 @@ int generateIdamDataError(int handle) auto lel = (unsigned long*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { leh[i] = (unsigned long)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) lel[i] = (unsigned long)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + lel[i] = (unsigned long)errlo[i]; + } } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto leh = (unsigned long long int *) getIdamDataErrHi(handle); - auto lel = (unsigned long long int *) getIdamDataErrLo(handle); + auto leh = (unsigned long long int*)getIdamDataErrHi(handle); + auto lel = (unsigned long long int*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { - leh[i] = (unsigned long long int) errhi[i]; - if (getIdamDataErrAsymmetry(handle)) lel[i] = (unsigned long long int) errlo[i]; + leh[i] = (unsigned long long int)errhi[i]; + if (getIdamDataErrAsymmetry(handle)) { + lel[i] = (unsigned long long int)errlo[i]; + } } break; } @@ -752,7 +937,9 @@ int generateIdamDataError(int handle) auto sel = (unsigned short*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { seh[i] = (unsigned short)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) sel[i] = (unsigned short)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + sel[i] = (unsigned short)errlo[i]; + } } break; } @@ -761,11 +948,12 @@ int generateIdamDataError(int handle) auto cel = (unsigned char*)getIdamDataErrLo(handle); for (int i = 0; i < getIdamDataNum(handle); i++) { ceh[i] = (unsigned char)errhi[i]; - if (getIdamDataErrAsymmetry(handle)) cel[i] = (unsigned char)errlo[i]; + if (getIdamDataErrAsymmetry(handle)) { + cel[i] = (unsigned char)errlo[i]; + } } break; } - } //-------------------------------------------------------------------------------------------------------------- @@ -788,9 +976,13 @@ int generateIdamDimDataError(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (getIdamData(handle) == nullptr) return 0; // No Data Block available + if (getIdamData(handle) == nullptr) { + return 0; // No Data Block available + } - if (ndim < 0 || ndim > getIdamRank(handle)) return 0; + if (ndim < 0 || ndim > getIdamRank(handle)) { + return 0; + } int model; int param_n; @@ -798,9 +990,13 @@ int generateIdamDimDataError(int handle, int ndim) getIdamErrorModel(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (getIdamDimNum(handle, ndim) <= 0) return 0; + if (getIdamDimNum(handle, ndim) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -816,69 +1012,99 @@ int generateIdamDimDataError(int handle, int ndim) char* errhi; char* errlo; - if ((data = (float*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) return 1; - if ((errhi = (char*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) return 1; - if ((errlo = (char*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) return 1; + if ((data = (float*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } + if ((errhi = (char*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } + if ((errlo = (char*)malloc(getIdamDimNum(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } switch (getIdamDataType(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)dp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)ip[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)up[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *) getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)getIdamDimData(handle, ndim); + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)getIdamDimData(handle, ndim); - for (int i = 0; i < getIdamDimNum(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -908,7 +1134,9 @@ int generateIdamDimDataError(int handle, int ndim) acc_setIdamDimErrAsymmetry(handle, ndim, asymmetry); if (getIdamDimErrAsymmetry(handle, ndim) && getIdamDimErrLo(handle, ndim) == nullptr) { - if ((err = allocArray(getIdamDimType(handle, ndim), getIdamDimNum(handle, ndim), &perrlo))) return err; + if ((err = allocArray(getIdamDimType(handle, ndim), getIdamDimNum(handle, ndim), &perrlo))) { + return err; + } acc_setIdamDimErrLo(handle, ndim, perrlo); } @@ -918,7 +1146,9 @@ int generateIdamDimDataError(int handle, int ndim) auto fel = (float*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { feh[i] = (float)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))fel[i] = (float)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + fel[i] = (float)errlo[i]; + } } break; } @@ -927,7 +1157,9 @@ int generateIdamDimDataError(int handle, int ndim) auto del = (double*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { deh[i] = (double)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))del[i] = (double)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + del[i] = (double)errlo[i]; + } } break; } @@ -936,7 +1168,9 @@ int generateIdamDimDataError(int handle, int ndim) auto iel = (int*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { ieh[i] = (int)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))iel[i] = (int)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + iel[i] = (int)errlo[i]; + } } break; } @@ -945,7 +1179,9 @@ int generateIdamDimDataError(int handle, int ndim) auto uel = (unsigned int*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { ueh[i] = (unsigned int)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))uel[i] = (unsigned int)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + uel[i] = (unsigned int)errlo[i]; + } } break; } @@ -954,7 +1190,9 @@ int generateIdamDimDataError(int handle, int ndim) auto lel = (long*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { leh[i] = (long)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))lel[i] = (long)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + lel[i] = (long)errlo[i]; + } } break; } @@ -963,7 +1201,9 @@ int generateIdamDimDataError(int handle, int ndim) auto lel = (long long int*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { leh[i] = (long long int)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))lel[i] = (long long int)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + lel[i] = (long long int)errlo[i]; + } } break; } @@ -972,7 +1212,9 @@ int generateIdamDimDataError(int handle, int ndim) auto sel = (short*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { seh[i] = (short)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))sel[i] = (short)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + sel[i] = (short)errlo[i]; + } } break; } @@ -981,7 +1223,9 @@ int generateIdamDimDataError(int handle, int ndim) char* cel = (char*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { ceh[i] = (char)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))cel[i] = errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + cel[i] = errlo[i]; + } } break; } @@ -990,16 +1234,20 @@ int generateIdamDimDataError(int handle, int ndim) auto lel = (unsigned long*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { leh[i] = (unsigned long)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))lel[i] = (unsigned long)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + lel[i] = (unsigned long)errlo[i]; + } } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto leh = (unsigned long long int *) getIdamDimErrHi(handle, ndim); - auto lel = (unsigned long long int *) getIdamDimErrLo(handle, ndim); + auto leh = (unsigned long long int*)getIdamDimErrHi(handle, ndim); + auto lel = (unsigned long long int*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { - leh[i] = (unsigned long long int) errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))lel[i] = (unsigned long long int) errlo[i]; + leh[i] = (unsigned long long int)errhi[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + lel[i] = (unsigned long long int)errlo[i]; + } } break; } @@ -1008,7 +1256,9 @@ int generateIdamDimDataError(int handle, int ndim) auto sel = (unsigned short*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { seh[i] = (unsigned short)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))sel[i] = (unsigned short)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + sel[i] = (unsigned short)errlo[i]; + } } break; } @@ -1017,7 +1267,9 @@ int generateIdamDimDataError(int handle, int ndim) auto cel = (unsigned char*)getIdamDimErrLo(handle, ndim); for (int i = 0; i < getIdamDimNum(handle, ndim); i++) { ceh[i] = (unsigned char)errhi[i]; - if (getIdamDimErrAsymmetry(handle, ndim))cel[i] = (unsigned char)errlo[i]; + if (getIdamDimErrAsymmetry(handle, ndim)) { + cel[i] = (unsigned char)errlo[i]; + } } break; } @@ -1032,4 +1284,3 @@ int generateIdamDimDataError(int handle, int ndim) return 0; } - diff --git a/source/client/generateErrors.h b/source/client/generateErrors.h old mode 100755 new mode 100644 index cb3d8b45..d87572ad --- a/source/client/generateErrors.h +++ b/source/client/generateErrors.h @@ -7,8 +7,9 @@ extern "C" { #endif -LIBRARY_API int idamErrorModel(int model, int param_n, float *params, int data_n, float *data, int *asymmetry, float *errhi, float *errlo); -LIBRARY_API int idamSyntheticModel(int model, int param_n, float *params, int data_n, float *data); +LIBRARY_API int idamErrorModel(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, + float* errhi, float* errlo); +LIBRARY_API int idamSyntheticModel(int model, int param_n, float* params, int data_n, float* data); LIBRARY_API int generateIdamSyntheticData(int handle); LIBRARY_API int generateIdamSyntheticDimData(int handle, int ndim); LIBRARY_API int generateIdamDataError(int handle); diff --git a/source/client/getEnvironment.cpp b/source/client/getEnvironment.cpp old mode 100755 new mode 100644 index 245f75bd..5267555e --- a/source/client/getEnvironment.cpp +++ b/source/client/getEnvironment.cpp @@ -5,7 +5,7 @@ #include -bool env_host = true; // User can change these before startup so flag to the getEnvironment function +bool env_host = true; // User can change these before startup so flag to the getEnvironment function bool env_port = true; static ENVIRONMENT udaEnviron; @@ -45,19 +45,23 @@ void printIdamClientEnvironment(const ENVIRONMENT* environment) UDA_LOG(UDA_LOG_INFO, "Private File Path Substitute: %s\n", environment->private_path_substitute); } -bool udaGetEnvHost() { +bool udaGetEnvHost() +{ return env_host; } -bool udaGetEnvPort() { +bool udaGetEnvPort() +{ return env_port; } -LIBRARY_API void udaSetEnvHost(bool value) { +LIBRARY_API void udaSetEnvHost(bool value) +{ env_host = value; } -LIBRARY_API void udaSetEnvPort(bool value) { +LIBRARY_API void udaSetEnvPort(bool value) +{ env_port = value; } @@ -84,13 +88,19 @@ ENVIRONMENT* getIdamClientEnvironment() strcpy(udaEnviron.logdir, ""); #endif } -udaEnviron.loglevel = UDA_LOG_NONE; + udaEnviron.loglevel = UDA_LOG_NONE; if ((env = getenv("UDA_LOG_LEVEL")) != nullptr) { - if (strncmp(env, "ACCESS", 6) == 0) udaEnviron.loglevel = UDA_LOG_ACCESS; - else if (strncmp(env, "ERROR", 5) == 0) udaEnviron.loglevel = UDA_LOG_ERROR; - else if (strncmp(env, "WARN", 4) == 0) udaEnviron.loglevel = UDA_LOG_WARN; - else if (strncmp(env, "DEBUG", 5) == 0) udaEnviron.loglevel = UDA_LOG_DEBUG; - else if (strncmp(env, "INFO", 4) == 0) udaEnviron.loglevel = UDA_LOG_INFO; + if (strncmp(env, "ACCESS", 6) == 0) { + udaEnviron.loglevel = UDA_LOG_ACCESS; + } else if (strncmp(env, "ERROR", 5) == 0) { + udaEnviron.loglevel = UDA_LOG_ERROR; + } else if (strncmp(env, "WARN", 4) == 0) { + udaEnviron.loglevel = UDA_LOG_WARN; + } else if (strncmp(env, "DEBUG", 5) == 0) { + udaEnviron.loglevel = UDA_LOG_DEBUG; + } else if (strncmp(env, "INFO", 4) == 0) { + udaEnviron.loglevel = UDA_LOG_INFO; + } } if (udaEnviron.loglevel <= UDA_LOG_ACCESS) { @@ -99,20 +109,19 @@ udaEnviron.loglevel = UDA_LOG_NONE; // TODO: How to log error before log files are open? }; } - + // Log Output Write Mode - strcpy(udaEnviron.logmode, "w"); // Write & Replace Mode + strcpy(udaEnviron.logmode, "w"); // Write & Replace Mode if ((env = getenv("UDA_LOG_MODE")) != nullptr) { if (env[0] == 'a' && strlen(env) == 1) { udaEnviron.logmode[0] = 'a'; } - } // Append Mode - + } // Append Mode // UDA Server Host Name - if (env_host) { // Check Not already set by User + if (env_host) { // Check Not already set by User if ((env = getenv("UDA_HOST")) != nullptr) { strcpy(udaEnviron.server_host, env); } else { @@ -147,8 +156,8 @@ udaEnviron.loglevel = UDA_LOG_NONE; // UDA Reconnect Status - udaEnviron.server_reconnect = 0; // No reconnection needed at startup! - udaEnviron.server_socket = -1; // No Socket open at startup + udaEnviron.server_reconnect = 0; // No reconnection needed at startup! + udaEnviron.server_socket = -1; // No Socket open at startup //------------------------------------------------------------------------------------------- // API Defaults @@ -197,8 +206,12 @@ udaEnviron.loglevel = UDA_LOG_NONE; # else udaEnviron.external_user = 0; # endif - if ((env = getenv("EXTERNAL_USER")) != nullptr) udaEnviron.external_user = 1; - if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) udaEnviron.external_user = 1; + if ((env = getenv("EXTERNAL_USER")) != nullptr) { + udaEnviron.external_user = 1; + } + if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { + udaEnviron.external_user = 1; + } #endif //------------------------------------------------------------------------------------------- @@ -206,15 +219,17 @@ udaEnviron.loglevel = UDA_LOG_NONE; #ifdef FATCLIENT # ifdef PROXYSERVER - if((env = getenv("UDA_PROXY_TARGETHOST")) != nullptr) - strcpy(udaEnviron.server_proxy, env); - else - udaEnviron.server_proxy[0] = '\0'; - - if((env = getenv("UDA_PROXY_THISHOST")) != nullptr) - strcpy(udaEnviron.server_this, env); - else - udaEnviron.server_this[0] = '\0'; + if ((env = getenv("UDA_PROXY_TARGETHOST")) != nullptr) { + strcpy(udaEnviron.server_proxy, env); + } else { + udaEnviron.server_proxy[0] = '\0'; + } + + if ((env = getenv("UDA_PROXY_THISHOST")) != nullptr) { + strcpy(udaEnviron.server_this, env); + } else { + udaEnviron.server_this[0] = '\0'; + } # endif #endif @@ -237,14 +252,18 @@ udaEnviron.loglevel = UDA_LOG_NONE; // Client defined Property Flags udaEnviron.clientFlags = 0; - if ((env = getenv("UDA_FLAGS")) != nullptr) udaEnviron.clientFlags = atoi(env); + if ((env = getenv("UDA_FLAGS")) != nullptr) { + udaEnviron.clientFlags = atoi(env); + } udaEnviron.altRank = 0; - if ((env = getenv("UDA_ALTRANK")) != nullptr) udaEnviron.altRank = atoi(env); + if ((env = getenv("UDA_ALTRANK")) != nullptr) { + udaEnviron.altRank = atoi(env); + } //------------------------------------------------------------------------------------------- - udaEnviron.initialised = 1; // Initialisation Complete + udaEnviron.initialised = 1; // Initialisation Complete return &udaEnviron; } diff --git a/source/client/getEnvironment.h b/source/client/getEnvironment.h old mode 100755 new mode 100644 index f37ef786..aa8a29b1 --- a/source/client/getEnvironment.h +++ b/source/client/getEnvironment.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENT_GETENVIRONMENT_H #define UDA_CLIENT_GETENVIRONMENT_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef FATCLIENT # define printIdamClientEnvironment printIdamClientEnvironmentFat diff --git a/source/client/makeClientRequestBlock.cpp b/source/client/makeClientRequestBlock.cpp old mode 100755 new mode 100644 index 4456e813..4b3b68c2 --- a/source/client/makeClientRequestBlock.cpp +++ b/source/client/makeClientRequestBlock.cpp @@ -22,14 +22,14 @@ Interprets the API arguments and assembles a Request data structure. #include -#include +#include "initStructs.h" #include "udaErrors.h" #include #include -#include -#include "initStructs.h" #include +#include #include +#include int makeRequestData(const char* data_object, const char* data_source, REQUEST_DATA* request) { @@ -39,13 +39,13 @@ int makeRequestData(const char* data_object, const char* data_source, REQUEST_DA if (strlen(data_object) >= MAXMETA) { UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument string is too long!"); } else { - strcpy(request->signal, data_object); // Passed to the server without modification + strcpy(request->signal, data_object); // Passed to the server without modification } if (strlen(data_source) >= STRING_LENGTH) { UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument string is too long!"); } else { - strcpy(request->source, data_source); // Passed to the server without modification + strcpy(request->source, data_source); // Passed to the server without modification } //------------------------------------------------------------------------------------------------------------------ @@ -54,34 +54,36 @@ int makeRequestData(const char* data_object, const char* data_source, REQUEST_DA * This delimiting string can be defined by the user via an environment variable "UDA_API_DELIM". * This must be passed to the server as it needs to separate the prefix from the main component in order to * interpret the data access request. - */ + */ ENVIRONMENT* environment = getIdamClientEnvironment(); - strcpy(request->api_delim, environment->api_delim); // Server needs to know how to parse the arguments + strcpy(request->api_delim, environment->api_delim); // Server needs to know how to parse the arguments //------------------------------------------------------------------------------------------------------------------ - /* If the default ARCHIVE and/or DEVICE is overridden by local environment variables and the arguments do not contain - * either an archive or device then prefix + /* If the default ARCHIVE and/or DEVICE is overridden by local environment variables and the arguments do not + * contain either an archive or device then prefix * * These environment variables are legacy and not used by the server - */ + */ if (environment->api_device[0] != '\0' && strstr(request->source, request->api_delim) == nullptr) { - int lstr = (int)strlen(request->source) + (int)strlen(environment->api_device) + - (int)strlen(request->api_delim); + int lstr = + (int)strlen(request->source) + (int)strlen(environment->api_device) + (int)strlen(request->api_delim); if (lstr >= STRING_LENGTH) { - UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument, prefixed with the Device Name, is too long!"); + UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, + "The Data Source Argument, prefixed with the Device Name, is too long!"); } std::string test = fmt::format("{}{}{}", environment->api_device, request->api_delim, request->source); strcpy(request->source, test.c_str()); } if (environment->api_archive[0] != '\0' && strstr(request->signal, request->api_delim) == nullptr) { - int lstr = (int)strlen(request->signal) + (int)strlen(environment->api_archive) + - (int)strlen(request->api_delim); + int lstr = + (int)strlen(request->signal) + (int)strlen(environment->api_archive) + (int)strlen(request->api_delim); if (lstr >= STRING_LENGTH) { - UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument, prefixed with the Archive Name, is too long!"); + UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, + "The Signal/Data Object Argument, prefixed with the Archive Name, is too long!"); } std::string test = fmt::format("{}{}{}", environment->api_archive, request->api_delim, request->signal); strcpy(request->signal, test.c_str()); @@ -104,7 +106,7 @@ int makeRequestData(const char* data_object, const char* data_source, REQUEST_DA * * Any attempted expansion of a server URL will result in a meaningless path. These are ignored by the server. * *** the original source is always retained ! - */ + */ // Path expansion disabled - applications must provide the full path to data resources. // XXXX::12345 shot number @@ -118,8 +120,7 @@ int makeRequestData(const char* data_object, const char* data_source, REQUEST_DA char* test = nullptr; if ((test = strstr(request->source, request->api_delim)) == nullptr) { - if (strchr(request->source, '(') == nullptr && - strchr(request->source, ')') == nullptr) { + if (strchr(request->source, '(') == nullptr && strchr(request->source, ')') == nullptr) { // source is not a function call strcpy(request->path, request->source); expandFilePath(request->path, getIdamClientEnvironment()); @@ -153,8 +154,9 @@ int makeClientRequestBlock(const char** signals, const char** sources, int count return err; } -void freeClientRequestBlock(REQUEST_BLOCK* request_block) { - if(request_block != nullptr && request_block->requests != nullptr) { +void freeClientRequestBlock(REQUEST_BLOCK* request_block) +{ + if (request_block != nullptr && request_block->requests != nullptr) { for (int i = 0; i < request_block->num_requests; i++) { freeNameValueList(&request_block->requests[i].nameValueList); freeClientPutDataBlockList(&request_block->requests[i].putDataBlockList); @@ -171,8 +173,12 @@ int shotRequestTest(const char* source) char* token = nullptr; char work[STRING_LENGTH]; - if (source[0] == '\0') return 0; - if (source[0] == '/') return 0; // Directory based data + if (source[0] == '\0') { + return 0; + } + if (source[0] == '/') { + return 0; // Directory based data + } //------------------------------------------------------------------------------ // Check if the source has one of these forms: @@ -180,14 +186,17 @@ int shotRequestTest(const char* source) // pulse plasma shot number - an integer // pulse/pass include a pass or sequence number - this may be a text based component, e.g. LATEST - if (IsNumber((char*) source)) return 1; // The source an integer number - + if (IsNumber((char*)source)) { + return 1; // The source an integer number + } + strcpy(work, source); - - if ((token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string - if (IsNumber(token)) return 1; // Is the First token an integer number? + + if ((token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string + if (IsNumber(token)) { + return 1; // Is the First token an integer number? + } } return 0; } - diff --git a/source/client/makeClientRequestBlock.h b/source/client/makeClientRequestBlock.h old mode 100755 new mode 100644 index a413dea8..54c43aff --- a/source/client/makeClientRequestBlock.h +++ b/source/client/makeClientRequestBlock.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENT_MAKECLIENTREQUESTBLOCK_H #define UDA_CLIENT_MAKECLIENTREQUESTBLOCK_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/client/startup.cpp b/source/client/startup.cpp old mode 100755 new mode 100644 index f8b44a96..5ae01540 --- a/source/client/startup.cpp +++ b/source/client/startup.cpp @@ -1,28 +1,28 @@ /*--------------------------------------------------------------- -* Open Client Side Log Files -* -* Argument: reset => if 1 then always reopen Files -* -* Checks for an Environment var (UDA_LOG) for the directory of the log file -* otherwise it assumes the file is to be local to the PWD. -* -* The directory named must not have a trailing forward slash. -* -* It is assumed that the directory specified by UDA_LOG already exits -* -* Returns: -* -*--------------------------------------------------------------*/ + * Open Client Side Log Files + * + * Argument: reset => if 1 then always reopen Files + * + * Checks for an Environment var (UDA_LOG) for the directory of the log file + * otherwise it assumes the file is to be local to the PWD. + * + * The directory named must not have a trailing forward slash. + * + * It is assumed that the directory specified by UDA_LOG already exits + * + * Returns: + * + *--------------------------------------------------------------*/ #include "startup.h" #include -#include -#include #include "udaErrors.h" +#include +#include -#include "udaClient.h" #include "getEnvironment.h" +#include "udaClient.h" int udaStartup(int reset, CLIENT_FLAGS* client_flags, bool* reopen_logs) { @@ -31,7 +31,9 @@ int udaStartup(int reset, CLIENT_FLAGS* client_flags, bool* reopen_logs) //--------------------------------------------------------------- // Are the Files Already Open? - if (start_status && !reset && !*reopen_logs) return 0; + if (start_status && !reset && !*reopen_logs) { + return 0; + } //---------------------------------------------------------------- // Read Environment Variable Values (Held in a Global Structure) @@ -59,17 +61,19 @@ int udaStartup(int reset, CLIENT_FLAGS* client_flags, bool* reopen_logs) //---------------------------------------------------------------- // X.509 Security Certification - //if((rc = readIdamSecurityCert(environment->security_cert)) != 0){ - // if(verbose) fprintf(stderr, "Idam: Problem Locating the Security Certificate [%d]\n", rc); - // return(-1); - //} + // if((rc = readIdamSecurityCert(environment->security_cert)) != 0){ + // if(verbose) fprintf(stderr, "Idam: Problem Locating the Security Certificate [%d]\n", rc); + // return(-1); + // } //---------------------------------------------------------------- // Check if Output Requested udaSetLogLevel((LOG_LEVEL)environment->loglevel); - if (environment->loglevel == UDA_LOG_NONE) return 0; + if (environment->loglevel == UDA_LOG_NONE) { + return 0; + } //--------------------------------------------------------------- // Open the Log File diff --git a/source/client/startup.h b/source/client/startup.h old mode 100755 new mode 100644 diff --git a/source/client/udaClient.cpp b/source/client/udaClient.cpp old mode 100755 new mode 100644 index 13766cd5..5444a9ea --- a/source/client/udaClient.cpp +++ b/source/client/udaClient.cpp @@ -1,36 +1,36 @@ #include "udaClient.h" -#include -#include #include +#include #include +#include -#include -#include "udaErrors.h" -#include #include "initStructs.h" -#include -#include -#include -#include "udaTypes.h" #include "struct.h" -#include -#include +#include "udaErrors.h" +#include "udaTypes.h" #include #include +#include +#include +#include +#include +#include +#include +#include -#include "closedown.h" #include "accAPI.h" +#include "closedown.h" #ifdef FATCLIENT # include # include #else # include "clientXDRStream.h" -# include -# include # include +# include # include +# include # ifdef SSLAUTHENTICATION # include # endif @@ -41,16 +41,17 @@ #if !defined(FATCLIENT) || !defined(NOLIBMEMCACHED) static int protocol_version = 9; #endif -int client_version = 9; // previous version +int client_version = 9; // previous version //---------------------------------------------------------------------------------------------------------------------- // FATCLIENT objects shared with server code #ifndef FATCLIENT -USERDEFINEDTYPELIST* g_user_defined_type_list = nullptr; // List of all known User Defined Structure Types -LOGMALLOCLIST* g_log_malloc_list = nullptr; // List of all Heap Allocations for Data -unsigned int g_last_malloc_index = 0; // Malloc Log search index last value -unsigned int* g_last_malloc_index_value = &g_last_malloc_index;; // Preserve Malloc Log search index last value in GENERAL_STRUCT +USERDEFINEDTYPELIST* g_user_defined_type_list = nullptr; // List of all known User Defined Structure Types +LOGMALLOCLIST* g_log_malloc_list = nullptr; // List of all Heap Allocations for Data +unsigned int g_last_malloc_index = 0; // Malloc Log search index last value +unsigned int* g_last_malloc_index_value = &g_last_malloc_index; +; // Preserve Malloc Log search index last value in GENERAL_STRUCT XDR** g_client_input = nullptr; XDR** g_client_output = nullptr; LOGSTRUCTLIST* g_log_struct_list = nullptr; @@ -82,7 +83,7 @@ void setLogMallocList(LOGMALLOCLIST* logmalloclist_in) #else void setUserDefinedTypeList(USERDEFINEDTYPELIST* userdefinedtypelist_in) {} -void setLogMallocList(LOGMALLOCLIST* logmalloclist_in){} +void setLogMallocList(LOGMALLOCLIST* logmalloclist_in) {} extern SOCKETLIST socket_list; #endif @@ -109,7 +110,7 @@ void updateClientBlock(CLIENT_BLOCK* str, const CLIENT_FLAGS* client_flags, unsi str->get_nodimdata = client_flags->get_nodimdata; str->privateFlags = private_flags; } -# ifndef NOLIBMEMCACHED +#ifndef NOLIBMEMCACHED /** * Check the local cache for the data (GET methods only - Note: some GET methods may disguise PUT methods!) * @@ -130,7 +131,7 @@ int check_file_cache(const REQUEST_DATA* request_data, DATA_BLOCK** p_data_block // Success int data_block_idx = acc_getIdamNewDataHandle(client_flags); - if (data_block_idx < 0) { // Error + if (data_block_idx < 0) { // Error return -data_block_idx; } @@ -160,15 +161,15 @@ int check_mem_cache(uda::cache::UdaCache* cache, REQUEST_DATA* request_data, DAT } // Query the cache for the Data - DATA_BLOCK* data = cache_read(cache, request_data, log_malloc_list, user_defined_type_list, - *getIdamClientEnvironment(), protocol_version, client_flags->flags, - log_struct_list, private_flags, malloc_source); + DATA_BLOCK* data = + cache_read(cache, request_data, log_malloc_list, user_defined_type_list, *getIdamClientEnvironment(), + protocol_version, client_flags->flags, log_struct_list, private_flags, malloc_source); if (data != nullptr) { // Success int data_block_idx = acc_getIdamNewDataHandle(client_flags); - if (data_block_idx < 0) { // Error + if (data_block_idx < 0) { // Error return -data_block_idx; } @@ -218,12 +219,12 @@ void copyClientBlock(CLIENT_BLOCK* str, const CLIENT_FLAGS* client_flags) } /* - *** stop using Data_Block_Count-1 to identify the new DATA_BLOCK structure, use newHandleIndex - *** retain Data_Block_Count as this identifies the upper value of valid handles issued - *** search for a handle < 0 - *** when freed/initialised, the DATA_BLOCK handle should be set to -1 - *** are there any instances where the data_block handle value is used? -*/ + *** stop using Data_Block_Count-1 to identify the new DATA_BLOCK structure, use newHandleIndex + *** retain Data_Block_Count as this identifies the upper value of valid handles issued + *** search for a handle < 0 + *** when freed/initialised, the DATA_BLOCK handle should be set to -1 + *** are there any instances where the data_block handle value is used? + */ #ifndef FATCLIENT /* @@ -231,12 +232,10 @@ void copyClientBlock(CLIENT_BLOCK* str, const CLIENT_FLAGS* client_flags) * * manages it's own client/server conversation current buffer status in protocolXML2 ... */ -static int -fetchHierarchicalData(XDR* client_input, DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, - unsigned int private_flags, int malloc_source) +static int fetchHierarchicalData(XDR* client_input, DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, + unsigned int private_flags, int malloc_source) { - if (data_block->data_type == UDA_TYPE_COMPOUND && - data_block->opaque_type != UDA_OPAQUE_TYPE_UNKNOWN) { + if (data_block->data_type == UDA_TYPE_COMPOUND && data_block->opaque_type != UDA_OPAQUE_TYPE_UNKNOWN) { int protocol_id; if (data_block->opaque_type == UDA_OPAQUE_TYPE_XML_DOCUMENT) { @@ -252,8 +251,9 @@ fetchHierarchicalData(XDR* client_input, DATA_BLOCK* data_block, LOGSTRUCTLIST* UDA_LOG(UDA_LOG_DEBUG, "Receiving Hierarchical Data Structure from Server\n"); int err = 0; - if ((err = protocol2(client_input, protocol_id, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - data_block, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { + if ((err = + protocol2(client_input, protocol_id, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, + data_block, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Client Side Protocol Error (Opaque Structure Type)"); return err; } @@ -275,8 +275,8 @@ static int allocMeta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, D *signal_rec = (SIGNAL*)malloc(sizeof(SIGNAL)); *signal_desc = (SIGNAL_DESC*)malloc(sizeof(SIGNAL_DESC)); - if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || - *signal_rec == nullptr || *signal_desc == nullptr) { + if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || *signal_rec == nullptr || + *signal_desc == nullptr) { err = ERROR_ALLOCATING_META_DATA_HEAP; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Error Allocating Heap for Meta Data"); return err; @@ -285,44 +285,48 @@ static int allocMeta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, D return err; } -static int -fetchMeta(XDR* client_input, DATA_SYSTEM* data_system, SYSTEM_CONFIG* system_config, DATA_SOURCE* data_source, - SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, - int malloc_source) +static int fetchMeta(XDR* client_input, DATA_SYSTEM* data_system, SYSTEM_CONFIG* system_config, + DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { int err = 0; -#ifndef FATCLIENT // <========================== Client Server Code Only - if ((err = protocol2(client_input, UDA_PROTOCOL_DATA_SYSTEM, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - data_system, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { +#ifndef FATCLIENT // <========================== Client Server Code Only + if ((err = protocol2(client_input, UDA_PROTOCOL_DATA_SYSTEM, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, data_system, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 4 Error (Data System)"); return err; } printDataSystem(*data_system); - if ((err = protocol2(client_input, UDA_PROTOCOL_SYSTEM_CONFIG, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - system_config, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { + if ((err = protocol2(client_input, UDA_PROTOCOL_SYSTEM_CONFIG, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, system_config, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error (System Config)"); return err; } printSystemConfig(*system_config); - if ((err = protocol2(client_input, UDA_PROTOCOL_DATA_SOURCE, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - data_source, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { + if ((err = protocol2(client_input, UDA_PROTOCOL_DATA_SOURCE, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, data_source, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 6 Error (Data Source)"); return err; } printDataSource(*data_source); - if ((err = protocol2(client_input, UDA_PROTOCOL_SIGNAL, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - signal_rec, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { + if ((err = protocol2(client_input, UDA_PROTOCOL_SIGNAL, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, signal_rec, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 7 Error (Signal)"); return err; } printSignal(*signal_rec); - if ((err = protocol2(client_input, UDA_PROTOCOL_SIGNAL_DESC, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - signal_desc, protocol_version, log_struct_list, private_flags, malloc_source)) != 0) { + if ((err = protocol2(client_input, UDA_PROTOCOL_SIGNAL_DESC, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, signal_desc, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 8 Error (Signal Desc)"); return err; } @@ -344,7 +348,6 @@ unsigned int* udaPrivateFlags() return &private_flags; } - int idamClient(REQUEST_BLOCK* request_block, int* indices) { // Efficient reduced (filled) tcp packet protocol for efficiency over large RTT fat pipes @@ -359,7 +362,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) # ifndef SECURITYENABLED static int startupStates; # endif // !SECURITYENABLED -#endif // !FATCLIENT +#endif // !FATCLIENT static bool system_startup = true; @@ -369,7 +372,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) static int malloc_source = UDA_MALLOC_SOURCE_NONE; #ifndef FATCLIENT - g_client_input = &client_input; // needed for udaFreeAll + g_client_input = &client_input; // needed for udaFreeAll g_client_output = &client_output; // needed for udaFreeAll #endif @@ -381,7 +384,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) client_flags->alt_rank = 0; client_flags->user_timeout = TIMEOUT; - time_t protocol_time; // Time a Conversation Occured + time_t protocol_time; // Time a Conversation Occured if (system_startup && getenv("UDA_TIMEOUT")) { client_flags->user_timeout = (int)strtol(getenv("UDA_TIMEOUT"), nullptr, 10); @@ -401,7 +404,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Initialise the Error Stack before Accessing Data if (tv_server_start != 0) { - freeIdamErrorStack(&server_block.idamerrorstack); // Free Previous Stack Heap + freeIdamErrorStack(&server_block.idamerrorstack); // Free Previous Stack Heap } initServerBlock(&server_block, 0); // Reset previous Error Messages from the Server & Free Heap @@ -434,10 +437,10 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) do { if (tv_server_start == 0) { - time(&tv_server_start); // First Call: Start the Clock + time(&tv_server_start); // First Call: Start the Clock } -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only # ifndef NOLIBMEMCACHED static uda::cache::UdaCache* cache; @@ -518,7 +521,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) # if !defined(FATCLIENT) && !defined(SECURITYENABLED) startupStates = 0; # endif - time(&tv_server_start); // Start the Clock again: Age of Server + time(&tv_server_start); // Start the Clock again: Age of Server //------------------------------------------------------------------------- // Connect to the server with SSL (X509) authentication @@ -553,9 +556,9 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) //------------------------------------------------------------------------- -#else // <========================== End of Client Server Code Only +#else // <========================== End of Client Server Code Only bool initServer = true; -#endif // <========================== End of FatClient Code Only +#endif // <========================== End of FatClient Code Only //------------------------------------------------------------------------- // Initialise the Client/Server Structures @@ -595,9 +598,9 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) //------------------------------------------------------------------------------ // User Authentication at startup -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only -#ifdef SECURITYENABLED +# ifdef SECURITYENABLED // Client/Server connection is established but neither the server nor the user identity has been authenticated. // Client initiates the process by sending an encrypted token with its claim of identity. @@ -606,13 +609,15 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Once passed, the original data request is processed. // TBD: - // Additional tests of identity will be included in consequent client/server dialogue to maintain authenticated state. - // If the connection breaks and the client has to start a new connection to the same host, the last good exchanged token - // (within a very short time window) can be used to byepass the multi-RTT cost of authentication. - // Use asynchronous encrypted caching to manage these short-lived session tokens. Use a key based on originating IP address and claimed identity. + // Additional tests of identity will be included in consequent client/server dialogue to maintain authenticated + // state. If the connection breaks and the client has to start a new connection to the same host, the last good + // exchanged token (within a very short time window) can be used to byepass the multi-RTT cost of + // authentication. Use asynchronous encrypted caching to manage these short-lived session tokens. Use a key + // based on originating IP address and claimed identity. - // When a server is a regular server and connects to another server as a data source, then the originating server has - // to authenticate as if a client. The originating client has also to authenticate with the final server. + // When a server is a regular server and connects to another server as a data source, then the originating + // server has to authenticate as if a client. The originating client has also to authenticate with the final + // server. // When a server is acting as a simple proxy it passes all requests onwards without authentication - it does not // interpret the data access request. @@ -625,7 +630,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // generate token A and encrypt with the server public key // send Client_block: the client certificate and encrypted token A - unsigned short authenticationStep = 1; // Client Certificate authenticated by server + unsigned short authenticationStep = 1; // Client Certificate authenticated by server if ((err = clientAuthentication(&client_block, &server_block, authenticationStep)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Client or Server Authentication Failed #1"); @@ -643,8 +648,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) break; } - // encrypt token B with the server public key => send proof client has a valid private key (paired with public key from certificate) - // send client block + // encrypt token B with the server public key => send proof client has a valid private key (paired + // with public key from certificate) send client block authenticationStep = 6; @@ -654,8 +659,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) } // receive server_block - // decrypt new token B using private key => proof server has a valid private key == server authenticated - // encrypt new token B with the server public key => maintain authentication + // decrypt new token B using private key => proof server has a valid private key == server + // authenticated encrypt new token B with the server public key => maintain authentication authenticationStep = 8; @@ -664,10 +669,10 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) break; } - authenticationNeeded = 0; // Both Client and Server have been mutually authenticated + authenticationNeeded = 0; // Both Client and Server have been mutually authenticated } -#else +# else //------------------------------------------------------------------------- // Client and Server States at Startup only (1 RTT) @@ -677,11 +682,11 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Flush (mark as at EOF) the input socket buffer (before the exchange begins) - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block (proxy for authenticationStep = 6) + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block (proxy for authenticationStep = 6) - if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, - &client_block, protocol_version, &log_struct_list, *private_flags, - malloc_source)) != 0) { + if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, + g_user_defined_type_list, &client_block, protocol_version, &log_struct_list, + *private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); UDA_LOG(UDA_LOG_DEBUG, "Error Sending Client Block\n"); break; @@ -704,11 +709,12 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) break; } - protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement (proxy for authenticationStep = 8) + protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement (proxy for + // authenticationStep = 8) - if ((err = protocol2(client_input, protocol_id, XDR_RECEIVE, nullptr, g_log_malloc_list, g_user_defined_type_list, - &server_block, protocol_version, &log_struct_list, *private_flags, - malloc_source)) != 0) { + if ((err = protocol2(client_input, protocol_id, XDR_RECEIVE, nullptr, g_log_malloc_list, + g_user_defined_type_list, &server_block, protocol_version, &log_struct_list, + *private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 11 Error (Server Block #1)"); // Assuming the server_block is corrupted, replace with a clean copy to avoid concatonation problems server_block.idamerrorstack.nerrors = 0; @@ -716,7 +722,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) break; } - // Flush (mark as at EOF) the input socket buffer (not all server state data may have been read - version dependent) + // Flush (mark as at EOF) the input socket buffer (not all server state data may have been read - version + // dependent) int rc = xdrrec_eof(client_input); @@ -730,7 +737,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) protocol_version = std::min(client_block.version, server_block.version); if (server_block.idamerrorstack.nerrors > 0) { - err = server_block.idamerrorstack.idamerror[0].code; // Problem on the Server Side! + err = server_block.idamerrorstack.idamerror[0].code; // Problem on the Server Side! break; } @@ -738,7 +745,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) } // startupStates -#endif // not SECURITYENABLED +# endif // not SECURITYENABLED //------------------------------------------------------------------------- // Check the Server version is not older than this client's version @@ -759,28 +766,29 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) char temp; do { - rc = xdr_char(client_input, &temp); // Flush the input (limit to 64 bytes) + rc = xdr_char(client_input, &temp); // Flush the input (limit to 64 bytes) if (rc) { UDA_LOG(UDA_LOG_DEBUG, "[%d] [%c]\n", count++, temp); } } while (rc && count < 64); - if (count > 0) { // Error if data is waiting + if (count > 0) { // Error if data is waiting err = 999; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Data waiting in the input data buffer when none expected! Please contact the system administrator."); + "Data waiting in the input data buffer when none expected! Please contact the system " + "administrator."); UDA_LOG(UDA_LOG_DEBUG, "[%d] excess data bytes waiting in input buffer!\n", count++); break; } - rc = xdrrec_eof(client_input); // Test for an EOF + rc = xdrrec_eof(client_input); // Test for an EOF if (!rc) { - rc = xdrrec_skiprecord(client_input); // Flush the input buffer (Zero data waiting but not an EOF!) + rc = xdrrec_skiprecord(client_input); // Flush the input buffer (Zero data waiting but not an EOF!) } - rc = xdrrec_eof(client_input); // Test for an EOF + rc = xdrrec_eof(client_input); // Test for an EOF if (!rc) { err = 999; @@ -796,24 +804,21 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) //------------------------------------------------------------------------- // Send the Client Block - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, - &client_block, protocol_version, &log_struct_list, *private_flags, - malloc_source)) != 0) { + &client_block, protocol_version, &log_struct_list, *private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); break; } - //------------------------------------------------------------------------- // Send the Client Request - protocol_id = UDA_PROTOCOL_REQUEST_BLOCK; // This is what the Client Wants + protocol_id = UDA_PROTOCOL_REQUEST_BLOCK; // This is what the Client Wants if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, - request_block, protocol_version, &log_struct_list, *private_flags, - malloc_source)) != 0) { + request_block, protocol_version, &log_struct_list, *private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (Request Block)"); break; } @@ -827,9 +832,9 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) if (request->put) { protocol_id = UDA_PROTOCOL_PUTDATA_BLOCK_LIST; - if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, - &(request->putDataBlockList), protocol_version, &log_struct_list, - *private_flags, malloc_source)) != 0) { + if ((err = protocol2(client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, + g_user_defined_type_list, &(request->putDataBlockList), protocol_version, + &log_struct_list, *private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (sending putDataBlockList from Request Block)"); break; @@ -879,13 +884,13 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) if (server_block.idamerrorstack.nerrors > 0) { UDA_LOG(UDA_LOG_DEBUG, "Server Block passed Server Error State %d\n", err); - err = server_block.idamerrorstack.idamerror[0].code; // Problem on the Server Side! + err = server_block.idamerrorstack.idamerror[0].code; // Problem on the Server Side! UDA_LOG(UDA_LOG_DEBUG, "Server Block passed Server Error State %d\n", err); - serverside = 1; // Most Server Side errors are benign so don't close the server + serverside = 1; // Most Server Side errors are benign so don't close the server break; } -#endif // not FATCLIENT // <===== End of Client Server Only Code +#endif // not FATCLIENT // <===== End of Client Server Only Code //------------------------------------------------------------------------------ // Return Database Meta Data if User Requests it @@ -907,7 +912,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) #endif // <===== End of Client Server Only Code } -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only //------------------------------------------------------------------------------ // Fetch the data Block @@ -915,8 +920,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) DATA_BLOCK_LIST recv_data_block_list; if ((err = protocol2(client_input, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_RECEIVE, nullptr, g_log_malloc_list, - g_user_defined_type_list, &recv_data_block_list, protocol_version, - &log_struct_list, *private_flags, malloc_source)) != 0) { + g_user_defined_type_list, &recv_data_block_list, protocol_version, &log_struct_list, + *private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Protocol 2 Error (Failure Receiving Data Block)\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 2 Error (Failure Receiving Data Block)"); @@ -933,7 +938,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Re-use existing stale Data Blocks int data_block_idx = acc_getIdamNewDataHandle(client_flags); - if (data_block_idx < 0) { // Error + if (data_block_idx < 0) { // Error data_block_indices[i] = -data_block_idx; continue; } @@ -952,12 +957,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) copyClientBlock(&data_block->client_block, client_flags); if (client_block.get_meta) { - if ((err = allocMeta( - &data_block->data_system, - &data_block->system_config, - &data_block->data_source, - &data_block->signal_rec, - &data_block->signal_desc)) != 0) { + if ((err = allocMeta(&data_block->data_system, &data_block->system_config, &data_block->data_source, + &data_block->signal_rec, &data_block->signal_desc)) != 0) { break; } *data_block->data_system = *data_system; @@ -972,20 +973,20 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) //------------------------------------------------------------------------------ // Cache the data if the server has passed permission and the application (client) has enabled caching if (client_flags->flags & CLIENTFLAG_FILECACHE) { - udaFileCacheWrite(data_block, request_block, g_log_malloc_list, g_user_defined_type_list, protocol_version, - &log_struct_list, *private_flags, malloc_source); + udaFileCacheWrite(data_block, request_block, g_log_malloc_list, g_user_defined_type_list, + protocol_version, &log_struct_list, *private_flags, malloc_source); } # ifndef NOLIBMEMCACHED # ifdef CACHEDEV - if (cache != nullptr && clientFlags & CLIENTFLAG_CACHE - && data_block.cachePermission == UDA_PLUGIN_OK_TO_CACHE) { + if (cache != nullptr && clientFlags & CLIENTFLAG_CACHE && + data_block.cachePermission == UDA_PLUGIN_OK_TO_CACHE) { # else if (cache != nullptr && client_flags->flags & CLIENTFLAG_CACHE) { # endif cache_write(cache, &request_block->requests[i], data_block, g_log_malloc_list, g_user_defined_type_list, - *environment, protocol_version, client_flags->flags, &log_struct_list, - *private_flags, malloc_source); + *environment, protocol_version, client_flags->flags, &log_struct_list, *private_flags, + malloc_source); } # endif // !NOLIBMEMCACHED @@ -997,7 +998,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) UDA_LOG(UDA_LOG_DEBUG, "Hierarchical Structure Block Received\n"); -#else // <========================== End of Client Server Code Only (not FATCLIENT) +#else // <========================== End of Client Server Code Only (not FATCLIENT) //------------------------------------------------------------------------------ // Fat Client Server @@ -1024,17 +1025,17 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) // Decompresss Dimensional Data - for (int i = 0; i < (int)data_block->rank; i++) { // Expand Compressed Regular Vector - err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required - err = 0; // Need to Test for Error Condition! + for (int i = 0; i < (int)data_block->rank; i++) { // Expand Compressed Regular Vector + err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required + err = 0; // Need to Test for Error Condition! } printDataBlock(*data_block); } -#endif // <========================== End of FatClient Code Only - //------------------------------------------------------------------------------ - // End of Error Trap Loop +#endif // <========================== End of FatClient Code Only + //------------------------------------------------------------------------------ + // End of Error Trap Loop } while (0); @@ -1051,7 +1052,7 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) cached_data_block_list.data = nullptr; -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only //------------------------------------------------------------------------------ // Close all File Handles, Streams, sockets and Free Heap Memory @@ -1065,7 +1066,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) for (auto data_block_idx : data_block_indices) { if (err == 0 && (getIdamDataStatus(data_block_idx)) == MIN_STATUS && !client_flags->get_bad) { // If Data are not usable, flag the client - addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, "Data Status is BAD ... Data are Not Usable!"); + 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); if (data_block->errcode == 0) { @@ -1127,16 +1129,16 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) return ERROR_CONDITION_UNKNOWN; } - return -abs(err); // Abnormal Exit + return -abs(err); // Abnormal Exit } } -#else // <========================== End of Client Server Code Only (not FATCLIENT) +#else // <========================== End of Client Server Code Only (not FATCLIENT) -//------------------------------------------------------------------------------ -// If an error has occured: Close all File Handles, Streams, sockets and Free Heap Memory + //------------------------------------------------------------------------------ + // If an error has occured: Close all File Handles, Streams, sockets and Free Heap Memory -//rc = fflush(nullptr); // save anything ... the user might not follow correct procedure! + // rc = fflush(nullptr); // save anything ... the user might not follow correct procedure! if (data_received) { if (err != 0) { @@ -1146,7 +1148,8 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) for (auto data_block_idx : data_block_indices) { if (err == 0 && (getIdamDataStatus(data_block_idx) == MIN_STATUS) && !client_flags->get_bad) { // If Data are not usable, flag the client - addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, "Data Status is BAD ... Data are Not Usable!"); + 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); if (data_block->errcode == 0) { @@ -1210,11 +1213,11 @@ int idamClient(REQUEST_BLOCK* request_block, int* indices) return ERROR_CONDITION_UNKNOWN; } - return -abs(err); // Abnormal Exit + return -abs(err); // Abnormal Exit } } -#endif // <========================== End of FatClient Code Only +#endif // <========================== End of FatClient Code Only void udaFree(int handle) { @@ -1227,7 +1230,9 @@ void udaFree(int handle) DATA_BLOCK* data_block = getIdamDataBlock(handle); - if (data_block == nullptr) { return; } + if (data_block == nullptr) { + return; + } // Free Hierarchical structured data first @@ -1249,7 +1254,8 @@ void udaFree(int handle) if (general_block->userdefinedtypelist != nullptr) { #ifndef FATCLIENT - if (g_user_defined_type_list == general_block->userdefinedtypelist) { // Is this the current setting? + if (g_user_defined_type_list == + general_block->userdefinedtypelist) { // Is this the current setting? freeUserDefinedTypeList(g_user_defined_type_list); free(g_user_defined_type_list); g_user_defined_type_list = nullptr; @@ -1322,7 +1328,7 @@ void udaFree(int handle) if ((cptr = data_block->data) != nullptr) { free(cptr); - data_block->data = nullptr; // Prevent another Free + data_block->data = nullptr; // Prevent another Free } if ((cptr = data_block->errhi) != nullptr) { @@ -1383,7 +1389,7 @@ void udaFree(int handle) free(cptr); } - data_block->dims[i].dim = nullptr; // Prevent another Free + data_block->dims[i].dim = nullptr; // Prevent another Free data_block->dims[i].synthetic = nullptr; data_block->dims[i].errhi = nullptr; data_block->dims[i].errlo = nullptr; @@ -1406,13 +1412,13 @@ void udaFree(int handle) } free(ddims); - data_block->dims = nullptr; // Prevent another Free + data_block->dims = nullptr; // Prevent another Free } // closeIdamError(&server_block.idamerrorstack); freeIdamErrorStack(&server_block.idamerrorstack); initDataBlock(data_block); - data_block->handle = -1; // Flag this as ready for re-use + data_block->handle = -1; // Flag this as ready for re-use } void udaFreeAll() @@ -1440,7 +1446,7 @@ void udaFreeAll() acc_freeDataBlocks(); #ifndef FATCLIENT - g_user_defined_type_list = nullptr; // malloc'd within protocolXML + g_user_defined_type_list = nullptr; // malloc'd within protocolXML g_log_malloc_list = nullptr; #endif @@ -1454,11 +1460,11 @@ void udaFreeAll() // To avoid this, we can send a CLIENT_BLOCK with a CLOSEDOWN instruction. if (connectionOpen()) { - client_block.timeout = 0; // Surrogate CLOSEDOWN instruction - client_block.clientFlags = client_block.clientFlags | CLIENTFLAG_CLOSEDOWN; // Direct CLOSEDOWN instruction + client_block.timeout = 0; // Surrogate CLOSEDOWN instruction + client_block.clientFlags = client_block.clientFlags | CLIENTFLAG_CLOSEDOWN; // Direct CLOSEDOWN instruction protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; - protocol2(*g_client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, &client_block, - protocol_version, g_log_struct_list, *udaPrivateFlags(), UDA_MALLOC_SOURCE_NONE); + protocol2(*g_client_output, protocol_id, XDR_SEND, nullptr, g_log_malloc_list, g_user_defined_type_list, + &client_block, protocol_version, g_log_struct_list, *udaPrivateFlags(), UDA_MALLOC_SOURCE_NONE); xdrrec_endofrecord(*g_client_output, 1); } @@ -1495,9 +1501,9 @@ void putIdamThreadClientBlock(CLIENT_BLOCK* str) } CLIENT_BLOCK saveIdamProperties(const CLIENT_FLAGS* client_flags) -{ // save current state of properties for future rollback - CLIENT_BLOCK cb = client_block; // Copy of Global Structure (maybe not initialised! i.e. idam API not called) - cb.get_datadble = client_flags->get_datadble; // Copy individual properties only +{ // save current state of properties for future rollback + CLIENT_BLOCK cb = client_block; // Copy of Global Structure (maybe not initialised! i.e. idam API not called) + cb.get_datadble = client_flags->get_datadble; // Copy individual properties only cb.get_dimdble = client_flags->get_dimdble; cb.get_timedble = client_flags->get_timedble; cb.get_bad = client_flags->get_bad; @@ -1515,8 +1521,8 @@ CLIENT_BLOCK saveIdamProperties(const CLIENT_FLAGS* client_flags) } void restoreIdamProperties(CLIENT_BLOCK cb, CLIENT_FLAGS* client_flags) -{ // Restore Properties to a prior saved state - client_block.get_datadble = cb.get_datadble; // Overwrite Individual Global Structure Components +{ // Restore Properties to a prior saved state + client_block.get_datadble = cb.get_datadble; // Overwrite Individual Global Structure Components client_block.get_dimdble = cb.get_dimdble; client_block.get_timedble = cb.get_timedble; client_block.get_bad = cb.get_bad; @@ -1546,8 +1552,8 @@ void restoreIdamProperties(CLIENT_BLOCK cb, CLIENT_FLAGS* client_flags) //! get the UDA client study DOI /** -* @return the DOI -*/ + * @return the DOI + */ const char* getIdamClientDOI() { return client_block.DOI; @@ -1555,8 +1561,8 @@ const char* getIdamClientDOI() //! put the UDA client study DOI /** -* @assign the DOI -*/ + * @assign the DOI + */ void putIdamClientDOI(char* doi) { strcpy(client_block.DOI, doi); @@ -1564,8 +1570,8 @@ void putIdamClientDOI(char* doi) //! get the UDA server configuration DOI /** -* @return the DOI -*/ + * @return the DOI + */ const char* getIdamServerDOI() { return server_block.DOI; @@ -1573,8 +1579,8 @@ const char* getIdamServerDOI() //! get the UDA client OS Name /** -* @return the OS name -*/ + * @return the OS name + */ const char* getIdamClientOSName() { return client_block.OSName; @@ -1582,8 +1588,8 @@ const char* getIdamClientOSName() //! put the UDA client OS Name /** -* @assign the OS name -*/ + * @assign the OS name + */ void putIdamClientOSName(char* os) { strcpy(client_block.OSName, os); @@ -1591,8 +1597,8 @@ void putIdamClientOSName(char* os) //! get the UDA server environment OS Name /** -* @return the OS name -*/ + * @return the OS name + */ const char* getIdamServerOSName() { return server_block.OSName; @@ -1600,80 +1606,80 @@ const char* getIdamServerOSName() //! the UDA client library verion number /** -* @return the verion number -*/ + * @return the verion number + */ int getIdamClientVersion() { - return client_version; // Client Library Version + return client_version; // Client Library Version } //! the UDA server verion number /** -* @return the verion number -*/ + * @return the verion number + */ int getIdamServerVersion() { - return server_block.version; // Server Version + return server_block.version; // Server Version } //! the UDA server error code returned /** -* @return the error code -*/ + * @return the error code + */ int getIdamServerErrorCode() { - return server_block.error; // Server Error Code + return server_block.error; // Server Error Code } //! the UDA server error message returned /** -* @return the error message -*/ + * @return the error message + */ const char* getIdamServerErrorMsg() { - return server_block.msg; // Server Error Message + return server_block.msg; // Server Error Message } //! the number of UDA server error message records returned in the error stack /** -* @return the number of records -*/ + * @return the number of records + */ int getIdamServerErrorStackSize() { - return server_block.idamerrorstack.nerrors; // Server Error Stack Size (No.Records) + return server_block.idamerrorstack.nerrors; // Server Error Stack Size (No.Records) } //! the Type of server error of a specific server error record /** -* @param record the error stack record number -* @return the type id -*/ + * @param record the error stack record number + * @return the type id + */ int getIdamServerErrorStackRecordType(int record) { if (record < 0 || (unsigned int)record >= server_block.idamerrorstack.nerrors) { return 0; } - return server_block.idamerrorstack.idamerror[record].type; // Server Error Stack Record Type + return server_block.idamerrorstack.idamerror[record].type; // Server Error Stack Record Type } //! the Error code of a specific server error record /** -* @param record the error stack record number -* @return the error code -*/ + * @param record the error stack record number + * @return the error code + */ int getIdamServerErrorStackRecordCode(int record) { if (record < 0 || (unsigned int)record >= server_block.idamerrorstack.nerrors) { return 0; } - return server_block.idamerrorstack.idamerror[record].code; // Server Error Stack Record Code + return server_block.idamerrorstack.idamerror[record].code; // Server Error Stack Record Code } //! the Server error Location name of a specific error record /** -* @param record the error stack record number -* @return the location name -*/ + * @param record the error stack record number + * @return the location name + */ const char* getIdamServerErrorStackRecordLocation(int record) { if (record < 0 || (unsigned int)record >= server_block.idamerrorstack.nerrors) { @@ -1684,9 +1690,9 @@ const char* getIdamServerErrorStackRecordLocation(int record) //! the Server error message of a specific error record /** -* @param record the error stack record number -* @return the error message -*/ + * @param record the error stack record number + * @return the error message + */ const char* getIdamServerErrorStackRecordMsg(int record) { UDA_LOG(UDA_LOG_DEBUG, "record %d\n", record); @@ -1694,7 +1700,7 @@ const char* getIdamServerErrorStackRecordMsg(int record) if (record < 0 || (unsigned int)record >= server_block.idamerrorstack.nerrors) { return nullptr; } - return server_block.idamerrorstack.idamerror[record].msg; // Server Error Stack Record Message + return server_block.idamerrorstack.idamerror[record].msg; // Server Error Stack Record Message } //! Return the Server error message stack data structure @@ -1703,5 +1709,5 @@ const char* getIdamServerErrorStackRecordMsg(int record) */ UDA_ERROR_STACK* getUdaServerErrorStack() { - return &server_block.idamerrorstack; // Server Error Stack Structure + return &server_block.idamerrorstack; // Server Error Stack Structure } diff --git a/source/client/udaClient.h b/source/client/udaClient.h index 8b3253fa..8f1bd07c 100644 --- a/source/client/udaClient.h +++ b/source/client/udaClient.h @@ -1,11 +1,11 @@ #pragma once #ifndef UDA_CLIENT_UDACLIENT_H -#define UDA_CLIENT_UDACLIENT_H +# define UDA_CLIENT_UDACLIENT_H -#include "genStructs.h" -#include "udaStructs.h" -#include "client.h" +# include "client.h" +# include "genStructs.h" +# include "udaStructs.h" int idamClient(REQUEST_BLOCK* request_block, int* indices); diff --git a/source/client/udaClientHostList.cpp b/source/client/udaClientHostList.cpp old mode 100755 new mode 100644 index 398cc4ad..93cd6eaa --- a/source/client/udaClientHostList.cpp +++ b/source/client/udaClientHostList.cpp @@ -1,15 +1,15 @@ /*--------------------------------------------------------------- -* Identify the Server Host Attributes -* Is user authentication over SSL? -*---------------------------------------------------------------------------------------------------------------------*/ + * Identify the Server Host Attributes + * Is user authentication over SSL? + *---------------------------------------------------------------------------------------------------------------------*/ +#include +#include +#include #include -#include -#include #include -#include -#include -#include +#include +#include #ifndef _WIN32 # include @@ -44,7 +44,7 @@ const HostData* udaClientFindHostByName(const char* name) const char* target = name; if (strcasestr(name, "SSL://")) { - target = &name[6]; // Host name must be stripped of SSL:// prefix + target = &name[6]; // Host name must be stripped of SSL:// prefix } for (const auto& data : g_host_list) { @@ -69,7 +69,7 @@ void udaClientInitHostList() // Locate the hosts registration file - constexpr const char* filename = "hosts.cfg"; // Default name + constexpr const char* filename = "hosts.cfg"; // Default name const char* config = getenv("UDA_CLIENT_HOSTS_CONFIG"); // Host configuration file std::string config_file; @@ -101,10 +101,12 @@ void udaClientInitHostList() // hostAlias and other attributes are not required // ordering is not important - // The host_name may be either a resolvable name or a numeric IP address. The latter may be in either IPv4 or IPv6 format. + // The host_name may be either a resolvable name or a numeric IP address. The latter may be in either IPv4 or IPv6 + // format. // The port number must be given separately from the IP address if the format is IPv6 - // The port number may be appended to the host name or IPv4 numeric address using the standard convention host:port pattern + // The port number may be appended to the host name or IPv4 numeric address using the standard convention host:port + // pattern // if the host IP address or name is prefixed with SSL:// this is stripped off and the isSSL bool set true // if the certificates and private key are defined, the isSSL bool set true @@ -121,7 +123,7 @@ void udaClientInitHostList() std::vector tokens; boost::split(tokens, line, boost::is_any_of(" ")); - std::for_each(tokens.begin(), tokens.end(), [](std::string& s){ boost::trim(s); }); + std::for_each(tokens.begin(), tokens.end(), [](std::string& s) { boost::trim(s); }); std::string name = tokens[0]; @@ -178,9 +180,8 @@ void udaClientInitHostList() // Extract and Strip the port number from the host name (a.b.c:9999, localhost:9999) for (auto& data : g_host_list) { size_t p; - if ((boost::iequals(data.host_name, "localhost") || data.host_name.find('.') != std::string::npos) - && (p = data.host_name.find(':')) != std::string::npos - && data.host_name.size() + 1 < p) { + if ((boost::iequals(data.host_name, "localhost") || data.host_name.find('.') != std::string::npos) && + (p = data.host_name.find(':')) != std::string::npos && data.host_name.size() + 1 < p) { data.port = atoi(&data.host_name[p]); data.host_name.resize(p); } diff --git a/source/client/udaClientHostList.h b/source/client/udaClientHostList.h old mode 100755 new mode 100644 index 29e1a1bf..09d677b7 --- a/source/client/udaClientHostList.h +++ b/source/client/udaClientHostList.h @@ -1,11 +1,11 @@ #pragma once #ifndef UDA_CLIENT_HOSTLIST_H -#define UDA_CLIENT_HOSTLIST_H +# define UDA_CLIENT_HOSTLIST_H -#include "export.h" -#include -#include +# include "export.h" +# include +# include void udaClientFreeHostList(); const HostData* udaClientFindHostByAlias(const char* alias); diff --git a/source/client/updateSelectParms.cpp b/source/client/updateSelectParms.cpp old mode 100755 new mode 100644 index bd541e8f..33d71386 --- a/source/client/updateSelectParms.cpp +++ b/source/client/updateSelectParms.cpp @@ -4,9 +4,10 @@ #include "updateSelectParms.h" -void udaUpdateSelectParms(int fd, fd_set *rfds, struct timeval *tv) { +void udaUpdateSelectParms(int fd, fd_set* rfds, struct timeval* tv) +{ FD_ZERO(rfds); FD_SET(fd, rfds); tv->tv_sec = 0; - tv->tv_usec = 500; // in microsecs => 0.5 ms wait + tv->tv_usec = 500; // in microsecs => 0.5 ms wait } diff --git a/source/client/updateSelectParms.h b/source/client/updateSelectParms.h old mode 100755 new mode 100644 index cca669c6..bc4dd322 --- a/source/client/updateSelectParms.h +++ b/source/client/updateSelectParms.h @@ -1,16 +1,16 @@ #pragma once #ifndef UDA_CLIENT_UPDATESELECTPARMS_H -#define UDA_CLIENT_UPDATESELECTPARMS_H +# define UDA_CLIENT_UPDATESELECTPARMS_H -#include -#include "export.h" +# include "export.h" +# include -#ifndef _WIN32 -# include -#else -# include -#endif +# ifndef _WIN32 +# include +# else +# include +# endif void udaUpdateSelectParms(int fd, fd_set* rfds, struct timeval* tv); diff --git a/source/client2/client.cpp b/source/client2/client.cpp index 1a80eb58..65d96ee9 100644 --- a/source/client2/client.cpp +++ b/source/client2/client.cpp @@ -1,27 +1,28 @@ #include "client.hpp" +#include "accAPI.h" #include "client_environment.hpp" -#include "make_request_block.hpp" -#include "error_codes.h" #include "client_xdr_stream.hpp" -#include "accAPI.h" +#include "error_codes.h" #include "exceptions.hpp" +#include "make_request_block.hpp" +#include "initStructs.h" #include "udaDefines.h" -#include +#include "udaErrors.h" +#include "udaTypes.h" +#include +#include #include -#include "initStructs.h" #include -#include #include -#include "udaErrors.h" -#include -#include -#include "udaTypes.h" #include -#include +#include +#include +#include -namespace { +namespace +{ void copy_data_block(DATA_BLOCK* str, DATA_BLOCK* in) { @@ -52,8 +53,8 @@ void copy_client_block(CLIENT_BLOCK* str, const ClientFlags* client_flags) str->get_nodimdata = client_flags->get_nodimdata; } -int alloc_meta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, DATA_SOURCE** data_source, - SIGNAL** signal_rec, SIGNAL_DESC** signal_desc) +int alloc_meta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, DATA_SOURCE** data_source, SIGNAL** signal_rec, + SIGNAL_DESC** signal_desc) { int err = 0; @@ -64,8 +65,8 @@ int alloc_meta(DATA_SYSTEM** data_system, SYSTEM_CONFIG** system_config, DATA_SO *signal_rec = (SIGNAL*)malloc(sizeof(SIGNAL)); *signal_desc = (SIGNAL_DESC*)malloc(sizeof(SIGNAL_DESC)); - if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || - *signal_rec == nullptr || *signal_desc == nullptr) { + if (*data_system == nullptr || *system_config == nullptr || *data_source == nullptr || *signal_rec == nullptr || + *signal_desc == nullptr) { err = ERROR_ALLOCATING_META_DATA_HEAP; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Error Allocating Heap for Meta Data"); return err; @@ -106,11 +107,9 @@ void update_client_block(CLIENT_BLOCK& client_block, const ClientFlags& client_f } } -} // anon namespace +} // namespace -uda::client::Client::Client() - : connection_{environment_} - , protocol_version_{ClientVersion} +uda::client::Client::Client() : connection_{environment_}, protocol_version_{ClientVersion} { host_ = DefaultHost; port_ = DefaultPort; @@ -145,10 +144,10 @@ uda::client::Client::Client() //---------------------------------------------------------------- // X.509 Security Certification - //if((rc = readIdamSecurityCert(environment->security_cert)) != 0){ - // if(verbose) fprintf(stderr, "Idam: Problem Locating the Security Certificate [%d]\n", rc); - // return(-1); - //} + // if((rc = readIdamSecurityCert(environment->security_cert)) != 0){ + // if(verbose) fprintf(stderr, "Idam: Problem Locating the Security Certificate [%d]\n", rc); + // return(-1); + // } cache_ = uda::cache::open_cache(); @@ -201,12 +200,11 @@ uda::client::Client::Client() } } -int -uda::client::Client::fetch_meta() +int uda::client::Client::fetch_meta() { int err = 0; -#ifndef FATCLIENT // <========================== Client Server Code Only +#ifndef FATCLIENT // <========================== Client Server Code Only DATA_SYSTEM* data_system = &metadata_.data_system; SYSTEM_CONFIG* system_config = &metadata_.system_config; DATA_SOURCE* data_source = &metadata_.data_source; @@ -214,24 +212,24 @@ uda::client::Client::fetch_meta() SIGNAL_DESC* signal_desc = &metadata_.signal_desc; if ((err = protocol2(client_input_, UDA_PROTOCOL_DATA_SYSTEM, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, - data_system, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, data_system, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 4 Error (Data System)"); return err; } printDataSystem(*data_system); if ((err = protocol2(client_input_, UDA_PROTOCOL_SYSTEM_CONFIG, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, - system_config, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, system_config, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error (System Config)"); return err; } printSystemConfig(*system_config); if ((err = protocol2(client_input_, UDA_PROTOCOL_DATA_SOURCE, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, - data_source, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, data_source, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 6 Error (Data Source)"); return err; } @@ -245,8 +243,8 @@ uda::client::Client::fetch_meta() printSignal(*signal_rec); if ((err = protocol2(client_input_, UDA_PROTOCOL_SIGNAL_DESC, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, - signal_desc, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, signal_desc, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 8 Error (Signal Desc)"); return err; } @@ -256,11 +254,9 @@ uda::client::Client::fetch_meta() return err; } -int -uda::client::Client::fetch_hierarchical_data(DATA_BLOCK* data_block) +int uda::client::Client::fetch_hierarchical_data(DATA_BLOCK* data_block) { - if (data_block->data_type == UDA_TYPE_COMPOUND && - data_block->opaque_type != UDA_OPAQUE_TYPE_UNKNOWN) { + if (data_block->data_type == UDA_TYPE_COMPOUND && data_block->opaque_type != UDA_OPAQUE_TYPE_UNKNOWN) { int protocol_id; if (data_block->opaque_type == UDA_OPAQUE_TYPE_XML_DOCUMENT) { @@ -293,7 +289,7 @@ const char* uda::client::Client::get_server_error_stack_record_msg(int record) if (record < 0 || (unsigned int)record >= server_block_.idamerrorstack.nerrors) { return nullptr; } - return server_block_.idamerrorstack.idamerror[record].msg; // Server Error Stack Record Message + return server_block_.idamerrorstack.idamerror[record].msg; // Server Error Stack Record Message } int uda::client::Client::get_server_error_stack_record_code(int record) @@ -301,11 +297,13 @@ int uda::client::Client::get_server_error_stack_record_code(int record) if (record < 0 || (unsigned int)record >= server_block_.idamerrorstack.nerrors) { return 0; } - return server_block_.idamerrorstack.idamerror[record].code; // Server Error Stack Record Code + return server_block_.idamerrorstack.idamerror[record].code; // Server Error Stack Record Code } -namespace { -int get_signal_status(DATA_BLOCK *data_block) { +namespace +{ +int get_signal_status(DATA_BLOCK* data_block) +{ // Signal Status if (data_block == nullptr) { return 0; @@ -313,7 +311,8 @@ int get_signal_status(DATA_BLOCK *data_block) { return data_block->signal_status; } -int get_data_status(DATA_BLOCK *data_block) { +int get_data_status(DATA_BLOCK* data_block) +{ // Data Status based on Standard Rule if (data_block == nullptr) { return 0; @@ -325,7 +324,7 @@ int get_data_status(DATA_BLOCK *data_block) { return data_block->signal_status; } } -} // anon namespace +} // namespace int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) { @@ -362,18 +361,18 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) if (client_output_->x_ops == nullptr || client_input_->x_ops == nullptr) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, "XDR Streams are Closed!"); UDA_LOG(UDA_LOG_DEBUG, "XDR Streams are Closed!\n"); - closedown(ClosedownType::CLOSE_SOCKETS, &connection_, client_input_, client_output_, &reopen_logs_, &env_host_, - &env_port_); + closedown(ClosedownType::CLOSE_SOCKETS, &connection_, client_input_, client_output_, &reopen_logs_, + &env_host_, &env_port_); } else { init_server = false; xdrrec_eof(client_input_); // Flush input socket } } - //bool authentication_needed = false; + // bool authentication_needed = false; bool startup_states = false; if (init_server) { - //authentication_needed = true; + // authentication_needed = true; startup_states = true; if (connection_.create(client_input_, client_output_, host_list_) != 0) { int err = NO_SOCKET_CONNECTION; @@ -383,7 +382,7 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) io_data_ = connection_.io_data(); std::tie(client_input_, client_output_) = createXDRStream(&io_data_); - time(&tv_server_start); // Start the Clock again: Age of Server + time(&tv_server_start); // Start the Clock again: Age of Server } char* env = nullptr; @@ -418,13 +417,13 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) err = receive_server_block(); - //bool server_side = false; + // bool server_side = false; if (server_block_.idamerrorstack.nerrors > 0) { UDA_LOG(UDA_LOG_DEBUG, "Server Block passed Server Error State %d\n", err); - err = server_block_.idamerrorstack.idamerror[0].code; // Problem on the Server Side! + err = server_block_.idamerrorstack.idamerror[0].code; // Problem on the Server Side! UDA_LOG(UDA_LOG_DEBUG, "Server Block passed Server Error State %d\n", err); - //server_side = true; // Most Server Side errors are benign so don't close the server + // server_side = true; // Most Server Side errors are benign so don't close the server return 0; } @@ -440,8 +439,8 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) DATA_BLOCK_LIST recv_data_block_list; if ((err = protocol2(client_input_, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, &recv_data_block_list, protocol_version_, - &log_struct_list_, private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, &recv_data_block_list, protocol_version_, &log_struct_list_, + private_flags_, malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Protocol 2 Error (Failure Receiving Data Block)\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 2 Error (Failure Receiving Data Block)"); @@ -467,19 +466,15 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) data_block->data_source = (DATA_SOURCE*)malloc(sizeof(DATA_SOURCE)); data_block->signal_rec = (SIGNAL*)malloc(sizeof(SIGNAL)); data_block->signal_desc = (SIGNAL_DESC*)malloc(sizeof(SIGNAL_DESC)); - if ((err = alloc_meta( - &data_block->data_system, - &data_block->system_config, - &data_block->data_source, - &data_block->signal_rec, - &data_block->signal_desc)) != 0) { + if ((err = alloc_meta(&data_block->data_system, &data_block->system_config, &data_block->data_source, + &data_block->signal_rec, &data_block->signal_desc)) != 0) { break; } - *data_block->data_system = metadata_.data_system; - *data_block->system_config = metadata_.system_config; - *data_block->data_source = metadata_.data_source; - *data_block->signal_rec = metadata_.signal_rec; - *data_block->signal_desc = metadata_.signal_desc; + *data_block->data_system = metadata_.data_system; + *data_block->system_config = metadata_.system_config; + *data_block->data_source = metadata_.data_source; + *data_block->signal_rec = metadata_.signal_rec; + *data_block->signal_desc = metadata_.signal_desc; } fetch_hierarchical_data(data_block); @@ -493,8 +488,8 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) if (cache_ != nullptr && client_flags_.flags & CLIENTFLAG_CACHE) { cache_write(cache_, &request_block.requests[i], data_block, logmalloclist_, userdefinedtypelist_, - environment_, protocol_version_, client_flags_.flags, &log_struct_list_, - private_flags_, malloc_source_); + environment_, protocol_version_, client_flags_.flags, &log_struct_list_, private_flags_, + malloc_source_); } data_block_indices[i] = data_block_idx; @@ -515,7 +510,8 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) if (err == 0 && (get_data_status(data_block) == MIN_STATUS) && !client_flags_.get_bad) { // If Data are not usable, flag the client - addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, "Data Status is BAD ... Data are Not Usable!"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, DATA_STATUS_BAD, + "Data Status is BAD ... Data are Not Usable!"); if (data_block->errcode == 0) { // Don't over-rule a server side error @@ -569,7 +565,7 @@ int uda::client::Client::get_requests(RequestBlock& request_block, int* indices) return ERROR_CONDITION_UNKNOWN; } - return -abs(err); // Abnormal Exit + return -abs(err); // Abnormal Exit } return 0; @@ -584,8 +580,8 @@ int uda::client::Client::send_putdata(const RequestBlock& request_block) int protocol_id = UDA_PROTOCOL_PUTDATA_BLOCK_LIST; int err = 0; if ((err = protocol2(client_output_, protocol_id, XDR_SEND, nullptr, logmalloclist_, userdefinedtypelist_, - &(request->putDataBlockList), protocol_version_, &log_struct_list_, - private_flags_, malloc_source_)) != 0) { + &(request->putDataBlockList), protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (sending putDataBlockList from Request Block)"); throw uda::exceptions::ClientError("Protocol 1 Error (sending putDataBlockList from Request Block)"); @@ -627,11 +623,11 @@ std::vector uda::client::Client::get(std::vector signals; std::transform(requests.begin(), requests.end(), std::back_inserter(signals), - [](const std::pair& p){ return p.first.c_str(); }); + [](const std::pair& p) { return p.first.c_str(); }); std::vector sources; std::transform(requests.begin(), requests.end(), std::back_inserter(sources), - [](const std::pair& p){ return p.second.c_str(); }); + [](const std::pair& p) { return p.second.c_str(); }); if (make_request_block(&environment_, signals.data(), sources.data(), requests.size(), &request_block) != 0) { if (udaNumErrors() == 0) { @@ -670,27 +666,29 @@ int uda::client::Client::test_connection() char temp; do { - rc = xdr_char(client_input_, &temp); // Flush the input (limit to 64 bytes) + rc = xdr_char(client_input_, &temp); // Flush the input (limit to 64 bytes) if (rc) { UDA_LOG(UDA_LOG_DEBUG, "[%d] [%c]\n", count++, temp); } } while (rc && count < 64); - if (count > 0) { // Error if data is waiting - addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, - "Data waiting in the input data buffer when none expected! Please contact the system administrator."); + if (count > 0) { // Error if data is waiting + addIdamError( + UDA_CODE_ERROR_TYPE, __func__, 999, + "Data waiting in the input data buffer when none expected! Please contact the system administrator."); UDA_LOG(UDA_LOG_DEBUG, "[%d] excess data bytes waiting in input buffer!\n", count++); - throw uda::exceptions::ClientError("Data waiting in the input data buffer when none expected! Please contact the system administrator."); + throw uda::exceptions::ClientError( + "Data waiting in the input data buffer when none expected! Please contact the system administrator."); } - rc = xdrrec_eof(client_input_); // Test for an EOF + rc = xdrrec_eof(client_input_); // Test for an EOF if (!rc) { - rc = xdrrec_skiprecord(client_input_); // Flush the input buffer (Zero data waiting but not an EOF!) + rc = xdrrec_skiprecord(client_input_); // Flush the input buffer (Zero data waiting but not an EOF!) } - rc = xdrrec_eof(client_input_); // Test for an EOF + rc = xdrrec_eof(client_input_); // Test for an EOF if (!rc) { int err = 999; @@ -708,11 +706,10 @@ int uda::client::Client::test_connection() int uda::client::Client::send_request_block(RequestBlock& request_block) { - int protocol_id = UDA_PROTOCOL_REQUEST_BLOCK; // This is what the Client Wants + int protocol_id = UDA_PROTOCOL_REQUEST_BLOCK; // This is what the Client Wants int err = 0; if ((err = protocol2(client_output_, protocol_id, XDR_SEND, nullptr, logmalloclist_, userdefinedtypelist_, - &request_block, protocol_version_, &log_struct_list_, private_flags_, - malloc_source_)) != 0) { + &request_block, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (Request Block)"); throw uda::exceptions::ClientError("Protocol 1 Error (Request Block)"); } @@ -722,11 +719,10 @@ int uda::client::Client::send_request_block(RequestBlock& request_block) int uda::client::Client::send_client_block() { - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block int err = 0; if ((err = protocol2(client_output_, protocol_id, XDR_SEND, nullptr, logmalloclist_, userdefinedtypelist_, - &client_block_, protocol_version_, &log_struct_list_, private_flags_, - malloc_source_)) != 0) { + &client_block_, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); throw uda::exceptions::ClientError("Protocol 10 Error (Client Block)"); } @@ -738,12 +734,11 @@ int uda::client::Client::perform_handshake() { // Flush (mark as at EOF) the input socket buffer (before the exchange begins) - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block (proxy for authenticationStep = 6) + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Send Client Block (proxy for authenticationStep = 6) int err = 0; if ((err = protocol2(client_output_, protocol_id, XDR_SEND, nullptr, logmalloclist_, userdefinedtypelist_, - &client_block_, protocol_version_, &log_struct_list_, private_flags_, - malloc_source_)) != 0) { + &client_block_, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); UDA_LOG(UDA_LOG_DEBUG, "Error Sending Client Block\n"); throw uda::exceptions::ClientError("Protocol 10 Error (Client Block)"); @@ -766,11 +761,11 @@ int uda::client::Client::perform_handshake() throw uda::exceptions::ClientError("Protocol 5 Error (Server Block)"); } - protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement (proxy for authenticationStep = 8) + protocol_id = + UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement (proxy for authenticationStep = 8) if ((err = protocol2(client_input_, protocol_id, XDR_RECEIVE, nullptr, logmalloclist_, userdefinedtypelist_, - &server_block_, protocol_version_, &log_struct_list_, private_flags_, - malloc_source_)) != 0) { + &server_block_, protocol_version_, &log_struct_list_, private_flags_, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 11 Error (Server Block #1)"); // Assuming the server_block is corrupted, replace with a clean copy to avoid concatonation problems server_block_.idamerrorstack.nerrors = 0; @@ -792,7 +787,7 @@ int uda::client::Client::perform_handshake() protocol_version_ = std::min(client_block_.version, server_block_.version); if (server_block_.idamerrorstack.nerrors > 0) { - err = server_block_.idamerrorstack.idamerror[0].code; // Problem on the Server Side! + err = server_block_.idamerrorstack.idamerror[0].code; // Problem on the Server Side! throw uda::exceptions::ServerError(server_block_.idamerrorstack.idamerror[0].msg); } @@ -833,8 +828,8 @@ int uda::client::Client::receive_server_block() int err = 0; if ((err = protocol2(client_input_, UDA_PROTOCOL_SERVER_BLOCK, XDR_RECEIVE, nullptr, logmalloclist_, - userdefinedtypelist_, &server_block_, protocol_version_, &log_struct_list_, - private_flags_, malloc_source_)) != 0) { + userdefinedtypelist_, &server_block_, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Protocol 11 Error (Server Block #2) = %d\n", err); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, " Protocol 11 Error (Server Block #2)"); // Assuming the server_block is corrupted, replace with a clean copy to avoid future concatonation problems @@ -885,18 +880,42 @@ void uda::client::Client::set_property(const char* property) char* value; if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) client_flags_.get_datadble = 1; - if (STR_IEQUALS(property, "get_dimdble")) client_flags_.get_dimdble = 1; - if (STR_IEQUALS(property, "get_timedble")) client_flags_.get_timedble = 1; - if (STR_IEQUALS(property, "get_bytes")) client_flags_.get_bytes = 1; - if (STR_IEQUALS(property, "get_bad")) client_flags_.get_bad = 1; - if (STR_IEQUALS(property, "get_meta")) client_flags_.get_meta = 1; - if (STR_IEQUALS(property, "get_asis")) client_flags_.get_asis = 1; - if (STR_IEQUALS(property, "get_uncal")) client_flags_.get_uncal = 1; - if (STR_IEQUALS(property, "get_notoff")) client_flags_.get_notoff = 1; - if (STR_IEQUALS(property, "get_synthetic")) client_flags_.get_synthetic = 1; - if (STR_IEQUALS(property, "get_scalar")) client_flags_.get_scalar = 1; - if (STR_IEQUALS(property, "get_nodimdata")) client_flags_.get_nodimdata = 1; + if (STR_IEQUALS(property, "get_datadble")) { + client_flags_.get_datadble = 1; + } + if (STR_IEQUALS(property, "get_dimdble")) { + client_flags_.get_dimdble = 1; + } + if (STR_IEQUALS(property, "get_timedble")) { + client_flags_.get_timedble = 1; + } + if (STR_IEQUALS(property, "get_bytes")) { + client_flags_.get_bytes = 1; + } + if (STR_IEQUALS(property, "get_bad")) { + client_flags_.get_bad = 1; + } + if (STR_IEQUALS(property, "get_meta")) { + client_flags_.get_meta = 1; + } + if (STR_IEQUALS(property, "get_asis")) { + client_flags_.get_asis = 1; + } + if (STR_IEQUALS(property, "get_uncal")) { + client_flags_.get_uncal = 1; + } + if (STR_IEQUALS(property, "get_notoff")) { + client_flags_.get_notoff = 1; + } + if (STR_IEQUALS(property, "get_synthetic")) { + client_flags_.get_synthetic = 1; + } + if (STR_IEQUALS(property, "get_scalar")) { + client_flags_.get_scalar = 1; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + client_flags_.get_nodimdata = 1; + } } else { if (property[0] == 't') { strncpy(name, property, 55); @@ -907,12 +926,20 @@ void uda::client::Client::set_property(const char* property) strlwr(name); if ((value = strstr(name, "timeout=")) != nullptr) { value = name + 8; - if (IsNumber(value)) client_flags_.user_timeout = atoi(value); + if (IsNumber(value)) { + client_flags_.user_timeout = atoi(value); + } } } else { - if (STR_IEQUALS(property, "verbose")) udaSetLogLevel(UDA_LOG_INFO); - if (STR_IEQUALS(property, "debug")) udaSetLogLevel(UDA_LOG_DEBUG); - if (STR_IEQUALS(property, "altData")) client_flags_.flags = client_flags_.flags | CLIENTFLAG_ALTDATA; + if (STR_IEQUALS(property, "verbose")) { + udaSetLogLevel(UDA_LOG_INFO); + } + if (STR_IEQUALS(property, "debug")) { + udaSetLogLevel(UDA_LOG_DEBUG); + } + if (STR_IEQUALS(property, "altData")) { + client_flags_.flags = client_flags_.flags | CLIENTFLAG_ALTDATA; + } if (!strncasecmp(property, "altRank", 7)) { strncpy(name, property, 55); name[55] = '\0'; @@ -922,13 +949,21 @@ void uda::client::Client::set_property(const char* property) strlwr(name); if ((value = strcasestr(name, "altRank=")) != nullptr) { value = name + 8; - if (IsNumber(value)) client_flags_.alt_rank = atoi(value); + if (IsNumber(value)) { + client_flags_.alt_rank = atoi(value); + } } } } - if (STR_IEQUALS(property, "reuseLastHandle")) client_flags_.flags = client_flags_.flags | CLIENTFLAG_REUSELASTHANDLE; - if (STR_IEQUALS(property, "freeAndReuseLastHandle")) client_flags_.flags = client_flags_.flags | CLIENTFLAG_FREEREUSELASTHANDLE; - if (STR_IEQUALS(property, "fileCache")) client_flags_.flags = client_flags_.flags | CLIENTFLAG_FILECACHE; + if (STR_IEQUALS(property, "reuseLastHandle")) { + client_flags_.flags = client_flags_.flags | CLIENTFLAG_REUSELASTHANDLE; + } + if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { + client_flags_.flags = client_flags_.flags | CLIENTFLAG_FREEREUSELASTHANDLE; + } + if (STR_IEQUALS(property, "fileCache")) { + client_flags_.flags = client_flags_.flags | CLIENTFLAG_FILECACHE; + } } } @@ -937,27 +972,67 @@ int uda::client::Client::get_property(const char* property) // User settings for Client and Server behaviour if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) return client_flags_.get_datadble; - if (STR_IEQUALS(property, "get_dimdble")) return client_flags_.get_dimdble; - if (STR_IEQUALS(property, "get_timedble")) return client_flags_.get_timedble; - if (STR_IEQUALS(property, "get_bytes")) return client_flags_.get_bytes; - if (STR_IEQUALS(property, "get_bad")) return client_flags_.get_bad; - if (STR_IEQUALS(property, "get_meta")) return client_flags_.get_meta; - if (STR_IEQUALS(property, "get_asis")) return client_flags_.get_asis; - if (STR_IEQUALS(property, "get_uncal")) return client_flags_.get_uncal; - if (STR_IEQUALS(property, "get_notoff")) return client_flags_.get_notoff; - if (STR_IEQUALS(property, "get_synthetic")) return client_flags_.get_synthetic; - if (STR_IEQUALS(property, "get_scalar")) return client_flags_.get_scalar; - if (STR_IEQUALS(property, "get_nodimdata")) return client_flags_.get_nodimdata; + if (STR_IEQUALS(property, "get_datadble")) { + return client_flags_.get_datadble; + } + if (STR_IEQUALS(property, "get_dimdble")) { + return client_flags_.get_dimdble; + } + if (STR_IEQUALS(property, "get_timedble")) { + return client_flags_.get_timedble; + } + if (STR_IEQUALS(property, "get_bytes")) { + return client_flags_.get_bytes; + } + if (STR_IEQUALS(property, "get_bad")) { + return client_flags_.get_bad; + } + if (STR_IEQUALS(property, "get_meta")) { + return client_flags_.get_meta; + } + if (STR_IEQUALS(property, "get_asis")) { + return client_flags_.get_asis; + } + if (STR_IEQUALS(property, "get_uncal")) { + return client_flags_.get_uncal; + } + if (STR_IEQUALS(property, "get_notoff")) { + return client_flags_.get_notoff; + } + if (STR_IEQUALS(property, "get_synthetic")) { + return client_flags_.get_synthetic; + } + if (STR_IEQUALS(property, "get_scalar")) { + return client_flags_.get_scalar; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + return client_flags_.get_nodimdata; + } } else { - if (STR_IEQUALS(property, "timeout")) return client_flags_.user_timeout; - if (STR_IEQUALS(property, "altRank")) return alt_rank_; - if (STR_IEQUALS(property, "reuseLastHandle")) return (int)(client_flags_.flags & CLIENTFLAG_REUSELASTHANDLE); - if (STR_IEQUALS(property, "freeAndReuseLastHandle")) return (int)(client_flags_.flags & CLIENTFLAG_FREEREUSELASTHANDLE); - if (STR_IEQUALS(property, "verbose")) return udaGetLogLevel() == UDA_LOG_INFO; - if (STR_IEQUALS(property, "debug")) return udaGetLogLevel() == UDA_LOG_DEBUG; - if (STR_IEQUALS(property, "altData")) return (int)(client_flags_.flags & CLIENTFLAG_ALTDATA); - if (STR_IEQUALS(property, "fileCache")) return (int)(client_flags_.flags & CLIENTFLAG_FILECACHE); + if (STR_IEQUALS(property, "timeout")) { + return client_flags_.user_timeout; + } + if (STR_IEQUALS(property, "altRank")) { + return alt_rank_; + } + if (STR_IEQUALS(property, "reuseLastHandle")) { + return (int)(client_flags_.flags & CLIENTFLAG_REUSELASTHANDLE); + } + if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { + return (int)(client_flags_.flags & CLIENTFLAG_FREEREUSELASTHANDLE); + } + if (STR_IEQUALS(property, "verbose")) { + return udaGetLogLevel() == UDA_LOG_INFO; + } + if (STR_IEQUALS(property, "debug")) { + return udaGetLogLevel() == UDA_LOG_DEBUG; + } + if (STR_IEQUALS(property, "altData")) { + return (int)(client_flags_.flags & CLIENTFLAG_ALTDATA); + } + if (STR_IEQUALS(property, "fileCache")) { + return (int)(client_flags_.flags & CLIENTFLAG_FILECACHE); + } } return 0; } @@ -967,28 +1042,64 @@ void uda::client::Client::reset_property(const char* property) // User settings for Client and Server behaviour if (property[0] == 'g') { - if (STR_IEQUALS(property, "get_datadble")) client_flags_.get_datadble = 0; - if (STR_IEQUALS(property, "get_dimdble")) client_flags_.get_dimdble = 0; - if (STR_IEQUALS(property, "get_timedble")) client_flags_.get_timedble = 0; - if (STR_IEQUALS(property, "get_bytes")) client_flags_.get_bytes = 0; - if (STR_IEQUALS(property, "get_bad")) client_flags_.get_bad = 0; - if (STR_IEQUALS(property, "get_meta")) client_flags_.get_meta = 0; - if (STR_IEQUALS(property, "get_asis")) client_flags_.get_asis = 0; - if (STR_IEQUALS(property, "get_uncal")) client_flags_.get_uncal = 0; - if (STR_IEQUALS(property, "get_notoff")) client_flags_.get_notoff = 0; - if (STR_IEQUALS(property, "get_synthetic")) client_flags_.get_synthetic = 0; - if (STR_IEQUALS(property, "get_scalar")) client_flags_.get_scalar = 0; - if (STR_IEQUALS(property, "get_nodimdata")) client_flags_.get_nodimdata = 0; + if (STR_IEQUALS(property, "get_datadble")) { + client_flags_.get_datadble = 0; + } + if (STR_IEQUALS(property, "get_dimdble")) { + client_flags_.get_dimdble = 0; + } + if (STR_IEQUALS(property, "get_timedble")) { + client_flags_.get_timedble = 0; + } + if (STR_IEQUALS(property, "get_bytes")) { + client_flags_.get_bytes = 0; + } + if (STR_IEQUALS(property, "get_bad")) { + client_flags_.get_bad = 0; + } + if (STR_IEQUALS(property, "get_meta")) { + client_flags_.get_meta = 0; + } + if (STR_IEQUALS(property, "get_asis")) { + client_flags_.get_asis = 0; + } + if (STR_IEQUALS(property, "get_uncal")) { + client_flags_.get_uncal = 0; + } + if (STR_IEQUALS(property, "get_notoff")) { + client_flags_.get_notoff = 0; + } + if (STR_IEQUALS(property, "get_synthetic")) { + client_flags_.get_synthetic = 0; + } + if (STR_IEQUALS(property, "get_scalar")) { + client_flags_.get_scalar = 0; + } + if (STR_IEQUALS(property, "get_nodimdata")) { + client_flags_.get_nodimdata = 0; + } } else { - if (STR_IEQUALS(property, "verbose")) udaSetLogLevel(UDA_LOG_NONE); - if (STR_IEQUALS(property, "debug")) udaSetLogLevel(UDA_LOG_NONE); - if (STR_IEQUALS(property, "altData")) client_flags_.flags &= !CLIENTFLAG_ALTDATA; - if (STR_IEQUALS(property, "altRank")) client_flags_.alt_rank = 0; - if (STR_IEQUALS(property, "reuseLastHandle")) client_flags_.flags &= !CLIENTFLAG_REUSELASTHANDLE; + if (STR_IEQUALS(property, "verbose")) { + udaSetLogLevel(UDA_LOG_NONE); + } + if (STR_IEQUALS(property, "debug")) { + udaSetLogLevel(UDA_LOG_NONE); + } + if (STR_IEQUALS(property, "altData")) { + client_flags_.flags &= !CLIENTFLAG_ALTDATA; + } + if (STR_IEQUALS(property, "altRank")) { + client_flags_.alt_rank = 0; + } + if (STR_IEQUALS(property, "reuseLastHandle")) { + client_flags_.flags &= !CLIENTFLAG_REUSELASTHANDLE; + } if (STR_IEQUALS(property, "freeAndReuseLastHandle")) { client_flags_.flags &= !CLIENTFLAG_FREEREUSELASTHANDLE; } - if (STR_IEQUALS(property, "fileCache")) client_flags_.flags &= !CLIENTFLAG_FILECACHE; + if (STR_IEQUALS(property, "fileCache")) { + client_flags_.flags &= !CLIENTFLAG_FILECACHE; + } } } diff --git a/source/client2/client_environment.cpp b/source/client2/client_environment.cpp index 2735b746..538f2c94 100644 --- a/source/client2/client_environment.cpp +++ b/source/client2/client_environment.cpp @@ -1,7 +1,7 @@ -#include -#include #include "client_environment.hpp" +#include #include +#include Environment uda::client::load_environment(bool* env_host, bool* env_port) { @@ -37,25 +37,31 @@ Environment uda::client::load_environment(bool* env_host, bool* env_port) // Log Output Write Mode - strcpy(environment.logmode, "w"); // Write & Replace Mode + strcpy(environment.logmode, "w"); // Write & Replace Mode if ((env = getenv("UDA_LOG_MODE")) != nullptr) { if (env[0] == 'a' && strlen(env) == 1) { environment.logmode[0] = 'a'; } - } // Append Mode + } // Append Mode environment.loglevel = UDA_LOG_NONE; if ((env = getenv("UDA_LOG_LEVEL")) != nullptr) { - if (strncmp(env, "ACCESS", 6) == 0) environment.loglevel = UDA_LOG_ACCESS; - else if (strncmp(env, "ERROR", 5) == 0) environment.loglevel = UDA_LOG_ERROR; - else if (strncmp(env, "WARN", 4) == 0) environment.loglevel = UDA_LOG_WARN; - else if (strncmp(env, "DEBUG", 5) == 0) environment.loglevel = UDA_LOG_DEBUG; - else if (strncmp(env, "INFO", 4) == 0) environment.loglevel = UDA_LOG_INFO; + if (strncmp(env, "ACCESS", 6) == 0) { + environment.loglevel = UDA_LOG_ACCESS; + } else if (strncmp(env, "ERROR", 5) == 0) { + environment.loglevel = UDA_LOG_ERROR; + } else if (strncmp(env, "WARN", 4) == 0) { + environment.loglevel = UDA_LOG_WARN; + } else if (strncmp(env, "DEBUG", 5) == 0) { + environment.loglevel = UDA_LOG_DEBUG; + } else if (strncmp(env, "INFO", 4) == 0) { + environment.loglevel = UDA_LOG_INFO; + } } // UDA Server Host Name - if (*env_host) { // Check Not already set by User + if (*env_host) { // Check Not already set by User if ((env = getenv("UDA_HOST")) != nullptr) { strcpy(environment.server_host, env); } else { @@ -90,8 +96,8 @@ Environment uda::client::load_environment(bool* env_host, bool* env_port) // UDA Reconnect Status - environment.server_reconnect = 0; // No reconnection needed at startup! - environment.server_socket = -1; // No Socket open at startup + environment.server_reconnect = 0; // No reconnection needed at startup! + environment.server_socket = -1; // No Socket open at startup //------------------------------------------------------------------------------------------- // API Defaults @@ -135,29 +141,35 @@ Environment uda::client::load_environment(bool* env_host, bool* env_port) // External User? #ifdef FATCLIENT - # ifdef EXTERNAL_USER +# ifdef EXTERNAL_USER environment.external_user = 1; # else environment.external_user = 0; # endif - if ((env = getenv("EXTERNAL_USER")) != nullptr) environment.external_user = 1; - if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) environment.external_user = 1; + if ((env = getenv("EXTERNAL_USER")) != nullptr) { + environment.external_user = 1; + } + if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { + environment.external_user = 1; + } #endif //------------------------------------------------------------------------------------------- // UDA Proxy Host: redirect ALL requests #ifdef FATCLIENT - # ifdef PROXYSERVER - if((env = getenv("UDA_PROXY_TARGETHOST")) != nullptr) - strcpy(environment.server_proxy, env); - else - environment.server_proxy[0] = '\0'; - - if((env = getenv("UDA_PROXY_THISHOST")) != nullptr) - strcpy(environment.server_this, env); - else - environment.server_this[0] = '\0'; +# ifdef PROXYSERVER + if ((env = getenv("UDA_PROXY_TARGETHOST")) != nullptr) { + strcpy(environment.server_proxy, env); + } else { + environment.server_proxy[0] = '\0'; + } + + if ((env = getenv("UDA_PROXY_THISHOST")) != nullptr) { + strcpy(environment.server_this, env); + } else { + environment.server_this[0] = '\0'; + } # endif #endif @@ -180,14 +192,18 @@ Environment uda::client::load_environment(bool* env_host, bool* env_port) // Client defined Property Flags environment.clientFlags = 0; - if ((env = getenv("UDA_FLAGS")) != nullptr) environment.clientFlags = atoi(env); + if ((env = getenv("UDA_FLAGS")) != nullptr) { + environment.clientFlags = atoi(env); + } environment.altRank = 0; - if ((env = getenv("UDA_ALTRANK")) != nullptr) environment.altRank = atoi(env); + if ((env = getenv("UDA_ALTRANK")) != nullptr) { + environment.altRank = atoi(env); + } //------------------------------------------------------------------------------------------- - environment.initialised = 1; // Initialisation Complete + environment.initialised = 1; // Initialisation Complete return environment; } diff --git a/source/client2/client_xdr_stream.cpp b/source/client2/client_xdr_stream.cpp old mode 100755 new mode 100644 index aa4af796..674957f3 --- a/source/client2/client_xdr_stream.cpp +++ b/source/client2/client_xdr_stream.cpp @@ -3,8 +3,8 @@ #include #include -#include #include "udaDefines.h" +#include #include "connection.hpp" @@ -24,61 +24,61 @@ std::pair uda::client::createXDRStream(IoData* io_data) #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) if (getUdaClientSSLDisabled()) { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); -#else - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); +# else + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); +# endif } else { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); -#else - xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); - - xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(readUdaClientSSL), - reinterpret_cast(writeUdaClientSSL)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); +# else + xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); + + xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(readUdaClientSSL), + reinterpret_cast(writeUdaClientSSL)); +# endif } #else -#if defined (__APPLE__) || defined(__TIRPC__) +# if defined(__APPLE__) || defined(__TIRPC__) xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); -#else + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); +# else xdrrec_create(&client_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); xdrrec_create(&client_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(uda::client::readin), - reinterpret_cast(uda::client::writeout)); -#endif + reinterpret_cast(uda::client::readin), + reinterpret_cast(uda::client::writeout)); +# endif #endif // SSLAUTHENTICATION diff --git a/source/client2/closedown.cpp b/source/client2/closedown.cpp old mode 100755 new mode 100644 index 48b60990..13ef17f0 --- a/source/client2/closedown.cpp +++ b/source/client2/closedown.cpp @@ -8,8 +8,8 @@ # include #endif -int uda::client::closedown(ClosedownType type, Connection* connection, XDR* client_input, XDR* client_output, bool* reopen_logs, - bool* env_host, bool* env_port) +int uda::client::closedown(ClosedownType type, Connection* connection, XDR* client_input, XDR* client_output, + bool* reopen_logs, bool* env_host, bool* env_port) { int rc = 0; @@ -22,7 +22,7 @@ int uda::client::closedown(ClosedownType type, Connection* connection, XDR* clie if (type == ClosedownType::CLOSE_ALL) { udaCloseLogging(); - *reopen_logs = true; // In case the User calls the IDAM API again! + *reopen_logs = true; // In case the User calls the IDAM API again! } if (client_input != nullptr) { @@ -39,12 +39,11 @@ int uda::client::closedown(ClosedownType type, Connection* connection, XDR* clie client_output->x_ops = nullptr; } - if (connection != nullptr) { connection->close_down(type); } - *env_host = true; // Initialise at Startup + *env_host = true; // Initialise at Startup *env_port = true; // Close the SSL binding and context diff --git a/source/client2/connection.cpp b/source/client2/connection.cpp old mode 100755 new mode 100644 index fe649886..da44982c --- a/source/client2/connection.cpp +++ b/source/client2/connection.cpp @@ -8,28 +8,28 @@ #include "connection.hpp" -#include +#include #include #include -#include +#include #include -#include +#include #if defined(__GNUC__) && !defined(__MINGW32__) # ifndef _WIN32 -# include -# include # include # include +# include # include +# include # endif -# include # include +# include #else # include # include # define strcasecmp _stricmp -# define sleep(DELAY) Sleep((DWORD)((DELAY)*1E3)) +# define sleep(DELAY) Sleep((DWORD)((DELAY) * 1E3)) # define close(SOCK) closesocket(SOCK) # ifndef __MINGW32__ # pragma comment(lib, "Ws2_32.lib") @@ -44,8 +44,8 @@ #include #include -#include "host_list.hpp" #include "error_codes.h" +#include "host_list.hpp" #if defined(SSLAUTHENTICATION) # include @@ -57,7 +57,7 @@ # define ALLOW_UNUSED_TYPE #endif -#define PORT_STRING 64 +#define PORT_STRING 64 int uda::client::Connection::open() { @@ -77,7 +77,7 @@ int uda::client::Connection::find_socket(int fh) } int uda::client::Connection::reconnect(XDR** client_input, XDR** client_output, time_t* tv_server_start, - int* user_timeout) + int* user_timeout) { int err = 0; @@ -96,9 +96,9 @@ int uda::client::Connection::reconnect(XDR** client_input, XDR** client_output, // Instance a new server if the Client has changed the host and/or port number if (environment.server_reconnect) { - time(tv_server_start); // Start a New Server AGE timer - client_socket = -1; // Flags no Socket is open - environment.server_change_socket = 0; // Client doesn't know the Socket ID so disable + time(tv_server_start); // Start a New Server AGE timer + client_socket = -1; // Flags no Socket is open + environment.server_change_socket = 0; // Client doesn't know the Socket ID so disable } // Client manages connections through the Socket id and specifies which running server to connect to @@ -140,9 +140,9 @@ int uda::client::Connection::reconnect(XDR** client_input, XDR** client_output, void localhostInfo(int* ai_family) { char addr_buf[64]; - struct addrinfo* info = nullptr, * result = nullptr; + struct addrinfo *info = nullptr, *result = nullptr; getaddrinfo("localhost", nullptr, nullptr, &info); - result = info; // Take the first linked list member + result = info; // Take the first linked list member if (result->ai_family == AF_INET) { *ai_family = AF_INET; inet_ntop(AF_INET, &((struct sockaddr_in*)result->ai_addr)->sin_addr, addr_buf, sizeof(addr_buf)); @@ -152,14 +152,16 @@ void localhostInfo(int* ai_family) inet_ntop(AF_INET6, &((struct sockaddr_in6*)result->ai_addr)->sin6_addr, addr_buf, sizeof(addr_buf)); UDA_LOG(UDA_LOG_DEBUG, "localhost Information: IPv6 - %s\n", addr_buf); } - if (info) freeaddrinfo(info); + if (info) { + freeaddrinfo(info); + } } void setHints(struct addrinfo* hints, const char* hostname) { hints->ai_family = AF_UNSPEC; hints->ai_socktype = SOCK_STREAM; - hints->ai_flags = 0; //AI_CANONNAME | AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG ; + hints->ai_flags = 0; // AI_CANONNAME | AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG ; hints->ai_protocol = 0; hints->ai_canonname = nullptr; hints->ai_addr = nullptr; @@ -167,11 +169,13 @@ void setHints(struct addrinfo* hints, const char* hostname) // Localhost? Which IP family? (AF_UNSPEC gives an 'Unknown Error'!) - if (!strcmp(hostname, "localhost")) localhostInfo(&hints->ai_family); + if (!strcmp(hostname, "localhost")) { + localhostInfo(&hints->ai_family); + } // Is the address Numeric? Is it IPv6? - if (strchr(hostname, ':')) { // Appended port number should have been stripped off + if (strchr(hostname, ':')) { // Appended port number should have been stripped off hints->ai_family = AF_INET6; hints->ai_flags = hints->ai_flags | AI_NUMERICHOST; } else { @@ -196,7 +200,7 @@ void setHints(struct addrinfo* hints, const char* hostname) int uda::client::Connection::create(XDR* client_input, XDR* client_output, const HostList& host_list) { - int window_size = DB_READ_BLOCK_SIZE; // 128K + int window_size = DB_READ_BLOCK_SIZE; // 128K int rc; static int max_socket_delay = -1; @@ -229,12 +233,12 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const putUdaClientSSLSocket(client_socket); #endif -#ifdef _WIN32 // Initialise WINSOCK Once only - static unsigned int initWinsock = 0; +#ifdef _WIN32 // Initialise WINSOCK Once only + static unsigned int initWinsock = 0; WORD sockVersion; WSADATA wsaData; if (!initWinsock) { - sockVersion = MAKEWORD(2, 2); // Select Winsock version 2.2 + sockVersion = MAKEWORD(2, 2); // Select Winsock version 2.2 WSAStartup(sockVersion, &wsaData); initWinsock = 1; } @@ -245,12 +249,13 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const const char* hostname = environment.server_host; char serviceport[PORT_STRING]; - // Check if the host_name is an alias for an IP address or domain name in the client configuration - replace if found + // Check if the host_name is an alias for an IP address or domain name in the client configuration - replace if + // found auto host = host_list.find_by_alias(hostname); if (host != nullptr) { if (host->host_name != environment.server_host) { - strcpy(environment.server_host, host->host_name.c_str()); // Replace + strcpy(environment.server_host, host->host_name.c_str()); // Replace } int port = host->port; if (port > 0 && environment.server_port != port) { @@ -271,12 +276,12 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) if (!strncasecmp(hostname, "SSL://", 6)) { // Should be stripped already if via the HOST client configuration file - strcpy(environment.server_host, &hostname[6]); // Replace + strcpy(environment.server_host, &hostname[6]); // Replace putUdaClientSSLProtocol(1); } else { if (host != nullptr && host->isSSL) { putUdaClientSSLProtocol(1); - } else { + } else { putUdaClientSSLProtocol(0); } } @@ -285,14 +290,18 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const // Resolve the Host and the IP protocol to be used (Hints not used) struct addrinfo* result = nullptr; - struct addrinfo hints = { 0 }; + struct addrinfo hints = {0}; setHints(&hints, hostname); errno = 0; if ((rc = getaddrinfo(hostname, serviceport, &hints, &result)) != 0 || (errno != 0 && errno != ESRCH)) { addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, rc, (char*)gai_strerror(rc)); - if (rc == EAI_SYSTEM || errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); - if (result) freeaddrinfo(result); + if (rc == EAI_SYSTEM || errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); + } + if (result) { + freeaddrinfo(result); + } return -1; } @@ -334,17 +343,19 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const int ps; ps = getpid(); - srand((unsigned int)ps); // Seed the random number generator with the process id + srand((unsigned int)ps); // Seed the random number generator with the process id unsigned int delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; // random delay sleep(delay); - errno = 0; // wait period - for (int i = 0; i < max_socket_attempts; i++) { // try again + errno = 0; // wait period + for (int i = 0; i < max_socket_attempts; i++) { // try again while ((rc = connect(client_socket, result->ai_addr, result->ai_addrlen)) && errno == EINTR) {} - if (rc == 0 && errno == 0) break; + if (rc == 0 && errno == 0) { + break; + } delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; - sleep(delay); // wait period + sleep(delay); // wait period } if (rc != 0 || errno != 0) { @@ -367,7 +378,8 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const client_socket = -1; hostname = environment.server_host2; - // Check if the host_name is an alias for an IP address or name in the client configuration - replace if found + // Check if the host_name is an alias for an IP address or name in the client configuration - replace if + // found host = host_list.find_by_alias(hostname); if (host != nullptr) { @@ -378,7 +390,7 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const if (port > 0 && environment.server_port2 != port) { environment.server_port2 = port; } - } else if ((host = host_list.find_by_name(hostname)) != nullptr) { // No alias found + } else if ((host = host_list.find_by_name(hostname)) != nullptr) { // No alias found int port = host->port; if (port > 0 && environment.server_port2 != port) { environment.server_port2 = port; @@ -389,14 +401,14 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const // Does the host name contain the SSL protocol prefix? If so strip this off #if defined(SSLAUTHENTICATION) && !defined(FATCLIENT) - if (!strncasecmp(hostname, "SSL://", 6)){ + if (!strncasecmp(hostname, "SSL://", 6)) { // Should be stripped already if via the HOST client configuration file - strcpy(environment.server_host2, &hostname[6]); // Replace + strcpy(environment.server_host2, &hostname[6]); // Replace putUdaClientSSLProtocol(1); } else { if (host != nullptr && host->isSSL) { putUdaClientSSLProtocol(1); - } else { + } else { putUdaClientSSLProtocol(0); } } @@ -409,8 +421,12 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const errno = 0; if ((rc = getaddrinfo(hostname, serviceport, &hints, &result)) != 0 || errno != 0) { addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, rc, (char*)gai_strerror(rc)); - if (rc == EAI_SYSTEM || errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); - if (result) freeaddrinfo(result); + if (rc == EAI_SYSTEM || errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, ""); + } + if (result) { + freeaddrinfo(result); + } return -1; } errno = 0; @@ -437,7 +453,7 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const for (int i = 0; i < max_socket_attempts; i++) { while ((rc = connect(client_socket, result->ai_addr, result->ai_addrlen)) && errno == EINTR) {} if (rc == 0) { - int port = environment.server_port2; // Swap data so that accessor function reports correctly + int port = environment.server_port2; // Swap data so that accessor function reports correctly environment.server_port2 = environment.server_port; environment.server_port = port; std::string name = environment.server_host2; @@ -446,7 +462,7 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const break; } delay = max_socket_delay > 0 ? (unsigned int)(rand() % max_socket_delay) : 0; - sleep(delay); // wait period + sleep(delay); // wait period } } @@ -462,15 +478,19 @@ int uda::client::Connection::create(XDR* client_input, XDR* client_output, const ::close(client_socket); } #else - closesocket(client_socket); + closesocket(client_socket); #endif client_socket = -1; - if (result) freeaddrinfo(result); + if (result) { + freeaddrinfo(result); + } return -1; } } - if (result) freeaddrinfo(result); + if (result) { + freeaddrinfo(result); + } // Set the receive and send buffer sizes @@ -530,7 +550,7 @@ void uda::client::Connection::close_socket(int fh) if (socket.fh == fh && socket.fh >= 0) { if (socket.type == TYPE_UDA_SERVER) { #ifndef _WIN32 - ::close(fh); // Only Genuine Sockets! + ::close(fh); // Only Genuine Sockets! #else ::closesocket(fh); #endif @@ -555,17 +575,18 @@ void uda::client::Connection::close_down(ClosedownType type) client_socket = -1; } -void update_select_params(int fd, fd_set *rfds, struct timeval *tv) { +void update_select_params(int fd, fd_set* rfds, struct timeval* tv) +{ FD_ZERO(rfds); FD_SET(fd, rfds); tv->tv_sec = 0; - tv->tv_usec = 500; // in microsecs => 0.5 ms wait + tv->tv_usec = 500; // in microsecs => 0.5 ms wait } int uda::client::writeout(void* iohandle, char* buf, int count) { #ifndef _WIN32 - void (* OldSIGPIPEHandler)(int); + void (*OldSIGPIPEHandler)(int); #endif int rc = 0; size_t BytesSent = 0; @@ -624,13 +645,13 @@ int uda::client::writeout(void* iohandle, char* buf, int count) #ifndef _WIN32 while (((rc = (int)write(*io_data->client_socket, buf, count)) == -1) && (errno == EINTR)) {} #else - while (((rc = send(*io_data->client_socket, buf , count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} + while (((rc = send(*io_data->client_socket, buf, count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} #endif BytesSent += rc; buf += rc; } -// Restore the original SIGPIPE handler set by the application + // Restore the original SIGPIPE handler set by the application #ifndef _WIN32 if (signal(SIGPIPE, OldSIGPIPEHandler) == SIG_ERR) { @@ -659,7 +680,7 @@ int uda::client::readin(void* iohandle, char* buf, int count) update_select_params(*io_data->client_socket, &rfds, &tv); while ((select(*io_data->client_socket + 1, &rfds, nullptr, nullptr, &tv) <= 0) && maxloop++ < MAXLOOP) { - update_select_params(*io_data->client_socket, &rfds, &tv); // Keep trying ... + update_select_params(*io_data->client_socket, &rfds, &tv); // Keep trying ... } // Read from it, checking for EINTR, as happens if called from IDL @@ -667,7 +688,7 @@ int uda::client::readin(void* iohandle, char* buf, int count) #ifndef _WIN32 while (((rc = (int)read(*io_data->client_socket, buf, count)) == -1) && (errno == EINTR)) {} #else - while (((rc=recv(*io_data->client_socket, buf, count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} + while (((rc = recv(*io_data->client_socket, buf, count, 0)) == SOCKET_ERROR) && (errno == EINTR)) {} #endif // As we have waited to be told that there is data to be read, if nothing diff --git a/source/client2/error_codes.h b/source/client2/error_codes.h index 9e2a05f0..e94187f1 100644 --- a/source/client2/error_codes.h +++ b/source/client2/error_codes.h @@ -1,13 +1,13 @@ #ifndef UDA_SOURCE_CLIENT2_ERROR_CODES_H #define UDA_SOURCE_CLIENT2_ERROR_CODES_H -#define NO_SOCKET_CONNECTION (-10000) -#define PROBLEM_OPENING_LOGS (-11000) -#define FILE_FORMAT_NOT_SUPPORTED (-12000) +#define NO_SOCKET_CONNECTION (-10000) +#define PROBLEM_OPENING_LOGS (-11000) +#define FILE_FORMAT_NOT_SUPPORTED (-12000) #define ERROR_ALLOCATING_DATA_BOCK_HEAP (-13000) -#define SERVER_BLOCK_ERROR (-14000) -#define SERVER_SIDE_ERROR (-14001) -#define DATA_BLOCK_RECEIPT_ERROR (-15000) -#define ERROR_CONDITION_UNKNOWN (-16000) +#define SERVER_BLOCK_ERROR (-14000) +#define SERVER_SIDE_ERROR (-14001) +#define DATA_BLOCK_RECEIPT_ERROR (-15000) +#define ERROR_CONDITION_UNKNOWN (-16000) -#endif //UDA_SOURCE_CLIENT2_ERROR_CODES_H +#endif // UDA_SOURCE_CLIENT2_ERROR_CODES_H diff --git a/source/client2/generate_errors.cpp b/source/client2/generate_errors.cpp old mode 100755 new mode 100644 index bd99ff09..dbf59b8b --- a/source/client2/generate_errors.cpp +++ b/source/client2/generate_errors.cpp @@ -4,8 +4,8 @@ #include #include "udaTypes.h" -#include #include +#include #include "accAPI.h" #include "thread_client.hpp" @@ -17,15 +17,17 @@ //-------------------------------------------------------------------------------------------------------------- // Generate Error Data -int uda::client::error_model(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, float* errhi, - float* errlo) +int uda::client::error_model(int model, int param_n, float* params, int data_n, float* data, int* asymmetry, + float* errhi, float* errlo) { - *asymmetry = 0; // No Error Asymmetry for most models + *asymmetry = 0; // No Error Asymmetry for most models switch (model) { case ERROR_MODEL_DEFAULT: - if (param_n != 2) return 1; + if (param_n != 2) { + return 1; + } for (int i = 0; i < data_n; i++) { errhi[i] = params[0] + params[1] * fabsf(data[i]); errlo[i] = errhi[i]; @@ -33,7 +35,9 @@ int uda::client::error_model(int model, int param_n, float* params, int data_n, break; case ERROR_MODEL_DEFAULT_ASYMMETRIC: - if (param_n != 4) return 1; + if (param_n != 4) { + return 1; + } *asymmetry = 1; for (int i = 0; i < data_n; i++) { errhi[i] = params[0] + params[1] * fabsf(data[i]); @@ -68,38 +72,59 @@ int uda::client::synthetic_model(int model, int param_n, float* params, int data return 999; #else float shift; - static gsl_rng *random=nullptr; + static gsl_rng* random = nullptr; - if(random == nullptr) { // Initialise the Random Number System + if (random == nullptr) { // Initialise the Random Number System gsl_rng_env_setup(); - random = gsl_rng_alloc (gsl_rng_default); - gsl_rng_set(random, (unsigned long int) ERROR_MODEL_SEED); // Seed the Random Number generator with the library default + random = gsl_rng_alloc(gsl_rng_default); + gsl_rng_set(random, + (unsigned long int)ERROR_MODEL_SEED); // Seed the Random Number generator with the library default } switch (model) { - case ERROR_MODEL_GAUSSIAN: // Standard normal Distribution - if(param_n < 1 || param_n > 2) return 1; - if(param_n == 2) gsl_rng_set(random, (unsigned long int) params[1]); // Change the Seed before Sampling - for(i=0; i 2) return 1; - if(param_n == 2) gsl_rng_set(random, (unsigned long int) params[1]); // Change the Seed before Sampling - shift = (float) gsl_ran_gaussian (random, (double) params[0]); - for(i=0; i 1) return 1; - if(param_n == 1) gsl_rng_set(random, (unsigned long int) params[0]); // Change the Seed before Sampling - for(i=0; i 2) { + return 1; + } + if (param_n == 2) { + gsl_rng_set(random, (unsigned long int)params[1]); // Change the Seed before Sampling + } + for (i = 0; i < data_n; i++) { + data[i] = data[i] + (float)gsl_ran_gaussian(random, (double)params[0]); // Random sample from PDF + } + break; + + case ERROR_MODEL_RESEED: // Change the Seed + if (param_n == 1) { + gsl_rng_set(random, (unsigned long int)params[0]); + } + break; + + case ERROR_MODEL_GAUSSIAN_SHIFT: + if (param_n < 1 || param_n > 2) { + return 1; + } + if (param_n == 2) { + gsl_rng_set(random, (unsigned long int)params[1]); // Change the Seed before Sampling + } + shift = (float)gsl_ran_gaussian(random, (double)params[0]); + for (i = 0; i < data_n; i++) { + data[i] = data[i] + shift; // Random linear shift of data array + } + break; + + case ERROR_MODEL_POISSON: + if (param_n < 0 || param_n > 1) { + return 1; + } + if (param_n == 1) { + gsl_rng_set(random, (unsigned long int)params[0]); // Change the Seed before Sampling + } + for (i = 0; i < data_n; i++) { + data[i] = data[i] + (float)gsl_ran_poisson(random, (double)data[i]); // Randomly perturb data array + } + break; } return 0; @@ -126,7 +151,9 @@ int uda::client::generate_synthetic_data(int handle) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (get_data(handle) == nullptr) return 0; + if (get_data(handle) == nullptr) { + return 0; + } int model; int param_n; @@ -134,9 +161,13 @@ int uda::client::generate_synthetic_data(int handle) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (get_data_num(handle) <= 0) return 0; + if (get_data_num(handle) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -156,62 +187,86 @@ int uda::client::generate_synthetic_data(int handle) switch (get_data_type(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)dp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)ip[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)up[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)get_data(handle); + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)cp[i]; + } break; } @@ -226,8 +281,7 @@ int uda::client::generate_synthetic_data(int handle) err = synthetic_model(model, param_n, params, get_data_num(handle), data); if (err != 0) { - addIdamError(UDA_CODE_ERROR_TYPE, "generate_synthetic_data", err, - "Unable to Generate Synthetic Data"); + addIdamError(UDA_CODE_ERROR_TYPE, "generate_synthetic_data", err, "Unable to Generate Synthetic Data"); free(data); return err; } @@ -247,65 +301,88 @@ int uda::client::generate_synthetic_data(int handle) switch (get_data_type(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) fp[i] = data[i]; // Overwrite the Data + for (int i = 0; i < get_data_num(handle); i++) { + fp[i] = data[i]; // Overwrite the Data + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) dp[i] = (double)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + dp[i] = (double)data[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) sp[i] = (short)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + sp[i] = (short)data[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) ip[i] = (int)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + ip[i] = (int)data[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) lp[i] = (long)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + lp[i] = (long)data[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) lp[i] = (long long int)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + lp[i] = (long long int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) sp[i] = (unsigned short)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + sp[i] = (unsigned short)data[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) up[i] = (unsigned int)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + up[i] = (unsigned int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) lp[i] = (unsigned long)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + lp[i] = (unsigned long)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) lp[i] = (unsigned long long int) data[i]; + auto lp = (unsigned long long int*)getSyntheticData(handle); + for (int i = 0; i < get_data_num(handle); i++) { + lp[i] = (unsigned long long int)data[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = (char*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) cp[i] = (char)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + cp[i] = (char)data[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)getSyntheticData(handle); - for (int i = 0; i < get_data_num(handle); i++) cp[i] = (unsigned char)data[i]; + for (int i = 0; i < get_data_num(handle); i++) { + cp[i] = (unsigned char)data[i]; + } break; } - } //-------------------------------------------------------------------------------------------------------------- @@ -325,9 +402,13 @@ int uda::client::generate_synthetic_dim_data(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (get_data(handle) == nullptr) return 0; // No Data Block available + if (get_data(handle) == nullptr) { + return 0; // No Data Block available + } - if (ndim < 0 || ndim > get_rank(handle)) return 0; + if (ndim < 0 || ndim > get_rank(handle)) { + return 0; + } int model; int param_n; @@ -335,9 +416,13 @@ int uda::client::generate_synthetic_dim_data(int handle, int ndim) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (get_dim_num(handle, ndim) <= 0) return 0; + if (get_dim_num(handle, ndim) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -359,62 +444,86 @@ int uda::client::generate_synthetic_dim_data(int handle, int ndim) switch (get_data_type(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)dp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)ip[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = (char*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)up[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)get_dim_data(handle, ndim); + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -450,62 +559,86 @@ int uda::client::generate_synthetic_dim_data(int handle, int ndim) switch (get_dim_type(handle, ndim)) { case UDA_TYPE_FLOAT: { auto fp = (float*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) fp[i] = data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + fp[i] = data[i]; + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) dp[i] = (double)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + dp[i] = (double)data[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) sp[i] = (short)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + sp[i] = (short)data[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) ip[i] = (int)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + ip[i] = (int)data[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) lp[i] = (long)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + lp[i] = (long)data[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) lp[i] = (long long int)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + lp[i] = (long long int)data[i]; + } break; } case UDA_TYPE_CHAR: { auto cp = get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) cp[i] = (char)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + cp[i] = (char)data[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) sp[i] = (unsigned short)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + sp[i] = (unsigned short)data[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) up[i] = (unsigned int)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + up[i] = (unsigned int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) lp[i] = (unsigned long)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + lp[i] = (unsigned long)data[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) lp[i] = (unsigned long long int) data[i]; + auto lp = (unsigned long long int*)get_synthetic_dim_data(handle, ndim); + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + lp[i] = (unsigned long long int)data[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)get_synthetic_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) cp[i] = (unsigned char)data[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + cp[i] = (unsigned char)data[i]; + } break; } } @@ -527,7 +660,9 @@ int uda::client::generate_data_error(int handle) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (get_data(handle) == nullptr) return 0; // No Data Block available + if (get_data(handle) == nullptr) { + return 0; // No Data Block available + } int model; int param_n; @@ -535,9 +670,13 @@ int uda::client::generate_data_error(int handle) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (get_data_num(handle) <= 0) return 0; + if (get_data_num(handle) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -553,69 +692,99 @@ int uda::client::generate_data_error(int handle) char* errhi; char* errlo; - if ((data = (float*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) return 1; - if ((errhi = (char*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) return 1; - if ((errlo = (char*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) return 1; + if ((data = (float*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) { + return 1; + } + if ((errhi = (char*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) { + return 1; + } + if ((errlo = (char*)malloc(get_data_num(handle) * sizeof(float))) == nullptr) { + return 1; + } switch (get_data_type(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)dp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)ip[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)up[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = (char*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)get_data(handle); + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)get_data(handle); - for (int i = 0; i < get_data_num(handle); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_data_num(handle); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -628,8 +797,7 @@ int uda::client::generate_data_error(int handle) //-------------------------------------------------------------------------------------------------------------- // Generate Error Data - err = error_model(model, param_n, params, get_data_num(handle), data, &asymmetry, (float*)errhi, - (float*)errlo); + err = error_model(model, param_n, params, get_data_num(handle), data, &asymmetry, (float*)errhi, (float*)errlo); if (err != 0) { free(data); @@ -645,7 +813,9 @@ int uda::client::generate_data_error(int handle) set_data_err_asymmetry(handle, asymmetry); if (asymmetry && get_data_err_lo(handle) == nullptr) { - if ((err = allocArray(get_data_type(handle), get_data_num(handle), &perrlo))) return err; + if ((err = allocArray(get_data_type(handle), get_data_num(handle), &perrlo))) { + return err; + } set_data_err_lo(handle, perrlo); } @@ -655,7 +825,9 @@ int uda::client::generate_data_error(int handle) auto fel = (float*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { feh[i] = (float)errhi[i]; - if (get_data_err_asymmetry(handle)) fel[i] = (float)errlo[i]; + if (get_data_err_asymmetry(handle)) { + fel[i] = (float)errlo[i]; + } } break; } @@ -664,7 +836,9 @@ int uda::client::generate_data_error(int handle) auto del = (double*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { deh[i] = (double)errhi[i]; - if (get_data_err_asymmetry(handle)) del[i] = (double)errlo[i]; + if (get_data_err_asymmetry(handle)) { + del[i] = (double)errlo[i]; + } } break; } @@ -673,7 +847,9 @@ int uda::client::generate_data_error(int handle) auto iel = (int*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { ieh[i] = (int)errhi[i]; - if (get_data_err_asymmetry(handle)) iel[i] = (int)errlo[i]; + if (get_data_err_asymmetry(handle)) { + iel[i] = (int)errlo[i]; + } } break; } @@ -682,7 +858,9 @@ int uda::client::generate_data_error(int handle) auto lel = (long*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { leh[i] = (long)errhi[i]; - if (get_data_err_asymmetry(handle)) lel[i] = (long)errlo[i]; + if (get_data_err_asymmetry(handle)) { + lel[i] = (long)errlo[i]; + } } break; } @@ -691,7 +869,9 @@ int uda::client::generate_data_error(int handle) auto lel = (long long int*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { leh[i] = (long long int)errhi[i]; - if (get_data_err_asymmetry(handle)) lel[i] = (long long int)errlo[i]; + if (get_data_err_asymmetry(handle)) { + lel[i] = (long long int)errlo[i]; + } } break; } @@ -700,7 +880,9 @@ int uda::client::generate_data_error(int handle) auto sel = (short*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { seh[i] = (short)errhi[i]; - if (get_data_err_asymmetry(handle)) sel[i] = (short)errlo[i]; + if (get_data_err_asymmetry(handle)) { + sel[i] = (short)errlo[i]; + } } break; } @@ -709,7 +891,9 @@ int uda::client::generate_data_error(int handle) char* cel = get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { ceh[i] = errhi[i]; - if (get_data_err_asymmetry(handle)) cel[i] = errlo[i]; + if (get_data_err_asymmetry(handle)) { + cel[i] = errlo[i]; + } } break; } @@ -718,7 +902,9 @@ int uda::client::generate_data_error(int handle) auto uel = (unsigned int*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { ueh[i] = (unsigned int)errhi[i]; - if (get_data_err_asymmetry(handle)) uel[i] = (unsigned int)errlo[i]; + if (get_data_err_asymmetry(handle)) { + uel[i] = (unsigned int)errlo[i]; + } } break; } @@ -727,16 +913,20 @@ int uda::client::generate_data_error(int handle) auto lel = (unsigned long*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { leh[i] = (unsigned long)errhi[i]; - if (get_data_err_asymmetry(handle)) lel[i] = (unsigned long)errlo[i]; + if (get_data_err_asymmetry(handle)) { + lel[i] = (unsigned long)errlo[i]; + } } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto leh = (unsigned long long int *)get_data_err_hi(handle); - auto lel = (unsigned long long int *)get_data_err_lo(handle); + auto leh = (unsigned long long int*)get_data_err_hi(handle); + auto lel = (unsigned long long int*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { - leh[i] = (unsigned long long int) errhi[i]; - if (get_data_err_asymmetry(handle)) lel[i] = (unsigned long long int) errlo[i]; + leh[i] = (unsigned long long int)errhi[i]; + if (get_data_err_asymmetry(handle)) { + lel[i] = (unsigned long long int)errlo[i]; + } } break; } @@ -745,7 +935,9 @@ int uda::client::generate_data_error(int handle) auto sel = (unsigned short*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { seh[i] = (unsigned short)errhi[i]; - if (get_data_err_asymmetry(handle)) sel[i] = (unsigned short)errlo[i]; + if (get_data_err_asymmetry(handle)) { + sel[i] = (unsigned short)errlo[i]; + } } break; } @@ -754,11 +946,12 @@ int uda::client::generate_data_error(int handle) auto cel = (unsigned char*)get_data_err_lo(handle); for (int i = 0; i < get_data_num(handle); i++) { ceh[i] = (unsigned char)errhi[i]; - if (get_data_err_asymmetry(handle)) cel[i] = (unsigned char)errlo[i]; + if (get_data_err_asymmetry(handle)) { + cel[i] = (unsigned char)errlo[i]; + } } break; } - } //-------------------------------------------------------------------------------------------------------------- @@ -781,9 +974,13 @@ int uda::client::generate_dim_data_error(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Check the handle and model are ok - if (get_data(handle) == nullptr) return 0; // No Data Block available + if (get_data(handle) == nullptr) { + return 0; // No Data Block available + } - if (ndim < 0 || ndim > get_rank(handle)) return 0; + if (ndim < 0 || ndim > get_rank(handle)) { + return 0; + } int model; int param_n; @@ -791,9 +988,13 @@ int uda::client::generate_dim_data_error(int handle, int ndim) get_error_model(handle, &model, ¶m_n, params); - if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) return 0; // No valid Model + if (model <= ERROR_MODEL_UNKNOWN || model >= ERROR_MODEL_UNDEFINED) { + return 0; // No valid Model + } - if (get_dim_num(handle, ndim) <= 0) return 0; + if (get_dim_num(handle, ndim) <= 0) { + return 0; + } //-------------------------------------------------------------------------------------------------------------- // Allocate local float work arrays and copy the data array to the work array @@ -809,69 +1010,99 @@ int uda::client::generate_dim_data_error(int handle, int ndim) char* errhi; char* errlo; - if ((data = (float*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) return 1; - if ((errhi = (char*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) return 1; - if ((errlo = (char*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) return 1; + if ((data = (float*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } + if ((errhi = (char*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } + if ((errlo = (char*)malloc(get_dim_num(handle, ndim) * sizeof(float))) == nullptr) { + return 1; + } switch (get_data_type(handle)) { case UDA_TYPE_FLOAT: { auto fp = (float*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = fp[i]; // Cast all data to Float + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = fp[i]; // Cast all data to Float + } break; } case UDA_TYPE_DOUBLE: { auto dp = (double*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)dp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)dp[i]; + } break; } case UDA_TYPE_INT: { auto ip = (int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)ip[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)ip[i]; + } break; } case UDA_TYPE_LONG: { auto lp = (long*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_LONG64: { auto lp = (long long int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_SHORT: { auto sp = (short*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_CHAR: { char* cp = get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } case UDA_TYPE_UNSIGNED_INT: { auto up = (unsigned int*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)up[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)up[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG: { auto lp = (unsigned long*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)lp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto lp = (unsigned long long int *)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float) lp[i]; + auto lp = (unsigned long long int*)get_dim_data(handle, ndim); + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)lp[i]; + } break; } case UDA_TYPE_UNSIGNED_SHORT: { auto sp = (unsigned short*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)sp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)sp[i]; + } break; } case UDA_TYPE_UNSIGNED_CHAR: { auto cp = (unsigned char*)get_dim_data(handle, ndim); - for (int i = 0; i < get_dim_num(handle, ndim); i++) data[i] = (float)cp[i]; + for (int i = 0; i < get_dim_num(handle, ndim); i++) { + data[i] = (float)cp[i]; + } break; } default: @@ -884,8 +1115,8 @@ int uda::client::generate_dim_data_error(int handle, int ndim) //-------------------------------------------------------------------------------------------------------------- // Generate Model Data - err = error_model(model, param_n, params, get_dim_num(handle, ndim), data, &asymmetry, (float*)errhi, - (float*)errlo); + err = + error_model(model, param_n, params, get_dim_num(handle, ndim), data, &asymmetry, (float*)errhi, (float*)errlo); if (err != 0) { free(data); @@ -901,7 +1132,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) set_dim_err_asymmetry(handle, ndim, asymmetry); if (get_dim_err_asymmetry(handle, ndim) && get_dim_err_lo(handle, ndim) == nullptr) { - if ((err = allocArray(get_dim_type(handle, ndim), get_dim_num(handle, ndim), &perrlo))) return err; + if ((err = allocArray(get_dim_type(handle, ndim), get_dim_num(handle, ndim), &perrlo))) { + return err; + } set_dim_err_lo(handle, ndim, perrlo); } @@ -911,7 +1144,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto fel = (float*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { feh[i] = (float)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))fel[i] = (float)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + fel[i] = (float)errlo[i]; + } } break; } @@ -920,7 +1155,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto del = (double*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { deh[i] = (double)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))del[i] = (double)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + del[i] = (double)errlo[i]; + } } break; } @@ -929,7 +1166,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto iel = (int*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { ieh[i] = (int)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))iel[i] = (int)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + iel[i] = (int)errlo[i]; + } } break; } @@ -938,7 +1177,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto uel = (unsigned int*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { ueh[i] = (unsigned int)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))uel[i] = (unsigned int)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + uel[i] = (unsigned int)errlo[i]; + } } break; } @@ -947,7 +1188,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto lel = (long*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { leh[i] = (long)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))lel[i] = (long)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + lel[i] = (long)errlo[i]; + } } break; } @@ -956,7 +1199,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto lel = (long long int*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { leh[i] = (long long int)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))lel[i] = (long long int)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + lel[i] = (long long int)errlo[i]; + } } break; } @@ -965,7 +1210,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto sel = (short*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { seh[i] = (short)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))sel[i] = (short)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + sel[i] = (short)errlo[i]; + } } break; } @@ -974,7 +1221,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) char* cel = (char*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { ceh[i] = (char)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))cel[i] = errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + cel[i] = errlo[i]; + } } break; } @@ -983,16 +1232,20 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto lel = (unsigned long*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { leh[i] = (unsigned long)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))lel[i] = (unsigned long)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + lel[i] = (unsigned long)errlo[i]; + } } break; } case UDA_TYPE_UNSIGNED_LONG64: { - auto leh = (unsigned long long int *)get_dim_err_hi(handle, ndim); - auto lel = (unsigned long long int *)get_dim_err_lo(handle, ndim); + auto leh = (unsigned long long int*)get_dim_err_hi(handle, ndim); + auto lel = (unsigned long long int*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { - leh[i] = (unsigned long long int) errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))lel[i] = (unsigned long long int) errlo[i]; + leh[i] = (unsigned long long int)errhi[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + lel[i] = (unsigned long long int)errlo[i]; + } } break; } @@ -1001,7 +1254,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto sel = (unsigned short*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { seh[i] = (unsigned short)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))sel[i] = (unsigned short)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + sel[i] = (unsigned short)errlo[i]; + } } break; } @@ -1010,7 +1265,9 @@ int uda::client::generate_dim_data_error(int handle, int ndim) auto cel = (unsigned char*)get_dim_err_lo(handle, ndim); for (int i = 0; i < get_dim_num(handle, ndim); i++) { ceh[i] = (unsigned char)errhi[i]; - if (get_dim_err_asymmetry(handle, ndim))cel[i] = (unsigned char)errlo[i]; + if (get_dim_err_asymmetry(handle, ndim)) { + cel[i] = (unsigned char)errlo[i]; + } } break; } @@ -1025,4 +1282,3 @@ int uda::client::generate_dim_data_error(int handle, int ndim) return 0; } - diff --git a/source/client2/handle.cpp b/source/client2/handle.cpp index f226e5a7..f4045c51 100644 --- a/source/client2/handle.cpp +++ b/source/client2/handle.cpp @@ -1,9 +1,9 @@ #include "handle.hpp" +#include "initStructs.h" +#include "struct.h" #include "udaStructs.h" #include "udaTypes.h" -#include "struct.h" -#include "initStructs.h" #include "thread_client.hpp" @@ -17,7 +17,9 @@ void uda::client::free_handle(int handle) DATA_BLOCK* data_block = get_data_block(handle); - if (data_block == nullptr) return; + if (data_block == nullptr) { + return; + } // Free Hierarchical structured data first @@ -46,7 +48,6 @@ void uda::client::free_handle(int handle) freeMallocLogList(general_block->logmalloclist); free(general_block->logmalloclist); } - } data_block->opaque_block = nullptr; @@ -82,7 +83,7 @@ void uda::client::free_handle(int handle) if ((cptr = data_block->data) != nullptr) { free(cptr); - data_block->data = nullptr; // Prevent another Free + data_block->data = nullptr; // Prevent another Free } if ((cptr = data_block->errhi) != nullptr) { @@ -143,7 +144,7 @@ void uda::client::free_handle(int handle) free(cptr); } - data_block->dims[i].dim = nullptr; // Prevent another Free + data_block->dims[i].dim = nullptr; // Prevent another Free data_block->dims[i].synthetic = nullptr; data_block->dims[i].errhi = nullptr; data_block->dims[i].errlo = nullptr; @@ -166,12 +167,11 @@ void uda::client::free_handle(int handle) } free(ddims); - data_block->dims = nullptr; // Prevent another Free + data_block->dims = nullptr; // Prevent another Free } // closeIdamError(&server_block.idamerrorstack); initDataBlock(data_block); - data_block->handle = -1; // Flag this as ready for re-use + data_block->handle = -1; // Flag this as ready for re-use } - diff --git a/source/client2/host_list.cpp b/source/client2/host_list.cpp old mode 100755 new mode 100644 index 93eb307d..6dfafc49 --- a/source/client2/host_list.cpp +++ b/source/client2/host_list.cpp @@ -1,12 +1,12 @@ #include "host_list.hpp" +#include +#include +#include #include -#include -#include #include -#include -#include -#include +#include +#include #ifndef _WIN32 # include @@ -31,7 +31,7 @@ const HostData* uda::client::HostList::find_by_name(std::string_view name) const { std::string_view target = name; if (name.find("SSL://") == 0) { - target = &name[6]; // Host name must be stripped of SSL:// prefix + target = &name[6]; // Host name must be stripped of SSL:// prefix } for (const auto& data : hosts_) { @@ -43,7 +43,6 @@ const HostData* uda::client::HostList::find_by_name(std::string_view name) const return nullptr; } - uda::client::HostList::HostList() { //---------------------------------------------------------------------------------------------------------------------- @@ -51,7 +50,7 @@ uda::client::HostList::HostList() // Locate the hosts registration file - constexpr const char* filename = "hosts.cfg"; // Default name + constexpr const char* filename = "hosts.cfg"; // Default name const char* config = getenv("UDA_CLIENT_HOSTS_CONFIG"); // Host configuration file std::string config_file; @@ -83,10 +82,12 @@ uda::client::HostList::HostList() // hostAlias and other attributes are not required // ordering is not important - // The host_name may be either a resolvable name or a numeric IP address. The latter may be in either IPv4 or IPv6 format. + // The host_name may be either a resolvable name or a numeric IP address. The latter may be in either IPv4 or IPv6 + // format. // The port number must be given separately from the IP address if the format is IPv6 - // The port number may be appended to the host name or IPv4 numeric address using the standard convention host:port pattern + // The port number may be appended to the host name or IPv4 numeric address using the standard convention host:port + // pattern // if the host IP address or name is prefixed with SSL:// this is stripped off and the isSSL bool set true // if the certificates and private key are defined, the isSSL bool set true @@ -103,7 +104,7 @@ uda::client::HostList::HostList() std::vector tokens; boost::split(tokens, line, boost::is_any_of(" ")); - std::for_each(tokens.begin(), tokens.end(), [](std::string& s){ boost::trim(s); }); + std::for_each(tokens.begin(), tokens.end(), [](std::string& s) { boost::trim(s); }); std::string name = tokens[0]; @@ -160,9 +161,8 @@ uda::client::HostList::HostList() // Extract and Strip the port number from the host name (a.b.c:9999, localhost:9999) for (auto& data : hosts_) { size_t p; - if ((boost::iequals(data.host_name, "localhost") || data.host_name.find('.') != std::string::npos) - && (p = data.host_name.find(':')) != std::string::npos - && data.host_name.size() + 1 < p) { + if ((boost::iequals(data.host_name, "localhost") || data.host_name.find('.') != std::string::npos) && + (p = data.host_name.find(':')) != std::string::npos && data.host_name.size() + 1 < p) { data.port = atoi(&data.host_name[p]); data.host_name.resize(p); } diff --git a/source/client2/make_request_block.cpp b/source/client2/make_request_block.cpp old mode 100755 new mode 100644 index 306d2e18..212aa984 --- a/source/client2/make_request_block.cpp +++ b/source/client2/make_request_block.cpp @@ -1,16 +1,17 @@ #include "make_request_block.hpp" #include "client_environment.hpp" -#include #include +#include -#include +#include "initStructs.h" #include "udaErrors.h" #include #include -#include "initStructs.h" +#include -namespace { +namespace +{ int make_request_data(const Environment* environment, const char* data_object, const char* data_source, REQUEST_DATA* request) { @@ -20,13 +21,13 @@ int make_request_data(const Environment* environment, const char* data_object, c if (strlen(data_object) >= MAXMETA) { UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument string is too long!"); } else { - strcpy(request->signal, data_object); // Passed to the server without modification + strcpy(request->signal, data_object); // Passed to the server without modification } if (strlen(data_source) >= STRING_LENGTH) { UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument string is too long!"); } else { - strcpy(request->source, data_source); // Passed to the server without modification + strcpy(request->source, data_source); // Passed to the server without modification } //------------------------------------------------------------------------------------------------------------------ @@ -35,27 +36,30 @@ int make_request_data(const Environment* environment, const char* data_object, c * This delimiting string can be defined by the user via an environment variable "UDA_API_DELIM". * This must be passed to the server as it needs to separate the prefix from the main component in order to * interpret the data access request. - */ + */ - strcpy(request->api_delim, environment->api_delim); // Server needs to know how to parse the arguments + strcpy(request->api_delim, environment->api_delim); // Server needs to know how to parse the arguments //------------------------------------------------------------------------------------------------------------------ - /* If the default ARCHIVE and/or DEVICE is overridden by local environment variables and the arguments do not contain - * either an archive or device then prefix + /* If the default ARCHIVE and/or DEVICE is overridden by local environment variables and the arguments do not + * contain either an archive or device then prefix * * These environment variables are legacy and not used by the server - */ + */ if (environment->api_device[0] != '\0' && strstr(request->source, request->api_delim) == nullptr) { - auto source = (boost::format("%1%%2%%3%") % environment->api_device % request->api_delim % request->source).str(); + auto source = + (boost::format("%1%%2%%3%") % environment->api_device % request->api_delim % request->source).str(); if (source.length() >= STRING_LENGTH) { - UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, "The Data Source Argument, prefixed with the Device Name, is too long!"); + UDA_THROW_ERROR(SOURCE_ARG_TOO_LONG, + "The Data Source Argument, prefixed with the Device Name, is too long!"); } strcpy(request->source, source.c_str()); } if (environment->api_archive[0] != '\0' && strstr(request->signal, request->api_delim) == nullptr) { - auto signal = (boost::format("%1%%2%%3%") % environment->api_archive % request->api_delim % request->signal).str(); + auto signal = + (boost::format("%1%%2%%3%") % environment->api_archive % request->api_delim % request->signal).str(); if (signal.length() >= STRING_LENGTH) { UDA_THROW_ERROR(SIGNAL_ARG_TOO_LONG, "The Signal/Data Object Argument, prefixed with the Archive Name, is too long!"); @@ -80,7 +84,7 @@ int make_request_data(const Environment* environment, const char* data_object, c * * Any attempted expansion of a server URL will result in a meaningless path. These are ignored by the server. * *** the original source is always retained ! - */ + */ // Path expansion disabled - applications must provide the full path to data resources. // XXXX::12345 shot number @@ -94,8 +98,7 @@ int make_request_data(const Environment* environment, const char* data_object, c char* test = nullptr; if ((test = strstr(request->source, request->api_delim)) == nullptr) { - if (strchr(request->source, '(') == nullptr && - strchr(request->source, ')') == nullptr) { + if (strchr(request->source, '(') == nullptr && strchr(request->source, ')') == nullptr) { // source is not a function call strcpy(request->path, request->source); expandFilePath(request->path, environment); @@ -111,7 +114,7 @@ int make_request_data(const Environment* environment, const char* data_object, c return 0; } -} // anon namespace +} // namespace int uda::client::make_request_block(const Environment* environment, const char** signals, const char** sources, int count, REQUEST_BLOCK* request_block) diff --git a/source/client2/thread_client.cpp b/source/client2/thread_client.cpp index 5e6bb75f..9eec7fa5 100644 --- a/source/client2/thread_client.cpp +++ b/source/client2/thread_client.cpp @@ -91,8 +91,9 @@ char* get_data(int handle) } } -DATA_BLOCK *get_data_block(int handle) { - auto &instance = uda::client::ThreadClient::instance(); +DATA_BLOCK* get_data_block(int handle) +{ + auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); if (data_block == nullptr) { @@ -101,7 +102,8 @@ DATA_BLOCK *get_data_block(int handle) { return data_block; } -DATA_BLOCK *uda::client::get_data_block(int handle) { +DATA_BLOCK* uda::client::get_data_block(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -111,7 +113,8 @@ DATA_BLOCK *uda::client::get_data_block(int handle) { return data_block; } -char *uda::client::get_data(int handle) { +char* uda::client::get_data(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); auto client_flags = instance.client_flags(); @@ -133,7 +136,8 @@ char *uda::client::get_data(int handle) { } } -char *uda::client::get_synthetic_data(int handle) { +char* uda::client::get_synthetic_data(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); auto client_flags = instance.client_flags(); @@ -155,7 +159,8 @@ char *uda::client::get_synthetic_data(int handle) { return data_block->synthetic; } -void uda::client::set_synthetic_data(int handle, char *data) { +void uda::client::set_synthetic_data(int handle, char* data) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -165,7 +170,8 @@ void uda::client::set_synthetic_data(int handle, char *data) { data_block->synthetic = data; } -int uda::client::get_data_status(int handle) { +int uda::client::get_data_status(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -181,7 +187,8 @@ int uda::client::get_data_status(int handle) { } } -int uda::client::get_signal_status(int handle) { +int uda::client::get_signal_status(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -192,7 +199,8 @@ int uda::client::get_signal_status(int handle) { return data_block->signal_status; } -int uda::client::get_data_num(int handle) { +int uda::client::get_data_num(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -203,7 +211,8 @@ int uda::client::get_data_num(int handle) { return data_block->data_n; } -int uda::client::get_data_type(int handle) { +int uda::client::get_data_type(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -213,7 +222,8 @@ int uda::client::get_data_type(int handle) { return data_block->data_type; } -void uda::client::get_error_model(int handle, int *model, int *param_n, float *params) { +void uda::client::get_error_model(int handle, int* model, int* param_n, float* params) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -223,24 +233,25 @@ void uda::client::get_error_model(int handle, int *model, int *param_n, float *p return; } *model = data_block->error_model; // Model ID - *param_n = data_block->error_param_n; // Number of parameters + *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 uda::client::get_dim_num(int handle, int n_dim) { +int uda::client::get_dim_num(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); - if (data_block == nullptr || n_dim < 0 || - (unsigned int)n_dim >= data_block->rank) { + if (data_block == nullptr || n_dim < 0 || (unsigned int)n_dim >= data_block->rank) { return 0; } return data_block->dims[n_dim].dim_n; } -char *uda::client::get_dim_data(int handle, int n_dim) { +char* uda::client::get_dim_data(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -255,18 +266,19 @@ char *uda::client::get_dim_data(int handle, int n_dim) { return get_synthetic_dim_data(handle, n_dim); } -int uda::client::get_dim_type(int handle, int n_dim) { +int uda::client::get_dim_type(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); - if (data_block == nullptr || n_dim < 0 || - (unsigned int)n_dim >= data_block->rank) { + if (data_block == nullptr || n_dim < 0 || (unsigned int)n_dim >= data_block->rank) { return UDA_TYPE_UNKNOWN; } return data_block->dims[n_dim].data_type; } -char *uda::client::get_synthetic_dim_data(int handle, int n_dim) { +char* uda::client::get_synthetic_dim_data(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -276,7 +288,8 @@ char *uda::client::get_synthetic_dim_data(int handle, int n_dim) { return data_block->dims[n_dim].synthetic; } -void uda::client::set_synthetic_dim_data(int handle, int n_dim, char *data) { +void uda::client::set_synthetic_dim_data(int handle, int n_dim, char* data) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -286,7 +299,8 @@ void uda::client::set_synthetic_dim_data(int handle, int n_dim, char *data) { data_block->dims[n_dim].synthetic = data; } -char *uda::client::get_data_err_hi(int handle) { +char* uda::client::get_data_err_hi(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -296,7 +310,8 @@ char *uda::client::get_data_err_hi(int handle) { return data_block->errhi; } -char *uda::client::get_data_err_lo(int handle) { +char* uda::client::get_data_err_lo(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -306,7 +321,8 @@ char *uda::client::get_data_err_lo(int handle) { return data_block->errlo; } -int uda::client::get_data_err_asymmetry(int handle) { +int uda::client::get_data_err_asymmetry(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -316,7 +332,8 @@ int uda::client::get_data_err_asymmetry(int handle) { return data_block->errasymmetry; } -char *uda::client::get_dim_err_hi(int handle, int n_dim) { +char* uda::client::get_dim_err_hi(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -326,7 +343,8 @@ char *uda::client::get_dim_err_hi(int handle, int n_dim) { return data_block->dims[n_dim].errhi; } -char *uda::client::get_dim_err_lo(int handle, int n_dim) { +char* uda::client::get_dim_err_lo(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -336,18 +354,19 @@ char *uda::client::get_dim_err_lo(int handle, int n_dim) { return data_block->dims[n_dim].errlo; } -int uda::client::get_dim_err_asymmetry(int handle, int n_dim) { +int uda::client::get_dim_err_asymmetry(int handle, int n_dim) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); - if (data_block == nullptr || n_dim < 0 || - (unsigned int)n_dim >= data_block->rank) { + if (data_block == nullptr || n_dim < 0 || (unsigned int)n_dim >= data_block->rank) { return 0; } return data_block->dims[n_dim].errasymmetry; } -void uda::client::set_dim_err_lo(int handle, int n_dim, char *err_lo) { +void uda::client::set_dim_err_lo(int handle, int n_dim, char* err_lo) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -357,7 +376,8 @@ void uda::client::set_dim_err_lo(int handle, int n_dim, char *err_lo) { data_block->dims[n_dim].errlo = err_lo; } -void uda::client::set_dim_err_type(int handle, int n_dim, int type) { +void uda::client::set_dim_err_type(int handle, int n_dim, int type) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -367,7 +387,8 @@ void uda::client::set_dim_err_type(int handle, int n_dim, int type) { data_block->dims[n_dim].error_type = type; } -void uda::client::set_dim_err_asymmetry(int handle, int n_dim, int asymmetry) { +void uda::client::set_dim_err_asymmetry(int handle, int n_dim, int asymmetry) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -377,7 +398,8 @@ void uda::client::set_dim_err_asymmetry(int handle, int n_dim, int asymmetry) { data_block->dims[n_dim].errasymmetry = asymmetry; } -int uda::client::get_rank(int handle) { +int uda::client::get_rank(int handle) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -388,7 +410,8 @@ int uda::client::get_rank(int handle) { return (int)data_block->rank; } -void uda::client::set_data_err_lo(int handle, char *err_lo) { +void uda::client::set_data_err_lo(int handle, char* err_lo) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -398,7 +421,8 @@ void uda::client::set_data_err_lo(int handle, char *err_lo) { data_block->errlo = err_lo; } -void uda::client::set_data_err_type(int handle, int type) { +void uda::client::set_data_err_type(int handle, int type) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); @@ -408,7 +432,8 @@ void uda::client::set_data_err_type(int handle, int type) { data_block->error_type = type; } -void uda::client::set_data_err_asymmetry(int handle, int asymmetry) { +void uda::client::set_data_err_asymmetry(int handle, int asymmetry) +{ auto& instance = uda::client::ThreadClient::instance(); auto data_block = instance.data_block(handle); diff --git a/source/client2/updateSelectParms.cpp b/source/client2/updateSelectParms.cpp old mode 100755 new mode 100644 index bd541e8f..33d71386 --- a/source/client2/updateSelectParms.cpp +++ b/source/client2/updateSelectParms.cpp @@ -4,9 +4,10 @@ #include "updateSelectParms.h" -void udaUpdateSelectParms(int fd, fd_set *rfds, struct timeval *tv) { +void udaUpdateSelectParms(int fd, fd_set* rfds, struct timeval* tv) +{ FD_ZERO(rfds); FD_SET(fd, rfds); tv->tv_sec = 0; - tv->tv_usec = 500; // in microsecs => 0.5 ms wait + tv->tv_usec = 500; // in microsecs => 0.5 ms wait } diff --git a/source/client2/updateSelectParms.h b/source/client2/updateSelectParms.h old mode 100755 new mode 100644 index cca669c6..bc4dd322 --- a/source/client2/updateSelectParms.h +++ b/source/client2/updateSelectParms.h @@ -1,16 +1,16 @@ #pragma once #ifndef UDA_CLIENT_UPDATESELECTPARMS_H -#define UDA_CLIENT_UPDATESELECTPARMS_H +# define UDA_CLIENT_UPDATESELECTPARMS_H -#include -#include "export.h" +# include "export.h" +# include -#ifndef _WIN32 -# include -#else -# include -#endif +# ifndef _WIN32 +# include +# else +# include +# endif void udaUpdateSelectParms(int fd, fd_set* rfds, struct timeval* tv); diff --git a/source/clientserver/allocData.cpp b/source/clientserver/allocData.cpp old mode 100755 new mode 100644 index 8c80921f..3f8efa80 --- a/source/clientserver/allocData.cpp +++ b/source/clientserver/allocData.cpp @@ -1,17 +1,17 @@ /*--------------------------------------------------------------- -* Allocate Memory for the Data and Dim Blocks and Data Error Block -* -* Arguments: DATA_BLOCK * Data Block Structure -* -* Returns: allocData 0 if heap allocation was successful -* DATA_BLOCK->data Pointer to Memory Block -* -*--------------------------------------------------------------*/ + * Allocate Memory for the Data and Dim Blocks and Data Error Block + * + * Arguments: DATA_BLOCK * Data Block Structure + * + * Returns: allocData 0 if heap allocation was successful + * DATA_BLOCK->data Pointer to Memory Block + * + *--------------------------------------------------------------*/ #include "allocData.h" -#include #include "udaTypes.h" +#include #include "initStructs.h" #include "udaErrors.h" @@ -25,7 +25,9 @@ */ int allocArray(int data_type, size_t n_data, char** ap) { - if (n_data == 0) return 0; // Insufficient Data to Allocate! + if (n_data == 0) { + return 0; // Insufficient Data to Allocate! + } *ap = nullptr; @@ -140,7 +142,9 @@ int allocDim(DATA_BLOCK* data_block) ndata = (unsigned int)data_block->dims[i].dim_n; - if (ndata == 0) return 1; // Insufficient Data to Allocate! + if (ndata == 0) { + return 1; // Insufficient Data to Allocate! + } size_t data_size = getSizeOf((UDA_TYPE)data_block->dims[i].data_type); @@ -160,8 +164,12 @@ int allocDim(DATA_BLOCK* data_block) } } - if (db == nullptr) return ERROR_ALLOCATING_HEAP; - if (ebh == nullptr || (ebl == nullptr && data_block->dims[i].errasymmetry)) return ERROR_ALLOCATING_HEAP; + if (db == nullptr) { + return ERROR_ALLOCATING_HEAP; + } + if (ebh == nullptr || (ebl == nullptr && data_block->dims[i].errasymmetry)) { + return ERROR_ALLOCATING_HEAP; + } data_block->dims[i].dim = db; data_block->dims[i].errhi = ebh; @@ -208,7 +216,9 @@ int allocPutData(PUTDATA_BLOCK* putData) //------------------------------------------------------------------------ // Allocate Memory for data - if ((count = putData->count) == 0) return 1; // Insufficient Data to Allocate! + if ((count = putData->count) == 0) { + return 1; // Insufficient Data to Allocate! + } size_t data_size = getSizeOf((UDA_TYPE)putData->data_type); if (data_size > 0) { @@ -230,11 +240,13 @@ int allocPutData(PUTDATA_BLOCK* putData) putData->data = db; -// Shape of data + // Shape of data - if (putData->rank > 0) putData->shape = (int*)malloc(putData->rank * sizeof(int)); + if (putData->rank > 0) { + putData->shape = (int*)malloc(putData->rank * sizeof(int)); + } -// Name of data + // Name of data if (putData->blockNameLength > 0) { putData->blockName = (char*)malloc((putData->blockNameLength + 1) * sizeof(char)); @@ -249,9 +261,9 @@ void addIdamPutDataBlockList(PUTDATA_BLOCK* putDataBlock, PUTDATA_BLOCK_LIST* pu { if (putDataBlockList->putDataBlock == nullptr || putDataBlockList->blockCount + 1 >= putDataBlockList->blockListSize) { - putDataBlockList->putDataBlock = (PUTDATA_BLOCK*)realloc((void*)putDataBlockList->putDataBlock, - (putDataBlockList->blockListSize + - GROWPUTDATABLOCKLIST) * sizeof(PUTDATA_BLOCK)); + putDataBlockList->putDataBlock = + (PUTDATA_BLOCK*)realloc((void*)putDataBlockList->putDataBlock, + (putDataBlockList->blockListSize + GROWPUTDATABLOCKLIST) * sizeof(PUTDATA_BLOCK)); putDataBlockList->blockListSize = putDataBlockList->blockListSize + GROWPUTDATABLOCKLIST; } putDataBlockList->putDataBlock[putDataBlockList->blockCount++] = *putDataBlock; diff --git a/source/clientserver/allocData.h b/source/clientserver/allocData.h old mode 100755 new mode 100644 index 48dd5c29..583ea37d --- a/source/clientserver/allocData.h +++ b/source/clientserver/allocData.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_ALLOCDATA_H #define UDA_CLIENTSERVER_ALLOCDATA_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #include diff --git a/source/clientserver/allocXMLData.cpp b/source/clientserver/allocXMLData.cpp old mode 100755 new mode 100644 index 774ef002..86e2d343 --- a/source/clientserver/allocXMLData.cpp +++ b/source/clientserver/allocXMLData.cpp @@ -1,13 +1,15 @@ #ifdef HIERARCHICAL_DATA -#include "allocXMLData.h" +# include "allocXMLData.h" int alloc_efit(EFIT* efit) { void* ap = nullptr; if (efit->npfcoils > 0) { - if ((ap = (void*)malloc(efit->npfcoils * sizeof(PFCOILS))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->npfcoils * sizeof(PFCOILS))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->pfcoils = (PFCOILS*)ap; ap = nullptr; } else { @@ -15,7 +17,9 @@ int alloc_efit(EFIT* efit) } if (efit->npfpassive > 0) { - if ((ap = (void*)malloc(efit->npfpassive * sizeof(PFPASSIVE))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->npfpassive * sizeof(PFPASSIVE))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->pfpassive = (PFPASSIVE*)ap; ap = nullptr; } else { @@ -23,7 +27,9 @@ int alloc_efit(EFIT* efit) } if (efit->npfsupplies > 0) { - if ((ap = (void*)malloc(efit->npfsupplies * sizeof(PFSUPPLIES))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->npfsupplies * sizeof(PFSUPPLIES))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->pfsupplies = (PFSUPPLIES*)ap; ap = nullptr; } else { @@ -31,7 +37,9 @@ int alloc_efit(EFIT* efit) } if (efit->nfluxloops > 0) { - if ((ap = (void*)malloc(efit->nfluxloops * sizeof(FLUXLOOP))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->nfluxloops * sizeof(FLUXLOOP))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->fluxloop = (FLUXLOOP*)ap; ap = nullptr; } else { @@ -39,7 +47,9 @@ int alloc_efit(EFIT* efit) } if (efit->nmagprobes > 0) { - if ((ap = (void*)malloc(efit->nmagprobes * sizeof(MAGPROBE))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->nmagprobes * sizeof(MAGPROBE))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->magprobe = (MAGPROBE*)ap; ap = nullptr; } else { @@ -47,7 +57,9 @@ int alloc_efit(EFIT* efit) } if (efit->npfcircuits > 0) { - if ((ap = (void*)malloc(efit->npfcircuits * sizeof(PFCIRCUIT))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->npfcircuits * sizeof(PFCIRCUIT))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->pfcircuit = (PFCIRCUIT*)ap; ap = nullptr; } else { @@ -65,7 +77,9 @@ int alloc_efit(EFIT* efit) } if (efit->ndiamagnetic > 0) { - if ((ap = (void*)malloc(efit->ndiamagnetic * sizeof(DIAMAGNETIC))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->ndiamagnetic * sizeof(DIAMAGNETIC))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->diamagnetic = (DIAMAGNETIC*)ap; ap = nullptr; } else { @@ -83,7 +97,9 @@ int alloc_efit(EFIT* efit) } if (efit->nlimiter > 0) { - if ((ap = (void*)malloc(efit->nlimiter * sizeof(LIMITER))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(efit->nlimiter * sizeof(LIMITER))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } efit->limiter = (LIMITER*)ap; ap = nullptr; } else { @@ -93,13 +109,14 @@ int alloc_efit(EFIT* efit) return 0; } - int alloc_pfcircuit(PFCIRCUIT* str) { void* ap = nullptr; if (str->nco > 0) { - if ((ap = (void*)malloc(str->nco * sizeof(int))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (void*)malloc(str->nco * sizeof(int))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->coil = (int*)ap; } else { str->coil = nullptr; @@ -108,19 +125,26 @@ int alloc_pfcircuit(PFCIRCUIT* str) return 0; } - int alloc_pfcoils(PFCOILS* str) { float* ap = nullptr; if (str->nco > 0) { - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->r = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->z = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->dr = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->dz = ap; } else { str->r = nullptr; @@ -131,25 +155,38 @@ int alloc_pfcoils(PFCOILS* str) return 0; } - int alloc_pfpassive(PFPASSIVE* str) { float* ap = nullptr; if (str->nco > 0) { - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->r = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->z = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->dr = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->dz = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->ang1 = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->ang2 = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->res = ap; } else { str->r = nullptr; @@ -163,17 +200,22 @@ int alloc_pfpassive(PFPASSIVE* str) return 0; } - int alloc_fluxloop(FLUXLOOP* str) { float* ap = nullptr; if (str->nco > 0) { - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->r = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->z = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->dphi = ap; } else { str->r = nullptr; @@ -183,15 +225,18 @@ int alloc_fluxloop(FLUXLOOP* str) return 0; } - int alloc_limiter(LIMITER* str) { float* ap = nullptr; if (str->nco > 0) { - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->r = ap; - if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) return ERROR_ALLOCATING_HEAP; + if ((ap = (float*)malloc(str->nco * sizeof(float))) == nullptr) { + return ERROR_ALLOCATING_HEAP; + } str->z = ap; } else { str->r = nullptr; diff --git a/source/clientserver/allocXMLData.h b/source/clientserver/allocXMLData.h old mode 100755 new mode 100644 index 3ba7c464..5ce867cb --- a/source/clientserver/allocXMLData.h +++ b/source/clientserver/allocXMLData.h @@ -3,24 +3,24 @@ #ifdef HIERARCHICAL_DATA -#include "idamclientserver.h" -#include "idamclientserverxml.h" -#include "export.h" +# include "export.h" +# include "idamclientserver.h" +# include "idamclientserverxml.h" -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif -LIBRARY_API int alloc_efit(EFIT *efit); -LIBRARY_API int alloc_pfcircuit(PFCIRCUIT *str); -LIBRARY_API int alloc_pfcoils(PFCOILS *str); -LIBRARY_API int alloc_pfpassive(PFPASSIVE *str); -LIBRARY_API int alloc_fluxloop(FLUXLOOP *str); -LIBRARY_API int alloc_limiter(LIMITER *str); +LIBRARY_API int alloc_efit(EFIT* efit); +LIBRARY_API int alloc_pfcircuit(PFCIRCUIT* str); +LIBRARY_API int alloc_pfcoils(PFCOILS* str); +LIBRARY_API int alloc_pfpassive(PFPASSIVE* str); +LIBRARY_API int alloc_fluxloop(FLUXLOOP* str); +LIBRARY_API int alloc_limiter(LIMITER* str); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif diff --git a/source/clientserver/compressDim.cpp b/source/clientserver/compressDim.cpp old mode 100755 new mode 100644 index ed46c9bb..39a4310d --- a/source/clientserver/compressDim.cpp +++ b/source/clientserver/compressDim.cpp @@ -1,17 +1,17 @@ #include "compressDim.h" #include -#include #include +#include #include "udaTypes.h" #include "udaErrors.h" -namespace { +namespace +{ -template -struct Precision { +template struct Precision { static T precision; }; @@ -19,8 +19,7 @@ template T Precision::precision = 0; template <> float Precision::precision = FLT_EPSILON; template <> double Precision::precision = DBL_EPSILON; -template -int compress(DIMS* ddim) +template int compress(DIMS* ddim) { T* dim_data = (T*)ddim->dim; if (dim_data == nullptr) { @@ -29,7 +28,7 @@ int compress(DIMS* ddim) int ndata = ddim->dim_n; - //no need to compress if the data is already compressed or if there are less or equal to 2 elements + // no need to compress if the data is already compressed or if there are less or equal to 2 elements if (ndata <= 3 || ddim->compressed == 1) { // prevent divide by 0 errors or accessing out-of-range memory return 1; @@ -51,19 +50,18 @@ int compress(DIMS* ddim) if (!constant) { ddim->compressed = 0; - return 1; // Data not regular + return 1; // Data not regular } ddim->compressed = 1; ddim->dim0 = dim_data[0]; - ddim->diff = mean_diff; // Average difference - ddim->method = 0; // Default Decompression Method + ddim->diff = mean_diff; // Average difference + ddim->method = 0; // Default Decompression Method return 0; } -template -int decompress(DIMS* ddim) +template int decompress(DIMS* ddim) { int ndata = ddim->dim_n; @@ -74,7 +72,7 @@ int decompress(DIMS* ddim) } T* dim_data = (T*)ddim->dim; - T d0 = (T)ddim->dim0; // Default Compression Method + T d0 = (T)ddim->dim0; // Default Compression Method T diff = (T)ddim->diff; int count = 0; @@ -107,7 +105,7 @@ int decompress(DIMS* ddim) return 0; } -} // anon namespace +} // namespace /** * UDA Naive Dimensional Data Compressor @@ -140,8 +138,8 @@ int compressDim(DIMS* ddim) return compress(ddim); case UDA_TYPE_LONG: return compress(ddim); -// case UDA_TYPE_LONG64: -// return compress(ddim); + // case UDA_TYPE_LONG64: + // return compress(ddim); case UDA_TYPE_FLOAT: return compress(ddim); case UDA_TYPE_DOUBLE: @@ -154,8 +152,8 @@ int compressDim(DIMS* ddim) return compress(ddim); case UDA_TYPE_UNSIGNED_LONG: return compress(ddim); -// case UDA_TYPE_UNSIGNED_LONG64: -// return compress(ddim); + // case UDA_TYPE_UNSIGNED_LONG64: + // return compress(ddim); default: ddim->compressed = 0; return 1; @@ -178,10 +176,10 @@ int compressDim(DIMS* ddim) int uncompressDim(DIMS* ddim) { if (!ddim || ddim->compressed == 0) { - return 0; // Nothing to Uncompress! + return 0; // Nothing to Uncompress! } if (ddim->dim_n == 0) { - return 0; // Nothing to Uncompress! + return 0; // Nothing to Uncompress! } switch (ddim->data_type) { @@ -193,8 +191,8 @@ int uncompressDim(DIMS* ddim) return decompress(ddim); case UDA_TYPE_LONG: return decompress(ddim); -// case UDA_TYPE_LONG64: -// return decompress(ddim); + // case UDA_TYPE_LONG64: + // return decompress(ddim); case UDA_TYPE_FLOAT: return decompress(ddim); case UDA_TYPE_DOUBLE: @@ -207,8 +205,8 @@ int uncompressDim(DIMS* ddim) return decompress(ddim); case UDA_TYPE_UNSIGNED_LONG: return decompress(ddim); -// case UDA_TYPE_UNSIGNED_LONG64: -// return decompress(ddim); + // case UDA_TYPE_UNSIGNED_LONG64: + // return decompress(ddim); default: return UNKNOWN_DATA_TYPE; } diff --git a/source/clientserver/compressDim.h b/source/clientserver/compressDim.h old mode 100755 new mode 100644 index 590d38c4..73f645c0 --- a/source/clientserver/compressDim.h +++ b/source/clientserver/compressDim.h @@ -1,31 +1,31 @@ #ifndef UDA_CLIENTSERVER_COMPRESSDIM_H #define UDA_CLIENTSERVER_COMPRESSDIM_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { #endif -LIBRARY_API int compressDim(DIMS * ddim); +LIBRARY_API int compressDim(DIMS* ddim); /*--------------------------------------------------------------- -* UDA Dimensional Data Uncompressor -* -* Input Arguments: DIMS * Dimensional Data -* -* Returns: uncompressDim 0 if no Problems Found -* Error Code if a Problem Occured -* -* DIMS* ->dim Un-Compressed Dimensional Data -* DIMS* ->compressed Unchanged (necessary) -* -* Note: XML based data correction also uses the compression models: New models -* must also have corrections applied. -* -*--------------------------------------------------------------*/ -LIBRARY_API int uncompressDim(DIMS * ddim); + * UDA Dimensional Data Uncompressor + * + * Input Arguments: DIMS * Dimensional Data + * + * Returns: uncompressDim 0 if no Problems Found + * Error Code if a Problem Occured + * + * DIMS* ->dim Un-Compressed Dimensional Data + * DIMS* ->compressed Unchanged (necessary) + * + * Note: XML based data correction also uses the compression models: New models + * must also have corrections applied. + * + *--------------------------------------------------------------*/ +LIBRARY_API int uncompressDim(DIMS* ddim); #ifdef __cplusplus } diff --git a/source/clientserver/copyStructs.cpp b/source/clientserver/copyStructs.cpp old mode 100755 new mode 100644 index 03e29abb..b9b3fded --- a/source/clientserver/copyStructs.cpp +++ b/source/clientserver/copyStructs.cpp @@ -2,21 +2,23 @@ #include -void copyRequestData(REQUEST_DATA *out, REQUEST_DATA in) { +void copyRequestData(REQUEST_DATA* out, REQUEST_DATA in) +{ *out = in; - strcpy(out->tpass, in.tpass); - strcpy(out->path, in.path); - strcpy(out->file, in.file); - strcpy(out->format, in.format); - strcpy(out->archive, in.archive); + strcpy(out->tpass, in.tpass); + strcpy(out->path, in.path); + strcpy(out->file, in.file); + strcpy(out->format, in.format); + strcpy(out->archive, in.archive); strcpy(out->device_name, in.device_name); - strcpy(out->server, in.server); - strcpy(out->signal, in.signal); - strcpy(out->source, in.source); - strcpy(out->api_delim, in.api_delim); + strcpy(out->server, in.server); + strcpy(out->signal, in.signal); + strcpy(out->source, in.source); + strcpy(out->api_delim, in.api_delim); } -void copyRequestBlock(REQUEST_BLOCK *out, REQUEST_BLOCK in) { +void copyRequestBlock(REQUEST_BLOCK* out, REQUEST_BLOCK in) +{ *out = in; out->requests = (REQUEST_DATA*)malloc(out->num_requests * sizeof(REQUEST_DATA)); for (int i = 0; i < out->num_requests; ++i) { @@ -24,43 +26,44 @@ void copyRequestBlock(REQUEST_BLOCK *out, REQUEST_BLOCK in) { } } -void copyDataSource(DATA_SOURCE *out, DATA_SOURCE 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->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->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); + 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; + 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 old mode 100755 new mode 100644 index 85ed361f..b00b2af5 --- a/source/clientserver/copyStructs.h +++ b/source/clientserver/copyStructs.h @@ -1,9 +1,9 @@ #ifndef UDA_CLIENTSERVER_COPYSTRUCTS_H #define UDA_CLIENTSERVER_COPYSTRUCTS_H +#include "export.h" #include "udaPlugin.h" #include "udaStructs.h" -#include "export.h" #ifdef __cplusplus extern "C" { diff --git a/source/clientserver/errorLog.cpp b/source/clientserver/errorLog.cpp old mode 100755 new mode 100644 index 78c60f8f..5c22337e --- a/source/clientserver/errorLog.cpp +++ b/source/clientserver/errorLog.cpp @@ -3,8 +3,8 @@ #include #include -#include #include +#include static std::vector udaerrorstack; @@ -35,8 +35,8 @@ void udaErrorLog(CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, UDA_ERR struct tm* broken = gmtime(&calendar); - static char accessdate[UDA_DATE_LENGTH]; // The Calendar Time as a formatted String - + static char accessdate[UDA_DATE_LENGTH]; // The Calendar Time as a formatted String + #ifndef _WIN32 asctime_r(broken, accessdate); #else @@ -48,15 +48,14 @@ void udaErrorLog(CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, UDA_ERR for (int i = 0; i < request_block.num_requests; ++i) { auto request = &request_block.requests[i]; - udaLog(UDA_LOG_ERROR, "0 %s [%s] [%d %s %d %d %s %s %s %s %s %s %s]\n", - client_block.uid, accessdate, request->request, request->signal, request->exp_number, - request->pass, request->tpass, request->path, request->file, request->format, request->archive, - request->device_name, request->server); + udaLog(UDA_LOG_ERROR, "0 %s [%s] [%d %s %d %d %s %s %s %s %s %s %s]\n", client_block.uid, accessdate, + request->request, request->signal, request->exp_number, request->pass, request->tpass, request->path, + request->file, request->format, request->archive, request->device_name, request->server); } for (unsigned int i = 0; i < nerrors; i++) { - udaLog(UDA_LOG_ERROR, "1 %s [%s] %d %d [%s] [%s]\n", client_block.uid, accessdate, - errors[i].type, errors[i].code, errors[i].location, errors[i].msg); + udaLog(UDA_LOG_ERROR, "1 %s [%s] %d %d [%s] [%s]\n", client_block.uid, accessdate, errors[i].type, + errors[i].code, errors[i].location, errors[i].msg); } } @@ -152,10 +151,10 @@ void concatUdaError(UDA_ERROR_STACK* errorstackout) void freeIdamErrorStack(UDA_ERROR_STACK* errorstack) { - // "FIX" : this is causing segfaults when using multiple clients (eg. get and put) + // "FIX" : this is causing segfaults when using multiple clients (eg. get and put) // apparently due to both trying to free the same memory. Needs fixing properly. // free(errorstack->idamerror); - + errorstack->nerrors = 0; errorstack->idamerror = nullptr; } diff --git a/source/clientserver/errorLog.h b/source/clientserver/errorLog.h old mode 100755 new mode 100644 index f6820c2e..806199a7 --- a/source/clientserver/errorLog.h +++ b/source/clientserver/errorLog.h @@ -1,18 +1,18 @@ #ifndef UDA_CLIENTSERVER_ERRORLOG_H #define UDA_CLIENTSERVER_ERRORLOG_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #include -#define UDA_DATE_LENGTH 27 +#define UDA_DATE_LENGTH 27 //-------------------------------------------------------- // Error Management -#define UDA_SYSTEM_ERROR_TYPE 1 -#define UDA_CODE_ERROR_TYPE 2 -#define UDA_PLUGIN_ERROR_TYPE 3 +#define UDA_SYSTEM_ERROR_TYPE 1 +#define UDA_CODE_ERROR_TYPE 2 +#define UDA_PLUGIN_ERROR_TYPE 3 #ifdef __cplusplus extern "C" { @@ -34,6 +34,8 @@ LIBRARY_API 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; +#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/clientserver/expand_path.cpp b/source/clientserver/expand_path.cpp old mode 100755 new mode 100644 index f1c87d0e..813acc4a --- a/source/clientserver/expand_path.cpp +++ b/source/clientserver/expand_path.cpp @@ -26,11 +26,11 @@ #include #include -#include #include "udaErrors.h" +#include -#include "stringUtils.h" #include "errorLog.h" +#include "stringUtils.h" #ifdef SERVERBUILD # include #endif @@ -38,22 +38,25 @@ #ifdef NOEXPANDPATH //! Dummy functions used when path expansion is disabled using the NOEXPANDPATH compiler option -char *hostid(char *host) { +char* hostid(char* host) +{ return host; } -char *pathid(char *path) { +char* pathid(char* path) +{ return path; } -void expandFilePath(char *path) { +void expandFilePath(char* path) +{ return; } #else -#include -#include +# include +# include -#define MAXPATHSUBS 10 -#define MAXPATHSUBSLENGTH 256 +# define MAXPATHSUBS 10 +# define MAXPATHSUBSLENGTH 256 /** * The workstation (client host) name is obtained using the operating system command 'hostname'. @@ -64,43 +67,46 @@ void expandFilePath(char *path) { char* hostid(char* host) { -#ifdef _WIN32 +# ifdef _WIN32 DWORD size = STRING_LENGTH - 1; GetComputerName(host, &size); return host; -#else +# else host[0] = '\0'; -#ifndef USEHOSTDOMAINNAME +# ifndef USEHOSTDOMAINNAME if ((gethostname(host, STRING_LENGTH - 1)) != 0) { char* env = getenv("HOSTNAME"); - if (env != nullptr) copyString(env, host, STRING_LENGTH); + if (env != nullptr) { + copyString(env, host, STRING_LENGTH); + } } -#else - if((gethostname(host, STRING_LENGTH-1)) == 0) { +# else + if ((gethostname(host, STRING_LENGTH - 1)) == 0) { char domain[STRING_LENGTH]; - if((getdomainname(domain, STRING_LENGTH-1)) == 0) { + if ((getdomainname(domain, STRING_LENGTH - 1)) == 0) { int l1 = (int)strlen(host); int l2 = (int)strlen(domain); - if(l1+l2+1 < STRING_LENGTH-1) { + if (l1 + l2 + 1 < STRING_LENGTH - 1) { strcat(host, "."); strcat(host, domain); } } } else { - char *env = getenv("HOSTNAME"); - if(env != nullptr) copyString(env, host, STRING_LENGTH); + char* env = getenv("HOSTNAME"); + if (env != nullptr) { + copyString(env, host, STRING_LENGTH); + } } -#endif +# endif if (host[0] == '\0') { addIdamError(UDA_CODE_ERROR_TYPE, "hostid", 999, "Unable to Identify the Host Name"); } return host; -#endif // _WIN32 - +# endif // _WIN32 } //---------------------------------------------------------------------------------------------- @@ -113,8 +119,8 @@ easily done by substitution. Examples: /.automount/funsrv1/root/home/xyz -> /net/funsrv1/home/xyz /.automount/funsrv1/root/home/xyz -> /home/xyz - /.automount/fuslsd/root/data/MAST_Data/013/13500/Pass0/amc0135.00 -> /net/fuslsd/data/MAST_Data/013/13500/Pass0/amc0135.00 - /scratch/mydata -> /net/hostname/scratch/mydata + /.automount/fuslsd/root/data/MAST_Data/013/13500/Pass0/amc0135.00 -> +/net/fuslsd/data/MAST_Data/013/13500/Pass0/amc0135.00 /scratch/mydata -> /net/hostname/scratch/mydata A list of Target path components is read from the environment variable UDA_PRIVATE_PATH_TARGET. The delimiter between components is , or : or ;. @@ -156,10 +162,10 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) std::vector substitutes; if (path[0] == '\0') { - return 0; // No replacement + return 0; // No replacement } if (environment->private_path_target[0] == '\0') { - return 0; // No replacement + return 0; // No replacement } std::string work; @@ -172,7 +178,8 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) boost::split(targets, environment->private_path_target, boost::is_any_of(delimiters), boost::token_compress_on); // Parse substitutes - boost::split(substitutes, environment->private_path_substitute, boost::is_any_of(delimiters), boost::token_compress_on); + boost::split(substitutes, environment->private_path_substitute, boost::is_any_of(delimiters), + boost::token_compress_on); if (targets.size() == substitutes.size()) { for (size_t i = 0; i < targets.size(); i++) { @@ -195,9 +202,10 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) if (substitutes[i] == "*") { // Wildcard found - boost::split(sub_tokens, substitutes[i], boost::is_any_of(PATH_SEPARATOR), boost::token_compress_on); + boost::split(sub_tokens, substitutes[i], boost::is_any_of(PATH_SEPARATOR), + boost::token_compress_on); - auto is_wild = [](const std::string& token){ return token[0] == '0'; }; + auto is_wild = [](const std::string& token) { return token[0] == '0'; }; size_t sub_wild_count = std::count_if(sub_tokens.begin(), sub_tokens.end(), is_wild); size_t target_wild_count = std::count_if(target_tokens.begin(), target_tokens.end(), is_wild); @@ -208,11 +216,13 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) } size_t lpath = 0; - bool match = true; // Test path tokens against target tokens + bool match = true; // Test path tokens against target tokens for (size_t j = 0; j < target_tokens.size(); j++) { match = match && (target_tokens[j] == path_tokens[j] || target_tokens[j][0] == '*'); - lpath = lpath + path_tokens[j].size() + 1; // Find the split point - if (!match) break; + lpath = lpath + path_tokens[j].size() + 1; // Find the split point + if (!match) { + break; + } } if (match) { @@ -244,8 +254,10 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) } } else { - if (substitutes[i] == "*") { // Wildcard found in substitute string! - UDA_THROW_ERROR(999, "No wildcards are permitted in the substitute path unless matched by one in the target path."); + if (substitutes[i] == "*") { // Wildcard found in substitute string! + UDA_THROW_ERROR( + 999, + "No wildcards are permitted in the substitute path unless matched by one in the target path."); } size_t lpath = targets[i].size(); @@ -260,7 +272,8 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) } } else { - UDA_THROW_ERROR(999, "Number of Path Targets and Substitutes is inconsistent. Correct the Environment Variables."); + UDA_THROW_ERROR(999, + "Number of Path Targets and Substitutes is inconsistent. Correct the Environment Variables."); } UDA_LOG(UDA_LOG_DEBUG, "%s\n", path); @@ -271,7 +284,7 @@ int pathReplacement(char* path, const ENVIRONMENT* environment) // Client side only -#ifndef SERVERBUILD +# ifndef SERVERBUILD int linkReplacement(char* path) { @@ -280,9 +293,9 @@ int linkReplacement(char* path) // Is the path a symbolic link not seen by the server? If so make a substitution. //---------------------------------------------------------------------------------------------- -# ifdef _WIN32 +# ifdef _WIN32 return path != nullptr; // No check for windows -# else +# else int err; FILE* ph = nullptr; @@ -298,7 +311,9 @@ int linkReplacement(char* path) errno = 0; if ((ph = popen(cmd.c_str(), "r")) == nullptr) { - if (errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, "linkReplacement", errno, ""); + if (errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, "linkReplacement", errno, ""); + } err = 1; addIdamError(UDA_CODE_ERROR_TYPE, "linkReplacement", err, "Unable to Dereference Symbolic links"); path[0] = '\0'; @@ -321,21 +336,22 @@ int linkReplacement(char* path) strcpy(path, p + 4); convertNonPrintable2(path); TrimString(path); - //expandFilePath(path); + // expandFilePath(path); } } return 0; -# endif // _WIN32 +# endif // _WIN32 } -#else -int linkReplacement(char* path) { +# else +int linkReplacement(char* path) +{ // Links are resolved client side only return 0; } -#endif +# endif //------------------------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------------------------ @@ -363,21 +379,21 @@ int linkReplacement(char* path) { int expandFilePath(char* path, const ENVIRONMENT* environment) { -#ifdef _WIN32 +# ifdef _WIN32 return 0; // No expansion for windows -#else +# else // //---------------------------------------------------------------------------------------------- - char* fp = nullptr, * fp1 = nullptr, * env = nullptr; + char *fp = nullptr, *fp1 = nullptr, *env = nullptr; char file[STRING_LENGTH]; -#ifndef NOHOSTPREFIX +# ifndef NOHOSTPREFIX char host[STRING_LENGTH]; -#endif +# endif char cwd[STRING_LENGTH]; - char ocwd[STRING_LENGTH]; // Current Working Directory - char opath[STRING_LENGTH]; // Original Path string + char ocwd[STRING_LENGTH]; // Current Working Directory + char opath[STRING_LENGTH]; // Original Path string char work[STRING_LENGTH]; char work1[STRING_LENGTH]; char scratch[STRING_LENGTH]; @@ -400,40 +416,42 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) } //------------------------------------------------------------------------------------------------------------------ - /*! Workstations have local hard drives that may also be mounted on the user's network. If this local disk is accessible - by the UDA server it's name needs to be expanded using additional information. As all similar workstations on the network might use - the same name for the local disk area, the host name is used to uniquely identify where the disk is on the network. + /*! Workstations have local hard drives that may also be mounted on the user's network. If this local disk is + accessible by the UDA server it's name needs to be expanded using additional information. As all similar + workstations on the network might use the same name for the local disk area, the host name is used to uniquely + identify where the disk is on the network. The name model adopted to expand directory paths to local disk drives is: /local -> /NETNAME/HOSTNAME/local NETNAME is defined by the environment variable UDA_NETWORKNAME - The hostname of the local workstation is obtained directly from the operating system. If this fails, it can be included - directly in the UDA_NETWORKNAME environment variable. + The hostname of the local workstation is obtained directly from the operating system. If this fails, it can be + included directly in the UDA_NETWORKNAME environment variable. - The local disk directory, e.g. /scratch or /tmp, is targeted using the name defined by the environment variable UDA_SCRATCHNAME + The local disk directory, e.g. /scratch or /tmp, is targeted using the name defined by the environment variable + UDA_SCRATCHNAME - Only ONE local drive can be targeted using the environment variable (current set up could be expanded to use a list). The path - replacement function could be used to target other local directories. + Only ONE local drive can be targeted using the environment variable (current set up could be expanded to use a + list). The path replacement function could be used to target other local directories. */ -#ifdef SCRATCHDIR +# ifdef SCRATCHDIR sprintf(scratch, "/%s/", SCRATCHDIR); lscratch = (int)strlen(scratch); -#else +# else strcpy(scratch, "/scratch/"); lscratch = 9; -#endif +# endif -#ifdef NETPREFIX +# ifdef NETPREFIX strcpy(netname, NETPREFIX); -#else +# else netname[0] = '\0'; -#endif +# endif // Override compiler options - if ((env = getenv("UDA_SCRATCHNAME")) != nullptr) { // Check for Environment Variable + if ((env = getenv("UDA_SCRATCHNAME")) != nullptr) { // Check for Environment Variable snprintf(scratch, STRING_LENGTH, "/%s/", env); lscratch = (int)strlen(scratch); } @@ -454,12 +472,12 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) // Test for necessary expansion - t1 = strstr(path, "./") == nullptr; // relative path? - t2 = strstr(path, "../") == nullptr; // relative path? - t3 = strchr(path, '~') == nullptr; // home path? - t4 = strchr(path, '$') == nullptr; // No imbedded Environment variable - t5 = path[0] == '/'; // No Relative Directory path - t6 = strncmp(path, scratch, lscratch) != 0; // Not the Scratch directory + t1 = strstr(path, "./") == nullptr; // relative path? + t2 = strstr(path, "../") == nullptr; // relative path? + t3 = strchr(path, '~') == nullptr; // home path? + t4 = strchr(path, '$') == nullptr; // No imbedded Environment variable + t5 = path[0] == '/'; // No Relative Directory path + t6 = strncmp(path, scratch, lscratch) != 0; // Not the Scratch directory if (t1 && t2 && t3 && t4 && t5 && t6) { // No Relative path name elements found @@ -470,33 +488,39 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) /*! The path argument has been stripped of any format or protocol prefix. If another prefix is within the path, this indicates the source is server to server. Therefore, the main source element is a URL and is not expanded. - If the ':' character is detected in the source prefix, it is assumed the request is is via a server (the : indicates a port - number) and the main source component is a URL. URLs are not path expanded. + If the ':' character is detected in the source prefix, it is assumed the request is is via a server (the : indicates + a port number) and the main source component is a URL. URLs are not path expanded. Server side functions are identified via the pair of parnethesis enclosing arguments. These are not expanded. */ -#ifdef SERVERELEMENTCHECK - int t7,t8,t9; - t7 = strstr(path,environment->api_delim) != nullptr; // Pass request forward to another server - t8 = strchr(path,':') != nullptr; // Port number => Server - t9 = strchr(path,'(') != nullptr && strchr(path,')') != nullptr; // Server Side Function +# ifdef SERVERELEMENTCHECK + int t7, t8, t9; + t7 = strstr(path, environment->api_delim) != nullptr; // Pass request forward to another server + t8 = strchr(path, ':') != nullptr; // Port number => Server + t9 = strchr(path, '(') != nullptr && strchr(path, ')') != nullptr; // Server Side Function - if(t7 || t8 || t9) return 0; // Server host, protocol, and server side functions -#endif + if (t7 || t8 || t9) { + return 0; // Server host, protocol, and server side functions + } +# endif //------------------------------------------------------------------------------------------------------------------ // Test if the Path begins with an Integer or /Integer => Resolved by the Server Data Plugin if (path[0] == '/') { - strcpy(work, path + 1); // the leading character is a / so ignore + strcpy(work, path + 1); // the leading character is a / so ignore } else { strcpy(work, path); } token = strtok(work, "/"); - if (token != nullptr) if (IsNumber(token)) return 0; // Is the First token an integer number? + if (token != nullptr) { + if (IsNumber(token)) { + return 0; // Is the First token an integer number? + } + } //------------------------------------------------------------------------------------------------------------------ //! Identify the Current Working Directory @@ -522,11 +546,12 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) strcpy(ocwd, cwd); - //! Does the path NOT contain a path directory separator character => filename only so prepend the CWD and return + //! Does the path NOT contain a path directory separator character => filename only so prepend the CWD and + //! return - if ((fp = strrchr(path, '/')) == nullptr) { // Search backwards - extract filename + if ((fp = strrchr(path, '/')) == nullptr) { // Search backwards - extract filename strcpy(work1, path); - snprintf(path, STRING_LENGTH, "%s/%s", cwd, work1); // prepend the CWD and return + snprintf(path, STRING_LENGTH, "%s/%s", cwd, work1); // prepend the CWD and return if ((err = linkReplacement(path)) != 0) { return err; } @@ -538,19 +563,21 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) // Not the Scratch directory ? return 0; } - fp = strrchr(path, '/'); // extract filename + fp = strrchr(path, '/'); // extract filename } - strcpy(file, &fp[1]); // Filename - fp[1] = '\0'; // Split the path string: path now contains directory only + strcpy(file, &fp[1]); // Filename + fp[1] = '\0'; // Split the path string: path now contains directory only //! Does the Path contain with an Environment variable (Not resolved by the function chdir!) fp = nullptr; lpath = (int)strlen(path); - if (lpath > 0) fp = strchr(path + 1, '$'); + if (lpath > 0) { + fp = strchr(path + 1, '$'); + } - if (path[0] == '$' || fp != nullptr) { // Search for a $ character + if (path[0] == '$' || fp != nullptr) { // Search for a $ character if (fp != nullptr) { strncpy(work, path, fp - path); @@ -559,10 +586,12 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) if ((fp1 = strchr(fp, '/')) != nullptr) { strncpy(work1, fp + 1, fp1 - fp - 1); work1[fp1 - fp - 1] = '\0'; - } else { strcpy(work1, fp + 1); } + } else { + strcpy(work1, fp + 1); + } if ((env = getenv(work1)) != - nullptr) { // Check for Environment Variable: If not found then assume it's server side + nullptr) { // Check for Environment Variable: If not found then assume it's server side if (env[0] == '/') { strcpy(work1, env + 1); } else { @@ -579,7 +608,9 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) strncpy(work, path + 1, fp - path - 1); work[fp - path - 1] = '\0'; strcpy(work1, fp); - } else { strcpy(work, path + 1); } + } else { + strcpy(work, path + 1); + } if ((env = getenv(work)) != nullptr) { // Check for Environment Variable: If not found then assume it's server side @@ -606,9 +637,11 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) if (chdir(ocwd) != 0) { UDA_THROW_ERROR(999, "Failed to chdir back to original working directory"); }; - strcpy(path, opath); // Return to the Original path name - UDA_LOG(UDA_LOG_DEBUG, "Unable to identify the Directory of the file: %s\n" - "The server will know if a true error exists: Plugin & Environment dependent", path); + strcpy(path, opath); // Return to the Original path name + UDA_LOG(UDA_LOG_DEBUG, + "Unable to identify the Directory of the file: %s\n" + "The server will know if a true error exists: Plugin & Environment dependent", + path); return 0; } @@ -642,16 +675,17 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) //! Prepend the expanded/resolved directory name to the File Name - snprintf(path, STRING_LENGTH, "%s/%s", work1, file); // Prepend the path to the filename - - } // End of t1 - t5 tests + snprintf(path, STRING_LENGTH, "%s/%s", work1, file); // Prepend the path to the filename + } // End of t1 - t5 tests //---------------------------------------------------------------------------------------------- /*! Symbolic Links might not be visible by the server: Pass the true location - */ + */ - if ((err = linkReplacement(path)) != 0) return err; + if ((err = linkReplacement(path)) != 0) { + return err; + } //---------------------------------------------------------------------------------------------- /*! Does the path contain the client workstation's local Scratch directory (Must be visible by the server) @@ -661,23 +695,24 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) */ -#ifndef NOHOSTPREFIX +# ifndef NOHOSTPREFIX - t6 = strncmp(path, scratch, lscratch) != 0; // Retest for the Scratch directory + t6 = strncmp(path, scratch, lscratch) != 0; // Retest for the Scratch directory - if (!t6) { // Scratch directory used without hostname prefix + if (!t6) { // Scratch directory used without hostname prefix strcpy(work, path); - if (!strncmp(work, scratch, lscratch)) { // case sensistive + if (!strncmp(work, scratch, lscratch)) { // case sensistive - if ((env = getenv("HOSTNAME")) != nullptr) { // Check for a system Environment Variable + if ((env = getenv("HOSTNAME")) != nullptr) { // Check for a system Environment Variable strcpy(host, env); } else { - hostid(host); // Identify the Name of the Current Workstation or Host + hostid(host); // Identify the Name of the Current Workstation or Host } // TODO: refactor this function so that we do not have to guess the path size if (strlen(netname) > 0 && strlen(host) > 0) { - snprintf(path, STRING_LENGTH, "/%s/%s%s", netname, host, work); // prepend /netname/hostname to /scratch/... + snprintf(path, STRING_LENGTH, "/%s/%s%s", netname, host, + work); // prepend /netname/hostname to /scratch/... } else { if (strlen(netname) > 0) { snprintf(path, STRING_LENGTH, "/%s%s", netname, work); @@ -690,7 +725,7 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) } } -#endif +# endif //---------------------------------------------------------------------------------------------- /*! Does the Path to a user's Private Files contain network components not seen by the server? @@ -700,7 +735,7 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) return err; -#endif // _WIN32 +# endif // _WIN32 } //---------------------------------------------------------------------------------------------- @@ -713,12 +748,12 @@ int expandFilePath(char* path, const ENVIRONMENT* environment) char* pathid(char* path) { -#ifdef _WIN32 - return path; // No check for windows -#else +# ifdef _WIN32 + return path; // No check for windows +# else char* p; - char work[STRING_LENGTH]; // Are these consistent with the system MAX_PATH? + char work[STRING_LENGTH]; // Are these consistent with the system MAX_PATH? char pwd[STRING_LENGTH]; strcpy(work, path); @@ -756,7 +791,7 @@ char* pathid(char* path) } path[0] = '\0'; return path; -#endif // _WIN32 +# endif // _WIN32 } #endif diff --git a/source/clientserver/expand_path.h b/source/clientserver/expand_path.h old mode 100755 new mode 100644 index b9818010..0fca601d --- a/source/clientserver/expand_path.h +++ b/source/clientserver/expand_path.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_EXPAND_PATH_H #define UDA_CLIENTSERVER_EXPAND_PATH_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -46,8 +46,8 @@ LIBRARY_API int expandFilePath(char* path, const ENVIRONMENT* environment); #ifndef NOEXPANDPATH -#define MAXPATHSUBS 10 -#define MAXPATHSUBSLENGTH 256 +# define MAXPATHSUBS 10 +# define MAXPATHSUBSLENGTH 256 /*! Free heap memory allocated to generate lists of target path elements and substitute path elements. @@ -73,8 +73,8 @@ easily done by substitution. Examples: /.automount/funsrv1/root/home/xyz -> /net/funsrv1/home/xyz /.automount/funsrv1/root/home/xyz -> /home/xyz - /.automount/fuslsd/root/data/MAST_Data/013/13500/Pass0/amc0135.00 -> /net/fuslsd/data/MAST_Data/013/13500/Pass0/amc0135.00 - /scratch/mydata -> /net/hostname/scratch/mydata + /.automount/fuslsd/root/data/MAST_Data/013/13500/Pass0/amc0135.00 -> +/net/fuslsd/data/MAST_Data/013/13500/Pass0/amc0135.00 /scratch/mydata -> /net/hostname/scratch/mydata A list of Target path components is read from the environment variable IDAM_PRIVATE_PATH_TARGET. The delimiter between components is , or : or ;. diff --git a/source/clientserver/initStructs.cpp b/source/clientserver/initStructs.cpp old mode 100755 new mode 100644 index 264ded92..018e12e2 --- a/source/clientserver/initStructs.cpp +++ b/source/clientserver/initStructs.cpp @@ -63,7 +63,7 @@ void initClientBlock(CLIENT_BLOCK* str, int version, const char* clientname) str->timeout = (int)strtol(getenv("UDA_TIMEOUT"), nullptr, 10); } str->pid = (int)getpid(); - strcpy(str->uid, clientname); // Global userid + strcpy(str->uid, clientname); // Global userid str->compressDim = COMPRESS_DIM; str->clientFlags = 0; @@ -81,7 +81,7 @@ void initClientBlock(CLIENT_BLOCK* str, int version, const char* clientname) str->get_bytes = 0; str->privateFlags = 0; - str->OSName[0] = '\0'; // Operating System Name + str->OSName[0] = '\0'; // Operating System Name str->DOI[0] = '\0'; // Digital Object Identifier (client study reference) #ifdef SECURITYENABLED @@ -97,7 +97,7 @@ void initServerBlock(SERVER_BLOCK* str, int version) str->pid = (int)getpid(); str->idamerrorstack.nerrors = 0; str->idamerrorstack.idamerror = nullptr; - str->OSName[0] = '\0'; // Operating System Name + str->OSName[0] = '\0'; // Operating System Name str->DOI[0] = '\0'; // Digital Object Identifier (server configuration) #ifdef SECURITYENABLED diff --git a/source/clientserver/initXMLStructs.cpp b/source/clientserver/initXMLStructs.cpp old mode 100755 new mode 100644 index 89aeaf2c..312c92a8 --- a/source/clientserver/initXMLStructs.cpp +++ b/source/clientserver/initXMLStructs.cpp @@ -1,6 +1,6 @@ #ifdef HIERARCHICAL_DATA -#include "initXMLStructs.h" +# include "initXMLStructs.h" void initEfit(EFIT* str) { @@ -38,7 +38,7 @@ void initInstance(INSTANCE* str) str->format[0] = '\0'; str->status = 0; str->seq = 0; - str->factor = 1.0; // Factor Always applied to Data! + str->factor = 1.0; // Factor Always applied to Data! } void initFluxLoop(FLUXLOOP* str) @@ -96,7 +96,6 @@ void initMagProbe(MAGPROBE* str) str->rerr = 0.0; } - void initPfSupplies(PFSUPPLIES* str) { str->id[0] = '\0'; @@ -141,7 +140,7 @@ void initToroidalField(TOROIDALFIELD* str) void initLimiter(LIMITER* str) { str->nco = 0; - str->factor = 1.0; // Unique as No Instance Child Structure + str->factor = 1.0; // Unique as No Instance Child Structure str->r = NULL; str->z = NULL; } @@ -254,8 +253,8 @@ void printPfPassive(FILE* fh, PFPASSIVE str) fprintf(fh, "rerr : %f\n", str.rerr); fprintf(fh, "model nr nr: %d %d\n", str.modelnrnz[0], str.modelnrnz[1]); for (int i = 0; i < str.nco; i++) { - fprintf(fh, "r,z,dr,dz,a1,a2,res # %d : %f %f %f %f %f %f %f\n", i, str.r[i], str.z[i], - str.dr[i], str.dz[i], str.ang1[i], str.ang2[i], str.res[i]); + fprintf(fh, "r,z,dr,dz,a1,a2,res # %d : %f %f %f %f %f %f %f\n", i, str.r[i], str.z[i], str.dr[i], + str.dz[i], str.ang1[i], str.ang2[i], str.res[i]); } } diff --git a/source/clientserver/initXMLStructs.h b/source/clientserver/initXMLStructs.h old mode 100755 new mode 100644 index 1dcf6848..e3183eb6 --- a/source/clientserver/initXMLStructs.h +++ b/source/clientserver/initXMLStructs.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_INITXMLSTRUCTS_H #define UDA_CLIENTSERVER_INITXMLSTRUCTS_H -#include "xmlStructs.h" #include "export.h" +#include "xmlStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/clientserver/makeRequestBlock.cpp b/source/clientserver/makeRequestBlock.cpp index c6b080f9..68b0edca 100644 --- a/source/clientserver/makeRequestBlock.cpp +++ b/source/clientserver/makeRequestBlock.cpp @@ -1,8 +1,8 @@ #include "makeRequestBlock.h" +#include #include #include -#include #if defined(__GNUC__) # include @@ -12,15 +12,15 @@ # include #endif -#include #include +#include -#include "pluginStructs.h" #include "errorLog.h" +#include "parseXML.h" +#include "pluginStructs.h" #include "stringUtils.h" #include "udaErrors.h" #include "udaStructs.h" -#include "parseXML.h" #if !defined(__GNUC__) && defined(_WIN32) # include @@ -30,8 +30,8 @@ # define chdir _chdir #endif -#define MAXMAPDEPTH 10 // Maximum number of chained signal name mappings (Recursive depth) -#define MAXREQDEPTH 4 // Maximum number of Device Name to Server Protocol and Host substitution +#define MAXMAPDEPTH 10 // Maximum number of chained signal name mappings (Recursive depth) +#define MAXREQDEPTH 4 // Maximum number of Device Name to Server Protocol and Host substitution static void extract_function_name(const char* str, REQUEST_DATA* request); @@ -60,7 +60,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM int err = 0; char work[MAXMETA]; char work2[MAXMETA]; - unsigned short strip = 1; // Remove enclosing quotes from name value pairs + unsigned short strip = 1; // Remove enclosing quotes from name value pairs UDA_LOG(UDA_LOG_DEBUG, "Source Argument\n"); @@ -80,17 +80,17 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM //------------------------------------------------------------------------------ // Check there is something to work with! - snprintf(work, MAXMETA, "%s%s", environment->api_archive, environment->api_delim); // default archive - snprintf(work2, MAXMETA, "%s%s", environment->api_device, environment->api_delim); // default device + snprintf(work, MAXMETA, "%s%s", environment->api_archive, environment->api_delim); // default archive + snprintf(work2, MAXMETA, "%s%s", environment->api_device, environment->api_delim); // default device LeftTrimString(request->signal); TrimString(request->signal); LeftTrimString(request->source); TrimString(request->source); - bool noSource = (request->source[0] == '\0' || // no source - STR_IEQUALS(request->source, environment->api_device) || // default device name - STR_IEQUALS(request->source, work2)); // default device name + delimiting string + bool noSource = (request->source[0] == '\0' || // no source + STR_IEQUALS(request->source, environment->api_device) || // default device name + STR_IEQUALS(request->source, work2)); // default device name + delimiting string if ((request->signal[0] == '\0' || STR_IEQUALS(request->signal, work)) && noSource) { UDA_THROW_ERROR(999, "Neither Data Object nor Source specified!"); @@ -108,8 +108,8 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM } //------------------------------------------------------------------------------ - // Is this server acting as an UDA Proxy? If all access requests are being re-directed then do nothing to the arguments. - // They are just passed onwards without interpretation. + // Is this server acting as an UDA Proxy? If all access requests are being re-directed then do nothing to the + // arguments. They are just passed onwards without interpretation. bool isProxy = environment->server_proxy[0] != '\0'; @@ -126,9 +126,10 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // DEVICE::pulse/pass // // FORMAT::/path/to/my/file - // FORMAT::./path/to/my/file use client side resolution of ./ location contained in path otherwise ignore - // FORMAT::../path/to/my/file use client side resolution of ../ location - // FORMAT::/scratch/path/to/my/file use client side resolution of /scratch location (change name via environment variable) + // FORMAT::./path/to/my/file use client side resolution of ./ location contained in path otherwise + // ignore FORMAT::../path/to/my/file use client side resolution of ../ location + // FORMAT::/scratch/path/to/my/file use client side resolution of /scratch location (change name via + // environment variable) // // FORMAT::pulse FORMAT is the default FORMAT, e.g. IDA3 // FORMAT::/pulse @@ -144,13 +145,15 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // ../path/to/my/file.ext // /scratch/path/to/my/file.ext // - // PROTOCOL::server.host.name:port/U/R/L server access requests - always requires the delimiter string element in string + // PROTOCOL::server.host.name:port/U/R/L server access requests - always requires the delimiter string element + // in string // // function(arguments or name value pair list) server side processing of data // LIBRARY::function(arguments or name value pair list) function plugin library // DEVICE::function(arguments or name value pair list) Not allowed - use DEVICE::SERVERSIDE::function() // - // DEVICE::FORMAT:: ... If the DEVICE is not the default device, then a server protocol is invoked to pass + // DEVICE::FORMAT:: ... If the DEVICE is not the default device, then a server protocol is invoked to + // pass // the request forward (FORMAT:: ...) // // Legacy exception: treat PPF and JPF formats as server protocols => no file path expansion required and ignored @@ -166,7 +169,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM bool isServer = false; bool isForeign = false; - char* test = strstr(request->source, request->api_delim); // Delimiter present? + char* test = strstr(request->source, request->api_delim); // Delimiter present? if (test != nullptr) { strncpy(work2, request->source, test - request->source); work2[test - request->source] = '\0'; @@ -183,7 +186,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM if (test != nullptr && STR_IEQUALS(work2, environment->api_device) && (p = strstr(work, request->api_delim)) != nullptr) { lstr = (p - work); - strncpy(work2, work, lstr); // Ignore the default device name - force a pass to Scenario 2 + strncpy(work2, work, lstr); // Ignore the default device name - force a pass to Scenario 2 work2[lstr] = '\0'; TrimString(work2); lstr = lstr + ldelim; @@ -199,24 +202,25 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM if (noSource) { // No Source - strcpy(request->device_name, environment->api_device); // Default Device Name + strcpy(request->device_name, environment->api_device); // Default Device Name break; } - if (test == nullptr || - STR_IEQUALS(work2, environment->api_device)) { // No delimiter present or default device? + if (test == nullptr || STR_IEQUALS(work2, environment->api_device)) { // No delimiter present or default device? UDA_LOG(UDA_LOG_DEBUG, "No device name or format or protocol or library is present\n"); - strcpy(request->device_name, environment->api_device); // Default Device Name + strcpy(request->device_name, environment->api_device); // Default Device Name // Regular request: pulse or pulse/pass ==> Generic request - if (generic_request_test(work, request)) break; + if (generic_request_test(work, request)) { + break; + } // Not a Server Side Function? Note: /a/b/fun(aaa) is a (bad!)file path and fun(a/b/c) is a function - char* p0 = strchr(work, '/'); // Path separator mixed with parenthesis? + char* p0 = strchr(work, '/'); // Path separator mixed with parenthesis? char* p1 = strrchr(work, '/'); p = strchr(work, '('); char* p2 = strchr(work, ')'); @@ -239,15 +243,15 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM #ifdef JETSERVER if (rc < 0) { - strcpy(request->format, "PPF"); // Assume the Default Format (PPF?) + 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; break; } } - test = request->source; // No prefix nor delimiter - ldelim = 0; // No offset required + test = request->source; // No prefix nor delimiter + ldelim = 0; // No offset required rc = 1; } #endif @@ -292,7 +296,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM for (int i = 0; i < pluginList.count; i++) { if (STR_IEQUALS(request->archive, pluginList.plugin[i].format)) { - request->request = pluginList.plugin[i].request; // Found! + request->request = pluginList.plugin[i].request; // Found! strcpy(request->format, pluginList.plugin[i].format); break; } @@ -316,25 +320,25 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM 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 + request->request = pluginList.plugin[i].request; // Found strcpy(request->format, pluginList.plugin[i].format); if (pluginList.plugin[i].plugin_class != - UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client + UDA_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 + test + ldelim); // Complete String following :: delimiter + strcpy(request->file, ""); // Clean the filename if (pluginList.plugin[i].plugin_class == UDA_PLUGIN_CLASS_FUNCTION) { isFunction = true; extract_function_name(work, request); } } else { #ifndef __GNUC__ - char base[1024] = { 0 }; + char base[1024] = {0}; _splitpath(test + ldelim, NULL, base, NULL, NULL); #else char* base = basename(test + ldelim); #endif - strcpy(request->file, base); // Final token + 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; @@ -346,12 +350,12 @@ 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 = 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); + pluginList.plugin[i].deviceHost); UDA_LOG(UDA_LOG_DEBUG, "work#1: %s\n", work); if (pluginList.plugin[i].devicePort[0] != '\0') { @@ -375,7 +379,8 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM strcpy(request->source, work); if (depth++ > MAXREQDEPTH) { - UDA_THROW_ERROR(999, "Too many chained Device Name to Server Protocol Host subtitutions!"); + UDA_THROW_ERROR(999, + "Too many chained Device Name to Server Protocol Host subtitutions!"); } err = makeRequestData(request, pluginList, environment); depth--; @@ -385,30 +390,30 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM } } - // If no match was found then the prefix must be a foreign Device Name not entered into the server configuration file. - // The request must be a generic lookup of how to access data remotely for the specified device. - // The external server providing access to the foreign device's data will interpret the arguments + // If no match was found then the prefix must be a foreign Device Name not entered into the server + // configuration file. The request must be a generic lookup of how to access data remotely for the specified + // device. The external server providing access to the foreign device's data will interpret the arguments if (request->request == REQUEST_READ_UNKNOWN) { UDA_LOG(UDA_LOG_DEBUG, "No plugin was identified for the format: %s\n", work2); isForeign = true; - strcpy(request->device_name, work2); // Copy the DEVICE prefix - request->request = REQUEST_READ_GENERIC; // The database will identify the target + strcpy(request->device_name, work2); // Copy the DEVICE prefix + request->request = REQUEST_READ_GENERIC; // The database will identify the target break; } // A match was found: The Source must be a format or a protocol or a library - strcpy(request->device_name, environment->api_device); // Default Device Name + strcpy(request->device_name, environment->api_device); // Default Device Name - if (isFile) { // Resolve any Serverside environment variables + if (isFile) { // Resolve any Serverside environment variables UDA_LOG(UDA_LOG_DEBUG, "File Format has been specified.\n"); expand_environment_variables(request->path); break; } - if (!isFile && !isFunction) { // Server Protocol + if (!isFile && !isFunction) { // Server Protocol UDA_LOG(UDA_LOG_DEBUG, "Server Protocol\n"); break; } @@ -416,8 +421,8 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // Must be a function // Test syntax - char* p0 = strchr(work, '/'); // Path separator mixed with parenthesis? - char* p1 = strrchr(work, '/'); // Path separator mixed with parenthesis? + char* p0 = strchr(work, '/'); // Path separator mixed with parenthesis? + char* p1 = strrchr(work, '/'); // Path separator mixed with parenthesis? p = strchr(work, '('); char* p2 = strchr(work, ')'); @@ -493,9 +498,11 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // as at 19Apr2011 no signals recorded in the UDA database use either [ or { characters // there will be no confusion between subset operations and valid signal names - if (rc == 1) { // the subset has valid syntax so reduce the signal name by removing the subset instructions + if (rc == 1) { // the subset has valid syntax so reduce the signal name by removing the subset instructions p = strstr(request->signal, request->subset); - if (p != nullptr) p[0] = '\0'; // Remove subset operations from variable name + if (p != nullptr) { + p[0] = '\0'; // Remove subset operations from variable name + } TrimString(request->signal); } else { request->subset[0] = '\0'; @@ -503,14 +510,15 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM } //------------------------------------------------------------------------------ - // Extract the Archive Name and detach from the signal (detachment is necessary when not passing on to another UDA server) - // the Plugin Name is synonymous with the Archive Name and takes priority (The archive name is discarded as unimportant) + // Extract the Archive Name and detach from the signal (detachment is necessary when not passing on to another UDA + // server) the Plugin Name is synonymous with the Archive Name and takes priority (The archive name is discarded as + // unimportant) if (request->request == REQUEST_READ_IDAM) { reduceSignal = false; err = extract_archive(request, reduceSignal, environment); } else { - reduceSignal = !isForeign; // Don't detach if a foreign device + reduceSignal = !isForeign; // Don't detach if a foreign device err = extract_archive(request, reduceSignal, environment); } if (request->archive[0] == '\0') { @@ -550,14 +558,14 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // If the signal could be a function call, check the archive name against the function library plugins - if (isFunction && err == 0) { // Test for known Function Libraries + 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 + request->request = pluginList.plugin[i].request; // Found strcpy(request->format, pluginList.plugin[i].format); - isFunction = (pluginList.plugin[i].plugin_class == - UDA_PLUGIN_CLASS_FUNCTION); // Must be a known Library + isFunction = + (pluginList.plugin[i].plugin_class == UDA_PLUGIN_CLASS_FUNCTION); // Must be a known Library break; } } @@ -565,17 +573,19 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM UDA_LOG(UDA_LOG_DEBUG, "A request: %d\n", request->request); UDA_LOG(UDA_LOG_DEBUG, "isFunction: %d\n", isFunction); - if (!isFunction) { // Must be a default server-side function + 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') { - request->request = REQUEST_READ_SERVERSIDE; // Found + request->request = REQUEST_READ_SERVERSIDE; // Found strcpy(request->format, pluginList.plugin[i].format); isFunction = true; break; } } - if (!isFunction) request->function[0] = '\0'; + if (!isFunction) { + request->function[0] = '\0'; + } } UDA_LOG(UDA_LOG_DEBUG, "B request: %d\n", request->request); @@ -595,13 +605,12 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM 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 + 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); 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"); } @@ -614,7 +623,8 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM //--------------------------------------------------------------------------------------------------------------------- // MDS+ Servers ... - // MDS+ Source naming models: MDS+::localhost/tree/number any source with one or more / must have a trailing number + // MDS+ Source naming models: MDS+::localhost/tree/number any source with one or more / must have a trailing + // number // MDS+::server/tree/number // MDS+::server/path/to/data/tree/number // MDS+::server/path.to.data/tree/number @@ -626,24 +636,26 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM if (request->request == REQUEST_READ_MDS && !isProxy) { - reverseString(test + ldelim, work); // Drop the delimiters and Reverse the Source String + reverseString(test + ldelim, work); // Drop the delimiters and Reverse the Source String char* token; - if ((token = strtok(work, "/")) != nullptr) { // Tokenise - if (IsNumber(token)) { // This should be the tree Number otherwise only the server is passed - reverseString(token, work2); // Un-Reverse the token - request->exp_number = (int)strtol(work2, nullptr, 10); // Extract the Data Tree Number + if ((token = strtok(work, "/")) != nullptr) { // Tokenise + if (IsNumber(token)) { // This should be the tree Number otherwise only the server is passed + reverseString(token, work2); // Un-Reverse the token + request->exp_number = (int)strtol(work2, nullptr, 10); // Extract the Data Tree Number if ((token = strtok(nullptr, "/")) != nullptr) { - reverseString(token, request->file); // This should be the Tree Name + reverseString(token, request->file); // This should be the Tree Name work2[0] = '\0'; while ((token = strtok(nullptr, "/")) != nullptr) { // Everything Else is the Server Host and URL Path to the Tree strcat(work2, token); strcat(work2, "/"); } - if (work2[0] == '/') strcpy(work2, &work2[1]); // Drop Trailing / + if (work2[0] == '/') { + strcpy(work2, &work2[1]); // Drop Trailing / + } reverseString(work2, request->server); - token = test + ldelim; // Preserve Leading / + token = test + ldelim; // Preserve Leading / if (token[0] != '/' && request->server[0] == '/') { request->server[0] = ' '; LeftTrimString(request->server); @@ -652,16 +664,16 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM err = 3; } } else { - strcpy(request->server, test + ldelim); // Server or null string (default server) + strcpy(request->server, test + ldelim); // Server or null string (default server) } } else { - strcpy(request->server, ""); // Default Server + strcpy(request->server, ""); // Default Server } if (err != 0) { - UDA_THROW_ERROR(NO_SERVER_SPECIFIED, - "The MDSPlus Data Source does not comply with the naming models: server/tree/number or server/path/to/data/tree/number"); + UDA_THROW_ERROR(NO_SERVER_SPECIFIED, "The MDSPlus Data Source does not comply with the naming models: " + "server/tree/number or server/path/to/data/tree/number"); } } @@ -669,7 +681,7 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM // UDA and WEB Servers ... parse source modelled as: server:port/source if (request->request == REQUEST_READ_IDAM || request->request == REQUEST_READ_WEB) { - strcpy(work, test + ldelim); // Drop the delimiters + strcpy(work, test + ldelim); // Drop the delimiters // Isolate the Server from the source UDA::server:port/source or SSL://server:port/source @@ -679,16 +691,16 @@ int makeRequestData(REQUEST_DATA* request, PLUGINLIST pluginList, const ENVIRONM if ((s = strstr(work, "SSL://")) != nullptr) { char* token; if ((token = strstr(s + 6, "/")) != nullptr) { - token[0] = '\0'; // Break the String (work) - strcpy(request->server, s); // Extract the Server Name and Port (with SSL:// prefix) - strcpy(request->file, token + 1); // Extract the Source URL Argument + token[0] = '\0'; // Break the String (work) + strcpy(request->server, s); // Extract the Server Name and Port (with SSL:// prefix) + strcpy(request->file, token + 1); // Extract the Source URL Argument } } else { char* token; if ((token = strstr(work, "/")) != nullptr) { - token[0] = '\0'; // Break the String (work) - strcpy(request->server, work); // Extract the Server Name and Port - strcpy(request->file, token + 1); // Extract the Source URL Argument + token[0] = '\0'; // Break the String (work) + strcpy(request->server, work); // Extract the Server Name and Port + strcpy(request->file, token + 1); // Extract the Source URL Argument } } @@ -780,19 +792,23 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS request->file[0] = '\0'; request->request = REQUEST_READ_UNKNOWN; - if (source[0] == '\0') return rc; + if (source[0] == '\0') { + return rc; + } // Does the path contain any Illegal (or problem) characters if (!IsLegalFilePath((char*)source)) { - return rc; // Not compliant with Portable Filename character set + return rc; // Not compliant with Portable Filename character set } - // Does the source have a file extension? If so choose the format using the extension, otherwise investigate the file. + // Does the source have a file extension? If so choose the format using the extension, otherwise investigate the + // file. if ((test = strrchr(source, '.')) == nullptr) { - // No extension => test the first line of file, e.g. head -c10 , but both netcdf and hdf5 use the same label HDF! + // No extension => test the first line of file, e.g. head -c10 , but both netcdf and hdf5 use the same + // label HDF! #ifndef _WIN32 const char* nc = " nc"; @@ -805,9 +821,10 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS cmd = fmt::format("head -c10 {} 2>/dev/null", source); errno = 0; if ((ph = popen(cmd.c_str(), "r")) == nullptr) { - if (errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, "sourceFileFormatTest", errno, ""); - addIdamError(UDA_CODE_ERROR_TYPE, "sourceFileFormatTest", 999, - "Unable to Identify the File's Format"); + if (errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, "sourceFileFormatTest", errno, ""); + } + addIdamError(UDA_CODE_ERROR_TYPE, "sourceFileFormatTest", 999, "Unable to Identify the File's Format"); return -999; } @@ -824,10 +841,10 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS LeftTrimString(buffer); TrimString(buffer); - if (STR_EQUALS(buffer, "CDF")) { // Legacy netCDF file + if (STR_EQUALS(buffer, "CDF")) { // Legacy netCDF file test = nc; } else { - if (STR_EQUALS(buffer, "HDF")) { // Either a netCDF or a HDF5 file: use utility programs to reveal! + if (STR_EQUALS(buffer, "HDF")) { // Either a netCDF or a HDF5 file: use utility programs to reveal! char* env = getenv("UDA_DUMP_NETCDF"); if (env != nullptr) { cmd = fmt::format("{} -h {} 2>/dev/null | head -c10 2>/dev/null", env, source); @@ -852,13 +869,15 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS LeftTrimString(buffer); TrimString(buffer); - if (STR_EQUALS(buffer, "netcdf")) { // netCDF file written to an HDF5 file + if (STR_EQUALS(buffer, "netcdf")) { // netCDF file written to an HDF5 file test = nc; } else { - if (cmd[0] == '\0') test = hf; // HDF5 file + if (cmd[0] == '\0') { + test = hf; // HDF5 file + } } } - } else { // an IDA File? + } else { // an IDA File? char* env = getenv("UDA_DUMP_IDA"); if (env != nullptr) { cmd = fmt::format("{} -h {} 2>/dev/null 2>/dev/null", env, source); @@ -907,7 +926,7 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS LeftTrimString(buffer); TrimString(buffer); if (strncmp(buffer, "ida_open error", 14) != 0) { - test = ida; // Legacy IDA file + test = ida; // Legacy IDA file } } } @@ -933,11 +952,13 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS break; } } - if (breakAgain)break; + if (breakAgain) { + break; + } // Other regular types - if (strlen(&test[1]) == 2 && IsNumber(&test[1])) { // an integer number? + if (strlen(&test[1]) == 2 && IsNumber(&test[1])) { // an integer number? strcpy(request->format, "IDA3"); break; } @@ -970,15 +991,15 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS break; } - if (source[0] == '/' && source[1] != '\0' && isdigit(source[1])) { // Default File Format? - if (generic_request_test(&source[1], request)) { // Matches 99999/999 + if (source[0] == '/' && source[1] != '\0' && isdigit(source[1])) { // Default File Format? + if (generic_request_test(&source[1], request)) { // Matches 99999/999 request->request = REQUEST_READ_UNKNOWN; - strcpy(request->format, environment->api_format); // the default Server File Format + strcpy(request->format, environment->api_format); // the default Server File Format break; } } - return -1; // No format identified + return -1; // No format identified } while (0); @@ -988,18 +1009,18 @@ int source_file_format_test(const char* source, REQUEST_DATA* request, PLUGINLIS 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 + request->request = pluginList.plugin[i].request; // Found if (pluginList.plugin[i].plugin_class != - UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client - strcpy(request->file, ""); // Clean the filename + UDA_PLUGIN_CLASS_FILE) { // The full file path fully resolved by the client + strcpy(request->file, ""); // Clean the filename } else { #ifndef __GNUC__ - char base[1024] = { 0 }; + char base[1024] = {0}; _splitpath(request->source, NULL, base, NULL, NULL); #else char* base = basename(request->source); #endif - strcpy(request->file, base); // Final token + strcpy(request->file, base); // Final token } break; } @@ -1024,8 +1045,12 @@ int generic_request_test(const char* source, REQUEST_DATA* request) request->file[0] = '\0'; request->request = REQUEST_READ_UNKNOWN; - if (source[0] == '\0') return rc; - if (source[0] == '/') return rc; // Directory based data + if (source[0] == '\0') { + return rc; + } + if (source[0] == '/') { + return rc; // Directory based data + } //------------------------------------------------------------------------------ // Check if the source has one of these forms: @@ -1033,25 +1058,25 @@ int generic_request_test(const char* source, REQUEST_DATA* request) // pulse plasma shot number - an integer // pulse/pass include a pass or sequence number - this may be a text based component, e.g. LATEST - if (IsNumber((char*)source)) { // Is the source an integer number? + if (IsNumber((char*)source)) { // Is the source an integer number? rc = 1; request->request = REQUEST_READ_GENERIC; - strcpy(request->path, ""); // Clean the path - request->exp_number = (int)strtol(source, nullptr, 10); // Plasma Shot Number + strcpy(request->path, ""); // Clean the path + request->exp_number = (int)strtol(source, nullptr, 10); // Plasma Shot Number UDA_LOG(UDA_LOG_DEBUG, "exp number identified, selecting GENERIC plugin.\n"); } else { strcpy(work, source); - if ((token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string - if (IsNumber(token)) { // Is the First token an integer number? + if ((token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string + if (IsNumber(token)) { // Is the First token an integer number? rc = 1; request->request = REQUEST_READ_GENERIC; - strcpy(request->path, ""); // Clean the path + strcpy(request->path, ""); // Clean the path request->exp_number = (int)strtol(token, nullptr, 10); - if ((token = strtok(nullptr, "/")) != nullptr) { // Next Token + if ((token = strtok(nullptr, "/")) != nullptr) { // Next Token if (IsNumber(token)) { - request->pass = (int)strtol(token, nullptr, 10); // Must be the Pass number + request->pass = (int)strtol(token, nullptr, 10); // Must be the Pass number } else { - strcpy(request->tpass, token); // capture anything else + strcpy(request->tpass, token); // capture anything else } } UDA_LOG(UDA_LOG_DEBUG, "exp number and pass id identified, selecting GENERIC plugin.\n"); @@ -1078,7 +1103,7 @@ int extract_archive(REQUEST_DATA* request, int reduceSignal, const ENVIRONMENT* { int err = 0, test1, test2; int ldelim = (int)strlen(request->api_delim); - char* test, * token, * work; + char *test, *token, *work; TrimString(request->signal); @@ -1118,8 +1143,7 @@ int extract_archive(REQUEST_DATA* request, int reduceSignal, const ENVIRONMENT* test1 = (strlen(&token[1]) == 0 || IsNumber(&token[1])); } - if ((token = strchr(test + ldelim, ']')) != nullptr || - (token = strchr(test + ldelim, '}')) != nullptr) { + if ((token = strchr(test + ldelim, ']')) != nullptr || (token = strchr(test + ldelim, '}')) != nullptr) { work = (char*)malloc((strlen(test + ldelim) + 1) * sizeof(char)); strcpy(work, test + ldelim); work[token - (test + ldelim)] = '\0'; @@ -1131,12 +1155,12 @@ int extract_archive(REQUEST_DATA* request, int reduceSignal, const ENVIRONMENT* if (reduceSignal) { work = (char*)malloc((strlen(test + ldelim) + 1) * sizeof(char)); strcpy(work, test + ldelim); - strcpy(request->signal, work); // Valid Archive & signal + strcpy(request->signal, work); // Valid Archive & signal free(work); TrimString(request->signal); } } else { - request->archive[0] = '\0'; // Reset Archive + request->archive[0] = '\0'; // Reset Archive } UDA_LOG(UDA_LOG_DEBUG, "Archive %s\n", request->archive); @@ -1161,12 +1185,12 @@ void expand_environment_variables(char* path) return; } - if (getcwd(ocwd, lcwd) == nullptr) { // Current Working Directory + if (getcwd(ocwd, lcwd) == nullptr) { // Current Working Directory UDA_LOG(UDA_LOG_DEBUG, "Unable to identify PWD!\n"); return; } - if (chdir(path) == 0) { // Change to path directory + if (chdir(path) == 0) { // Change to path directory // The Current Working Directory is now the resolved directory name char* pcwd = getcwd(cwd, lcwd); @@ -1175,7 +1199,7 @@ void expand_environment_variables(char* path) UDA_LOG(UDA_LOG_DEBUG, "to: %s\n", cwd); if (pcwd != nullptr) { - strcpy(path, cwd); // The expanded path + strcpy(path, cwd); // The expanded path } if (chdir(ocwd) != 0) { // Return to the Original WD @@ -1184,11 +1208,10 @@ void expand_environment_variables(char* path) } else { UDA_LOG(UDA_LOG_DEBUG, "expandEnvironmentvariables: Direct substitution! \n"); - char* fp = nullptr, * env, * fp1; + char *fp = nullptr, *env, *fp1; char work1[STRING_LENGTH]; - if (path[0] == '$' || - (fp = strchr(&path[1], '$')) != nullptr) { // Search for a $ character + if (path[0] == '$' || (fp = strchr(&path[1], '$')) != nullptr) { // Search for a $ character if (fp != nullptr) { strncpy(work, path, fp - path); @@ -1197,7 +1220,9 @@ void expand_environment_variables(char* path) if ((fp1 = strchr(fp, '/')) != nullptr) { strncpy(work1, fp + 1, fp1 - fp - 1); work1[fp1 - fp - 1] = '\0'; - } else { strcpy(work1, fp + 1); } + } else { + strcpy(work1, fp + 1); + } if ((env = getenv(work1)) != nullptr) { if (env[0] == '/') { @@ -1218,9 +1243,11 @@ void expand_environment_variables(char* path) strncpy(work, path + 1, fp - path - 1); work[fp - path - 1] = '\0'; strcpy(work1, fp); - } else { strcpy(work, path + 1); } + } else { + strcpy(work, path + 1); + } - if ((env = getenv(work)) != nullptr) { // Check for Environment Variable + if ((env = getenv(work)) != nullptr) { // Check for Environment Variable if (env[0] == '/') { strcpy(work, env); } else { @@ -1240,14 +1267,14 @@ void expand_environment_variables(char* path) OPTIONAL_LONG parse_integer(const std::string& value) { if (value.empty()) { - return { .init = false, .value = 0 }; + return {.init = false, .value = 0}; } size_t idx; long num = std::stol(value, &idx, 10); if (idx != value.size()) { throw std::runtime_error("Invalid integer"); } - return { .init = true, .value = num }; + return {.init = true, .value = num}; } int parse_element(SUBSET& subset, const std::string& element) @@ -1262,20 +1289,20 @@ int parse_element(SUBSET& subset, const std::string& element) try { switch (tokens.size()) { case 0: - subset.lbindex[index] = { .init = false, .value = 0 }; - subset.ubindex[index] = { .init = false, .value = 0 }; - subset.stride[index] = { .init = false, .value = 0 }; + subset.lbindex[index] = {.init = false, .value = 0}; + subset.ubindex[index] = {.init = false, .value = 0}; + subset.stride[index] = {.init = false, .value = 0}; break; case 1: // TODO: handle non-slice operations? i.e. [>=4], etc. subset.lbindex[index] = parse_integer(tokens[0]); - subset.ubindex[index] = { .init = true, .value = (subset.lbindex[index].value + 1) }; - subset.stride[index] = { .init = false, .value = 0 }; + subset.ubindex[index] = {.init = true, .value = (subset.lbindex[index].value + 1)}; + subset.stride[index] = {.init = false, .value = 0}; break; case 2: subset.lbindex[index] = parse_integer(tokens[0]); subset.ubindex[index] = parse_integer(tokens[1]); - subset.stride[index] = { .init = false, .value = 0 }; + subset.stride[index] = {.init = false, .value = 0}; break; case 3: subset.lbindex[index] = parse_integer(tokens[0]); @@ -1327,7 +1354,6 @@ int parse_operation(SUBSET& subset, const std::string& operation) return 0; } - //---------------------------------------------------------------------- // Parse subset instructions- [start:end:stride] or {start:end:stride} // @@ -1402,9 +1428,15 @@ void freeNameValueList(NAMEVALUELIST* nameValueList) { if (nameValueList->nameValue != nullptr) { for (int i = 0; i < nameValueList->pairCount; i++) { - if (nameValueList->nameValue[i].pair != nullptr) free(nameValueList->nameValue[i].pair); - if (nameValueList->nameValue[i].name != nullptr) free(nameValueList->nameValue[i].name); - if (nameValueList->nameValue[i].value != nullptr) free(nameValueList->nameValue[i].value); + if (nameValueList->nameValue[i].pair != nullptr) { + free(nameValueList->nameValue[i].pair); + } + if (nameValueList->nameValue[i].name != nullptr) { + free(nameValueList->nameValue[i].name); + } + if (nameValueList->nameValue[i].value != nullptr) { + free(nameValueList->nameValue[i].value); + } } } free(nameValueList->nameValue); @@ -1416,7 +1448,7 @@ void freeNameValueList(NAMEVALUELIST* nameValueList) void parse_name_value(const char* pair, NAMEVALUE* nameValue, unsigned short strip) { int lstr; - char* p, * copy; + char *p, *copy; lstr = (int)strlen(pair) + 1; copy = (char*)malloc(lstr * sizeof(char)); strcpy(copy, pair); @@ -1434,12 +1466,12 @@ void parse_name_value(const char* pair, NAMEVALUE* nameValue, unsigned short str lstr = (int)strlen(&p[1]) + 1; nameValue->value = (char*)malloc(lstr * sizeof(char)); strcpy(nameValue->value, &p[1]); - } else { // Mimic IDL keyword passing or stand alone values for placeholder substitution + } else { // Mimic IDL keyword passing or stand alone values for placeholder substitution UDA_LOG(UDA_LOG_DEBUG, "Keyword or placeholder value: %s\n", copy); lstr = (int)strlen(copy) + 1; nameValue->name = (char*)malloc(lstr * sizeof(char)); if (copy[0] == '/') { - strcpy(nameValue->name, ©[1]); // Ignore leader forward slash + strcpy(nameValue->name, ©[1]); // Ignore leader forward slash lstr = 5; nameValue->value = (char*)malloc(lstr * sizeof(char)); strcpy(nameValue->value, "true"); @@ -1457,15 +1489,16 @@ void parse_name_value(const char* pair, NAMEVALUE* nameValue, unsigned short str TrimString(nameValue->value); UDA_LOG(UDA_LOG_DEBUG, "Name: %s Value: %s\n", nameValue->name, nameValue->value); - // Regardless of whether or not the Value is not enclosed in quotes, strip out a possible closing parenthesis character (seen in placeholder value substitution) - // This would not be a valid value unless at the end of a string enclosed in quotes! + // Regardless of whether or not the Value is not enclosed in quotes, strip out a possible closing parenthesis + // character (seen in placeholder value substitution) This would not be a valid value unless at the end of a string + // enclosed in quotes! lstr = (int)strlen(nameValue->value); if (nameValue->value[lstr - 1] == ')' && strchr(nameValue->value, '(') == nullptr) { nameValue->value[lstr - 1] = '\0'; } UDA_LOG(UDA_LOG_DEBUG, "Name: %s Value: %s\n", nameValue->name, nameValue->value); - if (strip) { // remove enclosing single or double quotes + if (strip) { // remove enclosing single or double quotes lstr = (int)strlen(nameValue->name); if ((nameValue->name[0] == '\'' && nameValue->name[lstr - 1] == '\'') || (nameValue->name[0] == '"' && nameValue->name[lstr - 1] == '"')) { @@ -1496,24 +1529,30 @@ int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigne int lstr, pairCount = 0; char proposal, delimiter = ',', substitute = 1; - char* p, * p2, * p3 = nullptr, * buffer, * copy; + char *p, *p2, *p3 = nullptr, *buffer, *copy; NAMEVALUE nameValue; lstr = (int)strlen(pairList); - if (lstr == 0) return pairCount; // Nothing to Parse + if (lstr == 0) { + return pairCount; // Nothing to Parse + } // Placeholder substitution is neither a name-value pair nor a keyword so bypass this test - //if (strchr(pairList, '=') == nullptr && pairList[0] != '/') + // if (strchr(pairList, '=') == nullptr && pairList[0] != '/') // return pairCount; // Not a Name Value list or Keyword - if (pairList[0] == '=') return -1; // Syntax error - if (pairList[lstr - 1] == '=') return -1; // Syntax error + if (pairList[0] == '=') { + return -1; // Syntax error + } + if (pairList[lstr - 1] == '=') { + return -1; // Syntax error + } lstr = lstr + 1; buffer = (char*)malloc(lstr * sizeof(char)); copy = (char*)malloc(lstr * sizeof(char)); - strcpy(copy, pairList); // working copy + strcpy(copy, pairList); // working copy UDA_LOG(UDA_LOG_DEBUG, "Parsing name values from argument: %s\n", pairList); @@ -1524,31 +1563,31 @@ int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigne LeftTrimString(buffer); if (buffer[0] == '=' && buffer[1] != '\0') { buffer[0] = ' '; - LeftTrimString(buffer); // remove whitespace - if (strlen(buffer) >= 3 && ( - (buffer[0] == '\'' && buffer[2] == '\'') || (buffer[0] == '"' && buffer[2] == '"'))) { - proposal = buffer[1]; // proposal delimiter + LeftTrimString(buffer); // remove whitespace + if (strlen(buffer) >= 3 && + ((buffer[0] == '\'' && buffer[2] == '\'') || (buffer[0] == '"' && buffer[2] == '"'))) { + proposal = buffer[1]; // proposal delimiter lstr = (int)(p - copy); - if (lstr == 0) { // delimiter name value pair coincident with start of list - delimiter = proposal; // new delimiter - p3 = strchr(&p[9], delimiter); // change delimiter to avert incorrect parse + if (lstr == 0) { // delimiter name value pair coincident with start of list + delimiter = proposal; // new delimiter + p3 = strchr(&p[9], delimiter); // change delimiter to avert incorrect parse *p3 = '#'; } else { - strncpy(buffer, copy, lstr); // check 'delimiter' is not part of another name value pair + strncpy(buffer, copy, lstr); // check 'delimiter' is not part of another name value pair buffer[lstr] = '\0'; TrimString(buffer); lstr = (int)strlen(buffer); - if (buffer[lstr - 1] == proposal) { // must be an immediately preceeding delimiter character - delimiter = proposal; // new delimiter accepted - p3 = strchr(&p[9], delimiter); // change delimiter temporarily to avert incorrect parse + if (buffer[lstr - 1] == proposal) { // must be an immediately preceeding delimiter character + delimiter = proposal; // new delimiter accepted + p3 = strchr(&p[9], delimiter); // change delimiter temporarily to avert incorrect parse *p3 = '#'; } else { - TrimString(buffer); // Check for non alpha-numeric character + TrimString(buffer); // Check for non alpha-numeric character lstr = (int)strlen(buffer); - if (!isalpha(buffer[lstr - 1]) && !isdigit(buffer[lstr - 1])) { // Probable syntax error! + if (!isalpha(buffer[lstr - 1]) && !isdigit(buffer[lstr - 1])) { // Probable syntax error! free(buffer); free(copy); - return -1; // Flag an Error + return -1; // Flag an Error } } } @@ -1565,10 +1604,10 @@ int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigne for (int i = 0; i < lstr; i++) { if (copy[i] == '\'' || copy[i] == '"') { if (isList) { - isList = 0; // Switch substitution off + isList = 0; // Switch substitution off } else { isList = 1; - } // Switch substitution on + } // Switch substitution on } else { if (isList && copy[i] == delimiter) { isListDelim = 1; @@ -1593,9 +1632,8 @@ int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigne parse_name_value(buffer, &nameValue, strip); UDA_LOG(UDA_LOG_DEBUG, "Name %s, Value: %s\n", nameValue.name, nameValue.value); - //if (nameValue.name != nullptr && nameValue.value != nullptr) { - if (nameValue.name != - nullptr) { // Values may be nullptr for use case where placeholder substitution is used + // if (nameValue.name != nullptr && nameValue.value != nullptr) { + if (nameValue.name != nullptr) { // Values may be nullptr for use case where placeholder substitution is used pairCount++; if (pairCount > nameValueList->listSize) { nameValueList->nameValue = (NAMEVALUE*)realloc((void*)nameValueList->nameValue, @@ -1613,7 +1651,7 @@ int name_value_pairs(const char* pairList, NAMEVALUELIST* nameValueList, unsigne free(copy); for (int i = 0; i < nameValueList->pairCount; i++) { - if (STR_IEQUALS(nameValueList->nameValue[i].name, "delimiter")) { // replace with correct delimiter value + if (STR_IEQUALS(nameValueList->nameValue[i].name, "delimiter")) { // replace with correct delimiter value p = strchr(nameValueList->nameValue[i].value, '#'); *p = delimiter; p = strrchr(nameValueList->nameValue[i].pair, '#'); diff --git a/source/clientserver/makeRequestBlock.h b/source/clientserver/makeRequestBlock.h index 3b3c113d..60f885a6 100644 --- a/source/clientserver/makeRequestBlock.h +++ b/source/clientserver/makeRequestBlock.h @@ -3,8 +3,8 @@ #include "pluginStructs.h" -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/clientserver/manageSockets.cpp b/source/clientserver/manageSockets.cpp old mode 100755 new mode 100644 index eb16e6ae..7d4ac766 --- a/source/clientserver/manageSockets.cpp +++ b/source/clientserver/manageSockets.cpp @@ -7,11 +7,11 @@ #include #ifndef _WIN32 -# include # include +# include #else -# include # include +# include # define strcasecmp _stricmp # include #endif @@ -32,8 +32,10 @@ void initSocketList(SOCKETLIST* socks) int addSocket(SOCKETLIST* socks, int type, int status, char* host, int port, int fh) { int old_fh = -1; - if (!getSocket(socks, type, &status, host, port, &old_fh)) { // Is an Open Socket already listed? - if (old_fh == fh) return 0; + if (!getSocket(socks, type, &status, host, port, &old_fh)) { // Is an Open Socket already listed? + if (old_fh == fh) { + return 0; + } } socks->sockets = (Sockets*)realloc(socks->sockets, (socks->nsocks + 1) * sizeof(SOCKETS)); @@ -60,12 +62,12 @@ int getSocket(SOCKETLIST* socks, int type, int* status, char* host, int port, in if ((*status = socks->sockets[i].status) == 1) { *fh = socks->sockets[i].fh; } else { - *fh = -1; // Not an Open Socket + *fh = -1; // Not an Open Socket } - return 0; // Found + return 0; // Found } } - return 1; // Failed - Need to Open a Socket/Connection + return 1; // Failed - Need to Open a Socket/Connection } // Search for an Open Socket in the Socket List @@ -77,7 +79,7 @@ int getSocketRecordId(SOCKETLIST* socks, int fh) return i; } } - return -1; // Failed - No Socket + return -1; // Failed - No Socket } void closeClientSocket(SOCKETLIST* socks, int fh) @@ -86,7 +88,7 @@ void closeClientSocket(SOCKETLIST* socks, int fh) if (socks->sockets[i].fh == fh && socks->sockets[i].fh >= 0) { if (socks->sockets[i].type == TYPE_UDA_SERVER) { #ifndef _WIN32 - close(fh); // Only Genuine Sockets! + close(fh); // Only Genuine Sockets! #else closesocket(fh); #endif diff --git a/source/clientserver/manageSockets.h b/source/clientserver/manageSockets.h old mode 100755 new mode 100644 index 541e39de..5f7e1141 --- a/source/clientserver/manageSockets.h +++ b/source/clientserver/manageSockets.h @@ -1,24 +1,24 @@ #ifndef UDA_CLIENTSERVER_MANAGESOCKETS_H #define UDA_CLIENTSERVER_MANAGESOCKETS_H -#include "socketStructs.h" #include "export.h" +#include "socketStructs.h" #ifdef __cplusplus extern "C" { #endif // Initialise -LIBRARY_API void initSocketList(SOCKETLIST *socks); +LIBRARY_API void initSocketList(SOCKETLIST* socks); // Add a New Socket to the Socket List -LIBRARY_API int addSocket(SOCKETLIST *socks, int type, int status, char *host, int port, int fh); +LIBRARY_API int addSocket(SOCKETLIST* socks, int type, int status, char* host, int port, int fh); // Search for an Open Socket in the Socket List -LIBRARY_API int getSocket(SOCKETLIST *socks, int type, int *status, char *host, int port, int *fh); +LIBRARY_API int getSocket(SOCKETLIST* socks, int type, int* status, char* host, int port, int* fh); // Search for an Open Socket in the Socket List -LIBRARY_API int getSocketRecordId(SOCKETLIST *socks, int fh); +LIBRARY_API int getSocketRecordId(SOCKETLIST* socks, int fh); LIBRARY_API void closeClientSockets(SOCKETLIST* socks); @@ -29,4 +29,3 @@ LIBRARY_API void closeClientSocket(SOCKETLIST* socks, int fh); #endif #endif // UDA_CLIENTSERVER_MANAGESOCKETS_H - diff --git a/source/clientserver/memstream.cpp b/source/clientserver/memstream.cpp old mode 100755 new mode 100644 index 481bf63c..38429fb6 --- a/source/clientserver/memstream.cpp +++ b/source/clientserver/memstream.cpp @@ -4,11 +4,11 @@ #if defined(__APPLE__) && __DARWIN_C_LEVEL < 200809L -#include "memstream.h" +# include "memstream.h" -#include -#include -#include +# include +# include +# include struct memstream { char** cp; @@ -16,18 +16,16 @@ struct memstream { size_t offset; }; -static void -memstream_grow(struct memstream* ms, size_t newsize) +static void memstream_grow(struct memstream* ms, size_t newsize) { char* buf; if (newsize > *ms->lenp) { buf = (char*)realloc(*ms->cp, newsize + 1); if (buf != nullptr) { -#ifdef DEBUG - fprintf(stderr, "MS: %p growing from %zd to %zd\n", - ms, *ms->lenp, newsize); -#endif +# ifdef DEBUG + fprintf(stderr, "MS: %p growing from %zd to %zd\n", ms, *ms->lenp, newsize); +# endif memset(buf + *ms->lenp + 1, 0, newsize - *ms->lenp); *ms->cp = buf; *ms->lenp = newsize; @@ -35,8 +33,7 @@ memstream_grow(struct memstream* ms, size_t newsize) } } -static int -memstream_read(void* cookie, char* buf, int len) +static int memstream_read(void* cookie, char* buf, int len) { struct memstream* ms; int tocopy; @@ -49,14 +46,13 @@ memstream_read(void* cookie, char* buf, int len) } memcpy(buf, *ms->cp + ms->offset, tocopy); ms->offset += tocopy; -#ifdef DEBUG +# ifdef DEBUG fprintf(stderr, "MS: read(%p, %d) = %d\n", ms, len, tocopy); -#endif +# endif return tocopy; } -static int -memstream_write(void* cookie, const char* buf, int len) +static int memstream_write(void* cookie, const char* buf, int len) { struct memstream* ms; int tocopy; @@ -69,24 +65,23 @@ memstream_write(void* cookie, const char* buf, int len) } memcpy(*ms->cp + ms->offset, buf, tocopy); ms->offset += tocopy; -#ifdef DEBUG +# ifdef DEBUG fprintf(stderr, "MS: write(%p, %d) = %d\n", ms, len, tocopy); -#endif +# endif return tocopy; } -static fpos_t -memstream_seek(void* cookie, fpos_t pos, int whence) +static fpos_t memstream_seek(void* cookie, fpos_t pos, int whence) { struct memstream* ms; -#ifdef DEBUG +# ifdef DEBUG size_t old; -#endif +# endif ms = (memstream*)cookie; -#ifdef DEBUG +# ifdef DEBUG old = ms->offset; -#endif +# endif switch (whence) { case SEEK_SET: ms->offset = (size_t)pos; @@ -98,22 +93,19 @@ memstream_seek(void* cookie, fpos_t pos, int whence) ms->offset = *ms->lenp + pos; break; } -#ifdef DEBUG - fprintf(stderr, "MS: seek(%p, %zd, %d) %zd -> %zd\n", ms, pos, whence, - old, ms->offset); -#endif +# ifdef DEBUG + fprintf(stderr, "MS: seek(%p, %zd, %d) %zd -> %zd\n", ms, pos, whence, old, ms->offset); +# endif return (fpos_t)ms->offset; } -static int -memstream_close(void* cookie) +static int memstream_close(void* cookie) { free(cookie); return 0; } -FILE* -open_memstream(char** cp, size_t* lenp) +FILE* open_memstream(char** cp, size_t* lenp) { struct memstream* ms; int save_errno; diff --git a/source/clientserver/memstream.h b/source/clientserver/memstream.h old mode 100755 new mode 100644 index 48be0c46..b4ba024b --- a/source/clientserver/memstream.h +++ b/source/clientserver/memstream.h @@ -1,12 +1,11 @@ #ifndef UDA_CLIENTSERVER_MAC_MEMSTREAM_H #define UDA_CLIENTSERVER_MAC_MEMSTREAM_H -#include #include "export.h" +#include #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif LIBRARY_API FILE* open_memstream(char** cp, size_t* lenp); diff --git a/source/clientserver/memstream_win.cpp b/source/clientserver/memstream_win.cpp index a23e3a49..3ba147ff 100644 --- a/source/clientserver/memstream_win.cpp +++ b/source/clientserver/memstream_win.cpp @@ -2,36 +2,37 @@ #include "memstream.h" -#include -#include -#include #include +#include #include +#include +#include #define MAX_CACHE_SIZE 500000000 -FILE *open_memstream(char **cp, size_t *lenp) { +FILE* open_memstream(char** cp, size_t* lenp) +{ int fd; - FILE *stream; + FILE* stream; stream = tmpfile(); fd = _fileno(stream); - + HANDLE fm; - HANDLE h = (HANDLE) _get_osfhandle (fd); - *lenp=MAX_CACHE_SIZE; + HANDLE h = (HANDLE)_get_osfhandle(fd); + *lenp = MAX_CACHE_SIZE; - fm = CreateFileMapping(h, NULL, PAGE_READWRITE|SEC_RESERVE, 0, MAX_CACHE_SIZE, NULL); - - if (fm == NULL) { - fprintf (stderr, "memstream_win: Couldn't access memory space! %s\n", strerror (GetLastError())); + fm = CreateFileMapping(h, NULL, PAGE_READWRITE | SEC_RESERVE, 0, MAX_CACHE_SIZE, NULL); + + if (fm == NULL) { + fprintf(stderr, "memstream_win: Couldn't access memory space! %s\n", strerror(GetLastError())); exit(GetLastError()); } *cp = (char*)MapViewOfFile(fm, FILE_MAP_ALL_ACCESS, 0, 0, 0); - - if (*cp == NULL) { - fprintf (stderr, "memstream_win: Couldn't fill memory space! %s\n", strerror (GetLastError())); + + if (*cp == NULL) { + fprintf(stderr, "memstream_win: Couldn't fill memory space! %s\n", strerror(GetLastError())); exit(GetLastError()); } diff --git a/source/clientserver/mkstemp.cpp b/source/clientserver/mkstemp.cpp index d1b5ebd1..f3d9e35d 100644 --- a/source/clientserver/mkstemp.cpp +++ b/source/clientserver/mkstemp.cpp @@ -1,10 +1,10 @@ #include "mkstemp.h" +#include #include #include -#include -#include #include +#include /* mkstemp extracted from libc/sysdeps/posix/tempname.c. Copyright (C) 1991-1999, 2000, 2001, 2006 Free Software Foundation, Inc. @@ -14,18 +14,16 @@ License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. */ -static const char letters[] = -"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; +static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; /* Generate a temporary file name based on TMPL. TMPL must match the rules for mk[s]temp (i.e. end in "XXXXXX"). The name constructed does not exist at the time of the call to mkstemp. TMPL is overwritten with the result. */ -int -mkstemp(char *tmpl) +int mkstemp(char* tmpl) { size_t len; - char *XXXXXX; + char* XXXXXX; static unsigned long long value; unsigned long long random_time_bits; unsigned int count; @@ -40,8 +38,8 @@ mkstemp(char *tmpl) give the system administrator the chance to remove the problems. */ #define ATTEMPTS_MIN (62 * 62 * 62) - /* The number of times to attempt to generate a temporary file. To - conform to POSIX, this must be no smaller than TMP_MAX. */ + /* The number of times to attempt to generate a temporary file. To + conform to POSIX, this must be no smaller than TMP_MAX. */ #if ATTEMPTS_MIN < TMP_MAX unsigned int attempts = TMP_MAX; #else @@ -49,8 +47,7 @@ mkstemp(char *tmpl) #endif len = strlen(tmpl); - if (len < 6 || strcmp(&tmpl[len - 6], "XXXXXX")) - { + if (len < 6 || strcmp(&tmpl[len - 6], "XXXXXX")) { errno = EINVAL; return -1; } @@ -66,19 +63,16 @@ mkstemp(char *tmpl) // get system time GetSystemTime(&stNow); stNow.wMilliseconds = 500; - if (!SystemTimeToFileTime(&stNow, &ftNow)) - { + if (!SystemTimeToFileTime(&stNow, &ftNow)) { errno = -1; return -1; } - random_time_bits = (((unsigned long long)ftNow.dwHighDateTime << 32) - | (unsigned long long)ftNow.dwLowDateTime); + random_time_bits = (((unsigned long long)ftNow.dwHighDateTime << 32) | (unsigned long long)ftNow.dwLowDateTime); } value += random_time_bits ^ (unsigned long long)GetCurrentThreadId(); - for (count = 0; count < attempts; value += 7777, ++count) - { + for (count = 0; count < attempts; value += 7777, ++count) { unsigned long long v = value; /* Fill in the random bits. */ @@ -95,13 +89,12 @@ mkstemp(char *tmpl) XXXXXX[5] = letters[v % 62]; fd = _open(tmpl, O_RDWR | O_CREAT | O_EXCL, _S_IREAD | _S_IWRITE); - if (fd >= 0) - { + if (fd >= 0) { errno = save_errno; return fd; - } - else if (errno != EEXIST) + } else if (errno != EEXIST) { return -1; + } } /* We got out of the loop because we ran out of combinations to try. */ diff --git a/source/clientserver/mkstemp.h b/source/clientserver/mkstemp.h index b8930f21..9f8c333c 100644 --- a/source/clientserver/mkstemp.h +++ b/source/clientserver/mkstemp.h @@ -8,7 +8,7 @@ extern "C" { #endif #ifndef __GNUC__ -LIBRARY_API int mkstemp (char *tmpl); +LIBRARY_API int mkstemp(char* tmpl); #endif #ifdef __cplusplus diff --git a/source/clientserver/nameValueSubstitution.cpp b/source/clientserver/nameValueSubstitution.cpp index 72fa2aaf..bfd0808f 100644 --- a/source/clientserver/nameValueSubstitution.cpp +++ b/source/clientserver/nameValueSubstitution.cpp @@ -1,69 +1,76 @@ #include "nameValueSubstitution.h" -#include #include +#include #if defined(__GNUC__) -# include # include +# include #endif -#include "udaErrors.h" -#include #include "initStructs.h" -#include +#include "udaErrors.h" #include -#include +#include +#include #include +#include static void embedded_value_substitution(NAMEVALUELIST* nameValueList); // Deconstruct the text pass parameter (tpass) for name value placeholder substitution values // Identify name value placeholders in the signal argument and replace with substitution values -// Add additional name-value pairs and keywords to the plugin input +// Add additional name-value pairs and keywords to the plugin input -// shot/tpass data source pattern: "12345/a,b,c, name=value, name=value, d, e, delimiter=',', placeholder='$'" +// shot/tpass data source pattern: "12345/a,b,c, name=value, name=value, d, e, delimiter=',', placeholder='$'" // int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) { int err = 0; - if (!tpass && strlen(tpass) == 0) return 0; // nothing to substitute and no new NV pairs + if (!tpass && strlen(tpass) == 0) { + return 0; // nothing to substitute and no new NV pairs + } UDA_LOG(UDA_LOG_DEBUG, "nameValueSubstitution - Initial set of %d NV pairs\n", nameValueList->pairCount); - for (int i = 0; i < nameValueList->pairCount; i++) + for (int i = 0; i < nameValueList->pairCount; i++) { UDA_LOG(UDA_LOG_DEBUG, "Pair[%d] = %s, Name = %s, value = %s\n", i, nameValueList->nameValue[i].pair, nameValueList->nameValue[i].name, nameValueList->nameValue[i].value); + } NAMEVALUELIST newNameValueList; initNameValueList(&newNameValueList); - unsigned short strip = 0; // Do Not Remove enclosing quotes from name value pairs + unsigned short strip = 0; // Do Not Remove enclosing quotes from name value pairs if (name_value_pairs(tpass, &newNameValueList, strip) == -1) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "nameValueSubstitution", err, "Name Value pair syntax is incorrect!"); return err; } - if (newNameValueList.pairCount == 0) { // No passed substitution values or additional name value pairs - if (newNameValueList.nameValue != nullptr) freeNameValueList(&newNameValueList); + if (newNameValueList.pairCount == 0) { // No passed substitution values or additional name value pairs + if (newNameValueList.nameValue != nullptr) { + freeNameValueList(&newNameValueList); + } return 0; } UDA_LOG(UDA_LOG_DEBUG, "nameValueSubstitution - Additional set of %d NV pairs\n", newNameValueList.pairCount); - for (int i = 0; i < newNameValueList.pairCount; i++) + for (int i = 0; i < newNameValueList.pairCount; i++) { UDA_LOG(UDA_LOG_DEBUG, "Pair[%d] = %s, Name = %s, value = %s\n", i, newNameValueList.nameValue[i].pair, newNameValueList.nameValue[i].name, newNameValueList.nameValue[i].value); + } - // How many placeholders? [beginning with a '$' character. Placeholders may be numbered, named or simply a single naked $ character] + // How many placeholders? [beginning with a '$' character. Placeholders may be numbered, named or simply a single + // naked $ character] int placeholderCount = 0; int* placeholderIndex = nullptr; int* tpassIndex = nullptr; int tpassPosition = 0; - if (nameValueList->pairCount > 0) { // Identify and Count Placeholders + if (nameValueList->pairCount > 0) { // Identify and Count Placeholders do { placeholderIndex = (int*)malloc(nameValueList->pairCount * sizeof(int)); tpassIndex = (int*)malloc(nameValueList->pairCount * sizeof(int)); @@ -71,14 +78,16 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) for (int i = 0; i < nameValueList->pairCount; i++) { // Is it a placeholder? (Not a keyword and begining '$') if (nameValueList->nameValue[i].value != nullptr && nameValueList->nameValue[i].value[0] == '$') { - placeholderIndex[placeholderCount] = i; // Identify which pair - tpassIndex[placeholderCount] = tpassPosition++; // Ordering: Default substitution value to use - list position + placeholderIndex[placeholderCount] = i; // Identify which pair + tpassIndex[placeholderCount] = + tpassPosition++; // Ordering: Default substitution value to use - list position if (nameValueList->nameValue[i].value[1] != '\0') { - if (IsNumber( - &nameValueList->nameValue[i].value[1])) // Is the placeholder numbered? - Use the specific substitution value identified by list order + if (IsNumber(&nameValueList->nameValue[i] + .value[1])) { // Is the placeholder numbered? - Use the specific substitution + // value identified by list order tpassIndex[placeholderCount] = atoi(&nameValueList->nameValue[i].value[1]) - - 1; // Position labelling begins '1' not '0' - else { + 1; // Position labelling begins '1' not '0' + } else { // scan the list of substitute pairs and match by name (case sensitive) for (int j = 0; j < newNameValueList.pairCount; j++) { if (strcmp(&nameValueList->nameValue[i].value[1], newNameValueList.nameValue[j].name) == @@ -90,15 +99,17 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) } } placeholderCount++; - if (placeholderCount <= newNameValueList.pairCount) + if (placeholderCount <= newNameValueList.pairCount) { UDA_LOG(UDA_LOG_DEBUG, "[%d] name: %s, substitution position %d, substitution value %s\n", placeholderCount, nameValueList->nameValue[i].name, tpassIndex[placeholderCount - 1], newNameValueList.nameValue[tpassIndex[placeholderCount - 1]].value); + } } } - if (placeholderCount == 0) - break; // There are no placeholders to process + if (placeholderCount == 0) { + break; // There are no placeholders to process + } UDA_LOG(UDA_LOG_DEBUG, "Name Value Pair Count = %d\n", nameValueList->pairCount); UDA_LOG(UDA_LOG_DEBUG, "Placeholder Count = %d\n", placeholderCount); @@ -130,24 +141,28 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) break; } - if (nameValueList->nameValue[placeholderIndex[i]].value != nullptr) + if (nameValueList->nameValue[placeholderIndex[i]].value != nullptr) { free(nameValueList->nameValue[placeholderIndex[i]].value); + } nameValueList->nameValue[placeholderIndex[i]].value = newNameValueList.nameValue[tpassIndex[i]].value; newNameValueList.nameValue[tpassIndex[i]].value = nullptr; UDA_LOG(UDA_LOG_DEBUG, "Placeholder: [%d][%d] %s, Substitution Value [%d] %s\n", i, placeholderIndex[i], - nameValueList->nameValue[placeholderIndex[i]].name, - tpassIndex[i], nameValueList->nameValue[placeholderIndex[i]].value); + nameValueList->nameValue[placeholderIndex[i]].name, tpassIndex[i], + nameValueList->nameValue[placeholderIndex[i]].value); } // Remove all used NV pairs used in placeholder substitution for (int i = 0; i < placeholderCount; i++) { - if (newNameValueList.nameValue[tpassIndex[i]].pair != nullptr) + if (newNameValueList.nameValue[tpassIndex[i]].pair != nullptr) { free(newNameValueList.nameValue[tpassIndex[i]].pair); - if (newNameValueList.nameValue[tpassIndex[i]].name != nullptr) + } + if (newNameValueList.nameValue[tpassIndex[i]].name != nullptr) { free(newNameValueList.nameValue[tpassIndex[i]].name); - if (newNameValueList.nameValue[tpassIndex[i]].value != nullptr) + } + if (newNameValueList.nameValue[tpassIndex[i]].value != nullptr) { free(newNameValueList.nameValue[tpassIndex[i]].value); + } newNameValueList.nameValue[tpassIndex[i]].pair = nullptr; newNameValueList.nameValue[tpassIndex[i]].name = nullptr; newNameValueList.nameValue[tpassIndex[i]].value = nullptr; @@ -166,17 +181,18 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) // Add unused new name value pairs and keywords if (nameValueList->pairCount + newNameValueList.pairCount > nameValueList->listSize) { - nameValueList->nameValue = (NAMEVALUE*)realloc((void*)nameValueList->nameValue, - (nameValueList->listSize + newNameValueList.pairCount) * - sizeof(NAMEVALUE)); + nameValueList->nameValue = + (NAMEVALUE*)realloc((void*)nameValueList->nameValue, + (nameValueList->listSize + newNameValueList.pairCount) * sizeof(NAMEVALUE)); nameValueList->listSize = nameValueList->listSize + newNameValueList.pairCount; } for (int i = 0; i < newNameValueList.pairCount; i++) { if (newNameValueList.nameValue[i].name != nullptr) { nameValueList->nameValue[nameValueList->pairCount].pair = newNameValueList.nameValue[i].pair; - if (nameValueList->nameValue[nameValueList->pairCount].pair == nullptr) + if (nameValueList->nameValue[nameValueList->pairCount].pair == nullptr) { nameValueList->nameValue[nameValueList->pairCount].pair = strdup(""); + } nameValueList->nameValue[nameValueList->pairCount].name = newNameValueList.nameValue[i].name; nameValueList->nameValue[nameValueList->pairCount++].value = newNameValueList.nameValue[i].value; UDA_LOG(UDA_LOG_DEBUG, "[%d] Name = %s, Value = %s\n", i, newNameValueList.nameValue[i].name, @@ -196,35 +212,40 @@ int name_value_substitution(NAMEVALUELIST* nameValueList, char* tpass) return 0; } - // Substitute named placeholders within value strings -// patterns with name values: string="UDA::getdata(variable='/a/b/c', shot=$shot, tstart=$tstart, tend=$tend)" substitution for named string elements: $shot, $tstart, $tend +// patterns with name values: string="UDA::getdata(variable='/a/b/c', shot=$shot, tstart=$tstart, tend=$tend)" +// substitution for named string elements: $shot, $tstart, $tend void embedded_value_substitution(NAMEVALUELIST* nameValueList) { int m; NAMEVALUELIST newNameValueList; - if (nameValueList->pairCount == 0) return; + if (nameValueList->pairCount == 0) { + return; + } UDA_LOG(UDA_LOG_DEBUG, "embeddedValueSubstitution\n"); - for (int i = 0; i < nameValueList->pairCount; i++) + for (int i = 0; i < nameValueList->pairCount; i++) { UDA_LOG(UDA_LOG_DEBUG, "Pair[%d] = %s, Name = %s, value = %s\n", i, nameValueList->nameValue[i].pair, nameValueList->nameValue[i].name, nameValueList->nameValue[i].value); + } - //Search all NV pairs for values with placeholders + // Search all NV pairs for values with placeholders for (int i = 0; i < nameValueList->pairCount; i++) { - char* p = strchr(nameValueList->nameValue[i].value, '$'); // Is there a placeholder? - if (!p) continue; + char* p = strchr(nameValueList->nameValue[i].value, '$'); // Is there a placeholder? + if (!p) { + continue; + } initNameValueList(&newNameValueList); UDA_LOG(UDA_LOG_DEBUG, "Extracting Name Value Pairs from [%d]: %s\n", i, nameValueList->nameValue[i].value); - unsigned short strip = 1; // Remove enclosing quotes from name value pairs + unsigned short strip = 1; // Remove enclosing quotes from name value pairs char* work = strdup(nameValueList->nameValue[i].value); UDA_LOG(UDA_LOG_DEBUG, "[%d] work = %s\n", i, work); @@ -232,12 +253,15 @@ void embedded_value_substitution(NAMEVALUELIST* nameValueList) int rc = name_value_pairs(work, &newNameValueList, strip); free(work); - if (rc == -1) continue; + if (rc == -1) { + continue; + } UDA_LOG(UDA_LOG_DEBUG, "Embedded Pair Count = %d\n", newNameValueList.pairCount); - for (int j = 0; j < newNameValueList.pairCount; j++) + for (int j = 0; j < newNameValueList.pairCount; j++) { UDA_LOG(UDA_LOG_DEBUG, "Pair[%d] %s, Name = %s, value = %s\n", j, newNameValueList.nameValue[j].pair, newNameValueList.nameValue[j].name, newNameValueList.nameValue[j].value); + } for (int j = 0; j < newNameValueList.pairCount; j++) { @@ -251,9 +275,9 @@ void embedded_value_substitution(NAMEVALUELIST* nameValueList) // Match by name (case sensitive) only if (!strcmp(&newNameValueList.nameValue[j].value[1], nameValueList->nameValue[k].name)) { - UDA_LOG(UDA_LOG_DEBUG, "Substitution: embedded[%d] %s=%s with [%d] %s=%s\n", - j, newNameValueList.nameValue[j].name, newNameValueList.nameValue[j].value, - k, nameValueList->nameValue[k].name, nameValueList->nameValue[k].value); + UDA_LOG(UDA_LOG_DEBUG, "Substitution: embedded[%d] %s=%s with [%d] %s=%s\n", j, + newNameValueList.nameValue[j].name, newNameValueList.nameValue[j].value, k, + nameValueList->nameValue[k].name, nameValueList->nameValue[k].value); // Substitute into original string and replace original @@ -262,21 +286,23 @@ void embedded_value_substitution(NAMEVALUELIST* nameValueList) UDA_LOG(UDA_LOG_DEBUG, "Original: %s\n", original); char* p = strstr(original, newNameValueList.nameValue[j].value); - int lstr = strlen(newNameValueList.nameValue[j].value); // Target this + int lstr = strlen(newNameValueList.nameValue[j].value); // Target this int ok = 1; UDA_LOG(UDA_LOG_DEBUG, "targeting %s [%d] from %s to %s\n", p, lstr, newNameValueList.nameValue[j].value, nameValueList->nameValue[k].value); - for (m = 0; m < lstr; m++) - ok = ok && p[m] == newNameValueList.nameValue[j].value[m]; // Test the name is correct + for (m = 0; m < lstr; m++) { + ok = ok && p[m] == newNameValueList.nameValue[j].value[m]; // Test the name is correct + } if (ok) { UDA_LOG(UDA_LOG_DEBUG, "Substituting %s with %s\n", newNameValueList.nameValue[j].value, nameValueList->nameValue[k].value); p[0] = '\0'; - std::string replace = fmt::format("{}{}{}", original, nameValueList->nameValue[k].value, &p[lstr]); + std::string replace = + fmt::format("{}{}{}", original, nameValueList->nameValue[k].value, &p[lstr]); UDA_LOG(UDA_LOG_DEBUG, "original %s\n", original); UDA_LOG(UDA_LOG_DEBUG, "value %s\n", nameValueList->nameValue[k].value); @@ -288,7 +314,6 @@ void embedded_value_substitution(NAMEVALUELIST* nameValueList) nameValueList->nameValue[i].value = strdup(replace.c_str()); break; - } free(original); } @@ -297,5 +322,4 @@ void embedded_value_substitution(NAMEVALUELIST* nameValueList) } } freeNameValueList(&newNameValueList); -} - +} diff --git a/source/clientserver/parseOperation.cpp b/source/clientserver/parseOperation.cpp old mode 100755 new mode 100644 index c80f6b66..38704e5f --- a/source/clientserver/parseOperation.cpp +++ b/source/clientserver/parseOperation.cpp @@ -1,11 +1,11 @@ #include "parseOperation.h" -#include -#include #include +#include +#include -#include "stringUtils.h" #include "errorLog.h" +#include "stringUtils.h" int parseOperation(SUBSET* sub) { @@ -24,8 +24,8 @@ int parseOperation(SUBSET* sub) std::string operation = sub->operation[i]; - boost::trim_left_if(operation, [](char c){ return c == '['; }); - boost::trim_right_if(operation, [](char c){ return c == ']'; }); + boost::trim_left_if(operation, [](char c) { return c == '['; }); + boost::trim_right_if(operation, [](char c) { return c == ']'; }); if (boost::starts_with(operation, "[")) { operation = operation.substr(1); @@ -46,9 +46,9 @@ int parseOperation(SUBSET* sub) } sub->isindex[i] = true; - sub->ubindex[i] = { .init = false, .value = 0 }; - sub->lbindex[i] = { .init = false, .value = 0 }; - sub->stride[i] = { .init = false, .value = 0 }; + sub->ubindex[i] = {.init = false, .value = 0}; + sub->lbindex[i] = {.init = false, .value = 0}; + sub->stride[i] = {.init = false, .value = 0}; strcpy(sub->operation[i], ":"); if (!tokens[0].empty() && tokens[0] != "#" && tokens[0] != "*") { @@ -57,7 +57,7 @@ int parseOperation(SUBSET* sub) if (n != tokens[0].size()) { UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Invalid Lower Index Bound"); } - sub->lbindex[i] = { .init = true, .value = num }; + sub->lbindex[i] = {.init = true, .value = num}; } if (!tokens[1].empty() && tokens[1] != "#" && tokens[1] != "*") { @@ -66,7 +66,7 @@ int parseOperation(SUBSET* sub) if (n != tokens[1].size()) { UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Invalid Upper Index Bound"); } - sub->ubindex[i] = { .init = true, .value = num }; + sub->ubindex[i] = {.init = true, .value = num}; } if (tokens.size() == 3 && !tokens[2].empty()) { @@ -75,20 +75,20 @@ int parseOperation(SUBSET* sub) if (n != tokens[2].size()) { UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Invalid Stride"); } - sub->stride[i] = { .init = true, .value = num }; + sub->stride[i] = {.init = true, .value = num}; } } else if (operation == "*") { // Ignore this Dimension sub->isindex[i] = true; - sub->ubindex[i] = { .init = false, .value = 0 }; - sub->lbindex[i] = { .init = true, .value = 0 }; - sub->stride[i] = { .init = false, .value = 0 }; + sub->ubindex[i] = {.init = false, .value = 0}; + sub->lbindex[i] = {.init = true, .value = 0}; + sub->stride[i] = {.init = false, .value = 0}; } else if (operation == "#") { // Last Value in Dimension sub->isindex[i] = true; - sub->ubindex[i] = { .init = false, .value = 0 }; - sub->lbindex[i] = { .init = true, .value = -1 }; - sub->stride[i] = { .init = false, .value = 0 }; + sub->ubindex[i] = {.init = false, .value = 0}; + sub->lbindex[i] = {.init = true, .value = -1}; + sub->stride[i] = {.init = false, .value = 0}; } else { size_t n = 0; long num = std::stol(operation, &n, 10); @@ -98,9 +98,9 @@ int parseOperation(SUBSET* sub) } sub->isindex[i] = true; - sub->ubindex[i] = { .init = true, .value = num + 1 }; - sub->lbindex[i] = { .init = true, .value = num }; - sub->stride[i] = { .init = false, .value = 0 }; + sub->ubindex[i] = {.init = true, .value = num + 1}; + sub->lbindex[i] = {.init = true, .value = num}; + sub->stride[i] = {.init = false, .value = 0}; strcpy(sub->operation[i], ":"); } } diff --git a/source/clientserver/parseOperation.h b/source/clientserver/parseOperation.h old mode 100755 new mode 100644 index 6b0706c0..135a4a03 --- a/source/clientserver/parseOperation.h +++ b/source/clientserver/parseOperation.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_PARSEOPERATION_H #define UDA_CLIENTSERVER_PARSEOPERATION_H -#include "parseXML.h" #include "export.h" +#include "parseXML.h" #ifdef __cplusplus extern "C" { diff --git a/source/clientserver/parseXML.cpp b/source/clientserver/parseXML.cpp old mode 100755 new mode 100644 index ecbb0102..64ef7925 --- a/source/clientserver/parseXML.cpp +++ b/source/clientserver/parseXML.cpp @@ -22,10 +22,10 @@ #include #ifndef NOXMLPARSER -#include "udaTypes.h" -#include -#include -#include +# include "udaTypes.h" +# include +# include +# include static double deScale(char* scale); static void parse_target_value(xmlDocPtr doc, xmlNodePtr cur, const char* target, double* value); @@ -94,8 +94,7 @@ float* parse_float_array(xmlDocPtr doc, xmlNodePtr cur, const char* target, int* return value; } -template -void parse_fixed_length_array(xmlNodePtr cur, const char* target, void* array, int* n) +template void parse_fixed_length_array(xmlNodePtr cur, const char* target, void* array, int* n) { xmlChar* att = nullptr; *n = 0; @@ -112,12 +111,12 @@ void parse_fixed_length_array(xmlNodePtr cur, const char* target, void* array, i if (item != nullptr) { nco++; auto p = (T*)array; - std::stringstream ss{ item }; + std::stringstream ss{item}; ss >> p[nco - 1]; while ((item = strtok(nullptr, delim)) != nullptr && nco <= UDA_MAX_DATA_RANK) { nco++; - ss = std::stringstream{ item }; + ss = std::stringstream{item}; ss >> p[nco - 1]; } } @@ -262,7 +261,8 @@ void parse_fixed_length_array(xmlNodePtr cur, const char* target, void* array, i } } -void parse_fixed_length_str_array(xmlNodePtr cur, const char* target, char array[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING], int* n) +void parse_fixed_length_str_array(xmlNodePtr cur, const char* target, + char array[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING], int* n) { xmlChar* att = nullptr; *n = 0; @@ -300,12 +300,13 @@ void parse_fixed_length_str_array(xmlNodePtr cur, const char* target, char array } } - // Decode Scale Value double deScale(char* scale) { - if (strlen(scale) == 0) return 1.0E0; + if (strlen(scale) == 0) { + return 1.0E0; + } if (STR_EQUALS(scale, "milli")) { return 1.0E-3; } else { @@ -317,7 +318,7 @@ double deScale(char* scale) } } } - return 1.0E0; // Default value + return 1.0E0; // Default value } // Locate and extract Named Parameter (Numerical and String) Values @@ -332,8 +333,12 @@ void parse_target_value(xmlDocPtr doc, xmlNodePtr cur, const char* target, doubl if ((!xmlStrcmp(cur->name, (const xmlChar*)target))) { scale = xmlGetProp(cur, (xmlChar*)"scale"); key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key != nullptr) *value = (double)atof((char*)key); - if (scale != nullptr) *value = *value * deScale((char*)scale); + if (key != nullptr) { + *value = (double)atof((char*)key); + } + if (scale != nullptr) { + *value = *value * deScale((char*)scale); + } xmlFree(key); xmlFree(scale); break; @@ -349,7 +354,9 @@ void parse_target_string(xmlDocPtr doc, xmlNodePtr cur, const char* target, char while (cur != nullptr) { if ((!xmlStrcmp(cur->name, (const xmlChar*)target))) { key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); - if (key != nullptr) strcpy(str, (char*)key); + if (key != nullptr) { + strcpy(str, (char*)key); + } xmlFree(key); break; } @@ -360,10 +367,10 @@ void parse_target_string(xmlDocPtr doc, xmlNodePtr cur, const char* target, char void parse_time_offset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values ACTION* str = actions->action; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -379,31 +386,41 @@ void parse_time_offset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range Start: %d\n", str[n - 1].exp_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range End : %d\n", str[n - 1].exp_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range Start: %d\n", str[n - 1].pass_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range End : %d\n", str[n - 1].pass_range[1]); xmlFree(att); } @@ -417,7 +434,9 @@ void parse_time_offset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) } if ((att = xmlGetProp(cur, (xmlChar*)"method")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].timeoffset.method = (int)atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].timeoffset.method = (int)atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Time Offset Method : %d\n", str[n - 1].timeoffset.method); xmlFree(att); } @@ -439,26 +458,26 @@ void parse_time_offset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) } if ((att = xmlGetProp(cur, (xmlChar*)"scale")) != nullptr) { - if (strlen((char*)att) > 0) + if (strlen((char*)att) > 0) { str[n - 1].timeoffset.offset = deScale((char*)att) * str[n - 1].timeoffset.offset; + } UDA_LOG(UDA_LOG_DEBUG, "Scaled Time Offset : %f\n", str[n - 1].timeoffset.offset); xmlFree(att); } } cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } - void parseCompositeSubset(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values SUBSET* str = comp->subsets; - int n = 0; // Counter + int n = 0; // Counter int n0, n1; // Attributes @@ -475,30 +494,40 @@ void parseCompositeSubset(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"data")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].data_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].data_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset Signal: %s\n", str[n - 1].data_signal); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"reform")) != nullptr) { - if (att[0] == 'Y' || att[0] == 'y') str[n - 1].reform = 1; + if (att[0] == 'Y' || att[0] == 'y') { + str[n - 1].reform = 1; + } xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"member")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].member, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].member, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset member: %s\n", str[n - 1].member); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"function")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].function, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].function, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset function: %s\n", str[n - 1].function); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"order")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].order = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].order = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset order: %d\n", str[n - 1].order); xmlFree(att); } @@ -507,7 +536,7 @@ void parseCompositeSubset(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) parse_fixed_length_str_array(cur, "operation", str[n - 1].operation, &str[n - 1].nbound); for (int i = 0; i < str[n - 1].nbound; i++) { - str[n - 1].dimid[i] = i; // Ordering is as DATA[4][3][2][1][0] + str[n - 1].dimid[i] = i; // Ordering is as DATA[4][3][2][1][0] } parse_fixed_length_array(cur, "bound", (void*)str[n - 1].bound, UDA_TYPE_DOUBLE, &n0); @@ -528,23 +557,19 @@ void parseCompositeSubset(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) } cur = cur->next; } - comp->nsubsets = n; // Number of Subsets - comp->subsets = str; // Array of Subset Actions -} - - -void parseMaps(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) -{ + comp->nsubsets = n; // Number of Subsets + comp->subsets = str; // Array of Subset Actions } +void parseMaps(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) {} void parseDimComposite(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values DIMENSION* str = comp->dimensions; - int n = 0; // Counter + int n = 0; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -559,9 +584,9 @@ void parseDimComposite(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) // Attributes - if ((att = xmlGetProp(cur, (xmlChar*)"to_dim")) != nullptr) { // Target Dimension + if ((att = xmlGetProp(cur, (xmlChar*)"to_dim")) != nullptr) { // Target Dimension if (strlen((char*)att) > 0) { - str[n - 1].dimid = atoi((char*)att); // Duplicate these tags for convenience + str[n - 1].dimid = atoi((char*)att); // Duplicate these tags for convenience str[n - 1].dimcomposite.to_dim = atoi((char*)att); } UDA_LOG(UDA_LOG_DEBUG, "To Dimension : %d\n", str[n - 1].dimid); @@ -569,55 +594,65 @@ void parseDimComposite(xmlDocPtr doc, xmlNodePtr cur, COMPOSITE* comp) } if ((att = xmlGetProp(cur, (xmlChar*)"from_dim")) != - nullptr) { // Swap with this Dimension otherwise swap with Data - if (strlen((char*)att) > 0) str[n - 1].dimcomposite.from_dim = atoi((char*)att); + nullptr) { // Swap with this Dimension otherwise swap with Data + if (strlen((char*)att) > 0) { + str[n - 1].dimcomposite.from_dim = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "From Dimension : %d\n", str[n - 1].dimcomposite.from_dim); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"dim")) != nullptr || (att = xmlGetProp(cur, (xmlChar*)"data")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].dimcomposite.dim_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].dimcomposite.dim_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Signal : %s\n", str[n - 1].dimcomposite.dim_signal); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"error")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].dimcomposite.dim_error, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].dimcomposite.dim_error, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Error Signal : %s\n", str[n - 1].dimcomposite.dim_error); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"aserror")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].dimcomposite.dim_aserror, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].dimcomposite.dim_aserror, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Error Signal : %s\n", str[n - 1].dimcomposite.dim_aserror); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"file")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].dimcomposite.file, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].dimcomposite.file, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Source File: %s\n", str[n - 1].dimcomposite.file); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"format")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].dimcomposite.format, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].dimcomposite.format, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Source File Format: %s\n", str[n - 1].dimcomposite.format); xmlFree(att); } - - } cur = cur->next; } - comp->ndimensions = n; // Number of Tags Found - comp->dimensions = str; // Array of Composite Signal Actions on Dimensions + comp->ndimensions = n; // Number of Tags Found + comp->dimensions = str; // Array of Composite Signal Actions on Dimensions } void parseComposite(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values ACTION* str = actions->action; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -633,72 +668,95 @@ void parseComposite(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range Start: %d\n", str[n - 1].exp_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range End : %d\n", str[n - 1].exp_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range Start: %d\n", str[n - 1].pass_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range End : %d\n", str[n - 1].pass_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"data")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.data_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.data_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Data Signal : %s\n", str[n - 1].composite.data_signal); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"file")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.file, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.file, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Data Source File: %s\n", str[n - 1].composite.file); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"format")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.format, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.format, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Source File Format: %s\n", str[n - 1].composite.format); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"error")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.error_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.error_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Error Signal : %s\n", str[n - 1].composite.error_signal); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"aserror")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.aserror_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.aserror_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Error Signal : %s\n", str[n - 1].composite.aserror_signal); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"mapto")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].composite.aserror_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].composite.aserror_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Map to Signal : %s\n", str[n - 1].composite.map_to_signal); xmlFree(att); } - if ((att = xmlGetProp(cur, (xmlChar*)"order")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].composite.order = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].composite.order = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Time Dimension: %d\n", str[n - 1].composite.order); xmlFree(att); } @@ -711,24 +769,25 @@ void parseComposite(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Consolidate Composite Signal name with Subset Signal Name (the Composite record has precedence) if (str[n - 1].composite.nsubsets > 0 && strlen(str[n - 1].composite.data_signal) == 0) { - if (strlen(str[n - 1].composite.subsets[0].data_signal) > 0) + if (strlen(str[n - 1].composite.subsets[0].data_signal) > 0) { strcpy(str[n - 1].composite.data_signal, str[n - 1].composite.subsets[0].data_signal); + } } } cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } void parseDimErrorModel(xmlDocPtr doc, xmlNodePtr cur, ERRORMODEL* mod) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values float* params; DIMENSION* str = mod->dimensions; - int n = 0; // Counter + int n = 0; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -743,13 +802,17 @@ void parseDimErrorModel(xmlDocPtr doc, xmlNodePtr cur, ERRORMODEL* mod) // Attributes - if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension - if (strlen((char*)att) > 0) str[n - 1].dimid = atoi((char*)att); + if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension + if (strlen((char*)att) > 0) { + str[n - 1].dimid = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension : %d\n", str[n - 1].dimid); xmlFree(att); } - if ((att = xmlGetProp(cur, (xmlChar*)"model")) != nullptr) { // Error Model - if (strlen((char*)att) > 0) str[n - 1].dimerrormodel.model = atoi((char*)att); + if ((att = xmlGetProp(cur, (xmlChar*)"model")) != nullptr) { // Error Model + if (strlen((char*)att) > 0) { + str[n - 1].dimerrormodel.model = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Model : %d\n", str[n - 1].dimerrormodel.model); xmlFree(att); } @@ -758,29 +821,28 @@ void parseDimErrorModel(xmlDocPtr doc, xmlNodePtr cur, ERRORMODEL* mod) params = parse_float_array(doc, cur, "params", &str[n - 1].dimerrormodel.param_n); if (params != nullptr) { - if (str[n - 1].dimerrormodel.param_n > MAXERRPARAMS) str[n - 1].dimerrormodel.param_n = MAXERRPARAMS; + if (str[n - 1].dimerrormodel.param_n > MAXERRPARAMS) { + str[n - 1].dimerrormodel.param_n = MAXERRPARAMS; + } for (int i = 0; i < str[n - 1].dimerrormodel.param_n; i++) { str[n - 1].dimerrormodel.params[i] = params[i]; } free(params); } - - } cur = cur->next; } - mod->ndimensions = n; // Number of Tags Found - mod->dimensions = str; // Array of Error Model Actions on Dimensions + mod->ndimensions = n; // Number of Tags Found + mod->dimensions = str; // Array of Error Model Actions on Dimensions } - void parse_error_model(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values float* params; ACTION* str = actions->action; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -796,37 +858,49 @@ void parse_error_model(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range Start: %d\n", str[n - 1].exp_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range End : %d\n", str[n - 1].exp_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range Start: %d\n", str[n - 1].pass_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range End : %d\n", str[n - 1].pass_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"model")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].errormodel.model = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].errormodel.model = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Error Distribution Model: %d\n", str[n - 1].errormodel.model); xmlFree(att); } @@ -835,7 +909,9 @@ void parse_error_model(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) params = parse_float_array(doc, cur, "params", &str[n - 1].errormodel.param_n); if (params != nullptr) { - if (str[n - 1].errormodel.param_n > MAXERRPARAMS) str[n - 1].errormodel.param_n = MAXERRPARAMS; + if (str[n - 1].errormodel.param_n > MAXERRPARAMS) { + str[n - 1].errormodel.param_n = MAXERRPARAMS; + } for (int i = 0; i < str[n - 1].errormodel.param_n; i++) { str[n - 1].errormodel.params[i] = params[i]; } @@ -843,20 +919,19 @@ void parse_error_model(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) } parseDimErrorModel(doc, cur, &str[n - 1].errormodel); - } cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } void parseDimDocumentation(xmlDocPtr doc, xmlNodePtr cur, DOCUMENTATION* document) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values DIMENSION* str = document->dimensions; - int n = 0; // Counter + int n = 0; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -871,8 +946,10 @@ void parseDimDocumentation(xmlDocPtr doc, xmlNodePtr cur, DOCUMENTATION* documen // Attributes - if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension - if (strlen((char*)att) > 0) str[n - 1].dimid = atoi((char*)att); + if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension + if (strlen((char*)att) > 0) { + str[n - 1].dimid = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "To Dimension : %d\n", str[n - 1].dimid); xmlFree(att); } @@ -881,20 +958,19 @@ void parseDimDocumentation(xmlDocPtr doc, xmlNodePtr cur, DOCUMENTATION* documen parse_target_string(doc, cur, "label", str[n - 1].dimdocumentation.label); parse_target_string(doc, cur, "units", str[n - 1].dimdocumentation.units); - } cur = cur->next; } - document->ndimensions = n; // Number of Tags Found - document->dimensions = str; // Array of Composite Signal Actions on Dimensions + document->ndimensions = n; // Number of Tags Found + document->dimensions = str; // Array of Composite Signal Actions on Dimensions } void parse_documentation(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values ACTION* str = actions->action; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -910,31 +986,41 @@ void parse_documentation(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range Start: %d\n", str[n - 1].exp_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range End : %d\n", str[n - 1].exp_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range Start: %d\n", str[n - 1].pass_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range End : %d\n", str[n - 1].pass_range[1]); xmlFree(att); } @@ -946,20 +1032,19 @@ void parse_documentation(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) parse_target_string(doc, cur, "units", str[n - 1].documentation.units); parseDimDocumentation(doc, cur, &str[n - 1].documentation); - } cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } void parseDimCalibration(xmlDocPtr doc, xmlNodePtr cur, CALIBRATION* cal) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values DIMENSION* str = cal->dimensions; - int n = 0; // Counter + int n = 0; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -974,14 +1059,18 @@ void parseDimCalibration(xmlDocPtr doc, xmlNodePtr cur, CALIBRATION* cal) // Attributes - if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension - if (strlen((char*)att) > 0) str[n - 1].dimid = atoi((char*)att); + if ((att = xmlGetProp(cur, (xmlChar*)"dimid")) != nullptr) { // Target Dimension + if (strlen((char*)att) > 0) { + str[n - 1].dimid = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "To Dimension : %d\n", str[n - 1].dimid); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"invert")) != nullptr) { - if (att[0] == 'y' || att[0] == 'Y') str[n - 1].dimcalibration.invert = 1; + if (att[0] == 'y' || att[0] == 'Y') { + str[n - 1].dimcalibration.invert = 1; + } UDA_LOG(UDA_LOG_DEBUG, "Calibration Invert: %d\n", str[n - 1].dimcalibration.invert); xmlFree(att); } @@ -998,16 +1087,16 @@ void parseDimCalibration(xmlDocPtr doc, xmlNodePtr cur, CALIBRATION* cal) } cur = cur->next; } - cal->ndimensions = n; // Number of Tags Found - cal->dimensions = str; // Array of Composite Signal Actions on Dimensions + cal->ndimensions = n; // Number of Tags Found + cal->dimensions = str; // Array of Composite Signal Actions on Dimensions } void parse_calibration(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values ACTION* str = actions->action; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter cur = cur->xmlChildrenNode; while (cur != nullptr) { @@ -1023,43 +1112,57 @@ void parse_calibration(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range Start: %d\n", str[n - 1].exp_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"exp_number_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].exp_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].exp_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Exp Number Range End : %d\n", str[n - 1].exp_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_start")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[0] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[0] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range Start: %d\n", str[n - 1].pass_range[0]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"pass_end")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].pass_range[1] = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].pass_range[1] = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Pass Number Range End : %d\n", str[n - 1].pass_range[1]); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"target")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(str[n - 1].calibration.target, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(str[n - 1].calibration.target, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Calibration Target: %s\n", str[n - 1].calibration.target); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"invert")) != nullptr) { - if (att[0] == 'y' || att[0] == 'Y') str[n - 1].calibration.invert = 1; + if (att[0] == 'y' || att[0] == 'Y') { + str[n - 1].calibration.invert = 1; + } UDA_LOG(UDA_LOG_DEBUG, "Calibration Invert: %d\n", str[n - 1].calibration.invert); xmlFree(att); } @@ -1075,22 +1178,20 @@ void parse_calibration(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) UDA_LOG(UDA_LOG_DEBUG, "Data Calibration Offset : %f\n", str[n - 1].calibration.offset); parseDimCalibration(doc, cur, &str[n - 1].calibration); - } cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } - void parse_subset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) { - xmlChar* att; // General Input of tag attribute values + xmlChar* att; // General Input of tag attribute values ACTION* str = actions->action; SUBSET* sub = nullptr; - int n = actions->nactions; // Counter + int n = actions->nactions; // Counter int n0, n1; cur = cur->xmlChildrenNode; @@ -1108,13 +1209,17 @@ void parse_subset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"id")) != nullptr) { - if (strlen((char*)att) > 0) str[n - 1].actionId = atoi((char*)att); + if (strlen((char*)att) > 0) { + str[n - 1].actionId = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Action ID: %d\n", str[n - 1].actionId); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"data")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(sub->data_signal, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(sub->data_signal, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Data Signal : %s\n", sub->data_signal); xmlFree(att); } @@ -1124,24 +1229,32 @@ void parse_subset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) // Attributes if ((att = xmlGetProp(cur, (xmlChar*)"reform")) != nullptr) { - if (att[0] == 'Y' || att[0] == 'y') sub->reform = 1; + if (att[0] == 'Y' || att[0] == 'y') { + sub->reform = 1; + } xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"member")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(sub->member, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(sub->member, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset Member: %s\n", sub->member); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"function")) != nullptr) { - if (strlen((char*)att) > 0) strcpy(sub->function, (char*)att); + if (strlen((char*)att) > 0) { + strcpy(sub->function, (char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset function: %s\n", sub->function); xmlFree(att); } if ((att = xmlGetProp(cur, (xmlChar*)"order")) != nullptr) { - if (strlen((char*)att) > 0) sub->order = atoi((char*)att); + if (strlen((char*)att) > 0) { + sub->order = atoi((char*)att); + } UDA_LOG(UDA_LOG_DEBUG, "Subset order: %d\n", sub->order); xmlFree(att); } @@ -1150,7 +1263,7 @@ void parse_subset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) parse_fixed_length_str_array(cur, "operation", &sub->operation[0], &sub->nbound); for (int i = 0; i < sub->nbound; i++) { - sub->dimid[i] = i; // Ordering is as DATA[4][3][2][1][0] + sub->dimid[i] = i; // Ordering is as DATA[4][3][2][1][0] } parse_fixed_length_array(cur, "bound", (void*)sub->bound, UDA_TYPE_DOUBLE, &n0); @@ -1172,8 +1285,8 @@ void parse_subset(xmlDocPtr doc, xmlNodePtr cur, ACTIONS* actions) cur = cur->next; } - actions->nactions = n; // Number of Tags Found - actions->action = str; // Array of Actions bounded by a Ranges + actions->nactions = n; // Number of Tags Found + actions->action = str; // Array of Actions bounded by a Ranges } int parseDoc(char* docname, ACTIONS* actions) @@ -1181,12 +1294,12 @@ int parseDoc(char* docname, ACTIONS* actions) xmlDocPtr doc; xmlNodePtr cur; -#ifdef TIMETEST +# ifdef TIMETEST struct timeval tv_start; struct timeval tv_end; - float testtime ; + float testtime; int rc = gettimeofday(&tv_start, nullptr); -#endif +# endif xmlInitParser(); @@ -1204,7 +1317,7 @@ int parseDoc(char* docname, ACTIONS* actions) return 1; } - if (xmlStrcmp(cur->name, (const xmlChar*)"action")) { //If No Action Tag then Nothing to be done! + if (xmlStrcmp(cur->name, (const xmlChar*)"action")) { // If No Action Tag then Nothing to be done! xmlFreeDoc(doc); xmlCleanupParser(); return 1; @@ -1215,13 +1328,13 @@ int parseDoc(char* docname, ACTIONS* actions) if ((!xmlStrcmp(cur->name, (const xmlChar*)"signal"))) { - parseComposite(doc, cur, actions); // Composite can have SUBSET as a child + parseComposite(doc, cur, actions); // Composite can have SUBSET as a child parse_documentation(doc, cur, actions); parse_calibration(doc, cur, actions); parse_time_offset(doc, cur, actions); parse_error_model(doc, cur, actions); - parse_subset(doc, cur, actions); // Single Subset + parse_subset(doc, cur, actions); // Single Subset } cur = cur->next; } @@ -1229,10 +1342,10 @@ int parseDoc(char* docname, ACTIONS* actions) xmlFreeDoc(doc); xmlCleanupParser(); -#ifdef TIMETEST +# ifdef TIMETEST rc = gettimeofday(&tv_end, nullptr); - testtime = (float)(tv_end.tv_sec-tv_start.tv_sec)*1.0E6 + (float)(tv_end.tv_usec - tv_start.tv_usec) ; -#endif + testtime = (float)(tv_end.tv_sec - tv_start.tv_sec) * 1.0E6 + (float)(tv_end.tv_usec - tv_start.tv_usec); +# endif return 0; } @@ -1272,14 +1385,14 @@ void print_dimensions(int ndim, DIMENSION* dims) case UDA_DIM_ERROR_MODEL_TYPE: UDA_LOG(UDA_LOG_DEBUG, "Error Model Id : %d\n", dims[i].dimerrormodel.model); UDA_LOG(UDA_LOG_DEBUG, "Number of Model Parameters: %d\n", dims[i].dimerrormodel.param_n); - for (int j = 0; j < dims[i].dimerrormodel.param_n; j++) + for (int j = 0; j < dims[i].dimerrormodel.param_n; j++) { UDA_LOG(UDA_LOG_DEBUG, "Parameters[%d] = %.12f\n", j, dims[i].dimerrormodel.params[j]); + } break; default: break; } - } } @@ -1329,8 +1442,9 @@ void printAction(ACTION action) UDA_LOG(UDA_LOG_DEBUG, "ERRORMODEL xml\n"); UDA_LOG(UDA_LOG_DEBUG, "Error Model Id : %d\n", action.errormodel.model); UDA_LOG(UDA_LOG_DEBUG, "Number of Model Parameters: %d\n", action.errormodel.param_n); - for (int i = 0; i < action.errormodel.param_n; i++) + for (int i = 0; i < action.errormodel.param_n; i++) { UDA_LOG(UDA_LOG_DEBUG, "Parameters[%d] = %.12f\n", i, action.errormodel.params[i]); + } print_dimensions(action.errormodel.ndimensions, action.errormodel.dimensions); break; @@ -1371,7 +1485,6 @@ void printAction(ACTION action) default: break; } - } void printActions(ACTIONS actions) @@ -1388,33 +1501,33 @@ void printActions(ACTIONS actions) void init_dim_calibration(DIMCALIBRATION* act) { - act->factor = (double)1.0E0; // Data Calibration Correction/Scaling factor - act->offset = (double)0.0E0; // Data Calibration Correction/Scaling offset - act->invert = 0; // Don't Invert the data + act->factor = (double)1.0E0; // Data Calibration Correction/Scaling factor + act->offset = (double)0.0E0; // Data Calibration Correction/Scaling offset + act->invert = 0; // Don't Invert the data act->units[0] = '\0'; } void init_dim_composite(DIMCOMPOSITE* act) { - act->to_dim = -1; // Swap to Dimension ID - act->from_dim = -1; // Swap from Dimension ID - act->file[0] = '\0'; // Data Source File (with Full Path) - act->format[0] = '\0'; // Data Source File's Format - act->dim_signal[0] = '\0'; // Source Signal - act->dim_error[0] = '\0'; // Error Source Signal - act->dim_aserror[0] = '\0'; // Asymmetric Error Source Signal + act->to_dim = -1; // Swap to Dimension ID + act->from_dim = -1; // Swap from Dimension ID + act->file[0] = '\0'; // Data Source File (with Full Path) + act->format[0] = '\0'; // Data Source File's Format + act->dim_signal[0] = '\0'; // Source Signal + act->dim_error[0] = '\0'; // Error Source Signal + act->dim_aserror[0] = '\0'; // Asymmetric Error Source Signal } void init_dim_documentation(DIMDOCUMENTATION* act) { act->label[0] = '\0'; - act->units[0] = '\0'; // Lower in priority than Calibration Units + act->units[0] = '\0'; // Lower in priority than Calibration Units } void init_dim_error_model(DIMERRORMODEL* act) { - act->model = ERROR_MODEL_UNKNOWN; // No Error Model - act->param_n = 0; // No. Model parameters + act->model = ERROR_MODEL_UNKNOWN; // No Error Model + act->param_n = 0; // No. Model parameters for (int i = 0; i < MAXERRPARAMS; i++) { act->params[i] = 0.0; } @@ -1422,24 +1535,24 @@ void init_dim_error_model(DIMERRORMODEL* act) void init_dimension(DIMENSION* act) { - act->dimid = -1; // Dimension Id - act->dimType = 0; // Structure Type + act->dimid = -1; // Dimension Id + act->dimType = 0; // Structure Type } void init_time_offset(TIMEOFFSET* act) { - act->method = 0; // Correction Method: Standard offset correction only - act->offset = (double)0.0E0; // Time Dimension offset correction or start time - act->interval = (double)0.0E0; // Time Dimension Interval correction + act->method = 0; // Correction Method: Standard offset correction only + act->offset = (double)0.0E0; // Time Dimension offset correction or start time + act->interval = (double)0.0E0; // Time Dimension Interval correction } void init_calibration(CALIBRATION* act) { - act->factor = (double)1.0E0; // Data Calibration Correction/Scaling factor - act->offset = (double)0.0E0; // Data Calibration Correction/Scaling offset + act->factor = (double)1.0E0; // Data Calibration Correction/Scaling factor + act->offset = (double)0.0E0; // Data Calibration Correction/Scaling offset act->units[0] = '\0'; - act->target[0] = '\0'; // Which data Component to apply calibration? (all, data, error, aserror) - act->invert = 0; // No Inversion + act->target[0] = '\0'; // Which data Component to apply calibration? (all, data, error, aserror) + act->invert = 0; // No Inversion act->ndimensions = 0; act->dimensions = nullptr; } @@ -1447,7 +1560,7 @@ void init_calibration(CALIBRATION* act) void init_documentation(DOCUMENTATION* act) { act->label[0] = '\0'; - act->units[0] = '\0'; // Lower in priority than Calibration Units + act->units[0] = '\0'; // Lower in priority than Calibration Units act->description[0] = '\0'; act->ndimensions = 0; act->dimensions = nullptr; @@ -1455,13 +1568,13 @@ void init_documentation(DOCUMENTATION* act) void init_composite(COMPOSITE* act) { - act->data_signal[0] = '\0'; // Derived Data using this Data Source - act->error_signal[0] = '\0'; // Use Errors from this Source - act->aserror_signal[0] = '\0'; // Use Asymmetric Errors from this Source - act->map_to_signal[0] = '\0'; // Straight swap of data: map to this signal - act->file[0] = '\0'; // Data Source File (with Full Path) - act->format[0] = '\0'; // Data Source File's Format - act->order = -1; // Identify the Time Dimension + act->data_signal[0] = '\0'; // Derived Data using this Data Source + act->error_signal[0] = '\0'; // Use Errors from this Source + act->aserror_signal[0] = '\0'; // Use Asymmetric Errors from this Source + act->map_to_signal[0] = '\0'; // Straight swap of data: map to this signal + act->file[0] = '\0'; // Data Source File (with Full Path) + act->format[0] = '\0'; // Data Source File's Format + act->order = -1; // Identify the Time Dimension act->ndimensions = 0; act->nsubsets = 0; act->nmaps = 0; @@ -1480,8 +1593,8 @@ void initServerside(SERVERSIDE* act) void init_error_model(ERRORMODEL* act) { - act->model = ERROR_MODEL_UNKNOWN; // No Error Model - act->param_n = 0; // No. Model parameters + act->model = ERROR_MODEL_UNKNOWN; // No Error Model + act->param_n = 0; // No. Model parameters for (int i = 0; i < MAXERRPARAMS; i++) { act->params[i] = 0.0; } @@ -1492,32 +1605,32 @@ void init_error_model(ERRORMODEL* act) void initSubset(SUBSET* act) { for (int i = 0; i < UDA_MAX_DATA_RANK; i++) { - act->bound[i] = 0.0; // Subsetting Float Bounds - act->ubindex[i] = { .init = false, .value = 0 }; // Subsetting Integer Bounds (Upper Index) - act->lbindex[i] = { .init = false, .value = 0 }; // Lower Index - act->stride[i] = { .init = false, .value = 0 }; // Stride - act->isindex[i] = false; // Flag the Bound is an Integer Type - act->dimid[i] = -1; // Dimension IDs - act->operation[i][0] = '\0'; // Subsetting Operations + act->bound[i] = 0.0; // Subsetting Float Bounds + act->ubindex[i] = {.init = false, .value = 0}; // Subsetting Integer Bounds (Upper Index) + act->lbindex[i] = {.init = false, .value = 0}; // Lower Index + act->stride[i] = {.init = false, .value = 0}; // Stride + act->isindex[i] = false; // Flag the Bound is an Integer Type + act->dimid[i] = -1; // Dimension IDs + act->operation[i][0] = '\0'; // Subsetting Operations } - act->data_signal[0] = '\0'; // Data to Read - act->member[0] = '\0'; // Structure Member to target - act->function[0] = '\0'; // Name of simple function to apply - act->nbound = 0; // The number of Subsetting Operations - act->reform = 0; // reduce the Rank if a subsetted dimension has length 1 - act->order = -1; // Explicitly set the order of the time dimension if >= 0 + act->data_signal[0] = '\0'; // Data to Read + act->member[0] = '\0'; // Structure Member to target + act->function[0] = '\0'; // Name of simple function to apply + act->nbound = 0; // The number of Subsetting Operations + act->reform = 0; // reduce the Rank if a subsetted dimension has length 1 + act->order = -1; // Explicitly set the order of the time dimension if >= 0 } // Initialise an Action Structure void initAction(ACTION* act) { - act->actionType = 0; // Action Range Type - act->inRange = 0; // Is this Action Record Applicable to the Current data Request? - act->actionId = 0; // Action XML Tag Id - act->exp_range[0] = 0; // Applicable over this Exp. Number Range + act->actionType = 0; // Action Range Type + act->inRange = 0; // Is this Action Record Applicable to the Current data Request? + act->actionId = 0; // Action XML Tag Id + act->exp_range[0] = 0; // Applicable over this Exp. Number Range act->exp_range[1] = 0; - act->pass_range[0] = -1; // Applicable over this Pass Number Range + act->pass_range[0] = -1; // Applicable over this Pass Number Range act->pass_range[1] = -1; } @@ -1525,8 +1638,8 @@ void initAction(ACTION* act) void initActions(ACTIONS* act) { - act->nactions = 0; // Number of Action blocks - act->action = nullptr; // Array of Action blocks + act->nactions = 0; // Number of Action blocks + act->action = nullptr; // Array of Action blocks } void freeActions(ACTIONS* actions) @@ -1537,7 +1650,9 @@ void freeActions(ACTIONS* actions) UDA_LOG(UDA_LOG_DEBUG, "freeActions: Enter\n"); UDA_LOG(UDA_LOG_DEBUG, "freeDataBlock: Number of Actions = %d \n", actions->nactions); - if (actions->nactions == 0) return; + if (actions->nactions == 0) { + return; + } for (int i = 0; i < actions->nactions; i++) { UDA_LOG(UDA_LOG_DEBUG, "freeDataBlock: freeing action Type = %d \n", actions->action[i].actionType); @@ -1551,12 +1666,16 @@ void freeActions(ACTIONS* actions) actions->action[i].composite.ndimensions = 0; } if (actions->action[i].composite.nsubsets > 0) { - if ((cptr = (void*)actions->action[i].composite.subsets) != nullptr) free(cptr); + if ((cptr = (void*)actions->action[i].composite.subsets) != nullptr) { + free(cptr); + } actions->action[i].composite.subsets = nullptr; actions->action[i].composite.nsubsets = 0; } if (actions->action[i].composite.nmaps > 0) { - if ((cptr = (void*)actions->action[i].composite.maps) != nullptr) free(cptr); + if ((cptr = (void*)actions->action[i].composite.maps) != nullptr) { + free(cptr); + } actions->action[i].composite.maps = nullptr; actions->action[i].composite.nmaps = 0; } @@ -1565,12 +1684,13 @@ void freeActions(ACTIONS* actions) case UDA_ERROR_MODEL_TYPE: actions->action[i].errormodel.param_n = 0; - for (int j = 0; j < actions->action[i].errormodel.ndimensions; j++) + for (int j = 0; j < actions->action[i].errormodel.ndimensions; j++) { if ((cptr = (void*)actions->action[i].errormodel.dimensions) != nullptr) { free(cptr); actions->action[i].errormodel.dimensions = nullptr; actions->action[i].errormodel.ndimensions = 0; } + } break; @@ -1592,12 +1712,16 @@ void freeActions(ACTIONS* actions) case UDA_SERVER_SIDE_TYPE: if (actions->action[i].serverside.nsubsets > 0) { - if ((cptr = (void*)actions->action[i].serverside.subsets) != nullptr) free(cptr); + if ((cptr = (void*)actions->action[i].serverside.subsets) != nullptr) { + free(cptr); + } actions->action[i].serverside.subsets = nullptr; actions->action[i].serverside.nsubsets = 0; } if (actions->action[i].serverside.nmaps > 0) { - if ((cptr = (void*)actions->action[i].serverside.maps) != nullptr) free(cptr); + if ((cptr = (void*)actions->action[i].serverside.maps) != nullptr) { + free(cptr); + } actions->action[i].serverside.maps = nullptr; actions->action[i].serverside.nmaps = 0; } @@ -1608,7 +1732,9 @@ void freeActions(ACTIONS* actions) } } - if ((cptr = (void*)actions->action) != nullptr) free(cptr); + if ((cptr = (void*)actions->action) != nullptr) { + free(cptr); + } actions->nactions = 0; actions->action = nullptr; @@ -1623,4 +1749,3 @@ void copyActions(ACTIONS* actions_out, ACTIONS* actions_in) actions_in->action = nullptr; actions_in->nactions = 0; } - diff --git a/source/clientserver/parseXML.h b/source/clientserver/parseXML.h old mode 100755 new mode 100644 index d2b5b1f6..07feef84 --- a/source/clientserver/parseXML.h +++ b/source/clientserver/parseXML.h @@ -2,14 +2,14 @@ #define UDA_CLIENTSERVER_PARSEXML_H #ifndef NOXMLPARSER -#include -#include +# include +# include #endif #include -#include "udaDefines.h" #include "export.h" +#include "udaDefines.h" #include "udaStructs.h" #ifdef __cplusplus @@ -17,11 +17,11 @@ extern "C" { #endif typedef struct Map { - int nmap; // the Number of Mapping Operations - double value[UDA_MAX_DATA_RANK]; // Array of values to Map to - char mapping[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING]; // Array of Mapping Operations - int dimid[UDA_MAX_DATA_RANK]; // Array of Dimension IDs to Map to - char data_signal[UDA_SXML_MAX_STRING]; // Name of Signal + int nmap; // the Number of Mapping Operations + double value[UDA_MAX_DATA_RANK]; // Array of values to Map to + char mapping[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING]; // Array of Mapping Operations + int dimid[UDA_MAX_DATA_RANK]; // Array of Dimension IDs to Map to + char data_signal[UDA_SXML_MAX_STRING]; // Name of Signal } MAP; typedef struct DimCalibration { @@ -32,13 +32,13 @@ typedef struct DimCalibration { } DIMCALIBRATION; typedef struct DimComposite { - int to_dim; // duplicated as dimid // Swap to Dimension ID - int from_dim; // Swap from Dimension ID + int to_dim; // duplicated as dimid // Swap to Dimension ID + int from_dim; // Swap from Dimension ID char file[UDA_SXML_MAX_STRING]; char format[UDA_SXML_MAX_STRING]; - char dim_signal[UDA_SXML_MAX_STRING]; // Dimension Source Signal Name - char dim_error[UDA_SXML_MAX_STRING]; // Dimension Error Source Signal Name - char dim_aserror[UDA_SXML_MAX_STRING]; // Dimension Asymmetric Error Source Signal Name + char dim_signal[UDA_SXML_MAX_STRING]; // Dimension Source Signal Name + char dim_error[UDA_SXML_MAX_STRING]; // Dimension Error Source Signal Name + char dim_aserror[UDA_SXML_MAX_STRING]; // Dimension Asymmetric Error Source Signal Name } DIMCOMPOSITE; typedef struct DimDocumentation { @@ -47,9 +47,9 @@ typedef struct DimDocumentation { } DIMDOCUMENTATION; typedef struct DimErrorModel { - int model; // Error Model Id - int param_n; // The number of parameters - //float *params; // Parameter Array + int model; // Error Model Id + int param_n; // The number of parameters + // float *params; // Parameter Array float params[MAXERRPARAMS]; } DIMERRORMODEL; @@ -89,13 +89,13 @@ typedef struct Documentation { } DOCUMENTATION; typedef struct Composite { - char file[UDA_SXML_MAX_STRING]; // Complete file name - char format[UDA_SXML_MAX_STRING]; // File Format + char file[UDA_SXML_MAX_STRING]; // Complete file name + char format[UDA_SXML_MAX_STRING]; // File Format char data_signal[UDA_SXML_MAX_STRING]; char error_signal[UDA_SXML_MAX_STRING]; - char aserror_signal[UDA_SXML_MAX_STRING]; // Asymmetric Error Source Signal Name - char map_to_signal[UDA_SXML_MAX_STRING]; // straight replacement of signals (useful only if pass range is necessary) - int order; // Identify the Time Dimension + char aserror_signal[UDA_SXML_MAX_STRING]; // Asymmetric Error Source Signal Name + char map_to_signal[UDA_SXML_MAX_STRING]; // straight replacement of signals (useful only if pass range is necessary) + int order; // Identify the Time Dimension int ndimensions; int nsubsets; int nmaps; @@ -105,9 +105,9 @@ typedef struct Composite { } COMPOSITE; typedef struct ErrorModel { - int model; // Error Model Id - int param_n; // The number of parameters - //float *params; // Parameter Array + int model; // Error Model Id + int param_n; // The number of parameters + // float *params; // Parameter Array float params[MAXERRPARAMS]; int ndimensions; DIMENSION* dimensions; @@ -141,8 +141,8 @@ typedef struct Action { } ACTION; typedef struct Actions { - int nactions; // Number of Actions - ACTION* action; // Array of Actions + int nactions; // Number of Actions + ACTION* action; // Array of Actions } ACTIONS; #ifndef NOXMLPARSER diff --git a/source/clientserver/printStructs.cpp b/source/clientserver/printStructs.cpp old mode 100755 new mode 100644 index f838eb38..79e0f1f0 --- a/source/clientserver/printStructs.cpp +++ b/source/clientserver/printStructs.cpp @@ -4,9 +4,9 @@ #include "printStructs.h" -#include #include "udaTypes.h" #include +#include void printRequestData(REQUEST_DATA str) { @@ -27,10 +27,8 @@ void printRequestData(REQUEST_DATA str) UDA_LOG(UDA_LOG_DEBUG, "subset : %s\n", str.subset); UDA_LOG(UDA_LOG_DEBUG, "subsetCount : %d\n", str.datasubset.nbound); for (int i = 0; i < str.datasubset.nbound; i++) { - UDA_LOG(UDA_LOG_DEBUG, "[%d] %d %d %d %d\n", i, str.datasubset.dimid[i], - str.datasubset.lbindex[i].value, - str.datasubset.ubindex[i].value, - str.datasubset.stride[i].value); + UDA_LOG(UDA_LOG_DEBUG, "[%d] %d %d %d %d\n", i, str.datasubset.dimid[i], str.datasubset.lbindex[i].value, + str.datasubset.ubindex[i].value, str.datasubset.stride[i].value); } UDA_LOG(UDA_LOG_DEBUG, "nameValueCount : %d\n", str.nameValueList.pairCount); for (int i = 0; i < str.nameValueList.pairCount; i++) { @@ -80,7 +78,6 @@ void printClientBlock(CLIENT_BLOCK str) UDA_LOG(UDA_LOG_DEBUG, "Study DOI : %s\n", str.DOI); } - void printServerBlock(SERVER_BLOCK str) { UDA_LOG(UDA_LOG_DEBUG, "Server State Block\n"); @@ -125,7 +122,7 @@ void printDataBlock(DATA_BLOCK str) switch (str.opaque_type) { case (UDA_OPAQUE_TYPE_XML_DOCUMENT): if (str.opaque_block != nullptr) { - UDA_LOG(UDA_LOG_DEBUG, "XML: %s\n", (char*) str.opaque_block); + UDA_LOG(UDA_LOG_DEBUG, "XML: %s\n", (char*)str.opaque_block); } break; default: @@ -167,7 +164,7 @@ void printDataBlock(DATA_BLOCK str) for (int i = 0; i < str.error_param_n; i++) { UDA_LOG(UDA_LOG_DEBUG, "param[%d] = %f \n", i, str.errparams[i]); } - + UDA_LOG(UDA_LOG_DEBUG, "data_units : %s\n", str.data_units); UDA_LOG(UDA_LOG_DEBUG, "data_label : %s\n", str.data_label); UDA_LOG(UDA_LOG_DEBUG, "data_desc : %s\n", str.data_desc); @@ -185,11 +182,11 @@ void printDataBlock(DATA_BLOCK str) for (int j = 0; j < str.dims[i].error_param_n; j++) { UDA_LOG(UDA_LOG_DEBUG, "param[%d] = %f \n", j, str.dims[i].errparams[j]); } - + UDA_LOG(UDA_LOG_DEBUG, "data_number : %d\n", str.dims[i].dim_n); UDA_LOG(UDA_LOG_DEBUG, "compressed? : %d\n", str.dims[i].compressed); UDA_LOG(UDA_LOG_DEBUG, "method : %d\n", str.dims[i].method); - + if (str.dims[i].method == 0) { if (str.dims[i].compressed) { UDA_LOG(UDA_LOG_DEBUG, "starting val: %f\n", str.dims[i].dim0); @@ -197,17 +194,25 @@ void printDataBlock(DATA_BLOCK str) } else { if (str.dims[i].data_type == UDA_TYPE_FLOAT) { k = 10; - if (str.dims[i].dim_n < 10) k = str.dims[i].dim_n; - if (str.dims[i].dim != nullptr) - for (int j = 0; j < k; j++) - UDA_LOG(UDA_LOG_DEBUG, "val[%d] = %f\n", j, *((float*) str.dims[i].dim + j)); + if (str.dims[i].dim_n < 10) { + k = str.dims[i].dim_n; + } + if (str.dims[i].dim != nullptr) { + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "val[%d] = %f\n", j, *((float*)str.dims[i].dim + j)); + } + } } if (str.dims[i].data_type == UDA_TYPE_DOUBLE) { k = 10; - if (str.dims[i].dim_n < 10) k = str.dims[i].dim_n; - if (str.dims[i].dim != nullptr) - for (int j = 0; j < k; j++) - UDA_LOG(UDA_LOG_DEBUG, "val[%d] = %f\n", j, *((double*) str.dims[i].dim + j)); + if (str.dims[i].dim_n < 10) { + k = str.dims[i].dim_n; + } + if (str.dims[i].dim != nullptr) { + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "val[%d] = %f\n", j, *((double*)str.dims[i].dim + j)); + } + } } } } else { @@ -216,43 +221,55 @@ void printDataBlock(DATA_BLOCK str) case 1: if (str.dims[i].data_type == UDA_TYPE_FLOAT) { k = 10; - if (str.dims[i].udoms < 10) k = str.dims[i].udoms; + if (str.dims[i].udoms < 10) { + k = str.dims[i].udoms; + } for (int j = 0; j < k; j++) { - UDA_LOG(UDA_LOG_DEBUG, "sams[%d]: %d\n", j, (int) *(str.dims[i].sams + j)); - UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((float*) str.dims[i].offs + j)); - UDA_LOG(UDA_LOG_DEBUG, "ints[%d]: %f\n", j, *((float*) str.dims[i].ints + j)); + UDA_LOG(UDA_LOG_DEBUG, "sams[%d]: %d\n", j, (int)*(str.dims[i].sams + j)); + UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((float*)str.dims[i].offs + j)); + UDA_LOG(UDA_LOG_DEBUG, "ints[%d]: %f\n", j, *((float*)str.dims[i].ints + j)); } } if (str.dims[i].data_type == UDA_TYPE_DOUBLE) { k = 10; - if (str.dims[i].udoms < 10) k = str.dims[i].udoms; + if (str.dims[i].udoms < 10) { + k = str.dims[i].udoms; + } for (int j = 0; j < k; j++) { - UDA_LOG(UDA_LOG_DEBUG, "sams[%d]: %d\n", j, (int) *(str.dims[i].sams + j)); - UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((double*) str.dims[i].offs + j)); - UDA_LOG(UDA_LOG_DEBUG, "ints[%d]: %f\n", j, *((double*) str.dims[i].ints + j)); + UDA_LOG(UDA_LOG_DEBUG, "sams[%d]: %d\n", j, (int)*(str.dims[i].sams + j)); + UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((double*)str.dims[i].offs + j)); + UDA_LOG(UDA_LOG_DEBUG, "ints[%d]: %f\n", j, *((double*)str.dims[i].ints + j)); } } break; case 2: if (str.dims[i].data_type == UDA_TYPE_FLOAT) { k = 10; - if (str.dims[i].udoms < 10) k = str.dims[i].udoms; - for (int j = 0; j < k; j++) UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((float*) str.dims[i].offs + j)); + if (str.dims[i].udoms < 10) { + k = str.dims[i].udoms; + } + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((float*)str.dims[i].offs + j)); + } } if (str.dims[i].data_type == UDA_TYPE_DOUBLE) { k = 10; - if (str.dims[i].udoms < 10) k = str.dims[i].udoms; - for (int j = 0; j < k; j++) UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((double*) str.dims[i].offs + j)); + if (str.dims[i].udoms < 10) { + k = str.dims[i].udoms; + } + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "offs[%d]: %f\n", j, *((double*)str.dims[i].offs + j)); + } } break; case 3: if (str.dims[i].data_type == UDA_TYPE_FLOAT) { - UDA_LOG(UDA_LOG_DEBUG, "offs[0] val: %f\n", *((float*) str.dims[i].offs)); - UDA_LOG(UDA_LOG_DEBUG, "ints[0] val: %f\n", *((float*) str.dims[i].ints)); + UDA_LOG(UDA_LOG_DEBUG, "offs[0] val: %f\n", *((float*)str.dims[i].offs)); + UDA_LOG(UDA_LOG_DEBUG, "ints[0] val: %f\n", *((float*)str.dims[i].ints)); } if (str.dims[i].data_type == UDA_TYPE_DOUBLE) { - UDA_LOG(UDA_LOG_DEBUG, "offs[0] val: %f\n", *((double*) str.dims[i].offs)); - UDA_LOG(UDA_LOG_DEBUG, "ints[0] val: %f\n", *((double*) str.dims[i].ints)); + UDA_LOG(UDA_LOG_DEBUG, "offs[0] val: %f\n", *((double*)str.dims[i].offs)); + UDA_LOG(UDA_LOG_DEBUG, "ints[0] val: %f\n", *((double*)str.dims[i].ints)); } break; default: @@ -261,20 +278,25 @@ void printDataBlock(DATA_BLOCK str) } if (str.dims[i].error_type == UDA_TYPE_FLOAT) { k = 10; - if (str.dims[i].dim_n < 10) k = str.dims[i].dim_n; - if (str.dims[i].errhi != nullptr) - for (int j = 0; j < k; j++) - UDA_LOG(UDA_LOG_DEBUG, "errhi[%d] = %f\n", j, *((float*) str.dims[i].errhi + j)); - if (str.dims[i].errlo != nullptr && str.dims[i].errasymmetry) - for (int j = 0; j < k; j++) - UDA_LOG(UDA_LOG_DEBUG, "errlo[%d] = %f\n", j, *((float*) str.dims[i].errlo + j)); + if (str.dims[i].dim_n < 10) { + k = str.dims[i].dim_n; + } + if (str.dims[i].errhi != nullptr) { + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "errhi[%d] = %f\n", j, *((float*)str.dims[i].errhi + j)); + } + } + if (str.dims[i].errlo != nullptr && str.dims[i].errasymmetry) { + for (int j = 0; j < k; j++) { + UDA_LOG(UDA_LOG_DEBUG, "errlo[%d] = %f\n", j, *((float*)str.dims[i].errlo + j)); + } + } } UDA_LOG(UDA_LOG_DEBUG, "data_units : %s\n", str.dims[i].dim_units); UDA_LOG(UDA_LOG_DEBUG, "data_label : %s\n", str.dims[i].dim_label); } } - void printSystemConfig(SYSTEM_CONFIG str) { UDA_LOG(UDA_LOG_DEBUG, "System Configuration Record\n"); @@ -288,7 +310,6 @@ void printSystemConfig(SYSTEM_CONFIG str) UDA_LOG(UDA_LOG_DEBUG, "xml_creation: %s\n", str.xml_creation); } - void printDataSystem(DATA_SYSTEM str) { UDA_LOG(UDA_LOG_DEBUG, "Data System Record\n"); diff --git a/source/clientserver/printStructs.h b/source/clientserver/printStructs.h old mode 100755 new mode 100644 index 87978ef3..c1ba2b51 --- a/source/clientserver/printStructs.h +++ b/source/clientserver/printStructs.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_PRINTSTRUCTS_H #define UDA_CLIENTSERVER_PRINTSTRUCTS_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -25,4 +25,3 @@ LIBRARY_API void printSignalDesc(SIGNAL_DESC str); #endif #endif // UDA_CLIENTSERVER_PRINTSTRUCTS_H - diff --git a/source/clientserver/protocol.cpp b/source/clientserver/protocol.cpp old mode 100755 new mode 100644 index 9f1f94de..0c0b0218 --- a/source/clientserver/protocol.cpp +++ b/source/clientserver/protocol.cpp @@ -1,39 +1,39 @@ /*--------------------------------------------------------------- -* Client - Server Conversation Protocol -* -* Args: xdrs XDR Stream -* -* protocol_id Client/Server Conversation item: Data Exchange context -* direction Send (0) or Receive (1) or Free (2) -* token current error condition or next protocol or .... exchange token -* -* str Information Structure depending on the protocol id .... -* -* 2 data_block Data read from the external Source or Data to be written -* to an external source -* 4 data_system Database Data_Dystem table record -* 5 system_config Database System_Config table record -* 6 data_source Database Data_Source table record -* 7 signal Database Signal table record -* 8 signal_desc Database Signal_Desc table record -* -* Returns: error code if failure, otherwise 0 -* -*--------------------------------------------------------------*/ + * Client - Server Conversation Protocol + * + * Args: xdrs XDR Stream + * + * protocol_id Client/Server Conversation item: Data Exchange context + * direction Send (0) or Receive (1) or Free (2) + * token current error condition or next protocol or .... exchange token + * + * str Information Structure depending on the protocol id .... + * + * 2 data_block Data read from the external Source or Data to be written + * to an external source + * 4 data_system Database Data_Dystem table record + * 5 system_config Database System_Config table record + * 6 data_source Database Data_Source table record + * 7 signal Database Signal table record + * 8 signal_desc Database Signal_Desc table record + * + * Returns: error code if failure, otherwise 0 + * + *--------------------------------------------------------------*/ #include "protocol.h" -#include #include "udaTypes.h" #include +#include #include "allocData.h" #include "compressDim.h" -#include "xdrlib.h" +#include "errorLog.h" #include "initStructs.h" #include "protocolXML.h" #include "udaErrors.h" -#include "errorLog.h" +#include "xdrlib.h" #ifdef SERVERBUILD # include @@ -57,7 +57,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_REQUEST_BLOCK) { - auto request_block = (REQUEST_BLOCK*) str; + auto request_block = (REQUEST_BLOCK*)str; switch (direction) { case XDR_RECEIVE: @@ -125,9 +125,13 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - if (data_block->data_n == 0) break; // No Data to Receive! + if (data_block->data_n == 0) { + break; // No Data to Receive! + } - if ((err = allocData(data_block)) != 0) break; // Allocate Heap Memory + if ((err = allocData(data_block)) != 0) { + break; // Allocate Heap Memory + } if (!xdr_data_block2(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_62; @@ -135,19 +139,19 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } if (data_block->error_type != UDA_TYPE_UNKNOWN || - data_block->error_param_n > 0) { // Receive Only if Error Data are available + data_block->error_param_n > 0) { // Receive Only if Error Data are available if (!xdr_data_block3(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_62; break; } - if (!xdr_data_block4(xdrs, data_block)) { // Asymmetric Errors + if (!xdr_data_block4(xdrs, data_block)) { // Asymmetric Errors err = UDA_PROTOCOL_ERROR_62; break; } } - if (data_block->rank > 0) { // Check if there are Dimensional Data to Receive + if (data_block->rank > 0) { // Check if there are Dimensional Data to Receive for (unsigned int i = 0; i < data_block->rank; i++) { initDimBlock(&data_block->dims[i]); } @@ -167,18 +171,22 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } } } - if (err) break; + if (err) { + break; + } - if ((err = allocDim(data_block)) != 0) break; // Allocate Heap Memory + if ((err = allocDim(data_block)) != 0) { + break; // Allocate Heap Memory + } - if (!xdr_data_dim2(xdrs, data_block)) { // Collect Only Uncompressed data + if (!xdr_data_dim2(xdrs, data_block)) { // Collect Only Uncompressed data err = UDA_PROTOCOL_ERROR_64; break; } - for (unsigned int i = 0; i < data_block->rank; i++) { // Expand Compressed Regular Vector - err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required - err = 0; // Need to Test for Error Condition! + for (unsigned int i = 0; i < data_block->rank; i++) { // Expand Compressed Regular Vector + err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required + err = 0; // Need to Test for Error Condition! } if (!xdr_data_dim3(xdrs, data_block)) { @@ -186,11 +194,10 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - if (!xdr_data_dim4(xdrs, data_block)) { // Asymmetric Errors + if (!xdr_data_dim4(xdrs, data_block)) { // Asymmetric Errors err = UDA_PROTOCOL_ERROR_65; break; } - } break; @@ -199,7 +206,8 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Check client/server understands new data types - // direction == XDR_SEND && protocolVersion == 3 Means Server sending data to a Version 3 Client (Type is known) + // direction == XDR_SEND && protocolVersion == 3 Means Server sending data to a Version 3 Client + // (Type is known) if (protocolVersionTypeTest(protocolVersion, data_block->data_type) || protocolVersionTypeTest(protocolVersion, data_block->error_type)) { @@ -212,8 +220,10 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - if (data_block->data_n == 0) { // No Data or Dimensions to Send! - if (!xdrrec_endofrecord(xdrs, 1)) err = UDA_PROTOCOL_ERROR_7; + if (data_block->data_n == 0) { // No Data or Dimensions to Send! + if (!xdrrec_endofrecord(xdrs, 1)) { + err = UDA_PROTOCOL_ERROR_7; + } break; } @@ -223,7 +233,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } if (data_block->error_type != UDA_TYPE_UNKNOWN || - data_block->error_param_n > 0) { // Only Send if Error Data are available + data_block->error_param_n > 0) { // Only Send if Error Data are available if (!xdr_data_block3(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_62; break; @@ -234,8 +244,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } } - - if (data_block->rank > 0) { // Dimensional Data to Send + if (data_block->rank > 0) { // Dimensional Data to Send // Check client/server understands new data types @@ -251,7 +260,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } for (unsigned int i = 0; i < data_block->rank; i++) { - compressDim(&(data_block->dims[i])); // Minimise Data Transfer if Regular + compressDim(&(data_block->dims[i])); // Minimise Data Transfer if Regular } if (!xdr_data_dim1(xdrs, data_block)) { @@ -271,7 +280,6 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (!xdr_data_dim4(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_65; } - } if (!xdrrec_endofrecord(xdrs, 1)) { @@ -295,7 +303,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_PUTDATA_BLOCK_LIST) { - auto putDataBlockList = (PUTDATA_BLOCK_LIST*) str; + auto putDataBlockList = (PUTDATA_BLOCK_LIST*)str; PUTDATA_BLOCK putData; switch (direction) { @@ -317,7 +325,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "receive: putDataBlockList Count: %d\n", blockCount); - for (unsigned int i = 0; i < blockCount; i++) { // Fetch multiple put blocks + for (unsigned int i = 0; i < blockCount; i++) { // Fetch multiple put blocks initIdamPutDataBlock(&putData); @@ -334,15 +342,16 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (putData.count > 0 || putData.blockNameLength > 0) { - if ((err = allocPutData(&putData)) != 0) break; // Allocate Heap Memory + if ((err = allocPutData(&putData)) != 0) { + break; // Allocate Heap Memory + } - if (!xdr_putdata_block2(xdrs, &putData)) { // Fetch data + if (!xdr_putdata_block2(xdrs, &putData)) { // Fetch data err = UDA_PROTOCOL_ERROR_62; break; } - addIdamPutDataBlockList(&putData, putDataBlockList); // Add to the growing list - + addIdamPutDataBlockList(&putData, putDataBlockList); // Add to the growing list } } @@ -360,7 +369,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - for (unsigned int i = 0; i < putDataBlockList->blockCount; i++) { // Send multiple put blocks + for (unsigned int i = 0; i < putDataBlockList->blockCount; i++) { // Send multiple put blocks if (!xdr_putdata_block1(xdrs, &(putDataBlockList->putDataBlock[i]))) { err = UDA_PROTOCOL_ERROR_61; @@ -373,13 +382,12 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } if (putDataBlockList->putDataBlock[i].count > 0 || - putDataBlockList->putDataBlock[i].blockNameLength > 0) { // Data to Send? + putDataBlockList->putDataBlock[i].blockNameLength > 0) { // Data to Send? if (!xdr_putdata_block2(xdrs, &(putDataBlockList->putDataBlock[i]))) { err = UDA_PROTOCOL_ERROR_62; break; } - } } @@ -408,7 +416,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS switch (direction) { - case XDR_RECEIVE: // From Client to Server + case XDR_RECEIVE: // From Client to Server if (!xdrrec_skiprecord(xdrs)) { err = UDA_PROTOCOL_ERROR_5; break; @@ -446,10 +454,10 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Data System record if (protocol_id == UDA_PROTOCOL_DATA_SYSTEM) { - auto data_system = (DATA_SYSTEM*) str; + auto data_system = (DATA_SYSTEM*)str; switch (direction) { - case XDR_RECEIVE: // From Client to Server + case XDR_RECEIVE: // From Client to Server if (!xdrrec_skiprecord(xdrs)) { err = UDA_PROTOCOL_ERROR_5; break; @@ -492,7 +500,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_SYSTEM_CONFIG) { - auto system_config = (SYSTEM_CONFIG*) str; + auto system_config = (SYSTEM_CONFIG*)str; switch (direction) { case XDR_RECEIVE: @@ -509,7 +517,6 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS case XDR_SEND: - if (!xdr_system_config(xdrs, system_config)) { err = UDA_PROTOCOL_ERROR_12; break; @@ -540,7 +547,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_DATA_SOURCE) { - auto data_source = (DATA_SOURCE*) str; + auto data_source = (DATA_SOURCE*)str; switch (direction) { case XDR_RECEIVE: @@ -587,7 +594,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_SIGNAL) { - auto signal = (SIGNAL*) str; + auto signal = (SIGNAL*)str; switch (direction) { @@ -635,7 +642,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_SIGNAL_DESC) { - auto signal_desc = (SIGNAL_DESC*) str; + auto signal_desc = (SIGNAL_DESC*)str; switch (direction) { @@ -684,7 +691,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_CLIENT_BLOCK) { - auto client_block = (CLIENT_BLOCK*) str; + auto client_block = (CLIENT_BLOCK*)str; switch (direction) { @@ -734,7 +741,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id == UDA_PROTOCOL_SERVER_BLOCK) { - auto server_block = (SERVER_BLOCK*) str; + auto server_block = (SERVER_BLOCK*)str; switch (direction) { @@ -745,17 +752,17 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - closeUdaError(); // Free Heap associated with Previous Data Access + closeUdaError(); // Free Heap associated with Previous Data Access if (!xdr_server1(xdrs, server_block, protocolVersion)) { err = UDA_PROTOCOL_ERROR_22; break; } - if (server_block->idamerrorstack.nerrors > 0) { // No Data to Receive? + if (server_block->idamerrorstack.nerrors > 0) { // No Data to Receive? - server_block->idamerrorstack.idamerror = (UDA_ERROR*) malloc( - server_block->idamerrorstack.nerrors * sizeof(UDA_ERROR)); + server_block->idamerrorstack.idamerror = + (UDA_ERROR*)malloc(server_block->idamerrorstack.nerrors * sizeof(UDA_ERROR)); initErrorRecords(&server_block->idamerrorstack); if (!xdr_server2(xdrs, server_block)) { @@ -772,7 +779,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - if (server_block->idamerrorstack.nerrors > 0) { // No Data to Send? + if (server_block->idamerrorstack.nerrors > 0) { // No Data to Send? if (!xdr_server2(xdrs, server_block)) { err = UDA_PROTOCOL_ERROR_22; break; @@ -806,8 +813,7 @@ int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (protocol_id > UDA_PROTOCOL_OPAQUE_START && protocol_id < UDA_PROTOCOL_OPAQUE_STOP) { err = protocolXML(xdrs, protocol_id, direction, token, logmalloclist, userdefinedtypelist, str, - protocolVersion, log_struct_list, io_data, private_flags, malloc_source, - nullptr); + protocolVersion, log_struct_list, io_data, private_flags, malloc_source, nullptr); } //---------------------------------------------------------------------------- diff --git a/source/clientserver/protocol.h b/source/clientserver/protocol.h old mode 100755 new mode 100644 index 008eb1e6..a129cc52 --- a/source/clientserver/protocol.h +++ b/source/clientserver/protocol.h @@ -1,58 +1,58 @@ #pragma once #ifndef UDA_CLIENTSERVER_UDA_PROTOCOL_H -#define UDA_CLIENTSERVER_UDA_PROTOCOL_H +# define UDA_CLIENTSERVER_UDA_PROTOCOL_H -#include -#include +# include +# include -#include "genStructs.h" +# include "genStructs.h" -#include "export.h" +# include "export.h" //------------------------------------------------------- // Client Server Conversation Protocols -#define UDA_PROTOCOL_REGULAR_START 0 // Identifies Regular Data Protocol Group -#define UDA_PROTOCOL_REQUEST_BLOCK 1 -#define UDA_PROTOCOL_DATA_BLOCK_LIST 2 -#define UDA_PROTOCOL_NEXT_PROTOCOL 3 -#define UDA_PROTOCOL_DATA_SYSTEM 4 -#define UDA_PROTOCOL_SYSTEM_CONFIG 5 -#define UDA_PROTOCOL_DATA_SOURCE 6 -#define UDA_PROTOCOL_SIGNAL 7 -#define UDA_PROTOCOL_SIGNAL_DESC 8 -#define UDA_PROTOCOL_SPARE1 9 -#define UDA_PROTOCOL_CLIENT_BLOCK 10 -#define UDA_PROTOCOL_SERVER_BLOCK 11 -#define UDA_PROTOCOL_SPARE2 12 -#define UDA_PROTOCOL_CLOSEDOWN 13 -#define UDA_PROTOCOL_SLEEP 14 -#define UDA_PROTOCOL_WAKE_UP 15 -#define UDA_PROTOCOL_PUTDATA_BLOCK_LIST 16 -#define UDA_PROTOCOL_SECURITY_BLOCK 17 -#define UDA_PROTOCOL_OBJECT 18 -#define UDA_PROTOCOL_SERIALISE_OBJECT 19 -#define UDA_PROTOCOL_SERIALISE_FILE 20 -#define UDA_PROTOCOL_DATAOBJECT 21 -#define UDA_PROTOCOL_DATAOBJECT_FILE 22 -#define UDA_PROTOCOL_REGULAR_STOP 99 +# define UDA_PROTOCOL_REGULAR_START 0 // Identifies Regular Data Protocol Group +# define UDA_PROTOCOL_REQUEST_BLOCK 1 +# define UDA_PROTOCOL_DATA_BLOCK_LIST 2 +# define UDA_PROTOCOL_NEXT_PROTOCOL 3 +# define UDA_PROTOCOL_DATA_SYSTEM 4 +# define UDA_PROTOCOL_SYSTEM_CONFIG 5 +# define UDA_PROTOCOL_DATA_SOURCE 6 +# define UDA_PROTOCOL_SIGNAL 7 +# define UDA_PROTOCOL_SIGNAL_DESC 8 +# define UDA_PROTOCOL_SPARE1 9 +# define UDA_PROTOCOL_CLIENT_BLOCK 10 +# define UDA_PROTOCOL_SERVER_BLOCK 11 +# define UDA_PROTOCOL_SPARE2 12 +# define UDA_PROTOCOL_CLOSEDOWN 13 +# define UDA_PROTOCOL_SLEEP 14 +# define UDA_PROTOCOL_WAKE_UP 15 +# define UDA_PROTOCOL_PUTDATA_BLOCK_LIST 16 +# define UDA_PROTOCOL_SECURITY_BLOCK 17 +# define UDA_PROTOCOL_OBJECT 18 +# define UDA_PROTOCOL_SERIALISE_OBJECT 19 +# define UDA_PROTOCOL_SERIALISE_FILE 20 +# define UDA_PROTOCOL_DATAOBJECT 21 +# define UDA_PROTOCOL_DATAOBJECT_FILE 22 +# define UDA_PROTOCOL_REGULAR_STOP 99 -#define UDA_PROTOCOL_OPAQUE_START 100 // Identifies Legacy Hierarchical Data Protocol Group -#define UDA_PROTOCOL_STRUCTURES 101 -#define UDA_PROTOCOL_META 102 -#define UDA_PROTOCOL_EFIT 103 -#define UDA_PROTOCOL_PFCOILS 104 -#define UDA_PROTOCOL_PFPASSIVE 105 -#define UDA_PROTOCOL_PFSUPPLIES 106 -#define UDA_PROTOCOL_FLUXLOOP 107 -#define UDA_PROTOCOL_MAGPROBE 108 -#define UDA_PROTOCOL_PFCIRCUIT 109 -#define UDA_PROTOCOL_PLASMACURRENT 110 -#define UDA_PROTOCOL_DIAMAGNETIC 111 -#define UDA_PROTOCOL_TOROIDALFIELD 112 -#define UDA_PROTOCOL_LIMITER 113 -#define UDA_PROTOCOL_OPAQUE_STOP 200 +# define UDA_PROTOCOL_OPAQUE_START 100 // Identifies Legacy Hierarchical Data Protocol Group +# define UDA_PROTOCOL_STRUCTURES 101 +# define UDA_PROTOCOL_META 102 +# define UDA_PROTOCOL_EFIT 103 +# define UDA_PROTOCOL_PFCOILS 104 +# define UDA_PROTOCOL_PFPASSIVE 105 +# define UDA_PROTOCOL_PFSUPPLIES 106 +# define UDA_PROTOCOL_FLUXLOOP 107 +# define UDA_PROTOCOL_MAGPROBE 108 +# define UDA_PROTOCOL_PFCIRCUIT 109 +# define UDA_PROTOCOL_PLASMACURRENT 110 +# define UDA_PROTOCOL_DIAMAGNETIC 111 +# define UDA_PROTOCOL_TOROIDALFIELD 112 +# define UDA_PROTOCOL_LIMITER 113 +# define UDA_PROTOCOL_OPAQUE_STOP 200 struct IoData; @@ -60,12 +60,10 @@ struct IoData; // Client Server XDR data Streams (DON'T CHANGE ORDER or Legacy client won't work!) int protocol(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, - IoData* io_data, unsigned int private_flags, int malloc_source); + USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, + IoData* io_data, unsigned int private_flags, int malloc_source); int protocol2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, - unsigned int private_flags, int malloc_source); + USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, + unsigned int private_flags, int malloc_source); #endif // UDA_CLIENTSERVER_UDA_PROTOCOL_H diff --git a/source/clientserver/protocol2.cpp b/source/clientserver/protocol2.cpp old mode 100755 new mode 100644 index e1f8f018..4e940b2b --- a/source/clientserver/protocol2.cpp +++ b/source/clientserver/protocol2.cpp @@ -1,47 +1,47 @@ /*--------------------------------------------------------------- -* Client - Server Conversation Protocol -* -* Args: xdrs XDR Stream -* -* protocol_id Client/Server Conversation item: Data Exchange context -* direction Send (0) or Receive (1) or Free (2) -* token current error condition or next protocol or .... exchange token -* -* str Information Structure depending on the protocol id .... -* -* 2 data_block Data read from the external Source or Data to be written -* to an external source -* 4 data_system Database Data_Dystem table record -* 5 system_config Database System_Config table record -* 6 data_source Database Data_Source table record -* 7 signal Database Signal table record -* 8 signal_desc Database Signal_Desc table record -* -* Returns: error code if failure, otherwise 0 -* -*--------------------------------------------------------------*/ + * Client - Server Conversation Protocol + * + * Args: xdrs XDR Stream + * + * protocol_id Client/Server Conversation item: Data Exchange context + * direction Send (0) or Receive (1) or Free (2) + * token current error condition or next protocol or .... exchange token + * + * str Information Structure depending on the protocol id .... + * + * 2 data_block Data read from the external Source or Data to be written + * to an external source + * 4 data_system Database Data_Dystem table record + * 5 system_config Database System_Config table record + * 6 data_source Database Data_Source table record + * 7 signal Database Signal table record + * 8 signal_desc Database Signal_Desc table record + * + * Returns: error code if failure, otherwise 0 + * + *--------------------------------------------------------------*/ #include "protocol.h" #include -#include #include "udaTypes.h" +#include #include "allocData.h" #include "compressDim.h" -#include "printStructs.h" -#include "xdrlib.h" #include "initStructs.h" +#include "printStructs.h" #include "protocolXML2.h" +#include "xdrlib.h" #ifdef HIERARCHICAL_DATA -# include "idamclientserverxml.h" // legacy +# include "idamclientserverxml.h" // legacy #endif +#include "errorLog.h" #include "protocolXML2Put.h" #include "udaErrors.h" -#include "errorLog.h" static int handle_request_block(XDR* xdrs, int direction, const void* str, int protocolVersion); static int handle_data_block(XDR* xdrs, int direction, const void* str, int protocolVersion); @@ -160,24 +160,23 @@ static int handle_security_block(XDR* xdrs, int direction, const void* str) // Allocate heap if (security_block->client_ciphertextLength > 0) { - security_block->client_ciphertext = (unsigned char*)malloc( - security_block->client_ciphertextLength * sizeof(unsigned char)); + security_block->client_ciphertext = + (unsigned char*)malloc(security_block->client_ciphertextLength * sizeof(unsigned char)); } if (security_block->client2_ciphertextLength > 0) { - security_block->client2_ciphertext = (unsigned char*)malloc( - security_block->client2_ciphertextLength * sizeof(unsigned char)); + security_block->client2_ciphertext = + (unsigned char*)malloc(security_block->client2_ciphertextLength * sizeof(unsigned char)); } if (security_block->server_ciphertextLength > 0) { - security_block->server_ciphertext = (unsigned char*)malloc( - security_block->server_ciphertextLength * sizeof(unsigned char)); + security_block->server_ciphertext = + (unsigned char*)malloc(security_block->server_ciphertextLength * sizeof(unsigned char)); } if (security_block->client_X509Length > 0) { - security_block->client_X509 = (unsigned char*)malloc( - security_block->client_X509Length * sizeof(unsigned char)); + security_block->client_X509 = (unsigned char*)malloc(security_block->client_X509Length * sizeof(unsigned char)); } if (security_block->client2_X509Length > 0) { - security_block->client2_X509 = (unsigned char*)malloc( - security_block->client2_X509Length * sizeof(unsigned char)); + security_block->client2_X509 = + (unsigned char*)malloc(security_block->client2_X509Length * sizeof(unsigned char)); } switch (direction) { @@ -232,7 +231,7 @@ static int handle_dataobject(XDR* xdrs, int direction, const void* str) switch (direction) { case XDR_RECEIVE: - if (!xdr_data_object1(xdrs, data_object)) { // Storage requirements + if (!xdr_data_object1(xdrs, data_object)) { // Storage requirements err = UDA_PROTOCOL_ERROR_22; break; } @@ -274,17 +273,17 @@ static int handle_server_block(XDR* xdrs, int direction, const void* str, int pr switch (direction) { case XDR_RECEIVE: - closeUdaError(); // Free Heap associated with Previous Data Access + closeUdaError(); // Free Heap associated with Previous Data Access if (!xdr_server1(xdrs, server_block, protocolVersion)) { err = UDA_PROTOCOL_ERROR_22; break; } - if (server_block->idamerrorstack.nerrors > 0) { // No Data to Receive? + if (server_block->idamerrorstack.nerrors > 0) { // No Data to Receive? - server_block->idamerrorstack.idamerror = (UDA_ERROR*)malloc( - server_block->idamerrorstack.nerrors * sizeof(UDA_ERROR)); + server_block->idamerrorstack.idamerror = + (UDA_ERROR*)malloc(server_block->idamerrorstack.nerrors * sizeof(UDA_ERROR)); initErrorRecords(&server_block->idamerrorstack); if (!xdr_server2(xdrs, server_block)) { @@ -301,7 +300,7 @@ static int handle_server_block(XDR* xdrs, int direction, const void* str, int pr break; } - if (server_block->idamerrorstack.nerrors > 0) { // No Data to Send? + if (server_block->idamerrorstack.nerrors > 0) { // No Data to Send? if (!xdr_server2(xdrs, server_block)) { err = UDA_PROTOCOL_ERROR_22; break; @@ -505,7 +504,7 @@ static int handle_next_protocol(XDR* xdrs, int direction, int* token) { int err = 0; switch (direction) { - case XDR_RECEIVE: // From Client to Server + case XDR_RECEIVE: // From Client to Server if (!xdrrec_skiprecord(xdrs)) { err = UDA_PROTOCOL_ERROR_5; break; @@ -574,11 +573,13 @@ static int handle_putdata_block_list(XDR* xdrs, int direction, int* token, LOGMA break; } - if (putData.count > 0 || putData.blockNameLength > 0) { // Some data to receive? + if (putData.count > 0 || putData.blockNameLength > 0) { // Some data to receive? - if ((err = allocPutData(&putData)) != 0) break; // Allocate Heap Memory + if ((err = allocPutData(&putData)) != 0) { + break; // Allocate Heap Memory + } - if (!xdr_putdata_block2(xdrs, &putData)) { // Fetch data + if (!xdr_putdata_block2(xdrs, &putData)) { // Fetch data err = UDA_PROTOCOL_ERROR_62; break; } @@ -599,24 +600,23 @@ static int handle_putdata_block_list(XDR* xdrs, int direction, int* token, LOGMA initDataBlock(data_block); data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; - data_block->data_n = (int)putData.count; // This number (also rank and shape) - data_block->opaque_block = putData.opaque_block; // User Defined Type + data_block->data_n = (int)putData.count; // This number (also rank and shape) + data_block->opaque_block = putData.opaque_block; // User Defined Type int protocol_id = UDA_PROTOCOL_STRUCTURES; if ((err = protocolXML2Put(xdrs, protocol_id, direction, token, logmalloclist, userdefinedtypelist, - data_block, protocolVersion, log_struct_list, - private_flags, malloc_source)) != 0) { + data_block, protocolVersion, log_struct_list, private_flags, + malloc_source)) != 0) { // Fetch Structured data break; } - putData.data = reinterpret_cast(data_block); // Compact memory block with structures + putData.data = reinterpret_cast(data_block); // Compact memory block with structures auto general_block = (GENERAL_BLOCK*)data_block->opaque_block; putData.opaque_block = general_block->userdefinedtype; } - addIdamPutDataBlockList(&putData, putDataBlockList); // Add to the growing list - + addIdamPutDataBlockList(&putData, putDataBlockList); // Add to the growing list } break; } @@ -630,7 +630,7 @@ static int handle_putdata_block_list(XDR* xdrs, int direction, int* token, LOGMA break; } - for (unsigned int i = 0; i < putDataBlockList->blockCount; i++) { // Send multiple put blocks + for (unsigned int i = 0; i < putDataBlockList->blockCount; i++) { // Send multiple put blocks if (!xdr_putdata_block1(xdrs, &(putDataBlockList->putDataBlock[i]))) { err = UDA_PROTOCOL_ERROR_61; @@ -643,7 +643,7 @@ static int handle_putdata_block_list(XDR* xdrs, int direction, int* token, LOGMA } if (putDataBlockList->putDataBlock[i].count > 0 || - putDataBlockList->putDataBlock[i].blockNameLength > 0) { // Data to Send? + putDataBlockList->putDataBlock[i].blockNameLength > 0) { // Data to Send? if (!xdr_putdata_block2(xdrs, &(putDataBlockList->putDataBlock[i]))) { err = UDA_PROTOCOL_ERROR_62; @@ -662,14 +662,16 @@ static int handle_putdata_block_list(XDR* xdrs, int direction, int* token, LOGMA DATA_BLOCK data_block; initDataBlock(&data_block); data_block.opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; - data_block.data_n = (int)putDataBlockList->putDataBlock[i].count; // This number (also rank and shape) - data_block.opaque_block = putDataBlockList->putDataBlock[i].opaque_block; // User Defined Type - data_block.data = (char*)putDataBlockList->putDataBlock[i].data; // Compact memory block with structures + data_block.data_n = + (int)putDataBlockList->putDataBlock[i].count; // This number (also rank and shape) + data_block.opaque_block = putDataBlockList->putDataBlock[i].opaque_block; // User Defined Type + data_block.data = + (char*)putDataBlockList->putDataBlock[i].data; // Compact memory block with structures int protocol_id = UDA_PROTOCOL_STRUCTURES; if ((err = protocolXML2Put(xdrs, protocol_id, direction, token, logmalloclist, userdefinedtypelist, - &data_block, protocolVersion, log_struct_list, - private_flags, malloc_source)) != 0) { + &data_block, protocolVersion, log_struct_list, private_flags, + malloc_source)) != 0) { // Send Structured data break; } @@ -709,9 +711,13 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot break; } - if (data_block->data_n == 0) break; // No Data to Receive! + if (data_block->data_n == 0) { + break; // No Data to Receive! + } - if ((err = allocData(data_block)) != 0) break; // Allocate Heap Memory + if ((err = allocData(data_block)) != 0) { + break; // Allocate Heap Memory + } if (!xdr_data_block2(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_62; @@ -719,20 +725,19 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot } if (data_block->error_type != UDA_TYPE_UNKNOWN || - data_block->error_param_n > 0) { // Receive Only if Error Data are available + data_block->error_param_n > 0) { // Receive Only if Error Data are available if (!xdr_data_block3(xdrs, data_block)) { err = UDA_PROTOCOL_ERROR_62; break; } - if (!xdr_data_block4(xdrs, data_block)) { // Asymmetric Errors + if (!xdr_data_block4(xdrs, data_block)) { // Asymmetric Errors err = UDA_PROTOCOL_ERROR_62; break; } - } - if (data_block->rank > 0) { // Check if there are Dimensional Data to Receive + if (data_block->rank > 0) { // Check if there are Dimensional Data to Receive for (unsigned int i = 0; i < data_block->rank; i++) { initDimBlock(&data_block->dims[i]); @@ -757,16 +762,18 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot } } - if ((err = allocDim(data_block)) != 0) break; // Allocate Heap Memory + if ((err = allocDim(data_block)) != 0) { + break; // Allocate Heap Memory + } - if (!xdr_data_dim2(xdrs, data_block)) { // Collect Only Uncompressed data + if (!xdr_data_dim2(xdrs, data_block)) { // Collect Only Uncompressed data err = UDA_PROTOCOL_ERROR_64; break; } - for (unsigned int i = 0; i < data_block->rank; i++) { // Expand Compressed Regular Vector - err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required - err = 0; // Need to Test for Error Condition! + for (unsigned int i = 0; i < data_block->rank; i++) { // Expand Compressed Regular Vector + err = uncompressDim(&(data_block->dims[i])); // Allocate Heap as required + err = 0; // Need to Test for Error Condition! } if (!xdr_data_dim3(xdrs, data_block)) { @@ -774,11 +781,10 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot break; } - if (!xdr_data_dim4(xdrs, data_block)) { // Asymmetric Errors + if (!xdr_data_dim4(xdrs, data_block)) { // Asymmetric Errors err = UDA_PROTOCOL_ERROR_65; break; } - } break; } @@ -787,7 +793,8 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot // Check client/server understands new data types - // direction == XDR_SEND && protocolVersion == 3 Means Server sending data to a Version 3 Client (Type is known) + // direction == XDR_SEND && protocolVersion == 3 Means Server sending data to a Version 3 Client (Type is + // known) UDA_LOG(UDA_LOG_DEBUG, "#1 PROTOCOL: Send/Receive Data Block\n"); printDataBlock(*data_block); @@ -805,7 +812,7 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot break; } - if (data_block->data_n == 0) { // No Data or Dimensions to Send! + if (data_block->data_n == 0) { // No Data or Dimensions to Send! break; } @@ -846,7 +853,7 @@ static int handle_data_block(XDR* xdrs, int direction, const void* str, int prot } for (unsigned int i = 0; i < data_block->rank; i++) { - compressDim(&(data_block->dims[i])); // Minimise Data Transfer if Regular + compressDim(&(data_block->dims[i])); // Minimise Data Transfer if Regular } if (!xdr_data_dim1(xdrs, data_block)) { @@ -902,7 +909,9 @@ static int handle_data_block_list(XDR* xdrs, int direction, const void* str, int break; } } - if (err) break; + if (err) { + break; + } break; case XDR_SEND: { @@ -918,7 +927,9 @@ static int handle_data_block_list(XDR* xdrs, int direction, const void* str, int break; } } - if (err) break; + if (err) { + break; + } break; } @@ -951,7 +962,9 @@ static int handle_request_block(XDR* xdrs, int direction, const void* str, int p break; } } - if (err) break; + if (err) { + break; + } break; case XDR_SEND: @@ -965,7 +978,9 @@ static int handle_request_block(XDR* xdrs, int direction, const void* str, int p break; } } - if (err) break; + if (err) { + break; + } break; case XDR_FREE_HEAP: diff --git a/source/clientserver/protocolXML.cpp b/source/clientserver/protocolXML.cpp old mode 100755 new mode 100644 index b3637016..9edc1479 --- a/source/clientserver/protocolXML.cpp +++ b/source/clientserver/protocolXML.cpp @@ -1,78 +1,78 @@ /*---------------------------------------------------------------------------------------------- -* Client - Server Conversation Protocol for XML based Hierarchical Data Structures -* -* Args: xdrs XDR Stream -* -* protocol_id Client/Server Conversation item: Data Exchange context -* direction Send (0) or Receive (1) or Free (2) -* token current error condition or next protocol or .... exchange token -* -* str Information Structure depending on the protocol id .... -* -* 100 efit -* 101 pfcoils -* 102 pfpassive -* 103 pfsupplies -* 104 fluxloop -* 105 magprobe -* 106 pfcircuit -* 107 plasmacurrent -* 108 diamagnetic -* 109 toroidalfield -* 110 limiter -* -* Returns: error code if failure, otherwise 0 -* -*-----------------------------------------------------return;--------------------------------------------- -* Notes on Generalised Data Structures: -* -* The DATA_BLOCK structure has the following fields used to pass and receive generalised data structures -* -* data_block->data_type set to UDA_TYPE_COMPOUND (external to this routine) -* data_block->data_n set to the count of structure array elements (external to this routine) -* -* data_block->data sending (server side): set to the data array (external to this routine) -* receiving (client side): set to the root data tree node within this routine -* -* data_block->opaque_type set to UDA_OPAQUE_TYPE_STRUCTURES (external to this routine) -* data_block->count set to 1 (external to this routine). Not Used! -* -* data_block->opaque_block sending (server side): set to the User Defined Data Structure Definition of -* the Data (external to this routine). -* receiving (client side): set to the SARRAY Data Structure Definition -* -* The SARRAY structure has the following: -* -* sarray.count set to the count of structure array elements. Identical to data_block->data_n. -* sarray.rank set to 1 (Higher ranked arrays possible ?) -* sarray.shape set to [sarray.count] for consistency. -* sarray.data set to data_block->data -* sarray.type set to the name of the User Defined Structure type of data -* (data_block->opaque_block->name). This is registered within the Structure -* Type List. -**--------------------------------------------------------------------------------------------------*/ + * Client - Server Conversation Protocol for XML based Hierarchical Data Structures + * + * Args: xdrs XDR Stream + * + * protocol_id Client/Server Conversation item: Data Exchange context + * direction Send (0) or Receive (1) or Free (2) + * token current error condition or next protocol or .... exchange token + * + * str Information Structure depending on the protocol id .... + * + * 100 efit + * 101 pfcoils + * 102 pfpassive + * 103 pfsupplies + * 104 fluxloop + * 105 magprobe + * 106 pfcircuit + * 107 plasmacurrent + * 108 diamagnetic + * 109 toroidalfield + * 110 limiter + * + * Returns: error code if failure, otherwise 0 + * + *-----------------------------------------------------return;--------------------------------------------- + * Notes on Generalised Data Structures: + * + * The DATA_BLOCK structure has the following fields used to pass and receive generalised data structures + * + * data_block->data_type set to UDA_TYPE_COMPOUND (external to this routine) + * data_block->data_n set to the count of structure array elements (external to this routine) + * + * data_block->data sending (server side): set to the data array (external to this routine) + * receiving (client side): set to the root data tree node within this routine + * + * data_block->opaque_type set to UDA_OPAQUE_TYPE_STRUCTURES (external to this routine) + * data_block->count set to 1 (external to this routine). Not Used! + * + * data_block->opaque_block sending (server side): set to the User Defined Data Structure Definition of + * the Data (external to this routine). + * receiving (client side): set to the SARRAY Data Structure Definition + * + * The SARRAY structure has the following: + * + * sarray.count set to the count of structure array elements. Identical to data_block->data_n. + * sarray.rank set to 1 (Higher ranked arrays possible ?) + * sarray.shape set to [sarray.count] for consistency. + * sarray.data set to data_block->data + * sarray.type set to the name of the User Defined Structure type of data + * (data_block->opaque_block->name). This is registered within the Structure + * Type List. + **--------------------------------------------------------------------------------------------------*/ #include "protocolXML.h" -#include #include +#include #include #include -#include #include "struct.h" #include +#include -#include "readXDRFile.h" #include "errorLog.h" -#include "xdrlib.h" -#include "udaErrors.h" #include "protocol.h" +#include "readXDRFile.h" #include "stringUtils.h" +#include "udaErrors.h" +#include "xdrlib.h" #ifdef HIERARCHICAL_DATA -# include "xmlStructs.h" # include "allocXMLData.h" # include "xdrHData.h" +# include "xmlStructs.h" #endif int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, @@ -137,14 +137,14 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Compound Data Structure\n"); UDA_LOG(UDA_LOG_DEBUG, "direction : %d [%d][%d]\n", (int)xdrs->x_op, XDR_ENCODE, XDR_DECODE); - if (xdrs->x_op == XDR_ENCODE) { // Send Data + if (xdrs->x_op == XDR_ENCODE) { // Send Data - SARRAY sarray; // Structure array carrier structure + SARRAY sarray; // Structure array carrier structure SARRAY* psarray = &sarray; - int shape = data_block->data_n; // rank 1 array of dimension lengths - auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition + int shape = data_block->data_n; // rank 1 array of dimension lengths + auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition USERDEFINEDTYPE* u = findUserDefinedType(userdefinedtypelist, "SARRAY", - 0); // Locate the carrier structure definition + 0); // Locate the carrier structure definition UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Sending to Client\n"); @@ -160,12 +160,12 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Creating SARRAY carrier structure\n"); initSArray(&sarray); - sarray.count = data_block->data_n; // Number of this structure - sarray.rank = 1; // Array Data Rank? - sarray.shape = &shape; // Only if rank > 1? - sarray.data = (void*)data_block->data; // Pointer to the data to be passed - strcpy(sarray.type, udt->name); // The name of the type - data = (void*)&psarray; // Pointer to the SARRAY array pointer + sarray.count = data_block->data_n; // Number of this structure + sarray.rank = 1; // Array Data Rank? + sarray.shape = &shape; // Only if rank > 1? + sarray.data = (void*)data_block->data; // Pointer to the data to be passed + strcpy(sarray.type, udt->name); // The name of the type + data = (void*)&psarray; // Pointer to the SARRAY array pointer addNonMalloc(logmalloclist, (void*)&shape, 1, sizeof(int), "int"); UDA_LOG(UDA_LOG_DEBUG, "protocolXML: sending Structure Definitions\n"); @@ -199,7 +199,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC errno = 0; if (mkstemp(temp_file.data()) < 0 || errno != 0) { err = 999; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, "Unable to Obtain a Temporary/Cache File Name"); break; @@ -211,8 +213,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - int packageType = UDA_PACKAGE_XDRFILE; // The package is a file - rc = xdr_int(xdrs, &packageType); // Send data package type + int packageType = UDA_PACKAGE_XDRFILE; // The package is a file + rc = xdr_int(xdrs, &packageType); // Send data package type rc = rc && xdrrec_endofrecord(xdrs, 1); // Close current output xdr stream and create stdio file stream @@ -220,17 +222,16 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC xdr_destroy(xdrs); xdr_stdio_flag = true; xdrstdio_create(&XDROutput, xdrfile, XDR_ENCODE); - xdrs = &XDROutput; // Switch from stream to file + xdrs = &XDROutput; // Switch from stream to file UDA_LOG(UDA_LOG_DEBUG, "protocolXML: stdio XDR file: %s\n", temp_file.c_str()); } else { - int packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR + int packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Sending Package Type: %d\n", packageType); - rc = xdr_int(xdrs, &packageType); // Send data package type + rc = xdr_int(xdrs, &packageType); // Send data package type rc = rc && xdrrec_endofrecord(xdrs, 1); - } #endif // send the full set of known named structures @@ -239,9 +240,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Structure Definitions sent: rc = %d\n", rc); // send the Data - rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, u, - (void**)data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); + rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, u, (void**)data, + protocolVersion, xdr_stdio_flag, log_struct_list, malloc_source); UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Data sent: rc = %d\n", rc); @@ -255,7 +255,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC #ifndef FATCLIENT if ((private_flags & PRIVATEFLAG_XDRFILE) && - protocolVersion >= 5) { // Server calling another server + protocolVersion >= 5) { // Server calling another server // Close the stream and file @@ -274,10 +274,12 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: sending temporary XDR file\n"); - err = sendXDRFile(xdrs, temp_file.c_str()); // Read and send + err = sendXDRFile(xdrs, temp_file.c_str()); // Read and send remove(temp_file.c_str()); - if (err != 0) break; + if (err != 0) { + break; + } } #endif // !FATCLIENT @@ -288,10 +290,12 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Receiving from Server\n"); // 3 valid options: - // 1> unpack structures, no xdr file involved => private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_STRUCTDATA - // 2> unpack structures, from an xdr file => private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_XDRFILE - // 3> xdr file only, no unpacking, passforward => private_flags & PRIVATEFLAG_XDRFILE == 1 && packageType == PACKAGE_XDRFILE - // 4> Error => private_flags & PRIVATEFLAG_XDRFILE == 1 && packageType == PACKAGE_STRUCTDATA + // 1> unpack structures, no xdr file involved => private_flags & PRIVATEFLAG_XDRFILE == 0 && + // packageType == PACKAGE_STRUCTDATA 2> unpack structures, from an xdr file => + // private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_XDRFILE 3> xdr file only, + // no unpacking, passforward => private_flags & PRIVATEFLAG_XDRFILE == 1 && packageType == + // PACKAGE_XDRFILE 4> Error => private_flags & PRIVATEFLAG_XDRFILE == 1 && + // packageType == PACKAGE_STRUCTDATA // // Option 3 does not include intermediate file caching - option 2 only @@ -302,7 +306,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Receiving Package Type\n"); rc = xdrrec_skiprecord(xdrs); - rc = rc && xdr_int(xdrs, &packageType); // Receive data package type + rc = rc && xdr_int(xdrs, &packageType); // Receive data package type #else rc = 1; @@ -341,12 +345,15 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC if (option == 3) { - // Create a temporary XDR file, receive and write data to the file - do not unpack data structures, pass the file onward + // Create a temporary XDR file, receive and write data to the file - do not unpack data + // structures, pass the file onward errno = 0; if (mkstemp(tempFile) < 0 || errno != 0) { err = 998; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, "Unable to Obtain a Temporary File Name [3]"); err = 998; @@ -356,14 +363,14 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - err = receiveXDRFile(xdrs, tempFile); // Receive and write the file + err = receiveXDRFile(xdrs, tempFile); // Receive and write the file char* fname = (char*)malloc(sizeof(char) * (strlen(tempFile) + 1)); strcpy(fname, tempFile); - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = (void*)fname; // File name - data_block->opaque_type = UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only - + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = (void*)fname; // File name + data_block->opaque_type = + UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only } // Unpack data structures @@ -392,7 +399,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC errno = 0; if (mkstemp(tempFile) < 0 || errno != 0) { err = 997; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Obtain a Temporary File Name [2]"); err = 997; @@ -402,11 +411,11 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - err = receiveXDRFile(xdrs, tempFile); // Receive and write + err = receiveXDRFile(xdrs, tempFile); // Receive and write // Create input xdr file stream - if ((xdrfile = fopen(tempFile, "rb")) == nullptr) { // Read temporary file + if ((xdrfile = fopen(tempFile, "rb")) == nullptr) { // Read temporary file err = 999; addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Open a Temporary XDR File for Writing"); @@ -416,11 +425,10 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC xdr_destroy(xdrs); xdr_stdio_flag = true; xdrstdio_create(&XDRInput, xdrfile, XDR_DECODE); - xdrs = &XDRInput; // Switch from stream to file - + xdrs = &XDRInput; // Switch from stream to file } #endif // !FATCLIENT - // receive the full set of known named structures + // receive the full set of known named structures rc = rc && xdr_userdefinedtypelist(xdrs, userdefinedtypelist, xdr_stdio_flag); UDA_LOG(UDA_LOG_DEBUG, "protocolXML: xdr_userdefinedtypelist #B\n"); @@ -434,9 +442,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC UDA_LOG(UDA_LOG_DEBUG, "protocolXML: xdrUserDefinedTypeData #A\n"); initUserDefinedType(udt_received); - rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // receive the Data + rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, &data, + protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data UDA_LOG(UDA_LOG_DEBUG, "protocolXML: xdrUserDefinedTypeData #B\n"); if (!rc) { @@ -457,7 +465,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC // Switch back to the normal xdr record stream - //xdrs = priorxdrs; + // xdrs = priorxdrs; XDR* xdr_input; XDR* xdr_output; @@ -468,18 +476,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC } #endif // !FATCLIENT - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, - "Inconsistent S Array Counts"); + addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Inconsistent S Array Counts"); break; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = + (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; general_block->userdefinedtype = udt_received; general_block->userdefinedtypelist = userdefinedtypelist; @@ -497,17 +505,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC #ifdef FATCLIENT - } else { - err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Unknown Opaque type"); - break; - } + } else { + err = 999; + addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Unknown Opaque type"); + break; } + } #else //==================================================================================================================== - // Passing temporary XDR files: server to server (protocolVersion >= 5 is TRUE && packageType == PACKAGE_XDRFILE) + // Passing temporary XDR files: server to server (protocolVersion >= 5 is TRUE && packageType == + // PACKAGE_XDRFILE) } else { @@ -516,7 +525,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC if (xdrs->x_op == XDR_ENCODE) { UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Forwarding XDR File %s\n", (char*)data_block->opaque_block); - err = sendXDRFile(xdrs, (char*)data_block->opaque_block); // Forward the xdr file + err = sendXDRFile(xdrs, (char*)data_block->opaque_block); // Forward the xdr file } else { UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Receiving forwarded XDR File\n"); @@ -527,7 +536,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC errno = 0; if (mkstemp(tempFile) < 0 || errno != 0) { err = 996; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Obtain a Temporary File Name"); err = 996; @@ -536,17 +547,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - err = receiveXDRFile(xdrs, tempFile); // Receive and write the file + err = receiveXDRFile(xdrs, tempFile); // Receive and write the file - if (private_flags & PRIVATEFLAG_XDRFILE) { // Forward the file (option 3) again + if (private_flags & PRIVATEFLAG_XDRFILE) { // Forward the file (option 3) again // If this is an intermediate client then read the file without unpacking the structures char* fname = (char*)malloc(sizeof(char) * (strlen(tempFile) + 1)); strcpy(fname, tempFile); - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = (void*)fname; // File name - data_block->opaque_type = UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = (void*)fname; // File name + data_block->opaque_type = + UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only UDA_LOG(UDA_LOG_DEBUG, "protocolXML: Forwarding Received forwarded XDR File\n"); } else { @@ -564,7 +576,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC // Create input xdr file stream - if ((xdrfile = fopen(tempFile, "rb")) == nullptr) { // Read temporary file + if ((xdrfile = fopen(tempFile, "rb")) == nullptr) { // Read temporary file err = 999; addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Open a Temporary XDR File for Writing"); @@ -589,8 +601,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC initUserDefinedType(udt_received); rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // receive the Data + &data, protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data if (!rc) { err = 999; @@ -615,18 +627,19 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC // Regular client or server if (STR_EQUALS(udt_received->name, - "SARRAY")) { // expecting this carrier structure + "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Inconsistent S Array Counts"); break; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = (char*) + udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; general_block->userdefinedtype = udt_received; @@ -651,8 +664,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC } #endif // !FATCLIENT -//---------------------------------------------------------------------------- -// Meta Data XML + //---------------------------------------------------------------------------- + // Meta Data XML #ifndef FATCLIENT @@ -665,8 +678,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC err = UDA_PROTOCOL_ERROR_5; break; } - if ((data_block->opaque_block = (char*)malloc( - (data_block->opaque_count + 1) * sizeof(char))) == nullptr) { + if ((data_block->opaque_block = (char*)malloc((data_block->opaque_count + 1) * sizeof(char))) == + nullptr) { err = 991; break; } @@ -726,28 +739,28 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if ((err = alloc_efit(efit)) != 0) break; // Allocate Heap Memory + if ((err = alloc_efit(efit)) != 0) { + break; // Allocate Heap Memory + } for (int i = 0; i < efit->npfcoils; i++) { pfcoils = efit->pfcoils + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFCOILS, direction, token, logmalloclist, userdefinedtypelist, (void*)pfcoils)) != 0) { - break; + break; } } for (int i = 0; i < efit->npfpassive; i++) { pfpassive = efit->pfpassive + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFPASSIVE, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfpassive)) != - 0) { + userdefinedtypelist, (void*)pfpassive)) != 0) { break; } } for (int i = 0; i < efit->npfsupplies; i++) { pfsupplies = efit->pfsupplies + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFSUPPLIES, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfsupplies)) != - 0) { + userdefinedtypelist, (void*)pfsupplies)) != 0) { break; } } @@ -755,45 +768,41 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC fluxloop = efit->fluxloop + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_FLUXLOOP, direction, token, logmalloclist, userdefinedtypelist, (void*)fluxloop)) != 0) { - break; + break; } } for (int i = 0; i < efit->nmagprobes; i++) { magprobe = efit->magprobe + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_MAGPROBE, direction, token, logmalloclist, userdefinedtypelist, (void*)magprobe)) != 0) { - break; + break; } } for (int i = 0; i < efit->npfcircuits; i++) { pfcircuit = efit->pfcircuit + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFCIRCUIT, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfcircuit)) != - 0) { + userdefinedtypelist, (void*)pfcircuit)) != 0) { break; } } for (int i = 0; i < efit->nplasmacurrent; i++) { plasmacurrent = efit->plasmacurrent + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PLASMACURRENT, direction, token, logmalloclist, - userdefinedtypelist, (void*)plasmacurrent)) != - 0) { + userdefinedtypelist, (void*)plasmacurrent)) != 0) { break; } } for (int i = 0; i < efit->ndiamagnetic; i++) { diamagnetic = efit->diamagnetic + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_DIAMAGNETIC, direction, token, logmalloclist, - userdefinedtypelist, (void*)diamagnetic)) != - 0) { + userdefinedtypelist, (void*)diamagnetic)) != 0) { break; } } for (int i = 0; i < efit->ntoroidalfield; i++) { toroidalfield = efit->toroidalfield + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_TOROIDALFIELD, direction, token, logmalloclist, - userdefinedtypelist, (void*)toroidalfield)) != - 0) { + userdefinedtypelist, (void*)toroidalfield)) != 0) { break; } } @@ -801,7 +810,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC limiter = efit->limiter + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_LIMITER, direction, token, logmalloclist, userdefinedtypelist, (void*)limiter)) != 0) { - break; + break; } } @@ -818,28 +827,28 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } for (int i = 0; i < efit->npfcoils; i++) { pfcoils = efit->pfcoils + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFCOILS, direction, token, logmalloclist, userdefinedtypelist, (void*)pfcoils)) != 0) { - break; + break; } } for (int i = 0; i < efit->npfpassive; i++) { pfpassive = efit->pfpassive + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFPASSIVE, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfpassive)) != - 0) { + userdefinedtypelist, (void*)pfpassive)) != 0) { break; } } for (int i = 0; i < efit->npfsupplies; i++) { pfsupplies = efit->pfsupplies + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFSUPPLIES, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfsupplies)) != - 0) { + userdefinedtypelist, (void*)pfsupplies)) != 0) { break; } } @@ -847,45 +856,41 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC fluxloop = efit->fluxloop + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_FLUXLOOP, direction, token, logmalloclist, userdefinedtypelist, (void*)fluxloop)) != 0) { - break; + break; } } for (int i = 0; i < efit->nmagprobes; i++) { magprobe = efit->magprobe + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_MAGPROBE, direction, token, logmalloclist, userdefinedtypelist, (void*)magprobe)) != 0) { - break; + break; } } for (int i = 0; i < efit->npfcircuits; i++) { pfcircuit = efit->pfcircuit + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PFCIRCUIT, direction, token, logmalloclist, - userdefinedtypelist, (void*)pfcircuit)) != - 0) { + userdefinedtypelist, (void*)pfcircuit)) != 0) { break; } } for (int i = 0; i < efit->nplasmacurrent; i++) { plasmacurrent = efit->plasmacurrent + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_PLASMACURRENT, direction, token, logmalloclist, - userdefinedtypelist, (void*)plasmacurrent)) != - 0) { + userdefinedtypelist, (void*)plasmacurrent)) != 0) { break; } } for (int i = 0; i < efit->ndiamagnetic; i++) { diamagnetic = efit->diamagnetic + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_DIAMAGNETIC, direction, token, logmalloclist, - userdefinedtypelist, (void*)diamagnetic)) != - 0) { + userdefinedtypelist, (void*)diamagnetic)) != 0) { break; } } for (int i = 0; i < efit->ntoroidalfield; i++) { toroidalfield = efit->toroidalfield + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_TOROIDALFIELD, direction, token, logmalloclist, - userdefinedtypelist, (void*)toroidalfield)) != - 0) { + userdefinedtypelist, (void*)toroidalfield)) != 0) { break; } } @@ -893,7 +898,7 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC limiter = efit->limiter + i; if ((err = protocolXML(xdrs, UDA_PROTOCOL_LIMITER, direction, token, logmalloclist, userdefinedtypelist, (void*)limiter)) != 0) { - break; + break; } } @@ -930,9 +935,13 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfcoils->nco == 0) break; // No Data to Receive! + if (pfcoils->nco == 0) { + break; // No Data to Receive! + } - if ((err = alloc_pfcoils(pfcoils)) != 0) break; // Allocate Heap Memory + if ((err = alloc_pfcoils(pfcoils)) != 0) { + break; // Allocate Heap Memory + } if (!(rc = xdr_pfcoils2(xdrs, pfcoils))) { err = UDA_PROTOCOL_ERROR_1012; @@ -948,14 +957,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfcoils->nco == 0) break; // No Data to Send! + if (pfcoils->nco == 0) { + break; // No Data to Send! + } if (!(rc = xdr_pfcoils2(xdrs, pfcoils))) { err = UDA_PROTOCOL_ERROR_1012; break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -990,9 +1003,13 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfpassive->nco == 0) break; // No Data to Receive! + if (pfpassive->nco == 0) { + break; // No Data to Receive! + } - if ((err = alloc_pfpassive(pfpassive)) != 0) break; // Allocate Heap Memory + if ((err = alloc_pfpassive(pfpassive)) != 0) { + break; // Allocate Heap Memory + } if (!(rc = xdr_pfpassive2(xdrs, pfpassive))) { err = UDA_PROTOCOL_ERROR_1022; @@ -1008,14 +1025,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfpassive->nco == 0) break; // No Data to Send! + if (pfpassive->nco == 0) { + break; // No Data to Send! + } if (!(rc = xdr_pfpassive2(xdrs, pfpassive))) { err = UDA_PROTOCOL_ERROR_1022; break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1059,7 +1080,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1094,9 +1117,13 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (fluxloop->nco == 0) break; // No Data to Receive! + if (fluxloop->nco == 0) { + break; // No Data to Receive! + } - if ((err = alloc_fluxloop(fluxloop)) != 0) break; // Allocate Heap Memory + if ((err = alloc_fluxloop(fluxloop)) != 0) { + break; // Allocate Heap Memory + } if (!(rc = xdr_fluxloop2(xdrs, fluxloop))) { err = UDA_PROTOCOL_ERROR_1042; @@ -1112,14 +1139,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (fluxloop->nco == 0) break; + if (fluxloop->nco == 0) { + break; + } if (!(rc = xdr_fluxloop2(xdrs, fluxloop))) { err = UDA_PROTOCOL_ERROR_1042; break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1163,7 +1194,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1198,9 +1231,13 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfcircuit->nco == 0) break; // No Data to Receive! + if (pfcircuit->nco == 0) { + break; // No Data to Receive! + } - if ((err = alloc_pfcircuit(pfcircuit)) != 0) break; // Allocate Heap Memory + if ((err = alloc_pfcircuit(pfcircuit)) != 0) { + break; // Allocate Heap Memory + } if (!(rc = xdr_pfcircuit2(xdrs, pfcircuit))) { err = UDA_PROTOCOL_ERROR_1062; @@ -1216,14 +1253,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (pfcircuit->nco == 0) break; // No Data to Send! + if (pfcircuit->nco == 0) { + break; // No Data to Send! + } if (!(rc = xdr_pfcircuit2(xdrs, pfcircuit))) { err = UDA_PROTOCOL_ERROR_1062; break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1267,7 +1308,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1311,7 +1354,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1355,7 +1400,9 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1390,9 +1437,13 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (limiter->nco == 0) break; // No Data to Receive! + if (limiter->nco == 0) { + break; // No Data to Receive! + } - if ((err = alloc_limiter(limiter)) != 0) break; // Allocate Heap Memory + if ((err = alloc_limiter(limiter)) != 0) { + break; // Allocate Heap Memory + } if (!(rc = xdr_limiter2(xdrs, limiter))) { err = UDA_PROTOCOL_ERROR_1092; @@ -1408,14 +1459,18 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC break; } - if (limiter->nco == 0) break; // No Data to Send! + if (limiter->nco == 0) { + break; // No Data to Send! + } if (!(rc = xdr_limiter2(xdrs, limiter))) { err = UDA_PROTOCOL_ERROR_1092; break; } - if (!(rc = xdrrec_endofrecord(xdrs, 1))) err = UDA_PROTOCOL_ERROR_7; + if (!(rc = xdrrec_endofrecord(xdrs, 1))) { + err = UDA_PROTOCOL_ERROR_7; + } break; @@ -1431,8 +1486,8 @@ int protocolXML(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOC } # endif #endif // !FATCLIENT - //---------------------------------------------------------------------------- - // End of Error Trap Loop + //---------------------------------------------------------------------------- + // End of Error Trap Loop } while (0); diff --git a/source/clientserver/protocolXML.h b/source/clientserver/protocolXML.h old mode 100755 new mode 100644 index eb62ae53..76ba0523 --- a/source/clientserver/protocolXML.h +++ b/source/clientserver/protocolXML.h @@ -1,18 +1,18 @@ #pragma once #ifndef UDA_CLIENTSERVER_PROTOCOLXML_H -#define UDA_CLIENTSERVER_PROTOCOLXML_H +# define UDA_CLIENTSERVER_PROTOCOLXML_H -#include // this must be included before rpc.h -#include -#include +# include // this must be included before rpc.h +# include +# include -#include "genStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" -#ifdef FATCLIENT -# define protocolXML protocolXMLFat -#endif +# ifdef FATCLIENT +# define protocolXML protocolXMLFat +# endif struct IoData; diff --git a/source/clientserver/protocolXML2.cpp b/source/clientserver/protocolXML2.cpp old mode 100755 new mode 100644 index 65d93edf..e6c96274 --- a/source/clientserver/protocolXML2.cpp +++ b/source/clientserver/protocolXML2.cpp @@ -1,126 +1,124 @@ /*---------------------------------------------------------------------------------------------- -* Client - Server Conversation Protocol for XML based Hierarchical Data Structures -* -* Args: xdrs XDR Stream -* -* protocol_id Client/Server Conversation item: Data Exchange context -* direction Send (0) or Receive (1) or Free (2) -* token current error condition or next protocol or .... exchange token -* -* str Information Structure depending on the protocol id .... -* -* 100 efit -* 101 pfcoils -* 102 pfpassive -* 103 pfsupplies -* 104 fluxloop -* 105 magprobe -* 106 pfcircuit -* 107 plasmacurrent -* 108 diamagnetic -* 109 toroidalfield -* 110 limiter -* -* Returns: error code if failure, otherwise 0 -* -*--------------------------------------------------------------------------------------------------------- -* Notes on Generalised Data Structures: -* -* The DATA_BLOCK structure has the following fields used to pass and receive generalised data structures -* -* data_block->data_type set to UDA_TYPE_COMPOUND (external to this routine) -* data_block->data_n set to the count of structure array elements (external to this routine) -* -* data_block->data sending (server side): set to the data array (external to this routine) -* receiving (client side): set to the root data tree node within this routine -* -* data_block->opaque_type set to UDA_OPAQUE_TYPE_STRUCTURES (external to this routine) -* data_block->count set to 1 (external to this routine). Not Used! -* -* data_block->opaque_block sending (server side): set to the User Defined Data Structure Definition of -* the Data (external to this routine). -* receiving (client side): set to the SARRAY Data Structure Definition -* -* The SARRAY structure has the following: -* -* sarray.count set to the count of structure array elements. Identical to data_block->data_n. -* sarray.rank set to 1 (Higher ranked arrays possible ?) -* sarray.shape set to [sarray.count] for consistency. -* sarray.data set to data_block->data -* sarray.type set to the name of the User Defined Structure type of data -* (data_block->opaque_block->name). This is registered within the Structure -* Type List. -**--------------------------------------------------------------------------------------------------*/ + * Client - Server Conversation Protocol for XML based Hierarchical Data Structures + * + * Args: xdrs XDR Stream + * + * protocol_id Client/Server Conversation item: Data Exchange context + * direction Send (0) or Receive (1) or Free (2) + * token current error condition or next protocol or .... exchange token + * + * str Information Structure depending on the protocol id .... + * + * 100 efit + * 101 pfcoils + * 102 pfpassive + * 103 pfsupplies + * 104 fluxloop + * 105 magprobe + * 106 pfcircuit + * 107 plasmacurrent + * 108 diamagnetic + * 109 toroidalfield + * 110 limiter + * + * Returns: error code if failure, otherwise 0 + * + *--------------------------------------------------------------------------------------------------------- + * Notes on Generalised Data Structures: + * + * The DATA_BLOCK structure has the following fields used to pass and receive generalised data structures + * + * data_block->data_type set to UDA_TYPE_COMPOUND (external to this routine) + * data_block->data_n set to the count of structure array elements (external to this routine) + * + * data_block->data sending (server side): set to the data array (external to this routine) + * receiving (client side): set to the root data tree node within this routine + * + * data_block->opaque_type set to UDA_OPAQUE_TYPE_STRUCTURES (external to this routine) + * data_block->count set to 1 (external to this routine). Not Used! + * + * data_block->opaque_block sending (server side): set to the User Defined Data Structure Definition of + * the Data (external to this routine). + * receiving (client side): set to the SARRAY Data Structure Definition + * + * The SARRAY structure has the following: + * + * sarray.count set to the count of structure array elements. Identical to data_block->data_n. + * sarray.rank set to 1 (Higher ranked arrays possible ?) + * sarray.shape set to [sarray.count] for consistency. + * sarray.data set to data_block->data + * sarray.type set to the name of the User Defined Structure type of data + * (data_block->opaque_block->name). This is registered within the Structure + * Type List. + **--------------------------------------------------------------------------------------------------*/ #include "protocolXML2.h" -#include #include +#include #include "struct.h" -#include #include +#include -#include "readXDRFile.h" #include "errorLog.h" #include "protocol.h" -#include "xdrlib.h" +#include "readXDRFile.h" #include "stringUtils.h" +#include "xdrlib.h" #ifdef SERVERBUILD -# include # include # include +# include #endif #ifndef FATCLIENT # include "udaErrors.h" #endif -#include #include +#include -#define PARTBLOCKINIT 1 -#define PARTBLOCKUPDATE 2 -#define PARTBLOCKOUTPUT 3 +#define PARTBLOCKINIT 1 +#define PARTBLOCKUPDATE 2 +#define PARTBLOCKOUTPUT 3 extern "C" { void sha1Block(unsigned char* block, size_t blockSize, unsigned char* md); int sha1File(char* name, FILE* fh, unsigned char* md); - } -#define MAX_ELEMENT_SHA1 20 +#define MAX_ELEMENT_SHA1 20 -int -protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) +int protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { DATA_BLOCK* data_block; int rc, err = 0, count = 0; #ifndef FATCLIENT - XDR XDRInput; // stdio xdr files + XDR XDRInput; // stdio xdr files XDR XDROutput; #endif bool xdr_stdio_flag = false; FILE* xdrfile = nullptr; - XDR* priorxdrs = xdrs; // Preserve the current stream object + XDR* priorxdrs = xdrs; // Preserve the current stream object std::string temp_file = "/tmp/idamXDRXXXXXX"; char* env = nullptr; - unsigned char md[MAX_ELEMENT_SHA1 + 1]; // SHA1 Hash + unsigned char md[MAX_ELEMENT_SHA1 + 1]; // SHA1 Hash md[MAX_ELEMENT_SHA1] = '\0'; strcpy((char*)md, "12345678901234567890"); int hashSize = MAX_ELEMENT_SHA1; - unsigned char mdr[MAX_ELEMENT_SHA1]; // SHA1 Hash of data received + unsigned char mdr[MAX_ELEMENT_SHA1]; // SHA1 Hash of data received - if ((private_flags & PRIVATEFLAG_XDRFILE) && protocolVersion >= 5) { // Intermediate XDR File, not stream + if ((private_flags & PRIVATEFLAG_XDRFILE) && protocolVersion >= 5) { // Intermediate XDR File, not stream if ((env = getenv("UDA_WORK_DIR")) != nullptr) { // File to record XDR encoded data temp_file = fmt::format("{}/idamXDRXXXXXX", env); @@ -164,12 +162,12 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "Compound Data Structure\n"); UDA_LOG(UDA_LOG_DEBUG, "direction : %d [%d][%d]\n", (int)xdrs->x_op, XDR_ENCODE, XDR_DECODE); - if (xdrs->x_op == XDR_ENCODE) { // Send Data + if (xdrs->x_op == XDR_ENCODE) { // Send Data - SARRAY sarray; // Structure array carrier structure + SARRAY sarray; // Structure array carrier structure SARRAY* psarray = &sarray; - int shape = data_block->data_n; // rank 1 array of dimension lengths - auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition + int shape = data_block->data_n; // rank 1 array of dimension lengths + auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition // Locate the carrier structure definition USERDEFINEDTYPE* u = findUserDefinedType(userdefinedtypelist, "SARRAY", 0); @@ -187,12 +185,12 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "Creating SARRAY carrier structure\n"); initSArray(&sarray); - sarray.count = data_block->data_n; // Number of this structure - sarray.rank = 1; // Array Data Rank? - sarray.shape = &shape; // Only if rank > 1? - sarray.data = (void*)data_block->data; // Pointer to the data to be passed - strcpy(sarray.type, udt->name); // The name of the type - data = (void*)&psarray; // Pointer to the SARRAY array pointer + sarray.count = data_block->data_n; // Number of this structure + sarray.rank = 1; // Array Data Rank? + sarray.shape = &shape; // Only if rank > 1? + sarray.data = (void*)data_block->data; // Pointer to the data to be passed + strcpy(sarray.type, udt->name); // The name of the type + data = (void*)&psarray; // Pointer to the SARRAY array pointer addNonMalloc(logmalloclist, (void*)&shape, 1, sizeof(int), "int"); UDA_LOG(UDA_LOG_DEBUG, "sending Structure Definitions\n"); @@ -201,16 +199,17 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS #ifndef FATCLIENT - // If access is server to server then avoid multiple write/reads of structure components over xdr by creating a - // temporary xdr file or xdr object and passing the file or object. Structures need only be created in the originating client, not the - // intermediate server clients. Control using a global properties flag: private_flags - passed from the originating client - // to all servers along the chain + // If access is server to server then avoid multiple write/reads of structure components over xdr by + // creating a temporary xdr file or xdr object and passing the file or object. Structures need only + // be created in the originating client, not the intermediate server clients. Control using a global + // properties flag: private_flags - passed from the originating client to all servers along the + // chain UDA_LOG(UDA_LOG_DEBUG, "private_flags : %d \n", private_flags); UDA_LOG(UDA_LOG_DEBUG, "protocolVersion: %d \n", protocolVersion); if ((private_flags & PRIVATEFLAG_XDRFILE) && - protocolVersion >= 5) { // Server calling another server + protocolVersion >= 5) { // Server calling another server // Create a temporary or cached XDR file // Record name and location in MEMCACHE @@ -220,7 +219,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS errno = 0; if (mkstemp(temp_file.data()) < 0 || errno != 0) { err = 999; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Obtain a Temporary/Cache File Name"); break; @@ -234,15 +235,15 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "stdio XDR file: %s\n", temp_file.c_str()); - packageType = UDA_PACKAGE_XDRFILE; // The package is a file with XDR serialised data - rc = xdr_int(xdrs, &packageType); // Send data package type + packageType = UDA_PACKAGE_XDRFILE; // The package is a file with XDR serialised data + rc = xdr_int(xdrs, &packageType); // Send data package type rc = rc && xdrrec_endofrecord(xdrs, 1); // Create a stdio file stream xdr_stdio_flag = true; xdrstdio_create(&XDROutput, xdrfile, XDR_ENCODE); - xdrs = &XDROutput; // Switch from TCP stream to file based object + xdrs = &XDROutput; // Switch from TCP stream to file based object } else if ((private_flags & PRIVATEFLAG_XDROBJECT) && protocolVersion >= 7) { @@ -250,26 +251,28 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Write the serialised data into a data object using a stdio xdr stream errno = 0; -#ifndef _WIN32 - object = nullptr; // the data object - objectSize = 0; // the size of the data object +# ifndef _WIN32 + object = nullptr; // the data object + objectSize = 0; // the size of the data object xdrfile = open_memstream((char**)&object, &objectSize); -#else +# else xdrfile = tmpfile(); -#endif +# endif if (xdrfile == nullptr || errno != 0) { err = 999; - if (errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", errno, ""); + if (errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", errno, ""); + } addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML2", err, "Unable to Open a XDR Memory Stream for Writing data objects"); break; } - packageType = UDA_PACKAGE_XDROBJECT; // The package is an XDR serialised object + packageType = UDA_PACKAGE_XDROBJECT; // The package is an XDR serialised object - rc = xdr_int(xdrs, &packageType); // Send data package type + rc = xdr_int(xdrs, &packageType); // Send data package type rc = rc && xdrrec_endofrecord(xdrs, 1); UDA_LOG(UDA_LOG_DEBUG, "Sending Package Type: %d\n", packageType); @@ -278,9 +281,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS xdr_stdio_flag = true; xdrstdio_create(&XDROutput, xdrfile, XDR_ENCODE); - xdrs = &XDROutput; // Switch from TCP stream to memory based object + xdrs = &XDROutput; // Switch from TCP stream to memory based object -#ifdef _WIN32 +# ifdef _WIN32 fflush(xdrfile); fseek(xdrfile, 0, SEEK_END); long fsize = ftell(xdrfile); @@ -289,16 +292,15 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS objectSize = (size_t)fsize; object = (unsigned char*)malloc(objectSize); fread(object, objectSize, 1, xdrfile); -#endif +# endif } else { - packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR + packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR UDA_LOG(UDA_LOG_DEBUG, "Sending Package Type: %d\n", packageType); - rc = xdr_int(xdrs, &packageType); // Send data package type + rc = xdr_int(xdrs, &packageType); // Send data package type rc = rc && xdrrec_endofrecord(xdrs, 1); - } #endif @@ -314,17 +316,19 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Bad Return Code passing Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; - if (xdrfile != nullptr) fclose(xdrfile); + if (xdrfile != nullptr) { + fclose(xdrfile); + } } break; } - rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, u, - (void**)data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // send the Data + rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, u, (void**)data, + protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // send the Data UDA_LOG(UDA_LOG_DEBUG, "Data sent: rc = %d\n", rc); @@ -333,10 +337,12 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Bad Return Code passing data structures"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; - if (xdrfile != nullptr) fclose(xdrfile); + if (xdrfile != nullptr) { + fclose(xdrfile); + } } break; } @@ -344,7 +350,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS #ifndef FATCLIENT if ((private_flags & PRIVATEFLAG_XDRFILE) && - protocolVersion >= 5) { // Server calling another server + protocolVersion >= 5) { // Server calling another server // Close the stream and file @@ -352,7 +358,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Switch back to the normal TCP socket xdr stream - xdr_destroy(xdrs); // Close the stdio stream + xdr_destroy(xdrs); // Close the stdio stream xdrs = priorxdrs; xdr_stdio_flag = false; @@ -362,14 +368,16 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "sending temporary XDR file\n"); - err = sendXDRFile(xdrs, temp_file.c_str()); // Read and send + err = sendXDRFile(xdrs, temp_file.c_str()); // Read and send remove(temp_file.c_str()); - if (err != 0) break; + if (err != 0) { + break; + } } else if ((private_flags & PRIVATEFLAG_XDROBJECT) && - protocolVersion >= 7) { // Server calling another server + protocolVersion >= 7) { // Server calling another server // Close the stream and file @@ -390,7 +398,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Switch back to the normal TCP socket xdr stream - xdr_destroy(xdrs); // Close the stdio stream + xdr_destroy(xdrs); // Close the stdio stream xdrs = priorxdrs; xdr_stdio_flag = false; @@ -404,54 +412,63 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Send size, bytes, hash count = (int)objectSize; - rc = xdr_int(xdrs, &count) - && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) - && xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); + rc = xdr_int(xdrs, &count) && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) && + xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); rc = rc && xdrrec_endofrecord(xdrs, 1); // Free data object - if (object != nullptr) free(object); + if (object != nullptr) { + free(object); + } object = nullptr; objectSize = 0; - if (err != 0) break; + if (err != 0) { + break; + } -// dgm BUG 12/3/2015 - } //else + // dgm BUG 12/3/2015 + } // else -#endif // !FATCLIENT +#endif // !FATCLIENT -//====================================================================================================================== + //====================================================================================================================== - } else { // Receive Data + } else { // Receive Data UDA_LOG(UDA_LOG_DEBUG, "Receiving from Server\n"); -// 5 valid options: -// 1> unpack structures, no xdr file involved => private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_STRUCTDATA -// 2> unpack structures, from an xdr file => private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_XDRFILE -// 3> xdr file only, no unpacking, passforward => private_flags & PRIVATEFLAG_XDRFILE && packageType == PACKAGE_XDRFILE -// 4> Error => private_flags & PRIVATEFLAG_XDRFILE && (packageType == PACKAGE_STRUCTDATA || packageType == PACKAGE_XDROBJECT) -// 5> unpack structures, from an xdr object => private_flags & PRIVATEFLAG_XDROBJECT == 0 && packageType == PACKAGE_XDROBJECT -// 6> xdr object only, no unpacking, passforward => private_flags & PRIVATEFLAG_XDROBJECT && packageType == PACKAGE_XDROBJECT -// 4> Error => private_flags & PRIVATEFLAG_XDROBJECT && (packageType == PACKAGE_STRUCTDATA || packageType == PACKAGE_XDRFILE) - -// Data Object Caching rules: -// a) on send if the server is the origin of the data [what state variable flags this? Always when data are Not from an IDAM client plugin!] -// b) on receipt if a client that is the origin of the request [what state variable flags this? Not an IDAM client plugin!] -// c) no caching on intermediate servers: 2 cache updates only - 1x client and 1x server - -// Server plugins have a cachePermission property. All IDAM client plugins that chain servers together should have this property set False. This should be -// passed into the IDAM client environment to disable caching. The original client will have this set 'True' by default. The server will also act on -// this plugin property. -// -// setIdamCachePermission([T|F]); - -// Caching should be made on return from a plugin. All services are assumed to be plugin based. -// All enquiries against a cache should be made as early as possible. - -// A complete data object in serialised form should be cached. + // 5 valid options: + // 1> unpack structures, no xdr file involved => private_flags & PRIVATEFLAG_XDRFILE == 0 && + // packageType == PACKAGE_STRUCTDATA 2> unpack structures, from an xdr file => + // private_flags & PRIVATEFLAG_XDRFILE == 0 && packageType == PACKAGE_XDRFILE 3> xdr file only, + // no unpacking, passforward => private_flags & PRIVATEFLAG_XDRFILE && packageType == + // PACKAGE_XDRFILE 4> Error => private_flags & PRIVATEFLAG_XDRFILE && + // (packageType == PACKAGE_STRUCTDATA || packageType == PACKAGE_XDROBJECT) 5> unpack structures, + // from an xdr object => private_flags & PRIVATEFLAG_XDROBJECT == 0 && packageType == + // PACKAGE_XDROBJECT 6> xdr object only, no unpacking, passforward => private_flags & + // PRIVATEFLAG_XDROBJECT && packageType == PACKAGE_XDROBJECT 4> Error => + // private_flags & PRIVATEFLAG_XDROBJECT && (packageType == PACKAGE_STRUCTDATA || + // packageType == PACKAGE_XDRFILE) + + // Data Object Caching rules: + // a) on send if the server is the origin of the data [what state variable flags this? Always when + // data are Not from an IDAM client plugin!] b) on receipt if a client that is the origin of the + // request [what state variable flags this? Not an IDAM client plugin!] c) no caching on + // intermediate servers: 2 cache updates only - 1x client and 1x server + + // Server plugins have a cachePermission property. All IDAM client plugins that chain servers + // together should have this property set False. This should be passed into the IDAM client + // environment to disable caching. The original client will have this set 'True' by default. The + // server will also act on this plugin property. + // + // setIdamCachePermission([T|F]); + + // Caching should be made on return from a plugin. All services are assumed to be plugin based. + // All enquiries against a cache should be made as early as possible. + + // A complete data object in serialised form should be cached. int option = 4; @@ -459,7 +476,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "Receiving Package Type\n"); rc = xdrrec_skiprecord(xdrs); - rc = rc && xdr_int(xdrs, &packageType); // Receive data package type + rc = rc && xdr_int(xdrs, &packageType); // Receive data package type #else rc = 1; @@ -475,13 +492,15 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } #endif - if ((private_flags & PRIVATEFLAG_XDRFILE) == 0 && packageType == UDA_PACKAGE_STRUCTDATA) option = 1; + if ((private_flags & PRIVATEFLAG_XDRFILE) == 0 && packageType == UDA_PACKAGE_STRUCTDATA) { + option = 1; + } if ((private_flags & PRIVATEFLAG_XDRFILE) == 0 && packageType == UDA_PACKAGE_XDRFILE && protocolVersion >= 5) { option = 2; } - if ((private_flags & PRIVATEFLAG_XDRFILE) == PRIVATEFLAG_XDRFILE && packageType == UDA_PACKAGE_XDRFILE && - protocolVersion >= 5) { + if ((private_flags & PRIVATEFLAG_XDRFILE) == PRIVATEFLAG_XDRFILE && + packageType == UDA_PACKAGE_XDRFILE && protocolVersion >= 5) { option = 3; } if ((private_flags & PRIVATEFLAG_XDROBJECT) == 0 && packageType == UDA_PACKAGE_XDROBJECT && @@ -500,8 +519,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS if (option == 4) { err = 999; - addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, - "Unknown package Type control option"); + addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, "Unknown package Type control option"); break; } @@ -515,7 +533,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS errno = 0; if (mkstemp(temp_file.data()) < 0 || errno != 0) { err = 998; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, "Unable to Obtain a Temporary File Name [3]"); err = 998; @@ -525,13 +545,16 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file + err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file - if (err != 0) break; + if (err != 0) { + break; + } - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = strdup(temp_file.c_str()); // File name - data_block->opaque_type = UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = strdup(temp_file.c_str()); // File name + data_block->opaque_type = + UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only // The temporary file is essentially cached // The opaque type has been changed so the future receiving server or client knows what it is @@ -547,28 +570,33 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS rc = rc && xdr_int(xdrs, &count); objectSize = (size_t)count; - if (rc) object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + if (rc) { + object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + } - rc = rc && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) - && xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); + rc = rc && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) && + xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = (void*)object; // data object (needs to be freed when the Data_Block is sent) + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = + (void*)object; // data object (needs to be freed when the Data_Block is sent) data_block->opaque_count = (int)objectSize; data_block->opaque_type = UDA_OPAQUE_TYPE_XDROBJECT; - //data_block->hash = md; + // data_block->hash = md; // Check the hash sha1Block(object, objectSize, mdr); rc = 1; - for (int i = 0; i < MAX_ELEMENT_SHA1; i++) rc = rc && (md[i] == mdr[i]); + for (int i = 0; i < MAX_ELEMENT_SHA1; i++) { + rc = rc && (md[i] == mdr[i]); + } if (!rc) { // ERROR } - // The opaque type has been changed so the future receiving server or client knows what it is and how to de-serialise it. - + // The opaque type has been changed so the future receiving server or client knows what it is + // and how to de-serialise it. } // Unpack data structures @@ -597,7 +625,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS errno = 0; if (mkstemp(temp_file.data()) < 0 || errno != 0) { err = 997; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Obtain a Temporary File Name [2]"); err = 997; @@ -607,11 +637,11 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file + err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file // Create input xdr file stream - if ((xdrfile = fopen(temp_file.c_str(), "rb")) == nullptr) { // Read temporary file + if ((xdrfile = fopen(temp_file.c_str(), "rb")) == nullptr) { // Read temporary file err = 999; addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Open a Temporary XDR File for Writing"); @@ -620,7 +650,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS xdr_stdio_flag = true; xdrstdio_create(&XDRInput, xdrfile, XDR_DECODE); - xdrs = &XDRInput; // Switch from stream to file + xdrs = &XDRInput; // Switch from stream to file } else if (option == 5) { @@ -632,15 +662,19 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS rc = rc && xdr_int(xdrs, &count); objectSize = (size_t)count; - if (rc) object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + if (rc) { + object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + } - rc = rc && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) - && xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); + rc = rc && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize) && + xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); // Check the hash sha1Block(object, objectSize, mdr); rc = 1; - for (int i = 0; i < MAX_ELEMENT_SHA1; i++) rc = rc && (md[i] == mdr[i]); + for (int i = 0; i < MAX_ELEMENT_SHA1; i++) { + rc = rc && (md[i] == mdr[i]); + } if (!rc) { // ERROR } @@ -649,8 +683,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS xdr_stdio_flag = true; xdrmem_create(&XDRInput, (char*)object, (unsigned int)objectSize, XDR_DECODE); - xdrs = &XDRInput; // Switch from TCP stream to memory based object - + xdrs = &XDRInput; // Switch from TCP stream to memory based object } #endif @@ -664,10 +697,12 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; - if (xdrfile != nullptr) fclose(xdrfile); + if (xdrfile != nullptr) { + fclose(xdrfile); + } } break; } @@ -675,9 +710,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS UDA_LOG(UDA_LOG_DEBUG, "xdrUserDefinedTypeData #A\n"); initUserDefinedType(udt_received); - rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // receive the Data + rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, &data, + protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data UDA_LOG(UDA_LOG_DEBUG, "xdrUserDefinedTypeData #B\n"); if (!rc) { @@ -685,10 +720,12 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Data and Structure Definition"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; - if (xdrfile != nullptr) fclose(xdrfile); + if (xdrfile != nullptr) { + fclose(xdrfile); + } } break; } @@ -703,7 +740,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Switch back to the normal xdr record stream - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; @@ -714,31 +751,33 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Switch back to the normal xdr record stream - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; // Free the object - if (object != nullptr) free(object); + if (object != nullptr) { + free(object); + } object = nullptr; objectSize = 0; } -#endif // !FATCLIENT +#endif // !FATCLIENT - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, - "Inconsistent S Array Counts"); + addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Inconsistent S Array Counts"); break; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = + (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; general_block->userdefinedtype = udt_received; general_block->userdefinedtypelist = userdefinedtypelist; @@ -756,17 +795,18 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS #ifdef FATCLIENT - } else { - err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Unknown Opaque type"); - break; - } + } else { + err = 999; + addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Unknown Opaque type"); + break; } + } #else //==================================================================================================================== - // Passing temporary XDR files or objects: server to server (protocolVersion >= 5 && packageType == PACKAGE_XDRFILE) + // Passing temporary XDR files or objects: server to server (protocolVersion >= 5 && packageType == + // PACKAGE_XDRFILE) } else { @@ -777,15 +817,17 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Send size, bytes, hash - rc = xdr_int(xdrs, &(data_block->opaque_count)) - && xdr_opaque(xdrs, (char*)data_block->opaque_block, data_block->opaque_count) - && xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char) - && xdrrec_endofrecord(xdrs, 1); + rc = xdr_int(xdrs, &(data_block->opaque_count)) && + xdr_opaque(xdrs, (char*)data_block->opaque_block, data_block->opaque_count) && + xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char) && + xdrrec_endofrecord(xdrs, 1); // Check the hash sha1Block(object, objectSize, mdr); rc = 1; - for (int i = 0; i < MAX_ELEMENT_SHA1; i++) rc = rc && (md[i] == mdr[i]); + for (int i = 0; i < MAX_ELEMENT_SHA1; i++) { + rc = rc && (md[i] == mdr[i]); + } if (!rc) { // ERROR } @@ -800,7 +842,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS rc = rc && xdr_int(xdrs, &count); objectSize = (size_t)count; - if (rc) object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + if (rc) { + object = (unsigned char*)malloc(objectSize * sizeof(unsigned char)); + } rc = rc && xdr_opaque(xdrs, (char*)object, (unsigned int)objectSize); rc = rc && xdr_vector(xdrs, (char*)md, hashSize, sizeof(char), (xdrproc_t)xdr_char); @@ -808,15 +852,18 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Check the hash sha1Block(object, objectSize, mdr); rc = 1; - for (int i = 0; i < MAX_ELEMENT_SHA1; i++) rc = rc && (md[i] == mdr[i]); + for (int i = 0; i < MAX_ELEMENT_SHA1; i++) { + rc = rc && (md[i] == mdr[i]); + } if (!rc) { // ERROR } - if (private_flags & PRIVATEFLAG_XDROBJECT) { // Forward the object again + if (private_flags & PRIVATEFLAG_XDROBJECT) { // Forward the object again - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = (void*)object; // data object (needs to be freed when the Data_Block is sent) + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = + (void*)object; // data object (needs to be freed when the Data_Block is sent) data_block->opaque_count = (int)objectSize; data_block->opaque_type = UDA_OPAQUE_TYPE_XDROBJECT; @@ -838,7 +885,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS xdr_stdio_flag = true; xdrmem_create(&XDRInput, (char*)object, (unsigned int)objectSize, XDR_DECODE); - xdrs = &XDRInput; // Switch from TCP stream to memory based object + xdrs = &XDRInput; // Switch from TCP stream to memory based object // receive the full set of known named structures rc = xdr_userdefinedtypelist(xdrs, userdefinedtypelist, xdr_stdio_flag); @@ -848,7 +895,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -858,15 +905,15 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS initUserDefinedType(udt_received); rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // receive the Data + &data, protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data if (!rc) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Data and Structure Definition"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -875,7 +922,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Close the stream - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; @@ -884,18 +931,19 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Regular client or server if (STR_EQUALS(udt_received->name, - "SARRAY")) { // expecting this carrier structure + "SARRAY")) { // expecting this carrier structure GENERAL_BLOCK* general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); SARRAY* s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Inconsistent S Array Counts"); break; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = (char*) + udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; general_block->userdefinedtype = udt_received; @@ -915,7 +963,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } else if (data_block->opaque_type == UDA_OPAQUE_TYPE_XDRFILE) { if (xdrs->x_op == XDR_ENCODE) { UDA_LOG(UDA_LOG_DEBUG, "Forwarding XDR File %s\n", (char*)data_block->opaque_block); - err = sendXDRFile(xdrs, (char*)data_block->opaque_block); // Forward the xdr file + err = sendXDRFile(xdrs, (char*)data_block->opaque_block); // Forward the xdr file } else { UDA_LOG(UDA_LOG_DEBUG, "Receiving forwarded XDR File\n"); @@ -924,7 +972,9 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS errno = 0; if (mkstemp(temp_file.data()) < 0 || errno != 0) { err = 996; - if (errno != 0) err = errno; + if (errno != 0) { + err = errno; + } addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Obtain a Temporary File Name"); err = 996; @@ -934,15 +984,16 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS break; } - err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file + err = receiveXDRFile(xdrs, temp_file.c_str()); // Receive and write the file - if (private_flags & PRIVATEFLAG_XDRFILE) { // Forward the file (option 3) again + if (private_flags & PRIVATEFLAG_XDRFILE) { // Forward the file (option 3) again // If this is an intermediate client then read the file without unpacking the structures - data_block->data = nullptr; // No Data - not unpacked - data_block->opaque_block = strdup(temp_file.c_str()); // File name - data_block->opaque_type = UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only + data_block->data = nullptr; // No Data - not unpacked + data_block->opaque_block = strdup(temp_file.c_str()); // File name + data_block->opaque_type = + UDA_OPAQUE_TYPE_XDRFILE; // The data block is carrying the filename only UDA_LOG(UDA_LOG_DEBUG, "Forwarding Received forwarded XDR File\n"); } else { @@ -960,7 +1011,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Create input xdr file stream - if ((xdrfile = fopen(temp_file.c_str(), "rb")) == nullptr) { // Read temporary file + if ((xdrfile = fopen(temp_file.c_str(), "rb")) == nullptr) { // Read temporary file err = 999; addIdamError(UDA_SYSTEM_ERROR_TYPE, "protocolXML", err, " Unable to Open a Temporary XDR File for Writing"); @@ -979,7 +1030,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -989,15 +1040,15 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS initUserDefinedType(udt_received); rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, - log_struct_list, malloc_source); // receive the Data + &data, protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data if (!rc) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Failure receiving Data and Structure Definition"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -1006,7 +1057,7 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Close the stream and file - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; @@ -1018,17 +1069,18 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS // Regular client or server if (STR_EQUALS(udt_received->name, - "SARRAY")) { // expecting this carrier structure + "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML", err, "Inconsistent S Array Counts"); break; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = (char*) + udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; general_block->userdefinedtype = udt_received; @@ -1067,8 +1119,8 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS err = UDA_PROTOCOL_ERROR_5; break; } - if ((data_block->opaque_block = (char*)malloc( - (data_block->opaque_count + 1) * sizeof(char))) == nullptr) { + if ((data_block->opaque_block = (char*)malloc((data_block->opaque_count + 1) * sizeof(char))) == + nullptr) { err = 991; break; } @@ -1103,8 +1155,8 @@ protocolXML2(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIS } #endif - //---------------------------------------------------------------------------- - // End of Error Trap Loop + //---------------------------------------------------------------------------- + // End of Error Trap Loop } while (0); @@ -1130,7 +1182,7 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena void* data = nullptr; XDR XDRInput; FILE* xdrfile = nullptr; - XDR* priorxdrs = xdrs; // Preserve the current stream object + XDR* priorxdrs = xdrs; // Preserve the current stream object UDA_LOG(UDA_LOG_DEBUG, "unpackXDRFile: Unpacking XDR Data Files\n"); @@ -1146,7 +1198,7 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena // Close current input xdr stream and create a file stream - if ((xdrfile = fopen((char*)filename, "rb")) == nullptr) { // Read temporary file + if ((xdrfile = fopen((char*)filename, "rb")) == nullptr) { // Read temporary file err = 999; addIdamError(UDA_SYSTEM_ERROR_TYPE, "unpackXDRFile", err, " Unable to Open a XDR File for Reading"); return err; @@ -1154,9 +1206,9 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena xdr_stdio_flag = true; xdrstdio_create(&XDRInput, xdrfile, XDR_DECODE); - xdrs = &XDRInput; // Switch from stream to file + xdrs = &XDRInput; // Switch from stream to file - do { // Error trap + do { // Error trap // Unpack the associated set of named structures @@ -1164,10 +1216,9 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena if (!rc) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRFile", err, - "Failure receiving Structure Definitions"); + addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRFile", err, "Failure receiving Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -1183,10 +1234,9 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena if (!rc) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRFile", err, - "Failure receiving Data and Structure Definition"); + addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRFile", err, "Failure receiving Data and Structure Definition"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -1206,22 +1256,24 @@ int unpackXDRFile(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* filena xdrs = priorxdrs; xdr_stdio_flag = false; - if (err != 0) return err; + if (err != 0) { + return err; + } // Return data tree - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRFile", err, "Inconsistent SARRAY Counts"); return err; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; general_block->userdefinedtype = udt_received; @@ -1246,7 +1298,7 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje int rc = 1, err = 0; void* data = nullptr; XDR XDRInput; - XDR* priorxdrs = xdrs; // Preserve the current stream object + XDR* priorxdrs = xdrs; // Preserve the current stream object UDA_LOG(UDA_LOG_DEBUG, "unpackXDRObject: Unpacking XDR Data Object\n"); @@ -1266,7 +1318,7 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje xdrmem_create(&XDRInput, (char*)object, (unsigned int)objectSize, XDR_DECODE); xdrs = &XDRInput; - do { // Error trap + do { // Error trap // Unpack the associated set of named structures @@ -1274,10 +1326,9 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje if (!rc) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, - "Failure receiving Structure Definitions"); + addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, "Failure receiving Structure Definitions"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -1296,7 +1347,7 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, "Failure receiving Data and Structure Definition"); if (xdr_stdio_flag) { - xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream + xdr_destroy(xdrs); // Close the stdio stream and reuse the TCP socket stream xdrs = priorxdrs; xdr_stdio_flag = false; } @@ -1311,22 +1362,24 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje xdrs = priorxdrs; xdr_stdio_flag = false; - if (err != 0) return err; + if (err != 0) { + return err; + } // Return data tree - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, "Inconsistent SARRAY Counts"); return err; } - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data data_block->opaque_block = (void*)general_block; data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; general_block->userdefinedtype = udt_received; @@ -1336,8 +1389,7 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje } else { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, - "Name of Received Data Structure Incorrect"); + addIdamError(UDA_CODE_ERROR_TYPE, "unpackXDRObject", err, "Name of Received Data Structure Incorrect"); return err; } @@ -1348,30 +1400,31 @@ int unpackXDRObject(LOGMALLOCLIST* logmalloclist, XDR* xdrs, unsigned char* obje // Serialise a regular Data_Block structure // Write to a memory block - the data object - using a memory stream -int -packXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* data_block, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, - unsigned int private_flags, int malloc_source) +int packXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* data_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, + LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) { int err = 0; XDR xdrObject; FILE* xdrfile = nullptr; -#ifdef CACHEDEV - if(data_block->totalDataBlockSize > 1000000 || data_block->data_type == UDA_TYPE_UNKNOWN) return 0; // Size is too large and the type is not Atomic -#endif +# ifdef CACHEDEV + if (data_block->totalDataBlockSize > 1000000 || data_block->data_type == UDA_TYPE_UNKNOWN) { + return 0; // Size is too large and the type is not Atomic + } +# endif do { errno = 0; -#ifndef _WIN32 +# ifndef _WIN32 xdrfile = open_memstream((char**)&object, &objectSize); -#else +# else xdrfile = tmpfile(); fwrite(object, objectSize, 1, xdrfile); fflush(xdrfile); rewind(xdrfile); -#endif +# endif if (xdrfile == nullptr || errno != 0) { err = 999; @@ -1412,15 +1465,17 @@ packXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* dat // Deserialise a regular Data_Block structure // Read from a memory block - the data object - using a memory stream -int -unpackXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* data_block, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, - unsigned int private_flags, int malloc_source) +int unpackXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* data_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, + int malloc_source) { int err = 0; XDR xdrObject; - if (objectSize > 1000000) return 0; // Check type is Atomic + if (objectSize > 1000000) { + return 0; // Check type is Atomic + } do { @@ -1435,8 +1490,9 @@ unpackXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* d DATA_BLOCK_LIST data_block_list; data_block_list.count = 1; data_block_list.data = data_block; - err = protocol2(&xdrObject, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, - &data_block_list, protocolVersion, log_struct_list, private_flags, malloc_source); + err = protocol2(&xdrObject, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_RECEIVE, nullptr, logmalloclist, + userdefinedtypelist, &data_block_list, protocolVersion, log_struct_list, private_flags, + malloc_source); // Close the stream @@ -1447,4 +1503,4 @@ unpackXDRDataBlockObject(unsigned char* object, size_t objectSize, DATA_BLOCK* d return err; } -#endif // !FATCLIENT +#endif // !FATCLIENT diff --git a/source/clientserver/protocolXML2.h b/source/clientserver/protocolXML2.h old mode 100755 new mode 100644 index 453d00cd..edd41779 --- a/source/clientserver/protocolXML2.h +++ b/source/clientserver/protocolXML2.h @@ -1,10 +1,10 @@ #ifndef UDA_CLIENTSERVER_PROTOCOLXML2_H #define UDA_CLIENTSERVER_PROTOCOLXML2_H -#include -#include -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include +#include #ifdef __cplusplus extern "C" { @@ -23,4 +23,3 @@ LIBRARY_API int protocolXML2(XDR* xdrs, int protocol_id, int direction, int* tok #endif #endif // UDA_CLIENTSERVER_PROTOCOLXML2_H - diff --git a/source/clientserver/protocolXML2Put.cpp b/source/clientserver/protocolXML2Put.cpp old mode 100755 new mode 100644 index c5b2a45b..1488b062 --- a/source/clientserver/protocolXML2Put.cpp +++ b/source/clientserver/protocolXML2Put.cpp @@ -2,26 +2,26 @@ #include -#include #include "struct.h" -#include #include "udaErrors.h" +#include +#include #include "errorLog.h" -#include "xdrlib.h" -#include "stringUtils.h" #include "protocol.h" +#include "stringUtils.h" +#include "xdrlib.h" #ifdef SERVERBUILD # include #endif -static int recursiveDepthPut = 0; // Keep count of recursive calls +static int recursiveDepthPut = 0; // Keep count of recursive calls int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* log_struct_list, - USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, - void** data, int datacount, int structRank, - int* structShape, int index, NTREE** NTree, int protocolVersion, int malloc_source) + USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, void** data, + int datacount, int structRank, int* structShape, int index, NTREE** NTree, + int protocolVersion, int malloc_source) { // Grow the data tree recursively through pointer elements within individual structures // Build a linked list tree structure when receiving data. @@ -31,14 +31,14 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST int rc = 1, id, loopcount, rank, count, size, passdata = 0, isSOAP; int* shape; - char* p0, * d; + char *p0, *d; const char* type; - char rudtype[MAXELEMENTNAME]; // Received name of the user defined type + char rudtype[MAXELEMENTNAME]; // Received name of the user defined type const char* chartype = "char"; - VOIDTYPE* p; // Type Needs to be the same size as a local pointer, e.g., int* on 32 and long long* on 64 bit - VOIDTYPE* prev = nullptr; // Pointer to previous structure element (need to manage SOAP data bindings) + VOIDTYPE* p; // Type Needs to be the same size as a local pointer, e.g., int* on 32 and long long* on 64 bit + VOIDTYPE* prev = nullptr; // Pointer to previous structure element (need to manage SOAP data bindings) USERDEFINEDTYPE* utype = nullptr; @@ -51,11 +51,15 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST rc = xdr_int(xdrs, &passdata); } else { passdata = 0; - if (data != nullptr) passdata = *(int**)data != nullptr; + if (data != nullptr) { + passdata = *(int**)data != nullptr; + } rc = xdr_int(xdrs, &passdata); } - if (!passdata) return rc; + if (!passdata) { + return rc; + } // If the recursive depth is too large then perhaps an infinite loop is in play! @@ -67,12 +71,12 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST UDA_LOG(UDA_LOG_DEBUG, "xdrUserDefinedData Depth: %d\n", recursiveDepthPut); // Allocate HEAP if receiving Data: - // Size of Structure or atomic type array or scalar is provided by the structure definition (corrected for alignment and architecture) - // datacount, rank and shape are passed via the argument - it's the number of structure array elements to allocate in a single block - // Index is the element of the structure array to be received - // Allocation occurs only when index == 0, i.e. the first time the function is entered. Rank and shape of structured data are captured. - // Allocation occurs only when datacount > 0, i.e. Must be a Pointer to a User Defined Type Structure: Otherwise it's already - // allocated - but must add a tree node to the structure element. + // Size of Structure or atomic type array or scalar is provided by the structure definition (corrected for alignment + // and architecture) datacount, rank and shape are passed via the argument - it's the number of structure array + // elements to allocate in a single block Index is the element of the structure array to be received Allocation + // occurs only when index == 0, i.e. the first time the function is entered. Rank and shape of structured data are + // captured. Allocation occurs only when datacount > 0, i.e. Must be a Pointer to a User Defined Type Structure: + // Otherwise it's already allocated - but must add a tree node to the structure element. // // Child nodes of the same type are branched consequentially @@ -91,16 +95,15 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST structRank = 0; } - newNTree = (NTREE*)malloc(sizeof(NTREE)); // this is the parent node for the received structure + newNTree = (NTREE*)malloc(sizeof(NTREE)); // this is the parent node for the received structure // dgm 15Nov2011 addMalloc(logmalloclist, (void*)newNTree, 1, sizeof(NTREE), "NTREE"); - *NTree = newNTree; // Return the new tree node address + *NTree = newNTree; // Return the new tree node address initNTree(newNTree); newNTree->data = nullptr; - newNTree->userdefinedtype = userdefinedtype; // preserve Pairing of data and data type - + newNTree->userdefinedtype = userdefinedtype; // preserve Pairing of data and data type } // Start of the Structure Array Element @@ -109,7 +112,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST if (xdrs->x_op == XDR_DECODE) { newNTree->data = (void*)p0; - } // Each tree node points to a structure or an atomic array + } // Each tree node points to a structure or an atomic array // Loop over all structure elements: Send or Receive @@ -120,13 +123,13 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - p = (VOIDTYPE*)&p0[userdefinedtype->compoundfield[j].offset]; // the Element's location + p = (VOIDTYPE*)&p0[userdefinedtype->compoundfield[j].offset]; // the Element's location - if (xdrs->x_op == XDR_DECODE && userdefinedtype->compoundfield[j].pointer) { // Initialise - *p = 0; // nullptr pointer: to be allocated on heap + if (xdrs->x_op == XDR_DECODE && userdefinedtype->compoundfield[j].pointer) { // Initialise + *p = 0; // nullptr pointer: to be allocated on heap } - type = nullptr; // Reset pointer attributes + type = nullptr; // Reset pointer attributes d = nullptr; count = 0; size = 0; @@ -141,15 +144,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST UDA_LOG(UDA_LOG_DEBUG, "Type: FLOAT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; @@ -157,27 +161,32 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST d = (char*)malloc(count * sizeof(float)); addMalloc2(logmalloclist, (void*)d, count, sizeof(float), "float", rank, shape); *p = (VOIDTYPE)d; - } else { break; } - if (!rc)break; + } else { + break; + } + if (!rc) { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume 0 means No Pointer data to send! + &shape); // Assume 0 means No Pointer data to send! // Allocation of pointer data within SOAP is problematic. // Data malloc'd within SOAP are typed "unknown". - // Generally, pointer class data are preceded within the data binding structures with integer elements - // named __size followed by the name of the element. The value stored by this element is the equivalent - // of the count parameter required from findMalloc. + // Generally, pointer class data are preceded within the data binding structures with integer + // elements named __size followed by the name of the element. The value stored by this element + // is the equivalent of the count parameter required from findMalloc. // // Other data creators, e.g., XML DOM, also have types "unknown" - // In these cases, a best guess is made to the type and count based on expectations and the heap allocated - very unsatisfactory! + // In these cases, a best guess is made to the type and count based on expectations and the heap + // allocated - very unsatisfactory! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -185,17 +194,17 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(float); type = userdefinedtype->compoundfield[j].type; } else { if (count > 0) { - int totalsize = count * size; // from the malloc log - int rcount = totalsize % sizeof(float); // array element count remainder - size = sizeof(float); // element size - count = totalsize / size; // array element count + int totalsize = count * size; // from the malloc log + int rcount = totalsize % sizeof(float); // array element count remainder + size = sizeof(float); // element size + count = totalsize / size; // array element count - if (rcount != 0) { // there should be no remainder + if (rcount != 0) { // there should be no remainder addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Specified malloc total size not integer multiple!"); count = 0; @@ -212,17 +221,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(float), (xdrproc_t)xdr_float); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size rc = rc && xdr_float(xdrs, (float*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(float), (xdrproc_t)xdr_float); } @@ -233,33 +241,36 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_DOUBLE: { UDA_LOG(UDA_LOG_DEBUG, "Type: DOUBLE\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Double Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Double Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(double)); addMalloc2(logmalloclist, (void*)d, count, sizeof(double), "double", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -267,7 +278,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(double); type = userdefinedtype->compoundfield[j].type; @@ -295,18 +306,17 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(double), - (xdrproc_t)xdr_double); // Send or Receive data + (xdrproc_t)xdr_double); // Send or Receive data } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size rc = rc && xdr_double(xdrs, (double*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(double), (xdrproc_t)xdr_double); } @@ -317,32 +327,35 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_SHORT: { UDA_LOG(UDA_LOG_DEBUG, "Type: SHORT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Short Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Short Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(short)); addMalloc2(logmalloclist, (void*)d, count, sizeof(short), "short", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -350,7 +363,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(short); type = userdefinedtype->compoundfield[j].type; } else { @@ -377,17 +390,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(short), (xdrproc_t)xdr_short); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_short(xdrs, (short*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(short), (xdrproc_t)xdr_short); } @@ -398,15 +410,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_UNSIGNED_SHORT: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED_SHORT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; @@ -414,17 +427,19 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST d = (char*)malloc(count * sizeof(unsigned short)); addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned short), "unsigned short", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -432,7 +447,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned short); type = userdefinedtype->compoundfield[j].type; @@ -444,8 +459,9 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST count = totalsize / size; if (rcount != 0) { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "Specified unsigned short malloc total size not integer multiple!"); + addIdamError( + UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, + "Specified unsigned short malloc total size not integer multiple!"); count = 0; } } @@ -460,17 +476,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned short), (xdrproc_t)xdr_u_short); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_u_short(xdrs, (unsigned short*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(unsigned short), (xdrproc_t)xdr_u_short); } @@ -481,32 +496,35 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_INT: { UDA_LOG(UDA_LOG_DEBUG, "Type: INT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Integer Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Integer Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(int)); addMalloc2(logmalloclist, (void*)d, count, sizeof(int), "int", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -514,7 +532,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(int); type = userdefinedtype->compoundfield[j].type; @@ -542,16 +560,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(int), (xdrproc_t)xdr_int); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_int(xdrs, (int*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(int), (xdrproc_t)xdr_int); } @@ -562,15 +580,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_UNSIGNED_INT: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED INT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; @@ -578,17 +597,19 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST d = (char*)malloc(count * sizeof(unsigned int)); addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned int), "unsigned int", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -596,7 +617,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned int); type = userdefinedtype->compoundfield[j].type; } else { @@ -621,16 +642,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST "Unsigned Integer Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned int), (xdrproc_t)xdr_u_int); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_u_int(xdrs, (unsigned int*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(unsigned int), (xdrproc_t)xdr_u_int); } @@ -641,32 +662,35 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_LONG64: { UDA_LOG(UDA_LOG_DEBUG, "Type: LONG LONG\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to long long Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to long long Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(long long)); addMalloc2(logmalloclist, (void*)d, count, sizeof(long long), "long long", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -674,7 +698,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(long long); type = userdefinedtype->compoundfield[j].type; @@ -700,19 +724,18 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST "Long Long Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(long long), (xdrproc_t)xdr_int64_t); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_int64_t(xdrs, (int64_t*)p); - } else { // Element is an Array of fixed size - rc = rc && - xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(long long), - (xdrproc_t)xdr_int64_t); + } else { // Element is an Array of fixed size + rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, + sizeof(long long), (xdrproc_t)xdr_int64_t); } } break; @@ -721,15 +744,16 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_UNSIGNED_LONG64: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED LONG LONG\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; @@ -737,17 +761,19 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST d = (char*)malloc(count * sizeof(unsigned long long)); addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned long long), "unsigned long long", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -755,7 +781,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned long long); type = userdefinedtype->compoundfield[j].type; @@ -781,14 +807,14 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST "Unsigned Long Long Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned long long), (xdrproc_t)xdr_uint64_t); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_uint64_t(xdrs, (uint64_t*)p); } else { // Element is an Array of fixed size @@ -802,33 +828,38 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST case UDA_TYPE_CHAR: { UDA_LOG(UDA_LOG_DEBUG, "Type: CHAR\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender - if (!rc)break; + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender + if (!rc) { + break; + } if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(char)); addMalloc2(logmalloclist, (void*)d, count, sizeof(char), "char", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -837,7 +868,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST &userdefinedtype->compoundfield[j - 1].name[6])) { isSOAP = 1; - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(char); type = userdefinedtype->compoundfield[j].type; } else { @@ -856,7 +887,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } } else { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && (count == 0 || size == 0) && - *p != 0) { // Assume SOAP string + *p != 0) { // Assume SOAP string isSOAP = 1; if (d != nullptr) { int lstr = (int)strlen(d); @@ -865,34 +896,37 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST size = sizeof(char); type = userdefinedtype->compoundfield[j].type; } - convertNonPrintable2( - d); // Remove obvious garbage (bug - non initialised...?) + convertNonPrintable2(d); // Remove obvious garbage (bug - non initialised...?) } } } rc = rc && xdr_int(xdrs, &count); - if (!rc)break; + if (!rc) { + break; + } if ((count == 0 || size == 0) && *p != 0) { addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Char Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } - rc = rc && xdr_int(xdrs, &isSOAP); // synchronise XDR function calls - if (!rc)break; + rc = rc && xdr_int(xdrs, &isSOAP); // synchronise XDR function calls + if (!rc) { + break; + } - if (isSOAP) { // char* is a C String in gSOAP + if (isSOAP) { // char* is a C String in gSOAP if (xdrs->x_op == XDR_ENCODE) { int sl = (int)strlen(d); if (sl > count) { - d[count - 1] = '\0'; // Terminate + d[count - 1] = '\0'; // Terminate } } rc = rc && WrapXDRString(xdrs, d, count); @@ -900,46 +934,53 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } else { rc = rc && xdr_vector(xdrs, d, count, sizeof(char), (xdrproc_t)xdr_char); } - if (!rc)break; + if (!rc) { + break; + } } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_char(xdrs, (char*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(char), (xdrproc_t)xdr_char); } - if (!rc)break; + if (!rc) { + break; + } } break; } - case UDA_TYPE_STRING2: { // Array of char terminated by \0 - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + case UDA_TYPE_STRING2: { // Array of char terminated by \0 + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } - if (malloc_source == UDA_MALLOC_SOURCE_DOM) { // Bad address range? + if (malloc_source == UDA_MALLOC_SOURCE_DOM) { // Bad address range? count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc(logmalloclist, (void*)p, &count, &size, - &type); // Assume 0 means No Pointer data to send! + &type); // Assume 0 means No Pointer data to send! if (malloc_source == UDA_MALLOC_SOURCE_DOM && (count == 0 || size == 0) && d != nullptr) { int lstr = (int)strlen(d); @@ -954,8 +995,9 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST int lstr = (int)strlen(d); count = size; size = sizeof(char); - if (malloc_source == UDA_MALLOC_SOURCE_DOM && lstr > count - 1 && lstr < MAXSOAPSTACKSTRING) { - count = lstr + 1; // A bug in xml DOM? + if (malloc_source == UDA_MALLOC_SOURCE_DOM && lstr > count - 1 && + lstr < MAXSOAPSTACKSTRING) { + count = lstr + 1; // A bug in xml DOM? } } @@ -968,10 +1010,12 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } } - if (count > 0) rc = rc && WrapXDRString(xdrs, d, count); + if (count > 0) { + rc = rc && WrapXDRString(xdrs, d, count); + } } else { - if (userdefinedtype->compoundfield[j].rank == 1) { // Element is a Regular String + if (userdefinedtype->compoundfield[j].rank == 1) { // Element is a Regular String rc = rc && WrapXDRString(xdrs, (char*)p, userdefinedtype->compoundfield[j].count); } } @@ -985,22 +1029,24 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST // If the number of strings is arbitrary then the type is STRING* rather than STRING // Strings: - // char *p single scalar string of arbitrary length => rank = 0, pointer = 1, type STRING - // char **p; arbitrary number array of strings of arbitrary length => rank = 0, pointer = 1, type STRING* - // char p[int] single scalar string of fixed length => rank = 1, pointer = 0, type STRING - // char *p[int] fixed number array of strings of arbitrary length => rank = 1, pointer = 0, type STRING* - // char p[int][int] fixed number array of strings of fixed length => rank = 2, pointer = 0, type STRING - - case UDA_TYPE_STRING: { // Array of char terminated by \0 + // char *p single scalar string of arbitrary length => rank = 0, + // pointer = 1, type STRING char **p; arbitrary number array of strings of arbitrary + // length => rank = 0, pointer = 1, type STRING* char p[int] single scalar string of + // fixed length => rank = 1, pointer = 0, type STRING char *p[int] fixed + // number array of strings of arbitrary length => rank = 1, pointer = 0, type STRING* char + // p[int][int] fixed number array of strings of fixed length => rank = 2, pointer = 0, + // type STRING + + case UDA_TYPE_STRING: { // Array of char terminated by \0 UDA_LOG(UDA_LOG_DEBUG, "Type: STRING\n"); char** strarr; int nstr = 0, istr; - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data if (STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { - rc = rc && xdr_int(xdrs, &nstr); // Number of strings + rc = rc && xdr_int(xdrs, &nstr); // Number of strings if (nstr > 0) { char** str = (char**)malloc(nstr * sizeof(char*)); addMalloc(logmalloclist, (void*)str, nstr, sizeof(char*), "STRING *"); @@ -1018,36 +1064,41 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, - &nstr); // nstr (count) is known from the client's malloc log and passed by the sender + rc = rc && + xdr_int( + xdrs, + &nstr); // nstr (count) is known from the client's malloc log and passed by the sender if (nstr > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } - strarr = (char**)malloc( - nstr * sizeof(char*)); // nstr is the length of the array, not the strings + strarr = (char**)malloc(nstr * + sizeof(char*)); // nstr is the length of the array, not the strings addMalloc2(logmalloclist, (void*)strarr, nstr, sizeof(char*), "STRING", rank, shape); *p = (VOIDTYPE)strarr; // Save pointer: First String will be written here - for (istr = 0; - istr < nstr; istr++) { // Receive individual String lengths, then the string + for (istr = 0; istr < nstr; istr++) { // Receive individual String lengths, then the string rc = rc && xdr_int(xdrs, &count); strarr[istr] = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)strarr[istr], count, sizeof(char), "STRING"); rc = rc && WrapXDRString(xdrs, strarr[istr], count); - if (rank == 0 && nstr == 1) *p = (VOIDTYPE)strarr[0]; + if (rank == 0 && nstr == 1) { + *p = (VOIDTYPE)strarr[0]; + } } - } else { break; } + } else { + break; + } } else { if (STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { char** str = (char**)*p; findMalloc(logmalloclist, (void*)&str, &nstr, &size, &type); - rc = rc && xdr_int(xdrs, &nstr); // Number of strings + rc = rc && xdr_int(xdrs, &nstr); // Number of strings if (nstr > 0) { for (istr = 0; istr < nstr; istr++) { findMalloc(logmalloclist, (void*)&str[istr], &count, &size, &type); @@ -1061,15 +1112,15 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - d = (char*)*p; // First string in the Array + d = (char*)*p; // First string in the Array if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &nstr, &size, &type, &rank, - &shape); // Assume 0 means No Pointer data to send! + &shape); // Assume 0 means No Pointer data to send! // or heap allocated in external library! // Is this a fixed length array of strings ? @@ -1082,7 +1133,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST size = userdefinedtype->compoundfield[j].size; } - rc = rc && xdr_int(xdrs, &nstr); // This many strings to send + rc = rc && xdr_int(xdrs, &nstr); // This many strings to send if ((nstr == 0 || size == 0) && *p != 0) { addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, @@ -1090,18 +1141,18 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } if (rank == 0) { - rc = rc && xdr_int(xdrs, &size); // This length of string + rc = rc && xdr_int(xdrs, &size); // This length of string rc = rc && WrapXDRString(xdrs, d, size); } else { strarr = (char**)d; - for (istr = 0; istr < - nstr; istr++) { // Send individual String lengths, then the string itself + for (istr = 0; istr < nstr; + istr++) { // Send individual String lengths, then the string itself count = (int)strlen(strarr[istr]) + 1; rc = rc && xdr_int(xdrs, &count); rc = rc && WrapXDRString(xdrs, strarr[istr], count); @@ -1109,25 +1160,25 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } } } else { - if (userdefinedtype->compoundfield[j].rank >= 1) { // fixed length Regular Strings + if (userdefinedtype->compoundfield[j].rank >= 1) { // fixed length Regular Strings if (userdefinedtype->compoundfield[j].rank == 1 && strcmp(userdefinedtype->compoundfield[j].type, "STRING *") != - 0) { // Element is a Single String + 0) { // Element is a Single String rc = rc && WrapXDRString(xdrs, (char*)p, userdefinedtype->compoundfield[j].count); - } else { // Element is a String Array: Treat as Rank 1 array + } else { // Element is a String Array: Treat as Rank 1 array if (userdefinedtype->compoundfield[j].rank == 1 && STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { char** str = (char**)p; - nstr = userdefinedtype->compoundfield[j].count; // Number of strings + nstr = userdefinedtype->compoundfield[j].count; // Number of strings for (istr = 0; istr < nstr; istr++) { if (xdrs->x_op == XDR_DECODE) { - rc = rc && xdr_int(xdrs, &count); // Arbitrary String length + rc = rc && xdr_int(xdrs, &count); // Arbitrary String length if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); rc = rc && WrapXDRString(xdrs, d, count); str[istr] = d; - } // Save pointer: data will be written here + } // Save pointer: data will be written here } else { findMalloc(logmalloclist, (void*)&str[istr], &count, &size, &type); rc = rc && xdr_int(xdrs, &count); @@ -1139,39 +1190,41 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } } else { char* str = (char*)p; - int stride = userdefinedtype->compoundfield[j].shape[0]; // String length + int stride = userdefinedtype->compoundfield[j].shape[0]; // String length nstr = 1; for (istr = 1; istr < userdefinedtype->compoundfield[j].rank; istr++) { - nstr = nstr * - userdefinedtype->compoundfield[j].shape[istr]; // Number of strings to send/receive + nstr = nstr * userdefinedtype->compoundfield[j] + .shape[istr]; // Number of strings to send/receive } - for (istr = 0; - istr < nstr; istr++) { // send/receive individual strings + for (istr = 0; istr < nstr; istr++) { // send/receive individual strings rc = rc && WrapXDRString(xdrs, &str[istr * stride], userdefinedtype->compoundfield[j].count); } } } } else { // Element is a Single String of any size - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = + rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc(logmalloclist, (void*)p, &count, &size, - &type); // Assume 0 means No string to send! - if (count == 1 && - STR_EQUALS(type, "unknown")) { // ***** Fix for SOAP sources incomplete! + &type); // Assume 0 means No string to send! + if (count == 1 && STR_EQUALS(type, "unknown")) { // ***** Fix for SOAP sources incomplete! count = size; size = sizeof(char); } @@ -1196,7 +1249,8 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST default: { - // Send or Receive the Count, Size and Type of the sub-structure (All atomic types except void are trapped before this point) + // Send or Receive the Count, Size and Type of the sub-structure (All atomic types except void are + // trapped before this point) UDA_LOG(UDA_LOG_DEBUG, "Type: OTHER - Void Type or Structure\n"); @@ -1206,13 +1260,13 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST // Interpret an 'unknown' void data type using knowledge of the gSOAP or DOM systems - if (type != nullptr && STR_EQUALS(type, "unknown")) { // arises from a malloc redirection + if (type != nullptr && STR_EQUALS(type, "unknown")) { // arises from a malloc redirection if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && STR_EQUALS(userdefinedtype->compoundfield[j - 1].name, "__size") && STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = (int)getsizeof(userdefinedtypelist, userdefinedtype->compoundfield[j].type); type = userdefinedtype->compoundfield[j].type; } else { @@ -1221,11 +1275,11 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST totalsize = count * size; if (malloc_source == UDA_MALLOC_SOURCE_DOM && STR_EQUALS(userdefinedtype->compoundfield[j].type, "void")) { - ssize = sizeof(char); // Assume xml void pointer type is to char + ssize = sizeof(char); // Assume xml void pointer type is to char type = chartype; } else { - ssize = (int)getsizeof(userdefinedtypelist, - userdefinedtype->compoundfield[j].type); + ssize = + (int)getsizeof(userdefinedtypelist, userdefinedtype->compoundfield[j].type); type = userdefinedtype->compoundfield[j].type; } @@ -1246,16 +1300,17 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST "Data Heap Allocation not found in log!"); break; } - } - rc = rc && xdr_int(xdrs, &count); // Not passed with the Structure definition + rc = rc && xdr_int(xdrs, &count); // Not passed with the Structure definition - if (count == 0) break; // Nothing to Send or Receive + if (count == 0) { + break; // Nothing to Send or Receive + } - loopcount = count; // Array Count + loopcount = count; // Array Count - rc = rc && xdr_int(xdrs, &size); // Structure Size + rc = rc && xdr_int(xdrs, &size); // Structure Size if (xdrs->x_op == XDR_DECODE) { rc = rc && WrapXDRString(xdrs, (char*)rudtype, MAXELEMENTNAME - 1); @@ -1265,11 +1320,13 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } if (protocolVersion >= 7) { - rc = rc && xdr_int(xdrs, &structRank); // Rank of the Structure Array + rc = rc && xdr_int(xdrs, &structRank); // Rank of the Structure Array if (structRank > 1) { - if (xdrs->x_op == XDR_DECODE) structShape = (int*)malloc(structRank * sizeof(int)); - rc = rc && - xdr_vector(xdrs, (char*)structShape, structRank, sizeof(int), (xdrproc_t)xdr_int); + if (xdrs->x_op == XDR_DECODE) { + structShape = (int*)malloc(structRank * sizeof(int)); + } + rc = + rc && xdr_vector(xdrs, (char*)structShape, structRank, sizeof(int), (xdrproc_t)xdr_int); } else { structShape = nullptr; } @@ -1280,8 +1337,8 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST } else { -// Non Pointer types: Heap already allocated (pass 0 count to xdrUserDefinedData) -// Size and Type also known. Type cannot be 'void'. + // Non Pointer types: Heap already allocated (pass 0 count to xdrUserDefinedData) + // Size and Type also known. Type cannot be 'void'. addNonMalloc(logmalloclist, (void*)p, userdefinedtype->compoundfield[j].count, userdefinedtype->compoundfield[j].size, userdefinedtype->compoundfield[j].type); @@ -1295,7 +1352,7 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST userdefinedtype->compoundfield[j].type); } -// Pointer to structure definition (void type ignored) + // Pointer to structure definition (void type ignored) if ((utype = findUserDefinedType(userdefinedtypelist, type, 0)) == nullptr && strcmp(userdefinedtype->compoundfield[j].type, "void") != 0) { @@ -1311,18 +1368,19 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST break; } -// Must be a known User Defined Type -// Execute once for each structure array element: count comes either from the malloc log or from the structure definition for non-pointer types -// A new tree node is used for each array element when receiving + // Must be a known User Defined Type + // Execute once for each structure array element: count comes either from the malloc log or from the + // structure definition for non-pointer types A new tree node is used for each array element when + // receiving -// When passing linked lists, the parent->child->parent link needs to be detected and blocked when sending. -// On receiving data, the pointer references can be added back. + // When passing linked lists, the parent->child->parent link needs to be detected and blocked when + // sending. On receiving data, the pointer references can be added back. if (utype != nullptr) { for (int i = 0; i < loopcount; i++) { -// Has this structure already been sent/received (e.g. in a linked list) + // Has this structure already been sent/received (e.g. in a linked list) id = 0; @@ -1334,19 +1392,19 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST id = findStructId(heap, &stype, log_struct_list); } - if (id == 0) { // Only send/receive new structures + if (id == 0) { // Only send/receive new structures if (userdefinedtype->compoundfield[j].pointer) { rc = rc && - xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, utype, (void**)p, - count, structRank, structShape, i, - &subNTree, - protocolVersion, malloc_source); // User Defined type // rc set to 0 somewhere => stops call + xdrUserDefinedData( + xdrs, logmalloclist, log_struct_list, userdefinedtypelist, utype, (void**)p, + count, structRank, structShape, i, &subNTree, protocolVersion, + malloc_source); // User Defined type // rc set to 0 somewhere => stops call } else { rc = rc && - xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, utype, (void**)&p, - count, structRank, structShape, i, - &subNTree, - protocolVersion, malloc_source); // if rc is set to 0 somewhere => stops call + xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, + utype, (void**)&p, count, structRank, structShape, i, &subNTree, + protocolVersion, + malloc_source); // if rc is set to 0 somewhere => stops call } // Add the new data branch to the tree @@ -1357,22 +1415,22 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST strcpy(subNTree->name, userdefinedtype->compoundfield[j].name); if (i == 0 && loopcount > 0) { if (newNTree->children == nullptr && newNTree->branches == 0) { - newNTree->children = (NTREE**)malloc( - loopcount * sizeof(NTREE*)); // Allocate the node array + newNTree->children = + (NTREE**)malloc(loopcount * sizeof(NTREE*)); // Allocate the node array addMalloc(logmalloclist, (void*)newNTree->children, loopcount, sizeof(NTREE*), "NTREE *"); - } else { // Multiple branches (user types) originating in the same node + } else { // Multiple branches (user types) originating in the same node auto old = (VOIDTYPE)newNTree->children; - newNTree->children = (NTREE**)realloc((void*)old, - (newNTree->branches + loopcount) * - sizeof(NTREE*)); // Individual node addresses remain valid + newNTree->children = (NTREE**)realloc( + (void*)old, + (newNTree->branches + loopcount) * + sizeof(NTREE*)); // Individual node addresses remain valid changeMalloc(logmalloclist, old, (void*)newNTree->children, newNTree->branches + loopcount, sizeof(NTREE*), "NTREE *"); } } - addNTree(newNTree, subNTree); // Only first call creates new tree node + addNTree(newNTree, subNTree); // Only first call creates new tree node } - } } break; @@ -1383,38 +1441,33 @@ int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST if (gettypeof(type) != UDA_TYPE_UNKNOWN) { char* z = (char*)*p; - rc = rc && - xdrAtomicData(logmalloclist, xdrs, type, count, size, &z); // Must be an Atomic Type + rc = rc && xdrAtomicData(logmalloclist, xdrs, type, count, size, &z); // Must be an Atomic Type *p = (VOIDTYPE)z; break; } else { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "User Defined Type not known!"); + addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "User Defined Type not known!"); break; } } addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Type not known!"); break; - } } if (!rc) { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "XDR Return Code False => Bad send/receive!"); + addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "XDR Return Code False => Bad send/receive!"); recursiveDepthPut--; return rc; } - prev = p; // Preserve the previous data pointer + prev = p; // Preserve the previous data pointer } recursiveDepthPut--; return rc; } - // Send/Receive Array of Structures int xdrUserDefinedTypeDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, @@ -1430,11 +1483,11 @@ int xdrUserDefinedTypeDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFIN NTREE* dataNTree = nullptr; rc = rc && xdr_userdefinedtype(xdrs, userdefinedtypelist, - userdefinedtype); // User Defined Type Definitions + userdefinedtype); // User Defined Type Definitions rc = rc && - xdrUserDefinedDataPut(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, nullptr, 0, - &dataNTree, protocolVersion, malloc_source); // Data within Structures + xdrUserDefinedDataPut(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, + 0, nullptr, 0, &dataNTree, protocolVersion, malloc_source); // Data within Structures udaSetFullNTree(dataNTree); // Copy to Global } else { @@ -1446,26 +1499,25 @@ int xdrUserDefinedTypeDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFIN } rc = xdr_userdefinedtype(xdrs, userdefinedtypelist, - userdefinedtype); // User Defined Type Definitions + userdefinedtype); // User Defined Type Definitions rc = rc && - xdrUserDefinedDataPut(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, nullptr, 0, - nullptr, protocolVersion, malloc_source); // Data within Structures + xdrUserDefinedDataPut(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, + 0, nullptr, 0, nullptr, protocolVersion, malloc_source); // Data within Structures /* if(!XDRstdioFlag) rc = rc && xdrrec_endofrecord(xdrs, 1); */ } - freeLogStructList(log_struct_list); // Free Linked List Structure Log heap + freeLogStructList(log_struct_list); // Free Linked List Structure Log heap return rc; } - bool_t xdr_userdefinedtypelistPut(XDR* xdrs, USERDEFINEDTYPELIST* str) { -// Send/Receive the list of userdefined types + // Send/Receive the list of userdefined types int rc = 1; @@ -1473,19 +1525,24 @@ bool_t xdr_userdefinedtypelistPut(XDR* xdrs, USERDEFINEDTYPELIST* str) UDA_LOG(UDA_LOG_DEBUG, "xdr_userdefinedtypelist: rc = %d, listCount = %d\n", rc, str->listCount); - if (!rc || str->listCount == 0) return rc; + if (!rc || str->listCount == 0) { + return rc; + } - if (xdrs->x_op == XDR_DECODE) { // Receiving array so allocate Heap for it then initialise + if (xdrs->x_op == XDR_DECODE) { // Receiving array so allocate Heap for it then initialise str->userdefinedtype = (USERDEFINEDTYPE*)malloc(str->listCount * sizeof(USERDEFINEDTYPE)); - for (int i = 0; i < str->listCount; i++) initUserDefinedType(&str->userdefinedtype[i]); + for (int i = 0; i < str->listCount; i++) { + initUserDefinedType(&str->userdefinedtype[i]); + } } - for (int i = 0; i < str->listCount; i++) rc = rc && xdr_userdefinedtype(xdrs, str, &str->userdefinedtype[i]); + for (int i = 0; i < str->listCount; i++) { + rc = rc && xdr_userdefinedtype(xdrs, str, &str->userdefinedtype[i]); + } return rc; } - int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, void* str, int protocolVersion, LOGSTRUCTLIST* log_struct_list, unsigned int private_flags, int malloc_source) @@ -1511,12 +1568,12 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA if (data_block->opaque_type == UDA_OPAQUE_TYPE_STRUCTURES) { int packageType = 0; - if (xdrs->x_op == XDR_ENCODE) { // Send Data + if (xdrs->x_op == XDR_ENCODE) { // Send Data - SARRAY sarray; // Structure array carrier structure + SARRAY sarray; // Structure array carrier structure SARRAY* psarray = &sarray; int shape = data_block->data_n; // rank 1 array of dimension lengths - auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition + auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; // The data's structure definition USERDEFINEDTYPE* u = findUserDefinedType(userdefinedtypelist, "SARRAY", 0); // Locate the carrier structure definition @@ -1532,31 +1589,33 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA UDA_LOG(UDA_LOG_DEBUG, "Creating SARRAY carrier structure to Send\n"); initSArray(&sarray); - sarray.count = data_block->data_n; // Number of this structure - sarray.rank = 1; // Array Data Rank? - sarray.shape = &shape; // Only if rank > 1? - sarray.data = (void*)data_block->data; // Pointer to the data to be passed - strcpy(sarray.type, udt->name); // The name of the type - data = (void*)&psarray; // Pointer to the SARRAY array pointer + sarray.count = data_block->data_n; // Number of this structure + sarray.rank = 1; // Array Data Rank? + sarray.shape = &shape; // Only if rank > 1? + sarray.data = (void*)data_block->data; // Pointer to the data to be passed + strcpy(sarray.type, udt->name); // The name of the type + data = (void*)&psarray; // Pointer to the SARRAY array pointer addNonMalloc(logmalloclist, (void*)&shape, 1, sizeof(int), "int"); rc = 1; - packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR + packageType = UDA_PACKAGE_STRUCTDATA; // The package is regular XDR UDA_LOG(UDA_LOG_DEBUG, "Sending Package Type: %d\n", packageType); - rc = xdr_int(xdrs, &packageType); // Send data package type - // **** the original protocolXML2 marks this as the end of a record and dispatches. This causes an error - unknown root cause + rc = xdr_int(xdrs, &packageType); // Send data package type + // **** the original protocolXML2 marks this as the end of a record and dispatches. This causes an + // error - unknown root cause - rc = rc && xdr_userdefinedtypelistPut(xdrs, - userdefinedtypelist); // send the full set of known named structures + rc = rc && + xdr_userdefinedtypelistPut(xdrs, + userdefinedtypelist); // send the full set of known named structures UDA_LOG(UDA_LOG_DEBUG, "Structure Definitions sent: rc = %d\n", rc); - rc = rc && xdrUserDefinedTypeDataPut(xdrs, logmalloclist, userdefinedtypelist, u, - (void**)data, protocolVersion, log_struct_list, - malloc_source); // send the Data + rc = rc && xdrUserDefinedTypeDataPut(xdrs, logmalloclist, userdefinedtypelist, u, (void**)data, + protocolVersion, log_struct_list, + malloc_source); // send the Data UDA_LOG(UDA_LOG_DEBUG, "Structured Data sent: rc = %d\n", rc); @@ -1569,7 +1628,7 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA //====================================================================================================================== - } else { // Receive Data + } else { // Receive Data int option = 4; @@ -1577,9 +1636,11 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA // **** the original protocolXML2 reads the next record. This causes an error - unknown root cause - rc = rc && xdr_int(xdrs, &packageType); // Receive data package type + rc = rc && xdr_int(xdrs, &packageType); // Receive data package type - if ((private_flags & PRIVATEFLAG_XDRFILE) == 0 && packageType == UDA_PACKAGE_STRUCTDATA) option = 1; + if ((private_flags & PRIVATEFLAG_XDRFILE) == 0 && packageType == UDA_PACKAGE_STRUCTDATA) { + option = 1; + } UDA_LOG(UDA_LOG_DEBUG, "Receive data option : %d\n", option); UDA_LOG(UDA_LOG_DEBUG, "Receive package Type: %d\n", packageType); @@ -1591,7 +1652,6 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA break; } - // Unpack data structures if (option == 1) { @@ -1604,8 +1664,9 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA initUserDefinedTypeList(userdefinedtypelist); - rc = rc && xdr_userdefinedtypelistPut(xdrs, - userdefinedtypelist); // receive the full set of known named structures + rc = rc && xdr_userdefinedtypelistPut( + xdrs, + userdefinedtypelist); // receive the full set of known named structures UDA_LOG(UDA_LOG_DEBUG, "userdefinedtypelist received\n"); @@ -1620,8 +1681,8 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA rc = rc && xdrUserDefinedTypeDataPut(xdrs, logmalloclist, userdefinedtypelist, udt_received, &data, protocolVersion, log_struct_list, - malloc_source); // receive the Data - //rc = rc && xdrUserDefinedTypeData(xdrs, udt_received, &data); // receive the Data + malloc_source); // receive the Data + // rc = rc && xdrUserDefinedTypeData(xdrs, udt_received, &data); // receive the Data UDA_LOG(UDA_LOG_DEBUG, "xdrUserDefinedTypeData received\n"); @@ -1632,12 +1693,12 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA break; } - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != data_block->data_n) { // check for consistency + if (s->count != data_block->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolXML2Put", err, "Inconsistent S Array Counts"); @@ -1649,9 +1710,11 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA general_block->logmalloclist = logmalloclist; general_block->lastMallocIndex = 0; - data_block->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + data_block->data = + (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data - data_block->opaque_block = (void*)general_block; // Contains all the other information needed + data_block->opaque_block = + (void*)general_block; // Contains all the other information needed } else { err = 999; @@ -1659,15 +1722,13 @@ int protocolXML2Put(XDR* xdrs, int protocol_id, int direction, int* token, LOGMA "Name of Received Data Structure Incorrect"); break; } - } } - } } -//---------------------------------------------------------------------------- -// End of Error Trap Loop + //---------------------------------------------------------------------------- + // End of Error Trap Loop } while (0); diff --git a/source/clientserver/protocolXML2Put.h b/source/clientserver/protocolXML2Put.h old mode 100755 new mode 100644 index d2b591eb..8e2f34f9 --- a/source/clientserver/protocolXML2Put.h +++ b/source/clientserver/protocolXML2Put.h @@ -1,11 +1,11 @@ #ifndef UDA_CLIENTSERVER_PROTOCOLXML2PUT_H #define UDA_CLIENTSERVER_PROTOCOLXML2PUT_H -#include #include +#include -#include "genStructs.h" #include "export.h" +#include "genStructs.h" #ifdef __cplusplus extern "C" { @@ -13,15 +13,15 @@ extern "C" { LIBRARY_API int xdrUserDefinedDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* log_struct_list, USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, - void** data, int datacount, int structRank, int* structShape, - int index, NTREE** NTree, int protocolVersion, int malloc_source); + void** data, int datacount, int structRank, int* structShape, int index, + NTREE** NTree, int protocolVersion, int malloc_source); // Send/Receive Array of Structures -LIBRARY_API int -xdrUserDefinedTypeDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - USERDEFINEDTYPE* userdefinedtype, void** data, int protocolVersion, - LOGSTRUCTLIST* log_struct_list, int malloc_source); +LIBRARY_API int xdrUserDefinedTypeDataPut(XDR* xdrs, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, + void** data, int protocolVersion, LOGSTRUCTLIST* log_struct_list, + int malloc_source); LIBRARY_API bool_t xdr_userdefinedtypelistPut(XDR* xdrs, USERDEFINEDTYPELIST* str); diff --git a/source/clientserver/readXDRFile.cpp b/source/clientserver/readXDRFile.cpp old mode 100755 new mode 100644 index 0aebc39b..cb3cd70d --- a/source/clientserver/readXDRFile.cpp +++ b/source/clientserver/readXDRFile.cpp @@ -1,7 +1,7 @@ #include "readXDRFile.h" -#include #include +#include #include #include "errorLog.h" @@ -10,7 +10,7 @@ # include #endif -#define MAXDOLOOPLIMIT 500 // ~50MB file +#define MAXDOLOOPLIMIT 500 // ~50MB file int sendXDRFile(XDR* xdrs, const char* xdrfile) { @@ -54,24 +54,23 @@ int sendXDRFile(XDR* xdrs, const char* xdrfile) if ((bp = (char*)malloc(bufsize * sizeof(char))) == nullptr) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "sendXDRFile", err, - "Unable to Allocate Heap Memory for the XDR File"); + addIdamError(UDA_CODE_ERROR_TYPE, "sendXDRFile", err, "Unable to Allocate Heap Memory for the XDR File"); bufsize = 0; rc = xdr_int(xdrs, &bufsize); break; } - rc = xdr_int(xdrs, &bufsize); // Send Server buffer size, e.g., 100k bytes + rc = xdr_int(xdrs, &bufsize); // Send Server buffer size, e.g., 100k bytes UDA_LOG(UDA_LOG_DEBUG, "Buffer size %d\n", bufsize); while (!feof(fh)) { nchar = (int)fread(bp, sizeof(char), bufsize, fh); - rc = rc && xdr_int(xdrs, &nchar); // Number of Bytes to send + rc = rc && xdr_int(xdrs, &nchar); // Number of Bytes to send UDA_LOG(UDA_LOG_DEBUG, "File block size %d\n", nchar); - if (nchar > 0) { // Send the bytes + if (nchar > 0) { // Send the bytes rc = rc && xdr_vector(xdrs, (char*)bp, nchar, sizeof(char), (xdrproc_t)xdr_char); } @@ -84,17 +83,18 @@ int sendXDRFile(XDR* xdrs, const char* xdrfile) } while (0); - nchar = 0; // No more bytes to send + nchar = 0; // No more bytes to send rc = rc && xdr_int(xdrs, &nchar); rc = rc && xdrrec_endofrecord(xdrs, 1); // *** Send count to client as a check all data received - // *** Send hash sum to client as a test data is accurate - another reason to use files and cache rather than a data stream + // *** Send hash sum to client as a test data is accurate - another reason to use files and cache rather than a data + // stream //---------------------------------------------------------------------- // Housekeeping - fclose(fh); // Close the File + fclose(fh); // Close the File free(bp); return err; @@ -114,10 +114,13 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) if (fh == nullptr || errno != 0 || ferror(fh)) { err = 999; - if (errno != 0) addIdamError(UDA_SYSTEM_ERROR_TYPE, "receiveXDRFile", errno, ""); - addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, - "Unable to Open the XDR File for Write Access"); - if (fh != nullptr) fclose(fh); + if (errno != 0) { + addIdamError(UDA_SYSTEM_ERROR_TYPE, "receiveXDRFile", errno, ""); + } + addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, "Unable to Open the XDR File for Write Access"); + if (fh != nullptr) { + fclose(fh); + } return err; } @@ -134,7 +137,7 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) nchar = 0; rc = xdrrec_skiprecord(xdrs); - rc = xdr_int(xdrs, &bufsize); // Server buffer size, e.g., 100k bytes + rc = xdr_int(xdrs, &bufsize); // Server buffer size, e.g., 100k bytes UDA_LOG(UDA_LOG_DEBUG, "receiveXDRFile: Buffer size %d\n", bufsize); @@ -146,8 +149,7 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) if ((bp = (char*)malloc(bufsize * sizeof(char))) == nullptr) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, - "Unable to Allocate Heap Memory for the XDR File"); + addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, "Unable to Allocate Heap Memory for the XDR File"); break; } @@ -156,9 +158,11 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) do { errno = 0; - if (doLoopLimit > 0) rc = rc && xdrrec_skiprecord(xdrs); + if (doLoopLimit > 0) { + rc = rc && xdrrec_skiprecord(xdrs); + } - rc = rc && xdr_int(xdrs, &nchar); // How many bytes to receive? + rc = rc && xdr_int(xdrs, &nchar); // How many bytes to receive? UDA_LOG(UDA_LOG_DEBUG, "receiveXDRFile: [%d] File block size %d\n", doLoopLimit, nchar); @@ -170,15 +174,14 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) } if (nchar > 0) { - rc = rc && xdr_vector(xdrs, (char*)bp, nchar, sizeof(char), (xdrproc_t)xdr_char); //Bytes + rc = rc && xdr_vector(xdrs, (char*)bp, nchar, sizeof(char), (xdrproc_t)xdr_char); // Bytes count = count + (int)fwrite(bp, sizeof(char), nchar, fh); } } while (nchar > 0 && errno == 0 && doLoopLimit++ < MAXDOLOOPLIMIT); if (doLoopLimit >= MAXDOLOOPLIMIT) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, - "Maximum XDR file size reached: ~50MBytes"); + addIdamError(UDA_CODE_ERROR_TYPE, "receiveXDRFile", err, "Maximum XDR file size reached: ~50MBytes"); break; } @@ -199,9 +202,8 @@ int receiveXDRFile(XDR* xdrs, const char* xdrfile) //---------------------------------------------------------------------- // Housekeeping - fclose(fh); // Close the File + fclose(fh); // Close the File free(bp); return err; } - diff --git a/source/clientserver/readXDRFile.h b/source/clientserver/readXDRFile.h old mode 100755 new mode 100644 index 1c934e4f..946c0a1a --- a/source/clientserver/readXDRFile.h +++ b/source/clientserver/readXDRFile.h @@ -1,16 +1,15 @@ #pragma once #ifndef UDA_CLIENTSERVER_READXDRFILE_H -#define UDA_CLIENTSERVER_READXDRFILE_H +# define UDA_CLIENTSERVER_READXDRFILE_H -#include -#include -#include "export.h" +# include "export.h" +# include +# include -#define MAXDOLOOPLIMIT 500 // ~50MB file +# define MAXDOLOOPLIMIT 500 // ~50MB file int sendXDRFile(XDR* xdrs, const char* xdrfile); int receiveXDRFile(XDR* xdrs, const char* xdrfile); #endif // UDA_CLIENTSERVER_READXDRFILE_H - diff --git a/source/clientserver/socketStructs.h b/source/clientserver/socketStructs.h old mode 100755 new mode 100644 index d6cd6817..52483424 --- a/source/clientserver/socketStructs.h +++ b/source/clientserver/socketStructs.h @@ -1,15 +1,15 @@ #pragma once #ifndef UDA_CLIENTSERVER_SOCKETSTRUCTS_H -#define UDA_CLIENTSERVER_SOCKETSTRUCTS_H +# define UDA_CLIENTSERVER_SOCKETSTRUCTS_H -#include "udaDefines.h" +# include "udaDefines.h" -#include -#include -#include "export.h" +# include "export.h" +# include +# include -#include +# include struct HostData { std::string host_alias; @@ -24,16 +24,16 @@ struct HostData { //------------------------------------------------------- // Socket Types -#define TYPE_UNKNOWN_SERVER 0 -#define TYPE_UDA_SERVER 1 -#define TYPE_MDSPLUS_SERVER 2 +# define TYPE_UNKNOWN_SERVER 0 +# define TYPE_UDA_SERVER 1 +# define TYPE_MDSPLUS_SERVER 2 //-------------------------------------------------------- // Socket Management typedef struct Sockets { - int type; // Type Code (e.g.,1=>IDAM;2=>MDS+); - char host[MAXSERVER]; // Server's Host Name or IP Address + int type; // Type Code (e.g.,1=>IDAM;2=>MDS+); + char host[MAXSERVER]; // Server's Host Name or IP Address int port; int status; // Open (1) or Closed (0) int fh; // Socket to Server File Handle @@ -44,8 +44,8 @@ typedef struct Sockets { } SOCKETS; typedef struct SocketList { - int nsocks; // Number of Sockets - SOCKETS* sockets; // Array of Socket Management Data + int nsocks; // Number of Sockets + SOCKETS* sockets; // Array of Socket Management Data } SOCKETLIST; #endif // UDA_CLIENTSERVER_SOCKETSTRUCTS_H diff --git a/source/clientserver/stringUtils.cpp b/source/clientserver/stringUtils.cpp old mode 100755 new mode 100644 index dbf55189..1c0cf9db --- a/source/clientserver/stringUtils.cpp +++ b/source/clientserver/stringUtils.cpp @@ -1,8 +1,8 @@ #include "stringUtils.h" -#include #include #include +#include #include #ifdef __GNUC__ @@ -42,7 +42,9 @@ void reverseString(const char* in, char* out) { int lstr = (int)strlen(in); out[lstr] = '\0'; - for (int i = 0; i < lstr; i++) out[i] = in[lstr - 1 - i]; + for (int i = 0; i < lstr; i++) { + out[i] = in[lstr - 1 - i]; + } } // Copy a String subject to a Maximum length constraint @@ -87,8 +89,9 @@ char* TrimString(char* szSource) */ pszEOS = szSource + strlen(szSource) - 1; - while (pszEOS >= szSource && *pszEOS == ' ') + while (pszEOS >= szSource && *pszEOS == ' ') { *pszEOS-- = '\0'; + } return szSource; } @@ -140,7 +143,6 @@ char* strupr(char* a) return ret; } - // Convert all UpperCase Characters to Lower Case char* strlwr(char* a) @@ -166,7 +168,9 @@ char* MidTrimString(char* str) int j = 0, lstr; lstr = (int)strlen(str); for (int i = 0; i < lstr; i++) { - if (str[i] != ' ') str[j++] = str[i]; + if (str[i] != ' ') { + str[j++] = str[i]; + } } str[j] = '\0'; return str; @@ -178,7 +182,9 @@ int IsNumber(const char* a) { const char* wrk = a; while (*wrk != '\0') { - if (!isdigit(*wrk) && *wrk != '-' && *wrk != '+') return 0; + if (!isdigit(*wrk) && *wrk != '-' && *wrk != '+') { + return 0; + } ++wrk; } return 1; @@ -190,25 +196,27 @@ int IsFloat(char* a) { char* wrk = a; while (*wrk != '\0') { - if (!isdigit(*wrk) && *wrk != '-' && *wrk != '+' && *wrk != '.') return 0; + if (!isdigit(*wrk) && *wrk != '-' && *wrk != '+' && *wrk != '.') { + return 0; + } ++wrk; } return 1; } - // Is the String a Number List (#,#,#,#;#;#;#)? int IsNumberList(char* a) { char* wrk = a; while (*wrk != '\0') { - if (!isdigit(*wrk) || *wrk != ',' || *wrk != ';') return 0; + if (!isdigit(*wrk) || *wrk != ',' || *wrk != ';') { + return 0; + } ++wrk; } - if (a[0] == ',' || a[strlen(a)] == ',' || - a[0] == ';' || a[strlen(a)] == ';') { - return 0; + if (a[0] == ',' || a[strlen(a)] == ',' || a[0] == ';' || a[strlen(a)] == ';') { + return 0; } return 1; @@ -220,9 +228,8 @@ char* convertNonPrintable(char* str) char* ret = str; while (*str != '\0') { - if (!isalpha(*str) && !isdigit(*str) - && *str != ' ' && *str != '.' && *str != '+' && *str != '-') { - *str = ' '; + if (!isalpha(*str) && !isdigit(*str) && *str != ' ' && *str != '.' && *str != '+' && *str != '-') { + *str = ' '; } ++str; } @@ -235,7 +242,9 @@ char* convertNonPrintable2(char* str) char* ret = str; while (*str != '\0') { - if (*str < ' ' || *str > '~') *str = ' '; + if (*str < ' ' || *str > '~') { + *str = ' '; + } ++str; } return ret; @@ -245,10 +254,12 @@ int IsLegalFilePath(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 + // 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 + // The delimiter characters separating the device or format name from the source should have been split off of the + // path // const char* tst = str; @@ -265,11 +276,11 @@ int IsLegalFilePath(const char* str) #ifdef _WIN32 if (*tst == ' ' || *tst == '\\') { - tst++; - continue; - } + tst++; + continue; + } #endif - return 0; // Error - not compliant! + return 0; // Error - not compliant! } return 1; } @@ -279,11 +290,11 @@ int IsLegalFilePath(const char* str) /* * Allocating sprintf */ -#ifdef __APPLE__ +# ifdef __APPLE__ int asprintf(char** strp, const char* fmt, ...) -#else +# else int asprintf(char** strp, const char* fmt, ...) noexcept -#endif +# endif { va_list vargs; va_start(vargs, fmt); @@ -394,7 +405,9 @@ void FreeSplitStringTokens(char*** tokens) bool StringEquals(const char* a, const char* b) { - if (a == nullptr || b == nullptr) return false; + if (a == nullptr || b == nullptr) { + return false; + } while (*a != '\0') { if (*b == '\0' || *a != *b) { @@ -409,7 +422,9 @@ bool StringEquals(const char* a, const char* b) bool StringIEquals(const char* a, const char* b) { - if (a == nullptr || b == nullptr) return false; + if (a == nullptr || b == nullptr) { + return false; + } while (*a != '\0') { if (*b == '\0' || toupper(*a) != toupper(*b)) { @@ -424,7 +439,9 @@ bool StringIEquals(const char* a, const char* b) bool StringEndsWith(const char* str, const char* find) { - if (str == nullptr || find == nullptr) return false; + if (str == nullptr || find == nullptr) { + return false; + } size_t len = strlen(str); size_t find_len = strlen(find); @@ -432,11 +449,15 @@ bool StringEndsWith(const char* str, const char* find) const char* a = str + len; const char* b = find + find_len; - if (find_len > len) return false; + if (find_len > len) { + return false; + } size_t count = 0; while (count <= find_len) { - if (*a != *b) return false; + if (*a != *b) { + return false; + } --a; --b; ++count; diff --git a/source/clientserver/stringUtils.h b/source/clientserver/stringUtils.h old mode 100755 new mode 100644 index 50b401ba..afaf0a14 --- a/source/clientserver/stringUtils.h +++ b/source/clientserver/stringUtils.h @@ -1,24 +1,24 @@ #pragma once #ifndef UDA_CLIENTSERVER_STRINGUTILS_H -#define UDA_CLIENTSERVER_STRINGUTILS_H +# define UDA_CLIENTSERVER_STRINGUTILS_H -#include -#include -#include -#include "export.h" +# include "export.h" +# include +# include +# include -#ifndef _WIN32 -# include -#endif +# ifndef _WIN32 +# include +# endif -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif -#if !defined(_GNU_SOURCE) && !defined(strcasestr) +# if !defined(_GNU_SOURCE) && !defined(strcasestr) LIBRARY_API char* strcasestr(const char* haystack, const char* needle); -#endif +# endif // Reverse a String LIBRARY_API void reverseString(const char* in, char* out); @@ -42,13 +42,13 @@ LIBRARY_API char* LeftTrimString(char* str); LIBRARY_API void StringCopy(char* dest, const char* src, size_t len); -#ifdef __GNUC__ +# ifdef __GNUC__ // Convert all LowerCase Characters to Upper Case LIBRARY_API char* strupr(char* a); // Convert all UpperCase Characters to Lower Case LIBRARY_API char* strlwr(char* a); -#endif +# endif // Trim Internal Space Characters from a String LIBRARY_API char* MidTrimString(char* str); @@ -74,13 +74,13 @@ LIBRARY_API char* convertNonPrintable2(char* str); LIBRARY_API int IsLegalFilePath(const char* str); -#if !defined(asprintf) -# if defined(__cplusplus) && !defined(__APPLE__) +# if !defined(asprintf) +# if defined(__cplusplus) && !defined(__APPLE__) LIBRARY_API int asprintf(char** strp, const char* fmt, ...) noexcept; -# else +# else LIBRARY_API int asprintf(char** strp, const char* fmt, ...); +# endif # endif -#endif LIBRARY_API char** SplitString(const char* string, const char* delim); @@ -92,42 +92,39 @@ LIBRARY_API bool StringIEquals(const char* a, const char* b); LIBRARY_API bool StringEndsWith(const char* str, const char* find); -#define STR_STARTSWITH(X, Y) !strncmp(X, Y, strlen(Y)) -#define STR_ISTARTSWITH(X, Y) !strncasecmp(X, Y, strlen(Y)) +# define STR_STARTSWITH(X, Y) !strncmp(X, Y, strlen(Y)) +# define STR_ISTARTSWITH(X, Y) !strncasecmp(X, Y, strlen(Y)) -#define STR_EQUALS(X, Y) StringEquals(X, Y) -#define STR_IEQUALS(X, Y) StringIEquals(X, Y) +# define STR_EQUALS(X, Y) StringEquals(X, Y) +# define STR_IEQUALS(X, Y) StringIEquals(X, Y) -#ifdef __cplusplus +# ifdef __cplusplus } -#include -#include +# include +# include -namespace uda { +namespace uda +{ // remove non printable characters static inline void convert_non_printable(std::string& str) { - std::replace_if(str.begin(), str.end(), [](char c){ - return c < ' ' || c > '~'; - }, ' '); + std::replace_if( + str.begin(), str.end(), [](char c) { return c < ' ' || c > '~'; }, ' '); } // trim from start (in place) -static inline void ltrim(std::string &s) { - s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { - return !std::isspace(ch); - })); +static inline void ltrim(std::string& s) +{ + s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) { return !std::isspace(ch); })); } // trim from end (in place) -static inline void rtrim(std::string &s) { - s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { - return !std::isspace(ch); - }).base(), s.end()); -} +static inline void rtrim(std::string& s) +{ + s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) { return !std::isspace(ch); }).base(), s.end()); } -#endif // defined(__cplusplus) +} // namespace uda +# endif // defined(__cplusplus) #endif // UDA_CLIENTSERVER_STRINGUTILS_H - diff --git a/source/clientserver/udaDefines.cpp b/source/clientserver/udaDefines.cpp index 8467960c..5a107ddf 100644 --- a/source/clientserver/udaDefines.cpp +++ b/source/clientserver/udaDefines.cpp @@ -3,31 +3,31 @@ #if defined(_WIN32) -#include -#include -#include +# include +# include +# include -#if !defined(__MINGW32__) +# if !defined(__MINGW32__) int gettimeofday(struct timeval* tp, struct timezone* tzp) { // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) - // until 00:00:00 January 1, 1970 + // until 00:00:00 January 1, 1970 static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); - SYSTEMTIME system_time = { 0 }; - FILETIME file_time = { 0 }; + SYSTEMTIME system_time = {0}; + FILETIME file_time = {0}; uint64_t time = 0; GetSystemTime(&system_time); SystemTimeToFileTime(&system_time, &file_time); - time = ((uint64_t)file_time.dwLowDateTime ); + time = ((uint64_t)file_time.dwLowDateTime); time += ((uint64_t)file_time.dwHighDateTime) << 32; tp->tv_sec = (long)((time - EPOCH) / 10000000L); tp->tv_usec = (long)(system_time.wMilliseconds * 1000); return 0; } -#endif +# endif #endif diff --git a/source/clientserver/udaStructs.cpp b/source/clientserver/udaStructs.cpp index 752c1ad0..333c79d9 100644 --- a/source/clientserver/udaStructs.cpp +++ b/source/clientserver/udaStructs.cpp @@ -9,23 +9,23 @@ void freePutDataBlockList(PUTDATA_BLOCK_LIST* putDataBlockList) if (putDataBlockList->putDataBlock != nullptr && putDataBlockList->blockListSize > 0) { free(putDataBlockList->putDataBlock); } -// initPutDataBlockList(putDataBlockList); + // initPutDataBlockList(putDataBlockList); } -//void freeRequestData(REQUEST_DATA* request_data) +// void freeRequestData(REQUEST_DATA* request_data) //{ -// freeNameValueList(&request_data->nameValueList); -// freePutDataBlockList(&request_data->putDataBlockList); -//} +// freeNameValueList(&request_data->nameValueList); +// freePutDataBlockList(&request_data->putDataBlockList); +// } void freeRequestBlock(REQUEST_BLOCK* request_block) { -// for (int i = 0; i < request_block->num_requests; ++i) { -// freeRequestData(&request_block->requests[0]); -// } -// free(request_block->requests); -// request_block->num_requests = 0; -// request_block->requests = nullptr; + // for (int i = 0; i < request_block->num_requests; ++i) { + // freeRequestData(&request_block->requests[0]); + // } + // free(request_block->requests); + // request_block->num_requests = 0; + // request_block->requests = nullptr; } void freeClientPutDataBlockList(PUTDATA_BLOCK_LIST* putDataBlockList) @@ -33,7 +33,7 @@ void freeClientPutDataBlockList(PUTDATA_BLOCK_LIST* putDataBlockList) if (putDataBlockList->putDataBlock != nullptr && putDataBlockList->blockListSize > 0) { free(putDataBlockList->putDataBlock); } -// initPutDataBlockList(putDataBlockList); + // initPutDataBlockList(putDataBlockList); } void freeDataBlock(DATA_BLOCK* data_block) @@ -52,7 +52,9 @@ void freeDataBlock(DATA_BLOCK* data_block) switch (data_block->opaque_type) { case UDA_OPAQUE_TYPE_XML_DOCUMENT: { - if (data_block->opaque_block != nullptr) free(data_block->opaque_block); + if (data_block->opaque_block != nullptr) { + free(data_block->opaque_block); + } data_block->opaque_count = 0; data_block->opaque_block = nullptr; break; @@ -60,18 +62,18 @@ void freeDataBlock(DATA_BLOCK* data_block) case UDA_OPAQUE_TYPE_STRUCTURES: { if (data_block->opaque_block != nullptr) { -// if (logmalloclist != nullptr) { -// freeMallocLogList(logmalloclist); -// free(logmalloclist); -// logmalloclist = nullptr; -// } + // if (logmalloclist != nullptr) { + // freeMallocLogList(logmalloclist); + // free(logmalloclist); + // logmalloclist = nullptr; + // } data_block->opaque_count = 0; data_block->opaque_block = nullptr; data_block->data_type = UDA_TYPE_UNKNOWN; data_block->opaque_type = UDA_OPAQUE_TYPE_UNKNOWN; - data_block->data = nullptr; // Added to Malloc Log List for freeing + data_block->data = nullptr; // Added to Malloc Log List for freeing } break; } @@ -109,9 +111,15 @@ void freeDataBlock(DATA_BLOCK* data_block) rank = data_block->rank; ddims = data_block->dims; - if ((cptr = (void*)data_block->data) != nullptr) free(cptr); - if ((cptr = (void*)data_block->errhi) != nullptr) free(cptr); - if ((cptr = (void*)data_block->errlo) != nullptr) free(cptr); + if ((cptr = (void*)data_block->data) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->errhi) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->errlo) != nullptr) { + free(cptr); + } data_block->data = nullptr; data_block->errhi = nullptr; @@ -126,27 +134,39 @@ void freeDataBlock(DATA_BLOCK* data_block) UDA_LOG(UDA_LOG_DEBUG, "Dimension[%d] \n", i); UDA_LOG(UDA_LOG_DEBUG, "Dimension Data \n"); - if ((cptr = (void*)ddims[i].dim) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].dim) != nullptr) { + free(cptr); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Error Hi \n"); - if ((cptr = (void*)ddims[i].errhi) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].errhi) != nullptr) { + free(cptr); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Error Lo \n"); - if ((cptr = (void*)ddims[i].errlo) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].errlo) != nullptr) { + free(cptr); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension Sams \n"); - if ((cptr = (void*)ddims[i].sams) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].sams) != nullptr) { + free(cptr); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension offs \n"); - if ((cptr = (void*)ddims[i].offs) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].offs) != nullptr) { + free(cptr); + } UDA_LOG(UDA_LOG_DEBUG, "Dimension ints \n"); - if ((cptr = (void*)ddims[i].ints) != nullptr) free(cptr); + if ((cptr = (void*)ddims[i].ints) != nullptr) { + free(cptr); + } data_block->dims[i].dim = nullptr; data_block->dims[i].errhi = nullptr; @@ -170,7 +190,6 @@ void freeDataBlock(DATA_BLOCK* data_block) data_block->error_type = UDA_TYPE_UNKNOWN; data_block->data_n = 0; data_block->error_param_n = 0; - } UDA_LOG(UDA_LOG_DEBUG, "Exit\n"); @@ -190,23 +209,28 @@ void freeDataBlockList(DATA_BLOCK_LIST* data_block_list) void freeReducedDataBlock(DATA_BLOCK* data_block) { #ifdef FATCLIENT - if(data_block == nullptr) return; - if(data_block->opaque_type != UDA_OPAQUE_TYPE_STRUCTURES) return; - if(data_block->opaque_block == nullptr) return; + if (data_block == nullptr) { + return; + } + if (data_block->opaque_type != UDA_OPAQUE_TYPE_STRUCTURES) { + return; + } + if (data_block->opaque_block == nullptr) { + return; + } -// if(logmalloclist != nullptr) { -// freeMallocLogList(logmalloclist); -// free((void *)logmalloclist); -// logmalloclist = nullptr; -// } + // if(logmalloclist != nullptr) { + // freeMallocLogList(logmalloclist); + // free((void *)logmalloclist); + // logmalloclist = nullptr; + // } data_block->opaque_count = 0; data_block->opaque_block = nullptr; - data_block->data_type = UDA_TYPE_UNKNOWN; - data_block->opaque_type = UDA_OPAQUE_TYPE_UNKNOWN; + data_block->data_type = UDA_TYPE_UNKNOWN; + data_block->opaque_type = UDA_OPAQUE_TYPE_UNKNOWN; - data_block->data = nullptr; // Added to Malloc Log List for freeing + data_block->data = nullptr; // Added to Malloc Log List for freeing return; #endif } - diff --git a/source/clientserver/userid.cpp b/source/clientserver/userid.cpp old mode 100755 new mode 100644 index e3d44c6f..38488afa --- a/source/clientserver/userid.cpp +++ b/source/clientserver/userid.cpp @@ -25,14 +25,13 @@ void userid(char* uid) const char* user; uid[0] = '\0'; # if defined(cuserid) - if((user = cuserid(nullptr)) != nullptr) { + if ((user = cuserid(nullptr)) != nullptr) { copyString(user, uid, STRING_LENGTH); return; } else # endif - if ((user = getlogin()) != nullptr - || (user = getenv("USER")) != nullptr - || (user = getenv("LOGNAME")) != nullptr) { + if ((user = getlogin()) != nullptr || (user = getenv("USER")) != nullptr || + (user = getenv("LOGNAME")) != nullptr) { copyString(user, uid, STRING_LENGTH); return; } diff --git a/source/clientserver/userid.h b/source/clientserver/userid.h old mode 100755 new mode 100644 index 68d60e55..3e92aef8 --- a/source/clientserver/userid.h +++ b/source/clientserver/userid.h @@ -1,7 +1,7 @@ #pragma once #ifndef UDA_CLIENTSERVER_USERID_H -#define UDA_CLIENTSERVER_USERID_H +# define UDA_CLIENTSERVER_USERID_H void userid(char* uid); diff --git a/source/clientserver/xdrHData.cpp b/source/clientserver/xdrHData.cpp old mode 100755 new mode 100644 index 344368e8..2cdbce99 --- a/source/clientserver/xdrHData.cpp +++ b/source/clientserver/xdrHData.cpp @@ -5,198 +5,160 @@ #ifdef HIERARCHICAL_DATA -#include "xdrHData.h" +# include "xdrHData.h" //----------------------------------------------------------------------- // Signal Instance -bool_t xdr_instance(XDR *xdrs, INSTANCE *str) { - return( WrapXDRString(xdrs, (char *)str->archive, XMLMAXSTRING) - && WrapXDRString(xdrs, (char *)str->file, XMLMAXSTRING) - && WrapXDRString(xdrs, (char *)str->signal, XMLMAXSTRING) - && WrapXDRString(xdrs, (char *)str->owner, XMLMAXSTRING) - && WrapXDRString(xdrs, (char *)str->format, XMLMAXSTRING) - && xdr_int(xdrs, &str->seq) - && xdr_int(xdrs, &str->status) - && xdr_float(xdrs, &str->factor) - ); +bool_t xdr_instance(XDR* xdrs, INSTANCE* str) +{ + return ( + WrapXDRString(xdrs, (char*)str->archive, XMLMAXSTRING) && WrapXDRString(xdrs, (char*)str->file, XMLMAXSTRING) && + WrapXDRString(xdrs, (char*)str->signal, XMLMAXSTRING) && WrapXDRString(xdrs, (char*)str->owner, XMLMAXSTRING) && + WrapXDRString(xdrs, (char*)str->format, XMLMAXSTRING) && xdr_int(xdrs, &str->seq) && + xdr_int(xdrs, &str->status) && xdr_float(xdrs, &str->factor)); } //----------------------------------------------------------------------- // Toroidal Magnetic Field -bool_t xdr_toroidalfield(XDR *xdrs, TOROIDALFIELD *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_toroidalfield(XDR* xdrs, TOROIDALFIELD* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } //----------------------------------------------------------------------- // Plasma Current -bool_t xdr_plasmacurrent(XDR *xdrs, PLASMACURRENT *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_plasmacurrent(XDR* xdrs, PLASMACURRENT* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } //----------------------------------------------------------------------- // Diamagnetic Flux -bool_t xdr_diamagnetic(XDR *xdrs, DIAMAGNETIC *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_diamagnetic(XDR* xdrs, DIAMAGNETIC* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } //----------------------------------------------------------------------- // PF Circuit -bool_t xdr_pfcircuit1(XDR *xdrs, PFCIRCUIT *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_int(xdrs, &str->nco) - && xdr_int(xdrs, &str->supply) - ); +bool_t xdr_pfcircuit1(XDR* xdrs, PFCIRCUIT* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_int(xdrs, &str->nco) && xdr_int(xdrs, &str->supply)); } -bool_t xdr_pfcircuit2(XDR *xdrs, PFCIRCUIT *str) { - return(xdr_vector(xdrs, (char *)str->coil, (int)str->nco, sizeof(int), (xdrproc_t)xdr_int)); +bool_t xdr_pfcircuit2(XDR* xdrs, PFCIRCUIT* str) +{ + return (xdr_vector(xdrs, (char*)str->coil, (int)str->nco, sizeof(int), (xdrproc_t)xdr_int)); } //----------------------------------------------------------------------- // Magnetic Probe -bool_t xdr_magprobe(XDR *xdrs, MAGPROBE *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_float(xdrs, &str->r) - && xdr_float(xdrs, &str->z) - && xdr_float(xdrs, &str->angle) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_magprobe(XDR* xdrs, MAGPROBE* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_float(xdrs, &str->r) && xdr_float(xdrs, &str->z) && xdr_float(xdrs, &str->angle) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } //----------------------------------------------------------------------- // PF Supplies -bool_t xdr_pfsupplies(XDR *xdrs, PFSUPPLIES *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_pfsupplies(XDR* xdrs, PFSUPPLIES* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } //----------------------------------------------------------------------- // Flux Loops -bool_t xdr_fluxloop1(XDR *xdrs, FLUXLOOP *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_int(xdrs, &str->nco) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_fluxloop1(XDR* xdrs, FLUXLOOP* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_int(xdrs, &str->nco) && xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } -bool_t xdr_fluxloop2(XDR *xdrs, FLUXLOOP *str) { - return( xdr_vector(xdrs, (char *)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->dphi, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - ); +bool_t xdr_fluxloop2(XDR* xdrs, FLUXLOOP* str) +{ + return (xdr_vector(xdrs, (char*)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->dphi, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float)); } //----------------------------------------------------------------------- // PF Passive -bool_t xdr_pfpassive1(XDR *xdrs, PFPASSIVE *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_int(xdrs, &str->nco) - && xdr_int(xdrs, &str->modelnrnz[0]) - && xdr_int(xdrs, &str->modelnrnz[1]) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_pfpassive1(XDR* xdrs, PFPASSIVE* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_int(xdrs, &str->nco) && xdr_int(xdrs, &str->modelnrnz[0]) && xdr_int(xdrs, &str->modelnrnz[1]) && + xdr_float(xdrs, &str->aerr) && xdr_float(xdrs, &str->rerr)); } - -bool_t xdr_pfpassive2(XDR *xdrs, PFPASSIVE *str) { - return( xdr_vector(xdrs, (char *)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->dr, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->dz, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->ang1, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->ang2, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->res, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - ); +bool_t xdr_pfpassive2(XDR* xdrs, PFPASSIVE* str) +{ + return (xdr_vector(xdrs, (char*)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->dr, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->dz, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->ang1, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->ang2, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->res, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float)); } //----------------------------------------------------------------------- // PF Coils -bool_t xdr_pfcoils1(XDR *xdrs, PFCOILS *str) { - return( WrapXDRString(xdrs, (char *)str->id, XMLMAXSTRING) - && xdr_instance(xdrs, &str->instance) - && xdr_int(xdrs, &str->nco) - && xdr_int(xdrs, &str->turns) - && xdr_float(xdrs, &str->fturns) - && xdr_int(xdrs, &str->modelnrnz[0]) - && xdr_int(xdrs, &str->modelnrnz[1]) - && xdr_float(xdrs, &str->aerr) - && xdr_float(xdrs, &str->rerr) - ); +bool_t xdr_pfcoils1(XDR* xdrs, PFCOILS* str) +{ + return (WrapXDRString(xdrs, (char*)str->id, XMLMAXSTRING) && xdr_instance(xdrs, &str->instance) && + xdr_int(xdrs, &str->nco) && xdr_int(xdrs, &str->turns) && xdr_float(xdrs, &str->fturns) && + xdr_int(xdrs, &str->modelnrnz[0]) && xdr_int(xdrs, &str->modelnrnz[1]) && xdr_float(xdrs, &str->aerr) && + xdr_float(xdrs, &str->rerr)); } -bool_t xdr_pfcoils2(XDR *xdrs, PFCOILS *str) { - return( xdr_vector(xdrs, (char *)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->dr, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->dz, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - ); +bool_t xdr_pfcoils2(XDR* xdrs, PFCOILS* str) +{ + return (xdr_vector(xdrs, (char*)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->dr, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->dz, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float)); } - //----------------------------------------------------------------------- // Limiter -bool_t xdr_limiter1(XDR *xdrs, LIMITER *str) { - return( xdr_int(xdrs, &str->nco) - && xdr_float(xdrs, &str->factor) - ); +bool_t xdr_limiter1(XDR* xdrs, LIMITER* str) +{ + return (xdr_int(xdrs, &str->nco) && xdr_float(xdrs, &str->factor)); } -bool_t xdr_limiter2(XDR *xdrs, LIMITER *str) { - return( xdr_vector(xdrs, (char *)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, (char *)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) - ); +bool_t xdr_limiter2(XDR* xdrs, LIMITER* str) +{ + return (xdr_vector(xdrs, (char*)str->r, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, (char*)str->z, (int)str->nco, sizeof(float), (xdrproc_t)xdr_float)); } //----------------------------------------------------------------------- // EFIT -bool_t xdr_efit(XDR *xdrs, EFIT *str) { - return( WrapXDRString(xdrs, (char *)str->device, XMLMAXSTRING) - && xdr_int(xdrs, &str->exp_number) - && xdr_int(xdrs, &str->nfluxloops) - && xdr_int(xdrs, &str->nmagprobes) - && xdr_int(xdrs, &str->npfcircuits) - && xdr_int(xdrs, &str->npfpassive) - && xdr_int(xdrs, &str->npfsupplies) - && xdr_int(xdrs, &str->nplasmacurrent) - && xdr_int(xdrs, &str->ndiamagnetic) - && xdr_int(xdrs, &str->ntoroidalfield) - && xdr_int(xdrs, &str->npfcoils) - && xdr_int(xdrs, &str->nlimiter) - ); +bool_t xdr_efit(XDR* xdrs, EFIT* str) +{ + return (WrapXDRString(xdrs, (char*)str->device, XMLMAXSTRING) && xdr_int(xdrs, &str->exp_number) && + xdr_int(xdrs, &str->nfluxloops) && xdr_int(xdrs, &str->nmagprobes) && xdr_int(xdrs, &str->npfcircuits) && + xdr_int(xdrs, &str->npfpassive) && xdr_int(xdrs, &str->npfsupplies) && + xdr_int(xdrs, &str->nplasmacurrent) && xdr_int(xdrs, &str->ndiamagnetic) && + xdr_int(xdrs, &str->ntoroidalfield) && xdr_int(xdrs, &str->npfcoils) && xdr_int(xdrs, &str->nlimiter)); } #endif diff --git a/source/clientserver/xdrHData.h b/source/clientserver/xdrHData.h old mode 100755 new mode 100644 index d1afa227..c730fba1 --- a/source/clientserver/xdrHData.h +++ b/source/clientserver/xdrHData.h @@ -9,61 +9,61 @@ extern "C" { #ifdef HIERARCHICAL_DATA -#include "idamclientserver.h" -#include "idamclientserverxml.h" +# include "idamclientserver.h" +# include "idamclientserverxml.h" //----------------------------------------------------------------------- // Signal Instance -LIBRARY_API bool_t xdr_instance(XDR *xdrs, INSTANCE *str); +LIBRARY_API bool_t xdr_instance(XDR* xdrs, INSTANCE* str); //----------------------------------------------------------------------- // Toroidal Magnetic Field -LIBRARY_API bool_t xdr_toroidalfield(XDR *xdrs, TOROIDALFIELD *str); +LIBRARY_API bool_t xdr_toroidalfield(XDR* xdrs, TOROIDALFIELD* str); //----------------------------------------------------------------------- // Plasma Current -LIBRARY_API bool_t xdr_plasmacurrent(XDR *xdrs, PLASMACURRENT *str); +LIBRARY_API bool_t xdr_plasmacurrent(XDR* xdrs, PLASMACURRENT* str); //----------------------------------------------------------------------- // Diamagnetic Flux -LIBRARY_API bool_t xdr_diamagnetic(XDR *xdrs, DIAMAGNETIC *str); +LIBRARY_API bool_t xdr_diamagnetic(XDR* xdrs, DIAMAGNETIC* str); //----------------------------------------------------------------------- // PF Circuit -LIBRARY_API bool_t xdr_pfcircuit1(XDR *xdrs, PFCIRCUIT *str); -LIBRARY_API bool_t xdr_pfcircuit2(XDR *xdrs, PFCIRCUIT *str); +LIBRARY_API bool_t xdr_pfcircuit1(XDR* xdrs, PFCIRCUIT* str); +LIBRARY_API bool_t xdr_pfcircuit2(XDR* xdrs, PFCIRCUIT* str); //----------------------------------------------------------------------- // Magnetic Probe -LIBRARY_API bool_t xdr_magprobe(XDR *xdrs, MAGPROBE *str); +LIBRARY_API bool_t xdr_magprobe(XDR* xdrs, MAGPROBE* str); //----------------------------------------------------------------------- // PF Supplies -LIBRARY_API bool_t xdr_pfsupplies(XDR *xdrs, PFSUPPLIES *str); +LIBRARY_API bool_t xdr_pfsupplies(XDR* xdrs, PFSUPPLIES* str); //----------------------------------------------------------------------- // Flux Loops -LIBRARY_API bool_t xdr_fluxloop1(XDR *xdrs, FLUXLOOP *str); -LIBRARY_API bool_t xdr_fluxloop2(XDR *xdrs, FLUXLOOP *str); +LIBRARY_API bool_t xdr_fluxloop1(XDR* xdrs, FLUXLOOP* str); +LIBRARY_API bool_t xdr_fluxloop2(XDR* xdrs, FLUXLOOP* str); //----------------------------------------------------------------------- // PF Passive -LIBRARY_API bool_t xdr_pfpassive1(XDR *xdrs, PFPASSIVE *str); -LIBRARY_API bool_t xdr_pfpassive2(XDR *xdrs, PFPASSIVE *str); +LIBRARY_API bool_t xdr_pfpassive1(XDR* xdrs, PFPASSIVE* str); +LIBRARY_API bool_t xdr_pfpassive2(XDR* xdrs, PFPASSIVE* str); //----------------------------------------------------------------------- // PF Coils -LIBRARY_API bool_t xdr_pfcoils1(XDR *xdrs, PFCOILS *str); -LIBRARY_API bool_t xdr_pfcoils2(XDR *xdrs, PFCOILS *str); +LIBRARY_API bool_t xdr_pfcoils1(XDR* xdrs, PFCOILS* str); +LIBRARY_API bool_t xdr_pfcoils2(XDR* xdrs, PFCOILS* str); //----------------------------------------------------------------------- // Limiter -LIBRARY_API bool_t xdr_limiter1(XDR *xdrs, LIMITER *str); -LIBRARY_API bool_t xdr_limiter2(XDR *xdrs, LIMITER *str); +LIBRARY_API bool_t xdr_limiter1(XDR* xdrs, LIMITER* str); +LIBRARY_API bool_t xdr_limiter2(XDR* xdrs, LIMITER* str); //----------------------------------------------------------------------- // EFIT -LIBRARY_API bool_t xdr_efit(XDR *xdrs, EFIT *str); +LIBRARY_API bool_t xdr_efit(XDR* xdrs, EFIT* str); #endif // HIERARCHICAL_DATA @@ -72,4 +72,3 @@ LIBRARY_API bool_t xdr_efit(XDR *xdrs, EFIT *str); #endif #endif // UDA_CLIENTSERVER_XDRHDATA_H - diff --git a/source/clientserver/xdrlib.cpp b/source/clientserver/xdrlib.cpp old mode 100755 new mode 100644 index acdfefbc..748ab146 --- a/source/clientserver/xdrlib.cpp +++ b/source/clientserver/xdrlib.cpp @@ -7,15 +7,15 @@ #include "xdrlib.h" -#include #include +#include -#include #include "struct.h" #include +#include -#include "printStructs.h" #include "errorLog.h" +#include "printStructs.h" #include "stringUtils.h" //----------------------------------------------------------------------- @@ -41,13 +41,17 @@ int protocolVersionTypeTest(int protocol_version, int type) } } else { if (protocol_version < 4) { - if (type == UDA_TYPE_COMPOUND) return 1; + if (type == UDA_TYPE_COMPOUND) { + return 1; + } } if (protocol_version < 6) { - if (type == UDA_TYPE_STRING) return 1; + if (type == UDA_TYPE_STRING) { + return 1; + } } } - return 0; // Return Test False: This type is OK + return 0; // Return Test False: This type is OK } //----------------------------------------------------------------------- @@ -77,14 +81,10 @@ bool_t xdr_meta(XDR* xdrs, DATA_BLOCK* str) bool_t xdr_securityBlock1(XDR* xdrs, SECURITY_BLOCK* str) { - int rc = xdr_u_short(xdrs, &str->structVersion) - && xdr_u_short(xdrs, &str->encryptionMethod) - && xdr_u_short(xdrs, &str->authenticationStep) - && xdr_u_short(xdrs, &str->client_ciphertextLength) - && xdr_u_short(xdrs, &str->client2_ciphertextLength) - && xdr_u_short(xdrs, &str->server_ciphertextLength) - && xdr_u_short(xdrs, &str->client_X509Length) - && xdr_u_short(xdrs, &str->client2_X509Length); + int rc = xdr_u_short(xdrs, &str->structVersion) && xdr_u_short(xdrs, &str->encryptionMethod) && + xdr_u_short(xdrs, &str->authenticationStep) && xdr_u_short(xdrs, &str->client_ciphertextLength) && + xdr_u_short(xdrs, &str->client2_ciphertextLength) && xdr_u_short(xdrs, &str->server_ciphertextLength) && + xdr_u_short(xdrs, &str->client_X509Length) && xdr_u_short(xdrs, &str->client2_X509Length); return rc; } @@ -93,33 +93,28 @@ bool_t xdr_securityBlock2(XDR* xdrs, SECURITY_BLOCK* str) int rc = 1; if (str->client_ciphertextLength > 0) { - rc = rc && xdr_vector(xdrs, (char*)str->client_ciphertext, - (int)str->client_ciphertextLength, + rc = rc && xdr_vector(xdrs, (char*)str->client_ciphertext, (int)str->client_ciphertextLength, sizeof(unsigned char), (xdrproc_t)xdr_u_char); } if (str->client2_ciphertextLength > 0) { - rc = rc && xdr_vector(xdrs, (char*)str->client2_ciphertext, - (int)str->client2_ciphertextLength, + rc = rc && xdr_vector(xdrs, (char*)str->client2_ciphertext, (int)str->client2_ciphertextLength, sizeof(unsigned char), (xdrproc_t)xdr_u_char); } if (str->server_ciphertextLength > 0) { - rc = rc && xdr_vector(xdrs, (char*)str->server_ciphertext, - (int)str->server_ciphertextLength, + rc = rc && xdr_vector(xdrs, (char*)str->server_ciphertext, (int)str->server_ciphertextLength, sizeof(unsigned char), (xdrproc_t)xdr_u_char); } if (str->client_X509Length > 0) { - rc = rc && xdr_vector(xdrs, (char*)str->client_X509, - (int)str->client_X509Length, - sizeof(unsigned char), (xdrproc_t)xdr_u_char); + rc = rc && xdr_vector(xdrs, (char*)str->client_X509, (int)str->client_X509Length, sizeof(unsigned char), + (xdrproc_t)xdr_u_char); } if (str->client2_X509Length > 0) { - rc = rc && xdr_vector(xdrs, (char*)str->client2_X509, - (int)str->client2_X509Length, - sizeof(unsigned char), (xdrproc_t)xdr_u_char); + rc = rc && xdr_vector(xdrs, (char*)str->client2_X509, (int)str->client2_X509Length, sizeof(unsigned char), + (xdrproc_t)xdr_u_char); } return rc; @@ -134,7 +129,6 @@ bool_t xdr_securityBlock2(XDR* xdrs, SECURITY_BLOCK* str) // Server ignores what it doesn't need // Server must flush the tcp buffer before the next - // Notes: // debug_level ** Not Used // get_datadble ** Client Side Only @@ -148,13 +142,10 @@ bool_t xdr_securityBlock2(XDR* xdrs, SECURITY_BLOCK* str) // get_uncal // get_notoff - bool_t xdr_client(XDR* xdrs, CLIENT_BLOCK* str, int protocolVersion) { - int rc = xdr_int(xdrs, &str->version) - && xdr_int(xdrs, &str->pid) - && xdr_int(xdrs, &str->timeout) - && WrapXDRString(xdrs, (char*)str->uid, STRING_LENGTH); + int rc = xdr_int(xdrs, &str->version) && xdr_int(xdrs, &str->pid) && xdr_int(xdrs, &str->timeout) && + WrapXDRString(xdrs, (char*)str->uid, STRING_LENGTH); if (str->version < protocolVersion) { protocolVersion = str->version; @@ -165,23 +156,16 @@ bool_t xdr_client(XDR* xdrs, CLIENT_BLOCK* str, int protocolVersion) if (protocolVersion >= 6) { rc = rc && xdr_u_int(xdrs, &str->clientFlags) && xdr_int(xdrs, &str->altRank); } else { - int temp = 0; // retain Legacy! - rc = rc && xdr_int(xdrs, &temp) // Changed type (was verbose & not used) - && xdr_int(xdrs, &str->altRank); // (was debug) + int temp = 0; // retain Legacy! + rc = rc && xdr_int(xdrs, &temp) // Changed type (was verbose & not used) + && xdr_int(xdrs, &str->altRank); // (was debug) str->clientFlags = (unsigned int)temp; } - rc = rc && xdr_int(xdrs, &str->get_nodimdata) - && xdr_int(xdrs, &str->get_datadble) - && xdr_int(xdrs, &str->get_timedble) - && xdr_int(xdrs, &str->get_dimdble) - && xdr_int(xdrs, &str->get_scalar) - && xdr_int(xdrs, &str->get_bytes) - && xdr_int(xdrs, &str->get_bad) - && xdr_int(xdrs, &str->get_meta) - && xdr_int(xdrs, &str->get_asis) - && xdr_int(xdrs, &str->get_uncal) - && xdr_int(xdrs, &str->get_notoff); + rc = rc && xdr_int(xdrs, &str->get_nodimdata) && xdr_int(xdrs, &str->get_datadble) && + xdr_int(xdrs, &str->get_timedble) && xdr_int(xdrs, &str->get_dimdble) && xdr_int(xdrs, &str->get_scalar) && + xdr_int(xdrs, &str->get_bytes) && xdr_int(xdrs, &str->get_bad) && xdr_int(xdrs, &str->get_meta) && + xdr_int(xdrs, &str->get_asis) && xdr_int(xdrs, &str->get_uncal) && xdr_int(xdrs, &str->get_notoff); // output (ENCODE) means written by the client // input (DECODE) means read by the server @@ -196,18 +180,17 @@ bool_t xdr_client(XDR* xdrs, CLIENT_BLOCK* str, int protocolVersion) } if (xdrs->x_op == XDR_DECODE && protocolVersion < 6) { - str->clientFlags = 0; // The original properties have no effect on the server whatever the version + str->clientFlags = 0; // The original properties have no effect on the server whatever the version str->altRank = 0; } if (protocolVersion >= 7) { - rc = rc && WrapXDRString(xdrs, (char*)str->OSName, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->DOI, STRING_LENGTH); + rc = rc && WrapXDRString(xdrs, (char*)str->OSName, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->DOI, STRING_LENGTH); #ifdef SECURITYENABLED - rc = rc && WrapXDRString(xdrs, (char *)str->uid2, STRING_LENGTH); + rc = rc && WrapXDRString(xdrs, (char*)str->uid2, STRING_LENGTH); #endif - } UDA_LOG(UDA_LOG_DEBUG, "protocolVersion %d\n", protocolVersion); @@ -227,12 +210,12 @@ bool_t xdr_server1(XDR* xdrs, SERVER_BLOCK* str, int protocolVersion) rc = xdr_int(xdrs, &str->version); - if (xdrs->x_op == XDR_DECODE && rc) { // Test for a server crash! + if (xdrs->x_op == XDR_DECODE && rc) { // Test for a server crash! if (serverVersion == 0) { - serverVersion = str->version; // Assume OK on first exchange - } else if (serverVersion != str->version) { // Usually different if the server has crashed - rc = 0; // Force an error - str->version = serverVersion; // Replace the erroneous version number + serverVersion = str->version; // Assume OK on first exchange + } else if (serverVersion != str->version) { // Usually different if the server has crashed + rc = 0; // Force an error + str->version = serverVersion; // Replace the erroneous version number UDA_LOG(UDA_LOG_DEBUG, "Server #1 rc = %d\n", rc); return rc; } @@ -254,10 +237,10 @@ bool_t xdr_server1(XDR* xdrs, SERVER_BLOCK* str, int protocolVersion) UDA_LOG(UDA_LOG_DEBUG, "Server #1 protocolVersion %d [rc = %d]\n", protocolVersion, rc); if ((xdrs->x_op == XDR_DECODE && protocolVersion >= 7) || (xdrs->x_op == XDR_ENCODE && protocolVersion >= 7)) { - rc = rc && WrapXDRString(xdrs, (char*)str->OSName, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->DOI, STRING_LENGTH); + rc = rc && WrapXDRString(xdrs, (char*)str->OSName, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->DOI, STRING_LENGTH); #ifdef SECURITYENABLED - //rc = rc && xdr_securityBlock(xdrs, &str->securityBlock); + // rc = rc && xdr_securityBlock(xdrs, &str->securityBlock); #endif } @@ -270,10 +253,10 @@ bool_t xdr_server2(XDR* xdrs, SERVER_BLOCK* str) { int rc = 1; for (unsigned int i = 0; i < str->idamerrorstack.nerrors; i++) { - rc = rc && xdr_int(xdrs, &str->idamerrorstack.idamerror[i].type) - && xdr_int(xdrs, &str->idamerrorstack.idamerror[i].code) - && WrapXDRString(xdrs, (char*)str->idamerrorstack.idamerror[i].location, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->idamerrorstack.idamerror[i].msg, STRING_LENGTH); + rc = rc && xdr_int(xdrs, &str->idamerrorstack.idamerror[i].type) && + xdr_int(xdrs, &str->idamerrorstack.idamerror[i].code) && + WrapXDRString(xdrs, (char*)str->idamerrorstack.idamerror[i].location, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->idamerrorstack.idamerror[i].msg, STRING_LENGTH); UDA_LOG(UDA_LOG_DEBUG, "xdr_server2 [%d] %s\n", i, str->idamerrorstack.idamerror[i].msg); } @@ -285,9 +268,8 @@ bool_t xdr_server2(XDR* xdrs, SERVER_BLOCK* str) bool_t xdr_server(XDR* xdrs, SERVER_BLOCK* str) { - return xdr_int(xdrs, &str->version) - && xdr_int(xdrs, &str->error) - && WrapXDRString(xdrs, (char*)str->msg, STRING_LENGTH); + return xdr_int(xdrs, &str->version) && xdr_int(xdrs, &str->error) && + WrapXDRString(xdrs, (char*)str->msg, STRING_LENGTH); } //----------------------------------------------------------------------- @@ -311,9 +293,8 @@ bool_t xdr_request_data(XDR* xdrs, REQUEST_DATA* str, int protocolVersion) rc = rc && WrapXDRString(xdrs, (char*)str->signal, MAXMETA); if ((xdrs->x_op == XDR_DECODE && protocolVersion >= 6) || (xdrs->x_op == XDR_ENCODE && protocolVersion >= 6)) { - rc = rc - && WrapXDRString(xdrs, (char*)str->source, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->api_delim, MAXNAME); + rc = rc && WrapXDRString(xdrs, (char*)str->source, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->api_delim, MAXNAME); } if (protocolVersion >= 7) { @@ -363,12 +344,9 @@ bool_t xdr_putdatablocklist_block(XDR* xdrs, PUTDATA_BLOCK_LIST* str) bool_t xdr_putdata_block1(XDR* xdrs, PUTDATA_BLOCK* str) { int rc = 1; - rc = rc && xdr_u_int(xdrs, &str->rank) - && xdr_u_int(xdrs, &str->count) - && xdr_int(xdrs, &str->data_type) - && xdr_int(xdrs, &str->opaque_type) - && xdr_int(xdrs, &str->opaque_count) - && xdr_u_int(xdrs, &str->blockNameLength); + rc = rc && xdr_u_int(xdrs, &str->rank) && xdr_u_int(xdrs, &str->count) && xdr_int(xdrs, &str->data_type) && + xdr_int(xdrs, &str->opaque_type) && xdr_int(xdrs, &str->opaque_count) && + xdr_u_int(xdrs, &str->blockNameLength); return rc; } @@ -379,7 +357,9 @@ bool_t xdr_putdata_block2(XDR* xdrs, PUTDATA_BLOCK* str) rc = rc && xdr_vector(xdrs, (char*)str->shape, (int)str->rank, sizeof(int), (xdrproc_t)xdr_int); } - if (str->blockNameLength > 0) rc = rc && WrapXDRString(xdrs, (char*)str->blockName, str->blockNameLength + 1); + if (str->blockNameLength > 0) { + rc = rc && WrapXDRString(xdrs, (char*)str->blockName, str->blockNameLength + 1); + } switch (str->data_type) { case UDA_TYPE_FLOAT: @@ -427,73 +407,73 @@ bool_t xdr_putdata_block2(XDR* xdrs, PUTDATA_BLOCK* str) // General Data structures are passed using a specialised set of xdr components case UDA_TYPE_COMPOUND: - return rc; // Nothing to send so retain good return code + return rc; // Nothing to send so retain good return code default: return 0; } } - //----------------------------------------------------------------------- // Data Objects bool_t xdr_data_object1(XDR* xdrs, DATA_OBJECT* str) { - int rc = xdr_u_short(xdrs, &str->objectType) - && xdr_u_int(xdrs, &str->objectSize) - && xdr_u_short(xdrs, &str->hashLength); + int rc = + xdr_u_short(xdrs, &str->objectType) && xdr_u_int(xdrs, &str->objectSize) && xdr_u_short(xdrs, &str->hashLength); return rc; } bool_t xdr_data_object2(XDR* xdrs, DATA_OBJECT* str) { - int rc = xdr_opaque(xdrs, str->object, (unsigned int)str->objectSize) - && xdr_vector(xdrs, str->md, str->hashLength, sizeof(char), (xdrproc_t)xdr_char); + int rc = xdr_opaque(xdrs, str->object, (unsigned int)str->objectSize) && + xdr_vector(xdrs, str->md, str->hashLength, sizeof(char), (xdrproc_t)xdr_char); return rc; } -bool_t -xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, DATA_BLOCK* str, - int protocolVersion, bool xdr_stdio_flag, LOGSTRUCTLIST* log_struct_list, int malloc_source) +bool_t xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + DATA_BLOCK* str, int protocolVersion, bool xdr_stdio_flag, LOGSTRUCTLIST* log_struct_list, + int malloc_source) { int err = 0, rc = 1; int packageType = 0; void* data = nullptr; - if (xdrs->x_op == XDR_ENCODE) { // Send Data + if (xdrs->x_op == XDR_ENCODE) { // Send Data - SARRAY sarray; // Structure array carrier structure + SARRAY sarray; // Structure array carrier structure SARRAY* psarray = &sarray; - int shape = str->data_n; // rank 1 array of dimension lengths - auto udt = (USERDEFINEDTYPE*)str->opaque_block; // The data's structure definition + int shape = str->data_n; // rank 1 array of dimension lengths + auto udt = (USERDEFINEDTYPE*)str->opaque_block; // The data's structure definition auto u = findUserDefinedType(userdefinedtypelist, "SARRAY", - 0); // Locate the carrier structure definition + 0); // Locate the carrier structure definition if (udt == nullptr || u == nullptr) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolDataObject", err, "nullptr User defined data Structure Definition"); + addIdamError(UDA_CODE_ERROR_TYPE, "protocolDataObject", err, + "nullptr User defined data Structure Definition"); return 0; } initSArray(&sarray); - sarray.count = str->data_n; // Number of this structure - sarray.rank = 1; // Array Data Rank? - sarray.shape = &shape; // Only if rank > 1? - sarray.data = (void*)str->data; // Pointer to the data to be passed - strcpy(sarray.type, udt->name); // The name of the type - data = (void*)&psarray; // Pointer to the SARRAY array pointer + sarray.count = str->data_n; // Number of this structure + sarray.rank = 1; // Array Data Rank? + sarray.shape = &shape; // Only if rank > 1? + sarray.data = (void*)str->data; // Pointer to the data to be passed + strcpy(sarray.type, udt->name); // The name of the type + data = (void*)&psarray; // Pointer to the SARRAY array pointer addNonMalloc(logmalloclist, (void*)&shape, 1, sizeof(int), "int"); - packageType = UDA_PACKAGE_XDROBJECT; // The package is an XDR serialised object + packageType = UDA_PACKAGE_XDROBJECT; // The package is an XDR serialised object - rc = xdr_int(xdrs, &packageType); // Send data package type + rc = xdr_int(xdrs, &packageType); // Send data package type // Send the data - rc = rc && xdr_userdefinedtypelist(xdrs, userdefinedtypelist, xdr_stdio_flag); // send the full set of known named structures + rc = rc && xdr_userdefinedtypelist(xdrs, userdefinedtypelist, + xdr_stdio_flag); // send the full set of known named structures rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, u, (void**)data, protocolVersion, - xdr_stdio_flag, log_struct_list, malloc_source); // send the Data + xdr_stdio_flag, log_struct_list, malloc_source); // send the Data if (!rc) { err = 999; @@ -501,9 +481,9 @@ xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIS return 0; } - } else { // Receive Data + } else { // Receive Data - rc = rc && xdr_int(xdrs, &packageType); // Receive data package type + rc = rc && xdr_int(xdrs, &packageType); // Receive data package type if (packageType != UDA_PACKAGE_XDROBJECT) { err = 999; @@ -526,8 +506,7 @@ xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIS if (!rc) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "protocolDataObject", err, - "Failure receiving Structure Definitions"); + addIdamError(UDA_CODE_ERROR_TYPE, "protocolDataObject", err, "Failure receiving Structure Definitions"); return 0; } @@ -536,9 +515,9 @@ xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIS auto udt_received = (USERDEFINEDTYPE*)malloc(sizeof(USERDEFINEDTYPE)); initUserDefinedType(udt_received); - rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, - &data, protocolVersion, xdr_stdio_flag, log_struct_list, - malloc_source); // receive the Data + rc = rc && xdrUserDefinedTypeData(xdrs, logmalloclist, userdefinedtypelist, udt_received, &data, + protocolVersion, xdr_stdio_flag, log_struct_list, + malloc_source); // receive the Data if (!rc) { err = 999; @@ -549,17 +528,17 @@ xdr_serialise_object(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIS // Prepare returned data structure containing the data - if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure + if (STR_EQUALS(udt_received->name, "SARRAY")) { // expecting this carrier structure auto general_block = (GENERAL_BLOCK*)malloc(sizeof(GENERAL_BLOCK)); auto s = (SARRAY*)data; - if (s->count != str->data_n) { // check for consistency + if (s->count != str->data_n) { // check for consistency err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "protocolDataObject", err, "Inconsistent S Array Counts"); return 0; } - str->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data + str->data = (char*)udaGetFullNTree(); // Global Root Node with the Carrier Structure containing data str->opaque_block = (void*)general_block; general_block->userdefinedtype = udt_received; general_block->userdefinedtypelist = userdefinedtypelist; @@ -656,7 +635,7 @@ bool_t xdr_data_block2(XDR* xdrs, DATA_BLOCK* str) // General Data structures are passed using a specialised set of xdr components case UDA_TYPE_COMPOUND: - return 1; // Nothing to send so retain good return code + return 1; // Nothing to send so retain good return code case UDA_TYPE_CAPNP: return xdr_vector(xdrs, str->data, (u_int)str->data_n, sizeof(char), (xdrproc_t)xdr_char); @@ -715,7 +694,9 @@ bool_t xdr_data_block3(XDR* xdrs, DATA_BLOCK* str) bool_t xdr_data_block4(XDR* xdrs, DATA_BLOCK* str) { - if (!str->errasymmetry) return 1; // Nothing New to Pass or Receive (same as errhi!) + if (!str->errasymmetry) { + return 1; // Nothing New to Pass or Receive (same as errhi!) + } // Asymmetric Data Errors @@ -761,19 +742,14 @@ bool_t xdr_data_dim1(XDR* xdrs, DATA_BLOCK* str) { int rc = 1; for (unsigned int i = 0; i < str->rank; i++) { - rc = rc && xdr_int(xdrs, &str->dims[i].data_type) - && xdr_int(xdrs, &str->dims[i].error_type) - && xdr_int(xdrs, &str->dims[i].error_model) - && xdr_int(xdrs, &str->dims[i].errasymmetry) - && xdr_int(xdrs, &str->dims[i].error_param_n) - && xdr_int(xdrs, &str->dims[i].dim_n) - && xdr_int(xdrs, &str->dims[i].compressed) - && xdr_double(xdrs, &str->dims[i].dim0) - && xdr_double(xdrs, &str->dims[i].diff) - && xdr_int(xdrs, &str->dims[i].method) - && xdr_u_int(xdrs, &str->dims[i].udoms) - && WrapXDRString(xdrs, (char*)str->dims[i].dim_units, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->dims[i].dim_label, STRING_LENGTH); + rc = rc && xdr_int(xdrs, &str->dims[i].data_type) && xdr_int(xdrs, &str->dims[i].error_type) && + xdr_int(xdrs, &str->dims[i].error_model) && xdr_int(xdrs, &str->dims[i].errasymmetry) && + xdr_int(xdrs, &str->dims[i].error_param_n) && xdr_int(xdrs, &str->dims[i].dim_n) && + xdr_int(xdrs, &str->dims[i].compressed) && xdr_double(xdrs, &str->dims[i].dim0) && + xdr_double(xdrs, &str->dims[i].diff) && xdr_int(xdrs, &str->dims[i].method) && + xdr_u_int(xdrs, &str->dims[i].udoms) && + WrapXDRString(xdrs, (char*)str->dims[i].dim_units, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->dims[i].dim_label, STRING_LENGTH); } return rc; @@ -786,84 +762,84 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) switch (str->dims[i].data_type) { case UDA_TYPE_FLOAT: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(float), (xdrproc_t)xdr_float)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(float), + (xdrproc_t)xdr_float)) { return 0; } break; case UDA_TYPE_DOUBLE: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(double), (xdrproc_t)xdr_double)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(double), + (xdrproc_t)xdr_double)) { return 0; } break; case UDA_TYPE_CHAR: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(char), (xdrproc_t)xdr_char)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(char), + (xdrproc_t)xdr_char)) { return 0; } break; case UDA_TYPE_SHORT: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(short), (xdrproc_t)xdr_short)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(short), + (xdrproc_t)xdr_short)) { return 0; } break; case UDA_TYPE_INT: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(int), (xdrproc_t)xdr_int)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(int), + (xdrproc_t)xdr_int)) { return 0; } break; case UDA_TYPE_LONG: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(long), (xdrproc_t)xdr_long)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(long), + (xdrproc_t)xdr_long)) { return 0; } break; case UDA_TYPE_LONG64: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(long long int), (xdrproc_t)xdr_int64_t)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(long long int), + (xdrproc_t)xdr_int64_t)) { return 0; } break; case UDA_TYPE_UNSIGNED_CHAR: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(unsigned char), (xdrproc_t)xdr_u_char)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(unsigned char), + (xdrproc_t)xdr_u_char)) { return 0; } break; case UDA_TYPE_UNSIGNED_SHORT: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(unsigned short), (xdrproc_t)xdr_u_short)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(unsigned short), + (xdrproc_t)xdr_u_short)) { return 0; } break; case UDA_TYPE_UNSIGNED_INT: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(unsigned int), (xdrproc_t)xdr_u_int)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(unsigned int), + (xdrproc_t)xdr_u_int)) { return 0; } break; case UDA_TYPE_UNSIGNED_LONG: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(unsigned long), (xdrproc_t)xdr_u_long)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(unsigned long), + (xdrproc_t)xdr_u_long)) { return 0; } break; case UDA_TYPE_UNSIGNED_LONG64: - if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t)) { + if (!xdr_vector(xdrs, str->dims[i].dim, (u_int)str->dims[i].dim_n, sizeof(unsigned long long int), + (xdrproc_t)xdr_uint64_t)) { return 0; } break; @@ -871,15 +847,15 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) // Complex structure is a simple two float combination: => twice the number of element transmitted case UDA_TYPE_DCOMPLEX: - if (!xdr_vector(xdrs, str->dims[i].dim, 2 * (u_int)str->dims[i].dim_n, - sizeof(double), (xdrproc_t)xdr_double)) { + if (!xdr_vector(xdrs, str->dims[i].dim, 2 * (u_int)str->dims[i].dim_n, sizeof(double), + (xdrproc_t)xdr_double)) { return 0; } break; case UDA_TYPE_COMPLEX: - if (!xdr_vector(xdrs, str->dims[i].dim, 2 * (u_int)str->dims[i].dim_n, - sizeof(float), (xdrproc_t)xdr_float)) { + if (!xdr_vector(xdrs, str->dims[i].dim, 2 * (u_int)str->dims[i].dim_n, sizeof(float), + (xdrproc_t)xdr_float)) { return 0; } break; @@ -893,24 +869,24 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_FLOAT: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(float), (xdrproc_t)xdr_float))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(float), + (xdrproc_t)xdr_float) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(float), + (xdrproc_t)xdr_float))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(float), (xdrproc_t)xdr_float)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(float), + (xdrproc_t)xdr_float)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(float), (xdrproc_t)xdr_float) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(float), (xdrproc_t)xdr_float))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(float), (xdrproc_t)xdr_float) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(float), (xdrproc_t)xdr_float))) { return 0; } break; @@ -920,24 +896,23 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_DOUBLE: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, str->dims[i].udoms, - sizeof(double), (xdrproc_t)xdr_double) - && xdr_vector(xdrs, str->dims[i].ints, str->dims[i].udoms, - sizeof(double), (xdrproc_t)xdr_double))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, str->dims[i].udoms, sizeof(double), + (xdrproc_t)xdr_double) && + xdr_vector(xdrs, str->dims[i].ints, str->dims[i].udoms, sizeof(double), + (xdrproc_t)xdr_double))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, str->dims[i].udoms, - sizeof(double), (xdrproc_t)xdr_double)) { + if (!xdr_vector(xdrs, str->dims[i].offs, str->dims[i].udoms, sizeof(double), + (xdrproc_t)xdr_double)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(double), (xdrproc_t)xdr_double) - && + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(double), (xdrproc_t)xdr_double) && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(double), (xdrproc_t)xdr_double))) { return 0; } @@ -948,24 +923,24 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_CHAR: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(char), (xdrproc_t)xdr_char) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(char), (xdrproc_t)xdr_char))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(char), + (xdrproc_t)xdr_char) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(char), + (xdrproc_t)xdr_char))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(char), (xdrproc_t)xdr_char)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(char), + (xdrproc_t)xdr_char)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(char), (xdrproc_t)xdr_char) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(char), (xdrproc_t)xdr_char))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(char), (xdrproc_t)xdr_char) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(char), (xdrproc_t)xdr_char))) { return 0; } break; @@ -975,24 +950,24 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_SHORT: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(short), (xdrproc_t)xdr_short) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(short), (xdrproc_t)xdr_short))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(short), + (xdrproc_t)xdr_short) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(short), + (xdrproc_t)xdr_short))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(short), (xdrproc_t)xdr_short)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(short), + (xdrproc_t)xdr_short)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(short), (xdrproc_t)xdr_short) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(short), (xdrproc_t)xdr_short))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(short), (xdrproc_t)xdr_short) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(short), (xdrproc_t)xdr_short))) { return 0; } break; @@ -1002,24 +977,24 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_INT: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(int), (xdrproc_t)xdr_int))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(int), (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(int), (xdrproc_t)xdr_int))) { return 0; } break; @@ -1029,24 +1004,24 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_LONG: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(long), (xdrproc_t)xdr_long) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(long), (xdrproc_t)xdr_long))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(long), + (xdrproc_t)xdr_long) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(long), + (xdrproc_t)xdr_long))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(long), (xdrproc_t)xdr_long)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(long), + (xdrproc_t)xdr_long)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(long), (xdrproc_t)xdr_long) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(long), (xdrproc_t)xdr_long))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(long), (xdrproc_t)xdr_long) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(long), (xdrproc_t)xdr_long))) { return 0; } break; @@ -1056,26 +1031,26 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_LONG64: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(long long int), (xdrproc_t)xdr_int64_t) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(long long int), (xdrproc_t)xdr_int64_t))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, + sizeof(long long int), (xdrproc_t)xdr_int64_t) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, + sizeof(long long int), (xdrproc_t)xdr_int64_t))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(long long int), (xdrproc_t)xdr_int64_t)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(long long int), + (xdrproc_t)xdr_int64_t)) { return 0; } break; case 3: if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(long long int), - (xdrproc_t)xdr_int64_t) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(long long int), - (xdrproc_t)xdr_int64_t))) { + (xdrproc_t)xdr_int64_t) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(long long int), + (xdrproc_t)xdr_int64_t))) { return 0; } break; @@ -1085,26 +1060,26 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_UNSIGNED_CHAR: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned char), (xdrproc_t)xdr_u_char) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(unsigned char), (xdrproc_t)xdr_u_char))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, + sizeof(unsigned char), (xdrproc_t)xdr_u_char) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, + sizeof(unsigned char), (xdrproc_t)xdr_u_char))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned char), (xdrproc_t)xdr_u_char)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(unsigned char), + (xdrproc_t)xdr_u_char)) { return 0; } break; case 3: if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(unsigned char), - (xdrproc_t)xdr_u_char) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned char), - (xdrproc_t)xdr_u_char))) { + (xdrproc_t)xdr_u_char) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned char), + (xdrproc_t)xdr_u_char))) { return 0; } break; @@ -1114,12 +1089,12 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_UNSIGNED_SHORT: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned short), (xdrproc_t)xdr_u_short) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(unsigned short), (xdrproc_t)xdr_u_short))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, + sizeof(unsigned short), (xdrproc_t)xdr_u_short) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, + sizeof(unsigned short), (xdrproc_t)xdr_u_short))) { return 0; } break; @@ -1131,9 +1106,9 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) break; case 3: if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(unsigned short), - (xdrproc_t)xdr_u_short) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned short), - (xdrproc_t)xdr_u_short))) { + (xdrproc_t)xdr_u_short) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned short), + (xdrproc_t)xdr_u_short))) { return 0; } break; @@ -1143,25 +1118,26 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_UNSIGNED_INT: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned int), (xdrproc_t)xdr_u_int) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(unsigned int), (xdrproc_t)xdr_u_int))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(unsigned int), + (xdrproc_t)xdr_u_int) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, sizeof(unsigned int), + (xdrproc_t)xdr_u_int))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned int), (xdrproc_t)xdr_u_int)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(unsigned int), + (xdrproc_t)xdr_u_int)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(unsigned int), (xdrproc_t)xdr_u_int) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned int), - (xdrproc_t)xdr_u_int))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(unsigned int), + (xdrproc_t)xdr_u_int) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned int), + (xdrproc_t)xdr_u_int))) { return 0; } break; @@ -1171,26 +1147,26 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_UNSIGNED_LONG: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned long), (xdrproc_t)xdr_u_long) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(unsigned long), (xdrproc_t)xdr_u_long))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, + sizeof(unsigned long), (xdrproc_t)xdr_u_long) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, + sizeof(unsigned long), (xdrproc_t)xdr_u_long))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned long), (xdrproc_t)xdr_u_long)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(unsigned long), + (xdrproc_t)xdr_u_long)) { return 0; } break; case 3: if (!(xdr_vector(xdrs, str->dims[i].offs, 1, sizeof(unsigned long), - (xdrproc_t)xdr_u_long) - && xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned long), - (xdrproc_t)xdr_u_long))) { + (xdrproc_t)xdr_u_long) && + xdr_vector(xdrs, str->dims[i].ints, 1, sizeof(unsigned long), + (xdrproc_t)xdr_u_long))) { return 0; } break; @@ -1199,26 +1175,26 @@ bool_t xdr_data_dim2(XDR* xdrs, DATA_BLOCK* str) case UDA_TYPE_UNSIGNED_LONG64: switch (str->dims[i].method) { case 1: - if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, - sizeof(int), (xdrproc_t)xdr_int) - && xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t) - && xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t))) { + if (!(xdr_vector(xdrs, (char*)str->dims[i].sams, (int)str->dims[i].udoms, sizeof(int), + (xdrproc_t)xdr_int) && + xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, + sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t) && + xdr_vector(xdrs, str->dims[i].ints, (int)str->dims[i].udoms, + sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t))) { return 0; } break; case 2: - if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, - sizeof(unsigned long), (xdrproc_t)xdr_uint64_t)) { + if (!xdr_vector(xdrs, str->dims[i].offs, (int)str->dims[i].udoms, sizeof(unsigned long), + (xdrproc_t)xdr_uint64_t)) { return 0; } break; case 3: - if (!(xdr_vector(xdrs, str->dims[i].offs, (int)1, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t) - && xdr_vector(xdrs, str->dims[i].ints, (int)1, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t))) { + if (!(xdr_vector(xdrs, str->dims[i].offs, (int)1, sizeof(unsigned long long int), + (xdrproc_t)xdr_uint64_t) && + xdr_vector(xdrs, str->dims[i].ints, (int)1, sizeof(unsigned long long int), + (xdrproc_t)xdr_uint64_t))) { return 0; } break; @@ -1243,8 +1219,8 @@ bool_t xdr_data_dim3(XDR* xdrs, DATA_BLOCK* str) for (unsigned int i = 0; i < str->rank; i++) { if (str->dims[i].error_param_n > 0) { - xdr_vector(xdrs, (char*)str->dims[i].errparams, (unsigned int)str->dims[i].error_param_n, - sizeof(float), (xdrproc_t)xdr_float); + xdr_vector(xdrs, (char*)str->dims[i].errparams, (unsigned int)str->dims[i].error_param_n, sizeof(float), + (xdrproc_t)xdr_float); } switch (str->dims[i].error_type) { @@ -1257,20 +1233,17 @@ bool_t xdr_data_dim3(XDR* xdrs, DATA_BLOCK* str) (xdrproc_t)xdr_double); break; case UDA_TYPE_CHAR: - rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(char), - (xdrproc_t)xdr_char); + rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(char), (xdrproc_t)xdr_char); break; case UDA_TYPE_SHORT: rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(short), (xdrproc_t)xdr_short); break; case UDA_TYPE_INT: - rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(int), - (xdrproc_t)xdr_int); + rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(int), (xdrproc_t)xdr_int); break; case UDA_TYPE_LONG: - rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(long), - (xdrproc_t)xdr_long); + rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(long), (xdrproc_t)xdr_long); break; case UDA_TYPE_LONG64: rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(long long int), @@ -1293,8 +1266,8 @@ bool_t xdr_data_dim3(XDR* xdrs, DATA_BLOCK* str) (xdrproc_t)xdr_u_long); break; case UDA_TYPE_UNSIGNED_LONG64: - rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t); + rc = xdr_vector(xdrs, str->dims[i].errhi, (u_int)str->dims[i].dim_n, sizeof(unsigned long long int), + (xdrproc_t)xdr_uint64_t); break; // Complex structure is a simple two float combination: => twice the number of element transmitted @@ -1312,13 +1285,14 @@ bool_t xdr_data_dim3(XDR* xdrs, DATA_BLOCK* str) rc = 1; break; } - if (!(arc = arc && rc)) return 0; + if (!(arc = arc && rc)) { + return 0; + } } return 1; } - bool_t xdr_data_dim4(XDR* xdrs, DATA_BLOCK* str) { int arc = 1, rc; @@ -1370,8 +1344,8 @@ bool_t xdr_data_dim4(XDR* xdrs, DATA_BLOCK* str) (xdrproc_t)xdr_u_long); break; case UDA_TYPE_UNSIGNED_LONG64: - rc = xdr_vector(xdrs, str->dims[i].errlo, (u_int)str->dims[i].dim_n, - sizeof(unsigned long long int), (xdrproc_t)xdr_uint64_t); + rc = xdr_vector(xdrs, str->dims[i].errlo, (u_int)str->dims[i].dim_n, sizeof(unsigned long long int), + (xdrproc_t)xdr_uint64_t); break; // Complex structure is a simple two float combination: => twice the number of element transmitted @@ -1389,45 +1363,38 @@ bool_t xdr_data_dim4(XDR* xdrs, DATA_BLOCK* str) rc = 1; break; } - if (!(arc = arc && rc)) return 0; + if (!(arc = arc && rc)) { + return 0; + } } } return 1; } - //----------------------------------------------------------------------- // From DATA_SYSTEM Table bool_t xdr_data_system(XDR* xdrs, DATA_SYSTEM* str) { - return xdr_int(xdrs, &str->system_id) - && xdr_int(xdrs, &str->version) - && xdr_int(xdrs, &str->meta_id) - && xdr_char(xdrs, &str->type) - && WrapXDRString(xdrs, (char*)str->device_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->system_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->system_desc, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) - && WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); + return xdr_int(xdrs, &str->system_id) && xdr_int(xdrs, &str->version) && xdr_int(xdrs, &str->meta_id) && + xdr_char(xdrs, &str->type) && WrapXDRString(xdrs, (char*)str->device_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->system_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->system_desc, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) && + WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); } - //----------------------------------------------------------------------- // From SYSTEM_CONFIG Table bool_t xdr_system_config(XDR* xdrs, SYSTEM_CONFIG* str) { - return xdr_int(xdrs, &str->config_id) - && xdr_int(xdrs, &str->system_id) - && xdr_int(xdrs, &str->meta_id) - && WrapXDRString(xdrs, (char*)str->config_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->config_desc, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) - && WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); + return xdr_int(xdrs, &str->config_id) && xdr_int(xdrs, &str->system_id) && xdr_int(xdrs, &str->meta_id) && + WrapXDRString(xdrs, (char*)str->config_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->config_desc, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) && + WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); } //----------------------------------------------------------------------- @@ -1435,36 +1402,26 @@ bool_t xdr_system_config(XDR* xdrs, SYSTEM_CONFIG* str) bool_t xdr_data_source(XDR* xdrs, DATA_SOURCE* str) { - return xdr_int(xdrs, &str->source_id) - && xdr_int(xdrs, &str->config_id) - && xdr_int(xdrs, &str->reason_id) - && xdr_int(xdrs, &str->run_id) - && xdr_int(xdrs, &str->meta_id) - && xdr_int(xdrs, &str->status_desc_id) - && xdr_int(xdrs, &str->exp_number) - && xdr_int(xdrs, &str->pass) - && xdr_int(xdrs, &str->status) - && xdr_int(xdrs, &str->status_reason_code) - && xdr_int(xdrs, &str->status_impact_code) - && xdr_char(xdrs, &str->access) - && xdr_char(xdrs, &str->reprocess) - && xdr_char(xdrs, &str->type) - && WrapXDRString(xdrs, (char*)str->source_alias, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->pass_date, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->archive, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->device_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->format, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->path, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->filename, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->server, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->userid, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->reason_desc, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->status_desc, MAXMETA) - && WrapXDRString(xdrs, (char*)str->run_desc, MAXMETA) - && WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) - && WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); + return xdr_int(xdrs, &str->source_id) && xdr_int(xdrs, &str->config_id) && xdr_int(xdrs, &str->reason_id) && + xdr_int(xdrs, &str->run_id) && xdr_int(xdrs, &str->meta_id) && xdr_int(xdrs, &str->status_desc_id) && + xdr_int(xdrs, &str->exp_number) && xdr_int(xdrs, &str->pass) && xdr_int(xdrs, &str->status) && + xdr_int(xdrs, &str->status_reason_code) && xdr_int(xdrs, &str->status_impact_code) && + xdr_char(xdrs, &str->access) && xdr_char(xdrs, &str->reprocess) && xdr_char(xdrs, &str->type) && + WrapXDRString(xdrs, (char*)str->source_alias, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->pass_date, DATE_LENGTH) && + WrapXDRString(xdrs, (char*)str->archive, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->device_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->format, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->path, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->filename, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->server, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->userid, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->reason_desc, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->status_desc, MAXMETA) && + WrapXDRString(xdrs, (char*)str->run_desc, MAXMETA) && + WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) && + WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) && + WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); } //----------------------------------------------------------------------- @@ -1472,20 +1429,14 @@ bool_t xdr_data_source(XDR* xdrs, DATA_SOURCE* str) bool_t xdr_signal(XDR* xdrs, SIGNAL* str) { - return xdr_int(xdrs, &str->source_id) - && xdr_int(xdrs, &str->signal_desc_id) - && xdr_int(xdrs, &str->meta_id) - && xdr_int(xdrs, &str->status_desc_id) - && xdr_int(xdrs, &str->status) - && xdr_int(xdrs, &str->status_reason_code) - && xdr_int(xdrs, &str->status_impact_code) - && xdr_char(xdrs, &str->access) - && xdr_char(xdrs, &str->reprocess) - && WrapXDRString(xdrs, (char*)str->status_desc, MAXMETA) - && WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) - && WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); + return xdr_int(xdrs, &str->source_id) && xdr_int(xdrs, &str->signal_desc_id) && xdr_int(xdrs, &str->meta_id) && + xdr_int(xdrs, &str->status_desc_id) && xdr_int(xdrs, &str->status) && + xdr_int(xdrs, &str->status_reason_code) && xdr_int(xdrs, &str->status_impact_code) && + xdr_char(xdrs, &str->access) && xdr_char(xdrs, &str->reprocess) && + WrapXDRString(xdrs, (char*)str->status_desc, MAXMETA) && + WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) && + WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) && + WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); } //----------------------------------------------------------------------- @@ -1493,21 +1444,16 @@ bool_t xdr_signal(XDR* xdrs, SIGNAL* str) bool_t xdr_signal_desc(XDR* xdrs, SIGNAL_DESC* str) { - return xdr_int(xdrs, &str->signal_desc_id) - && xdr_int(xdrs, &str->meta_id) - && xdr_int(xdrs, &str->rank) - && xdr_int(xdrs, &str->range_start) - && xdr_int(xdrs, &str->range_stop) - && xdr_char(xdrs, &str->type) - && WrapXDRString(xdrs, (char*)str->source_alias, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->signal_alias, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->signal_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->generic_name, STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->description, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->signal_class, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->signal_owner, MAX_STRING_LENGTH) - && WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) - && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) - && WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); + return xdr_int(xdrs, &str->signal_desc_id) && xdr_int(xdrs, &str->meta_id) && xdr_int(xdrs, &str->rank) && + xdr_int(xdrs, &str->range_start) && xdr_int(xdrs, &str->range_stop) && xdr_char(xdrs, &str->type) && + WrapXDRString(xdrs, (char*)str->source_alias, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->signal_alias, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->signal_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->generic_name, STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->description, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->signal_class, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->signal_owner, MAX_STRING_LENGTH) && + WrapXDRString(xdrs, (char*)str->creation, DATE_LENGTH) && + WrapXDRString(xdrs, (char*)str->modified, DATE_LENGTH) && WrapXDRString(xdrs, (char*)str->xml, MAXMETA) && + WrapXDRString(xdrs, (char*)str->xml_creation, DATE_LENGTH); } diff --git a/source/clientserver/xdrlib.h b/source/clientserver/xdrlib.h old mode 100755 new mode 100644 index f857a3f4..497f3be9 --- a/source/clientserver/xdrlib.h +++ b/source/clientserver/xdrlib.h @@ -1,24 +1,24 @@ #pragma once #ifndef UDA_CLIENTSERVER_XDRLIB_H -#define UDA_CLIENTSERVER_XDRLIB_H +# define UDA_CLIENTSERVER_XDRLIB_H -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" -#include -#include +# include +# include //------------------------------------------------------- // XDR Stream Directions -#define XDR_SEND 0 -#define XDR_RECEIVE 1 -#define XDR_FREE_HEAP 2 +# define XDR_SEND 0 +# define XDR_RECEIVE 1 +# define XDR_FREE_HEAP 2 -#ifdef __APPLE__ -# define xdr_uint64_t xdr_u_int64_t -#endif +# ifdef __APPLE__ +# define xdr_uint64_t xdr_u_int64_t +# endif //----------------------------------------------------------------------- // Test version's type passing capability @@ -74,4 +74,3 @@ bool_t xdr_signal(XDR* xdrs, SIGNAL* str); bool_t xdr_signal_desc(XDR* xdrs, SIGNAL_DESC* str); #endif // UDA_CLIENTSERVER_XDRLIB_H - diff --git a/source/clientserver/xmlStructs.h b/source/clientserver/xmlStructs.h old mode 100755 new mode 100644 index 3dce9f03..215333a9 --- a/source/clientserver/xmlStructs.h +++ b/source/clientserver/xmlStructs.h @@ -7,143 +7,142 @@ extern "C" { #endif -#define XMLMAXSTRING 56 -#define XMLMAX 200*1024 -#define UDA_XML_MAX_LOOP 1024 // Max Number of Array elements +#define XMLMAXSTRING 56 +#define XMLMAX 200 * 1024 +#define UDA_XML_MAX_LOOP 1024 // Max Number of Array elements //--------------------------------------------------------------------------- // Flux Loop Data Structures typedef struct { - char archive[XMLMAXSTRING]; // Data Archive Name - char file[XMLMAXSTRING]; // Data File Name - char signal[XMLMAXSTRING]; // Signal Name (Generic or Specific) - char owner[XMLMAXSTRING]; // Owner Name - char format[XMLMAXSTRING]; // Data Format - int seq; // Data Sequence or Pass - int status; // Signal Status - float factor; // Scaling Factor + char archive[XMLMAXSTRING]; // Data Archive Name + char file[XMLMAXSTRING]; // Data File Name + char signal[XMLMAXSTRING]; // Signal Name (Generic or Specific) + char owner[XMLMAXSTRING]; // Owner Name + char format[XMLMAXSTRING]; // Data Format + int seq; // Data Sequence or Pass + int status; // Signal Status + float factor; // Scaling Factor } INSTANCE; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - float aerr; // Absolute Error - float rerr; // Relative Error + float aerr; // Absolute Error + float rerr; // Relative Error } TOROIDALFIELD; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - float aerr; // Absolute Error - float rerr; // Relative Error + float aerr; // Absolute Error + float rerr; // Relative Error } PLASMACURRENT; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - float aerr; // Absolute Error - float rerr; // Relative Error + float aerr; // Absolute Error + float rerr; // Relative Error } DIAMAGNETIC; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - int nco; // Number of Coils - int* coil; // List of Coil Connections - int supply; // Supply Connections + int nco; // Number of Coils + int* coil; // List of Coil Connections + int supply; // Supply Connections } PFCIRCUIT; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - float r; // Radial Position - float z; // Z Position - float angle; // Angle - float aerr; // Absolute Error - float rerr; // Relative Error + float r; // Radial Position + float z; // Z Position + float angle; // Angle + float aerr; // Absolute Error + float rerr; // Relative Error } MAGPROBE; - typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - float aerr; // Absolute Error - float rerr; // Relative Error + float aerr; // Absolute Error + float rerr; // Relative Error } PFSUPPLIES; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - int nco; // Number of Coordinates - float* r; // Radial Position - float* z; // Z Position - float* dphi; // Angle - float aerr; // Absolute Error - float rerr; // Relative Error + int nco; // Number of Coordinates + float* r; // Radial Position + float* z; // Z Position + float* dphi; // Angle + float aerr; // Absolute Error + float rerr; // Relative Error } FLUXLOOP; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - int nco; // Number of Coordinates/Elements - int modelnrnz[2]; // ? - float* r; // Radial Position - float* z; // Z Position - float* dr; // dRadial Position - float* dz; // dZ Position - float* ang1; // Angle #1 - float* ang2; // Angle #2 - float* res; // Resistance - float aerr; // Absolute Error - float rerr; // Relative Error + int nco; // Number of Coordinates/Elements + int modelnrnz[2]; // ? + float* r; // Radial Position + float* z; // Z Position + float* dr; // dRadial Position + float* dz; // dZ Position + float* ang1; // Angle #1 + float* ang2; // Angle #2 + float* res; // Resistance + float aerr; // Absolute Error + float rerr; // Relative Error } PFPASSIVE; typedef struct { - char id[XMLMAXSTRING]; // ID + char id[XMLMAXSTRING]; // ID INSTANCE instance; - int nco; // Number of Coordinates/Elements - float* r; // Radial Position - float* z; // Z Position - float* dr; // dRadial Position - float* dz; // dZ Position - int turns; // Turns per Element - float fturns; // Turns per Element if float! // Need to use Opaque types to avoid this mess!! - int modelnrnz[2]; // ? - float aerr; // Absolute Error - float rerr; // Relative Error + int nco; // Number of Coordinates/Elements + float* r; // Radial Position + float* z; // Z Position + float* dr; // dRadial Position + float* dz; // dZ Position + int turns; // Turns per Element + float fturns; // Turns per Element if float! // Need to use Opaque types to avoid this mess!! + int modelnrnz[2]; // ? + float aerr; // Absolute Error + float rerr; // Relative Error } PFCOILS; typedef struct { - int nco; // Number of Coordinates/Elements - float* r; // Radial Position - float* z; // Z Position - float factor; // Correction factor + int nco; // Number of Coordinates/Elements + float* r; // Radial Position + float* z; // Z Position + float factor; // Correction factor } LIMITER; typedef struct { - char device[XMLMAXSTRING]; // Device Name - int exp_number; // Experiment (Pulse) Number - int nfluxloops; // Number of Flux Loops - int nmagprobes; // Number of Magnetic Probes - int npfcircuits; // Number of PF Circuits - int npfpassive; // Number of PF Passive Components - int npfsupplies; // Number of PF Supplies - int nplasmacurrent; // Plasma Current Data - int ndiamagnetic; // Diamagnetic Data - int ntoroidalfield; // Toroidal Field Data - int npfcoils; // Number of PF Coils - int nlimiter; // Limiter Coordinates Available - PFCOILS* pfcoils; // PF Coils - PFPASSIVE* pfpassive; // PF Passive Components - PFSUPPLIES* pfsupplies; // PF Supplies - FLUXLOOP* fluxloop; // Flux Loops - MAGPROBE* magprobe; // Magnetic Probes - PFCIRCUIT* pfcircuit; // PF Circuits - PLASMACURRENT* plasmacurrent; // Plasma Current - DIAMAGNETIC* diamagnetic; // Diamagnetic Flux - TOROIDALFIELD* toroidalfield; // Toroidal Field - LIMITER* limiter; // Limiter Coordinates + char device[XMLMAXSTRING]; // Device Name + int exp_number; // Experiment (Pulse) Number + int nfluxloops; // Number of Flux Loops + int nmagprobes; // Number of Magnetic Probes + int npfcircuits; // Number of PF Circuits + int npfpassive; // Number of PF Passive Components + int npfsupplies; // Number of PF Supplies + int nplasmacurrent; // Plasma Current Data + int ndiamagnetic; // Diamagnetic Data + int ntoroidalfield; // Toroidal Field Data + int npfcoils; // Number of PF Coils + int nlimiter; // Limiter Coordinates Available + PFCOILS* pfcoils; // PF Coils + PFPASSIVE* pfpassive; // PF Passive Components + PFSUPPLIES* pfsupplies; // PF Supplies + FLUXLOOP* fluxloop; // Flux Loops + MAGPROBE* magprobe; // Magnetic Probes + PFCIRCUIT* pfcircuit; // PF Circuits + PLASMACURRENT* plasmacurrent; // Plasma Current + DIAMAGNETIC* diamagnetic; // Diamagnetic Flux + TOROIDALFIELD* toroidalfield; // Toroidal Field + LIMITER* limiter; // Limiter Coordinates } EFIT; #ifdef __cplusplus diff --git a/source/include/accAPI.h b/source/include/accAPI.h old mode 100755 new mode 100644 index ea83901d..d6c0df5e --- a/source/include/accAPI.h +++ b/source/include/accAPI.h @@ -1,13 +1,13 @@ #ifndef UDA_CLIENT_ACCAPI_H #define UDA_CLIENT_ACCAPI_H -#include #include +#include -#include "udaStructs.h" -#include "genStructs.h" -#include "export.h" #include "client.h" +#include "export.h" +#include "genStructs.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -261,9 +261,9 @@ LIBRARY_API SERVER_BLOCK getIdamThreadServerBlock(); LIBRARY_API CLIENT_BLOCK getIdamThreadClientBlock(); -LIBRARY_API void putIdamThreadServerBlock(SERVER_BLOCK *str); +LIBRARY_API void putIdamThreadServerBlock(SERVER_BLOCK* str); -LIBRARY_API void putIdamThreadClientBlock(CLIENT_BLOCK *str); +LIBRARY_API void putIdamThreadClientBlock(CLIENT_BLOCK* str); LIBRARY_API int setIdamDataTree(int handle); @@ -286,4 +286,3 @@ LIBRARY_API NTREE* findIdamNTreeStructureDefinition(NTREE* node, const char* tar #endif #endif // UDA_CLIENT_ACCAPI_H - diff --git a/source/include/accessors.h b/source/include/accessors.h old mode 100755 new mode 100644 index 6f37c812..9332b1f0 --- a/source/include/accessors.h +++ b/source/include/accessors.h @@ -1,243 +1,251 @@ #ifndef UDA_STRUCTURES_ACCESSORS_H #define UDA_STRUCTURES_ACCESSORS_H -#include "genStructs.h" #include "export.h" +#include "genStructs.h" #ifdef __cplusplus extern "C" { #endif /** Find (search type A) the first Tree Node with a data structure type containing a named element/member. -* The name of the element is also returned. -* -* This is a private function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If NULL the root node is assumed. -* @param target The name of the data structure element/member (case sensitive) using the hierachical naming syntax a.b.c or a/b/c. -* This element may be either a data structure or an atomic typed element. If a single named item is specified without -* its hierarchical naming context, the tree node with the first occurance of the name is selected. Using the hierarchy imposes -* more rigour to the search. -* @param lastname Returns the name of the element, i.e., the name of the last item in the name hierarchy. -* @return the Tree Node containing the named element. -*/ -LIBRARY_API NTREE* -findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, const char** lastname); + * The name of the element is also returned. + * + * This is a private function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If NULL the root node is + * assumed. + * @param target The name of the data structure element/member (case sensitive) using the hierachical naming syntax + * a.b.c or a/b/c. This element may be either a data structure or an atomic typed element. If a single named item is + * specified without its hierarchical naming context, the tree node with the first occurance of the name is selected. + * Using the hierarchy imposes more rigour to the search. + * @param lastname Returns the name of the element, i.e., the name of the last item in the name hierarchy. + * @return the Tree Node containing the named element. + */ +LIBRARY_API NTREE* findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + const char** lastname); /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* The name of the structure is also returned. -* -* This is a private function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @param lastname Returns the name of the Structure, i.e., the name of the last node in the name hierarchy. -* @return the Data Tree Node with the structure name. -*/ -LIBRARY_API NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, const char** lastname); - -/** Find (search type A) and return a Pointer to the Data Tree Node with a data structure that contains a named element. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* This element may be either a structure itself or an atomic typed element. -* @return the Data Tree Node. -*/ + * The name of the structure is also returned. + * + * This is a private function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @param lastname Returns the name of the Structure, i.e., the name of the last node in the name hierarchy. + * @return the Data Tree Node with the structure name. + */ +LIBRARY_API NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + const char** lastname); + +/** Find (search type A) and return a Pointer to the Data Tree Node with a data structure that contains a named element. + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or + * a/b/c. This element may be either a structure itself or an atomic typed element. + * @return the Data Tree Node. + */ LIBRARY_API NTREE* findNTreeStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Find (search type A) and return a Pointer to the Child Data Tree Node with a data structure that contains a named element. -* -* This is a public function with the child sub-trees in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* This element may be either a structure itself or an atomic typed element. -* @return the Data Tree Node. -*/ +/** Find (search type A) and return a Pointer to the Child Data Tree Node with a data structure that contains a named + * element. + * + * This is a public function with the child sub-trees in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or + * a/b/c. This element may be either a structure itself or an atomic typed element. + * @return the Data Tree Node. + */ LIBRARY_API NTREE* findNTreeChildStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @return the Data Tree Node. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @return the Data Tree Node. + */ LIBRARY_API NTREE* findNTreeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* -* This is a public function with child sub-trees in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @return the child Data Tree Node. -*/ + * + * This is a public function with child sub-trees in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @return the child Data Tree Node. + */ LIBRARY_API NTREE* findNTreeChildStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); /** Find and return a Pointer to a Data Tree Node with a data structure located at a specific memory location. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param data The heap address of the data. -* @return the Data Tree Node. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param data The heap address of the data. + * @return the Data Tree Node. + */ LIBRARY_API NTREE* findNTreeStructureMalloc(NTREE* ntree, void* data); -/** Locate a tree node with structured data having the specified Structure Definition name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the Structure Definition. -* @return A pointer to the First tree node found with the targeted structure definition. -*/ +/** Locate a tree node with structured data having the specified Structure Definition name. + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the Structure Definition. + * @return A pointer to the First tree node found with the targeted structure definition. + */ LIBRARY_API NTREE* findNTreeStructureDefinition(NTREE* ntree, const char* target); -/** Locate a tree node with structured data having the specified Structure Definition name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the Structure Definition. -* @return A pointer to the First tree node found with the targeted structure definition. -*/ +/** Locate a tree node with structured data having the specified Structure Definition name. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the Structure Definition. + * @return A pointer to the First tree node found with the targeted structure definition. + */ LIBRARY_API NTREE* findNTreeStructureComponentDefinition(NTREE* tree, const char* target); -/** Locate a tree node with structured data having a Specific Structure Class. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If NULL the root node is assumed. -* @param class The Structure Class, e.g., UDA_TYPE_VLEN. -* @return A pointer to the First tree node found with the targeted structure class. -*/ +/** Locate a tree node with structured data having a Specific Structure Class. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If NULL the root node is assumed. + * @param class The Structure Class, e.g., UDA_TYPE_VLEN. + * @return A pointer to the First tree node found with the targeted structure class. + */ LIBRARY_API NTREE* idam_findNTreeStructureClass(NTREE* tree, int cls); -/** Identify the largest count of a Variable Length Array with a given structure type. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the VLEN Structure Definition. -* @param reset Reset the counbter to zero. -* @return An integer returning the maximum count value. -*/ +/** Identify the largest count of a Variable Length Array with a given structure type. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the VLEN Structure Definition. + * @param reset Reset the counbter to zero. + * @return An integer returning the maximum count value. + */ LIBRARY_API int idam_maxCountVlenStructureArray(NTREE* tree, const char* target, int reset); -/** Regularise a specific VLEN structure. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If NULL the root node is assumed. -* @param target The name of the VLEN Structure Definition. -* @param count The maximum count size for the VLEN data arrays. -* @return An integer returning an error code: 0 => OK. -*/ -LIBRARY_API int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist, - const char* target, unsigned int count); - -/** Regularise the Shape of All VLEN structured data arrays in the data tree: necessary for accessing in some languages, e.g. IDL. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If NULL the root node is assumed. -* @return An integer returning an error code: 0 => OK. -*/ -LIBRARY_API int idam_regulariseVlenData(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist); +/** Regularise a specific VLEN structure. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If NULL the root node is assumed. + * @param target The name of the VLEN Structure Definition. + * @param count The maximum count size for the VLEN data arrays. + * @return An integer returning an error code: 0 => OK. + */ +LIBRARY_API int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, + USERDEFINEDTYPELIST* userdefinedtypelist, const char* target, + unsigned int count); + +/** Regularise the Shape of All VLEN structured data arrays in the data tree: necessary for accessing in some languages, + * e.g. IDL. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If NULL the root node is assumed. + * @return An integer returning an error code: 0 => OK. + */ +LIBRARY_API int idam_regulariseVlenData(LOGMALLOCLIST* logmalloclist, NTREE* tree, + USERDEFINEDTYPELIST* userdefinedtypelist); //--------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------- -// User Accessor functions to Node Data (only the current node is in scope) - -/** Return the Count of data array elements attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Count of structured data array elements. -*/ +// User Accessor functions to Node Data (only the current node is in scope) + +/** Return the Count of data array elements attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Count of structured data array elements. + */ LIBRARY_API int getNodeStructureDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return the Size (bytes) of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Size (bytes) of the structured data array. -*/ +/** Return the Size (bytes) of the structured data array attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Size (bytes) of the structured data array. + */ LIBRARY_API int getNodeStructureDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return the rank of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return The rank of the structured data array. -*/ +/** Return the rank of the structured data array attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return The rank of the structured data array. + */ LIBRARY_API int getNodeStructureDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return the shape of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return A pointer to the integer shape array of the structured data array. -*/ +/** Return the shape of the structured data array attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return A pointer to the integer shape array of the structured data array. + */ LIBRARY_API int* getNodeStructureDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a pointer to the structured data type name of the data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the data type name of the structured data array. -*/ +/** Return a pointer to the structured data type name of the data array attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the data type name of the structured data array. + */ LIBRARY_API const char* getNodeStructureDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* ntree); - -/** Return a pointer to the data attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return A void pointer to the data . -*/ + +/** Return a pointer to the data attached to this tree node. + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return A void pointer to the data . + */ LIBRARY_API void* getNodeStructureData(NTREE* ntree); //---------------------------------------------------------------------------------------------------------- // Sundry utility functions -/** Print the Contents of a tree node to a specified File Descriptor. The arguments for this function are -* available from the Structure Definition structure. -* -* This is a public function with the current tree node only in scope. -* -* @param fd The File Descriptor, e.g., stdout -* @param image A text block containing null terminated strings that forms an text image of the structure definition. -* @param imagecount The number of bytes in the image text block. -* @return Void -*/ +/** Print the Contents of a tree node to a specified File Descriptor. The arguments for this function are + * available from the Structure Definition structure. + * + * This is a public function with the current tree node only in scope. + * + * @param fd The File Descriptor, e.g., stdout + * @param image A text block containing null terminated strings that forms an text image of the structure definition. + * @param imagecount The number of bytes in the image text block. + * @return Void + */ LIBRARY_API void printImage(const char* image, int imagecount); -//---------------------------------------------------------------------------------------------------------- -/**User defined structure field definition for common types -* -* This is a public function -* -* @param field The user defined structure's field to be populated -* @param name Name of the structure's field. -* @param desc Description of the fields contents -* @param offset Current field byte offset from the start of the structure. Ppdated on return. -* @param type_id Enumerated key indicating the type of data field, e.g. float array -* @return Void -*/ -LIBRARY_API void defineField(COMPOUNDFIELD* field, const char* name, const char* desc, int* offset, unsigned short type_id); - -LIBRARY_API void defineCompoundField(COMPOUNDFIELD* field, const char* type, const char* name, char* desc, int offset, int size); +//---------------------------------------------------------------------------------------------------------- +/**User defined structure field definition for common types + * + * This is a public function + * + * @param field The user defined structure's field to be populated + * @param name Name of the structure's field. + * @param desc Description of the fields contents + * @param offset Current field byte offset from the start of the structure. Ppdated on return. + * @param type_id Enumerated key indicating the type of data field, e.g. float array + * @return Void + */ +LIBRARY_API void defineField(COMPOUNDFIELD* field, const char* name, const char* desc, int* offset, + unsigned short type_id); + +LIBRARY_API void defineCompoundField(COMPOUNDFIELD* field, const char* type, const char* name, char* desc, int offset, + int size); #ifdef __cplusplus } diff --git a/source/include/client.h b/source/include/client.h old mode 100755 new mode 100644 index 2633d5f6..a5525052 --- a/source/include/client.h +++ b/source/include/client.h @@ -4,9 +4,9 @@ // TODO: remove this and the XDR globals #include -#include "udaStructs.h" -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -21,35 +21,35 @@ extern "C" { //-------------------------------------------------------------- // Client Side API Error Codes -#define NO_SOCKET_CONNECTION (-10000) -#define PROBLEM_OPENING_LOGS (-11000) -#define FILE_FORMAT_NOT_SUPPORTED (-12000) +#define NO_SOCKET_CONNECTION (-10000) +#define PROBLEM_OPENING_LOGS (-11000) +#define FILE_FORMAT_NOT_SUPPORTED (-12000) #define ERROR_ALLOCATING_DATA_BOCK_HEAP (-13000) -#define SERVER_BLOCK_ERROR (-14000) -#define SERVER_SIDE_ERROR (-14001) -#define DATA_BLOCK_RECEIPT_ERROR (-15000) -#define ERROR_CONDITION_UNKNOWN (-16000) +#define SERVER_BLOCK_ERROR (-14000) +#define SERVER_SIDE_ERROR (-14001) +#define DATA_BLOCK_RECEIPT_ERROR (-15000) +#define ERROR_CONDITION_UNKNOWN (-16000) -#define NO_EXP_NUMBER_SPECIFIED (-18005) +#define NO_EXP_NUMBER_SPECIFIED (-18005) -#define MIN_STATUS (-1) // Deny Access to Data if this Status Value -#define DATA_STATUS_BAD (-17000) // Error Code if Status is Bad +#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_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 + 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; diff --git a/source/include/clientAPI.h b/source/include/clientAPI.h old mode 100755 new mode 100644 index 25f18abc..6fff9982 --- a/source/include/clientAPI.h +++ b/source/include/clientAPI.h @@ -1,18 +1,18 @@ #ifndef UDA_CLIENT_CLIENTAPI_H #define UDA_CLIENT_CLIENTAPI_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { #endif -LIBRARY_API int idamClientAPI(const char *file, const char *signal, int pass, int exp_number); -LIBRARY_API int idamClientFileAPI(const char *file, const char *signal, const char *format); -LIBRARY_API int idamClientFileAPI2(const char *file, const char *format, const char *owner, - const char *signal, int exp_number, int pass); -LIBRARY_API int idamClientTestAPI(const char *file, const char *signal, int pass, int exp_number); +LIBRARY_API int idamClientAPI(const char* file, const char* signal, int pass, int exp_number); +LIBRARY_API int idamClientFileAPI(const char* file, const char* signal, const char* format); +LIBRARY_API int idamClientFileAPI2(const char* file, const char* format, const char* owner, const char* signal, + int exp_number, int pass); +LIBRARY_API int idamClientTestAPI(const char* file, const char* signal, int pass, int exp_number); #ifdef __cplusplus } diff --git a/source/include/clientMDS.h b/source/include/clientMDS.h old mode 100755 new mode 100644 index 30a2d80e..dada6293 --- a/source/include/clientMDS.h +++ b/source/include/clientMDS.h @@ -7,7 +7,7 @@ extern "C" { #endif -LIBRARY_API int idamClientMDS(const char *server, const char *tree, const char *node, int treenum); +LIBRARY_API int idamClientMDS(const char* server, const char* tree, const char* node, int treenum); #ifdef __cplusplus } diff --git a/source/include/genStructs.h b/source/include/genStructs.h old mode 100755 new mode 100644 index f5c8d1b4..3ef985f0 --- a/source/include/genStructs.h +++ b/source/include/genStructs.h @@ -1,8 +1,8 @@ #ifndef UDA_STRUCTURES_GENSTRUCTS_H #define UDA_STRUCTURES_GENSTRUCTS_H -#include #include +#include #include "export.h" @@ -13,48 +13,48 @@ extern "C" { //------------------------------------------------------------------------------------------------------- // Macro definitions -#define MAXELEMENTS 256 // Max number of structure elements -#define MAXRANK 7 // Max rank of arrays within structure -#define MAXELEMENTNAME 256 // structure element name -#define MAXSOAPSTACKSTRING 256 // SOAP strings allocated on the stack must be less than this size - -#define GROWMALLOCLIST 20 // Each time realloc is called, increase the heap by this number of array elements - -#define POINTER_SIZE32 4 // Pointer size (bytes) on 32-bit architecture - -#define MAXRECURSIVEDEPTH 30 - -#define SCALARDOUBLE 1 -#define ARRAYDOUBLE 2 -#define SCALARFLOAT 3 -#define ARRAYFLOAT 4 -#define SCALARLONG64 5 -#define ARRAYLONG64 6 -#define SCALARULONG64 7 -#define ARRAYULONG64 8 -#define SCALARINT 9 -#define ARRAYINT 10 -#define SCALARUINT 11 -#define ARRAYUINT 12 -#define SCALARSHORT 13 -#define ARRAYSHORT 14 -#define SCALARUSHORT 15 -#define ARRAYUSHORT 16 -#define SCALARCHAR 17 -#define ARRAYCHAR 18 -#define SCALARSTRING 19 -#define ARRAYSTRING 20 -#define ARRAYVOID 21 -#define SCALARUCHAR 22 -#define ARRAYUCHAR 23 +#define MAXELEMENTS 256 // Max number of structure elements +#define MAXRANK 7 // Max rank of arrays within structure +#define MAXELEMENTNAME 256 // structure element name +#define MAXSOAPSTACKSTRING 256 // SOAP strings allocated on the stack must be less than this size + +#define GROWMALLOCLIST 20 // Each time realloc is called, increase the heap by this number of array elements + +#define POINTER_SIZE32 4 // Pointer size (bytes) on 32-bit architecture + +#define MAXRECURSIVEDEPTH 30 + +#define SCALARDOUBLE 1 +#define ARRAYDOUBLE 2 +#define SCALARFLOAT 3 +#define ARRAYFLOAT 4 +#define SCALARLONG64 5 +#define ARRAYLONG64 6 +#define SCALARULONG64 7 +#define ARRAYULONG64 8 +#define SCALARINT 9 +#define ARRAYINT 10 +#define SCALARUINT 11 +#define ARRAYUINT 12 +#define SCALARSHORT 13 +#define ARRAYSHORT 14 +#define SCALARUSHORT 15 +#define ARRAYUSHORT 16 +#define SCALARCHAR 17 +#define ARRAYCHAR 18 +#define SCALARSTRING 19 +#define ARRAYSTRING 20 +#define ARRAYVOID 21 +#define SCALARUCHAR 22 +#define ARRAYUCHAR 23 typedef intptr_t VOIDTYPE; typedef uintptr_t UVOIDTYPE; #ifdef A64 -# define ALIGNMENT 1 // Default Byte Boundary used for Structure Packing +# define ALIGNMENT 1 // Default Byte Boundary used for Structure Packing #else -# define ALIGNMENT 1 // Default Byte Boundary used for Structure Packing +# define ALIGNMENT 1 // Default Byte Boundary used for Structure Packing #endif typedef char STRING; @@ -62,128 +62,128 @@ typedef char STRING; //------------------------------------------------------------------------------------------------------- // Structure types -typedef struct SArray { // This structure must be parsed to create a structure definition. - // Its function is to send or receive arrays of user defined structures and - // atomic types. Single user defined structures can be passed directly. - int count; // Number of data array elements - int rank; // Rank of the data array - int* shape; // Shape of the data array - void* data; // Location of the Structure Array - STRING type[MAXELEMENTNAME]; // The Structure Array Element's type name (Must be Unique) +typedef struct SArray { // This structure must be parsed to create a structure definition. + // Its function is to send or receive arrays of user defined structures and + // atomic types. Single user defined structures can be passed directly. + int count; // Number of data array elements + int rank; // Rank of the data array + int* shape; // Shape of the data array + void* data; // Location of the Structure Array + STRING type[MAXELEMENTNAME]; // The Structure Array Element's type name (Must be Unique) } SARRAY; typedef struct EnumMember { - char name[MAXELEMENTNAME]; // The Enumeration member name - long long value; // The value of the member + char name[MAXELEMENTNAME]; // The Enumeration member name + long long value; // The value of the member } ENUMMEMBER; typedef struct EnumList { - char name[MAXELEMENTNAME]; // The Enumeration name - int type; // The integer base type - int count; // The number of members of this enumeration class - ENUMMEMBER* enummember; // Array of enum members - unsigned long long* enumarray; // Widest integer class to transport all integer type arrays + char name[MAXELEMENTNAME]; // The Enumeration name + int type; // The integer base type + int count; // The number of members of this enumeration class + ENUMMEMBER* enummember; // Array of enum members + unsigned long long* enumarray; // Widest integer class to transport all integer type arrays int enumarray_rank; int enumarray_count; - int *enumarray_shape; + int* enumarray_shape; } ENUMLIST; -typedef struct VLenType { // Variable length (ragged) arrays - unsigned int len; // The array element count - void* data; // Array data +typedef struct VLenType { // Variable length (ragged) arrays + unsigned int len; // The array element count + void* data; // Array data } VLENTYPE; typedef struct LogMalloc { - int count; // Number of elements allocated - int rank; // Dimensionality - size_t size; // Size of each element allocated - int freed; // Freed flag - char type[MAXELEMENTNAME]; // The type name (Atomic or User Defined) - void* heap; // Heap address of the allocated memory - int* shape; // Dimensional lengths. Only required when rank > 1. + int count; // Number of elements allocated + int rank; // Dimensionality + size_t size; // Size of each element allocated + int freed; // Freed flag + char type[MAXELEMENTNAME]; // The type name (Atomic or User Defined) + void* heap; // Heap address of the allocated memory + int* shape; // Dimensional lengths. Only required when rank > 1. } LOGMALLOC; typedef struct LogMallocList { - int listcount; // Number of mallocs logged - int listsize; // Size of List - LOGMALLOC* logmalloc; // List of individual mallocs in allocation order + int listcount; // Number of mallocs logged + int listsize; // Size of List + LOGMALLOC* logmalloc; // List of individual mallocs in allocation order } LOGMALLOCLIST; typedef struct LogStruct { - int id; // Structure Identity Number - char type[MAXELEMENTNAME]; // The structure's type name - void* heap; // The structure's Heap address + int id; // Structure Identity Number + char type[MAXELEMENTNAME]; // The structure's type name + void* heap; // The structure's Heap address } LOGSTRUCT; typedef struct LogStructList { - int listcount; // Number of Structures logged - int listsize; // Size of List - LOGSTRUCT* logstruct; // List of individual structures in dispatch order + int listcount; // Number of Structures logged + int listsize; // Size of List + LOGSTRUCT* logstruct; // List of individual structures in dispatch order } LOGSTRUCTLIST; typedef struct CompoundField { - int size; // The size of the field type: Atomic or User Defined - int offset; // Data byte position within the structure (Architecture dependent) - int offpad; // Structure Packing before this element's position - int alignment; // Alignment Byte Boundary used for Structure Packing - int atomictype; // Reference Type ID when atomic - int pointer; // Flags this field is a pointer type - int rank; // The rank of the field - int count; // The total count of elements of the field - int* shape; // The shape/organisation of the elements of the field - char type[MAXELEMENTNAME]; // The Element's type name (Atomic or User Defined) - char name[MAXELEMENTNAME]; // The Element's name (may be different to its type), i.e., variable name - char desc[MAXELEMENTNAME]; // Description or Comment about the structure element + int size; // The size of the field type: Atomic or User Defined + int offset; // Data byte position within the structure (Architecture dependent) + int offpad; // Structure Packing before this element's position + int alignment; // Alignment Byte Boundary used for Structure Packing + int atomictype; // Reference Type ID when atomic + int pointer; // Flags this field is a pointer type + int rank; // The rank of the field + int count; // The total count of elements of the field + int* shape; // The shape/organisation of the elements of the field + char type[MAXELEMENTNAME]; // The Element's type name (Atomic or User Defined) + char name[MAXELEMENTNAME]; // The Element's name (may be different to its type), i.e., variable name + char desc[MAXELEMENTNAME]; // Description or Comment about the structure element } COMPOUNDFIELD; typedef struct UserDefinedType { - int idamclass; // IDAM user defined class - char name[MAXELEMENTNAME]; // Name of the user defined Type (must be unique) - char source[MAXELEMENTNAME]; // Source of the Structure Definition (header file or data file) - int imagecount; // Length of the image blob - char* image; // An textual image of the c code used to define the structure type - int ref_id; // Unique reference ID tag (Database Key etc.) - int size; // The size of the type in local 32/64 bit architecture - int fieldcount; // the Number of data fields in the structure - COMPOUNDFIELD* compoundfield; // Array of field details + int idamclass; // IDAM user defined class + char name[MAXELEMENTNAME]; // Name of the user defined Type (must be unique) + char source[MAXELEMENTNAME]; // Source of the Structure Definition (header file or data file) + int imagecount; // Length of the image blob + char* image; // An textual image of the c code used to define the structure type + int ref_id; // Unique reference ID tag (Database Key etc.) + int size; // The size of the type in local 32/64 bit architecture + int fieldcount; // the Number of data fields in the structure + COMPOUNDFIELD* compoundfield; // Array of field details } USERDEFINEDTYPE; typedef struct UserDefinedTypeList { - int listCount; // Count of all User Structured Types - USERDEFINEDTYPE* userdefinedtype; // Array of User defined types + int listCount; // Count of all User Structured Types + USERDEFINEDTYPE* userdefinedtype; // Array of User defined types } USERDEFINEDTYPELIST; // ***** How many structures are in data (rank, shape, etc?) -typedef struct NTree { // N-ary Tree linking all related user defined data structures: definitions and data - int branches; // Children (Branch) Count from this node - char name[MAXELEMENTNAME]; // The Structure's and also the tree node's name - USERDEFINEDTYPE* userdefinedtype; // Definition of the data - void* data; // the Data - struct NTree* parent; // Pointer to the parent node - struct NTree** children; // Pointer Array of sibling tree nodes (branches). +typedef struct NTree { // N-ary Tree linking all related user defined data structures: definitions and data + int branches; // Children (Branch) Count from this node + char name[MAXELEMENTNAME]; // The Structure's and also the tree node's name + USERDEFINEDTYPE* userdefinedtype; // Definition of the data + void* data; // the Data + struct NTree* parent; // Pointer to the parent node + struct NTree** children; // Pointer Array of sibling tree nodes (branches). } NTREE; typedef struct NTreeList { - int listCount; // Count of all Individual Trees - NTREE* forrest; // Array of Tree list structures + int listCount; // Count of all Individual Trees + NTREE* forrest; // Array of Tree list structures } NTREELIST; -typedef struct GeneralBlock { // Generalised Data Structures: Client Side Only - USERDEFINEDTYPE* userdefinedtype; // User defined type of the Data - USERDEFINEDTYPELIST* userdefinedtypelist; // List of Known Structure Definitions - LOGMALLOCLIST* logmalloclist; // List of Heap Mallocs - unsigned int lastMallocIndex; // Associate last search entry position found in the Malloc Log +typedef struct GeneralBlock { // Generalised Data Structures: Client Side Only + USERDEFINEDTYPE* userdefinedtype; // User defined type of the Data + USERDEFINEDTYPELIST* userdefinedtypelist; // List of Known Structure Definitions + LOGMALLOCLIST* logmalloclist; // List of Heap Mallocs + unsigned int lastMallocIndex; // Associate last search entry position found in the Malloc Log } GENERAL_BLOCK; -#define UDA_MALLOC_SOURCE_NONE 0 -#define UDA_MALLOC_SOURCE_SOAP 1 -#define UDA_MALLOC_SOURCE_DOM 2 -#define UDA_MALLOC_SOURCE_NETCDF 3 +#define UDA_MALLOC_SOURCE_NONE 0 +#define UDA_MALLOC_SOURCE_SOAP 1 +#define UDA_MALLOC_SOURCE_DOM 2 +#define UDA_MALLOC_SOURCE_NETCDF 3 -#define UDA_PACKAGE_XDRFILE 1 -#define UDA_PACKAGE_STRUCTDATA 2 -#define UDA_PACKAGE_XDROBJECT 3 +#define UDA_PACKAGE_XDRFILE 1 +#define UDA_PACKAGE_STRUCTDATA 2 +#define UDA_PACKAGE_XDROBJECT 3 #ifdef __cplusplus } diff --git a/source/include/initStructs.h b/source/include/initStructs.h old mode 100755 new mode 100644 index 48348fb2..ba215cf6 --- a/source/include/initStructs.h +++ b/source/include/initStructs.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENTSERVER_INITSTRUCTS_H #define UDA_CLIENTSERVER_INITSTRUCTS_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/include/legacy.h b/source/include/legacy.h index db4cc931..c5f0d93f 100644 --- a/source/include/legacy.h +++ b/source/include/legacy.h @@ -1,27 +1,27 @@ #pragma once #ifndef UDA_LEGACY_H -#define UDA_LEGACY_H +# define UDA_LEGACY_H -#warning "using UDA legacy name mappings" +# warning "using UDA legacy name mappings" -#define getIdamServerHost udaGetServerHost -#define getIdamServerPort udaGetServerPort -#define getIdamServerSocket udaGetServerSocket -#define getIdamClientDOI udaGetClientDOI -#define getIdamServerDOI udaGetServerDOI -#define getIdamClientOSName udaGetClientOSName -#define getIdamServerOSName udaGetServerOSName -#define getIdamClientVersion udaGetClientVersion -#define getIdamServerVersion udaGetServerVersion -#define getIdamServerErrorCode udaGetServerErrorCode -#define getIdamServerErrorMsg udaGetServerErrorMsg -#define getIdamServerErrorStackSize udaGetServerErrorStackSize -#define getIdamServerErrorStackRecordType udaGetServerErrorStackRecordType -#define getIdamServerErrorStackRecordCode udaGetServerErrorStackRecordCode -#define getIdamServerErrorStackRecordLocation udaGetServerErrorStackRecordLocation -#define getIdamServerErrorStackRecordMsg udaGetServerErrorStackRecordMsg -#define setUserDefinedTypeList udaSetUserDefinedTypeList -#define setLogMallocList udaSetLogMallocList +# define getIdamServerHost udaGetServerHost +# define getIdamServerPort udaGetServerPort +# define getIdamServerSocket udaGetServerSocket +# define getIdamClientDOI udaGetClientDOI +# define getIdamServerDOI udaGetServerDOI +# define getIdamClientOSName udaGetClientOSName +# define getIdamServerOSName udaGetServerOSName +# define getIdamClientVersion udaGetClientVersion +# define getIdamServerVersion udaGetServerVersion +# define getIdamServerErrorCode udaGetServerErrorCode +# define getIdamServerErrorMsg udaGetServerErrorMsg +# define getIdamServerErrorStackSize udaGetServerErrorStackSize +# define getIdamServerErrorStackRecordType udaGetServerErrorStackRecordType +# define getIdamServerErrorStackRecordCode udaGetServerErrorStackRecordCode +# define getIdamServerErrorStackRecordLocation udaGetServerErrorStackRecordLocation +# define getIdamServerErrorStackRecordMsg udaGetServerErrorStackRecordMsg +# define setUserDefinedTypeList udaSetUserDefinedTypeList +# define setLogMallocList udaSetLogMallocList #endif // UDA_LEGACY_H \ No newline at end of file diff --git a/source/include/pluginStructs.h b/source/include/pluginStructs.h old mode 100755 new mode 100644 index a39e12b9..949278da --- a/source/include/pluginStructs.h +++ b/source/include/pluginStructs.h @@ -3,9 +3,9 @@ #include -#include "udaStructs.h" -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -13,23 +13,23 @@ extern "C" { 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_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 +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 +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; @@ -37,15 +37,15 @@ typedef struct IdamPluginInterface { // Standard Plugin interface CLIENT_BLOCK* client_block; DATA_SOURCE* data_source; SIGNAL_DESC* signal_desc; - const ENVIRONMENT* environment; // Server environment + const ENVIRONMENT* environment; // Server environment LOGMALLOCLIST* logmalloclist; USERDEFINEDTYPELIST* userdefinedtypelist; - void* sqlConnection; // Opaque structure - const PLUGINLIST* pluginList; // List of data readers, filters, models, and servers + 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 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 @@ -66,14 +66,14 @@ typedef struct PluginData { 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 + 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 + int count; // the number of plugins + int mcount; // malloc count allocated PLUGIN_DATA* plugin; }; diff --git a/source/include/struct.h b/source/include/struct.h old mode 100755 new mode 100644 index 80aeb8ad..62b75c2a --- a/source/include/struct.h +++ b/source/include/struct.h @@ -1,13 +1,13 @@ #ifndef UDA_STRUCTURES_STRUCT_H #define UDA_STRUCTURES_STRUCT_H +#include #include #include -#include -#include "udaTypes.h" -#include "genStructs.h" #include "export.h" +#include "genStructs.h" +#include "udaTypes.h" #ifdef SERVERBUILD # include @@ -22,461 +22,465 @@ LIBRARY_API void udaSetFullNTree(NTREE* ntree); LIBRARY_API void setLastMallocIndexValue(unsigned int* lastMallocIndexValue_in); -/** Initialise a SARRAY data structure. -* -* @param str A pointer to a SARRAY data structure instance. -* @return void. -*/ +/** Initialise a SARRAY data structure. + * + * @param str A pointer to a SARRAY data structure instance. + * @return void. + */ LIBRARY_API void initSArray(SARRAY* str); -/** Print the Contents of a SARRAY data structure. -* -* @param fd A File Descriptor. -* @param str A SARRAY data structure instance. -* @return void. -*/ +/** Print the Contents of a SARRAY data structure. + * + * @param fd A File Descriptor. + * @param str A SARRAY data structure instance. + * @return void. + */ LIBRARY_API void printSarray(SARRAY str); -/** Add an NTREE List entry. -* -* @param node A NTREE node to add. -* @return void. -*/ +/** Add an NTREE List entry. + * + * @param node A NTREE node to add. + * @return void. + */ LIBRARY_API void addNTreeList(LOGMALLOCLIST* logmalloclist, NTREE* node, NTREELIST* ntree_list); -/** Add an NTREE node to an array of child nodes. -* -* @param parent A NTREE node with a set of child nodes -* @param child A NTREE node to add to the existing set of child nodes -* @return void. -*/ +/** Add an NTREE node to an array of child nodes. + * + * @param parent A NTREE node with a set of child nodes + * @param child A NTREE node to add to the existing set of child nodes + * @return void. + */ LIBRARY_API void addNTree(NTREE* parent, NTREE* child); -/** Free an NTREE node together with the array of child nodes. -* -* @param ntree A NTREE node with or without a set of child nodes -* @return void. -*/ +/** Free an NTREE node together with the array of child nodes. + * + * @param ntree A NTREE node with or without a set of child nodes + * @return void. + */ LIBRARY_API void freeNTreeNode(NTREE* ntree); /** Add a new image line to the existing image. -* -* @param image A block of bytes used to record structure definition image data. -* @param imagecount The current count of bytes used to record the present image. -* @param line A new image line to add to the existing image. -* @return Both image and image count are updated on return. -*/ + * + * @param image A block of bytes used to record structure definition image data. + * @param imagecount The current count of bytes used to record the present image. + * @param line A new image line to add to the existing image. + * @return Both image and image count are updated on return. + */ LIBRARY_API void addImage(char** image, int* imagecount, const char* line); -/** Expand an image line that contains header defines and include the numerical value -* -* @param buffer An image line to be expanded -* @param defnames An array of define names -* @param defvalues An array of define values -* @param defCount The number of define names and values -* @param expand A pre-allocated array of char to be used to receive the expanded buffer string. -* @return expand An expanded Image line. -*/ -LIBRARY_API void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* defvalues, int defCount, char* expand); - -/** Initialise a LOGMALLOCLIST data structure. -* -* @param str A pointer to a LOGMALLOCLIST data structure instance. -* @return void. -*/ +/** Expand an image line that contains header defines and include the numerical value + * + * @param buffer An image line to be expanded + * @param defnames An array of define names + * @param defvalues An array of define values + * @param defCount The number of define names and values + * @param expand A pre-allocated array of char to be used to receive the expanded buffer string. + * @return expand An expanded Image line. + */ +LIBRARY_API void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* defvalues, int defCount, + char* expand); + +/** Initialise a LOGMALLOCLIST data structure. + * + * @param str A pointer to a LOGMALLOCLIST data structure instance. + * @return void. + */ LIBRARY_API void initLogMallocList(LOGMALLOCLIST* str); -/** Initialise a LOGMALLOC data structure. -* -* @param str A pointer to a LOGMALLOC data structure instance. -* @return void. -*/ +/** Initialise a LOGMALLOC data structure. + * + * @param str A pointer to a LOGMALLOC data structure instance. + * @return void. + */ LIBRARY_API void initLogMalloc(LOGMALLOC* str); -/** Initialise a LOGSTRUCTLIST data structure. -* -* @return void. -*/ +/** Initialise a LOGSTRUCTLIST data structure. + * + * @return void. + */ LIBRARY_API void initLogStructList(LOGSTRUCTLIST* logstructlist); -/** Initialise a LOGSTRUCT data structure. -* -* @param str A pointer to a LOGSTRUCT data structure instance. -* @return void. -*/ +/** Initialise a LOGSTRUCT data structure. + * + * @param str A pointer to a LOGSTRUCT data structure instance. + * @return void. + */ LIBRARY_API void initLogStruct(LOGSTRUCT* str); -/** Initialise a COMPOUNDFIELD data structure. -* -* @param str A pointer to a COMPOUNDFIELD data structure instance. -* @return void. -*/ +/** Initialise a COMPOUNDFIELD data structure. + * + * @param str A pointer to a COMPOUNDFIELD data structure instance. + * @return void. + */ LIBRARY_API void initCompoundField(COMPOUNDFIELD* str); -/** Initialise a USERDEFINEDTYPE data structure. -* -* @param str A pointer to a USERDEFINEDTYPE data structure instance. -* @return void. -*/ +/** Initialise a USERDEFINEDTYPE data structure. + * + * @param str A pointer to a USERDEFINEDTYPE data structure instance. + * @return void. + */ LIBRARY_API void initUserDefinedType(USERDEFINEDTYPE* str); -/** Initialise a USERDEFINEDTYPELIST data structure. -* -* @param str A pointer to a USERDEFINEDTYPELIST data structure instance. -* @return void. -*/ +/** Initialise a USERDEFINEDTYPELIST data structure. + * + * @param str A pointer to a USERDEFINEDTYPELIST data structure instance. + * @return void. + */ LIBRARY_API void initUserDefinedTypeList(USERDEFINEDTYPELIST* str); -/** Initialise a GENERAL_BLOCK data structure. -* -* @param str A pointer to a GENERAL_BLOCK data structure instance. -* @return void. -*/ +/** Initialise a GENERAL_BLOCK data structure. + * + * @param str A pointer to a GENERAL_BLOCK data structure instance. + * @return void. + */ LIBRARY_API void initGeneralBlock(GENERAL_BLOCK* str); -/** Print the Contents of a COMPOUNDFIELD data structure. -* -* @param fd A File Descriptor. -* @param str A COMPOUNDFIELD data structure instance. -* @return void. -*/ +/** Print the Contents of a COMPOUNDFIELD data structure. + * + * @param fd A File Descriptor. + * @param str A COMPOUNDFIELD data structure instance. + * @return void. + */ LIBRARY_API void printCompoundField(COMPOUNDFIELD str); -/** Print the Tabulated Contents of a COMPOUNDFIELD data structure. -* -* @param fd A File Descriptor. -* @param str A COMPOUNDFIELD data structure instance. -* @return void. -*/ +/** Print the Tabulated Contents of a COMPOUNDFIELD data structure. + * + * @param fd A File Descriptor. + * @param str A COMPOUNDFIELD data structure instance. + * @return void. + */ LIBRARY_API void printCompoundFieldTable(COMPOUNDFIELD str); -/** Print the Contents of a USERDEFINEDTYPE data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return void. -*/ +/** Print the Contents of a USERDEFINEDTYPE data structure. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return void. + */ LIBRARY_API void printUserDefinedType(USERDEFINEDTYPE str); -/** Print the Tabulated Contents of a USERDEFINEDTYPE data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return void. -*/ +/** Print the Tabulated Contents of a USERDEFINEDTYPE data structure. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return void. + */ LIBRARY_API void printUserDefinedTypeTable(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE str); -/** Print the Tabulated Contents of a USERDEFINEDTYPE data structure with Zero Sized elements. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return void. -*/ +/** Print the Tabulated Contents of a USERDEFINEDTYPE data structure with Zero Sized elements. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return void. + */ LIBRARY_API void printZeroSizedUserDefinedTypeTable(USERDEFINEDTYPE str); -/** Print the Contents of a USERDEFINEDTYPELIST data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return void. -*/ +/** Print the Contents of a USERDEFINEDTYPELIST data structure. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return void. + */ LIBRARY_API void printUserDefinedTypeList(USERDEFINEDTYPELIST str); -/** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return void. -*/ +/** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return void. + */ LIBRARY_API void printUserDefinedTypeListTable(USERDEFINEDTYPELIST str); -/** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure where the size is zero. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return void. -*/ +/** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure where the size is zero. + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return void. + */ LIBRARY_API void printZeroSizedUserDefinedTypeListTable(USERDEFINEDTYPELIST str); -/** Print the Contents of a LOGMALLOC data structure. -* -* @param fd A File Descriptor. -* @param str A LOGMALLOC data structure instance. -* @return void. -*/ +/** Print the Contents of a LOGMALLOC data structure. + * + * @param fd A File Descriptor. + * @param str A LOGMALLOC data structure instance. + * @return void. + */ LIBRARY_API void printMallocLog(LOGMALLOC str); -/** Print the Contents of the Global LOGMALLOCLIST data structure. -* -* @param fd A File Descriptor. -* @return void. -*/ +/** Print the Contents of the Global LOGMALLOCLIST data structure. + * + * @param fd A File Descriptor. + * @return void. + */ LIBRARY_API void printMallocLogList(const LOGMALLOCLIST* logmalloclist); //============================================================================================================== -// Utility Functions - -/** Add a stack memory location to the LOGMALLOCLIST data structure. These are not freed. -* -* @param stack The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ +// Utility Functions + +/** Add a stack memory location to the LOGMALLOCLIST data structure. These are not freed. + * + * @param stack The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ LIBRARY_API void addNonMalloc(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type); -/** Add a stack memory location to the LOGMALLOCLIST data structure. These are not freed. +/** Add a stack memory location to the LOGMALLOCLIST data structure. These are not freed. * * @param stack The memory location. * @param count The number of elements allocated. * @param size The size of a single element. -* @param type The name of the type allocated. -* @param rank The rank of the allocated array. +* @param type The name of the type allocated. +* @param rank The rank of the allocated array. * @param shape The shape of the allocated array. Only required when rank > 1. - -* @return void. -*/ -LIBRARY_API void addNonMalloc2(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type, int rank, - int* shape); -/** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. -* -* @param heap The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. * @return void. */ +LIBRARY_API void addNonMalloc2(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type, + int rank, int* shape); + +/** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. + * + * @param heap The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ LIBRARY_API void addMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type); -/** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. -* -* @param heap The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @param rank The rank of the allocated array. -* @param shape The shape of the allocated array. Only required when rank > 1. -* @return void. -*/ -LIBRARY_API void -addMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type, int rank, int* shape); - -/** Change the logged memory location to a new location (necessary with realloc). -* -* @param old The original logged memory location. -* @param anew The new replacement memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ -LIBRARY_API void changeMalloc(LOGMALLOCLIST* logmalloclist, VOIDTYPE old, void* anew, int count, size_t size, const char* type); - -/** Change the logged memory location to a new location (necessary with realloc). -* -* @param old The original logged memory location. -* @param anew The new replacement memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ -LIBRARY_API void changeNonMalloc(LOGMALLOCLIST* logmalloclist, void* old, void* anew, int count, size_t size, const char* type); +/** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. + * + * @param heap The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @param rank The rank of the allocated array. + * @param shape The shape of the allocated array. Only required when rank > 1. + * @return void. + */ +LIBRARY_API void addMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type, + int rank, int* shape); + +/** Change the logged memory location to a new location (necessary with realloc). + * + * @param old The original logged memory location. + * @param anew The new replacement memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ +LIBRARY_API void changeMalloc(LOGMALLOCLIST* logmalloclist, VOIDTYPE old, void* anew, int count, size_t size, + const char* type); + +/** Change the logged memory location to a new location (necessary with realloc). + * + * @param old The original logged memory location. + * @param anew The new replacement memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ +LIBRARY_API void changeNonMalloc(LOGMALLOCLIST* logmalloclist, void* old, void* anew, int count, size_t size, + const char* type); LIBRARY_API int dupCountMallocLog(LOGMALLOCLIST* str); -/** Free allocated heap memory but preserve the addresses. There are no arguments. -* -* @return void. -*/ +/** Free allocated heap memory but preserve the addresses. There are no arguments. + * + * @return void. + */ LIBRARY_API void freeMallocLog(LOGMALLOCLIST* str); -/** Free allocated heap memory and reinitialise a new logmalloclist-> There are no arguments. -* -* @return void. -*/ +/** Free allocated heap memory and reinitialise a new logmalloclist-> There are no arguments. + * + * @return void. + */ LIBRARY_API void freeMallocLogList(LOGMALLOCLIST* str); -/** Find the meta data associated with a specific memory location. -* -* @param heap The target memory location. -* @param count The returned allocation count. -* @param size The returned allocation size. -* @param type The returned allocation type. -* @return void. -*/ +/** Find the meta data associated with a specific memory location. + * + * @param heap The target memory location. + * @param count The returned allocation count. + * @param size The returned allocation size. + * @param type The returned allocation type. + * @return void. + */ LIBRARY_API void findMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type); -/** Find the meta data associated with a specific memory location. -* +/** Find the meta data associated with a specific memory location. +* * @param heap The target memory location. * @param count The returned allocation count. * @param size The returned allocation size. * @param type The returned allocation type. -* @param rank The returned rank of the allocated array. +* @param rank The returned rank of the allocated array. * @param shape The returned shape of the allocated array. Only given when rank > 1. * @return void. */ -LIBRARY_API void -findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type, int* rank, int** shape); +LIBRARY_API void findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type, + int* rank, int** shape); -/** Add a heap memory location to the LOGSTRUCTLIST data structure. These are freed. -* -* @param heap The memory location. -* @param type The name of the type allocated. -* @return void. -*/ +/** Add a heap memory location to the LOGSTRUCTLIST data structure. These are freed. + * + * @param heap The memory location. + * @param type The name of the type allocated. + * @return void. + */ LIBRARY_API void addStruct(void* heap, const char* type, LOGSTRUCTLIST* log_struct_list); /** Free allocated heap memory and reinitialise a new LOGSTRUCTLIST. There are no arguments. -* -* @return void. -*/ + * + * @return void. + */ LIBRARY_API void freeLogStructList(LOGSTRUCTLIST* log_struct_list); -/** Find the meta data associated with a specific Structure. -* -* @param heap The target memory location. -* @param type The returned structure type. -* @return The structure id. -*/ +/** Find the meta data associated with a specific Structure. + * + * @param heap The target memory location. + * @param type The returned structure type. + * @return The structure id. + */ LIBRARY_API int findStructId(void* heap, char** type, LOGSTRUCTLIST* log_struct_list); -/** Find the Heap address and Data Type of a specific Structure. -* -* @param id The structure id. -* @param type The returned structure type. -* @return The heap memory location -*/ +/** Find the Heap address and Data Type of a specific Structure. + * + * @param id The structure id. + * @param type The returned structure type. + * @return The heap memory location + */ LIBRARY_API void* findStructHeap(int id, char** type, LOGSTRUCTLIST* log_struct_list); -/** Copy a User Defined Structure Definition. -* -* @param old The type definition to be copied. -* @param anew The copy of the type definition. -* @return void. -*/ +/** Copy a User Defined Structure Definition. + * + * @param old The type definition to be copied. + * @param anew The copy of the type definition. + * @return void. + */ LIBRARY_API void copyUserDefinedType(USERDEFINEDTYPE* old, USERDEFINEDTYPE* anew); /** Copy the Master User Defined Structure Definition List. -* -* @param anew The copy of the type definition list. -* @return void. -*/ -LIBRARY_API void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, const USERDEFINEDTYPELIST* parseduserdefinedtypelist); + * + * @param anew The copy of the type definition list. + * @return void. + */ +LIBRARY_API void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, + const USERDEFINEDTYPELIST* parseduserdefinedtypelist); /** Create the Initial User Defined Structure Definition List. -* -* @param anew The initial type definition list. -* @return void. -*/ + * + * @param anew The initial type definition list. + * @return void. + */ LIBRARY_API void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew); -/** Add a Compound Field type to a structure definition. -* -* @param str The structure definition. -* @param field The Compound field type. -* @return void. -*/ +/** Add a Compound Field type to a structure definition. + * + * @param str The structure definition. + * @param field The Compound field type. + * @return void. + */ LIBRARY_API void addCompoundField(USERDEFINEDTYPE* str, COMPOUNDFIELD field); -/** Add a structure definition to the List of structure types -* -* @param str The list of structure definitions. -* @param type The new definition to add to the list. -* @return void. -*/ +/** Add a structure definition to the List of structure types + * + * @param str The list of structure definitions. + * @param type The new definition to add to the list. + * @return void. + */ LIBRARY_API void addUserDefinedType(USERDEFINEDTYPELIST* str, USERDEFINEDTYPE type); -/** Replace/Update the structure definition list with an different structure type. -* -* @param str The list of structure definitions. -* @param typeId The definition list entry to be replaced/updated -* @param type The definition to add into the list. -* @return void. -*/ +/** Replace/Update the structure definition list with an different structure type. + * + * @param str The list of structure definitions. + * @param typeId The definition list entry to be replaced/updated + * @param type The definition to add into the list. + * @return void. + */ LIBRARY_API void updateUserDefinedType(USERDEFINEDTYPELIST* str, int typeId, USERDEFINEDTYPE type); /** Change a structure element's property in the structure definition -* -* @param str The list of structure definitions. -* @param typeId The definition list entry to be modified -* @param element The structure element to be modified -* @param property The structure element's definition property to be modified -* @param value The new property value -* @return void. -*/ -LIBRARY_API void -changeUserDefinedTypeElementProperty(USERDEFINEDTYPELIST* str, int typeId, char* element, char* property, void* value); - -/** The number of Structure Definitions or User Defined Types in the structure list -* -* @param str The list of structure definitions. -* @return The count of structured types. -*/ + * + * @param str The list of structure definitions. + * @param typeId The definition list entry to be modified + * @param element The structure element to be modified + * @param property The structure element's definition property to be modified + * @param value The new property value + * @return void. + */ +LIBRARY_API void changeUserDefinedTypeElementProperty(USERDEFINEDTYPELIST* str, int typeId, char* element, + char* property, void* value); + +/** The number of Structure Definitions or User Defined Types in the structure list + * + * @param str The list of structure definitions. + * @return The count of structured types. + */ LIBRARY_API int countUserDefinedType(USERDEFINEDTYPELIST* str); -/** Free heap from a Compound Field. -* -* @param str The Compound Field. -* @return void. -*/ +/** Free heap from a Compound Field. + * + * @param str The Compound Field. + * @return void. + */ LIBRARY_API void freeCompoundField(COMPOUNDFIELD* str); -/** Free heap from a User Defined Type. -* -* @param type The User Defined Type. -* @return void. -*/ +/** Free heap from a User Defined Type. + * + * @param type The User Defined Type. + * @return void. + */ LIBRARY_API void freeUserDefinedType(USERDEFINEDTYPE* type); -/** Free heap from a User Defined Type List. -* -* @param userdefinedtypelist The User Defined Type List. -* @return void. -*/ +/** Free heap from a User Defined Type List. + * + * @param userdefinedtypelist The User Defined Type List. + * @return void. + */ LIBRARY_API void freeUserDefinedTypeList(USERDEFINEDTYPELIST* userdefinedtypelist); -/** The size or byte count of an atomic or structured type -* -* @param type The name of the type -* @return The size in bytes. -*/ +/** The size or byte count of an atomic or structured type + * + * @param type The name of the type + * @return The size in bytes. + */ LIBRARY_API size_t getsizeof(USERDEFINEDTYPELIST* userdefinedtypelist, const char* type); /** The value of the IDAM enumeration type for a named regular atomic type -* -* @param type The name of the atomic type -* @return The integer value of the corresponding IDAM enumeration. -*/ + * + * @param type The name of the atomic type + * @return The integer value of the corresponding IDAM enumeration. + */ LIBRARY_API int gettypeof(const char* type); -/** Return structure element alignment byte boundary -* -* @param type The name of the structure atomic type. -* @return number of bytes to align with. -* -* Alignment rules are Architecture Dependent: -* Single byte numbers are aligned at a single byte boundary -* Two byte numbers are aligned with two byte boundaries -* Four byte numbers are aligned on four byte boundaries -* Eight byte numbers are aligned on four byte boundaries if 32 bit architecture and Linux -* or 8 byte boundary if 64 bit or 32 bit and Windows. -* Structures are aligned depending on whichever element has the largest alignment boundary. -* -* Structures between 1 and 4 bytes of data should be padded so that the total structure is 4 bytes. -* Structures between 5 and 8 bytes of data should be padded so that the total structure is 8 bytes. -* Structures between 9 and 16 bytes of data should be padded so that the total structure is 16 bytes. -* Structures greater than 16 bytes should be padded to 16 byte boundary. -* -* Indexing into arrays can be speeded up by making the structure size a power of 2. The compiler can then replace the -* multiply (entry = base address + index*size of structure) with a simple shift operation. -* -* -*/ +/** Return structure element alignment byte boundary + * + * @param type The name of the structure atomic type. + * @return number of bytes to align with. + * + * Alignment rules are Architecture Dependent: + * Single byte numbers are aligned at a single byte boundary + * Two byte numbers are aligned with two byte boundaries + * Four byte numbers are aligned on four byte boundaries + * Eight byte numbers are aligned on four byte boundaries if 32 bit architecture and Linux + * or 8 byte boundary if 64 bit or 32 bit and Windows. + * Structures are aligned depending on whichever element has the largest alignment boundary. + * + * Structures between 1 and 4 bytes of data should be padded so that the total structure is 4 bytes. + * Structures between 5 and 8 bytes of data should be padded so that the total structure is 8 bytes. + * Structures between 9 and 16 bytes of data should be padded so that the total structure is 16 bytes. + * Structures greater than 16 bytes should be padded to 16 byte boundary. + * + * Indexing into arrays can be speeded up by making the structure size a power of 2. The compiler can then replace the + * multiply (entry = base address + index*size of structure) with a simple shift operation. + * + * + */ LIBRARY_API int getalignmentof(const char* type); LIBRARY_API size_t newoffset(size_t offset, const char* type); @@ -484,34 +488,32 @@ LIBRARY_API size_t newoffset(size_t offset, const char* type); LIBRARY_API size_t padding(size_t offset, const char* type); /** The name of an atomic type corresponding to a value of the IDAM enumeration type. -* -* @param type The integer value of the type enumeration. -* @return The name of the atomic type. -*/ + * + * @param type The integer value of the type enumeration. + * @return The name of the atomic type. + */ LIBRARY_API const char* udaNameType(UDA_TYPE type); /** The size or byte count of a user defined structured type. -* -* @param str The user defined structure definition. -* @return The size in bytes. -*/ + * + * @param str The user defined structure definition. + * @return The size in bytes. + */ LIBRARY_API size_t getStructureSize(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* str); /** Print an error message. -* -* @param fd The output file descriptor pointer. -* @param warning Print a warning message rather than an error message. -* @param line The line number where the error occured. -* @param file The file name where the error occured. -* @param msg The message to print. -* @return The size in bytes. -*/ + * + * @param fd The output file descriptor pointer. + * @param warning Print a warning message rather than an error message. + * @param line The line number where the error occured. + * @param file The file name where the error occured. + * @param msg The message to print. + * @return The size in bytes. + */ LIBRARY_API void printError(int warning, int line, char* file, char* msg); - //============================================================================================================== -// Functions to Send or Receive Data contained in User Defined Structures - +// Functions to Send or Receive Data contained in User Defined Structures // Send or Receive the Data Structure @@ -524,21 +526,23 @@ LIBRARY_API void printError(int warning, int line, char* file, char* msg); // Assume 32 bit architecture as the default and pass additional values for 64 bit systems // The type, length and size of pointer types is passed prior to sending. // Pointer type, length and size are recorded in a malloc log. -// The count of data structures to be received is passed ... +// The count of data structures to be received is passed ... // -LIBRARY_API int xdrAtomicData(LOGMALLOCLIST* logmalloclist, XDR* xdrs, const char* type, int count, int size, char** data); - +LIBRARY_API int xdrAtomicData(LOGMALLOCLIST* logmalloclist, XDR* xdrs, const char* type, int count, int size, + char** data); // Send/Receive Array of Structures -LIBRARY_API int xdrUserDefinedTypeData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - USERDEFINEDTYPE* userdefinedtype, void** data, int protocolVersion, bool xdr_stdio_flag, - LOGSTRUCTLIST* log_struct_list, int malloc_source); +LIBRARY_API int xdrUserDefinedTypeData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, + void** data, int protocolVersion, bool xdr_stdio_flag, + LOGSTRUCTLIST* log_struct_list, int malloc_source); LIBRARY_API int findUserDefinedTypeId(USERDEFINEDTYPELIST* userdefinedtypelist, const char* name); -LIBRARY_API USERDEFINEDTYPE* findUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, const char* name, int ref_id); +LIBRARY_API USERDEFINEDTYPE* findUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, const char* name, + int ref_id); LIBRARY_API int testUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* udt); @@ -555,37 +559,36 @@ LIBRARY_API bool_t xdr_userdefinedtypelist(XDR* xdrs, USERDEFINEDTYPELIST* str, //---------------------------------------------------------------------------------------------------------- // Client Utility functions operating on Linked List N-Tree - -/** Print the data from an array of Atomic Type to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param data A pointer to the data. -* @param atomictype The name of a Atomic type. -* @param count The array element count. -* @param label A label to print before the value. -* @return void -*/ +/** Print the data from an array of Atomic Type to a specified File Descriptor. + * + * @param fd The File Descriptor, e.g., stdout + * @param data A pointer to the data. + * @param atomictype The name of a Atomic type. + * @param count The array element count. + * @param label A label to print before the value. + * @return void + */ LIBRARY_API void printAtomicData(void* data, int atomictype, int count, const char* label); -/** Print the data from a named array of Atomic Type from a given tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. -* @param target The name of a User Defined Structure type. -* @return void -* -* \todo {When the structure is an array, either print data from a single array element or print data from -* all structure elements} -*/ +/** Print the data from a named array of Atomic Type from a given tree node to a specified File Descriptor. + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. + * @param target The name of a User Defined Structure type. + * @return void + * + * \todo {When the structure is an array, either print data from a single array element or print data from + * all structure elements} + */ LIBRARY_API void printAtomicType(LOGMALLOCLIST* logmalloclist, NTREE* tree, const char* target); -/** Print the Count of elements of a named data array from a given tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param ntree A pointer to a tree node. -* @param target The name of a Structure element. -* @return void -*/ +/** Print the Count of elements of a named data array from a given tree node to a specified File Descriptor. + * + * @param fd The File Descriptor, e.g., stdout + * @param ntree A pointer to a tree node. + * @param target The name of a Structure element. + * @return void + */ LIBRARY_API void printTypeCount(NTREE* ntree, const char* target); // The compound field element of the structure definition contains the count, rank and shape details @@ -593,496 +596,492 @@ LIBRARY_API void printTypeCount(NTREE* ntree, const char* target); // Pointer data have a count from the malloc log. //--------------------------------------------------------------------------------------------- -// Node Data Structure Component - -/** Return a pointer to a User Defined Structure Component Structure. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a Structure Element. -* @return the Structure Element Definition Structure. -*/ +// Node Data Structure Component + +/** Return a pointer to a User Defined Structure Component Structure. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a Structure Element. + * @return the Structure Element Definition Structure. + */ COMPOUNDFIELD* getNodeStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); //--------------------------------------------------------------------------------------------- -// Tree Node Family: Single tree node is in scope - -/** Return a Pointer to a string array containing the hierarchical names of structure components. -* -* @param target The name of a User Defined Structure element (case sensitive). -* @param ntargets A returned count of the number of names in the returned list. -* @return the list of structure component names. -*/ +// Tree Node Family: Single tree node is in scope + +/** Return a Pointer to a string array containing the hierarchical names of structure components. + * + * @param target The name of a User Defined Structure element (case sensitive). + * @param ntargets A returned count of the number of names in the returned list. + * @return the list of structure component names. + */ LIBRARY_API char** parseTarget(const char* target, int* ntargets); /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNode(NTREE* tree); -/** Print the Contents of a tree node with the specified User Defined Structure name to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param target The name of a User Defined Structure type. If an null string is passed, the structure -* of the root node is used. -* @return void -*/ +/** Print the Contents of a tree node with the specified User Defined Structure name to a specified File Descriptor. + * + * @param fd The File Descriptor, e.g., stdout + * @param target The name of a User Defined Structure type. If an null string is passed, the structure + * of the root node is used. + * @return void + */ LIBRARY_API void printNodeStructureDefinition(const char* target); -/** Print an Image of the Named Structure Definition to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param target The name of a User Defined Structure type. -* @return void -*/ +/** Print an Image of the Named Structure Definition to a specified File Descriptor. + * + * @param fd The File Descriptor, e.g., stdout + * @param target The name of a User Defined Structure type. + * @return void + */ LIBRARY_API void printNodeStructureImage(const char* target); - -/** Return a Pointer to the User Defined Type Structure of the data attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the User Defined Type Structure Definition. -*/ +/** Return a Pointer to the User Defined Type Structure of the data attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the User Defined Type Structure Definition. + */ LIBRARY_API USERDEFINEDTYPE* getNodeUserDefinedType(NTREE* ntree); -/** Return the name of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the name of the User Defined Type Structure. -*/ +/** Return the name of the User Defined Type Structure. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the name of the User Defined Type Structure. + */ LIBRARY_API char* getNodeStructureName(NTREE* ntree); -/** Return the Type of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Type of the User Defined Type Structure. -*/ +/** Return the Type of the User Defined Type Structure. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Type of the User Defined Type Structure. + */ LIBRARY_API char* getNodeStructureType(NTREE* ntree); -/** Return the Size of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Size (Bytes) of the User Defined Type Structure. -*/ +/** Return the Size of the User Defined Type Structure. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Size (Bytes) of the User Defined Type Structure. + */ LIBRARY_API int getNodeStructureSize(NTREE* ntree); -/** Return a pointer to a Tree Nodes's Data Structure Array element. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param index The array index -* @return a Pointer to a Structure Array element. -*/ +/** Return a pointer to a Tree Nodes's Data Structure Array element. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param index The array index + * @return a Pointer to a Structure Array element. + */ LIBRARY_API void* getNodeStructureArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, int index); -/** Return a pointer to a Component Data Structure Array element. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of the Structure Array element. -* @param structureindex The Array index -* @param componentindex The structure element index -* @return a Pointer to a Component Structure Array element. -*/ -LIBRARY_API void* -getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, int structureindex, - int componentindex); - -/** Return the count of child User Defined Type Structures (elements of this structure). -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the name of the User Defined Type Structure. -*/ +/** Return a pointer to a Component Data Structure Array element. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of the Structure Array element. + * @param structureindex The Array index + * @param componentindex The structure element index + * @return a Pointer to a Component Structure Array element. + */ +LIBRARY_API void* getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + int structureindex, int componentindex); + +/** Return the count of child User Defined Type Structures (elements of this structure). + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the name of the User Defined Type Structure. + */ LIBRARY_API int getNodeChildrenCount(NTREE* ntree); -/** Return a Child Node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param child A integer index identifying which child from the child array to return -* @return the Child Node. -*/ +/** Return a Child Node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param child A integer index identifying which child from the child array to return + * @return the Child Node. + */ LIBRARY_API NTREE* getNodeChild(NTREE* ntree, int child); -/** Return a Child Node'd ID (Branch index value). -* -* @param ntree A pointer to a Parent tree node. If NULL the root node is assumed. -* @param child A ipointer to a Child tree node. -* @return the Child Node's ID. -*/ +/** Return a Child Node'd ID (Branch index value). + * + * @param ntree A pointer to a Parent tree node. If NULL the root node is assumed. + * @param child A ipointer to a Child tree node. + * @return the Child Node's ID. + */ LIBRARY_API int getNodeChildId(NTREE* ntree, NTREE* child); -/** Return a Pointer to the children of this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Array of children. -*/ +/** Return a Pointer to the children of this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Array of children. + */ LIBRARY_API NTREE** getNodeChildren(NTREE* ntree); -/** Return the parent Node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Parent Node. -*/ +/** Return the parent Node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Parent Node. + */ LIBRARY_API NTREE* getNodeParent(NTREE* ntree); -/** Return the Data pointer. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return a Pointer to the Data. -*/ +/** Return the Data pointer. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return a Pointer to the Data. + */ LIBRARY_API void* getNodeData(NTREE* ntree); -/** Return a Count of Structured Component Types attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Count of Structured types. -*/ +/** Return a Count of Structured Component Types attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Count of Structured types. + */ LIBRARY_API int getNodeStructureCount(NTREE* ntree); -/** Return a Count of Atomic Component Types attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Count of Atomic types. -*/ +/** Return a Count of Atomic Component Types attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Count of Atomic types. + */ LIBRARY_API int getNodeAtomicCount(NTREE* ntree); -/** Return a List of Structure component Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Structure names. -*/ +/** Return a List of Structure component Names attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Structure names. + */ LIBRARY_API char** getNodeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Atomic component Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Atomic element names. -*/ +/** Return a List of Atomic component Names attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Atomic element names. + */ LIBRARY_API char** getNodeAtomicNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Structure Component Type Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Structure Type names. -*/ +/** Return a List of Structure Component Type Names attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Structure Type names. + */ LIBRARY_API char** getNodeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Atomic Component Type Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Atomic Type names. -*/ +/** Return a List of Atomic Component Type Names attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Atomic Type names. + */ LIBRARY_API char** getNodeAtomicTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Structure Component Pointer property attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Structure Pointer Properties. -*/ +/** Return a List of Structure Component Pointer property attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Structure Pointer Properties. + */ LIBRARY_API int* getNodeStructurePointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Atomic Component Pointer property attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Atomic Pointer Properties. -*/ +/** Return a List of Atomic Component Pointer property attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Atomic Pointer Properties. + */ LIBRARY_API int* getNodeAtomicPointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Rank values of the Structure Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Structure Ranks. -*/ +/** Return a List of Rank values of the Structure Components attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Structure Ranks. + */ LIBRARY_API int* getNodeStructureRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Rank values of the Atomic Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Atomic Ranks. -*/ +/** Return a List of Rank values of the Atomic Components attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Atomic Ranks. + */ LIBRARY_API int* getNodeAtomicRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Shape Arrays of the Structure Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Structure Shape Arrays. -*/ +/** Return a List of Shape Arrays of the Structure Components attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Structure Shape Arrays. + */ LIBRARY_API int** getNodeStructureShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of Shape Arrays of the Atomic Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of Atomic Shape Arrays. -*/ +/** Return a List of Shape Arrays of the Atomic Components attached to a tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of Atomic Shape Arrays. + */ LIBRARY_API int** getNodeAtomicShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree); - /** Print the Names and Types of all Node Data Elements to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNodeNames(LOGMALLOCLIST* logmalloclist, NTREE* tree); /** Print the Atomic Data from a data node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNodeAtomic(LOGMALLOCLIST* logmalloclist, NTREE* tree); -/** Return the number of User Defined Type Structure Definition Components attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the number of User Defined Type Structure Definition Components. -*/ +/** Return the number of User Defined Type Structure Definition Components attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the number of User Defined Type Structure Definition Components. + */ LIBRARY_API int getNodeStructureComponentCount(NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Names attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component names. -*/ +/** Return a List of User Defined Type Structure Definition Components Names attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component names. + */ LIBRARY_API char** getNodeStructureComponentNames(NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Types attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Types. -*/ +/** Return a List of User Defined Type Structure Definition Components Types attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Types. + */ LIBRARY_API char** getNodeStructureComponentTypes(NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Descriptions. -*/ +/** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Descriptions. + */ LIBRARY_API char** getNodeStructureComponentDescriptions(NTREE* ntree); - -/** Return the Count of User Defined Structure Component Data array elements attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Count of User Defined Structure Component Data Array elements. -*/ +/** Return the Count of User Defined Structure Component Data array elements attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Count of User Defined Structure Component Data Array elements. + */ LIBRARY_API int getNodeStructureComponentDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Return the Rank of User Defined Structure Component Data array attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Rank of User Defined Structure Component Data array. -*/ +/** Return the Rank of User Defined Structure Component Data array attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Rank of User Defined Structure Component Data array. + */ LIBRARY_API int getNodeStructureComponentDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Return the Shape array of the User Defined Structure Component Data array attached to this tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Shape array of length Rank of the User Defined Structure Component Data array. -*/ +/** Return the Shape array of the User Defined Structure Component Data array attached to this tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Shape array of length Rank of the User Defined Structure Component Data array. + */ LIBRARY_API int* getNodeStructureComponentDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); /** Return True (1) if the User Defined Structure Component Data array, attached to this tree node, -* is a pointer type. Returns False (0) otherwise. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the value 1 if the User Defined Structure Component Data array is a pointer type. -*/ + * is a pointer type. Returns False (0) otherwise. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the value 1 if the User Defined Structure Component Data array is a pointer type. + */ LIBRARY_API int getNodeStructureComponentDataIsPointer(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Return the Size of a User Defined Structure Component. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the Size of the User Defined Structure Component. -*/ +/** Return the Size of a User Defined Structure Component. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the Size of the User Defined Structure Component. + */ LIBRARY_API int getNodeStructureComponentDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Return the Type Name of a User Defined Structure Component. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the Type Name of the User Defined Structure Component. -*/ +/** Return the Type Name of a User Defined Structure Component. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the Type Name of the User Defined Structure Component. + */ -LIBRARY_API const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); +LIBRARY_API const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* ntree, + const char* target); -/** Return a pointer to a User Defined Structure Component's data. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data. -*/ +/** Return a pointer to a User Defined Structure Component's data. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data. + */ LIBRARY_API void* getNodeStructureComponentData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); -/** Print a User Defined Structure Component's data. -* -* @param fd File Descriptor -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return void. -*/ +/** Print a User Defined Structure Component's data. + * + * @param fd File Descriptor + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return void. + */ -LIBRARY_API void -printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - const char* target); +LIBRARY_API void printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, const char* target); -/** Print a Data Structure's Contents. -* -* @param fd File Descriptor -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return void. -*/ +/** Print a Data Structure's Contents. + * + * @param fd File Descriptor + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return void. + */ LIBRARY_API void printNodeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a pointer to a User Defined Structure Component's data cast to FLOAT. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data cast to float. -*/ - -LIBRARY_API float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); +/** Return a pointer to a User Defined Structure Component's data cast to FLOAT. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data cast to float. + */ +LIBRARY_API float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE* ntree, + const char* target); -/** Return a pointer to a User Defined Structure Component's data cast to DOUBLE. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data cast to float. -*/ +/** Return a pointer to a User Defined Structure Component's data cast to DOUBLE. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data cast to float. + */ -LIBRARY_API double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); +LIBRARY_API double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTREE* ntree, + const char* target); //--------------------------------------------------------------------------------------------- -// Tree Branch Family: Whole tree is in scope +// Tree Branch Family: Whole tree is in scope -/** Initialise a NTREE data structure. -* -* @param str A pointer to a NTREE data structure instance. -* @return void. -*/ +/** Initialise a NTREE data structure. + * + * @param str A pointer to a NTREE data structure instance. + * @return void. + */ LIBRARY_API void initNTree(NTREE* str); /** Initialise the Global NTREE list structure. -* -* @return void. -*/ + * + * @return void. + */ LIBRARY_API void initNTreeList(NTREELIST* ntree_list); /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNTree2(NTREE* tree); /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNTree(NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist); /** Print Details of the tree node List to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNTreeList(NTREE* tree); -/** Return a Count of User Defined Type Tree Nodes from and including the passed tree node. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the Count of Tree Nodes. -*/ +/** Return a Count of User Defined Type Tree Nodes from and including the passed tree node. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the Count of Tree Nodes. + */ LIBRARY_API int getNTreeStructureCount(NTREE* ntree); -/** Return a List of User Defined Type Structure Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure names. -*/ +/** Return a List of User Defined Type Structure Names attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure names. + */ LIBRARY_API char** getNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree); - -/** Return a List of User Defined Type Structure Type Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Type names. -*/ +/** Return a List of User Defined Type Structure Type Names attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Type names. + */ LIBRARY_API char** getNTreeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree); /** Print the Names and Types of all Data Structures to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* tree); -/** Return the total number of User Defined Type Structure Definition Components attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the number of User Defined Type Structure Definition Components. -*/ +/** Return the total number of User Defined Type Structure Definition Components attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the number of User Defined Type Structure Definition Components. + */ LIBRARY_API int getNTreeStructureComponentCount(NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component names. -*/ +/** Return a List of User Defined Type Structure Definition Components Names attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component names. + */ LIBRARY_API char** getNTreeStructureComponentNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Types attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Types. -*/ +/** Return a List of User Defined Type Structure Definition Components Types attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Types. + */ LIBRARY_API char** getNTreeStructureComponentTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree); -/** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree branch. -* -* @param ntree A pointer to a tree node. If NULL the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Descriptions. -*/ +/** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree branch. + * + * @param ntree A pointer to a tree node. If NULL the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Descriptions. + */ LIBRARY_API char** getNTreeStructureComponentDescriptions(LOGMALLOCLIST* logmalloclist, NTREE* ntree); /** Print the Names and Types of all Data Elements to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If NULL the root node is assumed. -* @return void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If NULL the root node is assumed. + * @return void + */ LIBRARY_API void printNTreeStructureComponentNames(LOGMALLOCLIST* logmalloclist, NTREE* tree); //======================================================================================================= @@ -1100,31 +1099,33 @@ LIBRARY_API void printNTreeStructureComponentNames_stdout(LOGMALLOCLIST* logmall LIBRARY_API void printAtomicType_stdout(LOGMALLOCLIST* logmalloclist, NTREE* tree, const char* target); -LIBRARY_API void getNodeStructureComponentDataShape_f(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, int* shape_f); +LIBRARY_API void getNodeStructureComponentDataShape_f(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + int* shape_f); -LIBRARY_API void getNodeStructureComponentShortData_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, short* data_f); +LIBRARY_API void getNodeStructureComponentShortData_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + short* data_f); -LIBRARY_API void getNodeStructureComponentFloatData_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, float* data_f); +LIBRARY_API void getNodeStructureComponentFloatData_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + float* data_f); LIBRARY_API void dereferenceShortData(short* data_c, int count, short* data_f); LIBRARY_API void dereferenceFloatData(float* data_c, int count, float* data_f); -LIBRARY_API short* castNodeStructureComponentDatatoShort(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target); +LIBRARY_API short* castNodeStructureComponentDatatoShort(LOGMALLOCLIST* logmalloclist, NTREE* ntree, + const char* target); -LIBRARY_API void -castNodeStructureComponentDatatoShort_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, short* data_f); +LIBRARY_API void castNodeStructureComponentDatatoShort_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + short* data_f); -LIBRARY_API void -castNodeStructureComponentDatatoFloat_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, float* data_f); +LIBRARY_API void castNodeStructureComponentDatatoFloat_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + float* data_f); -LIBRARY_API void -addStructureField(USERDEFINEDTYPE* user_type, const char* name, const char* desc, UDA_TYPE data_type, bool is_pointer, - int rank, int* shape, size_t offset); +LIBRARY_API void addStructureField(USERDEFINEDTYPE* user_type, const char* name, const char* desc, UDA_TYPE data_type, + bool is_pointer, int rank, int* shape, size_t offset); #ifdef __cplusplus } #endif #endif // UDA_STRUCTURES_STRUCT_H - diff --git a/source/include/udaDefines.h b/source/include/udaDefines.h old mode 100755 new mode 100644 index 36e068f3..36cc46df --- a/source/include/udaDefines.h +++ b/source/include/udaDefines.h @@ -10,139 +10,142 @@ extern "C" { //-------------------------------------------------------- // Size Definitions -#define WORKDIR tmp // Location of the Work Directories +#define WORKDIR tmp // Location of the Work Directories -#define MAXDATE 12 // Ensure same as DATE_LENGTH -#define MAXNAME 1024 // Same as STRING_LENGTH -#define MAXFILENAME 1024 // Same as STRING_LENGTH -#define MAXSERVER 1024 // Same as STRING_LENGTH -#define MAXPATH 1024 // Same as STRING_LENGTH -#define MAXMODE 8 -#define MAXFORMAT 1024 // Same as STRING_LENGTH +#define MAXDATE 12 // Ensure same as DATE_LENGTH +#define MAXNAME 1024 // Same as STRING_LENGTH +#define MAXFILENAME 1024 // Same as STRING_LENGTH +#define MAXSERVER 1024 // Same as STRING_LENGTH +#define MAXPATH 1024 // Same as STRING_LENGTH +#define MAXMODE 8 +#define MAXFORMAT 1024 // Same as STRING_LENGTH -#define MAXDESC 1024 // Same as STRING_LENGTH -#define MAXNAMELISTREC 1024 +#define MAXDESC 1024 // Same as STRING_LENGTH +#define MAXNAMELISTREC 1024 -#define MAXKEY 56 -#define MAXSQL 21*1024 -#define MAXRECLENGTH 256 +#define MAXKEY 56 +#define MAXSQL 21 * 1024 +#define MAXRECLENGTH 256 -#define MAXMETA 10*1024 +#define MAXMETA 10 * 1024 -#define MAXERRPARAMS 8 +#define MAXERRPARAMS 8 -#define MAXRANK2 10 // Number of subsetting dimensions +#define MAXRANK2 10 // Number of subsetting dimensions -#define UDA_SXML_MAX_STRING 1024 -#define UDA_MAX_DATA_RANK 8 -#define UDA_XML_MAX_DESC 1024 -#define UDA_XML_MAX_RECURSIVE 10 -#define UDA_XML_MAX_LOOP 1024 +#define UDA_SXML_MAX_STRING 1024 +#define UDA_MAX_DATA_RANK 8 +#define UDA_XML_MAX_DESC 1024 +#define UDA_XML_MAX_RECURSIVE 10 +#define UDA_XML_MAX_LOOP 1024 -#define UDA_DIM_CALIBRATION_TYPE 1 // Identifies DIMENSION Union Structures -#define UDA_DIM_COMPOSITE_TYPE 2 -#define UDA_DIM_DOCUMENTATION_TYPE 3 -#define UDA_DIM_ERROR_MODEL_TYPE 4 +#define UDA_DIM_CALIBRATION_TYPE 1 // Identifies DIMENSION Union Structures +#define UDA_DIM_COMPOSITE_TYPE 2 +#define UDA_DIM_DOCUMENTATION_TYPE 3 +#define UDA_DIM_ERROR_MODEL_TYPE 4 -#define UDA_TIME_OFFSET_TYPE 1 // Identifies ACTION Union Structures -#define UDA_DOCUMENTATION_TYPE 2 -#define UDA_CALIBRATION_TYPE 3 -#define UDA_COMPOSITE_TYPE 4 -#define UDA_ERROR_MODEL_TYPE 5 -#define UDA_SERVER_SIDE_TYPE 6 -#define UDA_SUBSET_TYPE 7 -#define UDA_MAP_TYPE 8 +#define UDA_TIME_OFFSET_TYPE 1 // Identifies ACTION Union Structures +#define UDA_DOCUMENTATION_TYPE 2 +#define UDA_CALIBRATION_TYPE 3 +#define UDA_COMPOSITE_TYPE 4 +#define UDA_ERROR_MODEL_TYPE 5 +#define UDA_SERVER_SIDE_TYPE 6 +#define UDA_SUBSET_TYPE 7 +#define UDA_MAP_TYPE 8 -#define NUMSIGNALS 2048 -#define NUMPULSES 2048 +#define NUMSIGNALS 2048 +#define NUMPULSES 2048 -#define MAXNAMARRAY 1024 -#define MAXVARNAME 56 -#define MAXVARVALUE 56 +#define MAXNAMARRAY 1024 +#define MAXVARNAME 56 +#define MAXVARVALUE 56 -#define MAXFILES 2048 -#define MAXDIRS 2048 -#define MAXITEM 12 +#define MAXFILES 2048 +#define MAXDIRS 2048 +#define MAXITEM 12 -//#define MINYEAR "1980" // for Date Problems +// #define MINYEAR "1980" // for Date Problems -#define MD5_SIZE 16 +#define MD5_SIZE 16 -#define STRING_LENGTH 1024 -#define MAX_STRING_LENGTH 1024 // Ensure same as STRING_LENGTH -#define DATE_LENGTH 12 +#define STRING_LENGTH 1024 +#define MAX_STRING_LENGTH 1024 // Ensure same as STRING_LENGTH +#define DATE_LENGTH 12 -#define MAXLOOP 10000 -#define MAXBLOCK 1000 // msecs +#define MAXLOOP 10000 +#define MAXBLOCK 1000 // msecs -#define DB_READ_BLOCK_SIZE 32*1024 //16384 -#define DB_WRITE_BLOCK_SIZE 32*1024 //16384 +#define DB_READ_BLOCK_SIZE 32 * 1024 // 16384 +#define DB_WRITE_BLOCK_SIZE 32 * 1024 // 16384 -#define GROWPUTDATABLOCKLIST 10 +#define GROWPUTDATABLOCKLIST 10 //-------------------------------------------------------- // Client Specified Properties -#define TIMEOUT 600 // Server Shutdown after this time (Secs) -#define COMPRESS_DIM 1 // Compress regular dimensional data +#define TIMEOUT 600 // Server Shutdown after this time (Secs) +#define COMPRESS_DIM 1 // Compress regular dimensional data //-------------------------------------------------------- // Private Flags: Properties passed to IDAM clients called by servers (32 bits) -#define PRIVATEFLAG_FULLRESET (unsigned int)-1 // ffff - 0010 Reset flags except EXTERNAL -#define PRIVATEFLAG_XDRFILE (unsigned int)1 // 0001 Use an intermediate file containing the XDR data rather than a data stream -#define PRIVATEFLAG_EXTERNAL (unsigned int)2 // 0010 The originating server is an External Facing server -#define PRIVATEFLAG_CACHE (unsigned int)4 // 0100 Cache all data +#define PRIVATEFLAG_FULLRESET (unsigned int)-1 // ffff - 0010 Reset flags except EXTERNAL +#define PRIVATEFLAG_XDRFILE \ + (unsigned int)1 // 0001 Use an intermediate file containing the XDR data rather than a data stream +#define PRIVATEFLAG_EXTERNAL (unsigned int)2 // 0010 The originating server is an External Facing server +#define PRIVATEFLAG_CACHE (unsigned int)4 // 0100 Cache all data -#define PRIVATEFLAG_XDROBJECT 8 // 1000 Use an intermediate XDR data object rather than a data stream +#define PRIVATEFLAG_XDROBJECT 8 // 1000 Use an intermediate XDR data object rather than a data stream //-------------------------------------------------------- // Client Flags: Client specified local properties (32 bits) -#define CLIENTFLAG_FULLRESET -1 // ffff Reset flags -#define CLIENTFLAG_ALTDATA 1u // 0000 0001 -#define CLIENTFLAG_XDRFILE 2u // 0000 0010 Use an intermediate file with the XDR data rather than a data stream -#define CLIENTFLAG_CACHE 4u // 0000 0100 Access data from the local cache and write new data to cache -#define CLIENTFLAG_CLOSEDOWN 8u // 0000 1000 Immediate Closedown -#define CLIENTFLAG_XDROBJECT 16u // 0001 0000 Use a XDR object in memory -#define CLIENTFLAG_REUSELASTHANDLE 32u // 0010 0000 Reuse the last issued handle value (for this thread) - assume application has freed heap -#define CLIENTFLAG_FREEREUSELASTHANDLE 64u // 0100 0000 Free the heap associated with the last issued handle and reuse the handle value -#define CLIENTFLAG_FILECACHE 128u // 1000 0000 Access data from and save data to local cache files +#define CLIENTFLAG_FULLRESET -1 // ffff Reset flags +#define CLIENTFLAG_ALTDATA 1u // 0000 0001 +#define CLIENTFLAG_XDRFILE 2u // 0000 0010 Use an intermediate file with the XDR data rather than a data stream +#define CLIENTFLAG_CACHE 4u // 0000 0100 Access data from the local cache and write new data to cache +#define CLIENTFLAG_CLOSEDOWN 8u // 0000 1000 Immediate Closedown +#define CLIENTFLAG_XDROBJECT 16u // 0001 0000 Use a XDR object in memory +#define CLIENTFLAG_REUSELASTHANDLE \ + 32u // 0010 0000 Reuse the last issued handle value (for this thread) - assume application has freed heap +#define CLIENTFLAG_FREEREUSELASTHANDLE \ + 64u // 0100 0000 Free the heap associated with the last issued handle and reuse the handle value +#define CLIENTFLAG_FILECACHE 128u // 1000 0000 Access data from and save data to local cache files //-------------------------------------------------------- // Error Models -#define ERROR_MODEL_SEED 12345 -#define ERROR_MODEL_UNKNOWN 0 -#define ERROR_MODEL_DEFAULT 1 +#define ERROR_MODEL_SEED 12345 +#define ERROR_MODEL_UNKNOWN 0 +#define ERROR_MODEL_DEFAULT 1 #define ERROR_MODEL_DEFAULT_ASYMMETRIC 2 -#define ERROR_MODEL_GAUSSIAN 3 -#define ERROR_MODEL_RESEED 4 -#define ERROR_MODEL_GAUSSIAN_SHIFT 5 -#define ERROR_MODEL_POISSON 6 -#define ERROR_MODEL_UNDEFINED 7 +#define ERROR_MODEL_GAUSSIAN 3 +#define ERROR_MODEL_RESEED 4 +#define ERROR_MODEL_GAUSSIAN_SHIFT 5 +#define ERROR_MODEL_POISSON 6 +#define ERROR_MODEL_UNDEFINED 7 //-------------------------------------------------------- // Caching -#define UDA_PLUGIN_NOT_OK_TO_CACHE 0 // Plugin state management incompatible with client side cacheing -#define UDA_PLUGIN_OK_TO_CACHE 1 // Data are OK for the Client to Cache +#define UDA_PLUGIN_NOT_OK_TO_CACHE 0 // Plugin state management incompatible with client side cacheing +#define UDA_PLUGIN_OK_TO_CACHE 1 // Data are OK for the Client to Cache -#define UDA_PLUGIN_CACHE_DEFAULT UDA_PLUGIN_NOT_OK_TO_CACHE // The cache permission to use as the default +#define UDA_PLUGIN_CACHE_DEFAULT UDA_PLUGIN_NOT_OK_TO_CACHE // The cache permission to use as the default //-------------------------------------------------------- // Character used to separate directory file path elements #ifndef _WIN32 -# define PATH_SEPARATOR "/" +# define PATH_SEPARATOR "/" #else -# define PATH_SEPARATOR "\\" +# define PATH_SEPARATOR "\\" #endif //-------------------------------------------------------- // QA Status -#define DEFAULT_STATUS 1 // Default Signal and Data_Source Status value +#define DEFAULT_STATUS 1 // Default Signal and Data_Source Status value //-------------------------------------------------------- // Not defined functions for Windows MSVC diff --git a/source/include/udaErrors.h b/source/include/udaErrors.h old mode 100755 new mode 100644 index 6a03d9ef..895a5e7b --- a/source/include/udaErrors.h +++ b/source/include/udaErrors.h @@ -4,48 +4,48 @@ //------------------------------------------------------- // Request specific errors -#define SIGNAL_ARG_TOO_LONG 18000 -#define SOURCE_ARG_TOO_LONG 18001 -#define ARCHIVE_NAME_TOO_LONG 18002 -#define DEVICE_NAME_TOO_LONG 18003 -#define NO_SERVER_SPECIFIED 18004 +#define SIGNAL_ARG_TOO_LONG 18000 +#define SOURCE_ARG_TOO_LONG 18001 +#define ARCHIVE_NAME_TOO_LONG 18002 +#define DEVICE_NAME_TOO_LONG 18003 +#define NO_SERVER_SPECIFIED 18004 //------------------------------------------------------- // Fatal Server Errors -#define FATAL_ERROR_LOGS 666 +#define FATAL_ERROR_LOGS 666 //------------------------------------------------------- // Client Server Conversaton Protocol XDR Errors -#define UDA_PROTOCOL_ERROR_1 1 -#define UDA_PROTOCOL_ERROR_2 2 -#define UDA_PROTOCOL_ERROR_3 3 -#define UDA_PROTOCOL_ERROR_4 4 -#define UDA_PROTOCOL_ERROR_5 5 -#define UDA_PROTOCOL_ERROR_61 61 -#define UDA_PROTOCOL_ERROR_62 62 -#define UDA_PROTOCOL_ERROR_63 63 -#define UDA_PROTOCOL_ERROR_64 64 -#define UDA_PROTOCOL_ERROR_65 65 -#define UDA_PROTOCOL_ERROR_7 7 -#define UDA_PROTOCOL_ERROR_8 8 -#define UDA_PROTOCOL_ERROR_9 9 -#define UDA_PROTOCOL_ERROR_10 10 -#define UDA_PROTOCOL_ERROR_11 11 -#define UDA_PROTOCOL_ERROR_12 12 -#define UDA_PROTOCOL_ERROR_13 13 -#define UDA_PROTOCOL_ERROR_14 14 -#define UDA_PROTOCOL_ERROR_15 15 -#define UDA_PROTOCOL_ERROR_16 16 -#define UDA_PROTOCOL_ERROR_17 17 -#define UDA_PROTOCOL_ERROR_18 18 -#define UDA_PROTOCOL_ERROR_19 19 -#define UDA_PROTOCOL_ERROR_20 20 -#define UDA_PROTOCOL_ERROR_21 21 -#define UDA_PROTOCOL_ERROR_22 22 -#define UDA_PROTOCOL_ERROR_23 23 -#define UDA_PROTOCOL_ERROR_24 24 +#define UDA_PROTOCOL_ERROR_1 1 +#define UDA_PROTOCOL_ERROR_2 2 +#define UDA_PROTOCOL_ERROR_3 3 +#define UDA_PROTOCOL_ERROR_4 4 +#define UDA_PROTOCOL_ERROR_5 5 +#define UDA_PROTOCOL_ERROR_61 61 +#define UDA_PROTOCOL_ERROR_62 62 +#define UDA_PROTOCOL_ERROR_63 63 +#define UDA_PROTOCOL_ERROR_64 64 +#define UDA_PROTOCOL_ERROR_65 65 +#define UDA_PROTOCOL_ERROR_7 7 +#define UDA_PROTOCOL_ERROR_8 8 +#define UDA_PROTOCOL_ERROR_9 9 +#define UDA_PROTOCOL_ERROR_10 10 +#define UDA_PROTOCOL_ERROR_11 11 +#define UDA_PROTOCOL_ERROR_12 12 +#define UDA_PROTOCOL_ERROR_13 13 +#define UDA_PROTOCOL_ERROR_14 14 +#define UDA_PROTOCOL_ERROR_15 15 +#define UDA_PROTOCOL_ERROR_16 16 +#define UDA_PROTOCOL_ERROR_17 17 +#define UDA_PROTOCOL_ERROR_18 18 +#define UDA_PROTOCOL_ERROR_19 19 +#define UDA_PROTOCOL_ERROR_20 20 +#define UDA_PROTOCOL_ERROR_21 21 +#define UDA_PROTOCOL_ERROR_22 22 +#define UDA_PROTOCOL_ERROR_23 23 +#define UDA_PROTOCOL_ERROR_24 24 #define UDA_PROTOCOL_ERROR_1001 1001 #define UDA_PROTOCOL_ERROR_1011 1011 @@ -71,71 +71,71 @@ //------------------------------------------------------- // Server Side Error Codes -#define MDS_ERROR_CONNECTING_TO_SERVER 1 -#define MDS_ERROR_OPENING_TREE 2 -#define MDS_ERROR_ALLOCATING_HEAP_TDI_RANK 3 -#define MDS_ERROR_MDSVALUE_RANK 4 -#define MDS_ERROR_ALLOCATING_HEAP_TDI_SIZE 5 -#define MDS_ERROR_MDSVALUE_SIZE 6 -#define MDS_ERROR_ALLOCATING_HEAP_DATA_BLOCK 7 -#define MDS_ERROR_MDSVALUE_DATA 8 +#define MDS_ERROR_CONNECTING_TO_SERVER 1 +#define MDS_ERROR_OPENING_TREE 2 +#define MDS_ERROR_ALLOCATING_HEAP_TDI_RANK 3 +#define MDS_ERROR_MDSVALUE_RANK 4 +#define MDS_ERROR_ALLOCATING_HEAP_TDI_SIZE 5 +#define MDS_ERROR_MDSVALUE_SIZE 6 +#define MDS_ERROR_ALLOCATING_HEAP_DATA_BLOCK 7 +#define MDS_ERROR_MDSVALUE_DATA 8 #define MDS_ERROR_ALLOCATING_HEAP_TDI_LEN_UNITS 9 -#define MDS_ERROR_MDSVALUE_LEN_UNITS 10 -#define MDS_ERROR_UNITS_LENGTH_TOO_LARGE 11 -#define MDS_ERROR_ALLOCATING_HEAP_TDI_UNITS 12 -#define MDS_ERROR_ALLOCATING_HEAP_UNITS 13 -#define MDS_ERROR_MDSVALUE_UNITS 14 -#define MDS_ERROR_READING_DIMENSIONAL_DATA 15 -#define MDS_ERROR_MDSVALUE_TYPE 16 - -#define MDS_ERROR_DIM_DIMENSION_NUMBER_EXCEEDED 17 -#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_SIZE 18 -#define MDS_ERROR_DIM_MDSVALUE_SIZE 19 -#define MDS_ERROR_DIM_ALLOCATING_HEAP_DATA_BLOCK 20 -#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_DIM_OF 21 -#define MDS_ERROR_DIM_MDSVALUE_DATA 22 +#define MDS_ERROR_MDSVALUE_LEN_UNITS 10 +#define MDS_ERROR_UNITS_LENGTH_TOO_LARGE 11 +#define MDS_ERROR_ALLOCATING_HEAP_TDI_UNITS 12 +#define MDS_ERROR_ALLOCATING_HEAP_UNITS 13 +#define MDS_ERROR_MDSVALUE_UNITS 14 +#define MDS_ERROR_READING_DIMENSIONAL_DATA 15 +#define MDS_ERROR_MDSVALUE_TYPE 16 + +#define MDS_ERROR_DIM_DIMENSION_NUMBER_EXCEEDED 17 +#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_SIZE 18 +#define MDS_ERROR_DIM_MDSVALUE_SIZE 19 +#define MDS_ERROR_DIM_ALLOCATING_HEAP_DATA_BLOCK 20 +#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_DIM_OF 21 +#define MDS_ERROR_DIM_MDSVALUE_DATA 22 #define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_LEN_UNITS 23 -#define MDS_ERROR_DIM_MDSVALUE_LEN_UNITS 24 -#define MDS_ERROR_DIM_UNITS_LENGTH_TOO_LARGE 25 -#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_UNITS 26 -#define MDS_ERROR_DIM_ALLOCATING_HEAP_DIM_UNITS 27 -#define MDS_ERROR_DIM_MDSVALUE_UNITS 28 +#define MDS_ERROR_DIM_MDSVALUE_LEN_UNITS 24 +#define MDS_ERROR_DIM_UNITS_LENGTH_TOO_LARGE 25 +#define MDS_ERROR_DIM_ALLOCATING_HEAP_TDI_UNITS 26 +#define MDS_ERROR_DIM_ALLOCATING_HEAP_DIM_UNITS 27 +#define MDS_ERROR_DIM_MDSVALUE_UNITS 28 -#define MDS_SERVER_NOT_RESPONDING 30 -#define MDS_SERVER_NOT_KNOWN 31 -#define MDS_SERVER_PING_TEST_PROBLEM 32 +#define MDS_SERVER_NOT_RESPONDING 30 +#define MDS_SERVER_NOT_KNOWN 31 +#define MDS_SERVER_PING_TEST_PROBLEM 32 -#define UNCOMPRESS_ALLOCATING_HEAP 40 -#define UNKNOWN_DATA_TYPE 41 -#define ERROR_ALLOCATING_HEAP 42 -#define ERROR_ALLOCATING_META_DATA_HEAP 43 +#define UNCOMPRESS_ALLOCATING_HEAP 40 +#define UNKNOWN_DATA_TYPE 41 +#define ERROR_ALLOCATING_HEAP 42 +#define ERROR_ALLOCATING_META_DATA_HEAP 43 //------------------------------------------------------- -#define MDS_ERROR_READING_SERVER_NAME 50 -#define MDS_ERROR_RETURNING_RANK 51 -#define MDS_ERROR_DATA_ARRAY_SIZE 52 -#define MDS_ERROR_XDR_ENDOFRECORD 53 -#define MDS_ERROR_RETURNING_DATA_UNITS 54 -#define MDS_ERROR_RETURNING_DATA_VALUES 55 -#define MDS_ERROR_DIMENSION_ARRAY_SIZE 56 -#define MDS_ERROR_RETURNING_DIMENSION_UNITS 57 -#define MDS_ERROR_RETURNING_DIMENSION_VALUES 58 +#define MDS_ERROR_READING_SERVER_NAME 50 +#define MDS_ERROR_RETURNING_RANK 51 +#define MDS_ERROR_DATA_ARRAY_SIZE 52 +#define MDS_ERROR_XDR_ENDOFRECORD 53 +#define MDS_ERROR_RETURNING_DATA_UNITS 54 +#define MDS_ERROR_RETURNING_DATA_VALUES 55 +#define MDS_ERROR_DIMENSION_ARRAY_SIZE 56 +#define MDS_ERROR_RETURNING_DIMENSION_UNITS 57 +#define MDS_ERROR_RETURNING_DIMENSION_VALUES 58 //------------------------------------------------------- -#define IDA_CLIENT_FILE_NAME_TOO_LONG 100 -#define IDA_CLIENT_SIGNAL_NAME_TOO_LONG 101 -#define IDA_ERROR_OPENING_FILE 102 -#define IDA_ERROR_IDENTIFYING_ITEM 103 -#define IDA_ERROR_READING_DATA 104 -#define IDA_ERROR_RETURNING_RANK 105 -#define IDA_ERROR_DATA_ARRAY_SIZE 106 -#define IDA_ERROR_XDR_ENDOFRECORD 107 -#define IDA_ERROR_ALLOCATING_HEAP 108 -#define IDA_ERROR_RETURNING_DATA_UNITS 109 -#define IDA_ERROR_RETURNING_DATA_VALUES 110 -#define IDA_ERROR_DIMENSION_ARRAY_SIZE 111 -#define IDA_ERROR_RETURNING_DIMENSION_UNITS 112 -#define IDA_ERROR_RETURNING_DIMENSION_VALUES 113 +#define IDA_CLIENT_FILE_NAME_TOO_LONG 100 +#define IDA_CLIENT_SIGNAL_NAME_TOO_LONG 101 +#define IDA_ERROR_OPENING_FILE 102 +#define IDA_ERROR_IDENTIFYING_ITEM 103 +#define IDA_ERROR_READING_DATA 104 +#define IDA_ERROR_RETURNING_RANK 105 +#define IDA_ERROR_DATA_ARRAY_SIZE 106 +#define IDA_ERROR_XDR_ENDOFRECORD 107 +#define IDA_ERROR_ALLOCATING_HEAP 108 +#define IDA_ERROR_RETURNING_DATA_UNITS 109 +#define IDA_ERROR_RETURNING_DATA_VALUES 110 +#define IDA_ERROR_DIMENSION_ARRAY_SIZE 111 +#define IDA_ERROR_RETURNING_DIMENSION_UNITS 112 +#define IDA_ERROR_RETURNING_DIMENSION_VALUES 113 #endif // UDA_CLIENTSERVER_UDAERRORS_H diff --git a/source/include/udaGetAPI.h b/source/include/udaGetAPI.h old mode 100755 new mode 100644 index 8d6cad7b..1b8be7c0 --- a/source/include/udaGetAPI.h +++ b/source/include/udaGetAPI.h @@ -14,14 +14,14 @@ extern "C" { # define idamGetBatchAPIWithHost idamGetBatchAPIWithHostFat #endif -LIBRARY_API int idamGetAPI(const char *data_object, const char *data_source); +LIBRARY_API int idamGetAPI(const char* data_object, const char* data_source); LIBRARY_API int idamGetBatchAPI(const char** uda_signals, const char** sources, int count, int* handles); -LIBRARY_API int idamGetAPIWithHost(const char *data_object, const char *data_source, const char *host, int port); -LIBRARY_API int idamGetBatchAPIWithHost(const char** uda_signals, const char** sources, int count, int* handles, const char* host, int port); +LIBRARY_API int idamGetAPIWithHost(const char* data_object, const char* data_source, const char* host, int port); +LIBRARY_API int idamGetBatchAPIWithHost(const char** uda_signals, const char** sources, int count, int* handles, + const char* host, int port); #ifdef __cplusplus } #endif #endif // UDA_CLIENT_UDAGETAPI_H - diff --git a/source/include/udaPlugin.h b/source/include/udaPlugin.h old mode 100755 new mode 100644 index 061e90e1..db062694 --- a/source/include/udaPlugin.h +++ b/source/include/udaPlugin.h @@ -3,35 +3,36 @@ #include -#include "udaStructs.h" #include "export.h" -#include "udaTypes.h" #include "pluginStructs.h" +#include "udaStructs.h" +#include "udaTypes.h" #include #ifdef __cplusplus extern "C" { #endif -#define MAXFUNCTIONNAME 256 +#define MAXFUNCTIONNAME 256 // plugin State -#define UDA_PLUGIN_INTERNAL 0 -#define UDA_PLUGIN_EXTERNAL 1 // The plugin resides in an external shared library -#define UDA_PLUGIN_NOT_OPERATIONAL 0 -#define UDA_PLUGIN_OPERATIONAL 1 +#define UDA_PLUGIN_INTERNAL 0 +#define UDA_PLUGIN_EXTERNAL 1 // The plugin resides in an external shared library +#define UDA_PLUGIN_NOT_OPERATIONAL 0 +#define UDA_PLUGIN_OPERATIONAL 1 // privacy -#define UDA_PLUGIN_PRIVATE 1 // Only internal users can use the service (access the data!) -#define UDA_PLUGIN_PUBLIC 0 // All users - internal and external - can use the service +#define UDA_PLUGIN_PRIVATE 1 // Only internal users can use the service (access the data!) +#define UDA_PLUGIN_PUBLIC 0 // All users - internal and external - can use the service -typedef void (* ADDIDAMERRORFUNP)(UDA_ERROR_STACK*, int, char*, int, char*); // Write to the Error Log +typedef void (*ADDIDAMERRORFUNP)(UDA_ERROR_STACK*, int, char*, int, char*); // Write to the Error Log // Prototypes -LIBRARY_API int callPlugin(const PLUGINLIST* pluginlist, const char* request, const IDAM_PLUGIN_INTERFACE* old_plugin_interface); +LIBRARY_API int callPlugin(const PLUGINLIST* pluginlist, const char* request, + const IDAM_PLUGIN_INTERFACE* old_plugin_interface); IDAM_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request); void udaFreePluginInterface(IDAM_PLUGIN_INTERFACE* plugin_interface); @@ -42,9 +43,12 @@ LIBRARY_API int findPluginIdByDevice(const char* device, const PLUGINLIST* plugi 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 setReturnDataFloatArray(DATA_BLOCK* data_block, 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, const char* description); -LIBRARY_API int setReturnDataIntArray(DATA_BLOCK* data_block, int* values, size_t rank, const size_t* shape, const char* description); +LIBRARY_API int setReturnDataFloatArray(DATA_BLOCK* data_block, 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, + const char* description); +LIBRARY_API int setReturnDataIntArray(DATA_BLOCK* data_block, 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); @@ -52,7 +56,8 @@ LIBRARY_API int setReturnDataLongScalar(DATA_BLOCK* data_block, long value, cons 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, const int* shape, const char* description); +LIBRARY_API int setReturnData(DATA_BLOCK* data_block, 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); @@ -62,7 +67,8 @@ LIBRARY_API bool findCharValue(const NAMEVALUELIST* namevaluelist, char* value, 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, const char* name); +LIBRARY_API bool findDoubleArray(const NAMEVALUELIST* namevaluelist, double** values, size_t* nvalues, + const char* name); #define QUOTE_(X) #X #define QUOTE(X) QUOTE_(X) @@ -70,77 +76,90 @@ 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) \ -{ 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); \ -return UNIQUE_VAR(err); } - -#define RAISE_PLUGIN_ERROR(MSG) \ -{ int UNIQUE_VAR(err) = 999; \ -UDA_LOG(UDA_LOG_ERROR, "%s\n", MSG); \ -addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ -return UNIQUE_VAR(err); } - -#define RAISE_PLUGIN_ERROR_F(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); \ -return UNIQUE_VAR(err); } - -#define RAISE_PLUGIN_ERROR_AND_EXIT_F(plugin_interface_ptr, 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); \ -return UNIQUE_VAR(err); } - -#define RAISE_PLUGIN_ERROR_EX(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; \ -return UNIQUE_VAR(err); - -#define FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, TYPE) \ -if (!find##TYPE##Value(&NAME_VALUE_LIST, &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))) { \ - 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 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); \ -if (UNIQUE_VAR(err)) { \ - RAISE_PLUGIN_ERROR("Plugin call failed"); \ -} } +#define RAISE_PLUGIN_ERROR_AND_EXIT(MSG, plugin_interface_ptr) \ + { \ + 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); \ + return UNIQUE_VAR(err); \ + } + +#define RAISE_PLUGIN_ERROR(MSG) \ + { \ + int UNIQUE_VAR(err) = 999; \ + UDA_LOG(UDA_LOG_ERROR, "%s\n", MSG); \ + addIdamError(UDA_CODE_ERROR_TYPE, __func__, UNIQUE_VAR(err), MSG); \ + return UNIQUE_VAR(err); \ + } + +#define RAISE_PLUGIN_ERROR_F(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); \ + return UNIQUE_VAR(err); \ + } + +#define RAISE_PLUGIN_ERROR_AND_EXIT_F(plugin_interface_ptr, 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); \ + return UNIQUE_VAR(err); \ + } + +#define RAISE_PLUGIN_ERROR_EX(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; \ + return UNIQUE_VAR(err); + +#define FIND_REQUIRED_VALUE(NAME_VALUE_LIST, VARIABLE, TYPE) \ + if (!find##TYPE##Value(&NAME_VALUE_LIST, &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))) { \ + 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 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); \ + if (UNIQUE_VAR(err)) { \ + RAISE_PLUGIN_ERROR("Plugin call failed"); \ + } \ + } #ifdef __cplusplus } diff --git a/source/include/udaPutAPI.h b/source/include/udaPutAPI.h old mode 100755 new mode 100644 index cf773241..654a2967 --- a/source/include/udaPutAPI.h +++ b/source/include/udaPutAPI.h @@ -1,8 +1,8 @@ #ifndef UDA_CLIENT_UDAPUTAPI_H #define UDA_CLIENT_UDAPUTAPI_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef FATCLIENT # define idamPutListAPI idamPutListAPIFat diff --git a/source/include/udaStructs.h b/source/include/udaStructs.h old mode 100755 new mode 100644 index 31d5b51f..931e2deb --- a/source/include/udaStructs.h +++ b/source/include/udaStructs.h @@ -7,9 +7,9 @@ #include -#include "udaDefines.h" #include "export.h" -//#include "clientserver/parseXML.h" +#include "udaDefines.h" +// #include "clientserver/parseXML.h" #ifdef __cplusplus extern "C" { @@ -19,12 +19,12 @@ extern "C" { // Structure Definitions typedef struct DataSubset { - int subsetCount; // Number of defined dimensions to subset - int subset[MAXRANK2]; // If 1 then subset to apply - int start[MAXRANK2]; // Starting Index of each dimension - int stop[MAXRANK2]; // Ending Index of each dimension - int count[MAXRANK2]; // The number of values (sub-samples) read from each dimension - int stride[MAXRANK2]; // The step stride along each dimension + int subsetCount; // Number of defined dimensions to subset + int subset[MAXRANK2]; // If 1 then subset to apply + int start[MAXRANK2]; // Starting Index of each dimension + int stop[MAXRANK2]; // Ending Index of each dimension + int count[MAXRANK2]; // The number of values (sub-samples) read from each dimension + int stride[MAXRANK2]; // The step stride along each dimension } DATASUBSET; typedef struct VLen { @@ -144,83 +144,84 @@ typedef struct SignalDesc { } SIGNAL_DESC; typedef struct Dims { - int data_type; // Type of data - int error_type; // Type of error data - int error_model; // Identify the Error Model - int errasymmetry; // Flags whether or not error data are asymmetrical - int error_param_n; // the Number of Model Parameters - int dim_n; // Array lengths - - int compressed; // TRUE if data is regular and in compressed form - double dim0; // Starting Value for Regular Grid - double diff; // Step value for Regular Grid - - int method; // Compression Method - unsigned int udoms; // Number of Domains - int* sams; // Array of Domain Lengths == sams[udoms] - char* offs; // Array of Domain Starting Values == offs[udoms] - char* ints; // Array of Domain Interval Values == ints[udoms] - - char* dim; // Dimension Data Array - char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling - - char* errhi; // Dimension Error Array (Errors above the line: data + error) - char* errlo; // Dimension Error Array (Errors below the line: data - error) - float errparams[MAXERRPARAMS]; // the array of model parameters + int data_type; // Type of data + int error_type; // Type of error data + int error_model; // Identify the Error Model + int errasymmetry; // Flags whether or not error data are asymmetrical + int error_param_n; // the Number of Model Parameters + int dim_n; // Array lengths + + int compressed; // TRUE if data is regular and in compressed form + double dim0; // Starting Value for Regular Grid + double diff; // Step value for Regular Grid + + int method; // Compression Method + unsigned int udoms; // Number of Domains + int* sams; // Array of Domain Lengths == sams[udoms] + char* offs; // Array of Domain Starting Values == offs[udoms] + char* ints; // Array of Domain Interval Values == ints[udoms] + + char* dim; // Dimension Data Array + char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling + + char* errhi; // Dimension Error Array (Errors above the line: data + error) + char* errlo; // Dimension Error Array (Errors below the line: data - error) + float errparams[MAXERRPARAMS]; // the array of model parameters char dim_units[STRING_LENGTH]; char dim_label[STRING_LENGTH]; } DIMS; typedef struct SecurityBlock { - unsigned short structVersion; // Structure Version number - unsigned short encryptionMethod; // How mutual authentication is executed - unsigned short authenticationStep; // Authentication step that created this data structure - unsigned short client_ciphertextLength; // cipher lengths (not strings but unsigned byte arrays) + unsigned short structVersion; // Structure Version number + unsigned short encryptionMethod; // How mutual authentication is executed + unsigned short authenticationStep; // Authentication step that created this data structure + unsigned short client_ciphertextLength; // cipher lengths (not strings but unsigned byte arrays) unsigned short client2_ciphertextLength; unsigned short server_ciphertextLength; unsigned short client_X509Length; unsigned short client2_X509Length; - unsigned char* client_ciphertext; // client token encrypted with either the client's or 1st server's public key - unsigned char* server_ciphertext; // server token encrypted with the client's public key - unsigned char* client2_ciphertext; // client2 token encrypted with either the client's or nth server's public key + unsigned char* client_ciphertext; // client token encrypted with either the client's or 1st server's public key + unsigned char* server_ciphertext; // server token encrypted with the client's public key + unsigned char* client2_ciphertext; // client2 token encrypted with either the client's or nth server's public key unsigned char* client_X509; unsigned char* client2_X509; } SECURITY_BLOCK; typedef struct ClientBlock { int version; - int pid; // Client Application process id - char uid[STRING_LENGTH]; // Who the Client is (claim of identity to the first server) + int pid; // Client Application process id + char uid[STRING_LENGTH]; // Who the Client is (claim of identity to the first server) // Server properties set by the client - int timeout; // Server Shutdown after this time (minutes) if no data request - int compressDim; // Enable Compression of the Dimensional Data? + int timeout; // Server Shutdown after this time (minutes) if no data request + int compressDim; // Enable Compression of the Dimensional Data? - unsigned int clientFlags; // client defined properties passed via bit flags - int altRank; // Specify the rank of the alternative signal/source to be used + unsigned int clientFlags; // client defined properties passed via bit flags + int altRank; // Specify the rank of the alternative signal/source to be used - int get_nodimdata; // Don't send Dimensional Data: Send an index only. - int get_timedble; // Return Time Dimension Data in Double Precision if originally compressed - int get_dimdble; // Return all Dimensional Data in Double Precision - int get_datadble; // Return Data in Double Precision + int get_nodimdata; // Don't send Dimensional Data: Send an index only. + int get_timedble; // Return Time Dimension Data in Double Precision if originally compressed + int get_dimdble; // Return all Dimensional Data in Double Precision + int get_datadble; // Return Data in Double Precision - int get_bad; // Return Only Data with Bad Status value - int get_meta; // Return Metadata associated with Signal - int get_asis; // Return data as Stored in data Archive - int get_uncal; // Disable Calibration Correction - int get_notoff; // Disable Timing Offset Correction - int get_scalar; // Reduce rank from 1 to 0 (Scalar) if dimensional data are all zero - int get_bytes; // Return Data as Bytes or Integers without applying the signal's ADC Calibration Data + int get_bad; // Return Only Data with Bad Status value + int get_meta; // Return Metadata associated with Signal + int get_asis; // Return data as Stored in data Archive + int get_uncal; // Disable Calibration Correction + int get_notoff; // Disable Timing Offset Correction + int get_scalar; // Reduce rank from 1 to 0 (Scalar) if dimensional data are all zero + int get_bytes; // Return Data as Bytes or Integers without applying the signal's ADC Calibration Data - unsigned int privateFlags; // set of private flags used to communicate server to server + unsigned int privateFlags; // set of private flags used to communicate server to server - char OSName[STRING_LENGTH]; // Name of the Client side Operating System, e.g. OSX - char DOI[STRING_LENGTH]; // User's research DOI - to be logged with all data access requests + char OSName[STRING_LENGTH]; // Name of the Client side Operating System, e.g. OSX + char DOI[STRING_LENGTH]; // User's research DOI - to be logged with all data access requests - char uid2[STRING_LENGTH]; // Who the Client is (claim of identity to the last server) - SECURITY_BLOCK securityBlock; // Contains encrypted tokens exchanged between client and server for mutual authentication + char uid2[STRING_LENGTH]; // Who the Client is (claim of identity to the last server) + SECURITY_BLOCK + securityBlock; // Contains encrypted tokens exchanged between client and server for mutual authentication } CLIENT_BLOCK; @@ -234,17 +235,17 @@ typedef struct DataBlock { int data_type; int error_type; - int error_model; // Identify the Error Model - int errasymmetry; // Flags whether error data are asymmetrical - int error_param_n; // the Number of Model Parameters + int error_model; // Identify the Error Model + int errasymmetry; // Flags whether error data are asymmetrical + int error_param_n; // the Number of Model Parameters int data_n; char* data; - char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling + char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling - char* errhi; // Error Array (Errors above the line: data + error) - char* errlo; // Error Array (Errors below the line: data - error) - float errparams[MAXERRPARAMS]; // the array of model parameters + char* errhi; // Error Array (Errors above the line: data + error) + char* errlo; // Error Array (Errors below the line: data - error) + float errparams[MAXERRPARAMS]; // the array of model parameters char data_units[STRING_LENGTH]; char data_label[STRING_LENGTH]; @@ -259,13 +260,13 @@ typedef struct DataBlock { SIGNAL* signal_rec; SIGNAL_DESC* signal_desc; - CLIENT_BLOCK client_block; // Used to pass properties into data reader plugins + CLIENT_BLOCK client_block; // Used to pass properties into data reader plugins - int opaque_type; // Identifies the Data Structure Type; - int opaque_count; // Number of Instances of the Data Structure; - void* opaque_block; // Opaque pointer to Hierarchical Data Structures - unsigned int totalDataBlockSize;// The amount of data within this structure. - unsigned int cachePermission; // Permission for the Client to cache this structure. + int opaque_type; // Identifies the Data Structure Type; + int opaque_count; // Number of Instances of the Data Structure; + void* opaque_block; // Opaque pointer to Hierarchical Data Structures + unsigned int totalDataBlockSize; // The amount of data within this structure. + unsigned int cachePermission; // Permission for the Client to cache this structure. } DATA_BLOCK; typedef struct DataBlockList { @@ -274,7 +275,7 @@ typedef struct DataBlockList { } DATA_BLOCK_LIST; typedef struct DataObject { - unsigned short objectType; // File or regular object + unsigned short objectType; // File or regular object unsigned int objectSize; unsigned short hashType; unsigned short hashLength; @@ -288,79 +289,80 @@ typedef struct PutDataBlock { unsigned int count; int* shape; const char* data; - int opaque_type; // Identifies the Data Structure Type; - int opaque_count; // Number of Instances of the Data Structure; - void* opaque_block; // Opaque pointer to Hierarchical Data Structures - unsigned int blockNameLength; // Size of the Name character string - const char* blockName; // Name of the Data Block + int opaque_type; // Identifies the Data Structure Type; + int opaque_count; // Number of Instances of the Data Structure; + void* opaque_block; // Opaque pointer to Hierarchical Data Structures + unsigned int blockNameLength; // Size of the Name character string + const char* blockName; // Name of the Data Block } PUTDATA_BLOCK; typedef struct PutDataBlockList { - unsigned int blockCount; // Number of data blocks - unsigned int blockListSize; // Number of data blocks allocated - PUTDATA_BLOCK* putDataBlock; // Array of data blocks + unsigned int blockCount; // Number of data blocks + unsigned int blockListSize; // Number of data blocks allocated + PUTDATA_BLOCK* putDataBlock; // Array of data blocks } PUTDATA_BLOCK_LIST; typedef struct UdaError { - int type; // Error Classification - int code; // Error Code - char location[STRING_LENGTH]; // Where this Error is Located - char msg[STRING_LENGTH]; // Message + int type; // Error Classification + int code; // Error Code + char location[STRING_LENGTH]; // Where this Error is Located + char msg[STRING_LENGTH]; // Message } UDA_ERROR; typedef struct UdaErrorStack { - unsigned int nerrors; // Number of Errors - UDA_ERROR* idamerror; // Array of Errors + unsigned int nerrors; // Number of Errors + UDA_ERROR* idamerror; // Array of Errors } UDA_ERROR_STACK; typedef struct ServerBlock { int version; int error; char msg[STRING_LENGTH]; - int pid; // Server Application process id + int pid; // Server Application process id UDA_ERROR_STACK idamerrorstack; - char OSName[STRING_LENGTH]; // Name of the Server's Operating System, e.g. OSX - char DOI[STRING_LENGTH]; // Server version/implementation DOI - to be logged with all data consumers - SECURITY_BLOCK securityBlock; // Contains encrypted tokens exchanged between client and server for mutual authentication + char OSName[STRING_LENGTH]; // Name of the Server's Operating System, e.g. OSX + char DOI[STRING_LENGTH]; // Server version/implementation DOI - to be logged with all data consumers + SECURITY_BLOCK + securityBlock; // Contains encrypted tokens exchanged between client and server for mutual authentication } SERVER_BLOCK; typedef struct NameValue { - char* pair; // The name value pair string - char* name; // The name - char* value; // The value + char* pair; // The name value pair string + char* name; // The name + char* value; // The value } NAMEVALUE; typedef struct NameValueList { int pairCount; // Number of name value pairs in list int listSize; // Allocated Size of the List - NAMEVALUE* nameValue; // List of individual name value pairs in parse order + NAMEVALUE* nameValue; // List of individual name value pairs in parse order } NAMEVALUELIST; enum REQUEST { REQUEST_SHUTDOWN = 1, - REQUEST_READ_GENERIC, // Generic Signal via the UDA Database - REQUEST_READ_IDA, // an IDA File - REQUEST_READ_MDS, // an MDSPlus Server - REQUEST_READ_IDAM, // a Remote UDA server - REQUEST_READ_FORMAT, // Server to Choose Plugin for Requested Format - REQUEST_READ_CDF, // netCDF File - REQUEST_READ_HDF5, // HDF5 FIle - REQUEST_READ_XML, // XML Document defining a Signal - REQUEST_READ_UFILE, // TRANSP UFile - REQUEST_READ_FILE, // Read a File: A Container of Bytes! - REQUEST_READ_SQL, // Read from an SQL Data Source - REQUEST_READ_PPF, // JET PPF - REQUEST_READ_JPF, // JET JPF + REQUEST_READ_GENERIC, // Generic Signal via the UDA Database + REQUEST_READ_IDA, // an IDA File + REQUEST_READ_MDS, // an MDSPlus Server + REQUEST_READ_IDAM, // a Remote UDA server + REQUEST_READ_FORMAT, // Server to Choose Plugin for Requested Format + REQUEST_READ_CDF, // netCDF File + REQUEST_READ_HDF5, // HDF5 FIle + REQUEST_READ_XML, // XML Document defining a Signal + REQUEST_READ_UFILE, // TRANSP UFile + REQUEST_READ_FILE, // Read a File: A Container of Bytes! + REQUEST_READ_SQL, // Read from an SQL Data Source + REQUEST_READ_PPF, // JET PPF + REQUEST_READ_JPF, // JET JPF REQUEST_READ_NEW_PLUGIN, - REQUEST_READ_NOTHING, // Immediate Return without Error: Client Server Timing Tests - REQUEST_READ_BLOCKED, // Disable Server Option for External Users (Not a client side option) - REQUEST_READ_HDATA, // Hierarchical Data Structures - REQUEST_READ_SERVERSIDE, // Server Side Functions - REQUEST_READ_UNKNOWN, // Plugin Not Known - REQUEST_READ_WEB, // a Remote or Local web server - REQUEST_READ_BIN, // Binary file - REQUEST_READ_HELP, // Help file - REQUEST_READ_DEVICE, // Request to an External Device's data server + REQUEST_READ_NOTHING, // Immediate Return without Error: Client Server Timing Tests + REQUEST_READ_BLOCKED, // Disable Server Option for External Users (Not a client side option) + REQUEST_READ_HDATA, // Hierarchical Data Structures + REQUEST_READ_SERVERSIDE, // Server Side Functions + REQUEST_READ_UNKNOWN, // Plugin Not Known + REQUEST_READ_WEB, // a Remote or Local web server + REQUEST_READ_BIN, // Binary file + REQUEST_READ_HELP, // Help file + REQUEST_READ_DEVICE, // Request to an External Device's data server REQUEST_CACHED, }; @@ -370,39 +372,39 @@ typedef struct OptionalLong { } OPTIONAL_LONG; typedef struct Subset { - int nbound; // the Number of Subsetting Operations - int reform; // reduce Rank if any dimension has length 1 - int order; // Time Dimension order - double bound[UDA_MAX_DATA_RANK]; // Array of Floating point Bounding values - OPTIONAL_LONG stride[UDA_MAX_DATA_RANK]; // Array of Integer values: Striding values - OPTIONAL_LONG ubindex[UDA_MAX_DATA_RANK]; // Array of Integer values: Bounding or Upper Index - OPTIONAL_LONG lbindex[UDA_MAX_DATA_RANK]; // Array of Integer values: Lower Index - char operation[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING]; // Array of Subsetting Operations - int dimid[UDA_MAX_DATA_RANK]; // Array of Dimension IDs to subset - bool isindex[UDA_MAX_DATA_RANK]; // Flag the Operation Bound is an Integer Type - char data_signal[UDA_SXML_MAX_STRING]; // Name of Signal to subset - char member[UDA_SXML_MAX_STRING]; // Name of Structure Member to extract and to subset - char function[UDA_SXML_MAX_STRING]; // Apply this named function to the subsetted data + int nbound; // the Number of Subsetting Operations + int reform; // reduce Rank if any dimension has length 1 + int order; // Time Dimension order + double bound[UDA_MAX_DATA_RANK]; // Array of Floating point Bounding values + OPTIONAL_LONG stride[UDA_MAX_DATA_RANK]; // Array of Integer values: Striding values + OPTIONAL_LONG ubindex[UDA_MAX_DATA_RANK]; // Array of Integer values: Bounding or Upper Index + OPTIONAL_LONG lbindex[UDA_MAX_DATA_RANK]; // Array of Integer values: Lower Index + char operation[UDA_MAX_DATA_RANK][UDA_SXML_MAX_STRING]; // Array of Subsetting Operations + int dimid[UDA_MAX_DATA_RANK]; // Array of Dimension IDs to subset + bool isindex[UDA_MAX_DATA_RANK]; // Flag the Operation Bound is an Integer Type + char data_signal[UDA_SXML_MAX_STRING]; // Name of Signal to subset + char member[UDA_SXML_MAX_STRING]; // Name of Structure Member to extract and to subset + char function[UDA_SXML_MAX_STRING]; // Apply this named function to the subsetted data } SUBSET; typedef struct RequestData { - int request; // Plugin or Shutdown Server - int exp_number; // Pulse No.,Tree No., etc - int pass; // Pass, Sequence, etc - char tpass[STRING_LENGTH]; // - char path[STRING_LENGTH]; // Path to File, Path to Node - char file[STRING_LENGTH]; // File name, Tree name - char format[STRING_LENGTH]; // File Format - char signal[MAXMETA]; // Signal, Node etc - char archive[STRING_LENGTH]; // Archive: pr98, transp, etc - char device_name[STRING_LENGTH]; // Device name: Mast, Jet, etc - char server[STRING_LENGTH]; // UDA, MDS+ Server - char source[STRING_LENGTH]; // Data Source, Server Host, URL etc - char function[STRING_LENGTH]; // Server-Side function or attached plugin function - char api_delim[MAXNAME]; // Delimiter string to use decoding the signal and source arguments - char subset[STRING_LENGTH]; // Subset instructions - SUBSET datasubset; // Parsed subset instructions (Server Side) - NAMEVALUELIST nameValueList; // Set of Name-Value pairs (Server Side Function) + int request; // Plugin or Shutdown Server + int exp_number; // Pulse No.,Tree No., etc + int pass; // Pass, Sequence, etc + char tpass[STRING_LENGTH]; // + char path[STRING_LENGTH]; // Path to File, Path to Node + char file[STRING_LENGTH]; // File name, Tree name + char format[STRING_LENGTH]; // File Format + char signal[MAXMETA]; // Signal, Node etc + char archive[STRING_LENGTH]; // Archive: pr98, transp, etc + char device_name[STRING_LENGTH]; // Device name: Mast, Jet, etc + char server[STRING_LENGTH]; // UDA, MDS+ Server + char source[STRING_LENGTH]; // Data Source, Server Host, URL etc + char function[STRING_LENGTH]; // Server-Side function or attached plugin function + char api_delim[MAXNAME]; // Delimiter string to use decoding the signal and source arguments + char subset[STRING_LENGTH]; // Subset instructions + SUBSET datasubset; // Parsed subset instructions (Server Side) + NAMEVALUELIST nameValueList; // Set of Name-Value pairs (Server Side Function) int put; // flag to set the server to a put state PUTDATA_BLOCK_LIST putDataBlockList; // Data to be put on the server @@ -417,33 +419,34 @@ typedef struct RequestBlock { // System Environment Variables typedef struct Environment { - int server_port; // Principal UDA server port - int server_port2; // Backup UDA server port + int server_port; // Principal UDA server port + int server_port2; // Backup UDA server port int sql_port; - int server_reconnect; // If the client changes to a different UDA server then open a new socket - int server_change_socket; // Connect to a Running Server - int server_socket; // Clients must keep track of the sockets they open - int data_path_id; // Identifies the algorithm that defines the default path to the standard data source. - int external_user; // Flags this service as accessible by external users: Disable some access formats for security. - unsigned int clientFlags; // Use legacy Name substitution - int altRank; // Use specific set of legacy name substitutes + int server_reconnect; // If the client changes to a different UDA server then open a new socket + int server_change_socket; // Connect to a Running Server + int server_socket; // Clients must keep track of the sockets they open + int data_path_id; // Identifies the algorithm that defines the default path to the standard data source. + int external_user; // Flags this service as accessible by external users: Disable some access formats for security. + unsigned int clientFlags; // Use legacy Name substitution + int altRank; // Use specific set of legacy name substitutes char logdir[MAXPATH]; char logmode[2]; int loglevel; - char server_host[MAXNAME]; // Principal UDA server host - char server_host2[MAXNAME]; // Backup UDA server host - char server_proxy[MAXNAME]; // host:port - Running as a Proxy UDA server: Prefix 'UDA::host:port/' to redirect request - char server_this[MAXNAME]; // host:port - The current server. Used to trap potential infinite redirects + char server_host[MAXNAME]; // Principal UDA server host + char server_host2[MAXNAME]; // Backup UDA server host + char server_proxy[MAXNAME]; // host:port - Running as a Proxy UDA server: Prefix 'UDA::host:port/' to redirect + // request + char server_this[MAXNAME]; // host:port - The current server. Used to trap potential infinite redirects char sql_host[MAXNAME]; char sql_dbname[MAXNAME]; char sql_user[MAXNAME]; - char api_delim[MAXNAME]; // Default API Signal and Source Delimiter Sub-String - char api_device[STRING_LENGTH]; // API Default Device name - char api_archive[STRING_LENGTH]; // API Default Archive name - char api_format[STRING_LENGTH]; // API Default Client File Format - char private_path_target[STRING_LENGTH]; // Target this path to private files - char private_path_substitute[STRING_LENGTH]; // and substitute with this path (so the server can locate them!) - char initialised; // Environment already initialised. + char api_delim[MAXNAME]; // Default API Signal and Source Delimiter Sub-String + char api_device[STRING_LENGTH]; // API Default Device name + char api_archive[STRING_LENGTH]; // API Default Archive name + char api_format[STRING_LENGTH]; // API Default Client File Format + char private_path_target[STRING_LENGTH]; // Target this path to private files + char private_path_substitute[STRING_LENGTH]; // and substitute with this path (so the server can locate them!) + char initialised; // Environment already initialised. char _padding[1]; } ENVIRONMENT; @@ -457,7 +460,7 @@ void freeReducedDataBlock(DATA_BLOCK* data_block); void freeRequestBlock(REQUEST_BLOCK* request_block); -//void freeRequestData(REQUEST_DATA* request_data); +// void freeRequestData(REQUEST_DATA* request_data); void freePutDataBlockList(PUTDATA_BLOCK_LIST* putDataBlockList); diff --git a/source/include/udaTypes.h b/source/include/udaTypes.h old mode 100755 new mode 100644 index bf9f9f97..d734604a --- a/source/include/udaTypes.h +++ b/source/include/udaTypes.h @@ -38,7 +38,7 @@ typedef enum UdaType { UDA_TYPE_COMPOUND = 18, UDA_TYPE_OPAQUE = 19, UDA_TYPE_ENUM = 20, - UDA_TYPE_VOID = 21, + UDA_TYPE_VOID = 21, UDA_TYPE_CAPNP = 22, UDA_TYPE_STRING2 = 99 } UDA_TYPE; @@ -49,7 +49,7 @@ typedef enum UdaType { typedef enum UdaOpaqueTypes { UDA_OPAQUE_TYPE_UNKNOWN = 0, UDA_OPAQUE_TYPE_XML_DOCUMENT = 1, - UDA_OPAQUE_TYPE_STRUCTURES = 2, + UDA_OPAQUE_TYPE_STRUCTURES = 2, UDA_OPAQUE_TYPE_XDRFILE = 3, UDA_OPAQUE_TYPE_XDROBJECT = 4 } UDA_OPAQUE_TYPE; diff --git a/source/logging/accessLog.cpp b/source/logging/accessLog.cpp old mode 100755 new mode 100644 index 74630ff7..010c5b89 --- a/source/logging/accessLog.cpp +++ b/source/logging/accessLog.cpp @@ -1,14 +1,14 @@ /*--------------------------------------------------------------- -* Server Access Log -* -* Log Format: Conforms to the Common Log Format for the first 6 fields -* -* client address, client userid, date, client request, -* error code, data bytes returned -* plus: error message, elapsed time, client version, server version -* client process id -* -*--------------------------------------------------------------*/ + * Server Access Log + * + * Log Format: Conforms to the Common Log Format for the first 6 fields + * + * client address, client userid, date, client request, + * error code, data bytes returned + * plus: error message, elapsed time, client version, server version + * client process id + * + *--------------------------------------------------------------*/ #include "accessLog.h" @@ -21,14 +21,14 @@ # include #endif -#include -#include "udaTypes.h" #include "clientserver/errorLog.h" #include "logging.h" +#include "udaTypes.h" +#include #if defined(SERVERBUILD) || defined(FATCLIENT) -# include # include +# include #endif unsigned int countDataBlockListSize(const DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block) @@ -62,11 +62,13 @@ unsigned int countDataBlockSize(const DATA_BLOCK* data_block, CLIENT_BLOCK* clie if (!dim.compressed) { count += (unsigned int)(getSizeOf((UDA_TYPE)dim.data_type) * dim.dim_n); factor = 1; - if (dim.errasymmetry) factor = 2; + if (dim.errasymmetry) { + factor = 2; + } if (dim.error_type != UDA_TYPE_UNKNOWN) { count += (unsigned int)(factor * getSizeOf((UDA_TYPE)dim.error_type) * dim.dim_n); } - } else {; + } else { switch (dim.method) { case 0: count += +2 * sizeof(double); @@ -88,8 +90,8 @@ unsigned int countDataBlockSize(const DATA_BLOCK* data_block, CLIENT_BLOCK* clie } if (client_block->get_meta) { - count += sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + - sizeof(SIGNAL_DESC); + count += + sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + sizeof(SIGNAL_DESC); } return count; @@ -102,24 +104,24 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo { int err = 0; -#ifndef FATCLIENT +# ifndef FATCLIENT int socket; socklen_t addrlen; -#endif -#ifndef IPV6PROTOCOL -# ifndef FATCLIENT - struct sockaddr_in addr = {}; # endif +# ifndef IPV6PROTOCOL +# ifndef FATCLIENT + struct sockaddr_in addr = {}; +# endif static char host[INET6_ADDRSTRLEN + 1]; -#else -# ifndef FATCLIENT +# else +# ifndef FATCLIENT struct sockaddr_in6 addr; +# endif + static char host[INET6_ADDRSTRLEN + 1]; # endif - static char host[INET6_ADDRSTRLEN+1]; -#endif static struct timeval et_start; static struct timeval et_end; - static char accessdate[UDA_DATE_LENGTH]; // The Calendar Time as a formatted String + static char accessdate[UDA_DATE_LENGTH]; // The Calendar Time as a formatted String errno = 0; @@ -128,13 +130,13 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo // Remote Host IP Address -#ifndef FATCLIENT +# ifndef FATCLIENT socket = 0; memset(&addr, 0, sizeof(addr)); addrlen = sizeof(addr); -#ifndef IPV6PROTOCOL +# ifndef IPV6PROTOCOL addr.sin_family = AF_INET; - if ((getpeername(socket, (struct sockaddr*)&addr, &addrlen)) == -1) { // Socket Address + if ((getpeername(socket, (struct sockaddr*)&addr, &addrlen)) == -1) { // Socket Address strcpy(host, "-"); } else { if (addrlen <= HOSTNAMELENGTH - 1) { @@ -144,14 +146,16 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo strncpy(host, inet_ntoa(addr.sin_addr), HOSTNAMELENGTH - 1); host[HOSTNAMELENGTH - 1] = '\0'; } -#endif +# endif convertNonPrintable2(host); TrimString(host); - if (strlen(host) == 0) strcpy(host, "-"); + if (strlen(host) == 0) { + strcpy(host, "-"); + } } -#else +# else strcpy(host, "-"); -#endif +# endif // Client's Userid: from the client_block structure @@ -163,11 +167,11 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo time_t calendar; time(&calendar); struct tm* broken = gmtime(&calendar); -#ifndef _WIN32 +# ifndef _WIN32 asctime_r(broken, accessdate); -#else +# else asctime_s(accessdate, DATELENGTH, broken); -#endif +# endif convertNonPrintable2(accessdate); TrimString(accessdate); @@ -197,7 +201,7 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo // Request Completed Time: Elasped & CPU gettimeofday(&et_end, nullptr); - auto elapsedtime = (double)((et_end.tv_sec - et_start.tv_sec) * 1000); // millisecs + auto elapsedtime = (double)((et_end.tv_sec - et_start.tv_sec) * 1000); // millisecs if (et_end.tv_usec < et_start.tv_usec) { elapsedtime = elapsedtime - 1.0 + (double)(1000000 + et_end.tv_usec - et_start.tv_usec) / 1000.0; @@ -210,45 +214,44 @@ void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_blo for (int i = 0; i < request_block.num_requests; ++i) { auto request = request_block.requests[i]; std::stringstream ss; - ss << host << " - " - << client_block.uid << " " + ss << host << " - " << client_block.uid << " " << "[" << accessdate << "] " << "[" << request.request << " " - << ""; - - auto fmt = boost::format("%1% - %2% [%3%] [%4% %5% %6% %7% %8% %9% %10% %11% %12% %13% %14%] %15% %16% [%17%] %18% %19% %20% [%21% %22%] [%23%]") - % host // 1 - % client_block.uid // 2 - % accessdate // 3 - % request.request // 4 - % request.signal // 5 - % request.exp_number // 6 - % request.pass // 7 - % request.tpass // 8 - % request.path // 9 - % request.file // 10 - % request.format // 11 - % request.archive // 12 - % request.device_name // 13 - % request.server // 14 - % err // 15 - % total_datablock_size // 16 - % msg // 17 - % elapsedtime // 18 - % client_block.version // 19 - % server_block.version // 20 - % client_block.pid // 21 - % server_block.pid // 22 - % client_block.DOI; // 23 + << ""; + + auto fmt = boost::format("%1% - %2% [%3%] [%4% %5% %6% %7% %8% %9% %10% %11% %12% %13% %14%] %15% %16% [%17%] " + "%18% %19% %20% [%21% %22%] [%23%]") % + host // 1 + % client_block.uid // 2 + % accessdate // 3 + % request.request // 4 + % request.signal // 5 + % request.exp_number // 6 + % request.pass // 7 + % request.tpass // 8 + % request.path // 9 + % request.file // 10 + % request.format // 11 + % request.archive // 12 + % request.device_name // 13 + % request.server // 14 + % err // 15 + % total_datablock_size // 16 + % msg // 17 + % elapsedtime // 18 + % client_block.version // 19 + % server_block.version // 20 + % client_block.pid // 21 + % server_block.pid // 22 + % client_block.DOI; // 23 auto str = fmt.str(); udaLog(UDA_LOG_ACCESS, "%s\n", str.c_str()); -// udaServerRedirectStdStreams(0); -// udaProvenancePlugin(&client_block, &request, nullptr, nullptr, pluginlist, str.c_str(), environment); -// udaServerRedirectStdStreams(1); + // udaServerRedirectStdStreams(0); + // udaProvenancePlugin(&client_block, &request, nullptr, nullptr, pluginlist, str.c_str(), environment); + // udaServerRedirectStdStreams(1); } - } #endif // defined(SERVERBUILD) || defined(FATCLIENT) diff --git a/source/logging/accessLog.h b/source/logging/accessLog.h old mode 100755 new mode 100644 index 2ee0f1f3..62105ac1 --- a/source/logging/accessLog.h +++ b/source/logging/accessLog.h @@ -1,11 +1,11 @@ #ifndef UDA_LOGGING_ACCESSLOG_H #define UDA_LOGGING_ACCESSLOG_H -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" -#define HOSTNAMELENGTH 20 -#define DATELENGTH 27 +#define HOSTNAMELENGTH 20 +#define DATELENGTH 27 #ifdef __cplusplus extern "C" { @@ -14,9 +14,8 @@ extern "C" { LIBRARY_API unsigned int countDataBlockListSize(const DATA_BLOCK_LIST* data_block_list, CLIENT_BLOCK* client_block); LIBRARY_API unsigned int countDataBlockSize(const DATA_BLOCK* data_block, CLIENT_BLOCK* client_block); -LIBRARY_API void -udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, SERVER_BLOCK server_block, - unsigned int total_datablock_size); +LIBRARY_API void udaAccessLog(int init, CLIENT_BLOCK client_block, REQUEST_BLOCK request_block, + SERVER_BLOCK server_block, unsigned int total_datablock_size); #ifdef __cplusplus } diff --git a/source/logging/fileLogging.cpp b/source/logging/fileLogging.cpp old mode 100755 new mode 100644 index f5b914ab..77b79834 --- a/source/logging/fileLogging.cpp +++ b/source/logging/fileLogging.cpp @@ -2,12 +2,12 @@ #include -int reopen_logs = 0; // No need to Re-Open Logs +int reopen_logs = 0; // No need to Re-Open Logs -static FILE* error_log = nullptr; -static FILE* warn_log = nullptr; -static FILE* debug_log = nullptr; -static FILE* info_log = nullptr; +static FILE* error_log = nullptr; +static FILE* warn_log = nullptr; +static FILE* debug_log = nullptr; +static FILE* info_log = nullptr; static FILE* access_log = nullptr; static LOG_LEVEL log_level = UDA_LOG_NONE; @@ -25,24 +25,41 @@ LOG_LEVEL udaGetLogLevel() static FILE* idamGetLogFile(LOG_LEVEL mode) { switch (mode) { - case UDA_LOG_ACCESS: return access_log; - case UDA_LOG_ERROR: return error_log; - case UDA_LOG_WARN: return warn_log; - case UDA_LOG_INFO: return info_log; - case UDA_LOG_DEBUG: return debug_log; - default: return nullptr; + case UDA_LOG_ACCESS: + return access_log; + case UDA_LOG_ERROR: + return error_log; + case UDA_LOG_WARN: + return warn_log; + case UDA_LOG_INFO: + return info_log; + case UDA_LOG_DEBUG: + return debug_log; + default: + return nullptr; } } void udaSetLogFile(LOG_LEVEL mode, FILE* file) { switch (mode) { - case UDA_LOG_ACCESS: access_log = file; break; - case UDA_LOG_ERROR: error_log = file; break; - case UDA_LOG_WARN: warn_log = file; break; - case UDA_LOG_INFO: info_log = file; break; - case UDA_LOG_DEBUG: debug_log = file; break; - default: return; // do nothing + case UDA_LOG_ACCESS: + access_log = file; + break; + case UDA_LOG_ERROR: + error_log = file; + break; + case UDA_LOG_WARN: + warn_log = file; + break; + case UDA_LOG_INFO: + info_log = file; + break; + case UDA_LOG_DEBUG: + debug_log = file; + break; + default: + return; // do nothing } } @@ -56,7 +73,7 @@ void udaLogWithFunc(LOG_LEVEL mode, logFunc func) } } -void udaLog(LOG_LEVEL mode, const char * fmt, ...) +void udaLog(LOG_LEVEL mode, const char* fmt, ...) { va_list args; va_start(args, fmt); @@ -85,7 +102,8 @@ void udaCloseLogging() if (debug_log != nullptr && debug_log != warn_log && debug_log != error_log && debug_log != access_log) { fclose(debug_log); } - if (info_log != nullptr && info_log != debug_log && info_log != warn_log && info_log != error_log && info_log != access_log) { + if (info_log != nullptr && info_log != debug_log && info_log != warn_log && info_log != error_log && + info_log != access_log) { fclose(info_log); } diff --git a/source/logging/logging.h b/source/logging/logging.h old mode 100755 new mode 100644 index dd6743b3..78598830 --- a/source/logging/logging.h +++ b/source/logging/logging.h @@ -1,30 +1,37 @@ #ifndef UDA_LOGGING_IDAMLOG_H #define UDA_LOGGING_IDAMLOG_H +#include "export.h" #include #include -#include "export.h" #ifdef _WIN32 # define FILENAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__) # define UDA_LOG(LEVEL, FMT, ...) udaLog(LEVEL, "%s:%d >> " FMT, FILENAME, __LINE__, ##__VA_ARGS__) #else # include -# include -# include # include -# define UIX_DEFINETIME \ - struct timeval uix_tmnow = {}; \ - struct tm* uix_tm = NULL; \ - char uix_buf[30];\ - gettimeofday(&uix_tmnow, NULL); \ - uix_tm = localtime(&uix_tmnow.tv_sec); \ - strftime(uix_buf, 30, "%Y:%m:%dT%H:%M:%S", uix_tm); -# define uix_printtime() { \ - UIX_DEFINETIME \ - printf("%s.%dZ, ", uix_buf,(int32_t)uix_tmnow.tv_usec); \ - } -# define UDA_LOG(LEVEL, FMT, ...) do{ if (LEVEL >= udaGetLogLevel()) {UIX_DEFINETIME udaLog(LEVEL, "%s.%dZ, %s:%d >> " FMT, uix_buf, (int32_t)uix_tmnow.tv_usec, basename((char *)__FILE__), __LINE__, ##__VA_ARGS__); }} while(0) +# include +# include +# define UIX_DEFINETIME \ + struct timeval uix_tmnow = {}; \ + struct tm* uix_tm = NULL; \ + char uix_buf[30]; \ + gettimeofday(&uix_tmnow, NULL); \ + uix_tm = localtime(&uix_tmnow.tv_sec); \ + strftime(uix_buf, 30, "%Y:%m:%dT%H:%M:%S", uix_tm); +# define uix_printtime() \ + { \ + UIX_DEFINETIME \ + printf("%s.%dZ, ", uix_buf, (int32_t)uix_tmnow.tv_usec); \ + } +# define UDA_LOG(LEVEL, FMT, ...) \ + do { \ + if (LEVEL >= udaGetLogLevel()) { \ + UIX_DEFINETIME udaLog(LEVEL, "%s.%dZ, %s:%d >> " FMT, uix_buf, (int32_t)uix_tmnow.tv_usec, \ + basename((char*)__FILE__), __LINE__, ##__VA_ARGS__); \ + } \ + } while (0) #endif #ifdef __cplusplus @@ -40,7 +47,7 @@ typedef enum LogLevel { UDA_LOG_NONE = 6 } LOG_LEVEL; -typedef void (* logFunc)(FILE*); +typedef void (*logFunc)(FILE*); LIBRARY_API void udaSetLogLevel(LOG_LEVEL level); LIBRARY_API LOG_LEVEL udaGetLogLevel(); diff --git a/source/logging/sysLogging.cpp b/source/logging/sysLogging.cpp old mode 100755 new mode 100644 index 4f66955a..ae5c3d12 --- a/source/logging/sysLogging.cpp +++ b/source/logging/sysLogging.cpp @@ -1,12 +1,12 @@ #include "logging.h" -#include -#include #include +#include +#include static LOG_LEVEL log_level = UDA_LOG_NONE; -int reopen_logs = 0; // No need to Re-Open Logs +int reopen_logs = 0; // No need to Re-Open Logs void udaSetLogLevel(LOG_LEVEL level) { @@ -31,12 +31,18 @@ void udaSetLogFile(LOG_LEVEL mode, FILE* file) static int syslogPriority(LOG_LEVEL log_mode) { switch (log_mode) { - case UDA_LOG_ACCESS: return LOG_ALERT; - case UDA_LOG_ERROR: return LOG_ERR; - case UDA_LOG_WARN: return LOG_WARNING; - case UDA_LOG_INFO: return LOG_INFO; - case UDA_LOG_DEBUG: return LOG_DEBUG; - default: return LOG_EMERG; + case UDA_LOG_ACCESS: + return LOG_ALERT; + case UDA_LOG_ERROR: + return LOG_ERR; + case UDA_LOG_WARN: + return LOG_WARNING; + case UDA_LOG_INFO: + return LOG_INFO; + case UDA_LOG_DEBUG: + return LOG_DEBUG; + default: + return LOG_EMERG; } } diff --git a/source/plugins/bytes/bytesPlugin.cpp b/source/plugins/bytes/bytesPlugin.cpp index 4b849375..b713b245 100644 --- a/source/plugins/bytes/bytesPlugin.cpp +++ b/source/plugins/bytes/bytesPlugin.cpp @@ -1,17 +1,18 @@ #include "bytesPlugin.h" -#include -#include -#include -#include #include "logging/logging.h" +#include +#include +#include +#include #include #include "readBytesNonOptimally.h" -class BytesPlugin : public UDAPluginBase { -public: +class BytesPlugin : public UDAPluginBase +{ + public: BytesPlugin(); int read(IDAM_PLUGIN_INTERFACE* plugin_interface); void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} @@ -19,12 +20,7 @@ class BytesPlugin : public UDAPluginBase { }; BytesPlugin::BytesPlugin() - : UDAPluginBase( - "BYTES", - 1, - "read", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("BYTES", 1, "read", boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("read", static_cast(&BytesPlugin::read)); } diff --git a/source/plugins/bytes/bytesPlugin.h b/source/plugins/bytes/bytesPlugin.h index 800020c7..510eb18a 100644 --- a/source/plugins/bytes/bytesPlugin.h +++ b/source/plugins/bytes/bytesPlugin.h @@ -1,18 +1,18 @@ #ifndef UDA_PLUGIN_BYTESPLUGIN_H #define UDA_PLUGIN_BYTESPLUGIN_H -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! -#define THISPLUGIN_DEFAULT_METHOD "help" +#define THISPLUGIN_VERSION 1 +#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(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/bytes/md5Sum.cpp b/source/plugins/bytes/md5Sum.cpp old mode 100755 new mode 100644 index 5a778bf1..93c8ade9 --- a/source/plugins/bytes/md5Sum.cpp +++ b/source/plugins/bytes/md5Sum.cpp @@ -1,46 +1,48 @@ /*--------------------------------------------------------------- -* Returns an MD5 Checksum String for a Block of Bytes in Memory -* -* Input Arguments: char *bp Pointer to a Block of Memory -* int size Size of the Memory block in Bytes -* -* Returns: md5check checksum String of Minimum Length 2*MD5_SIZE+1 -* allocated in the calling routine, e.g., -* char md5check[2*MD5_SIZE+1]=""; -* -* Calls -* -* Notes: -* -* ToDo: -* -*-----------------------------------------------------------------------------*/ + * Returns an MD5 Checksum String for a Block of Bytes in Memory + * + * Input Arguments: char *bp Pointer to a Block of Memory + * int size Size of the Memory block in Bytes + * + * Returns: md5check checksum String of Minimum Length 2*MD5_SIZE+1 + * allocated in the calling routine, e.g., + * char md5check[2*MD5_SIZE+1]=""; + * + * Calls + * + * Notes: + * + * ToDo: + * + *-----------------------------------------------------------------------------*/ #include "md5Sum.h" #include #ifdef MD5SUM -# include # include +# include -void md5Sum(char *bp, int size, char *md5check) { - unsigned char signature[MD5_SIZE]=""; +void md5Sum(char* bp, int size, char* md5check) +{ + unsigned char signature[MD5_SIZE] = ""; MD5_CTX context; MD5_Init(&context); MD5_Update(&context, bp, size); MD5_Final(signature, &context); - md5check[2*MD5_SIZE]='\0'; + md5check[2 * MD5_SIZE] = '\0'; - for(i=0; i #include -#include +#include "initStructs.h" +#include "udaTypes.h" #include #include +#include #include -#include "udaTypes.h" -#include "initStructs.h" -#define BYTEFILEDOESNOTEXIST 100001 -#define BYTEFILEATTRIBUTEERROR 100002 -#define BYTEFILEISNOTREGULAR 100003 -#define BYTEFILEOPENERROR 100004 -#define BYTEFILEHEAPERROR 100005 -#define BYTEFILEMD5ERROR 100006 -#define BYTEFILEMD5DIFF 100007 +#define BYTEFILEDOESNOTEXIST 100001 +#define BYTEFILEATTRIBUTEERROR 100002 +#define BYTEFILEISNOTREGULAR 100003 +#define BYTEFILEOPENERROR 100004 +#define BYTEFILEHEAPERROR 100005 +#define BYTEFILEMD5ERROR 100006 +#define BYTEFILEMD5DIFF 100007 int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) { @@ -90,7 +90,7 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) 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 + data_block->data_n = bufsize; // 1 less than no. bytes read: Last Byte is an EOF char* bp = nullptr; while (!feof(fh)) { @@ -109,7 +109,7 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) break; } - //nchar--; // Remove EOF Character from end of Byte Block + // nchar--; // Remove EOF Character from end of Byte Block data_block->data_n = nchar; data_block->data = bp; @@ -118,7 +118,7 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) md5Sum(bp, data_block->data_n, md5check); - strcpy(data_block->data_desc, md5check); // Pass back the Checksum to the Client + 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); @@ -140,7 +140,7 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) data_block->dims[0].diff = 1.0; data_block->dims[0].method = 0; - data_block->order = -1; // No Dimensions + data_block->order = -1; // No Dimensions data_block->data_type = UDA_TYPE_CHAR; } while (0); @@ -148,9 +148,9 @@ int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------- // Housekeeping -// if (err != 0) { -// freeDataBlock(data_block); -// } + // if (err != 0) { + // freeDataBlock(data_block); + // } fclose(fh); // Close the File diff --git a/source/plugins/bytes/readBytesNonOptimally.h b/source/plugins/bytes/readBytesNonOptimally.h old mode 100755 new mode 100644 index a6b41537..567b6613 --- a/source/plugins/bytes/readBytesNonOptimally.h +++ b/source/plugins/bytes/readBytesNonOptimally.h @@ -1,13 +1,12 @@ #ifndef UDA_PLUGIN_READBYTESNONOPTIMALLY_H #define UDA_PLUGIN_READBYTESNONOPTIMALLY_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" -#include #include "pluginStructs.h" +#include int readBytes(const std::string& path, IDAM_PLUGIN_INTERFACE* plugin_interface); #endif // UDA_PLUGIN_READBYTESNONOPTIMALLY_H - diff --git a/source/plugins/hdf5/hdf5plugin.cpp b/source/plugins/hdf5/hdf5plugin.cpp index 2be8044a..d18c0646 100644 --- a/source/plugins/hdf5/hdf5plugin.cpp +++ b/source/plugins/hdf5/hdf5plugin.cpp @@ -4,8 +4,9 @@ #include "readHDF58.h" -class HDF5Plugin : public UDAPluginBase { -public: +class HDF5Plugin : public UDAPluginBase +{ + public: HDF5Plugin(); int read(IDAM_PLUGIN_INTERFACE* plugin_interface); int hello(IDAM_PLUGIN_INTERFACE* plugin_interface) @@ -20,8 +21,7 @@ class HDF5Plugin : public UDAPluginBase { void reset() override {} }; -HDF5Plugin::HDF5Plugin() - : UDAPluginBase("HDF5", 1, "read", "") +HDF5Plugin::HDF5Plugin() : UDAPluginBase("HDF5", 1, "read", "") { register_method("read", static_cast(&HDF5Plugin::read)); register_method("hello", static_cast(&HDF5Plugin::hello)); @@ -40,7 +40,6 @@ extern int hdf5Plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------------------------- // Read data from a HDF5 File - int HDF5Plugin::read(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_SOURCE* data_source = plugin_interface->data_source; diff --git a/source/plugins/hdf5/hdf5plugin.h b/source/plugins/hdf5/hdf5plugin.h old mode 100755 new mode 100644 index 6a23cbb5..03aff1b5 --- a/source/plugins/hdf5/hdf5plugin.h +++ b/source/plugins/hdf5/hdf5plugin.h @@ -1,23 +1,23 @@ #ifndef UDA_PLUGIN_HDF5PLUGIN_H #define UDA_PLUGIN_HDF5PLUGIN_H -#include #include +#include #ifdef __GNUC__ # include #endif -#include -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" +#include #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 -#define THISPLUGIN_DEFAULT_METHOD "get" +#define THISPLUGIN_VERSION 1 +#define THISPLUGIN_MAX_INTERFACE_VERSION 1 +#define THISPLUGIN_DEFAULT_METHOD "get" extern UDA_PLUGIN_FILE_LIST pluginFileList; diff --git a/source/plugins/hdf5/readHDF58.cpp b/source/plugins/hdf5/readHDF58.cpp index 48dbf5e1..d4fda92a 100644 --- a/source/plugins/hdf5/readHDF58.cpp +++ b/source/plugins/hdf5/readHDF58.cpp @@ -1,23 +1,23 @@ /*--------------------------------------------------------------- -* IDAM Plugin data Reader to Access DATA from HDF5 Files -* -* Input Arguments: DATA_SOURCE data_source -* SIGNAL_DESC signal_desc -* -* Returns: readHDF5 0 if read was successful -* otherwise a Error Code is returned -* DATA_BLOCK Structure with Data from the HDF5 File -* -* Calls freeDataBlock to free Heap memory if an Error Occurs -* -* Notes: All memory required to hold data is allocated dynamically -* in heap storage. Pointers to these areas of memory are held -* by the passed DATA_BLOCK structure. Local memory allocations -* are freed on exit. However, the blocks reserved for data are -* not and MUST BE FREED by the calling routine. -* -* ToDo: BUG - seg fault occurs when a signal name without a leading / is passed -*-----------------------------------------------------------------------------*/ + * IDAM Plugin data Reader to Access DATA from HDF5 Files + * + * Input Arguments: DATA_SOURCE data_source + * SIGNAL_DESC signal_desc + * + * Returns: readHDF5 0 if read was successful + * otherwise a Error Code is returned + * DATA_BLOCK Structure with Data from the HDF5 File + * + * Calls freeDataBlock to free Heap memory if an Error Occurs + * + * Notes: All memory required to hold data is allocated dynamically + * in heap storage. Pointers to these areas of memory are held + * by the passed DATA_BLOCK structure. Local memory allocations + * are freed on exit. However, the blocks reserved for data are + * not and MUST BE FREED by the calling routine. + * + * ToDo: BUG - seg fault occurs when a signal name without a leading / is passed + *-----------------------------------------------------------------------------*/ #include "readHDF58.h" @@ -25,46 +25,45 @@ # include #endif -#include #include "udaErrors.h" +#include #ifdef NOHDF5PLUGIN -int readHDF5(DATA_SOURCE data_source, - SIGNAL_DESC signal_desc, - DATA_BLOCK *data_block) { +int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_block) +{ int err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Cannot Read HDF5 Files - PLUGIN NOT ENABLED"); return err; } -void H5Fclose(int fh) { +void H5Fclose(int fh) +{ return; } #else -#include -#include "udaTypes.h" -#include -#include -#include "initStructs.h" -#include -#include +# include "initStructs.h" +# include "udaTypes.h" +# include +# include +# include +# include +# include // #define H5TEST -#define HDF5_ERROR_OPENING_FILE 200 -#define HDF5_ERROR_IDENTIFYING_DATA_ITEM 201 -#define HDF5_ERROR_OPENING_DATASPACE 202 -#define HDF5_ERROR_ALLOCATING_DIM_HEAP 203 -#define HDF5_ERROR_ALLOCATING_DATA_HEAP 204 -#define HDF5_ERROR_READING_DATA 205 -#define HDF5_ERROR_OPENING_ATTRIBUTE 206 -#define HDF5_ERROR_NO_STORAGE_SIZE 207 -#define HDF5_ERROR_UNKNOWN_TYPE 208 -#define HDF5_ERROR_OPENING_DATASET 209 - +# define HDF5_ERROR_OPENING_FILE 200 +# define HDF5_ERROR_IDENTIFYING_DATA_ITEM 201 +# define HDF5_ERROR_OPENING_DATASPACE 202 +# define HDF5_ERROR_ALLOCATING_DIM_HEAP 203 +# define HDF5_ERROR_ALLOCATING_DATA_HEAP 204 +# define HDF5_ERROR_READING_DATA 205 +# define HDF5_ERROR_OPENING_ATTRIBUTE 206 +# define HDF5_ERROR_NO_STORAGE_SIZE 207 +# define HDF5_ERROR_UNKNOWN_TYPE 208 +# define HDF5_ERROR_OPENING_DATASET 209 //-------------------------------------------------------------------------------------------- // Identify the Data's Type @@ -104,7 +103,6 @@ int readHDF5IdamType(H5T_class_t classtype, int precision, int issigned) } } - int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_BLOCK* data_block) { H5T_class_t classtype; @@ -119,15 +117,14 @@ int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_B if ((space_id = H5Aget_space(att_id)) < 0) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5Att", err, - "Error Querying for Attribute Space Information"); + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5Att", err, "Error Querying for Attribute Space Information"); return err; } - data_block->rank = (unsigned int)H5Sget_simple_extent_dims(space_id, shape, 0); // Shape of Dimensions + data_block->rank = (unsigned int)H5Sget_simple_extent_dims(space_id, shape, 0); // Shape of Dimensions H5Sclose(space_id); - size = (int)H5Aget_storage_size(att_id); // Amount of Storage required for the Attribute + size = (int)H5Aget_storage_size(att_id); // Amount of Storage required for the Attribute if (size == 0) { err = 999; @@ -138,9 +135,9 @@ int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_B // Get the Precision and if signed datatype_id = H5Aget_type(att_id); - precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision - classtype = H5Tget_class(datatype_id); // Class - issigned = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed + precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision + classtype = H5Tget_class(datatype_id); // Class + issigned = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed H5Tclose(datatype_id); @@ -164,8 +161,7 @@ int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_B if (data == NULL) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5Att", err, - "Unable to Allocate HEAP Memory for Attribute Data"); + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5Att", err, "Unable to Allocate HEAP Memory for Attribute Data"); return err; } @@ -252,7 +248,7 @@ int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_B data_block->dims[i].dim_n = (int)shape[data_block->rank - i - 1]; data_block->dims[i].dim0 = 0; data_block->dims[i].diff = 1; - data_block->dims[i].data_type = UDA_TYPE_INT; // No Standard to enable identification of the dims + data_block->dims[i].data_type = UDA_TYPE_INT; // No Standard to enable identification of the dims data_block->dims[i].dim = NULL; strcpy(data_block->dims[i].dim_label, "array index"); data_block->dims[i].dim_units[0] = '\0'; @@ -271,10 +267,10 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ hid_t classtype; herr_t status; hsize_t shape[64]; -#ifdef H5TEST - hid_t nativetype; - int typesize = 0; -#endif +# ifdef H5TEST + hid_t nativetype; + int typesize = 0; +# endif char* data = NULL; H5O_info_t dataset_info; @@ -324,7 +320,7 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ char grpname[MAXNAME]; char attname[MAXNAME]; char dataset[MAXNAME]; - char* p = NULL, * d = NULL; + char *p = NULL, *d = NULL; strcpy(grpname, signal_desc.signal_name); p = strrchr(grpname, '/'); @@ -367,11 +363,11 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ //---------------------------------------------------------------------- // Identify the Dataset Type -#if defined(H5Oget_info_vers) && H5Oget_info_vers >= 2 +# if defined(H5Oget_info_vers) && H5Oget_info_vers >= 2 if ((status = H5Oget_info(dataset_id, &dataset_info, H5O_INFO_ALL)) < 0) { -#else +# else if ((status = H5Oget_info(dataset_id, &dataset_info)) < 0) { -#endif +# endif err = HDF5_ERROR_IDENTIFYING_DATA_ITEM; addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Error Accessing Signal Dataset Information"); break; @@ -386,88 +382,87 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ int precision = 0; bool is_signed = false; - if (dataset_type == H5O_TYPE_DATASET) { // Dataset Object + if (dataset_type == H5O_TYPE_DATASET) { // Dataset Object if ((space_id = H5Dget_space(dataset_id)) < 0) { err = HDF5_ERROR_OPENING_DATASPACE; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, - "Error Opening the Dataspace for the Dataset"); + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Error Opening the Dataspace for the Dataset"); break; } data_block->rank = (unsigned int)H5Sget_simple_extent_dims(space_id, (hsize_t*)shape, 0); - size = H5Dget_storage_size(dataset_id); // Amount of Storage required for the Data - datatype_id = H5Dget_type(dataset_id); // Identify the Data's type - precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision -#ifdef H5TEST - nativetype = H5Tget_native_type(datatype_id,H5T_DIR_ASCEND); // the Native Datatype - typesize = (int) H5Tget_size(datatype_id); // Type Size (Bytes) -#endif - classtype = H5Tget_class(datatype_id); // Class - is_signed = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed + size = H5Dget_storage_size(dataset_id); // Amount of Storage required for the Data + datatype_id = H5Dget_type(dataset_id); // Identify the Data's type + precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision +# ifdef H5TEST + nativetype = H5Tget_native_type(datatype_id, H5T_DIR_ASCEND); // the Native Datatype + typesize = (int)H5Tget_size(datatype_id); // Type Size (Bytes) +# endif + classtype = H5Tget_class(datatype_id); // Class + is_signed = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed H5Sclose(space_id); - } else { // Assume an Attribute Object + } else { // Assume an Attribute Object if ((space_id = H5Aget_space(dataset_id)) < 0) { err = HDF5_ERROR_OPENING_DATASPACE; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, - "Error Opening the Dataspace for the Attribute"); + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Error Opening the Dataspace for the Attribute"); break; } data_block->rank = (unsigned int)H5Sget_simple_extent_dims(space_id, (hsize_t*)shape, 0); - size = (int)H5Aget_storage_size(dataset_id); // Amount of Storage required for the Attribute + size = (int)H5Aget_storage_size(dataset_id); // Amount of Storage required for the Attribute datatype_id = H5Aget_type(dataset_id); - precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision -#ifdef H5TEST - nativetype = (hid_t) -1; - typesize = (int) H5Tget_size(datatype_id); // Type Size (Bytes) -#endif - classtype = H5Tget_class(datatype_id); // Class - is_signed = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed + precision = (int)H5Tget_precision(datatype_id); // Atomic Datatype's precision +# ifdef H5TEST + nativetype = (hid_t)-1; + typesize = (int)H5Tget_size(datatype_id); // Type Size (Bytes) +# endif + classtype = H5Tget_class(datatype_id); // Class + is_signed = H5Tget_sign(datatype_id) != H5T_SGN_NONE; // Whether or Not the Type is Signed H5Sclose(space_id); } -#ifdef H5TEST - fprintf(stdout,"file_id = %d\n", (int)file_id); - fprintf(stdout,"datatype_id = %d\n", (int)datatype_id); - fprintf(stdout,"rank = %d\n", data_block->rank); - fprintf(stdout,"size = %d\n", size); - fprintf(stdout,"nativetype = %d\n", nativetype); - fprintf(stdout,"precision = %d\n", precision); - fprintf(stdout,"typesize = %d\n", typesize); - fprintf(stdout,"classtype = %d\n", (int) classtype); - fprintf(stdout,"issigned = %d\n", (int) issigned); - - fprintf(stdout,"Integer Class ? %d\n", H5T_INTEGER == classtype); - fprintf(stdout,"Float Class ? %d\n", H5T_FLOAT == classtype); - fprintf(stdout,"Array Class ? %d\n", H5T_ARRAY == classtype); - fprintf(stdout,"Time Class ? %d\n", H5T_TIME == classtype); - fprintf(stdout,"String Class ? %d\n", H5T_STRING == classtype); - fprintf(stdout,"Bitfield Class ? %d\n", H5T_BITFIELD == classtype); - fprintf(stdout,"Opaque Class ? %d\n", H5T_OPAQUE == classtype); - fprintf(stdout,"Compound Class ? %d\n", H5T_COMPOUND == classtype); - fprintf(stdout,"Reference Class ?%d\n", H5T_REFERENCE == classtype); - fprintf(stdout,"Enumerated Class?%d\n", H5T_ENUM == classtype); - fprintf(stdout,"VLen Class ? %d\n", H5T_VLEN == classtype); - fprintf(stdout,"No Class ? %d\n", H5T_NO_CLASS == classtype); - - fprintf(stdout,"Native Char? %d\n", H5T_NATIVE_CHAR == nativetype); - fprintf(stdout,"Native Short? %d\n", H5T_NATIVE_SHORT == nativetype); - fprintf(stdout,"Native Int? %d\n", H5T_NATIVE_INT == nativetype); - fprintf(stdout,"Native Long? %d\n", H5T_NATIVE_LONG == nativetype); - fprintf(stdout,"Native LLong? %d\n", H5T_NATIVE_LLONG == nativetype); - fprintf(stdout,"Native UChar? %d\n", H5T_NATIVE_UCHAR == nativetype); - fprintf(stdout,"Native SChar? %d\n", H5T_NATIVE_SCHAR == nativetype); - fprintf(stdout,"Native UShort? %d\n", H5T_NATIVE_USHORT == nativetype); - fprintf(stdout,"Native UInt? %d\n", H5T_NATIVE_UINT == nativetype); - fprintf(stdout,"Native ULong? %d\n", H5T_NATIVE_ULONG == nativetype); - fprintf(stdout,"Native ULLong? %d\n", H5T_NATIVE_ULLONG == nativetype); - fprintf(stdout,"Native Float? %d\n", H5T_NATIVE_FLOAT == nativetype); - fprintf(stdout,"Native Double? %d\n", H5T_NATIVE_DOUBLE == nativetype); - fprintf(stdout,"Native LDouble? %d\n", H5T_NATIVE_LDOUBLE== nativetype); -#endif +# ifdef H5TEST + fprintf(stdout, "file_id = %d\n", (int)file_id); + fprintf(stdout, "datatype_id = %d\n", (int)datatype_id); + fprintf(stdout, "rank = %d\n", data_block->rank); + fprintf(stdout, "size = %d\n", size); + fprintf(stdout, "nativetype = %d\n", nativetype); + fprintf(stdout, "precision = %d\n", precision); + fprintf(stdout, "typesize = %d\n", typesize); + fprintf(stdout, "classtype = %d\n", (int)classtype); + fprintf(stdout, "issigned = %d\n", (int)issigned); + + fprintf(stdout, "Integer Class ? %d\n", H5T_INTEGER == classtype); + fprintf(stdout, "Float Class ? %d\n", H5T_FLOAT == classtype); + fprintf(stdout, "Array Class ? %d\n", H5T_ARRAY == classtype); + fprintf(stdout, "Time Class ? %d\n", H5T_TIME == classtype); + fprintf(stdout, "String Class ? %d\n", H5T_STRING == classtype); + fprintf(stdout, "Bitfield Class ? %d\n", H5T_BITFIELD == classtype); + fprintf(stdout, "Opaque Class ? %d\n", H5T_OPAQUE == classtype); + fprintf(stdout, "Compound Class ? %d\n", H5T_COMPOUND == classtype); + fprintf(stdout, "Reference Class ?%d\n", H5T_REFERENCE == classtype); + fprintf(stdout, "Enumerated Class?%d\n", H5T_ENUM == classtype); + fprintf(stdout, "VLen Class ? %d\n", H5T_VLEN == classtype); + fprintf(stdout, "No Class ? %d\n", H5T_NO_CLASS == classtype); + + fprintf(stdout, "Native Char? %d\n", H5T_NATIVE_CHAR == nativetype); + fprintf(stdout, "Native Short? %d\n", H5T_NATIVE_SHORT == nativetype); + fprintf(stdout, "Native Int? %d\n", H5T_NATIVE_INT == nativetype); + fprintf(stdout, "Native Long? %d\n", H5T_NATIVE_LONG == nativetype); + fprintf(stdout, "Native LLong? %d\n", H5T_NATIVE_LLONG == nativetype); + fprintf(stdout, "Native UChar? %d\n", H5T_NATIVE_UCHAR == nativetype); + fprintf(stdout, "Native SChar? %d\n", H5T_NATIVE_SCHAR == nativetype); + fprintf(stdout, "Native UShort? %d\n", H5T_NATIVE_USHORT == nativetype); + fprintf(stdout, "Native UInt? %d\n", H5T_NATIVE_UINT == nativetype); + fprintf(stdout, "Native ULong? %d\n", H5T_NATIVE_ULONG == nativetype); + fprintf(stdout, "Native ULLong? %d\n", H5T_NATIVE_ULLONG == nativetype); + fprintf(stdout, "Native Float? %d\n", H5T_NATIVE_FLOAT == nativetype); + fprintf(stdout, "Native Double? %d\n", H5T_NATIVE_DOUBLE == nativetype); + fprintf(stdout, "Native LDouble? %d\n", H5T_NATIVE_LDOUBLE == nativetype); +# endif if (size == 0) { - if (err == 0) err = HDF5_ERROR_NO_STORAGE_SIZE; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, - "No Storage Size returned for this data item"); + if (err == 0) { + err = HDF5_ERROR_NO_STORAGE_SIZE; + } + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "No Storage Size returned for this data item"); break; } @@ -477,8 +472,7 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ if (data_block->rank > 0) { if ((data_block->dims = (DIMS*)malloc(data_block->rank * sizeof(DIMS))) == NULL) { err = HDF5_ERROR_ALLOCATING_DIM_HEAP; - addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, - "Problem Allocating Dimension Heap Memory"); + addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Problem Allocating Dimension Heap Memory"); break; } } @@ -498,14 +492,14 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ data_block->dims[i].dim_n = (int)shape[data_block->rank - i - 1]; data_block->dims[i].dim0 = 0; data_block->dims[i].diff = 1; - data_block->dims[i].data_type = UDA_TYPE_INT; // No Standard to enable identification of the dims + data_block->dims[i].data_type = UDA_TYPE_INT; // No Standard to enable identification of the dims data_block->dims[i].dim = NULL; strcpy(data_block->dims[i].dim_label, "array index"); data_block->dims[i].dim_units[0] = '\0'; } } - data_block->order = -1; // Don't know the t-vector (or any other!) + data_block->order = -1; // Don't know the t-vector (or any other!) //-------------------------------------------------------------------------------------------- // Identify the Data's Type @@ -552,7 +546,6 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ err = HDF5_ERROR_UNKNOWN_TYPE; addIdamError(UDA_CODE_ERROR_TYPE, "readHDF5", err, "Unknown Data Type for this data item"); break; - } //-------------------------------------------------------------------------------------------- @@ -563,7 +556,7 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ int natt = H5Aget_num_attrs(dataset_id); { - for (int i = 0; i < natt; i++) { // Fetch Attribute Names + for (int i = 0; i < natt; i++) { // Fetch Attribute Names char att_name[STRING_LENGTH] = ""; char att_buff[STRING_LENGTH] = ""; hid_t att_id = -1; @@ -576,19 +569,25 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ H5Aread(att_id, att_type, (void*)att_buff); H5Aclose(att_id); -#ifdef H5TEST - int att_size = H5Aget_name(att_id, (size_t)STRING_LENGTH, att_name); - fprintf(stdout,"%d attribute[%d]: %s\n", i, (int)att_size, att_name); - fprintf(stdout,"%d type: %d\n", i, (int)att_type); - fprintf(stdout,"Value: %s\n", att_buff); - fprintf(stdout,"H5T_STRING ? %d\n", H5T_STRING == att_type); - fprintf(stdout,"H5T_CSET_ASCII ? %d\n", H5T_CSET_ASCII == att_type); - fprintf(stdout,"H5T_C_S1 ? %d\n", H5T_C_S1 == att_type); -#endif - - if (STR_IEQUALS(att_name, "units")) strcpy(data_block->data_units, att_buff); - if (STR_IEQUALS(att_name, "label")) strcpy(data_block->data_label, att_buff); - if (STR_IEQUALS(att_name, "description")) strcpy(data_block->data_desc, att_buff); +# ifdef H5TEST + int att_size = H5Aget_name(att_id, (size_t)STRING_LENGTH, att_name); + fprintf(stdout, "%d attribute[%d]: %s\n", i, (int)att_size, att_name); + fprintf(stdout, "%d type: %d\n", i, (int)att_type); + fprintf(stdout, "Value: %s\n", att_buff); + fprintf(stdout, "H5T_STRING ? %d\n", H5T_STRING == att_type); + fprintf(stdout, "H5T_CSET_ASCII ? %d\n", H5T_CSET_ASCII == att_type); + fprintf(stdout, "H5T_C_S1 ? %d\n", H5T_C_S1 == att_type); +# endif + + if (STR_IEQUALS(att_name, "units")) { + strcpy(data_block->data_units, att_buff); + } + if (STR_IEQUALS(att_name, "label")) { + strcpy(data_block->data_label, att_buff); + } + if (STR_IEQUALS(att_name, "description")) { + strcpy(data_block->data_desc, att_buff); + } if (strlen(data_block->data_label) == 0 && strlen(data_block->data_desc) > 0) { strcpy(data_block->data_label, data_block->data_desc); @@ -755,11 +754,21 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ //---------------------------------------------------------------------- // Housekeeping - if (datatype_id >= 0) H5Tclose(datatype_id); - if (dataset_id >= 0) H5Dclose(dataset_id); - if (space_id >= 0) H5Sclose(space_id); - if (grp_id >= 0) H5Gclose(grp_id); - if (att_id >= 0) H5Aclose(att_id); + if (datatype_id >= 0) { + H5Tclose(datatype_id); + } + if (dataset_id >= 0) { + H5Dclose(dataset_id); + } + if (space_id >= 0) { + H5Sclose(space_id); + } + if (grp_id >= 0) { + H5Gclose(grp_id); + } + if (att_id >= 0) { + H5Aclose(att_id); + } H5garbage_collect(); @@ -771,4 +780,3 @@ int readHDF5(DATA_SOURCE data_source, SIGNAL_DESC signal_desc, DATA_BLOCK* data_ } #endif - diff --git a/source/plugins/hdf5/readHDF58.h b/source/plugins/hdf5/readHDF58.h old mode 100755 new mode 100644 index ac5ac458..245d32d0 --- a/source/plugins/hdf5/readHDF58.h +++ b/source/plugins/hdf5/readHDF58.h @@ -1,8 +1,8 @@ #ifndef UDA_PLUGIN_READHDF58_H #define UDA_PLUGIN_READHDF58_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { @@ -16,18 +16,18 @@ LIBRARY_API void H5Fclose(int fh); #else -#include +# include -#define HDF5_ERROR_OPENING_FILE 200 -#define HDF5_ERROR_IDENTIFYING_DATA_ITEM 201 -#define HDF5_ERROR_OPENING_DATASPACE 202 -#define HDF5_ERROR_ALLOCATING_DIM_HEAP 203 -#define HDF5_ERROR_ALLOCATING_DATA_HEAP 204 -#define HDF5_ERROR_READING_DATA 205 -#define HDF5_ERROR_OPENING_ATTRIBUTE 206 -#define HDF5_ERROR_NO_STORAGE_SIZE 207 -#define HDF5_ERROR_UNKNOWN_TYPE 208 -#define HDF5_ERROR_OPENING_DATASET 209 +# define HDF5_ERROR_OPENING_FILE 200 +# define HDF5_ERROR_IDENTIFYING_DATA_ITEM 201 +# define HDF5_ERROR_OPENING_DATASPACE 202 +# define HDF5_ERROR_ALLOCATING_DIM_HEAP 203 +# define HDF5_ERROR_ALLOCATING_DATA_HEAP 204 +# define HDF5_ERROR_READING_DATA 205 +# define HDF5_ERROR_OPENING_ATTRIBUTE 206 +# define HDF5_ERROR_NO_STORAGE_SIZE 207 +# define HDF5_ERROR_UNKNOWN_TYPE 208 +# define HDF5_ERROR_OPENING_DATASET 209 LIBRARY_API int readHDF5IdamType(H5T_class_t classtype, int precision, int issigned); LIBRARY_API int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* attname, DATA_BLOCK* data_block); @@ -39,4 +39,3 @@ LIBRARY_API int readHDF5Att(hid_t file_id, char* object, hid_t att_id, char* att #endif #endif // UDA_PLUGIN_READHDF58_H - diff --git a/source/plugins/help/help_plugin.cpp b/source/plugins/help/help_plugin.cpp old mode 100755 new mode 100644 index c8e144b2..ffe73848 --- a/source/plugins/help/help_plugin.cpp +++ b/source/plugins/help/help_plugin.cpp @@ -1,15 +1,16 @@ #include "help_plugin.h" -#include #include +#include +#include "accessors.h" #include "initStructs.h" #include "struct.h" -#include "accessors.h" #include -class HelpPlugin : public UDAPluginBase { -public: +class HelpPlugin : public UDAPluginBase +{ + public: HelpPlugin(); int ping(IDAM_PLUGIN_INTERFACE* plugin_interface); int services(IDAM_PLUGIN_INTERFACE* plugin_interface); @@ -18,12 +19,7 @@ class HelpPlugin : public UDAPluginBase { }; HelpPlugin::HelpPlugin() - : UDAPluginBase( - "HELP", - 1, - "read", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("HELP", 1, "read", boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("ping", static_cast(&HelpPlugin::ping)); register_method("services", static_cast(&HelpPlugin::services)); @@ -40,30 +36,29 @@ int HelpPlugin::ping(IDAM_PLUGIN_INTERFACE* plugin_interface) //---------------------------------------------------------------------------------------- // Ping: Timing - struct timeval serverTime; // Local time in microseconds + struct timeval serverTime; // Local time in microseconds gettimeofday(&serverTime, nullptr); // define the returned data structure - struct HELP_PING - { - unsigned int seconds; // Server time in seconds - unsigned int microseconds; // Server time in microseconds + struct HELP_PING { + unsigned int seconds; // Server time in seconds + unsigned int microseconds; // Server time in microseconds }; typedef struct HELP_PING HELP_PING; USERDEFINEDTYPE usertype; COMPOUNDFIELD field; - initUserDefinedType(&usertype); // New structure definition + 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.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(HELP_PING); // Structure size + usertype.size = sizeof(HELP_PING); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -78,7 +73,7 @@ int HelpPlugin::ping(IDAM_PLUGIN_INTERFACE* plugin_interface) // 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 + addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(HELP_PING), "HELP_PING"); // Register data->seconds = (unsigned int)serverTime.tv_sec; data->microseconds = (unsigned int)serverTime.tv_usec; diff --git a/source/plugins/help/help_plugin.h b/source/plugins/help/help_plugin.h old mode 100755 new mode 100644 index b62bd347..26b8d597 --- a/source/plugins/help/help_plugin.h +++ b/source/plugins/help/help_plugin.h @@ -1,18 +1,18 @@ #ifndef UDA_PLUGIN_IDAMSERVERHELP_H #define UDA_PLUGIN_IDAMSERVERHELP_H -#include "pluginStructs.h" #include "export.h" +#include "pluginStructs.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 -#define THISPLUGIN_DEFAULT_METHOD "help" +#define THISPLUGIN_VERSION 1 +#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(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/keyvalue/keyvaluePlugin.cpp b/source/plugins/keyvalue/keyvaluePlugin.cpp old mode 100755 new mode 100644 index 5b64dc9e..97e4c471 --- a/source/plugins/keyvalue/keyvaluePlugin.cpp +++ b/source/plugins/keyvalue/keyvaluePlugin.cpp @@ -2,19 +2,22 @@ #include -#include #include +#include -#include #include "initStructs.h" -#include "udaTypes.h" #include "udaPlugin.h" +#include "udaTypes.h" +#include -namespace uda { -namespace keyvalue { +namespace uda +{ +namespace keyvalue +{ -class Plugin : public UDAPluginBase { -public: +class Plugin : public UDAPluginBase +{ + public: Plugin(); int write(IDAM_PLUGIN_INTERFACE* plugin_interface); int read(IDAM_PLUGIN_INTERFACE* plugin_interface); @@ -22,7 +25,7 @@ class Plugin : public UDAPluginBase { void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override; void reset() override; -private: + private: leveldb_readoptions_t* roptions_ = nullptr; leveldb_writeoptions_t* woptions_ = nullptr; leveldb_options_t* options_ = nullptr; @@ -30,20 +33,15 @@ class Plugin : public UDAPluginBase { }; Plugin::Plugin() - : UDAPluginBase( - "KEYVALUE", - 1, - "read", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("KEYVALUE", 1, "read", boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("write", static_cast(&Plugin::write)); register_method("read", static_cast(&Plugin::read)); register_method("delete", static_cast(&Plugin::del)); } -} -} +} // namespace keyvalue +} // namespace uda int keyValue(IDAM_PLUGIN_INTERFACE* plugin_interface) { diff --git a/source/plugins/keyvalue/keyvaluePlugin.h b/source/plugins/keyvalue/keyvaluePlugin.h old mode 100755 new mode 100644 index b3bc6837..425cdd8f --- a/source/plugins/keyvalue/keyvaluePlugin.h +++ b/source/plugins/keyvalue/keyvaluePlugin.h @@ -1,18 +1,18 @@ #ifndef UDA_PLUGIN_KEYVALUEPLUGIN_H #define UDA_PLUGIN_KEYVALUEPLUGIN_H -#include "pluginStructs.h" #include "export.h" +#include "pluginStructs.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! -#define THISPLUGIN_DEFAULT_METHOD "help" +#define THISPLUGIN_VERSION 1 +#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(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/managePluginFiles.cpp b/source/plugins/managePluginFiles.cpp old mode 100755 new mode 100644 index 8c6101e8..33d09f49 --- a/source/plugins/managePluginFiles.cpp +++ b/source/plugins/managePluginFiles.cpp @@ -9,11 +9,11 @@ # include #endif -#include #include +#include -#define UDA_PLUGIN_FILE_ALLOC 10 -#define MAX_OPEN_PLUGIN_FILE_DESC 50 +#define UDA_PLUGIN_FILE_ALLOC 10 +#define MAX_OPEN_PLUGIN_FILE_DESC 50 // Initialise the File List and allocate heap for the list @@ -42,11 +42,13 @@ int addIdamPluginFilePtr(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, if ((old_handle = getOpenIdamPluginFilePtr(uda_files, filename)) != nullptr) { // Is an Open File Handle already listed? - if (old_handle == handle) return 1; + if (old_handle == handle) { + return 1; + } } - if ((closed = getClosedIdamPluginFile(uda_files, filename)) >= 0) { // Does a Closed File Handle entry exist? - uda_files->files[closed].status = 1; // If so then reopen and update the record + if ((closed = getClosedIdamPluginFile(uda_files, filename)) >= 0) { // Does a Closed File Handle entry exist? + uda_files->files[closed].status = 1; // If so then reopen and update the record uda_files->files[closed].handlePtr = handle; uda_files->files[closed].handleInt = -1; gettimeofday(&uda_files->files[closed].file_open, nullptr); @@ -55,11 +57,13 @@ int addIdamPluginFilePtr(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, // New File (Close Stalest File if at maximum open handle limit) - if (uda_files->count >= MAX_OPEN_PLUGIN_FILE_DESC) purgeStalestIdamPluginFile(uda_files); + if (uda_files->count >= MAX_OPEN_PLUGIN_FILE_DESC) { + purgeStalestIdamPluginFile(uda_files); + } if (uda_files->count == uda_files->mcount || uda_files->mcount == 0) { - uda_files->files = (UDA_PLUGIN_FILE*)realloc((void*)uda_files->files, - (uda_files->count + UDA_PLUGIN_FILE_ALLOC) * sizeof(UDA_PLUGIN_FILE)); + uda_files->files = (UDA_PLUGIN_FILE*)realloc( + (void*)uda_files->files, (uda_files->count + UDA_PLUGIN_FILE_ALLOC) * sizeof(UDA_PLUGIN_FILE)); uda_files->mcount += UDA_PLUGIN_FILE_ALLOC; } uda_files->files[uda_files->count].status = 1; @@ -69,7 +73,7 @@ int addIdamPluginFilePtr(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, strcpy(uda_files->files[uda_files->count].filename, filename); gettimeofday(&uda_files->files[uda_files->count].file_open, nullptr); - (uda_files->count)++; // Count of Open File handles + (uda_files->count)++; // Count of Open File handles return 0; } @@ -80,11 +84,13 @@ int addIdamPluginFileLong(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, if ((old_handle = getOpenIdamPluginFileLong(uda_files, filename)) >= 0) { // Is an Open File Handle already listed? - if (old_handle == handle) return 1; + if (old_handle == handle) { + return 1; + } } - if ((closed = getClosedIdamPluginFile(uda_files, filename)) >= 0) { // Does a Closed File Handle entry exist? - uda_files->files[closed].status = 1; // If so then reopen and update the record + if ((closed = getClosedIdamPluginFile(uda_files, filename)) >= 0) { // Does a Closed File Handle entry exist? + uda_files->files[closed].status = 1; // If so then reopen and update the record uda_files->files[closed].handleInt = handle; uda_files->files[closed].handlePtr = nullptr; gettimeofday(&uda_files->files[closed].file_open, nullptr); @@ -93,11 +99,13 @@ int addIdamPluginFileLong(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, // New File (Close Stalest File if at maximum open handle limit) - if (uda_files->count >= MAX_OPEN_PLUGIN_FILE_DESC) purgeStalestIdamPluginFile(uda_files); + if (uda_files->count >= MAX_OPEN_PLUGIN_FILE_DESC) { + purgeStalestIdamPluginFile(uda_files); + } if (uda_files->count == uda_files->mcount || uda_files->mcount == 0) { - uda_files->files = (UDA_PLUGIN_FILE*)realloc((void*)uda_files->files, - (uda_files->count + UDA_PLUGIN_FILE_ALLOC) * sizeof(UDA_PLUGIN_FILE)); + uda_files->files = (UDA_PLUGIN_FILE*)realloc( + (void*)uda_files->files, (uda_files->count + UDA_PLUGIN_FILE_ALLOC) * sizeof(UDA_PLUGIN_FILE)); uda_files->mcount += UDA_PLUGIN_FILE_ALLOC; } uda_files->files[uda_files->count].status = 1; @@ -107,7 +115,7 @@ int addIdamPluginFileLong(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename, strcpy(uda_files->files[uda_files->count].filename, filename); gettimeofday(&uda_files->files[uda_files->count].file_open, nullptr); - (uda_files->count)++; // Count of Open File handles + (uda_files->count)++; // Count of Open File handles return 0; } @@ -118,34 +126,34 @@ void* getOpenIdamPluginFilePtr(UDA_PLUGIN_FILE_LIST* uda_files, const char* file { UDA_LOG(UDA_LOG_DEBUG, "Open File Count %d\n", uda_files->count); for (int i = 0; i < uda_files->count; i++) { - UDA_LOG(UDA_LOG_DEBUG, "Status %d, Name %s [%s]\n", - uda_files->files[i].status, uda_files->files[i].filename, filename); + UDA_LOG(UDA_LOG_DEBUG, "Status %d, Name %s [%s]\n", uda_files->files[i].status, uda_files->files[i].filename, + filename); if (uda_files->files[i].status == 1) { if (STR_IEQUALS(filename, uda_files->files[i].filename)) { - gettimeofday(&uda_files->files[i].file_open, nullptr); // Refresh Time of Last use + gettimeofday(&uda_files->files[i].file_open, nullptr); // Refresh Time of Last use return uda_files->files[i].handlePtr; } } } - return nullptr; // Not Found => Not open + return nullptr; // Not Found => Not open } long getOpenIdamPluginFileLong(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename) { UDA_LOG(UDA_LOG_DEBUG, "Open File Count %d\n", uda_files->count); for (int i = 0; i < uda_files->count; i++) { - UDA_LOG(UDA_LOG_DEBUG, "Status %d, Name %s [%s]\n", - uda_files->files[i].status, uda_files->files[i].filename, filename); + UDA_LOG(UDA_LOG_DEBUG, "Status %d, Name %s [%s]\n", uda_files->files[i].status, uda_files->files[i].filename, + filename); if (uda_files->files[i].status == 1) { if (STR_IEQUALS(filename, uda_files->files[i].filename)) { - gettimeofday(&uda_files->files[i].file_open, nullptr); // Refresh Time of Last use + gettimeofday(&uda_files->files[i].file_open, nullptr); // Refresh Time of Last use return uda_files->files[i].handleInt; } } } - return -1; // Not Found => Not open + return -1; // Not Found => Not open } // Search for a Closed File in the List @@ -153,29 +161,30 @@ long getOpenIdamPluginFileLong(UDA_PLUGIN_FILE_LIST* uda_files, const char* file int getClosedIdamPluginFile(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename) { for (int i = 0; i < uda_files->count; i++) { - if (uda_files->files[i].status == 0) { // Only check Close handle records - if (STR_IEQUALS(filename, uda_files->files[i].filename)) return i; + if (uda_files->files[i].status == 0) { // Only check Close handle records + if (STR_IEQUALS(filename, uda_files->files[i].filename)) { + return i; + } } } - return -1; // No Closed File Found + return -1; // No Closed File Found } - // Close a specific file (Ignoring returned values) void closeIdamPluginFile(UDA_PLUGIN_FILE_LIST* uda_files, const char* filename) { for (int i = 0; i < uda_files->count; i++) { - if (uda_files->files[i].status == 1) { // Only check Open handle records + if (uda_files->files[i].status == 1) { // Only check Open handle records if (STR_IEQUALS(filename, uda_files->files[i].filename)) { if (uda_files->files[i].handlePtr != nullptr) { - typedef void (* close_t)(void*); + typedef void (*close_t)(void*); auto close = (close_t)uda_files->close; if (close != nullptr) { close(uda_files->files[i].handlePtr); } } else { - typedef void (* close_t)(long); + typedef void (*close_t)(long); auto close = (close_t)uda_files->close; if (close != nullptr) { close(uda_files->files[i].handleInt); @@ -203,10 +212,10 @@ void purgeStalestIdamPluginFile(UDA_PLUGIN_FILE_LIST* uda_files) { int stalest = -1; struct timeval oldest = {}; - gettimeofday(&oldest, nullptr); // Start comparison with Present time + gettimeofday(&oldest, nullptr); // Start comparison with Present time for (int i = 0; i < uda_files->count; i++) { - if (uda_files->files[i].status == 0) { // Drop Closed Files First + if (uda_files->files[i].status == 0) { // Drop Closed Files First if (uda_files->files[i].file_open.tv_sec < oldest.tv_sec || (uda_files->files[i].file_open.tv_sec == oldest.tv_sec && uda_files->files[i].file_open.tv_usec <= oldest.tv_usec)) { @@ -216,7 +225,7 @@ void purgeStalestIdamPluginFile(UDA_PLUGIN_FILE_LIST* uda_files) } } - if (stalest < 0) { // No Closed files so choose an Open File + if (stalest < 0) { // No Closed files so choose an Open File stalest = 0; for (int i = 0; i < uda_files->count; i++) { if (uda_files->files[i].file_open.tv_sec < oldest.tv_sec || @@ -229,19 +238,19 @@ void purgeStalestIdamPluginFile(UDA_PLUGIN_FILE_LIST* uda_files) } if (stalest >= 0) { - if (uda_files->files[stalest].status == 1) { // Close the Stale File + if (uda_files->files[stalest].status == 1) { // Close the Stale File if (uda_files->files[stalest].handlePtr != nullptr) { - typedef void (* close_t)(void*); + typedef void (*close_t)(void*); auto close = (close_t)uda_files->close; close(uda_files->files[stalest].handlePtr); } else { - typedef void (* close_t)(long); + typedef void (*close_t)(long); auto close = (close_t)uda_files->close; close(uda_files->files[stalest].handleInt); } } for (int i = stalest; i < uda_files->count - 1; i++) { - uda_files->files[i] = uda_files->files[i + 1]; // Overwrite Stale Position + uda_files->files[i] = uda_files->files[i + 1]; // Overwrite Stale Position } uda_files->files[uda_files->count - 1].status = 0; uda_files->files[uda_files->count - 1].filename[0] = '\0'; diff --git a/source/plugins/managePluginFiles.h b/source/plugins/managePluginFiles.h old mode 100755 new mode 100644 index 17cc5b7d..4b9208b1 --- a/source/plugins/managePluginFiles.h +++ b/source/plugins/managePluginFiles.h @@ -1,8 +1,8 @@ #ifndef UDA_PLUGINS_MANAGEPLUGINFILES_H #define UDA_PLUGINS_MANAGEPLUGINFILES_H -#include #include "export.h" +#include #ifdef __cplusplus extern "C" { diff --git a/source/plugins/pluginUtils.cpp b/source/plugins/pluginUtils.cpp old mode 100755 new mode 100644 index e109ea42..beb16c92 --- a/source/plugins/pluginUtils.cpp +++ b/source/plugins/pluginUtils.cpp @@ -1,22 +1,20 @@ #include "pluginUtils.h" -#include #include +#include #include #ifdef __GNUC__ # include #endif -#include #include "client.h" +#include "initStructs.h" +#include "struct.h" +#include "udaErrors.h" +#include #include #include -#include "initStructs.h" +#include #include #include #include -#include "udaErrors.h" -#include "struct.h" -#include -#include - diff --git a/source/plugins/template/templatePlugin.cpp b/source/plugins/template/templatePlugin.cpp old mode 100755 new mode 100644 index 040b59e7..1487abe1 --- a/source/plugins/template/templatePlugin.cpp +++ b/source/plugins/template/templatePlugin.cpp @@ -1,33 +1,34 @@ /*--------------------------------------------------------------- -* v1 UDA Plugin Template: Standardised plugin design template, just add ... -* -* Input Arguments: IDAM_PLUGIN_INTERFACE *idam_plugin_interface -* -* Returns: 0 if the plugin functionality was successful -* otherwise a Error Code is returned -* -* Standard functionality: -* -* help a description of what this plugin does together with a list of functions available -* -* reset frees all previously allocated heap, closes file handles and resets all static parameters. -* This has the same functionality as setting the housekeeping directive in the plugin interface -* data structure to TRUE (1) -* -* init Initialise the plugin: read all required data and process. Retain staticly for -* future reference. -* -*---------------------------------------------------------------------------------------------------------------*/ + * v1 UDA Plugin Template: Standardised plugin design template, just add ... + * + * Input Arguments: IDAM_PLUGIN_INTERFACE *idam_plugin_interface + * + * Returns: 0 if the plugin functionality was successful + * otherwise a Error Code is returned + * + * Standard functionality: + * + * help a description of what this plugin does together with a list of functions available + * + * reset frees all previously allocated heap, closes file handles and resets all static parameters. + * This has the same functionality as setting the housekeeping directive in the plugin interface + * data structure to TRUE (1) + * + * init Initialise the plugin: read all required data and process. Retain staticly for + * future reference. + * + *---------------------------------------------------------------------------------------------------------------*/ #include "templatePlugin.h" -#include -#include #include "initStructs.h" +#include +#include #include -class TemplatePlugin : public UDAPluginBase { -public: +class TemplatePlugin : public UDAPluginBase +{ + public: TemplatePlugin(); int function(IDAM_PLUGIN_INTERFACE* plugin_interface); void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} @@ -35,12 +36,8 @@ class TemplatePlugin : public UDAPluginBase { }; TemplatePlugin::TemplatePlugin() - : UDAPluginBase( - "TEMPLATE", - 1, - "function", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("TEMPLATE", 1, "function", + boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("function", static_cast(&TemplatePlugin::function)); } @@ -51,10 +48,11 @@ int templatePlugin(IDAM_PLUGIN_INTERFACE* plugin_interface) return plugin.call(plugin_interface); } -namespace { +namespace +{ -template -std::string to_string(const std::vector& array) { +template std::string to_string(const std::vector& array) +{ std::string result; const char* delim = ""; for (const auto& el : array) { @@ -64,7 +62,7 @@ std::string to_string(const std::vector& array) { return result; } -} // anon namespace +} // namespace //---------------------------------------------------------------------------------------- // Add functionality here .... @@ -77,8 +75,8 @@ int TemplatePlugin::function(IDAM_PLUGIN_INTERFACE* plugin_interface) auto optional = find_arg(plugin_interface, "optional"); std::string optional_str = optional ? std::to_string(*optional) : ""; - std::string result = fmt::format("Passed args: required={}, array=[{}], optional={}", - required, to_string(array), optional_str); + 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"); diff --git a/source/plugins/template/templatePlugin.h b/source/plugins/template/templatePlugin.h old mode 100755 new mode 100644 index 1d88a346..21a226c9 --- a/source/plugins/template/templatePlugin.h +++ b/source/plugins/template/templatePlugin.h @@ -1,18 +1,18 @@ #ifndef UDA_PLUGIN_TEMPLATEPLUGIN_H #define UDA_PLUGIN_TEMPLATEPLUGIN_H -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! -#define THISPLUGIN_DEFAULT_METHOD "help" +#define THISPLUGIN_VERSION 1 +#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(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/testplugin/testplugin.cpp b/source/plugins/testplugin/testplugin.cpp old mode 100755 new mode 100644 index 06750fdf..ea2ceb0e --- a/source/plugins/testplugin/testplugin.cpp +++ b/source/plugins/testplugin/testplugin.cpp @@ -1,20 +1,20 @@ #include "testplugin.h" -#include #include +#include #include -#include +#include "accessors.h" #include "initStructs.h" #include "struct.h" -#include -#include "accessors.h" #include #include +#include +#include #include -#include #include +#include #include "teststructs.h" @@ -23,27 +23,29 @@ #endif // PUTDATAENABLED #ifdef TESTUDT -# include # include "udtc.h" +# include # include typedef int bool; -int g_IP_Version = AF_INET; // IPv4 family of addresses -int g_Socket_Type = SOCK_STREAM; // use reliable transport layer protocol with Aknowledgements (default TCP) +int g_IP_Version = AF_INET; // IPv4 family of addresses +int g_Socket_Type = SOCK_STREAM; // use reliable transport layer protocol with Aknowledgements (default TCP) -char g_Localhost[] = "192.168.16.88"; //"192.168.16.125"; //"127.0.0.1"; // "192.168.16.88"; // Client IP address (*** passed as a parameter) -int g_Server_Port = 50000; // port number (*** passed as a parameter) +char g_Localhost[] = "192.168.16.88"; //"192.168.16.125"; //"127.0.0.1"; // "192.168.16.88"; // Client IP address + //(*** passed as a parameter) +int g_Server_Port = 50000; // port number (*** passed as a parameter) -int g_TotalNum = 1000000; // Test data +int g_TotalNum = 1000000; // Test data -int tcp_connect(SYSSOCKET *ssock, int port); -int c_connect(UDTSOCKET *usock, int port); -int createUDTSocket(int *usock, int port, int rendezvous); -int createTCPSocket(SYSSOCKET *ssock, int port, bool rendezvous); +int tcp_connect(SYSSOCKET* ssock, int port); +int c_connect(UDTSOCKET* usock, int port); +int createUDTSocket(int* usock, int port, int rendezvous); +int createTCPSocket(SYSSOCKET* ssock, int port, bool rendezvous); #endif -class TestPlugin : public UDAPluginBase { -public: +class TestPlugin : public UDAPluginBase +{ + public: TestPlugin(); int test0(IDAM_PLUGIN_INTERFACE* plugin_interface); int test2(IDAM_PLUGIN_INTERFACE* plugin_interface); @@ -108,12 +110,8 @@ class TestPlugin : public UDAPluginBase { }; TestPlugin::TestPlugin() - : UDAPluginBase( - "TESTPLUGIN", - 1, - "test0", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("TESTPLUGIN", 1, "test0", + boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("test0", static_cast(&TestPlugin::test0)); register_method("test2", static_cast(&TestPlugin::test2)); @@ -159,13 +157,17 @@ TestPlugin::TestPlugin() register_method("scalartest", static_cast(&TestPlugin::scalartest)); register_method("array1dtest", static_cast(&TestPlugin::array1dtest)); register_method("call_plugin_test", static_cast(&TestPlugin::call_plugin_test)); - register_method("call_plugin_test_index", static_cast(&TestPlugin::call_plugin_test_index)); - register_method("call_plugin_test_slice", static_cast(&TestPlugin::call_plugin_test_slice)); - register_method("call_plugin_test_stride", static_cast(&TestPlugin::call_plugin_test_stride)); + register_method("call_plugin_test_index", + static_cast(&TestPlugin::call_plugin_test_index)); + register_method("call_plugin_test_slice", + static_cast(&TestPlugin::call_plugin_test_slice)); + register_method("call_plugin_test_stride", + static_cast(&TestPlugin::call_plugin_test_stride)); register_method("emptytest", static_cast(&TestPlugin::emptytest)); #ifdef CAPNP_ENABLED register_method("capnp_test", static_cast(&TestPlugin::capnp_test)); - register_method("nested_capnp_test", static_cast(&TestPlugin::nested_capnp_test)); + register_method("nested_capnp_test", + static_cast(&TestPlugin::nested_capnp_test)); register_method("long_capnp_test", static_cast(&TestPlugin::long_capnp_test)); register_method("large_capnp_test", static_cast(&TestPlugin::large_capnp_test)); #endif // CAPNP_ENABLED @@ -246,9 +248,9 @@ int TestPlugin::test2(IDAM_PLUGIN_INTERFACE* plugin_interface) // 2> An array of string pointers: each string has its own length. Memory is not contiguous. This is the normal // representation of string arrays. - // To pass back the data as a block of chars/bytes or as type STRING, model 1 must be adopted - its how the middleware operates. - // By labeling the type as STRING, we can convert the data within the client to the correct type - + // To pass back the data as a block of chars/bytes or as type STRING, model 1 must be adopted - its how the + // middleware operates. By labeling the type as STRING, we can convert the data within the client to the correct + // type // create original data using model 2 @@ -343,22 +345,21 @@ int TestPlugin::test4(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test4 - { + typedef struct Test4 { char value[56]; } TEST4; TEST4* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST4"); strcpy(usertype.source, "Test #4"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST4); // Structure size + usertype.size = sizeof(TEST4); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -368,32 +369,32 @@ int TestPlugin::test4(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: value[56]"); field.pointer = 0; field.count = 56; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); // Create Data - data = (TEST4*)malloc(sizeof(TEST4)); // Structured Data Must be a heap variable + data = (TEST4*)malloc(sizeof(TEST4)); // Structured Data Must be a heap variable strcpy(data->value, "012345678901234567890"); addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST4), "TEST4"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -415,22 +416,21 @@ int TestPlugin::test5(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test5 - { + typedef struct Test5 { char value[3][56]; } TEST5; TEST5* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST5"); strcpy(usertype.source, "Test #5"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST5); // Structure size + usertype.size = sizeof(TEST5); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -440,14 +440,14 @@ int TestPlugin::test5(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: value[3][56]"); field.pointer = 0; field.count = 3 * 56; field.rank = 2; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 56; field.shape[1] = 3; @@ -455,20 +455,20 @@ int TestPlugin::test5(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST5*)malloc(sizeof(TEST5)); // Structured Data Must be a heap variable + data = (TEST5*)malloc(sizeof(TEST5)); // Structured Data Must be a heap variable strcpy(data->value[0], "012345678901234567890"); strcpy(data->value[1], "QWERTY KEYBOARD"); strcpy(data->value[2], "MAST TOKAMAK"); addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST5), "TEST5"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -490,22 +490,21 @@ int TestPlugin::test6(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test6 - { + typedef struct Test6 { char* value; } TEST6; TEST6* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST6"); strcpy(usertype.source, "Test #6"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST6); // Structure size + usertype.size = sizeof(TEST6); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -515,7 +514,7 @@ int TestPlugin::test6(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: *value"); field.pointer = 1; @@ -528,20 +527,20 @@ int TestPlugin::test6(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST6*)malloc(sizeof(TEST6)); // Structured Data Must be a heap variable + data = (TEST6*)malloc(sizeof(TEST6)); // Structured Data Must be a heap variable data->value = (char*)malloc(56 * sizeof(char)); strcpy(data->value, "PI=3.1415927"); addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST6), "TEST6"); addMalloc(plugin_interface->logmalloclist, (void*)data->value, 1, 56 * sizeof(char), "char"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -563,22 +562,21 @@ int TestPlugin::test7(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test7 - { - char* value[3]; // 3 strings of arbitrary length + typedef struct Test7 { + char* value[3]; // 3 strings of arbitrary length } TEST7; TEST7* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST7"); strcpy(usertype.source, "Test #7"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST7); // Structure size + usertype.size = sizeof(TEST7); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -588,28 +586,28 @@ int TestPlugin::test7(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING *"); // Array of String pointers + strcpy(field.type, "STRING *"); // Array of String pointers strcpy(field.desc, "string structure element: *value[3]"); field.pointer = 0; field.count = 3; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 3; field.size = field.count * sizeof(char*); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST7*)malloc(sizeof(TEST7)); // Structured Data Must be a heap variable + data = (TEST7*)malloc(sizeof(TEST7)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST7), "TEST7"); data->value[0] = (char*)malloc(56 * sizeof(char)); @@ -624,8 +622,7 @@ int TestPlugin::test7(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(data->value[1], "QWERTY KEYBOARD"); strcpy(data->value[2], "MAST TOKAMAK"); - -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -647,22 +644,21 @@ int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test8 - { - char** value; // arbitrary number of strings of arbitrary length + typedef struct Test8 { + char** value; // arbitrary number of strings of arbitrary length } TEST8; TEST8* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST8"); strcpy(usertype.source, "Test #8"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST8); // Structure size + usertype.size = sizeof(TEST8); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -672,7 +668,7 @@ int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING *"); // Array of String pointers + strcpy(field.type, "STRING *"); // Array of String pointers strcpy(field.desc, "string structure element: **value"); field.pointer = 1; @@ -685,14 +681,14 @@ int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST8*)malloc(sizeof(TEST8)); // Structured Data Must be a heap variable + data = (TEST8*)malloc(sizeof(TEST8)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST8), "TEST8"); data->value = (char**)malloc(3 * sizeof(char*)); @@ -710,7 +706,7 @@ int TestPlugin::test8(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(data->value[1], "QWERTY KEYBOARD"); strcpy(data->value[2], "MAST TOKAMAK"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -734,7 +730,7 @@ int TestPlugin::test9(IDAM_PLUGIN_INTERFACE* plugin_interface) // Create Data - TEST9* data = (TEST9*)malloc(4 * sizeof(TEST9)); // Structured Data Must be a heap variable + TEST9* data = (TEST9*)malloc(4 * sizeof(TEST9)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 4, sizeof(TEST9), "TEST9"); { @@ -772,7 +768,7 @@ int TestPlugin::test9(IDAM_PLUGIN_INTERFACE* plugin_interface) } } -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 1; @@ -809,9 +805,9 @@ int TestPlugin::test9A(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; -// Create Data + // Create Data - TEST9A* data = (TEST9A*)malloc(4 * sizeof(TEST9A)); // Structured Data Must be a heap variable + TEST9A* data = (TEST9A*)malloc(4 * sizeof(TEST9A)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 4, sizeof(TEST9A), "TEST9A"); { @@ -880,7 +876,7 @@ int TestPlugin::test9A(IDAM_PLUGIN_INTERFACE* plugin_interface) } } -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 1; @@ -916,12 +912,12 @@ int TestPlugin::test10(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; -// Create Data + // Create Data int* data = (int*)malloc(sizeof(int)); data[0] = 7; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_INT; data_block->rank = 0; @@ -939,22 +935,21 @@ int TestPlugin::test11(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test11 - { + typedef struct Test11 { int value; } TEST11; TEST11* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST11"); strcpy(usertype.source, "Test #11"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST11); // Structure size + usertype.size = sizeof(TEST11); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -964,31 +959,31 @@ int TestPlugin::test11(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 0; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST11*)malloc(sizeof(TEST11)); // Structured Data Must be a heap variable + data = (TEST11*)malloc(sizeof(TEST11)); // Structured Data Must be a heap variable data[0].value = 11; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST11), "TEST11"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1010,22 +1005,21 @@ int TestPlugin::test12(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test12 - { + typedef struct Test12 { int value[3]; } TEST12; TEST12* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST12"); strcpy(usertype.source, "Test #12"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST12); // Structure size + usertype.size = sizeof(TEST12); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1035,33 +1029,33 @@ int TestPlugin::test12(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 0; field.count = 3; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST12*)malloc(sizeof(TEST12)); // Structured Data Must be a heap variable + data = (TEST12*)malloc(sizeof(TEST12)); // Structured Data Must be a heap variable data[0].value[0] = 10; data[0].value[1] = 11; data[0].value[2] = 12; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST12), "TEST12"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1083,22 +1077,21 @@ int TestPlugin::test13(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test13 - { + typedef struct Test13 { int value[2][3]; } TEST13; TEST13* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST13"); strcpy(usertype.source, "Test #13"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST13); // Structure size + usertype.size = sizeof(TEST13); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1108,28 +1101,28 @@ int TestPlugin::test13(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 0; field.count = 6; field.rank = 2; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 2; - field.shape[1] = 3; // Reversed ... Fortran/IDL like + field.shape[1] = 3; // Reversed ... Fortran/IDL like field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST13*)malloc(sizeof(TEST13)); // Structured Data Must be a heap variable + data = (TEST13*)malloc(sizeof(TEST13)); // Structured Data Must be a heap variable data[0].value[0][0] = 0; data[0].value[0][1] = 1; data[0].value[0][2] = 2; @@ -1138,7 +1131,7 @@ int TestPlugin::test13(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[1][2] = 12; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST13), "TEST13"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1160,22 +1153,21 @@ int TestPlugin::test14(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test14 - { + typedef struct Test14 { int* value; } TEST14; TEST14* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST14"); strcpy(usertype.source, "Test #14"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST14); // Structure size + usertype.size = sizeof(TEST14); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1185,27 +1177,27 @@ int TestPlugin::test14(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: int *value"); field.pointer = 1; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(int*); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST14*)malloc(sizeof(TEST14)); // Structured Data Must be a heap variable + data = (TEST14*)malloc(sizeof(TEST14)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST14), "TEST14"); data[0].value = (int*)malloc(sizeof(int)); @@ -1213,7 +1205,7 @@ int TestPlugin::test14(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[0] = 14; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1235,22 +1227,21 @@ int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test15 - { + typedef struct Test15 { int* value; } TEST15; TEST15* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST15"); strcpy(usertype.source, "Test #15"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST15); // Structure size + usertype.size = sizeof(TEST15); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1260,7 +1251,7 @@ int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 1; @@ -1272,14 +1263,14 @@ int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST15*)malloc(sizeof(TEST15)); // Structured Data Must be a heap variable + data = (TEST15*)malloc(sizeof(TEST15)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST15), "TEST15"); data[0].value = (int*)malloc(3 * sizeof(int)); @@ -1290,7 +1281,7 @@ int TestPlugin::test15(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[1] = 14; data[0].value[2] = 15; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1312,22 +1303,21 @@ int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test16 - { + typedef struct Test16 { int* value; } TEST16; TEST16* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST16"); strcpy(usertype.source, "Test #16"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST16); // Structure size + usertype.size = sizeof(TEST16); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1337,7 +1327,7 @@ int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 1; @@ -1349,14 +1339,14 @@ int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST16*)malloc(sizeof(TEST16)); // Structured Data Must be a heap variable + data = (TEST16*)malloc(sizeof(TEST16)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST16), "TEST16"); int* shape = (int*)malloc(2 * sizeof(int)); @@ -1374,7 +1364,7 @@ int TestPlugin::test16(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[4] = 11; data[0].value[5] = 12; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1396,22 +1386,21 @@ int TestPlugin::test18(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test18 - { + typedef struct Test18 { int value; } TEST18; TEST18* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST18"); strcpy(usertype.source, "Test #18"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST18); // Structure size + usertype.size = sizeof(TEST18); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1421,25 +1410,25 @@ int TestPlugin::test18(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_INT; - strcpy(field.type, "int"); // convert atomic type to a string label + strcpy(field.type, "int"); // convert atomic type to a string label strcpy(field.desc, "single integer structure element: value"); field.pointer = 0; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data data_block->data_n = 100000; data = (TEST18*)malloc(data_block->data_n * sizeof(TEST18)); // Structured Data Must be a heap variable @@ -1451,7 +1440,7 @@ int TestPlugin::test18(IDAM_PLUGIN_INTERFACE* plugin_interface) } addMalloc(plugin_interface->logmalloclist, (void*)data, data_block->data_n, sizeof(TEST18), "TEST18"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 1; @@ -1484,20 +1473,19 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test19A - { + typedef struct Test19A { int value; } TEST19A; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST19A"); strcpy(usertype.source, "Test #19"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST19A); // Structure size + usertype.size = sizeof(TEST19A); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1514,33 +1502,32 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); - typedef struct Test19 - { + typedef struct Test19 { int value; TEST19A vals[7]; } TEST19; TEST19* data; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST19"); strcpy(usertype.source, "Test #19"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST19); // Structure size + usertype.size = sizeof(TEST19); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -1556,14 +1543,14 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(int); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); @@ -1576,21 +1563,21 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) field.count = 7; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 7; field.size = field.count * sizeof(TEST19A); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data data_block->data_n = 3; - data = (TEST19*)malloc(data_block->data_n * sizeof(TEST19)); // Structured Data Must be a heap variable + data = (TEST19*)malloc(data_block->data_n * sizeof(TEST19)); // Structured Data Must be a heap variable { for (int i = 0; i < data_block->data_n; i++) { @@ -1602,7 +1589,7 @@ int TestPlugin::test19(IDAM_PLUGIN_INTERFACE* plugin_interface) } addMalloc(plugin_interface->logmalloclist, (void*)data, data_block->data_n, sizeof(TEST19), "TEST19"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 1; @@ -1635,12 +1622,12 @@ int TestPlugin::test20(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; -// Create Data + // Create Data short* data = (short*)malloc(sizeof(short)); data[0] = 7; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_SHORT; data_block->rank = 0; @@ -1658,22 +1645,21 @@ int TestPlugin::test21(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test21 - { + typedef struct Test21 { short value; } TEST21; TEST21* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST21"); strcpy(usertype.source, "Test #21"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST21); // Structure size + usertype.size = sizeof(TEST21); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1683,31 +1669,31 @@ int TestPlugin::test21(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "single short integer structure element: value"); field.pointer = 0; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(short); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST21*)malloc(sizeof(TEST21)); // Structured Data Must be a heap variable + data = (TEST21*)malloc(sizeof(TEST21)); // Structured Data Must be a heap variable data[0].value = 21; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST21), "TEST21"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1729,22 +1715,21 @@ int TestPlugin::test22(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test22 - { + typedef struct Test22 { short value[3]; } TEST22; TEST22* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST22"); strcpy(usertype.source, "Test #22"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST22); // Structure size + usertype.size = sizeof(TEST22); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1754,33 +1739,33 @@ int TestPlugin::test22(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "single short integer structure element: value"); field.pointer = 0; field.count = 3; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(short); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST22*)malloc(sizeof(TEST22)); // Structured Data Must be a heap variable + data = (TEST22*)malloc(sizeof(TEST22)); // Structured Data Must be a heap variable data[0].value[0] = 20; data[0].value[1] = 21; data[0].value[2] = 22; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST22), "TEST22"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1802,22 +1787,21 @@ int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test23 - { + typedef struct Test23 { short value[2][3]; } TEST23; TEST23* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST23"); strcpy(usertype.source, "Test #23"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST23); // Structure size + usertype.size = sizeof(TEST23); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1827,13 +1811,13 @@ int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short integer array: value"); field.pointer = 0; field.count = 6; field.rank = 2; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 3; field.shape[1] = 2; @@ -1841,14 +1825,14 @@ int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST23*)malloc(sizeof(TEST23)); // Structured Data Must be a heap variable + data = (TEST23*)malloc(sizeof(TEST23)); // Structured Data Must be a heap variable data[0].value[0][0] = 0; data[0].value[0][1] = 1; data[0].value[0][2] = 2; @@ -1857,7 +1841,7 @@ int TestPlugin::test23(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[1][2] = 12; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST23), "TEST23"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -1879,22 +1863,21 @@ int TestPlugin::test24(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test24 - { + typedef struct Test24 { short* value; } TEST24; TEST24* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST24"); strcpy(usertype.source, "Test #24"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST24); // Structure size + usertype.size = sizeof(TEST24); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1904,27 +1887,27 @@ int TestPlugin::test24(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short *value"); field.pointer = 1; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(short*); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); // Create Data - data = (TEST24*)malloc(sizeof(TEST24)); // Structured Data Must be a heap variable + data = (TEST24*)malloc(sizeof(TEST24)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST24), "TEST24"); data[0].value = (short*)malloc(sizeof(short)); @@ -1954,22 +1937,21 @@ int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test25 - { + typedef struct Test25 { short* value; } TEST25; TEST25* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST25"); strcpy(usertype.source, "Test #25"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST25); // Structure size + usertype.size = sizeof(TEST25); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -1979,7 +1961,7 @@ int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short *value"); field.pointer = 1; @@ -1991,14 +1973,14 @@ int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST25*)malloc(sizeof(TEST25)); // Structured Data Must be a heap variable + data = (TEST25*)malloc(sizeof(TEST25)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST25), "TEST25"); data[0].value = (short*)malloc(3 * sizeof(short)); @@ -2009,7 +1991,7 @@ int TestPlugin::test25(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[1] = 14; data[0].value[2] = 15; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -2031,22 +2013,21 @@ int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test26 - { + typedef struct Test26 { short* value; } TEST26; TEST26* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST26"); strcpy(usertype.source, "Test #26"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST26); // Structure size + usertype.size = sizeof(TEST26); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2056,7 +2037,7 @@ int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short *value"); field.pointer = 1; @@ -2068,17 +2049,17 @@ int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data Structure + // Create Data Structure - data = (TEST26*)malloc(sizeof(TEST26)); // Structured Data Must be a heap variable + data = (TEST26*)malloc(sizeof(TEST26)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST26), "TEST26"); -// Data is a compact Fortran like rank 2 array + // Data is a compact Fortran like rank 2 array data[0].value = (short*)malloc(6 * sizeof(short)); int* shape = (int*)malloc(2 * sizeof(int)); @@ -2094,7 +2075,7 @@ int TestPlugin::test26(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[4] = 24; data[0].value[5] = 25; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -2116,22 +2097,21 @@ int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test27 - { + typedef struct Test27 { short value[2][3][4]; } TEST27; TEST27* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST27"); strcpy(usertype.source, "Test #27"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST27); // Structure size + usertype.size = sizeof(TEST27); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2141,13 +2121,13 @@ int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short integer array: value"); field.pointer = 0; field.count = 24; field.rank = 3; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 4; field.shape[1] = 3; field.shape[2] = 2; @@ -2156,14 +2136,14 @@ int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - data = (TEST27*)malloc(sizeof(TEST27)); // Structured Data Must be a heap variable + data = (TEST27*)malloc(sizeof(TEST27)); // Structured Data Must be a heap variable data[0].value[0][0][0] = 0; data[0].value[0][0][1] = 1; @@ -2193,7 +2173,7 @@ int TestPlugin::test27(IDAM_PLUGIN_INTERFACE* plugin_interface) addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST27), "TEST27"); -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -2215,22 +2195,21 @@ int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test28 - { + typedef struct Test28 { short* value; } TEST28; TEST28* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST28"); strcpy(usertype.source, "Test #28"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST28); // Structure size + usertype.size = sizeof(TEST28); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2240,7 +2219,7 @@ int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) strcpy(field.name, "value"); field.atomictype = UDA_TYPE_SHORT; - strcpy(field.type, "short"); // convert atomic type to a string label + strcpy(field.type, "short"); // convert atomic type to a string label strcpy(field.desc, "short *value"); field.pointer = 1; @@ -2252,17 +2231,17 @@ int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); -// Create Data Structure + // Create Data Structure - data = (TEST28*)malloc(sizeof(TEST28)); // Structured Data Must be a heap variable + data = (TEST28*)malloc(sizeof(TEST28)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST28), "TEST28"); -// Data is a compact Fortran like rank 3 array + // Data is a compact Fortran like rank 3 array data[0].value = (short*)malloc(24 * sizeof(short)); int* shape = (int*)malloc(3 * sizeof(int)); @@ -2297,7 +2276,7 @@ int TestPlugin::test28(IDAM_PLUGIN_INTERFACE* plugin_interface) data[0].value[index++] = 122; data[0].value[index] = 123; -// Pass Data + // Pass Data data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; @@ -2319,8 +2298,7 @@ int TestPlugin::test30(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test30 - { + typedef struct Test30 { double R; double Z; } TEST30; @@ -2328,14 +2306,14 @@ int TestPlugin::test30(IDAM_PLUGIN_INTERFACE* plugin_interface) TEST30* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST30"); strcpy(usertype.source, "Test #30"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST30); // Structure size + usertype.size = sizeof(TEST30); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2357,7 +2335,7 @@ int TestPlugin::test30(IDAM_PLUGIN_INTERFACE* plugin_interface) // Create Data - data = (TEST30*)malloc(sizeof(TEST30)); // Structured Data Must be a heap variable + data = (TEST30*)malloc(sizeof(TEST30)); // Structured Data Must be a heap variable data[0].R = 1.0; data[0].Z = 2.0; addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST30), "TEST30"); @@ -2384,8 +2362,7 @@ int TestPlugin::test31(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test30 - { + typedef struct Test30 { double R; double Z; } TEST30; @@ -2393,14 +2370,14 @@ int TestPlugin::test31(IDAM_PLUGIN_INTERFACE* plugin_interface) TEST30* data; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST30"); strcpy(usertype.source, "Test #31"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST30); // Structure size + usertype.size = sizeof(TEST30); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2423,7 +2400,7 @@ int TestPlugin::test31(IDAM_PLUGIN_INTERFACE* plugin_interface) // Create Data int count = 100; - data = (TEST30*)malloc(count * sizeof(TEST30)); // Structured Data Must be a heap variable + data = (TEST30*)malloc(count * sizeof(TEST30)); // Structured Data Must be a heap variable offset = 0; @@ -2464,21 +2441,20 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test32A - { + typedef struct Test32A { double R; double Z; } TEST32A; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST32A"); strcpy(usertype.source, "Test #32"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST32A); // Structure size + usertype.size = sizeof(TEST32A); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2488,32 +2464,31 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "R", "double structure element", &offset, SCALARDOUBLE); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); defineField(&field, "Z", "double structure element", &offset, SCALARDOUBLE); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); - typedef struct Test32 - { + typedef struct Test32 { int count; TEST32A coords[100]; } TEST32; TEST32* data; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST32"); strcpy(usertype.source, "Test #32"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST32); // Structure size + usertype.size = sizeof(TEST32); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -2521,7 +2496,7 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "count", "int structure element", &offset, SCALARINT); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); @@ -2534,7 +2509,7 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) field.count = 100; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(TEST32A); @@ -2542,14 +2517,14 @@ int TestPlugin::test32(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); // Create Data data_block->data_n = 1; - data = (TEST32*)malloc(data_block->data_n * sizeof(TEST32)); // Structured Data Must be a heap variable + data = (TEST32*)malloc(data_block->data_n * sizeof(TEST32)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, data_block->data_n, sizeof(TEST32), "TEST32"); data[0].count = field.count; @@ -2581,21 +2556,20 @@ int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test33A - { + typedef struct Test33A { double R; double Z; } TEST33A; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST33A"); strcpy(usertype.source, "Test #33"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST33A); // Structure size + usertype.size = sizeof(TEST33A); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2605,32 +2579,31 @@ int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "R", "double structure element", &offset, SCALARDOUBLE); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); defineField(&field, "Z", "double structure element", &offset, SCALARDOUBLE); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); - typedef struct Test33 - { + typedef struct Test33 { int count; TEST33A* coords; } TEST33; TEST33* data; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST33"); strcpy(usertype.source, "Test #33"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST33); // Structure size + usertype.size = sizeof(TEST33); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -2638,7 +2611,7 @@ int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "count", "int structure element", &offset, SCALARINT); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); @@ -2657,14 +2630,14 @@ int TestPlugin::test33(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); // Create Data data_block->data_n = 1; - data = (TEST33*)malloc(data_block->data_n * sizeof(TEST33)); // Structured Data Must be a heap variable + data = (TEST33*)malloc(data_block->data_n * sizeof(TEST33)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, data_block->data_n, sizeof(TEST33), "TEST33"); data->count = 100; @@ -2705,21 +2678,20 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) { DATA_BLOCK* data_block = plugin_interface->data_block; - typedef struct Test33A - { + typedef struct Test33A { unsigned char* R; unsigned char* Z; } TEST33A; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST33A"); strcpy(usertype.source, "Test #33"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST33A); // Structure size + usertype.size = sizeof(TEST33A); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2732,7 +2704,7 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) field.shape = nullptr; defineField(&field, "R", "unsigned char structure element", &offset, ARRAYUCHAR); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); field.count = 1; @@ -2740,27 +2712,26 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) field.shape = nullptr; defineField(&field, "Z", "unsigned char structure element", &offset, ARRAYUCHAR); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); - typedef struct Test33 - { + typedef struct Test33 { int count; TEST33A* coords; } TEST33; TEST33* data; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST33"); strcpy(usertype.source, "Test #33"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST33); // Structure size + usertype.size = sizeof(TEST33); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -2768,7 +2739,7 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "count", "int structure element", &offset, SCALARINT); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); @@ -2787,14 +2758,14 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) field.offpad = (int)padding((size_t)offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); // Create Data data_block->data_n = 1; - data = (TEST33*)malloc(data_block->data_n * sizeof(TEST33)); // Structured Data Must be a heap variable + data = (TEST33*)malloc(data_block->data_n * sizeof(TEST33)); // Structured Data Must be a heap variable addMalloc(plugin_interface->logmalloclist, (void*)data, data_block->data_n, sizeof(TEST33), "TEST33"); data->count = 100; @@ -2822,8 +2793,8 @@ int TestPlugin::test34(IDAM_PLUGIN_INTERFACE* plugin_interface) data->coords[i].Z[j] = (unsigned char)(10 * i); } -// data->coords[i].R = 1 * i; -// data->coords[i].Z = 10 * i; + // data->coords[i].R = 1 * i; + // data->coords[i].Z = 10 * i; } // Pass Data @@ -2868,14 +2839,14 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) REQUEST_BLOCK* request_block = plugin_interface->request_block; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST40"); strcpy(usertype.source, "Test #40"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST40); // Structure size + usertype.size = sizeof(TEST40); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -2883,9 +2854,9 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) COMPOUNDFIELD field; initCompoundField(&field); -// The number of data blocks is given by: request_block->putDataBlockList.blockCount -// For this test, all blocks must be of the same type: request_block->putDataBlockList.putDataBlock[0].data_type; -// Repeat call with changing types may cause client side issues! + // The number of data blocks is given by: request_block->putDataBlockList.blockCount + // For this test, all blocks must be of the same type: request_block->putDataBlockList.putDataBlock[0].data_type; + // Repeat call with changing types may cause client side issues! UDA_LOG(UDA_LOG_DEBUG, "Number of PutData Blocks: %d\n", request_block->putDataBlockList.blockCount); @@ -2911,14 +2882,14 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) addUserDefinedType(userdefinedtypelist, usertype); - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST41"); strcpy(usertype.source, "Test #41"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST41); // Structure size + usertype.size = sizeof(TEST41); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -2934,35 +2905,37 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) field.pointer = 0; field.count = 1; field.rank = 0; - field.shape = nullptr; // Needed when rank >= 1 + field.shape = nullptr; // Needed when rank >= 1 field.size = field.count * sizeof(TEST40); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); -// Create Data + // Create Data - TEST41* data = (TEST41*) malloc(sizeof(TEST41)); - TEST40* blocks = (TEST40*) malloc(request_block->putDataBlockList.blockCount * sizeof(TEST40)); + TEST41* data = (TEST41*)malloc(sizeof(TEST41)); + TEST40* blocks = (TEST40*)malloc(request_block->putDataBlockList.blockCount * sizeof(TEST40)); - addMalloc(plugin_interface->logmalloclist, (void*) data, 1, sizeof(TEST41), "TEST41"); - addMalloc(plugin_interface->logmalloclist, (void*) blocks, request_block->putDataBlockList.blockCount, sizeof(TEST40), "TEST40"); + addMalloc(plugin_interface->logmalloclist, (void*)data, 1, sizeof(TEST41), "TEST41"); + addMalloc(plugin_interface->logmalloclist, (void*)blocks, request_block->putDataBlockList.blockCount, + sizeof(TEST40), "TEST40"); data->count = request_block->putDataBlockList.blockCount; for (int i = 0; i < request_block->putDataBlockList.blockCount; i++) { blocks[i].dataCount = request_block->putDataBlockList.putDataBlock[i].count; - blocks[i].data = (void*) request_block->putDataBlockList.putDataBlock[i].data; + blocks[i].data = (void*)request_block->putDataBlockList.putDataBlock[i].data; UDA_LOG(UDA_LOG_DEBUG, "data type : %d\n", request_block->putDataBlockList.putDataBlock[0].data_type); UDA_LOG(UDA_LOG_DEBUG, "data count: %d\n", request_block->putDataBlockList.putDataBlock[0].count); -// Data blocks already allocated and will be freed by a separate process so use addNonMalloc instead of addMalloc + // Data blocks already allocated and will be freed by a separate process so use addNonMalloc instead of + // addMalloc switch (request_block->putDataBlockList.putDataBlock[0].data_type) { case UDA_TYPE_INT: @@ -2970,7 +2943,7 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) break; case UDA_TYPE_FLOAT: addNonMalloc(blocks[i].data, blocks[i].dataCount, sizeof(float), "float"); - float* f = (float*) blocks[i].data; + float* f = (float*)blocks[i].data; break; case UDA_TYPE_DOUBLE: addNonMalloc(blocks[i].data, blocks[i].dataCount, sizeof(double), "double"); @@ -2978,12 +2951,12 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) } } -// Pass Data back + // Pass Data back data_block->data_type = UDA_TYPE_COMPOUND; data_block->rank = 0; data_block->data_n = 1; - data_block->data = (char*) data; + data_block->data = (char*)data; strcpy(data_block->data_desc, "Test of receiving passed data blocks #40"); strcpy(data_block->data_label, "Data type TEST41 with array of TEST40"); @@ -2991,14 +2964,14 @@ int TestPlugin::test40(IDAM_PLUGIN_INTERFACE* plugin_interface) data_block->opaque_type = UDA_OPAQUE_TYPE_STRUCTURES; data_block->opaque_count = 1; - data_block->opaque_block = (void*) findUserDefinedType(userdefinedtypelist, "TEST41", 0); + data_block->opaque_block = (void*)findUserDefinedType(userdefinedtypelist, "TEST41", 0); return 0; } #endif // PUTDATAENABLED //====================================================================================== -// Passing parameters into plugins using placeholders and substitution +// Passing parameters into plugins using placeholders and substitution // Shot number passed via request_block->exp_number // Placeholder values passed via request_block->tpass @@ -3043,23 +3016,22 @@ int TestPlugin::test50(IDAM_PLUGIN_INTERFACE* plugin_interface) // Returning ENUM data: Values with labels // // Unless the ENUM structures are defined when the ENUM data are accessed, the integer type cannot be pre-specified. -// A void pointer type is used as the placeholder in the structure +// A void pointer type is used as the placeholder in the structure // When the type is known the structure definition can be created with the correct type -// otherwise, an unsigned long long array can be returned as this will provide for all integer types. The application will have to deal with the type conversion. +// otherwise, an unsigned long long array can be returned as this will provide for all integer types. The application +// will have to deal with the type conversion. -typedef struct EnumMember60 -{ - char name[MAXELEMENTNAME]; // The Enumeration member name - long long value; // The value of the member +typedef struct EnumMember60 { + char name[MAXELEMENTNAME]; // The Enumeration member name + long long value; // The value of the member } ENUMMEMBER60; -typedef struct EnumList60 -{ - char name[MAXELEMENTNAME]; // The Enumeration name - int type; // The original integer base type - int count; // The number of members of this enumeration class - ENUMMEMBER60* enummember; // Array of enum members - void* arraydata; // Generalised data pointer for all integer type arrays +typedef struct EnumList60 { + char name[MAXELEMENTNAME]; // The Enumeration name + int type; // The original integer base type + int count; // The number of members of this enumeration class + ENUMMEMBER60* enummember; // Array of enum members + void* arraydata; // Generalised data pointer for all integer type arrays int arraydata_rank; int arraydata_count; int* arraydata_shape; @@ -3105,7 +3077,7 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) count = 1; int rank = 1; - int shape[] = {1}; // Shape of the shape array! + int shape[] = {1}; // Shape of the shape array! addMalloc2(plugin_interface->logmalloclist, (void*)enumlist->arraydata_shape, count, sizeof(int), "int", rank, shape); @@ -3114,13 +3086,13 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) COMPOUNDFIELD field; USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMMEMBER60"); strcpy(usertype.source, "Test #60 ENUMMEMBER structure"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMMEMBER60); // Structure size + usertype.size = sizeof(ENUMMEMBER60); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -3128,12 +3100,12 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM label"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMMEMBER60, name); @@ -3148,13 +3120,13 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) addUserDefinedType(userdefinedtypelist, usertype); - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMLIST60"); strcpy(usertype.source, "Test #60 ENUMLIST structure"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMLIST60); // Structure size + usertype.size = sizeof(ENUMLIST60); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -3162,13 +3134,13 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM name"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMLIST60, name); @@ -3195,7 +3167,7 @@ int TestPlugin::test60(IDAM_PLUGIN_INTERFACE* plugin_interface) field.rank = 0; field.shape = nullptr; field.size = sizeof(ENUMMEMBER60*); - field.offset = offsetof(ENUMLIST60, enummember); // Different to newoffset + field.offset = offsetof(ENUMLIST60, enummember); // Different to newoffset offset = field.offset + field.size; field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); @@ -3299,7 +3271,7 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) count = 1; int rank = 1; - int shape[] = {1}; // Shape of the shape array! + int shape[] = {1}; // Shape of the shape array! addMalloc2(plugin_interface->logmalloclist, (void*)enumlist->arraydata_shape, count, sizeof(int), "int", rank, shape); @@ -3308,13 +3280,13 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) COMPOUNDFIELD field; USERDEFINEDTYPELIST* userdefinedtypelist = plugin_interface->userdefinedtypelist; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMMEMBER60"); strcpy(usertype.source, "Test #61 ENUMMEMBER structure"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMMEMBER60); // Structure size + usertype.size = sizeof(ENUMMEMBER60); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -3322,12 +3294,12 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM label"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMMEMBER60, name); @@ -3342,14 +3314,13 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) addUserDefinedType(userdefinedtypelist, usertype); - - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMLIST60"); strcpy(usertype.source, "Test #61 ENUMLIST structure"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMLIST60); // Structure size + usertype.size = sizeof(ENUMLIST60); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -3357,12 +3328,12 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM name"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMLIST60, name); @@ -3389,7 +3360,7 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) field.rank = 0; field.shape = nullptr; field.size = sizeof(ENUMMEMBER60*); - field.offset = offsetof(ENUMLIST60, enummember); // Different to newoffset + field.offset = offsetof(ENUMLIST60, enummember); // Different to newoffset offset = field.offset + field.size; field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); @@ -3397,7 +3368,7 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) initCompoundField(&field); defineField(&field, "arraydata", "Data with this enumerated type", &offset, - ARRAYULONG64); // Data need to be converted to this type + ARRAYULONG64); // Data need to be converted to this type addCompoundField(&usertype, field); initCompoundField(&field); defineField(&field, "arraydata_rank", "The rank of arraydata", &offset, SCALARINT); @@ -3411,7 +3382,6 @@ int TestPlugin::test61(IDAM_PLUGIN_INTERFACE* plugin_interface) addUserDefinedType(userdefinedtypelist, usertype); - DATA_BLOCK* data_block = plugin_interface->data_block; initDataBlock(data_block); @@ -3467,9 +3437,9 @@ int TestPlugin::test62(IDAM_PLUGIN_INTERFACE* plugin_interface) addMalloc(plugin_interface->logmalloclist, (void*)enumlist->enumarray, count, sizeof(unsigned long long), "unsigned long long"); - //count = 1; - //int rank = 1; - //int shape[] = {1}; // Shape of the shape array! + // count = 1; + // int rank = 1; + // int shape[] = {1}; // Shape of the shape array! addMalloc(plugin_interface->logmalloclist, (void*)enumlist->enumarray_shape, 1, sizeof(int), "int"); DATA_BLOCK* data_block = plugin_interface->data_block; @@ -3491,7 +3461,7 @@ int TestPlugin::test62(IDAM_PLUGIN_INTERFACE* plugin_interface) changeUserDefinedTypeElementProperty(userdefinedtypelist, id, "data", "name", (void *)"arraydata"); int value = UDA_TYPE_UNSIGNED_LONG64; changeUserDefinedTypeElementProperty(userdefinedtypelist, id, "arraydata", "atomictype", (void *)&value); - changeUserDefinedTypeElementProperty(userdefinedtypelist, id, "arraydata", "type", (void *)"unsigned long long"); + changeUserDefinedTypeElementProperty(userdefinedtypelist, id, "arraydata", "type", (void *)"unsigned long long"); */ return 0; } @@ -3526,9 +3496,9 @@ int TestPlugin::plugin(IDAM_PLUGIN_INTERFACE* plugin_interface) FIND_REQUIRED_STRING_VALUE(request->nameValueList, signal); FIND_REQUIRED_STRING_VALUE(request->nameValueList, source); - if (signal != nullptr || source != nullptr) { // Identify the plugin to test + if (signal != nullptr || source != nullptr) { // Identify the plugin to test - next_plugin_interface = *plugin_interface; // New plugin interface + next_plugin_interface = *plugin_interface; // New plugin interface next_plugin_interface.request_data = &next_request; strcpy(next_request.api_delim, request->api_delim); @@ -3587,7 +3557,7 @@ int TestPlugin::errortest(IDAM_PLUGIN_INTERFACE* plugin_interface) concatUdaError(&plugin_interface->error_stack); return err; case 3: { - const char* p = "crash!"; // force a server crash! (write to read-only memory) + const char* p = "crash!"; // force a server crash! (write to read-only memory) *const_cast(p) = '*'; p = nullptr; @@ -3710,7 +3680,7 @@ int TestPlugin::capnp_test(IDAM_PLUGIN_INTERFACE* plugin_interface) data_block->data = buffer.data; data_block->dims = nullptr; data_block->data_type = UDA_TYPE_CAPNP; - + return 0; } @@ -3857,51 +3827,48 @@ int createUDTSocket(int* usock, int port, int rendezvous) if (0 != getaddrinfo(nullptr, service, &hints, &res)) { int err = 9991; - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createUDTSocket", err, - "Illegal port number or port is busy"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createUDTSocket", err, - (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createUDTSocket", err, "Illegal port number or port is busy"); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createUDTSocket", err, (char*)udt_getlasterror_desc()); return -1; } *usock = udt_socket(res->ai_family, res->ai_socktype, - res->ai_protocol); // AF_INET, SOCK_STREAM, default protocol + res->ai_protocol); // AF_INET, SOCK_STREAM, default protocol -// since we will start a lot of connections, we set the buffer size to smaller value. + // since we will start a lot of connections, we set the buffer size to smaller value. -// UDT buffer size limit (default 10MB) + // UDT buffer size limit (default 10MB) int snd_buf = 16000; int rcv_buf = 16000; udt_setsockopt(*usock, 0, UDT_UDT_SNDBUF, &snd_buf, sizeof(int)); udt_setsockopt(*usock, 0, UDT_UDT_RCVBUF, &rcv_buf, sizeof(int)); -// UDP buffer size limit (default 1MB) + // UDP buffer size limit (default 1MB) snd_buf = 8192; rcv_buf = 8192; udt_setsockopt(*usock, 0, UDT_UDP_SNDBUF, &snd_buf, sizeof(int)); udt_setsockopt(*usock, 0, UDT_UDP_RCVBUF, &rcv_buf, sizeof(int)); -// Maximum window size (packets) (default 25600) *** change with care! + // Maximum window size (packets) (default 25600) *** change with care! int fc = 16; udt_setsockopt(*usock, 0, UDT_UDT_FC, &fc, sizeof(int)); - -// Reuse an existing address or create a new one (default true) + // Reuse an existing address or create a new one (default true) bool reuse = 1; udt_setsockopt(*usock, 0, UDT_UDT_REUSEADDR, &reuse, sizeof(bool)); -// Rendezvous connection setup (default false) + // Rendezvous connection setup (default false) udt_setsockopt(*usock, 0, UDT_UDT_RENDEZVOUS, &rendezvous, sizeof(bool)); -// Bind socket to port + // Bind socket to port int err; udt_bind(*usock, res->ai_addr, res->ai_addrlen); -/* - if((err= udt_bind(*usock, res->ai_addr, res->ai_addrlen)) != UDT_SUCCESS){ - fprintf(stderr, "UDT bind: [%s]\n",udt_getlasterror_desc()); - return -1; - } -*/ + /* + if((err= udt_bind(*usock, res->ai_addr, res->ai_addrlen)) != UDT_SUCCESS){ + fprintf(stderr, "UDT bind: [%s]\n",udt_getlasterror_desc()); + return -1; + } + */ freeaddrinfo(res); return 0; } @@ -3922,10 +3889,8 @@ int createTCPSocket(SYSSOCKET* ssock, int port, bool rendezvous) if (0 != getaddrinfo(nullptr, service, &hints, &res)) { int err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, - "Illegal port number or port is busy"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, - (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, "Illegal port number or port is busy"); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, (char*)udt_getlasterror_desc()); return -1; } @@ -3934,8 +3899,7 @@ int createTCPSocket(SYSSOCKET* ssock, int port, bool rendezvous) if (bind(*ssock, res->ai_addr, res->ai_addrlen) != 0) { int err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, "Socket Bind error"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, - (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:createTCPSocket", err, (char*)udt_getlasterror_desc()); return -1; } @@ -3946,7 +3910,7 @@ int createTCPSocket(SYSSOCKET* ssock, int port, bool rendezvous) // connect conflicts with system function int c_connect(UDTSOCKET* usock, int port) { - struct addrinfo hints, * peer; + struct addrinfo hints, *peer; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; hints.ai_family = g_IP_Version; @@ -3958,7 +3922,7 @@ int c_connect(UDTSOCKET* usock, int port) if (0 != getaddrinfo(g_Localhost, buffer, &hints, &peer)) { int err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:c_connect", err, "Socket Connect error"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:c_connect", err, (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:c_connect", err, (char*)udt_getlasterror_desc()); return -1; } @@ -3970,7 +3934,7 @@ int c_connect(UDTSOCKET* usock, int port) int tcp_connect(SYSSOCKET* ssock, int port) { - struct addrinfo hints, * peer; + struct addrinfo hints, *peer; memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_flags = AI_PASSIVE; hints.ai_family = g_IP_Version; @@ -3982,7 +3946,7 @@ int tcp_connect(SYSSOCKET* ssock, int port) if (0 != getaddrinfo(g_Localhost, buffer, &hints, &peer)) { int err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:tcp_connect", err, "Socket Connect error"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:tcp_connect", err, (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:tcp_connect", err, (char*)udt_getlasterror_desc()); return -1; } @@ -4004,24 +3968,25 @@ int TestPlugin::testudt(IDAM_PLUGIN_INTERFACE* plugin_interface) { // Start a mini server loop and create a separate communiation channel with the client bye-passing the TCP socket - int client; // listening socket id + int client; // listening socket id int false = 0; int err = 0; -// Create a UDT socket without specifying the port number + // Create a UDT socket without specifying the port number - if (createUDTSocket(&client, 0, false) < 0) { ; + if (createUDTSocket(&client, 0, false) < 0) { + ; err = 9990; addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:udt", err, "Unable to create a UDT Socket"); return err; } -// Connect to the IDAM client on a specific port -// Client and server sockets are connected + // Connect to the IDAM client on a specific port + // Client and server sockets are connected c_connect(&client, g_Server_Port); -// Create data to send + // Create data to send int32_t buffer[g_TotalNum]; int32_t sum = 0; @@ -4030,7 +3995,7 @@ int TestPlugin::testudt(IDAM_PLUGIN_INTERFACE* plugin_interface) sum += buffer[i]; } -// Send the data (*** NOT Architecture independent ***) + // Send the data (*** NOT Architecture independent ***) struct timeval tm1, tm2; gettimeofday(&tm1, nullptr); @@ -4043,35 +4008,35 @@ int TestPlugin::testudt(IDAM_PLUGIN_INTERFACE* plugin_interface) tosend = g_TotalNum * sizeof(int32_t); while (tosend > 0) { - int sent = udt_send(client, (char*) buffer + g_TotalNum * sizeof(int32_t) - tosend, tosend, 0); + int sent = udt_send(client, (char*)buffer + g_TotalNum * sizeof(int32_t) - tosend, tosend, 0); if (sent < 0) { err = 9990; addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:udt", err, "Unable to Send Data"); - addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:udt", err, (char*) udt_getlasterror_desc()); + addIdamError(UDA_CODE_ERROR_TYPE, "testplugin:udt", err, (char*)udt_getlasterror_desc()); break; } tosend -= sent; } gettimeofday(&tm2, nullptr); - int dsecs = (int) (tm2.tv_sec - tm1.tv_sec); - int dmics = (int) (tm2.tv_usec - tm1.tv_usec); + int dsecs = (int)(tm2.tv_sec - tm1.tv_sec); + int dmics = (int)(tm2.tv_usec - tm1.tv_usec); buffer[0] = dsecs; buffer[1] = dmics; tosend = 2 * sizeof(int32_t); - sent = udt_send(client, (char*) buffer, tosend, 0); + sent = udt_send(client, (char*)buffer, tosend, 0); ticks = time(nullptr); snprintf(sendBuff, sizeof(sendBuff), "%.24s", ctime(&ticks)); - tosend = (int) strlen(sendBuff) + 1; + tosend = (int)strlen(sendBuff) + 1; sent = udt_send(client, sendBuff, tosend, 0); -// Close the connection + // Close the connection udt_close(client); -// Return IDAM status + // Return IDAM status initDataBlock(data_block); @@ -4079,9 +4044,9 @@ int TestPlugin::testudt(IDAM_PLUGIN_INTERFACE* plugin_interface) data_block->data_n = 1; data_block->data_type = UDA_TYPE_INT; - int* status = (int*) malloc(sizeof(int)); + int* status = (int*)malloc(sizeof(int)); status[0] = 0; - data_block->data = (char*) status; + data_block->data = (char*)status; strcpy(data_block->data_desc, "testplugins:udt status"); strcpy(data_block->data_label, ""); diff --git a/source/plugins/testplugin/testplugin.h b/source/plugins/testplugin/testplugin.h old mode 100755 new mode 100644 index b5917918..b2a2022a --- a/source/plugins/testplugin/testplugin.h +++ b/source/plugins/testplugin/testplugin.h @@ -1,14 +1,14 @@ #ifndef UDA_PLUGIN_TESTPLUGIN_TESTPLUGIN_H #define UDA_PLUGIN_TESTPLUGIN_TESTPLUGIN_H -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { #endif -int testPlugin(IDAM_PLUGIN_INTERFACE *idam_plugin_interface); +int testPlugin(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/testplugin/teststructs.cpp b/source/plugins/testplugin/teststructs.cpp index fa61ecf7..9999a12d 100644 --- a/source/plugins/testplugin/teststructs.cpp +++ b/source/plugins/testplugin/teststructs.cpp @@ -8,14 +8,14 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) USERDEFINEDTYPE* old; USERDEFINEDTYPE usertype; - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "TEST9"); strcpy(usertype.source, "Test #9"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(TEST9); // Structure size + usertype.size = sizeof(TEST9); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; int offset = 0; @@ -24,42 +24,42 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) initCompoundField(&field); strcpy(field.name, "v1"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: char [56]"); field.pointer = 0; field.count = 56; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); strcpy(field.name, "v2"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: char [3][56]"); field.pointer = 0; field.count = 3 * 56; field.rank = 2; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 56; field.shape[1] = 3; field.size = field.count * sizeof(char); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); strcpy(field.name, "v3"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "string structure element: char *"); field.pointer = 1; field.count = 1; @@ -69,30 +69,30 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); strcpy(field.name, "v4"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING *"); // Array of String pointers + strcpy(field.type, "STRING *"); // Array of String pointers strcpy(field.desc, "string structure element: char *[3]"); field.pointer = 0; field.count = 3; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = 3; field.size = field.count * sizeof(char*); field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - offset = field.offset + field.size; // Next Offset - addCompoundField(&usertype, field); // Single Structure element + offset = field.offset + field.size; // Next Offset + addCompoundField(&usertype, field); // Single Structure element initCompoundField(&field); strcpy(field.name, "v5"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING *"); // Array of String pointers + strcpy(field.type, "STRING *"); // Array of String pointers strcpy(field.desc, "string structure element: char **"); field.pointer = 1; field.count = 1; @@ -102,28 +102,28 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element USERDEFINEDTYPELIST* userdefinedtypelist = idam_plugin_interface->userdefinedtypelist; addUserDefinedType(userdefinedtypelist, usertype); UDA_LOG(UDA_LOG_DEBUG, "Type TEST9 defined\n"); - old = findUserDefinedType(userdefinedtypelist, "TEST9", 0); // Clone existing structure & modify + old = findUserDefinedType(userdefinedtypelist, "TEST9", 0); // Clone existing structure & modify copyUserDefinedType(old, &usertype); UDA_LOG(UDA_LOG_DEBUG, "Type TEST9 located\n"); strcpy(usertype.name, "TEST9A"); strcpy(usertype.source, "Test #9A"); - usertype.size = sizeof(TEST9A); // Structure size + usertype.size = sizeof(TEST9A); // Structure size offset = old->size; initCompoundField(&field); strcpy(field.name, "v6"); field.atomictype = UDA_TYPE_UNKNOWN; - strcpy(field.type, "TEST9"); // Array of String pointers + strcpy(field.type, "TEST9"); // Array of String pointers strcpy(field.desc, "string structure elements with sub structure"); field.pointer = 0; field.count = 1; @@ -133,7 +133,7 @@ void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface) field.offset = newoffset(offset, field.type); field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); - addCompoundField(&usertype, field); // Single Structure element + addCompoundField(&usertype, field); // Single Structure element addUserDefinedType(userdefinedtypelist, usertype); diff --git a/source/plugins/testplugin/teststructs.h b/source/plugins/testplugin/teststructs.h index 3e235aa7..606ef388 100644 --- a/source/plugins/testplugin/teststructs.h +++ b/source/plugins/testplugin/teststructs.h @@ -3,23 +3,21 @@ #include "pluginStructs.h" -typedef struct Test9 -{ - char v1[56]; // single fixed length string - char v2[3][56]; // 3 fixed length strings - char* v3; // single arbitrary length string - char* v4[3]; // 3 strings of arbitrary length - char** v5; // arbitrary number of strings of arbitrary length +typedef struct Test9 { + char v1[56]; // single fixed length string + char v2[3][56]; // 3 fixed length strings + char* v3; // single arbitrary length string + char* v4[3]; // 3 strings of arbitrary length + char** v5; // arbitrary number of strings of arbitrary length } TEST9; -typedef struct Test9A -{ - char v1[56]; // single fixed length string - char v2[3][56]; // 3 fixed length strings - char* v3; // single arbitrary length string - char* v4[3]; // 3 strings of arbitrary length - char** v5; // arbitrary number of strings of arbitrary length - TEST9 v6; // Sub Structure with String types +typedef struct Test9A { + char v1[56]; // single fixed length string + char v2[3][56]; // 3 fixed length strings + char* v3; // single arbitrary length string + char* v4[3]; // 3 strings of arbitrary length + char** v5; // arbitrary number of strings of arbitrary length + TEST9 v6; // Sub Structure with String types } TEST9A; void init_structure_definitions(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); diff --git a/source/plugins/uda/uda_plugin.cpp b/source/plugins/uda/uda_plugin.cpp old mode 100755 new mode 100644 index e4da789c..ccd93db8 --- a/source/plugins/uda/uda_plugin.cpp +++ b/source/plugins/uda/uda_plugin.cpp @@ -4,43 +4,41 @@ #include "accAPI.h" #include "initStructs.h" -#include #include "udaGetAPI.h" -#include #include "udaPlugin.h" -#include #include +#include +#include +#include -#include #include +#include -namespace uda::plugins::uda { +namespace uda::plugins::uda +{ -class Plugin : public UDAPluginBase { -public: +class Plugin : public UDAPluginBase +{ + public: Plugin(); - int get(IDAM_PLUGIN_INTERFACE *plugin_interface); + int get(IDAM_PLUGIN_INTERFACE* plugin_interface); - void init(IDAM_PLUGIN_INTERFACE *plugin_interface) override { + void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override + { old_host_ = getIdamServerHost(); old_port_ = getIdamServerPort(); } void reset() override {} -private: + private: std::string old_host_; int old_port_; }; Plugin::Plugin() - : UDAPluginBase( - "UDA", - 1, - "get", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("UDA", 1, "get", boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("get", static_cast(&Plugin::get)); } @@ -62,31 +60,31 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) typedef struct OldClientBlock { int version; - int pid; // Client Application process id - char uid[STRING_LENGTH]; // Who the Client is + int pid; // Client Application process id + char uid[STRING_LENGTH]; // Who the Client is // Server properties set by the client - int timeout; // Server Shutdown after this time (minutes) if no data request - int compressDim; // Enable Compression of the Dimensional Data? + int timeout; // Server Shutdown after this time (minutes) if no data request + int compressDim; // Enable Compression of the Dimensional Data? - unsigned int clientFlags; // client defined properties passed via bit flags - int altRank; // Specify the rank of the alternative signal/source to be used + unsigned int clientFlags; // client defined properties passed via bit flags + int altRank; // Specify the rank of the alternative signal/source to be used - int get_nodimdata; // Don't send Dimensional Data: Send an index only. - int get_timedble; // Return Time Dimension Data in Double Precision if originally compressed - int get_dimdble; // Return all Dimensional Data in Double Precision - int get_datadble; // Return Data in Double Precision + int get_nodimdata; // Don't send Dimensional Data: Send an index only. + int get_timedble; // Return Time Dimension Data in Double Precision if originally compressed + int get_dimdble; // Return all Dimensional Data in Double Precision + int get_datadble; // Return Data in Double Precision - int get_bad; // Return Only Data with Bad Status value - int get_meta; // Return Meta Data associated with Signal - int get_asis; // Return data as Stored in data Archive - int get_uncal; // Disable Calibration Correction - int get_notoff; // Disable Timing Offset Correction - int get_scalar; // Reduce rank from 1 to 0 (Scalar) if dimensional data are all zero - int get_bytes; // Return Data as Bytes or Integers without applying the signal's ADC Calibration Data + int get_bad; // Return Only Data with Bad Status value + int get_meta; // Return Meta Data associated with Signal + int get_asis; // Return data as Stored in data Archive + int get_uncal; // Disable Calibration Correction + int get_notoff; // Disable Timing Offset Correction + int get_scalar; // Reduce rank from 1 to 0 (Scalar) if dimensional data are all zero + int get_bytes; // Return Data as Bytes or Integers without applying the signal's ADC Calibration Data - unsigned int privateFlags; // set of private flags used to communicate server to server + unsigned int privateFlags; // set of private flags used to communicate server to server } OLD_CLIENT_BLOCK; @@ -100,17 +98,17 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) int data_type; int error_type; - int error_model; // Identify the Error Model - int errasymmetry; // Flags whether or not error data are asymmetrical - int error_param_n; // the Number of Model Parameters + int error_model; // Identify the Error Model + int errasymmetry; // Flags whether or not error data are asymmetrical + int error_param_n; // the Number of Model Parameters int data_n; char* data; - char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling + char* synthetic; // Synthetic Data Array used in Client Side Error/Monte-Carlo Modelling - char* errhi; // Error Array (Errors above the line: data + error) - char* errlo; // Error Array (Errors below the line: data - error) - float errparams[MAXERRPARAMS]; // the array of model parameters + char* errhi; // Error Array (Errors above the line: data + error) + char* errlo; // Error Array (Errors below the line: data - error) + float errparams[MAXERRPARAMS]; // the array of model parameters char data_units[STRING_LENGTH]; char data_label[STRING_LENGTH]; @@ -125,30 +123,30 @@ int uda::plugins::uda::Plugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) SIGNAL* signal_rec; SIGNAL_DESC* signal_desc; - OLD_CLIENT_BLOCK client_block; // Used to pass properties into legacy data reader plugins - ignore! + OLD_CLIENT_BLOCK client_block; // Used to pass properties into legacy data reader plugins - ignore! - int opaque_type; // Identifies the Data Structure Type; - int opaque_count; // Number of Instances of the Data Structure; - void* opaque_block; // Opaque pointer to Hierarchical Data Structures + int opaque_type; // Identifies the Data Structure Type; + int opaque_count; // Number of Instances of the Data Structure; + void* opaque_block; // Opaque pointer to Hierarchical Data Structures } OLD_DATA_BLOCK; int handle = 0; int newPort = 0; -/* ---------------------------------------------------------------------- -Notes: there are three pathways depending on the request pattern + /* ---------------------------------------------------------------------- + Notes: there are three pathways depending on the request pattern -1> request is the result of an SQL query against the metadata catalog - if the primary key fields of the data_source and signal_desc structures are non zero -2> request is a device redirect or a server protocol - path = server:port/source, server="" -3> request is a function call - path = "", name-value pair arguments, server="" -4> request is a server call - server=server:port, path=source -*/ + 1> request is the result of an SQL query against the metadata catalog + if the primary key fields of the data_source and signal_desc structures are non zero + 2> request is a device redirect or a server protocol + path = server:port/source, server="" + 3> request is a function call + path = "", name-value pair arguments, server="" + 4> request is a server call + server=server:port, path=source + */ -// Identify execution pathway + // Identify execution pathway int pathway = 0; @@ -178,7 +176,7 @@ Notes: there are three pathways depending on the request pattern // This fails if the legacy UDA plugin is called by a server in the forward chain and it set marked a 'private' // For IMAS development, this has been disabled - //if(environment.external_user) setIdamPrivateFlag(PRIVATEFLAG_EXTERNAL); // Maintain external user status + // if(environment.external_user) setIdamPrivateFlag(PRIVATEFLAG_EXTERNAL); // Maintain external user status // Set Userid @@ -189,18 +187,40 @@ Notes: there are three pathways depending on the request pattern CLIENT_BLOCK* client_block = plugin_interface->client_block; auto client_flags = udaClientFlags(); - if (client_block->get_nodimdata) setIdamProperty("get_nodimdata", client_flags); - if (client_block->get_timedble) setIdamProperty("get_timedble", client_flags); - if (client_block->get_dimdble) setIdamProperty("get_dimdble", client_flags); - if (client_block->get_datadble) setIdamProperty("get_datadble", client_flags); + if (client_block->get_nodimdata) { + setIdamProperty("get_nodimdata", client_flags); + } + if (client_block->get_timedble) { + setIdamProperty("get_timedble", client_flags); + } + if (client_block->get_dimdble) { + setIdamProperty("get_dimdble", client_flags); + } + if (client_block->get_datadble) { + setIdamProperty("get_datadble", client_flags); + } - if (client_block->get_bad) setIdamProperty("get_bad", client_flags); - if (client_block->get_meta) setIdamProperty("get_meta", client_flags); - if (client_block->get_asis) setIdamProperty("get_asis", client_flags); - if (client_block->get_uncal) setIdamProperty("get_uncal", client_flags); - if (client_block->get_notoff) setIdamProperty("get_notoff", client_flags); - if (client_block->get_scalar) setIdamProperty("get_scalar", client_flags); - if (client_block->get_bytes) setIdamProperty("get_bytes", client_flags); + if (client_block->get_bad) { + setIdamProperty("get_bad", client_flags); + } + if (client_block->get_meta) { + setIdamProperty("get_meta", client_flags); + } + if (client_block->get_asis) { + setIdamProperty("get_asis", client_flags); + } + if (client_block->get_uncal) { + setIdamProperty("get_uncal", client_flags); + } + if (client_block->get_notoff) { + setIdamProperty("get_notoff", client_flags); + } + if (client_block->get_scalar) { + setIdamProperty("get_scalar", client_flags); + } + if (client_block->get_bytes) { + setIdamProperty("get_bytes", client_flags); + } // Timeout ... @@ -213,8 +233,8 @@ Notes: there are three pathways depending on the request pattern // Client application provenance - //putIdamClientDOI(client_block->DOI); - //putIdamClientOSName(client_block->OSName); + // putIdamClientDOI(client_block->DOI); + // putIdamClientOSName(client_block->OSName); // Client authentication x509 certificate @@ -223,7 +243,7 @@ Notes: there are three pathways depending on the request pattern // Very primitive: Need to replicate fully the idamGetAPI arguments from the database - if (pathway == 1) { // Request via the Database + if (pathway == 1) { // Request via the Database std::string signal; std::string source; @@ -232,7 +252,7 @@ Notes: there are three pathways depending on the request pattern source = fmt::format("{}::{}", data_source->device_name, data_source->exp_number); if (data_source->server[0] != '\0') { - char* p = nullptr, * s = nullptr; + char *p = nullptr, *s = nullptr; if ((s = strstr(data_source->server, "SSL://")) != nullptr) { if ((p = strstr(s + 6, ":")) == nullptr) { // look for a port number in the server name @@ -258,7 +278,8 @@ Notes: there are three pathways depending on the request pattern old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the formats 'server:port' or 'server port'"); + error("The Server Port must be an Integer Number passed using the formats 'server:port' or 'server " + "port'"); } } else { if (strcasecmp(old_host_.c_str(), data_source->server) != 0) { @@ -285,24 +306,26 @@ Notes: there are three pathways depending on the request pattern //---------------------------------------------------------------------- // Device redirect or server protocol - strcpy(request->server, request->path); // Extract the Server Name and Port - char* p = nullptr, * s = nullptr; + strcpy(request->server, request->path); // Extract the Server Name and Port + char *p = nullptr, *s = nullptr; if ((s = strstr(data_source->server, "SSL://")) != nullptr) { if ((p = strchr(s + 6, '/')) != nullptr) { // Isolate the Server from the source server:port/source - p[0] = '\0'; // Break the String (work) - strcpy(source, p + 1); // Extract the Source URL Argument + 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: serverHost:port/sourceURL"); + error("The Remote Server Data Source specified does not comply with the naming model: " + "serverHost:port/sourceURL"); } } else { if ((p = strchr(request->server, '/')) != nullptr) { // Isolate the Server from the source server:port/source - p[0] = '\0'; // Break the String (work) - strcpy(source, p + 1); // Extract the Source URL Argument + 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: serverHost:port/sourceURL"); + error("The Remote Server Data Source specified does not comply with the naming model: " + "serverHost:port/sourceURL"); } } @@ -322,7 +345,7 @@ Notes: there are three pathways depending on the request pattern p[0] = '\0'; if (strcasecmp(old_host_.c_str(), request->server) != 0) { old_host_ = request->server; - putIdamServerHost(request->server); // different host name? + putIdamServerHost(request->server); // different host name? } if (IsNumber(&p[1])) { newPort = atoi(&p[1]); @@ -331,7 +354,8 @@ Notes: there are three pathways depending on the request pattern old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server port'"); + error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server " + "port'"); } } else { if (strcasecmp(old_host_.c_str(), request->server) != 0) { @@ -397,7 +421,7 @@ Notes: there are three pathways depending on the request pattern //---------------------------------------------------------------------- // Server protocol - strcpy(source, request->file); // The Source URL Argument + strcpy(source, request->file); // The Source URL Argument char* p = nullptr; char* s = nullptr; @@ -414,11 +438,11 @@ Notes: there are three pathways depending on the request pattern } } - if (p != nullptr) { // look for a port number in the server name - p[0] = '\0'; // Split - if (strcasecmp(old_host_.c_str(), request->server) != 0) { // Different Hosts? + if (p != nullptr) { // look for a port number in the server name + p[0] = '\0'; // Split + if (strcasecmp(old_host_.c_str(), request->server) != 0) { // Different Hosts? old_host_ = request->server; - putIdamServerHost(request->server); // Change to a different host name + putIdamServerHost(request->server); // Change to a different host name } if (IsNumber(&p[1])) { newPort = atoi(&p[1]); @@ -428,11 +452,12 @@ Notes: there are three pathways depending on the request pattern old_port_ = newPort; } } else { - error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server port'"); + error("The Server Port must be an Integer Number passed using the format 'server:port' or 'server " + "port'"); } } else { // No port number passed - if (strcasecmp(old_host_.c_str(), request->server) != 0) { // Different Hosts? + if (strcasecmp(old_host_.c_str(), request->server) != 0) { // Different Hosts? old_host_ = request->server; putIdamServerHost(request->server); } @@ -453,8 +478,7 @@ Notes: there are three pathways depending on the request pattern //---------------------------------------------------------------------- // Test for Errors: Close Socket and Free heap - debug("Returned from idamGetAPI API: handle = {}, error code = {}\n", handle, - getIdamErrorCode(handle)); + debug("Returned from idamGetAPI API: handle = {}, error code = {}\n", handle, getIdamErrorCode(handle)); if (handle < 0) { error(getIdamServerErrorStackRecordMsg(0)); @@ -478,7 +502,7 @@ Notes: there are three pathways depending on the request pattern if (getIdamClientVersion() >= 7) { // This should contain everything! *data_block = *getIdamDataBlock(handle); - } else { // use abstraction functions + } else { // use abstraction functions // Straight structure mapping causes potential problems when the client library uses different versions // of the DATA_BLOCK structure @@ -520,7 +544,7 @@ Notes: there are three pathways depending on the request pattern strcpy(db.data_desc, odb->data_desc); strcpy(db.error_msg, odb->error_msg); - db.dims = odb->dims; // These have not changed between versions 6 & 7 + db.dims = odb->dims; // These have not changed between versions 6 & 7 db.data_system = odb->data_system; db.system_config = odb->system_config; db.data_source = odb->data_source; @@ -557,20 +581,18 @@ Notes: there are three pathways depending on the request pattern // Required if http is to be adopted as middleware protocol // Relay everything from the external server back to the client without interpretation. // - // Namespace issues: Both the Client and the Server use the same functions to Query. The PRE_LOAD requirement of MDS+ - // causes the UDA client library to be loaded ahead of the server library: Result confusion and seg fault errors. - // Need to add unique name component to UDA client server to provide namespace separation. - // Prepare a reduced set of external symbols for the client library attached to the server! + // Namespace issues: Both the Client and the Server use the same functions to Query. The PRE_LOAD requirement of + // MDS+ causes the UDA client library to be loaded ahead of the server library: Result confusion and seg fault + // errors. Need to add unique name component to UDA client server to provide namespace separation. Prepare a reduced + // set of external symbols for the client library attached to the server! // Structured data are best served as serialised objects - no messy heap logs to free // Data should be freed with a 'reset' method call after the data have been transmitted // Add a new 'freeImmediate' plugin property that causes a heap free without other state changes, e.g. socket - // Problem tests: 115, 118, 124, 141, 142 //---------------------------------------------------------------------- return err; } - diff --git a/source/plugins/uda/uda_plugin.h b/source/plugins/uda/uda_plugin.h old mode 100755 new mode 100644 index 1a8b8c22..72cf965c --- a/source/plugins/uda/uda_plugin.h +++ b/source/plugins/uda/uda_plugin.h @@ -1,18 +1,18 @@ #ifndef UDA_PLUGIN_UDA_PLUGIN_H #define UDA_PLUGIN_UDA_PLUGIN_H -#include "pluginStructs.h" #include "export.h" +#include "pluginStructs.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! -#define THISPLUGIN_DEFAULT_METHOD "help" +#define THISPLUGIN_VERSION 1 +#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(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/plugins/udaPlugin.cpp b/source/plugins/udaPlugin.cpp index 88e673e3..3b2e4bbd 100644 --- a/source/plugins/udaPlugin.cpp +++ b/source/plugins/udaPlugin.cpp @@ -1,16 +1,16 @@ #include "udaPlugin.h" #include "server/initPluginList.h" #include "server/serverPlugin.h" -#include "struct.h" #include "server/serverSubsetData.h" +#include "struct.h" -#include -#include -#include -#include -#include "logging/logging.h" #include "initStructs.h" +#include "logging/logging.h" #include "udaTypes.h" +#include +#include +#include +#include IDAM_PLUGIN_INTERFACE* udaCreatePluginInterface(const char* request) { @@ -137,8 +137,8 @@ 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, const char* description) +int setReturnDataIntArray(DATA_BLOCK* data_block, int* values, size_t rank, const size_t* shape, + const char* description) { initDataBlock(data_block); @@ -306,7 +306,8 @@ 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, const char* description) +int setReturnData(DATA_BLOCK* data_block, void* value, size_t size, UDA_TYPE type, int rank, const int* shape, + const char* description) { initDataBlock(data_block); @@ -350,7 +351,9 @@ int setReturnData(DATA_BLOCK* data_block, void* value, size_t size, UDA_TYPE typ 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; + if (plugin_list->plugin[i].request == request) { + return i; + } } return -1; } @@ -364,7 +367,9 @@ int findPluginIdByRequest(int request, const PLUGINLIST* plugin_list) 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; + if (STR_IEQUALS(plugin_list->plugin[i].format, format)) { + return i; + } } return -1; } @@ -378,7 +383,8 @@ int findPluginIdByFormat(const char* format, const PLUGINLIST* plugin_list) 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)) { + if (plugin_list->plugin[i].plugin_class == UDA_PLUGIN_CLASS_DEVICE && + STR_IEQUALS(plugin_list->plugin[i].format, device)) { return i; } } @@ -630,7 +636,7 @@ int callPlugin(const PLUGINLIST* pluginlist, const char* signal, const IDAM_PLUG int id = findPluginIdByRequest(request.request, pluginlist); PLUGIN_DATA* plugin = &(pluginlist->plugin[id]); if (id >= 0 && plugin->idamPlugin != nullptr) { - err = plugin->idamPlugin(&idam_plugin_interface); // Call the data reader + err = plugin->idamPlugin(&idam_plugin_interface); // Call the data reader } else { RAISE_PLUGIN_ERROR("Data Access is not available for this data request!"); } diff --git a/source/plugins/udaPluginFiles.h b/source/plugins/udaPluginFiles.h old mode 100755 new mode 100644 index 34f31af6..7832f984 --- a/source/plugins/udaPluginFiles.h +++ b/source/plugins/udaPluginFiles.h @@ -8,8 +8,8 @@ # include #endif -#include "udaDefines.h" #include "export.h" +#include "udaDefines.h" #ifdef __cplusplus extern "C" { @@ -18,23 +18,23 @@ extern "C" { //------------------------------------------------------------------------------------------------------------------------ // Plugins opening files can maintain state by recording file handles in a list. // Two usage patterns are assumed: the file opening function returns an integer or a pointer -// Also assumed is the function used to close the file has a single argument - the returned value from the opening function. -// A function pointer to the Close function needs to be registerd the first time the plugin is called. +// Also assumed is the function used to close the file has a single argument - the returned value from the opening +// function. A function pointer to the Close function needs to be registerd the first time the plugin is called. //------------------------------------------------------------------------------------------------------------------------ typedef struct UdaPluginFile { - int status; // Open (1) or Closed (0) - char filename[STRING_LENGTH]; // Full Data Source Filename - long handleInt; // Integer File Handle - void* handlePtr; // Pointer file handle - struct timeval file_open; // File Open Clock Time + int status; // Open (1) or Closed (0) + char filename[STRING_LENGTH]; // Full Data Source Filename + long handleInt; // Integer File Handle + void* handlePtr; // Pointer file handle + struct timeval file_open; // File Open Clock Time } UDA_PLUGIN_FILE; typedef struct UdaPluginFileList { - int count; // Number of Files - int mcount; // malloc count allocated - UDA_PLUGIN_FILE* files; // Array of File Handles - void* close; // Function pointer to the File Close API function + int count; // Number of Files + int mcount; // malloc count allocated + UDA_PLUGIN_FILE* files; // Array of File Handles + void* close; // Function pointer to the File Close API function } UDA_PLUGIN_FILE_LIST; #ifdef __cplusplus diff --git a/source/plugins/uda_plugin_base.cpp b/source/plugins/uda_plugin_base.cpp index a32d6a9e..1907bc13 100644 --- a/source/plugins/uda_plugin_base.cpp +++ b/source/plugins/uda_plugin_base.cpp @@ -1,13 +1,14 @@ #include "uda_plugin_base.hpp" -#include "udaPlugin.h" #include "clientserver/stringUtils.h" +#include "udaPlugin.h" #include #include #include #include -int UDAPluginBase::call(IDAM_PLUGIN_INTERFACE* plugin_interface) { +int UDAPluginBase::call(IDAM_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!"); @@ -48,12 +49,14 @@ int UDAPluginBase::call(IDAM_PLUGIN_INTERFACE* plugin_interface) { } } -std::string UDAPluginBase::get_function(IDAM_PLUGIN_INTERFACE* plugin_interface) { +std::string UDAPluginBase::get_function(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ REQUEST_DATA* request = plugin_interface->request_data; return boost::to_lower_copy(request->function); } -void UDAPluginBase::do_init(IDAM_PLUGIN_INTERFACE* plugin_interface) { +void UDAPluginBase::do_init(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ std::string function = get_function(plugin_interface); if (!init_ || (function == "init" || function == "initialise")) { init(plugin_interface); @@ -61,7 +64,8 @@ void UDAPluginBase::do_init(IDAM_PLUGIN_INTERFACE* plugin_interface) { } } -void UDAPluginBase::do_reset() { +void UDAPluginBase::do_reset() +{ if (!init_) { // Not previously initialised: Nothing to do! return; @@ -71,7 +75,8 @@ void UDAPluginBase::do_reset() { init_ = false; } -int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE *plugin_interface) { +int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ std::string desc = name_ + ": help = description of this plugin"; if (help_file_.empty()) { @@ -85,7 +90,7 @@ int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE *plugin_interface) { return setReturnDataString(plugin_interface->data_block, help.c_str(), desc.c_str()); } - std::ifstream help_file{ path.string() }; + std::ifstream help_file{path.string()}; std::stringstream buffer; buffer << help_file.rdbuf(); auto help = buffer.str(); @@ -93,27 +98,33 @@ int UDAPluginBase::help(IDAM_PLUGIN_INTERFACE *plugin_interface) { return setReturnDataString(plugin_interface->data_block, help.c_str(), desc.c_str()); } -int UDAPluginBase::version(IDAM_PLUGIN_INTERFACE *plugin_interface) { +int UDAPluginBase::version(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ return setReturnDataIntScalar(plugin_interface->data_block, version_, "Plugin version number"); } -int UDAPluginBase::build_date(IDAM_PLUGIN_INTERFACE *plugin_interface) { +int UDAPluginBase::build_date(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ return setReturnDataString(plugin_interface->data_block, __DATE__, "Plugin build date"); } -int UDAPluginBase::default_method(IDAM_PLUGIN_INTERFACE *plugin_interface) { +int UDAPluginBase::default_method(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ return setReturnDataString(plugin_interface->data_block, default_method_.c_str(), "Plugin default method"); } -int UDAPluginBase::max_interface_version(IDAM_PLUGIN_INTERFACE *plugin_interface) { +int UDAPluginBase::max_interface_version(IDAM_PLUGIN_INTERFACE* plugin_interface) +{ return setReturnDataIntScalar(plugin_interface->data_block, interface_version_, "Maximum Interface Version"); } -void UDAPluginBase::register_method(const std::string &name, plugin_member_type plugin_method) { +void UDAPluginBase::register_method(const std::string& name, plugin_member_type plugin_method) +{ method_map_[name] = plugin_method; } -void UDAPluginBase::register_function(const std::string &name, plugin_function_type plugin_function) { +void UDAPluginBase::register_function(const std::string& name, plugin_function_type plugin_function) +{ function_map_[name] = plugin_function; } diff --git a/source/plugins/viewport/viewport.cpp b/source/plugins/viewport/viewport.cpp old mode 100755 new mode 100644 index 1d0c59e1..e0e218e3 --- a/source/plugins/viewport/viewport.cpp +++ b/source/plugins/viewport/viewport.cpp @@ -1,28 +1,28 @@ /*--------------------------------------------------------------- -* 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 -* -* Returns: 0 if the plugin functionality was successful -* otherwise a Error Code is returned -* -* Standard functionality: -* -*---------------------------------------------------------------------------------------------------------------*/ + * 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 + * + * Returns: 0 if the plugin functionality was successful + * otherwise a Error Code is returned + * + * Standard functionality: + * + *---------------------------------------------------------------------------------------------------------------*/ #include "viewport.h" -#include #include +#include #ifdef __GNUC__ # include #endif -#include -#include "udaGetAPI.h" -#include "initStructs.h" #include "accAPI.h" +#include "initStructs.h" +#include "udaGetAPI.h" #include +#include #include #include @@ -33,25 +33,22 @@ struct CacheEntry { std::string source; }; -class ViewportPlugin : public UDAPluginBase { -public: +class ViewportPlugin : public UDAPluginBase +{ + public: ViewportPlugin(); int get(IDAM_PLUGIN_INTERFACE* plugin_interface); void init(IDAM_PLUGIN_INTERFACE* plugin_interface) override {} void reset() override {} -private: + private: std::vector cache_; int find_handle(const std::string& signal, const std::string& source); }; ViewportPlugin::ViewportPlugin() - : UDAPluginBase( - "VIEWPORT", - 1, - "function", - boost::filesystem::path(__FILE__).parent_path().append("help.txt").string() -) + : UDAPluginBase("VIEWPORT", 1, "function", + boost::filesystem::path(__FILE__).parent_path().append("help.txt").string()) { register_method("get", static_cast(&ViewportPlugin::get)); } @@ -62,10 +59,11 @@ 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* memdup(const void* mem, size_t size) +{ char* out = (char*)malloc(size); - if(out != nullptr) { + if (out != nullptr) { memcpy(out, mem, size); } @@ -134,27 +132,27 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) getIdamFloatDimData(handle, 0, coords.data()); if (test) { - debug( "Running Viewport Test {}\n", *test); + debug("Running Viewport Test {}\n", *test); switch (*test) { - case 1: { // Do nothing + case 1: { // Do nothing break; } - case 2: { // 100 values mapped to 100 pixels: each pixel column has a single data value + case 2: { // 100 values mapped to 100 pixels: each pixel column has a single data value pixel_width = 100; break; } - case 3: { // 100 values mapped to 100 pixels: each pixel column has a single data value + case 3: { // 100 values mapped to 100 pixels: each pixel column has a single data value pixel_height = 100; break; } - case 4: { // 100 values mapped to 100 pixels: each pixel column has a single data value + case 4: { // 100 values mapped to 100 pixels: each pixel column has a single data value pixel_height = 100; pixel_width = 100; break; } - case 5: { // 100 values mapped to 100 pixels: each pixel column has a single data value + case 5: { // 100 values mapped to 100 pixels: each pixel column has a single data value count = 101; for (int i = 0; i < count; i++) { values[i] = (float)i + 1; @@ -165,7 +163,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) break; } - case 6: { // 50 values mapped to 100 pixels: alternate pixels have no data! + case 6: { // 50 values mapped to 100 pixels: alternate pixels have no data! count = 201; for (int i = 0; i < count; i++) { values[i] = (float)i + 1; @@ -176,7 +174,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) pixel_width = 100; break; } - case 7: { // 50 values mapped to 100 pixels: alternate pixels have no data! + case 7: { // 50 values mapped to 100 pixels: alternate pixels have no data! count = 201; for (int i = 0; i < count; i++) { values[i] = (float)i + 1; @@ -202,7 +200,6 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) // 1> Insufficient data to fill some pixels // 2> requested range lies outside the data's range - // Reduce data to fit the value ranges specified // Assume X data (coordinates) are ordered in increasing value @@ -231,7 +228,9 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (!start_y) { min_y = FLT_MAX; for (int j = 0; j < count; j++) { - if (values[j] < min_y) min_y = values[j]; + if (values[j] < min_y) { + min_y = values[j]; + } } } else { min_y = *start_y; @@ -240,7 +239,9 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (!end_y) { max_y = -FLT_MAX; for (int j = 0; j < count; j++) { - if (values[j] > max_y) max_y = values[j]; + if (values[j] > max_y) { + max_y = values[j]; + } } } else { max_y = *end_y; @@ -297,14 +298,15 @@ 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, *pixel_height); + debug("Viewport: Mapping data to device pixel coordinate range (width, height) = {}, {}\n", *pixel_width, + *pixel_height); int* column = nullptr; // Assign coordinates to pixel columns - horizontal_pixel_values = getBins(coords.data(), count, *pixel_width, (double)min_x, (double)max_x, &column); + horizontal_pixel_values = + getBins(coords.data(), count, *pixel_width, (double)min_x, (double)max_x, &column); // Frequency distribution of pixel hits along each vertical pixel column @@ -314,11 +316,10 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) int* good = (int*)malloc(*pixel_width * sizeof(int)); - float* verticalPixelValues = nullptr; // Value at the pixel center + float* verticalPixelValues = nullptr; // Value at the pixel center float delta; - getVerticalPixelValues(values.data(), count, *pixel_height, &min_y, &max_y, &verticalPixelValues, - &delta); + getVerticalPixelValues(values.data(), count, *pixel_height, &min_y, &max_y, &verticalPixelValues, &delta); auto verticalPixelBoundaries = (float*)malloc((*pixel_height + 2) * sizeof(float)); verticalPixelBoundaries[0] = min_y; @@ -344,7 +345,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } for (int i = 0; i < count; i++) { - fctot[column[i]]++; // total counts + fctot[column[i]]++; // total counts } int colCount = 0; @@ -352,16 +353,16 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) colCount = colCount + fctot[i]; } - debug( "Column Totals: {}\n", colCount); + debug("Column Totals: {}\n", colCount); for (int i = 0; i < *pixel_width; i++) { - debug( "[{}] {}\n", i, fctot[i]); + debug("[{}] {}\n", i, fctot[i]); } // Which pixel row bin do each un-ordered data point fall into? for (int j = 0; j < count; j++) { row[j] = -1; - for (int i = 0; i < *pixel_height + 1; i++) { // Search within pixel boundaries + for (int i = 0; i < *pixel_height + 1; i++) { // Search within pixel boundaries if (values[j] >= verticalPixelBoundaries[i] && values[j] < verticalPixelBoundaries[i + 1]) { row[j] = i; break; @@ -372,7 +373,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } if (column[j] >= 0 && row[j] >= 0) { - freq[column[j]][row[j]]++; // build frequency distribution + freq[column[j]][row[j]]++; // build frequency distribution } } @@ -381,7 +382,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } for (int i = 0; i < count; i++) { - frtot[row[i]]++; // total counts + frtot[row[i]]++; // total counts } int rowCount = 0; @@ -389,9 +390,9 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) rowCount = rowCount + frtot[i]; } - debug( "Row Totals: {}\n", rowCount); + debug("Row Totals: {}\n", rowCount); for (int i = 0; i < *pixel_height; i++) { - debug( "[{}] {}\n", i, frtot[i]); + debug("[{}] {}\n", i, frtot[i]); } free(column); @@ -420,7 +421,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) if (range && mean) { if (i == 0) { - debug( "Mean returned\n"); + debug("Mean returned\n"); } for (int j = 0; j < pixel_height; j++) { if (freq[i][j] > 0) { @@ -435,11 +436,11 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } else if (!range && mode) { - debug( "Mode returned\n"); + debug("Mode returned\n"); int fmax = 0; int fmaxID = -1; for (int j = 0; j < pixel_height; j++) { - if (freq[i][j] > fmax) { // First mode found if multi-modal + if (freq[i][j] > fmax) { // First mode found if multi-modal fmaxID = j; fmax = freq[i][j]; } @@ -451,7 +452,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) } } else if (!range && median) { if (i == 0) { - debug( "Median returned\n"); + debug("Median returned\n"); } integral[0] = freq[i][0]; @@ -467,8 +468,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) float dx = (float)(integral[j] - integral[j - 1]); if (dx != 0.0) { float m = (verticalPixelValues[j] - verticalPixelValues[j - 1]) / dx; - data[i] = m * (target - integral[j]) + - verticalPixelValues[j]; // Linear Interpolate + data[i] = m * (target - integral[j]) + verticalPixelValues[j]; // Linear Interpolate } else { data[i] = verticalPixelValues[j]; } @@ -496,21 +496,21 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) for (int j = 0; j < *pixel_height; j++) { if (freq[i][j] > 0) { - err_lo[i] = verticalPixelValues[j]; // lowest value + err_lo[i] = verticalPixelValues[j]; // lowest value break; } } for (int j = *pixel_height - 1; j >= 0; j--) { if (freq[i][j] > 0) { - err_hi[i] = verticalPixelValues[j]; // highest value + err_hi[i] = verticalPixelValues[j]; // highest value break; } } if (range) { if (i == 0) { - debug( "Range returned\n"); + debug("Range returned\n"); } data[i] = 0.5 * (err_lo[i] + err_hi[i]); good_count++; @@ -518,16 +518,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("[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); - } // end of loop over pixel_width + } // end of loop over pixel_width - debug( "good_count = {}\n", good_count); - debug( "pixel_width = {}\n", *pixel_width); + debug("good_count = {}\n", good_count); + debug("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("[{}] {} {} {} {}\n", i, data[i], err_lo[i], err_hi[i], horizontal_pixel_values[i]); } // Free allocated heap @@ -542,7 +540,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("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)); @@ -567,7 +565,7 @@ int ViewportPlugin::get(IDAM_PLUGIN_INTERFACE* plugin_interface) horizontal_pixel_values = pixel_values; pixelWidth2 = good_count; } - } else { // Device pixel coordinate range not set + } else { // Device pixel coordinate range not set data = values; horizontal_pixel_values = coords; pixelWidth2 = count; @@ -638,20 +636,24 @@ std::vector getBins(float* coords, int count, int pixel_width, float minV start = 0; for (int j = 0; j < count; j++) { bin[j] = -1; - for (int i = start; i < pixel_width + 1; i++) { // Search within pixel boundaries + for (int i = start; i < pixel_width + 1; i++) { // Search within pixel boundaries if (coords[j] >= pix_values[i] && coords[j] < pix_values[i + 1]) { bin[j] = i; start = i; break; } } - if (bin[j] > pixel_width - 1) bin[j] = pixel_width - 1; + if (bin[j] > pixel_width - 1) { + bin[j] = pixel_width - 1; + } } // mid pixel value: the range of data is mapped to these pixels pix_values[0] = minValue + 0.5 * delta; - for (int i = 1; i < pixel_width; i++) pix_values[i] = pix_values[i - 1] + delta; + for (int i = 1; i < pixel_width; i++) { + pix_values[i] = pix_values[i - 1] + delta; + } *column = bin; return pix_values; @@ -667,7 +669,9 @@ void getVerticalPixelValues(float* values, int count, int pixel_height, float* s if (startValue == nullptr) { for (int i = 0; i < count; i++) { - if (values[i] < minValue) minValue = values[i]; + if (values[i] < minValue) { + minValue = values[i]; + } } } else { minValue = *startValue; @@ -675,7 +679,9 @@ void getVerticalPixelValues(float* values, int count, int pixel_height, float* s if (endValue == nullptr) { for (int i = 0; i < count; i++) { - if (values[i] > maxValue) maxValue = values[i]; + if (values[i] > maxValue) { + maxValue = values[i]; + } } } else { maxValue = *endValue; @@ -699,7 +705,9 @@ void getBinIds(float* values, int count, int pixel_height, float* pixel_values, } for (int i = 0; i < count; i++) { for (int j = 0; j < pixel_height; j++) { - if (values[i] >= pixel_values[j] && values[i] <= pixel_values[j]) f[j]++; + if (values[i] >= pixel_values[j] && values[i] <= pixel_values[j]) { + f[j]++; + } } } *freq = f; @@ -758,5 +766,3 @@ void reduceOrderedData(float* values, int* count, float* startValue, float* endV *min = minValue; *max = maxValue; } - - diff --git a/source/plugins/viewport/viewport.h b/source/plugins/viewport/viewport.h old mode 100755 new mode 100644 index 170eda2d..fb386fc1 --- a/source/plugins/viewport/viewport.h +++ b/source/plugins/viewport/viewport.h @@ -1,22 +1,22 @@ #ifndef IDAM_PLUGINS_VIEWPORT_VIEWPORT_H #define IDAM_PLUGINS_VIEWPORT_VIEWPORT_H -#include "udaPlugin.h" #include "export.h" +#include "udaPlugin.h" #ifdef __cplusplus extern "C" { #endif -#define THISPLUGIN_VERSION 1 -#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! -#define THISPLUGIN_DEFAULT_METHOD "get" +#define THISPLUGIN_VERSION 1 +#define THISPLUGIN_MAX_INTERFACE_VERSION 1 // Interface versions higher than this will not be understood! +#define THISPLUGIN_DEFAULT_METHOD "get" -#define MAXHANDLES 8 -#define MAXSIGNALNAME 256 -#define FREEHANDLEBLOCK 4 +#define MAXHANDLES 8 +#define MAXSIGNALNAME 256 +#define FREEHANDLEBLOCK 4 -int viewport(IDAM_PLUGIN_INTERFACE * idam_plugin_interface); +int viewport(IDAM_PLUGIN_INTERFACE* idam_plugin_interface); #ifdef __cplusplus } diff --git a/source/security/authenticationUtils.cpp b/source/security/authenticationUtils.cpp old mode 100755 new mode 100644 index 4f2fa66b..896c2c49 --- a/source/security/authenticationUtils.cpp +++ b/source/security/authenticationUtils.cpp @@ -1,7 +1,7 @@ #include "authenticationUtils.h" -#include #include +#include #include @@ -20,12 +20,8 @@ int testFilePermissions(const char* object) "Could not verify the user's private key directory's access permissions!"); return err; } - if (buffer.st_mode & S_IRGRP || - buffer.st_mode & S_IWGRP || - buffer.st_mode & S_IXGRP || - buffer.st_mode & S_IROTH || - buffer.st_mode & S_IWOTH || - buffer.st_mode & S_IXOTH) { + if (buffer.st_mode & S_IRGRP || buffer.st_mode & S_IWGRP || buffer.st_mode & S_IXGRP || buffer.st_mode & S_IROTH || + buffer.st_mode & S_IWOTH || buffer.st_mode & S_IXOTH) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "testSecurityFilePermissions", err, "The user's private key directory is public: Your keys and certificate may be compromised!!!"); @@ -50,4 +46,3 @@ void initSecurityBlock(SECURITY_BLOCK* str) str->client_X509 = nullptr; str->client2_X509 = nullptr; } - diff --git a/source/security/authenticationUtils.h b/source/security/authenticationUtils.h old mode 100755 new mode 100644 index 99758051..307d06cf --- a/source/security/authenticationUtils.h +++ b/source/security/authenticationUtils.h @@ -1,8 +1,8 @@ #ifndef UDA_SECURITY_AUTHENTICATIONUTILS_H #define UDA_SECURITY_AUTHENTICATIONUTILS_H -#include "udaStructs.h" #include "export.h" +#include "udaStructs.h" #ifdef __cplusplus extern "C" { diff --git a/source/security/clientAuthentication.cpp b/source/security/clientAuthentication.cpp old mode 100755 new mode 100644 index 3915b298..3acab35e --- a/source/security/clientAuthentication.cpp +++ b/source/security/clientAuthentication.cpp @@ -1,20 +1,20 @@ #include "clientAuthentication.h" #include -#include #include +#include #include #ifndef TESTIDAMSECURITY -# include -# include "include/udaErrors.h" # include "include/client.h" +# include "include/udaErrors.h" +# include #endif #include "authenticationUtils.h" #include "x509Utils.h" static ENCRYPTION_METHOD encryptionMethod = ASYMMETRICKEY; -static unsigned short tokenByteLength = NONCEBYTELENGTH; // System problem when >~ 110 ! +static unsigned short tokenByteLength = NONCEBYTELENGTH; // System problem when >~ 110 ! static TOKEN_TYPE tokenType = NONCESTRONGRANDOM; // NONCESTRONGRANDOM NONCESTRINGRANDOM NONCEWEAKRANDOM NONCETEST; // /** @@ -28,10 +28,10 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out { SECURITY_BLOCK* securityBlock = nullptr; - static gcry_sexp_t privatekey = nullptr; // Client's private key - maintain state for future en/decryption - static gcry_sexp_t publickey = nullptr; // Server's public key + static gcry_sexp_t privatekey = nullptr; // Client's private key - maintain state for future en/decryption + static gcry_sexp_t publickey = nullptr; // Server's public key - static short initialised = FALSE; // Input keys and certificates at startup + static short initialised = FALSE; // Input keys and certificates at startup if (initialised) { *privatekey_out = privatekey; @@ -44,19 +44,19 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out char* clientPrivateKeyFile = nullptr; char* serverPublicKeyFile = nullptr; - char* clientX509File = nullptr; // Authentication with the first server in a server chain - char* client2X509File = nullptr; // Delivered to the final host in a server chain where the data resides - char* serverX509File = nullptr; // Certificate of the first server host + char* clientX509File = nullptr; // Authentication with the first server in a server chain + char* client2X509File = nullptr; // Delivered to the final host in a server chain where the data resides + char* serverX509File = nullptr; // Certificate of the first server host - if ((env = getenv("UDA_CLIENT_CERTIFICATE")) != nullptr) { // Directory with certificates and key files + if ((env = getenv("UDA_CLIENT_CERTIFICATE")) != nullptr) { // Directory with certificates and key files len = strlen(env) + 56; clientPrivateKeyFile = (char*)malloc(len * sizeof(unsigned char)); serverPublicKeyFile = (char*)malloc(len * sizeof(unsigned char)); clientX509File = (char*)malloc(len * sizeof(unsigned char)); serverX509File = (char*)malloc(len * sizeof(unsigned char)); - sprintf(clientPrivateKeyFile, "%s/clientskey.pem", env); // Client's - sprintf(serverPublicKeyFile, "%s/serverpkey.pem", env); // Server's + sprintf(clientPrivateKeyFile, "%s/clientskey.pem", env); // Client's + sprintf(serverPublicKeyFile, "%s/serverpkey.pem", env); // Server's sprintf(clientX509File, "%s/clientX509.der", env); sprintf(serverX509File, "%s/serverX509.der", env); } else { @@ -86,18 +86,18 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out ksba_cert_t serverCert = nullptr; int err = 0; -// Read the Client's certificates and check date validity + // Read the Client's certificates and check date validity securityBlock = &client_block->securityBlock; initSecurityBlock(securityBlock); if (clientX509File != nullptr) { - if ((err = importSecurityDoc(clientX509File, &securityBlock->client_X509, - &securityBlock->client_X509Length)) != 0) { + if ((err = importSecurityDoc(clientX509File, &securityBlock->client_X509, &securityBlock->client_X509Length)) != + 0) { return err; } - if ((err = makeX509CertObject(securityBlock->client_X509, securityBlock->client_X509Length, - &clientCert)) != 0) { + if ((err = makeX509CertObject(securityBlock->client_X509, securityBlock->client_X509Length, &clientCert)) != + 0) { return err; } if ((err = testX509Dates(clientCert)) != 0) { @@ -112,8 +112,8 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out &securityBlock->client2_X509Length)) != 0) { return err; } - if ((err = makeX509CertObject(securityBlock->client2_X509, securityBlock->client2_X509Length, - &client2Cert)) != 0) { + if ((err = makeX509CertObject(securityBlock->client2_X509, securityBlock->client2_X509Length, &client2Cert)) != + 0) { return err; } if ((err = testX509Dates(client2Cert)) != 0) { @@ -123,7 +123,7 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out client2Cert = nullptr; } -// Test the private key file and its directory directory have permissions set to owner read only + // Test the private key file and its directory directory have permissions set to owner read only if ((err = testFilePermissions(clientPrivateKeyFile)) != 0) { return err; @@ -156,7 +156,7 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out // If from a PEM file, convert to S-Expression if (serverX509File != nullptr) { - unsigned char* serverCertificate; // Server's X509 authentication certificate + unsigned char* serverCertificate; // Server's X509 authentication certificate unsigned short serverCertificateLength; if ((err = importSecurityDoc(serverX509File, &serverCertificate, &serverCertificateLength)) != 0) { @@ -170,14 +170,14 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out } if ((err = extractX509SExpKey(serverCert, &publickey)) != 0) { return err; - } // get the server's Public key from an X509 certificate + } // get the server's Public key from an X509 certificate ksba_cert_release(serverCert); serverCert = nullptr; free(serverCertificate); serverCertificate = nullptr; } else if ((err = importPEMPublicKey(serverPublicKeyFile, &publickey)) != 0) { return err; - } // get the server's Public key from a file + } // get the server's Public key from a file // Test the user's private key for consistency // User keys also have a lifetime - automatically checked if there is a x509 certificate @@ -206,16 +206,26 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out securityBlock->client_X509Length = 0; securityBlock->client2_X509Length = 0; - if (clientCert != nullptr) ksba_cert_release(clientCert); - if (client2Cert != nullptr) ksba_cert_release(client2Cert); - if (serverCert != nullptr) ksba_cert_release(serverCert); + if (clientCert != nullptr) { + ksba_cert_release(clientCert); + } + if (client2Cert != nullptr) { + ksba_cert_release(client2Cert); + } + if (serverCert != nullptr) { + ksba_cert_release(serverCert); + } clientCert = nullptr; client2Cert = nullptr; serverCert = nullptr; - if (privatekey != nullptr) gcry_sexp_release(privatekey); - if (publickey != nullptr) gcry_sexp_release(publickey); - privatekey = nullptr; // These are declared as static so ensure they are reset when an error occurs + if (privatekey != nullptr) { + gcry_sexp_release(privatekey); + } + if (publickey != nullptr) { + gcry_sexp_release(publickey); + } + privatekey = nullptr; // These are declared as static so ensure they are reset when an error occurs publickey = nullptr; return err; } @@ -227,8 +237,9 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out return 0; } -static int issueToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - gcry_sexp_t publickey, gcry_sexp_t privatekey, gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) +static int issueToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, gcry_sexp_t publickey, gcry_sexp_t privatekey, + gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) { int err = 0; @@ -239,18 +250,15 @@ static int issueToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, size_t client_ciphertextLength = 0; size_t server_ciphertextLength = 0; - err = udaAuthentication(CLIENT_ISSUE_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(CLIENT_ISSUE_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, privatekey, + client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { UDA_THROW_ERROR(err, "Failed Preparing Authentication Step #1!"); } -// Send the encrypted token to the server together with Client's claim of identity + // Send the encrypted token to the server together with Client's claim of identity SECURITY_BLOCK* securityBlock = &client_block->securityBlock; @@ -264,7 +272,8 @@ static int issueToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, #ifndef TESTIDAMSECURITY int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; - if ((err = protocol2(clientOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, &client_block)) != 0) { + if ((err = protocol2(clientOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, + &client_block)) != 0) { UDA_THROW_ERROR(err, "Protocol 10 Error (securityBlock #1)"); } @@ -310,7 +319,8 @@ static int decryptServerToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_b int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; - if ((err = protocol2(clientInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, &server_block)) != 0) { + if ((err = protocol2(clientInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, + &server_block)) != 0) { UDA_THROW_ERROR(err, "Protocol 11 Error (securityBlock #5)"); } @@ -351,11 +361,8 @@ static int decryptServerToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_b // Decrypt tokens (A, B) and Authenticate the Server - err = udaAuthentication(CLIENT_DECRYPT_SERVER_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(CLIENT_DECRYPT_SERVER_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, + privatekey, client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -368,8 +375,9 @@ static int decryptServerToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_b return err; } -static int encryptServerToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - gcry_sexp_t publickey, gcry_sexp_t privatekey, gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) +static int encryptServerToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, gcry_sexp_t publickey, gcry_sexp_t privatekey, + gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) { int err = 0; @@ -383,11 +391,8 @@ static int encryptServerToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmall size_t client_ciphertextLength = 0; size_t server_ciphertextLength = 0; - err = udaAuthentication(CLIENT_ENCRYPT_SERVER_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(CLIENT_ENCRYPT_SERVER_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, + privatekey, client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -407,7 +412,8 @@ static int encryptServerToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmall #ifndef TESTIDAMSECURITY int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; - if ((err = protocol2(clientOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, &client_block)) != 0) { + if ((err = protocol2(clientOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, + &client_block)) != 0) { UDA_THROW_ERROR(err, "Protocol 10 Error (securityBlock #6)"); } @@ -439,22 +445,29 @@ int clientAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, switch (authenticationStep) { case CLIENT_ISSUE_TOKEN: - err = issueToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = issueToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, + &server_mpiToken); break; case CLIENT_DECRYPT_SERVER_TOKEN: - err = decryptServerToken(server_block, client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = decryptServerToken(server_block, client_block, logmalloclist, userdefinedtypelist, publickey, + privatekey, &client_mpiToken, &server_mpiToken); break; case CLIENT_ENCRYPT_SERVER_TOKEN: - err = encryptServerToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = encryptServerToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, + &client_mpiToken, &server_mpiToken); break; case HOUSEKEEPING: free(publickey); free(privatekey); - if (client_mpiToken != nullptr) gcry_mpi_release(client_mpiToken); - if (server_mpiToken != nullptr) gcry_mpi_release(server_mpiToken); + if (client_mpiToken != nullptr) { + gcry_mpi_release(client_mpiToken); + } + if (server_mpiToken != nullptr) { + gcry_mpi_release(server_mpiToken); + } break; default: @@ -462,8 +475,12 @@ int clientAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, } if (err != 0) { - if (client_mpiToken != nullptr) gcry_mpi_release(client_mpiToken); - if (server_mpiToken != nullptr) gcry_mpi_release(server_mpiToken); + if (client_mpiToken != nullptr) { + gcry_mpi_release(client_mpiToken); + } + if (server_mpiToken != nullptr) { + gcry_mpi_release(server_mpiToken); + } } return err; diff --git a/source/security/clientAuthentication.h b/source/security/clientAuthentication.h old mode 100755 new mode 100644 index 860b4a4a..1af78d05 --- a/source/security/clientAuthentication.h +++ b/source/security/clientAuthentication.h @@ -2,8 +2,8 @@ #define UDA_SECURITY_CLIENTAUTHENTICATION_H #include "export.h" -#include "udaStructs.h" #include "genStructs.h" +#include "udaStructs.h" #include "security.h" @@ -11,8 +11,9 @@ extern "C" { #endif -LIBRARY_API int clientAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, AUTHENTICATION_STEP authenticationStep); +LIBRARY_API int clientAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + AUTHENTICATION_STEP authenticationStep); #ifdef __cplusplus } diff --git a/source/security/security.cpp b/source/security/security.cpp old mode 100755 new mode 100644 index 2c89e75a..d13dd28d --- a/source/security/security.cpp +++ b/source/security/security.cpp @@ -9,43 +9,43 @@ // d) client connects to a proxy that connects to a server that connects to a server etc. (multi-tier connection) // // IDAM servers without a public key server component must use PKI (Public Key Infrastructure) X.509 based certificates. -// X.509 certificates establish the authenticity of the binding between a public key and its owner through a +// X.509 certificates establish the authenticity of the binding between a public key and its owner through a // digital signature created using the private key of a trusted third party - a Certificate Authority. // *** libksba *** to create and parse X.509 certificates (can self sign!) // Use linux CLI openssl to create certificates [http://www.openssl.org/] // Authenticate the client and/or server involves checking that their certificate was signed by an acceptable authority // (Signing means the public key was generated by an authenticated person. They need the private key to complete -// the authentication process.) +// the authentication process.) // The certificate contains the user's public key. Use the CA public key to test the -// signature => proof the certificate is valid. Servers only need the CA public keys to assist in authentication. +// signature => proof the certificate is valid. Servers only need the CA public keys to assist in authentication. // -// Web based access requires HTTPS - based on Transport Layer Security (TLS) +// Web based access requires HTTPS - based on Transport Layer Security (TLS) // [http://en.wikipedia.org/wiki/Transport_Layer_Security] and X.509 (SSL) certificates for public keys. -// *** http://www.gnutls.org/ *** +// *** http://www.gnutls.org/ *** // // Options: // // a) Mutual athentication for 2 claims of identity (the server may choose not to authenticate) -// b) Proxy does not authenticate and passes through the claim of identity to the next server as a). +// b) Proxy does not authenticate and passes through the claim of identity to the next server as a). // c) Option: // 1) The User has one identity. Intermediate servers don't authenticate with each other or the client and -// pass through the claim of identity to the final server. Authentication occurs between the final server -// and the user. +// pass through the claim of identity to the final server. Authentication occurs between the final server +// and the user. // 2) The User has one identity. Intermediate servers authenticate with each other but don't authenticate -// with the client. They pass through the claim of identity to the final server. Authentication occurs +// with the client. They pass through the claim of identity to the final server. Authentication occurs // between the final server and the user. // 3) The User has one identity. All servers authenticate with the client. **** Not adopted **** // 4) The User has two identities. The first server authenticates with the first user identity. -// Intermediate servers don't authenticate with each other or the client and -// pass through the claim of identity to the final server. Authentication occurs between the final server -// and the user (second identity). +// Intermediate servers don't authenticate with each other or the client and +// pass through the claim of identity to the final server. Authentication occurs between the final server +// and the user (second identity). // 5) The User has two identities. The first server authenticates with the first user identity. // Intermediate servers authenticate with each other but don't authenticate with the client. They -// pass through the second claim of identity to the final server. Authentication occurs between the final server +// pass through the second claim of identity to the final server. Authentication occurs between the final server // and the user (second identity). // 6) The User has n identities. Each of n servers authenticates with the n user identities. **** Not adopted **** // d) Proxy does not authenticate and passes through the claims of identity to the multiple servers as c). -// +// // Steps: // // 1> Client issues a token (A), encrypts with the server's public key (->EASP), passes to server (with X.509) @@ -68,27 +68,27 @@ // authorised data access. (X.509 certificate signature check now unneccesary) // // 1> Client data access request includes the encrypted token (B) -// 2> Server data (unencrypted) returned with new encrypted token + encrypted data checksum +// 2> Server data (unencrypted) returned with new encrypted token + encrypted data checksum // // Authentication cost is 3 RTT, incurred before the first data request is processed by the server. // -// Authentication is completed during the first data request. No additional security based TCP/IP exchanges +// Authentication is completed during the first data request. No additional security based TCP/IP exchanges // are required thereafter. // -// Server closedown should be avoided to maintain state. +// Server closedown should be avoided to maintain state. // // **** The server could issue a session ID in case of lost connections to speed up access. This ID could -// have a short lifetime ~ 1 mins, sufficient to re-establish the connection at no extra cost. -// The last issued ID could serve as both the session ID and the authentication token. +// have a short lifetime ~ 1 mins, sufficient to re-establish the connection at no extra cost. +// The last issued ID could serve as both the session ID and the authentication token. // //-------------------------------------------------------------------------------------------------------------------- #include "security.h" #include -#include -#include #include "udaTypes.h" +#include +#include #include static void logToken(const char* msg, const gcry_mpi_t mpi_token) @@ -119,8 +119,7 @@ static int createMPIToken(unsigned short tokenType, unsigned short tokenByteLeng if (gcry_mpi_scan(mpiToken, GCRYMPI_FMT_USG, txt, strlen(txt), nullptr) != 0) { UDA_THROW_ERROR(999, "Unable to generate MPI Token"); } - } - break; + } break; // Random bits case NONCEWEAKRANDOM: { @@ -130,8 +129,7 @@ static int createMPIToken(unsigned short tokenType, unsigned short tokenByteLeng UDA_THROW_ERROR(999, "Unable to generate MPI Token"); } - } - break; + } break; // Random bits case NONCESTRONGRANDOM: { @@ -140,8 +138,7 @@ static int createMPIToken(unsigned short tokenType, unsigned short tokenByteLeng if (*mpiToken == nullptr) { UDA_THROW_ERROR(999, "Unable to generate MPI Token"); } - } - break; + } break; // Random String case NONCESTRINGRANDOM: { @@ -151,7 +148,7 @@ static int createMPIToken(unsigned short tokenType, unsigned short tokenByteLeng // Get the current time and convert to a string unsigned long long t = (unsigned long long)time(nullptr); - char timeList[256]; // Overestimate of the maximum possible size of a long long integer + char timeList[256]; // Overestimate of the maximum possible size of a long long integer sprintf(timeList, "%llu", t); size_t timeLength = strlen(timeList); @@ -199,7 +196,7 @@ static int createMPIToken(unsigned short tokenType, unsigned short tokenByteLeng } default: - UDA_THROW_ERROR(999, "Unknown token type"); + UDA_THROW_ERROR(999, "Unknown token type"); } return err; @@ -264,13 +261,12 @@ static int generateToken(gcry_mpi_t* mpi_token, unsigned short tokenType, unsign return err; } -static int -encryptToken(gcry_mpi_t* mpi_token, unsigned short encryptionMethod, gcry_sexp_t key, unsigned char** ciphertext, - size_t* ciphertext_len) +static int encryptToken(gcry_mpi_t* mpi_token, unsigned short encryptionMethod, gcry_sexp_t key, + unsigned char** ciphertext, size_t* ciphertext_len) { int err = 0; - gcry_sexp_t mpiTokenSexp = nullptr; // Token as a S-Expression + gcry_sexp_t mpiTokenSexp = nullptr; // Token as a S-Expression gpg_error_t gerr; @@ -291,24 +287,32 @@ encryptToken(gcry_mpi_t* mpi_token, unsigned short encryptionMethod, gcry_sexp_t // Encrypt if ((gerr = gcry_pk_encrypt(&encr, mpiTokenSexp, key)) != 0) { - if (mpiTokenSexp != nullptr) gcry_sexp_release(mpiTokenSexp); + if (mpiTokenSexp != nullptr) { + gcry_sexp_release(mpiTokenSexp); + } addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, "Encryption Error"); UDA_THROW_ERROR(999, gpg_strerror(gerr)); } - if (mpiTokenSexp != nullptr) gcry_sexp_release(mpiTokenSexp); + if (mpiTokenSexp != nullptr) { + gcry_sexp_release(mpiTokenSexp); + } gcry_mpi_t encrypted_token = nullptr; // MPI in encrypted form // Extract the ciphertext from the S-expression if ((encrypted_token = extract_a_from_sexp(encr)) == nullptr) { - if (encr != nullptr) gcry_sexp_release(encr); + if (encr != nullptr) { + gcry_sexp_release(encr); + } UDA_THROW_ERROR(999, "Poor Encryption"); } // Check the ciphertext does not match the plaintext if (!gcry_mpi_cmp(*mpi_token, encrypted_token)) { - if (encrypted_token != nullptr) gcry_mpi_release(encrypted_token); + if (encrypted_token != nullptr) { + gcry_mpi_release(encrypted_token); + } UDA_THROW_ERROR(999, "Poor Encryption"); } @@ -316,8 +320,12 @@ encryptToken(gcry_mpi_t* mpi_token, unsigned short encryptionMethod, gcry_sexp_t *ciphertext_len = gcry_sexp_sprint(encr, GCRYSEXP_FMT_DEFAULT, nullptr, 0); if (*ciphertext_len == 0) { - if (encr != nullptr) gcry_sexp_release(encr); - if (encrypted_token != nullptr) gcry_mpi_release(encrypted_token); + if (encr != nullptr) { + gcry_sexp_release(encr); + } + if (encrypted_token != nullptr) { + gcry_mpi_release(encrypted_token); + } *ciphertext = nullptr; UDA_THROW_ERROR(999, "Ciphertext extraction error"); } @@ -326,20 +334,26 @@ encryptToken(gcry_mpi_t* mpi_token, unsigned short encryptionMethod, gcry_sexp_t gcry_sexp_sprint(encr, GCRYSEXP_FMT_DEFAULT, *ciphertext, *ciphertext_len); if (*ciphertext == nullptr) { - if (encr != nullptr) gcry_sexp_release(encr); - if (encrypted_token != nullptr) gcry_mpi_release(encrypted_token); + if (encr != nullptr) { + gcry_sexp_release(encr); + } + if (encrypted_token != nullptr) { + gcry_mpi_release(encrypted_token); + } UDA_THROW_ERROR(999, "Ciphertext extraction error"); } logToken("Encrypted", encrypted_token); - if (encrypted_token != nullptr) gcry_mpi_release(encrypted_token); + if (encrypted_token != nullptr) { + gcry_mpi_release(encrypted_token); + } break; } default: - UDA_THROW_ERROR(999, "Unknown encryption method"); + UDA_THROW_ERROR(999, "Unknown encryption method"); } return err; @@ -394,12 +408,11 @@ static int decryptToken(gcry_mpi_t* mpi_token, gcry_sexp_t key, unsigned char** return err; } -int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD encryptionMethod, - TOKEN_TYPE tokenType, unsigned short tokenByteLength, - gcry_sexp_t publickey, gcry_sexp_t privatekey, - gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken, - unsigned char** client_ciphertext, size_t* client_ciphertextLength, - unsigned char** server_ciphertext, size_t* server_ciphertextLength) +int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD encryptionMethod, TOKEN_TYPE tokenType, + unsigned short tokenByteLength, gcry_sexp_t publickey, gcry_sexp_t privatekey, + gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken, unsigned char** client_ciphertext, + size_t* client_ciphertextLength, unsigned char** server_ciphertext, + size_t* server_ciphertextLength) { int err = 0; @@ -426,13 +439,14 @@ int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD //-------------------------------------------------------------------------------------------------------------------- // Authentication Steps - static gcry_mpi_t mpiTokenA = nullptr; // Token passed from the client to the server (preserve for comparison) - static gcry_mpi_t mpiTokenB = nullptr; // Token passed from the server to the client (preserve for comparison) + static gcry_mpi_t mpiTokenA = nullptr; // Token passed from the client to the server (preserve for comparison) + static gcry_mpi_t mpiTokenB = nullptr; // Token passed from the server to the client (preserve for comparison) UDA_LOG(UDA_LOG_DEBUG, "Step %d\n", authenticationStep); switch (authenticationStep) { - case CLIENT_ISSUE_TOKEN: { // Client issues a token (A), encrypts with the server's public key (EASP), passes to server + case CLIENT_ISSUE_TOKEN: { // Client issues a token (A), encrypts with the server's public key (EASP), passes to + // server err = generateToken(&mpiTokenA, tokenType, tokenByteLength); if (err != 0) { break; @@ -441,18 +455,20 @@ int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD break; } - case SERVER_DECRYPT_CLIENT_TOKEN: { // Server decrypts the passed cipher (EASP) with the server's private key (A) + case SERVER_DECRYPT_CLIENT_TOKEN: { // Server decrypts the passed cipher (EASP) with the server's private key + // (A) err = decryptToken(client_mpiToken, privatekey, client_ciphertext, client_ciphertextLength); break; } - case SERVER_ENCRYPT_CLIENT_TOKEN: { // Server encrypts the client token (A) with the client's public key (EACP) - err = encryptToken(client_mpiToken, encryptionMethod, publickey, client_ciphertext, - client_ciphertextLength); + case SERVER_ENCRYPT_CLIENT_TOKEN: { // Server encrypts the client token (A) with the client's public key (EACP) + err = + encryptToken(client_mpiToken, encryptionMethod, publickey, client_ciphertext, client_ciphertextLength); break; } - case SERVER_ISSUE_TOKEN: { // Server issues a new token (B) encrypted with the client's public key (EBCP), passes both to client + case SERVER_ISSUE_TOKEN: { // Server issues a new token (B) encrypted with the client's public key (EBCP), + // passes both to client err = generateToken(&mpiTokenB, tokenType, tokenByteLength); if (err != 0) { break; @@ -461,7 +477,8 @@ int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD break; } - case CLIENT_DECRYPT_SERVER_TOKEN: { // Client decrypts the passed ciphers (EACP, EBCP) with the client's private key (A, B) + case CLIENT_DECRYPT_SERVER_TOKEN: { // Client decrypts the passed ciphers (EACP, EBCP) with the client's private + // key (A, B) gcry_mpi_t received_token = nullptr; err = decryptToken(&received_token, privatekey, client_ciphertext, client_ciphertextLength); if (err != 0) { @@ -484,13 +501,14 @@ int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD break; } - case CLIENT_ENCRYPT_SERVER_TOKEN: { // Client encrypts passed token (B) with the server's public key (EBSP), passes to server - err = encryptToken(server_mpiToken, encryptionMethod, publickey, server_ciphertext, - server_ciphertextLength); + case CLIENT_ENCRYPT_SERVER_TOKEN: { // Client encrypts passed token (B) with the server's public key (EBSP), + // passes to server + err = + encryptToken(server_mpiToken, encryptionMethod, publickey, server_ciphertext, server_ciphertextLength); break; } - case SERVER_VERIFY_TOKEN: { // Server decrypts the passed cipher (EBSP) with the server's private key (B) + case SERVER_VERIFY_TOKEN: { // Server decrypts the passed cipher (EBSP) with the server's private key (B) gcry_mpi_t received_token = nullptr; err = decryptToken(&received_token, privatekey, server_ciphertext, server_ciphertextLength); @@ -511,9 +529,7 @@ int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD default: { UDA_THROW_ERROR(999, "Uknown User Authentication Step"); } - } return err; } - diff --git a/source/security/security.h b/source/security/security.h old mode 100755 new mode 100644 index ef8e1273..496f2a29 --- a/source/security/security.h +++ b/source/security/security.h @@ -1,8 +1,8 @@ #ifndef UDA_SECURITY_SECURITY_H #define UDA_SECURITY_SECURITY_H -#include #include "export.h" +#include #ifdef __cplusplus extern "C" { @@ -11,43 +11,42 @@ extern "C" { #define UDA_SECURITY_VERSION 7 // Limits -#define NONCEBYTELENGTH 50 // System problem when >~ 110 ! +#define NONCEBYTELENGTH 50 // System problem when >~ 110 ! #define UDA_MAXKEY 4096 typedef enum TokenType { - NONCETEST = 0, - NONCEWEAKRANDOM = 1, - NONCESTRONGRANDOM = 2, - NONCESTRINGRANDOM = 3, + NONCETEST = 0, + NONCEWEAKRANDOM = 1, + NONCESTRONGRANDOM = 2, + NONCESTRINGRANDOM = 3, } TOKEN_TYPE; typedef enum EncryptionMethod { - NOTKNOWNKEY = 0, // Initialisation value - SHAREDPRIVATEKEY = 1, - ASYMMETRICKEY = 2, // Default + NOTKNOWNKEY = 0, // Initialisation value + SHAREDPRIVATEKEY = 1, + ASYMMETRICKEY = 2, // Default DIGITALSIGNATUREKEY = 3, - DIFFIEHELLMANKEY = 4, - CERTIFICATEKEY = 5, - NOTREQUIREDKEY = 6, // Trusted client so byepass authentication (server initiated only) + DIFFIEHELLMANKEY = 4, + CERTIFICATEKEY = 5, + NOTREQUIREDKEY = 6, // Trusted client so byepass authentication (server initiated only) } ENCRYPTION_METHOD; typedef enum AuthenticationStep { - CLIENT_ISSUE_TOKEN = 1, + CLIENT_ISSUE_TOKEN = 1, SERVER_DECRYPT_CLIENT_TOKEN = 2, SERVER_ENCRYPT_CLIENT_TOKEN = 3, - SERVER_ISSUE_TOKEN = 4, + SERVER_ISSUE_TOKEN = 4, CLIENT_DECRYPT_SERVER_TOKEN = 5, CLIENT_ENCRYPT_SERVER_TOKEN = 6, - SERVER_VERIFY_TOKEN = 7, - HOUSEKEEPING = 9, + SERVER_VERIFY_TOKEN = 7, + HOUSEKEEPING = 9, } AUTHENTICATION_STEP; LIBRARY_API int udaAuthentication(AUTHENTICATION_STEP authenticationStep, ENCRYPTION_METHOD encryptionMethod, - TOKEN_TYPE tokenType, unsigned short tokenByteLength, - gcry_sexp_t publickey, gcry_sexp_t privatekey, - gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken, - unsigned char** client_ciphertext, size_t* client_ciphertextLength, - unsigned char** server_ciphertext, size_t* server_ciphertextLength); + TOKEN_TYPE tokenType, unsigned short tokenByteLength, gcry_sexp_t publickey, + gcry_sexp_t privatekey, gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken, + unsigned char** client_ciphertext, size_t* client_ciphertextLength, + unsigned char** server_ciphertext, size_t* server_ciphertextLength); #ifdef __cplusplus } diff --git a/source/security/serverAuthentication.cpp b/source/security/serverAuthentication.cpp old mode 100755 new mode 100644 index cb1e31f3..375746cf --- a/source/security/serverAuthentication.cpp +++ b/source/security/serverAuthentication.cpp @@ -1,24 +1,25 @@ -#if defined(SERVERBUILD) || defined(TESTIDAMSECURITY) +#if defined(SERVERBUILD) || defined(TESTIDAMSECURITY) -#include "serverAuthentication.h" +# include "serverAuthentication.h" -#include -#include -#include -#ifndef TESTIDAMSECURITY -# include -# include -# include -# include -#endif +# include +# include +# include +# ifndef TESTIDAMSECURITY +# include +# include +# include +# include +# endif -#include "security.h" -#include "authenticationUtils.h" -#include "x509Utils.h" +# include "authenticationUtils.h" +# include "security.h" +# include "x509Utils.h" static const ENCRYPTION_METHOD encryptionMethod = ASYMMETRICKEY; -static const unsigned short tokenByteLength = NONCEBYTELENGTH; // System problem when >~ 110 ! -static const TOKEN_TYPE tokenType = NONCESTRONGRANDOM; // NONCESTRONGRANDOM NONCESTRINGRANDOM NONCEWEAKRANDOM NONCETEST // +static const unsigned short tokenByteLength = NONCEBYTELENGTH; // System problem when >~ 110 ! +static const TOKEN_TYPE tokenType = + NONCESTRONGRANDOM; // NONCESTRONGRANDOM NONCESTRINGRANDOM NONCEWEAKRANDOM NONCETEST // /** * Read the Server's Private Key (from a PEM file) and the User's Public Key (from the passed x509 cert) @@ -38,8 +39,8 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out int err = 0; static int initialised = FALSE; - static gcry_sexp_t privatekey = nullptr; // Server's - static gcry_sexp_t publickey = nullptr; // Client's + static gcry_sexp_t privatekey = nullptr; // Server's + static gcry_sexp_t publickey = nullptr; // Client's if (initialised) { *publickey_out = publickey; @@ -53,13 +54,13 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out char* serverPrivateKeyFile = nullptr; char* CACertFile = nullptr; - if ((env = getenv("UDA_SERVER_CERTIFICATE")) != nullptr) { // Directory with certificates and key files + if ((env = getenv("UDA_SERVER_CERTIFICATE")) != nullptr) { // Directory with certificates and key files len = strlen(env) + 56; serverPrivateKeyFile = (char*)malloc(len * sizeof(unsigned char)); CACertFile = (char*)malloc(len * sizeof(unsigned char)); - sprintf(serverPrivateKeyFile, "%s/serverskey.pem", env); // Server's - sprintf(CACertFile, "%s/carootX509.der", env); // CA Certificate for signature verification + sprintf(serverPrivateKeyFile, "%s/serverskey.pem", env); // Server's + sprintf(CACertFile, "%s/carootX509.der", env); // CA Certificate for signature verification } else { char* home = getenv("HOME"); len = 256 + strlen(home); @@ -74,38 +75,44 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out ksba_cert_t clientCert = nullptr; ksba_cert_t CACert = nullptr; - do { // Error Trap + do { // Error Trap SECURITY_BLOCK* securityBlock = &client_block->securityBlock; -// Read the Client's certificate, check validity, extract the public key + // Read the Client's certificate, check validity, extract the public key if (securityBlock->client_X509 != nullptr) { - if ((err = makeX509CertObject(securityBlock->client_X509, securityBlock->client_X509Length, - &clientCert)) != 0) { + if ((err = makeX509CertObject(securityBlock->client_X509, securityBlock->client_X509Length, &clientCert)) != + 0) { break; } - if ((err = testX509Dates(clientCert)) != 0) break; // Check the Certificate Validity + if ((err = testX509Dates(clientCert)) != 0) { + break; // Check the Certificate Validity + } if ((err = extractX509SExpKey(clientCert, &publickey)) != 0) { break; - } // get the Public key from an X509 certificate + } // get the Public key from an X509 certificate } -// get the server's Private key from a PEM file (for decryption) and convert to S-Expression + // get the server's Private key from a PEM file (for decryption) and convert to S-Expression if ((err = importPEMPrivateKey(serverPrivateKeyFile, &privatekey)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Failed to load Server's Private Key File"); break; } -// Read the CA's certificate, check date validity + // Read the CA's certificate, check date validity if (CACertFile != nullptr) { - if ((err = importX509Reader(CACertFile, &CACert)) != 0) break; - if ((err = testX509Dates(CACert)) != 0) break; + if ((err = importX509Reader(CACertFile, &CACert)) != 0) { + break; + } + if ((err = testX509Dates(CACert)) != 0) { + break; + } } -// Test the server's private key for consistency + // Test the server's private key for consistency if (gcry_pk_testkey(privatekey) != 0) { err = 999; @@ -114,9 +121,11 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out break; } -// Verify the client certificate's signature using the CA's public key + // Verify the client certificate's signature using the CA's public key - if ((err = checkX509Signature(CACert, clientCert)) != 0) break; + if ((err = checkX509Signature(CACert, clientCert)) != 0) { + break; + } ksba_cert_release(clientCert); ksba_cert_release(CACert); @@ -129,11 +138,19 @@ static int initialiseKeys(CLIENT_BLOCK* client_block, gcry_sexp_t* publickey_out free(CACertFile); if (err != 0) { - if (privatekey != nullptr) gcry_sexp_release(privatekey); - if (publickey != nullptr) gcry_sexp_release(publickey); - if (clientCert != nullptr) ksba_cert_release(clientCert); - if (CACert != nullptr) ksba_cert_release(CACert); // BUG in ksba library# ksba_free ! - privatekey = nullptr; // These are declared as static so ensure reset when an error occurs + if (privatekey != nullptr) { + gcry_sexp_release(privatekey); + } + if (publickey != nullptr) { + gcry_sexp_release(publickey); + } + if (clientCert != nullptr) { + ksba_cert_release(clientCert); + } + if (CACert != nullptr) { + ksba_cert_release(CACert); // BUG in ksba library# ksba_free ! + } + privatekey = nullptr; // These are declared as static so ensure reset when an error occurs publickey = nullptr; return err; } @@ -155,15 +172,16 @@ static SECURITY_BLOCK* receiveSecurityBlock(CLIENT_BLOCK* client_block, LOGMALLO { UDA_LOG(UDA_LOG_DEBUG, "Waiting for Initial Client Block\n"); -#ifndef TESTIDAMSECURITY +# ifndef TESTIDAMSECURITY if (!xdrrec_skiprecord(serverInput)) { UDA_LOG(UDA_LOG_DEBUG, "xdrrec_skiprecord error!\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, UDA_PROTOCOL_ERROR_5, "Protocol 5 Error (Client Block #2)"); } else { - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block int err = 0; - if ((err = protocol2(serverInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, client_block)) != 0) { + if ((err = protocol2(serverInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, + client_block)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block #2)"); UDA_LOG(UDA_LOG_DEBUG, "protocol error! Client Block not received!\n"); } @@ -174,10 +192,10 @@ static SECURITY_BLOCK* receiveSecurityBlock(CLIENT_BLOCK* client_block, LOGMALLO } } -// Flush (mark as at EOF) the input socket buffer (not all client state data may have been read - version dependent) + // Flush (mark as at EOF) the input socket buffer (not all client state data may have been read - version dependent) xdrrec_eof(serverInput); -#endif +# endif return &client_block->securityBlock; } @@ -209,11 +227,8 @@ static int decryptClientToken(CLIENT_BLOCK* client_block, LOGMALLOCLIST* logmall // Decrypt token (A) - err = udaAuthentication(SERVER_DECRYPT_CLIENT_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(SERVER_DECRYPT_CLIENT_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, + privatekey, client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -245,11 +260,8 @@ static int encryptClientToken(SERVER_BLOCK* server_block, gcry_sexp_t publickey, size_t client_ciphertextLength = 0; size_t server_ciphertextLength = 0; - err = udaAuthentication(SERVER_ENCRYPT_CLIENT_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(SERVER_ENCRYPT_CLIENT_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, + privatekey, client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -267,12 +279,14 @@ static int encryptClientToken(SERVER_BLOCK* server_block, gcry_sexp_t publickey, return err; } -static int issueToken(SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - gcry_sexp_t publickey, gcry_sexp_t privatekey, gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) +static int issueToken(SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, gcry_sexp_t publickey, gcry_sexp_t privatekey, + gcry_mpi_t* client_mpiToken, gcry_mpi_t* server_mpiToken) { int err = 0; //--------------------------------------------------------------------------------------------------------------- - // Step 4: Server issues a new token (B) also encrypted with the client's public key (->EBCP), passes both to client. + // Step 4: Server issues a new token (B) also encrypted with the client's public key (->EBCP), passes both to + // client. // Generate new Token and Encrypt (B) @@ -281,11 +295,8 @@ static int issueToken(SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, size_t client_ciphertextLength = 0; size_t server_ciphertextLength = 0; - err = udaAuthentication(SERVER_ISSUE_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(SERVER_ISSUE_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, privatekey, + client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -300,17 +311,18 @@ static int issueToken(SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, securityBlock->server_ciphertext = server_ciphertext; securityBlock->server_ciphertextLength = (unsigned short)server_ciphertextLength; -#ifndef TESTIDAMSECURITY +# ifndef TESTIDAMSECURITY int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; - if ((err = protocol2(serverOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, server_block)) != 0) { + if ((err = protocol2(serverOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, + server_block)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (securityBlock #4)"); } if (!xdrrec_endofrecord(serverOutput, 1)) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, UDA_PROTOCOL_ERROR_7, "Protocol 7 Error (Server Block)"); } -#endif +# endif return err; } @@ -327,7 +339,7 @@ static int verifyToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_block, L // Receive the encrypted token (B) from the client -#ifndef TESTIDAMSECURITY +# ifndef TESTIDAMSECURITY int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; if (!xdrrec_skiprecord(serverInput)) { @@ -335,13 +347,14 @@ static int verifyToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_block, L UDA_THROW_ERROR(UDA_PROTOCOL_ERROR_5, "Protocol 5 Error (Client Block #7)"); } - if ((err = protocol2(serverInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, client_block)) != 0) { + if ((err = protocol2(serverInput, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, + client_block)) != 0) { UDA_THROW_ERROR(err, "Protocol 11 Error (securityBlock #7)"); } // Flush (mark as at EOF) the input socket buffer (not all client state data may have been read - version dependent) xdrrec_eof(serverInput); -#endif +# endif SECURITY_BLOCK* securityBlock = &client_block->securityBlock; @@ -356,11 +369,8 @@ static int verifyToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_block, L // Decrypt token (B) and Authenticate the Client - err = udaAuthentication(SERVER_VERIFY_TOKEN, encryptionMethod, - tokenType, tokenByteLength, - publickey, privatekey, - client_mpiToken, server_mpiToken, - &client_ciphertext, &client_ciphertextLength, + err = udaAuthentication(SERVER_VERIFY_TOKEN, encryptionMethod, tokenType, tokenByteLength, publickey, privatekey, + client_mpiToken, server_mpiToken, &client_ciphertext, &client_ciphertextLength, &server_ciphertext, &server_ciphertextLength); if (err != 0) { @@ -377,17 +387,18 @@ static int verifyToken(SERVER_BLOCK* server_block, CLIENT_BLOCK* client_block, L securityBlock->client_ciphertext = client_ciphertext; securityBlock->client_ciphertextLength = (unsigned short)client_ciphertextLength; -#ifndef TESTIDAMSECURITY +# ifndef TESTIDAMSECURITY protocol_id = UDA_PROTOCOL_SERVER_BLOCK; - if ((err = protocol2(serverOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, server_block)) != 0) { + if ((err = protocol2(serverOutput, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, + server_block)) != 0) { UDA_THROW_ERROR(err, "Protocol 10 Error (securityBlock #7)"); } if (!xdrrec_endofrecord(serverOutput, 1)) { UDA_THROW_ERROR(UDA_PROTOCOL_ERROR_7, "Protocol 7 Error (Server Block #7)"); } -#endif +# endif return err; } @@ -411,7 +422,8 @@ int serverAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, switch (authenticationStep) { case SERVER_DECRYPT_CLIENT_TOKEN: - err = decryptClientToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = decryptClientToken(client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, + &client_mpiToken, &server_mpiToken); break; case SERVER_ENCRYPT_CLIENT_TOKEN: @@ -419,18 +431,24 @@ int serverAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, break; case SERVER_ISSUE_TOKEN: - err = issueToken(server_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = issueToken(server_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, + &server_mpiToken); break; case SERVER_VERIFY_TOKEN: - err = verifyToken(server_block, client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, &client_mpiToken, &server_mpiToken); + err = verifyToken(server_block, client_block, logmalloclist, userdefinedtypelist, publickey, privatekey, + &client_mpiToken, &server_mpiToken); break; case HOUSEKEEPING: free(privatekey); free(publickey); - if (client_mpiToken != nullptr) gcry_mpi_release(client_mpiToken); - if (server_mpiToken != nullptr) gcry_mpi_release(server_mpiToken); + if (client_mpiToken != nullptr) { + gcry_mpi_release(client_mpiToken); + } + if (server_mpiToken != nullptr) { + gcry_mpi_release(server_mpiToken); + } break; default: @@ -438,11 +456,15 @@ int serverAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, } if (err != 0) { - if (client_mpiToken != nullptr) gcry_mpi_release(client_mpiToken); - if (server_mpiToken != nullptr) gcry_mpi_release(server_mpiToken); + if (client_mpiToken != nullptr) { + gcry_mpi_release(client_mpiToken); + } + if (server_mpiToken != nullptr) { + gcry_mpi_release(server_mpiToken); + } } return err; } -#endif // SERVERBUILD || TESTIDAMSECURITY +#endif // SERVERBUILD || TESTIDAMSECURITY diff --git a/source/security/serverAuthentication.h b/source/security/serverAuthentication.h old mode 100755 new mode 100644 index b299c573..39b6a29c --- a/source/security/serverAuthentication.h +++ b/source/security/serverAuthentication.h @@ -2,8 +2,8 @@ #define UDA_SECURITY_SERVERAUTHENTICATION_H #include "export.h" -#include "udaStructs.h" #include "genStructs.h" +#include "udaStructs.h" #include "security.h" @@ -11,12 +11,12 @@ extern "C" { #endif -LIBRARY_API int serverAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist, AUTHENTICATION_STEP authenticationStep); +LIBRARY_API int serverAuthentication(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, + AUTHENTICATION_STEP authenticationStep); #ifdef __cplusplus } #endif #endif // UDA_SECURITY_SERVERAUTHENTICATION_H - diff --git a/source/security/x509Utils.cpp b/source/security/x509Utils.cpp old mode 100755 new mode 100644 index 9103398b..08c4893f --- a/source/security/x509Utils.cpp +++ b/source/security/x509Utils.cpp @@ -7,19 +7,16 @@ #include "security.h" -#define digitp(p) (*(p) >= '0' && *(p) <= '9') -#define xfree(a) ksba_free(a) +#define digitp(p) (*(p) >= '0' && *(p) <= '9') +#define xfree(a) ksba_free(a) #define xtrymalloc(a) gcry_malloc((a)) -#define HASH_FNC ((void(*)(void *, const void *, size_t))gcry_md_write) -#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define HASH_FNC ((void (*)(void*, const void*, size_t))gcry_md_write) +#define DIM(v) (sizeof(v) / sizeof((v)[0])) -#define hexdigitp(a) (digitp (a) \ - || (*(a) >= 'A' && *(a) <= 'F') \ - || (*(a) >= 'a' && *(a) <= 'f')) -#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ - *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) -#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) +#define hexdigitp(a) (digitp(a) || (*(a) >= 'A' && *(a) <= 'F') || (*(a) >= 'a' && *(a) <= 'f')) +#define xtoi_1(p) (*(p) <= '9' ? (*(p) - '0') : *(p) <= 'F' ? (*(p) - 'A' + 10) : (*(p) - 'a' + 10)) +#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p) + 1)) //======================================================================================================== // Components taken from @@ -44,12 +41,7 @@ */ /* ASN.1 classes. */ -enum { - UNIVERSAL = 0, - APPLICATION = 1, - ASNCONTEXT = 2, - PRIVATE = 3 -}; +enum { UNIVERSAL = 0, APPLICATION = 1, ASNCONTEXT = 2, PRIVATE = 3 }; /* ASN.1 tags. */ enum { @@ -90,8 +82,8 @@ struct tag_info { unsigned long tag; /* The tag of the object. */ unsigned long length; /* Length of the values. */ int nhdr; /* Length of the header (TL). */ - unsigned int ndef:1; /* The object has an indefinite length. */ - unsigned int cons:1; /* This is a constructed object. */ + unsigned int ndef : 1; /* The object has an indefinite length. */ + unsigned int cons : 1; /* This is a constructed object. */ }; /* Return the number of bits of the Q parameter from the DSA key @@ -318,13 +310,13 @@ static void* read_file(FILE* fp, int decode, size_t* r_length) for (s = buffer, p = buffer, nread = 0; nread + 1 < buflen; s += 2, nread += 2) { if (!hexdigitp(s) || !hexdigitp(s + 1)) { gcry_free(buffer); - return nullptr; /* Invalid hex digits. */ + return nullptr; /* Invalid hex digits. */ } *(unsigned char*)p++ = xtoi_2(s); } if (nread != buflen) { gcry_free(buffer); - return nullptr; /* Odd number of hex digits. */ + return nullptr; /* Odd number of hex digits. */ } buflen = p - buffer; } @@ -342,26 +334,21 @@ static void* read_file(FILE* fp, int decode, size_t* r_length) */ static int base64_decode(char* buffer, size_t length, size_t* newLength) { - static unsigned char const asctobin[128] = - { - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, - 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, - 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, - 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, - 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff - }; + static unsigned char const asctobin[128] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, + 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, + 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, + 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0xff, 0xff, 0xff, 0xff, 0xff}; int err = 0; int idx = 0; unsigned char val = 0; int c = 0; - char* d, * s; + char *d, *s; int lfseen = 1; *newLength = 0; @@ -369,7 +356,8 @@ static int base64_decode(char* buffer, size_t length, size_t* newLength) /* Find BEGIN line. */ for (s = buffer; length; length--, s++) { if (lfseen && *s == '-' && length > 11 && !memcmp(s, "-----BEGIN ", 11)) { - for (; length && *s != '\n'; length--, s++); + for (; length && *s != '\n'; length--, s++) + ; break; } lfseen = (*s == '\n'); @@ -393,7 +381,7 @@ static int base64_decode(char* buffer, size_t length, size_t* newLength) if ((*s & 0x80) || (c = asctobin[*(unsigned char*)s]) == 0xff) { err = 999; - //die ("invalid base64 character %02X at pos %d detected\n", *(unsigned char*)s, (int)(s-buffer)); + // die ("invalid base64 character %02X at pos %d detected\n", *(unsigned char*)s, (int)(s-buffer)); return err; } @@ -478,20 +466,21 @@ static int parse_tag(unsigned char const** buffer, size_t* buflen, struct tag_in length--; ti->nhdr++; - if (!(c & 0x80)) + if (!(c & 0x80)) { ti->length = c; - else if (c == 0x80) + } else if (c == 0x80) { ti->ndef = 1; - else if (c == 0xff) + } else if (c == 0xff) { return -1; /* Forbidden length value. */ - else { + } else { unsigned long len = 0; int count = c & 0x7f; for (; count; count--) { len <<= 8; - if (!length) + if (!length) { return -1; /* Premature EOF. */ + } c = *buf++; length--; ti->nhdr++; @@ -500,11 +489,13 @@ static int parse_tag(unsigned char const** buffer, size_t* buflen, struct tag_in ti->length = len; } - if (ti->class == UNIVERSAL && !ti->tag) + if (ti->class == UNIVERSAL && !ti->tag) { ti->length = 0; + } - if (ti->length > length) + if (ti->length > length) { return -1; /* Data larger than buffer. */ + } *buffer = buf; *buflen = length; @@ -585,14 +576,14 @@ int extractX509SExpKey(ksba_cert_t cert, gcry_sexp_t* key_sexp) UDA_THROW_ERROR(999, "Failure to get the Public key!"); } -// Get the length of the canonical S-Expression (public key) + // Get the length of the canonical S-Expression (public key) if ((n = gcry_sexp_canon_len(p, 0, nullptr, nullptr)) == 0) { ksba_free(p); UDA_THROW_ERROR(999, "did not return a proper S-Exp!"); } -// Create an internal S-Expression from the external representation + // Create an internal S-Expression from the external representation if (gcry_sexp_sscan(key_sexp, nullptr, (char*)p, n) != 0) { ksba_free(p); @@ -652,18 +643,18 @@ int testX509Dates(ksba_cert_t certificate) { int err = 0; ksba_isotime_t startDateTime = {}; - ksba_isotime_t endDateTime = {}; // ISO format referenced from UTC + ksba_isotime_t endDateTime = {}; // ISO format referenced from UTC ksba_cert_get_validity(certificate, 0, startDateTime); ksba_cert_get_validity(certificate, 1, endDateTime); -// Current Date and Time + // Current Date and Time - time_t calendar; // Simple Calendar Date & Time - struct tm* broken; // Broken Down calendar Time - static char datetime[DATELENGTH]; // The Calendar Time as a formatted String + time_t calendar; // Simple Calendar Date & Time + struct tm* broken; // Broken Down calendar Time + static char datetime[DATELENGTH]; // The Calendar Time as a formatted String -// Calendar Time + // Calendar Time time(&calendar); broken = gmtime(&calendar); @@ -676,13 +667,13 @@ int testX509Dates(ksba_cert_t certificate) convertNonPrintable2(datetime); TrimString(datetime); -// Year + // Year char work[56]; sprintf(work, "%.4d%.2d%.2dT%.2d%.2d%.2d", broken->tm_year + 1900, broken->tm_mon + 1, broken->tm_mday, broken->tm_hour, broken->tm_min, broken->tm_sec); - if ((strcmp(work, startDateTime) <= 0) || (strcmp(endDateTime, work) <= 0)) { // dates are in ascending order + if ((strcmp(work, startDateTime) <= 0) || (strcmp(endDateTime, work) <= 0)) { // dates are in ascending order UDA_THROW_ERROR(999, "X509 Certificate is Invalid: Time Expired!"); } @@ -702,38 +693,38 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) const char* algoid = nullptr; -// Extract the digest algorithm OID used for the signature + // Extract the digest algorithm OID used for the signature if ((algoid = ksba_cert_get_digest_algo(cert)) == nullptr) { UDA_THROW_ERROR(999, "unknown digest algorithm OID"); } -// Map the algorithm OID to an algorithm identifier + // Map the algorithm OID to an algorithm identifier int algo; if ((algo = gcry_md_map_name(algoid)) == 0) { UDA_THROW_ERROR(999, "unknown digest algorithm identifier"); } -// Create a new digest object with the same algorithm as the certificate signature + // Create a new digest object with the same algorithm as the certificate signature gcry_md_hd_t md; if (gcry_md_open(&md, algo, 0) != 0) { UDA_THROW_ERROR(999, "md_open failed!"); } -// Hash the certificate + // Hash the certificate if (ksba_cert_hash(cert, 1, HASH_FNC, md) != 0) { gcry_md_close(md); UDA_THROW_ERROR(999, "cert hash failed!"); } -// Finalise the digest calculation + // Finalise the digest calculation gcry_md_final(md); -// Get the certificate signature + // Get the certificate signature ksba_sexp_t p; if ((p = ksba_cert_get_sig_val(cert)) == nullptr) { @@ -741,7 +732,7 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) UDA_THROW_ERROR(999, "Failure to get the certificate signature!"); } -// Get the length of the canonical S-Expression (certificate signature) + // Get the length of the canonical S-Expression (certificate signature) size_t n; if ((n = gcry_sexp_canon_len(p, 0, nullptr, nullptr)) == 0) { @@ -750,7 +741,7 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) UDA_THROW_ERROR(999, "libksba did not return a proper S-Exp!"); } -// Create an internal S-Expression from the external representation + // Create an internal S-Expression from the external representation gcry_sexp_t s_sig; if (gcry_sexp_sscan(&s_sig, nullptr, (char*)p, n) != 0) { @@ -760,14 +751,14 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) ksba_free(p); -// Get the CA Public key + // Get the CA Public key if ((p = ksba_cert_get_public_key(issuer_cert)) == nullptr) { gcry_md_close(md); UDA_THROW_ERROR(999, "Failure to get the Public key!"); } -// Get the length of the canonical S-Expression (public key) + // Get the length of the canonical S-Expression (public key) if ((n = gcry_sexp_canon_len(p, 0, nullptr, nullptr)) == 0) { gcry_md_close(md); @@ -776,7 +767,7 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) UDA_THROW_ERROR(999, "libksba did not return a proper S-Exp!"); } -// Create an internal S-Expression from the external representation + // Create an internal S-Expression from the external representation gcry_sexp_t s_pkey; if (gcry_sexp_sscan(&s_pkey, nullptr, (char*)p, n) != 0) { @@ -797,14 +788,14 @@ int checkX509Signature(ksba_cert_t issuer_cert, ksba_cert_t cert) UDA_THROW_ERROR(999, "do_encode_md failed!"); } -// put hash into the S-Exp s_hash + // put hash into the S-Exp s_hash gcry_sexp_t s_hash; gcry_sexp_build(&s_hash, nullptr, "%m", frame); gcry_mpi_release(frame); -// Verify the signature, data, public key + // Verify the signature, data, public key if (gcry_pk_verify(s_sig, s_hash, s_pkey) != 0) { UDA_THROW_ERROR(999, "Signature verification failed!"); @@ -852,7 +843,7 @@ int importPEMPrivateKey(const char* keyFile, gcry_sexp_t* key_sexp) UDA_THROW_ERROR(err, "Failed to decode private key buffer"); } -// Parse the ASN.1 structure. + // Parse the ASN.1 structure. const unsigned char* der = (const unsigned char*)buffer; size_t derlen = buflen; @@ -903,15 +894,15 @@ int importPEMPrivateKey(const char* keyFile, gcry_sexp_t* key_sexp) gcry_free(buffer); -// Convert from OpenSSL parameter ordering to the OpenPGP order. -// First check that p < q; if not swap p and q and recompute u. + // Convert from OpenSSL parameter ordering to the OpenPGP order. + // First check that p < q; if not swap p and q and recompute u. if (gcry_mpi_cmp(keyparms[3], keyparms[4]) > 0) { gcry_mpi_swap(keyparms[3], keyparms[4]); gcry_mpi_invm(keyparms[7], keyparms[3], keyparms[4]); } -// Build the S-expression. + // Build the S-expression. gcry_error_t gerr = gcry_sexp_build(&s_key, nullptr, "(private-key(rsa(n%m)(e%m)(d%m)(p%m)(q%m)(u%m)))", keyparms[0], keyparms[1], keyparms[2], keyparms[3], keyparms[4], keyparms[7]); @@ -976,7 +967,7 @@ int importPEMPublicKey(char* keyFile, gcry_sexp_t* key_sexp) UDA_THROW_ERROR(err, "Failed to parse tag from public key buffer"); } -// We skip the description of the key parameters and assume it is RSA. + // We skip the description of the key parameters and assume it is RSA. der += ti.length; derlen -= ti.length; @@ -994,7 +985,7 @@ int importPEMPublicKey(char* keyFile, gcry_sexp_t* key_sexp) der += 1; derlen -= 1; -// Parse the BIT string. + // Parse the BIT string. if (parse_tag(&der, &derlen, &ti) || ti.tag != TAG_SEQUENCE || ti.class || !ti.cons || ti.ndef) { gcry_free(buffer); @@ -1039,7 +1030,9 @@ int importPEMPublicKey(char* keyFile, gcry_sexp_t* key_sexp) UDA_THROW_ERROR(err, gcry_strerror(gerr)); } - for (idx = 0; idx < n_keyparms; idx++) gcry_mpi_release(keyparms[idx]); + for (idx = 0; idx < n_keyparms; idx++) { + gcry_mpi_release(keyparms[idx]); + } *key_sexp = s_key; diff --git a/source/security/x509Utils.h b/source/security/x509Utils.h old mode 100755 new mode 100644 index b54a9578..c02fb3ac --- a/source/security/x509Utils.h +++ b/source/security/x509Utils.h @@ -1,8 +1,8 @@ #ifndef UDA_X509UTILS_H #define UDA_X509UTILS_H -#include #include +#include #include "export.h" @@ -23,4 +23,4 @@ LIBRARY_API int importPEMPublicKey(char* keyFile, gcry_sexp_t* key_sexp); } #endif -#endif //UDA_X509UTILS_H +#endif // UDA_X509UTILS_H diff --git a/source/serialisation/capnp_serialisation.cpp b/source/serialisation/capnp_serialisation.cpp index 21fd5fe8..ae948921 100644 --- a/source/serialisation/capnp_serialisation.cpp +++ b/source/serialisation/capnp_serialisation.cpp @@ -1,38 +1,40 @@ #include "capnp_serialisation.h" -#include +#include #include #include -#include -#include -#include -#include #include -#include #include +#include +#include +#include +#include +#include #include "udaTypes.h" #include "schema.capnp.h" -namespace { - -class PackedMessageStreamReader : public capnp::MessageReader { -public: - PackedMessageStreamReader(const char *bytes, size_t size, capnp::ReaderOptions options) - : capnp::MessageReader{options}, - in_{kj::ArrayPtr{reinterpret_cast(bytes), size}}, reader_{in_, options} {} +namespace +{ - kj::ArrayPtr getSegment(capnp::uint id) override { - return reader_.getSegment(id); +class PackedMessageStreamReader : public capnp::MessageReader +{ + public: + PackedMessageStreamReader(const char* bytes, size_t size, capnp::ReaderOptions options) + : capnp::MessageReader{options}, + in_{kj::ArrayPtr{reinterpret_cast(bytes), size}}, reader_{in_, options} + { } -private: + kj::ArrayPtr getSegment(capnp::uint id) override { return reader_.getSegment(id); } + + private: kj::ArrayInputStream in_; capnp::PackedMessageReader reader_; }; -} // anon namespace +} // namespace std::ostream& operator<<(std::ostream& out, const kj::ArrayPtr<::kj::byte> bytes) { @@ -45,18 +47,30 @@ std::ostream& operator<<(std::ostream& out, const kj::ArrayPtr<::kj::byte> bytes const char* to_string(::TreeNode::Type type) { switch (type) { - case ::TreeNode::Type::INT8: return "int8"; - case ::TreeNode::Type::INT16: return "int16"; - case ::TreeNode::Type::INT32: return "int32"; - case ::TreeNode::Type::INT64: return "int64"; - case ::TreeNode::Type::UINT8: return "uint8"; - case ::TreeNode::Type::UINT16: return "uint16"; - case ::TreeNode::Type::UINT32: return "uint32"; - case ::TreeNode::Type::UINT64: return "uint64"; - case ::TreeNode::Type::FLT32: return "flt32"; - case ::TreeNode::Type::FLT64: return "flt64"; - case ::TreeNode::Type::STRING: return "string"; - case ::TreeNode::Type::VOID: return "void"; + case ::TreeNode::Type::INT8: + return "int8"; + case ::TreeNode::Type::INT16: + return "int16"; + case ::TreeNode::Type::INT32: + return "int32"; + case ::TreeNode::Type::INT64: + return "int64"; + case ::TreeNode::Type::UINT8: + return "uint8"; + case ::TreeNode::Type::UINT16: + return "uint16"; + case ::TreeNode::Type::UINT32: + return "uint32"; + case ::TreeNode::Type::UINT64: + return "uint64"; + case ::TreeNode::Type::FLT32: + return "flt32"; + case ::TreeNode::Type::FLT64: + return "flt64"; + case ::TreeNode::Type::STRING: + return "string"; + case ::TreeNode::Type::VOID: + return "void"; } return ""; } @@ -77,8 +91,7 @@ std::ostream& operator<<(std::ostream& out, const typename capnp::List -std::ostream& operator<<(std::ostream& out, gsl::span span) +template std::ostream& operator<<(std::ostream& out, gsl::span span) { const char* delim = ""; int count = 0; @@ -94,15 +107,13 @@ std::ostream& operator<<(std::ostream& out, gsl::span span) return out; } -template -void print_slices(std::ostream& out, capnp::List::Reader& slices) +template void print_slices(std::ostream& out, capnp::List::Reader& slices) { slices.size(); slices[0].size(); } -template -void print_data(std::ostream& out, ::TreeNode::Array::Reader& array, const std::string& indent) +template void print_data(std::ostream& out, ::TreeNode::Array::Reader& array, const std::string& indent) { auto data = array.getData(); auto slices = data.getSlices(); @@ -121,8 +132,7 @@ void print_data(std::ostream& out, ::TreeNode::Array::Reader& array, const std:: } } -template <> -void print_data(std::ostream& out, ::TreeNode::Array::Reader& array, const std::string& indent) +template <> void print_data(std::ostream& out, ::TreeNode::Array::Reader& array, const std::string& indent) { auto data = array.getData(); auto slices = data.getSlices(); @@ -138,8 +148,7 @@ void print_data(std::ostream& out, ::TreeNode::Array::Reader& array void print_node(std::ostream& out, const ::TreeNode::Reader& tree, const std::string& indent = "") { - out << indent << "{\n " - << indent << "name: " << tree.getName().cStr() << "\n"; + out << indent << "{\n " << indent << "name: " << tree.getName().cStr() << "\n"; if (tree.hasChildren()) { for (auto child : tree.getChildren()) { @@ -150,18 +159,42 @@ void print_node(std::ostream& out, const ::TreeNode::Reader& tree, const std::st auto array = tree.getArray(); switch (array.getType()) { - case ::TreeNode::Type::FLT32: print_data(out, array, indent); break; - case ::TreeNode::Type::FLT64: print_data(out, array, indent); break; - case ::TreeNode::Type::INT8: print_data(out, array, indent); break; - case ::TreeNode::Type::INT16: print_data(out, array, indent); break; - case ::TreeNode::Type::INT32: print_data(out, array, indent); break; - case ::TreeNode::Type::INT64: print_data(out, array, indent); break; - case ::TreeNode::Type::UINT8: print_data(out, array, indent); break; - case ::TreeNode::Type::UINT16: print_data(out, array, indent); break; - case ::TreeNode::Type::UINT32: print_data(out, array, indent); break; - case ::TreeNode::Type::UINT64: print_data(out, array, indent); break; - case ::TreeNode::Type::STRING: print_data(out, array, indent); break; - case ::TreeNode::Type::VOID: out << indent << " data: \n"; break; + case ::TreeNode::Type::FLT32: + print_data(out, array, indent); + break; + case ::TreeNode::Type::FLT64: + print_data(out, array, indent); + break; + case ::TreeNode::Type::INT8: + print_data(out, array, indent); + break; + case ::TreeNode::Type::INT16: + print_data(out, array, indent); + break; + case ::TreeNode::Type::INT32: + print_data(out, array, indent); + break; + case ::TreeNode::Type::INT64: + print_data(out, array, indent); + break; + case ::TreeNode::Type::UINT8: + print_data(out, array, indent); + break; + case ::TreeNode::Type::UINT16: + print_data(out, array, indent); + break; + case ::TreeNode::Type::UINT32: + print_data(out, array, indent); + break; + case ::TreeNode::Type::UINT64: + print_data(out, array, indent); + break; + case ::TreeNode::Type::STRING: + print_data(out, array, indent); + break; + case ::TreeNode::Type::VOID: + out << indent << " data: \n"; + break; } out << indent << " type: " << to_string(array.getType()) << "\n"; @@ -172,7 +205,6 @@ void print_node(std::ostream& out, const ::TreeNode::Reader& tree, const std::st out << indent << "}"; } - std::ostream& operator<<(std::ostream& out, const ::TreeNode::Reader& tree) { print_node(out, tree); @@ -186,7 +218,7 @@ struct NodeReader { struct TreeReader { std::shared_ptr message_reader; NodeReader* root = nullptr; - std::vector> nodes= {}; + std::vector> nodes = {}; }; struct NodeBuilder { @@ -196,7 +228,7 @@ struct NodeBuilder { struct TreeBuilder { std::shared_ptr message_builder = {}; NodeBuilder* root = nullptr; - std::vector> nodes= {}; + std::vector> nodes = {}; }; Buffer uda_capnp_serialise(TreeBuilder* tree) @@ -208,7 +240,7 @@ Buffer uda_capnp_serialise(TreeBuilder* tree) char* buffer = (char*)malloc(bytes.size()); memcpy(buffer, bytes.begin(), bytes.size()); - return Buffer{ buffer, bytes.size() }; + return Buffer{buffer, bytes.size()}; } TreeReader* uda_capnp_deserialise(const char* bytes, size_t size) @@ -217,8 +249,8 @@ TreeReader* uda_capnp_deserialise(const char* bytes, size_t size) options.traversalLimitInWords = std::numeric_limits::max() / 8; auto message_reader = std::make_shared(bytes, size, options); auto root = message_reader->getRoot(); - auto tree = new TreeReader{ message_reader, nullptr }; - tree->nodes.emplace_back(std::make_unique(NodeReader{ root })); + auto tree = new TreeReader{message_reader, nullptr}; + tree->nodes.emplace_back(std::make_unique(NodeReader{root})); tree->root = tree->nodes.back().get(); return tree; @@ -227,7 +259,7 @@ TreeReader* uda_capnp_deserialise(const char* bytes, size_t size) TreeBuilder* uda_capnp_new_tree() { auto message_builder = std::make_shared(); - return new TreeBuilder{message_builder, {} }; + return new TreeBuilder{message_builder, {}}; } void uda_capnp_free_tree_builder(TreeBuilder* tree) @@ -245,7 +277,7 @@ NodeBuilder* uda_capnp_get_root(TreeBuilder* tree) if (tree->root == nullptr) { assert(tree->nodes.empty()); auto node = tree->message_builder->initRoot(); - tree->nodes.emplace_back(std::make_unique(NodeBuilder{node })); + tree->nodes.emplace_back(std::make_unique(NodeBuilder{node})); tree->root = tree->nodes.back().get(); } @@ -275,12 +307,11 @@ NodeBuilder* uda_capnp_get_child(TreeBuilder* tree, NodeBuilder* node, size_t in return nullptr; } auto child = children[index]; - tree->nodes.emplace_back(std::make_unique(NodeBuilder{child })); + tree->nodes.emplace_back(std::make_unique(NodeBuilder{child})); return tree->nodes.back().get(); } -template -struct TreeNodeTypeConverter { +template struct TreeNodeTypeConverter { static TreeNode::Type type; }; @@ -308,11 +339,13 @@ void uda_capnp_add_md_array(NodeBuilder* node, const T* data_ptr, size_t* shape_ auto array = node->node.initArray(); array.setType(TreeNodeTypeConverter::type); - size_t size = std::accumulate(shape_array, shape_array+rank, 1, std::multiplies()); + size_t size = std::accumulate(shape_array, shape_array + rank, 1, std::multiplies()); array.setLen(size); auto shape = array.initShape(rank); - for (unsigned int i=0; i ptr = { - reinterpret_cast(data_ptr) + offset, - data_stored - }; + kj::ArrayPtr ptr = {reinterpret_cast(data_ptr) + offset, data_stored}; slices.set(slice_num, ptr); data_size -= data_stored; offset += data_stored; @@ -397,8 +427,7 @@ void uda_capnp_add_md_array_char(NodeBuilder* node, const char* data, size_t* sh return uda_capnp_add_md_array(node, data, shape_array, rank); } -template -void uda_capnp_add_array(NodeBuilder* node, const T* data_ptr, size_t size) +template void uda_capnp_add_array(NodeBuilder* node, const T* data_ptr, size_t size) { assert(!node->node.isChildren()); auto array = node->node.initArray(); @@ -419,10 +448,7 @@ void uda_capnp_add_array(NodeBuilder* node, const T* data_ptr, size_t size) while (data_size != 0) { size_t data_stored = std::min(data_size, max_slice_size); - kj::ArrayPtr ptr = { - reinterpret_cast(data_ptr) + offset, - data_stored - }; + kj::ArrayPtr ptr = {reinterpret_cast(data_ptr) + offset, data_stored}; slices.set(slice_num, ptr); data_size -= data_stored; offset += data_stored; @@ -490,8 +516,7 @@ void uda_capnp_add_array_char(NodeBuilder* node, const char* data, size_t size) return uda_capnp_add_array(node, data, size); } -template -void uda_capnp_add_scalar(NodeBuilder* node, T scalar) +template void uda_capnp_add_scalar(NodeBuilder* node, T scalar) { assert(!node->node.isChildren()); auto array = node->node.initArray(); @@ -588,7 +613,7 @@ NodeReader* uda_capnp_read_child(TreeReader* tree, NodeReader* node, const char* for (auto child : node->node.getChildren()) { std::string s_name = child.getName().cStr(); if (s_name == name) { - tree->nodes.emplace_back(std::make_unique(NodeReader{ child })); + tree->nodes.emplace_back(std::make_unique(NodeReader{child})); return tree->nodes.back().get(); } } @@ -602,7 +627,7 @@ NodeReader* uda_capnp_read_child_n(TreeReader* tree, NodeReader* node, size_t in return nullptr; } auto child = children[index]; - tree->nodes.emplace_back(std::make_unique(NodeReader{ child })); + tree->nodes.emplace_back(std::make_unique(NodeReader{child})); return tree->nodes.back().get(); } @@ -618,28 +643,40 @@ int uda_capnp_read_type(NodeReader* node) } auto type = node->node.getArray().getType(); switch (type) { - case TreeNode::Type::INT8: return UDA_TYPE_CHAR; - case TreeNode::Type::INT16: return UDA_TYPE_SHORT; - case TreeNode::Type::INT32: return UDA_TYPE_INT; - case TreeNode::Type::INT64: return UDA_TYPE_LONG64; - case TreeNode::Type::UINT8: return UDA_TYPE_UNSIGNED_CHAR; - case TreeNode::Type::UINT16: return UDA_TYPE_UNSIGNED_SHORT; - case TreeNode::Type::UINT32: return UDA_TYPE_UNSIGNED_INT; - case TreeNode::Type::UINT64: return UDA_TYPE_UNSIGNED_LONG64; - case TreeNode::Type::FLT32: return UDA_TYPE_FLOAT; - case TreeNode::Type::FLT64: return UDA_TYPE_DOUBLE; - case TreeNode::Type::STRING: return UDA_TYPE_STRING; - default: return UDA_TYPE_UNKNOWN; + case TreeNode::Type::INT8: + return UDA_TYPE_CHAR; + case TreeNode::Type::INT16: + return UDA_TYPE_SHORT; + case TreeNode::Type::INT32: + return UDA_TYPE_INT; + case TreeNode::Type::INT64: + return UDA_TYPE_LONG64; + case TreeNode::Type::UINT8: + return UDA_TYPE_UNSIGNED_CHAR; + case TreeNode::Type::UINT16: + return UDA_TYPE_UNSIGNED_SHORT; + case TreeNode::Type::UINT32: + return UDA_TYPE_UNSIGNED_INT; + case TreeNode::Type::UINT64: + return UDA_TYPE_UNSIGNED_LONG64; + case TreeNode::Type::FLT32: + return UDA_TYPE_FLOAT; + case TreeNode::Type::FLT64: + return UDA_TYPE_DOUBLE; + case TreeNode::Type::STRING: + return UDA_TYPE_STRING; + default: + return UDA_TYPE_UNKNOWN; } } Optional_Size_t uda_capnp_read_rank(NodeReader* node) { if (!node->node.isArray()) { - return { false, 0 }; + return {false, 0}; } auto array = node->node.getArray(); - return { true, array.getShape().size() }; + return {true, array.getShape().size()}; } bool uda_capnp_read_shape(NodeReader* node, size_t* shape) diff --git a/source/serialisation/capnp_serialisation.h b/source/serialisation/capnp_serialisation.h index 5f784e77..adecaf65 100644 --- a/source/serialisation/capnp_serialisation.h +++ b/source/serialisation/capnp_serialisation.h @@ -1,14 +1,14 @@ #pragma once #ifndef UDA_CLIENTSERVER_CAPNP_SERIALISATION_H -#define UDA_CLIENTSERVER_CAPNP_SERIALISATION_H +# define UDA_CLIENTSERVER_CAPNP_SERIALISATION_H -#include -#include +# include +# include -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# endif typedef struct Buffer { char* data; @@ -91,8 +91,8 @@ void uda_capnp_add_char(NodeBuilder* node, char data); void uda_capnp_print_tree_builder(TreeBuilder* tree); void uda_capnp_print_tree_reader(TreeReader* tree); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif // UDA_CLIENTSERVER_CAPNP_SERIALISATION_H \ No newline at end of file diff --git a/source/server/applyXML.cpp b/source/server/applyXML.cpp old mode 100755 new mode 100644 index 2ae71c3c..a470026f --- a/source/server/applyXML.cpp +++ b/source/server/applyXML.cpp @@ -1,52 +1,53 @@ /*--------------------------------------------------------------------------------------------- -* Apply Actionable XML based Corrections to Data -* -* Returns: -* -* Notes: Actions defined within the SIGNAL record have a Higher priority than -* Actions defined within the SIGNAL_DESC record. -* -* Priorities are subject to exp_number and pass range checks -* -* A specific time_offset correction occurs befor any time dimension rescaling. -* -*-----------------------------------------------------------------------------------------------*/ + * Apply Actionable XML based Corrections to Data + * + * Returns: + * + * Notes: Actions defined within the SIGNAL record have a Higher priority than + * Actions defined within the SIGNAL_DESC record. + * + * Priorities are subject to exp_number and pass range checks + * + * A specific time_offset correction occurs befor any time dimension rescaling. + * + *-----------------------------------------------------------------------------------------------*/ #include "applyXML.h" #include #include -#include #include "udaTypes.h" #include +#include -int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, - ACTIONS* actions_desc, ACTIONS* actions_sig) +int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, ACTIONS* actions_desc, + ACTIONS* actions_sig) { -// return -1 if No Qualifying Actionable XML otherwise return 0 + // return -1 if No Qualifying Actionable XML otherwise return 0 int ndesc, rc = 0; UDA_LOG(UDA_LOG_DEBUG, "Parsing XML\n"); -//---------------------------------------------------------------------- -// Anything to Parse? + //---------------------------------------------------------------------- + // Anything to Parse? - if (strlen(signal.xml) == 0 && strlen(signal_desc.xml) == 0) return -1; // No XML to parse or switched off! + if (strlen(signal.xml) == 0 && strlen(signal_desc.xml) == 0) { + return -1; // No XML to parse or switched off! + } -//---------------------------------------------------------------------- -// Initialise + //---------------------------------------------------------------------- + // Initialise - initActions(actions_desc); // Array of actions from the Signal_Desc record - initActions(actions_sig); // Array of actions from the Signal Record + initActions(actions_desc); // Array of actions from the Signal_Desc record + initActions(actions_sig); // Array of actions from the Signal Record -//---------------------------------------------------------------------- -// Parse Signal XML + //---------------------------------------------------------------------- + // Parse Signal XML - if (strlen(signal.xml) > - 0) { // If this Signal level XML exists then populated components takes priority. + if (strlen(signal.xml) > 0) { // If this Signal level XML exists then populated components takes priority. if ((rc = parseDoc(signal.xml, actions_sig)) != 0) { return 1; } @@ -54,8 +55,8 @@ int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC sig printActions(*actions_sig); } -//---------------------------------------------------------------------- -// Parse Signal_Desc XML + //---------------------------------------------------------------------- + // Parse Signal_Desc XML if (strlen(signal_desc.xml) > 0) { if ((rc = parseDoc(signal_desc.xml, actions_desc)) != 0) { @@ -66,32 +67,34 @@ int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC sig printActions(*actions_desc); } -//---------------------------------------------------------------------------------------------- -// Test Range Groups (Only Applies to XML from Signal_desc records) + //---------------------------------------------------------------------------------------------- + // Test Range Groups (Only Applies to XML from Signal_desc records) - for (int i = 0; i < actions_sig->nactions; i++)actions_sig->action[i].inRange = 1; // Always in Range + for (int i = 0; i < actions_sig->nactions; i++) { + actions_sig->action[i].inRange = 1; // Always in Range + } ndesc = 0; for (int i = 0; i < actions_desc->nactions; i++) { UDA_LOG(UDA_LOG_DEBUG, "Range Test on Record %d\n", i); - UDA_LOG(UDA_LOG_DEBUG, "#1 %d\n", (actions_desc->action[i].exp_range[0] == 0 || - (actions_desc->action[i].exp_range[0] > 0 && - actions_desc->action[i].exp_range[0] <= data_source.exp_number))); + UDA_LOG(UDA_LOG_DEBUG, "#1 %d\n", + (actions_desc->action[i].exp_range[0] == 0 || + (actions_desc->action[i].exp_range[0] > 0 && + actions_desc->action[i].exp_range[0] <= data_source.exp_number))); - UDA_LOG(UDA_LOG_DEBUG, "#2 %d\n", (actions_desc->action[i].exp_range[1] == 0 || - (actions_desc->action[i].exp_range[1] > 0 && - actions_desc->action[i].exp_range[1] >= data_source.exp_number))); + UDA_LOG(UDA_LOG_DEBUG, "#2 %d\n", + (actions_desc->action[i].exp_range[1] == 0 || + (actions_desc->action[i].exp_range[1] > 0 && + actions_desc->action[i].exp_range[1] >= data_source.exp_number))); - UDA_LOG(UDA_LOG_DEBUG, "#3 %d\n", (data_source.pass = -1 || - ((actions_desc->action[i].pass_range[0] == -1 || - (actions_desc->action[i].pass_range[0] > -1 && - actions_desc->action[i].pass_range[0] <= - data_source.pass)) && - (actions_desc->action[i].pass_range[1] == -1 || - (actions_desc->action[i].pass_range[1] > -1 && - actions_desc->action[i].pass_range[1] >= - data_source.pass))))); + UDA_LOG(UDA_LOG_DEBUG, "#3 %d\n", + (data_source.pass = -1 || ((actions_desc->action[i].pass_range[0] == -1 || + (actions_desc->action[i].pass_range[0] > -1 && + actions_desc->action[i].pass_range[0] <= data_source.pass)) && + (actions_desc->action[i].pass_range[1] == -1 || + (actions_desc->action[i].pass_range[1] > -1 && + actions_desc->action[i].pass_range[1] >= data_source.pass))))); if ((actions_desc->action[i].exp_range[0] == 0 || (actions_desc->action[i].exp_range[0] > 0 && @@ -99,13 +102,12 @@ int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC sig (actions_desc->action[i].exp_range[1] == 0 || (actions_desc->action[i].exp_range[1] > 0 && actions_desc->action[i].exp_range[1] >= data_source.exp_number)) && - (data_source.pass == -1 || - ((actions_desc->action[i].pass_range[0] == -1 || - (actions_desc->action[i].pass_range[0] > -1 && - actions_desc->action[i].pass_range[0] <= data_source.pass)) && - (actions_desc->action[i].pass_range[1] == -1 || - (actions_desc->action[i].pass_range[1] > -1 && - actions_desc->action[i].pass_range[1] >= data_source.pass))))) { + (data_source.pass == -1 || ((actions_desc->action[i].pass_range[0] == -1 || + (actions_desc->action[i].pass_range[0] > -1 && + actions_desc->action[i].pass_range[0] <= data_source.pass)) && + (actions_desc->action[i].pass_range[1] == -1 || + (actions_desc->action[i].pass_range[1] > -1 && + actions_desc->action[i].pass_range[1] >= data_source.pass))))) { ndesc++; actions_desc->action[i].inRange = 1; } else { @@ -115,7 +117,7 @@ int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC sig printActions(*actions_desc); - if (actions_sig->nactions == 0 && ndesc == 0) { // No qualifying XML from either source + if (actions_sig->nactions == 0 && ndesc == 0) { // No qualifying XML from either source UDA_LOG(UDA_LOG_DEBUG, "No Applicable Actionable XML Found\n"); return -1; } @@ -123,7 +125,6 @@ int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC sig return 0; } - void applyCalibration(int type, int ndata, double factor, double offset, int invert, char* array) { float* fp; @@ -139,73 +140,99 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv unsigned long* ul; unsigned long long* ull; - if (array == nullptr) return; // No Data - if (factor == (double)1.0E0 && offset == (double)0.0E0 && !invert) return; // Nothing to be applied - + if (array == nullptr) { + return; // No Data + } + if (factor == (double)1.0E0 && offset == (double)0.0E0 && !invert) { + return; // Nothing to be applied + } if (factor != (double)1.0E0 || offset != (double)0.0E0) { switch (type) { case UDA_TYPE_FLOAT: fp = (float*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)factor * fp[i] + (float)offset; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)factor * fp[i] + (float)offset; + } break; case UDA_TYPE_DOUBLE: dp = (double*)array; - for (int i = 0; i < ndata; i++) dp[i] = factor * dp[i] + offset; + for (int i = 0; i < ndata; i++) { + dp[i] = factor * dp[i] + offset; + } break; case UDA_TYPE_CHAR: cp = (char*)array; - for (int i = 0; i < ndata; i++) cp[i] = (char)factor * cp[i] + (char)offset; + for (int i = 0; i < ndata; i++) { + cp[i] = (char)factor * cp[i] + (char)offset; + } break; case UDA_TYPE_SHORT: sp = (short*)array; - for (int i = 0; i < ndata; i++) sp[i] = (short)factor * sp[i] + (short)offset; + for (int i = 0; i < ndata; i++) { + sp[i] = (short)factor * sp[i] + (short)offset; + } break; case UDA_TYPE_INT: ip = (int*)array; - for (int i = 0; i < ndata; i++) ip[i] = (int)factor * ip[i] + (int)offset; + for (int i = 0; i < ndata; i++) { + ip[i] = (int)factor * ip[i] + (int)offset; + } break; case UDA_TYPE_LONG: lp = (long*)array; - for (int i = 0; i < ndata; i++) lp[i] = (long)factor * lp[i] + (long)offset; + for (int i = 0; i < ndata; i++) { + lp[i] = (long)factor * lp[i] + (long)offset; + } break; -// cause a bug: unresolved __fixunsdfdi - need gcc_s library + // cause a bug: unresolved __fixunsdfdi - need gcc_s library case UDA_TYPE_LONG64: llp = (long long*)array; - for (int i = 0; i < ndata; i++) llp[i] = (long long)factor * llp[i] + (long long)offset; + for (int i = 0; i < ndata; i++) { + llp[i] = (long long)factor * llp[i] + (long long)offset; + } break; case UDA_TYPE_UNSIGNED_CHAR: uc = (unsigned char*)array; - for (int i = 0; i < ndata; i++) uc[i] = (unsigned char)factor * uc[i] + (unsigned char)offset; + for (int i = 0; i < ndata; i++) { + uc[i] = (unsigned char)factor * uc[i] + (unsigned char)offset; + } break; case UDA_TYPE_UNSIGNED_SHORT: us = (unsigned short*)array; - for (int i = 0; i < ndata; i++) us[i] = (unsigned short)factor * us[i] + (unsigned short)offset; + for (int i = 0; i < ndata; i++) { + us[i] = (unsigned short)factor * us[i] + (unsigned short)offset; + } break; case UDA_TYPE_UNSIGNED_INT: up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) up[i] = (unsigned int)factor * up[i] + (unsigned int)offset; + for (int i = 0; i < ndata; i++) { + up[i] = (unsigned int)factor * up[i] + (unsigned int)offset; + } break; case UDA_TYPE_UNSIGNED_LONG: ul = (unsigned long*)array; - for (int i = 0; i < ndata; i++) ul[i] = (unsigned long)factor * ul[i] + (unsigned long)offset; + for (int i = 0; i < ndata; i++) { + ul[i] = (unsigned long)factor * ul[i] + (unsigned long)offset; + } break; case UDA_TYPE_UNSIGNED_LONG64: ull = (unsigned long long*)array; - for (int i = 0; i < ndata; i++) ull[i] = (unsigned long long)factor * ull[i] + - (unsigned long long)offset; + for (int i = 0; i < ndata; i++) { + ull[i] = (unsigned long long)factor * ull[i] + (unsigned long long)offset; + } break; default: @@ -220,16 +247,24 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv case UDA_TYPE_FLOAT: fp = (float*)array; - for (int i = 0; i < ndata; i++) - if (fp[i] != 0.0) { fp[i] = 1.0f / fp[i]; } - else { fp[i] = NAN; } + for (int i = 0; i < ndata; i++) { + if (fp[i] != 0.0) { + fp[i] = 1.0f / fp[i]; + } else { + fp[i] = NAN; + } + } break; case UDA_TYPE_DOUBLE: dp = (double*)array; - for (int i = 0; i < ndata; i++) - if (dp[i] != 0.0) { dp[i] = 1.0 / dp[i]; } - else { dp[i] = NAN; } + for (int i = 0; i < ndata; i++) { + if (dp[i] != 0.0) { + dp[i] = 1.0 / dp[i]; + } else { + dp[i] = NAN; + } + } break; default: @@ -238,9 +273,7 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv } } - -void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, SIGNAL* signal, - SIGNAL_DESC* signal_desc, +void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, SIGNAL* signal, SIGNAL_DESC* signal_desc, DATA_BLOCK* data_block, ACTIONS actions) { @@ -260,40 +293,49 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S UDA_LOG(UDA_LOG_DEBUG, "Applying XML\n"); - if (client_block.get_asis) return; // User specifies No Actions to be Applied + if (client_block.get_asis) { + return; // User specifies No Actions to be Applied + } //---------------------------------------------------------------------------------------------- // Loop over all actions for (int i = 0; i < actions.nactions; i++) { - if (!actions.action[i].inRange) continue; // Out of Pulse/Pass Range + if (!actions.action[i].inRange) { + continue; // Out of Pulse/Pass Range + } switch (actions.action[i].actionType) { - //---------------------------------------------------------------------------------------------- - // Documentation Changes: Label/Units Corrections + //---------------------------------------------------------------------------------------------- + // Documentation Changes: Label/Units Corrections case UDA_DOCUMENTATION_TYPE: - if (strlen(actions.action[i].documentation.label) > 0) + if (strlen(actions.action[i].documentation.label) > 0) { strcpy(data_block->data_label, actions.action[i].documentation.label); + } - if (strlen(actions.action[i].documentation.units) > 0) + if (strlen(actions.action[i].documentation.units) > 0) { strcpy(data_block->data_units, actions.action[i].documentation.units); + } - if (strlen(actions.action[i].documentation.description) > 0) + if (strlen(actions.action[i].documentation.description) > 0) { strcpy(data_block->data_desc, actions.action[i].documentation.description); + } for (int j = 0; j < actions.action[i].documentation.ndimensions; j++) { if (actions.action[i].documentation.dimensions[j].dimType == UDA_DIM_DOCUMENTATION_TYPE) { if (actions.action[i].documentation.dimensions[j].dimid > -1 && (unsigned int)actions.action[i].documentation.dimensions[j].dimid < data_block->rank) { - if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.label) > 0) + if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.label) > 0) { strcpy(data_block->dims[actions.action[i].documentation.dimensions[j].dimid].dim_label, actions.action[i].documentation.dimensions[j].dimdocumentation.label); - if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.units) > 0) + } + if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.units) > 0) { strcpy(data_block->dims[actions.action[i].documentation.dimensions[j].dimid].dim_units, actions.action[i].documentation.dimensions[j].dimdocumentation.units); + } } } } @@ -305,21 +347,22 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S case UDA_ERROR_MODEL_TYPE: data_block->error_model = actions.action[i].errormodel.model; data_block->error_param_n = actions.action[i].errormodel.param_n; - for (int j = 0; j < data_block->error_param_n; j++) + for (int j = 0; j < data_block->error_param_n; j++) { data_block->errparams[j] = actions.action[i].errormodel.params[j]; + } for (int j = 0; j < actions.action[i].errormodel.ndimensions; j++) { if (actions.action[i].errormodel.dimensions[j].dimType == UDA_DIM_ERROR_MODEL_TYPE) { if (actions.action[i].errormodel.dimensions[j].dimid > -1 && (unsigned int)actions.action[i].errormodel.dimensions[j].dimid < data_block->rank) { data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].error_model = - actions.action[i].errormodel.dimensions[j].dimerrormodel.model; + actions.action[i].errormodel.dimensions[j].dimerrormodel.model; data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].error_param_n = - actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; + actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; int jj; for (jj = 0; jj < actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; jj++) { data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].errparams[jj] = - actions.action[i].errormodel.dimensions[j].dimerrormodel.params[jj]; + actions.action[i].errormodel.dimensions[j].dimerrormodel.params[jj]; } } } @@ -333,7 +376,8 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S // timeoffset.method == 0 => there must be a Non_Zero offset value // timeoffset.method == 1 => Create a New Time Vector using both Offset and Interval values. - // timeoffset.method == 2 => Create a New Time Vector using an interval value only. Use the Original Starting value if possible. + // timeoffset.method == 2 => Create a New Time Vector using an interval value only. Use the Original + // Starting value if possible. case UDA_TIME_OFFSET_TYPE: @@ -346,23 +390,30 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S if ((actions.action[i].timeoffset.method == 1 || actions.action[i].timeoffset.method == 2) && actions.action[i].timeoffset.interval != (double)0.0E0) { - // Correct the Interval Only not the Starting value: Change to the standard simple data compression model + // Correct the Interval Only not the Starting value: Change to the standard simple data compression + // model if (actions.action[i].timeoffset.method == 2) { if (data_block->dims[data_block->order].method == 1 && - data_block->dims[data_block->order].udoms == 1 - && data_block->dims[data_block->order].data_type == UDA_TYPE_FLOAT) { + data_block->dims[data_block->order].udoms == 1 && + data_block->dims[data_block->order].data_type == UDA_TYPE_FLOAT) { float* offs = (float*)data_block->dims[data_block->order].offs; data_block->dims[data_block->order].method = 0; data_block->dims[data_block->order].dim0 = (double)*offs; data_block->dims[data_block->order].diff = actions.action[i].timeoffset.interval; - if (data_block->dims[data_block->order].compressed) { // Free Heap + if (data_block->dims[data_block->order].compressed) { // Free Heap void* cptr = nullptr; - if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) { + free(cptr); + } data_block->dims[data_block->order].sams = nullptr; data_block->dims[data_block->order].offs = nullptr; data_block->dims[data_block->order].ints = nullptr; @@ -379,15 +430,22 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S break; } - // Correct both the Starting and Interval values: Change to the standard simple data compression model + // Correct both the Starting and Interval values: Change to the standard simple data compression + // model if (actions.action[i].timeoffset.method == 1) { - if (data_block->dims[data_block->order].compressed) { // Free Heap with erroneous data + if (data_block->dims[data_block->order].compressed) { // Free Heap with erroneous data void* cptr = nullptr; - if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) { + free(cptr); + } data_block->dims[data_block->order].sams = nullptr; data_block->dims[data_block->order].offs = nullptr; data_block->dims[data_block->order].ints = nullptr; @@ -423,9 +481,9 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[data_block->order].method) { case 0: -// *** + // *** data_block->dims[data_block->order].dim0 = - data_block->dims[data_block->order].dim0 + actions.action[i].timeoffset.offset; + data_block->dims[data_block->order].dim0 + actions.action[i].timeoffset.offset; break; case 1: @@ -708,29 +766,27 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S if (STR_EQUALS("data", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { - if (strlen(actions.action[i].calibration.units) > 0) + if (strlen(actions.action[i].calibration.units) > 0) { strcpy(data_block->data_units, actions.action[i].calibration.units); + } applyCalibration(data_block->data_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->data); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->data); } if (STR_EQUALS("error", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { applyCalibration(data_block->error_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->errhi); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->errhi); } if (STR_EQUALS("aserror", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { applyCalibration(data_block->error_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->errlo); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->errlo); } // Dimension Corrections @@ -742,9 +798,10 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S if (actions.action[i].calibration.dimensions[j].dimType == UDA_DIM_CALIBRATION_TYPE && actions.action[i].actionId != 0 && dimid > -1 && (unsigned int)dimid < data_block->rank) { - if (strlen(actions.action[i].calibration.dimensions[j].dimcalibration.units) > 0) + if (strlen(actions.action[i].calibration.dimensions[j].dimcalibration.units) > 0) { strcpy(data_block->dims[dimid].dim_units, actions.action[i].calibration.dimensions[j].dimcalibration.units); + } if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != (double)1.0E0 || actions.action[i].calibration.dimensions[j].dimcalibration.offset != (double)0.0E0) { @@ -759,15 +816,15 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != (double)1.0E0) { data_block->dims[dimid].diff = - data_block->dims[dimid].diff * - actions.action[i].calibration.dimensions[j].dimcalibration.factor; + data_block->dims[dimid].diff * + actions.action[i].calibration.dimensions[j].dimcalibration.factor; } if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != (double)0.0E0) { data_block->dims[dimid].dim0 = - data_block->dims[dimid].dim0 + - actions.action[i].calibration.dimensions[j].dimcalibration.offset; + data_block->dims[dimid].dim0 + + actions.action[i].calibration.dimensions[j].dimcalibration.offset; } } else { @@ -781,47 +838,60 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S fp0 = (float*)data_block->dims[dimid].offs; fp = (float*)data_block->dims[dimid].ints; for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp[jj] = fp[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp[jj] = fp[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[jj] = fp0[jj] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[jj] = fp0[jj] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: fp0 = (float*)data_block->dims[dimid].offs; for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp0[jj] = fp0[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp0[jj] = fp0[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[jj] = fp0[jj] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[jj] = fp0[jj] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: fp0 = (float*)data_block->dims[dimid].offs; fp = (float*)data_block->dims[dimid].ints; - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[0] = fp0[0] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[0] = fp0[0] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp[jj] = fp[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp[jj] = fp[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; @@ -834,50 +904,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_CHAR: { char* ar0 = (char*)data_block->dims[dimid].offs; @@ -885,50 +967,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_SHORT: { short* ar = (short*)data_block->dims[dimid].ints; @@ -936,50 +1030,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_INT: { int* ar = (int*)data_block->dims[dimid].ints; @@ -987,50 +1093,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_LONG: { long* ar = (long*)data_block->dims[dimid].ints; @@ -1038,50 +1156,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_CHAR: { unsigned char* ar = (unsigned char*)data_block->dims[dimid].ints; @@ -1089,50 +1219,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_SHORT: { unsigned short* ar = (unsigned short*)data_block->dims[dimid].ints; @@ -1140,50 +1282,65 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = + ar0[jj] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = + ar0[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = + ar0[jj] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_INT: { unsigned int* ar = (unsigned int*)data_block->dims[dimid].ints; @@ -1191,50 +1348,62 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_LONG: { unsigned long* ar = (unsigned long*)data_block->dims[dimid].ints; @@ -1242,71 +1411,85 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; default: - break; // Need to Add for all data types + break; // Need to Add for all data types } } } else { - applyCalibration(data_block->dims[dimid].data_type, - data_block->dims[dimid].dim_n, - actions.action[i].calibration.dimensions[j].dimcalibration.factor, - actions.action[i].calibration.dimensions[j].dimcalibration.offset, - actions.action[i].calibration.dimensions[j].dimcalibration.invert, - data_block->dims[dimid].dim); + applyCalibration( + data_block->dims[dimid].data_type, data_block->dims[dimid].dim_n, + actions.action[i].calibration.dimensions[j].dimcalibration.factor, + actions.action[i].calibration.dimensions[j].dimcalibration.offset, + actions.action[i].calibration.dimensions[j].dimcalibration.invert, + data_block->dims[dimid].dim); UDA_LOG(UDA_LOG_DEBUG, "Rescaling Dimension : %d\n", dimid); UDA_LOG(UDA_LOG_DEBUG, "Time Dimension ? : %d\n", data_block->order); - UDA_LOG(UDA_LOG_DEBUG, "Scale ? : %f\n", - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor); - UDA_LOG(UDA_LOG_DEBUG, "Offset ? : %f\n", - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset); + UDA_LOG( + UDA_LOG_DEBUG, "Scale ? : %f\n", + (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor); + UDA_LOG( + UDA_LOG_DEBUG, "Offset ? : %f\n", + (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset); UDA_LOG(UDA_LOG_DEBUG, "Invert ? : %d\n", (int)actions.action[i].calibration.dimensions[j].dimcalibration.invert); } @@ -1329,7 +1512,6 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S actions.action[i].calibration.dimensions[j].dimcalibration.invert, data_block->dims[dimid].errlo); } - } } } @@ -1339,12 +1521,9 @@ void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, S default: break; } - } } - - // Combine the set of Actions from both sources with Signal XML having Priority of Signal_Desc XML void serverDeselectSignalXML(ACTIONS* actions_desc, ACTIONS* actions_sig) @@ -1354,18 +1533,22 @@ void serverDeselectSignalXML(ACTIONS* actions_desc, ACTIONS* actions_sig) UDA_LOG(UDA_LOG_DEBUG, "Deselecting Conflicting XML\n"); -//---------------------------------------------------------------------------------------------- -// Loop over all Signal actions + //---------------------------------------------------------------------------------------------- + // Loop over all Signal actions for (int i = 0; i < actions_sig->nactions; i++) { - type = actions_sig->action[i].actionType; // Target (This has Priority) + type = actions_sig->action[i].actionType; // Target (This has Priority) -// Loop over all Signal_Desc actions + // Loop over all Signal_Desc actions for (int j = 0; j < actions_desc->nactions; j++) { - if (!actions_desc->action[j].inRange) continue; // Out of Pulse/Pass Range - if (actions_desc->action[j].actionType == type) actions_desc->action[j].inRange = 0; // Disable + if (!actions_desc->action[j].inRange) { + continue; // Out of Pulse/Pass Range + } + if (actions_desc->action[j].actionType == type) { + actions_desc->action[j].inRange = 0; // Disable + } } } } diff --git a/source/server/applyXML.h b/source/server/applyXML.h old mode 100755 new mode 100644 index b3e1edd7..3e827fa7 --- a/source/server/applyXML.h +++ b/source/server/applyXML.h @@ -1,18 +1,18 @@ #pragma once #ifndef UDA_SERVER_APPLYXML_H -#define UDA_SERVER_APPLYXML_H +# define UDA_SERVER_APPLYXML_H -#include -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" +# include -int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, - ACTIONS *actions_desc, ACTIONS *actions_sig); +int serverParseSignalXML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, ACTIONS* actions_desc, + ACTIONS* actions_sig); -void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE *data_source, SIGNAL *signal, - SIGNAL_DESC *signal_desc, DATA_BLOCK *data_block, ACTIONS actions); +void serverApplySignalXML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, SIGNAL* signal, SIGNAL_DESC* signal_desc, + DATA_BLOCK* data_block, ACTIONS actions); -void serverDeselectSignalXML(ACTIONS *actions_desc, ACTIONS *actions_sig); +void serverDeselectSignalXML(ACTIONS* actions_desc, ACTIONS* actions_sig); #endif // UDA_SERVER_APPLYXML_H diff --git a/source/server/closeServerSockets.cpp b/source/server/closeServerSockets.cpp old mode 100755 new mode 100644 index 78a1bedb..c020e3b1 --- a/source/server/closeServerSockets.cpp +++ b/source/server/closeServerSockets.cpp @@ -1,8 +1,8 @@ #include "closeServerSockets.h" #if defined(__GNUC__) -# include # include +# include #else # include # define close _close @@ -16,9 +16,11 @@ void closeNamedServerSocket(SOCKETLIST* socks, char* host, int port) { for (int i = 0; i < socks->nsocks; i++) { if (STR_IEQUALS(host, socks->sockets[i].host) && socks->sockets[i].port == port) { - if (socks->sockets[i].type == TYPE_UDA_SERVER) close(socks->sockets[i].fh); // Only Genuine Sockets! + if (socks->sockets[i].type == TYPE_UDA_SERVER) { + close(socks->sockets[i].fh); // Only Genuine Sockets! + } socks->sockets[i].status = 0; - socks->sockets[i].fh = -1; // Need to call a closing function for other types of Connection, e.g. MDS+! + socks->sockets[i].fh = -1; // Need to call a closing function for other types of Connection, e.g. MDS+! break; } } @@ -28,9 +30,11 @@ void closeServerSocket(SOCKETLIST* socks, int fh) { for (int i = 0; i < socks->nsocks; i++) { if (socks->sockets[i].fh == fh) { - if (socks->sockets[i].type == TYPE_UDA_SERVER) close(fh); // Only Genuine Sockets! + if (socks->sockets[i].type == TYPE_UDA_SERVER) { + close(fh); // Only Genuine Sockets! + } socks->sockets[i].status = 0; - socks->sockets[i].fh = -1; // Need to call a closing function for other types of Connection, e.g. MDS+! + socks->sockets[i].fh = -1; // Need to call a closing function for other types of Connection, e.g. MDS+! break; } } @@ -38,10 +42,11 @@ void closeServerSocket(SOCKETLIST* socks, int fh) void closeServerSockets(SOCKETLIST* socks) { - for (int i = 0; i < socks->nsocks; i++) closeServerSocket(socks, socks->sockets[i].fh); + for (int i = 0; i < socks->nsocks; i++) { + closeServerSocket(socks, socks->sockets[i].fh); + } if (socks->sockets != nullptr) { free(socks->sockets); } initSocketList(socks); } - diff --git a/source/server/closeServerSockets.h b/source/server/closeServerSockets.h old mode 100755 new mode 100644 index d618c47d..94e22807 --- a/source/server/closeServerSockets.h +++ b/source/server/closeServerSockets.h @@ -1,12 +1,12 @@ #pragma once #ifndef UDA_SERVER_CLOSESERVERSOCKETS_H -#define UDA_SERVER_CLOSESERVERSOCKETS_H +# define UDA_SERVER_CLOSESERVERSOCKETS_H -#include -#include "export.h" +# include "export.h" +# include -void closeServerSocket(SOCKETLIST *socks, int fh); -void closeServerSockets(SOCKETLIST *socks); +void closeServerSocket(SOCKETLIST* socks, int fh); +void closeServerSockets(SOCKETLIST* socks); #endif // UDA_SERVER_CLOSESERVERSOCKETS_H diff --git a/source/server/createXDRStream.cpp b/source/server/createXDRStream.cpp old mode 100755 new mode 100644 index f686ab99..37715963 --- a/source/server/createXDRStream.cpp +++ b/source/server/createXDRStream.cpp @@ -5,7 +5,7 @@ #include "writer.h" #if !defined(FATCLIENT) && defined(SSLAUTHENTICATION) -#include +# include #endif std::pair serverCreateXDRStream(IoData* io_data) @@ -18,45 +18,45 @@ std::pair serverCreateXDRStream(IoData* io_data) #if !defined(FATCLIENT) && defined(SSLAUTHENTICATION) if (getUdaServerSSLDisabled()) { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create( &server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); - - xdrrec_create( &server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#else - xdrrec_create( &server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); - - xdrrec_create( &server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#endif - } else { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create( &server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); - - xdrrec_create( &server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); -#else - xdrrec_create( &server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); - - xdrrec_create( &server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); + + xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# else + xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); + + xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# endif + } else { +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); + + xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); +# else + xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); + + xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); +# endif } #else // SSLAUTHENTICATION -#if defined (__APPLE__) || defined(__TIRPC__) +# if defined(__APPLE__) || defined(__TIRPC__) xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, reinterpret_cast(server_read), reinterpret_cast(server_write)); @@ -64,17 +64,17 @@ std::pair serverCreateXDRStream(IoData* io_data) xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, io_data, reinterpret_cast(server_read), reinterpret_cast(server_write)); -#else +# else xdrrec_create(&server_output, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); + reinterpret_cast(server_read), + reinterpret_cast(server_write)); xdrrec_create(&server_input, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)io_data, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#endif + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# endif -#endif // SSLAUTHENTICATION +#endif // SSLAUTHENTICATION server_input.x_op = XDR_DECODE; server_output.x_op = XDR_ENCODE; diff --git a/source/server/createXDRStream.h b/source/server/createXDRStream.h old mode 100755 new mode 100644 index 162e6bd1..0841f2d2 --- a/source/server/createXDRStream.h +++ b/source/server/createXDRStream.h @@ -1,12 +1,12 @@ #pragma once #ifndef UDA_SERVER_CREATEXDRSTREAM_H -#define UDA_SERVER_CREATEXDRSTREAM_H +# define UDA_SERVER_CREATEXDRSTREAM_H -#include -#include +# include +# include -#include "export.h" +# include "export.h" struct IoData { int* server_tot_block_time; diff --git a/source/server/fatServer.cpp b/source/server/fatServer.cpp old mode 100755 new mode 100644 index e3b04e85..be90d1b7 --- a/source/server/fatServer.cpp +++ b/source/server/fatServer.cpp @@ -1,35 +1,34 @@ -#include #include #include +#include -#include #include "initStructs.h" +#include "logging/logging.h" +#include "struct.h" +#include +#include #include #include #include #include -#include #include #include #include #include -#include "logging/logging.h" -#include "struct.h" +#include "createXDRStream.h" #include "getServerEnvironment.h" +#include "initPluginList.h" #include "serverGetData.h" #include "serverLegacyPlugin.h" #include "serverProcessing.h" -#include "initPluginList.h" -#include "createXDRStream.h" #ifdef NONETCDFPLUGIN -void ncclose(int fh) { -} +void ncclose(int fh) {} #endif -static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) -ENVIRONMENT environment; // Holds local environment variable values +static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) +ENVIRONMENT environment; // Holds local environment variable values static USERDEFINEDTYPELIST* user_defined_type_list = nullptr; static LOGMALLOCLIST* log_malloc_list = nullptr; @@ -65,7 +64,6 @@ void setLogMallocList(LOGMALLOCLIST* logmalloclist_in) { log_malloc_list = logmalloclist_in; } - } #endif @@ -85,9 +83,8 @@ static int fatClientReturn(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_blo //-------------------------------------------------------------------------------------- // Server Entry point -int -fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, - DATA_BLOCK_LIST* data_blocks0) +int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, + DATA_BLOCK_LIST* data_blocks0) { assert(data_blocks0 != nullptr); @@ -104,7 +101,7 @@ fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* initLogStructList(&log_struct_list); int server_tot_block_time = 0; - int server_timeout = TIMEOUT; // user specified Server Lifetime + int server_timeout = TIMEOUT; // user specified Server Lifetime IoData io_data = {}; io_data.server_tot_block_time = &server_tot_block_time; @@ -118,14 +115,14 @@ fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* initServerBlock(server_block, server_version); initDataBlockList(&data_blocks); - initActions(&actions_desc); // There may be a Sequence of Actions to Apply + initActions(&actions_desc); // There may be a Sequence of Actions to Apply initActions(&actions_sig); USERDEFINEDTYPELIST parseduserdefinedtypelist; getInitialUserDefinedTypeList(&user_defined_type_list); parseduserdefinedtypelist = *user_defined_type_list; - //printUserDefinedTypeList(*userdefinedtypelist); + // printUserDefinedTypeList(*userdefinedtypelist); log_malloc_list = (LOGMALLOCLIST*)malloc(sizeof(LOGMALLOCLIST)); initLogMallocList(log_malloc_list); @@ -149,8 +146,7 @@ fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* return err; } - udaAccessLog(FALSE, client_block, request_block, *server_block, - total_datablock_size); + udaAccessLog(FALSE, client_block, request_block, *server_block, total_datablock_size); err = doFatServerClosedown(server_block, &data_blocks, &actions_desc, &actions_sig, data_blocks0); @@ -158,8 +154,8 @@ fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* free(user_defined_type_list); user_defined_type_list = nullptr; - //freeMallocLogList(logmalloclist); - //free(logmalloclist); + // freeMallocLogList(logmalloclist); + // free(logmalloclist); return err; } @@ -178,8 +174,7 @@ fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* * Client deletes stale files automatically on startup. * @return */ -static int -processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, IoData* io_data) +static int processHierarchicalData(DATA_BLOCK* data_block, LOGSTRUCTLIST* log_struct_list, IoData* io_data) { int err = 0; @@ -310,8 +305,8 @@ int handleRequestFat(REQUEST_BLOCK* request_block, REQUEST_BLOCK* request_block0 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, getServerEnvironment())) != 0) { + if ((err = udaServerPlugin(request, &metadata_block->data_source, &metadata_block->signal_desc, &pluginList, + getServerEnvironment())) != 0) { return err; } } else { @@ -416,7 +411,7 @@ int startupFatServer(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduser { static int socket_list_initialised = 0; static int plugin_list_initialised = 0; - //static int fileParsed = 0; + // static int fileParsed = 0; //------------------------------------------------------------------------- // Open and Initialise the Socket List (Once Only) @@ -432,7 +427,7 @@ int startupFatServer(SERVER_BLOCK* server_block, USERDEFINEDTYPELIST& parseduser getInitialUserDefinedTypeList(&user_defined_type_list); parseduserdefinedtypelist = *user_defined_type_list; printUserDefinedTypeList(*user_defined_type_list); - user_defined_type_list = nullptr; // Startup State + user_defined_type_list = nullptr; // Startup State /* // this step needs doing once only - the first time a generalised user defined structure is encountered. diff --git a/source/server/getPluginAddress.cpp b/source/server/getPluginAddress.cpp old mode 100755 new mode 100644 index f06c7448..541757b6 --- a/source/server/getPluginAddress.cpp +++ b/source/server/getPluginAddress.cpp @@ -1,11 +1,11 @@ #include "getPluginAddress.h" -#include #include +#include #include -#include #include "logging/logging.h" +#include /** * Return the function address for plugin data readers located in external shared libraries @@ -18,7 +18,7 @@ */ int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp) { - *pluginfunp = (PLUGINFUNP)nullptr; + *pluginfunp = (PLUGINFUNP) nullptr; if (library[0] == '\0' || symbol[0] == '\0') { // Nothing to 'point' to! Is this an Error? @@ -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)(IDAM_PLUGIN_INTERFACE*); *(void**)(&fptr) = dlsym(*pluginHandle, symbol); char* errstr = dlerror(); diff --git a/source/server/getPluginAddress.h b/source/server/getPluginAddress.h old mode 100755 new mode 100644 index 3b322d81..84002b9c --- a/source/server/getPluginAddress.h +++ b/source/server/getPluginAddress.h @@ -1,11 +1,11 @@ #pragma once #ifndef UDA_GETPLUGIN_ADDRESS_H -#define UDA_GETPLUGIN_ADDRESS_H +# define UDA_GETPLUGIN_ADDRESS_H -#include "udaPlugin.h" -#include "export.h" +# include "export.h" +# include "udaPlugin.h" -int getPluginAddress(void **pluginHandle, const char *library, const char *symbol, PLUGINFUNP *pluginfunp); +int getPluginAddress(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp); #endif // UDA_GETPLUGIN_ADDRESS_H diff --git a/source/server/getServerEnvironment.cpp b/source/server/getServerEnvironment.cpp old mode 100755 new mode 100644 index f0a56aea..1f561785 --- a/source/server/getServerEnvironment.cpp +++ b/source/server/getServerEnvironment.cpp @@ -36,26 +36,32 @@ ENVIRONMENT* getServerEnvironment() strcpy(g_environ.logdir, env); strcat(g_environ.logdir, "/"); } else { - strcpy(g_environ.logdir, "/scratch/udalog/"); // Log is on Scratch + strcpy(g_environ.logdir, "/scratch/udalog/"); // Log is on Scratch } g_environ.loglevel = UDA_LOG_NONE; if ((env = getenv("UDA_LOG_LEVEL")) != nullptr) { - if (strncmp(env, "ACCESS", 6) == 0) { g_environ.loglevel = UDA_LOG_ACCESS; } - else if (strncmp(env, "ERROR", 5) == 0) { g_environ.loglevel = UDA_LOG_ERROR; } - else if (strncmp(env, "WARN", 4) == 0) { g_environ.loglevel = UDA_LOG_WARN; } - else if (strncmp(env, "DEBUG", 5) == 0) { g_environ.loglevel = UDA_LOG_DEBUG; } - else if (strncmp(env, "INFO", 4) == 0) { g_environ.loglevel = UDA_LOG_INFO; } + if (strncmp(env, "ACCESS", 6) == 0) { + g_environ.loglevel = UDA_LOG_ACCESS; + } else if (strncmp(env, "ERROR", 5) == 0) { + g_environ.loglevel = UDA_LOG_ERROR; + } else if (strncmp(env, "WARN", 4) == 0) { + g_environ.loglevel = UDA_LOG_WARN; + } else if (strncmp(env, "DEBUG", 5) == 0) { + g_environ.loglevel = UDA_LOG_DEBUG; + } else if (strncmp(env, "INFO", 4) == 0) { + g_environ.loglevel = UDA_LOG_INFO; + } } // Log Output Write Mode - strcpy(g_environ.logmode, "w"); // Write & Replace Mode + strcpy(g_environ.logmode, "w"); // Write & Replace Mode if ((env = getenv("UDA_LOG_MODE")) != nullptr) { if (env[0] == 'a' && strlen(env) == 1) { g_environ.logmode[0] = 'a'; } - } // Append Mode + } // Append Mode //------------------------------------------------------------------------------------------- // API Defaults @@ -101,8 +107,12 @@ ENVIRONMENT* getServerEnvironment() g_environ.external_user = 0; #endif - if ((env = getenv("EXTERNAL_USER")) != nullptr) { g_environ.external_user = 1; } - if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { g_environ.external_user = 1; } + if ((env = getenv("EXTERNAL_USER")) != nullptr) { + g_environ.external_user = 1; + } + if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { + g_environ.external_user = 1; + } //------------------------------------------------------------------------------------------- // UDA Proxy Host: redirect ALL requests diff --git a/source/server/getServerEnvironment.h b/source/server/getServerEnvironment.h old mode 100755 new mode 100644 index 80c12dfd..69f68cbe --- a/source/server/getServerEnvironment.h +++ b/source/server/getServerEnvironment.h @@ -1,10 +1,10 @@ #pragma once #ifndef UDA_SERVER_GETSERVERENVIRONMENT_H -#define UDA_SERVER_GETSERVERENVIRONMENT_H +# define UDA_SERVER_GETSERVERENVIRONMENT_H -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" void printServerEnvironment(const ENVIRONMENT* environment); ENVIRONMENT* getServerEnvironment(); diff --git a/source/server/initPluginList.cpp b/source/server/initPluginList.cpp index d6efac07..b9eb9916 100644 --- a/source/server/initPluginList.cpp +++ b/source/server/initPluginList.cpp @@ -3,10 +3,10 @@ #include #include -#include #include -#include +#include #include +#include #include "getPluginAddress.h" @@ -40,15 +40,15 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) // Complete Common Registration for (int i = 0; i < plugin_list->count; i++) { - plugin_list->plugin[i].external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions - plugin_list->plugin[i].status = UDA_PLUGIN_OPERATIONAL; // By default all these are available - plugin_list->plugin[i].cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache + plugin_list->plugin[i].external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions + plugin_list->plugin[i].status = UDA_PLUGIN_OPERATIONAL; // By default all these are available + plugin_list->plugin[i].cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache } //---------------------------------------------------------------------------------------------------------------------- // Server-Side Functions - int pluginCount = plugin_list->count; // Number of internal plugins before adding server-side + int pluginCount = plugin_list->count; // Number of internal plugins before adding server-side strcpy(plugin_list->plugin[plugin_list->count].format, "SERVERSIDE"); allocPluginList(plugin_list->count++, plugin_list); @@ -67,9 +67,9 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) plugin_list->plugin[i].is_private = UDA_PLUGIN_PUBLIC; plugin_list->plugin[i].library[0] = '\0'; plugin_list->plugin[i].pluginHandle = nullptr; - plugin_list->plugin[i].external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions - plugin_list->plugin[i].status = UDA_PLUGIN_OPERATIONAL; // By default all these are available - plugin_list->plugin[i].cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache + plugin_list->plugin[i].external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions + plugin_list->plugin[i].status = UDA_PLUGIN_OPERATIONAL; // By default all these are available + plugin_list->plugin[i].cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache } //---------------------------------------------------------------------------------------------------------------------- @@ -81,15 +81,15 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) char csvChar = ','; char buffer[STRING_LENGTH]; char* root; - char* config = getenv("UDA_PLUGIN_CONFIG"); // Server plugin configuration file + char* config = getenv("UDA_PLUGIN_CONFIG"); // Server plugin configuration file FILE* conf = nullptr; - const char* filename = "udaPlugins.conf"; // Default name + const char* filename = "udaPlugins.conf"; // Default name std::string work; // Locate the plugin registration file if (config == nullptr) { - root = getenv("UDA_SERVERROOT"); // Where udaPlugins.conf is located by default + root = getenv("UDA_SERVERROOT"); // Where udaPlugins.conf is located by default if (root == nullptr) { work = fmt::format("./{}", filename); // Default ROOT is the server's Working Directory } else { @@ -136,14 +136,18 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) convertNonPrintable2(buffer); LeftTrimString(TrimString(buffer)); do { - if (buffer[0] == '#') break; - if (strlen(buffer) == 0) break; + if (buffer[0] == '#') { + break; + } + if (strlen(buffer) == 0) { + break; + } char* next = buffer; initPluginData(&plugin_list->plugin[plugin_list->count]); for (int i = 0; i < 10; i++) { - char* csv = strchr(next, csvChar); // Split the string + char* csv = strchr(next, csvChar); // Split the string if (csv != nullptr && i <= 8) { - csv[0] = '\0'; // Extract the sub-string ignoring the example - has a comma within text + csv[0] = '\0'; // Extract the sub-string ignoring the example - has a comma within text } LeftTrimString(TrimString(next)); switch (i) { @@ -151,10 +155,11 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) case 0: // File Format or Server Protocol or Library name or Device name etc. strcpy(plugin_list->plugin[plugin_list->count].format, LeftTrimString(next)); - // If the Format or Protocol is Not unique, the plugin that is selected will be the first one registered: others will be ignored. + // If the Format or Protocol is Not unique, the plugin that is selected will be the first + // one registered: others will be ignored. break; - case 1: // Plugin class: File, Server, Function or Device + case 1: // Plugin class: File, Server, Function or Device plugin_list->plugin[plugin_list->count].plugin_class = UDA_PLUGIN_CLASS_FILE; if (STR_IEQUALS(LeftTrimString(next), "server")) { plugin_list->plugin[plugin_list->count].plugin_class = UDA_PLUGIN_CLASS_SERVER; @@ -168,17 +173,20 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) break; case 2: - // Allow the same symbol (name of data access reader function or plugin entrypoint symbol) but from different libraries! + // Allow the same symbol (name of data access reader function or plugin entrypoint symbol) + // but from different libraries! if (plugin_list->plugin[plugin_list->count].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { strcpy(plugin_list->plugin[plugin_list->count].symbol, LeftTrimString(next)); - plugin_list->plugin[plugin_list->count].external = UDA_PLUGIN_EXTERNAL; // External (not linked) shared library + plugin_list->plugin[plugin_list->count].external = + UDA_PLUGIN_EXTERNAL; // External (not linked) shared library if (plugin_list->plugin[plugin_list->count].plugin_class == UDA_PLUGIN_CLASS_FILE) { // Plugin method name using a dot syntax char* p; if ((p = strchr(plugin_list->plugin[plugin_list->count].symbol, '.')) != nullptr) { - p[0] = '\0'; // Remove the method name from the symbol text - strcpy(plugin_list->plugin[plugin_list->count].method, &p[1]); // Save the method name + p[0] = '\0'; // Remove the method name from the symbol text + strcpy(plugin_list->plugin[plugin_list->count].method, + &p[1]); // Save the method name } } @@ -188,7 +196,8 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) } break; - case 3: // Server Host or Name of the shared library - can contain multiple plugin symbols so may not be unique + case 3: // Server Host or Name of the shared library - can contain multiple plugin symbols so + // may not be unique if (plugin_list->plugin[plugin_list->count].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { strcpy(plugin_list->plugin[plugin_list->count].library, LeftTrimString(next)); } else { @@ -196,7 +205,7 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) } break; - case 4: // File extension or Method Name or Port number + case 4: // File extension or Method Name or Port number // TODO: make extensions a list of valid extensions to minimise plugin duplication if (plugin_list->plugin[plugin_list->count].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { if (plugin_list->plugin[plugin_list->count].plugin_class == UDA_PLUGIN_CLASS_FILE) { @@ -210,44 +219,47 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) } break; - case 5: // Minimum Plugin Interface Version + case 5: // Minimum Plugin Interface Version if (strlen(next) > 0) { plugin_list->plugin[plugin_list->count].interfaceVersion = (unsigned short)atoi(next); } break; - case 6: // Permission to Cache returned values + case 6: // Permission to Cache returned values strcpy(plugin_list->plugin[plugin_list->count].desc, LeftTrimString(next)); - if (plugin_list->plugin[plugin_list->count].desc[0] != '\0' && ( - plugin_list->plugin[plugin_list->count].desc[0] == 'Y' || - plugin_list->plugin[plugin_list->count].desc[0] == 'y' || - plugin_list->plugin[plugin_list->count].desc[0] == 'T' || - plugin_list->plugin[plugin_list->count].desc[0] == 't' || - plugin_list->plugin[plugin_list->count].desc[0] == '1')) { - plugin_list->plugin[plugin_list->count].cachePermission = UDA_PLUGIN_OK_TO_CACHE; // True + if (plugin_list->plugin[plugin_list->count].desc[0] != '\0' && + (plugin_list->plugin[plugin_list->count].desc[0] == 'Y' || + plugin_list->plugin[plugin_list->count].desc[0] == 'y' || + plugin_list->plugin[plugin_list->count].desc[0] == 'T' || + plugin_list->plugin[plugin_list->count].desc[0] == 't' || + plugin_list->plugin[plugin_list->count].desc[0] == '1')) { + plugin_list->plugin[plugin_list->count].cachePermission = + UDA_PLUGIN_OK_TO_CACHE; // True plugin_list->plugin[plugin_list->count].desc[0] = '\0'; - } else - plugin_list->plugin[plugin_list->count].cachePermission = UDA_PLUGIN_NOT_OK_TO_CACHE; // False + } else { + plugin_list->plugin[plugin_list->count].cachePermission = + UDA_PLUGIN_NOT_OK_TO_CACHE; // False + } break; - case 7: // Private or Public plugin - i.e. available to external users + case 7: // Private or Public plugin - i.e. available to external users strcpy(plugin_list->plugin[plugin_list->count].desc, LeftTrimString(next)); - if (plugin_list->plugin[plugin_list->count].desc[0] != '\0' && ( - plugin_list->plugin[plugin_list->count].desc[0] == 'Y' || - plugin_list->plugin[plugin_list->count].desc[0] == 'y' || - plugin_list->plugin[plugin_list->count].desc[0] == 'T' || - plugin_list->plugin[plugin_list->count].desc[0] == 't' || - plugin_list->plugin[plugin_list->count].desc[0] == '1')) { + if (plugin_list->plugin[plugin_list->count].desc[0] != '\0' && + (plugin_list->plugin[plugin_list->count].desc[0] == 'Y' || + plugin_list->plugin[plugin_list->count].desc[0] == 'y' || + plugin_list->plugin[plugin_list->count].desc[0] == 'T' || + plugin_list->plugin[plugin_list->count].desc[0] == 't' || + plugin_list->plugin[plugin_list->count].desc[0] == '1')) { plugin_list->plugin[plugin_list->count].is_private = UDA_PLUGIN_PUBLIC; plugin_list->plugin[plugin_list->count].desc[0] = '\0'; } break; - case 8: // Description + case 8: // Description strcpy(plugin_list->plugin[plugin_list->count].desc, LeftTrimString(next)); break; @@ -266,15 +278,16 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) default: break; - } - if (csv != nullptr) next = &csv[1]; // Next element starting point + if (csv != nullptr) { + next = &csv[1]; // Next element starting point + } } // Issue Unique request ID plugin_list->plugin[plugin_list->count].request = REQUEST_READ_START + offset++; - plugin_list->plugin[plugin_list->count].pluginHandle = nullptr; // Library handle: Not opened - plugin_list->plugin[plugin_list->count].status = UDA_PLUGIN_NOT_OPERATIONAL; // Not yet available + plugin_list->plugin[plugin_list->count].pluginHandle = nullptr; // Library handle: Not opened + plugin_list->plugin[plugin_list->count].status = UDA_PLUGIN_NOT_OPERATIONAL; // Not yet available // Internal Serverside function ? @@ -287,16 +300,18 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) plugin_list->plugin[plugin_list->count].status = UDA_PLUGIN_OPERATIONAL; } - // Check this library has not already been opened: Preserve the library handle for use if already opened. + // Check this library has not already been opened: Preserve the library handle for use if already + // opened. int pluginID = -1; // States: - // 1. library not opened: open library and locate symbol (Only if the Class is SERVER or FUNCTION or File) + // 1. library not opened: open library and locate symbol (Only if the Class is SERVER or FUNCTION or + // File) // 2. library opened, symbol not located: locate symbol // 3. library opened, symbol located: re-use - for (int j = pluginCount; j < plugin_list->count - 1; j++) { // External sources only + for (int j = pluginCount; j < plugin_list->count - 1; j++) { // External sources only if (plugin_list->plugin[j].external == UDA_PLUGIN_EXTERNAL && plugin_list->plugin[j].status == UDA_PLUGIN_OPERATIONAL && plugin_list->plugin[j].pluginHandle != nullptr && @@ -308,17 +323,17 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) plugin_list->plugin[plugin_list->count].symbol) && plugin_list->plugin[j].idamPlugin != nullptr) { rc = 0; - plugin_list->plugin[plugin_list->count].idamPlugin = plugin_list->plugin[j].idamPlugin; // re-use + plugin_list->plugin[plugin_list->count].idamPlugin = + plugin_list->plugin[j].idamPlugin; // re-use } else { // New symbol in opened library if (plugin_list->plugin[plugin_list->count].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { - rc = getPluginAddress( - &plugin_list->plugin[j].pluginHandle, // locate symbol - plugin_list->plugin[j].library, - plugin_list->plugin[plugin_list->count].symbol, - &plugin_list->plugin[plugin_list->count].idamPlugin); + rc = getPluginAddress(&plugin_list->plugin[j].pluginHandle, // locate symbol + plugin_list->plugin[j].library, + plugin_list->plugin[plugin_list->count].symbol, + &plugin_list->plugin[plugin_list->count].idamPlugin); } } @@ -328,7 +343,7 @@ void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment) } } - if (pluginID == -1) { // open library and locate symbol + if (pluginID == -1) { // open library and locate symbol if (plugin_list->plugin[plugin_list->count].plugin_class != UDA_PLUGIN_CLASS_DEVICE) { rc = getPluginAddress(&plugin_list->plugin[plugin_list->count].pluginHandle, plugin_list->plugin[plugin_list->count].library, diff --git a/source/server/initPluginList.h b/source/server/initPluginList.h index 77c047cf..0711b1bb 100644 --- a/source/server/initPluginList.h +++ b/source/server/initPluginList.h @@ -1,11 +1,11 @@ #pragma once #ifndef UDA_SERVER_INITPLUGINLIST_H -#define UDA_SERVER_INITPLUGINLIST_H +# define UDA_SERVER_INITPLUGINLIST_H -#include "udaStructs.h" -#include "pluginStructs.h" -#include "export.h" +# include "export.h" +# include "pluginStructs.h" +# include "udaStructs.h" void initPluginList(PLUGINLIST* plugin_list, ENVIRONMENT* environment); diff --git a/source/server/makeServerRequestBlock.cpp b/source/server/makeServerRequestBlock.cpp old mode 100755 new mode 100644 index 83daab92..54258266 --- a/source/server/makeServerRequestBlock.cpp +++ b/source/server/makeServerRequestBlock.cpp @@ -1,7 +1,7 @@ #include "makeServerRequestBlock.h" -#include #include "initStructs.h" +#include #include "getServerEnvironment.h" diff --git a/source/server/makeServerRequestBlock.h b/source/server/makeServerRequestBlock.h old mode 100755 new mode 100644 index 271daeca..6155db4e --- a/source/server/makeServerRequestBlock.h +++ b/source/server/makeServerRequestBlock.h @@ -1,17 +1,17 @@ #pragma once #ifndef UDA_SERVER_MAKESERVERREQUESTBLOCK_H -#define UDA_SERVER_MAKESERVERREQUESTBLOCK_H +# define UDA_SERVER_MAKESERVERREQUESTBLOCK_H -#include "udaPlugin.h" -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaPlugin.h" +# include "udaStructs.h" -#if defined(SERVERBUILD) || defined(FATCLIENT) +# if defined(SERVERBUILD) || defined(FATCLIENT) int makeServerRequestBlock(REQUEST_BLOCK* request_block, PLUGINLIST pluginList); int makeServerRequestData(REQUEST_DATA* request, PLUGINLIST pluginList); -#endif +# endif #endif // UDA_SERVER_MAKESERVERREQUESTBLOCK_H diff --git a/source/server/serverGetData.cpp b/source/server/serverGetData.cpp old mode 100755 new mode 100644 index 8c661918..87ad231a --- a/source/server/serverGetData.cpp +++ b/source/server/serverGetData.cpp @@ -8,13 +8,13 @@ #endif #include "initStructs.h" -#include -#include -#include -#include -#include #include "logging/logging.h" #include "struct.h" +#include +#include +#include +#include +#include #include "applyXML.h" #include "getServerEnvironment.h" @@ -26,16 +26,14 @@ static int swap_signal_error(DATA_BLOCK* data_block, DATA_BLOCK* data_block2, in static int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2); static int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2, int asymmetry); -static int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, - DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, - const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, - USERDEFINEDTYPELIST* userdefinedtypelist); - -int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block, - DATA_BLOCK* data_block, DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, - ACTIONS* actions_desc, ACTIONS* actions_sig, const PLUGINLIST* pluginlist, - LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, SOCKETLIST* socket_list, - int protocolVersion) +static int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, DATA_SOURCE* data_source, + SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const PLUGINLIST* pluginlist, + LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist); + +int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, + DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, ACTIONS* actions_desc, + ACTIONS* actions_sig, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, SOCKETLIST* socket_list, int protocolVersion) { int isDerived = 0, compId = -1, serverside = 0; @@ -48,8 +46,8 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block ACTIONS actions_comp_desc, actions_comp_sig; ACTIONS actions_comp_desc2, actions_comp_sig2; - static int original_request = 0; // First entry value of the Plugin Request - static int original_xml = 0; // First entry flag that XML was passed in + static int original_request = 0; // First entry value of the Plugin Request + static int original_xml = 0; // First entry flag that XML was passed in //-------------------------------------------------------------------------------------------------------------------------- // Retain the original request (Needed to flag that signal/file details are in the Request or Action structures) @@ -58,13 +56,15 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block if (original_request == 0 || *depth == 0) { original_request = request_data->request; if (request_data->request != REQUEST_READ_XML) { - if (STR_STARTSWITH(request_data->signal, "signal, "xml[0] = '\0'; - } // remove redirected XML after first recursive pass + } // remove redirected XML after first recursive pass #endif //-------------------------------------------------------------------------------------------------------------------------- @@ -78,7 +78,8 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block UDA_LOG(UDA_LOG_DEBUG, "udaGetData Recursive Depth = %d\n", *depth); - // Can't use REQUEST_READ_SERVERSIDE because data must be read first using a 'real' data reader or REQUEST_READ_GENERIC + // Can't use REQUEST_READ_SERVERSIDE because data must be read first using a 'real' data reader or + // REQUEST_READ_GENERIC if (protocolVersion < 6) { if (STR_IEQUALS(request_data->archive, "SS") || STR_IEQUALS(request_data->archive, "SERVERSIDE")) { @@ -112,15 +113,15 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block //-------------------------------------------------------------------------------------------------------------------------- // Read the Data (Returns rc < 0 if the signal is a derived type or is defined in an XML document) - int rc = read_data(request_data, client_block, data_block, data_source, signal_rec, signal_desc, - pluginlist, logmalloclist, userdefinedtypelist); + int rc = read_data(request_data, client_block, data_block, data_source, signal_rec, signal_desc, pluginlist, + logmalloclist, userdefinedtypelist); UDA_LOG(UDA_LOG_DEBUG, "After read_data rc = %d\n", rc); UDA_LOG(UDA_LOG_DEBUG, "Is the Signal a Composite? %d\n", signal_desc->type == 'C'); if (rc > 0) { (*depth)--; - return rc; // An Error Occurred + return rc; // An Error Occurred } // Perform data subsetting if requested @@ -154,14 +155,15 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block UDA_LOG(UDA_LOG_DEBUG, "Derived/Composite Signal %s\n", request_data->signal); - isDerived = 1; // is True + isDerived = 1; // is True - //derived_signal_desc = *signal_desc; // Preserve details of Derived Signal Description Record - data_source->exp_number = request_data->exp_number; // Needed for Pulse Number Range Check in XML Parser - data_source->pass = request_data->pass; // Needed for a Pass/Sequence Range Check in XML Parser + // derived_signal_desc = *signal_desc; // Preserve details of Derived Signal Description + // Record + data_source->exp_number = request_data->exp_number; // Needed for Pulse Number Range Check in XML Parser + data_source->pass = request_data->pass; // Needed for a Pass/Sequence Range Check in XML Parser - // Allways Parse Signal XML to Identify the True Data Source for this Pulse Number - not subject to client request: get_asis - // (First Valid Action Record found only - others ignored) + // Allways Parse Signal XML to Identify the True Data Source for this Pulse Number - not subject to client + // request: get_asis (First Valid Action Record found only - others ignored) initActions(&actions_comp_desc); initActions(&actions_comp_sig); @@ -179,14 +181,16 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block UDA_THROW_ERROR(8881, "Unable to Parse XML"); } - // Identify which XML statements are in Range (Only signal_desc xml need be checked as signal xml is specific to a single pulse/pass) + // Identify which XML statements are in Range (Only signal_desc xml need be checked as signal xml is specific to + // a single pulse/pass) compId = -1; if (rc == 0) { for (int i = 0; i < actions_comp_desc.nactions; i++) { - if (actions_comp_desc.action[i].actionType == UDA_COMPOSITE_TYPE && actions_comp_desc.action[i].inRange) { + if (actions_comp_desc.action[i].actionType == UDA_COMPOSITE_TYPE && + actions_comp_desc.action[i].inRange) { compId = i; - break; // First Record found only! + break; // First Record found only! } } @@ -196,12 +200,14 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0) { // If we haven't a True Signal then can't identify the data required! - request_block2 = *request_data; // Preserve details of the Original User Request (Do Not FREE Elements) + request_block2 = + *request_data; // Preserve details of the Original User Request (Do Not FREE Elements) strcpy(request_block2.signal, - actions_comp_desc.action[compId].composite.data_signal); // True Signal Identity + actions_comp_desc.action[compId].composite.data_signal); // True Signal Identity - // Does this Composite originate from a subsetting operation? If so then fill out any missing items in the composite record + // Does this Composite originate from a subsetting operation? If so then fill out any missing items + // in the composite record if (actions_comp_desc.action[compId].composite.nsubsets > 0 || actions_comp_desc.action[compId].composite.nmaps > 0 || @@ -210,24 +216,25 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block // ******** If there is No subset then composite.file is missing!!! - if (strlen(actions_comp_desc.action[compId].composite.file) == 0 - && strlen(data_source->path) > 0) { + if (strlen(actions_comp_desc.action[compId].composite.file) == 0 && + strlen(data_source->path) > 0) { strcpy(actions_comp_desc.action[compId].composite.file, data_source->path); } - if (strlen(actions_comp_desc.action[compId].composite.format) == 0 - && strlen(data_source->format) > 0) { + if (strlen(actions_comp_desc.action[compId].composite.format) == 0 && + strlen(data_source->format) > 0) { strcpy(actions_comp_desc.action[compId].composite.format, data_source->format); } - if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0 - && strlen(signal_desc->signal_name) == 0) { + if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0 && + strlen(signal_desc->signal_name) == 0) { strcpy(signal_desc->signal_name, actions_comp_desc.action[compId].composite.data_signal); } } //=======>>> Experimental ============================================ - // Need to change formats from GENERIC if Composite and Signal Description record only exists and format Not Generic! + // Need to change formats from GENERIC if Composite and Signal Description record only exists and + // format Not Generic! if (request_data->request == REQUEST_READ_GENERIC && request_data->exp_number <= 0) { request_data->request = REQUEST_READ_XML; @@ -242,12 +249,13 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; - UDA_THROW_ERROR(8888, "User Specified Composite Data Signal Not Fully Defined: Format?, File?"); + UDA_THROW_ERROR(8888, + "User Specified Composite Data Signal Not Fully Defined: Format?, File?"); } strcpy(request_block2.path, actions_comp_desc.action[compId].composite.file); - request_block2.request = findPluginRequestByFormat( - actions_comp_desc.action[compId].composite.format, pluginlist); + request_block2.request = + findPluginRequestByFormat(actions_comp_desc.action[compId].composite.format, pluginlist); if (request_block2.request == REQUEST_READ_UNKNOWN) { if (actions_comp_desc.action[compId].composite.format[0] == '\0' && @@ -257,7 +265,8 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; - UDA_THROW_ERROR(8889, "User Specified Composite Data Signal's File Format NOT Recognised"); + UDA_THROW_ERROR(8889, + "User Specified Composite Data Signal's File Format NOT Recognised"); } } @@ -287,14 +296,14 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block UDA_LOG(UDA_LOG_DEBUG, "Reading Composite Signal DATA\n"); - rc = udaGetData(depth, &request_block2, client_block, data_block, data_source, signal_rec, signal_desc, - actions_desc, actions_sig, pluginlist, logmalloclist, userdefinedtypelist, socket_list, - protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, data_block, data_source, signal_rec, + signal_desc, actions_desc, actions_sig, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); - freeActions(actions_desc); // Added 06Nov2008 + freeActions(actions_desc); // Added 06Nov2008 freeActions(actions_sig); - if (rc != 0) { // Error + if (rc != 0) { // Error freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; @@ -317,7 +326,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block } } - } else { isDerived = 0; } + } else { + isDerived = 0; + } //-------------------------------------------------------------------------------------------------------------------------- // Parse Qualifying Actionable XML @@ -337,7 +348,7 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block if (rc == -1) { if (!serverside) { (*depth)--; - return 0; // No XML to Apply so No More to be Done! + return 0; // No XML to Apply so No More to be Done! } } else { if (rc == 1) { @@ -347,7 +358,7 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block } } else { (*depth)--; - return 0; // Ignore All XML so nothing to be done! Done! + return 0; // Ignore All XML so nothing to be done! Done! } } @@ -384,9 +395,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block strcpy(data_source2.filename, request_data->file); } - rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, - &signal_rec2, &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, - logmalloclist, userdefinedtypelist, socket_list, protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, &signal_rec2, + &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); freeActions(&actions_comp_desc2); freeActions(&actions_comp_sig2); @@ -430,9 +441,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block strcpy(data_source2.filename, request_data->file); } - rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, - &signal_rec2, &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, - logmalloclist, userdefinedtypelist, socket_list, protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, &signal_rec2, + &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); freeActions(&actions_comp_desc2); freeActions(&actions_comp_sig2); @@ -453,7 +464,6 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block return rc; } } - } //-------------------------------------------------------------------------------------------------------------------------- @@ -467,7 +477,7 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block UDA_LOG(UDA_LOG_DEBUG, "Substituting Dimension Data\n"); strcpy(request_block2.format, - "GENERIC"); // Database Lookup if not specified in XML or by Client + "GENERIC"); // Database Lookup if not specified in XML or by Client // Replace signal name re-using the Local Working REQUEST Block @@ -476,8 +486,12 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block // Replace other properties if defined by the original client request or the XML DIMCOMPOSITE record - if (strlen(request_data->path) > 0) strcpy(request_block2.path, request_data->file); - if (strlen(request_data->format) > 0) strcpy(request_block2.format, request_data->format); + if (strlen(request_data->path) > 0) { + strcpy(request_block2.path, request_data->file); + } + if (strlen(request_data->format) > 0) { + strcpy(request_block2.format, request_data->format); + } if (strlen(actions_desc->action[compId].composite.file) > 0) { strcpy(request_block2.path, actions_desc->action[compId].composite.file); @@ -502,7 +516,7 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block initActions(&actions_comp_desc2); initActions(&actions_comp_sig2); initDataBlock(&data_block2); - initSignalDesc(&signal_desc2); // Added 06Nov2008 + initSignalDesc(&signal_desc2); // Added 06Nov2008 // Check if the source file was originally defined in the client API? @@ -531,9 +545,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block // Recursive call - rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, - &signal_rec2, &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, - pluginlist, logmalloclist, userdefinedtypelist, socket_list, protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, &signal_rec2, + &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); freeActions(&actions_comp_desc2); freeActions(&actions_comp_sig2); @@ -546,8 +560,8 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block // Replace Dimension Data - rc = swap_signal_dim(actions_desc->action[compId].composite.dimensions[i].dimcomposite, - data_block, &data_block2); + rc = swap_signal_dim(actions_desc->action[compId].composite.dimensions[i].dimcomposite, data_block, + &data_block2); freeDataBlock(&data_block2); @@ -579,9 +593,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block strcpy(data_source2.filename, request_data->file); } - rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, - &signal_rec2, &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, - pluginlist, logmalloclist, userdefinedtypelist, socket_list, protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, &signal_rec2, + &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); freeActions(&actions_comp_desc2); freeActions(&actions_comp_sig2); @@ -627,9 +641,9 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block strcpy(data_source2.filename, request_data->file); } - rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, - &signal_rec2, &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, - pluginlist, logmalloclist, userdefinedtypelist, socket_list, protocolVersion); + rc = udaGetData(depth, &request_block2, client_block, &data_block2, &data_source2, &signal_rec2, + &signal_desc2, &actions_comp_desc2, &actions_comp_sig2, pluginlist, logmalloclist, + userdefinedtypelist, socket_list, protocolVersion); freeActions(&actions_comp_desc2); freeActions(&actions_comp_sig2); @@ -651,13 +665,13 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block return rc; } } - } } } //-------------------------------------------------------------------------------------------------------------------------- - // Apply Any Labeling, Timing Offsets and Calibration Actions to Data and Dimension (no Data or Dimension substituting) + // Apply Any Labeling, Timing Offsets and Calibration Actions to Data and Dimension (no Data or Dimension + // substituting) UDA_LOG(UDA_LOG_DEBUG, "#Timing Before XML\n"); printDataBlock(*data_block); @@ -725,7 +739,7 @@ int udaGetData(int* depth, REQUEST_DATA* request_data, CLIENT_BLOCK client_block freeActions(&actions_serverside); } -//-------------------------------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------------------------------- (*depth)--; return 0; @@ -738,12 +752,16 @@ int swap_signal_error(DATA_BLOCK* data_block, DATA_BLOCK* data_block2, int asymm if (data_block->rank == data_block2->rank && data_block->data_n == data_block2->data_n) { if (!asymmetry) { - if (data_block->errhi != nullptr) free(data_block->errhi); // Free unwanted Error Data Heap - data_block->errhi = data_block2->data; // straight swap! - data_block2->data = nullptr; // Prevent Double Heap Free + if (data_block->errhi != nullptr) { + free(data_block->errhi); // Free unwanted Error Data Heap + } + data_block->errhi = data_block2->data; // straight swap! + data_block2->data = nullptr; // Prevent Double Heap Free data_block->errasymmetry = 0; } else { - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->errlo = data_block2->data; data_block2->data = nullptr; data_block->errasymmetry = 1; @@ -773,26 +791,36 @@ int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOC if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].dim) != nullptr) { free(cptr); } // Free unwanted dimension Heap - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } - data_block->dims[dimcomposite.to_dim].dim = nullptr; // Prevent Double Heap Free + data_block->dims[dimcomposite.to_dim].dim = nullptr; // Prevent Double Heap Free data_block->dims[dimcomposite.to_dim].sams = nullptr; data_block->dims[dimcomposite.to_dim].offs = nullptr; data_block->dims[dimcomposite.to_dim].ints = nullptr; data_block->dims[dimcomposite.to_dim].errhi = nullptr; data_block->dims[dimcomposite.to_dim].errlo = nullptr; - data_block->dims[dimcomposite.to_dim].dim = data_block2->data; // straight swap! + data_block->dims[dimcomposite.to_dim].dim = data_block2->data; // straight swap! data_block->dims[dimcomposite.to_dim].errhi = data_block2->errhi; data_block->dims[dimcomposite.to_dim].errlo = data_block2->errlo; for (int i = 0; i < data_block2->error_param_n; i++) { data_block->dims[dimcomposite.to_dim].errparams[i] = data_block2->errparams[i]; } - data_block2->data = nullptr; // Prevent Double Heap Free + data_block2->data = nullptr; // Prevent Double Heap Free data_block2->errhi = nullptr; data_block2->errlo = nullptr; @@ -800,7 +828,7 @@ int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOC data_block->dims[dimcomposite.to_dim].data_type = data_block2->data_type; data_block->dims[dimcomposite.to_dim].error_type = data_block2->error_type; data_block->dims[dimcomposite.to_dim].errasymmetry = data_block2->errasymmetry; - data_block->dims[dimcomposite.to_dim].compressed = 0; // Not Applicable to Signal Data + data_block->dims[dimcomposite.to_dim].compressed = 0; // Not Applicable to Signal Data data_block->dims[dimcomposite.to_dim].dim0 = 0.0E0; data_block->dims[dimcomposite.to_dim].diff = 0.0E0; data_block->dims[dimcomposite.to_dim].method = 0; @@ -824,23 +852,35 @@ int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOC if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].dim) != nullptr) { free(cptr); - } // Free unwanted dimension Heap - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) free(cptr); - - data_block->dims[dimcomposite.to_dim].dim = data_block2->dims[dimcomposite.from_dim].dim; // straight swap! + } // Free unwanted dimension Heap + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) { + free(cptr); + } + + data_block->dims[dimcomposite.to_dim].dim = + data_block2->dims[dimcomposite.from_dim].dim; // straight swap! data_block->dims[dimcomposite.to_dim].errhi = data_block2->dims[dimcomposite.from_dim].errhi; data_block->dims[dimcomposite.to_dim].errlo = data_block2->dims[dimcomposite.from_dim].errlo; data_block->dims[dimcomposite.to_dim].sams = data_block2->dims[dimcomposite.from_dim].sams; data_block->dims[dimcomposite.to_dim].offs = data_block2->dims[dimcomposite.from_dim].offs; data_block->dims[dimcomposite.to_dim].ints = data_block2->dims[dimcomposite.from_dim].ints; for (int i = 0; i < data_block2->dims[dimcomposite.from_dim].error_param_n; i++) { - data_block->dims[dimcomposite.to_dim].errparams[i] = data_block2->dims[dimcomposite.from_dim].errparams[i]; + data_block->dims[dimcomposite.to_dim].errparams[i] = + data_block2->dims[dimcomposite.from_dim].errparams[i]; } - data_block2->dims[dimcomposite.from_dim].dim = nullptr; // Prevent Double Heap Free + data_block2->dims[dimcomposite.from_dim].dim = nullptr; // Prevent Double Heap Free data_block2->dims[dimcomposite.from_dim].errhi = nullptr; data_block2->dims[dimcomposite.from_dim].errlo = nullptr; data_block2->dims[dimcomposite.from_dim].sams = nullptr; @@ -856,9 +896,12 @@ int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOC data_block->dims[dimcomposite.to_dim].udoms = data_block2->dims[dimcomposite.from_dim].udoms; data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].error_type; - data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].errasymmetry; - data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].error_model; - data_block->dims[dimcomposite.to_dim].error_param_n = data_block2->dims[dimcomposite.from_dim].error_param_n; + data_block->dims[dimcomposite.to_dim].error_model = + data_block2->dims[dimcomposite.from_dim].errasymmetry; + data_block->dims[dimcomposite.to_dim].error_model = + data_block2->dims[dimcomposite.from_dim].error_model; + data_block->dims[dimcomposite.to_dim].error_param_n = + data_block2->dims[dimcomposite.from_dim].error_param_n; strcpy(data_block->dims[dimcomposite.to_dim].dim_units, data_block2->dims[dimcomposite.from_dim].dim_units); @@ -873,13 +916,11 @@ int swap_signal_dim(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOC return 0; } - -int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2, - int asymmetry) +int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DATA_BLOCK* data_block2, int asymmetry) { void* cptr = nullptr; -// Replace Dimension Error Data with Signal Data + // Replace Dimension Error Data with Signal Data if (dimcomposite.from_dim < 0 && dimcomposite.to_dim >= 0) { @@ -888,12 +929,14 @@ int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DAT if (!asymmetry) { if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { free(cptr); - } // Unwanted - data_block->dims[dimcomposite.to_dim].errhi = data_block2->data; // straight swap! - data_block2->data = nullptr; // Prevent Double Heap Free + } // Unwanted + data_block->dims[dimcomposite.to_dim].errhi = data_block2->data; // straight swap! + data_block2->data = nullptr; // Prevent Double Heap Free data_block->dims[dimcomposite.to_dim].errasymmetry = 0; } else { - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } data_block->dims[dimcomposite.to_dim].errlo = data_block2->data; data_block2->data = nullptr; data_block->dims[dimcomposite.to_dim].errasymmetry = 1; @@ -907,9 +950,8 @@ int swap_signal_dim_error(DIMCOMPOSITE dimcomposite, DATA_BLOCK* data_block, DAT return 0; } -int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, - DATA_BLOCK* data_block, DATA_SOURCE* data_source, SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, - const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, +int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, DATA_BLOCK* data_block, DATA_SOURCE* data_source, + SIGNAL* signal_rec, SIGNAL_DESC* signal_desc, const PLUGINLIST* pluginlist, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist) { // If err = 0 then standard signal data read @@ -927,9 +969,9 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, #ifndef PROXYSERVER if (request->request != REQUEST_READ_XML) { if (STR_STARTSWITH(request->signal, "type = 'C'; // Composite/Derived Type - signal_desc->signal_name[0] = '\0'; // The true signal is contained in the XML - strcpy(signal_desc->xml, request->signal); // XML is passed via the signal string + signal_desc->type = 'C'; // Composite/Derived Type + signal_desc->signal_name[0] = '\0'; // The true signal is contained in the XML + strcpy(signal_desc->xml, request->signal); // XML is passed via the signal string strcpy(data_source->format, request->format); strcpy(data_source->path, request->path); strcpy(data_source->filename, request->file); @@ -950,8 +992,8 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, // // If the source is a private file and the Legacy Name has No Alternative record, then fail access // If the source is Not a private file (Generic Access method) and the Legacy Name has No Alternative record and - // the Source Alias associated with the Legacy Name (Signal_Desc table) is Not used by ANY Alternative mapping with the same - // Rank, then allow normal Generic lookup. + // the Source Alias associated with the Legacy Name (Signal_Desc table) is Not used by ANY Alternative mapping with + // the same Rank, then allow normal Generic lookup. //------------------------------------------------------------------------------ #ifndef PROXYSERVER if (client_block.clientFlags & CLIENTFLAG_ALTDATA && request->request != REQUEST_READ_XML && @@ -959,15 +1001,16 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, if (request->request != REQUEST_READ_GENERIC) { // Must be a Private File so switch signal names - strcpy(request->signal, signal_desc->signal_name); // Alias or Generic have no context wrt private files - signal_desc->xml[0] = '\0'; // No corrections to private data files - strcpy(signal_desc->xml, mapping); // Only mapping XML is applicable + strcpy(request->signal, signal_desc->signal_name); // Alias or Generic have no context wrt private files + signal_desc->xml[0] = '\0'; // No corrections to private data files + strcpy(signal_desc->xml, mapping); // Only mapping XML is applicable if (mapping[0] != '\0') { signal_desc->type = 'S'; - } // Switched data with mapping Transform in XML + } // Switched data with mapping Transform in XML } else { if (signal_desc->signal_alias[0] != '\0') { - strcpy(request->signal, signal_desc->signal_alias); // Alias or Generic name is what is passed into sqlGeneric + strcpy(request->signal, + signal_desc->signal_alias); // Alias or Generic name is what is passed into sqlGeneric } } } @@ -989,7 +1032,8 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, UDA_LOG(UDA_LOG_DEBUG, "Metadata Plugin ID = %d\nExecuting the plugin\n", plugin_id); - // If the plugin is registered as a FILE or LIBRARY type then call the default method as no method will have been specified + // If the plugin is registered as a FILE or LIBRARY type then call the default method as no method will have + // been specified strcpy(request->function, pluginlist->plugin[plugin_id].method); @@ -1018,7 +1062,9 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, { int err = name_value_substitution(&request->nameValueList, request->tpass); - if (err != 0) return err; + if (err != 0) { + return err; + } } //------------------------------------------------------------------------------ @@ -1027,8 +1073,8 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, if (request->request == REQUEST_READ_XML) { if (strlen(request->signal) > 0) { - strcpy(signal_desc->xml, request->signal); // XML is passed via the signal string - } else if (strlen(request->path) > 0) { // XML is passed via a file + strcpy(signal_desc->xml, request->signal); // XML is passed via the signal string + } else if (strlen(request->path) > 0) { // XML is passed via a file FILE* xmlfile = nullptr; int nchar; errno = 0; @@ -1047,7 +1093,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, while (!feof(xmlfile) && nchar < MAXMETA) { request->signal[nchar++] = (char)getc(xmlfile); } - request->signal[nchar - 2] = '\0'; // Remove EOF Character and replace with String Terminator + request->signal[nchar - 2] = '\0'; // Remove EOF Character and replace with String Terminator strcpy(signal_desc->xml, request->signal); fclose(xmlfile); } else { @@ -1096,10 +1142,10 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, int plugin_id; if (request->request != REQUEST_READ_GENERIC && request->request != REQUEST_READ_UNKNOWN) { - plugin_id = request->request; // User has Specified a Plugin + plugin_id = request->request; // User has Specified a Plugin UDA_LOG(UDA_LOG_DEBUG, "Plugin Request ID %d\n", plugin_id); } else { - plugin_id = findPluginRequestByFormat(data_source->format, pluginlist); // via Generic database query + plugin_id = findPluginRequestByFormat(data_source->format, pluginlist); // via Generic database query UDA_LOG(UDA_LOG_DEBUG, "findPluginRequestByFormat Plugin Request ID %d\n", plugin_id); } @@ -1120,8 +1166,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, #endif if (pluginlist->plugin[id].external == UDA_PLUGIN_EXTERNAL && pluginlist->plugin[id].status == UDA_PLUGIN_OPERATIONAL && - pluginlist->plugin[id].pluginHandle != nullptr && - pluginlist->plugin[id].idamPlugin != nullptr) { + pluginlist->plugin[id].pluginHandle != nullptr && pluginlist->plugin[id].idamPlugin != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "[%d] %s Plugin Selected\n", plugin_id, data_source->format); @@ -1180,7 +1225,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, return 0; } - request->request = REQUEST_READ_GENERIC; // Use a different Plugin + request->request = REQUEST_READ_GENERIC; // Use a different Plugin } } } @@ -1188,7 +1233,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, int plugin_id = REQUEST_READ_UNKNOWN; if (request->request != REQUEST_READ_GENERIC) { - plugin_id = request->request; // User API has Specified a Plugin + plugin_id = request->request; // User API has Specified a Plugin } else { // Test for known File formats and Server protocols @@ -1196,7 +1241,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, int id = -1; for (int i = 0; i < pluginlist->count; i++) { if (STR_IEQUALS(data_source->format, pluginlist->plugin[i].format)) { - plugin_id = pluginlist->plugin[i].request; // Found + plugin_id = pluginlist->plugin[i].request; // Found id = i; UDA_LOG(UDA_LOG_DEBUG, "[%d] %s Plugin Selected\n", plugin_id, data_source->format); break; @@ -1248,8 +1293,7 @@ int read_data(REQUEST_DATA* request, CLIENT_BLOCK client_block, // Save Provenance with socket stream protection udaServerRedirectStdStreams(0); - udaProvenancePlugin(&client_block, request, data_source, signal_desc, pluginlist, nullptr, - getServerEnvironment()); + udaProvenancePlugin(&client_block, request, data_source, signal_desc, pluginlist, nullptr, getServerEnvironment()); udaServerRedirectStdStreams(1); return 0; diff --git a/source/server/serverGetData.h b/source/server/serverGetData.h old mode 100755 new mode 100644 index 9a2099b6..30ae204e --- a/source/server/serverGetData.h +++ b/source/server/serverGetData.h @@ -1,20 +1,18 @@ #pragma once #ifndef UDA_SERVER_SERVERGETDATA_H -#define UDA_SERVER_SERVERGETDATA_H +# define UDA_SERVER_SERVERGETDATA_H -#include -#include "udaStructs.h" -#include -#include "genStructs.h" -#include "pluginStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" +# include "pluginStructs.h" +# include "udaStructs.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); +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.cpp b/source/server/serverLegacyPlugin.cpp old mode 100755 new mode 100644 index 86176ecb..73ec0b6c --- a/source/server/serverLegacyPlugin.cpp +++ b/source/server/serverLegacyPlugin.cpp @@ -5,9 +5,9 @@ # include #endif -#include #include #include +#include #ifndef FATCLIENT # include @@ -27,7 +27,8 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA do { //---------------------------------------------------------------------------- - // Does the Path to Private Files contain hierarchical components not seen by the server? If so make a substitution. + // Does the Path to Private Files contain hierarchical components not seen by the server? If so make a + // substitution. #ifndef FATCLIENT @@ -44,16 +45,20 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA strcpy(work, environment->private_path_target); token = strtok(work, delimiters); strcpy(targets[tcount++], token); - while ((token = strtok(nullptr, delimiters)) != nullptr) strcpy(targets[tcount++], token); + while ((token = strtok(nullptr, delimiters)) != nullptr) { + strcpy(targets[tcount++], token); + } strcpy(work, environment->private_path_substitute); token = strtok(work, delimiters); strcpy(substitutes[scount++], token); - while ((token = strtok(nullptr, delimiters)) != nullptr) strcpy(substitutes[scount++], token); + while ((token = strtok(nullptr, delimiters)) != nullptr) { + strcpy(substitutes[scount++], token); + } if (tcount == scount) { for (int i = 0; i < tcount; i++) { - lpath = (int) strlen(targets[i]); + lpath = (int)strlen(targets[i]); if (!strncmp(request->path, targets[i], lpath)) { strcpy(work, &request->path[lpath]); strcpy(request->path, substitutes[i]); @@ -62,7 +67,8 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA } } else { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Unmatched count of Target and Substitute File Paths."); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, + "Unmatched count of Target and Substitute File Paths."); break; } } @@ -79,21 +85,31 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA if (STR_IEQUALS(request->format, "IDA") || STR_IEQUALS(request->format, "IDA3")) { request->request = REQUEST_READ_IDA; -// parseIDAPath(request); // Check Path for file details - } else if (STR_IEQUALS(request->format, "NETCDF")) request->request = REQUEST_READ_CDF; - else if (STR_IEQUALS(request->format, "HDF5")) request->request = REQUEST_READ_HDF5; - else if (STR_IEQUALS(request->format, "XML")) { + // parseIDAPath(request); // Check Path for file details + } else if (STR_IEQUALS(request->format, "NETCDF")) { + request->request = REQUEST_READ_CDF; + } else if (STR_IEQUALS(request->format, "HDF5")) { + request->request = REQUEST_READ_HDF5; + } else if (STR_IEQUALS(request->format, "XML")) { request->request = REQUEST_READ_XML; -// parseXMLPath(request); // Check Path for details - } else if (STR_IEQUALS(request->format, "UFILE")) request->request = REQUEST_READ_UFILE; - else if (STR_IEQUALS(request->format, "BIN") || STR_IEQUALS(request->format, "BINARY")) + // parseXMLPath(request); // Check Path for details + } else if (STR_IEQUALS(request->format, "UFILE")) { + request->request = REQUEST_READ_UFILE; + } else if (STR_IEQUALS(request->format, "BIN") || STR_IEQUALS(request->format, "BINARY")) { request->request = REQUEST_READ_FILE; - else if (STR_IEQUALS(request->format, "PPF")) request->request = REQUEST_READ_PPF; - else if (STR_IEQUALS(request->format, "JPF")) request->request = REQUEST_READ_JPF; - else if (STR_IEQUALS(request->format, "TEST")) request->request = REQUEST_READ_NEW_PLUGIN; - else if (STR_IEQUALS(request->format, "NOTHING")) request->request = REQUEST_READ_NOTHING; - else if (STR_IEQUALS(request->format, "HDATA")) request->request = REQUEST_READ_HDATA; - else if (STR_IEQUALS(request->format, "SQL")) request->request = REQUEST_READ_SQL; + } else if (STR_IEQUALS(request->format, "PPF")) { + request->request = REQUEST_READ_PPF; + } else if (STR_IEQUALS(request->format, "JPF")) { + request->request = REQUEST_READ_JPF; + } else if (STR_IEQUALS(request->format, "TEST")) { + request->request = REQUEST_READ_NEW_PLUGIN; + } else if (STR_IEQUALS(request->format, "NOTHING")) { + request->request = REQUEST_READ_NOTHING; + } else if (STR_IEQUALS(request->format, "HDATA")) { + request->request = REQUEST_READ_HDATA; + } else if (STR_IEQUALS(request->format, "SQL")) { + request->request = REQUEST_READ_SQL; + } UDA_LOG(UDA_LOG_DEBUG, "Request Selected: %d\n", request->request); UDA_LOG(UDA_LOG_DEBUG, "File: %s\n", request->file); @@ -147,17 +163,17 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA break; case REQUEST_READ_MDS: - strcpy(data_source->filename, TrimString(request->file)); // MDS+ Tree - strcpy(data_source->server, TrimString(request->server)); // MDS+ Server Name + strcpy(data_source->filename, TrimString(request->file)); // MDS+ Tree + strcpy(data_source->server, TrimString(request->server)); // MDS+ Server Name copyString(TrimString(request->signal), signal_desc->signal_name, MAXNAME); if (strlen(signal_desc->signal_name) == MAXNAME - 1) { - copyString(TrimString(request->signal), signal_desc->xml, MAXMETA); // Pass via XML member + copyString(TrimString(request->signal), signal_desc->xml, MAXMETA); // Pass via XML member signal_desc->signal_name[0] = '\0'; } - data_source->exp_number = request->exp_number; // MDS+ Tree Number + data_source->exp_number = request->exp_number; // MDS+ Tree Number UDA_LOG(UDA_LOG_DEBUG, "Request: Read MDS+ \n"); UDA_LOG(UDA_LOG_DEBUG, "Server : %s \n", request->server); @@ -174,7 +190,7 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA break; case REQUEST_READ_CDF: - strcpy(data_source->path, TrimString(request->path)); // netCDF File Location + strcpy(data_source->path, TrimString(request->path)); // netCDF File Location copyString(TrimString(request->signal), signal_desc->signal_name, MAXNAME); UDA_LOG(UDA_LOG_DEBUG, "Request: readnetCDF \n"); @@ -183,7 +199,7 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA break; case REQUEST_READ_HDF5: - strcpy(data_source->path, TrimString(request->path)); // HDF5 File Location + strcpy(data_source->path, TrimString(request->path)); // HDF5 File Location copyString(TrimString(request->signal), signal_desc->signal_name, MAXNAME); UDA_LOG(UDA_LOG_DEBUG, "Request: ReadHDF5 \n"); @@ -201,30 +217,29 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA break; case REQUEST_READ_UFILE: - strcpy(data_source->path, TrimString(request->path)); // UFile File Location + strcpy(data_source->path, TrimString(request->path)); // UFile File Location UDA_LOG(UDA_LOG_DEBUG, "Request: ReadUFile \n"); UDA_LOG(UDA_LOG_DEBUG, "UFile File : %s \n", request->path); break; case REQUEST_READ_FILE: - strcpy(data_source->path, TrimString(request->path)); // File Location + strcpy(data_source->path, TrimString(request->path)); // File Location UDA_LOG(UDA_LOG_DEBUG, "Request: ReadBytes \n"); UDA_LOG(UDA_LOG_DEBUG, "File : %s \n", request->path); break; - case REQUEST_READ_HDATA: - strcpy(data_source->path, TrimString(request->path)); // File Location + strcpy(data_source->path, TrimString(request->path)); // File Location UDA_LOG(UDA_LOG_DEBUG, "Request: ReadHData \n"); UDA_LOG(UDA_LOG_DEBUG, "File : %s \n", request->path); break; case REQUEST_READ_SQL: - strcpy(data_source->path, TrimString(request->path)); // SQL database etc. - strcpy(data_source->server, TrimString(request->server)); // SQL server host + strcpy(data_source->path, TrimString(request->path)); // SQL database etc. + strcpy(data_source->server, TrimString(request->server)); // SQL server host strcpy(data_source->format, TrimString(request->format)); strcpy(data_source->archive, TrimString(request->archive)); strcpy(data_source->device_name, TrimString(request->device_name)); @@ -234,24 +249,24 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA break; case REQUEST_READ_NOTHING: - data_source->exp_number = request->exp_number; // Size of Data Block - data_source->pass = request->pass; // Compressible or Not + data_source->exp_number = request->exp_number; // Size of Data Block + data_source->pass = request->pass; // Compressible or Not - if (data_source->exp_number == 0 && data_source->pass == -1) { // May be passed in Path String + if (data_source->exp_number == 0 && data_source->pass == -1) { // May be passed in Path String strcpy(work, request->path); - if (work[0] == '/' && (token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string - if (IsNumber(token)) { // Is the First token an integer number? + if (work[0] == '/' && (token = strtok(work, "/")) != nullptr) { // Tokenise the remaining string + if (IsNumber(token)) { // Is the First token an integer number? request->exp_number = atoi(token); - if ((token = strtok(nullptr, "/")) != nullptr) { // Next Token + if ((token = strtok(nullptr, "/")) != nullptr) { // Next Token if (IsNumber(token)) { - request->pass = atoi(token); // Must be the Pass number + request->pass = atoi(token); // Must be the Pass number } else { - strcpy(request->tpass, token); // anything else + strcpy(request->tpass, token); // anything else } } } - data_source->exp_number = request->exp_number; // Size of Data Block - data_source->pass = request->pass; // Compressible or Not + data_source->exp_number = request->exp_number; // Size of Data Block + data_source->pass = request->pass; // Compressible or Not } } @@ -287,12 +302,13 @@ int udaServerLegacyPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNA default: UDA_LOG(UDA_LOG_DEBUG, "Unknown Requested Data Access Routine (%d) \n", request->request); err = 9999; - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Unknown Requested Data Access Routine"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Unknown Requested Data Access Routine"); break; } - if (err != 0) break; + if (err != 0) { + break; + } //------------------------------------------------------------------------------------------------ // End of Error Trap diff --git a/source/server/serverLegacyPlugin.h b/source/server/serverLegacyPlugin.h old mode 100755 new mode 100644 index 1f3bbab1..ab32f426 --- a/source/server/serverLegacyPlugin.h +++ b/source/server/serverLegacyPlugin.h @@ -1,10 +1,10 @@ #pragma once #ifndef UDA_SERVER_SERVERLEGACYPLUGIN_H -#define UDA_SERVER_SERVERLEGACYPLUGIN_H +# define UDA_SERVER_SERVERLEGACYPLUGIN_H -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "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 old mode 100755 new mode 100644 index 882af287..aa0d0e80 --- a/source/server/serverMain.cpp +++ b/source/server/serverMain.cpp @@ -8,11 +8,11 @@ #include "udaServer.h" -int main(int argc, char ** argv) +int main(int argc, char** argv) { // Optional sleep at startup - char * env = getenv("UDA_SLEEP"); + char* env = getenv("UDA_SLEEP"); if (env != nullptr) { sleep((unsigned int)atoi(env)); } diff --git a/source/server/serverPlugin.cpp b/source/server/serverPlugin.cpp old mode 100755 new mode 100644 index 06216458..a840bd2d --- a/source/server/serverPlugin.cpp +++ b/source/server/serverPlugin.cpp @@ -1,41 +1,41 @@ /*--------------------------------------------------------------- -* Identify the correct UDA Data Server Plugin -*---------------------------------------------------------------------------------------------------------------------*/ + * Identify the correct UDA Data Server Plugin + *---------------------------------------------------------------------------------------------------------------------*/ #include "serverPlugin.h" -#include #include -#include +#include #include +#include #if defined(__GNUC__) # include #else -# include # include +# include # define dup _dup # define dup2 _dup2 #endif +#include "initStructs.h" +#include "struct.h" #include +#include #include -#include "initStructs.h" #include #include #include -#include #include -#include "struct.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 +#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 void allocPluginList(int count, PLUGINLIST* plugin_list) { if (count >= plugin_list->mcount) { plugin_list->mcount = plugin_list->mcount + REQUEST_PLUGIN_MSTEP; - plugin_list->plugin = (PLUGIN_DATA*)realloc((void*)plugin_list->plugin, - plugin_list->mcount * sizeof(PLUGIN_DATA)); + plugin_list->plugin = + (PLUGIN_DATA*)realloc((void*)plugin_list->plugin, plugin_list->mcount * sizeof(PLUGIN_DATA)); } } @@ -47,11 +47,11 @@ void resetPlugins(const PLUGINLIST* plugin_list) strcpy(request_block.function, "reset"); idam_plugin_interface.interfaceVersion = 1; - idam_plugin_interface.housekeeping = 1; // Force a full reset + idam_plugin_interface.housekeeping = 1; // Force a full reset idam_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(&idam_plugin_interface); // Call the housekeeping method } } } @@ -120,37 +120,37 @@ int udaServerRedirectStdStreams(int reset) // Any OS messages will corrupt xdr streams so re-divert IO from plugin libraries to a temporary file // Multi platform compliance - //static FILE* originalStdFH = nullptr; - //static FILE* originalErrFH = nullptr; + // static FILE* originalStdFH = nullptr; + // static FILE* originalErrFH = nullptr; static int originalStdFH = 0; static int originalErrFH = 0; static FILE* mdsmsgFH = nullptr; - static char mksdir_template[MAXPATH] = { 0 }; - static char tempFile[MAXPATH] = { 0 }; + static char mksdir_template[MAXPATH] = {0}; + static char tempFile[MAXPATH] = {0}; static bool singleFile = false; if (!reset) { if (!singleFile) { - const char* env = getenv("UDA_PLUGIN_DEBUG_SINGLEFILE"); // Use a single file for all plugin data requests + const char* env = getenv("UDA_PLUGIN_DEBUG_SINGLEFILE"); // Use a single file for all plugin data requests if (env != nullptr) { - singleFile = true; // Define UDA_PLUGIN_DEBUG to retain the file + singleFile = true; // Define UDA_PLUGIN_DEBUG to retain the file } } if (mdsmsgFH != nullptr && singleFile) { // Multi platform compliance - //stdout = mdsmsgFH; // Redirect all IO to a temporary file - //stderr = mdsmsgFH; + // stdout = mdsmsgFH; // Redirect all IO to a temporary file + // stderr = mdsmsgFH; dup2(fileno(mdsmsgFH), fileno(stdout)); dup2(fileno(mdsmsgFH), fileno(stderr)); return 0; } // Multi platform compliance - //originalStdFH = stdout; // Retain current values - //originalErrFH = stderr; + // originalStdFH = stdout; // Retain current values + // originalErrFH = stderr; originalStdFH = dup(fileno(stdout)); originalErrFH = dup(fileno(stderr)); mdsmsgFH = nullptr; @@ -190,8 +190,8 @@ int udaServerRedirectStdStreams(int reset) } // Multi platform compliance - //stdout = mdsmsgFH; // Redirect to a temporary file - //stderr = mdsmsgFH; + // stdout = mdsmsgFH; // Redirect to a temporary file + // stderr = mdsmsgFH; dup2(fileno(mdsmsgFH), fileno(stdout)); dup2(fileno(mdsmsgFH), fileno(stderr)); } else { @@ -210,7 +210,7 @@ int udaServerRedirectStdStreams(int reset) mdsmsgFH = nullptr; if (getenv("UDA_PLUGIN_DEBUG") == nullptr) { errno = 0; - int rc = remove(tempFile); // Delete the temporary file + int rc = remove(tempFile); // Delete the temporary file if (rc) { int err = errno; UDA_THROW_ERROR(err, strerror(err)); @@ -220,8 +220,8 @@ int udaServerRedirectStdStreams(int reset) } // Multi platform compliance - //stdout = originalStdFH; - //stderr = originalErrFH; + // stdout = originalStdFH; + // stderr = originalErrFH; dup2(originalStdFH, fileno(stdout)); dup2(originalErrFH, fileno(stderr)); @@ -230,8 +230,8 @@ int udaServerRedirectStdStreams(int reset) UDA_LOG(UDA_LOG_DEBUG, "Resetting original file handles\n"); // Multi platform compliance - //stdout = originalStdFH; - //stderr = originalErrFH; + // stdout = originalStdFH; + // stderr = originalErrFH; dup2(originalStdFH, fileno(stdout)); dup2(originalErrFH, fileno(stderr)); } @@ -319,9 +319,9 @@ int udaServerPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC // changePlugin option disabled in this context // private malloc log and userdefinedtypelist -int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_request, - DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, const PLUGINLIST* plugin_list, - const char* logRecord, const ENVIRONMENT* environment) +int 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) { if (STR_EQUALS(client_block->DOI, "")) { @@ -332,7 +332,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque // Identify the Provenance Gathering plugin (must be a function library type plugin) static int plugin_id = -2; - static int execMethod = 1; // The default method used to write efficiently to the backend SQL server + static int execMethod = 1; // The default method used to write efficiently to the backend SQL server char* env = nullptr; struct timeval tv_start = {}; @@ -340,7 +340,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque gettimeofday(&tv_start, nullptr); - if (plugin_id == -2) { // On initialisation + if (plugin_id == -2) { // On initialisation plugin_id = -1; if ((env = getenv("UDA_PROVENANCE_PLUGIN")) != nullptr) { // Must be set in the server startup script @@ -358,12 +358,9 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque UDA_LOG(UDA_LOG_DEBUG, "plugin_list->plugin[id].idamPlugin != nullptr = %d\n", plugin_list->plugin[id].idamPlugin != nullptr); } - if (id >= 0 && - plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION && - !environment->external_user && - plugin_list->plugin[id].status == UDA_PLUGIN_OPERATIONAL && - plugin_list->plugin[id].pluginHandle != nullptr && - plugin_list->plugin[id].idamPlugin != nullptr) { + if (id >= 0 && plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION && + !environment->external_user && plugin_list->plugin[id].status == UDA_PLUGIN_OPERATIONAL && + plugin_list->plugin[id].pluginHandle != nullptr && plugin_list->plugin[id].idamPlugin != nullptr) { plugin_id = id; } } @@ -389,17 +386,17 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque // mimic a client request if (logRecord == nullptr || strlen(logRecord) == 0) { - snprintf(request.signal, MAXMETA, "%s::putSignal(uuid='%s',requestedSignal='%s',requestedSource='%s', " - "trueSignal='%s', trueSource='%s', trueSourceDOI='%s', execMethod=%d, status=new)", - plugin_list->plugin[plugin_id].format, client_block->DOI, - original_request->signal, original_request->source, - signal_desc->signal_name, data_source->path, "", execMethod); + snprintf(request.signal, MAXMETA, + "%s::putSignal(uuid='%s',requestedSignal='%s',requestedSource='%s', " + "trueSignal='%s', trueSource='%s', trueSourceDOI='%s', execMethod=%d, status=new)", + plugin_list->plugin[plugin_id].format, client_block->DOI, original_request->signal, + original_request->source, signal_desc->signal_name, data_source->path, "", execMethod); } else { // need 2> record the server log record snprintf(request.signal, MAXMETA, "%s::putSignal(uuid='%s',logRecord='%s', execMethod=%d, status=update)", - plugin_list->plugin[plugin_id].format, client_block->DOI, logRecord, execMethod); + plugin_list->plugin[plugin_id].format, client_block->DOI, logRecord, execMethod); } // Activate the plugin @@ -468,8 +465,7 @@ int udaProvenancePlugin(CLIENT_BLOCK* client_block, REQUEST_DATA* original_reque freeNameValueList(&request.nameValueList); UDA_LOG(UDA_LOG_DEBUG, "testing for bug!!!\n"); - if (data_block.opaque_type != UDA_OPAQUE_TYPE_UNKNOWN || - data_block.opaque_count != 0 || + if (data_block.opaque_type != UDA_OPAQUE_TYPE_UNKNOWN || data_block.opaque_count != 0 || data_block.opaque_block != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "bug detected: mitigation!!!\n"); data_block.opaque_block = nullptr; @@ -510,19 +506,21 @@ int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* UDA_LOG(UDA_LOG_DEBUG, "Entered: noPluginRegistered state = %d\n", noPluginRegistered); UDA_LOG(UDA_LOG_DEBUG, "Entered: plugin_id state = %d\n", plugin_id); - if (plugin_id >= 0) return plugin_id; // Plugin previously identified - if (noPluginRegistered) return -1; // No Plugin for the MetaData Catalog to resolve Generic Name mappings + if (plugin_id >= 0) { + return plugin_id; // Plugin previously identified + } + if (noPluginRegistered) { + return -1; // No Plugin for the MetaData Catalog to resolve Generic Name mappings + } // Identify the MetaData Catalog plugin (must be a function library type plugin) char* env = nullptr; - if ((env = getenv("UDA_METADATA_PLUGIN")) != nullptr) { // Must be set in the server startup script - int id = findPluginIdByFormat(env, plugin_list); // Must be defined in the server plugin configuration file - if (id >= 0 && - plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION && + if ((env = getenv("UDA_METADATA_PLUGIN")) != nullptr) { // Must be set in the server startup script + int id = findPluginIdByFormat(env, plugin_list); // Must be defined in the server plugin configuration file + if (id >= 0 && plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION && plugin_list->plugin[id].status == UDA_PLUGIN_OPERATIONAL && - plugin_list->plugin[id].pluginHandle != nullptr && - plugin_list->plugin[id].idamPlugin != nullptr) { + plugin_list->plugin[id].pluginHandle != nullptr && plugin_list->plugin[id].idamPlugin != nullptr) { plugin_id = (short)id; } @@ -532,12 +530,14 @@ int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* } UDA_LOG(UDA_LOG_DEBUG, "Generic Name Mapping Plugin Name: %s\n", env); - UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_CLASS_FUNCTION?: %d\n", plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION); + UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_CLASS_FUNCTION?: %d\n", + plugin_list->plugin[id].plugin_class == UDA_PLUGIN_CLASS_FUNCTION); UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_PRIVATE?: %d\n", plugin_list->plugin[id].is_private == UDA_PLUGIN_PRIVATE); UDA_LOG(UDA_LOG_DEBUG, "External User?: %d\n", environment->external_user); UDA_LOG(UDA_LOG_DEBUG, "Private?: %d\n", plugin_list->plugin[id].is_private == UDA_PLUGIN_PRIVATE && environment->external_user); - UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_OPERATIONAL?: %d\n", plugin_list->plugin[id].status == UDA_PLUGIN_OPERATIONAL); + UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_OPERATIONAL?: %d\n", + plugin_list->plugin[id].status == UDA_PLUGIN_OPERATIONAL); UDA_LOG(UDA_LOG_DEBUG, "Plugin OK?: %d\n", plugin_list->plugin[id].pluginHandle != nullptr && plugin_list->plugin[id].idamPlugin != nullptr); UDA_LOG(UDA_LOG_DEBUG, "id: %d\n", id); @@ -546,7 +546,9 @@ int udaServerMetaDataPluginId(const PLUGINLIST* plugin_list, const ENVIRONMENT* UDA_LOG(UDA_LOG_DEBUG, "NO Generic Name Mapping Plugin identified\n"); } - if (plugin_id < 0) noPluginRegistered = 1; // No Plugin found (registered) + if (plugin_id < 0) { + noPluginRegistered = 1; // No Plugin found (registered) + } return plugin_id; } @@ -611,7 +613,9 @@ int udaServerMetaDataPlugin(const PLUGINLIST* plugin_list, int plugin_id, REQUES if (rc != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, rc, "Error Resetting Redirected Plugin Message Output"); } - if (err != 0) return err; + if (err != 0) { + return err; + } return rc; } diff --git a/source/server/serverPlugin.h b/source/server/serverPlugin.h old mode 100755 new mode 100644 index 2c84ace5..333a9138 --- a/source/server/serverPlugin.h +++ b/source/server/serverPlugin.h @@ -1,12 +1,12 @@ #ifndef UDA_SERVER_SERVERPLUGIN_H #define UDA_SERVER_SERVERPLUGIN_H -#include "udaPlugin.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 +#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" { diff --git a/source/server/serverProcessing.cpp b/source/server/serverProcessing.cpp old mode 100755 new mode 100644 index 5a2c8808..b2d0f2a5 --- a/source/server/serverProcessing.cpp +++ b/source/server/serverProcessing.cpp @@ -2,11 +2,10 @@ #include -#include #include "udaTypes.h" +#include -template -bool reduce_dim(DIMS* ddim) +template bool reduce_dim(DIMS* ddim) { T sf = (T)0.0; switch (ddim->method) { @@ -111,8 +110,7 @@ int reduce_data(DATA_BLOCK* data_block) return 0; } -template -int cast_dim(DIMS* ddim) +template int cast_dim(DIMS* ddim) { switch (ddim->method) { case 1: { @@ -136,8 +134,9 @@ int cast_dim(DIMS* ddim) } case 2: { auto newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((T*)ddim->offs + i); + } free(ddim->offs); ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; @@ -171,7 +170,7 @@ int cast_data(DATA_BLOCK* data_block, const CLIENT_BLOCK* client_block) int rc = 0; for (unsigned int k = 0; k < data_block->rank; k++) { if (client_block->get_timedble && k != (unsigned int)data_block->order) { - continue; // Only Process the Time Dimension + continue; // Only Process the Time Dimension } UDA_LOG(UDA_LOG_DEBUG, "Processing Dimension %d\n", k); DIMS* ddim = &data_block->dims[k]; diff --git a/source/server/serverProcessing.h b/source/server/serverProcessing.h old mode 100755 new mode 100644 index 7c6e252b..2b4b2c1b --- a/source/server/serverProcessing.h +++ b/source/server/serverProcessing.h @@ -1,12 +1,11 @@ #pragma once #ifndef UDA_SERVER_SERVERPROCESSING_H -#define UDA_SERVER_SERVERPROCESSING_H +# define UDA_SERVER_SERVERPROCESSING_H -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" -int serverProcessing(CLIENT_BLOCK client_block, DATA_BLOCK *data_block); +int serverProcessing(CLIENT_BLOCK client_block, DATA_BLOCK* data_block); #endif // UDA_SERVER_SERVERPROCESSING_H - diff --git a/source/server/serverStartup.cpp b/source/server/serverStartup.cpp old mode 100755 new mode 100644 index 9d32443e..fcc8aa5f --- a/source/server/serverStartup.cpp +++ b/source/server/serverStartup.cpp @@ -1,11 +1,11 @@ #include "serverStartup.h" -#include #include +#include #include -#include #include +#include #include "getServerEnvironment.h" @@ -29,7 +29,7 @@ int startup() } errno = 0; - std::string log_file = std::string{ environment->logdir } + "Access.log"; + std::string log_file = std::string{environment->logdir} + "Access.log"; FILE* accout = fopen(log_file.c_str(), environment->logmode); if (errno != 0) { @@ -44,7 +44,7 @@ int startup() if (environment->loglevel <= UDA_LOG_ERROR) { errno = 0; - std::string log_file = std::string{ environment->logdir } + "Error.log"; + std::string log_file = std::string{environment->logdir} + "Error.log"; FILE* errout = fopen(log_file.c_str(), environment->logmode); if (errno != 0) { @@ -59,7 +59,7 @@ int startup() if (environment->loglevel <= UDA_LOG_WARN) { errno = 0; - std::string log_file = std::string{ environment->logdir } + "DebugServer.log"; + std::string log_file = std::string{environment->logdir} + "DebugServer.log"; FILE* dbgout = fopen(log_file.c_str(), environment->logmode); if (errno != 0) { diff --git a/source/server/serverStartup.h b/source/server/serverStartup.h old mode 100755 new mode 100644 index 963ed944..dfe18b10 --- a/source/server/serverStartup.h +++ b/source/server/serverStartup.h @@ -1,11 +1,10 @@ #pragma once #ifndef UDA_SERVER_SERVERSTARTUP_H -#define UDA_SERVER_SERVERSTARTUP_H +# define UDA_SERVER_SERVERSTARTUP_H -#include "export.h" +# include "export.h" int startup(); #endif // UDA_SERVER_SERVERSTARTUP_H - diff --git a/source/server/serverSubsetData.cpp b/source/server/serverSubsetData.cpp old mode 100755 new mode 100644 index e8eceaee..10f197d4 --- a/source/server/serverSubsetData.cpp +++ b/source/server/serverSubsetData.cpp @@ -6,31 +6,31 @@ //-------------------------------------------------------------------------------------------------------------------- #include "serverSubsetData.h" -#include "getServerEnvironment.h" +#include "clientserver/makeRequestBlock.h" #include "clientserver/parseOperation.h" +#include "getServerEnvironment.h" #include "udaPlugin.h" -#include "clientserver/makeRequestBlock.h" -#include -#include #include -#include +#include +#include #include +#include #if defined(__GNUC__) # include #else # define strncasecmp _strnicmp #endif -#include -#include -#include -#include "udaTypes.h" -#include "struct.h" #include "initStructs.h" +#include "struct.h" +#include "udaTypes.h" +#include #include +#include +#include #include -#include +#include //---------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------- @@ -46,28 +46,27 @@ // // reform - reduce the rank by 1 if the dimension length is 1 and the rank > 1 - // todo: // static int get_subset_indices(const std::string& operation, DIMS* dim, double value, unsigned int* subset_indices); -int apply_sub_setting(DIMS* dims, int rank, int dim_id, - char* data, int ndata, int data_type, int not_operation, +int apply_sub_setting(DIMS* dims, int rank, int dim_id, char* data, int ndata, int data_type, int not_operation, int start, int end, int start1, int end1, int stride, int* n, void** new_data); -int number_of_subsetting_operations(const ACTION* action) { +int number_of_subsetting_operations(const ACTION* action) +{ switch (action->actionType) { case UDA_COMPOSITE_TYPE: // XML Based sub-setting if (action->composite.nsubsets == 0) { - return 0; // Nothing to Subset + return 0; // Nothing to Subset } return action->composite.nsubsets; case UDA_SERVER_SIDE_TYPE: // Client Requested sub-setting if (action->serverside.nsubsets == 0) { - return 0; // Nothing to Subset + return 0; // Nothing to Subset } return action->serverside.nsubsets; case UDA_SUBSET_TYPE: @@ -80,45 +79,44 @@ int number_of_subsetting_operations(const ACTION* action) { int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGMALLOCLIST* logmalloclist) { - int n_bound = subset.nbound; // the Number of operations in the set + int n_bound = subset.nbound; // the Number of operations in the set // treat x[0] as a no-op when x is a scalar - if (n_bound == 1 - && (subset.lbindex[0].init && subset.lbindex[0].value == 0) - && (subset.ubindex[0].init && subset.ubindex[0].value == 1) - && data_block->rank == 0) { + if (n_bound == 1 && (subset.lbindex[0].init && subset.lbindex[0].value == 0) && + (subset.ubindex[0].init && subset.ubindex[0].value == 1) && data_block->rank == 0) { return 0; } - for (int j = 0; j < n_bound; j++) { // Process each operation separately + for (int j = 0; j < n_bound; j++) { // Process each operation separately double value = subset.bound[j]; - std::string operation = subset.operation[j]; // a single operation - int dim_id = subset.dimid[j]; // applied to this dimension (if -1 then to data only!) + std::string operation = subset.operation[j]; // a single operation + int dim_id = subset.dimid[j]; // applied to this dimension (if -1 then to data only!) - UDA_LOG(UDA_LOG_DEBUG, "[%d][%d]Value = %e, Operation = %s, DIM id = %d, Reform = %d\n", ii, j, value, operation.c_str(), dim_id, subset.reform); + UDA_LOG(UDA_LOG_DEBUG, "[%d][%d]Value = %e, Operation = %s, DIM id = %d, Reform = %d\n", ii, j, value, + operation.c_str(), dim_id, subset.reform); if (dim_id < 0 || dim_id >= (int)data_block->rank) { - UDA_LOG(UDA_LOG_ERROR, "DIM id = %d, Rank = %d, Test = %d \n", - dim_id, data_block->rank, dim_id >= (int)data_block->rank); + UDA_LOG(UDA_LOG_ERROR, "DIM id = %d, Rank = %d, Test = %d \n", dim_id, data_block->rank, + dim_id >= (int)data_block->rank); printDataBlock(*data_block); - UDA_THROW_ERROR(9999, "Data Subsetting is Impossible as the subset Dimension is not Compatible with the Rank of the Signal"); + UDA_THROW_ERROR( + 9999, + "Data Subsetting is Impossible as the subset Dimension is not Compatible with the Rank of the Signal"); return 9999; } //---------------------------------------------------------------------------------------------------------------------------- // Operations on Simple Data Structures: target must be an Atomic Type, Scalar, Name is Case Sensitive // - // (mapType=1) Array of Structures - member = single scalar value: rank and shape = rank and shape of structure array - // (mapType=2) Single Structure - member = array of values: rank and shape = increase rank and shape of structure member by 1 - // Array of Structures - member = array of values: Not allowed. + // (mapType=1) Array of Structures - member = single scalar value: rank and shape = rank and shape of structure + // array (mapType=2) Single Structure - member = array of values: rank and shape = increase rank and shape of + // structure member by 1 Array of Structures - member = array of values: Not allowed. // // (mapType=3) structure[14].array[100] -> newarray[14][100]: - if (data_block->opaque_type == UDA_OPAQUE_TYPE_STRUCTURES - && subset.member[0] != '\0' - && data_block->opaque_block != nullptr) { - + if (data_block->opaque_type == UDA_OPAQUE_TYPE_STRUCTURES && subset.member[0] != '\0' && + data_block->opaque_block != nullptr) { auto udt = (USERDEFINEDTYPE*)data_block->opaque_block; @@ -126,7 +124,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM for (int i = 0; i < udt->fieldcount; i++) { char* extract = nullptr; - if (STR_EQUALS(udt->compoundfield[i].name, subset.member)) { // Locate target member by name + if (STR_EQUALS(udt->compoundfield[i].name, subset.member)) { // Locate target member by name int data_n = data_block->data_n; @@ -143,17 +141,18 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM int* shape = nullptr; - if (!udt->compoundfield[i].pointer) { // Regular Array of data + if (!udt->compoundfield[i].pointer) { // Regular Array of data switch (udt->compoundfield[i].atomictype) { case UDA_TYPE_DOUBLE: { - double* data = nullptr, * dp; + double *data = nullptr, *dp; if (mapType == 1) { data = (double*)malloc(data_n * sizeof(double)); - for (int k = 0; k < data_n; k++) - data[k] = *(double*)&data_block->data[k * udt->size + - udt->compoundfield[i].offset]; + for (int k = 0; k < data_n; k++) { + data[k] = + *(double*)&data_block->data[k * udt->size + udt->compoundfield[i].offset]; + } } else { if (mapType == 2) { data_n = udt_count; @@ -168,17 +167,18 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM if ((shape = udt->compoundfield[i].shape) == nullptr && udt->compoundfield[i].rank > 1) { - UDA_THROW_ERROR(999, "The Data Structure member's shape data is missing (rank > 1)"); + UDA_THROW_ERROR( + 999, "The Data Structure member's shape data is missing (rank > 1)"); } - } else { // mapType == 3 + } else { // mapType == 3 int total_n; total_n = udt_count * data_n; data = (double*)malloc(total_n * sizeof(double)); int jjj = 0; - for (int jj = 0; jj < data_n; jj++) { // Loop over structures - dp = (double*)&data_block->data[jj * udt->size + - udt->compoundfield[i].offset]; + for (int jj = 0; jj < data_n; jj++) { // Loop over structures + dp = (double*)&data_block + ->data[jj * udt->size + udt->compoundfield[i].offset]; for (int k = 0; k < udt_count; k++) { data[jjj++] = dp[k]; } @@ -192,7 +192,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM } } - } else { // Locate the pointer data's properties: + } else { // Locate the pointer data's properties: int count = 0; int size = 0; @@ -210,8 +210,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM // Properties Must be identical for all structure array elements extract = *(char**)&data_block->data[jj * udt->size + udt->compoundfield[i].offset]; - findMalloc2(logmalloclist, (void*)extract, &count, &size, &type_name, &rank, - &shape); + findMalloc2(logmalloclist, (void*)extract, &count, &size, &type_name, &rank, &shape); if (jj > 0) { if (count != count_p || size != size_p || rank != rank_p || strcmp(type_name, type_name_p) != 0) { @@ -220,12 +219,13 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM if (shape != nullptr) { for (int k = 0; k < rank; k++) { if (shape[k] != shape_p[k]) { - //ERROR + // ERROR } } } else { if (rank > 1) { - UDA_THROW_ERROR(999, "The Data Structure member's shape data is missing (rank > 1)"); + UDA_THROW_ERROR( + 999, "The Data Structure member's shape data is missing (rank > 1)"); } } } @@ -243,19 +243,18 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM if (mapType == 3) { UDA_THROW_ERROR(999, "Unable to subset an array of Data Structures when the target " - "member is also an array. (Functionality has not been implemented!)"); + "member is also an array. (Functionality has not been implemented!)"); } int type = gettypeof(type_name); switch (type) { case UDA_TYPE_DOUBLE: { - double* data = nullptr, * dp; + double *data = nullptr, *dp; if (mapType == 1) { data = (double*)malloc(data_n * sizeof(double)); for (int k = 0; k < data_n; k++) { - dp = *(double**)&data_block->data[k * udt->size + - udt->compoundfield[i].offset]; + dp = *(double**)&data_block->data[k * udt->size + udt->compoundfield[i].offset]; data[k] = dp[0]; } } else { @@ -273,7 +272,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM break; } - //default: + // default: } } @@ -326,8 +325,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM unsigned int k0 = data_block->rank; data_block->rank = data_block->rank + udt->compoundfield[i].rank; - data_block->dims = (DIMS*)realloc((void*)data_block->dims, - data_block->rank * sizeof(DIMS)); + data_block->dims = (DIMS*)realloc((void*)data_block->dims, data_block->rank * sizeof(DIMS)); for (unsigned int k = k0; k < data_block->rank; k++) { initDimBlock(&data_block->dims[k]); @@ -356,7 +354,6 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM data_block->opaque_count = 0; data_block->opaque_block = nullptr; break; - } } } @@ -366,26 +363,26 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM if (operation == "*") { continue; - } // This means No subset - Part of an array Reshape Operation + } // This means No subset - Part of an array Reshape Operation - if (operation[0] == ':' - && (subset.lbindex[j].init ? subset.lbindex[j].value : 0) == 0 - && (subset.ubindex[j].init ? subset.lbindex[j].value : data_block->dims[dim_id].dim_n) == data_block->dims[dim_id].dim_n - && (subset.stride[j].init ? subset.stride[j].value : 1) == 1) { - continue; // subset spans the complete dimension + if (operation[0] == ':' && (subset.lbindex[j].init ? subset.lbindex[j].value : 0) == 0 && + (subset.ubindex[j].init ? subset.lbindex[j].value : data_block->dims[dim_id].dim_n) == + data_block->dims[dim_id].dim_n && + (subset.stride[j].init ? subset.stride[j].value : 1) == 1) { + continue; // subset spans the complete dimension } //---------------------------------------------------------------------------------------------------------------------------- // Decompress the dimensional data if necessary & free Heap Associated with Compression DIMS new_dim; - initDimBlock(&new_dim); // Holder for the Sub-setted Dimension (part copy of the original) + initDimBlock(&new_dim); // Holder for the Sub-setted Dimension (part copy of the original) - auto dim = &(data_block->dims[dim_id]); // the original dimension to be subset + auto dim = &(data_block->dims[dim_id]); // the original dimension to be subset if (dim->compressed) { uncompressDim(dim); - dim->compressed = 0; // Can't preserve this status after the subset has been applied + dim->compressed = 0; // Can't preserve this status after the subset has been applied dim->method = 0; free(dim->sams); @@ -393,7 +390,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM free(dim->ints); dim->udoms = 0; - dim->sams = nullptr; // Avoid double freeing of Heap + dim->sams = nullptr; // Avoid double freeing of Heap dim->offs = nullptr; dim->ints = nullptr; } @@ -413,19 +410,19 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM // Sub-setting Indices -// int start = -1; // Starting Index satisfying the operation -// int end = -1; // Ending Index + // int start = -1; // Starting Index satisfying the operation + // int end = -1; // Ending Index int start1 = -1; int end1 = -1; // Test for Array Reshaping Operations - int reshape = 0; // Sub-setting has been defined using array indexing notation + int reshape = 0; // Sub-setting has been defined using array indexing notation - auto not_operation = (operation[0] == '!'); // a NOT operator => One or Two subsets + auto not_operation = (operation[0] == '!'); // a NOT operator => One or Two subsets if (operation[0] == '*') { - continue; // This means No dimensional subset - Part of an array Reshape Operation + continue; // This means No dimensional subset - Part of an array Reshape Operation } int dim_n = 0; @@ -434,10 +431,10 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM int end = dim->dim_n; int stride = 1; - if (operation[0] == ':') { // Reshape Operation - Index Range Specified - auto maybe_start = subset.lbindex[j]; // Number before the first : - auto maybe_end = subset.ubindex[j]; // Number after the first : - auto maybe_stride = subset.stride[j]; // Number after the second : + if (operation[0] == ':') { // Reshape Operation - Index Range Specified + auto maybe_start = subset.lbindex[j]; // Number before the first : + auto maybe_end = subset.ubindex[j]; // Number after the first : + auto maybe_stride = subset.stride[j]; // Number after the second : start = (int)(maybe_start.init ? maybe_start.value : 0); if (start < 0) { @@ -458,7 +455,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM dim_n = abs((end - start) / stride); } - if (operation[0] == '#') { // Reshape Operation - Highest array position (last value) + if (operation[0] == '#') { // Reshape Operation - Highest array position (last value) start = dim->dim_n - 1; end = dim->dim_n; reshape = 1; @@ -494,10 +491,10 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM start = (int)subset_indices[0]; end = (int)subset_indices[dim_n - 1]; - if (not_operation && dim_n > 1) { // Double Range ? + if (not_operation && dim_n > 1) { // Double Range ? int range2 = 0; if (dim_n == dim->dim_n) { - not_operation = false; // No Second Range found so switch OFF NOT Operation + not_operation = false; // No Second Range found so switch OFF NOT Operation } else { end1 = (int)subset_indices[dim_n - 1]; for (int k = 0; k < dim_n; k++) { @@ -509,12 +506,12 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM } range2 = end1 - start1 + 1; } - if (dim_n != end - start + 1 + range2) { // Dimension array is Not well ordered! + if (dim_n != end - start + 1 + range2) { // Dimension array is Not well ordered! free(subset_indices); UDA_THROW_ERROR(9999, "The Dimensional Array is Not Ordered: Unable to Subset"); } } else { - if (dim_n != end - start + 1) { // Dimension array is Not well ordered! + if (dim_n != end - start + 1) { // Dimension array is Not well ordered! free(subset_indices); UDA_THROW_ERROR(9999, "The Dimensional Array is Not Ordered: Unable to Subset"); } @@ -535,21 +532,23 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM int n; int ierr = 0; - if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->dim, dim_n, dim->data_type, not_operation, - start, end, start1, end1, stride, &n, (void**)&new_dim.dim)) != 0) { + if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->dim, dim_n, dim->data_type, not_operation, start, end, + start1, end1, stride, &n, (void**)&new_dim.dim)) != 0) { return ierr; } if (dim->errhi != nullptr && dim->error_type != UDA_TYPE_UNKNOWN) { - if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->errhi, dim_n, dim->error_type, not_operation, - start, end, start1, end1, stride, &n, (void**)&new_dim.errhi)) != 0) + if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->errhi, dim_n, dim->error_type, not_operation, start, end, + start1, end1, stride, &n, (void**)&new_dim.errhi)) != 0) { return ierr; + } } if (dim->errlo != nullptr && dim->error_type != UDA_TYPE_UNKNOWN) { - if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->errlo, dim_n, dim->error_type, not_operation, - start, end, start1, end1, stride, &n, (void**)&new_dim.errlo)) != 0) + if ((ierr = apply_sub_setting(dim, 1, dim_id, dim->errlo, dim_n, dim->error_type, not_operation, start, end, + start1, end1, stride, &n, (void**)&new_dim.errlo)) != 0) { return ierr; + } } //----------------------------------------------------------------------------------------------------------------------- @@ -560,9 +559,9 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM int n_data; char* new_data; - if ((ierr = apply_sub_setting(data_block->dims, data_block->rank, dim_id, data_block->data, - data_block->data_n, data_block->data_type, not_operation, - start, end, start1, end1, stride, &n_data, (void**)&new_data)) != 0) { + if ((ierr = apply_sub_setting(data_block->dims, data_block->rank, dim_id, data_block->data, data_block->data_n, + data_block->data_type, not_operation, start, end, start1, end1, stride, &n_data, + (void**)&new_data)) != 0) { return ierr; } @@ -570,33 +569,34 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM if (data_block->error_type != UDA_TYPE_UNKNOWN && data_block->errhi != nullptr) { if ((ierr = apply_sub_setting(data_block->dims, data_block->rank, dim_id, data_block->errhi, - data_block->data_n, data_block->error_type, not_operation, - start, end, start1, end1, stride, &n, (void**)&new_errhi)) != 0) { + data_block->data_n, data_block->error_type, not_operation, start, end, start1, + end1, stride, &n, (void**)&new_errhi)) != 0) { return ierr; } - free(data_block->errhi); // Free Original Heap - data_block->errhi = new_errhi; // Replace with the Reshaped Array + free(data_block->errhi); // Free Original Heap + data_block->errhi = new_errhi; // Replace with the Reshaped Array } char* new_errlo; if (data_block->error_type != UDA_TYPE_UNKNOWN && dim->errlo != nullptr) { if ((ierr = apply_sub_setting(data_block->dims, data_block->rank, dim_id, data_block->errlo, - data_block->data_n, data_block->error_type, not_operation, - start, end, start1, end1, stride, &n, (void**)&new_errlo)) != 0) { + data_block->data_n, data_block->error_type, not_operation, start, end, start1, + end1, stride, &n, (void**)&new_errlo)) != 0) { return ierr; } - free(data_block->errlo); // Free Original Heap - data_block->errlo = new_errlo; // Replace with the Reshaped Array + free(data_block->errlo); // Free Original Heap + data_block->errlo = new_errlo; // Replace with the Reshaped Array } data_block->data_n = n_data; - free(data_block->data); // Free Original Heap - data_block->data = new_data; // Replace with the Reshaped Array + free(data_block->data); // Free Original Heap + data_block->data = new_data; // Replace with the Reshaped Array // replace the Original Dimensional Structure with the New Subsetted Structure unless a - // REFORM [Rank Reduction] has been requested and the dimension length is 1 (this has no effect on the Data Array items) + // REFORM [Rank Reduction] has been requested and the dimension length is 1 (this has no effect on the Data + // Array items) // Free Heap associated with the original Dimensional Structure Array @@ -610,7 +610,7 @@ int process_subset_operation(int ii, SUBSET subset, DATA_BLOCK* data_block, LOGM // Save the reshaped Dimension or Reform the whole - data_block->dims[dim_id] = new_dim; // Replace with the subsetted dimension + data_block->dims[dim_id] = new_dim; // Replace with the subsetted dimension } return 0; @@ -626,26 +626,38 @@ int reform_data(DATA_BLOCK* data_block) data_block->dims[j].compressed = 0; data_block->dims[j].method = 0; - if (data_block->dims[j].dim != nullptr) free(data_block->dims[j].dim); - if (data_block->dims[j].errlo != nullptr) free(data_block->dims[j].errlo); - if (data_block->dims[j].errhi != nullptr) free(data_block->dims[j].errhi); - if (data_block->dims[j].sams != nullptr) free(data_block->dims[j].sams); - if (data_block->dims[j].offs != nullptr) free(data_block->dims[j].offs); - if (data_block->dims[j].ints != nullptr) free(data_block->dims[j].ints); + if (data_block->dims[j].dim != nullptr) { + free(data_block->dims[j].dim); + } + if (data_block->dims[j].errlo != nullptr) { + free(data_block->dims[j].errlo); + } + if (data_block->dims[j].errhi != nullptr) { + free(data_block->dims[j].errhi); + } + if (data_block->dims[j].sams != nullptr) { + free(data_block->dims[j].sams); + } + if (data_block->dims[j].offs != nullptr) { + free(data_block->dims[j].offs); + } + if (data_block->dims[j].ints != nullptr) { + free(data_block->dims[j].ints); + } for (int k = j + 1; k < rank; k++) { - data_block->dims[k - 1] = data_block->dims[k]; // Shift array contents + data_block->dims[k - 1] = data_block->dims[k]; // Shift array contents } if (data_block->order == j) { - data_block->order = -1; // No Time Dimension if Reformed + data_block->order = -1; // No Time Dimension if Reformed } else { if (data_block->order > j) { data_block->order = data_block->order - 1; - } // Time Dimension ID reduced by 1 + } // Time Dimension ID reduced by 1 } - data_block->rank = data_block->rank - 1; // Reduce the Rank + data_block->rank = data_block->rank - 1; // Reduce the Rank } } return 0; @@ -658,7 +670,7 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) if (data_block->rank >= 1) { char* p1 = strstr(subset.function, "dim_id"); if (p1 != nullptr) { - char* p3, * p2 = strchr(p1, '='); + char *p3, *p2 = strchr(p1, '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -673,9 +685,9 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) } if (dim_id < 0 || dim_id >= (int)data_block->rank) { - UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dim_id = %d, Rank = %d\n", dim_id, - data_block->rank); - UDA_THROW_ERROR(999, "The dimension ID identified via the subset function is outside the rank bounds of the array!"); + UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dim_id = %d, Rank = %d\n", dim_id, data_block->rank); + UDA_THROW_ERROR(999, + "The dimension ID identified via the subset function is outside the rank bounds of the array!"); } switch (data_block->data_type) { @@ -683,13 +695,14 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) auto dp = (float*)data_block->data; float min = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dim_id argument - for (int j = 1; j < data_block->data_n; j++) + case 0: { // Ignore function dim_id argument + for (int j = 1; j < data_block->data_n; j++) { if (dp[j] < min) { min = dp[j]; } + } dp[0] = min; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->data_n = 1; break; } @@ -700,7 +713,7 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) } } dp[0] = min; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -760,13 +773,14 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) auto dp = (double*)data_block->data; double min = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dim_id argument - for (int j = 1; j < data_block->data_n; j++) + case 0: { // Ignore function dim_id argument + for (int j = 1; j < data_block->data_n; j++) { if (dp[j] < min) { min = dp[j]; } + } dp[0] = min; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->data_n = 1; break; } @@ -777,7 +791,7 @@ int apply_minimum(SUBSET subset, DATA_BLOCK* data_block) } } dp[0] = min; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -846,7 +860,7 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) if (data_block->rank >= 1) { char* p1 = strstr(subset.function, "dim_id"); if (p1 != nullptr) { - char* p3, * p2 = strchr(p1, '='); + char *p3, *p2 = strchr(p1, '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -861,9 +875,9 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) } if (dim_id < 0 || dim_id >= (int)data_block->rank) { - UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dim_id = %d, Rank = %d\n", dim_id, - data_block->rank); - UDA_THROW_ERROR(999, "The dimension ID identified via the subset function is outside the rank bounds of the array!"); + UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dim_id = %d, Rank = %d\n", dim_id, data_block->rank); + UDA_THROW_ERROR(999, + "The dimension ID identified via the subset function is outside the rank bounds of the array!"); } switch (data_block->data_type) { @@ -871,14 +885,14 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) auto dp = (float*)data_block->data; float max = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dim_id argument + case 0: { // Ignore function dim_id argument for (int j = 1; j < data_block->data_n; j++) { if (dp[j] > max) { max = dp[j]; } } dp[0] = max; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->data_n = 1; break; } @@ -889,7 +903,7 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) } } dp[0] = max; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -949,13 +963,14 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) auto dp = (double*)data_block->data; double max = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dim_id argument - for (int j = 1; j < data_block->data_n; j++) + case 0: { // Ignore function dim_id argument + for (int j = 1; j < data_block->data_n; j++) { if (dp[j] > max) { max = dp[j]; } + } dp[0] = max; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->data_n = 1; break; } @@ -966,7 +981,7 @@ int apply_maximum(SUBSET subset, DATA_BLOCK* data_block) } } dp[0] = max; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -1042,7 +1057,7 @@ int apply_count(SUBSET subset, DATA_BLOCK* data_block) } else { int dim_id = 0; if (data_block->rank >= 1) { - char* p3, * p2 = strchr(p1, '='); + char *p3, *p2 = strchr(p1, '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -1053,14 +1068,26 @@ int apply_count(SUBSET subset, DATA_BLOCK* data_block) } } if (dim_id < (int)data_block->rank) { - count[0] = (unsigned int)data_block->dims[dim_id].dim_n; // Preserve this value + count[0] = (unsigned int)data_block->dims[dim_id].dim_n; // Preserve this value DIMS ddim = data_block->dims[dim_id]; - if (ddim.dim != nullptr) free(ddim.dim); - if (ddim.errhi != nullptr) free(ddim.errhi); - if (ddim.errlo != nullptr) free(ddim.errlo); - if (ddim.sams != nullptr) free(ddim.sams); - if (ddim.offs != nullptr) free(ddim.offs); - if (ddim.ints != nullptr) free(ddim.ints); + if (ddim.dim != nullptr) { + free(ddim.dim); + } + if (ddim.errhi != nullptr) { + free(ddim.errhi); + } + if (ddim.errlo != nullptr) { + free(ddim.errlo); + } + if (ddim.sams != nullptr) { + free(ddim.sams); + } + if (ddim.offs != nullptr) { + free(ddim.offs); + } + if (ddim.ints != nullptr) { + free(ddim.ints); + } ddim.dim = nullptr; ddim.errhi = nullptr; ddim.errlo = nullptr; @@ -1070,9 +1097,15 @@ int apply_count(SUBSET subset, DATA_BLOCK* data_block) } else { // ERROR } - if (data_block->data != nullptr) free(data_block->data); - if (data_block->errhi != nullptr) free(data_block->errhi); - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->data != nullptr) { + free(data_block->data); + } + if (data_block->errhi != nullptr) { + free(data_block->errhi); + } + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->data = nullptr; data_block->errhi = nullptr; data_block->errlo = nullptr; @@ -1082,7 +1115,7 @@ int apply_count(SUBSET subset, DATA_BLOCK* data_block) data_block->data_n = 1; for (unsigned int j = 0; j < data_block->rank - 1; j++) { if (j >= (unsigned int)dim_id) { - data_block->dims[j] = data_block->dims[j + 1]; // skip over the target + data_block->dims[j] = data_block->dims[j + 1]; // skip over the target } data_block->data_n = data_block->data_n * data_block->dims[j].dim_n; } @@ -1126,14 +1159,14 @@ int apply_abs(SUBSET subset, DATA_BLOCK* data_block) int apply_const(SUBSET subset, DATA_BLOCK* data_block) { - double value = 0.0; // Zero data default + double value = 0.0; // Zero data default char* p1 = strstr(subset.function, "value"); strcpy(data_block->data_label, subset.function); UDA_LOG(UDA_LOG_DEBUG, "%s\n", subset.function); if (p1 != nullptr) { - char* p3, * p2 = strchr(&p1[5], '='); + char *p3, *p2 = strchr(&p1[5], '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -1150,8 +1183,12 @@ int apply_const(SUBSET subset, DATA_BLOCK* data_block) UDA_LOG(UDA_LOG_DEBUG, "value = %f\n", value); - if (data_block->errhi != nullptr) free(data_block->errhi); - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->errhi != nullptr) { + free(data_block->errhi); + } + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->errhi = nullptr; data_block->errlo = nullptr; data_block->error_type = UDA_TYPE_UNKNOWN; @@ -1185,7 +1222,7 @@ int apply_order(SUBSET subset, DATA_BLOCK* data_block) char* p1 = strstr(subset.function, "dim_id"); UDA_LOG(UDA_LOG_DEBUG, "%s\n", subset.function); if (p1 != nullptr) { - char* p3, * p2 = strchr(&p1[5], '='); + char *p3, *p2 = strchr(&p1[5], '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -1221,7 +1258,7 @@ int apply_rotate_rz(SUBSET subset, DATA_BLOCK* data_block) auto newData = (double*)malloc(count * sizeof(double)); unsigned int offset = 0; auto old = (double*)data_block->data; - if (order == 0) { // array[nz][nr][nt] -> [nr][nz][nt] + if (order == 0) { // array[nz][nr][nt] -> [nr][nz][nt] nt = data_block->dims[0].dim_n; nr = data_block->dims[1].dim_n; nz = data_block->dims[2].dim_n; @@ -1231,16 +1268,23 @@ int apply_rotate_rz(SUBSET subset, DATA_BLOCK* data_block) data[j] = (double**)malloc(nr * sizeof(double*)); for (int i = 0; i < nr; i++) { data[j][i] = (double*)malloc(nt * sizeof(double)); - for (int k = 0; k < nt; k++)data[j][i][k] = old[offset++]; + for (int k = 0; k < nt; k++) { + data[j][i][k] = old[offset++]; + } } } offset = 0; - for (int i = 0; i < nr; i++) - for (int j = 0; j < nz; j++) - for (int k = 0; k < nt; k++) + for (int i = 0; i < nr; i++) { + for (int j = 0; j < nz; j++) { + for (int k = 0; k < nt; k++) { newData[offset++] = data[j][i][k]; + } + } + } for (int j = 0; j < nz; j++) { - for (int i = 0; i < nr; i++) free(data[j][i]); + for (int i = 0; i < nr; i++) { + free(data[j][i]); + } free(data[j]); } free(data); @@ -1249,9 +1293,9 @@ int apply_rotate_rz(SUBSET subset, DATA_BLOCK* data_block) DIMS d2 = data_block->dims[2]; data_block->dims[1] = d2; data_block->dims[2] = d1; - } else if (order == 1) { // array[nz][nt][nr] + } else if (order == 1) { // array[nz][nt][nr] UDA_THROW_ERROR(999, "The function rotateRZ only operates on arrays with shape [nz][nr][nt] or [nt][nz][nr]"); - } else if (order == 2) { // array[nt][nz][nr] -> [nt][nr][nz] + } else if (order == 2) { // array[nt][nz][nr] -> [nt][nr][nz] nr = data_block->dims[0].dim_n; nz = data_block->dims[1].dim_n; nt = data_block->dims[2].dim_n; @@ -1261,16 +1305,23 @@ int apply_rotate_rz(SUBSET subset, DATA_BLOCK* data_block) data[k] = (double**)malloc(nz * sizeof(double*)); for (int j = 0; j < nz; j++) { data[k][j] = (double*)malloc(nr * sizeof(double)); - for (int i = 0; i < nr; i++)data[k][j][i] = old[offset++]; + for (int i = 0; i < nr; i++) { + data[k][j][i] = old[offset++]; + } } } offset = 0; - for (int k = 0; k < nt; k++) - for (int i = 0; i < nr; i++) - for (int j = 0; j < nz; j++) + for (int k = 0; k < nt; k++) { + for (int i = 0; i < nr; i++) { + for (int j = 0; j < nz; j++) { newData[offset++] = data[k][j][i]; + } + } + } for (int k = 0; k < nt; k++) { - for (int j = 0; j < nz; j++)free(data[k][j]); + for (int j = 0; j < nz; j++) { + free(data[k][j]); + } free(data[k]); } free(data); @@ -1288,31 +1339,31 @@ int apply_rotate_rz(SUBSET subset, DATA_BLOCK* data_block) int apply_functions(SUBSET subset, DATA_BLOCK* data_block) { - if (STR_ISTARTSWITH(subset.function, "minimum")) { // Single scalar result + if (STR_ISTARTSWITH(subset.function, "minimum")) { // Single scalar result return apply_minimum(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "maximum")) { // Single scalar result + if (STR_ISTARTSWITH(subset.function, "maximum")) { // Single scalar result return apply_maximum(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "count")) { // Single scalar result + if (STR_ISTARTSWITH(subset.function, "count")) { // Single scalar result return apply_count(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "abs")) { // Absolute value + if (STR_ISTARTSWITH(subset.function, "abs")) { // Absolute value return apply_abs(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "const")) { // Constant value substitution + if (STR_ISTARTSWITH(subset.function, "const")) { // Constant value substitution return apply_const(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "order")) { // Identify the Time dimension order + if (STR_ISTARTSWITH(subset.function, "order")) { // Identify the Time dimension order return apply_order(subset, data_block); } - if (STR_ISTARTSWITH(subset.function, "rotateRZ")) { // Rotate R,Z coordinates in rank 3 array + if (STR_ISTARTSWITH(subset.function, "rotateRZ")) { // Rotate R,Z coordinates in rank 3 array return apply_rotate_rz(subset, data_block); } @@ -1340,10 +1391,10 @@ int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST //----------------------------------------------------------------------------------------------------------------------- // Process all sets of sub-setting operations - for (int i = 0; i < n_subsets; i++) { // the number of sets of Subset Operations + for (int i = 0; i < n_subsets; i++) { // the number of sets of Subset Operations SUBSET subset; if (action.actionType == UDA_COMPOSITE_TYPE) { - subset = action.composite.subsets[i]; // the set of Subset Operations + subset = action.composite.subsets[i]; // the set of Subset Operations } else { if (action.actionType == UDA_SERVER_SIDE_TYPE) { subset = action.serverside.subsets[i]; @@ -1381,9 +1432,6 @@ int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST return 0; } - - - //------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------- // Build an Action Structure for Serverside Data Operations @@ -1610,25 +1658,18 @@ int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serversi return ierr; } - //---------------------------------------------------------------------------------------------------------------------- // Identify the Index Range satisfying a small set of conditional operators -template -struct EpsilonSelector -{ +template struct EpsilonSelector { static T Epsilon; }; -template -T EpsilonSelector::Epsilon = (T)0; +template T EpsilonSelector::Epsilon = (T)0; -template <> -double EpsilonSelector::Epsilon = DBL_EPSILON; - -template <> -float EpsilonSelector::Epsilon = FLT_EPSILON; +template <> double EpsilonSelector::Epsilon = DBL_EPSILON; +template <> float EpsilonSelector::Epsilon = FLT_EPSILON; template int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double value, unsigned int* subset_indices) @@ -1656,7 +1697,7 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double double minvalue = fabs((T)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabs((T)value - p[k]); - if (delta < minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1665,15 +1706,16 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double count = 1; subset_indices[0] = index; - if (index == 0 || - index == dim->dim_n - 1) { // Check not an end point by default + if (index == 0 || index == dim->dim_n - 1) { // Check not an end point by default if (dim->dim_n > 1) { if (index == 0) { delta = fabs(p[1] - p[0]); } else { delta = fabs(p[dim->dim_n - 1] - p[dim->dim_n - 2]); } - if (fabs((T)value - p[index]) > delta) count = 0; // Suspect match! + if (fabs((T)value - p[index]) > delta) { + count = 0; // Suspect match! + } } } } @@ -1716,8 +1758,7 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double double delta, minvalue = fabs((T)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabs((T)value - p[k]); - if (delta < - minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1726,7 +1767,7 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double for (int k = 0; k < dim->dim_n; k++) { if (k != index) { subset_indices[count++] = k; - } // Drop the single nearest value + } // Drop the single nearest value } if (index == 0 || index == dim->dim_n - 1) { // Check not an end point by default @@ -1738,7 +1779,7 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double } if (fabs((T)value - p[index]) > delta) { count = 0; - } // Suspect match! + } // Suspect match! } } } @@ -1749,7 +1790,6 @@ int get_subset_indices_for_type(const std::string& operation, DIMS* dim, double return 0; } - int get_subset_indices(const std::string& operation, DIMS* dim, double value, unsigned int* subset_indices) { int count = 0; @@ -1782,11 +1822,10 @@ int get_subset_indices(const std::string& operation, DIMS* dim, double value, un return count; } - template -int apply_sub_setting_for_type(DIMS* dims, int rank, int dim_id, - const char* data, int ndata, int data_type, int not_operation, - int start, int end, int start1, int end1, int stride, int* n, void** new_data) +int apply_sub_setting_for_type(DIMS* dims, int rank, int dim_id, const char* data, int ndata, int data_type, + int not_operation, int start, int end, int start1, int end1, int stride, int* n, + void** new_data) { // Allocate heap for the reshaped array @@ -1795,7 +1834,7 @@ int apply_sub_setting_for_type(DIMS* dims, int rank, int dim_id, UDA_THROW_ERROR(9999, "Unable to Allocate Heap memory"); } - auto dp = (T*)data; // the Originating Data Array + auto dp = (T*)data; // the Originating Data Array // Reshape @@ -1835,11 +1874,15 @@ int apply_sub_setting_for_type(DIMS* dims, int rank, int dim_id, if (dim_id == 0) { new_rows = dims[1].dim_n; new_cols = end - start + 1; - if (not_operation) new_cols = new_cols + end1 - start1 + 1; + if (not_operation) { + new_cols = new_cols + end1 - start1 + 1; + } } else { new_cols = dims[0].dim_n; new_rows = end - start + 1; - if (not_operation) new_rows = new_rows + end1 - start1 + 1; + if (not_operation) { + new_rows = new_rows + end1 - start1 + 1; + } } auto pa = (T**)malloc(new_rows * sizeof(T*)); @@ -1926,9 +1969,8 @@ int apply_sub_setting_for_type(DIMS* dims, int rank, int dim_id, return 0; } -int apply_sub_setting(DIMS* dims, int rank, int dim_id, - char* data, int ndata, int data_type, int not_operation, - int start, int end, int start1, int end1, int stride, int* n, void** new_data) +int apply_sub_setting(DIMS* dims, int rank, int dim_id, char* data, int ndata, int data_type, int not_operation, + int start, int end, int start1, int end1, int stride, int* n, void** new_data) { UDA_LOG(UDA_LOG_DEBUG, "Data Type: %d Rank: %d\n", data_type, rank); @@ -1936,34 +1978,44 @@ int apply_sub_setting(DIMS* dims, int rank, int dim_id, switch (data_type) { case UDA_TYPE_FLOAT: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_DOUBLE: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_INT: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_SHORT: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_LONG: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_LONG64: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, + end, start1, end1, stride, n, new_data); break; case UDA_TYPE_UNSIGNED_INT: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, + start, end, start1, end1, stride, n, new_data); break; case UDA_TYPE_UNSIGNED_SHORT: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, + start, end, start1, end1, stride, n, new_data); break; case UDA_TYPE_UNSIGNED_LONG: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, + start, end, start1, end1, stride, n, new_data); break; case UDA_TYPE_UNSIGNED_LONG64: - return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, start, end, start1, end1, stride, n, new_data); + return apply_sub_setting_for_type(dims, rank, dim_id, data, ndata, data_type, not_operation, + start, end, start1, end1, stride, n, new_data); break; default: UDA_LOG(UDA_LOG_ERROR, "Invalid data type for sub-setting operation!\n"); @@ -1973,6 +2025,3 @@ int apply_sub_setting(DIMS* dims, int rank, int dim_id, return 0; } - - - diff --git a/source/server/serverSubsetData.h b/source/server/serverSubsetData.h old mode 100755 new mode 100644 index cbe613f7..7e6873ac --- a/source/server/serverSubsetData.h +++ b/source/server/serverSubsetData.h @@ -1,23 +1,24 @@ #pragma once #ifndef UDA_SERVER_SERVERSUBSETDATA_H -#define UDA_SERVER_SERVERSUBSETDATA_H +# define UDA_SERVER_SERVERSUBSETDATA_H -#include -#include "udaStructs.h" -#include "genStructs.h" -#include "export.h" -#include "pluginStructs.h" +# include "export.h" +# include "genStructs.h" +# include "pluginStructs.h" +# include "udaStructs.h" +# include -#ifdef __cplusplus +# ifdef __cplusplus extern "C" { -#endif +# 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, const PLUGINLIST* plugin_list); +LIBRARY_API int serverSubsetData(DATA_BLOCK* data_block, const ACTION& action, LOGMALLOCLIST* logmalloclist); +LIBRARY_API int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, + const PLUGINLIST* plugin_list); -#ifdef __cplusplus +# ifdef __cplusplus } -#endif +# endif #endif // UDA_SERVER_SERVERSUBSETDATA_H diff --git a/source/server/sleepServer.cpp b/source/server/sleepServer.cpp old mode 100755 new mode 100644 index ba778ce4..71560d77 --- a/source/server/sleepServer.cpp +++ b/source/server/sleepServer.cpp @@ -1,17 +1,17 @@ /*--------------------------------------------------------------- -* Server Sleeps and Waits for a Wake-up Instruction from the Client -* -* Returns: 1 (True) if Next Client Request to be Served -* 0 (False) if No Request within the Time Limit -* -*--------------------------------------------------------------*/ + * Server Sleeps and Waits for a Wake-up Instruction from the Client + * + * Returns: 1 (True) if Next Client Request to be Served + * 0 (False) if No Request within the Time Limit + * + *--------------------------------------------------------------*/ #include "sleepServer.h" -#include #include #include -#include #include +#include +#include int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, int protocolVersion, LOGSTRUCTLIST* log_struct_list, @@ -27,8 +27,7 @@ int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmallocl UDA_LOG(UDA_LOG_DEBUG, "Protocol 3 Listening for Next Client Request\n"); if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, &next_protocol, logmalloclist, userdefinedtypelist, - nullptr, protocolVersion, log_struct_list, io_data, private_flags, - malloc_source)) != 0) { + nullptr, protocolVersion, log_struct_list, io_data, private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Protocol 3 Error Listening for Wake-up %d\n", err); @@ -47,8 +46,7 @@ int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmallocl #ifndef NOCHAT // Echo Next Protocol straight back to Client if ((err = protocol(server_output, protocol_id, XDR_SEND, &next_protocol, logmalloclist, userdefinedtypelist, - nullptr, protocolVersion, log_struct_list, io_data, private_flags, - malloc_source)) != 0) { + nullptr, protocolVersion, log_struct_list, io_data, private_flags, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, "sleepServer", err, "Protocol 3 Error Echoing Next Protocol ID"); return 0; } @@ -61,12 +59,11 @@ int sleepServer(XDR* server_input, XDR* server_output, LOGMALLOCLIST* logmallocl if (next_protocol != UDA_PROTOCOL_WAKE_UP) { UDA_LOG(UDA_LOG_DEBUG, "Unknown Wakeup Request -> Server Shutting down\n"); - addIdamError(UDA_CODE_ERROR_TYPE, "sleepServer", next_protocol, - "Unknown Wakeup Request -> Server Shutdown"); + addIdamError(UDA_CODE_ERROR_TYPE, "sleepServer", next_protocol, "Unknown Wakeup Request -> Server Shutdown"); return 0; } UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Wake-Up\n"); - return 1; // No Time out and Non-Zero Next Protocol id => Next Client Request + return 1; // No Time out and Non-Zero Next Protocol id => Next Client Request } diff --git a/source/server/sleepServer.h b/source/server/sleepServer.h old mode 100755 new mode 100644 index 8d306b96..f59e101e --- a/source/server/sleepServer.h +++ b/source/server/sleepServer.h @@ -1,12 +1,12 @@ #pragma once #ifndef UDA_SERVER_SLEEPSERVER_H -#define UDA_SERVER_SLEEPSERVER_H +# define UDA_SERVER_SLEEPSERVER_H -#include +# include -#include "genStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" struct IoData; diff --git a/source/server/udaLegacyServer.cpp b/source/server/udaLegacyServer.cpp old mode 100755 new mode 100644 index b29fbbc8..a8d98691 --- a/source/server/udaLegacyServer.cpp +++ b/source/server/udaLegacyServer.cpp @@ -1,32 +1,33 @@ /*--------------------------------------------------------------- -* UDA Legacy Data Server (protocol versions <= 6) -* -*---------------------------------------------------------------------------------------------------------------------*/ + * UDA Legacy Data Server (protocol versions <= 6) + * + *---------------------------------------------------------------------------------------------------------------------*/ #include "udaLegacyServer.h" -#include #include "initStructs.h" +#include "struct.h" +#include "udaTypes.h" +#include #include #include #include -#include "udaTypes.h" #include #include #include #include -#include "struct.h" #include "closeServerSockets.h" +#include "createXDRStream.h" #include "getServerEnvironment.h" #include "serverGetData.h" #include "serverLegacyPlugin.h" #include "serverProcessing.h" #include "sleepServer.h" -#include "createXDRStream.h" #ifdef LEGACYSERVER -int idamLegacyServer(CLIENT_BLOCK client_block) { +int idamLegacyServer(CLIENT_BLOCK client_block) +{ return 0; } #else @@ -63,7 +64,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL initLogStructList(&log_struct_list); int server_tot_block_time = 0; - int server_timeout = TIMEOUT; // user specified Server Lifetime + int server_timeout = TIMEOUT; // user specified Server Lifetime IoData io_data = {}; io_data.server_tot_block_time = &server_tot_block_time; @@ -77,7 +78,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL initServerBlock(&server_block, server_version); initDataBlock(&data_block); - initActions(&actions_desc); // There may be a Sequence of Actions to Apply + initActions(&actions_desc); // There may be a Sequence of Actions to Apply initActions(&actions_sig); USERDEFINEDTYPELIST parseduserdefinedtypelist; @@ -97,7 +98,9 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL //---------------------------------------------------------------------------- // Initialise the Client Structure - only if this is not the first time in the wait loop - if (normalLegacyWait) initClientBlock(&client_block, 0, ""); + if (normalLegacyWait) { + initClientBlock(&client_block, 0, ""); + } //---------------------------------------------------------------------------- // Initialise the Request Structure @@ -120,11 +123,10 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, - &client_block, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &client_block, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Receiving Client Data Block\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 10 Error (Receiving Client Block)"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Receiving Client Block)"); concatUdaError(&server_block.idamerrorstack); closeUdaError(); @@ -134,24 +136,29 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL } } - server_timeout = client_block.timeout; // User specified Server Lifetime - private_flags = client_block.privateFlags; // Server to Server flags - uint32_t client_flags = client_block.clientFlags; // Client set flags - int alt_rank = client_block.altRank; // Rank of Alternative source + server_timeout = client_block.timeout; // User specified Server Lifetime + private_flags = client_block.privateFlags; // Server to Server flags + uint32_t client_flags = client_block.clientFlags; // Client set flags + int alt_rank = client_block.altRank; // Rank of Alternative source // Protocol Version: Lower of the client and server version numbers // This defines the set of elements within data structures passed between client and server // Must be the same on both sides of the socket protocolVersion = server_version; - if (client_block.version < server_version) protocolVersion = client_block.version; + if (client_block.version < server_version) { + protocolVersion = client_block.version; + } // The client request may originate from a server. - // Is the Originating server an externally facing server? If so then switch to this mode: preserve local access policy + // Is the Originating server an externally facing server? If so then switch to this mode: preserve local + // access policy ENVIRONMENT* environment = getServerEnvironment(); - if (!environment->external_user && (private_flags & PRIVATEFLAG_EXTERNAL)) environment->external_user = 1; + if (!environment->external_user && (private_flags & PRIVATEFLAG_EXTERNAL)) { + environment->external_user = 1; + } UDA_LOG(UDA_LOG_DEBUG, "client protocolVersion %d\n", protocolVersion); UDA_LOG(UDA_LOG_DEBUG, "private_flags %d\n", private_flags); @@ -166,11 +173,10 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL UDA_LOG(UDA_LOG_DEBUG, "Sending Server Block\n"); if ((err = protocol(server_output, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, - &server_block, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &server_block, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Server Data Block\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 11 Error (Sending Server Block #1)"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 11 Error (Sending Server Block #1)"); concatUdaError(&server_block.idamerrorstack); // Update Server State with Error Stack closeUdaError(); normalLegacyWait = 1; @@ -183,11 +189,11 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL } else { err = 1; } - break; // Manage the Fatal Server State + break; // Manage the Fatal Server State } } - normalLegacyWait = 1; // Enable client & server state block legacy exchange + normalLegacyWait = 1; // Enable client & server state block legacy exchange //------------------------------------------------------------------------- // Client Request @@ -201,8 +207,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL &request_block, protocolVersion, &log_struct_list, &io_data, private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Receiving Client Request Block\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 1 Error (Receiving Client Request)"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (Receiving Client Request)"); break; } @@ -217,53 +222,60 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL //------------------------------------------------------------------------------------------------------------------ // Prepend Proxy Host to Source to redirect client request - /*! On parallel clusters where nodes are connected together on a private network, only the master node may have access - to external data sources. Cluster nodes can access these external sources via an UDA server running on the master node. - This server acts as a proxy server. It simply redirects requests to other external UDA servers. To facilitate this redirection, - each access request source string must be prepended with "UDA::host:port/" within the server. The host:port component is defined - by the system administrator via an environment variable "UDA_PROXY". Client's don't need to specifiy redirection via a Proxy - it's - automatic if the UDA_PROXY environment variable is defined. No prepending is done if the source is already a redirection, i.e. it - begins "UDA::". + /*! On parallel clusters where nodes are connected together on a private network, only the master node may + have access to external data sources. Cluster nodes can access these external sources via an UDA server + running on the master node. This server acts as a proxy server. It simply redirects requests to other + external UDA servers. To facilitate this redirection, each access request source string must be prepended + with "UDA::host:port/" within the server. The host:port component is defined by the system administrator via + an environment variable "UDA_PROXY". Client's don't need to specifiy redirection via a Proxy - it's + automatic if the UDA_PROXY environment variable is defined. No prepending is done if the source is already a + redirection, i.e. it begins "UDA::". */ -#ifdef PROXYSERVER +# ifdef PROXYSERVER char work[STRING_LENGTH]; - if(request_block.api_delim[0] != '\0') + if (request_block.api_delim[0] != '\0') { sprintf(work, "UDA%s", request_block.api_delim); - else + } else { sprintf(work, "UDA%s", environment->api_delim); + } - if(environment->server_proxy[0] != '\0' && strncasecmp(request_block.source, work, strlen(work)) != 0) { + if (environment->server_proxy[0] != '\0' && strncasecmp(request_block.source, work, strlen(work)) != 0) { -// Check the Server Version is Compatible with the Originating client version ? + // Check the Server Version is Compatible with the Originating client version ? - if(client_block.version < 6) { + if (client_block.version < 6) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); + "PROXY redirection: Originating Client Version not compatible with the PROXY server " + "interface."); break; } // Test for Proxy calling itself indirectly => potential infinite loop - // The UDA Plugin strips out the host and port data from the source so the originating server details are never passed. + // The UDA Plugin strips out the host and port data from the source so the originating server details + // are never passed. - if(request_block.api_delim[0] != '\0') + if (request_block.api_delim[0] != '\0') { sprintf(work, "UDA%s%s", request_block.api_delim, environment->server_this); - else + } else { sprintf(work, "UDA%s%s", environment->api_delim, environment->server_this); + } - if(strstr(request_block.source, work) != nullptr) { + if (strstr(request_block.source, work) != nullptr) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); + addIdamError( + UDA_CODE_ERROR_TYPE, __func__, err, + "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); break; } // Check string length compatibility - if(strlen(request_block.source) >= (STRING_LENGTH-1 - strlen(environment->server_proxy) - 4+strlen(request_block.api_delim))) { + if (strlen(request_block.source) >= + (STRING_LENGTH - 1 - strlen(environment->server_proxy) - 4 + strlen(request_block.api_delim))) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "PROXY redirection: The source argument string is too long!"); @@ -272,29 +284,30 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL // Prepend the redirection UDA server details - if(request_block.api_delim[0] != '\0') - sprintf(work, "UDA%s%s/%s", request_block.api_delim, environment->server_proxy, request_block.source); - else - sprintf(work, "UDA%s%s/%s", environment->api_delim, environment->server_proxy, request_block.source); + if (request_block.api_delim[0] != '\0') { + sprintf(work, "UDA%s%s/%s", request_block.api_delim, environment->server_proxy, + request_block.source); + } else { + sprintf(work, "UDA%s%s/%s", environment->api_delim, environment->server_proxy, + request_block.source); + } strcpy(request_block.source, work); - //strcpy(request_block.server, environment->server_proxy); + // strcpy(request_block.server, environment->server_proxy); - if(debugon) { + if (debugon) { UDA_LOG(UDA_LOG_DEBUG, "PROXY Redirection to %s\n", environment->server_proxy); UDA_LOG(UDA_LOG_DEBUG, "source: %s\n", request_block.source); - //UDA_LOG(UDA_LOG_DEBUG, "server: %s\n", request_block.server); + // UDA_LOG(UDA_LOG_DEBUG, "server: %s\n", request_block.server); } - } -#endif +# endif //---------------------------------------------------------------------- // Write to the Access Log - udaAccessLog(TRUE, client_block, request_block, server_block, - total_datablock_size); + udaAccessLog(TRUE, client_block, request_block, server_block, total_datablock_size); //---------------------------------------------------------------------- // Initialise Data Structures @@ -315,9 +328,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_PUTDATA_BLOCK_LIST; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, nullptr, logmalloclist, userdefinedtypelist, - &(request_data->putDataBlockList), protocolVersion, &log_struct_list, - &io_data, private_flags, malloc_source)) != - 0) { + &(request_data->putDataBlockList), protocolVersion, &log_struct_list, &io_data, + private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Receiving putData Block List\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 1 Error (Receiving Client putDataBlockList)"); @@ -342,7 +354,9 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL break; } } else { - if ((err = udaServerLegacyPlugin(request, &data_source, &signal_desc)) != 0) break; + if ((err = udaServerLegacyPlugin(request, &data_source, &signal_desc)) != 0) { + break; + } } } @@ -355,9 +369,9 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL for (int i = 0; i < request_block.num_requests; ++i) { auto request = &request_block.requests[i]; - err = udaGetData(&depth, request, client_block, &data_block, &data_source, &signal_rec, - &signal_desc, &actions_desc, &actions_sig, pluginlist, logmalloclist, - userdefinedtypelist, socket_list, protocolVersion); + err = udaGetData(&depth, request, client_block, &data_block, &data_source, &signal_rec, &signal_desc, + &actions_desc, &actions_sig, pluginlist, logmalloclist, userdefinedtypelist, + socket_list, protocolVersion); } UDA_LOG(UDA_LOG_DEBUG, @@ -379,7 +393,9 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL UDA_LOG(UDA_LOG_DEBUG, "======================== ******************** ==========================================\n"); - if (err != 0) break; + if (err != 0) { + break; + } //------------------------------------------------------------------------------------------------ // Server-Side Data Processing @@ -396,14 +412,16 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL // Check the Client can receive the data type: Version dependent // Otherwise inform the client via the server state block - if (protocolVersion < 6 && data_block.data_type == UDA_TYPE_STRING) data_block.data_type = UDA_TYPE_CHAR; + if (protocolVersion < 6 && data_block.data_type == UDA_TYPE_STRING) { + data_block.data_type = UDA_TYPE_CHAR; + } - if (data_block.data_n > 0 && - (protocolVersionTypeTest(protocolVersion, data_block.data_type) || - protocolVersionTypeTest(protocolVersion, data_block.error_type))) { + if (data_block.data_n > 0 && (protocolVersionTypeTest(protocolVersion, data_block.data_type) || + protocolVersionTypeTest(protocolVersion, data_block.error_type))) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "The Data has a type that cannot be passed to the Client: A newer client library version is required."); + "The Data has a type that cannot be passed to the Client: A newer client library version " + "is required."); break; } @@ -415,7 +433,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocolVersionTypeTest(protocolVersion, dim.error_type)) { err = 999; addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "A Coordinate Data has a numerical type that cannot be passed to the Client: A newer client library version is required."); + "A Coordinate Data has a numerical type that cannot be passed to the Client: A " + "newer client library version is required."); break; } } @@ -453,8 +472,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL &server_block, protocolVersion, &log_struct_list, &io_data, private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Server Data Block #2\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 11 Error (Sending Server Block #2)"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 11 Error (Sending Server Block #2)"); break; } @@ -474,7 +492,6 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL //---------------------------------------------------------------------------- // Return Database Meta Data if User Requests it - if (client_block.get_meta) { // Next Protocol id @@ -482,11 +499,10 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_NEXT_PROTOCOL; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, &next_protocol, logmalloclist, - userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, - &io_data, private_flags, malloc_source)) != 0) { + userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, &io_data, + private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem #1 Receiving Next Protocol ID\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 3 (Next Protocol #1) Error"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 3 (Next Protocol #1) Error"); break; } @@ -507,8 +523,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_DATA_SYSTEM; if ((err = protocol(server_output, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, - &data_system, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &data_system, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data System Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 4 Error"); break; @@ -520,8 +536,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_SYSTEM_CONFIG; if ((err = protocol(server_output, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, - &system_config, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &system_config, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending System Configuration Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error"); break; @@ -533,8 +549,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_DATA_SOURCE; if ((err = protocol(server_output, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, - &data_source, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &data_source, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data Source Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 6 Error"); break; @@ -559,8 +575,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_SIGNAL_DESC; if ((err = protocol(server_output, protocol_id, XDR_SEND, nullptr, logmalloclist, userdefinedtypelist, - &signal_desc, protocolVersion, &log_struct_list, &io_data, - private_flags, malloc_source)) != 0) { + &signal_desc, protocolVersion, &log_struct_list, &io_data, private_flags, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Signal Description Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 8 Error"); break; @@ -574,8 +590,8 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_NEXT_PROTOCOL; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, &next_protocol, logmalloclist, - userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, - &io_data, private_flags, malloc_source)) != 0) { + userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, &io_data, + private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem #2 Receiving Next Protocol ID\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 3 (Next Protocol #2) Error"); break; @@ -617,18 +633,16 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL protocol_id = UDA_PROTOCOL_NEXT_PROTOCOL; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, &next_protocol, logmalloclist, - userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, - &io_data, private_flags, malloc_source)) != 0) { + userdefinedtypelist, nullptr, protocolVersion, &log_struct_list, &io_data, + private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem #2a Receiving Next Protocol ID\n"); - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Protocol 3 (Next Protocol #2) Error"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 3 (Next Protocol #2) Error"); break; } if (next_protocol != UDA_PROTOCOL_STRUCTURES) { err = 999; - addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, - "Incorrect Next Protocol received: (Structures)"); + addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Incorrect Next Protocol received: (Structures)"); break; } } @@ -671,8 +685,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL //---------------------------------------------------------------------- // Complete & Write the Access Log Record - udaAccessLog(0, client_block, request_block, server_block, - total_datablock_size); + udaAccessLog(0, client_block, request_block, server_block, total_datablock_size); //---------------------------------------------------------------------------- // Server Shutdown ? Next Instruction from Client @@ -687,8 +700,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL next_protocol = 0; if ((err = protocol(server_input, protocol_id, XDR_RECEIVE, &next_protocol, logmalloclist, userdefinedtypelist, - nullptr, protocolVersion, &log_struct_list, &io_data, private_flags, - malloc_source)) != 0) { + nullptr, protocolVersion, &log_struct_list, &io_data, private_flags, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem #3 Receiving Next Protocol ID\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 3 (Server Shutdown) Error"); break; @@ -700,9 +712,15 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL UDA_LOG(UDA_LOG_DEBUG, "Current Error Value %d\n", err); UDA_LOG(UDA_LOG_DEBUG, "Client Request %d\n", next_protocol); - if (next_protocol == UDA_PROTOCOL_CLOSEDOWN) UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Die\n"); - if (next_protocol == UDA_PROTOCOL_SLEEP) UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Sleep\n"); - if (next_protocol == UDA_PROTOCOL_WAKE_UP) UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Wake-up\n"); + if (next_protocol == UDA_PROTOCOL_CLOSEDOWN) { + UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Die\n"); + } + if (next_protocol == UDA_PROTOCOL_SLEEP) { + UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Sleep\n"); + } + if (next_protocol == UDA_PROTOCOL_WAKE_UP) { + UDA_LOG(UDA_LOG_DEBUG, "Client Requests Server Wake-up\n"); + } //---------------------------------------------------------------------------- // Free Data Block Heap Memory @@ -723,7 +741,7 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL // Write the Error Log Record & Free Error Stack Heap UDA_LOG(UDA_LOG_DEBUG, "concatUdaError\n"); - concatUdaError(&server_block.idamerrorstack); // Update Server State with Error Stack + concatUdaError(&server_block.idamerrorstack); // Update Server State with Error Stack UDA_LOG(UDA_LOG_DEBUG, "closeUdaError\n"); closeUdaError(); @@ -742,10 +760,10 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL //---------------------------------------------------------------------------- // Server Wait Loop - } while (err == 0 && next_protocol == UDA_PROTOCOL_SLEEP - && sleepServer(server_input, server_output, logmalloclist, userdefinedtypelist, protocolVersion, - &log_struct_list, server_tot_block_time, server_timeout, &io_data, private_flags, - malloc_source)); + } while (err == 0 && next_protocol == UDA_PROTOCOL_SLEEP && + sleepServer(server_input, server_output, logmalloclist, userdefinedtypelist, protocolVersion, + &log_struct_list, server_tot_block_time, server_timeout, &io_data, private_flags, + malloc_source)); //---------------------------------------------------------------------------- // Server Destruct..... diff --git a/source/server/udaLegacyServer.h b/source/server/udaLegacyServer.h old mode 100755 new mode 100644 index f4b74684..fa019b01 --- a/source/server/udaLegacyServer.h +++ b/source/server/udaLegacyServer.h @@ -1,13 +1,13 @@ #pragma once #ifndef UDA_SERVER_UDALEGACYSERVER_H -#define UDA_SERVER_UDALEGACYSERVER_H +# define UDA_SERVER_UDALEGACYSERVER_H -#include "udaStructs.h" -#include "genStructs.h" -#include -#include "pluginStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" +# include "pluginStructs.h" +# include "udaStructs.h" +# include /** * UDA Legacy Data Server (protocol versions <= 6) @@ -17,4 +17,3 @@ int legacyServer(CLIENT_BLOCK client_block, const PLUGINLIST* pluginlist, LOGMAL 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 old mode 100755 new mode 100644 index faa7a6b9..2dda093a --- a/source/server/udaServer.cpp +++ b/source/server/udaServer.cpp @@ -1,5 +1,5 @@ -#include #include +#include #if defined(__GNUC__) # include #else @@ -9,28 +9,28 @@ #include #include "initStructs.h" +#include "struct.h" +#include "udaErrors.h" +#include +#include #include #include #include -#include "udaErrors.h" #include -#include #include +#include #include #include -#include "struct.h" -#include -#include #include "closeServerSockets.h" #include "createXDRStream.h" #include "getServerEnvironment.h" +#include "initPluginList.h" #include "serverGetData.h" #include "serverLegacyPlugin.h" #include "serverProcessing.h" #include "serverStartup.h" #include "udaLegacyServer.h" -#include "initPluginList.h" #ifdef SECURITYENABLED # include @@ -47,16 +47,17 @@ constexpr int server_version = 9; static int protocol_version = 9; static int legacy_server_version = 6; -static USERDEFINEDTYPELIST* user_defined_type_list = nullptr; // User Defined Structure Types from Data Files & Plugins -static LOGMALLOCLIST* log_malloc_list = nullptr; // List of all Heap Allocations for Data: Freed after data is dispatched +static USERDEFINEDTYPELIST* user_defined_type_list = nullptr; // User Defined Structure Types from Data Files & Plugins +static LOGMALLOCLIST* log_malloc_list = + nullptr; // List of all Heap Allocations for Data: Freed after data is dispatched int malloc_source = UDA_MALLOC_SOURCE_NONE; -USERDEFINEDTYPELIST parsed_user_defined_type_list; // Initial set of User Defined Structure Types +USERDEFINEDTYPELIST parsed_user_defined_type_list; // Initial set of User Defined Structure Types // Total amount sent for the last data request -static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) -ENVIRONMENT environment; // Holds local environment variable values +static PLUGINLIST pluginList; // List of all data reader plugins (internal and external shared libraries) +ENVIRONMENT environment; // Holds local environment variable values static SOCKETLIST socket_list; @@ -73,21 +74,18 @@ static int startupServer(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& s static int handleRequest(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); + 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, 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); + 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 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 doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, int server_tot_block_time, int server_timeout); @@ -95,9 +93,8 @@ static int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_ #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, - LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output); +static int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* server_closedown, + LOGSTRUCTLIST* log_struct_list, XDR* server_input, XDR* server_output); #endif //-------------------------------------------------------------------------------------- @@ -122,7 +119,7 @@ int udaServer(CLIENT_BLOCK client_block) initLogStructList(&log_struct_list); int server_tot_block_time = 0; - int server_timeout = TIMEOUT; // user specified Server Lifetime + int server_timeout = TIMEOUT; // user specified Server Lifetime IoData io_data = {}; io_data.server_tot_block_time = &server_tot_block_time; @@ -134,7 +131,7 @@ int udaServer(CLIENT_BLOCK client_block) initUdaErrorStack(); initServerBlock(&server_block, server_version); - initActions(&actions_desc); // There may be a Sequence of Actions to Apply + initActions(&actions_desc); // There may be a Sequence of Actions to Apply initActions(&actions_sig); initRequestBlock(&request_block); @@ -142,14 +139,16 @@ 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) return err; + if ((err = startupServer(&server_block, server_input, server_output, &io_data)) != 0) { + return err; + } #ifdef SECURITYENABLED err = authenticateClient(&client_block, &server_block); #else int server_closedown = 0; - err = handshakeClient(&client_block, &server_block, &server_closedown, &log_struct_list, server_input, - server_output); + err = + handshakeClient(&client_block, &server_block, &server_closedown, &log_struct_list, server_input, server_output); #endif DATA_BLOCK_LIST data_block_list; @@ -159,8 +158,8 @@ 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, - &actions_sig, &fatal, cache, &log_struct_list, server_input, server_output, - &total_datablock_size, server_tot_block_time, &server_timeout); + &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); @@ -168,10 +167,9 @@ int udaServer(CLIENT_BLOCK client_block) 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 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) { //---------------------------------------------------------------------------- // Gather Server Error State @@ -231,8 +229,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI if (client_block->get_meta) { *total_datablock_size += - sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + - sizeof(SIGNAL_DESC); + sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + sizeof(SIGNAL_DESC); //---------------------------------------------------------------------------- // Send the Data System Structure @@ -240,8 +237,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI protocol_id = UDA_PROTOCOL_DATA_SYSTEM; if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block->data_system, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + &metadata_block->data_system, protocol_version, log_struct_list, 0, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data System Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 4 Error"); return err; @@ -253,8 +249,8 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI protocol_id = UDA_PROTOCOL_SYSTEM_CONFIG; if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block->system_config, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + &metadata_block->system_config, protocol_version, log_struct_list, 0, malloc_source)) != + 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending System Configuration Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error"); return err; @@ -266,8 +262,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI protocol_id = UDA_PROTOCOL_DATA_SOURCE; if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block->data_source, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + &metadata_block->data_source, protocol_version, log_struct_list, 0, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data Source Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 6 Error"); return err; @@ -279,8 +274,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI protocol_id = UDA_PROTOCOL_SIGNAL; if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block->signal_rec, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + &metadata_block->signal_rec, protocol_version, log_struct_list, 0, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Signal Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 7 Error"); return err; @@ -292,8 +286,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI protocol_id = UDA_PROTOCOL_SIGNAL_DESC; if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block->signal_desc, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + &metadata_block->signal_desc, protocol_version, log_struct_list, 0, malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Signal Description Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 8 Error"); return err; @@ -318,8 +311,8 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI } if ((err = protocol2(server_output, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_SEND, nullptr, log_malloc_list, - user_defined_type_list, data_block_list, protocol_version, log_struct_list, - 0, malloc_source)) != 0) { + user_defined_type_list, data_block_list, protocol_version, log_struct_list, 0, + malloc_source)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 2 Error"); return err; @@ -360,8 +353,7 @@ reportToClient(SERVER_BLOCK* server_block, DATA_BLOCK_LIST* data_block_list, CLI UDA_LOG(UDA_LOG_DEBUG, "Sending Hierarchical Data Structure to Client\n"); if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - data_block, protocol_version, log_struct_list, 0, - malloc_source)) != 0) { + data_block, protocol_version, log_struct_list, 0, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Server Side Protocol Error (Opaque Structure Type)"); return err; } @@ -419,10 +411,10 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV return err; } - *server_timeout = client_block->timeout; // User specified Server Lifetime - unsigned int private_flags = client_block->privateFlags; // Server to Server flags - unsigned int clientFlags = client_block->clientFlags; // Client set flags - int altRank = client_block->altRank; // Rank of Alternative source + *server_timeout = client_block->timeout; // User specified Server Lifetime + unsigned int private_flags = client_block->privateFlags; // Server to Server flags + unsigned int clientFlags = client_block->clientFlags; // Client set flags + int altRank = client_block->altRank; // Rank of Alternative source // Protocol Version: Lower of the client and server version numbers // This defines the set of elements within data structures passed between client and server @@ -434,7 +426,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV } // The client request may originate from a server. - // Is the Originating server an externally facing server? If so then switch to this mode: preserve local access policy + // Is the Originating server an externally facing server? If so then switch to this mode: preserve local access + // policy if (!environment.external_user && (private_flags & PRIVATEFLAG_EXTERNAL)) { environment.external_user = 1; @@ -463,7 +456,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV } else { err = 1; } - return err; // Manage the Fatal Server State + return err; // Manage the Fatal Server State } // Test for an immediate CLOSEDOWN instruction @@ -480,8 +473,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV // Pass Back and Await Client Instruction if ((err = protocol2(server_input, UDA_PROTOCOL_REQUEST_BLOCK, XDR_RECEIVE, nullptr, log_malloc_list, - user_defined_type_list, request_block, protocol_version, log_struct_list, - private_flags, malloc_source)) != 0) { + user_defined_type_list, request_block, protocol_version, log_struct_list, private_flags, + malloc_source)) != 0) { UDA_THROW_ERROR(err, "Protocol 1 Error (Receiving Client Request)"); } @@ -510,9 +503,9 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV * * The name of the proxy reirection plugin is UDA by default but may be changed using the environment variable * UDA_PROXYPLUGINNAME - */ + */ -# ifdef PROXYSERVER +#ifdef PROXYSERVER // Name of the Proxy plugin @@ -521,7 +514,9 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV char work[STRING_LENGTH]; - if ((proxyName = getenv("UDA_PROXYPLUGINNAME")) == nullptr) proxyName = proxyNameDefault; + if ((proxyName = getenv("UDA_PROXYPLUGINNAME")) == nullptr) { + proxyName = proxyNameDefault; + } // Check string length compatibility @@ -541,7 +536,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV if (strncasecmp(request_block->source, work, strlen(work)) != 0) { // Not a recognised redirection so prepending is necessary - // Has a proxy host been specified in the server startup script? If not assume the plugin has a default host and port + // Has a proxy host been specified in the server startup script? If not assume the plugin has a default host and + // port if (environment.server_proxy[0] == '\0') { if (request_block->api_delim[0] != '\0') { @@ -552,18 +548,20 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV strcpy(request_block->source, work); - } else { // UDA::host.port/source + } else { // UDA::host.port/source // Check the Server Version is Compatible with the Originating client version ? if (client_block->version < 6) { - UDA_THROW_ERROR(999, "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); + UDA_THROW_ERROR( + 999, + "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); } // Test for Proxy calling itself indirectly => potential infinite loop - // The UDA Plugin strips out the host and port data from the source so the originating server details are never passed. - // Primitive test as the same IP address can be mapped to different names! - // Should pass on the number of redirections and cap the limit! + // The UDA Plugin strips out the host and port data from the source so the originating server details are + // never passed. Primitive test as the same IP address can be mapped to different names! Should pass on the + // number of redirections and cap the limit! if (environment.server_this[0] != '\0') { if (request_block->api_delim[0] != '\0') { @@ -573,32 +571,41 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV } if (strstr(request_block->source, work) != nullptr) { - UDA_THROW_ERROR(999, "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); + UDA_THROW_ERROR( + 999, + "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); } } // Prepend the redirection UDA server details and replace the original if (request_block->source[0] == '/') { - if (request_block->api_delim[0] != '\0') - sprintf(work, "%s%s%s%s", proxyName, request_block->api_delim, environment.server_proxy, request_block->source); - else - sprintf(work, "%s%s%s%s", proxyName, environment.api_delim, environment.server_proxy, request_block->source); + if (request_block->api_delim[0] != '\0') { + sprintf(work, "%s%s%s%s", proxyName, request_block->api_delim, environment.server_proxy, + request_block->source); + } else { + sprintf(work, "%s%s%s%s", proxyName, environment.api_delim, environment.server_proxy, + request_block->source); + } } else { - if (request_block->api_delim[0] != '\0') - sprintf(work, "%s%s%s/%s", proxyName, request_block->api_delim, environment.server_proxy, request_block->source); - else - sprintf(work, "%s%s%s/%s", proxyName, environment.api_delim, environment.server_proxy, request_block->source); + if (request_block->api_delim[0] != '\0') { + sprintf(work, "%s%s%s/%s", proxyName, request_block->api_delim, environment.server_proxy, + request_block->source); + } else { + sprintf(work, "%s%s%s/%s", proxyName, environment.api_delim, environment.server_proxy, + request_block->source); + } } strcpy(request_block->source, work); } - UDA_LOG(UDA_LOG_DEBUG, "PROXY Redirection to %s avoiding %s\n", environment.server_proxy, environment.server_this); + UDA_LOG(UDA_LOG_DEBUG, "PROXY Redirection to %s avoiding %s\n", environment.server_proxy, + environment.server_this); UDA_LOG(UDA_LOG_DEBUG, "plugin: %s\n", proxyName); UDA_LOG(UDA_LOG_DEBUG, "source: %s\n", request_block->source); } -# else +#else for (int i = 0; i < request_block->num_requests; ++i) { REQUEST_DATA* request = &request_block->requests[i]; @@ -615,12 +622,14 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV // Check the Server Version is Compatible with the Originating client version ? if (client_block->version < 6) { - UDA_THROW_ERROR(999, - "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); + UDA_THROW_ERROR( + 999, + "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); } // Test for Proxy calling itself indirectly => potential infinite loop - // The UDA Plugin strips out the host and port data from the source so the originating server details are never passed. + // The UDA Plugin strips out the host and port data from the source so the originating server details are + // never passed. if (request->api_delim[0] != '\0') { work = fmt::format("UDA{}{}", request->api_delim, environment.server_this); @@ -629,8 +638,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV } if (strstr(request->source, work.c_str()) != nullptr) { - UDA_THROW_ERROR(999, - "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); + UDA_THROW_ERROR( + 999, "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); } // Check string length compatibility @@ -654,13 +663,12 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV UDA_LOG(UDA_LOG_DEBUG, "source: %s\n", request->source); } } -# endif +#endif //---------------------------------------------------------------------- // Write to the Access Log - udaAccessLog(TRUE, *client_block, *request_block, *server_block, - *total_datablock_size); + udaAccessLog(TRUE, *client_block, *request_block, *server_block, *total_datablock_size); //---------------------------------------------------------------------- // Initialise Data Structures @@ -679,8 +687,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV if (request->put) { if ((err = protocol2(server_input, UDA_PROTOCOL_PUTDATA_BLOCK_LIST, XDR_RECEIVE, nullptr, log_malloc_list, - user_defined_type_list, &request->putDataBlockList, protocol_version, - log_struct_list, private_flags, malloc_source)) != 0) { + user_defined_type_list, &request->putDataBlockList, protocol_version, log_struct_list, + private_flags, malloc_source)) != 0) { UDA_THROW_ERROR(err, "Protocol 1 Error (Receiving Client putDataBlockList)"); } @@ -702,8 +710,8 @@ 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, getServerEnvironment())) != 0) { + if ((err = udaServerPlugin(request, &metadata_block->data_source, &metadata_block->signal_desc, &pluginList, + getServerEnvironment())) != 0) { return err; } } else { @@ -735,8 +743,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV &metadata_block->signal_rec, &metadata_block->signal_desc, actions_desc, actions_sig, &pluginList, 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); + cache_write(cache, request, data_block, log_malloc_list, user_defined_type_list, environment, 8, + CLIENTFLAG_CACHE, log_struct_list, private_flags, malloc_source); } for (int i = 0; i < request_block->num_requests; ++i) { @@ -754,7 +762,7 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV UDA_LOG(UDA_LOG_DEBUG, "File Name : %s \n", data_source->filename); UDA_LOG(UDA_LOG_DEBUG, "Pulse Number : %d \n", data_source->exp_number); UDA_LOG(UDA_LOG_DEBUG, "Pass Number : %d \n", data_source->pass); -// UDA_LOG(UDA_LOG_DEBUG, "Recursive # : %d \n", depth); + // UDA_LOG(UDA_LOG_DEBUG, "Recursive # : %d \n", depth); printRequestBlock(*request_block); printDataSource(*data_source); printSignal(metadata_block->signal_rec); @@ -764,7 +772,9 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV UDA_LOG(UDA_LOG_DEBUG, "======================== ******************** ==========================================\n"); - if (err != 0) return err; + if (err != 0) { + return err; + } //------------------------------------------------------------------------------------------------ // Server-Side Data Processing @@ -789,11 +799,11 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV data_block->data_type = UDA_TYPE_CHAR; } - if (data_block->data_n > 0 && - (protocolVersionTypeTest(protocol_version, data_block->data_type) || - protocolVersionTypeTest(protocol_version, data_block->error_type))) { - UDA_THROW_ERROR(999, - "The Data has a type that cannot be passed to the Client: A newer client library version is required."); + if (data_block->data_n > 0 && (protocolVersionTypeTest(protocol_version, data_block->data_type) || + protocolVersionTypeTest(protocol_version, data_block->error_type))) { + UDA_THROW_ERROR( + 999, + "The Data has a type that cannot be passed to the Client: A newer client library version is required."); } if (data_block->rank > 0) { @@ -802,8 +812,8 @@ int handleRequest(REQUEST_BLOCK* request_block, CLIENT_BLOCK* client_block, SERV dim = data_block->dims[j]; if (protocolVersionTypeTest(protocol_version, dim.data_type) || protocolVersionTypeTest(protocol_version, dim.error_type)) { - UDA_THROW_ERROR(999, - "A Coordinate Data has a numerical type that cannot be passed to the Client: A newer client library version is required."); + UDA_THROW_ERROR(999, "A Coordinate Data has a numerical type that cannot be passed to the Client: " + "A newer client library version is required."); } } } @@ -831,7 +841,7 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, UDA_LOG(UDA_LOG_DEBUG, "Start of Server Wait Loop\n"); // Create a new userdefinedtypelist for the request by copying the parseduserdefinedtypelist structure - //copyUserDefinedTypeList(&userdefinedtypelist); + // copyUserDefinedTypeList(&userdefinedtypelist); getInitialUserDefinedTypeList(&user_defined_type_list); parsed_user_defined_type_list = *user_defined_type_list; @@ -851,14 +861,13 @@ 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 = reportToClient(server_block, data_block_list, client_block, err, metadata_block, log_struct_list, + server_input, 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); - udaAccessLog(FALSE, *client_block, *request_block, *server_block, - *total_datablock_size); + udaAccessLog(FALSE, *client_block, *request_block, *server_block, *total_datablock_size); err = 0; next_protocol = UDA_PROTOCOL_SLEEP; @@ -890,7 +899,7 @@ int doServerLoop(REQUEST_BLOCK* request_block, DATA_BLOCK_LIST* data_block_list, // Write the Error Log Record & Free Error Stack Heap UDA_LOG(UDA_LOG_DEBUG, "concatUdaError\n"); - concatUdaError(&server_block->idamerrorstack); // Update Server State with Error Stack + concatUdaError(&server_block->idamerrorstack); // Update Server State with Error Stack UDA_LOG(UDA_LOG_DEBUG, "closeUdaError\n"); closeUdaError(); @@ -937,7 +946,7 @@ int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, //---------------------------------------------------------------------------- // Free Structure Definition List (don't free the structure as stack variable) - //freeUserDefinedTypeList(&parseduserdefinedtypelist); + // freeUserDefinedTypeList(&parseduserdefinedtypelist); //---------------------------------------------------------------------------- // Free Plugin List and Close all open library entries @@ -976,14 +985,14 @@ int doServerClosedown(CLIENT_BLOCK* client_block, REQUEST_BLOCK* request_block, #ifdef SECURITYENABLED int authenticateClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block) { - static int authenticationNeeded = 1; // No data access until this is set TRUE + static int authenticationNeeded = 1; // No data access until this is set TRUE initClientBlock(client_block, 0, ""); if (authenticationNeeded && protocolVersion >= UDA_SECURITY_VERSION) { // User or intermediate server Must Authenticate - // If the request is passed on through a chain of servers, user#2 authentication occurs within the external server. - // An authentication structure is passed back from the server to the client + // If the request is passed on through a chain of servers, user#2 authentication occurs within the external + // server. An authentication structure is passed back from the server to the client // Receive the client_block // Test data validity of certificate @@ -1008,10 +1017,9 @@ int authenticateClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block) } // Receive the client_block - // Decrypt token B with the server private key => Proof Client has valid private key == client authenticated - // Test token B identical to that sent in step 4 - // Generate a new token B and encrypt with the client public key => maintain mutual authentication - // Send the server_block + // Decrypt token B with the server private key => Proof Client has valid private key == client + // authenticated Test token B identical to that sent in step 4 Generate a new token B and encrypt with the + // client public key => maintain mutual authentication Send the server_block if ((err = serverAuthentication(client_block, server_block, SERVER_VERIFY_TOKEN)) != 0) { UDA_THROW_ERROR(err, "Client or Server Authentication Failed #7"); @@ -1043,11 +1051,10 @@ int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error (Client Block)"); } else { - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block if ((err = protocol2(server_input, protocol_id, XDR_RECEIVE, nullptr, log_malloc_list, user_defined_type_list, - client_block, protocol_version, log_struct_list, 0, - malloc_source)) != 0) { + client_block, protocol_version, log_struct_list, 0, malloc_source)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); UDA_LOG(UDA_LOG_DEBUG, "protocol error! Client Block not received!\n"); } @@ -1065,7 +1072,9 @@ int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* } } - if (err != 0) return err; + if (err != 0) { + return err; + } // Flush (mark as at EOF) the input socket buffer (not all client state data may have been read - version dependent) @@ -1074,23 +1083,23 @@ int handshakeClient(CLIENT_BLOCK* client_block, SERVER_BLOCK* server_block, int* // Must be the same on both sides of the socket // set in xdr_client - //protocolVersion = serverVersion; - //if(client_block.version < serverVersion) protocolVersion = client_block.version; - //if(client_block.version < server_block.version) protocolVersion = client_block.version; + // protocolVersion = serverVersion; + // if(client_block.version < serverVersion) protocolVersion = client_block.version; + // if(client_block.version < server_block.version) protocolVersion = client_block.version; // Send the server block UDA_LOG(UDA_LOG_DEBUG, "Sending Initial Server Block \n"); printServerBlock(*server_block); - int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement + int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement if ((err = protocol2(server_output, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, server_block, protocol_version, log_struct_list, 0, malloc_source)) != 0) { UDA_THROW_ERROR(err, "Protocol 11 Error (Server Block #1)"); } - if (!xdrrec_endofrecord(server_output, 1)) { // Send data now + if (!xdrrec_endofrecord(server_output, 1)) { // Send data now UDA_THROW_ERROR(UDA_PROTOCOL_ERROR_7, "Protocol 7 Error (Server Block)"); } @@ -1134,7 +1143,7 @@ int startupServer(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_o // Identify the authenticated user for service authorisation putUdaServerSSLSocket(0); - + int err = 0; if ((err = startUdaServerSSL()) != 0) { return err; @@ -1163,23 +1172,23 @@ int startupServer(SERVER_BLOCK* server_block, XDR*& server_input, XDR*& server_o // this step needs doing once only - the first time a generalised user defined structure is encountered. // For FAT clients use a static state variable to prevent multiple parsing -/* - if (!fileParsed) { - fileParsed = 1; - initUserDefinedTypeList(&parseduserdefinedtypelist); + /* + if (!fileParsed) { + fileParsed = 1; + initUserDefinedTypeList(&parseduserdefinedtypelist); - char* token = nullptr; - if ((token = getenv("UDA_SARRAY_CONFIG")) == nullptr) { - UDA_THROW_ERROR(999, "No Environment variable UDA_SARRAY_CONFIG"); - } + char* token = nullptr; + if ((token = getenv("UDA_SARRAY_CONFIG")) == nullptr) { + UDA_THROW_ERROR(999, "No Environment variable UDA_SARRAY_CONFIG"); + } - UDA_LOG(UDA_LOG_DEBUG, "Parsing structure definition file: %s\n", token); - parseIncludeFile(&parseduserdefinedtypelist, token); // file containing the SARRAY structure definition - printUserDefinedTypeList(parseduserdefinedtypelist); - } -*/ + UDA_LOG(UDA_LOG_DEBUG, "Parsing structure definition file: %s\n", token); + parseIncludeFile(&parseduserdefinedtypelist, token); // file containing the SARRAY structure definition + printUserDefinedTypeList(parseduserdefinedtypelist); + } + */ - user_defined_type_list = nullptr; // Startup State + user_defined_type_list = nullptr; // Startup State //---------------------------------------------------------------------- // Initialise the Data Reader Plugin list diff --git a/source/server/udaServer.h b/source/server/udaServer.h old mode 100755 new mode 100644 index 735d6144..f73737a5 --- a/source/server/udaServer.h +++ b/source/server/udaServer.h @@ -1,16 +1,16 @@ #pragma once #ifndef UDA_SERVER_UDASERVER_H -#define UDA_SERVER_UDASERVER_H +# define UDA_SERVER_UDASERVER_H -#include "pluginStructs.h" -#include -#include "genStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" +# include "pluginStructs.h" +# include LIBRARY_API int udaServer(CLIENT_BLOCK client_block); LIBRARY_API int fatServer(CLIENT_BLOCK client_block, SERVER_BLOCK* server_block, REQUEST_BLOCK* request_block0, - DATA_BLOCK_LIST* data_blocks0); + DATA_BLOCK_LIST* data_blocks0); #endif // UDA_SERVER_UDASERVER_H diff --git a/source/server/writer.cpp b/source/server/writer.cpp old mode 100755 new mode 100644 index 3987654b..9d2d7a16 --- a/source/server/writer.cpp +++ b/source/server/writer.cpp @@ -2,8 +2,8 @@ #include -#include #include "udaDefines.h" +#include #include "createXDRStream.h" @@ -18,9 +18,9 @@ int serverSocket = 0; void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) { FD_ZERO(rfds); // Initialise the File Descriptor set - FD_SET(fd, rfds); // Identify the Socket in the FD set + FD_SET(fd, rfds); // Identify the Socket in the FD set tv->tv_sec = 0; - tv->tv_usec = MIN_BLOCK_TIME; // minimum wait microsecs (1ms) + tv->tv_usec = MIN_BLOCK_TIME; // minimum wait microsecs (1ms) *server_tot_block_time = 0; } @@ -31,10 +31,10 @@ void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_ if (server_tot_block_time < MAXBLOCK) { // (ms) For the First blocking period have rapid response (clientserver/udaDefines.h == 1000) tv->tv_sec = 0; - tv->tv_usec = MIN_BLOCK_TIME; // minimum wait (1ms) + tv->tv_usec = MIN_BLOCK_TIME; // minimum wait (1ms) } else { tv->tv_sec = 0; - tv->tv_usec = MAX_BLOCK_TIME; // maximum wait (10ms) + tv->tv_usec = MAX_BLOCK_TIME; // maximum wait (10ms) } } @@ -65,7 +65,7 @@ void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_ int server_read(void* iohandle, char* buf, int count) { int rc = 0; - fd_set rfds; // File Descriptor Set for Reading from the Socket + fd_set rfds; // File Descriptor Set for Reading from the Socket timeval tv = {}; timeval tvc = {}; @@ -79,11 +79,12 @@ int server_read(void* iohandle, char* buf, int count) while (select(serverSocket + 1, &rfds, nullptr, nullptr, &tvc) <= 0) { *io_data->server_tot_block_time += (int)tv.tv_usec / 1000; if (*io_data->server_tot_block_time > 1000 * *io_data->server_timeout) { - UDA_LOG(UDA_LOG_DEBUG, "Total Wait Time Exceeds Lifetime Limit = %d (ms)\n", *io_data->server_timeout * 1000); + UDA_LOG(UDA_LOG_DEBUG, "Total Wait Time Exceeds Lifetime Limit = %d (ms)\n", + *io_data->server_timeout * 1000); return -1; } - updateSelectParms(serverSocket, &rfds, &tv, *io_data->server_tot_block_time); // Keep trying ... + updateSelectParms(serverSocket, &rfds, &tv, *io_data->server_tot_block_time); // Keep trying ... tvc = tv; } @@ -109,7 +110,7 @@ int server_write(void* iohandle, char* buf, int count) int rc = 0; int BytesSent = 0; - fd_set wfds; // File Descriptor Set for Writing to the Socket + fd_set wfds; // File Descriptor Set for Writing to the Socket timeval tv = {}; auto io_data = reinterpret_cast(iohandle); diff --git a/source/server/writer.h b/source/server/writer.h old mode 100755 new mode 100644 index b9896bae..60c649ba --- a/source/server/writer.h +++ b/source/server/writer.h @@ -1,23 +1,23 @@ #pragma once #ifndef UDA_SERVER_WRITER_H -#define UDA_SERVER_WRITER_H +# define UDA_SERVER_WRITER_H -#if defined(__GNUC__) -# include -#endif -#include +# if defined(__GNUC__) +# include +# endif +# include -#ifdef _WIN32 -# include // must be included before connection.h to avoid macro redefinition in rpc/types.h -#else -# include -#endif +# ifdef _WIN32 +# include // must be included before connection.h to avoid macro redefinition in rpc/types.h +# else +# include +# endif -#include "export.h" +# include "export.h" -#define MIN_BLOCK_TIME 1000 -#define MAX_BLOCK_TIME 10000 +# define MIN_BLOCK_TIME 1000 +# define MAX_BLOCK_TIME 10000 void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time); void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_block_time); @@ -34,7 +34,7 @@ int server_write(void* iohandle, char* buf, int count); // is modified: It is extended to 100ms to minimise server resource consumption. // // When the Server is in a Holding state, it is listening to the Socket for either a -// Closedown or a Data request. +// Closedown or a Data request. // // Three Global variables are used to control the Blocking timeout // diff --git a/source/server2/apply_XML.cpp b/source/server2/apply_XML.cpp old mode 100755 new mode 100644 index 1edf7310..f714466a --- a/source/server2/apply_XML.cpp +++ b/source/server2/apply_XML.cpp @@ -1,52 +1,53 @@ /*--------------------------------------------------------------------------------------------- -* Apply Actionable XML based Corrections to Data -* -* Returns: -* -* Notes: Actions defined within the SIGNAL record have a Higher priority than -* Actions defined within the SIGNAL_DESC record. -* -* Priorities are subject to exp_number and pass range checks -* -* A specific time_offset correction occurs befor any time dimension rescaling. -* -*-----------------------------------------------------------------------------------------------*/ + * Apply Actionable XML based Corrections to Data + * + * Returns: + * + * Notes: Actions defined within the SIGNAL record have a Higher priority than + * Actions defined within the SIGNAL_DESC record. + * + * Priorities are subject to exp_number and pass range checks + * + * A specific time_offset correction occurs befor any time dimension rescaling. + * + *-----------------------------------------------------------------------------------------------*/ #include "apply_XML.hpp" #include #include -#include #include "udaTypes.h" #include +#include -int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, - ACTIONS* actions_desc, ACTIONS* actions_sig) +int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_DESC signal_desc, ACTIONS* actions_desc, + ACTIONS* actions_sig) { -// return -1 if No Qualifying Actionable XML otherwise return 0 + // return -1 if No Qualifying Actionable XML otherwise return 0 int ndesc, rc = 0; UDA_LOG(UDA_LOG_DEBUG, "Parsing XML\n"); -//---------------------------------------------------------------------- -// Anything to Parse? + //---------------------------------------------------------------------- + // Anything to Parse? - if (strlen(signal.xml) == 0 && strlen(signal_desc.xml) == 0) return -1; // No XML to parse or switched off! + if (strlen(signal.xml) == 0 && strlen(signal_desc.xml) == 0) { + return -1; // No XML to parse or switched off! + } -//---------------------------------------------------------------------- -// Initialise + //---------------------------------------------------------------------- + // Initialise - initActions(actions_desc); // Array of actions from the Signal_Desc record - initActions(actions_sig); // Array of actions from the Signal Record + initActions(actions_desc); // Array of actions from the Signal_Desc record + initActions(actions_sig); // Array of actions from the Signal Record -//---------------------------------------------------------------------- -// Parse Signal XML + //---------------------------------------------------------------------- + // Parse Signal XML - if (strlen(signal.xml) > - 0) { // If this Signal level XML exists then populated components takes priority. + if (strlen(signal.xml) > 0) { // If this Signal level XML exists then populated components takes priority. if ((rc = parseDoc(signal.xml, actions_sig)) != 0) { return 1; } @@ -54,8 +55,8 @@ int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_ printActions(*actions_sig); } -//---------------------------------------------------------------------- -// Parse Signal_Desc XML + //---------------------------------------------------------------------- + // Parse Signal_Desc XML if (strlen(signal_desc.xml) > 0) { if ((rc = parseDoc(signal_desc.xml, actions_desc)) != 0) { @@ -66,32 +67,34 @@ int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_ printActions(*actions_desc); } -//---------------------------------------------------------------------------------------------- -// Test Range Groups (Only Applies to XML from Signal_desc records) + //---------------------------------------------------------------------------------------------- + // Test Range Groups (Only Applies to XML from Signal_desc records) - for (int i = 0; i < actions_sig->nactions; i++)actions_sig->action[i].inRange = 1; // Always in Range + for (int i = 0; i < actions_sig->nactions; i++) { + actions_sig->action[i].inRange = 1; // Always in Range + } ndesc = 0; for (int i = 0; i < actions_desc->nactions; i++) { UDA_LOG(UDA_LOG_DEBUG, "Range Test on Record %d\n", i); - UDA_LOG(UDA_LOG_DEBUG, "#1 %d\n", (actions_desc->action[i].exp_range[0] == 0 || - (actions_desc->action[i].exp_range[0] > 0 && - actions_desc->action[i].exp_range[0] <= data_source.exp_number))); + UDA_LOG(UDA_LOG_DEBUG, "#1 %d\n", + (actions_desc->action[i].exp_range[0] == 0 || + (actions_desc->action[i].exp_range[0] > 0 && + actions_desc->action[i].exp_range[0] <= data_source.exp_number))); - UDA_LOG(UDA_LOG_DEBUG, "#2 %d\n", (actions_desc->action[i].exp_range[1] == 0 || - (actions_desc->action[i].exp_range[1] > 0 && - actions_desc->action[i].exp_range[1] >= data_source.exp_number))); + UDA_LOG(UDA_LOG_DEBUG, "#2 %d\n", + (actions_desc->action[i].exp_range[1] == 0 || + (actions_desc->action[i].exp_range[1] > 0 && + actions_desc->action[i].exp_range[1] >= data_source.exp_number))); - UDA_LOG(UDA_LOG_DEBUG, "#3 %d\n", (data_source.pass = -1 || - ((actions_desc->action[i].pass_range[0] == -1 || - (actions_desc->action[i].pass_range[0] > -1 && - actions_desc->action[i].pass_range[0] <= - data_source.pass)) && - (actions_desc->action[i].pass_range[1] == -1 || - (actions_desc->action[i].pass_range[1] > -1 && - actions_desc->action[i].pass_range[1] >= - data_source.pass))))); + UDA_LOG(UDA_LOG_DEBUG, "#3 %d\n", + (data_source.pass = -1 || ((actions_desc->action[i].pass_range[0] == -1 || + (actions_desc->action[i].pass_range[0] > -1 && + actions_desc->action[i].pass_range[0] <= data_source.pass)) && + (actions_desc->action[i].pass_range[1] == -1 || + (actions_desc->action[i].pass_range[1] > -1 && + actions_desc->action[i].pass_range[1] >= data_source.pass))))); if ((actions_desc->action[i].exp_range[0] == 0 || (actions_desc->action[i].exp_range[0] > 0 && @@ -99,13 +102,12 @@ int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_ (actions_desc->action[i].exp_range[1] == 0 || (actions_desc->action[i].exp_range[1] > 0 && actions_desc->action[i].exp_range[1] >= data_source.exp_number)) && - (data_source.pass == -1 || - ((actions_desc->action[i].pass_range[0] == -1 || - (actions_desc->action[i].pass_range[0] > -1 && - actions_desc->action[i].pass_range[0] <= data_source.pass)) && - (actions_desc->action[i].pass_range[1] == -1 || - (actions_desc->action[i].pass_range[1] > -1 && - actions_desc->action[i].pass_range[1] >= data_source.pass))))) { + (data_source.pass == -1 || ((actions_desc->action[i].pass_range[0] == -1 || + (actions_desc->action[i].pass_range[0] > -1 && + actions_desc->action[i].pass_range[0] <= data_source.pass)) && + (actions_desc->action[i].pass_range[1] == -1 || + (actions_desc->action[i].pass_range[1] > -1 && + actions_desc->action[i].pass_range[1] >= data_source.pass))))) { ndesc++; actions_desc->action[i].inRange = 1; } else { @@ -115,7 +117,7 @@ int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_ printActions(*actions_desc); - if (actions_sig->nactions == 0 && ndesc == 0) { // No qualifying XML from either source + if (actions_sig->nactions == 0 && ndesc == 0) { // No qualifying XML from either source UDA_LOG(UDA_LOG_DEBUG, "No Applicable Actionable XML Found\n"); return -1; } @@ -123,8 +125,8 @@ int uda::server_parse_signal_XML(DATA_SOURCE data_source, SIGNAL signal, SIGNAL_ return 0; } - -namespace { +namespace +{ void applyCalibration(int type, int ndata, double factor, double offset, int invert, char* array) { @@ -141,65 +143,103 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv unsigned long* ul; unsigned long long* ull; - if (array == nullptr) return; // No Data - if (factor == (double)1.0E0 && offset == (double)0.0E0 && !invert) return; // Nothing to be applied - + if (array == nullptr) { + return; // No Data + } + if (factor == (double)1.0E0 && offset == (double)0.0E0 && !invert) { + return; // Nothing to be applied + } if (factor != (double)1.0E0 || offset != (double)0.0E0) { switch (type) { - case UDA_TYPE_FLOAT:fp = (float*)array; - for (int i = 0; i < ndata; i++) fp[i] = (float)factor * fp[i] + (float)offset; + case UDA_TYPE_FLOAT: + fp = (float*)array; + for (int i = 0; i < ndata; i++) { + fp[i] = (float)factor * fp[i] + (float)offset; + } break; - case UDA_TYPE_DOUBLE:dp = (double*)array; - for (int i = 0; i < ndata; i++) dp[i] = factor * dp[i] + offset; + case UDA_TYPE_DOUBLE: + dp = (double*)array; + for (int i = 0; i < ndata; i++) { + dp[i] = factor * dp[i] + offset; + } break; - case UDA_TYPE_CHAR:cp = (char*)array; - for (int i = 0; i < ndata; i++) cp[i] = (char)factor * cp[i] + (char)offset; + case UDA_TYPE_CHAR: + cp = (char*)array; + for (int i = 0; i < ndata; i++) { + cp[i] = (char)factor * cp[i] + (char)offset; + } break; - case UDA_TYPE_SHORT:sp = (short*)array; - for (int i = 0; i < ndata; i++) sp[i] = (short)factor * sp[i] + (short)offset; + case UDA_TYPE_SHORT: + sp = (short*)array; + for (int i = 0; i < ndata; i++) { + sp[i] = (short)factor * sp[i] + (short)offset; + } break; - case UDA_TYPE_INT:ip = (int*)array; - for (int i = 0; i < ndata; i++) ip[i] = (int)factor * ip[i] + (int)offset; + case UDA_TYPE_INT: + ip = (int*)array; + for (int i = 0; i < ndata; i++) { + ip[i] = (int)factor * ip[i] + (int)offset; + } break; - case UDA_TYPE_LONG:lp = (long*)array; - for (int i = 0; i < ndata; i++) lp[i] = (long)factor * lp[i] + (long)offset; + case UDA_TYPE_LONG: + lp = (long*)array; + for (int i = 0; i < ndata; i++) { + lp[i] = (long)factor * lp[i] + (long)offset; + } break; -// cause a bug: unresolved __fixunsdfdi - need gcc_s library - case UDA_TYPE_LONG64:llp = (long long*)array; - for (int i = 0; i < ndata; i++) llp[i] = (long long)factor * llp[i] + (long long)offset; + // cause a bug: unresolved __fixunsdfdi - need gcc_s library + case UDA_TYPE_LONG64: + llp = (long long*)array; + for (int i = 0; i < ndata; i++) { + llp[i] = (long long)factor * llp[i] + (long long)offset; + } break; - case UDA_TYPE_UNSIGNED_CHAR:uc = (unsigned char*)array; - for (int i = 0; i < ndata; i++) uc[i] = (unsigned char)factor * uc[i] + (unsigned char)offset; + case UDA_TYPE_UNSIGNED_CHAR: + uc = (unsigned char*)array; + for (int i = 0; i < ndata; i++) { + uc[i] = (unsigned char)factor * uc[i] + (unsigned char)offset; + } break; - case UDA_TYPE_UNSIGNED_SHORT:us = (unsigned short*)array; - for (int i = 0; i < ndata; i++) us[i] = (unsigned short)factor * us[i] + (unsigned short)offset; + case UDA_TYPE_UNSIGNED_SHORT: + us = (unsigned short*)array; + for (int i = 0; i < ndata; i++) { + us[i] = (unsigned short)factor * us[i] + (unsigned short)offset; + } break; - case UDA_TYPE_UNSIGNED_INT:up = (unsigned int*)array; - for (int i = 0; i < ndata; i++) up[i] = (unsigned int)factor * up[i] + (unsigned int)offset; + case UDA_TYPE_UNSIGNED_INT: + up = (unsigned int*)array; + for (int i = 0; i < ndata; i++) { + up[i] = (unsigned int)factor * up[i] + (unsigned int)offset; + } break; - case UDA_TYPE_UNSIGNED_LONG:ul = (unsigned long*)array; - for (int i = 0; i < ndata; i++) ul[i] = (unsigned long)factor * ul[i] + (unsigned long)offset; + case UDA_TYPE_UNSIGNED_LONG: + ul = (unsigned long*)array; + for (int i = 0; i < ndata; i++) { + ul[i] = (unsigned long)factor * ul[i] + (unsigned long)offset; + } break; - case UDA_TYPE_UNSIGNED_LONG64:ull = (unsigned long long*)array; - for (int i = 0; i < ndata; i++) - ull[i] = (unsigned long long)factor * ull[i] + - (unsigned long long)offset; + case UDA_TYPE_UNSIGNED_LONG64: + ull = (unsigned long long*)array; + for (int i = 0; i < ndata; i++) { + ull[i] = (unsigned long long)factor * ull[i] + (unsigned long long)offset; + } break; - default:break; + default: + break; } } @@ -208,28 +248,38 @@ void applyCalibration(int type, int ndata, double factor, double offset, int inv if (invert) { switch (type) { - case UDA_TYPE_FLOAT:fp = (float*)array; - for (int i = 0; i < ndata; i++) - if (fp[i] != 0.0) { fp[i] = 1.0f / fp[i]; } - else { fp[i] = NAN; } + case UDA_TYPE_FLOAT: + fp = (float*)array; + for (int i = 0; i < ndata; i++) { + if (fp[i] != 0.0) { + fp[i] = 1.0f / fp[i]; + } else { + fp[i] = NAN; + } + } break; - case UDA_TYPE_DOUBLE:dp = (double*)array; - for (int i = 0; i < ndata; i++) - if (dp[i] != 0.0) { dp[i] = 1.0 / dp[i]; } - else { dp[i] = NAN; } + case UDA_TYPE_DOUBLE: + dp = (double*)array; + for (int i = 0; i < ndata; i++) { + if (dp[i] != 0.0) { + dp[i] = 1.0 / dp[i]; + } else { + dp[i] = NAN; + } + } break; - default:break; + default: + break; } } } -} // anon namespace +} // namespace void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_source, SIGNAL* signal, - SIGNAL_DESC* signal_desc, - DATA_BLOCK* data_block, ACTIONS actions) + SIGNAL_DESC* signal_desc, DATA_BLOCK* data_block, ACTIONS actions) { int ndata, dimid; @@ -248,40 +298,49 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s UDA_LOG(UDA_LOG_DEBUG, "Applying XML\n"); - if (client_block.get_asis) return; // User specifies No Actions to be Applied + if (client_block.get_asis) { + return; // User specifies No Actions to be Applied + } //---------------------------------------------------------------------------------------------- // Loop over all actions for (int i = 0; i < actions.nactions; i++) { - if (!actions.action[i].inRange) continue; // Out of Pulse/Pass Range + if (!actions.action[i].inRange) { + continue; // Out of Pulse/Pass Range + } switch (actions.action[i].actionType) { - //---------------------------------------------------------------------------------------------- - // Documentation Changes: Label/Units Corrections + //---------------------------------------------------------------------------------------------- + // Documentation Changes: Label/Units Corrections case UDA_DOCUMENTATION_TYPE: - if (strlen(actions.action[i].documentation.label) > 0) + if (strlen(actions.action[i].documentation.label) > 0) { strcpy(data_block->data_label, actions.action[i].documentation.label); + } - if (strlen(actions.action[i].documentation.units) > 0) + if (strlen(actions.action[i].documentation.units) > 0) { strcpy(data_block->data_units, actions.action[i].documentation.units); + } - if (strlen(actions.action[i].documentation.description) > 0) + if (strlen(actions.action[i].documentation.description) > 0) { strcpy(data_block->data_desc, actions.action[i].documentation.description); + } for (int j = 0; j < actions.action[i].documentation.ndimensions; j++) { if (actions.action[i].documentation.dimensions[j].dimType == UDA_DIM_DOCUMENTATION_TYPE) { if (actions.action[i].documentation.dimensions[j].dimid > -1 && (unsigned int)actions.action[i].documentation.dimensions[j].dimid < data_block->rank) { - if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.label) > 0) + if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.label) > 0) { strcpy(data_block->dims[actions.action[i].documentation.dimensions[j].dimid].dim_label, actions.action[i].documentation.dimensions[j].dimdocumentation.label); - if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.units) > 0) + } + if (strlen(actions.action[i].documentation.dimensions[j].dimdocumentation.units) > 0) { strcpy(data_block->dims[actions.action[i].documentation.dimensions[j].dimid].dim_units, actions.action[i].documentation.dimensions[j].dimdocumentation.units); + } } } } @@ -293,21 +352,22 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s case UDA_ERROR_MODEL_TYPE: data_block->error_model = actions.action[i].errormodel.model; data_block->error_param_n = actions.action[i].errormodel.param_n; - for (int j = 0; j < data_block->error_param_n; j++) + for (int j = 0; j < data_block->error_param_n; j++) { data_block->errparams[j] = actions.action[i].errormodel.params[j]; + } for (int j = 0; j < actions.action[i].errormodel.ndimensions; j++) { if (actions.action[i].errormodel.dimensions[j].dimType == UDA_DIM_ERROR_MODEL_TYPE) { if (actions.action[i].errormodel.dimensions[j].dimid > -1 && (unsigned int)actions.action[i].errormodel.dimensions[j].dimid < data_block->rank) { data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].error_model = - actions.action[i].errormodel.dimensions[j].dimerrormodel.model; + actions.action[i].errormodel.dimensions[j].dimerrormodel.model; data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].error_param_n = - actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; + actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; int jj; for (jj = 0; jj < actions.action[i].errormodel.dimensions[j].dimerrormodel.param_n; jj++) { data_block->dims[actions.action[i].errormodel.dimensions[j].dimid].errparams[jj] = - actions.action[i].errormodel.dimensions[j].dimerrormodel.params[jj]; + actions.action[i].errormodel.dimensions[j].dimerrormodel.params[jj]; } } } @@ -321,7 +381,8 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s // timeoffset.method == 0 => there must be a Non_Zero offset value // timeoffset.method == 1 => Create a New Time Vector using both Offset and Interval values. - // timeoffset.method == 2 => Create a New Time Vector using an interval value only. Use the Original Starting value if possible. + // timeoffset.method == 2 => Create a New Time Vector using an interval value only. Use the Original + // Starting value if possible. case UDA_TIME_OFFSET_TYPE: @@ -334,23 +395,30 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s if ((actions.action[i].timeoffset.method == 1 || actions.action[i].timeoffset.method == 2) && actions.action[i].timeoffset.interval != (double)0.0E0) { - // Correct the Interval Only not the Starting value: Change to the standard simple data compression model + // Correct the Interval Only not the Starting value: Change to the standard simple data compression + // model if (actions.action[i].timeoffset.method == 2) { if (data_block->dims[data_block->order].method == 1 && - data_block->dims[data_block->order].udoms == 1 - && data_block->dims[data_block->order].data_type == UDA_TYPE_FLOAT) { + data_block->dims[data_block->order].udoms == 1 && + data_block->dims[data_block->order].data_type == UDA_TYPE_FLOAT) { float* offs = (float*)data_block->dims[data_block->order].offs; data_block->dims[data_block->order].method = 0; data_block->dims[data_block->order].dim0 = (double)*offs; data_block->dims[data_block->order].diff = actions.action[i].timeoffset.interval; - if (data_block->dims[data_block->order].compressed) { // Free Heap + if (data_block->dims[data_block->order].compressed) { // Free Heap void* cptr = nullptr; - if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) { + free(cptr); + } data_block->dims[data_block->order].sams = nullptr; data_block->dims[data_block->order].offs = nullptr; data_block->dims[data_block->order].ints = nullptr; @@ -367,15 +435,22 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s break; } - // Correct both the Starting and Interval values: Change to the standard simple data compression model + // Correct both the Starting and Interval values: Change to the standard simple data compression + // model if (actions.action[i].timeoffset.method == 1) { - if (data_block->dims[data_block->order].compressed) { // Free Heap with erroneous data + if (data_block->dims[data_block->order].compressed) { // Free Heap with erroneous data void* cptr = nullptr; - if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[data_block->order].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[data_block->order].ints) != nullptr) { + free(cptr); + } data_block->dims[data_block->order].sams = nullptr; data_block->dims[data_block->order].offs = nullptr; data_block->dims[data_block->order].ints = nullptr; @@ -411,9 +486,9 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[data_block->order].method) { case 0: -// *** + // *** data_block->dims[data_block->order].dim0 = - data_block->dims[data_block->order].dim0 + actions.action[i].timeoffset.offset; + data_block->dims[data_block->order].dim0 + actions.action[i].timeoffset.offset; break; case 1: @@ -696,29 +771,27 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s if (STR_EQUALS("data", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { - if (strlen(actions.action[i].calibration.units) > 0) + if (strlen(actions.action[i].calibration.units) > 0) { strcpy(data_block->data_units, actions.action[i].calibration.units); + } applyCalibration(data_block->data_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->data); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->data); } if (STR_EQUALS("error", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { applyCalibration(data_block->error_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->errhi); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->errhi); } if (STR_EQUALS("aserror", actions.action[i].calibration.target) || STR_EQUALS("all", actions.action[i].calibration.target)) { applyCalibration(data_block->error_type, data_block->data_n, - actions.action[i].calibration.factor, - actions.action[i].calibration.offset, actions.action[i].calibration.invert, - data_block->errlo); + actions.action[i].calibration.factor, actions.action[i].calibration.offset, + actions.action[i].calibration.invert, data_block->errlo); } // Dimension Corrections @@ -730,9 +803,10 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s if (actions.action[i].calibration.dimensions[j].dimType == UDA_DIM_CALIBRATION_TYPE && actions.action[i].actionId != 0 && dimid > -1 && (unsigned int)dimid < data_block->rank) { - if (strlen(actions.action[i].calibration.dimensions[j].dimcalibration.units) > 0) + if (strlen(actions.action[i].calibration.dimensions[j].dimcalibration.units) > 0) { strcpy(data_block->dims[dimid].dim_units, actions.action[i].calibration.dimensions[j].dimcalibration.units); + } if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != (double)1.0E0 || actions.action[i].calibration.dimensions[j].dimcalibration.offset != (double)0.0E0) { @@ -747,15 +821,15 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != (double)1.0E0) { data_block->dims[dimid].diff = - data_block->dims[dimid].diff * - actions.action[i].calibration.dimensions[j].dimcalibration.factor; + data_block->dims[dimid].diff * + actions.action[i].calibration.dimensions[j].dimcalibration.factor; } if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != (double)0.0E0) { data_block->dims[dimid].dim0 = - data_block->dims[dimid].dim0 + - actions.action[i].calibration.dimensions[j].dimcalibration.offset; + data_block->dims[dimid].dim0 + + actions.action[i].calibration.dimensions[j].dimcalibration.offset; } } else { @@ -769,47 +843,60 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s fp0 = (float*)data_block->dims[dimid].offs; fp = (float*)data_block->dims[dimid].ints; for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp[jj] = fp[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp[jj] = fp[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[jj] = fp0[jj] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[jj] = fp0[jj] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: fp0 = (float*)data_block->dims[dimid].offs; for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp0[jj] = fp0[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp0[jj] = fp0[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[jj] = fp0[jj] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[jj] = fp0[jj] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: fp0 = (float*)data_block->dims[dimid].offs; fp = (float*)data_block->dims[dimid].ints; - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - fp0[0] = fp0[0] + - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + fp0[0] = fp0[0] + (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - fp[jj] = fp[jj] * - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + fp[jj] = fp[jj] * (float)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; @@ -822,50 +909,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (double)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (double)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (double)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_CHAR: { char* ar0 = (char*)data_block->dims[dimid].offs; @@ -873,50 +972,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_SHORT: { short* ar = (short*)data_block->dims[dimid].ints; @@ -924,50 +1035,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_INT: { int* ar = (int*)data_block->dims[dimid].ints; @@ -975,50 +1098,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_LONG: { long* ar = (long*)data_block->dims[dimid].ints; @@ -1026,50 +1161,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_CHAR: { unsigned char* ar = (unsigned char*)data_block->dims[dimid].ints; @@ -1077,50 +1224,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned char)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned char)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_SHORT: { unsigned short* ar = (unsigned short*)data_block->dims[dimid].ints; @@ -1128,50 +1287,65 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = + ar0[jj] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = + ar0[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = + ar0[jj] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned short)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned short)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_INT: { unsigned int* ar = (unsigned int*)data_block->dims[dimid].ints; @@ -1179,50 +1353,62 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned int)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned int)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; case UDA_TYPE_UNSIGNED_LONG: { unsigned long* ar = (unsigned long*)data_block->dims[dimid].ints; @@ -1230,71 +1416,85 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s switch (data_block->dims[dimid].method) { case 1: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 2: for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar0[jj] = ar0[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar0[jj] = ar0[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[jj] = ar0[jj] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[jj] = ar0[jj] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } } break; case 3: - if (actions.action[i].calibration.dimensions[j].dimcalibration.offset != - (double)0.0E0) { - ar0[0] = ar0[0] + - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.offset; + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset != (double)0.0E0) { + ar0[0] = ar0[0] + (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.offset; } - for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) - if (actions.action[i].calibration.dimensions[j].dimcalibration.factor != - (double)1.0E0) { - ar[jj] = ar[jj] * - (unsigned long)actions.action[i].calibration.dimensions[j].dimcalibration.factor; + for (jj = 0; jj < data_block->dims[dimid].udoms; jj++) { + if (actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor != (double)1.0E0) { + ar[jj] = ar[jj] * (unsigned long)actions.action[i] + .calibration.dimensions[j] + .dimcalibration.factor; } + } break; default: break; } - } - break; + } break; default: - break; // Need to Add for all data types + break; // Need to Add for all data types } } } else { - applyCalibration(data_block->dims[dimid].data_type, - data_block->dims[dimid].dim_n, - actions.action[i].calibration.dimensions[j].dimcalibration.factor, - actions.action[i].calibration.dimensions[j].dimcalibration.offset, - actions.action[i].calibration.dimensions[j].dimcalibration.invert, - data_block->dims[dimid].dim); + applyCalibration( + data_block->dims[dimid].data_type, data_block->dims[dimid].dim_n, + actions.action[i].calibration.dimensions[j].dimcalibration.factor, + actions.action[i].calibration.dimensions[j].dimcalibration.offset, + actions.action[i].calibration.dimensions[j].dimcalibration.invert, + data_block->dims[dimid].dim); UDA_LOG(UDA_LOG_DEBUG, "Rescaling Dimension : %d\n", dimid); UDA_LOG(UDA_LOG_DEBUG, "Time Dimension ? : %d\n", data_block->order); - UDA_LOG(UDA_LOG_DEBUG, "Scale ? : %f\n", - (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor); - UDA_LOG(UDA_LOG_DEBUG, "Offset ? : %f\n", - (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset); + UDA_LOG( + UDA_LOG_DEBUG, "Scale ? : %f\n", + (float)actions.action[i].calibration.dimensions[j].dimcalibration.factor); + UDA_LOG( + UDA_LOG_DEBUG, "Offset ? : %f\n", + (float)actions.action[i].calibration.dimensions[j].dimcalibration.offset); UDA_LOG(UDA_LOG_DEBUG, "Invert ? : %d\n", (int)actions.action[i].calibration.dimensions[j].dimcalibration.invert); } @@ -1317,7 +1517,6 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s actions.action[i].calibration.dimensions[j].dimcalibration.invert, data_block->dims[dimid].errlo); } - } } } @@ -1327,12 +1526,9 @@ void uda::server_apply_signal_XML(CLIENT_BLOCK client_block, DATA_SOURCE* data_s default: break; } - } } - - // Combine the set of Actions from both sources with Signal XML having Priority of Signal_Desc XML void uda::server_deselect_signal_XML(ACTIONS* actions_desc, ACTIONS* actions_sig) @@ -1342,18 +1538,22 @@ void uda::server_deselect_signal_XML(ACTIONS* actions_desc, ACTIONS* actions_sig UDA_LOG(UDA_LOG_DEBUG, "Deselecting Conflicting XML\n"); -//---------------------------------------------------------------------------------------------- -// Loop over all Signal actions + //---------------------------------------------------------------------------------------------- + // Loop over all Signal actions for (int i = 0; i < actions_sig->nactions; i++) { - type = actions_sig->action[i].actionType; // Target (This has Priority) + type = actions_sig->action[i].actionType; // Target (This has Priority) -// Loop over all Signal_Desc actions + // Loop over all Signal_Desc actions for (int j = 0; j < actions_desc->nactions; j++) { - if (!actions_desc->action[j].inRange) continue; // Out of Pulse/Pass Range - if (actions_desc->action[j].actionType == type) actions_desc->action[j].inRange = 0; // Disable + if (!actions_desc->action[j].inRange) { + continue; // Out of Pulse/Pass Range + } + if (actions_desc->action[j].actionType == type) { + actions_desc->action[j].inRange = 0; // Disable + } } } } diff --git a/source/server2/get_data.cpp b/source/server2/get_data.cpp index 4b724619..075d830f 100644 --- a/source/server2/get_data.cpp +++ b/source/server2/get_data.cpp @@ -1,18 +1,19 @@ #include "get_data.hpp" -#include "clientserver/stringUtils.h" +#include "apply_XML.hpp" #include "clientserver/errorLog.h" +#include "clientserver/nameValueSubstitution.h" +#include "clientserver/printStructs.h" +#include "clientserver/stringUtils.h" +#include "initStructs.h" #include "logging/logging.h" +#include "make_server_request_block.hpp" +#include "server_plugin.h" #include "server_subset_data.h" -#include "apply_XML.hpp" -#include "initStructs.h" -#include "clientserver/printStructs.h" #include "udaPlugin.h" -#include "server_plugin.h" -#include "make_server_request_block.hpp" -#include "clientserver/nameValueSubstitution.h" #include "udaTypes.h" -namespace { +namespace +{ int swap_signal_error(DataBlock* data_block, DataBlock* data_block2, int asymmetry) { @@ -21,12 +22,16 @@ int swap_signal_error(DataBlock* data_block, DataBlock* data_block2, int asymmet if (data_block->rank == data_block2->rank && data_block->data_n == data_block2->data_n) { if (!asymmetry) { - if (data_block->errhi != nullptr) free(data_block->errhi); // Free unwanted Error Data Heap - data_block->errhi = data_block2->data; // straight swap! - data_block2->data = nullptr; // Prevent Double Heap Free + if (data_block->errhi != nullptr) { + free(data_block->errhi); // Free unwanted Error Data Heap + } + data_block->errhi = data_block2->data; // straight swap! + data_block2->data = nullptr; // Prevent Double Heap Free data_block->errasymmetry = 0; } else { - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->errlo = data_block2->data; data_block2->data = nullptr; data_block->errasymmetry = 1; @@ -56,26 +61,36 @@ int swap_signal_dim(DimComposite dimcomposite, DataBlock* data_block, DataBlock* if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].dim) != nullptr) { free(cptr); } // Free unwanted dimension Heap - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } - data_block->dims[dimcomposite.to_dim].dim = nullptr; // Prevent Double Heap Free + data_block->dims[dimcomposite.to_dim].dim = nullptr; // Prevent Double Heap Free data_block->dims[dimcomposite.to_dim].sams = nullptr; data_block->dims[dimcomposite.to_dim].offs = nullptr; data_block->dims[dimcomposite.to_dim].ints = nullptr; data_block->dims[dimcomposite.to_dim].errhi = nullptr; data_block->dims[dimcomposite.to_dim].errlo = nullptr; - data_block->dims[dimcomposite.to_dim].dim = data_block2->data; // straight swap! + data_block->dims[dimcomposite.to_dim].dim = data_block2->data; // straight swap! data_block->dims[dimcomposite.to_dim].errhi = data_block2->errhi; data_block->dims[dimcomposite.to_dim].errlo = data_block2->errlo; for (int i = 0; i < data_block2->error_param_n; i++) { data_block->dims[dimcomposite.to_dim].errparams[i] = data_block2->errparams[i]; } - data_block2->data = nullptr; // Prevent Double Heap Free + data_block2->data = nullptr; // Prevent Double Heap Free data_block2->errhi = nullptr; data_block2->errlo = nullptr; @@ -83,7 +98,7 @@ int swap_signal_dim(DimComposite dimcomposite, DataBlock* data_block, DataBlock* data_block->dims[dimcomposite.to_dim].data_type = data_block2->data_type; data_block->dims[dimcomposite.to_dim].error_type = data_block2->error_type; data_block->dims[dimcomposite.to_dim].errasymmetry = data_block2->errasymmetry; - data_block->dims[dimcomposite.to_dim].compressed = 0; // Not Applicable to Signal Data + data_block->dims[dimcomposite.to_dim].compressed = 0; // Not Applicable to Signal Data data_block->dims[dimcomposite.to_dim].dim0 = 0.0E0; data_block->dims[dimcomposite.to_dim].diff = 0.0E0; data_block->dims[dimcomposite.to_dim].method = 0; @@ -107,23 +122,35 @@ int swap_signal_dim(DimComposite dimcomposite, DataBlock* data_block, DataBlock* if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].dim) != nullptr) { free(cptr); - } // Free unwanted dimension Heap - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) free(cptr); - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) free(cptr); - - data_block->dims[dimcomposite.to_dim].dim = data_block2->dims[dimcomposite.from_dim].dim; // straight swap! + } // Free unwanted dimension Heap + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].sams) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].offs) != nullptr) { + free(cptr); + } + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].ints) != nullptr) { + free(cptr); + } + + data_block->dims[dimcomposite.to_dim].dim = + data_block2->dims[dimcomposite.from_dim].dim; // straight swap! data_block->dims[dimcomposite.to_dim].errhi = data_block2->dims[dimcomposite.from_dim].errhi; data_block->dims[dimcomposite.to_dim].errlo = data_block2->dims[dimcomposite.from_dim].errlo; data_block->dims[dimcomposite.to_dim].sams = data_block2->dims[dimcomposite.from_dim].sams; data_block->dims[dimcomposite.to_dim].offs = data_block2->dims[dimcomposite.from_dim].offs; data_block->dims[dimcomposite.to_dim].ints = data_block2->dims[dimcomposite.from_dim].ints; for (int i = 0; i < data_block2->dims[dimcomposite.from_dim].error_param_n; i++) { - data_block->dims[dimcomposite.to_dim].errparams[i] = data_block2->dims[dimcomposite.from_dim].errparams[i]; + data_block->dims[dimcomposite.to_dim].errparams[i] = + data_block2->dims[dimcomposite.from_dim].errparams[i]; } - data_block2->dims[dimcomposite.from_dim].dim = nullptr; // Prevent Double Heap Free + data_block2->dims[dimcomposite.from_dim].dim = nullptr; // Prevent Double Heap Free data_block2->dims[dimcomposite.from_dim].errhi = nullptr; data_block2->dims[dimcomposite.from_dim].errlo = nullptr; data_block2->dims[dimcomposite.from_dim].sams = nullptr; @@ -139,9 +166,12 @@ int swap_signal_dim(DimComposite dimcomposite, DataBlock* data_block, DataBlock* data_block->dims[dimcomposite.to_dim].udoms = data_block2->dims[dimcomposite.from_dim].udoms; data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].error_type; - data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].errasymmetry; - data_block->dims[dimcomposite.to_dim].error_model = data_block2->dims[dimcomposite.from_dim].error_model; - data_block->dims[dimcomposite.to_dim].error_param_n = data_block2->dims[dimcomposite.from_dim].error_param_n; + data_block->dims[dimcomposite.to_dim].error_model = + data_block2->dims[dimcomposite.from_dim].errasymmetry; + data_block->dims[dimcomposite.to_dim].error_model = + data_block2->dims[dimcomposite.from_dim].error_model; + data_block->dims[dimcomposite.to_dim].error_param_n = + data_block2->dims[dimcomposite.from_dim].error_param_n; strcpy(data_block->dims[dimcomposite.to_dim].dim_units, data_block2->dims[dimcomposite.from_dim].dim_units); @@ -160,7 +190,7 @@ int swap_signal_dim_error(DimComposite dimcomposite, DataBlock* data_block, Data { void* cptr = nullptr; -// Replace Dimension Error Data with Signal Data + // Replace Dimension Error Data with Signal Data if (dimcomposite.from_dim < 0 && dimcomposite.to_dim >= 0) { @@ -169,12 +199,14 @@ int swap_signal_dim_error(DimComposite dimcomposite, DataBlock* data_block, Data if (!asymmetry) { if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errhi) != nullptr) { free(cptr); - } // Unwanted - data_block->dims[dimcomposite.to_dim].errhi = data_block2->data; // straight swap! - data_block2->data = nullptr; // Prevent Double Heap Free + } // Unwanted + data_block->dims[dimcomposite.to_dim].errhi = data_block2->data; // straight swap! + data_block2->data = nullptr; // Prevent Double Heap Free data_block->dims[dimcomposite.to_dim].errasymmetry = 0; } else { - if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) free(cptr); + if ((cptr = (void*)data_block->dims[dimcomposite.to_dim].errlo) != nullptr) { + free(cptr); + } data_block->dims[dimcomposite.to_dim].errlo = data_block2->data; data_block2->data = nullptr; data_block->dims[dimcomposite.to_dim].errasymmetry = 1; @@ -188,7 +220,7 @@ int swap_signal_dim_error(DimComposite dimcomposite, DataBlock* data_block, Data return 0; } -} // anon namespace +} // namespace int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data_block, int protocol_version) { @@ -203,8 +235,8 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data ACTIONS actions_comp_desc, actions_comp_sig; ACTIONS actions_comp_desc2, actions_comp_sig2; - static int original_request = 0; // First entry value of the Plugin Request - static int original_xml = 0; // First entry flag that XML was passed in + static int original_request = 0; // First entry value of the Plugin Request + static int original_xml = 0; // First entry flag that XML was passed in //-------------------------------------------------------------------------------------------------------------------------- // Retain the original request (Needed to flag that signal/file details are in the Request or Action structures) @@ -223,7 +255,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data if (original_xml == 1 && *depth == 1) { metadata_block_.signal_desc.xml[0] = '\0'; - } // remove redirected XML after first recursive pass + } // remove redirected XML after first recursive pass #endif //-------------------------------------------------------------------------------------------------------------------------- @@ -237,7 +269,8 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data UDA_LOG(UDA_LOG_DEBUG, "GetData Recursive Depth = %d\n", *depth); - // Can't use REQUEST_READ_SERVERSIDE because data must be read first using a 'real' data reader or REQUEST_READ_GENERIC + // Can't use REQUEST_READ_SERVERSIDE because data must be read first using a 'real' data reader or + // REQUEST_READ_GENERIC if (protocol_version < 6) { if (STR_IEQUALS(request_data->archive, "SS") || STR_IEQUALS(request_data->archive, "SERVERSIDE")) { @@ -281,7 +314,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data if (rc > 0) { (*depth)--; - return rc; // An Error Occurred + return rc; // An Error Occurred } //-------------------------------------------------------------------------------------------------------------------------- @@ -301,14 +334,16 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data UDA_LOG(UDA_LOG_DEBUG, "Derived/Composite Signal %s\n", request_data->signal); - isDerived = 1; // is True + isDerived = 1; // is True - //derived_signal_desc = *signal_desc; // Preserve details of Derived Signal Description Record - metadata_block_.data_source.exp_number = request_data->exp_number; // Needed for Pulse Number Range Check in XML Parser - metadata_block_.data_source.pass = request_data->pass; // Needed for a Pass/Sequence Range Check in XML Parser + // derived_signal_desc = *signal_desc; // Preserve details of Derived Signal Description + // Record + metadata_block_.data_source.exp_number = + request_data->exp_number; // Needed for Pulse Number Range Check in XML Parser + metadata_block_.data_source.pass = request_data->pass; // Needed for a Pass/Sequence Range Check in XML Parser - // Allways Parse Signal XML to Identify the True Data Source for this Pulse Number - not subject to client request: get_asis - // (First Valid Action Record found only - others ignored) + // Allways Parse Signal XML to Identify the True Data Source for this Pulse Number - not subject to client + // request: get_asis (First Valid Action Record found only - others ignored) initActions(&actions_comp_desc); initActions(&actions_comp_sig); @@ -326,14 +361,16 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data UDA_THROW_ERROR(8881, "Unable to Parse XML"); } - // Identify which XML statements are in Range (Only signal_desc xml need be checked as signal xml is specific to a single pulse/pass) + // Identify which XML statements are in Range (Only signal_desc xml need be checked as signal xml is specific to + // a single pulse/pass) compId = -1; if (rc == 0) { for (int i = 0; i < actions_comp_desc.nactions; i++) { - if (actions_comp_desc.action[i].actionType == UDA_COMPOSITE_TYPE && actions_comp_desc.action[i].inRange) { + if (actions_comp_desc.action[i].actionType == UDA_COMPOSITE_TYPE && + actions_comp_desc.action[i].inRange) { compId = i; - break; // First Record found only! + break; // First Record found only! } } @@ -343,12 +380,14 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0) { // If we haven't a True Signal then can't identify the data required! - request_block2 = *request_data; // Preserve details of the Original User Request (Do Not FREE Elements) + request_block2 = + *request_data; // Preserve details of the Original User Request (Do Not FREE Elements) strcpy(request_block2.signal, - actions_comp_desc.action[compId].composite.data_signal); // True Signal Identity + actions_comp_desc.action[compId].composite.data_signal); // True Signal Identity - // Does this Composite originate from a subsetting operation? If so then fill out any missing items in the composite record + // Does this Composite originate from a subsetting operation? If so then fill out any missing items + // in the composite record if (actions_comp_desc.action[compId].composite.nsubsets > 0 || actions_comp_desc.action[compId].composite.nmaps > 0 || @@ -357,24 +396,27 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data // ******** If there is No subset then composite.file is missing!!! - if (strlen(actions_comp_desc.action[compId].composite.file) == 0 - && strlen(metadata_block_.data_source.path) > 0) { + if (strlen(actions_comp_desc.action[compId].composite.file) == 0 && + strlen(metadata_block_.data_source.path) > 0) { strcpy(actions_comp_desc.action[compId].composite.file, metadata_block_.data_source.path); } - if (strlen(actions_comp_desc.action[compId].composite.format) == 0 - && strlen(metadata_block_.data_source.format) > 0) { - strcpy(actions_comp_desc.action[compId].composite.format, metadata_block_.data_source.format); + if (strlen(actions_comp_desc.action[compId].composite.format) == 0 && + strlen(metadata_block_.data_source.format) > 0) { + strcpy(actions_comp_desc.action[compId].composite.format, + metadata_block_.data_source.format); } - if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0 - && strlen(metadata_block_.signal_desc.signal_name) == 0) { - strcpy(metadata_block_.signal_desc.signal_name, actions_comp_desc.action[compId].composite.data_signal); + if (strlen(actions_comp_desc.action[compId].composite.data_signal) > 0 && + strlen(metadata_block_.signal_desc.signal_name) == 0) { + strcpy(metadata_block_.signal_desc.signal_name, + actions_comp_desc.action[compId].composite.data_signal); } } //=======>>> Experimental ============================================ - // Need to change formats from GENERIC if Composite and Signal Description record only exists and format Not Generic! + // Need to change formats from GENERIC if Composite and Signal Description record only exists and + // format Not Generic! if (request_data->request == REQUEST_READ_GENERIC && request_data->exp_number <= 0) { request_data->request = REQUEST_READ_XML; @@ -389,7 +431,8 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; - UDA_THROW_ERROR(8888, "User Specified Composite Data Signal Not Fully Defined: Format?, File?"); + UDA_THROW_ERROR(8888, + "User Specified Composite Data Signal Not Fully Defined: Format?, File?"); } strcpy(request_block2.path, actions_comp_desc.action[compId].composite.file); @@ -408,13 +451,16 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; - UDA_THROW_ERROR(8889, "User Specified Composite Data Signal's File Format NOT Recognised"); + UDA_THROW_ERROR(8889, + "User Specified Composite Data Signal's File Format NOT Recognised"); } } if (request_block2.request == REQUEST_READ_HDF5) { - strcpy(metadata_block_.data_source.path, TrimString(request_block2.path)); // HDF5 File Location - strcpy(metadata_block_.signal_desc.signal_name, TrimString(request_block2.signal)); // HDF5 Variable Name + strcpy(metadata_block_.data_source.path, + TrimString(request_block2.path)); // HDF5 File Location + strcpy(metadata_block_.signal_desc.signal_name, + TrimString(request_block2.signal)); // HDF5 Variable Name } } @@ -440,10 +486,10 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data rc = get_data(depth, &request_block2, data_block, 0); - freeActions(&actions_desc_); // Added 06Nov2008 + freeActions(&actions_desc_); // Added 06Nov2008 freeActions(&actions_sig_); - if (rc != 0) { // Error + if (rc != 0) { // Error freeActions(&actions_comp_desc); freeActions(&actions_comp_sig); (*depth)--; @@ -466,7 +512,9 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data } } - } else { isDerived = 0; } + } else { + isDerived = 0; + } //-------------------------------------------------------------------------------------------------------------------------- // Parse Qualifying Actionable XML @@ -486,7 +534,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data if (rc == -1) { if (!serverside) { (*depth)--; - return 0; // No XML to Apply so No More to be Done! + return 0; // No XML to Apply so No More to be Done! } } else { if (rc == 1) { @@ -496,7 +544,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data } } else { (*depth)--; - return 0; // Ignore All XML so nothing to be done! Done! + return 0; // Ignore All XML so nothing to be done! Done! } } @@ -598,7 +646,6 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data return rc; } } - } //-------------------------------------------------------------------------------------------------------------------------- @@ -612,7 +659,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data UDA_LOG(UDA_LOG_DEBUG, "Substituting Dimension Data\n"); strcpy(request_block2.format, - "GENERIC"); // Database Lookup if not specified in XML or by Client + "GENERIC"); // Database Lookup if not specified in XML or by Client // Replace signal name re-using the Local Working REQUEST Block @@ -621,8 +668,12 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data // Replace other properties if defined by the original client request or the XML DIMCOMPOSITE record - if (strlen(request_data->path) > 0) strcpy(request_block2.path, request_data->file); - if (strlen(request_data->format) > 0) strcpy(request_block2.format, request_data->format); + if (strlen(request_data->path) > 0) { + strcpy(request_block2.path, request_data->file); + } + if (strlen(request_data->format) > 0) { + strcpy(request_block2.format, request_data->format); + } if (strlen(actions_desc_.action[compId].composite.file) > 0) { strcpy(request_block2.path, actions_desc_.action[compId].composite.file); @@ -647,7 +698,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data initActions(&actions_comp_desc2); initActions(&actions_comp_sig2); initDataBlock(&data_block2); - initSignalDesc(&signal_desc2); // Added 06Nov2008 + initSignalDesc(&signal_desc2); // Added 06Nov2008 // Check if the source file was originally defined in the client API? @@ -694,8 +745,8 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data // Replace Dimension Data - rc = swap_signal_dim(actions_desc_.action[compId].composite.dimensions[i].dimcomposite, - data_block, &data_block2); + rc = swap_signal_dim(actions_desc_.action[compId].composite.dimensions[i].dimcomposite, data_block, + &data_block2); freeDataBlock(&data_block2); @@ -795,13 +846,13 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data return rc; } } - } } } //-------------------------------------------------------------------------------------------------------------------------- - // Apply Any Labeling, Timing Offsets and Calibration Actions to Data and Dimension (no Data or Dimension substituting) + // Apply Any Labeling, Timing Offsets and Calibration Actions to Data and Dimension (no Data or Dimension + // substituting) UDA_LOG(UDA_LOG_DEBUG, "#Timing Before XML\n"); printDataBlock(*data_block); @@ -869,7 +920,7 @@ int uda::Server::get_data(int* depth, RequestData* request_data, DataBlock* data freeActions(&actions_serverside); } -//-------------------------------------------------------------------------------------------------------------------------- + //-------------------------------------------------------------------------------------------------------------------------- (*depth)--; return 0; @@ -892,9 +943,9 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) #ifndef PROXYSERVER if (request->request != REQUEST_READ_XML) { if (STR_STARTSWITH(request->signal, "signal); // XML is passed via the signal string + metadata_block_.signal_desc.type = 'C'; // Composite/Derived Type + metadata_block_.signal_desc.signal_name[0] = '\0'; // The true signal is contained in the XML + strcpy(metadata_block_.signal_desc.xml, request->signal); // XML is passed via the signal string strcpy(metadata_block_.data_source.format, request->format); strcpy(metadata_block_.data_source.path, request->path); strcpy(metadata_block_.data_source.filename, request->file); @@ -915,8 +966,8 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) // // If the source is a private file and the Legacy Name has No Alternative record, then fail access // If the source is Not a private file (Generic Access method) and the Legacy Name has No Alternative record and - // the Source Alias associated with the Legacy Name (Signal_Desc table) is Not used by ANY Alternative mapping with the same - // Rank, then allow normal Generic lookup. + // the Source Alias associated with the Legacy Name (Signal_Desc table) is Not used by ANY Alternative mapping with + // the same Rank, then allow normal Generic lookup. //------------------------------------------------------------------------------ #ifndef PROXYSERVER if (client_block_.clientFlags & CLIENTFLAG_ALTDATA && request->request != REQUEST_READ_XML && @@ -924,15 +975,17 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) if (request->request != REQUEST_READ_GENERIC) { // Must be a Private File so switch signal names - strcpy(request->signal, metadata_block_.signal_desc.signal_name); // Alias or Generic have no context wrt private files - metadata_block_.signal_desc.xml[0] = '\0'; // No corrections to private data files - strcpy(metadata_block_.signal_desc.xml, mapping); // Only mapping XML is applicable + strcpy(request->signal, + metadata_block_.signal_desc.signal_name); // Alias or Generic have no context wrt private files + metadata_block_.signal_desc.xml[0] = '\0'; // No corrections to private data files + strcpy(metadata_block_.signal_desc.xml, mapping); // Only mapping XML is applicable if (mapping[0] != '\0') { metadata_block_.signal_desc.type = 'S'; - } // Switched data with mapping Transform in XML + } // Switched data with mapping Transform in XML } else { if (metadata_block_.signal_desc.signal_alias[0] != '\0') { - strcpy(request->signal, metadata_block_.signal_desc.signal_alias); // Alias or Generic name is what is passed into sqlGeneric + strcpy(request->signal, metadata_block_.signal_desc + .signal_alias); // Alias or Generic name is what is passed into sqlGeneric } } } @@ -952,7 +1005,8 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) UDA_THROW_ERROR(778, "Unable to identify requested data item"); } - // If the plugin is registered as a FILE or LIBRARY type then call the default method as no method will have been specified + // If the plugin is registered as a FILE or LIBRARY type then call the default method as no method will have + // been specified strcpy(request->function, maybe_plugin->method); @@ -980,7 +1034,9 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) { int err = name_value_substitution(&request->nameValueList, request->tpass); - if (err != 0) return err; + if (err != 0) { + return err; + } } //------------------------------------------------------------------------------ @@ -989,8 +1045,8 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) if (request->request == REQUEST_READ_XML) { if (strlen(request->signal) > 0) { - strcpy(metadata_block_.signal_desc.xml, request->signal); // XML is passed via the signal string - } else if (strlen(request->path) > 0) { // XML is passed via a file + strcpy(metadata_block_.signal_desc.xml, request->signal); // XML is passed via the signal string + } else if (strlen(request->path) > 0) { // XML is passed via a file FILE* xmlfile = nullptr; int nchar; errno = 0; @@ -1009,7 +1065,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) while (!feof(xmlfile) && nchar < MAXMETA) { request->signal[nchar++] = (char)getc(xmlfile); } - request->signal[nchar - 2] = '\0'; // Remove EOF Character and replace with String Terminator + request->signal[nchar - 2] = '\0'; // Remove EOF Character and replace with String Terminator strcpy(metadata_block_.signal_desc.xml, request->signal); fclose(xmlfile); } else { @@ -1057,7 +1113,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) int plugin_request = REQUEST_READ_UNKNOWN; if (request->request != REQUEST_READ_GENERIC && request->request != REQUEST_READ_UNKNOWN) { - plugin_request = request->request; // User has Specified a Plugin + plugin_request = request->request; // User has Specified a Plugin UDA_LOG(UDA_LOG_DEBUG, "Plugin Request %d\n", plugin_request); } else { auto maybe_plugin = plugins_.find_by_format(metadata_block_.data_source.format); @@ -1083,8 +1139,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) } #endif if (maybe_plugin.get().external == UDA_PLUGIN_EXTERNAL && - maybe_plugin.get().status == UDA_PLUGIN_OPERATIONAL && - maybe_plugin.get().pluginHandle != nullptr && + maybe_plugin.get().status == UDA_PLUGIN_OPERATIONAL && maybe_plugin.get().pluginHandle != nullptr && maybe_plugin.get().idamPlugin != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "[%d] %s Plugin Selected\n", plugin_request, metadata_block_.data_source.format); @@ -1139,7 +1194,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) return 0; } - request->request = REQUEST_READ_GENERIC; // Use a different Plugin + request->request = REQUEST_READ_GENERIC; // Use a different Plugin } } } @@ -1147,7 +1202,7 @@ int uda::Server::read_data(RequestData* request, DATA_BLOCK* data_block) int plugin_request = REQUEST_READ_UNKNOWN; if (request->request != REQUEST_READ_GENERIC) { - plugin_request = request->request; // User API has Specified a Plugin + plugin_request = request->request; // User API has Specified a Plugin } else { // Test for known File formats and Server protocols diff --git a/source/server2/get_plugin_address.cpp b/source/server2/get_plugin_address.cpp old mode 100755 new mode 100644 index c217eb01..c7bc1d36 --- a/source/server2/get_plugin_address.cpp +++ b/source/server2/get_plugin_address.cpp @@ -1,11 +1,11 @@ #include "get_plugin_address.hpp" -#include #include +#include #include -#include #include "logging/logging.h" +#include /** * Return the function address for plugin data readers located in external shared libraries @@ -18,7 +18,7 @@ */ int uda::get_plugin_address(void** pluginHandle, const char* library, const char* symbol, PLUGINFUNP* pluginfunp) { - *pluginfunp = (PLUGINFUNP)nullptr; + *pluginfunp = (PLUGINFUNP) nullptr; if (library[0] == '\0' || symbol[0] == '\0') { // Nothing to 'point' to! Is this an Error? @@ -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)(IDAM_PLUGIN_INTERFACE*); *(void**)(&fptr) = dlsym(*pluginHandle, symbol); char* errstr = dlerror(); diff --git a/source/server2/make_server_request_block.cpp b/source/server2/make_server_request_block.cpp old mode 100755 new mode 100644 index dc19871f..dcd2b31d --- a/source/server2/make_server_request_block.cpp +++ b/source/server2/make_server_request_block.cpp @@ -1,20 +1,22 @@ #include "make_server_request_block.hpp" -#include #include "initStructs.h" +#include -#include "server_environment.hpp" #include "plugins.hpp" +#include "server_environment.hpp" #if defined(SERVERBUILD) || defined(FATCLIENT) -int uda::makeServerRequestBlock(RequestBlock* request_block, const uda::Plugins& plugins, const server::Environment& environment) +int uda::makeServerRequestBlock(RequestBlock* request_block, const uda::Plugins& plugins, + const server::Environment& environment) { auto plugin_list = plugins.as_plugin_list(); return make_request_block(request_block, plugin_list, environment.p_env()); } -int uda::makeServerRequestData(RequestData* request, const uda::Plugins& plugins, const server::Environment& environment) +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()); diff --git a/source/server2/plugins.cpp b/source/server2/plugins.cpp index 9a00de96..7507bf75 100644 --- a/source/server2/plugins.cpp +++ b/source/server2/plugins.cpp @@ -1,20 +1,21 @@ +#include +#include #include #include #include -#include -#include -#include "plugins.hpp" #include "get_plugin_address.hpp" +#include "plugins.hpp" -#include "udaPlugin.h" #include "clientserver/stringUtils.h" -#include #include "logging/logging.h" +#include "udaPlugin.h" +#include -#define REQUEST_READ_START 1000 +#define REQUEST_READ_START 1000 -namespace { +namespace +{ void init_plugin_data(PLUGIN_DATA* plugin) { @@ -65,10 +66,11 @@ int process_line(const std::string& line, PluginData& plugin) case 0: // File Format or Server Protocol or Library name or Device name etc. strcpy(plugin.format, token.c_str()); - // If the Format or Protocol is Not unique, the plugin that is selected will be the first one registered: others will be ignored. + // If the Format or Protocol is Not unique, the plugin that is selected will be the first one + // registered: others will be ignored. break; - case 1: // Plugin class: File, Server, Function or Device + case 1: // Plugin class: File, Server, Function or Device plugin.plugin_class = UDA_PLUGIN_CLASS_FILE; if (ltoken == "server") { plugin.plugin_class = UDA_PLUGIN_CLASS_SERVER; @@ -82,17 +84,18 @@ int process_line(const std::string& line, PluginData& plugin) break; case 2: - // Allow the same symbol (name of data access reader function or plugin entrypoint symbol) but from different libraries! + // Allow the same symbol (name of data access reader function or plugin entrypoint symbol) but from + // different libraries! if (plugin.plugin_class != UDA_PLUGIN_CLASS_DEVICE) { strcpy(plugin.symbol, token.c_str()); - plugin.external = UDA_PLUGIN_EXTERNAL; // External (not linked) shared library + plugin.external = UDA_PLUGIN_EXTERNAL; // External (not linked) shared library if (plugin.plugin_class == UDA_PLUGIN_CLASS_FILE) { // Plugin method name using a dot syntax char* p; if ((p = strchr(plugin.symbol, '.')) != nullptr) { - p[0] = '\0'; // Remove the method name from the symbol text - strcpy(plugin.method, &p[1]); // Save the method name + p[0] = '\0'; // Remove the method name from the symbol text + strcpy(plugin.method, &p[1]); // Save the method name } } @@ -136,28 +139,23 @@ int process_line(const std::string& line, PluginData& plugin) case 6: // Permission to Cache returned values strcpy(plugin.desc, token.c_str()); - if (plugin.desc[0] != '\0' && ( - plugin.desc[0] == 'Y' || - plugin.desc[0] == 'y' || - plugin.desc[0] == 'T' || - plugin.desc[0] == 't' || - plugin.desc[0] == '1')) { - plugin.cachePermission = UDA_PLUGIN_OK_TO_CACHE; // True + if (plugin.desc[0] != '\0' && + (plugin.desc[0] == 'Y' || plugin.desc[0] == 'y' || plugin.desc[0] == 'T' || plugin.desc[0] == 't' || + plugin.desc[0] == '1')) { + plugin.cachePermission = UDA_PLUGIN_OK_TO_CACHE; // True plugin.desc[0] = '\0'; - } else - plugin.cachePermission = UDA_PLUGIN_NOT_OK_TO_CACHE; // False + } else { + plugin.cachePermission = UDA_PLUGIN_NOT_OK_TO_CACHE; // False + } break; case 7: // Private or Public plugin - i.e. available to external users strcpy(plugin.desc, token.c_str()); - if (plugin.desc[0] != '\0' && ( - plugin.desc[0] == 'Y' || - plugin.desc[0] == 'y' || - plugin.desc[0] == 'T' || - plugin.desc[0] == 't' || - plugin.desc[0] == '1')) { + if (plugin.desc[0] != '\0' && + (plugin.desc[0] == 'Y' || plugin.desc[0] == 'y' || plugin.desc[0] == 'T' || plugin.desc[0] == 't' || + plugin.desc[0] == '1')) { plugin.is_private = UDA_PLUGIN_PUBLIC; plugin.desc[0] = '\0'; } @@ -187,14 +185,14 @@ int process_line(const std::string& line, PluginData& plugin) std::ifstream open_config_file() { char* root; - char* config = getenv("UDA_PLUGIN_CONFIG"); // Server plugin configuration file - const char* default_file = "udaPlugins.conf"; // Default name + char* config = getenv("UDA_PLUGIN_CONFIG"); // Server plugin configuration file + const char* default_file = "udaPlugins.conf"; // Default name std::string file_path; // Locate the plugin registration file if (config == nullptr) { - root = getenv("UDA_SERVERROOT"); // Where udaPlugins.conf is located by default + root = getenv("UDA_SERVERROOT"); // Where udaPlugins.conf is located by default if (root == nullptr) { file_path = std::string{"./"} + default_file; } else { @@ -210,7 +208,7 @@ std::ifstream open_config_file() return conf_file; } -} // anon namespace +} // namespace void uda::Plugins::init() { @@ -289,13 +287,12 @@ void uda::Plugins::process_config_file(std::ifstream& conf_file) // Issue Unique request ID plugin.request = REQUEST_READ_START + offset++; - plugin.pluginHandle = nullptr; // Library handle: Not opened - plugin.status = UDA_PLUGIN_NOT_OPERATIONAL; // Not yet available + plugin.pluginHandle = nullptr; // Library handle: Not opened + plugin.status = UDA_PLUGIN_NOT_OPERATIONAL; // Not yet available // Internal Serverside function ? - if (plugin.plugin_class == UDA_PLUGIN_CLASS_FUNCTION && - STR_IEQUALS(plugin.symbol, "serverside") && - plugin.library[0] == '\0') { + if (plugin.plugin_class == UDA_PLUGIN_CLASS_FUNCTION && STR_IEQUALS(plugin.symbol, "serverside") && + plugin.library[0] == '\0') { strcpy(plugin.symbol, "SERVERSIDE"); plugin.request = REQUEST_READ_GENERIC; plugin.external = UDA_PLUGIN_INTERNAL; @@ -314,24 +311,19 @@ void uda::Plugins::process_config_file(std::ifstream& conf_file) int j = 0; for (auto& test : plugins_) { // External sources only - if (test.external == UDA_PLUGIN_EXTERNAL && - test.status == UDA_PLUGIN_OPERATIONAL && - test.pluginHandle != nullptr && - STR_IEQUALS(test.library, plugin.library)) { + if (test.external == UDA_PLUGIN_EXTERNAL && test.status == UDA_PLUGIN_OPERATIONAL && + test.pluginHandle != nullptr && STR_IEQUALS(test.library, plugin.library)) { // Library may contain different symbols if (STR_IEQUALS(test.symbol, plugin.symbol) && test.idamPlugin != nullptr) { rc = 0; - plugin.idamPlugin = test.idamPlugin; // re-use + plugin.idamPlugin = test.idamPlugin; // re-use } else { // New symbol in opened library if (plugin.plugin_class != UDA_PLUGIN_CLASS_DEVICE) { - rc = get_plugin_address( - &test.pluginHandle, // locate symbol - test.library, - plugin.symbol, - &plugin.idamPlugin); + rc = get_plugin_address(&test.pluginHandle, // locate symbol + test.library, plugin.symbol, &plugin.idamPlugin); } } @@ -342,12 +334,9 @@ void uda::Plugins::process_config_file(std::ifstream& conf_file) ++j; } - if (pluginID == -1) { // open library and locate symbol + if (pluginID == -1) { // open library and locate symbol if (plugin.plugin_class != UDA_PLUGIN_CLASS_DEVICE) { - rc = get_plugin_address(&plugin.pluginHandle, - plugin.library, - plugin.symbol, - &plugin.idamPlugin); + rc = get_plugin_address(&plugin.pluginHandle, plugin.library, plugin.symbol, &plugin.idamPlugin); } } @@ -372,23 +361,22 @@ void uda::Plugins::init_generic_plugin() plugin.request = REQUEST_READ_GENERIC; plugin.plugin_class = UDA_PLUGIN_CLASS_OTHER; plugin.is_private = UDA_PLUGIN_PUBLIC; - strcpy(plugin.desc, - "Generic Data Access request - no file format or server name specified, only the shot number"); + strcpy(plugin.desc, "Generic Data Access request - no file format or server name specified, only the shot number"); strcpy(plugin.example, R"(udaGetAPI("signal name", "12345"))"); - plugin.external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions - plugin.status = UDA_PLUGIN_OPERATIONAL; // By default all these are available - plugin.cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache + plugin.external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions + plugin.status = UDA_PLUGIN_OPERATIONAL; // By default all these are available + plugin.cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache plugins_.push_back(plugin); } void uda::Plugins::init_serverside_functions() -{//---------------------------------------------------------------------------------------------------------------------- -// Server-Side Functions +{ //---------------------------------------------------------------------------------------------------------------------- + // Server-Side Functions auto names = {"SERVERSIDE", "SSIDE", "SS"}; - for (auto& name: names) { + for (auto& name : names) { PluginData plugin = {}; strcpy(plugin.format, name); @@ -399,9 +387,9 @@ void uda::Plugins::init_serverside_functions() plugin.is_private = UDA_PLUGIN_PUBLIC; plugin.library[0] = '\0'; plugin.pluginHandle = nullptr; - plugin.external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions - plugin.status = UDA_PLUGIN_OPERATIONAL; // By default all these are available - plugin.cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache + plugin.external = UDA_PLUGIN_INTERNAL; // These are all linked as internal functions + plugin.status = UDA_PLUGIN_OPERATIONAL; // By default all these are available + plugin.cachePermission = UDA_PLUGIN_CACHE_DEFAULT; // OK or not for Client and Server to Cache plugins_.push_back(plugin); } diff --git a/source/server2/server.cpp b/source/server2/server.cpp index ce4627c9..278d5dce 100644 --- a/source/server2/server.cpp +++ b/source/server2/server.cpp @@ -1,22 +1,22 @@ #include "server.hpp" +#include #include #include -#include -#include "initStructs.h" -#include "server_environment.hpp" -#include "logging/logging.h" #include "clientserver/errorLog.h" -#include "udaErrors.h" +#include "clientserver/printStructs.h" #include "clientserver/protocol.h" #include "clientserver/xdrlib.h" -#include "clientserver/printStructs.h" +#include "initStructs.h" #include "logging/accessLog.h" +#include "logging/logging.h" +#include "server_environment.hpp" +#include "server_exceptions.h" #include "server_plugin.h" #include "server_processing.h" #include "struct.h" -#include "server_exceptions.h" +#include "udaErrors.h" #ifdef SSLAUTHENTICATION # include "authentication/udaServerSSL.h" #endif @@ -51,13 +51,10 @@ void print_data_block_list(const std::vector& data_blocks) } } -uda::Server::Server() - : error_stack_{} - , environment_{} - , sockets_{} +uda::Server::Server() : error_stack_{}, environment_{}, sockets_{} { initServerBlock(&server_block_, ServerVersion); - initActions(&actions_desc_); // There may be a Sequence of Actions to Apply + initActions(&actions_desc_); // There may be a Sequence of Actions to Apply initActions(&actions_sig_); initRequestBlock(&request_block_); cache_ = cache::open_cache(); @@ -73,11 +70,11 @@ void uda::Server::start_logs() } errno = 0; - std::string log_file = std::string{ environment_->logdir } + "Access.log"; + std::string log_file = std::string{environment_->logdir} + "Access.log"; FILE* accout = fopen(log_file.c_str(), environment_->logmode); if (errno != 0) { - addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__ , errno, "Access Log: "); + addIdamError(UDA_SYSTEM_ERROR_TYPE, __func__, errno, "Access Log: "); addIdamError(UDA_CODE_ERROR_TYPE, __func__, 999, "Failed to open access log"); if (accout != nullptr) { fclose(accout); @@ -89,7 +86,7 @@ void uda::Server::start_logs() if (environment_->loglevel <= UDA_LOG_ERROR) { errno = 0; - std::string log_file = std::string{ environment_->logdir } + "Error.log"; + std::string log_file = std::string{environment_->logdir} + "Error.log"; FILE* errout = fopen(log_file.c_str(), environment_->logmode); if (errno != 0) { @@ -105,7 +102,7 @@ void uda::Server::start_logs() if (environment_->loglevel <= UDA_LOG_WARN) { errno = 0; - std::string log_file = std::string{ environment_->logdir } + "DebugServer.log"; + std::string log_file = std::string{environment_->logdir} + "DebugServer.log"; FILE* dbgout = fopen(log_file.c_str(), environment_->logmode); if (errno != 0) { @@ -228,11 +225,11 @@ void uda::Server::loop() UDA_LOG(UDA_LOG_DEBUG, "Start of Server Wait Loop\n"); // Create a new userdefinedtypelist for the request by copying the parseduserdefinedtypelist structure - //copyUserDefinedTypeList(&userdefinedtypelist); + // copyUserDefinedTypeList(&userdefinedtypelist); getInitialUserDefinedTypeList(&user_defined_type_list_); parsed_user_defined_type_list_ = *user_defined_type_list_; -// printUserDefinedTypeList(*user_defined_type_list_); + // printUserDefinedTypeList(*user_defined_type_list_); log_malloc_list_ = (LOGMALLOCLIST*)malloc(sizeof(LOGMALLOCLIST)); initLogMallocList(log_malloc_list_); @@ -284,7 +281,7 @@ void uda::Server::loop() // Write the Error Log Record & Free Error Stack Heap UDA_LOG(UDA_LOG_DEBUG, "concatUdaError\n"); - concatUdaError(&server_block_.idamerrorstack); // Update Server State with Error Stack + concatUdaError(&server_block_.idamerrorstack); // Update Server State with Error Stack UDA_LOG(UDA_LOG_DEBUG, "closeUdaError\n"); closeUdaError(); @@ -318,16 +315,16 @@ int uda::Server::handle_request() initClientBlock(&client_block_, 0, ""); - err = protocol_.recv_client_block(server_block_, &client_block_, &fatal_error_, server_tot_block_time_, &server_timeout_, - log_malloc_list_, user_defined_type_list_); + err = protocol_.recv_client_block(server_block_, &client_block_, &fatal_error_, server_tot_block_time_, + &server_timeout_, log_malloc_list_, user_defined_type_list_); if (err != 0) { return err; } - server_timeout_ = client_block_.timeout; // User specified Server Lifetime - unsigned int private_flags = client_block_.privateFlags; // Server to Server flags - unsigned int clientFlags = client_block_.clientFlags; // Client set flags - int altRank = client_block_.altRank; // Rank of Alternative source + server_timeout_ = client_block_.timeout; // User specified Server Lifetime + unsigned int private_flags = client_block_.privateFlags; // Server to Server flags + unsigned int clientFlags = client_block_.clientFlags; // Client set flags + int altRank = client_block_.altRank; // Rank of Alternative source // Protocol Version: Lower of the client and server version numbers // This defines the set of elements within data structures passed between client and server @@ -340,7 +337,8 @@ int uda::Server::handle_request() protocol_.set_version(protocol_version); // The client request may originate from a server. - // Is the Originating server an externally facing server? If so then switch to this mode: preserve local access policy + // Is the Originating server an externally facing server? If so then switch to this mode: preserve local access + // policy if (!environment_->external_user && (private_flags & PRIVATEFLAG_EXTERNAL)) { environment_->external_user = 1; @@ -369,7 +367,7 @@ int uda::Server::handle_request() } else { err = 1; } - return err; // Manage the Fatal Server State + return err; // Manage the Fatal Server State } // Test for an immediate CLOSEDOWN instruction @@ -410,9 +408,9 @@ int uda::Server::handle_request() * * The name of the proxy reirection plugin is UDA by default but may be changed using the environment variable * UDA_PROXYPLUGINNAME - */ + */ -# ifdef PROXYSERVER +#ifdef PROXYSERVER // Name of the Proxy plugin @@ -421,12 +419,14 @@ int uda::Server::handle_request() char work[STRING_LENGTH]; - if ((proxyName = getenv("UDA_PROXYPLUGINNAME")) == nullptr) proxyName = proxyNameDefault; + if ((proxyName = getenv("UDA_PROXYPLUGINNAME")) == nullptr) { + proxyName = proxyNameDefault; + } // Check string length compatibility - if (strlen(request_block_.source) >= - (STRING_LENGTH - 1 - strlen(proxyName) - strlen(environment_->server_proxy) - strlen(request_block_.api_delim))) { + if (strlen(request_block_.source) >= (STRING_LENGTH - 1 - strlen(proxyName) - strlen(environment_->server_proxy) - + strlen(request_block_.api_delim))) { UDA_THROW_ERROR(999, "PROXY redirection: The source argument string is too long!"); } @@ -441,7 +441,8 @@ int uda::Server::handle_request() if (strncasecmp(request_block_.source, work, strlen(work)) != 0) { // Not a recognised redirection so prepending is necessary - // Has a proxy host been specified in the server startup script? If not assume the plugin has a default host and port + // Has a proxy host been specified in the server startup script? If not assume the plugin has a default host and + // port if (environment_->server_proxy[0] == '\0') { if (request_block_.api_delim[0] != '\0') { @@ -452,18 +453,20 @@ int uda::Server::handle_request() strcpy(request_block_.source, work); - } else { // UDA::host.port/source + } else { // UDA::host.port/source // Check the Server Version is Compatible with the Originating client version ? if (client_block->version < 6) { - UDA_THROW_ERROR(999, "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); + UDA_THROW_ERROR( + 999, + "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); } // Test for Proxy calling itself indirectly => potential infinite loop - // The UDA Plugin strips out the host and port data from the source so the originating server details are never passed. - // Primitive test as the same IP address can be mapped to different names! - // Should pass on the number of redirections and cap the limit! + // The UDA Plugin strips out the host and port data from the source so the originating server details are + // never passed. Primitive test as the same IP address can be mapped to different names! Should pass on the + // number of redirections and cap the limit! if (environment_->server_this[0] != '\0') { if (request_block_.api_delim[0] != '\0') { @@ -473,32 +476,41 @@ int uda::Server::handle_request() } if (strstr(request_block_.source, work) != nullptr) { - UDA_THROW_ERROR(999, "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); + UDA_THROW_ERROR( + 999, + "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); } } // Prepend the redirection UDA server details and replace the original if (request_block_.source[0] == '/') { - if (request_block_.api_delim[0] != '\0') - sprintf(work, "%s%s%s%s", proxyName, request_block_.api_delim, environment_->server_proxy, request_block_.source); - else - sprintf(work, "%s%s%s%s", proxyName, environment_->api_delim, environment_->server_proxy, request_block_.source); + if (request_block_.api_delim[0] != '\0') { + sprintf(work, "%s%s%s%s", proxyName, request_block_.api_delim, environment_->server_proxy, + request_block_.source); + } else { + sprintf(work, "%s%s%s%s", proxyName, environment_->api_delim, environment_->server_proxy, + request_block_.source); + } } else { - if (request_block_.api_delim[0] != '\0') - sprintf(work, "%s%s%s/%s", proxyName, request_block_.api_delim, environment_->server_proxy, request_block_.source); - else - sprintf(work, "%s%s%s/%s", proxyName, environment_->api_delim, environment_->server_proxy, request_block_.source); + if (request_block_.api_delim[0] != '\0') { + sprintf(work, "%s%s%s/%s", proxyName, request_block_.api_delim, environment_->server_proxy, + request_block_.source); + } else { + sprintf(work, "%s%s%s/%s", proxyName, environment_->api_delim, environment_->server_proxy, + request_block_.source); + } } strcpy(request_block_.source, work); } - UDA_LOG(UDA_LOG_DEBUG, "PROXY Redirection to %s avoiding %s\n", environment_->server_proxy, environment_->server_this); + UDA_LOG(UDA_LOG_DEBUG, "PROXY Redirection to %s avoiding %s\n", environment_->server_proxy, + environment_->server_this); UDA_LOG(UDA_LOG_DEBUG, "plugin: %s\n", proxyName); UDA_LOG(UDA_LOG_DEBUG, "source: %s\n", request_block_.source); } -# else +#else for (int i = 0; i < request_block_.num_requests; ++i) { REQUEST_DATA* request = &request_block_.requests[0]; @@ -515,12 +527,14 @@ int uda::Server::handle_request() // Check the Server Version is Compatible with the Originating client version ? if (client_block_.version < 6) { - UDA_THROW_ERROR(999, - "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); + UDA_THROW_ERROR( + 999, + "PROXY redirection: Originating Client Version not compatible with the PROXY server interface."); } // Test for Proxy calling itself indirectly => potential infinite loop - // The UDA Plugin strips out the host and port data from the source so the originating server details are never passed. + // The UDA Plugin strips out the host and port data from the source so the originating server details are + // never passed. if (request->api_delim[0] != '\0') { snprintf(work, STRING_LENGTH, "UDA%s%s", request->api_delim, environment_->server_this); @@ -529,8 +543,8 @@ int uda::Server::handle_request() } if (strstr(request->source, work) != nullptr) { - UDA_THROW_ERROR(999, - "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); + UDA_THROW_ERROR( + 999, "PROXY redirection: The PROXY is calling itself - Recursive server calls are not advisable!"); } // Check string length compatibility @@ -543,9 +557,11 @@ int uda::Server::handle_request() // Prepend the redirection UDA server details if (request->api_delim[0] != '\0') { - snprintf(work, STRING_LENGTH, "UDA%s%s/%s", request->api_delim, environment_->server_proxy, request->source); + snprintf(work, STRING_LENGTH, "UDA%s%s/%s", request->api_delim, environment_->server_proxy, + request->source); } else { - snprintf(work, STRING_LENGTH, "UDA%s%s/%s", environment_->api_delim, environment_->server_proxy, request->source); + snprintf(work, STRING_LENGTH, "UDA%s%s/%s", environment_->api_delim, environment_->server_proxy, + request->source); } strcpy(request->source, work); @@ -554,7 +570,7 @@ int uda::Server::handle_request() UDA_LOG(UDA_LOG_DEBUG, "source: %s\n", request->source); } } -# endif +#endif //---------------------------------------------------------------------- // Write to the Access Log @@ -577,7 +593,8 @@ int uda::Server::handle_request() initPutDataBlockList(&request->putDataBlockList); if (request->put) { - err = protocol_.recv_putdata_block_list(&request->putDataBlockList, log_malloc_list_, user_defined_type_list_); + err = protocol_.recv_putdata_block_list(&request->putDataBlockList, log_malloc_list_, + user_defined_type_list_); if (err != 0) { return err; } @@ -593,8 +610,8 @@ int uda::Server::handle_request() for (int i = 0; i < request_block_.num_requests; ++i) { auto request = &request_block_.requests[i]; if (protocol_version >= 6) { - if ((err = uda::serverPlugin(request, &metadata_block_.data_source, &metadata_block_.signal_desc, - plugins_, environment_.p_env())) != 0) { + if ((err = uda::serverPlugin(request, &metadata_block_.data_source, &metadata_block_.signal_desc, plugins_, + environment_.p_env())) != 0) { return err; } } else { @@ -612,7 +629,8 @@ int uda::Server::handle_request() for (int i = 0; i < request_block_.num_requests; ++i) { auto request = &request_block_.requests[i]; - auto cache_block = protocol_.read_from_cache(cache_, request, environment_, log_malloc_list_, user_defined_type_list_); + auto cache_block = + protocol_.read_from_cache(cache_, request, environment_, log_malloc_list_, user_defined_type_list_); if (cache_block != nullptr) { data_blocks_.push_back(*cache_block); continue; @@ -651,7 +669,9 @@ int uda::Server::handle_request() UDA_LOG(UDA_LOG_DEBUG, "======================== ******************** ==========================================\n"); - if (err != 0) return err; + if (err != 0) { + return err; + } //------------------------------------------------------------------------------------------------ // Server-Side Data Processing @@ -674,11 +694,11 @@ int uda::Server::handle_request() data_block.data_type = UDA_TYPE_CHAR; } - if (data_block.data_n > 0 && - (protocolVersionTypeTest(protocol_version, data_block.data_type) || - protocolVersionTypeTest(protocol_version, data_block.error_type))) { - UDA_THROW_ERROR(999, - "The Data has a type that cannot be passed to the Client: A newer client library version is required."); + if (data_block.data_n > 0 && (protocolVersionTypeTest(protocol_version, data_block.data_type) || + protocolVersionTypeTest(protocol_version, data_block.error_type))) { + UDA_THROW_ERROR( + 999, + "The Data has a type that cannot be passed to the Client: A newer client library version is required."); } if (data_block.rank > 0) { @@ -687,8 +707,8 @@ int uda::Server::handle_request() dim = data_block.dims[j]; if (protocolVersionTypeTest(protocol_version, dim.data_type) || protocolVersionTypeTest(protocol_version, dim.error_type)) { - UDA_THROW_ERROR(999, - "A Coordinate Data has a numerical type that cannot be passed to the Client: A newer client library version is required."); + UDA_THROW_ERROR(999, "A Coordinate Data has a numerical type that cannot be passed to the Client: " + "A newer client library version is required."); } } } @@ -769,8 +789,7 @@ int uda::Server::report_to_client() if (client_block_.get_meta) { total_datablock_size_ += - sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + - sizeof(SIGNAL_DESC); + sizeof(DATA_SYSTEM) + sizeof(SYSTEM_CONFIG) + sizeof(DATA_SOURCE) + sizeof(SIGNAL) + sizeof(SIGNAL_DESC); err = protocol_.send_meta_data(metadata_block_, log_malloc_list_, user_defined_type_list_); if (err != 0) { @@ -835,9 +854,9 @@ void uda::Server::handshake_client() // Must be the same on both sides of the socket // set in xdr_client - //protocolVersion = serverVersion; - //if(client_block.version < serverVersion) protocolVersion = client_block.version; - //if(client_block.version < server_block.version) protocolVersion = client_block.version; + // protocolVersion = serverVersion; + // if(client_block.version < serverVersion) protocolVersion = client_block.version; + // if(client_block.version < server_block.version) protocolVersion = client_block.version; // Send the server block diff --git a/source/server2/server_environment.cpp b/source/server2/server_environment.cpp old mode 100755 new mode 100644 index 75c79c10..9a7a28ef --- a/source/server2/server_environment.cpp +++ b/source/server2/server_environment.cpp @@ -1,8 +1,8 @@ #include "server_environment.hpp" +#include #include #include -#include #include @@ -31,28 +31,34 @@ uda::server::Environment::Environment() strcpy(environment_.logdir, env); strcat(environment_.logdir, "/"); } else { - strcpy(environment_.logdir, "/scratch/udalog/"); // Log is on Scratch + strcpy(environment_.logdir, "/scratch/udalog/"); // Log is on Scratch } environment_.loglevel = UDA_LOG_NONE; if ((env = getenv("UDA_LOG_LEVEL")) != nullptr) { std::string level = env; boost::to_upper(level); - if (level == "ACCESS") { environment_.loglevel = UDA_LOG_ACCESS; } - else if (level == "ERROR") { environment_.loglevel = UDA_LOG_ERROR; } - else if (level == "WARN") { environment_.loglevel = UDA_LOG_WARN; } - else if (level == "DEBUG") { environment_.loglevel = UDA_LOG_DEBUG; } - else if (level == "INFO") { environment_.loglevel = UDA_LOG_INFO; } + if (level == "ACCESS") { + environment_.loglevel = UDA_LOG_ACCESS; + } else if (level == "ERROR") { + environment_.loglevel = UDA_LOG_ERROR; + } else if (level == "WARN") { + environment_.loglevel = UDA_LOG_WARN; + } else if (level == "DEBUG") { + environment_.loglevel = UDA_LOG_DEBUG; + } else if (level == "INFO") { + environment_.loglevel = UDA_LOG_INFO; + } } // Log Output Write Mode - strcpy(environment_.logmode, "w"); // Write & Replace Mode + strcpy(environment_.logmode, "w"); // Write & Replace Mode if ((env = getenv("UDA_LOG_MODE")) != nullptr) { if (env[0] == 'a' && strlen(env) == 1) { environment_.logmode[0] = 'a'; } - } // Append Mode + } // Append Mode //------------------------------------------------------------------------------------------- // API Defaults @@ -98,8 +104,12 @@ uda::server::Environment::Environment() environment_.external_user = 0; #endif - if ((env = getenv("EXTERNAL_USER")) != nullptr) { environment_.external_user = 1; } - if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { environment_.external_user = 1; } + if ((env = getenv("EXTERNAL_USER")) != nullptr) { + environment_.external_user = 1; + } + if ((env = getenv("UDA_EXTERNAL_USER")) != nullptr) { + environment_.external_user = 1; + } //------------------------------------------------------------------------------------------- // UDA Proxy Host: redirect ALL requests diff --git a/source/server2/server_exceptions.h b/source/server2/server_exceptions.h index 65ece60d..b331807f 100644 --- a/source/server2/server_exceptions.h +++ b/source/server2/server_exceptions.h @@ -1,12 +1,14 @@ #pragma once #ifndef UDA_SOURCE_SERVER2_SERVER_EXCEPTIONS_H -#define UDA_SOURCE_SERVER2_SERVER_EXCEPTIONS_H +# define UDA_SOURCE_SERVER2_SERVER_EXCEPTIONS_H -#include +# include -namespace uda { -namespace server { +namespace uda +{ +namespace server +{ enum class ErrorCode { ProtocolVersionError, @@ -16,36 +18,36 @@ enum class ErrorCode { class Exception : public std::exception { -public: + public: explicit Exception(ErrorCode ec) : ec_{ec}, msg_{""} {} explicit Exception(ErrorCode ec, const char* msg) : ec_{ec}, msg_{msg} {} int code() { return static_cast(ec_); } [[nodiscard]] const char* what() const noexcept override { return msg_; } -private: + private: ErrorCode ec_; const char* msg_; }; class ProtocolError : public Exception { -public: + public: explicit ProtocolError(const char* msg) : Exception(ErrorCode::ProtocolError, msg) {} }; class ProtocolVersionError : public Exception { -public: + public: explicit ProtocolVersionError(const char* msg) : Exception(ErrorCode::ProtocolError, msg) {} }; class StartupException : public Exception { -public: + public: explicit StartupException(const char* msg) : Exception(ErrorCode::StartupError, msg) {} }; } // namespace server } // namespace uda -#endif //UDA_SOURCE_SERVER2_SERVER_EXCEPTIONS_H +#endif // UDA_SOURCE_SERVER2_SERVER_EXCEPTIONS_H diff --git a/source/server2/server_main.cpp b/source/server2/server_main.cpp old mode 100755 new mode 100644 index 52e5b171..dc452434 --- a/source/server2/server_main.cpp +++ b/source/server2/server_main.cpp @@ -13,7 +13,7 @@ int main() { // Optional sleep at startup - char * env = getenv("UDA_SLEEP"); + char* env = getenv("UDA_SLEEP"); if (env != nullptr) { sleep((unsigned int)atoi(env)); } @@ -22,7 +22,7 @@ int main() try { uda::Server server; -// server.run(); + // server.run(); } catch (uda::server::Exception& ex) { return ex.code(); } diff --git a/source/server2/server_plugin.cpp b/source/server2/server_plugin.cpp old mode 100755 new mode 100644 index 205c9e84..0bf7bab7 --- a/source/server2/server_plugin.cpp +++ b/source/server2/server_plugin.cpp @@ -1,73 +1,73 @@ /*--------------------------------------------------------------- -* Identify the correct UDA Data Server Plugin -*---------------------------------------------------------------------------------------------------------------------*/ + * Identify the correct UDA Data Server Plugin + *---------------------------------------------------------------------------------------------------------------------*/ #include "server_plugin.h" #include "plugins.hpp" #include "server.hpp" -#include #include -#include +#include #include +#include #if defined(__GNUC__) # include #else -# include # include +# include # define dup _dup # define dup2 _dup2 #endif +#include "initStructs.h" +#include "logging/logging.h" +#include "struct.h" #include +#include #include -#include "initStructs.h" #include #include #include -#include "struct.h" -#include -#include "logging/logging.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 +#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 int uda::serverRedirectStdStreams(int reset) { // Any OS messages will corrupt xdr streams so re-divert IO from plugin libraries to a temporary file // Multi platform compliance - //static FILE* originalStdFH = nullptr; - //static FILE* originalErrFH = nullptr; + // static FILE* originalStdFH = nullptr; + // static FILE* originalErrFH = nullptr; static int originalStdFH = 0; static int originalErrFH = 0; static FILE* mdsmsgFH = nullptr; - static char mksdir_template[MAXPATH] = { 0 }; - static char tempFile[MAXPATH] = { 0 }; + static char mksdir_template[MAXPATH] = {0}; + static char tempFile[MAXPATH] = {0}; static bool singleFile = false; if (!reset) { if (!singleFile) { - const char* env = getenv("UDA_PLUGIN_DEBUG_SINGLEFILE"); // Use a single file for all plugin data requests + const char* env = getenv("UDA_PLUGIN_DEBUG_SINGLEFILE"); // Use a single file for all plugin data requests if (env != nullptr) { - singleFile = true; // Define UDA_PLUGIN_DEBUG to retain the file + singleFile = true; // Define UDA_PLUGIN_DEBUG to retain the file } } if (mdsmsgFH != nullptr && singleFile) { // Multi platform compliance - //stdout = mdsmsgFH; // Redirect all IO to a temporary file - //stderr = mdsmsgFH; + // stdout = mdsmsgFH; // Redirect all IO to a temporary file + // stderr = mdsmsgFH; dup2(fileno(mdsmsgFH), fileno(stdout)); dup2(fileno(mdsmsgFH), fileno(stderr)); return 0; } // Multi platform compliance - //originalStdFH = stdout; // Retain current values - //originalErrFH = stderr; + // originalStdFH = stdout; // Retain current values + // originalErrFH = stderr; originalStdFH = dup(fileno(stdout)); originalErrFH = dup(fileno(stderr)); mdsmsgFH = nullptr; @@ -107,8 +107,8 @@ int uda::serverRedirectStdStreams(int reset) } // Multi platform compliance - //stdout = mdsmsgFH; // Redirect to a temporary file - //stderr = mdsmsgFH; + // stdout = mdsmsgFH; // Redirect to a temporary file + // stderr = mdsmsgFH; dup2(fileno(mdsmsgFH), fileno(stdout)); dup2(fileno(mdsmsgFH), fileno(stderr)); } else { @@ -127,7 +127,7 @@ int uda::serverRedirectStdStreams(int reset) mdsmsgFH = nullptr; if (getenv("UDA_PLUGIN_DEBUG") == nullptr) { errno = 0; - int rc = remove(tempFile); // Delete the temporary file + int rc = remove(tempFile); // Delete the temporary file if (rc) { int err = errno; UDA_THROW_ERROR(err, strerror(err)); @@ -137,8 +137,8 @@ int uda::serverRedirectStdStreams(int reset) } // Multi platform compliance - //stdout = originalStdFH; - //stderr = originalErrFH; + // stdout = originalStdFH; + // stderr = originalErrFH; dup2(originalStdFH, fileno(stdout)); dup2(originalErrFH, fileno(stderr)); @@ -147,8 +147,8 @@ int uda::serverRedirectStdStreams(int reset) UDA_LOG(UDA_LOG_DEBUG, "Resetting original file handles\n"); // Multi platform compliance - //stdout = originalStdFH; - //stderr = originalErrFH; + // stdout = originalStdFH; + // stderr = originalErrFH; dup2(originalStdFH, fileno(stdout)); dup2(originalErrFH, fileno(stderr)); } @@ -168,8 +168,8 @@ int uda::serverRedirectStdStreams(int reset) // 5. open the library // 6. get plugin function address // 7. close the file -int uda::serverPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, - const Plugins& plugins, const ENVIRONMENT* environment) +int uda::serverPlugin(REQUEST_DATA* request, DATA_SOURCE* data_source, SIGNAL_DESC* signal_desc, const Plugins& plugins, + const ENVIRONMENT* environment) { int err = 0; @@ -249,7 +249,7 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque static bool initialised = false; static boost::optional plugin = {}; - static int exec_method = 1; // The default method used to write efficiently to the backend SQL server + static int exec_method = 1; // The default method used to write efficiently to the backend SQL server char* env = nullptr; struct timeval tv_start = {}; @@ -274,12 +274,9 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque UDA_LOG(UDA_LOG_DEBUG, "plugin_list->plugin[id].idamPlugin != nullptr = %d\n", maybe_plugin->idamPlugin != nullptr); } - if (maybe_plugin && - maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION && - !environment->external_user && - maybe_plugin->status == UDA_PLUGIN_OPERATIONAL && - maybe_plugin->pluginHandle != nullptr && - maybe_plugin->idamPlugin != nullptr) { + if (maybe_plugin && maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION && + !environment->external_user && maybe_plugin->status == UDA_PLUGIN_OPERATIONAL && + maybe_plugin->pluginHandle != nullptr && maybe_plugin->idamPlugin != nullptr) { plugin = maybe_plugin.get(); } } @@ -304,16 +301,17 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque // mimic a client request if (logRecord == nullptr || strlen(logRecord) == 0) { - snprintf(request.signal, MAXMETA, "%s::putSignal(uuid='%s',requestedSignal='%s',requestedSource='%s', " - "trueSignal='%s', trueSource='%s', trueSourceDOI='%s', execMethod=%d, status=new)", - plugin->format, client_block->DOI, original_request->signal, original_request->source, - metadata.signal_desc.signal_name, metadata.data_source.path, "", exec_method); + snprintf(request.signal, MAXMETA, + "%s::putSignal(uuid='%s',requestedSignal='%s',requestedSource='%s', " + "trueSignal='%s', trueSource='%s', trueSourceDOI='%s', execMethod=%d, status=new)", + plugin->format, client_block->DOI, original_request->signal, original_request->source, + metadata.signal_desc.signal_name, metadata.data_source.path, "", exec_method); } else { // need 2> record the server log record snprintf(request.signal, MAXMETA, "%s::putSignal(uuid='%s',logRecord='%s', execMethod=%d, status=update)", - plugin->format, client_block->DOI, logRecord, exec_method); + plugin->format, client_block->DOI, logRecord, exec_method); } // Activate the plugin @@ -383,8 +381,7 @@ int uda::provenancePlugin(ClientBlock* client_block, RequestData* original_reque freeNameValueList(&request.nameValueList); UDA_LOG(UDA_LOG_DEBUG, "testing for bug!!!\n"); - if (data_block.opaque_type != UDA_OPAQUE_TYPE_UNKNOWN || - data_block.opaque_count != 0 || + if (data_block.opaque_type != UDA_OPAQUE_TYPE_UNKNOWN || data_block.opaque_count != 0 || data_block.opaque_block != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "bug detected: mitigation!!!\n"); data_block.opaque_block = nullptr; @@ -425,21 +422,19 @@ boost::optional uda::find_metadata_plugin(const Plugins& plugins, co UDA_LOG(UDA_LOG_DEBUG, "Entered: no_plugin_registered state = %d\n", no_plugin_registered); if (plugin) { - return plugin.get(); // Plugin previously identified + return plugin.get(); // Plugin previously identified } if (no_plugin_registered) { - return {}; // No Plugin for the MetaData Catalog to resolve Generic Name mappings + return {}; // No Plugin for the MetaData Catalog to resolve Generic Name mappings } // Identify the MetaData Catalog plugin (must be a function library type plugin) char* env = nullptr; - if ((env = getenv("UDA_METADATA_PLUGIN")) != nullptr) { // Must be set in the server startup script + if ((env = getenv("UDA_METADATA_PLUGIN")) != nullptr) { // Must be set in the server startup script auto maybe_plugin = plugins.find_by_format(env); - if (maybe_plugin && - maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION && - maybe_plugin->status == UDA_PLUGIN_OPERATIONAL && - maybe_plugin->pluginHandle != nullptr && + if (maybe_plugin && maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION && + maybe_plugin->status == UDA_PLUGIN_OPERATIONAL && maybe_plugin->pluginHandle != nullptr && maybe_plugin->idamPlugin != nullptr) { plugin = maybe_plugin.get(); } @@ -450,7 +445,8 @@ boost::optional uda::find_metadata_plugin(const Plugins& plugins, co } UDA_LOG(UDA_LOG_DEBUG, "Generic Name Mapping Plugin Name: %s\n", env); - UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_CLASS_FUNCTION?: %d\n", maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION); + UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_CLASS_FUNCTION?: %d\n", + maybe_plugin->plugin_class == UDA_PLUGIN_CLASS_FUNCTION); UDA_LOG(UDA_LOG_DEBUG, "UDA_PLUGIN_PRIVATE?: %d\n", maybe_plugin->is_private == UDA_PLUGIN_PRIVATE); UDA_LOG(UDA_LOG_DEBUG, "External User?: %d\n", environment->external_user); UDA_LOG(UDA_LOG_DEBUG, "Private?: %d\n", @@ -463,7 +459,7 @@ boost::optional uda::find_metadata_plugin(const Plugins& plugins, co } if (!plugin) { - no_plugin_registered = true; // No Plugin found (registered) + no_plugin_registered = true; // No Plugin found (registered) } return plugin; @@ -472,8 +468,9 @@ boost::optional uda::find_metadata_plugin(const Plugins& plugins, co //------------------------------------------------------------------------------------------------ // Execute the Generic Name mapping Plugin -int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_block, const server::Environment& environment, - const uda::Plugins& plugins, uda::MetadataBlock& metadata) +int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_block, + const server::Environment& environment, const uda::Plugins& plugins, + uda::MetadataBlock& metadata) { int err, reset, rc; IdamPluginInterface idam_plugin_interface = {}; @@ -529,7 +526,9 @@ int uda::call_metadata_plugin(const PluginData& plugin, RequestData* request_blo if (rc != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, rc, "Error Resetting Redirected Plugin Message Output"); } - if (err != 0) return err; + if (err != 0) { + return err; + } return rc; } diff --git a/source/server2/server_plugin.h b/source/server2/server_plugin.h old mode 100755 new mode 100644 index 9fbbfaca..98703e32 --- a/source/server2/server_plugin.h +++ b/source/server2/server_plugin.h @@ -1,21 +1,22 @@ #ifndef UDA_SERVER_SERVERPLUGIN_H #define UDA_SERVER_SERVERPLUGIN_H -#include "udaPlugin.h" #include "export.h" #include "plugins.hpp" #include "server.hpp" +#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 +#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 -namespace uda { +namespace uda +{ int serverRedirectStdStreams(int reset); -int serverPlugin(RequestData* request, DataSource* data_source, SignalDesc* signal_desc, - const Plugins& plugins, const Environment* environment); +int serverPlugin(RequestData* request, DataSource* data_source, SignalDesc* signal_desc, const Plugins& plugins, + const Environment* environment); int provenancePlugin(ClientBlock* client_block, RequestData* original_request, const Plugins& plugins, const char* logRecord, const server::Environment& environment, uda::MetadataBlock& metadata); @@ -25,6 +26,6 @@ boost::optional find_metadata_plugin(const Plugins& plugins, const s int call_metadata_plugin(const PluginData& plugin, RequestData* request_block, const server::Environment& environment, const uda::Plugins& plugins, uda::MetadataBlock& metadata); -} +} // namespace uda #endif // UDA_SERVER_SERVERPLUGIN_H diff --git a/source/server2/server_processing.cpp b/source/server2/server_processing.cpp old mode 100755 new mode 100644 index 2bc77eff..09221313 --- a/source/server2/server_processing.cpp +++ b/source/server2/server_processing.cpp @@ -2,8 +2,8 @@ #include -#include #include "udaTypes.h" +#include /** * UDA Server Side Data Processing @@ -15,7 +15,7 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) { DIMS* ddim = nullptr; - double* newoffs = nullptr, * newints = nullptr; + double *newoffs = nullptr, *newints = nullptr; int reduce = 0; short ss; @@ -34,7 +34,9 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) if (ddim->compressed) { reduce = 1; if (ddim->method == 0) { - if (ddim->dim0 != (double)0.0 || ddim->diff == (double)0.0) reduce = 0; + if (ddim->dim0 != (double)0.0 || ddim->diff == (double)0.0) { + reduce = 0; + } } else { switch (ddim->data_type) { @@ -79,8 +81,7 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) case 1: for (unsigned int i = 0; i < ddim->udoms; i++) { for (int j = 0; j < *((long*)ddim->sams + i); j++) { - sd = sd + *((double*)ddim->offs + i) + - (double)j * *((double*)ddim->ints + i); + sd = sd + *((double*)ddim->offs + i) + (double)j * *((double*)ddim->ints + i); if (sd != (double)0.0) { reduce = 0; break; @@ -406,15 +407,27 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) break; } } - if (reduce) { // Reduce the Rank to Scalar and free Dimensional Heap Memory + if (reduce) { // Reduce the Rank to Scalar and free Dimensional Heap Memory data_block->order = -1; data_block->rank = 0; - if (ddim->dim != nullptr) free(ddim->dim); - if (ddim->errhi != nullptr) free(ddim->errhi); - if (ddim->errlo != nullptr) free(ddim->errlo); - if (ddim->sams != nullptr) free(ddim->sams); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->dim != nullptr) { + free(ddim->dim); + } + if (ddim->errhi != nullptr) { + free(ddim->errhi); + } + if (ddim->errlo != nullptr) { + free(ddim->errlo); + } + if (ddim->sams != nullptr) { + free(ddim->sams); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } free(ddim); data_block->dims = nullptr; } @@ -430,7 +443,7 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) if (client_block.get_timedble || client_block.get_dimdble) { for (unsigned int k = 0; k < data_block->rank; k++) { if (client_block.get_timedble && k != (unsigned int)data_block->order) { - continue; // Only Process the Time Dimension + continue; // Only Process the Time Dimension } UDA_LOG(UDA_LOG_DEBUG, "Processing Dimension %d\n", k); ddim = data_block->dims + k; @@ -445,25 +458,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((char*)ddim->offs + i); *(newints + i) = (double)*((char*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((char*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -472,8 +496,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((char*)ddim->offs); *newints = (double)*((char*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -487,25 +515,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((short*)ddim->offs + i); *(newints + i) = (double)*((short*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((short*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -514,8 +553,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((short*)ddim->offs); *newints = (double)*((short*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -529,25 +572,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((int*)ddim->offs + i); *(newints + i) = (double)*((int*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((int*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -556,8 +610,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((int*)ddim->offs); *newints = (double)*((int*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -571,25 +629,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((long*)ddim->offs + i); *(newints + i) = (double)*((long*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((long*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -598,8 +667,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((long*)ddim->offs); *newints = (double)*((long*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -613,25 +686,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned char*)ddim->offs + i); *(newints + i) = (double)*((unsigned char*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned char*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -640,8 +724,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((unsigned char*)ddim->offs); *newints = (double)*((unsigned char*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -655,25 +743,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned short*)ddim->offs + i); *(newints + i) = (double)*((unsigned short*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned short*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -682,8 +781,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((unsigned short*)ddim->offs); *newints = (double)*((unsigned short*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -697,25 +800,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned int*)ddim->offs + i); *(newints + i) = (double)*((unsigned int*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned int*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -724,8 +838,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((unsigned int*)ddim->offs); *newints = (double)*((unsigned int*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -739,25 +857,36 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned long*)ddim->offs + i); *(newints + i) = (double)*((unsigned long*)ddim->ints + i); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((unsigned long*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -766,8 +895,12 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((unsigned long*)ddim->offs); *newints = (double)*((unsigned long*)ddim->ints); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; ddim->data_type = UDA_TYPE_DOUBLE; @@ -781,36 +914,48 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newoffs = (double*)malloc(ddim->udoms * sizeof(double)); newints = (double*)malloc(ddim->udoms * sizeof(double)); if (newoffs == nullptr || newints == nullptr) { - if (newoffs != nullptr) free(newoffs); - if (newints != nullptr) free(newints); + if (newoffs != nullptr) { + free(newoffs); + } + if (newints != nullptr) { + free(newints); + } return 1; } for (unsigned int i = 0; i < ddim->udoms; i++) { UDA_LOG(UDA_LOG_DEBUG, "%i %f %f\n", i, *((float*)ddim->offs + i), - *((float*)ddim->ints + i)); + *((float*)ddim->ints + i)); *(newoffs + i) = (double)*((float*)ddim->offs + i); *(newints + i) = (double)*((float*)ddim->ints + i); UDA_LOG(UDA_LOG_DEBUG, "%i %f %f\n", i, *(newoffs + i), *(newints + i)); } - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { UDA_LOG(UDA_LOG_DEBUG, "%i %f %f\n", i, *((double*)ddim->offs + i), - *((double*)ddim->ints + i)); + *((double*)ddim->ints + i)); + } ddim->data_type = UDA_TYPE_DOUBLE; break; case 2: UDA_LOG(UDA_LOG_DEBUG, "Processing Float Method 2\n"); UDA_LOG(UDA_LOG_DEBUG, "udoms: %d\n", ddim->udoms); newoffs = (double*)malloc(ddim->udoms * sizeof(double)); - for (unsigned int i = 0; i < ddim->udoms; i++) + for (unsigned int i = 0; i < ddim->udoms; i++) { *(newoffs + i) = (double)*((float*)ddim->offs + i); - if (ddim->offs != nullptr) free(ddim->offs); + } + if (ddim->offs != nullptr) { + free(ddim->offs); + } ddim->offs = (char*)newoffs; ddim->data_type = UDA_TYPE_DOUBLE; break; @@ -820,14 +965,16 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) newints = (double*)malloc(sizeof(double)); *newoffs = (double)*((float*)ddim->offs); *newints = (double)*((float*)ddim->ints); - UDA_LOG(UDA_LOG_DEBUG, "%f %f\n", *((double*)ddim->offs), - *((double*)ddim->ints)); - if (ddim->offs != nullptr) free(ddim->offs); - if (ddim->ints != nullptr) free(ddim->ints); + UDA_LOG(UDA_LOG_DEBUG, "%f %f\n", *((double*)ddim->offs), *((double*)ddim->ints)); + if (ddim->offs != nullptr) { + free(ddim->offs); + } + if (ddim->ints != nullptr) { + free(ddim->ints); + } ddim->offs = (char*)newoffs; ddim->ints = (char*)newints; - UDA_LOG(UDA_LOG_DEBUG, "%f %f\n", *((double*)ddim->offs), - *((double*)ddim->ints)); + UDA_LOG(UDA_LOG_DEBUG, "%f %f\n", *((double*)ddim->offs), *((double*)ddim->ints)); ddim->data_type = UDA_TYPE_DOUBLE; break; } @@ -835,7 +982,6 @@ int uda::serverProcessing(ClientBlock client_block, DataBlock* data_block) default: break; - } } } diff --git a/source/server2/server_processing.h b/source/server2/server_processing.h old mode 100755 new mode 100644 index 10b86255..188b0bfc --- a/source/server2/server_processing.h +++ b/source/server2/server_processing.h @@ -1,16 +1,16 @@ #pragma once #ifndef UDA_SERVER_SERVERPROCESSING_H -#define UDA_SERVER_SERVERPROCESSING_H +# define UDA_SERVER_SERVERPROCESSING_H -#include "udaStructs.h" -#include "export.h" +# include "export.h" +# include "udaStructs.h" -namespace uda { +namespace uda +{ int serverProcessing(ClientBlock client_block, DataBlock* data_block); } // namespace uda #endif // UDA_SERVER_SERVERPROCESSING_H - diff --git a/source/server2/server_subset_data.cpp b/source/server2/server_subset_data.cpp old mode 100755 new mode 100644 index 1ac06290..460f47f0 --- a/source/server2/server_subset_data.cpp +++ b/source/server2/server_subset_data.cpp @@ -8,23 +8,23 @@ #include "server_subset_data.h" #include "server_environment.hpp" -#include -#include #include +#include +#include #if defined(__GNUC__) # include #else # define strncasecmp _strnicmp #endif -#include -#include -#include -#include "udaTypes.h" -#include "struct.h" #include "initStructs.h" +#include "struct.h" +#include "udaTypes.h" #include +#include +#include #include +#include //---------------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------------- @@ -40,19 +40,18 @@ // // reform - reduce the rank by 1 if the dimension length is 1 and the rank > 1 - // todo: // -namespace { +namespace +{ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* subsetindices); -int serverNewDataArray2(DIMS* dims, int rank, int dimid, - char* data, int ndata, int data_type, int notoperation, int reverse, - int start, int end, int start1, int end1, int* n, void** newdata); +int serverNewDataArray2(DIMS* dims, int rank, int dimid, char* data, int ndata, int data_type, int notoperation, + int reverse, int start, int end, int start1, int end1, int* n, void** newdata); -} // anon namespace +} // namespace int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* logmalloclist) { @@ -61,7 +60,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* SUBSET subset; char* operation; - char* newdata, * newerrhi, * newerrlo; + char *newdata, *newerrhi, *newerrlo; int nsubsets, nbound, dimid, start, end, start1, end1, dim_n, ndata, n, reshape, reverse, notoperation, ierr = 0; printAction(action); @@ -70,15 +69,19 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* //----------------------------------------------------------------------------------------------------------------------- // How many sets of subsetting operations? - if (action.actionType == UDA_COMPOSITE_TYPE) { // XML Based subsetting - if (action.composite.nsubsets == 0) return 0; // Nothing to Subset + if (action.actionType == UDA_COMPOSITE_TYPE) { // XML Based subsetting + if (action.composite.nsubsets == 0) { + return 0; // Nothing to Subset + } nsubsets = action.composite.nsubsets; } else { - if (action.actionType == UDA_SERVER_SIDE_TYPE) { // Client Requested subsetting - if (action.serverside.nsubsets == 0) return 0; // Nothing to Subset + if (action.actionType == UDA_SERVER_SIDE_TYPE) { // Client Requested subsetting + if (action.serverside.nsubsets == 0) { + return 0; // Nothing to Subset + } nsubsets = action.serverside.nsubsets; } else { - if (action.actionType == UDA_SUBSET_TYPE) { // Client Requested subsetting + if (action.actionType == UDA_SUBSET_TYPE) { // Client Requested subsetting nsubsets = 1; } else { return 0; @@ -97,10 +100,10 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* //----------------------------------------------------------------------------------------------------------------------- // Process all sets of subsetting operations - for (int i = 0; i < nsubsets; i++) { // the number of sets of Subset Operations + for (int i = 0; i < nsubsets; i++) { // the number of sets of Subset Operations if (action.actionType == UDA_COMPOSITE_TYPE) { - subset = action.composite.subsets[i]; // the set of Subset Operations + subset = action.composite.subsets[i]; // the set of Subset Operations } else { if (action.actionType == UDA_SERVER_SIDE_TYPE) { subset = action.serverside.subsets[i]; @@ -111,31 +114,32 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - nbound = subset.nbound; // the Number of operations in the set + nbound = subset.nbound; // the Number of operations in the set - for (int j = 0; j < nbound; j++) { // Process each operation separately + for (int j = 0; j < nbound; j++) { // Process each operation separately double value = subset.bound[j]; - operation = subset.operation[j]; // a single operation - dimid = subset.dimid[j]; // applied to this dimension (if -1 then to data only!) + operation = subset.operation[j]; // a single operation + dimid = subset.dimid[j]; // applied to this dimension (if -1 then to data only!) - UDA_LOG(UDA_LOG_DEBUG, "[%d][%d]Value = %e, Operation = %s, DIM id = %d, Reform = %d\n", - i, j, value, operation, dimid, subset.reform); + UDA_LOG(UDA_LOG_DEBUG, "[%d][%d]Value = %e, Operation = %s, DIM id = %d, Reform = %d\n", i, j, value, + operation, dimid, subset.reform); if (dimid < 0 || dimid >= (int)data_block->rank) { - UDA_LOG(UDA_LOG_ERROR, "DIM id = %d, Rank = %d, Test = %d \n", - dimid, data_block->rank, dimid >= (int)data_block->rank); + UDA_LOG(UDA_LOG_ERROR, "DIM id = %d, Rank = %d, Test = %d \n", dimid, data_block->rank, + dimid >= (int)data_block->rank); printDataBlock(*data_block); - UDA_THROW_ERROR(9999, "Data Subsetting is Impossible as the subset Dimension is not Compatible with the Rank of the Signal"); + UDA_THROW_ERROR(9999, "Data Subsetting is Impossible as the subset Dimension is not Compatible with " + "the Rank of the Signal"); return ierr; } //---------------------------------------------------------------------------------------------------------------------------- // Operations on Simple Data Structures: target must be an Atomic Type, Scalar, Name is Case Sensitive // - // (mapType=1) Array of Structures - member = single scalar value: rank and shape = rank and shape of structure array - // (mapType=2) Single Structure - member = array of values: rank and shape = increase rank and shape of structure member by 1 - // Array of Structures - member = array of values: Not allowed. + // (mapType=1) Array of Structures - member = single scalar value: rank and shape = rank and shape of + // structure array (mapType=2) Single Structure - member = array of values: rank and shape = increase rank + // and shape of structure member by 1 Array of Structures - member = array of values: Not allowed. // // (mapType=3) structure[14].array[100] -> newarray[14][100]: @@ -156,11 +160,11 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* // Extract an atomic type data element from the data structure for (i = 0; i < udt->fieldcount; i++) { - if (STR_EQUALS(udt->compoundfield[i].name, subset.member)) { // Locate target member by name + if (STR_EQUALS(udt->compoundfield[i].name, subset.member)) { // Locate target member by name data_n = data_block->data_n; - if (!udt->compoundfield[i].pointer) { // Regular Array of data + if (!udt->compoundfield[i].pointer) { // Regular Array of data count = udt->compoundfield[i].count; @@ -176,13 +180,14 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* switch (udt->compoundfield[i].atomictype) { case UDA_TYPE_DOUBLE: { - double* data = nullptr, * dp; + double *data = nullptr, *dp; if (mapType == 1) { data = (double*)malloc(data_n * sizeof(double)); - for (int k = 0; k < data_n; k++) - data[k] = *(double*)&data_block->data[k * udt->size + - udt->compoundfield[i].offset]; + for (int k = 0; k < data_n; k++) { + data[k] = *(double*)&data_block + ->data[k * udt->size + udt->compoundfield[i].offset]; + } } else { if (mapType == 2) { data_n = count; @@ -197,17 +202,19 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if ((shape = udt->compoundfield[i].shape) == nullptr && udt->compoundfield[i].rank > 1) { - UDA_THROW_ERROR(999, "The Data Structure member's shape data is missing (rank > 1)"); + UDA_THROW_ERROR( + 999, + "The Data Structure member's shape data is missing (rank > 1)"); } - } else { // mapType == 3 + } else { // mapType == 3 int total_n; total_n = count * data_n; data = (double*)malloc(total_n * sizeof(double)); int jjj = 0; - for (int jj = 0; jj < data_n; jj++) { // Loop over structures - dp = (double*)&data_block->data[jj * udt->size + - udt->compoundfield[i].offset]; + for (int jj = 0; jj < data_n; jj++) { // Loop over structures + dp = (double*)&data_block + ->data[jj * udt->size + udt->compoundfield[i].offset]; for (int k = 0; k < count; k++) { data[jjj++] = dp[k]; } @@ -221,7 +228,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - } else { // Locate the pointer data's properties: + } else { // Locate the pointer data's properties: if (data_n > 1) { int count_p = 0; @@ -243,12 +250,14 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if (shape != nullptr) { for (int k = 0; k < rank; k++) { if (shape[k] != shape_p[k]) { - //ERROR + // ERROR } } } else { if (rank > 1) { - UDA_THROW_ERROR(999, "The Data Structure member's shape data is missing (rank > 1)"); + UDA_THROW_ERROR( + 999, + "The Data Structure member's shape data is missing (rank > 1)"); } } } @@ -270,8 +279,9 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if (count >= 1 && data_n == 1) { mapType = 2; } else { - UDA_THROW_ERROR(999, "Unable to subset an array of Data Structures when the target " - "member is also an array. Functionality has not been implemented!)") + UDA_THROW_ERROR(999, + "Unable to subset an array of Data Structures when the target " + "member is also an array. Functionality has not been implemented!)") } } @@ -279,12 +289,12 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* switch (type) { case UDA_TYPE_DOUBLE: { - double* data = nullptr, * dp; + double *data = nullptr, *dp; if (mapType == 1) { data = (double*)malloc(data_n * sizeof(double)); for (int k = 0; k < data_n; k++) { - dp = *(double**)&data_block->data[k * udt->size + - udt->compoundfield[i].offset]; + dp = *(double**)&data_block + ->data[k * udt->size + udt->compoundfield[i].offset]; data[k] = dp[0]; } } else { @@ -302,7 +312,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* break; } - //default: + // default: } } @@ -353,8 +363,8 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* unsigned int k0 = data_block->rank; data_block->rank = data_block->rank + udt->compoundfield[i].rank; - data_block->dims = (DIMS*)realloc((void*)data_block->dims, - data_block->rank * sizeof(DIMS)); + data_block->dims = + (DIMS*)realloc((void*)data_block->dims, data_block->rank * sizeof(DIMS)); for (unsigned int k = k0; k < data_block->rank; k++) { initDimBlock(&data_block->dims[k]); @@ -383,7 +393,6 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* data_block->opaque_count = 0; data_block->opaque_block = nullptr; break; - } } } @@ -393,33 +402,39 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if (STR_EQUALS(operation, "*")) { continue; - } // This means No subset - Part of an array Reshape Operation + } // This means No subset - Part of an array Reshape Operation - if (operation[0] == ':' - && (subset.lbindex[j].init ? subset.lbindex[j].value : 0) == 0 - && (subset.ubindex[j].init ? subset.lbindex[j].value : data_block->dims[dimid].dim_n) == data_block->dims[dimid].dim_n - && (subset.stride[j].init ? subset.stride[j].value : 1) == 1) { - continue; // subset spans the complete dimension + if (operation[0] == ':' && (subset.lbindex[j].init ? subset.lbindex[j].value : 0) == 0 && + (subset.ubindex[j].init ? subset.lbindex[j].value : data_block->dims[dimid].dim_n) == + data_block->dims[dimid].dim_n && + (subset.stride[j].init ? subset.stride[j].value : 1) == 1) { + continue; // subset spans the complete dimension } //---------------------------------------------------------------------------------------------------------------------------- // Decompress the dimensional data if necessary & free Heap Associated with Compression - initDimBlock(&newdim); // Holder for the Subsetted Dimension (part copy of the original) + initDimBlock(&newdim); // Holder for the Subsetted Dimension (part copy of the original) - dim = &(data_block->dims[dimid]); // the original dimension to be subset + dim = &(data_block->dims[dimid]); // the original dimension to be subset if (dim->compressed) { uncompressDim(dim); - dim->compressed = 0; // Can't preserve this status after the subset has been applied + dim->compressed = 0; // Can't preserve this status after the subset has been applied dim->method = 0; - if (dim->sams != nullptr) free(dim->sams); - if (dim->offs != nullptr) free(dim->offs); - if (dim->ints != nullptr) free(dim->ints); + if (dim->sams != nullptr) { + free(dim->sams); + } + if (dim->offs != nullptr) { + free(dim->offs); + } + if (dim->ints != nullptr) { + free(dim->ints); + } dim->udoms = 0; - dim->sams = nullptr; // Avoid double freeing of Heap + dim->sams = nullptr; // Avoid double freeing of Heap dim->offs = nullptr; dim->ints = nullptr; } @@ -436,39 +451,46 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* // Subsetting Indices - start = -1; // Starting Index satisfying the operation - end = -1; // Ending Index + start = -1; // Starting Index satisfying the operation + end = -1; // Ending Index start1 = -1; end1 = -1; // Test for Array Reshaping Operations - reshape = 0; // Subsetting has been defined using array indexing notation - reverse = 0; // Reverse the ordering of elements (also uses array indexing notation) + reshape = 0; // Subsetting has been defined using array indexing notation + reverse = 0; // Reverse the ordering of elements (also uses array indexing notation) - notoperation = (operation[0] == '!'); // a NOT operator => One or Two subsets + notoperation = (operation[0] == '!'); // a NOT operator => One or Two subsets - if (operation[0] == '*') - continue; // This means No dimensional subset - Part of an array Reshape Operation + if (operation[0] == '*') { + continue; // This means No dimensional subset - Part of an array Reshape Operation + } - if (operation[0] == ':') { // Reshape Operation - Index Range Specified - start = (int)subset.lbindex[j].value; // Number before the : - end = (int)subset.ubindex[j].value; // Number after the : - if (start == -1) start = 0; - if (start == -2) start = dim->dim_n - 1; // Final array element requested - if (end == -1) end = dim->dim_n - 1; + if (operation[0] == ':') { // Reshape Operation - Index Range Specified + start = (int)subset.lbindex[j].value; // Number before the : + end = (int)subset.ubindex[j].value; // Number after the : + if (start == -1) { + start = 0; + } + if (start == -2) { + start = dim->dim_n - 1; // Final array element requested + } + if (end == -1) { + end = dim->dim_n - 1; + } - if (start > end) { // Check Ordering (Allow for Reversing?) + if (start > end) { // Check Ordering (Allow for Reversing?) int startcpy = start; reverse = 1; - start = end; // Swap indices + start = end; // Swap indices end = startcpy; } reshape = 1; dim_n = end - start + 1; } - if (operation[0] == '#') { // Reshape Operation - Highest array position (last value) + if (operation[0] == '#') { // Reshape Operation - Highest array position (last value) start = dim->dim_n - 1; end = dim->dim_n - 1; reshape = 1; @@ -481,10 +503,18 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* auto subsetindices = (unsigned int*)malloc(dim->dim_n * sizeof(unsigned int)); - if (STR_EQUALS(operation, "!<")) strcpy(operation, ">="); - if (STR_EQUALS(operation, "!>")) strcpy(operation, "<="); - if (STR_EQUALS(operation, "!<=")) strcpy(operation, ">"); - if (STR_EQUALS(operation, "!>=")) strcpy(operation, "<"); + if (STR_EQUALS(operation, "!<")) { + strcpy(operation, ">="); + } + if (STR_EQUALS(operation, "!>")) { + strcpy(operation, "<="); + } + if (STR_EQUALS(operation, "!<=")) { + strcpy(operation, ">"); + } + if (STR_EQUALS(operation, "!>=")) { + strcpy(operation, "<"); + } if ((dim_n = serverSubsetIndices(operation, dim, value, subsetindices)) == 0) { free(subsetindices); @@ -496,10 +526,10 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* start = subsetindices[0]; end = subsetindices[dim_n - 1]; - if (notoperation && dim_n > 1) { // Double Range ? + if (notoperation && dim_n > 1) { // Double Range ? int range2 = 0; if (dim_n == dim->dim_n) { - notoperation = 0; // No Second Range found so switch OFF NOT Operation + notoperation = 0; // No Second Range found so switch OFF NOT Operation } else { end1 = subsetindices[dim_n - 1]; for (int k = 0; k < dim_n; k++) { @@ -511,12 +541,12 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } range2 = end1 - start1 + 1; } - if (dim_n != end - start + 1 + range2) { // Dimension array is Not well ordered! + if (dim_n != end - start + 1 + range2) { // Dimension array is Not well ordered! free(subsetindices); UDA_THROW_ERROR(9999, "The Dimensional Array is Not Ordered: Unable to Subset"); } } else { - if (dim_n != end - start + 1) { // Dimension array is Not well ordered! + if (dim_n != end - start + 1) { // Dimension array is Not well ordered! free(subsetindices); UDA_THROW_ERROR(9999, "The Dimensional Array is Not Ordered: Unable to Subset"); } @@ -541,16 +571,16 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if (dim->errhi != nullptr && dim->error_type != UDA_TYPE_UNKNOWN) { if ((ierr = serverNewDataArray2(dim, 1, dimid, dim->errhi, dim_n, dim->error_type, notoperation, - reverse, - start, end, start1, end1, &n, (void**)&newdim.errhi)) != 0) + reverse, start, end, start1, end1, &n, (void**)&newdim.errhi)) != 0) { return ierr; + } } if (dim->errlo != nullptr && dim->error_type != UDA_TYPE_UNKNOWN) { if ((ierr = serverNewDataArray2(dim, 1, dimid, dim->errlo, dim_n, dim->error_type, notoperation, - reverse, - start, end, start1, end1, &n, (void**)&newdim.errlo)) != 0) + reverse, start, end, start1, end1, &n, (void**)&newdim.errlo)) != 0) { return ierr; + } } //----------------------------------------------------------------------------------------------------------------------- @@ -559,8 +589,8 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* printDataBlock(*data_block); if ((ierr = serverNewDataArray2(data_block->dims, data_block->rank, dimid, data_block->data, - data_block->data_n, data_block->data_type, notoperation, reverse, - start, end, start1, end1, &ndata, (void**)&newdata)) != 0) { + data_block->data_n, data_block->data_type, notoperation, reverse, start, + end, start1, end1, &ndata, (void**)&newdata)) != 0) { return ierr; } @@ -570,8 +600,8 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* start, end, start1, end1, &n, (void**)&newerrhi)) != 0) { return ierr; } - free(data_block->errhi); // Free Original Heap - data_block->errhi = newerrhi; // Replace with the Reshaped Array + free(data_block->errhi); // Free Original Heap + data_block->errhi = newerrhi; // Replace with the Reshaped Array } if (data_block->error_type != UDA_TYPE_UNKNOWN && dim->errlo != nullptr) { @@ -580,17 +610,18 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* start, end, start1, end1, &n, (void**)&newerrlo)) != 0) { return ierr; } - free(data_block->errlo); // Free Original Heap - data_block->errlo = newerrlo; // Replace with the Reshaped Array + free(data_block->errlo); // Free Original Heap + data_block->errlo = newerrlo; // Replace with the Reshaped Array } data_block->data_n = ndata; - free(data_block->data); // Free Original Heap - data_block->data = newdata; // Replace with the Reshaped Array + free(data_block->data); // Free Original Heap + data_block->data = newdata; // Replace with the Reshaped Array // replace the Original Dimensional Structure with the New Subsetted Structure unless a - // REFORM [Rank Reduction] has been requested and the dimension length is 1 (this has no effect on the Data Array items) + // REFORM [Rank Reduction] has been requested and the dimension length is 1 (this has no effect on the Data + // Array items) // Free Heap associated with the original Dimensional Structure Array @@ -604,7 +635,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* // Save the reshaped Dimension or Reform the whole - data_block->dims[dimid] = newdim; // Replace with the subsetted dimension + data_block->dims[dimid] = newdim; // Replace with the subsetted dimension } } @@ -620,26 +651,38 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* data_block->dims[j].compressed = 0; data_block->dims[j].method = 0; - if (data_block->dims[j].dim != nullptr) free(data_block->dims[j].dim); - if (data_block->dims[j].errlo != nullptr) free(data_block->dims[j].errlo); - if (data_block->dims[j].errhi != nullptr) free(data_block->dims[j].errhi); - if (data_block->dims[j].sams != nullptr) free(data_block->dims[j].sams); - if (data_block->dims[j].offs != nullptr) free(data_block->dims[j].offs); - if (data_block->dims[j].ints != nullptr) free(data_block->dims[j].ints); + if (data_block->dims[j].dim != nullptr) { + free(data_block->dims[j].dim); + } + if (data_block->dims[j].errlo != nullptr) { + free(data_block->dims[j].errlo); + } + if (data_block->dims[j].errhi != nullptr) { + free(data_block->dims[j].errhi); + } + if (data_block->dims[j].sams != nullptr) { + free(data_block->dims[j].sams); + } + if (data_block->dims[j].offs != nullptr) { + free(data_block->dims[j].offs); + } + if (data_block->dims[j].ints != nullptr) { + free(data_block->dims[j].ints); + } for (int k = j + 1; k < rank; k++) { - data_block->dims[k - 1] = data_block->dims[k]; // Shift array contents + data_block->dims[k - 1] = data_block->dims[k]; // Shift array contents } if (data_block->order == j) { - data_block->order = -1; // No Time Dimension if Reformed + data_block->order = -1; // No Time Dimension if Reformed } else { if (data_block->order > j) { data_block->order = data_block->order - 1; - } // Time Dimension ID reduced by 1 + } // Time Dimension ID reduced by 1 } - data_block->rank = data_block->rank - 1; // Reduce the Rank + data_block->rank = data_block->rank - 1; // Reduce the Rank } } } @@ -649,12 +692,12 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* if (ierr == 0 && subset.function[0] != '\0') { - if (!strncasecmp(subset.function, "minimum(", 8)) { // Single scalar result + if (!strncasecmp(subset.function, "minimum(", 8)) { // Single scalar result dimid = 0; if (data_block->rank >= 1) { char* p1 = strstr(subset.function, "dimid"); if (p1 != nullptr) { - char* p3, * p2 = strchr(p1, '='); + char *p3, *p2 = strchr(p1, '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -669,9 +712,10 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } if (dimid < 0 || dimid >= (int)data_block->rank) { - UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dimid = %d, Rank = %d\n", dimid, - data_block->rank); - UDA_THROW_ERROR(999, "The dimension ID identified via the subset function is outside the rank bounds of the array!"); + UDA_LOG(UDA_LOG_ERROR, "Function Syntax Error - dimid = %d, Rank = %d\n", dimid, data_block->rank); + UDA_THROW_ERROR( + 999, + "The dimension ID identified via the subset function is outside the rank bounds of the array!"); } switch (data_block->data_type) { @@ -679,13 +723,14 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* auto dp = (float*)data_block->data; float min = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dimid argument - for (int j = 1; j < data_block->data_n; j++) + case 0: { // Ignore function dimid argument + for (int j = 1; j < data_block->data_n; j++) { if (dp[j] < min) { min = dp[j]; } + } dp[0] = min; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->data_n = 1; break; } @@ -697,7 +742,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } dp[0] = min; - dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size + dp = (float*)realloc((void*)dp, sizeof(float)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -757,13 +802,14 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* auto dp = (double*)data_block->data; double min = dp[0]; switch (data_block->rank) { - case 0: { // Ignore function dimid argument - for (int j = 1; j < data_block->data_n; j++) + case 0: { // Ignore function dimid argument + for (int j = 1; j < data_block->data_n; j++) { if (dp[j] < min) { min = dp[j]; } + } dp[0] = min; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->data_n = 1; break; } @@ -775,7 +821,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } dp[0] = min; - dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size + dp = (double*)realloc((void*)dp, sizeof(double)); // Reduce array size data_block->rank = 0; data_block->data_n = 1; free(data_block->dims[0].dim); @@ -836,10 +882,10 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - if (STR_IEQUALS(subset.function, "maximum")) { // Single scalar result + if (STR_IEQUALS(subset.function, "maximum")) { // Single scalar result } - if (!strncasecmp(subset.function, "count", 5)) { // Single scalar result + if (!strncasecmp(subset.function, "count", 5)) { // Single scalar result char* p1 = strstr(subset.function, "dimid"); auto count = (unsigned int*)malloc(sizeof(unsigned int)); if (p1 == nullptr) { @@ -852,7 +898,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } else { dimid = 0; if (data_block->rank >= 1) { - char* p3, * p2 = strchr(p1, '='); + char *p3, *p2 = strchr(p1, '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -863,20 +909,38 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } if (dimid < (int)data_block->rank) { - count[0] = (unsigned int)data_block->dims[dimid].dim_n; // Preserve this value + count[0] = (unsigned int)data_block->dims[dimid].dim_n; // Preserve this value DIMS ddim = data_block->dims[dimid]; - if (ddim.dim != nullptr) free(ddim.dim); - if (ddim.errhi != nullptr) free(ddim.errhi); - if (ddim.errlo != nullptr) free(ddim.errlo); - if (ddim.sams != nullptr) free(ddim.sams); - if (ddim.offs != nullptr) free(ddim.offs); - if (ddim.ints != nullptr) free(ddim.ints); + if (ddim.dim != nullptr) { + free(ddim.dim); + } + if (ddim.errhi != nullptr) { + free(ddim.errhi); + } + if (ddim.errlo != nullptr) { + free(ddim.errlo); + } + if (ddim.sams != nullptr) { + free(ddim.sams); + } + if (ddim.offs != nullptr) { + free(ddim.offs); + } + if (ddim.ints != nullptr) { + free(ddim.ints); + } } else { // ERROR } - if (data_block->data != nullptr) free(data_block->data); - if (data_block->errhi != nullptr) free(data_block->errhi); - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->data != nullptr) { + free(data_block->data); + } + if (data_block->errhi != nullptr) { + free(data_block->errhi); + } + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->data = nullptr; data_block->errhi = nullptr; data_block->errlo = nullptr; @@ -886,7 +950,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* data_block->data_n = 1; for (unsigned int j = 0; j < data_block->rank - 1; j++) { if (j >= (unsigned int)dimid) { - data_block->dims[j] = data_block->dims[j + 1]; // skip over the target + data_block->dims[j] = data_block->dims[j + 1]; // skip over the target } data_block->data_n = data_block->data_n * data_block->dims[j].dim_n; } @@ -903,7 +967,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - if (!strncasecmp(subset.function, "abs()", 5)) { // Absolute value + if (!strncasecmp(subset.function, "abs()", 5)) { // Absolute value switch (data_block->data_type) { case UDA_TYPE_FLOAT: { auto dp = (float*)data_block->data; @@ -924,15 +988,15 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - if (!strncasecmp(subset.function, "const", 5)) { // Constant value substitution - double value = 0.0; // Zero data default + if (!strncasecmp(subset.function, "const", 5)) { // Constant value substitution + double value = 0.0; // Zero data default char* p1 = strstr(subset.function, "value"); strcpy(data_block->data_label, subset.function); UDA_LOG(UDA_LOG_DEBUG, "%s\n", subset.function); if (p1 != nullptr) { - char* p3, * p2 = strchr(&p1[5], '='); + char *p3, *p2 = strchr(&p1[5], '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -949,8 +1013,12 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* UDA_LOG(UDA_LOG_DEBUG, "value = %f\n", value); - if (data_block->errhi != nullptr) free(data_block->errhi); - if (data_block->errlo != nullptr) free(data_block->errlo); + if (data_block->errhi != nullptr) { + free(data_block->errhi); + } + if (data_block->errlo != nullptr) { + free(data_block->errlo); + } data_block->errhi = nullptr; data_block->errlo = nullptr; data_block->error_type = UDA_TYPE_UNKNOWN; @@ -978,11 +1046,11 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* } } - if (!strncasecmp(subset.function, "order", 5)) { // Identify the Time dimension order + if (!strncasecmp(subset.function, "order", 5)) { // Identify the Time dimension order char* p1 = strstr(subset.function, "dimid"); UDA_LOG(UDA_LOG_DEBUG, "%s\n", subset.function); if (p1 != nullptr) { - char* p3, * p2 = strchr(&p1[5], '='); + char *p3, *p2 = strchr(&p1[5], '='); p2[0] = ' '; p3 = strchr(p2, ')'); p3[0] = '\0'; @@ -998,7 +1066,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* UDA_LOG(UDA_LOG_DEBUG, "order = %d\n", data_block->order); } - if (!strncasecmp(subset.function, "rotateRZ", 8)) { // Rotate R,Z coordinates in rank 3 array + if (!strncasecmp(subset.function, "rotateRZ", 8)) { // Rotate R,Z coordinates in rank 3 array UDA_LOG(UDA_LOG_DEBUG, "%s\n", subset.function); if (data_block->rank != 3) { UDA_THROW_ERROR(999, "The function rotateRZ only operates on rank 3 arrays"); @@ -1016,7 +1084,7 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* auto newData = (double*)malloc(count * sizeof(double)); unsigned int offset = 0; auto old = (double*)data_block->data; - if (order == 0) { // array[nz][nr][nt] -> [nr][nz][nt] + if (order == 0) { // array[nz][nr][nt] -> [nr][nz][nt] nt = data_block->dims[0].dim_n; nr = data_block->dims[1].dim_n; nz = data_block->dims[2].dim_n; @@ -1026,16 +1094,23 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* data[j] = (double**)malloc(nr * sizeof(double*)); for (int i = 0; i < nr; i++) { data[j][i] = (double*)malloc(nt * sizeof(double)); - for (int k = 0; k < nt; k++)data[j][i][k] = old[offset++]; + for (int k = 0; k < nt; k++) { + data[j][i][k] = old[offset++]; + } } } offset = 0; - for (int i = 0; i < nr; i++) - for (int j = 0; j < nz; j++) - for (int k = 0; k < nt; k++) + for (int i = 0; i < nr; i++) { + for (int j = 0; j < nz; j++) { + for (int k = 0; k < nt; k++) { newData[offset++] = data[j][i][k]; + } + } + } for (int j = 0; j < nz; j++) { - for (int i = 0; i < nr; i++) free(data[j][i]); + for (int i = 0; i < nr; i++) { + free(data[j][i]); + } free(data[j]); } free(data); @@ -1044,9 +1119,10 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* DIMS d2 = data_block->dims[2]; data_block->dims[1] = d2; data_block->dims[2] = d1; - } else if (order == 1) { // array[nz][nt][nr] - UDA_THROW_ERROR(999, "The function rotateRZ only operates on arrays with shape [nz][nr][nt] or [nt][nz][nr]"); - } else if (order == 2) { // array[nt][nz][nr] -> [nt][nr][nz] + } else if (order == 1) { // array[nz][nt][nr] + UDA_THROW_ERROR( + 999, "The function rotateRZ only operates on arrays with shape [nz][nr][nt] or [nt][nz][nr]"); + } else if (order == 2) { // array[nt][nz][nr] -> [nt][nr][nz] nr = data_block->dims[0].dim_n; nz = data_block->dims[1].dim_n; nt = data_block->dims[2].dim_n; @@ -1056,16 +1132,23 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* data[k] = (double**)malloc(nz * sizeof(double*)); for (int j = 0; j < nz; j++) { data[k][j] = (double*)malloc(nr * sizeof(double)); - for (int i = 0; i < nr; i++)data[k][j][i] = old[offset++]; + for (int i = 0; i < nr; i++) { + data[k][j][i] = old[offset++]; + } } } offset = 0; - for (int k = 0; k < nt; k++) - for (int i = 0; i < nr; i++) - for (int j = 0; j < nz; j++) + for (int k = 0; k < nt; k++) { + for (int i = 0; i < nr; i++) { + for (int j = 0; j < nz; j++) { newData[offset++] = data[k][j][i]; + } + } + } for (int k = 0; k < nt; k++) { - for (int j = 0; j < nz; j++)free(data[k][j]); + for (int j = 0; j < nz; j++) { + free(data[k][j]); + } free(data[k]); } free(data); @@ -1079,20 +1162,18 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* free(data_block->data); data_block->data = (char*)newData; } - } //------------------------------------------------------------------------------------------------------------- // Explicitly set the order of the time dimension if not possible via the other options - if (subset.order >= 0) data_block->order = subset.order; + if (subset.order >= 0) { + data_block->order = subset.order; + } return ierr; } - - - //------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------- // Build an Action Structure for Serverside Data Operations @@ -1107,13 +1188,13 @@ int uda::serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* // SS::SUBSET(\"xx\", [*, 3], member=\"name\", reform) // SS::SUBSET(\"xx\", [*, 3], member=\"name\", reform, function=\"minimum(dimid=0)\" ) - int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, Environment* environment) { char qchar[2]; - char* p = nullptr, * t1 = nullptr, * t2 = nullptr; - char api_delim[3] = "::"; // ********** TO DO: This should be an Environment Variable compatible with the Client delimiter + char *p = nullptr, *t1 = nullptr, *t2 = nullptr; + char api_delim[3] = + "::"; // ********** TO DO: This should be an Environment Variable compatible with the Client delimiter char archive[STRING_LENGTH] = ""; char signal[STRING_LENGTH] = ""; char options[STRING_LENGTH] = ""; @@ -1140,8 +1221,10 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser UDA_THROW_ERROR(9999, "Syntax Error: The Signal Name has no Terminating Quotation character!"); } - lsignal = (int)(p - request_block->signal) - 8; // Signal name Length - if (lsignal >= STRING_LENGTH) lsignal = STRING_LENGTH - 1; + lsignal = (int)(p - request_block->signal) - 8; // Signal name Length + if (lsignal >= STRING_LENGTH) { + lsignal = STRING_LENGTH - 1; + } strncpy(signal, request_block->signal + 8, lsignal); signal[lsignal] = '\0'; @@ -1170,7 +1253,7 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser UDA_THROW_ERROR(9999, "Syntax Error: No ] enclosing the Operation "); } - strncpy(operation, t1 + 1, t2 - t1 - 1); // The Requested Operation including Values + strncpy(operation, t1 + 1, t2 - t1 - 1); // The Requested Operation including Values operation[t2 - t1 - 1] = '\0'; //------------------------------------------------------------------------------------------------------------- @@ -1220,47 +1303,55 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser // Seek specific options - if ((p = strstr(options, "reform")) != nullptr) { // Reduce rank + if ((p = strstr(options, "reform")) != nullptr) { // Reduce rank subsets[nsubsets - 1].reform = 1; } - if ((p = strstr(options, "member=")) != nullptr) { // Extract a Structure member + if ((p = strstr(options, "member=")) != nullptr) { // Extract a Structure member strcpy(subsets[nsubsets - 1].member, &p[7]); LeftTrimString(subsets[nsubsets - 1].member); if (subsets[nsubsets - 1].member[0] == '"') { subsets[nsubsets - 1].member[0] = ' '; LeftTrimString(subsets[nsubsets - 1].member); } - if ((p = strchr(subsets[nsubsets - 1].member, '"')) != nullptr) p[0] = '\0'; - if ((p = strchr(subsets[nsubsets - 1].member, ',')) != nullptr) p[0] = '\0'; + if ((p = strchr(subsets[nsubsets - 1].member, '"')) != nullptr) { + p[0] = '\0'; + } + if ((p = strchr(subsets[nsubsets - 1].member, ',')) != nullptr) { + p[0] = '\0'; + } } // Simple functions - if ((p = strstr(options, "function=")) != nullptr) { // Identify a function + if ((p = strstr(options, "function=")) != nullptr) { // Identify a function strcpy(subsets[nsubsets - 1].function, &p[9]); LeftTrimString(subsets[nsubsets - 1].function); if (subsets[nsubsets - 1].function[0] == '"') { subsets[nsubsets - 1].function[0] = ' '; LeftTrimString(subsets[nsubsets - 1].function); } - if ((p = strchr(subsets[nsubsets - 1].function, '"')) != nullptr) p[0] = '\0'; - if ((p = strchr(subsets[nsubsets - 1].function, ',')) != nullptr) p[0] = '\0'; + if ((p = strchr(subsets[nsubsets - 1].function, '"')) != nullptr) { + p[0] = '\0'; + } + if ((p = strchr(subsets[nsubsets - 1].function, ',')) != nullptr) { + p[0] = '\0'; + } } //------------------------------------------------------------------------------------------------------------- // Parse the Operation String for Value and Operation - LeftTrimString(TrimString(operation)); // Remove Leading white space + LeftTrimString(TrimString(operation)); // Remove Leading white space strcpy(opcopy, operation); nbound = 0; - if ((p = strtok(opcopy, ",")) != nullptr) { // Tokenise into Individual Operations on each Dimension - subsets[nsubsets - 1].dimid[nbound] = nbound; // Identify the Dimension to apply the operation on + if ((p = strtok(opcopy, ",")) != nullptr) { // Tokenise into Individual Operations on each Dimension + subsets[nsubsets - 1].dimid[nbound] = nbound; // Identify the Dimension to apply the operation on nbound++; if (strlen(p) < UDA_SXML_MAX_STRING) { strcpy(subsets[nsubsets - 1].operation[nbound - 1], p); - MidTrimString(subsets[nsubsets - 1].operation[nbound - 1]); // Remove internal white space + MidTrimString(subsets[nsubsets - 1].operation[nbound - 1]); // Remove internal white space } else { free(subsets); UDA_THROW_ERROR(9999, "Syntax Error: The Signal Operation String is too long"); @@ -1275,7 +1366,7 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser } if (strlen(p) < UDA_SXML_MAX_STRING) { strcpy(subsets[nsubsets - 1].operation[nbound - 1], p); - MidTrimString(subsets[nsubsets - 1].operation[nbound - 1]); // Remove white space + MidTrimString(subsets[nsubsets - 1].operation[nbound - 1]); // Remove white space } else { free(subsets); UDA_THROW_ERROR(9999, "Syntax Error: The Signal Operation String is too long"); @@ -1299,23 +1390,23 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser strcpy(opcopy, subsets[nsubsets - 1].operation[i]); - if ((p = strstr(opcopy, ":")) != nullptr) { // Integer Type Array Index Bounds + if ((p = strstr(opcopy, ":")) != nullptr) { // Integer Type Array Index Bounds t2 = p + 1; - opcopy[p - opcopy] = '\0'; // Split the Operation String into two components + opcopy[p - opcopy] = '\0'; // Split the Operation String into two components t1 = opcopy; subsets[nsubsets - 1].isindex[i] = true; - subsets[nsubsets - 1].ubindex[i] = { .init=true, .value=-1 }; - subsets[nsubsets - 1].lbindex[i] = { .init=true, .value=-1 }; + subsets[nsubsets - 1].ubindex[i] = {.init = true, .value = -1}; + subsets[nsubsets - 1].lbindex[i] = {.init = true, .value = -1}; if (t1[0] == '#') { - subsets[nsubsets - 1].lbindex[i] = { .init=true, .value=-1 }; - } // Reverse the data as # => Final array value + subsets[nsubsets - 1].lbindex[i] = {.init = true, .value = -1}; + } // Reverse the data as # => Final array value if (strlen(t1) > 0 && t1[0] != '*' && t1[0] != '#') { if (IsNumber(t1)) { // the Lower Index Value of the Bound - subsets[nsubsets - 1].lbindex[i] = { .init=true, .value=strtol(t1, &endp, 0) }; + subsets[nsubsets - 1].lbindex[i] = {.init = true, .value = strtol(t1, &endp, 0)}; if (*endp != '\0' || errno == EINVAL || errno == ERANGE) { free(subsets); UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Lower Index Bound"); @@ -1328,7 +1419,7 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser if (strlen(t2) > 0 && t2[0] != '*' && t2[0] != '#') { if (IsNumber(t2)) { // the Upper Index Value of the Bound - subsets[nsubsets - 1].ubindex[i] = { .init=true, .value=strtol(t2, &endp, 0) }; + subsets[nsubsets - 1].ubindex[i] = {.init = true, .value = strtol(t2, &endp, 0)}; if (*endp != '\0' || errno == EINVAL || errno == ERANGE) { free(subsets); UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Upper Index Bound"); @@ -1338,47 +1429,47 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Upper Index Bound"); } } - strcpy(subsets[nsubsets - 1].operation[i], ":"); // Define Simple Operation + strcpy(subsets[nsubsets - 1].operation[i], ":"); // Define Simple Operation continue; } - if ((p = strstr(opcopy, "*")) != nullptr) { // Ignore this Dimension + if ((p = strstr(opcopy, "*")) != nullptr) { // Ignore this Dimension subsets[nsubsets - 1].isindex[i] = true; - subsets[nsubsets - 1].ubindex[i] = { .init=true, .value=-1 }; - subsets[nsubsets - 1].lbindex[i] = { .init=true, .value=-1 }; - strcpy(subsets[nsubsets - 1].operation[i], "*"); // Define Simple Operation + subsets[nsubsets - 1].ubindex[i] = {.init = true, .value = -1}; + subsets[nsubsets - 1].lbindex[i] = {.init = true, .value = -1}; + strcpy(subsets[nsubsets - 1].operation[i], "*"); // Define Simple Operation continue; } - if ((p = strstr(opcopy, "#")) != nullptr) { // Last Value in Dimension + if ((p = strstr(opcopy, "#")) != nullptr) { // Last Value in Dimension subsets[nsubsets - 1].isindex[i] = true; - subsets[nsubsets - 1].ubindex[i] = { .init=true, .value=-1 }; - subsets[nsubsets - 1].lbindex[i] = { .init=true, .value=-1 }; - strcpy(subsets[nsubsets - 1].operation[i], "#"); // Define Simple Operation + subsets[nsubsets - 1].ubindex[i] = {.init = true, .value = -1}; + subsets[nsubsets - 1].lbindex[i] = {.init = true, .value = -1}; + strcpy(subsets[nsubsets - 1].operation[i], "#"); // Define Simple Operation continue; } - if (IsNumber(opcopy)) { // Single Index value + if (IsNumber(opcopy)) { // Single Index value subsets[nsubsets - 1].isindex[i] = true; // the Index Value of the Bound - subsets[nsubsets - 1].ubindex[i] = { .init=true, .value=strtol(opcopy, &endp, 0) }; + subsets[nsubsets - 1].ubindex[i] = {.init = true, .value = strtol(opcopy, &endp, 0)}; if (*endp != '\0' || errno == EINVAL || errno == ERANGE) { free(subsets); UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: Single Index Bound"); } subsets[nsubsets - 1].lbindex[i] = subsets[nsubsets - 1].ubindex[i]; - strcpy(subsets[nsubsets - 1].operation[i], ":"); // Define Simple Operation + strcpy(subsets[nsubsets - 1].operation[i], ":"); // Define Simple Operation continue; } // Single value Operation - p = nullptr; // Locate the Start of the Numerical Substring + p = nullptr; // Locate the Start of the Numerical Substring lop = (int)strlen(subsets[nsubsets - 1].operation[i]); for (int j = 0; j < lop; j++) { if (subsets[nsubsets - 1].operation[i][j] >= '0' && subsets[nsubsets - 1].operation[i][j] <= '9') { p = &subsets[nsubsets - 1].operation[i][j]; - if (j > 0) { // Capture sign + if (j > 0) { // Capture sign if (subsets[nsubsets - 1].operation[i][j - 1] == '+' || subsets[nsubsets - 1].operation[i][j - 1] == '-') { p = &subsets[nsubsets - 1].operation[i][j - 1]; @@ -1396,7 +1487,7 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser UDA_THROW_ERROR(9999, "Server Side Operation Syntax Error: No Numerical Bound"); } - subsets[nsubsets - 1].bound[i] = strtod(p, &endp); // the Value of the Bound + subsets[nsubsets - 1].bound[i] = strtod(p, &endp); // the Value of the Bound if (*endp != '\0' || errno == EINVAL || errno == ERANGE) { free(subsets); @@ -1416,11 +1507,11 @@ int uda::serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_ser return ierr; } - //---------------------------------------------------------------------------------------------------------------------- // Identify the Index Range satisfying a small set of conditional operators -namespace { +namespace +{ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* subsetindices) { @@ -1433,18 +1524,23 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* case UDA_TYPE_DOUBLE: { auto p = (double*)dim->dim; if (STR_IEQUALS(operation, "eq") || operation[0] == '=' || STR_EQUALS(operation, "~=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] == (double)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] == (double)value) { + subsetindices[count++] = k; + } + } if (count == 0 && STR_EQUALS(operation, "~=")) { - for (int k = 0; k < dim->dim_n; k++) + for (int k = 0; k < dim->dim_n; k++) { if (fabs(p[k] - (double)value) <= DBL_EPSILON) { subsetindices[count++] = k; } + } if (count == 0) { int index = -1; double delta, minvalue = fabs((double)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabs((double)value - p[k]); - if (delta < minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1453,15 +1549,16 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* count = 1; subsetindices[0] = index; - if (index == 0 || - index == dim->dim_n - 1) { // Check not an end point by default + if (index == 0 || index == dim->dim_n - 1) { // Check not an end point by default if (dim->dim_n > 1) { if (index == 0) { delta = fabs(p[1] - p[0]); } else { delta = fabs(p[dim->dim_n - 1] - p[dim->dim_n - 2]); } - if (fabs((double)value - p[index]) > delta) count = 0; // Suspect match! + if (fabs((double)value - p[index]) > delta) { + count = 0; // Suspect match! + } } } } @@ -1469,31 +1566,47 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* } } else { if (STR_IEQUALS(operation, "lt") || STR_EQUALS(operation, "<")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] < (double)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] < (double)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "gt") || STR_EQUALS(operation, ">")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] > (double)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] > (double)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "le") || STR_EQUALS(operation, "<=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] <= (double)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] <= (double)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ge") || STR_EQUALS(operation, ">=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] >= (double)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] >= (double)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ne") || STR_EQUALS(operation, "!=") || STR_EQUALS(operation, "!~=")) { if (strncmp(operation, "!~=", 3) != 0) { - for (int k = 0; k < dim->dim_n; k++) + for (int k = 0; k < dim->dim_n; k++) { if (p[k] != (double)value) { subsetindices[count++] = k; } + } } else { int index = -1; double delta, minvalue = fabs((double)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabs((double)value - p[k]); - if (delta < - minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1502,10 +1615,10 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* for (int k = 0; k < dim->dim_n; k++) { if (k != index) { subsetindices[count++] = k; - } // Drop the single nearest value + } // Drop the single nearest value } - if (index == 0 || index == dim->dim_n - - 1) { // Check not an end point by default + if (index == 0 || + index == dim->dim_n - 1) { // Check not an end point by default if (dim->dim_n > 1) { if (index == 0) { delta = fabs(p[1] - p[0]); @@ -1514,7 +1627,7 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* } if (fabs((double)value - p[index]) > delta) { count = 0; - } // Suspect match! + } // Suspect match! } } } @@ -1531,18 +1644,23 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* case UDA_TYPE_FLOAT: { auto p = (float*)dim->dim; if (STR_IEQUALS(operation, "eq") || operation[0] == '=' || STR_EQUALS(operation, "~=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] == (float)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] == (float)value) { + subsetindices[count++] = k; + } + } if (count == 0 && STR_EQUALS(operation, "~=")) { - for (int k = 0; k < dim->dim_n; k++) + for (int k = 0; k < dim->dim_n; k++) { if (fabsf(p[k] - (float)value) <= FLT_EPSILON) { subsetindices[count++] = k; } + } if (count == 0) { int index = -1; double delta, minvalue = fabsf((float)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabsf((float)value - p[k]); - if (delta < minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1551,15 +1669,16 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* count = 1; subsetindices[0] = index; - if (index == 0 || - index == dim->dim_n - 1) { // Check not an end point by default + if (index == 0 || index == dim->dim_n - 1) { // Check not an end point by default if (dim->dim_n > 1) { if (index == 0) { delta = fabsf(p[1] - p[0]); } else { delta = fabsf(p[dim->dim_n - 1] - p[dim->dim_n - 2]); } - if (fabsf((float)value - p[index]) > delta) count = 0; // Suspect match! + if (fabsf((float)value - p[index]) > delta) { + count = 0; // Suspect match! + } } } } @@ -1567,31 +1686,47 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* } } else { if (STR_IEQUALS(operation, "lt") || STR_EQUALS(operation, "<")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] < (float)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] < (float)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "gt") || STR_EQUALS(operation, ">")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] > (float)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] > (float)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "le") || STR_EQUALS(operation, "<=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] <= (float)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] <= (float)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ge") || STR_EQUALS(operation, ">=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] >= (float)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] >= (float)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ne") || STR_EQUALS(operation, "!=") || STR_EQUALS(operation, "!~=")) { if (strncmp(operation, "!~=", 3) != 0) { - for (int k = 0; k < dim->dim_n; k++) + for (int k = 0; k < dim->dim_n; k++) { if (p[k] != (float)value) { subsetindices[count++] = k; } + } } else { int index = -1; double delta, minvalue = fabsf((float)value - p[0]); for (int k = 0; k < dim->dim_n; k++) { delta = fabsf((float)value - p[k]); - if (delta < - minvalue) { // Look for the Single Nearest Value + if (delta < minvalue) { // Look for the Single Nearest Value minvalue = delta; index = k; } @@ -1600,10 +1735,10 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* for (int k = 0; k < dim->dim_n; k++) { if (k != index) { subsetindices[count++] = k; - } // Drop the single nearest value + } // Drop the single nearest value } - if (index == 0 || index == dim->dim_n - - 1) { // Check not an end point by default + if (index == 0 || + index == dim->dim_n - 1) { // Check not an end point by default if (dim->dim_n > 1) { if (index == 0) { delta = fabsf(p[1] - p[0]); @@ -1612,7 +1747,7 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* } if (fabsf((float)value - p[index]) > delta) { count = 0; - } // Suspect match! + } // Suspect match! } } } @@ -1629,26 +1764,47 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* case UDA_TYPE_INT: { int* p = (int*)dim->dim; if (STR_IEQUALS(operation, "eq") || operation[0] == '=' || STR_EQUALS(operation, "~=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] == (int)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] == (int)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "lt") || STR_EQUALS(operation, "<")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] < (int)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] < (int)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "gt") || STR_EQUALS(operation, ">")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] > (int)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] > (int)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "le") || STR_EQUALS(operation, "<=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] <= (int)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] <= (int)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ge") || STR_EQUALS(operation, ">=")) { - for (int k = 0; k < dim->dim_n; k++) if (p[k] >= (int)value) subsetindices[count++] = k; + for (int k = 0; k < dim->dim_n; k++) { + if (p[k] >= (int)value) { + subsetindices[count++] = k; + } + } } else { if (STR_IEQUALS(operation, "ne") || STR_EQUALS(operation, "!=") || STR_EQUALS(operation, "!~=")) { - for (int k = 0; k < dim->dim_n; k++) + for (int k = 0; k < dim->dim_n; k++) { if (p[k] != (int)value) { subsetindices[count++] = k; } + } } } } @@ -1657,17 +1813,13 @@ int serverSubsetIndices(char* operation, DIMS* dim, double value, unsigned int* } break; } - - } return count; } - -int serverNewDataArray2(DIMS* dims, int rank, int dimid, - char* data, int ndata, int data_type, int notoperation, int reverse, - int start, int end, int start1, int end1, int* n, void** newdata) +int serverNewDataArray2(DIMS* dims, int rank, int dimid, char* data, int ndata, int data_type, int notoperation, + int reverse, int start, int end, int start1, int end1, int* n, void** newdata) { int ierr = 0, rows, columns, newrows, newcols, count = 0; @@ -1680,8 +1832,8 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case UDA_TYPE_FLOAT: { - float* p, * dp; - float** pa, ** dpa; + float *p, *dp; + float **pa, **dpa; // Allocate heap for the reshaped array @@ -1689,7 +1841,7 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, UDA_THROW_ERROR(9999, "Unable to Allocate Heap memory"); } - dp = (float*)data; // the Originating Data Array + dp = (float*)data; // the Originating Data Array // Reshape @@ -1697,11 +1849,23 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case 1: { int k = 0; if (!reverse) { - for (int i = start; i <= end; i++) p[k++] = dp[i]; - if (notoperation) for (int i = start1; i <= end1; i++) p[k++] = dp[i]; + for (int i = start; i <= end; i++) { + p[k++] = dp[i]; + } + if (notoperation) { + for (int i = start1; i <= end1; i++) { + p[k++] = dp[i]; + } + } } else { - if (notoperation) for (int i = end1; i >= start1; i--) p[k++] = dp[i]; - for (int i = end; i >= start; i--) p[k++] = dp[i]; + if (notoperation) { + for (int i = end1; i >= start1; i--) { + p[k++] = dp[i]; + } + } + for (int i = end; i >= start; i--) { + p[k++] = dp[i]; + } } *n = k; *newdata = (void*)p; @@ -1715,21 +1879,29 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, rows = dims[1].dim_n; columns = dims[0].dim_n; dpa = (float**)malloc(rows * sizeof(float*)); - for (int j = 0; j < rows; j++) dpa[j] = &dp[j * columns]; + for (int j = 0; j < rows; j++) { + dpa[j] = &dp[j * columns]; + } // Array for Reshaped Data if (dimid == 0) { newrows = dims[1].dim_n; newcols = end - start + 1; - if (notoperation) newcols = newcols + end1 - start1 + 1; + if (notoperation) { + newcols = newcols + end1 - start1 + 1; + } } else { newcols = dims[0].dim_n; newrows = end - start + 1; - if (notoperation) newrows = newrows + end1 - start1 + 1; + if (notoperation) { + newrows = newrows + end1 - start1 + 1; + } } pa = (float**)malloc(newrows * sizeof(float*)); - for (int j = 0; j < newrows; j++) pa[j] = &p[j * newcols]; + for (int j = 0; j < newrows; j++) { + pa[j] = &p[j * newcols]; + } // Reshape the Data @@ -1808,8 +1980,8 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case UDA_TYPE_DOUBLE: { - double* p, * dp; - double** pa, ** dpa; + double *p, *dp; + double **pa, **dpa; // Allocate heap for the reshaped array @@ -1817,7 +1989,7 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, UDA_THROW_ERROR(9999, "Unable to Allocate Heap memory"); } - dp = (double*)data; // the Originating Data Array + dp = (double*)data; // the Originating Data Array // Reshape @@ -1825,11 +1997,23 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case 1: { int k = 0; if (!reverse) { - for (int i = start; i <= end; i++) p[k++] = dp[i]; - if (notoperation) for (int i = start1; i <= end1; i++) p[k++] = dp[i]; + for (int i = start; i <= end; i++) { + p[k++] = dp[i]; + } + if (notoperation) { + for (int i = start1; i <= end1; i++) { + p[k++] = dp[i]; + } + } } else { - if (notoperation) for (int i = end1; i >= start1; i--) p[k++] = dp[i]; - for (int i = end; i >= start; i--) p[k++] = dp[i]; + if (notoperation) { + for (int i = end1; i >= start1; i--) { + p[k++] = dp[i]; + } + } + for (int i = end; i >= start; i--) { + p[k++] = dp[i]; + } } *n = k; *newdata = (void*)p; @@ -1843,21 +2027,29 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, rows = dims[1].dim_n; columns = dims[0].dim_n; dpa = (double**)malloc(rows * sizeof(double*)); - for (int j = 0; j < rows; j++) dpa[j] = &dp[j * columns]; + for (int j = 0; j < rows; j++) { + dpa[j] = &dp[j * columns]; + } // Array for Reshaped Data if (dimid == 0) { newrows = dims[1].dim_n; newcols = end - start + 1; - if (notoperation) newcols = newcols + end1 - start1 + 1; + if (notoperation) { + newcols = newcols + end1 - start1 + 1; + } } else { newcols = dims[0].dim_n; newrows = end - start + 1; - if (notoperation) newrows = newrows + end1 - start1 + 1; + if (notoperation) { + newrows = newrows + end1 - start1 + 1; + } } pa = (double**)malloc(newrows * sizeof(double*)); - for (int j = 0; j < newrows; j++) pa[j] = &p[j * newcols]; + for (int j = 0; j < newrows; j++) { + pa[j] = &p[j * newcols]; + } // Reshape the Data @@ -1936,8 +2128,8 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case UDA_TYPE_INT: { - int* p, * dp; - int** pa, ** dpa; + int *p, *dp; + int **pa, **dpa; // Allocate heap for the reshaped array @@ -1945,7 +2137,7 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, UDA_THROW_ERROR(9999, "Unable to Allocate Heap memory"); } - dp = (int*)data; // the Originating Data Array + dp = (int*)data; // the Originating Data Array // Reshape @@ -1953,11 +2145,23 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, case 1: { int k = 0; if (!reverse) { - for (int i = start; i <= end; i++) p[k++] = dp[i]; - if (notoperation) for (int i = start1; i <= end1; i++) p[k++] = dp[i]; + for (int i = start; i <= end; i++) { + p[k++] = dp[i]; + } + if (notoperation) { + for (int i = start1; i <= end1; i++) { + p[k++] = dp[i]; + } + } } else { - if (notoperation) for (int i = end1; i >= start1; i--) p[k++] = dp[i]; - for (int i = end; i >= start; i--) p[k++] = dp[i]; + if (notoperation) { + for (int i = end1; i >= start1; i--) { + p[k++] = dp[i]; + } + } + for (int i = end; i >= start; i--) { + p[k++] = dp[i]; + } } *n = k; *newdata = (void*)p; @@ -1971,21 +2175,29 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, rows = dims[1].dim_n; columns = dims[0].dim_n; dpa = (int**)malloc(rows * sizeof(int*)); - for (int j = 0; j < rows; j++) dpa[j] = &dp[j * columns]; + for (int j = 0; j < rows; j++) { + dpa[j] = &dp[j * columns]; + } // Array for Reshaped Data if (dimid == 0) { newrows = dims[1].dim_n; newcols = end - start + 1; - if (notoperation) newcols = newcols + end1 - start1 + 1; + if (notoperation) { + newcols = newcols + end1 - start1 + 1; + } } else { newcols = dims[0].dim_n; newrows = end - start + 1; - if (notoperation) newrows = newrows + end1 - start1 + 1; + if (notoperation) { + newrows = newrows + end1 - start1 + 1; + } } pa = (int**)malloc(newrows * sizeof(int*)); - for (int j = 0; j < newrows; j++) pa[j] = &p[j * newcols]; + for (int j = 0; j < newrows; j++) { + pa[j] = &p[j * newcols]; + } // Reshape the Data @@ -2063,12 +2275,14 @@ int serverNewDataArray2(DIMS* dims, int rank, int dimid, } default: - UDA_LOG(UDA_LOG_ERROR, "Only Float, Double and 32 bit Signed Integer Numerical Types can be Subset at this time!\n"); + UDA_LOG(UDA_LOG_ERROR, + "Only Float, Double and 32 bit Signed Integer Numerical Types can be Subset at this time!\n"); UDA_LOG(UDA_LOG_ERROR, "Data Type: %d Rank: %d\n", data_type, rank); - UDA_THROW_ERROR(9999, "Only Float, Double and 32 bit Signed Integer Numerical Types can be Subset at this time!"); + UDA_THROW_ERROR(9999, + "Only Float, Double and 32 bit Signed Integer Numerical Types can be Subset at this time!"); } return ierr; } -} // anon namespace \ No newline at end of file +} // namespace \ No newline at end of file diff --git a/source/server2/server_subset_data.h b/source/server2/server_subset_data.h old mode 100755 new mode 100644 index c059c271..12c004a8 --- a/source/server2/server_subset_data.h +++ b/source/server2/server_subset_data.h @@ -1,19 +1,20 @@ #pragma once #ifndef UDA_SERVER_SERVERSUBSETDATA_H -#define UDA_SERVER_SERVERSUBSETDATA_H +# define UDA_SERVER_SERVERSUBSETDATA_H -#include -#include "udaStructs.h" -#include "genStructs.h" -#include "export.h" +# include "export.h" +# include "genStructs.h" +# include "udaStructs.h" +# include -namespace uda { +namespace uda +{ int serverSubsetData(DATA_BLOCK* data_block, ACTION action, LOGMALLOCLIST* logmalloclist); int serverParseServerSide(REQUEST_DATA* request_block, ACTIONS* actions_serverside, Environment* environment); -} +} // namespace uda #endif // UDA_SERVER_SERVERSUBSETDATA_H diff --git a/source/server2/xdr_protocol.cpp b/source/server2/xdr_protocol.cpp index e27d9c9d..083e0e3f 100644 --- a/source/server2/xdr_protocol.cpp +++ b/source/server2/xdr_protocol.cpp @@ -1,11 +1,11 @@ #include "xdr_protocol.hpp" +#include "clientserver/errorLog.h" #include "clientserver/printStructs.h" -#include "clientserver/xdrlib.h" #include "clientserver/protocol.h" -#include "clientserver/errorLog.h" +#include "clientserver/xdrlib.h" +#include "struct.h" #include "udaErrors.h" #include "udaTypes.h" -#include "struct.h" #ifdef SSLAUTHENTICATION # include "authentication/udaServerSSL.h" #endif @@ -13,8 +13,8 @@ #include #include -#include #include "udaDefines.h" +#include #include "server.hpp" @@ -38,9 +38,9 @@ int serverSocket = 0; void setSelectParms(int fd, fd_set* rfds, struct timeval* tv, int* server_tot_block_time) { FD_ZERO(rfds); // Initialise the File Descriptor set - FD_SET(fd, rfds); // Identify the Socket in the FD set + FD_SET(fd, rfds); // Identify the Socket in the FD set tv->tv_sec = 0; - tv->tv_usec = MinBlockTime; // minimum wait microsecs (1ms) + tv->tv_usec = MinBlockTime; // minimum wait microsecs (1ms) *server_tot_block_time = 0; } @@ -51,17 +51,17 @@ void updateSelectParms(int fd, fd_set* rfds, struct timeval* tv, int server_tot_ if (server_tot_block_time < MAXBLOCK) { // (ms) For the First blocking period have rapid response (clientserver/udaDefines.h == 1000) tv->tv_sec = 0; - tv->tv_usec = MinBlockTime; // minimum wait (1ms) + tv->tv_usec = MinBlockTime; // minimum wait (1ms) } else { tv->tv_sec = 0; - tv->tv_usec = MaxBlockTime; // maximum wait (10ms) + tv->tv_usec = MaxBlockTime; // maximum wait (10ms) } } int server_read(void* iohandle, char* buf, int count) { int rc = 0; - fd_set rfds; // File Descriptor Set for Reading from the Socket + fd_set rfds; // File Descriptor Set for Reading from the Socket timeval tv = {}; timeval tvc = {}; @@ -75,11 +75,12 @@ int server_read(void* iohandle, char* buf, int count) while (select(serverSocket + 1, &rfds, nullptr, nullptr, &tvc) <= 0) { *io_data->server_tot_block_time += (int)tv.tv_usec / 1000; if (*io_data->server_tot_block_time > 1000 * *io_data->server_timeout) { - UDA_LOG(UDA_LOG_DEBUG, "Total Wait Time Exceeds Lifetime Limit = %d (ms)\n", *io_data->server_timeout * 1000); + UDA_LOG(UDA_LOG_DEBUG, "Total Wait Time Exceeds Lifetime Limit = %d (ms)\n", + *io_data->server_timeout * 1000); return -1; } - updateSelectParms(serverSocket, &rfds, &tv, *io_data->server_tot_block_time); // Keep trying ... + updateSelectParms(serverSocket, &rfds, &tv, *io_data->server_tot_block_time); // Keep trying ... tvc = tv; } @@ -105,7 +106,7 @@ int server_write(void* iohandle, char* buf, int count) int rc = 0; int BytesSent = 0; - fd_set wfds; // File Descriptor Set for Writing to the Socket + fd_set wfds; // File Descriptor Set for Writing to the Socket timeval tv = {}; auto io_data = reinterpret_cast(iohandle); @@ -140,11 +141,7 @@ void uda::XdrProtocol::create() } uda::XdrProtocol::XdrProtocol() - : server_input_{} - , server_output_{} - , server_tot_block_time_{0} - , server_timeout_{TIMEOUT} - , io_data_{} + : server_input_{}, server_output_{}, server_tot_block_time_{0}, server_timeout_{TIMEOUT}, io_data_{} { io_data_.server_tot_block_time = &server_tot_block_time_; io_data_.server_timeout = &server_timeout_; @@ -157,45 +154,45 @@ void uda::XdrProtocol::create_streams() #if defined(SSLAUTHENTICATION) if (getUdaServerSSLDisabled()) { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create( &server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); - - xdrrec_create( &server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#else - xdrrec_create( &server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); - - xdrrec_create( &server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); + + xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# else + xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); + + xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# endif } else { -#if defined (__APPLE__) || defined(__TIRPC__) - xdrrec_create( &server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); - - xdrrec_create( &server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); -#else - xdrrec_create( &server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); - - xdrrec_create( &server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(readUdaServerSSL), - reinterpret_cast(writeUdaServerSSL)); -#endif +# if defined(__APPLE__) || defined(__TIRPC__) + xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); + + xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); +# else + xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); + + xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, + reinterpret_cast(readUdaServerSSL), + reinterpret_cast(writeUdaServerSSL)); +# endif } #else // SSLAUTHENTICATION -#if defined (__APPLE__) || defined(__TIRPC__) +# if defined(__APPLE__) || defined(__TIRPC__) xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, reinterpret_cast(server_read), reinterpret_cast(server_write)); @@ -203,15 +200,15 @@ void uda::XdrProtocol::create_streams() xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, &io_data_, reinterpret_cast(server_read), reinterpret_cast(server_write)); -#else +# else xdrrec_create(&server_output_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); + reinterpret_cast(server_read), + reinterpret_cast(server_write)); xdrrec_create(&server_input_, DB_READ_BLOCK_SIZE, DB_WRITE_BLOCK_SIZE, (char*)&io_data_, - reinterpret_cast(server_read), - reinterpret_cast(server_write)); -#endif + reinterpret_cast(server_read), + reinterpret_cast(server_write)); +# endif #endif // SSLAUTHENTICATION @@ -234,11 +231,10 @@ int uda::XdrProtocol::read_client_block(ClientBlock* client_block, LogMallocList addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error (Client Block)"); } else { - int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block + int protocol_id = UDA_PROTOCOL_CLIENT_BLOCK; // Recieve Client Block if ((err = protocol2(&server_input_, protocol_id, XDR_RECEIVE, nullptr, log_malloc_list, user_defined_type_list, - client_block, protocol_version_, &log_struct_list_, 0, - malloc_source_)) != 0) { + client_block, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 10 Error (Client Block)"); UDA_LOG(UDA_LOG_DEBUG, "protocol error! Client Block not received!\n"); } @@ -249,8 +245,6 @@ int uda::XdrProtocol::read_client_block(ClientBlock* client_block, LogMallocList } // Test for an immediate CLOSEDOWN instruction - - } return err; @@ -262,7 +256,7 @@ int uda::XdrProtocol::send_server_block(SERVER_BLOCK server_block, LogMallocList UDA_LOG(UDA_LOG_DEBUG, "Sending Server Block\n"); printServerBlock(server_block); - int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement + int protocol_id = UDA_PROTOCOL_SERVER_BLOCK; // Receive Server Block: Server Aknowledgement int err; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, @@ -277,7 +271,7 @@ int uda::XdrProtocol::send_server_block(SERVER_BLOCK server_block, LogMallocList int uda::XdrProtocol::flush() { - if (!xdrrec_endofrecord(&server_output_, 1)) { // Send data now + if (!xdrrec_endofrecord(&server_output_, 1)) { // Send data now UDA_THROW_ERROR(UDA_PROTOCOL_ERROR_7, "Protocol 7 Error (Server Block)"); } @@ -294,8 +288,7 @@ int uda::XdrProtocol::send_meta_data(MetadataBlock& metadata_block, LogMallocLis int err = 0; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block.data_system, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + &metadata_block.data_system, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data System Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 4 Error"); return err; @@ -307,8 +300,8 @@ int uda::XdrProtocol::send_meta_data(MetadataBlock& metadata_block, LogMallocLis protocol_id = UDA_PROTOCOL_SYSTEM_CONFIG; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block.system_config, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + &metadata_block.system_config, protocol_version_, &log_struct_list_, 0, malloc_source_)) != + 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending System Configuration Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 5 Error"); return err; @@ -320,8 +313,7 @@ int uda::XdrProtocol::send_meta_data(MetadataBlock& metadata_block, LogMallocLis protocol_id = UDA_PROTOCOL_DATA_SOURCE; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block.data_source, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + &metadata_block.data_source, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data Source Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 6 Error"); return err; @@ -333,8 +325,7 @@ int uda::XdrProtocol::send_meta_data(MetadataBlock& metadata_block, LogMallocLis protocol_id = UDA_PROTOCOL_SIGNAL; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block.signal_rec, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + &metadata_block.signal_rec, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Signal Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 7 Error"); return err; @@ -346,8 +337,7 @@ int uda::XdrProtocol::send_meta_data(MetadataBlock& metadata_block, LogMallocLis protocol_id = UDA_PROTOCOL_SIGNAL_DESC; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - &metadata_block.signal_desc, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + &metadata_block.signal_desc, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Signal Description Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 8 Error"); return err; @@ -363,12 +353,12 @@ int uda::XdrProtocol::send_data_blocks(const std::vector& data_blocks DATA_BLOCK_LIST data_block_list = {}; data_block_list.count = static_cast(data_blocks.size()); - data_block_list.data = const_cast(data_blocks.data()); + data_block_list.data = const_cast(data_blocks.data()); int err = 0; if ((err = protocol2(&server_output_, UDA_PROTOCOL_DATA_BLOCK_LIST, XDR_SEND, nullptr, log_malloc_list, - user_defined_type_list, (void*)&data_block_list, protocol_version_, &log_struct_list_, - 0, malloc_source_)) != 0) { + user_defined_type_list, (void*)&data_block_list, protocol_version_, &log_struct_list_, 0, + malloc_source_)) != 0) { UDA_LOG(UDA_LOG_DEBUG, "Problem Sending Data Structure\n"); addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Protocol 2 Error"); return err; @@ -402,8 +392,7 @@ int uda::XdrProtocol::send_hierachical_data(const DataBlock& data_block, LogMall int err = 0; if ((err = protocol2(&server_output_, protocol_id, XDR_SEND, nullptr, log_malloc_list, user_defined_type_list, - (void*)&data_block, protocol_version_, &log_struct_list_, 0, - malloc_source_)) != 0) { + (void*)&data_block, protocol_version_, &log_struct_list_, 0, malloc_source_)) != 0) { addIdamError(UDA_CODE_ERROR_TYPE, __func__, err, "Server Side Protocol Error (Opaque Structure Type)"); return err; } @@ -415,8 +404,8 @@ int uda::XdrProtocol::send_hierachical_data(const DataBlock& data_block, LogMall } int uda::XdrProtocol::recv_client_block(SERVER_BLOCK& server_block, CLIENT_BLOCK* client_block, bool* fatal, - int server_tot_block_time, const int* server_timeout, LogMallocList* log_malloc_list, - UserDefinedTypeList* user_defined_type_list) + int server_tot_block_time, const int* server_timeout, + LogMallocList* log_malloc_list, UserDefinedTypeList* user_defined_type_list) { // Receive the Client Block, request block and putData block @@ -458,8 +447,8 @@ int uda::XdrProtocol::recv_request_block(REQUEST_BLOCK* request_block, LogMalloc { int err = 0; if ((err = protocol2(&server_input_, UDA_PROTOCOL_REQUEST_BLOCK, XDR_RECEIVE, nullptr, log_malloc_list, - user_defined_type_list, request_block, protocol_version_, &log_struct_list_, - private_flags_, malloc_source_)) != 0) { + user_defined_type_list, request_block, protocol_version_, &log_struct_list_, private_flags_, + malloc_source_)) != 0) { UDA_THROW_ERROR(err, "Protocol 1 Error (Receiving Client Request)"); } @@ -472,8 +461,8 @@ int uda::XdrProtocol::recv_putdata_block_list(PUTDATA_BLOCK_LIST* putdata_block_ { int err = 0; if ((err = protocol2(&server_input_, UDA_PROTOCOL_PUTDATA_BLOCK_LIST, XDR_RECEIVE, nullptr, log_malloc_list, - user_defined_type_list, putdata_block_list, protocol_version_, - &log_struct_list_, private_flags_, malloc_source_)) != 0) { + user_defined_type_list, putdata_block_list, protocol_version_, &log_struct_list_, + private_flags_, malloc_source_)) != 0) { UDA_THROW_ERROR(err, "Protocol 1 Error (Receiving Client putDataBlockList)"); } @@ -492,18 +481,17 @@ int uda::XdrProtocol::eof() } DATA_BLOCK* uda::XdrProtocol::read_from_cache(uda::cache::UdaCache* cache, RequestData* request, - server::Environment& environment, - LogMallocList* log_malloc_list, + server::Environment& environment, LogMallocList* log_malloc_list, UserDefinedTypeList* user_defined_type_list) { return cache_read(cache, request, log_malloc_list, user_defined_type_list, *environment.p_env(), protocol_version_, - CLIENTFLAG_CACHE, &log_struct_list_, private_flags_, malloc_source_); + CLIENTFLAG_CACHE, &log_struct_list_, private_flags_, malloc_source_); } -void uda::XdrProtocol::write_to_cache(uda::cache::UdaCache* cache, RequestData* request, server::Environment& environment, - DataBlock* data_block, LogMallocList* log_malloc_list, - UserDefinedTypeList* user_defined_type_list) +void uda::XdrProtocol::write_to_cache(uda::cache::UdaCache* cache, RequestData* request, + server::Environment& environment, DataBlock* data_block, + LogMallocList* log_malloc_list, UserDefinedTypeList* user_defined_type_list) { - cache_write(cache, request, data_block, log_malloc_list, user_defined_type_list, *environment.p_env(), 8, CLIENTFLAG_CACHE, - &log_struct_list_, private_flags_, malloc_source_); + cache_write(cache, request, data_block, log_malloc_list, user_defined_type_list, *environment.p_env(), 8, + CLIENTFLAG_CACHE, &log_struct_list_, private_flags_, malloc_source_); } diff --git a/source/structures/accessors.cpp b/source/structures/accessors.cpp old mode 100755 new mode 100644 index 9fa7f15a..ef2316e8 --- a/source/structures/accessors.cpp +++ b/source/structures/accessors.cpp @@ -6,14 +6,16 @@ // There are 6 node location methods: // The NTREE data structure can be identified either by its name, its user defined type name, its user defined class id, // or by the memory address of its data. -// It can also be identified by targeting the user defined type by a member name or a member type (user defined type only) +// It can also be identified by targeting the user defined type by a member name or a member type (user defined type +// only) // // Two types: // A) Return the Tree Node whose data structure type contains a named element or member. This may be // either a structure or an atomic typed element. // // B) Return the Tree Node containing a named Data Structure (node will be a child of the node located using A). -// The hierarchical name must consist only of structure types. Identifying data by type may fail as types are named uniquely: same 'type' but different type name! +// The hierarchical name must consist only of structure types. Identifying data by type may fail as types are named +// uniquely: same 'type' but different type name! // // Hierarchical names can have one of two forms: a.b.c or a/b/c. The latter can also begin with an optional '/'. // @@ -46,21 +48,22 @@ // #include "accessors.h" -#include -#include #include +#include +#include #include "struct.h" /** Find (search type A) the first Tree Node with a data structure type containing a named element/member. -* -* This is a private function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If nullptr the root node is assumed. -* @param target The name of the data structure's element/member (case sensitive) -* This element may be either a data structure or an atomic typed element. The first occurance of the name is selected. -* @return the Tree Node containing the named element. -*/ + * + * This is a private function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If nullptr the root node + * is assumed. + * @param target The name of the data structure's element/member (case sensitive) + * This element may be either a data structure or an atomic typed element. The first occurance of the name is selected. + * @return the Tree Node containing the named element. + */ NTREE* findNTreeStructureComponent1(NTREE* ntree, const char* target) { @@ -98,31 +101,32 @@ NTREE* findNTreeStructureComponent1(NTREE* ntree, const char* target) } } - return nullptr; // Not found + return nullptr; // Not found } /** Find (search type A) the first Tree Node with a data structure type containing a named element/member. -* The name of the element is also returned. -* -* This is a private function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If nullptr the root node is assumed. -* @param target The name of the data structure element/member (case sensitive) using the hierachical naming syntax a.b.c or a/b/c. -* This element may be either a data structure or an atomic typed element. If a single named item is specified without -* its hierarchical naming context, the tree node with the first occurance of the name is selected. Using the hierarchy imposes -* more rigour to the search. -* @param lastname Returns the name of the element, i.e., the name of the last item in the name hierarchy. -* @return the Tree Node containing the named element. -*/ -/* + * The name of the element is also returned. + * + * This is a private function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node that defines the start (root) of the sub-tree. If nullptr the root node + * is assumed. + * @param target The name of the data structure element/member (case sensitive) using the hierachical naming syntax + * a.b.c or a/b/c. This element may be either a data structure or an atomic typed element. If a single named item is + * specified without its hierarchical naming context, the tree node with the first occurance of the name is selected. + * Using the hierarchy imposes more rigour to the search. + * @param lastname Returns the name of the element, i.e., the name of the last item in the name hierarchy. + * @return the Tree Node containing the named element. + */ +/* If a hierarchical set of names is passed, all except the last must be a structured type The last may be either a structured or an atomic type Search all but the last on the child tree nodes. The first name must be searched for down the tree from the root or starting node All subsequent names must be within child nodes unless the last name */ -NTREE* -findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, const char** lastname) +NTREE* findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + const char** lastname) { if (ntree == nullptr) { ntree = udaGetFullNTree(); @@ -132,9 +136,9 @@ findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const c if ((strchr(target, '.') != nullptr) || strchr(target, '/') != nullptr) { int ntargets; - char** targetlist = parseTarget(target, &ntargets); // Deconstruct the Name and search for each hierarchy group + char** targetlist = parseTarget(target, &ntargets); // Deconstruct the Name and search for each hierarchy group - *lastname = targetlist[ntargets - 1]; // Preserve the last element name + *lastname = targetlist[ntargets - 1]; // Preserve the last element name // Search recursively for the first name @@ -161,22 +165,23 @@ findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const c child = found; } - addMalloc(logmalloclist, (void*)targetlist[ntargets - 1], (int)strlen(targetlist[ntargets - 1]) + 1, sizeof(char), "char"); + addMalloc(logmalloclist, (void*)targetlist[ntargets - 1], (int)strlen(targetlist[ntargets - 1]) + 1, + sizeof(char), "char"); const char* last_target = targetlist[ntargets - 1]; for (int i = 0; i < ntargets - 1; i++) { - free(targetlist[i]); // Free all others + free(targetlist[i]); // Free all others } - free(targetlist); // Free the list + free(targetlist); // Free the list // Search the user defined type definition for the last name - return if an atomic type for (int i = 0; i < child->userdefinedtype->fieldcount; i++) { if (STR_EQUALS(child->userdefinedtype->compoundfield[i].name, last_target) && child->userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { - return child; - } // Atomic type found + return child; + } // Atomic type found } // Search child nodes for structured types @@ -187,7 +192,7 @@ findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const c } } - return nullptr; // Not Found + return nullptr; // Not Found } // Recursively search using the single name passed @@ -196,22 +201,22 @@ findNTreeStructureComponent2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const c NTREE* child; if ((child = findNTreeStructureComponent1(ntree, target)) != nullptr) { - return child; // Found + return child; // Found } - return nullptr; // Not found + return nullptr; // Not found } /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* The name of the structure is also returned. -* -* This is a private function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @param lastname Returns the name of the Structure, i.e., the name of the last node in the name hierarchy. -* @return the Data Tree Node with the structure name. -*/ + * The name of the structure is also returned. + * + * This is a private function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @param lastname Returns the name of the Structure, i.e., the name of the last node in the name hierarchy. + * @return the Data Tree Node with the structure name. + */ NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, const char** lastname) { if (ntree == nullptr) { @@ -227,7 +232,7 @@ NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const cha targetlist = parseTarget(target, &ntargets); // Deconstruct Name and search for each hierarchy group - for (int i = 0; i < ntargets; i++) { // Drill Down to requested named structure element + for (int i = 0; i < ntargets; i++) { // Drill Down to requested named structure element if (i < ntargets - 1) { child = findNTreeStructure2(logmalloclist, child, targetlist[i], lastname); } else { @@ -246,14 +251,15 @@ NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const cha } } - *lastname = targetlist[ntargets - 1]; // Preserve the last element name + *lastname = targetlist[ntargets - 1]; // Preserve the last element name - addMalloc(logmalloclist, (void*)targetlist[ntargets - 1], (int)strlen(targetlist[ntargets - 1]) + 1, sizeof(char), "char"); + addMalloc(logmalloclist, (void*)targetlist[ntargets - 1], (int)strlen(targetlist[ntargets - 1]) + 1, + sizeof(char), "char"); for (int i = 0; i < ntargets - 1; i++) { // Free all others free(targetlist[i]); } - free(targetlist); // Free the list + free(targetlist); // Free the list return child; // Always the last node you look in ! } @@ -279,29 +285,30 @@ NTREE* findNTreeStructure2(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const cha } /** Find (search type A) and return a Pointer to the Data Tree Node with a data structure that contains a named element. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* This element may be either a structure itself or an atomic typed element. -* @return the Data Tree Node. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or + * a/b/c. This element may be either a structure itself or an atomic typed element. + * @return the Data Tree Node. + */ NTREE* findNTreeStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname = nullptr; return findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); } -/** Find (search type A) and return a Pointer to the Child Data Tree Node with a data structure that contains a named element. -* -* This is a public function with the child sub-trees in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* This element may be either a structure itself or an atomic typed element. -* @return the Data Tree Node. -*/ +/** Find (search type A) and return a Pointer to the Child Data Tree Node with a data structure that contains a named + * element. + * + * This is a public function with the child sub-trees in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the structure element or member (case sensitive) using a hierachical naming syntax a.b.c or + * a/b/c. This element may be either a structure itself or an atomic typed element. + * @return the Data Tree Node. + */ NTREE* findNTreeChildStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { if (ntree == nullptr) { @@ -312,20 +319,22 @@ NTREE* findNTreeChildStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntr for (int i = 0; i < ntree->branches; i++) { NTREE* child = nullptr; - if ((child = findNTreeStructureComponent(logmalloclist, ntree->children[i], target)) != nullptr) return child; + if ((child = findNTreeStructureComponent(logmalloclist, ntree->children[i], target)) != nullptr) { + return child; + } } return nullptr; } /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @return the Data Tree Node. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @return the Data Tree Node. + */ NTREE* findNTreeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname = nullptr; @@ -333,13 +342,13 @@ NTREE* findNTreeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char } /** Find (search type B) and return a Pointer to the named Data Tree Node with a data structure of the same name. -* -* This is a public function with child sub-trees in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. -* @return the child Data Tree Node. -*/ + * + * This is a public function with child sub-trees in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the Structure (case sensitive) using a hierachical naming syntax a.b.c or a/b/c. + * @return the child Data Tree Node. + */ NTREE* findNTreeChildStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { if (ntree == nullptr) { @@ -359,13 +368,13 @@ NTREE* findNTreeChildStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const } /** Find and return a Pointer to a Data Tree Node with a data structure located at a specific memory location. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param data The heap address of the data. -* @return the Data Tree Node. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param data The heap address of the data. + * @return the Data Tree Node. + */ NTREE* findNTreeStructureMalloc(NTREE* ntree, void* data) { if (ntree == nullptr) { @@ -384,13 +393,13 @@ NTREE* findNTreeStructureMalloc(NTREE* ntree, void* data) } /** Locate a tree node with structured data having the specified Structure Definition name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the Structure Definition. -* @return A pointer to the First tree node found with the targeted structure definition. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param ntree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the Structure Definition. + * @return A pointer to the First tree node found with the targeted structure definition. + */ NTREE* findNTreeStructureDefinition(NTREE* ntree, const char* target) { if (ntree == nullptr) { @@ -417,7 +426,7 @@ NTREE* findNTreeStructureDefinition(NTREE* ntree, const char* target) free(targetlist[i]); } - free(targetlist); // Free the list + free(targetlist); // Free the list return child; } @@ -457,13 +466,13 @@ NTREE* xfindNTreeStructureDefinition(NTREE* tree, const char* target) } /** Locate a tree node with structured data having the specified Structure Definition name. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the Structure Definition. -* @return A pointer to the First tree node found with the targeted structure definition. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the Structure Definition. + * @return A pointer to the First tree node found with the targeted structure definition. + */ NTREE* findNTreeStructureComponentDefinition(NTREE* tree, const char* target) { NTREE* next; @@ -489,13 +498,13 @@ NTREE* findNTreeStructureComponentDefinition(NTREE* tree, const char* target) } /** Locate a tree node with structured data having a Specific Structure Class. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param class The Structure Class, e.g., UDA_TYPE_VLEN. -* @return A pointer to the First tree node found with the targeted structure class. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param class The Structure Class, e.g., UDA_TYPE_VLEN. + * @return A pointer to the First tree node found with the targeted structure class. + */ NTREE* idam_findNTreeStructureClass(NTREE* tree, int cls) { NTREE* next; @@ -518,18 +527,20 @@ NTREE* idam_findNTreeStructureClass(NTREE* tree, int cls) } /** Identify the largest count of a Variable Length Array with a given structure type. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the VLEN Structure Definition. -* @param reset Reset the counbter to zero. -* @return An integer returning the maximum count value. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the VLEN Structure Definition. + * @param reset Reset the counbter to zero. + * @return An integer returning the maximum count value. + */ int idam_maxCountVlenStructureArray(NTREE* tree, const char* target, int reset) { static unsigned int count = 0; - if (reset) count = 0; + if (reset) { + count = 0; + } if (tree == nullptr) { tree = udaGetFullNTree(); @@ -550,14 +561,14 @@ int idam_maxCountVlenStructureArray(NTREE* tree, const char* target, int reset) } /** Regularise a specific VLEN structure. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If nullptr the root node is assumed. -* @param target The name of the VLEN Structure Definition. -* @param count The maximum count size for the VLEN data arrays. -* @return An integer returning an error code: 0 => OK. -*/ + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If nullptr the root node is assumed. + * @param target The name of the VLEN Structure Definition. + * @param count The maximum count size for the VLEN data arrays. + * @return An integer returning an error code: 0 => OK. + */ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist, const char* target, unsigned int count) { @@ -575,14 +586,20 @@ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USE // VLEN stuctures have only two fields: len and data // Need the size of the data component - if (vlen->len == 0) return 1; // No data! - if (vlen->len > count) return 1; // Incorrect count value + if (vlen->len == 0) { + return 1; // No data! + } + if (vlen->len > count) { + return 1; // Incorrect count value + } - // VLEN Memory is contiguous so re-allocate: regularise by expanding to a consistent array size (No longer a VLEN!) + // VLEN Memory is contiguous so re-allocate: regularise by expanding to a consistent array size (No longer a + // VLEN!) auto old = (VOIDTYPE)vlen->data; - USERDEFINEDTYPE* child = findUserDefinedType(userdefinedtypelist, tree->userdefinedtype->compoundfield[1].type, 0); - vlen->data = realloc(vlen->data, count * child->size); // Expand Heap to regularise + USERDEFINEDTYPE* child = + findUserDefinedType(userdefinedtypelist, tree->userdefinedtype->compoundfield[1].type, 0); + vlen->data = realloc(vlen->data, count * child->size); // Expand Heap to regularise newnew = vlen->data; size = child->size; changeMalloc(logmalloclist, old, vlen->data, count, child->size, child->name); @@ -594,7 +611,7 @@ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USE tree->children[i]->data = (char*)newnew + i * size; } - resetBranches = vlen->len; // Flag requirement to add extra tree nodes + resetBranches = vlen->len; // Flag requirement to add extra tree nodes } for (int i = 0; i < tree->branches; i++) { @@ -608,7 +625,7 @@ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USE // Update branch count and add new Child nodes with New data array if (resetBranches > 0) { - tree->branches = count; // Only update once all True children have been regularised + tree->branches = count; // Only update once all True children have been regularised auto old = (VOIDTYPE)tree->children; tree->children = (NTREE**)realloc((void*)tree->children, count * sizeof(void*)); @@ -623,7 +640,7 @@ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USE // Update All new Child Nodes with array element addresses for (ui = (unsigned int)resetBranches; ui < count; ui++) { - memcpy((char*)newnew + ui * size, newnew, size); // write extra array items: use the first array element + memcpy((char*)newnew + ui * size, newnew, size); // write extra array items: use the first array element } for (ui = (unsigned int)resetBranches; ui < count; ui++) { @@ -634,14 +651,14 @@ int idam_regulariseVlenStructures(LOGMALLOCLIST* logmalloclist, NTREE* tree, USE return 0; } - -/** Regularise the Shape of All VLEN structured data arrays in the data tree: necessary for accessing in some languages, e.g. IDL. -* -* This is a public function with the whole sub-tree in scope. -* -* @param tree A pointer to a parent tree node. If nullptr the root node is assumed. -* @return An integer returning an error code: 0 => OK. -*/ +/** Regularise the Shape of All VLEN structured data arrays in the data tree: necessary for accessing in some languages, + * e.g. IDL. + * + * This is a public function with the whole sub-tree in scope. + * + * @param tree A pointer to a parent tree node. If nullptr the root node is assumed. + * @return An integer returning an error code: 0 => OK. + */ int idam_regulariseVlenData(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist) { int rc = 0, count = 0; @@ -660,7 +677,7 @@ int idam_regulariseVlenData(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFIN if (rc != 0) { return rc; } - nt->userdefinedtype->idamclass = UDA_TYPE_COMPOUND; // Change the class to 'regular compound structure' + nt->userdefinedtype->idamclass = UDA_TYPE_COMPOUND; // Change the class to 'regular compound structure' } } while (nt != nullptr); @@ -672,12 +689,12 @@ int idam_regulariseVlenData(LOGMALLOCLIST* logmalloclist, NTREE* tree, USERDEFIN // User Accessor functions to Node Data (only the current node is in scope) /** Return the Count of data array elements attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Count of structured data array elements. -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Count of structured data array elements. + */ int getNodeStructureDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, size; @@ -690,12 +707,12 @@ int getNodeStructureDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return the Size (bytes) of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Size (bytes) of the structured data array. -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Size (bytes) of the structured data array. + */ int getNodeStructureDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, size; @@ -708,12 +725,12 @@ int getNodeStructureDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return the rank of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return The rank of the structured data array. -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return The rank of the structured data array. + */ int getNodeStructureDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, size, rank; @@ -727,12 +744,12 @@ int getNodeStructureDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return the shape of the structured data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return A pointer to the integer shape array of the structured data array. -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return A pointer to the integer shape array of the structured data array. + */ int* getNodeStructureDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, size, rank; @@ -765,12 +782,12 @@ int* getNodeStructureDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a pointer to the structured data type name of the data array attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the data type name of the structured data array. -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the data type name of the structured data array. + */ const char* getNodeStructureDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, size; @@ -783,12 +800,12 @@ const char* getNodeStructureDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* nt } /** Return a pointer to the data attached to this tree node. -* -* This is a public function with the current tree node only in scope. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return A void pointer to the data . -*/ + * + * This is a public function with the current tree node only in scope. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return A void pointer to the data . + */ void* getNodeStructureData(NTREE* ntree) { if (ntree == nullptr) { @@ -801,15 +818,15 @@ void* getNodeStructureData(NTREE* ntree) // Sundry utility functions /** Print the Contents of a tree node to a specified File Descriptor. The arguments for this function are -* available from the Structure Definition structure. -* -* This is a public function with the current tree node only in scope. -* -* @param fd The File Descriptor, e.g., stdout -* @param image A text block containing null terminated strings that forms an text image of the structure definition. -* @param imagecount The number of bytes in the image text block. -* @return Void -*/ + * available from the Structure Definition structure. + * + * This is a public function with the current tree node only in scope. + * + * @param fd The File Descriptor, e.g., stdout + * @param image A text block containing null terminated strings that forms an text image of the structure definition. + * @param imagecount The number of bytes in the image text block. + * @return Void + */ void printImage(const char* image, int imagecount) { int next = 0; @@ -824,22 +841,22 @@ void printImage(const char* image, int imagecount) //---------------------------------------------------------------------------------------------------------- /**User defined structure field definition for common types -* -* This is a public function -* -* @param field The user defined structure's field to be populated -* @param name Name of the structure's field. -* @param desc Description of the fields contents -* @param offset Current field byte offset from the start of the structure. Ppdated on return. -* @param type_id Enumerated key indicating the type of data field, e.g. float array -* @return Void -*/ + * + * This is a public function + * + * @param field The user defined structure's field to be populated + * @param name Name of the structure's field. + * @param desc Description of the fields contents + * @param offset Current field byte offset from the start of the structure. Ppdated on return. + * @param type_id Enumerated key indicating the type of data field, e.g. float array + * @return Void + */ void defineField(COMPOUNDFIELD* field, const char* name, const char* desc, int* offset, unsigned short type_id) { initCompoundField(field); strcpy(field->name, name); - field->pointer = 0; // default for scalar values + field->pointer = 0; // default for scalar values field->count = 1; switch (type_id) { @@ -966,12 +983,13 @@ void defineField(COMPOUNDFIELD* field, const char* name, const char* desc, int* snprintf(field->desc, MAXELEMENTNAME, "[char *%s] %s", name, desc); field->pointer = 1; field->size = field->count * sizeof(char*); - field->offset = (int)newoffset((size_t)*offset, "char *"); // must be an explicit char pointer (STRING Convention!) + field->offset = + (int)newoffset((size_t)*offset, "char *"); // must be an explicit char pointer (STRING Convention!) field->offpad = (int)padding((size_t)*offset, "char *"); field->alignment = getalignmentof("char *"); break; case ARRAYSTRING: - //Bug Fix dgm 07Jul2014: atomictype was missing! + // Bug Fix dgm 07Jul2014: atomictype was missing! field->atomictype = UDA_TYPE_STRING; strcpy(field->type, "STRING *"); snprintf(field->desc, MAXELEMENTNAME, "[char **%s] %s", name, desc); diff --git a/source/structures/parseIncludeFile.cpp b/source/structures/parseIncludeFile.cpp old mode 100755 new mode 100644 index 6157e333..23649af8 --- a/source/structures/parseIncludeFile.cpp +++ b/source/structures/parseIncludeFile.cpp @@ -22,19 +22,20 @@ #include "parseIncludeFile.h" #include -#include #include +#include #include "udaDefines.h" -#include -#include #include "udaErrors.h" +#include +#include #include "struct.h" int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* header) { - int lstr, rnk = 0, status = 0, err, model = 0, space, isStruct, isConst, isUnsigned, isLong64, isEnum = 0, maxAlign = 0; + int lstr, rnk = 0, status = 0, err, model = 0, space, isStruct, isConst, isUnsigned, isLong64, isEnum = 0, + maxAlign = 0; FILE* fh = nullptr; char buffer[STRING_LENGTH]; @@ -49,20 +50,20 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade char item[MAXELEMENTS][MAXELEMENTNAME]; char desc[MAXELEMENTS][MAXELEMENTNAME]; char typeStrName[MAXELEMENTS][MAXELEMENTNAME]; - char typeStruct[MAXELEMENTS][MAXELEMENTNAME]; // structure types + char typeStruct[MAXELEMENTS][MAXELEMENTNAME]; // structure types char typeDefName[MAXELEMENTS][MAXELEMENTNAME]; - char typeDef[MAXELEMENTS][MAXELEMENTNAME]; // Type Definitions - int typeStrPtr[MAXELEMENTS]; // Flag pointer type def + char typeDef[MAXELEMENTS][MAXELEMENTNAME]; // Type Definitions + int typeStrPtr[MAXELEMENTS]; // Flag pointer type def int typeDefPtr[MAXELEMENTS]; - char typeEnum[MAXELEMENTS][MAXELEMENTNAME]; // enumerated Types + char typeEnum[MAXELEMENTS][MAXELEMENTNAME]; // enumerated Types int pointer[MAXELEMENTS]; int offset[MAXELEMENTS]; - int offpad[MAXELEMENTS]; // Position before the structure element + int offpad[MAXELEMENTS]; // Position before the structure element int size[MAXELEMENTS]; int count[MAXELEMENTS]; int rank[MAXELEMENTS]; - int shape[MAXELEMENTS][MAXRANK] = { {0} }; + int shape[MAXELEMENTS][MAXRANK] = {{0}}; char defnames[MAXELEMENTS][MAXELEMENTNAME]; int defvalues[MAXELEMENTS]; @@ -95,74 +96,91 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade addIdamError(UDA_SYSTEM_ERROR_TYPE, "parseIncludeFile", errno, "Unable to Open Structure Definition Header file for Read Access!"); } - if (fh != nullptr) fclose(fh); + if (fh != nullptr) { + fclose(fh); + } return err; } -//------------------------------------------------------------------------------------------ -// Parse the Test File -// -// 3 type of structure type defintion: -// -// struct AAA { or -// struct AAA -// { -// int a; // Descriptions are captured if the begin with // -// float b; -// }; -// typedef struct AAA AAA ; assumed not split over lines -// -// typedef struct -// { or -// typedef struct{ -// int a; -// float b; -// } AAA; -// -// struct AAA { or -// struct AAA This does not use a typedef: instead the type defintion -// { struct AAA aaa; is used -// int a; -// float b; -// }; This is identical to the first definition. However, it is not -// followed by a typedef statement. -// -// -// Assumed rules: -// -// 1> retain all #define using integer values for resolving array lengths. -// Arithmetic products like 123*234 cannot be resolved. Why recreate the preprocessor if not necessary. -// Compiler options cannot be resolved: Prune as necessary -// There are defCount defined values. Names do Not Match. -// Don't add constants to #defined values within array definitions. -// 2> The start of a Structure definition begins with 'struct' then the structure name. -// The structure contents are immediately followed by 'typedef struct' then the structure and type name (must be the same) -// 3> The start of a Structure definition begins with 'typedef struct'. -// The structure contents are immediately followed by the type name. -// 4> Don't use /* */ comment block syntax -// 5> Structure UNIONS are not used, not anything complex: simple structures are required. -// 6> multiple pointer types, e.g., char **, are not yet impemented -// 7> Structure elements should be aligned to avoid packing bytes: these may cause problems client side -// 8> If a typedef is not used, prefix the structure name with 'struct' -// -// -// + //------------------------------------------------------------------------------------------ + // Parse the Test File + // + // 3 type of structure type defintion: + // + // struct AAA { or + // struct AAA + // { + // int a; // Descriptions are captured if the begin with // + // float b; + // }; + // typedef struct AAA AAA ; assumed not split over lines + // + // typedef struct + // { or + // typedef struct{ + // int a; + // float b; + // } AAA; + // + // struct AAA { or + // struct AAA This does not use a typedef: instead the type defintion + // { struct AAA aaa; is used + // int a; + // float b; + // }; This is identical to the first definition. However, it is not + // followed by a typedef statement. + // + // + // Assumed rules: + // + // 1> retain all #define using integer values for resolving array lengths. + // Arithmetic products like 123*234 cannot be resolved. Why recreate the preprocessor if not necessary. + // Compiler options cannot be resolved: Prune as necessary + // There are defCount defined values. Names do Not Match. + // Don't add constants to #defined values within array definitions. + // 2> The start of a Structure definition begins with 'struct' then the structure name. + // The structure contents are immediately followed by 'typedef struct' then the structure and type name (must be + // the same) + // 3> The start of a Structure definition begins with 'typedef struct'. + // The structure contents are immediately followed by the type name. + // 4> Don't use /* */ comment block syntax + // 5> Structure UNIONS are not used, not anything complex: simple structures are required. + // 6> multiple pointer types, e.g., char **, are not yet impemented + // 7> Structure elements should be aligned to avoid packing bytes: these may cause problems client side + // 8> If a typedef is not used, prefix the structure name with 'struct' + // + // + // while (fgets(buffer, STRING_LENGTH, fh) != nullptr) { LeftTrimString(TrimString(buffer)); do { - if (STR_STARTSWITH(buffer, "# ")) break; - if (STR_STARTSWITH(buffer, "//")) break; - if (STR_STARTSWITH(buffer, "/*")) break; - if (STR_STARTSWITH(buffer, "*/")) break; - if (buffer[0] == '\n') break; - if (buffer[0] == '\0') break; + if (STR_STARTSWITH(buffer, "# ")) { + break; + } + if (STR_STARTSWITH(buffer, "//")) { + break; + } + if (STR_STARTSWITH(buffer, "/*")) { + break; + } + if (STR_STARTSWITH(buffer, "*/")) { + break; + } + if (buffer[0] == '\n') { + break; + } + if (buffer[0] == '\0') { + break; + } if (STR_STARTSWITH(buffer, "#define ")) { strcpy(defnames[defCount], &buffer[8]); - if ((p = strstr(defnames[defCount], "//")) != nullptr) p[0] = '\0'; // drop Comments + if ((p = strstr(defnames[defCount], "//")) != nullptr) { + p[0] = '\0'; // drop Comments + } convertNonPrintable2(defnames[defCount]); LeftTrimString(defnames[defCount]); TrimString(defnames[defCount]); @@ -176,7 +194,6 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade defCount++; // TO DO: Check MAXELEMENTS not exceeded! - } } break; @@ -185,7 +202,7 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade // *** Scan for free standing typedef statements if (!isEnum && STR_STARTSWITH(buffer, "typedef enum")) { - isEnum = 1; // Enumerated Type Definition + isEnum = 1; // Enumerated Type Definition break; } @@ -193,12 +210,16 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (buffer[0] == '}') { isEnum = 0; strcpy(name1, &buffer[2]); - if ((p = strchr(name1, ';')) != nullptr) p[0] = '\0'; + if ((p = strchr(name1, ';')) != nullptr) { + p[0] = '\0'; + } LeftTrimString(name1); TrimString(name1); - strcpy(typeEnum[typeEnumCount++], name1); // type name + strcpy(typeEnum[typeEnumCount++], name1); // type name name1[0] = '\0'; - } else { break; } + } else { + break; + } } if (!isEnum && STR_STARTSWITH(buffer, "typedef") && @@ -209,15 +230,19 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if ((p = strchr(name1, ' ')) != nullptr) { p[0] = '\0'; strcpy(name2, &p[1]); - if ((p = strchr(name2, ';')) != nullptr) p[0] = '\0'; + if ((p = strchr(name2, ';')) != nullptr) { + p[0] = '\0'; + } if ((p = strchr(name2, '*')) != nullptr) { p[0] = ' '; typeDefPtr[typeDefCount] = 1; - } else { typeDefPtr[typeDefCount] = 0; } + } else { + typeDefPtr[typeDefCount] = 0; + } LeftTrimString(name2); TrimString(name2); - strcpy(typeDefName[typeDefCount], name2); // type synonym - strcpy(typeDef[typeDefCount++], name1); // actual type + strcpy(typeDefName[typeDefCount], name2); // type synonym + strcpy(typeDef[typeDefCount++], name1); // actual type name1[0] = '\0'; name2[0] = '\0'; } else { @@ -236,15 +261,19 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if ((p = strchr(name1, ' ')) != nullptr) { p[0] = '\0'; strcpy(name2, &p[1]); - if ((p = strchr(name2, ';')) != nullptr) p[0] = '\0'; + if ((p = strchr(name2, ';')) != nullptr) { + p[0] = '\0'; + } if ((p = strchr(name2, '*')) != nullptr) { p[0] = ' '; typeStrPtr[typeDefCount] = 1; - } else { typeStrPtr[typeDefCount] = 0; } + } else { + typeStrPtr[typeDefCount] = 0; + } LeftTrimString(name2); TrimString(name2); - strcpy(typeStrName[typeStrCount], name2); // type synonym - strcpy(typeStruct[typeStrCount++], name1); // actual type + strcpy(typeStrName[typeStrCount], name2); // type synonym + strcpy(typeStruct[typeStrCount++], name1); // actual type name1[0] = '\0'; name2[0] = '\0'; } else { @@ -265,14 +294,15 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade do { - if (status && model == 1 && (STR_STARTSWITH(buffer, "{\n") || STR_STARTSWITH(buffer, "#endif") || - STR_STARTSWITH(buffer, "#define") || STR_STARTSWITH(buffer, "#ifdef") || - STR_STARTSWITH(buffer, "#ifndef"))) { + if (status && model == 1 && + (STR_STARTSWITH(buffer, "{\n") || STR_STARTSWITH(buffer, "#endif") || + STR_STARTSWITH(buffer, "#define") || STR_STARTSWITH(buffer, "#ifdef") || + STR_STARTSWITH(buffer, "#ifndef"))) { break; } - if (status || model != 0) { // Start of structure definition - if (!status) { // Structure Name (also Type) follows (model 1 only) + if (status || model != 0) { // Start of structure definition + if (!status) { // Structure Name (also Type) follows (model 1 only) image = nullptr; imagecount = 0; @@ -280,8 +310,12 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (model == 1) { strcpy(name, &buffer[7]); - if ((p = strchr(name, ' ')) != nullptr) p[0] = '\0'; - if ((p = strchr(name, '{')) != nullptr) p[0] = '\0'; + if ((p = strchr(name, ' ')) != nullptr) { + p[0] = '\0'; + } + if ((p = strchr(name, '{')) != nullptr) { + p[0] = '\0'; + } convertNonPrintable2(name); LeftTrimString(name); TrimString(name); @@ -289,23 +323,25 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade name[0] = '\0'; } - itemCount = 0; // New Structure Contents + itemCount = 0; // New Structure Contents status = 1; // Flag start of definition } else { // End of the Structure definition? if (model != 0 && STR_STARTSWITH(buffer, "}")) { - if (model == 1) addImage(&image, &imagecount, "};\n"); + if (model == 1) { + addImage(&image, &imagecount, "};\n"); + } addImage(&image, &imagecount, buffer); addImage(&image, &imagecount, "\n"); if (model == 1) { - if (buffer[0] == '}') { // No typedef statement + if (buffer[0] == '}') { // No typedef statement strcpy(name1, name); strcpy(name2, name1); strcpy(name3, name1); - } else { // typedef statement + } else { // typedef statement if ((p = strchr(&buffer[14], ' ')) != nullptr) { strcpy(name2, &p[1]); if ((p = strchr(name2, ' ')) != nullptr) { @@ -315,9 +351,11 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade strcpy(name2, name3); MidTrimString(name1); MidTrimString(name2); - if ((p = strchr(name2, ';')) != nullptr) p[0] = '\0'; - strcpy(typeStrName[typeStrCount], name1); // type synonym - strcpy(typeStruct[typeStrCount++], name2); // actual type + if ((p = strchr(name2, ';')) != nullptr) { + p[0] = '\0'; + } + strcpy(typeStrName[typeStrCount], name1); // type synonym + strcpy(typeStruct[typeStrCount++], name2); // actual type } } } @@ -325,33 +363,35 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if ((p = strchr(buffer, ' ')) != nullptr) { strcpy(name, &p[1]); MidTrimString(name); - if ((p = strchr(name, ';')) != nullptr) p[0] = '\0'; + if ((p = strchr(name, ';')) != nullptr) { + p[0] = '\0'; + } strcpy(name1, name); strcpy(name2, name); - strcpy(typeStrName[typeStrCount], name); // type synonym - strcpy(typeStruct[typeStrCount++], name); // actual type - + strcpy(typeStrName[typeStrCount], name); // type synonym + strcpy(typeStruct[typeStrCount++], name); // actual type } } if (STR_STARTSWITH(name, name1) && - STR_STARTSWITH(name, name2)) { // Create Meta data on structure + STR_STARTSWITH(name, name2)) { // Create Meta data on structure if (itemCount > 0) { userdefinedtypelist->userdefinedtype = (USERDEFINEDTYPE*)realloc( - (void*)userdefinedtypelist->userdefinedtype, - (userdefinedtypelist->listCount + 1) * sizeof(USERDEFINEDTYPE)); - userdefinedtype = &userdefinedtypelist->userdefinedtype[userdefinedtypelist->listCount]; + (void*)userdefinedtypelist->userdefinedtype, + (userdefinedtypelist->listCount + 1) * sizeof(USERDEFINEDTYPE)); + userdefinedtype = + &userdefinedtypelist->userdefinedtype[userdefinedtypelist->listCount]; initUserDefinedType(userdefinedtype); userdefinedtypelist->listCount = userdefinedtypelist->listCount + 1; strcpy(userdefinedtype->name, name); // Object Name - strcpy(userdefinedtype->source, header); // Source of the Definition - userdefinedtype->idamclass = UDA_TYPE_COMPOUND; // Class of object + strcpy(userdefinedtype->source, header); // Source of the Definition + userdefinedtype->idamclass = UDA_TYPE_COMPOUND; // Class of object - userdefinedtype->compoundfield = (COMPOUNDFIELD*)malloc( - itemCount * sizeof(COMPOUNDFIELD)); + userdefinedtype->compoundfield = + (COMPOUNDFIELD*)malloc(itemCount * sizeof(COMPOUNDFIELD)); byteCount = 0; maxAlign = 0; for (int i = 0; i < itemCount; i++) { @@ -375,13 +415,14 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade userdefinedtype->compoundfield[i].rank = rank[i]; userdefinedtype->compoundfield[i].count = count[i]; if (rank[i] > 0) { - userdefinedtype->compoundfield[i].shape = (int*)malloc( - rank[i] * sizeof(int)); + userdefinedtype->compoundfield[i].shape = + (int*)malloc(rank[i] * sizeof(int)); } else { userdefinedtype->compoundfield[i].shape = nullptr; } - for (int j = 0; j < rank[i]; j++) + for (int j = 0; j < rank[i]; j++) { userdefinedtype->compoundfield[i].shape[j] = shape[i][j]; + } byteCount = byteCount + size[i] * count[i] + offpad[i]; } @@ -389,28 +430,28 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade // Add a final Packing to align the structure if necessary byteCount = byteCount + ((maxAlign - (byteCount % maxAlign)) % - maxAlign); // padding(byteCount, "STRUCTURE"); + maxAlign); // padding(byteCount, "STRUCTURE"); - userdefinedtype->fieldcount = itemCount; // Count of child elements - userdefinedtype->size = byteCount; // Size of the Object (on the run time system) + userdefinedtype->fieldcount = itemCount; // Count of child elements + userdefinedtype->size = byteCount; // Size of the Object (on the run time system) userdefinedtype->imagecount = imagecount; userdefinedtype->image = image; } } else { - //fprintf(stdout,"Names do Not Match: %s, %s, %s\n", name, name1, name2); + // fprintf(stdout,"Names do Not Match: %s, %s, %s\n", name, name1, name2); err = 999; addIdamError(UDA_CODE_ERROR_TYPE, "parseIncludeFile", 999, "typedef statement does not conform to syntax model!"); return err; } - status = 0; // Structure Definition Completed + status = 0; // Structure Definition Completed model = 0; } else { - if (buffer[0] != '}' && strlen(buffer) > 0) { // Structure Contents + if (buffer[0] != '}' && strlen(buffer) > 0) { // Structure Contents expandImage(buffer, defnames, defvalues, defCount, work); addImage(&image, &imagecount, work); @@ -446,7 +487,7 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (!isConst && !isUnsigned && !isLong64) { strcpy(type[itemCount], - buffer); // Atomic or User Defined Type of element + buffer); // Atomic or User Defined Type of element } else { type[itemCount][0] = '\0'; if (isConst) { @@ -461,7 +502,7 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade strcat(type[itemCount], buffer); } - strcpy(item[itemCount], &p[1]); // Element Name + strcpy(item[itemCount], &p[1]); // Element Name // Is this a Description or comment on the item? @@ -473,7 +514,9 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if ((p = strstr(item[itemCount], "/*")) != nullptr) { p[0] = '\0'; strcpy(desc[itemCount], &p[2]); - if ((p = strstr(desc[itemCount], "*/")) != nullptr) p[0] = '\0'; + if ((p = strstr(desc[itemCount], "*/")) != nullptr) { + p[0] = '\0'; + } } // Compact strings and remove unprintable characters and terminating ; @@ -482,14 +525,18 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade TrimString(desc[itemCount]); LeftTrimString(type[itemCount]); - if (!isConst && !isUnsigned && !isLong64) MidTrimString(type[itemCount]); + if (!isConst && !isUnsigned && !isLong64) { + MidTrimString(type[itemCount]); + } TrimString(type[itemCount]); convertNonPrintable2(item[itemCount]); LeftTrimString(item[itemCount]); MidTrimString(item[itemCount]); TrimString(item[itemCount]); - if ((p = strstr(item[itemCount], ";")) != nullptr) p[0] = '\0'; + if ((p = strstr(item[itemCount], ";")) != nullptr) { + p[0] = '\0'; + } // Is this a pointer ? (pointer size is NOT passed: 32/64 bit dependent) @@ -518,14 +565,18 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (STR_STARTSWITH(typeDefName[j], type[itemCount]) && strcmp(type[itemCount], "STRING") != 0) { strcpy(type[itemCount], typeDef[j]); - if (typeDefPtr[j]) pointer[itemCount] = 1; + if (typeDefPtr[j]) { + pointer[itemCount] = 1; + } break; } } for (int j = 0; j < typeStrCount; j++) { if (STR_STARTSWITH(typeStrName[j], type[itemCount])) { strcpy(type[itemCount], typeStruct[j]); - if (typeStrPtr[j]) pointer[itemCount] = 1; + if (typeStrPtr[j]) { + pointer[itemCount] = 1; + } break; } } @@ -542,14 +593,18 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (STR_STARTSWITH(typeDefName[j], type[itemCount]) && strcmp(type[itemCount], "STRING") != 0) { strcpy(type[itemCount], typeDef[j]); - if (typeDefPtr[j]) pointer[itemCount] = 1; + if (typeDefPtr[j]) { + pointer[itemCount] = 1; + } break; } } for (int j = 0; j < typeStrCount; j++) { if (STR_STARTSWITH(typeStrName[j], type[itemCount])) { strcpy(type[itemCount], typeStruct[j]); - if (typeStrPtr[j]) pointer[itemCount] = 1; + if (typeStrPtr[j]) { + pointer[itemCount] = 1; + } break; } } @@ -569,7 +624,7 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade rnk = 0; count[itemCount] = 0; if (!pointer[itemCount] && - ((p = strchr(item[itemCount], '[')) != nullptr)) { // Array + ((p = strchr(item[itemCount], '[')) != nullptr)) { // Array char* p1 = p; char* p2 = nullptr; do { @@ -579,20 +634,20 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade buffer[lstr] = '\0'; shape[itemCount][rnk] = 0; - if (IsNumber(buffer)) { // hard coded size + if (IsNumber(buffer)) { // hard coded size shape[itemCount][rnk] = atoi(buffer); count[itemCount] = count[itemCount] + shape[itemCount][rnk++]; } else { for (int j = 0; j < defCount; j++) { if (STR_STARTSWITH(defnames[j], buffer)) { - shape[itemCount][rnk++] = defvalues[j]; // Array Shape - count[itemCount] = count[itemCount] + - defvalues[j]; // Total Count of Array elements + shape[itemCount][rnk++] = defvalues[j]; // Array Shape + count[itemCount] = + count[itemCount] + + defvalues[j]; // Total Count of Array elements break; } } - } } } while (p2 != nullptr && (p = strchr(p2, '[')) != nullptr); @@ -602,12 +657,15 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade // Scalar values and Pointers must have a count of at least 1 - if (count[itemCount] == 0) count[itemCount] = 1; + if (count[itemCount] == 0) { + count[itemCount] = 1; + } // Offset: Adjusted for structure packing because of alignment boundaries if (pointer[itemCount]) { - size[itemCount] = sizeof(void*); // Offsets and Pointer sizes are architecture dependent + size[itemCount] = + sizeof(void*); // Offsets and Pointer sizes are architecture dependent if (itemCount > 0) { space = size[itemCount - 1] * count[itemCount - 1]; offpad[itemCount] = padding(offset[itemCount - 1] + space, "*"); @@ -620,8 +678,8 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade if (itemCount > 0) { space = size[itemCount - 1] * count[itemCount - 1]; offpad[itemCount] = padding(offset[itemCount - 1] + space, type[itemCount]); - offset[itemCount] = newoffset(offset[itemCount - 1] + space, - type[itemCount]); + offset[itemCount] = + newoffset(offset[itemCount - 1] + space, type[itemCount]); } else { offpad[itemCount] = 0; offset[itemCount] = 0; @@ -631,7 +689,6 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade itemCount++; // TO DO: Check MAXELEMENTS not exceeded! - } } } @@ -648,11 +705,3 @@ int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const char* heade return 0; } - - - - - - - - diff --git a/source/structures/parseIncludeFile.h b/source/structures/parseIncludeFile.h old mode 100755 new mode 100644 index 7e963b38..aa94bb8a --- a/source/structures/parseIncludeFile.h +++ b/source/structures/parseIncludeFile.h @@ -16,4 +16,3 @@ LIBRARY_API int parseIncludeFile(USERDEFINEDTYPELIST* userdefinedtypelist, const #endif #endif // UDA_STRUCTURES_PARSEINCLUDEFILE_H - diff --git a/source/structures/struct.cpp b/source/structures/struct.cpp old mode 100755 new mode 100644 index fd86f983..f3d3a031 --- a/source/structures/struct.cpp +++ b/source/structures/struct.cpp @@ -51,28 +51,31 @@ # define strcasecmp _stricmp #endif -#include +#include "udaErrors.h" #include #include #include -#include "udaErrors.h" +#include -#include "xdrUserDefinedData.h" #include "accessors.h" +#include "xdrUserDefinedData.h" #if defined(SERVERBUILD) # include #endif -static unsigned int last_malloc_index = 0; // Malloc Log search index last value -static unsigned int* last_malloc_index_value = &last_malloc_index; // Preserve Malloc Log search index last value in GENERAL_STRUCT +static unsigned int last_malloc_index = 0; // Malloc Log search index last value +static unsigned int* last_malloc_index_value = + &last_malloc_index; // Preserve Malloc Log search index last value in GENERAL_STRUCT static NTREE* full_ntree = nullptr; -NTREE* udaGetFullNTree() { +NTREE* udaGetFullNTree() +{ return full_ntree; } -void udaSetFullNTree(NTREE* ntree) { +void udaSetFullNTree(NTREE* ntree) +{ full_ntree = ntree; } @@ -86,10 +89,10 @@ void setLastMallocIndexValue(unsigned int* lastMallocIndexValue_in) //--------------------------------------------------------------------------------------------------- /** Initialise a SARRAY data structure. -* -* @param str A pointer to a SARRAY data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a SARRAY data structure instance. + * @return Void. + */ void initSArray(SARRAY* str) { str->count = 0; @@ -100,11 +103,11 @@ void initSArray(SARRAY* str) } /** Print the Contents of a SARRAY data structure. -* -* @param fd A File Descriptor. -* @param str A SARRAY data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A SARRAY data structure instance. + * @return Void. + */ void printSarray(SARRAY str) { UDA_LOG(UDA_LOG_DEBUG, "SARRAY Contents\n"); @@ -114,10 +117,11 @@ void printSarray(SARRAY str) if (str.rank > 0 && str.shape != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "shape : [%d", str.shape[0]); for (int i = 1; i < str.rank; i++) { - if (i < str.rank - 1) + if (i < str.rank - 1) { UDA_LOG(UDA_LOG_DEBUG, "%d,", str.shape[i]); - else + } else { UDA_LOG(UDA_LOG_DEBUG, "%d", str.shape[i]); + } } UDA_LOG(UDA_LOG_DEBUG, "]\n"); } @@ -125,10 +129,10 @@ void printSarray(SARRAY str) } /** Add an NTREE List entry. -* -* @param node A NTREE node to add. -* @return Void. -*/ + * + * @param node A NTREE node to add. + * @return Void. + */ void addNTreeList(LOGMALLOCLIST* logmalloclist, NTREE* node, NTREELIST* ntree_list) { VOIDTYPE old = (VOIDTYPE)ntree_list->forrest; @@ -138,29 +142,33 @@ void addNTreeList(LOGMALLOCLIST* logmalloclist, NTREE* node, NTREELIST* ntree_li } /** Add an NTREE node to an array of child nodes. -* -* @param parent A NTREE node with a set of child nodes -* @param child A NTREE node to add to the existing set of child nodes -* @return Void. -*/ + * + * @param parent A NTREE node with a set of child nodes + * @param child A NTREE node to add to the existing set of child nodes + * @return Void. + */ void addNTree(NTREE* parent, NTREE* child) { int branch; - if (child == nullptr || parent == nullptr) return; - child->parent = parent; // Identify the parent of the child node - branch = parent->branches; // Number of existing siblings + if (child == nullptr || parent == nullptr) { + return; + } + child->parent = parent; // Identify the parent of the child node + branch = parent->branches; // Number of existing siblings parent->children[branch] = child; // Append the new node - parent->branches++; // Update the count of children + parent->branches++; // Update the count of children } /** Free an NTREE node together with the array of child nodes. -* -* @param ntree A NTREE node with or without a set of child nodes -* @return Void. -*/ + * + * @param ntree A NTREE node with or without a set of child nodes + * @return Void. + */ void freeNTreeNode(NTREE* ntree) { - if (ntree == nullptr) return; + if (ntree == nullptr) { + return; + } if (ntree->branches > 0 && ntree->children != nullptr) { for (int i = 0; i < ntree->branches; i++) { freeNTreeNode(ntree->children[i]); @@ -170,18 +178,20 @@ void freeNTreeNode(NTREE* ntree) } /** Add a new image line to the existing image. -* -* @param image A block of bytes used to record structure definition image data. -* @param imagecount The current count of bytes used to record the present image. -* @param line A new image line to add to the existing image. -* @return Both image and image count are updated on return. -*/ + * + * @param image A block of bytes used to record structure definition image data. + * @param imagecount The current count of bytes used to record the present image. + * @param line A new image line to add to the existing image. + * @return Both image and image count are updated on return. + */ void addImage(char** image, int* imagecount, const char* line) { int len; void* old = (void*)*image; char* anew = nullptr; - if (line == nullptr || line[0] == '\0') return; + if (line == nullptr || line[0] == '\0') { + return; + } len = (int)strlen(line); anew = (char*)realloc((void*)old, (*imagecount + len + 1) * sizeof(char)); strcpy(&anew[*imagecount], line); @@ -190,27 +200,29 @@ void addImage(char** image, int* imagecount, const char* line) } /** Expand an image line that contains header defines and include the numerical value -* -* @param buffer An image line to be expanded -* @param defnames An array of define names -* @param defvalues An array of define values -* @param defCount The number of define names and values -* @param expand A pre-allocated array of char to be used to receive the expanded buffer string. -* @return expand An expanded Image line. -*/ + * + * @param buffer An image line to be expanded + * @param defnames An array of define names + * @param defvalues An array of define values + * @param defCount The number of define names and values + * @param expand A pre-allocated array of char to be used to receive the expanded buffer string. + * @return expand An expanded Image line. + */ void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* defvalues, int defCount, char* expand) { // Insert values with #define names int len, lstr; char work[STRING_LENGTH]; - char* p1, * p2, * p3; + char *p1, *p2, *p3; if (buffer[0] != '\t' || buffer[0] != ' ') { - strcpy(expand, "\t"); // Tab out the structure contents - } else { expand[0] = '\0'; } + strcpy(expand, "\t"); // Tab out the structure contents + } else { + expand[0] = '\0'; + } len = (int)strlen(expand); - if ((p1 = strchr(buffer, '[')) != nullptr) { // Array + if ((p1 = strchr(buffer, '[')) != nullptr) { // Array strncat(expand, buffer, p1 - buffer + 1); expand[len + (int)(p1 - buffer + 1)] = '\0'; len = (int)strlen(expand); @@ -219,7 +231,7 @@ void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* lstr = (int)(p2 - p1 - 1); strncpy(work, &p1[1], lstr); work[lstr] = '\0'; - if (IsNumber(work)) { // hard coded size + if (IsNumber(work)) { // hard coded size strncat(expand, &p1[1], p2 - &p1[1] + 1); len = len + (int)(p2 - &p1[1] + 1); expand[len] = '\0'; @@ -227,7 +239,7 @@ void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* } else { for (int j = 0; j < defCount; j++) { if (!strcmp((char*)defnames[j], work)) { - snprintf(work, STRING_LENGTH, " = %d]", defvalues[j]); // Array size + snprintf(work, STRING_LENGTH, " = %d]", defvalues[j]); // Array size strncat(expand, &p1[1], p2 - &p1[1]); len = len + (int)(p2 - &p1[1]); expand[len] = '\0'; @@ -247,10 +259,10 @@ void expandImage(char* buffer, char defnames[MAXELEMENTS][MAXELEMENTNAME], int* } /** Initialise a LOGMALLOCLIST data structure. -* -* @param str A pointer to a LOGMALLOCLIST data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a LOGMALLOCLIST data structure instance. + * @return Void. + */ void initLogMallocList(LOGMALLOCLIST* str) { str->listcount = 0; @@ -259,10 +271,10 @@ void initLogMallocList(LOGMALLOCLIST* str) } /** Initialise a LOGMALLOC data structure. -* -* @param str A pointer to a LOGMALLOC data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a LOGMALLOC data structure instance. + * @return Void. + */ void initLogMalloc(LOGMALLOC* str) { str->count = 0; @@ -274,11 +286,10 @@ void initLogMalloc(LOGMALLOC* str) str->shape = nullptr; } - /** Initialise a LOGSTRUCTLIST data structure. -* -* @return Void. -*/ + * + * @return Void. + */ void initLogStructList(LOGSTRUCTLIST* log_struct_list) { log_struct_list->listcount = 0; @@ -287,10 +298,10 @@ void initLogStructList(LOGSTRUCTLIST* log_struct_list) } /** Initialise a LOGSTRUCT data structure. -* -* @param str A pointer to a LOGSTRUCT data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a LOGSTRUCT data structure instance. + * @return Void. + */ void initLogStruct(LOGSTRUCT* str) { str->id = 0; @@ -299,10 +310,10 @@ void initLogStruct(LOGSTRUCT* str) } /** Initialise a COMPOUNDFIELD data structure. -* -* @param str A pointer to a COMPOUNDFIELD data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a COMPOUNDFIELD data structure instance. + * @return Void. + */ void initCompoundField(COMPOUNDFIELD* str) { str->size = 0; @@ -320,10 +331,10 @@ void initCompoundField(COMPOUNDFIELD* str) } /** Initialise a USERDEFINEDTYPE data structure. -* -* @param str A pointer to a USERDEFINEDTYPE data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a USERDEFINEDTYPE data structure instance. + * @return Void. + */ void initUserDefinedType(USERDEFINEDTYPE* str) { str->idamclass = UDA_TYPE_UNKNOWN; @@ -335,26 +346,24 @@ void initUserDefinedType(USERDEFINEDTYPE* str) str->size = 0; str->fieldcount = 0; str->compoundfield = nullptr; - } /** Initialise a USERDEFINEDTYPELIST data structure. -* -* @param str A pointer to a USERDEFINEDTYPELIST data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a USERDEFINEDTYPELIST data structure instance. + * @return Void. + */ void initUserDefinedTypeList(USERDEFINEDTYPELIST* str) { str->listCount = 0; str->userdefinedtype = nullptr; } - /** Initialise a GENERAL_BLOCK data structure. -* -* @param str A pointer to a GENERAL_BLOCK data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a GENERAL_BLOCK data structure instance. + * @return Void. + */ void initGeneralBlock(GENERAL_BLOCK* str) { str->userdefinedtype = nullptr; @@ -364,11 +373,11 @@ void initGeneralBlock(GENERAL_BLOCK* str) } /** Print the Contents of a COMPOUNDFIELD data structure. -* -* @param fd A File Descriptor. -* @param str A COMPOUNDFIELD data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A COMPOUNDFIELD data structure instance. + * @return Void. + */ void printCompoundField(COMPOUNDFIELD str) { UDA_LOG(UDA_LOG_DEBUG, "COMPOUNDFIELD Contents\n"); @@ -397,23 +406,23 @@ void printCompoundField(COMPOUNDFIELD str) } /** Print the Tabulated Contents of a COMPOUNDFIELD data structure. -* -* @param fd A File Descriptor. -* @param str A COMPOUNDFIELD data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A COMPOUNDFIELD data structure instance. + * @return Void. + */ void printCompoundFieldTable(COMPOUNDFIELD str) { - UDA_LOG(UDA_LOG_DEBUG, "\t%20s\t%16s\t%d\t%d\t%d\t%d\t%d\t%d\n", - str.name, str.type, str.pointer, str.size, str.count, str.offset, str.offpad, str.alignment); + UDA_LOG(UDA_LOG_DEBUG, "\t%20s\t%16s\t%d\t%d\t%d\t%d\t%d\t%d\n", str.name, str.type, str.pointer, str.size, + str.count, str.offset, str.offpad, str.alignment); } /** Print the Contents of a USERDEFINEDTYPE data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return Void. + */ void printUserDefinedType(USERDEFINEDTYPE str) { UDA_LOG(UDA_LOG_DEBUG, "USERDEFINEDTYPE Contents\n"); @@ -427,21 +436,23 @@ void printUserDefinedType(USERDEFINEDTYPE str) UDA_LOG(UDA_LOG_DEBUG, "\n"); if (str.compoundfield != nullptr) { - for (int i = 0; i < str.fieldcount; i++) printCompoundField(str.compoundfield[i]); + for (int i = 0; i < str.fieldcount; i++) { + printCompoundField(str.compoundfield[i]); + } } UDA_LOG(UDA_LOG_DEBUG, "\n"); } /** Print the Tabulated Contents of a USERDEFINEDTYPE data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return Void. + */ void printUserDefinedTypeTable(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE str) { - UDA_LOG(UDA_LOG_DEBUG, "USERDEFINEDTYPE name: %s size: %d [%d] fieldcount: %d ref_id: %d \n", - str.name, str.size, getStructureSize(userdefinedtypelist, &str), str.fieldcount, str.ref_id); + UDA_LOG(UDA_LOG_DEBUG, "USERDEFINEDTYPE name: %s size: %d [%d] fieldcount: %d ref_id: %d \n", str.name, str.size, + getStructureSize(userdefinedtypelist, &str), str.fieldcount, str.ref_id); if (str.compoundfield != nullptr) { UDA_LOG(UDA_LOG_DEBUG, "\t Item\t type\tpointer\tsize\tcount\toffset\toffpad\talignment\n"); @@ -452,11 +463,11 @@ void printUserDefinedTypeTable(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEF } /** Print the Tabulated Contents of a USERDEFINEDTYPE data structure with Zero Sized elements. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPE data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPE data structure instance. + * @return Void. + */ void printZeroSizedUserDefinedTypeTable(USERDEFINEDTYPE str) { int size1 = 0, size2 = 0; @@ -465,7 +476,9 @@ void printZeroSizedUserDefinedTypeTable(USERDEFINEDTYPE str) UDA_LOG(UDA_LOG_DEBUG, "\t Item\t type\tpointer\tsize\tcount\toffset\toffpad\talignment\n"); for (int i = 0; i < str.fieldcount; i++) { - if (str.compoundfield[i].size > 0) continue; + if (str.compoundfield[i].size > 0) { + continue; + } printCompoundFieldTable(str.compoundfield[i]); if (str.compoundfield[i].pointer) { size1 = size1 + str.compoundfield[i].size; @@ -480,18 +493,16 @@ void printZeroSizedUserDefinedTypeTable(USERDEFINEDTYPE str) } else { size2 = size2 + str.compoundfield[str.fieldcount - 1].size * str.compoundfield[str.fieldcount - 1].count; } - } UDA_LOG(UDA_LOG_DEBUG, "[%d][%d]\n", size1, size2); } - /** Print the Contents of a USERDEFINEDTYPELIST data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return Void. + */ void printUserDefinedTypeList(USERDEFINEDTYPELIST str) { UDA_LOG(UDA_LOG_DEBUG, "USERDEFINEDTYPELIST Contents\n"); @@ -503,11 +514,11 @@ void printUserDefinedTypeList(USERDEFINEDTYPELIST str) } /** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return Void. + */ void printUserDefinedTypeListTable(USERDEFINEDTYPELIST str) { UDA_LOG(UDA_LOG_DEBUG, "USERDEFINEDTYPELIST Contents\n"); @@ -519,11 +530,11 @@ void printUserDefinedTypeListTable(USERDEFINEDTYPELIST str) } /** Print the Tabulated Contents of a USERDEFINEDTYPELIST data structure where the size is zero. -* -* @param fd A File Descriptor. -* @param str A USERDEFINEDTYPELIST data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A USERDEFINEDTYPELIST data structure instance. + * @return Void. + */ void printZeroSizedUserDefinedTypeListTable(USERDEFINEDTYPELIST str) { UDA_LOG(UDA_LOG_DEBUG, "Zero Size USERDEFINEDTYPELIST Contents\n"); @@ -535,11 +546,11 @@ void printZeroSizedUserDefinedTypeListTable(USERDEFINEDTYPELIST str) } /** Print the Contents of a LOGMALLOC data structure. -* -* @param fd A File Descriptor. -* @param str A LOGMALLOC data structure instance. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @param str A LOGMALLOC data structure instance. + * @return Void. + */ void printMallocLog(LOGMALLOC str) { UDA_LOG(UDA_LOG_DEBUG, "%p\t%d\t%d\t%d\t%s\n", (void*)str.heap, str.count, str.size, str.freed, str.type); @@ -553,10 +564,10 @@ void printMallocLog(LOGMALLOC str) } /** Print the Contents of the Global LOGMALLOCLIST data structure. -* -* @param fd A File Descriptor. -* @return Void. -*/ + * + * @param fd A File Descriptor. + * @return Void. + */ void printMallocLogList(const LOGMALLOCLIST* logmalloclist) { UDA_LOG(UDA_LOG_DEBUG, "MALLOC LOG List Contents\n"); @@ -572,15 +583,14 @@ void printMallocLogList(const LOGMALLOCLIST* logmalloclist) //============================================================================================================== // Utility Functions - /** Add a stack memory location to the LOGMALLOCLIST data structure. These are not freed. -* -* @param stack The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ + * + * @param stack The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ void addNonMalloc(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type) { // Put a non malloc'd memory location on the malloc log flagging it as freed @@ -614,8 +624,8 @@ void addNonMalloc(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t s * @return void. */ -void -addNonMalloc2(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type, int rank, int* shape) +void addNonMalloc2(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, const char* type, int rank, + int* shape) { // Put a non malloc'd memory location on the malloc log flagging it as freed @@ -642,21 +652,23 @@ addNonMalloc2(LOGMALLOCLIST* logmalloclist, void* stack, int count, size_t size, } /** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. -* -* @param heap The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ + * + * @param heap The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ void addMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type) { // Log all Heap allocations for Data from User Defined Structures // Grow the list when necessary - //USERDEFINEDTYPE *udt; + // USERDEFINEDTYPE *udt; - if (heap == nullptr) return; + if (heap == nullptr) { + return; + } if (logmalloclist->listcount + 1 >= logmalloclist->listsize) { logmalloclist->logmalloc = (LOGMALLOC*)realloc((void*)logmalloclist->logmalloc, @@ -677,22 +689,24 @@ void addMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, } /** Add a heap memory location to the LOGMALLOCLIST data structure. These are freed. -* -* @param heap The memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @param rank The rank of the allocated array. -* @param shape The shape of the allocated array. Only required when rank > 1. -* @return void. -*/ -void -addMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type, int rank, int* shape) + * + * @param heap The memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @param rank The rank of the allocated array. + * @param shape The shape of the allocated array. Only required when rank > 1. + * @return void. + */ +void addMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, const char* type, int rank, + int* shape) { // Log all Heap allocations for Data from User Defined Structures // Grow the list when necessary - if (heap == nullptr) return; + if (heap == nullptr) { + return; + } if (logmalloclist->listcount + 1 >= logmalloclist->listsize) { logmalloclist->logmalloc = (LOGMALLOC*)realloc((void*)logmalloclist->logmalloc, @@ -717,14 +731,14 @@ addMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int count, size_t size, con } /** Change the logged memory location to a new location (necessary with realloc). -* -* @param old The original logged memory location. -* @param anew The new replacement memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ + * + * @param old The original logged memory location. + * @param anew The new replacement memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ void changeMalloc(LOGMALLOCLIST* logmalloclist, VOIDTYPE old, void* anew, int count, size_t size, const char* type) { // Change a List Entry @@ -747,14 +761,14 @@ void changeMalloc(LOGMALLOCLIST* logmalloclist, VOIDTYPE old, void* anew, int co } /** Change the logged memory location to a new location (necessary with realloc). -* -* @param old The original logged memory location. -* @param anew The new replacement memory location. -* @param count The number of elements allocated. -* @param size The size of a single element. -* @param type The name of the type allocated. -* @return void. -*/ + * + * @param old The original logged memory location. + * @param anew The new replacement memory location. + * @param count The number of elements allocated. + * @param size The size of a single element. + * @param type The name of the type allocated. + * @return void. + */ void changeNonMalloc(LOGMALLOCLIST* logmalloclist, void* old, void* anew, int count, size_t size, const char* type) { // Change a non-malloc List Entry @@ -779,9 +793,9 @@ void changeNonMalloc(LOGMALLOCLIST* logmalloclist, void* old, void* anew, int co } /** Check allocated heap memory for Duplicates - Isolate to prevent double free error. -* -* @return void. -*/ + * + * @return void. + */ #ifdef A64 int compare_ulonglong(const void* a, const void* b) @@ -792,9 +806,10 @@ int compare_ulonglong(const void* a, const void* b) } #else -static int compare_ulong(const void *a, const void *b) { - const unsigned long *da = (const unsigned long *) a; - const unsigned long *db = (const unsigned long *) b; +static int compare_ulong(const void* a, const void* b) +{ + const unsigned long* da = (const unsigned long*)a; + const unsigned long* db = (const unsigned long*)b; return (int)(*da > *db) - (int)(*da < *db); } #endif @@ -803,8 +818,12 @@ int dupCountMallocLog(LOGMALLOCLIST* str) { int sortCount = 0, dupCount = 0; int compare_ulonglong(const void*, const void*); - if (str == nullptr) return 0; - if (str->listcount <= 1) return 0; + if (str == nullptr) { + return 0; + } + if (str->listcount <= 1) { + return 0; + } #ifdef A64 unsigned long long* sorted = (unsigned long long*)malloc(str->listcount * sizeof(unsigned long long)); for (int i = 0; i < str->listcount; i++) { @@ -814,31 +833,37 @@ int dupCountMallocLog(LOGMALLOCLIST* str) } qsort((void*)sorted, (size_t)sortCount, (size_t)sizeof(unsigned long long), compare_ulonglong); #else - unsigned long *sorted = (unsigned long *)malloc(str->listcount*sizeof(unsigned long)); + unsigned long* sorted = (unsigned long*)malloc(str->listcount * sizeof(unsigned long)); for (int i = 0; i < str->listcount; i++) { if (str->logmalloc[i].freed == 0) { sorted[sortCount++] = (unsigned long)str->logmalloc[i].heap; } } - qsort((void *)sorted,(size_t)sortCount,(size_t)sizeof(unsigned long), compare_ulong); + qsort((void*)sorted, (size_t)sortCount, (size_t)sizeof(unsigned long), compare_ulong); #endif for (int i = 1; i < sortCount; i++) { - if (sorted[i] == sorted[i - 1]) dupCount++; + if (sorted[i] == sorted[i - 1]) { + dupCount++; + } } free(sorted); return dupCount; } /** Free allocated heap memory but preserve the addresses. There are no arguments. -* -* @return void. -*/ + * + * @return void. + */ void freeMallocLog(LOGMALLOCLIST* str) { - if (str == nullptr) return; + if (str == nullptr) { + return; + } for (int i = 0; i < str->listcount; i++) { if (str->logmalloc[i].freed == 0) { - if (str->logmalloc[i].heap != nullptr && str->logmalloc[i].count > 0) free(str->logmalloc[i].heap); + if (str->logmalloc[i].heap != nullptr && str->logmalloc[i].count > 0) { + free(str->logmalloc[i].heap); + } str->logmalloc[i].freed = 1; if (str->logmalloc[i].rank > 1 && str->logmalloc[i].shape != nullptr) { free(str->logmalloc[i].shape); @@ -849,12 +874,14 @@ void freeMallocLog(LOGMALLOCLIST* str) } /** Free allocated heap memory and reinitialise a new logmalloclist-> There are no arguments. -* -* @return void. -*/ + * + * @return void. + */ void freeMallocLogList(LOGMALLOCLIST* str) { - if (str == nullptr) return; + if (str == nullptr) { + return; + } freeMallocLog(str); if (str->logmalloc != nullptr) { free(str->logmalloc); @@ -864,13 +891,13 @@ void freeMallocLogList(LOGMALLOCLIST* str) } /** Find the meta data associated with a specific memory location. -* -* @param heap The target memory location. -* @param count The returned allocation count. -* @param size The returned allocation size. -* @param type The returned allocation type. -* @return void. -*/ + * + * @param heap The target memory location. + * @param count The returned allocation count. + * @param size The returned allocation size. + * @param type The returned allocation type. + * @return void. + */ void findMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type) { // Find a specific Heap allocation for Data within User Defined Structures @@ -879,11 +906,15 @@ void findMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, *count = 0; *size = 0; *type = nullptr; - if (heap == nullptr) return; + if (heap == nullptr) { + return; + } - if ((target = *((VOIDTYPE*)heap)) == 0) return; + if ((target = *((VOIDTYPE*)heap)) == 0) { + return; + } - if (last_malloc_index >= (unsigned int)logmalloclist->listcount) { // Defensive check + if (last_malloc_index >= (unsigned int)logmalloclist->listcount) { // Defensive check last_malloc_index = 0; *last_malloc_index_value = last_malloc_index; } @@ -924,8 +955,8 @@ void findMalloc(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, * @return void. */ -void -findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type, int* rank, int** shape) +void findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, const char** type, int* rank, + int** shape) { // Find a specific Heap allocation for Data within User Defined Structures @@ -935,11 +966,15 @@ findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, con *type = nullptr; *rank = 0; *shape = nullptr; - if (heap == nullptr) return; + if (heap == nullptr) { + return; + } - if ((target = *((VOIDTYPE*)heap)) == 0) return; + if ((target = *((VOIDTYPE*)heap)) == 0) { + return; + } - if (last_malloc_index >= (unsigned int)logmalloclist->listcount) { // Defensive check + if (last_malloc_index >= (unsigned int)logmalloclist->listcount) { // Defensive check last_malloc_index = 0; *last_malloc_index_value = last_malloc_index; } @@ -954,13 +989,13 @@ findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, con if (*rank > 1) { *shape = logmalloclist->logmalloc[i].shape; } - last_malloc_index = i; // Start at the current log entry + last_malloc_index = i; // Start at the current log entry *last_malloc_index_value = last_malloc_index; return; } } - for (unsigned int i = 0; i < last_malloc_index; i++) { // Start search at the first log entry + for (unsigned int i = 0; i < last_malloc_index; i++) { // Start search at the first log entry candidate = (VOIDTYPE)logmalloclist->logmalloc[i].heap; if (target == candidate) { *count = logmalloclist->logmalloc[i].count; @@ -977,23 +1012,24 @@ findMalloc2(LOGMALLOCLIST* logmalloclist, void* heap, int* count, int* size, con } } - /** Add a heap memory location to the LOGSTRUCTLIST data structure. These are freed. -* -* @param heap The memory location. -* @param type The name of the type allocated. -* @return void. -*/ + * + * @param heap The memory location. + * @param type The name of the type allocated. + * @return void. + */ void addStruct(void* heap, const char* type, LOGSTRUCTLIST* log_struct_list) { // Log all dispatched/received Structures // Grow the list when necessary - if (heap == nullptr) return; + if (heap == nullptr) { + return; + } if (log_struct_list->listcount + 1 >= log_struct_list->listsize) { - log_struct_list->logstruct = (LOGSTRUCT*)realloc((void*)log_struct_list->logstruct, - (log_struct_list->listsize + GROWMALLOCLIST) * sizeof(LOGSTRUCT)); + log_struct_list->logstruct = (LOGSTRUCT*)realloc( + (void*)log_struct_list->logstruct, (log_struct_list->listsize + GROWMALLOCLIST) * sizeof(LOGSTRUCT)); log_struct_list->listsize = log_struct_list->listsize + GROWMALLOCLIST; } @@ -1005,9 +1041,9 @@ void addStruct(void* heap, const char* type, LOGSTRUCTLIST* log_struct_list) } /** Free allocated heap memory and reinitialise a new LOGSTRUCTLIST. There are no arguments. -* -* @return void. -*/ + * + * @return void. + */ void freeLogStructList(LOGSTRUCTLIST* log_struct_list) { free(log_struct_list->logstruct); @@ -1015,18 +1051,20 @@ void freeLogStructList(LOGSTRUCTLIST* log_struct_list) } /** Find the meta data associated with a specific Structure. -* -* @param heap The target memory location. -* @param type The returned structure type. -* @return The structure id. -*/ + * + * @param heap The target memory location. + * @param type The returned structure type. + * @return The structure id. + */ int findStructId(void* heap, char** type, LOGSTRUCTLIST* log_struct_list) { // Find a specific Data Structure - //VOIDTYPE candidate, target; + // VOIDTYPE candidate, target; *type = nullptr; - if (heap == nullptr) return 0; + if (heap == nullptr) { + return 0; + } for (int i = 0; i < log_struct_list->listcount; i++) { if (heap == log_struct_list->logstruct[i].heap) { @@ -1038,17 +1076,19 @@ int findStructId(void* heap, char** type, LOGSTRUCTLIST* log_struct_list) } /** Find the Heap address and Data Type of a specific Structure. -* -* @param id The structure id. -* @param type The returned structure type. -* @return The heap memory location -*/ + * + * @param id The structure id. + * @param type The returned structure type. + * @return The heap memory location + */ void* findStructHeap(int id, char** type, LOGSTRUCTLIST* log_struct_list) { // Find a specific Data Structure *type = nullptr; - if (id == 0) return nullptr; + if (id == 0) { + return nullptr; + } for (int i = 0; i < log_struct_list->listcount; i++) { if (log_struct_list->logstruct[i].id == id) { @@ -1059,13 +1099,12 @@ void* findStructHeap(int id, char** type, LOGSTRUCTLIST* log_struct_list) return nullptr; } - /** Copy a User Defined Structure Definition. -* -* @param old The type definition to be copied. -* @param anew The copy of the type definition. -* @return void. -*/ + * + * @param old The type definition to be copied. + * @param anew The copy of the type definition. + * @return void. + */ void copyUserDefinedType(USERDEFINEDTYPE* old, USERDEFINEDTYPE* anew) { USERDEFINEDTYPE udt; @@ -1088,12 +1127,13 @@ void copyUserDefinedType(USERDEFINEDTYPE* old, USERDEFINEDTYPE* anew) } /** Copy the Master User Defined Structure Definition List. -* -* @param anew The copy of the type definition list. -* @return void. -*/ + * + * @param anew The copy of the type definition list. + * @return void. + */ #if defined(SERVERBUILD) -void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, const USERDEFINEDTYPELIST* parseduserdefinedtypelist) { +void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, const USERDEFINEDTYPELIST* parseduserdefinedtypelist) +{ USERDEFINEDTYPELIST* list = (USERDEFINEDTYPELIST*)malloc(sizeof(USERDEFINEDTYPELIST)); initUserDefinedTypeList(list); list->listCount = parseduserdefinedtypelist->listCount; // Copy the standard set of structure definitions @@ -1104,8 +1144,9 @@ void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, const USERDEFINEDTYPELI USERDEFINEDTYPE usertypeNew; initUserDefinedType(&usertypeNew); usertypeNew = usertypeOld; - usertypeNew.image = (char*)malloc(usertypeOld.imagecount * sizeof(char)); // Copy pointer type (prevents double free) - memcpy (usertypeNew.image, usertypeOld.image, usertypeOld.imagecount); + usertypeNew.image = + (char*)malloc(usertypeOld.imagecount * sizeof(char)); // Copy pointer type (prevents double free) + memcpy(usertypeNew.image, usertypeOld.image, usertypeOld.imagecount); usertypeNew.compoundfield = (COMPOUNDFIELD*)malloc(usertypeOld.fieldcount * sizeof(COMPOUNDFIELD)); @@ -1134,10 +1175,10 @@ void copyUserDefinedTypeList(USERDEFINEDTYPELIST** anew, const USERDEFINEDTYPELI #endif /** Create the Initial User Defined Structure Definition List. -* -* @param anew The initial type definition list. -* @return void. -*/ + * + * @param anew The initial type definition list. + * @return void. + */ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) { auto list = (USERDEFINEDTYPELIST*)malloc(sizeof(USERDEFINEDTYPELIST)); @@ -1151,15 +1192,15 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) //---------------------------------------------------------------------------------------------------------------- // SARRAY - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition initCompoundField(&field); strcpy(usertype.name, "SARRAY"); strcpy(usertype.source, "getInitialUserDefinedTypeList"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(SARRAY); // Structure size + usertype.size = sizeof(SARRAY); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -1181,7 +1222,7 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = newoffset(offset, field.type); @@ -1195,13 +1236,13 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) //---------------------------------------------------------------------------------------------------------------- // ENUMMEMBER - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMMEMBER"); strcpy(usertype.source, "ENUMMEMBER structure: for labels and values"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMMEMBER); // Structure size + usertype.size = sizeof(ENUMMEMBER); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -1209,12 +1250,12 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM label"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMMEMBER, name); @@ -1232,13 +1273,13 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) //---------------------------------------------------------------------------------------------------------------- // ENUMLIST - initUserDefinedType(&usertype); // New structure definition + initUserDefinedType(&usertype); // New structure definition strcpy(usertype.name, "ENUMLIST"); strcpy(usertype.source, "Array of ENUM values with properties"); usertype.ref_id = 0; - usertype.imagecount = 0; // No Structure Image data + usertype.imagecount = 0; // No Structure Image data usertype.image = nullptr; - usertype.size = sizeof(ENUMLIST); // Structure size + usertype.size = sizeof(ENUMLIST); // Structure size usertype.idamclass = UDA_TYPE_COMPOUND; offset = 0; @@ -1246,12 +1287,12 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) initCompoundField(&field); strcpy(field.name, "name"); field.atomictype = UDA_TYPE_STRING; - strcpy(field.type, "STRING"); // convert atomic type to a string label + strcpy(field.type, "STRING"); // convert atomic type to a string label strcpy(field.desc, "The ENUM name"); field.pointer = 0; field.count = MAXELEMENTNAME; field.rank = 1; - field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 + field.shape = (int*)malloc(field.rank * sizeof(int)); // Needed when rank >= 1 field.shape[0] = field.count; field.size = field.count * sizeof(char); field.offset = offsetof(ENUMLIST, name); @@ -1278,7 +1319,7 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) field.rank = 0; field.shape = nullptr; field.size = sizeof(ENUMMEMBER*); - field.offset = offsetof(ENUMLIST, enummember); // Different to newoffset + field.offset = offsetof(ENUMLIST, enummember); // Different to newoffset offset = field.offset + field.size; field.offpad = padding(offset, field.type); field.alignment = getalignmentof(field.type); @@ -1289,11 +1330,11 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) // Naming the field "data" hits a bug and garbage is returned! // Don't know the correct type until the structure is used!!!! - so cannot pre-define! // Make the necessary changes to the structure definition when ENUMLIST is used or - // Convert data to standard unsigned long64 + // Convert data to standard unsigned long64 initCompoundField(&field); defineField(&field, "enumarray", "Data with this enumerated type", &offset, - ARRAYULONG64); // Data need to be converted to this type + ARRAYULONG64); // Data need to be converted to this type addCompoundField(&usertype, field); initCompoundField(&field); defineField(&field, "enumarray_rank", "The rank of arraydata", &offset, SCALARINT); @@ -1308,61 +1349,59 @@ void getInitialUserDefinedTypeList(USERDEFINEDTYPELIST** anew) addUserDefinedType(list, usertype); *anew = list; - } - /** Add a Compound Field type to a structure definition. -* -* @param str The structure definition. -* @param field The Compound field type. -* @return void. -*/ + * + * @param str The structure definition. + * @param field The Compound field type. + * @return void. + */ void addCompoundField(USERDEFINEDTYPE* str, COMPOUNDFIELD field) { - str->compoundfield = (COMPOUNDFIELD*)realloc((void*)str->compoundfield, - (str->fieldcount + 1) * sizeof(COMPOUNDFIELD)); + str->compoundfield = + (COMPOUNDFIELD*)realloc((void*)str->compoundfield, (str->fieldcount + 1) * sizeof(COMPOUNDFIELD)); initCompoundField(&str->compoundfield[str->fieldcount]); str->compoundfield[str->fieldcount++] = field; } /** Add a structure definition to the List of structure types -* -* @param str The list of structure definitions. -* @param type The new definition to add to the list. -* @return void. -*/ + * + * @param str The list of structure definitions. + * @param type The new definition to add to the list. + * @return void. + */ void addUserDefinedType(USERDEFINEDTYPELIST* str, USERDEFINEDTYPE type) { - str->userdefinedtype = (USERDEFINEDTYPE*)realloc((void*)str->userdefinedtype, - (str->listCount + 1) * sizeof(USERDEFINEDTYPE)); + str->userdefinedtype = + (USERDEFINEDTYPE*)realloc((void*)str->userdefinedtype, (str->listCount + 1) * sizeof(USERDEFINEDTYPE)); initUserDefinedType(&str->userdefinedtype[str->listCount]); str->userdefinedtype[str->listCount++] = type; } /** Replace the structure definition list with an different structure type. -* -* @param str The list of structure definitions. -* @param typeId The definition list entry to be replaced -* @param type The definition to add into the list. -* @return void. -*/ + * + * @param str The list of structure definitions. + * @param typeId The definition list entry to be replaced + * @param type The definition to add into the list. + * @return void. + */ void updateUserDefinedType(USERDEFINEDTYPELIST* str, int typeId, USERDEFINEDTYPE type) { - str->userdefinedtype[typeId] = type; // replace existing entry + str->userdefinedtype[typeId] = type; // replace existing entry } /** Change a structure element's property in the structure definition -* -* @param str The list of structure definitions. -* @param typeId The definition list entry to be modified -* @param element The structure element to be modified -* @param property The structure element's definition property to be modified -* @param value The new property value -* @return void. -*/ -void -changeUserDefinedTypeElementProperty(USERDEFINEDTYPELIST* str, int typeId, char* element, char* property, void* value) + * + * @param str The list of structure definitions. + * @param typeId The definition list entry to be modified + * @param element The structure element to be modified + * @param property The structure element's definition property to be modified + * @param value The new property value + * @return void. + */ +void changeUserDefinedTypeElementProperty(USERDEFINEDTYPELIST* str, int typeId, char* element, char* property, + void* value) { USERDEFINEDTYPE* userdefinedtype = str->userdefinedtype; // Target this definition for (int i = 0; i < userdefinedtype[typeId].fieldcount; i++) { @@ -1380,37 +1419,40 @@ changeUserDefinedTypeElementProperty(USERDEFINEDTYPELIST* str, int typeId, char* } } - /** The number of Structure Definitions or User Defined Types in the structure list -* -* @param str The list of structure definitions. -* @return The count of structured types. -*/ + * + * @param str The list of structure definitions. + * @return The count of structured types. + */ int countUserDefinedType(USERDEFINEDTYPELIST* str) { - return str->listCount; // Number of user defined types + return str->listCount; // Number of user defined types } /** Free heap from a Compound Field. -* -* @param str The Compound Field. -* @return void. -*/ + * + * @param str The Compound Field. + * @return void. + */ void freeCompoundField(COMPOUNDFIELD* str) { - if (str == nullptr) return; + if (str == nullptr) { + return; + } free(str->shape); str->shape = nullptr; } /** Free heap from a User Defined Type. -* -* @param type The User Defined Type. -* @return void. -*/ + * + * @param type The User Defined Type. + * @return void. + */ void freeUserDefinedType(USERDEFINEDTYPE* type) { - if (type == nullptr) return; + if (type == nullptr) { + return; + } for (int i = 0; i < type->fieldcount; i++) { freeCompoundField(&type->compoundfield[i]); } @@ -1422,10 +1464,10 @@ void freeUserDefinedType(USERDEFINEDTYPE* type) } /** Free heap from a User Defined Type List. -* -* @param userdefinedtypelist The User Defined Type List. -* @return void. -*/ + * + * @param userdefinedtypelist The User Defined Type List. + * @return void. + */ void freeUserDefinedTypeList(USERDEFINEDTYPELIST* userdefinedtypelist) { if (userdefinedtypelist == nullptr) { @@ -1445,10 +1487,10 @@ void freeUserDefinedTypeList(USERDEFINEDTYPELIST* userdefinedtypelist) } /** The size or byte count of an atomic or structured type -* -* @param type The name of the type -* @return The size in bytes. -*/ + * + * @param type The name of the type + * @return The size in bytes. + */ size_t getsizeof(USERDEFINEDTYPELIST* userdefinedtypelist, const char* type) { USERDEFINEDTYPE* udt; @@ -1463,27 +1505,69 @@ size_t getsizeof(USERDEFINEDTYPELIST* userdefinedtypelist, const char* type) } } - if (!strcasecmp(base, "FLOAT")) return sizeof(float); - if (!strcasecmp(base, "DOUBLE")) return sizeof(double); - if (!strcasecmp(base, "CHAR")) return sizeof(char); - if (!strcasecmp(base, "UNSIGNED CHAR")) return sizeof(unsigned char); - if (!strcasecmp(base, "UCHAR")) return sizeof(unsigned char); - if (!strcasecmp(base, "STRING")) return sizeof(char); // Same as char array but null terminated - if (!strcasecmp(base, "SHORT")) return sizeof(short); - if (!strcasecmp(base, "UNSIGNED SHORT")) return sizeof(unsigned short); - if (!strcasecmp(base, "USHORT")) return sizeof(unsigned short); - if (!strcasecmp(base, "INT")) return sizeof(int); - if (!strcasecmp(base, "UNSIGNED INT")) return sizeof(unsigned int); - if (!strcasecmp(base, "UINT")) return sizeof(unsigned int); - if (!strcasecmp(base, "LONG")) return sizeof(long); - if (!strcasecmp(base, "UNSIGNED LONG")) return sizeof(unsigned long); - if (!strcasecmp(base, "ULONG")) return sizeof(unsigned long); - if (!strcasecmp(base, "LONG LONG")) return sizeof(long long); - if (!strcasecmp(base, "UNSIGNED LONG LONG")) return sizeof(unsigned long long); - if (!strcasecmp(base, "LONG64")) return sizeof(long long); - if (!strcasecmp(base, "ULONG64")) return sizeof(unsigned long long); - if (!strcasecmp(base, "COMPLEX")) return 2 * sizeof(float); - if (!strcasecmp(base, "DCOMPLEX")) return 2 * sizeof(double); // Always aligned on correct byte boundary + if (!strcasecmp(base, "FLOAT")) { + return sizeof(float); + } + if (!strcasecmp(base, "DOUBLE")) { + return sizeof(double); + } + if (!strcasecmp(base, "CHAR")) { + return sizeof(char); + } + if (!strcasecmp(base, "UNSIGNED CHAR")) { + return sizeof(unsigned char); + } + if (!strcasecmp(base, "UCHAR")) { + return sizeof(unsigned char); + } + if (!strcasecmp(base, "STRING")) { + return sizeof(char); // Same as char array but null terminated + } + if (!strcasecmp(base, "SHORT")) { + return sizeof(short); + } + if (!strcasecmp(base, "UNSIGNED SHORT")) { + return sizeof(unsigned short); + } + if (!strcasecmp(base, "USHORT")) { + return sizeof(unsigned short); + } + if (!strcasecmp(base, "INT")) { + return sizeof(int); + } + if (!strcasecmp(base, "UNSIGNED INT")) { + return sizeof(unsigned int); + } + if (!strcasecmp(base, "UINT")) { + return sizeof(unsigned int); + } + if (!strcasecmp(base, "LONG")) { + return sizeof(long); + } + if (!strcasecmp(base, "UNSIGNED LONG")) { + return sizeof(unsigned long); + } + if (!strcasecmp(base, "ULONG")) { + return sizeof(unsigned long); + } + if (!strcasecmp(base, "LONG LONG")) { + return sizeof(long long); + } + if (!strcasecmp(base, "UNSIGNED LONG LONG")) { + return sizeof(unsigned long long); + } + if (!strcasecmp(base, "LONG64")) { + return sizeof(long long); + } + if (!strcasecmp(base, "ULONG64")) { + return sizeof(unsigned long long); + } + if (!strcasecmp(base, "COMPLEX")) { + return 2 * sizeof(float); + } + if (!strcasecmp(base, "DCOMPLEX")) { + return 2 * sizeof(double); // Always aligned on correct byte boundary + } // Search list of User defined types for size @@ -1499,73 +1583,121 @@ size_t getsizeof(USERDEFINEDTYPELIST* userdefinedtypelist, const char* type) } /** The value of the IDAM enumeration type for a named regular atomic type -* -* @param type The name of the atomic type -* @return The integer value of the corresponding IDAM enumeration. -*/ + * + * @param type The name of the atomic type + * @return The integer value of the corresponding IDAM enumeration. + */ int gettypeof(const char* type) -{ // **** const unsigned .... - if (type == nullptr) return UDA_TYPE_UNKNOWN; - if (!strcasecmp(type, "FLOAT")) return UDA_TYPE_FLOAT; - if (!strcasecmp(type, "DOUBLE")) return UDA_TYPE_DOUBLE; - if (!strcasecmp(type, "CHAR")) return UDA_TYPE_CHAR; - if (!strcasecmp(type, "SHORT")) return UDA_TYPE_SHORT; - if (!strcasecmp(type, "INT")) return UDA_TYPE_INT; - if (!strcasecmp(type, "LONG")) return UDA_TYPE_LONG; - if (!strcasecmp(type, "LONG64")) return UDA_TYPE_LONG64; - if (!strcasecmp(type, "LONG LONG"))return UDA_TYPE_LONG64; - if (!strcasecmp(type, "COMPLEX")) return UDA_TYPE_COMPLEX; - if (!strcasecmp(type, "DCOMPLEX")) return UDA_TYPE_DCOMPLEX; - if (!strcasecmp(type, "STRING")) return UDA_TYPE_STRING; - if (!strcasecmp(type, "VOID")) return UDA_TYPE_VOID; - - if (!strcasecmp(type, "UCHAR")) return UDA_TYPE_UNSIGNED_CHAR; - if (!strcasecmp(type, "USHORT")) return UDA_TYPE_UNSIGNED_SHORT; - if (!strcasecmp(type, "UINT")) return UDA_TYPE_UNSIGNED_INT; - if (!strcasecmp(type, "ULONG")) return UDA_TYPE_UNSIGNED_LONG; +{ // **** const unsigned .... + if (type == nullptr) { + return UDA_TYPE_UNKNOWN; + } + if (!strcasecmp(type, "FLOAT")) { + return UDA_TYPE_FLOAT; + } + if (!strcasecmp(type, "DOUBLE")) { + return UDA_TYPE_DOUBLE; + } + if (!strcasecmp(type, "CHAR")) { + return UDA_TYPE_CHAR; + } + if (!strcasecmp(type, "SHORT")) { + return UDA_TYPE_SHORT; + } + if (!strcasecmp(type, "INT")) { + return UDA_TYPE_INT; + } + if (!strcasecmp(type, "LONG")) { + return UDA_TYPE_LONG; + } + if (!strcasecmp(type, "LONG64")) { + return UDA_TYPE_LONG64; + } + if (!strcasecmp(type, "LONG LONG")) { + return UDA_TYPE_LONG64; + } + if (!strcasecmp(type, "COMPLEX")) { + return UDA_TYPE_COMPLEX; + } + if (!strcasecmp(type, "DCOMPLEX")) { + return UDA_TYPE_DCOMPLEX; + } + if (!strcasecmp(type, "STRING")) { + return UDA_TYPE_STRING; + } + if (!strcasecmp(type, "VOID")) { + return UDA_TYPE_VOID; + } + + if (!strcasecmp(type, "UCHAR")) { + return UDA_TYPE_UNSIGNED_CHAR; + } + if (!strcasecmp(type, "USHORT")) { + return UDA_TYPE_UNSIGNED_SHORT; + } + if (!strcasecmp(type, "UINT")) { + return UDA_TYPE_UNSIGNED_INT; + } + if (!strcasecmp(type, "ULONG")) { + return UDA_TYPE_UNSIGNED_LONG; + } #ifndef __APPLE__ - if (!strcasecmp(type, "ULONG64")) return UDA_TYPE_UNSIGNED_LONG64; + if (!strcasecmp(type, "ULONG64")) { + return UDA_TYPE_UNSIGNED_LONG64; + } #endif - if (!strcasecmp(type, "UNSIGNED CHAR")) return UDA_TYPE_UNSIGNED_CHAR; - if (!strcasecmp(type, "UNSIGNED SHORT")) return UDA_TYPE_UNSIGNED_SHORT; - if (!strcasecmp(type, "UNSIGNED INT")) return UDA_TYPE_UNSIGNED_INT; - if (!strcasecmp(type, "UNSIGNED LONG")) return UDA_TYPE_UNSIGNED_LONG; + if (!strcasecmp(type, "UNSIGNED CHAR")) { + return UDA_TYPE_UNSIGNED_CHAR; + } + if (!strcasecmp(type, "UNSIGNED SHORT")) { + return UDA_TYPE_UNSIGNED_SHORT; + } + if (!strcasecmp(type, "UNSIGNED INT")) { + return UDA_TYPE_UNSIGNED_INT; + } + if (!strcasecmp(type, "UNSIGNED LONG")) { + return UDA_TYPE_UNSIGNED_LONG; + } #ifndef __APPLE__ - if (!strcasecmp(type, "UNSIGNED LONG64")) return UDA_TYPE_UNSIGNED_LONG64; - if (!strcasecmp(type, "UNSIGNED LONG LONG")) return UDA_TYPE_UNSIGNED_LONG64; + if (!strcasecmp(type, "UNSIGNED LONG64")) { + return UDA_TYPE_UNSIGNED_LONG64; + } + if (!strcasecmp(type, "UNSIGNED LONG LONG")) { + return UDA_TYPE_UNSIGNED_LONG64; + } #endif - return UDA_TYPE_UNKNOWN; // Means Non Atomic => User defined structure type + return UDA_TYPE_UNKNOWN; // Means Non Atomic => User defined structure type } /** Return structure element alignment byte boundary -* -* @param type The name of the structure atomic type. -* @return number of bytes to align with. -* -* Alignment rules are Architecture Dependent: -* Single byte numbers are aligned at a single byte boundary -* Two byte numbers are aligned with two byte boundaries -* Four byte numbers are aligned on four byte boundaries -* Eight byte numbers are aligned on four byte boundaries if 32 bit architecture and Linux -* or 8 byte boundary if 64 bit or 32 bit and Windows. -* Structures are aligned depending on whichever element has the largest alignment boundary. -* -* Structures between 1 and 4 bytes of data should be padded so that the total structure is 4 bytes. -* Structures between 5 and 8 bytes of data should be padded so that the total structure is 8 bytes. -* Structures between 9 and 16 bytes of data should be padded so that the total structure is 16 bytes. -* Structures greater than 16 bytes should be padded to 16 byte boundary. -* -* Indexing into arrays can be speeded up by making the structure size a power of 2. The compiler can then replace the -* multiply (entry = base address + index*size of structure) with a simple shift operation. -* -* -*/ + * + * @param type The name of the structure atomic type. + * @return number of bytes to align with. + * + * Alignment rules are Architecture Dependent: + * Single byte numbers are aligned at a single byte boundary + * Two byte numbers are aligned with two byte boundaries + * Four byte numbers are aligned on four byte boundaries + * Eight byte numbers are aligned on four byte boundaries if 32 bit architecture and Linux + * or 8 byte boundary if 64 bit or 32 bit and Windows. + * Structures are aligned depending on whichever element has the largest alignment boundary. + * + * Structures between 1 and 4 bytes of data should be padded so that the total structure is 4 bytes. + * Structures between 5 and 8 bytes of data should be padded so that the total structure is 8 bytes. + * Structures between 9 and 16 bytes of data should be padded so that the total structure is 16 bytes. + * Structures greater than 16 bytes should be padded to 16 byte boundary. + * + * Indexing into arrays can be speeded up by making the structure size a power of 2. The compiler can then replace the + * multiply (entry = base address + index*size of structure) with a simple shift operation. + * + * + */ int getalignmentof(const char* type) { int is32 = (sizeof(void*) == POINTER_SIZE32); // Test architecture const char* base = type; - if (!strncmp(type, "const", 5) || !strncmp(type, "unsigned", 8)) { // ignore const and unsigned + if (!strncmp(type, "const", 5) || !strncmp(type, "unsigned", 8)) { // ignore const and unsigned const char* p = strrchr(type, ' '); if (p != nullptr) { base = &p[1]; @@ -1577,50 +1709,124 @@ int getalignmentof(const char* type) } } } - if (type == nullptr) return ALIGNMENT; - if (strchr(base, '*'))return sizeof(void*); // Pointer type + if (type == nullptr) { + return ALIGNMENT; + } + if (strchr(base, '*')) { + return sizeof(void*); // Pointer type + } if (is32) { - if (!strcasecmp(base, "FLOAT")) return 4; // 32 bit architecture + if (!strcasecmp(base, "FLOAT")) { + return 4; // 32 bit architecture + } #ifndef WINDOWS - if (!strcasecmp(base, "DOUBLE")) return 4; + if (!strcasecmp(base, "DOUBLE")) { + return 4; + } #else - if (!strcasecmp(base, "DOUBLE")) return 8; + if (!strcasecmp(base, "DOUBLE")) { + return 8; + } #endif - if (!strcasecmp(base, "CHAR")) return 1; - if (!strcasecmp(base, "STRING")) return 1; - if (!strcasecmp(base, "SHORT")) return 2; - if (!strcasecmp(base, "INT")) return 4; - if (!strcasecmp(base, "LONG")) return 4; - if (!strcasecmp(base, "LONG64")) return 4; - if (!strcasecmp(base, "LONG LONG")) return 4; - if (!strcasecmp(base, "UCHAR")) return 1; - if (!strcasecmp(base, "USHORT")) return 2; - if (!strcasecmp(base, "UINT")) return 4; - if (!strcasecmp(base, "ULONG")) return 4; - if (!strcasecmp(base, "ULONG64")) return 4; - if (!strcasecmp(base, "COMPLEX")) return 4; - if (!strcasecmp(base, "DCOMPLEX")) return 4; - if (!strcasecmp(base, "STRUCTURE")) return 1; // Structures are aligned depending on structure content + if (!strcasecmp(base, "CHAR")) { + return 1; + } + if (!strcasecmp(base, "STRING")) { + return 1; + } + if (!strcasecmp(base, "SHORT")) { + return 2; + } + if (!strcasecmp(base, "INT")) { + return 4; + } + if (!strcasecmp(base, "LONG")) { + return 4; + } + if (!strcasecmp(base, "LONG64")) { + return 4; + } + if (!strcasecmp(base, "LONG LONG")) { + return 4; + } + if (!strcasecmp(base, "UCHAR")) { + return 1; + } + if (!strcasecmp(base, "USHORT")) { + return 2; + } + if (!strcasecmp(base, "UINT")) { + return 4; + } + if (!strcasecmp(base, "ULONG")) { + return 4; + } + if (!strcasecmp(base, "ULONG64")) { + return 4; + } + if (!strcasecmp(base, "COMPLEX")) { + return 4; + } + if (!strcasecmp(base, "DCOMPLEX")) { + return 4; + } + if (!strcasecmp(base, "STRUCTURE")) { + return 1; // Structures are aligned depending on structure content + } } else { #ifdef A64 - if (!strcasecmp(base, "FLOAT")) return 4; // 64 bit architecture - if (!strcasecmp(base, "DOUBLE")) return 8; - if (!strcasecmp(base, "CHAR")) return 1; - if (!strcasecmp(base, "STRING")) return 1; - if (!strcasecmp(base, "SHORT")) return 2; - if (!strcasecmp(base, "INT")) return 4; - if (!strcasecmp(base, "LONG")) return 4; - if (!strcasecmp(base, "LONG64")) return 8; - if (!strcasecmp(base, "LONG LONG")) return 8; - if (!strcasecmp(base, "UCHAR")) return 1; - if (!strcasecmp(base, "USHORT")) return 2; - if (!strcasecmp(base, "UINT")) return 4; - if (!strcasecmp(base, "ULONG")) return 4; - if (!strcasecmp(base, "ULONG64")) return 8; - if (!strcasecmp(base, "COMPLEX")) return 4; - if (!strcasecmp(base, "DCOMPLEX")) return 8; - if (!strcasecmp(base, "STRUCTURE")) return 1; + if (!strcasecmp(base, "FLOAT")) { + return 4; // 64 bit architecture + } + if (!strcasecmp(base, "DOUBLE")) { + return 8; + } + if (!strcasecmp(base, "CHAR")) { + return 1; + } + if (!strcasecmp(base, "STRING")) { + return 1; + } + if (!strcasecmp(base, "SHORT")) { + return 2; + } + if (!strcasecmp(base, "INT")) { + return 4; + } + if (!strcasecmp(base, "LONG")) { + return 4; + } + if (!strcasecmp(base, "LONG64")) { + return 8; + } + if (!strcasecmp(base, "LONG LONG")) { + return 8; + } + if (!strcasecmp(base, "UCHAR")) { + return 1; + } + if (!strcasecmp(base, "USHORT")) { + return 2; + } + if (!strcasecmp(base, "UINT")) { + return 4; + } + if (!strcasecmp(base, "ULONG")) { + return 4; + } + if (!strcasecmp(base, "ULONG64")) { + return 8; + } + if (!strcasecmp(base, "COMPLEX")) { + return 4; + } + if (!strcasecmp(base, "DCOMPLEX")) { + return 8; + } + if (!strcasecmp(base, "STRUCTURE")) { + return 1; + } #endif } return ALIGNMENT; // Best Guess! @@ -1639,10 +1845,10 @@ size_t padding(size_t offset, const char* type) } /** The name of an atomic type corresponding to a value of the IDAM enumeration type. -* -* @param type The integer value of the type enumeration. -* @return The name of the atomic type. -*/ + * + * @param type The integer value of the type enumeration. + * @return The name of the atomic type. + */ const char* udaNameType(UDA_TYPE type) { switch (type) { @@ -1678,10 +1884,10 @@ const char* udaNameType(UDA_TYPE type) } /** The size or byte count of a user defined structured type. -* -* @param str The user defined structure definition. -* @return The size in bytes. -*/ + * + * @param str The user defined structure definition. + * @return The size in bytes. + */ size_t getStructureSize(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* str) { size_t size; @@ -1724,7 +1930,7 @@ size_t getStructureSize(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYP maxAlign = alignment; } - space0 = space; // Retain Previous values + space0 = space; // Retain Previous values } // Add any additional structure packing to align the structure @@ -1739,14 +1945,14 @@ size_t getStructureSize(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYP } /** Print an error message. -* -* @param fd The output file descriptor pointer. -* @param warning Print a warning message rather than an error message. -* @param line The line number where the error occured. -* @param file The file name where the error occured. -* @param msg The message to print. -* @return The size in bytes. -*/ + * + * @param fd The output file descriptor pointer. + * @param warning Print a warning message rather than an error message. + * @param line The line number where the error occured. + * @param file The file name where the error occured. + * @param msg The message to print. + * @return The size in bytes. + */ void printError(int warning, int line, char* file, char* msg) { if (warning) { @@ -1756,11 +1962,9 @@ void printError(int warning, int line, char* file, char* msg) } } - //============================================================================================================== // Functions to Send or Receive Data contained in User Defined Structures - // Send or Receive the Data Structure // Recursive Send/Receive Individual User Defined Structure Elements @@ -1789,21 +1993,29 @@ int xdrAtomicData(LOGMALLOCLIST* logmalloclist, XDR* xdrs, const char* type, int #ifdef DEBUG2 if (xdrs->x_op != XDR_DECODE) { int rc; - switch(type_id) { - case(UDA_TYPE_FLOAT): - for (rc=0; rcx_op == XDR_DECODE) { int rc; - switch(type_id) { - case(UDA_TYPE_FLOAT): - for (rc=0; rcx_op == XDR_DECODE) { NTREE* dataNTree = nullptr; if (!xdr_stdio_flag) { - rc = xdrrec_skiprecord(xdrs); // Receiving + rc = xdrrec_skiprecord(xdrs); // Receiving } else { rc = 1; } - rc = rc && xdr_userdefinedtype(xdrs, userdefinedtypelist, userdefinedtype); // User Defined Type Definitions - rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, nullptr, 0, - &dataNTree, protocolVersion, malloc_source); // Data within Structures + rc = rc && xdr_userdefinedtype(xdrs, userdefinedtypelist, userdefinedtype); // User Defined Type Definitions + rc = rc && + xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, + nullptr, 0, &dataNTree, protocolVersion, malloc_source); // Data within Structures udaSetFullNTree(dataNTree); // Copy to Global } else { @@ -1895,26 +2116,25 @@ int xdrUserDefinedTypeData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, USERDEFINEDT return 0; } - rc = xdr_userdefinedtype(xdrs, userdefinedtypelist, userdefinedtype); // User Defined Type Definitions - rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, nullptr, 0, - nullptr, protocolVersion, malloc_source); // Data within Structures + rc = xdr_userdefinedtype(xdrs, userdefinedtypelist, userdefinedtype); // User Defined Type Definitions + rc = rc && + xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, userdefinedtype, data, 1, 0, + nullptr, 0, nullptr, protocolVersion, malloc_source); // Data within Structures if (!xdr_stdio_flag) { rc = rc && xdrrec_endofrecord(xdrs, 1); } - } - freeLogStructList(log_struct_list); // Free Linked List Structure Log heap + freeLogStructList(log_struct_list); // Free Linked List Structure Log heap return rc; } - int findUserDefinedTypeId(USERDEFINEDTYPELIST* userdefinedtypelist, const char* name) { -// Return the List Index key for a Named User Defined Structure + // Return the List Index key for a Named User Defined Structure for (int i = 0; i < userdefinedtypelist->listCount; i++) { if (!strcmp(userdefinedtypelist->userdefinedtype[i].name, name)) { @@ -1922,15 +2142,19 @@ int findUserDefinedTypeId(USERDEFINEDTYPELIST* userdefinedtypelist, const char* } } #ifdef INCLUDESTRUCTPREFIX - if (!strncmp(name, "struct ", 7)) { // search without the struct prefix - for (i=0; ilistCount; i++) { - if (!strcmp(userdefinedtypelist->userdefinedtype[i].name, &name[7])) return(i); + if (!strncmp(name, "struct ", 7)) { // search without the struct prefix + for (i = 0; i < userdefinedtypelist->listCount; i++) { + if (!strcmp(userdefinedtypelist->userdefinedtype[i].name, &name[7])) { + return (i); + } } } else { - char work[MAXELEMENTNAME+25] = "struct "; // search with the struct prefix + char work[MAXELEMENTNAME + 25] = "struct "; // search with the struct prefix strcat(work, name); - for (i=0; ilistCount; i++) { - if (!strcmp(userdefinedtypelist->userdefinedtype[i].name, work)) return(i); + for (i = 0; i < userdefinedtypelist->listCount; i++) { + if (!strcmp(userdefinedtypelist->userdefinedtype[i].name, work)) { + return (i); + } } } #endif @@ -1945,7 +2169,9 @@ USERDEFINEDTYPE* findUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, c UDA_LOG(UDA_LOG_DEBUG, "ref_id: %d\n", ref_id); UDA_LOG(UDA_LOG_DEBUG, "listCount: %d\n", userdefinedtypelist->listCount); - if (name == nullptr) return nullptr; + if (name == nullptr) { + return nullptr; + } if (ref_id > 0 && name[0] != '\0') { for (int i = 0; i < userdefinedtypelist->listCount; i++) { @@ -1987,7 +2213,9 @@ int testUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYP USERDEFINEDTYPE* test; - if (udt == nullptr) return 0; + if (udt == nullptr) { + return 0; + } for (int i = 0; i < userdefinedtypelist->listCount; i++) { test = &userdefinedtypelist->userdefinedtype[i]; if (test == udt) { @@ -1997,14 +2225,13 @@ int testUserDefinedType(USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYP return 0; } - //============================================================================================================== // Functions to Send or Receive Definitions of User Defined Structure bool_t xdr_compoundfield(XDR* xdrs, COMPOUNDFIELD* str) { -// Send/Receive individual compound types + // Send/Receive individual compound types int rc; rc = xdr_int(xdrs, &str->size); @@ -2018,7 +2245,9 @@ bool_t xdr_compoundfield(XDR* xdrs, COMPOUNDFIELD* str) rc = rc && WrapXDRString(xdrs, (char*)str->type, MAXELEMENTNAME - 1); rc = rc && WrapXDRString(xdrs, (char*)str->name, MAXELEMENTNAME - 1); rc = rc && WrapXDRString(xdrs, (char*)str->desc, MAXELEMENTNAME - 1); - if (!rc) return 0; + if (!rc) { + return 0; + } if (str->rank > 1) { // Only necessary to pass shape if the rank > 1 if (rc && xdrs->x_op == XDR_DECODE) { @@ -2035,7 +2264,6 @@ bool_t xdr_compoundfield(XDR* xdrs, COMPOUNDFIELD* str) return rc; } - bool_t xdr_userdefinedtype(XDR* xdrs, USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* str) { // Send/Receive a single user defined type @@ -2046,13 +2274,13 @@ bool_t xdr_userdefinedtype(XDR* xdrs, USERDEFINEDTYPELIST* userdefinedtypelist, rc = rc && WrapXDRString(xdrs, (char*)str->name, MAXELEMENTNAME - 1); rc = rc && WrapXDRString(xdrs, (char*)str->source, MAXELEMENTNAME - 1); rc = rc && xdr_int(xdrs, &str->ref_id); - rc = rc && xdr_int(xdrs, &str->size); // Size determined on the server side: client must recalculate + rc = rc && xdr_int(xdrs, &str->size); // Size determined on the server side: client must recalculate rc = rc && xdr_int(xdrs, &str->imagecount); rc = rc && xdr_int(xdrs, &str->fieldcount); printUserDefinedType(*str); - if (xdrs->x_op == XDR_DECODE) { // Receiving an array so allocate Heap for it then initialise + if (xdrs->x_op == XDR_DECODE) { // Receiving an array so allocate Heap for it then initialise if (str->imagecount > 0) { str->image = (char*)malloc(str->imagecount * sizeof(char)); } else { @@ -2117,8 +2345,9 @@ bool_t xdr_userdefinedtype(XDR* xdrs, USERDEFINEDTYPELIST* userdefinedtypelist, offset = newoffset(offset + space0, "*"); } else { offpad = padding(offset + space0, str->compoundfield[i].type); - offset = newoffset(offset + space0, - str->compoundfield[i].type); // Non-atomic types (structures) will already have been adjusted + offset = newoffset( + offset + space0, + str->compoundfield[i].type); // Non-atomic types (structures) will already have been adjusted } } else { offpad = 0; @@ -2136,7 +2365,7 @@ bool_t xdr_userdefinedtype(XDR* xdrs, USERDEFINEDTYPELIST* userdefinedtypelist, maxAlign = alignment; } - space0 = space; // Retain Previous values + space0 = space; // Retain Previous values } // Add any additional structure packing to align the structure @@ -2171,9 +2400,11 @@ bool_t xdr_userdefinedtypelist(XDR* xdrs, USERDEFINEDTYPELIST* str, bool xdr_std UDA_LOG(UDA_LOG_DEBUG, "xdr_userdefinedtypelist: rc = %d, listCount = %d\n", rc, str->listCount); - if (!rc || str->listCount == 0) return rc; + if (!rc || str->listCount == 0) { + return rc; + } - if (xdrs->x_op == XDR_DECODE) { // Receiving array so allocate Heap for it then initialise + if (xdrs->x_op == XDR_DECODE) { // Receiving array so allocate Heap for it then initialise str->userdefinedtype = (USERDEFINEDTYPE*)malloc(str->listCount * sizeof(USERDEFINEDTYPE)); for (int i = 0; i < str->listCount; i++) { initUserDefinedType(&str->userdefinedtype[i]); @@ -2197,16 +2428,15 @@ bool_t xdr_userdefinedtypelist(XDR* xdrs, USERDEFINEDTYPELIST* str, bool xdr_std //---------------------------------------------------------------------------------------------------------- // Client Utility functions operating on Linked List N-Tree - /** Print the data from an array of Atomic Type to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param data A pointer to the data. -* @param atomictype The name of a Atomic type. -* @param count The array element count. -* @param label A label to print before the value. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param data A pointer to the data. + * @param atomictype The name of a Atomic type. + * @param count The array element count. + * @param label A label to print before the value. + * @return Void + */ void printAtomicData(void* data, int atomictype, int count, const char* label) { if (data == nullptr || count == 0) { @@ -2316,7 +2546,9 @@ void printAtomicData(void* data, int atomictype, int count, const char* label) unsigned long long* d = (unsigned long long*)data; if (count > 1) { UDA_LOG(UDA_LOG_DEBUG, "%40s:\n", label); - for (int i = 0; i < count; i++)UDA_LOG(UDA_LOG_DEBUG, "[%d] %llu\n", i, d[i]); + for (int i = 0; i < count; i++) { + UDA_LOG(UDA_LOG_DEBUG, "[%d] %llu\n", i, d[i]); + } } else { UDA_LOG(UDA_LOG_DEBUG, "%40s: %llu\n", label, d[0]); } @@ -2336,15 +2568,15 @@ void printAtomicData(void* data, int atomictype, int count, const char* label) } /** Print the data from a named array of Atomic Type from a given tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. -* @param target The name of a User Defined Structure type. -* @return Void -* -* \todo {When the structure is an array, either print data from a single array element or print data from -* all structure elements} -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. + * @param target The name of a User Defined Structure type. + * @return Void + * + * \todo {When the structure is an array, either print data from a single array element or print data from + * all structure elements} + */ void printAtomicType(LOGMALLOCLIST* logmalloclist, NTREE* tree, const char* target) { USERDEFINEDTYPE* userdefinedtype = tree->userdefinedtype; @@ -2356,7 +2588,7 @@ void printAtomicType(LOGMALLOCLIST* logmalloclist, NTREE* tree, const char* targ if (userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { p = (char*)tree->data; if (userdefinedtype->compoundfield[i].pointer || - !strcmp(userdefinedtype->compoundfield[i].type, "STRING *")) { // Strings are an exception! + !strcmp(userdefinedtype->compoundfield[i].type, "STRING *")) { // Strings are an exception! int count, size; const char* type; data = (void*)*((VOIDTYPE*)&p[userdefinedtype->compoundfield[i].offset]); @@ -2383,12 +2615,12 @@ void printAtomicType(LOGMALLOCLIST* logmalloclist, NTREE* tree, const char* targ } /** Print the Count of elements of a named data array from a given tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param ntree A pointer to a tree node. -* @param target The name of a Structure element. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param ntree A pointer to a tree node. + * @param target The name of a Structure element. + * @return Void + */ void printTypeCount(NTREE* ntree, const char* target) { USERDEFINEDTYPE* userdefinedtype = ntree->userdefinedtype; @@ -2409,11 +2641,11 @@ void printTypeCount(NTREE* ntree, const char* target) // Node Data Structure Component /** Return a pointer to a User Defined Structure Component Structure. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a Structure Element. -* @return the Structure Element Definition Structure. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a Structure Element. + * @return the Structure Element Definition Structure. + */ COMPOUNDFIELD* getNodeStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { USERDEFINEDTYPE* userdefinedtype; @@ -2442,15 +2674,15 @@ COMPOUNDFIELD* getNodeStructureComponent(LOGMALLOCLIST* logmalloclist, NTREE* nt // Tree Node Family: Single tree node is in scope /** Return a Pointer to a string array containing the hierarchical names of structure components. -* -* @param target The name of a User Defined Structure element (case sensitive). -* @param ntargets A returned count of the number of names in the returned list. -* @return the list of structure component names. -*/ + * + * @param target The name of a User Defined Structure element (case sensitive). + * @param ntargets A returned count of the number of names in the returned list. + * @return the list of structure component names. + */ char** parseTarget(const char* target, int* ntargets) { char** targetlist = nullptr; - char* buffer = nullptr, * work, * p; + char *buffer = nullptr, *work, *p; buffer = (char*)malloc((strlen(target) + 1) * sizeof(char)); strcpy(buffer, target); work = buffer; @@ -2476,7 +2708,7 @@ char** parseTarget(const char* target, int* ntargets) *ntargets = *ntargets + 1; } while (p != nullptr); } - if (*ntargets == 0) { // Return the target even if not hierarchical + if (*ntargets == 0) { // Return the target even if not hierarchical *ntargets = 1; targetlist = (char**)malloc(sizeof(char*)); targetlist[0] = buffer; @@ -2488,11 +2720,11 @@ char** parseTarget(const char* target, int* ntargets) } /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNode(NTREE* tree) { if (tree == nullptr) { @@ -2508,21 +2740,21 @@ void printNode(NTREE* tree) (UVOIDTYPE)tree->children[i]); } #else - UDA_LOG(UDA_LOG_DEBUG, "Parent : %p (%x) \n", (void *)tree->parent, (UVOIDTYPE)tree->parent); + UDA_LOG(UDA_LOG_DEBUG, "Parent : %p (%x) \n", (void*)tree->parent, (UVOIDTYPE)tree->parent); for (int i = 0; i < tree->branches; i++) { - UDA_LOG(UDA_LOG_DEBUG, "Children[%d]: %p (%x) \n", i, (void *)tree->children[i], (UVOIDTYPE)tree->children[i]); + UDA_LOG(UDA_LOG_DEBUG, "Children[%d]: %p (%x) \n", i, (void*)tree->children[i], (UVOIDTYPE)tree->children[i]); } #endif printUserDefinedType(*tree->userdefinedtype); } /** Print the Contents of a tree node with the specified User Defined Structure name to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param target The name of a User Defined Structure type. If an null string is passed, the structure -* of the root node is used. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param target The name of a User Defined Structure type. If an null string is passed, the structure + * of the root node is used. + * @return Void + */ void printNodeStructureDefinition(const char* target) { NTREE* ntree = nullptr; @@ -2536,11 +2768,11 @@ void printNodeStructureDefinition(const char* target) } /** Print an Image of the Named Structure Definition to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param target The name of a User Defined Structure type. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param target The name of a User Defined Structure type. + * @return Void + */ void printNodeStructureImage(const char* target) { @@ -2556,12 +2788,11 @@ void printNodeStructureImage(const char* target) } } - /** Return a Pointer to the User Defined Type Structure of the data attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the User Defined Type Structure Definition. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the User Defined Type Structure Definition. + */ USERDEFINEDTYPE* getNodeUserDefinedType(NTREE* ntree) { @@ -2572,10 +2803,10 @@ USERDEFINEDTYPE* getNodeUserDefinedType(NTREE* ntree) } /** Return the name of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the name of the User Defined Type Structure. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the name of the User Defined Type Structure. + */ char* getNodeStructureName(NTREE* ntree) { if (ntree == nullptr) { @@ -2585,10 +2816,10 @@ char* getNodeStructureName(NTREE* ntree) } /** Return the Type of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Type of the User Defined Type Structure. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Type of the User Defined Type Structure. + */ char* getNodeStructureType(NTREE* ntree) { if (ntree == nullptr) { @@ -2598,10 +2829,10 @@ char* getNodeStructureType(NTREE* ntree) } /** Return the Size of the User Defined Type Structure. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Size (Bytes) of the User Defined Type Structure. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Size (Bytes) of the User Defined Type Structure. + */ int getNodeStructureSize(NTREE* ntree) { if (ntree == nullptr) { @@ -2611,11 +2842,11 @@ int getNodeStructureSize(NTREE* ntree) } /** Return a pointer to a Tree Nodes's Data Structure Array element. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param index The array index -* @return a Pointer to a Structure Array element. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param index The array index + * @return a Pointer to a Structure Array element. + */ void* getNodeStructureArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, int index) { char* p; @@ -2623,7 +2854,9 @@ void* getNodeStructureArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, int addIdamError(UDA_CODE_ERROR_TYPE, "getNodeStructureArrayData", 999, "The Tree Node array index < 0"); return nullptr; } - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } if (getNodeStructureDataCount(logmalloclist, ntree) < (index + 1)) { addIdamError(UDA_CODE_ERROR_TYPE, "getNodeStructureArrayData", 999, "The Tree Node array index > allocated array dimension"); @@ -2634,16 +2867,15 @@ void* getNodeStructureArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, int } /** Return a pointer to a Component Data Structure Array element. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of the Structure Array element. -* @param structureindex The Array index -* @param componentindex The structure element index -* @return a Pointer to a Component Structure Array element. -*/ -void* -getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, int structureindex, - int componentindex) + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of the Structure Array element. + * @param structureindex The Array index + * @param componentindex The structure element index + * @return a Pointer to a Component Structure Array element. + */ +void* getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, + int structureindex, int componentindex) { int offset, count, size; char* p; @@ -2658,22 +2890,28 @@ getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, c "The Tree Node Structure Component array index < 0"); return nullptr; } - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } - if ((pp = (char*)getNodeStructureArrayData(logmalloclist, ntree, structureindex)) == nullptr) return nullptr; + if ((pp = (char*)getNodeStructureArrayData(logmalloclist, ntree, structureindex)) == nullptr) { + return nullptr; + } for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) { if (!strcmp(ntree->userdefinedtype->compoundfield[i].name, target)) { offset = ntree->userdefinedtype->compoundfield[i].offset; if (ntree->userdefinedtype->compoundfield[i].pointer) { - p = (char*)*((VOIDTYPE*)&pp[offset]); // Data Element from the single Structure Array Element + p = (char*)*((VOIDTYPE*)&pp[offset]); // Data Element from the single Structure Array Element findMalloc(logmalloclist, p, &count, &size, &type); } else { p = &pp[offset]; size = ntree->userdefinedtype->compoundfield[i].size; count = ntree->userdefinedtype->compoundfield[i].count; } - if (size == 0) return nullptr; + if (size == 0) { + return nullptr; + } if (count <= componentindex) { addIdamError(UDA_CODE_ERROR_TYPE, "getNodeStructureComponentArrayData", 999, "The Tree Node Structure Component array index > allocated array dimension"); @@ -2688,10 +2926,10 @@ getNodeStructureComponentArrayData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, c } /** Return the count of child User Defined Type Structures (elements of this structure). -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the name of the User Defined Type Structure. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the name of the User Defined Type Structure. + */ int getNodeChildrenCount(NTREE* ntree) { if (ntree == nullptr) { @@ -2701,11 +2939,11 @@ int getNodeChildrenCount(NTREE* ntree) } /** Return a Child Node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param child A integer index identifying which child from the child array to return -* @return the Child Node. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param child A integer index identifying which child from the child array to return + * @return the Child Node. + */ NTREE* getNodeChild(NTREE* ntree, int child) { if (ntree == nullptr) { @@ -2718,11 +2956,11 @@ NTREE* getNodeChild(NTREE* ntree, int child) } /** Return a Child Node'd ID (Branch index value). -* -* @param ntree A pointer to a Parent tree node. If nullptr the root node is assumed. -* @param child A ipointer to a Child tree node. -* @return the Child Node's ID. -*/ + * + * @param ntree A pointer to a Parent tree node. If nullptr the root node is assumed. + * @param child A ipointer to a Child tree node. + * @return the Child Node's ID. + */ int getNodeChildId(NTREE* ntree, NTREE* child) { if (ntree == nullptr) { @@ -2743,10 +2981,10 @@ int getNodeChildId(NTREE* ntree, NTREE* child) } /** Return a Pointer to the children of this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Array of children. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Array of children. + */ NTREE** getNodeChildren(NTREE* ntree) { @@ -2757,10 +2995,10 @@ NTREE** getNodeChildren(NTREE* ntree) } /** Return the parent Node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Parent Node. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Parent Node. + */ NTREE* getNodeParent(NTREE* ntree) { if (ntree == nullptr) { @@ -2769,12 +3007,11 @@ NTREE* getNodeParent(NTREE* ntree) return ntree->parent; } - /** Return the Data pointer. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return a Pointer to the Data. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return a Pointer to the Data. + */ void* getNodeData(NTREE* ntree) { if (ntree == nullptr) { @@ -2783,12 +3020,11 @@ void* getNodeData(NTREE* ntree) return ntree->data; } - /** Return a Count of Structured Component Types attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Count of Structured types. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Count of Structured types. + */ int getNodeStructureCount(NTREE* ntree) { @@ -2805,15 +3041,17 @@ int getNodeStructureCount(NTREE* ntree) } /** Return a Count of Atomic Component Types attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Count of Atomic types. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Count of Atomic types. + */ int getNodeAtomicCount(NTREE* ntree) { int count = 0; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) { if (ntree->userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { count++; @@ -2823,10 +3061,10 @@ int getNodeAtomicCount(NTREE* ntree) } /** Return a List of Structure component Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Structure names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Structure names. + */ char** getNodeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2850,10 +3088,10 @@ char** getNodeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Atomic component Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Atomic element names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Atomic element names. + */ char** getNodeAtomicNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2878,10 +3116,10 @@ char** getNodeAtomicNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Structure Component Type Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Structure Type names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Structure Type names. + */ char** getNodeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2905,10 +3143,10 @@ char** getNodeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Atomic Component Type Names attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Atomic Type names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Atomic Type names. + */ char** getNodeAtomicTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2932,10 +3170,10 @@ char** getNodeAtomicTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Structure Component Pointer property attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Structure Pointer Properties. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Structure Pointer Properties. + */ int* getNodeStructurePointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2960,10 +3198,10 @@ int* getNodeStructurePointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Atomic Component Pointer property attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Atomic Pointer Properties. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Atomic Pointer Properties. + */ int* getNodeAtomicPointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { @@ -2989,15 +3227,15 @@ int* getNodeAtomicPointers(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of Rank values of the Structure Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Structure Ranks. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Structure Ranks. + */ int* getNodeStructureRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, count0, size, rank; - int* ranks, * shape; + int *ranks, *shape; const char* type; char* data; if (ntree == nullptr) { @@ -3027,17 +3265,16 @@ int* getNodeStructureRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) return ranks; } - /** Return a List of Rank values of the Atomic Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Atomic Ranks. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Atomic Ranks. + */ int* getNodeAtomicRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, count0, size, rank; - int* ranks, * shape; + int *ranks, *shape; const char* type; char* data; if (ntree == nullptr) { @@ -3049,7 +3286,7 @@ int* getNodeAtomicRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) ranks = (int*)malloc(count * sizeof(int)); addMalloc(logmalloclist, (void*)ranks, count, sizeof(int), "int"); count = 0; - for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) + for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) { if (ntree->userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { if (!ntree->userdefinedtype->compoundfield[i].pointer) { ranks[count] = ntree->userdefinedtype->compoundfield[i].rank; @@ -3063,14 +3300,15 @@ int* getNodeAtomicRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } count++; } + } return ranks; } /** Return a List of Shape Arrays of the Structure Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Structure Shape Arrays. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Structure Shape Arrays. + */ int** getNodeStructureShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, count0, size, rank; @@ -3087,7 +3325,7 @@ int** getNodeStructureShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) shapes = (int**)malloc(count * sizeof(int*)); addMalloc(logmalloclist, (void*)shapes, count, sizeof(int*), "int *"); count = 0; - for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) + for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) { if (ntree->userdefinedtype->compoundfield[i].atomictype == UDA_TYPE_UNKNOWN) { if (!ntree->userdefinedtype->compoundfield[i].pointer) { shapes[count] = ntree->userdefinedtype->compoundfield[i].shape; @@ -3101,14 +3339,15 @@ int** getNodeStructureShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } count++; } + } return (shapes); } /** Return a List of Shape Arrays of the Atomic Components attached to a tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of Atomic Shape Arrays. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of Atomic Shape Arrays. + */ int** getNodeAtomicShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, count0, size, rank; @@ -3123,53 +3362,58 @@ int** getNodeAtomicShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree) int** shapes = (int**)malloc(count * sizeof(int*)); addMalloc(logmalloclist, (void*)shapes, count, sizeof(int*), "int *"); count = 0; - for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) + for (int i = 0; i < ntree->userdefinedtype->fieldcount; i++) { if (ntree->userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { if (!ntree->userdefinedtype->compoundfield[i].pointer) { shapes[count] = ntree->userdefinedtype->compoundfield[i].shape; if (shapes[count] == nullptr && - ntree->userdefinedtype->compoundfield[i].rank < 2) { // Not passed so create + ntree->userdefinedtype->compoundfield[i].rank < 2) { // Not passed so create shapes[count] = (int*)malloc(sizeof(int)); shapes[count][0] = ntree->userdefinedtype->compoundfield[i].count; ntree->userdefinedtype->compoundfield[i].shape = shapes[count]; } } else { - if ((data = (char*)ntree->data) == nullptr) return nullptr; + if ((data = (char*)ntree->data) == nullptr) { + return nullptr; + } int* shape; void* ptr = &data[ntree->userdefinedtype->compoundfield[i].offset]; findMalloc2(logmalloclist, ptr, &count0, &size, &type, &rank, &shape); shapes[count] = shape; if (shape == 0 && (rank < 2)) { - shape = (int*)malloc(sizeof(int)); // Assume rank 1 + shape = (int*)malloc(sizeof(int)); // Assume rank 1 addMalloc(logmalloclist, (void*)shape, 1, sizeof(int), "int"); shape[0] = count0; - shapes[count] = shape; // Pass back the length of the scalar or rank 1 array from the malloc log query + shapes[count] = + shape; // Pass back the length of the scalar or rank 1 array from the malloc log query } } count++; } + } return shapes; } - /** Print the Names and Types of all Node Data Elements to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNodeNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) { int namecount; char** namelist; char** typelist; - if (tree == nullptr) tree = full_ntree; + if (tree == nullptr) { + tree = full_ntree; + } UDA_LOG(UDA_LOG_DEBUG, "\nData Node Structure Names and Types\n"); - namecount = getNodeStructureCount(tree); // Count of all local data structures - namelist = getNodeStructureNames(logmalloclist, tree); // Names - typelist = getNodeStructureTypes(logmalloclist, tree); // Types + namecount = getNodeStructureCount(tree); // Count of all local data structures + namelist = getNodeStructureNames(logmalloclist, tree); // Names + typelist = getNodeStructureTypes(logmalloclist, tree); // Types UDA_LOG(UDA_LOG_DEBUG, "Structure Count %d\n", namecount); if (namecount > 0) { UDA_LOG(UDA_LOG_DEBUG, " #\tName\tType\n"); @@ -3178,9 +3422,9 @@ void printNodeNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) } } UDA_LOG(UDA_LOG_DEBUG, "\nData Node Atomic Names and Types\n"); - namecount = getNodeAtomicCount(tree); // Count of all local atomic data - namelist = getNodeAtomicNames(logmalloclist, tree); // Names - typelist = getNodeAtomicTypes(logmalloclist, tree); // Types + namecount = getNodeAtomicCount(tree); // Count of all local atomic data + namelist = getNodeAtomicNames(logmalloclist, tree); // Names + typelist = getNodeAtomicTypes(logmalloclist, tree); // Types UDA_LOG(UDA_LOG_DEBUG, "Atomic Count %d\n", namecount); if (namecount > 0) { UDA_LOG(UDA_LOG_DEBUG, " #\tName\tType\n"); @@ -3191,11 +3435,11 @@ void printNodeNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) } /** Print the Atomic Data from a data node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNodeAtomic(LOGMALLOCLIST* logmalloclist, NTREE* tree) { int namecount; @@ -3203,18 +3447,18 @@ void printNodeAtomic(LOGMALLOCLIST* logmalloclist, NTREE* tree) if (tree == nullptr) { tree = full_ntree; } - namecount = getNodeAtomicCount(tree); // Count of all local atomic data - namelist = getNodeAtomicNames(logmalloclist, tree); // Names + namecount = getNodeAtomicCount(tree); // Count of all local atomic data + namelist = getNodeAtomicNames(logmalloclist, tree); // Names for (int i = 0; i < namecount; i++) { printAtomicType(logmalloclist, tree, namelist[i]); } } /** Return the number of User Defined Type Structure Definition Components attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the number of User Defined Type Structure Definition Components. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the number of User Defined Type Structure Definition Components. + */ int getNodeStructureComponentCount(NTREE* ntree) { if (ntree == nullptr) { @@ -3224,10 +3468,10 @@ int getNodeStructureComponentCount(NTREE* ntree) } /** Return a List of User Defined Type Structure Definition Components Names attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component names. + */ char** getNodeStructureComponentNames(NTREE* ntree) { int count; @@ -3247,10 +3491,10 @@ char** getNodeStructureComponentNames(NTREE* ntree) } /** Return a List of User Defined Type Structure Definition Components Types attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Types. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Types. + */ char** getNodeStructureComponentTypes(NTREE* ntree) { int count; @@ -3270,10 +3514,10 @@ char** getNodeStructureComponentTypes(NTREE* ntree) } /** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Descriptions. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Descriptions. + */ char** getNodeStructureComponentDescriptions(NTREE* ntree) { int count; @@ -3292,13 +3536,12 @@ char** getNodeStructureComponentDescriptions(NTREE* ntree) return names; } - /** Return the Count of User Defined Structure Component Data array elements attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Count of User Defined Structure Component Data Array elements. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Count of User Defined Structure Component Data Array elements. + */ int getNodeStructureComponentDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { @@ -3315,15 +3558,19 @@ int getNodeStructureComponentDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntre return 0; } -//dgm 05Aug2015 structure and first component share the same address - if (!strcmp(ntree->name, lastname)) return ntree->parent->branches; + // dgm 05Aug2015 structure and first component share the same address + if (!strcmp(ntree->name, lastname)) { + return ntree->parent->branches; + } userdefinedtype = ntree->userdefinedtype; fieldcount = ntree->userdefinedtype->fieldcount; for (int i = 0; i < fieldcount; i++) { if (!strcmp(userdefinedtype->compoundfield[i].name, lastname)) { if (userdefinedtype->compoundfield[i].pointer) { - if ((data = (char*)ntree->data) == nullptr) break; + if ((data = (char*)ntree->data) == nullptr) { + break; + } findMalloc(logmalloclist, &data[userdefinedtype->compoundfield[i].offset], &count, &size, &type); break; } else { @@ -3336,11 +3583,11 @@ int getNodeStructureComponentDataCount(LOGMALLOCLIST* logmalloclist, NTREE* ntre } /** Return the Rank of User Defined Structure Component Data array attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Rank of User Defined Structure Component Data array. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Rank of User Defined Structure Component Data array. + */ int getNodeStructureComponentDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; @@ -3349,18 +3596,26 @@ int getNodeStructureComponentDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree USERDEFINEDTYPE* userdefinedtype; int rank = 0, fieldcount, count, size; int* shape; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name - if (ntree == nullptr) return 0; + if (ntree == nullptr) { + return 0; + } userdefinedtype = ntree->userdefinedtype; fieldcount = ntree->userdefinedtype->fieldcount; for (int i = 0; i < fieldcount; i++) { if (!strcmp(userdefinedtype->compoundfield[i].name, lastname)) { if (userdefinedtype->compoundfield[i].pointer) { - if ((data = (char*)ntree->data) == nullptr) return 0; - findMalloc2(logmalloclist, &data[ntree->userdefinedtype->compoundfield[i].offset], &count, &size, - &type, &rank, &shape); - if (count == 0) rank = 0; + if ((data = (char*)ntree->data) == nullptr) { + return 0; + } + findMalloc2(logmalloclist, &data[ntree->userdefinedtype->compoundfield[i].offset], &count, &size, &type, + &rank, &shape); + if (count == 0) { + rank = 0; + } } else { rank = userdefinedtype->compoundfield[i].rank; } @@ -3371,11 +3626,11 @@ int getNodeStructureComponentDataRank(LOGMALLOCLIST* logmalloclist, NTREE* ntree } /** Return the Shape array of the User Defined Structure Component Data array attached to this tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the Shape array of length Rank of the User Defined Structure Component Data array. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the Shape array of length Rank of the User Defined Structure Component Data array. + */ int* getNodeStructureComponentDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; @@ -3384,18 +3639,26 @@ int* getNodeStructureComponentDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntr USERDEFINEDTYPE* userdefinedtype; int fieldcount, count, size, rank; int* shape = nullptr; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name - if (ntree == nullptr) return nullptr; + if (ntree == nullptr) { + return nullptr; + } userdefinedtype = ntree->userdefinedtype; fieldcount = ntree->userdefinedtype->fieldcount; for (int i = 0; i < fieldcount; i++) { if (!strcmp(userdefinedtype->compoundfield[i].name, lastname)) { if (userdefinedtype->compoundfield[i].pointer) { - if ((data = (char*)ntree->data) == nullptr) return 0; - findMalloc2(logmalloclist, &data[ntree->userdefinedtype->compoundfield[i].offset], &count, &size, - &type, &rank, &shape); - if (count == 0) shape = nullptr; + if ((data = (char*)ntree->data) == nullptr) { + return 0; + } + findMalloc2(logmalloclist, &data[ntree->userdefinedtype->compoundfield[i].offset], &count, &size, &type, + &rank, &shape); + if (count == 0) { + shape = nullptr; + } } else { shape = userdefinedtype->compoundfield[i].shape; } @@ -3406,20 +3669,24 @@ int* getNodeStructureComponentDataShape(LOGMALLOCLIST* logmalloclist, NTREE* ntr } /** Return True (1) if the User Defined Structure Component Data array, attached to this tree node, -* is a pointer type. Returns False (0) otherwise. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure definition. -* @return the value 1 if the User Defined Structure Component Data array is a pointer type. -*/ + * is a pointer type. Returns False (0) otherwise. + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure definition. + * @return the value 1 if the User Defined Structure Component Data array is a pointer type. + */ int getNodeStructureComponentDataIsPointer(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; USERDEFINEDTYPE* userdefinedtype; int ispointer = 0, fieldcount; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name - if (ntree == nullptr) return 0; + if (ntree == nullptr) { + return 0; + } userdefinedtype = ntree->userdefinedtype; fieldcount = ntree->userdefinedtype->fieldcount; for (int i = 0; i < fieldcount; i++) { @@ -3432,11 +3699,11 @@ int getNodeStructureComponentDataIsPointer(LOGMALLOCLIST* logmalloclist, NTREE* } /** Return the Size of a User Defined Structure Component. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the Size of the User Defined Structure Component. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the Size of the User Defined Structure Component. + */ int getNodeStructureComponentDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; @@ -3444,15 +3711,21 @@ int getNodeStructureComponentDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree int count, size = 0, fieldcount; const char* type; char* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name - if (ntree == nullptr) return 0; + if (ntree == nullptr) { + return 0; + } userdefinedtype = ntree->userdefinedtype; fieldcount = ntree->userdefinedtype->fieldcount; for (int i = 0; i < fieldcount; i++) { if (!strcmp(userdefinedtype->compoundfield[i].name, lastname)) { if (userdefinedtype->compoundfield[i].pointer) { - if ((data = (char*)ntree->data) == nullptr) break; + if ((data = (char*)ntree->data) == nullptr) { + break; + } findMalloc(logmalloclist, &data[userdefinedtype->compoundfield[i].offset], &count, &size, &type); break; } else { @@ -3465,11 +3738,11 @@ int getNodeStructureComponentDataSize(LOGMALLOCLIST* logmalloclist, NTREE* ntree } /** Return the Type Name of a User Defined Structure Component. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the Type Name of the User Defined Structure Component. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the Type Name of the User Defined Structure Component. + */ const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; @@ -3477,7 +3750,9 @@ const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, int count, size, fieldcount; const char* type = nullptr; char* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name if (ntree == nullptr) { return "unknown"; @@ -3487,7 +3762,9 @@ const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, for (int i = 0; i < fieldcount; i++) { if (!strcmp(userdefinedtype->compoundfield[i].name, lastname)) { if (userdefinedtype->compoundfield[i].pointer) { - if ((data = (char*)ntree->data) == nullptr) break; + if ((data = (char*)ntree->data) == nullptr) { + break; + } findMalloc(logmalloclist, &data[userdefinedtype->compoundfield[i].offset], &count, &size, &type); break; } else { @@ -3500,11 +3777,11 @@ const char* getNodeStructureComponentDataDataType(LOGMALLOCLIST* logmalloclist, } /** Return a pointer to a User Defined Structure Component's data. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data. + */ void* getNodeStructureComponentData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { const char* lastname; @@ -3512,7 +3789,9 @@ void* getNodeStructureComponentData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, int offset, fieldcount; char* p; void* data = nullptr; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } ntree = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Identify node and component name if (ntree == nullptr) { return nullptr; @@ -3522,8 +3801,7 @@ void* getNodeStructureComponentData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, return ntree->data; } - - if (strcmp(ntree->name, lastname)==0 && strcmp(target, lastname)==0) { + if (strcmp(ntree->name, lastname) == 0 && strcmp(target, lastname) == 0) { return ntree->data; } @@ -3544,29 +3822,31 @@ void* getNodeStructureComponentData(LOGMALLOCLIST* logmalloclist, NTREE* ntree, return data; } - /** Print a User Defined Structure Component's data. -* -* @param fd File Descriptor -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return void. -*/ -void -printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USERDEFINEDTYPELIST* userdefinedtypelist, - const char* target) + * + * @param fd File Descriptor + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return void. + */ +void printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, + USERDEFINEDTYPELIST* userdefinedtypelist, const char* target) { NTREE* node; USERDEFINEDTYPE* userdefinedtype; int namecount, count; const char* type; const char* lastname; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } node = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); // Locate the Node - if (ntree == nullptr) return; + if (ntree == nullptr) { + return; + } - count = getNodeStructureComponentDataCount(logmalloclist, node, lastname); // Array Size + count = getNodeStructureComponentDataCount(logmalloclist, node, lastname); // Array Size type = getNodeStructureComponentDataDataType(logmalloclist, node, lastname); // Type if (count > 0) { @@ -3574,12 +3854,16 @@ printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USER UDA_LOG(UDA_LOG_DEBUG, "Data Values\n"); if (!strcmp(type, "float")) { auto s = (float*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) UDA_LOG(UDA_LOG_DEBUG, "[%d] %f\n", i, s[i]); + for (int i = 0; i < count; i++) { + UDA_LOG(UDA_LOG_DEBUG, "[%d] %f\n", i, s[i]); + } return; } if (!strcmp(type, "int")) { auto s = (int*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) UDA_LOG(UDA_LOG_DEBUG, "[%d] %d\n", i, s[i]); + for (int i = 0; i < count; i++) { + UDA_LOG(UDA_LOG_DEBUG, "[%d] %d\n", i, s[i]); + } return; } if (!strcmp(type, "STRING")) { @@ -3597,7 +3881,7 @@ printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USER void* olddata = nullptr; char* p = (char*)getNodeStructureComponentData(logmalloclist, node, lastname); // Structure Array char* pp = nullptr; - namecount = userdefinedtype->fieldcount; // Count of sub-structure elements + namecount = userdefinedtype->fieldcount; // Count of sub-structure elements UDA_LOG(UDA_LOG_DEBUG, "Data Count %d Type %s\n", namecount, type); for (int j = 0; j < count; j++) { str = (void*)&p[j * userdefinedtype->size]; @@ -3609,11 +3893,13 @@ printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USER userdefinedtype->compoundfield[i].name); if (userdefinedtype->compoundfield[i].pointer) { - data = (void*)*((VOIDTYPE*)&pp[offset]); // Data Element from the single Structure Array Element + data = (void*)*((VOIDTYPE*)&pp[offset]); // Data Element from the single Structure Array Element } else { data = (void*)&pp[offset]; } - if (data == nullptr) continue; + if (data == nullptr) { + continue; + } if (userdefinedtype->compoundfield[i].atomictype != UDA_TYPE_UNKNOWN) { printAtomicData(data, userdefinedtype->compoundfield[i].atomictype, userdefinedtype->compoundfield[i].count, lastname); @@ -3631,7 +3917,7 @@ printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USER } olddata = data; - namecount2 = getNodeStructureComponentCount(&temp); // Count of structure elements + namecount2 = getNodeStructureComponentCount(&temp); // Count of structure elements namelist2 = getNodeStructureComponentNames(&temp); // List of structure element names UDA_LOG(UDA_LOG_DEBUG, "Data Count %d Type %s\n", namecount2, type); @@ -3647,23 +3933,25 @@ printNodeStructureComponentData(NTREE* ntree, LOGMALLOCLIST* logmalloclist, USER } /** Print a Data Structure's Contents. -* -* @param fd File Descriptor -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return void. -*/ + * + * @param fd File Descriptor + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return void. + */ void printNodeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { int count, acount, scount, kstart = 1; - char** anamelist, ** snamelist; - NTREE* node, * node2; + char **anamelist, **snamelist; + NTREE *node, *node2; void* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } - acount = getNodeAtomicCount(ntree); // Count of the Tree Node Structure atomic type components + acount = getNodeAtomicCount(ntree); // Count of the Tree Node Structure atomic type components anamelist = getNodeAtomicNames(logmalloclist, ntree); - scount = getNodeStructureCount(ntree); // Count of the Tree Node Structure structure type components + scount = getNodeStructureCount(ntree); // Count of the Tree Node Structure structure type components snamelist = getNodeStructureNames(logmalloclist, ntree); count = getNodeStructureDataCount(logmalloclist, ntree); // Count of the Tree Node Structure Array elements @@ -3673,7 +3961,7 @@ void printNodeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree) UDA_LOG(UDA_LOG_DEBUG, "%s contents:\n", ntree->userdefinedtype->name); - data = getNodeStructureArrayData(logmalloclist, ntree, j); // Loop over Structure Array Elements + data = getNodeStructureArrayData(logmalloclist, ntree, j); // Loop over Structure Array Elements // Find the next structure array element node - it must be a sibling node // Nodes are ordered so start at the previous node @@ -3685,36 +3973,38 @@ void printNodeStructure(LOGMALLOCLIST* logmalloclist, NTREE* ntree) if (!strcmp(ntree->parent->children[k]->name, ntree->name) && (ntree->parent->children[k]->data == data)) { node = ntree->parent->children[k]; - kstart = k + 1; // Next Start from the next sibling node + kstart = k + 1; // Next Start from the next sibling node } } if (node == nullptr) { - addIdamError(UDA_CODE_ERROR_TYPE, "printNodeStructure", 999, - "Structure Array element Node not Found!"); + addIdamError(UDA_CODE_ERROR_TYPE, "printNodeStructure", 999, "Structure Array element Node not Found!"); return; } } - for (int i = 0; i < acount; i++) printAtomicType(logmalloclist, node, anamelist[i]); // Print Atomic Components + for (int i = 0; i < acount; i++) { + printAtomicType(logmalloclist, node, anamelist[i]); // Print Atomic Components + } - for (int i = 0; i < scount; i++) { // Print Structured Components + for (int i = 0; i < scount; i++) { // Print Structured Components // Structured components must be children of this node. if ((node2 = findNTreeStructure(logmalloclist, node, snamelist[i])) != nullptr) { printNodeStructure(logmalloclist, node2); - } else + } else { UDA_LOG(UDA_LOG_DEBUG, "%40s: null\n", snamelist[i]); + } } } } /** Return a pointer to a User Defined Structure Component's data cast to FLOAT. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data cast to float. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data cast to float. + */ float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { NTREE* node; @@ -3722,10 +4012,14 @@ float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE const char* type; const char* lastname; float* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } node = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); - if (ntree == nullptr) return nullptr; + if (ntree == nullptr) { + return nullptr; + } count = getNodeStructureComponentDataCount(logmalloclist, node, lastname); type = getNodeStructureComponentDataDataType(logmalloclist, node, lastname); @@ -3734,17 +4028,23 @@ float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE return ((float*)getNodeStructureComponentData(logmalloclist, node, lastname)); } - if (count == 0) return nullptr; + if (count == 0) { + return nullptr; + } data = (float*)malloc(count * sizeof(float)); if (!strcmp(type, "double")) { double* s = (double*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (float)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (float)s[i]; + } return data; } if (!strcmp(type, "int")) { int* s = (int*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (float)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (float)s[i]; + } return data; } @@ -3752,11 +4052,11 @@ float* castNodeStructureComponentDatatoFloat(LOGMALLOCLIST* logmalloclist, NTREE } /** Return a pointer to a User Defined Structure Component's data cast to DOUBLE. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @param target The name of a User Defined Structure Component. -* @return the User Defined Structure Component's data cast to float. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @param target The name of a User Defined Structure Component. + * @return the User Defined Structure Component's data cast to float. + */ double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) { NTREE* node; @@ -3764,10 +4064,14 @@ double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTR const char* type; const char* lastname; double* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } node = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); - if (ntree == nullptr) return nullptr; + if (ntree == nullptr) { + return nullptr; + } count = getNodeStructureComponentDataCount(logmalloclist, node, lastname); type = getNodeStructureComponentDataDataType(logmalloclist, node, lastname); @@ -3776,17 +4080,23 @@ double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTR return (double*)getNodeStructureComponentData(logmalloclist, node, lastname); } - if (count == 0) return nullptr; + if (count == 0) { + return nullptr; + } data = (double*)malloc(count * sizeof(double)); if (!strcmp(type, "float")) { float* s = (float*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (double)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (double)s[i]; + } return data; } if (!strcmp(type, "int")) { int* s = (int*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (double)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (double)s[i]; + } return data; } @@ -3797,10 +4107,10 @@ double* castNodeStructureComponentDatatoDouble(LOGMALLOCLIST* logmalloclist, NTR // Tree Branch Family: Whole tree is in scope /** Initialise a NTREE data structure. -* -* @param str A pointer to a NTREE data structure instance. -* @return Void. -*/ + * + * @param str A pointer to a NTREE data structure instance. + * @return Void. + */ void initNTree(NTREE* str) { str->branches = 0; @@ -3812,9 +4122,9 @@ void initNTree(NTREE* str) } /** Initialise the Global NTREE list structure. -* -* @return Void. -*/ + * + * @return Void. + */ void initNTreeList(NTREELIST* ntree_list) { ntree_list->listCount = 0; @@ -3822,11 +4132,11 @@ void initNTreeList(NTREELIST* ntree_list) } /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNTree2(NTREE* tree) { if (tree == nullptr) { @@ -3842,19 +4152,25 @@ void printNTree2(NTREE* tree) #endif UDA_LOG(UDA_LOG_DEBUG, "Children: %d\n", tree->branches); #ifdef A64 - for (int i = 0; i < tree->branches; i++) UDA_LOG(UDA_LOG_DEBUG, "[%2d]: %llx\n", i, (UVOIDTYPE)tree->children[i]); + for (int i = 0; i < tree->branches; i++) { + UDA_LOG(UDA_LOG_DEBUG, "[%2d]: %llx\n", i, (UVOIDTYPE)tree->children[i]); + } #else - for (int i = 0; i < tree->branches; i++) UDA_LOG(UDA_LOG_DEBUG, "[%2d]: %x\n", i, (UVOIDTYPE)tree->children[i]); + for (int i = 0; i < tree->branches; i++) { + UDA_LOG(UDA_LOG_DEBUG, "[%2d]: %x\n", i, (UVOIDTYPE)tree->children[i]); + } #endif - for (int i = 0; i < tree->branches; i++) printNTree2(tree->children[i]); + for (int i = 0; i < tree->branches; i++) { + printNTree2(tree->children[i]); + } } /** Print the Contents of a tree node to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNTree(NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist) { if (tree == nullptr) { @@ -3871,16 +4187,15 @@ void printNTree(NTREE* tree, USERDEFINEDTYPELIST* userdefinedtypelist) printUserDefinedTypeTable(userdefinedtypelist, *tree->userdefinedtype); for (int i = 0; i < tree->branches; i++) { printNTree(tree->children[i], userdefinedtypelist); - } } /** Print Details of the tree node List to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNTreeList(NTREE* tree) { if (tree == nullptr) { @@ -3890,7 +4205,8 @@ void printNTreeList(NTREE* tree) UDA_LOG(UDA_LOG_DEBUG, "%llx\t(%lld)\t%s\t%s\t%d\n", (UVOIDTYPE)tree, (UVOIDTYPE)tree, tree->name, tree->userdefinedtype->name, tree->branches); #else - UDA_LOG(UDA_LOG_DEBUG, "%x\t(%d)\t%s\t%s\t%d\n", (UVOIDTYPE)tree, (UVOIDTYPE)tree, tree->name,tree->userdefinedtype->name,tree->branches); + UDA_LOG(UDA_LOG_DEBUG, "%x\t(%d)\t%s\t%s\t%d\n", (UVOIDTYPE)tree, (UVOIDTYPE)tree, tree->name, + tree->userdefinedtype->name, tree->branches); #endif for (int i = 0; i < tree->branches; i++) { printNTreeList(tree->children[i]); @@ -3898,17 +4214,19 @@ void printNTreeList(NTREE* tree) } /** Return a Count of User Defined Type Tree Nodes from and including the passed tree node. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the Count of Tree Nodes. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the Count of Tree Nodes. + */ int getNTreeStructureCount(NTREE* ntree) { int count = 1; if (ntree == nullptr) { ntree = udaGetFullNTree(); } - if (ntree->branches == 0) return count; + if (ntree->branches == 0) { + return count; + } for (int i = 0; i < ntree->branches; i++) { if (i == 0 || strcmp(ntree->children[i]->userdefinedtype->name, ntree->children[i - 1]->userdefinedtype->name) != 0) { @@ -3919,10 +4237,10 @@ int getNTreeStructureCount(NTREE* ntree) } /** Return a List of User Defined Type Structure Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure names. + */ char** getNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { if (ntree == nullptr) { @@ -3956,10 +4274,10 @@ char** getNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Return a List of User Defined Type Structure Type Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Type names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Type names. + */ char** getNTreeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { if (ntree == nullptr) { @@ -3969,7 +4287,9 @@ char** getNTreeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) auto names = (char**)malloc(sizeof(char*)); addMalloc(logmalloclist, (void*)names, 1, sizeof(char*), "char *"); names[0] = ntree->userdefinedtype->name; - if (ntree->branches == 0) return names; + if (ntree->branches == 0) { + return names; + } int count = 1; for (int i = 0; i < ntree->branches; i++) { @@ -3990,15 +4310,15 @@ char** getNTreeStructureTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) } /** Print the Names and Types of all Data Structures to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) { int namecount; - char** namelist, ** typelist; + char **namelist, **typelist; if (tree == nullptr) { tree = full_ntree; } @@ -4007,9 +4327,9 @@ void printNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) #else UDA_LOG(UDA_LOG_DEBUG, "\nData Tree %x Structure Names and Types\n", (UVOIDTYPE)tree); #endif - namecount = getNTreeStructureCount(tree); // Count of all Tree Nodes - namelist = getNTreeStructureNames(logmalloclist, tree); // Names of all user defined data structures - typelist = getNTreeStructureTypes(logmalloclist, tree); // Types of all user defined data structures + namecount = getNTreeStructureCount(tree); // Count of all Tree Nodes + namelist = getNTreeStructureNames(logmalloclist, tree); // Names of all user defined data structures + typelist = getNTreeStructureTypes(logmalloclist, tree); // Types of all user defined data structures UDA_LOG(UDA_LOG_DEBUG, "Total Structure Count %d\n", namecount); UDA_LOG(UDA_LOG_DEBUG, " #\tName\tType\n"); for (int i = 0; i < namecount; i++) { @@ -4018,10 +4338,10 @@ void printNTreeStructureNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) } /** Return the total number of User Defined Type Structure Definition Components attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the number of User Defined Type Structure Definition Components. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the number of User Defined Type Structure Definition Components. + */ int getNTreeStructureComponentCount(NTREE* ntree) { int count; @@ -4040,10 +4360,10 @@ int getNTreeStructureComponentCount(NTREE* ntree) } /** Return a List of User Defined Type Structure Definition Components Names attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component names. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component names. + */ char** getNTreeStructureComponentNames(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { if (ntree == nullptr) { @@ -4075,10 +4395,10 @@ char** getNTreeStructureComponentNames(LOGMALLOCLIST* logmalloclist, NTREE* ntre } /** Return a List of User Defined Type Structure Definition Components Types attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Types. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Types. + */ char** getNTreeStructureComponentTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { if (ntree == nullptr) { @@ -4110,10 +4430,10 @@ char** getNTreeStructureComponentTypes(LOGMALLOCLIST* logmalloclist, NTREE* ntre } /** Return a List of User Defined Type Structure Definition Components Descriptions attached to this tree branch. -* -* @param ntree A pointer to a tree node. If nullptr the root node is assumed. -* @return the List of User Defined Type Structure Definition Component Descriptions. -*/ + * + * @param ntree A pointer to a tree node. If nullptr the root node is assumed. + * @return the List of User Defined Type Structure Definition Component Descriptions. + */ char** getNTreeStructureComponentDescriptions(LOGMALLOCLIST* logmalloclist, NTREE* ntree) { if (ntree == nullptr) { @@ -4145,22 +4465,22 @@ char** getNTreeStructureComponentDescriptions(LOGMALLOCLIST* logmalloclist, NTRE } /** Print the Names and Types of all Data Elements to a specified File Descriptor. -* -* @param fd The File Descriptor, e.g., stdout -* @param tree A pointer to a tree node. If nullptr the root node is assumed. -* @return Void -*/ + * + * @param fd The File Descriptor, e.g., stdout + * @param tree A pointer to a tree node. If nullptr the root node is assumed. + * @return Void + */ void printNTreeStructureComponentNames(LOGMALLOCLIST* logmalloclist, NTREE* tree) { int namecount; - char** namelist, ** typelist, ** desclist; + char **namelist, **typelist, **desclist; if (tree == nullptr) { tree = full_ntree; } UDA_LOG(UDA_LOG_DEBUG, "\nData Tree Structure Component Names, Types and Descriptions\n"); - namecount = getNTreeStructureComponentCount(tree); // Count of all Tree Nodes - namelist = getNTreeStructureComponentNames(logmalloclist, tree); // Names of all structure elements - typelist = getNTreeStructureComponentTypes(logmalloclist, tree); // Types of all structure elements + namecount = getNTreeStructureComponentCount(tree); // Count of all Tree Nodes + namelist = getNTreeStructureComponentNames(logmalloclist, tree); // Names of all structure elements + typelist = getNTreeStructureComponentTypes(logmalloclist, tree); // Types of all structure elements desclist = getNTreeStructureComponentDescriptions(logmalloclist, tree); // Descriptions of all structure elements UDA_LOG(UDA_LOG_DEBUG, "Total Structure Component Count %d\n", namecount); UDA_LOG(UDA_LOG_DEBUG, " #\tName\tType\tDescription\n"); @@ -4204,10 +4524,16 @@ void printAtomicType_stdout(LOGMALLOCLIST* logmalloclist, NTREE* tree, const cha void getNodeStructureComponentDataShape_f(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target, int* shape_f) { int rank = getNodeStructureComponentDataRank(logmalloclist, ntree, target); - for (int i = 0; i < MAXRANK; i++)shape_f[i] = 0; + for (int i = 0; i < MAXRANK; i++) { + shape_f[i] = 0; + } if (rank > 1 && rank <= MAXRANK) { int* shape = getNodeStructureComponentDataShape(logmalloclist, ntree, target); - if (shape != nullptr) for (int i = 0; i < rank; i++)shape_f[i] = shape[i]; + if (shape != nullptr) { + for (int i = 0; i < rank; i++) { + shape_f[i] = shape[i]; + } + } } else { shape_f[0] = getNodeStructureComponentDataCount(logmalloclist, ntree, target); } @@ -4217,24 +4543,32 @@ void getNodeStructureComponentShortData_f(LOGMALLOCLIST* logmalloclist, NTREE* n { auto data = (short*)getNodeStructureComponentData(logmalloclist, node, target); int count = getNodeStructureComponentDataCount(logmalloclist, node, target); - for (int i = 0; i < count; i++)data_f[i] = data[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data[i]; + } } void getNodeStructureComponentFloatData_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, float* data_f) { float* data = (float*)getNodeStructureComponentData(logmalloclist, node, target); int count = getNodeStructureComponentDataCount(logmalloclist, node, target); - for (int i = 0; i < count; i++)data_f[i] = data[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data[i]; + } } void dereferenceShortData(short* data_c, int count, short* data_f) { - for (int i = 0; i < count; i++)data_f[i] = data_c[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data_c[i]; + } } void dereferenceFloatData(float* data_c, int count, float* data_f) { - for (int i = 0; i < count; i++)data_f[i] = data_c[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data_c[i]; + } } short* castNodeStructureComponentDatatoShort(LOGMALLOCLIST* logmalloclist, NTREE* ntree, const char* target) @@ -4244,10 +4578,14 @@ short* castNodeStructureComponentDatatoShort(LOGMALLOCLIST* logmalloclist, NTREE const char* type; const char* lastname; short* data; - if (ntree == nullptr) ntree = udaGetFullNTree(); + if (ntree == nullptr) { + ntree = udaGetFullNTree(); + } node = findNTreeStructureComponent2(logmalloclist, ntree, target, &lastname); - if (ntree == nullptr) return nullptr; + if (ntree == nullptr) { + return nullptr; + } count = getNodeStructureComponentDataCount(logmalloclist, node, lastname); type = getNodeStructureComponentDataDataType(logmalloclist, node, lastname); @@ -4256,62 +4594,77 @@ short* castNodeStructureComponentDatatoShort(LOGMALLOCLIST* logmalloclist, NTREE return (short*)getNodeStructureComponentData(logmalloclist, node, lastname); } - if (count == 0) return nullptr; + if (count == 0) { + return nullptr; + } data = (short*)malloc(count * sizeof(short)); if (!strcmp(type, "double")) { double* s = (double*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (short)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (short)s[i]; + } return data; } if (!strcmp(type, "float")) { float* s = (float*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (short)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (short)s[i]; + } return data; } if (!strcmp(type, "int")) { int* s = (int*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (short)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (short)s[i]; + } return data; } if (!strcmp(type, "unsigned int")) { unsigned int* s = (unsigned int*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (short)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (short)s[i]; + } return data; } if (!strcmp(type, "unsigned short")) { unsigned short* s = (unsigned short*)getNodeStructureComponentData(logmalloclist, node, lastname); - for (int i = 0; i < count; i++) data[i] = (short)s[i]; + for (int i = 0; i < count; i++) { + data[i] = (short)s[i]; + } return data; } return nullptr; } -void -castNodeStructureComponentDatatoShort_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, short* data_f) +void castNodeStructureComponentDatatoShort_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + short* data_f) { short* data = castNodeStructureComponentDatatoShort(logmalloclist, node, target); if (data != nullptr) { int count = getNodeStructureComponentDataCount(logmalloclist, node, target); - for (int i = 0; i < count; i++)data_f[i] = data[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data[i]; + } free(data); } } -void -castNodeStructureComponentDatatoFloat_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, float* data_f) +void castNodeStructureComponentDatatoFloat_f(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* target, + float* data_f) { float* data = castNodeStructureComponentDatatoFloat(logmalloclist, node, target); if (data != nullptr) { int count = getNodeStructureComponentDataCount(logmalloclist, node, target); - for (int i = 0; i < count; i++)data_f[i] = data[i]; + for (int i = 0; i < count; i++) { + data_f[i] = data[i]; + } free(data); } } -void -addStructureField(USERDEFINEDTYPE* user_type, const char* name, const char* desc, UDA_TYPE data_type, bool is_pointer, - int rank, int* shape, size_t offset) +void addStructureField(USERDEFINEDTYPE* user_type, const char* name, const char* desc, UDA_TYPE data_type, + bool is_pointer, int rank, int* shape, size_t offset) { COMPOUNDFIELD field; initCompoundField(&field); diff --git a/source/structures/xdrUserDefinedData.cpp b/source/structures/xdrUserDefinedData.cpp old mode 100755 new mode 100644 index 2c9cc1d1..d27cf6f0 --- a/source/structures/xdrUserDefinedData.cpp +++ b/source/structures/xdrUserDefinedData.cpp @@ -2,21 +2,21 @@ #include -#include -#include +#include "udaErrors.h" #include +#include #include #include -#include "udaErrors.h" +#include #include "struct.h" -static int recursiveDepth = 0; // Keep count of recursive calls +static int recursiveDepth = 0; // Keep count of recursive calls int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* log_struct_list, - USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, - void** data, int datacount, int structRank, int* structShape, - int index, NTREE** NTree, int protocolVersion, int malloc_source) + USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, void** data, + int datacount, int structRank, int* structShape, int index, NTREE** NTree, int protocolVersion, + int malloc_source) { // Grow the data tree recursively through pointer elements within individual structures // Build a linked list tree structure when receiving data. @@ -26,14 +26,14 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l int rc = 1, id, loopcount, rank, count, size, passdata = 0, isSOAP; int* shape; - char* p0, * d; + char *p0, *d; const char* type; - char rudtype[MAXELEMENTNAME]; // Received name of the user defined type + char rudtype[MAXELEMENTNAME]; // Received name of the user defined type const char* chartype = "char"; - VOIDTYPE* p; // Type Needs to be the same size as a local pointer, e.g., int* on 32 and long long* on 64 bit - VOIDTYPE* prev = nullptr; // Pointer to previous structure element (need to manage SOAP data bindings) + VOIDTYPE* p; // Type Needs to be the same size as a local pointer, e.g., int* on 32 and long long* on 64 bit + VOIDTYPE* prev = nullptr; // Pointer to previous structure element (need to manage SOAP data bindings) USERDEFINEDTYPE* utype = nullptr; @@ -46,11 +46,15 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l rc = xdr_int(xdrs, &passdata); } else { passdata = 0; - if (data != nullptr) passdata = *(int**)data != nullptr; + if (data != nullptr) { + passdata = *(int**)data != nullptr; + } rc = xdr_int(xdrs, &passdata); } - if (!passdata) return rc; + if (!passdata) { + return rc; + } // If the recursive depth is too large then perhaps an infinite loop is in play! @@ -61,14 +65,13 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l UDA_LOG(UDA_LOG_DEBUG, "Depth: %d\n", recursiveDepth); - // Allocate HEAP if receiving Data: - // Size of Structure or atomic type array or scalar is provided by the structure definition (corrected for alignment and architecture) - // datacount, rank and shape are passed via the argument - it's the number of structure array elements to allocate in a single block - // Index is the element of the structure array to be received - // Allocation occurs only when index == 0, i.e. the first time the function is entered. Rank and shape of structured data are captured. - // Allocation occurs only when datacount > 0, i.e. Must be a Pointer to a User Defined Type Structure: Otherwise it's already - // allocated - but must add a tree node to the structure element. + // Size of Structure or atomic type array or scalar is provided by the structure definition (corrected for alignment + // and architecture) datacount, rank and shape are passed via the argument - it's the number of structure array + // elements to allocate in a single block Index is the element of the structure array to be received Allocation + // occurs only when index == 0, i.e. the first time the function is entered. Rank and shape of structured data are + // captured. Allocation occurs only when datacount > 0, i.e. Must be a Pointer to a User Defined Type Structure: + // Otherwise it's already allocated - but must add a tree node to the structure element. // // Child nodes of the same type are branched consequentially @@ -86,15 +89,14 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l structRank = 0; } - newNTree = (NTREE*)malloc(sizeof(NTREE)); // this is the parent node for the received structure + newNTree = (NTREE*)malloc(sizeof(NTREE)); // this is the parent node for the received structure addMalloc(logmalloclist, (void*)newNTree, 1, sizeof(NTREE), "NTREE"); - *NTree = newNTree; // Return the new tree node address + *NTree = newNTree; // Return the new tree node address initNTree(newNTree); newNTree->data = nullptr; - newNTree->userdefinedtype = userdefinedtype; // preserve Pairing of data and data type - + newNTree->userdefinedtype = userdefinedtype; // preserve Pairing of data and data type } // Start of the Structure Array Element @@ -103,7 +105,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l if (xdrs->x_op == XDR_DECODE) { newNTree->data = (void*)p0; - } // Each tree node points to a structure or an atomic array + } // Each tree node points to a structure or an atomic array // Loop over all structure elements: Send or Receive @@ -114,13 +116,13 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - p = (VOIDTYPE*)&p0[userdefinedtype->compoundfield[j].offset]; // the Element's location + p = (VOIDTYPE*)&p0[userdefinedtype->compoundfield[j].offset]; // the Element's location - if (xdrs->x_op == XDR_DECODE && userdefinedtype->compoundfield[j].pointer) { // Initialise - *p = 0; // nullptr pointer: to be allocated on heap + if (xdrs->x_op == XDR_DECODE && userdefinedtype->compoundfield[j].pointer) { // Initialise + *p = 0; // nullptr pointer: to be allocated on heap } - type = nullptr; // Reset pointer attributes + type = nullptr; // Reset pointer attributes d = nullptr; count = 0; size = 0; @@ -134,13 +136,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_FLOAT: { UDA_LOG(UDA_LOG_DEBUG, "Type: FLOAT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received - rc = rc && xdr_int(xdrs, &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { - rc = rc && xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) + rc = rc && + xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; @@ -148,13 +153,17 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l d = (char*)malloc(count * sizeof(float)); addMalloc2(logmalloclist, (void*)d, count, sizeof(float), "float", rank, shape); *p = (VOIDTYPE)d; - } else { break; } - if (!rc)break; + } else { + break; + } + if (!rc) { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } @@ -163,12 +172,13 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l // Allocation of pointer data within SOAP is problematic. // Data malloc'd within SOAP are typed "unknown". - // Generally, pointer class data are preceded within the data binding structures with integer elements - // named __size followed by the name of the element. The value stored by this element is the equivalent - // of the count parameter required from findMalloc. + // Generally, pointer class data are preceded within the data binding structures with integer + // elements named __size followed by the name of the element. The value stored by this element + // is the equivalent of the count parameter required from findMalloc. // // Other data creators, e.g., XML DOM, also have types "unknown" - // In these cases, a best guess is made to the type and count based on expectations and the heap allocated - very unsatisfactory! + // In these cases, a best guess is made to the type and count based on expectations and the heap + // allocated - very unsatisfactory! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -176,17 +186,17 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(float); type = userdefinedtype->compoundfield[j].type; } else { if (count > 0) { - int totalsize = count * size; // from the malloc log - int rcount = totalsize % sizeof(float); // array element count remainder - size = sizeof(float); // element size - count = totalsize / size; // array element count + int totalsize = count * size; // from the malloc log + int rcount = totalsize % sizeof(float); // array element count remainder + size = sizeof(float); // element size + count = totalsize / size; // array element count - if (rcount != 0) { // there should be no remainder + if (rcount != 0) { // there should be no remainder addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Specified malloc total size not integer multiple!"); count = 0; @@ -203,17 +213,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(float), (xdrproc_t)xdr_float); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size rc = rc && xdr_float(xdrs, (float*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(float), (xdrproc_t)xdr_float); } @@ -224,26 +233,31 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_DOUBLE: { UDA_LOG(UDA_LOG_DEBUG, "Type: DOUBLE\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Double Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received - rc = rc && xdr_int(xdrs, &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Double Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data Received + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { - rc = rc && xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) + rc = rc && + xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(double)); addMalloc2(logmalloclist, (void*)d, count, sizeof(double), "double", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } @@ -256,7 +270,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(double); type = userdefinedtype->compoundfield[j].type; } else { @@ -282,18 +296,17 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(double), - (xdrproc_t)xdr_double); // Send or Receive data + (xdrproc_t)xdr_double); // Send or Receive data } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar of fixed size rc = rc && xdr_double(xdrs, (double*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(double), (xdrproc_t)xdr_double); } @@ -304,32 +317,35 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_SHORT: { UDA_LOG(UDA_LOG_DEBUG, "Type: SHORT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Short Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Short Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(short)); addMalloc2(logmalloclist, (void*)d, count, sizeof(short), "short", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -337,7 +353,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(short); type = userdefinedtype->compoundfield[j].type; } else { @@ -363,17 +379,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(short), (xdrproc_t)xdr_short); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_short(xdrs, (short*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(short), (xdrproc_t)xdr_short); } @@ -384,32 +399,36 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_UNSIGNED_CHAR: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED_CHAR\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(unsigned char)); - addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned char), "unsigned char", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned char), "unsigned char", rank, + shape); + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -417,7 +436,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned char); type = userdefinedtype->compoundfield[j].type; } else { @@ -443,17 +462,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned char), (xdrproc_t)xdr_u_char); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_u_char(xdrs, (unsigned char*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(unsigned char), (xdrproc_t)xdr_u_char); } @@ -464,32 +482,36 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_UNSIGNED_SHORT: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED_SHORT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(unsigned short)); - addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned short), "unsigned short", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned short), "unsigned short", rank, + shape); + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -497,7 +519,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned short); type = userdefinedtype->compoundfield[j].type; } else { @@ -507,8 +529,9 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l size = sizeof(unsigned short); count = totalsize / size; if (rcount != 0) { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "Specified unsigned short malloc total size not integer multiple!"); + addIdamError( + UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, + "Specified unsigned short malloc total size not integer multiple!"); count = 0; } } @@ -523,17 +546,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } - } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned short), (xdrproc_t)xdr_u_short); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_u_short(xdrs, (unsigned short*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(unsigned short), (xdrproc_t)xdr_u_short); } @@ -544,32 +566,35 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_INT: { UDA_LOG(UDA_LOG_DEBUG, "Type: INT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Integer Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Integer Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(int)); addMalloc2(logmalloclist, (void*)d, count, sizeof(int), "int", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -577,7 +602,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(int); type = userdefinedtype->compoundfield[j].type; } else { @@ -603,16 +628,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(int), (xdrproc_t)xdr_int); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_int(xdrs, (int*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(int), (xdrproc_t)xdr_int); } @@ -623,32 +648,36 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_UNSIGNED_INT: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED INT\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(unsigned int)); - addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned int), "unsigned int", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned int), "unsigned int", rank, + shape); + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -656,7 +685,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned int); type = userdefinedtype->compoundfield[j].type; } else { @@ -680,16 +709,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l "Unsigned Integer Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned int), (xdrproc_t)xdr_u_int); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_u_int(xdrs, (unsigned int*)p); - } else { // Element is an Array of fixed size + } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(unsigned int), (xdrproc_t)xdr_u_int); } @@ -700,32 +729,35 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_LONG64: { UDA_LOG(UDA_LOG_DEBUG, "Type: LONG LONG\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to long long Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to long long Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(long long)); addMalloc2(logmalloclist, (void*)d, count, sizeof(long long), "long long", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*)*p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && @@ -733,7 +765,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(long long); type = userdefinedtype->compoundfield[j].type; @@ -758,19 +790,18 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l "Long Long Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } rc = rc && xdr_vector(xdrs, d, count, sizeof(long long), (xdrproc_t)xdr_int64_t); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_int64_t(xdrs, (int64_t*)p); - } else { // Element is an Array of fixed size - rc = rc && - xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(long long), - (xdrproc_t)xdr_int64_t); + } else { // Element is an Array of fixed size + rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, + sizeof(long long), (xdrproc_t)xdr_int64_t); } } break; @@ -780,39 +811,44 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_UNSIGNED_LONG64: { UDA_LOG(UDA_LOG_DEBUG, "Type: UNSIGNED LONG LONG\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*) malloc(rank * sizeof(int)); // freed via the malloc log registration - rc = rc && xdr_vector(xdrs, (char*) shape, rank, sizeof(int), (xdrproc_t) xdr_int); - } else + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); + } else { shape = nullptr; - d = (char*) malloc(count * sizeof(unsigned long long)); - addMalloc2(logmalloclist, (void*) d, count, sizeof(unsigned long long), "unsigned long long", rank, shape); - *p = (VOIDTYPE) d; // Save pointer: data will be written here - } else break; + } + d = (char*)malloc(count * sizeof(unsigned long long)); + addMalloc2(logmalloclist, (void*)d, count, sizeof(unsigned long long), "unsigned long long", + rank, shape); + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { - d = (char*) *p; // data read from here + d = (char*)*p; // data read from here if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } - findMalloc2(logmalloclist, (void*) p, &count, &size, &type, &rank, - &shape); // Assume count of 0 means No Pointer data to send! + findMalloc2(logmalloclist, (void*)p, &count, &size, &type, &rank, + &shape); // Assume count of 0 means No Pointer data to send! if (type != nullptr && STR_EQUALS(type, "unknown")) { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && STR_EQUALS(userdefinedtype->compoundfield[j - 1].name, "__size") && STR_EQUALS(userdefinedtype->compoundfield[j].name, - &userdefinedtype->compoundfield[j - 1].name[6])) { + &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int) *prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(unsigned long long); type = userdefinedtype->compoundfield[j].type; @@ -837,18 +873,18 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l "Unsigned Long Long Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { - rc = rc && xdr_vector(xdrs, (char*) shape, rank, sizeof(int), (xdrproc_t) xdr_int); + rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } - rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned long long), (xdrproc_t) xdr_uint64_t); + rc = rc && xdr_vector(xdrs, d, count, sizeof(unsigned long long), (xdrproc_t)xdr_uint64_t); } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar - rc = rc && xdr_uint64_t(xdrs, (uint64_t*) p); - } else { // Element is an Array of fixed size - rc = rc && xdr_vector(xdrs, (char*) p, userdefinedtype->compoundfield[j].count, - sizeof(unsigned long long), (xdrproc_t) xdr_uint64_t); + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + rc = rc && xdr_uint64_t(xdrs, (uint64_t*)p); + } else { // Element is an Array of fixed size + rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, + sizeof(unsigned long long), (xdrproc_t)xdr_uint64_t); } } break; @@ -857,27 +893,34 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l case UDA_TYPE_CHAR: { UDA_LOG(UDA_LOG_DEBUG, "Type: CHAR\n"); - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, &count); // Count is known from the client's malloc log and passed by the sender - if (!rc)break; + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to Float Data array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender + if (!rc) { + break; + } if (count > 0) { - rc = rc && xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) + rc = rc && + xdr_int(xdrs, &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } d = (char*)malloc(count * sizeof(char)); addMalloc2(logmalloclist, (void*)d, count, sizeof(char), "char", rank, shape); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } // Assume count of 0 means No Pointer data to send! @@ -890,7 +933,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l &userdefinedtype->compoundfield[j - 1].name[6])) { isSOAP = 1; - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = sizeof(char); type = userdefinedtype->compoundfield[j].type; } else { @@ -908,7 +951,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } } else { if (malloc_source == UDA_MALLOC_SOURCE_SOAP && (count == 0 || size == 0) && - *p != 0) { // Assume SOAP string + *p != 0) { // Assume SOAP string isSOAP = 1; if (d != nullptr) { int lstr = (int)strlen(d); @@ -923,27 +966,31 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } rc = rc && xdr_int(xdrs, &count); - if (!rc)break; + if (!rc) { + break; + } if ((count == 0 || size == 0) && *p != 0) { addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Char Data Heap Allocation not found in log!"); break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } } - rc = rc && xdr_int(xdrs, &isSOAP); // synchronise XDR function calls - if (!rc) break; + rc = rc && xdr_int(xdrs, &isSOAP); // synchronise XDR function calls + if (!rc) { + break; + } - if (isSOAP) { // char* is a C String in gSOAP + if (isSOAP) { // char* is a C String in gSOAP if (xdrs->x_op == XDR_ENCODE) { int sl = (int)strlen(d); if (sl > count) { - d[count - 1] = '\0'; // Terminate + d[count - 1] = '\0'; // Terminate } } rc = rc && WrapXDRString(xdrs, d, count); @@ -951,45 +998,54 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } else { rc = rc && xdr_vector(xdrs, d, count, sizeof(char), (xdrproc_t)xdr_char); } - if (!rc) break; + if (!rc) { + break; + } } else { - if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar + if (userdefinedtype->compoundfield[j].rank == 0) { // Element is a Scalar rc = rc && xdr_char(xdrs, (char*)p); } else { // Element is an Array of fixed size rc = rc && xdr_vector(xdrs, (char*)p, userdefinedtype->compoundfield[j].count, sizeof(char), (xdrproc_t)xdr_char); } - if (!rc) break; + if (!rc) { + break; + } } break; } - case UDA_TYPE_STRING2: { // Array of char terminated by \0 - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, &count); // Count is known from the client's malloc log and passed by the sender + case UDA_TYPE_STRING2: { // Array of char terminated by \0 + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } - if (malloc_source == UDA_MALLOC_SOURCE_DOM) { // Bad address range? + if (malloc_source == UDA_MALLOC_SOURCE_DOM) { // Bad address range? count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } - findMalloc(logmalloclist, (void*)p, &count, &size, &type); // Assume 0 means No Pointer data to send! + findMalloc(logmalloclist, (void*)p, &count, &size, + &type); // Assume 0 means No Pointer data to send! if (malloc_source == UDA_MALLOC_SOURCE_DOM && (count == 0 || size == 0) && d != nullptr) { int lstr = (int)strlen(d); @@ -1004,8 +1060,9 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l int lstr = (int)strlen(d); count = size; size = sizeof(char); - if (malloc_source == UDA_MALLOC_SOURCE_DOM && lstr > count - 1 && lstr < MAXSOAPSTACKSTRING) { - count = lstr + 1; // A bug in xml DOM? + if (malloc_source == UDA_MALLOC_SOURCE_DOM && lstr > count - 1 && + lstr < MAXSOAPSTACKSTRING) { + count = lstr + 1; // A bug in xml DOM? } } @@ -1018,9 +1075,11 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } } - if (count > 0) rc = rc && WrapXDRString(xdrs, d, count); + if (count > 0) { + rc = rc && WrapXDRString(xdrs, d, count); + } } else { - if (userdefinedtype->compoundfield[j].rank == 1) { // Element is a Regular String + if (userdefinedtype->compoundfield[j].rank == 1) { // Element is a Regular String rc = rc && WrapXDRString(xdrs, (char*)p, userdefinedtype->compoundfield[j].count); } else { // Element is an Array of Strings of fixed max size @@ -1029,29 +1088,30 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - // String handling is complicated ... + // String handling is complicated ... - // Strings with a Fixed Length: Rank >= 1, Pointer = FALSE (Convention) - // Strings with a Non-Fixed Length: Rank = 0, Pointer = TRUE - // If the number of strings is arbitrary then the type is STRING* rather than STRING + // Strings with a Fixed Length: Rank >= 1, Pointer = FALSE (Convention) + // Strings with a Non-Fixed Length: Rank = 0, Pointer = TRUE + // If the number of strings is arbitrary then the type is STRING* rather than STRING - // Strings: - // char *p single scalar string of arbitrary length => rank = 0, pointer = 1, type STRING - // char **p; arbitrary number array of strings of arbitrary length => rank = 0, pointer = 1, type STRING* - // char p[int] single scalar string of fixed length => rank = 1, pointer = 0, type STRING - // char *p[int] fixed number array of strings of arbitrary length => rank = 1, pointer = 0, type STRING* - // char p[int][int] fixed number array of strings of fixed length => rank = 2, pointer = 0, type STRING + // Strings: + // char *p single scalar string of arbitrary length => rank = 0, pointer = 1, type + // STRING char **p; arbitrary number array of strings of arbitrary length => rank = 0, + // pointer = 1, type STRING* char p[int] single scalar string of fixed length => rank + // = 1, pointer = 0, type STRING char *p[int] fixed number array of strings of arbitrary length + // => rank = 1, pointer = 0, type STRING* char p[int][int] fixed number array of strings of fixed + // length => rank = 2, pointer = 0, type STRING - case UDA_TYPE_STRING: { // Array of char terminated by \0 + case UDA_TYPE_STRING: { // Array of char terminated by \0 UDA_LOG(UDA_LOG_DEBUG, "Type: STRING\n"); char** strarr; int nstr = 0, istr; - if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + if (userdefinedtype->compoundfield[j].pointer) { // Pointer to string array + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data if (STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { - rc = rc && xdr_int(xdrs, &nstr); // Number of strings + rc = rc && xdr_int(xdrs, &nstr); // Number of strings if (nstr > 0) { char** str = (char**)malloc(nstr * sizeof(char*)); addMalloc(logmalloclist, (void*)str, nstr, sizeof(char*), "STRING *"); @@ -1069,23 +1129,24 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, - &nstr); // nstr (count) is known from the client's malloc log and passed by the sender + rc = rc && + xdr_int( + xdrs, + &nstr); // nstr (count) is known from the client's malloc log and passed by the sender if (nstr > 0) { rc = rc && xdr_int(xdrs, - &rank); // Receive Shape of pointer arrays (not included in definition) + &rank); // Receive Shape of pointer arrays (not included in definition) if (rank > 1) { - shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration + shape = (int*)malloc(rank * sizeof(int)); // freed via the malloc log registration rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } else { shape = nullptr; } - strarr = (char**)malloc( - nstr * sizeof(char*)); // nstr is the length of the array, not the strings + strarr = (char**)malloc(nstr * + sizeof(char*)); // nstr is the length of the array, not the strings addMalloc2(logmalloclist, (void*)strarr, nstr, sizeof(char*), "STRING", rank, shape); *p = (VOIDTYPE)strarr; // Save pointer: First String will be written here - for (istr = 0; - istr < nstr; istr++) { // Receive individual String lengths, then the string + for (istr = 0; istr < nstr; istr++) { // Receive individual String lengths, then the string rc = rc && xdr_int(xdrs, &count); strarr[istr] = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)strarr[istr], count, sizeof(char), "STRING"); @@ -1094,13 +1155,15 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l *p = (VOIDTYPE)strarr[0]; } } - } else { break; } + } else { + break; + } } else { if (STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { char** str = (char**)*p; findMalloc(logmalloclist, (void*)&str, &nstr, &size, &type); - rc = rc && xdr_int(xdrs, &nstr); // Number of strings + rc = rc && xdr_int(xdrs, &nstr); // Number of strings if (nstr > 0) { for (istr = 0; istr < nstr; istr++) { findMalloc(logmalloclist, (void*)&str[istr], &count, &size, &type); @@ -1114,15 +1177,15 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - d = (char*)*p; // First string in the Array + d = (char*)*p; // First string in the Array if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } findMalloc2(logmalloclist, (void*)p, &nstr, &size, &type, &rank, - &shape); // Assume 0 means No Pointer data to send! + &shape); // Assume 0 means No Pointer data to send! // or heap allocated in external library! // Is this a fixed length array of strings ? @@ -1135,7 +1198,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l size = userdefinedtype->compoundfield[j].size; } - rc = rc && xdr_int(xdrs, &nstr); // This many strings to send + rc = rc && xdr_int(xdrs, &nstr); // This many strings to send if ((nstr == 0 || size == 0) && *p != 0) { addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, @@ -1143,17 +1206,17 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays + rc = rc && xdr_int(xdrs, &rank); // Send Shape of arrays if (rank > 1) { rc = rc && xdr_vector(xdrs, (char*)shape, rank, sizeof(int), (xdrproc_t)xdr_int); } if (rank == 0) { - rc = rc && xdr_int(xdrs, &size); // This length of string + rc = rc && xdr_int(xdrs, &size); // This length of string rc = rc && WrapXDRString(xdrs, (char*)d, size); } else { strarr = (char**)d; - for (istr = 0; istr < - nstr; istr++) { // Send individual String lengths, then the string itself + for (istr = 0; istr < nstr; + istr++) { // Send individual String lengths, then the string itself count = (int)strlen(strarr[istr]) + 1; rc = rc && xdr_int(xdrs, &count); rc = rc && WrapXDRString(xdrs, strarr[istr], count); @@ -1161,27 +1224,26 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } } - } else { - if (userdefinedtype->compoundfield[j].rank >= 1) { // fixed length Regular Strings + if (userdefinedtype->compoundfield[j].rank >= 1) { // fixed length Regular Strings if (userdefinedtype->compoundfield[j].rank == 1 && strcmp(userdefinedtype->compoundfield[j].type, "STRING *") != - 0) { // Element is a Single String + 0) { // Element is a Single String rc = rc && WrapXDRString(xdrs, (char*)p, userdefinedtype->compoundfield[j].count); - } else { // Element is a String Array: Treat as Rank 1 array + } else { // Element is a String Array: Treat as Rank 1 array if (userdefinedtype->compoundfield[j].rank == 1 && STR_EQUALS(userdefinedtype->compoundfield[j].type, "STRING *")) { char** str = (char**)p; - nstr = userdefinedtype->compoundfield[j].count; // Number of strings + nstr = userdefinedtype->compoundfield[j].count; // Number of strings for (istr = 0; istr < nstr; istr++) { if (xdrs->x_op == XDR_DECODE) { - rc = rc && xdr_int(xdrs, &count); // Arbitrary String length + rc = rc && xdr_int(xdrs, &count); // Arbitrary String length if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); rc = rc && WrapXDRString(xdrs, d, count); str[istr] = d; - } // Save pointer: data will be written here + } // Save pointer: data will be written here } else { findMalloc(logmalloclist, (void*)&str[istr], &count, &size, &type); rc = rc && xdr_int(xdrs, &count); @@ -1193,38 +1255,41 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } } else { char* str = (char*)p; - int stride = userdefinedtype->compoundfield[j].shape[0]; // String length + int stride = userdefinedtype->compoundfield[j].shape[0]; // String length nstr = 1; for (istr = 1; istr < userdefinedtype->compoundfield[j].rank; istr++) { - nstr = nstr * - userdefinedtype->compoundfield[j].shape[istr]; // Number of strings to send/receive + nstr = nstr * userdefinedtype->compoundfield[j] + .shape[istr]; // Number of strings to send/receive } - for (istr = 0; - istr < nstr; istr++) { // send/receive individual strings + for (istr = 0; istr < nstr; istr++) { // send/receive individual strings rc = rc && WrapXDRString(xdrs, &str[istr * stride], userdefinedtype->compoundfield[j].count); } } } } else { // Element is a Single String of any size - if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data - rc = rc && xdr_int(xdrs, - &count); // Count is known from the client's malloc log and passed by the sender + if (xdrs->x_op == XDR_DECODE) { // Allocate Heap for Data + rc = + rc && + xdr_int(xdrs, + &count); // Count is known from the client's malloc log and passed by the sender if (count > 0) { d = (char*)malloc(count * sizeof(char)); addMalloc(logmalloclist, (void*)d, count, sizeof(char), "STRING"); - *p = (VOIDTYPE)d; // Save pointer: data will be written here - } else { break; } + *p = (VOIDTYPE)d; // Save pointer: data will be written here + } else { + break; + } } else { d = (char*)*p; if (d == nullptr) { count = 0; - rc = rc && xdr_int(xdrs, &count); // No data to send + rc = rc && xdr_int(xdrs, &count); // No data to send break; } - findMalloc(logmalloclist, (void*)p, &count, &size, &type); // Assume 0 means No string to send! - if (count == 1 && - STR_EQUALS(type, "unknown")) { // ***** Fix for SOAP sources incomplete! + findMalloc(logmalloclist, (void*)p, &count, &size, + &type); // Assume 0 means No string to send! + if (count == 1 && STR_EQUALS(type, "unknown")) { // ***** Fix for SOAP sources incomplete! count = size; size = sizeof(char); } @@ -1241,15 +1306,16 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l break; } - // Atomic Type or User Defined Type => Recursive Send/Receive - // Scalar or Array of fixed count within a structure - // Pointer to Scalar or Array - // For fixed count types, the count is given by the structure definition - // For pointer types, the count is given by the malloc log + // Atomic Type or User Defined Type => Recursive Send/Receive + // Scalar or Array of fixed count within a structure + // Pointer to Scalar or Array + // For fixed count types, the count is given by the structure definition + // For pointer types, the count is given by the malloc log default: { - // Send or Receive the Count, Size and Type of the sub-structure (All atomic types except void are trapped before this point) + // Send or Receive the Count, Size and Type of the sub-structure (All atomic types except void are + // trapped before this point) UDA_LOG(UDA_LOG_DEBUG, "Type: OTHER - Void Type or Structure\n"); @@ -1259,13 +1325,13 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l // Interpret an 'unknown' void data type using knowledge of the gSOAP or DOM systems - if (type != nullptr && STR_EQUALS(type, "unknown")) { // arises from a malloc redirection + if (type != nullptr && STR_EQUALS(type, "unknown")) { // arises from a malloc redirection if (malloc_source == UDA_MALLOC_SOURCE_SOAP && j > 0 && STR_EQUALS(userdefinedtype->compoundfield[j - 1].name, "__size") && STR_EQUALS(userdefinedtype->compoundfield[j].name, &userdefinedtype->compoundfield[j - 1].name[6])) { - count = (int)*prev; // the value of __size... + count = (int)*prev; // the value of __size... size = getsizeof(userdefinedtypelist, userdefinedtype->compoundfield[j].type); type = userdefinedtype->compoundfield[j].type; } else { @@ -1274,7 +1340,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l totalsize = count * size; if (malloc_source == UDA_MALLOC_SOURCE_DOM && STR_EQUALS(userdefinedtype->compoundfield[j].type, "void")) { - ssize = sizeof(char); // Assume xml void pointer type is to char + ssize = sizeof(char); // Assume xml void pointer type is to char type = chartype; } else { ssize = getsizeof(userdefinedtypelist, userdefinedtype->compoundfield[j].type); @@ -1285,8 +1351,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l rcount = totalsize % ssize; size = ssize; count = totalsize / size; - if (rcount != 0) { - } + if (rcount != 0) {} } else { addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Specified malloc total size not integer multiple!"); @@ -1301,16 +1366,17 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l "Data Heap Allocation not found in log!"); break; } - } - rc = rc && xdr_int(xdrs, &count); // Not passed with the Structure definition + rc = rc && xdr_int(xdrs, &count); // Not passed with the Structure definition - if (count == 0) break; // Nothing to Send or Receive + if (count == 0) { + break; // Nothing to Send or Receive + } - loopcount = count; // Array Count + loopcount = count; // Array Count - rc = rc && xdr_int(xdrs, &size); // Structure Size + rc = rc && xdr_int(xdrs, &size); // Structure Size if (xdrs->x_op == XDR_DECODE) { rc = rc && WrapXDRString(xdrs, (char*)rudtype, MAXELEMENTNAME - 1); @@ -1320,17 +1386,20 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } if (protocolVersion >= 7) { - rc = rc && xdr_int(xdrs, &structRank); // Rank of the Structure Array + rc = rc && xdr_int(xdrs, &structRank); // Rank of the Structure Array if (structRank > 1) { - if (xdrs->x_op == XDR_DECODE) structShape = (int*)malloc(structRank * sizeof(int)); - rc = rc && - xdr_vector(xdrs, (char*)structShape, structRank, sizeof(int), (xdrproc_t)xdr_int); + if (xdrs->x_op == XDR_DECODE) { + structShape = (int*)malloc(structRank * sizeof(int)); + } + rc = + rc && xdr_vector(xdrs, (char*)structShape, structRank, sizeof(int), (xdrproc_t)xdr_int); } else { structShape = nullptr; } } - UDA_LOG(UDA_LOG_DEBUG, "Pointer: Send or Receive Count: %d, Size: %d, Type: %s\n", count, size, type); + UDA_LOG(UDA_LOG_DEBUG, "Pointer: Send or Receive Count: %d, Size: %d, Type: %s\n", count, size, + type); } else { @@ -1345,8 +1414,8 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l type = userdefinedtype->compoundfield[j].type; UDA_LOG(UDA_LOG_DEBUG, "Pointer: Send or Receive Count: %d, Size: %d, Type: %s\n", - userdefinedtype->compoundfield[j].count, userdefinedtype->compoundfield[j].size, - userdefinedtype->compoundfield[j].type); + userdefinedtype->compoundfield[j].count, userdefinedtype->compoundfield[j].size, + userdefinedtype->compoundfield[j].type); } // Pointer to structure definition (void type ignored) @@ -1355,7 +1424,7 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l strcmp(userdefinedtype->compoundfield[j].type, "void") != 0) { UDA_LOG(UDA_LOG_DEBUG, "**** Error #1: User Defined Type %s not known!\n", - userdefinedtype->compoundfield[j].type); + userdefinedtype->compoundfield[j].type); UDA_LOG(UDA_LOG_DEBUG, "structure Name: %s\n", userdefinedtype->name); UDA_LOG(UDA_LOG_DEBUG, "Element Type : %s\n", userdefinedtype->compoundfield[j].type); UDA_LOG(UDA_LOG_DEBUG, " Offset: %d\n", userdefinedtype->compoundfield[j].offset); @@ -1366,11 +1435,12 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l } // Must be a known User Defined Type - // Execute once for each structure array element: count comes either from the malloc log or from the structure definition for non-pointer types - // A new tree node is used for each array element when receiving + // Execute once for each structure array element: count comes either from the malloc log or from the + // structure definition for non-pointer types A new tree node is used for each array element when + // receiving - // When passing linked lists, the parent->child->parent link needs to be detected and blocked when sending. - // On receiving data, the pointer references can be added back. + // When passing linked lists, the parent->child->parent link needs to be detected and blocked when + // sending. On receiving data, the pointer references can be added back. if (utype != nullptr) { @@ -1388,19 +1458,15 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l id = findStructId(heap, &stype, log_struct_list); } - if (id == 0) { // Only send/receive new structures + if (id == 0) { // Only send/receive new structures if (userdefinedtype->compoundfield[j].pointer) { - rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, - userdefinedtypelist, utype, - (void**)p, count, - structRank, structShape, i, &subNTree, protocolVersion, - malloc_source); + rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, + utype, (void**)p, count, structRank, structShape, i, + &subNTree, protocolVersion, malloc_source); } else { - rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, - userdefinedtypelist, utype, - (void**)&p, count, - structRank, structShape, i, &subNTree, protocolVersion, - malloc_source); + rc = rc && xdrUserDefinedData(xdrs, logmalloclist, log_struct_list, userdefinedtypelist, + utype, (void**)&p, count, structRank, structShape, i, + &subNTree, protocolVersion, malloc_source); } // Add the new data branch to the tree @@ -1411,24 +1477,25 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l strcpy(subNTree->name, userdefinedtype->compoundfield[j].name); if (i == 0 && loopcount > 0) { if (newNTree->children == nullptr && newNTree->branches == 0) { - newNTree->children = (NTREE**)malloc( - loopcount * sizeof(NTREE*)); // Allocate the node array - addMalloc(logmalloclist, (void*)newNTree->children, loopcount, sizeof(NTREE*), "NTREE *"); - } else { // Multiple branches (user types) originating in the same node + newNTree->children = + (NTREE**)malloc(loopcount * sizeof(NTREE*)); // Allocate the node array + addMalloc(logmalloclist, (void*)newNTree->children, loopcount, sizeof(NTREE*), + "NTREE *"); + } else { // Multiple branches (user types) originating in the same node auto old = (VOIDTYPE)newNTree->children; - newNTree->children = (NTREE**)realloc((void*)old, - (newNTree->branches + loopcount) * - sizeof(NTREE*)); // Individual node addresses remain valid + newNTree->children = (NTREE**)realloc( + (void*)old, + (newNTree->branches + loopcount) * + sizeof(NTREE*)); // Individual node addresses remain valid changeMalloc(logmalloclist, old, (void*)newNTree->children, newNTree->branches + loopcount, sizeof(NTREE*), "NTREE *"); } } - addNTree(newNTree, subNTree); // Only first call creates new tree node + addNTree(newNTree, subNTree); // Only first call creates new tree node } } else { } - } break; @@ -1438,33 +1505,29 @@ int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* l if (gettypeof(type) != UDA_TYPE_UNKNOWN) { char* z = (char*)*p; - rc = rc && xdrAtomicData(logmalloclist, xdrs, type, count, size, &z); // Must be an Atomic Type + rc = rc && xdrAtomicData(logmalloclist, xdrs, type, count, size, &z); // Must be an Atomic Type *p = (VOIDTYPE)z; break; } else { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "User Defined Type not known!"); + addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "User Defined Type not known!"); break; } } addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "Type not known!"); break; - } } if (!rc) { - addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, - "XDR Return Code False => Bad send/receive!"); + addIdamError(UDA_CODE_ERROR_TYPE, "xdrUserDefinedData", 999, "XDR Return Code False => Bad send/receive!"); recursiveDepth--; return rc; } - prev = p; // Preserve the previous data pointer + prev = p; // Preserve the previous data pointer } recursiveDepth--; return rc; } - diff --git a/source/structures/xdrUserDefinedData.h b/source/structures/xdrUserDefinedData.h old mode 100755 new mode 100644 index a75dd201..3430853e --- a/source/structures/xdrUserDefinedData.h +++ b/source/structures/xdrUserDefinedData.h @@ -3,8 +3,8 @@ #include -#include "genStructs.h" #include "export.h" +#include "genStructs.h" #ifdef __cplusplus extern "C" { @@ -12,8 +12,8 @@ extern "C" { LIBRARY_API int xdrUserDefinedData(XDR* xdrs, LOGMALLOCLIST* logmalloclist, LOGSTRUCTLIST* log_struct_list, USERDEFINEDTYPELIST* userdefinedtypelist, USERDEFINEDTYPE* userdefinedtype, - void** data, int datacount, int structRank, int* structShape, - int index, NTREE** NTree, int protocolVersion, int malloc_source); + void** data, int datacount, int structRank, int* structShape, int index, + NTREE** NTree, int protocolVersion, int malloc_source); #ifdef __cplusplus } diff --git a/source/uda.h b/source/uda.h old mode 100755 new mode 100644 index 79f25f7d..cefcfb65 --- a/source/uda.h +++ b/source/uda.h @@ -1,24 +1,24 @@ #pragma once #ifndef UDA_H -#define UDA_H +# define UDA_H -#include "accAPI.h" -#include "accessors.h" -#include "clientAPI.h" -#include "clientMDS.h" -#include "genStructs.h" -#include "initStructs.h" -#include "struct.h" -#include "udaGetAPI.h" -#include "udaPlugin.h" -#include "udaPutAPI.h" -#include "udaStructs.h" -#include "udaTypes.h" -#include "version.h" +# include "accAPI.h" +# include "accessors.h" +# include "clientAPI.h" +# include "clientMDS.h" +# include "genStructs.h" +# include "initStructs.h" +# include "struct.h" +# include "udaGetAPI.h" +# include "udaPlugin.h" +# include "udaPutAPI.h" +# include "udaStructs.h" +# include "udaTypes.h" +# include "version.h" -#ifdef UDA_LEGACY -# include "legacy.h" -#endif // UDA_LEGACY +# ifdef UDA_LEGACY +# include "legacy.h" +# endif // UDA_LEGACY #endif // UDA_H diff --git a/source/wrappers/PHP/php_idamgetapi.cpp b/source/wrappers/PHP/php_idamgetapi.cpp old mode 100755 new mode 100644 index bb3ac215..92e8be4f --- a/source/wrappers/PHP/php_idamgetapi.cpp +++ b/source/wrappers/PHP/php_idamgetapi.cpp @@ -6,15 +6,15 @@ * Default Cpp libraries */ -#include #include +#include /** * Libraries used. */ -#include #include #include +#include /** * Namespace to use @@ -27,7 +27,7 @@ using namespace std; * @return Php::Value the IDAM data handle (integer) * @param Php::Parameters the two API arguments */ -Php::Value idamgetapi(Php::Parameters & params) +Php::Value idamgetapi(Php::Parameters& params) { if (params.size() != 2) { return "The API requires 2 string arguments!"; @@ -41,7 +41,7 @@ Php::Value idamgetapi(Php::Parameters & params) * @return Php::Value the error code * @param Php::Parameters the data handle (integer) */ -Php::Value getidamerrorcode(Php::Parameters & params) +Php::Value getidamerrorcode(Php::Parameters& params) { if (params.size() != 1) { return "The getidamerrorcode function requires 1 integer argument!"; @@ -54,7 +54,7 @@ Php::Value getidamerrorcode(Php::Parameters & params) * @return Php::Value the error message * @param Php::Parameters the data handle (integer) */ -Php::Value getidamerrormsg(Php::Parameters & params) +Php::Value getidamerrormsg(Php::Parameters& params) { if (params.size() != 1) { return "The getidamerrormsg function requires 1 integer argument!"; @@ -68,7 +68,7 @@ Php::Value getidamerrormsg(Php::Parameters & params) * @return Php::Value the data rank * @param Php::Parameters the data handle (integer) */ -Php::Value getidamrank(Php::Parameters & params) +Php::Value getidamrank(Php::Parameters& params) { if (params.size() != 1) { return "The getidamrank function requires 1 integer argument!"; @@ -81,7 +81,7 @@ Php::Value getidamrank(Php::Parameters & params) * @return Php::Value the data array element count * @param Php::Parameters the data handle (integer) */ -Php::Value getidamdatanum(Php::Parameters & params) +Php::Value getidamdatanum(Php::Parameters& params) { if (params.size() != 1) { return "The getidamdatanum function requires 1 integer argument!"; @@ -94,7 +94,7 @@ Php::Value getidamdatanum(Php::Parameters & params) * @return Php::Value the data type * @param Php::Parameters the data handle (integer) */ -Php::Value getidamdatatype(Php::Parameters & params) +Php::Value getidamdatatype(Php::Parameters& params) { if (params.size() != 1) { return "The getidamdatatype function requires 1 integer argument!"; @@ -111,17 +111,17 @@ Php::Value getidamdatatype(Php::Parameters & params) * @return Php::Value the returned uuid * @param Php::Parameters the data handle (integer) */ -Php::Value getidamuuid(Php::Parameters & params) +Php::Value getidamuuid(Php::Parameters& params) { if (params.size() != 1) { return "The getidamuuid function requires 1 string argument!"; } - //std::string arg = params[0]; - //int length = arg.length(); + // std::string arg = params[0]; + // int length = arg.length(); - char * work = (char *)malloc((params[0].length() + 256) * sizeof(char)); - //char *work = (char *)malloc((strlen(params[0])+256)*sizeof(char)); + char* work = (char*)malloc((params[0].length() + 256) * sizeof(char)); + // char *work = (char *)malloc((strlen(params[0])+256)*sizeof(char)); strcpy(work, "provenance::get("); strcat(work, params[0]); strcat(work, ", /returnUUID)"); @@ -129,12 +129,12 @@ Php::Value getidamuuid(Php::Parameters & params) int h = idamGetAPI(work, ""); if (work != NULL) { - free((void *)work); + free((void*)work); } if (h >= 0 && getIdamErrorCode(h) == 0) { if (getIdamDataType(h) == UDA_TYPE_CHAR || getIdamDataType(h) == UDA_TYPE_STRING) { - return (char *)getIdamData(h); + return (char*)getIdamData(h); } } else { if (h >= 0) { @@ -151,9 +151,9 @@ Php::Value getidamuuid(Php::Parameters & params) * @return Php::Value the current uuid status * @param Php::Parameters the uuid */ -Php::Value getidamuuidstatus(Php::Parameters & params) +Php::Value getidamuuidstatus(Php::Parameters& params) { - if (params.size() != 1 ) { + if (params.size() != 1) { return "The getidamuuidstatus function requires a uuid (string) argument!"; } @@ -161,13 +161,13 @@ Php::Value getidamuuidstatus(Php::Parameters & params) strcpy(work, "provenance::status(uuid='"); strcat(work, params[0]); strcat(work, "', /returnStatus)"); - //sprintf(work, "provenance::status(uuid='%s', /returnStatus)", (char *)params[0]); + // sprintf(work, "provenance::status(uuid='%s', /returnStatus)", (char *)params[0]); int h = idamGetAPI(work, ""); if (h >= 0 && getIdamErrorCode(h) == 0) { if (getIdamDataType(h) == UDA_TYPE_CHAR || getIdamDataType(h) == UDA_TYPE_STRING) { - return (char *)getIdamData(h); + return (char*)getIdamData(h); } } else { if (h >= 0) { @@ -184,10 +184,12 @@ Php::Value getidamuuidstatus(Php::Parameters & params) * @return Php::Value the uuid status to be set * @param Php::Parameters the uuid */ -Php::Value putidamuuidstatus(Php::Parameters & params) +Php::Value putidamuuidstatus(Php::Parameters& params) { - if (params.size() != 2) return "The putidamuuidstatus function requires a uuid (string)" - "and a status (string) value!"; + if (params.size() != 2) { + return "The putidamuuidstatus function requires a uuid (string)" + "and a status (string) value!"; + } char work[1024]; strcpy(work, "provenance::status(uuid='"); @@ -202,7 +204,7 @@ Php::Value putidamuuidstatus(Php::Parameters & params) if (h >= 0 && getIdamErrorCode(h) == 0) { if (getIdamDataType(h) == UDA_TYPE_CHAR || getIdamDataType(h) == UDA_TYPE_STRING) { - return (char *)getIdamData(h); + return (char*)getIdamData(h); } } else { if (h >= 0) { @@ -219,13 +221,13 @@ Php::Value putidamuuidstatus(Php::Parameters & params) * @return Php::Value the data archive directory path * @param Php::Parameters the data handle (integer) */ -Php::Value putidamprovenance(Php::Parameters & params) +Php::Value putidamprovenance(Php::Parameters& params) { if (params.size() != 1) { return "The putidamprovenance function requires 1 string argument!"; } - char * work = (char *)malloc((params[0].length() + 256) * sizeof(char)); + char* work = (char*)malloc((params[0].length() + 256) * sizeof(char)); strcpy(work, "provenance::put("); strcat(work, params[0]); strcat(work, ", /returnPath)"); @@ -233,12 +235,12 @@ Php::Value putidamprovenance(Php::Parameters & params) int h = idamGetAPI(work, ""); if (work != NULL) { - free((void *)work); + free((void*)work); } if (h >= 0 && getIdamErrorCode(h) == 0) { if (getIdamDataType(h) == UDA_TYPE_CHAR || getIdamDataType(h) == UDA_TYPE_STRING) { - return (char *)getIdamData(h); + return (char*)getIdamData(h); } } else { if (h >= 0) { @@ -251,55 +253,30 @@ Php::Value putidamprovenance(Php::Parameters & params) return "Error B in putidamprovenance"; } - // Symbols are exported according to the "C" language -extern "C" +extern "C" { +// export the "get_module" function that will be called by the Zend engine +PHPCPP_EXPORT void* get_module() { - // export the "get_module" function that will be called by the Zend engine - PHPCPP_EXPORT void * get_module() - { - // create the extension - static Php::Extension extension("idamgetapi", "1.0"); - - // add API functions to the extension - - extension.add("idamgetapi", idamgetapi, { - Php::ByVal("x", Php::Type::String), - Php::ByVal("y", Php::Type::String) - }); - extension.add("getidamerrorcode", getidamerrorcode, { - Php::ByVal("h", Php::Type::Numeric) - }); - extension.add("getidamerrormsg", getidamerrormsg, { - Php::ByVal("h", Php::Type::Numeric) - }); - extension.add("getidamrank", getidamrank, { - Php::ByVal("h", Php::Type::Numeric) - }); - extension.add("getidamdatanum", getidamdatanum, { - Php::ByVal("h", Php::Type::Numeric) - }); - extension.add("getidamdatatype", getidamdatatype, { - Php::ByVal("h", Php::Type::Numeric) - }); - - extension.add("getidamuuid", getidamuuid, { - Php::ByVal("h", Php::Type::String) - }); - extension.add("getidamuuidstatus", getidamuuidstatus, { - Php::ByVal("a", Php::Type::String) - }); - extension.add("putidamuuidstatus", putidamuuidstatus, { - Php::ByVal("a", Php::Type::String), - Php::ByVal("b", Php::Type::String) - }); - extension.add("putidamprovenance", putidamprovenance, { - Php::ByVal("b", Php::Type::String) - }); - - - // return the extension module - return extension.module(); - } + // create the extension + static Php::Extension extension("idamgetapi", "1.0"); + + // add API functions to the extension + + extension.add("idamgetapi", idamgetapi, {Php::ByVal("x", Php::Type::String), Php::ByVal("y", Php::Type::String)}); + extension.add("getidamerrorcode", getidamerrorcode, {Php::ByVal("h", Php::Type::Numeric)}); + extension.add("getidamerrormsg", getidamerrormsg, {Php::ByVal("h", Php::Type::Numeric)}); + extension.add("getidamrank", getidamrank, {Php::ByVal("h", Php::Type::Numeric)}); + extension.add("getidamdatanum", getidamdatanum, {Php::ByVal("h", Php::Type::Numeric)}); + extension.add("getidamdatatype", getidamdatatype, {Php::ByVal("h", Php::Type::Numeric)}); + + extension.add("getidamuuid", getidamuuid, {Php::ByVal("h", Php::Type::String)}); + extension.add("getidamuuidstatus", getidamuuidstatus, {Php::ByVal("a", Php::Type::String)}); + extension.add("putidamuuidstatus", putidamuuidstatus, + {Php::ByVal("a", Php::Type::String), Php::ByVal("b", Php::Type::String)}); + extension.add("putidamprovenance", putidamprovenance, {Php::ByVal("b", Php::Type::String)}); + + // return the extension module + return extension.module(); +} } - diff --git a/source/wrappers/c++/array.cpp b/source/wrappers/c++/array.cpp old mode 100755 new mode 100644 index 31857802..c7c284f6 --- a/source/wrappers/c++/array.cpp +++ b/source/wrappers/c++/array.cpp @@ -1,5 +1,6 @@ #ifdef _WIN32 -// this needs to be included until we can remove the need to include in udaClient.h, i.e after removal of XDR globals. +// this needs to be included until we can remove the need to include in udaClient.h, i.e after removal of XDR +// globals. # include #endif #include diff --git a/source/wrappers/c++/client.cpp b/source/wrappers/c++/client.cpp old mode 100755 new mode 100644 index acf40f58..e3d40c27 --- a/source/wrappers/c++/client.cpp +++ b/source/wrappers/c++/client.cpp @@ -1,15 +1,15 @@ #include "client.hpp" +#include #include #include -#include #include "accAPI.h" -#include "udaGetAPI.h" #include "client.h" +#include "initStructs.h" +#include "udaGetAPI.h" #include "udaPutAPI.h" #include "udaTypes.h" -#include "initStructs.h" #include "data.hpp" #include "result.hpp" @@ -20,21 +20,51 @@ void uda::Client::setProperty(Property prop, bool value) std::string name; switch (prop) { - case PROP_DATADBLE: name = "get_datadble"; break; - case PROP_DIMDBLE: name = "get_dimdble"; break; - case PROP_TIMEDBLE: name = "get_timedble"; break; - case PROP_BYTES: name = "get_bytes"; break; - case PROP_BAD: name = "get_bad"; break; - case PROP_META: name = "get_meta"; break; - case PROP_ASIS: name = "get_asis"; break; - case PROP_UNCAL: name = "get_uncal"; break; - case PROP_NOTOFF: name = "get_notoff"; break; - case PROP_SYNTHETIC: name = "get_synthetic"; break; - case PROP_SCALAR: name = "get_scalar"; break; - case PROP_NODIMDATA: name = "get_nodimdata"; break; - case PROP_VERBOSE: name = "verbose"; break; - case PROP_DEBUG: name = "debug"; break; - case PROP_ALTDATA: name = "altdata"; break; + case PROP_DATADBLE: + name = "get_datadble"; + break; + case PROP_DIMDBLE: + name = "get_dimdble"; + break; + case PROP_TIMEDBLE: + name = "get_timedble"; + break; + case PROP_BYTES: + name = "get_bytes"; + break; + case PROP_BAD: + name = "get_bad"; + break; + case PROP_META: + name = "get_meta"; + break; + case PROP_ASIS: + name = "get_asis"; + break; + case PROP_UNCAL: + name = "get_uncal"; + break; + case PROP_NOTOFF: + name = "get_notoff"; + break; + case PROP_SYNTHETIC: + name = "get_synthetic"; + break; + case PROP_SCALAR: + name = "get_scalar"; + break; + case PROP_NODIMDATA: + name = "get_nodimdata"; + break; + case PROP_VERBOSE: + name = "verbose"; + break; + case PROP_DEBUG: + name = "debug"; + break; + case PROP_ALTDATA: + name = "altdata"; + break; case PROP_TIMEOUT: case PROP_ALTRANK: @@ -45,9 +75,7 @@ void uda::Client::setProperty(Property prop, bool value) } CLIENT_FLAGS* client_flags = udaClientFlags(); - value - ? setIdamProperty(name.c_str(), client_flags) - : resetIdamProperty(name.c_str(), client_flags); + value ? setIdamProperty(name.c_str(), client_flags) : resetIdamProperty(name.c_str(), client_flags); } void uda::Client::setProperty(Property prop, int value) @@ -95,23 +123,40 @@ int uda::Client::property(Property prop) { auto client_flags = udaClientFlags(); switch (prop) { - case PROP_DATADBLE: return getIdamProperty("get_datadble", client_flags); - case PROP_DIMDBLE: return getIdamProperty("get_dimdble", client_flags); - case PROP_TIMEDBLE: return getIdamProperty("get_timedble", client_flags); - case PROP_BYTES: return getIdamProperty("get_bytes", client_flags); - case PROP_BAD: return getIdamProperty("get_bad", client_flags); - case PROP_META: return getIdamProperty("get_meta", client_flags); - case PROP_ASIS: return getIdamProperty("get_asis", client_flags); - case PROP_UNCAL: return getIdamProperty("get_uncal", client_flags); - case PROP_NOTOFF: return getIdamProperty("get_notoff", client_flags); - case PROP_SYNTHETIC: return getIdamProperty("get_synthetic", client_flags); - case PROP_SCALAR: return getIdamProperty("get_scalar", client_flags); - case PROP_NODIMDATA: return getIdamProperty("get_nodimdata", client_flags); - case PROP_VERBOSE: return getIdamProperty("verbose", client_flags); - case PROP_DEBUG: return getIdamProperty("debug", client_flags); - case PROP_ALTDATA: return getIdamProperty("altdata", client_flags); - case PROP_TIMEOUT: return getIdamProperty("timeout", client_flags); - case PROP_ALTRANK: return getIdamProperty("altrank", client_flags); + case PROP_DATADBLE: + return getIdamProperty("get_datadble", client_flags); + case PROP_DIMDBLE: + return getIdamProperty("get_dimdble", client_flags); + case PROP_TIMEDBLE: + return getIdamProperty("get_timedble", client_flags); + case PROP_BYTES: + return getIdamProperty("get_bytes", client_flags); + case PROP_BAD: + return getIdamProperty("get_bad", client_flags); + case PROP_META: + return getIdamProperty("get_meta", client_flags); + case PROP_ASIS: + return getIdamProperty("get_asis", client_flags); + case PROP_UNCAL: + return getIdamProperty("get_uncal", client_flags); + case PROP_NOTOFF: + return getIdamProperty("get_notoff", client_flags); + case PROP_SYNTHETIC: + return getIdamProperty("get_synthetic", client_flags); + case PROP_SCALAR: + return getIdamProperty("get_scalar", client_flags); + case PROP_NODIMDATA: + return getIdamProperty("get_nodimdata", client_flags); + case PROP_VERBOSE: + return getIdamProperty("verbose", client_flags); + case PROP_DEBUG: + return getIdamProperty("debug", client_flags); + case PROP_ALTDATA: + return getIdamProperty("altdata", client_flags); + case PROP_TIMEOUT: + return getIdamProperty("timeout", client_flags); + case PROP_ALTRANK: + return getIdamProperty("altrank", client_flags); default: throw UDAException("Unknown property"); @@ -147,7 +192,8 @@ int uda::Client::serverPort() 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.push_back(std::string("[") + errorstack->idamerror[i].location + + "]: " + errorstack->idamerror[i].msg); } if ((code > 0 && code < 25) || (code > 60 && code < 66)) { @@ -211,8 +257,7 @@ uda::ResultList uda::Client::get_batch(const std::vector indices, Client& client) - : indices_{std::move(indices)} - , client_(client) + : indices_{std::move(indices)}, client_(client) { } @@ -238,52 +283,67 @@ const uda::Result& uda::Client::at(size_t index) static int typeIDToUDAType(const std::type_info& type) { - if (type == typeid(char)) + if (type == typeid(char)) { return UDA_TYPE_CHAR; - if (type == typeid(short)) + } + if (type == typeid(short)) { return UDA_TYPE_SHORT; - if (type == typeid(int)) + } + if (type == typeid(int)) { return UDA_TYPE_INT; - if (type == typeid(unsigned int)) + } + if (type == typeid(unsigned int)) { return UDA_TYPE_UNSIGNED_INT; - if (type == typeid(long)) + } + if (type == typeid(long)) { return UDA_TYPE_LONG; - if (type == typeid(float)) + } + if (type == typeid(float)) { return UDA_TYPE_FLOAT; - if (type == typeid(double)) + } + if (type == typeid(double)) { return UDA_TYPE_DOUBLE; - if (type == typeid(unsigned char)) + } + if (type == typeid(unsigned char)) { return UDA_TYPE_UNSIGNED_CHAR; - if (type == typeid(unsigned short)) + } + if (type == typeid(unsigned short)) { return UDA_TYPE_UNSIGNED_SHORT; - if (type == typeid(unsigned long)) + } + if (type == typeid(unsigned long)) { return UDA_TYPE_UNSIGNED_LONG; - if (type == typeid(long long)) + } + if (type == typeid(long long)) { return UDA_TYPE_LONG64; - if (type == typeid(unsigned long long)) + } + if (type == typeid(unsigned long long)) { return UDA_TYPE_UNSIGNED_LONG64; - if (type == typeid(std::complex)) + } + if (type == typeid(std::complex)) { return UDA_TYPE_COMPLEX; - if (type == typeid(std::complex)) + } + if (type == typeid(std::complex)) { return UDA_TYPE_DCOMPLEX; - if (type == typeid(char*)) + } + if (type == typeid(char*)) { return UDA_TYPE_STRING; + } return UDA_TYPE_UNKNOWN; } -//typedef struct PutDataBlock { -// int data_type; -// unsigned int rank; -// unsigned int count; -// int* shape; -// const char* data; -// int opaque_type; // Identifies the Data Structure Type; -// int opaque_count; // Number of Instances of the Data Structure; -// void* opaque_block; // Opaque pointer to Hierarchical Data Structures -// unsigned int blockNameLength; // Size of the Name character string -// char* blockName; // Name of the Data Block -//} PUTDATA_BLOCK; +// typedef struct PutDataBlock { +// int data_type; +// unsigned int rank; +// unsigned int count; +// int* shape; +// const char* data; +// int opaque_type; // Identifies the Data Structure Type; +// int opaque_count; // Number of Instances of the Data Structure; +// void* opaque_block; // Opaque pointer to Hierarchical Data Structures +// unsigned int blockNameLength; // Size of the Name character string +// char* blockName; // Name of the Data Block +// } PUTDATA_BLOCK; void uda::Client::put(const uda::Signal& signal) { @@ -302,18 +362,19 @@ void uda::Client::put(const uda::Signal& signal) break; } - std::string request = (boost::format("putdata::open(/create," - " filename='%s'," - " conventions='Fusion-1.0'," - " class='%s'," - " title='%s'," - " shot=%d," - " pass=%d," - " comment='%s'," - " code=%s," - " version=1)") - % filename % signal_class % signal.title() % signal.shot() % signal.pass() - % signal.comment() % signal.code()).str(); + std::string request = + (boost::format("putdata::open(/create," + " filename='%s'," + " conventions='Fusion-1.0'," + " class='%s'," + " title='%s'," + " shot=%d," + " pass=%d," + " comment='%s'," + " code=%s," + " version=1)") % + filename % signal_class % signal.title() % signal.shot() % signal.pass() % signal.comment() % signal.code()) + .str(); idamPutAPI(request.c_str(), nullptr); @@ -334,8 +395,7 @@ void uda::Client::put(const uda::Signal& signal) idamPutAPI("", &pdblock); } -template -void put_scalar(const std::string& instruction, T data) +template void put_scalar(const std::string& instruction, T data) { PUTDATA_BLOCK putdata_block{}; initIdamPutDataBlock(&putdata_block); @@ -355,20 +415,52 @@ void put_scalar(const std::string& instruction, T data) delete dp; } -void uda::Client::put(const std::string& instruction, char data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, int8_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, int16_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, int32_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, int64_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, uint8_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, uint16_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, uint32_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, uint64_t data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, float data) { put_scalar(instruction, data); } -void uda::Client::put(const std::string& instruction, double data) { put_scalar(instruction, data); } +void uda::Client::put(const std::string& instruction, char data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, int8_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, int16_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, int32_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, int64_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, uint8_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, uint16_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, uint32_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, uint64_t data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, float data) +{ + put_scalar(instruction, data); +} +void uda::Client::put(const std::string& instruction, double data) +{ + put_scalar(instruction, data); +} -template -void put_vector(const std::string& instruction, const std::vector& data) +template void put_vector(const std::string& instruction, const std::vector& data) { PUTDATA_BLOCK putdata_block{}; initIdamPutDataBlock(&putdata_block); @@ -389,35 +481,64 @@ void put_vector(const std::string& instruction, const std::vector& data) delete[] shape; } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } -void uda::Client::put(const std::string& instruction, const std::vector& data) { put_vector(instruction, data); } +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} +void uda::Client::put(const std::string& instruction, const std::vector& data) +{ + put_vector(instruction, data); +} uda::Client::~Client() { for (auto& data : results_) { - delete(data); + delete (data); } -// udaFreeAll(nullptr, nullptr); + // udaFreeAll(nullptr, nullptr); } void uda::Client::put(const std::string& instruction, const uda::Array& data) { // Use to convert size_t to int - struct Downcast - { - int operator() (size_t s) const - { - return static_cast(s); - } + struct Downcast { + int operator()(size_t s) const { return static_cast(s); } }; PUTDATA_BLOCK putdata_block{}; @@ -431,7 +552,7 @@ void uda::Client::put(const std::string& instruction, const uda::Array& data) std::vector shape; // C++ error: conversion from 'size_t' to 'const int', possible loss of data - //std::copy(array_shape.begin(), array_shape.end(), std::back_inserter(shape)); + // std::copy(array_shape.begin(), array_shape.end(), std::back_inserter(shape)); std::transform(array_shape.begin(), array_shape.end(), std::back_inserter(shape), Downcast()); putdata_block.shape = shape.data(); diff --git a/source/wrappers/c++/dim.cpp b/source/wrappers/c++/dim.cpp old mode 100755 new mode 100644 index a0579b54..91d06df6 --- a/source/wrappers/c++/dim.cpp +++ b/source/wrappers/c++/dim.cpp @@ -5,4 +5,3 @@ #include "dim.hpp" uda::Dim uda::Dim::Null = uda::Dim(); - diff --git a/source/wrappers/c++/main.cpp b/source/wrappers/c++/main.cpp old mode 100755 new mode 100644 index 1fd93327..948f9d97 --- a/source/wrappers/c++/main.cpp +++ b/source/wrappers/c++/main.cpp @@ -1,27 +1,27 @@ -#include #include #include +#include #include "UDA.hpp" struct coilGeometryType { - int id ; - int count ; - double turnCount[63] ; - double rCentre[63] ; - double zCentre[63] ; - double dR[63] ; - double dZ[63] ; - double angle1[63] ; - double angle2[63] ; + int id; + int count; + double turnCount[63]; + double rCentre[63]; + double zCentre[63]; + double dR[63]; + double dZ[63]; + double angle1[63]; + double angle2[63]; }; int main() { int test = 1; - //uda::Client::setServerHostName("localhost"); - //uda::Client::setServerPort(56564); + // uda::Client::setServerHostName("localhost"); + // uda::Client::setServerPort(56564); uda::Client::setServerHostName("idam0"); uda::Client::setServerPort(56561); @@ -59,7 +59,9 @@ int main() std::cout << dim.label() << std::endl; std::cout << dim.units() << std::endl; - if (test != 0) return 0; + if (test != 0) { + return 0; + } } //----------------------------------------------------------------------------------- @@ -106,10 +108,10 @@ int main() }; typedef struct DATALASTSHOT DATALASTSHOT; - DATALASTSHOT *datalastshot = (DATALASTSHOT *)node.data(); + DATALASTSHOT* datalastshot = (DATALASTSHOT*)node.data(); printf("\nstructure array count = %d\n\n", count); - printf("\nlast shot = %d\n\n", (int) datalastshot->lastshot); + printf("\nlast shot = %d\n\n", (int)datalastshot->lastshot); // Alternatively, assuming the structure definition is volatile, extract the atomic // scalar component directly @@ -130,17 +132,14 @@ int main() std::vector anames = node.atomicNames(); std::vector atypes = node.atomicTypes(); std::vector apoint = node.atomicPointers(); // is this component a Pointer - std::vector arank = node.atomicRank(); - std::vector > ashape = node.atomicShape(); + std::vector arank = node.atomicRank(); + std::vector> ashape = node.atomicShape(); - for (int i=0; i < acount; i++) { - fprintf(stdout, "%s [%s] %d %zu\n", - anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i]); + for (int i = 0; i < acount; i++) { + fprintf(stdout, "%s [%s] %d %zu\n", anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i]); - if (anames[i] == "lastshot" - && atypes[i] == "unsigned int" - && !apoint[i] - && (arank[i] == 0 || (arank[i] == 1 && ashape[i][0] == 1))) { + if (anames[i] == "lastshot" && atypes[i] == "unsigned int" && !apoint[i] && + (arank[i] == 0 || (arank[i] == 1 && ashape[i][0] == 1))) { unsigned int lastshot = *reinterpret_cast(node.structureComponentData(anames[i])); printf("\nlast shot = %u\n\n", lastshot); break; @@ -161,7 +160,9 @@ int main() printf("\ntype = %s\n", lastshot.type().name()); printf("\nlast shot = %u\n\n", lastshot.as()); - if (test != 0) return 0; + if (test != 0) { + return 0; + } } //----------------------------------------------------------------------------------- @@ -212,11 +213,13 @@ int main() // the returned data is an array of structures - loop over each array member and print the signal name for (std::vector::iterator iter = children.begin(); iter != children.end(); ++iter) { - char * signal_name = reinterpret_cast(iter->structureComponentData("signal_name")); + char* signal_name = reinterpret_cast(iter->structureComponentData("signal_name")); printf("%s\n", signal_name); } - if (test != 0) return 0; + if (test != 0) { + return 0; + } } //======================================================================================================= @@ -224,7 +227,8 @@ int main() if (test == 4 || test == 0) { - const uda::Result& data = client.get("meta::listdata(context=data,cast=COLUMN,device=MAST,shot=22812)", "MAST::"); + const uda::Result& data = + client.get("meta::listdata(context=data,cast=COLUMN,device=MAST,shot=22812)", "MAST::"); // Check for errors if (data.errorCode() != uda::OK) { @@ -269,14 +273,14 @@ int main() unsigned int count; unsigned int shot; int pass; - char **signal_name; - char **generic_name; - char **source_alias; - char **type; - char **description; + char** signal_name; + char** generic_name; + char** source_alias; + char** type; + char** description; }; - DATALISTSIGNALS_C * sdata = reinterpret_cast(node.data()); + DATALISTSIGNALS_C* sdata = reinterpret_cast(node.data()); printf("\nstructure array count = %d\n\n", sdata->count); @@ -300,9 +304,9 @@ int main() fprintf(stdout, "%s [%s] %d %zu\n", anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i]); } - int signalListCount = *reinterpret_cast(node.structureComponentData("count")); + int signalListCount = *reinterpret_cast(node.structureComponentData("count")); - char ** signalList = reinterpret_cast(node.structureComponentData("signal_name")); + char** signalList = reinterpret_cast(node.structureComponentData("signal_name")); for (int i = 0; i < signalListCount; ++i) { printf("%s\n", signalList[i]); @@ -310,19 +314,21 @@ int main() // Use the High level method - std::vector signalVec = node.atomicVector("signal_name").as(); + std::vector signalVec = node.atomicVector("signal_name").as(); - for (std::vector::iterator iter = signalVec.begin(); iter != signalVec.end(); ++iter) { + for (std::vector::iterator iter = signalVec.begin(); iter != signalVec.end(); ++iter) { printf("%s\n", *iter); } - if (test != 0) return 0; + if (test != 0) { + return 0; + } } //============================================================================================================= // Code configuration signal set names - if(test == 5 || test == 0) { + if (test == 5 || test == 0) { struct SIGNALSET { int type; @@ -333,7 +339,9 @@ int main() char configuration[20]; }; - const uda::Result& data = client.get("meta::getdata(context=meta,device=MAST,cast=column,class=code,system=specview,configuration=default,/latest)", "MAST::22812"); + const uda::Result& data = client.get("meta::getdata(context=meta,device=MAST,cast=column,class=code,system=" + "specview,configuration=default,/latest)", + "MAST::22812"); // Check for errors if (data.errorCode() != uda::OK) { @@ -380,56 +388,59 @@ int main() // Loop over all child nodes (structure array elements) and print the atomic data from each - char * name; - char * className; - char * system; - char * subSystem; - char * configuration; + char* name; + char* className; + char* system; + char* subSystem; + char* configuration; int i = 0; for (std::vector::iterator iter = signals.begin(); iter != signals.end(); ++iter) { - name = iter->atomicScalar("name").as(); - className = iter->atomicScalar("class").as(); - system = iter->atomicScalar("system").as(); - subSystem = iter->atomicScalar("subSystem").as(); - configuration = iter->atomicScalar("configuration").as(); - fprintf(stdout, "[%d] name=%s, class=%s, system=%s, subsystem=%s, configuration=%s\n", - i++, name, className, system, subSystem, configuration); + name = iter->atomicScalar("name").as(); + className = iter->atomicScalar("class").as(); + system = iter->atomicScalar("system").as(); + subSystem = iter->atomicScalar("subSystem").as(); + configuration = iter->atomicScalar("configuration").as(); + fprintf(stdout, "[%d] name=%s, class=%s, system=%s, subsystem=%s, configuration=%s\n", i++, name, className, + system, subSystem, configuration); } // Cast to known type and print - SIGNALSET *signalSet = static_cast(signals[0].data()); + SIGNALSET* signalSet = static_cast(signals[0].data()); std::cout << std::endl; for (int i = 0; i < signalSetCount; i++) { - printf("[%d] name=%s, classname=%s, system=%s\n", - i, signalSet[i].name, signalSet[i].classname, signalSet[i].system); + printf("[%d] name=%s, classname=%s, system=%s\n", i, signalSet[i].name, signalSet[i].classname, + signalSet[i].system); } // Use the High level method - std::vector names = node.atomicVector("name").as(); - std::vector classNames = node.atomicVector("class").as(); - std::vector systems = node.atomicVector("system").as(); - std::vector subSystems = node.atomicVector("subSystem").as(); - std::vector configurations = node.atomicVector("configuration").as(); + std::vector names = node.atomicVector("name").as(); + std::vector classNames = node.atomicVector("class").as(); + std::vector systems = node.atomicVector("system").as(); + std::vector subSystems = node.atomicVector("subSystem").as(); + std::vector configurations = node.atomicVector("configuration").as(); std::cout << std::endl; for (int i = 0; i < signalSetCount; i++) { printf("[%d] name=%s, classname=%s, system=%s\n", i, names[i], classNames[i], systems[i]); } - if(test != 0) return 0; - + if (test != 0) { + return 0; + } } -//============================================================================================================= -// Code configuration signal set names + //============================================================================================================= + // Code configuration signal set names - if(test == 6 || test == 0) { + if (test == 6 || test == 0) { - const uda::Result& data = client.get("meta::getdata(context=meta,device=MAST,cast=column,class=code,system=specview,configuration=default,/latest)", "MAST::22812"); + const uda::Result& data = client.get("meta::getdata(context=meta,device=MAST,cast=column,class=code,system=" + "specview,configuration=default,/latest)", + "MAST::22812"); uda::TreeNode root = data.tree(); @@ -449,7 +460,7 @@ int main() }; // Cast to Array of structures - SIGNALSET * signalSet = static_cast(signals[0].data()); + SIGNALSET* signalSet = static_cast(signals[0].data()); struct COORDINATE { float r; @@ -467,10 +478,10 @@ int main() COORDINATE coordinate; }; - COIL * coilSet; - COORDINATE * coord; + COIL* coilSet; + COORDINATE* coord; - VLEN * specviewCoilSet = (VLEN *)calloc(signalSetCount, sizeof(VLEN)); + VLEN* specviewCoilSet = (VLEN*)calloc(signalSetCount, sizeof(VLEN)); printf("\nCOIL size = %zu\n", sizeof(COIL)); printf("COORDINATE size = %zu\n\n", sizeof(COORDINATE)); @@ -511,14 +522,14 @@ int main() int count = coils.size(); printf("\nCOIL structure array count = %d\n\n", count); - COIL * coilSet = (COIL *)malloc(count * sizeof(COIL)); + COIL* coilSet = (COIL*)malloc(count * sizeof(COIL)); - specviewCoilSet[i].data = (void *)coilSet; - specviewCoilSet[i].len = count; + specviewCoilSet[i].data = (void*)coilSet; + specviewCoilSet[i].len = count; for (int j = 0; j < count; j++) { - char * signal = coils[j].atomicScalar("signal").as(); - char * orientation = coils[j].atomicScalar("orientation").as(); + char* signal = coils[j].atomicScalar("signal").as(); + char* orientation = coils[j].atomicScalar("orientation").as(); short polarity = coils[j].atomicScalar("polarity").as(); float calibration = coils[j].atomicScalar("calibration").as(); int number = coils[j].atomicScalar("number").as(); @@ -526,48 +537,48 @@ int main() strcpy(coilSet[j].signal, signal); strcpy(coilSet[j].orientation, orientation); - coilSet[j].polarity = polarity; + coilSet[j].polarity = polarity; coilSet[j].calibration = calibration; - coilSet[j].number = number; - coilSet[j].dataStatus = dataStatus; + coilSet[j].number = number; + coilSet[j].dataStatus = dataStatus; - COORDINATE * coord = static_cast(coils[j].child(0).data()); - coilSet[j].coordinate = * coord; + COORDINATE* coord = static_cast(coils[j].child(0).data()); + coilSet[j].coordinate = *coord; printf("\n[%d] \n", j); printf("A R=%f, Z=%f, Phi=%f\n", coord->r, coord->z, coord->phi); - printf("B R=%f, Z=%f, Phi=%f\n", - coilSet[j].coordinate.r, coilSet[j].coordinate.z, coilSet[j].coordinate.phi); + printf("B R=%f, Z=%f, Phi=%f\n", coilSet[j].coordinate.r, coilSet[j].coordinate.z, + coilSet[j].coordinate.phi); } // Using a cast to a known type .... - coilSet = static_cast(coils[0].data()); + coilSet = static_cast(coils[0].data()); for (int j = 0; j < count; j++) { - coord = static_cast(coils[j].child(0).data()); + coord = static_cast(coils[j].child(0).data()); printf("\n[%d] \n", j); printf("A R=%f, Z=%f, Phi=%f\n", coord->r, coord->z, coord->phi); - coilSet[j].coordinate = * coord; - printf("B R=%f, Z=%f, Phi=%f\n", - coilSet[j].coordinate.r, coilSet[j].coordinate.z, coilSet[j].coordinate.phi); + coilSet[j].coordinate = *coord; + printf("B R=%f, Z=%f, Phi=%f\n", coilSet[j].coordinate.r, coilSet[j].coordinate.z, + coilSet[j].coordinate.phi); } } for (int i = 0; i < signalSetCount; i++) { for (int j = 0; j < specviewCoilSet[i].len; j++) { - coilSet = static_cast(specviewCoilSet[i].data); - printf("[%2d] [%2d] signal = %s, (R,Z,Phi) = (%f,%f,%f)\n", - i, j, coilSet[j].signal, + coilSet = static_cast(specviewCoilSet[i].data); + printf("[%2d] [%2d] signal = %s, (R,Z,Phi) = (%f,%f,%f)\n", i, j, coilSet[j].signal, coilSet[j].coordinate.r, coilSet[j].coordinate.z, coilSet[j].coordinate.phi); } } - if(test != 0) return 0; + if (test != 0) { + return 0; + } } - //============================================================================================================= // Integer array tests @@ -616,27 +627,27 @@ int main() std::vector atypes = node.atomicTypes(); std::vector apoint = node.atomicPointers(); // is this component a Pointer std::vector arank = node.atomicRank(); - std::vector > ashape = node.atomicShape(); + std::vector> ashape = node.atomicShape(); for (int i = 0; i < acount; i++) { - fprintf(stdout,"%s [%s] %d %zu\n", - anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i]); + fprintf(stdout, "%s [%s] %d %zu\n", anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i]); } // Call a high level method for the data uda::Vector vec = node.atomicVector("value"); - std::vector idata = vec.as(); + std::vector idata = vec.as(); for (std::size_t i = 0; i < idata.size(); i++) { printf("value[%zu] = %d\n", i, idata[i]); } - if (test != 0) return 0; + if (test != 0) { + return 0; + } } - if (test == 8 || test == 0) { struct TEST12 { @@ -681,30 +692,32 @@ int main() std::vector atypes = node.atomicTypes(); std::vector apoint = node.atomicPointers(); // is this component a Pointer std::vector arank = node.atomicRank(); - std::vector > ashape = root.atomicShape(); + std::vector> ashape = root.atomicShape(); for (int i = 0; i < acount; i++) { - fprintf(stdout, "%s [%s] %d %zu %zu\n", - anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i], ashape[i][0]); + fprintf(stdout, "%s [%s] %d %zu %zu\n", anames[i].c_str(), atypes[i].c_str(), bool(apoint[i]), arank[i], + ashape[i][0]); } // Call a high level method for the data uda::Vector vec = node.atomicVector("value"); - std::vector idata = vec.as(); + std::vector idata = vec.as(); for (std::size_t i = 0; i < vec.size(); i++) { printf("value[%zu] = %d\n", i, idata[i]); } - if (test != 0) return 0; + if (test != 0) { + return 0; + } } //======================================================================================================== // Test 9: IMAS IDS data access from a private file - if(test == 9 || test == 0) { + if (test == 9 || test == 0) { // Read the whole IDS file const uda::Result& data = client.get("/", "NETCDF::/home/dgm/IDAM/test/source/plugins/imas/ids_123_1.hd5"); @@ -749,26 +762,29 @@ int main() node.printUserDefinedTypeTable(); // *** Searching by Type may fail as types are auto-generated to be unique. - // *** Searching without hierarchical structure will return the first data node satisfying the passed name - which may not be what is needed! + // *** Searching without hierarchical structure will return the first data node satisfying the passed name - + // which may not be what is needed! // *** Searching by structure component name should be a more robust method // node containing data with a specific component name node = root.findStructureComponent("magnetics.flux_loop.13.flux"); node.printUserDefinedTypeTable(); - if(test != 0) return 0; + if (test != 0) { + return 0; + } } //======================================================================================================== - if(test == 10 || test == 0) { + if (test == 10 || test == 0) { struct FLUX { - float *data; - float *time; + float* data; + float* time; }; - const uda::Result& data = client.get("/magnetics/flux_loop/13/flux", - "NETCDF::/home/dgm/IDAM/test/source/plugins/imas/ids_123_1.hd5"); + const uda::Result& data = + client.get("/magnetics/flux_loop/13/flux", "NETCDF::/home/dgm/IDAM/test/source/plugins/imas/ids_123_1.hd5"); // Check for errors if (data.errorCode() != uda::OK) { @@ -805,35 +821,37 @@ int main() std::vector atypes = node.atomicTypes(); std::vector apoint = node.atomicPointers(); // is this component a Pointer std::vector arank = node.atomicRank(); - std::vector > ashape = root.atomicShape(); + std::vector> ashape = root.atomicShape(); - for (int i=0; i time = node.atomicVector("data.time").as(); - for (size_t i=0; i atypes = node.atomicTypes(); std::vector apoint = node.atomicPointers(); // is this component a Pointer std::vector arank = node.atomicRank(); - std::vector > ashape = root.atomicShape(); + std::vector> ashape = root.atomicShape(); - for (int i=0; i vals = node.atomicVector("rValues").as(); - for (std::size_t i=0; i pfCoils = root.structData("data").as(); + std::vector pfCoils = root.structData("data").as(); // or just extract what's needed @@ -917,7 +937,9 @@ int main() printf("turnCount[%d][%d] = %f %f\n", 0, 0, turnCount[0], pfCoils[0]->turnCount[0]); - if(test != 0) return 0; + if (test != 0) { + return 0; + } } return 0; diff --git a/source/wrappers/c++/result.cpp b/source/wrappers/c++/result.cpp old mode 100755 new mode 100644 index 80d10075..79adba61 --- a/source/wrappers/c++/result.cpp +++ b/source/wrappers/c++/result.cpp @@ -4,15 +4,15 @@ #include "result.hpp" -#include #include +#include #include "accAPI.h" #include "client.h" #include "udaTypes.h" -#include "string.hpp" #include "array.hpp" +#include "string.hpp" static const std::type_info* idamTypeToTypeID(int type) { @@ -64,14 +64,12 @@ int uda::Result::errorCode() const } uda::Result::Result(int handle) - : handle_(handle) - , label_(handle >= 0 ? getIdamDataLabel(handle) : "") - , units_(handle >= 0 ? getIdamDataUnits(handle) : "") - , desc_(handle >= 0 ? getIdamDataDesc(handle) : "") - , type_(handle >= 0 ? idamTypeToTypeID(getIdamDataType(handle)) : &typeid(void)) - , uda_type_(handle >= 0 ? getIdamDataType(handle) : UDA_TYPE_UNKNOWN) - , rank_(handle >= 0 ? static_cast(getIdamRank(handle)) : 0) - , size_(handle >= 0 ? static_cast(getIdamDataNum(handle)) : 0) + : handle_(handle), label_(handle >= 0 ? getIdamDataLabel(handle) : ""), + units_(handle >= 0 ? getIdamDataUnits(handle) : ""), desc_(handle >= 0 ? getIdamDataDesc(handle) : ""), + type_(handle >= 0 ? idamTypeToTypeID(getIdamDataType(handle)) : &typeid(void)), + uda_type_(handle >= 0 ? getIdamDataType(handle) : UDA_TYPE_UNKNOWN), + 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); @@ -107,8 +105,7 @@ const std::vector uda::Result::shape() const return shape; } -template -static uda::Dim getDim(int handle, uda::dim_type num, uda::Result::DataType data_type) +template static uda::Dim getDim(int handle, uda::dim_type num, uda::Result::DataType data_type) { if (data_type == uda::Result::DataType::DATA) { std::string label = getIdamDimLabel(handle, num); @@ -180,8 +177,7 @@ uda::Dim uda::Result::dim(uda::dim_type num, DataType data_type) const return Dim::Null; } -template -uda::Data* getDataAs(int handle, uda::Result::DataType data_type, const uda::Result* result) +template uda::Data* getDataAs(int handle, uda::Result::DataType data_type, const uda::Result* result) { T* data = nullptr; if (data_type == uda::Result::DataType::DATA) { @@ -223,9 +219,8 @@ uda::Data* getDataAsStringArray(int handle) auto dim_size = static_cast(getIdamDimNum(handle, dim_n)); auto label = getIdamDimLabel(handle, dim_n); auto units = getIdamDimUnits(handle, dim_n); - dims.emplace_back(uda::Dim(dim_n, dim_data, dim_size, - label != nullptr ? label : "", - units != nullptr ? units : "")); + dims.emplace_back( + uda::Dim(dim_n, dim_data, dim_size, label != nullptr ? label : "", units != nullptr ? units : "")); } for (size_t i = 0; i < arr_len; ++i) { @@ -278,7 +273,6 @@ uda::Data* uda::Result::data() const } } - bool uda::Result::hasErrors() const { return getIdamErrorType(handle_) != UDA_TYPE_UNKNOWN; @@ -342,5 +336,5 @@ const char* uda::Result::raw_data() const uda::TreeNode uda::Result::tree() const { - return { handle_, getIdamDataTree(handle_) }; + return {handle_, getIdamDataTree(handle_)}; } diff --git a/source/wrappers/c++/scalar.cpp b/source/wrappers/c++/scalar.cpp old mode 100755 new mode 100644 index d5036056..117f7092 --- a/source/wrappers/c++/scalar.cpp +++ b/source/wrappers/c++/scalar.cpp @@ -5,4 +5,3 @@ #include "scalar.hpp" uda::Scalar uda::Scalar::Null = uda::Scalar(); - diff --git a/source/wrappers/c++/signal.cpp b/source/wrappers/c++/signal.cpp old mode 100755 new mode 100644 index 385df739..3d61eeb6 --- a/source/wrappers/c++/signal.cpp +++ b/source/wrappers/c++/signal.cpp @@ -1,14 +1,15 @@ #include "signal.hpp" -#include -#include #include +#include +#include void uda::Signal::put() const { // Open file - const char* fmt = "putdata::open(filename='%1%.nc', conventions='FUSION', class='%2%', shot='%3%', pass='%4%', comment='%5%', /create)"; - std::string query = (boost::format(fmt) % alias_ % signal_class_ % shot_ % pass_ % comment_).str(); + const char* fmt = "putdata::open(filename='%1%.nc', conventions='FUSION', class='%2%', shot='%3%', pass='%4%', " + "comment='%5%', /create)"; + std::string query = (boost::format(fmt) % alias_ % signal_class_ % shot_ % pass_ % comment_).str(); idamPutAPI(query.c_str(), NULL); idamPutAPI("", NULL); diff --git a/source/wrappers/c++/test.cpp b/source/wrappers/c++/test.cpp old mode 100755 new mode 100644 index 0d8b121a..0277e52c --- a/source/wrappers/c++/test.cpp +++ b/source/wrappers/c++/test.cpp @@ -1,6 +1,7 @@ #include "UDA.hpp" -int main() { +int main() +{ uda::Client::setServerHostName("idam0"); uda::Client::setServerPort(56561); @@ -15,10 +16,9 @@ int main() { std::cout << dim.type().name() << std::endl; std::cout << dim_data[0] << std::endl; - uda::Array * data = dynamic_cast(result.data()); + uda::Array* data = dynamic_cast(result.data()); std::cout << data->isNull() << std::endl; return 0; } - diff --git a/source/wrappers/c++/treenode.cpp b/source/wrappers/c++/treenode.cpp old mode 100755 new mode 100644 index 49d7a023..2ec12833 --- a/source/wrappers/c++/treenode.cpp +++ b/source/wrappers/c++/treenode.cpp @@ -1,8 +1,8 @@ #include "treenode.hpp" -#include "struct.h" -#include "accessors.h" #include "accAPI.h" +#include "accessors.h" +#include "struct.h" uda::TreeNode uda::TreeNode::parent() { @@ -21,7 +21,7 @@ const std::vector uda::TreeNode::children() const std::vector vec; for (int i = 0; i < numChildren; ++i) { auto child = getNodeChild(node_, i); - vec.push_back(TreeNode{ handle_, child }); + vec.push_back(TreeNode{handle_, child}); } return vec; @@ -63,13 +63,13 @@ void uda::TreeNode::printStructureNames() uda::TreeNode uda::TreeNode::findStructureDefinition(const std::string& name) { - return {handle_, findNTreeStructureDefinition(node_, (char*)name.c_str()) }; + return {handle_, findNTreeStructureDefinition(node_, (char*)name.c_str())}; } uda::TreeNode uda::TreeNode::findStructureComponent(const std::string& name) { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); - return {handle_, findNTreeStructureComponent(logmalloclist, node_, (char*)name.c_str()) }; + return {handle_, findNTreeStructureComponent(logmalloclist, node_, (char*)name.c_str())}; } void uda::TreeNode::printUserDefinedTypeTable(const std::string& name) @@ -153,19 +153,19 @@ std::vector uda::TreeNode::atomicRank() const return vec; } -std::vector > uda::TreeNode::atomicShape() const +std::vector> uda::TreeNode::atomicShape() const { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); int** shapes = getNodeAtomicShape(logmalloclist, node_); int* ranks = getNodeAtomicRank(logmalloclist, node_); int size = getNodeAtomicCount(node_); - std::vector > vec; + std::vector> vec; for (int i = 0; i < size; ++i) { if (shapes[i] == nullptr) { std::vector vec2; vec2.push_back(0); vec.push_back(vec2); - } else if (ranks[i] == 0){ + } else if (ranks[i] == 0) { std::vector vec2(shapes[i], shapes[i] + 1); vec.push_back(vec2); } else { @@ -182,22 +182,19 @@ void* uda::TreeNode::structureComponentData(const std::string& name) const return getNodeStructureComponentData(logmalloclist, node_, (char*)name.c_str()); } -template -static uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) +template static uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) { T* val = reinterpret_cast(getNodeStructureComponentData(logmalloclist, node, (char*)name)); return uda::Scalar(*val); } -template <> -uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) +template <> uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) { char* val = reinterpret_cast(getNodeStructureComponentData(logmalloclist, node, (char*)name)); return uda::Scalar(val); } -template <> -uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) +template <> uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const char* name) { char** val = reinterpret_cast(getNodeStructureComponentData(logmalloclist, node, (char*)name)); return uda::Scalar(val[0]); @@ -206,12 +203,17 @@ uda::Scalar getScalar(LOGMALLOCLIST* logmalloclist, NTREE* node, const c uda::Scalar uda::TreeNode::atomicScalar(const std::string& target) { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); - NTREE* node = findNTreeStructureComponent(logmalloclist, node_, (char*)target.c_str()); // Locate the named variable target - //NTREE * node = findNTreeStructureComponent(node_, target.c_str()); // Locate the named variable target - if (node == nullptr) return Scalar::Null; + NTREE* node = + findNTreeStructureComponent(logmalloclist, node_, (char*)target.c_str()); // Locate the named variable target + // NTREE * node = findNTreeStructureComponent(node_, target.c_str()); // Locate the named variable target + if (node == nullptr) { + return Scalar::Null; + } int acount = getNodeAtomicCount(node); // Number of atomic typed structure members - if (acount == 0) return Scalar::Null; // No atomic data + if (acount == 0) { + return Scalar::Null; // No atomic data + } char** anames = getNodeAtomicNames(logmalloclist, node); char** atypes = getNodeAtomicTypes(logmalloclist, node); @@ -223,60 +225,72 @@ uda::Scalar uda::TreeNode::atomicScalar(const std::string& target) } for (int i = 0; i < acount; i++) { - if (target == anames[i] - && std::string("STRING") == atypes[i] - && (arank[i] == 0 || arank[i] == 1)) { + if (target == anames[i] && std::string("STRING") == atypes[i] && (arank[i] == 0 || arank[i] == 1)) { return getScalar(logmalloclist, node, anames[i]); } else if (target == anames[i] && std::string("STRING *") == atypes[i] && arank[i] == 0) { return getScalar(logmalloclist, node, anames[i]); - } else if (target == anames[i] - && (arank[i] == 0 - || (arank[i] == 1 && ashape[i][0] == 1))) { - if (std::string("short") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("double") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("float") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("int") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("char") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("unsigned int") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("unsigned short") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); - if (std::string("unsigned char") == atypes[i]) return getScalar(logmalloclist, node, anames[i]); + } else if (target == anames[i] && (arank[i] == 0 || (arank[i] == 1 && ashape[i][0] == 1))) { + if (std::string("short") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("double") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("float") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("int") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("char") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("unsigned int") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("unsigned short") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } + if (std::string("unsigned char") == atypes[i]) { + return getScalar(logmalloclist, node, anames[i]); + } } } return Scalar::Null; } -//template -//static uda::Vector getVectorOverSiblings(NTREE* node, const std::string& target) +// template +// static uda::Vector getVectorOverSiblings(NTREE* node, const std::string& target) //{ -// int count = getNodeChildrenCount(node->parent); -// T* data = static_cast(malloc(count * sizeof(T))); -// if (data == nullptr) { -// return uda::Vector::Null; -// } -// for (int j = 0; j < count; j++) { -// data[j] = *reinterpret_cast(getNodeStructureComponentData(node->parent->children[j], -// (char*)target.c_str())); -// } -// return uda::Vector(data, (size_t)count); -//} +// int count = getNodeChildrenCount(node->parent); +// T* data = static_cast(malloc(count * sizeof(T))); +// if (data == nullptr) { +// return uda::Vector::Null; +// } +// for (int j = 0; j < count; j++) { +// data[j] = *reinterpret_cast(getNodeStructureComponentData(node->parent->children[j], +// (char*)target.c_str())); +// } +// return uda::Vector(data, (size_t)count); +// } // -//template <> -//uda::Vector getVectorOverSiblings(NTREE* node, const std::string& target) +// template <> +// uda::Vector getVectorOverSiblings(NTREE* node, const std::string& target) //{ -// // Scalar String in an array of data structures -// int count = getNodeChildrenCount(node->parent); -// char** data = static_cast(malloc(count * sizeof(char*))); // Managed by IDAM -// if (data == nullptr) { -// return uda::Vector::Null; -// } -// addMalloc(data, count, sizeof(char*), (char*)"char *"); -// for (int j = 0; j < count; j++) { -// data[j] = reinterpret_cast(getNodeStructureComponentData(node->parent->children[j], -// (char*)target.c_str())); -// } -// return uda::Vector(data, (size_t)count); -//} +// // Scalar String in an array of data structures +// int count = getNodeChildrenCount(node->parent); +// char** data = static_cast(malloc(count * sizeof(char*))); // Managed by IDAM +// if (data == nullptr) { +// return uda::Vector::Null; +// } +// addMalloc(data, count, sizeof(char*), (char*)"char *"); +// for (int j = 0; j < count; j++) { +// data[j] = reinterpret_cast(getNodeStructureComponentData(node->parent->children[j], +// (char*)target.c_str())); +// } +// return uda::Vector(data, (size_t)count); +// } template static uda::Vector getVector(LOGMALLOCLIST* logmalloclist, NTREE* node, const std::string& target, int count) @@ -321,11 +335,15 @@ uda::Vector uda::TreeNode::atomicVector(const std::string& target) { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); NTREE* node = findNTreeStructureComponent(logmalloclist, node_, (char*)target.c_str()); - //NTREE * node = findNTreeStructureComponent(node_, (char *)target.c_str()); // Locate the named variable target - if (node == nullptr) return Vector::Null; + // NTREE * node = findNTreeStructureComponent(node_, (char *)target.c_str()); // Locate the named variable target + if (node == nullptr) { + return Vector::Null; + } int acount = getNodeAtomicCount(node); // Number of atomic typed structure members - if (acount == 0) return Vector::Null; // No atomic data + if (acount == 0) { + return Vector::Null; // No atomic data + } char** anames = getNodeAtomicNames(logmalloclist, node); char** atypes = getNodeAtomicTypes(logmalloclist, node); @@ -339,32 +357,69 @@ uda::Vector uda::TreeNode::atomicVector(const std::string& target) for (int i = 0; i < acount; i++) { if (target == anames[i]) { - if (std::string("STRING *") == atypes[i] && ((arank[i] == 0 && apoint[i] == 1) || (arank[i] == 1 && apoint[i] == 0))) { + if (std::string("STRING *") == atypes[i] && + ((arank[i] == 0 && apoint[i] == 1) || (arank[i] == 1 && apoint[i] == 0))) { // String array in a single data structure - char** val = reinterpret_cast(getNodeStructureComponentData(logmalloclist, node, (char*)target.c_str())); + char** val = + reinterpret_cast(getNodeStructureComponentData(logmalloclist, node, (char*)target.c_str())); return uda::Vector(val, (size_t)ashape[i][0]); } else if (arank[i] == 0 && apoint[i] == 1) { int count = getNodeStructureComponentDataCount(logmalloclist, node, (char*)target.c_str()); - if (std::string("STRING *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("char *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("short *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("double *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("float *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("int *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("unsigned int *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("unsigned short *") == atypes[i]) return getVector(logmalloclist, node, target, count); - if (std::string("unsigned char *") == atypes[i]) return getVector(logmalloclist, node, target, count); + if (std::string("STRING *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("char *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("short *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("double *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("float *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("int *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("unsigned int *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("unsigned short *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } + if (std::string("unsigned char *") == atypes[i]) { + return getVector(logmalloclist, node, target, count); + } } else if (arank[i] == 1) { -// if (std::string("STRING") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); -// if (std::string("STRING") == atypes[i]) return getStringVector(logmalloclist, node, target); - if (std::string("char") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("short") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("double") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("float") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("int") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("unsigned int") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("unsigned short") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); - if (std::string("unsigned char") == atypes[i]) return getVector(logmalloclist, node, target, ashape[i][0]); + // if (std::string("STRING") == atypes[i]) return getVector(logmalloclist, node, + // target, ashape[i][0]); if (std::string("STRING") == atypes[i]) return + // getStringVector(logmalloclist, node, target); + if (std::string("char") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("short") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("double") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("float") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("int") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("unsigned int") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("unsigned short") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } + if (std::string("unsigned char") == atypes[i]) { + return getVector(logmalloclist, node, target, ashape[i][0]); + } } else if (arank[i] == 2 && std::string("STRING") == atypes[i]) { return getStringVector(logmalloclist, node, target, ashape[i]); } @@ -395,11 +450,15 @@ uda::Array uda::TreeNode::atomicArray(const std::string& target) { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); NTREE* node = findNTreeStructureComponent(logmalloclist, node_, (char*)target.c_str()); - //NTREE * node = findNTreeStructureComponent(node_, (char *)target.c_str()); // Locate the named variable target - if (node == nullptr) return Array::Null; + // NTREE * node = findNTreeStructureComponent(node_, (char *)target.c_str()); // Locate the named variable target + if (node == nullptr) { + return Array::Null; + } int acount = getNodeAtomicCount(node); // Number of atomic typed structure members - if (acount == 0) return Array::Null; // No atomic data + if (acount == 0) { + return Array::Null; // No atomic data + } char** anames = getNodeAtomicNames(logmalloclist, node); char** atypes = getNodeAtomicTypes(logmalloclist, node); @@ -413,14 +472,30 @@ uda::Array uda::TreeNode::atomicArray(const std::string& target) for (int i = 0; i < acount; i++) { if (target == anames[i]) { - if (std::string("STRING") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("short") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("double") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("float") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("int") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("unsigned int") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("unsigned short") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); - if (std::string("unsigned char") == atypes[i]) return getArray(logmalloclist, node, target, ashape[i], arank[i]); + if (std::string("STRING") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("short") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("double") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("float") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("int") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("unsigned int") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("unsigned short") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } + if (std::string("unsigned char") == atypes[i]) { + return getArray(logmalloclist, node, target, ashape[i], arank[i]); + } } } @@ -431,7 +506,9 @@ uda::StructData uda::TreeNode::structData(const std::string& target) { LOGMALLOCLIST* logmalloclist = getIdamLogMallocList(handle_); NTREE* node = findNTreeStructureComponent(logmalloclist, node_, (char*)target.c_str()); - if (node == nullptr) return StructData::Null; + if (node == nullptr) { + return StructData::Null; + } int count = getNodeChildrenCount(node->parent); @@ -451,5 +528,3 @@ void* uda::TreeNode::data() { return getNodeData(node_); } - - diff --git a/source/wrappers/c++/utilities.h b/source/wrappers/c++/utilities.h old mode 100755 new mode 100644 index daccec09..013aa60f --- a/source/wrappers/c++/utilities.h +++ b/source/wrappers/c++/utilities.h @@ -1,18 +1,18 @@ #ifndef UtilsClass #define UtilsClass +#include "export.h" +#include "singleValue.h" +#include +#include +#include +#include #include -#include #include -#include -#include -#include -#include -#include -#include -#include "singleValue.h" +#include #include -#include "export.h" +#include +#include //! Utility routines namespace UtilitiesNs @@ -24,12 +24,15 @@ namespace UtilitiesNs array is suppled in a parameter "index". \param timeWindow Size of time-window (secs). \param timePoint Central time about which to perform time-average. - \param index Approximate index of timePoint in the times array. If this is not known, suggest put a value close to values.size()/2. - \param times Array of times. - \param values Array of times-series values. + \param index Approximate index of timePoint in the times array. If this is not known, suggest put a value + close to values.size()/2. \param times Array of times. \param values Array of times-series values. \return Time-window average. */ -LIBRARY_API SingleValueNs::SingleValue timeAverage(const SingleValueNs::SingleValue timeWindow, const SingleValueNs::SingleValue timePoint, const SingleValueNs::SingleValue index, const blitz::Array& times, const blitz::Array& values); +LIBRARY_API SingleValueNs::SingleValue timeAverage(const SingleValueNs::SingleValue timeWindow, + const SingleValueNs::SingleValue timePoint, + const SingleValueNs::SingleValue index, + const blitz::Array& times, + const blitz::Array& values); //! Assigns the value of an XML attribute to a SingleValueNs::SingleValue object. /*! @@ -38,7 +41,8 @@ LIBRARY_API SingleValueNs::SingleValue timeAverage(const SingleValueNs:: \param AttributeValue The variable into which to place the contents of the XML attribute. \return If successful returns true, otherwise false */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, SingleValueNs::SingleValue& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + SingleValueNs::SingleValue& attributeValue); //! Assigns the value of an XML attribute to a SingleValueNs::SingleValue object. /*! @@ -47,7 +51,8 @@ LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::str \param AttributeValue The variable into which to place the contents of the XML attribute. \return If successful returns true, otherwise false */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, SingleValueNs::SingleValue& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + SingleValueNs::SingleValue& attributeValue); //! Assigns the value of an XML attribute to a blitz::Array object. /*! @@ -60,7 +65,8 @@ LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::str \param AttributeValue The variable into which to place the contents of the XML attribute. \return If successful returns true, otherwise false */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, blitz::Array& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + blitz::Array& attributeValue); //! Assigns the value of an XML attribute to a blitz::Array object. /*! @@ -73,7 +79,8 @@ LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::str \param AttributeValue The variable into which to place the contents of the XML attribute. \return If successful returns true, otherwise false */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, blitz::Array& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + blitz::Array& attributeValue); //! Assigns the value of an XML attribute to a blitz::Array object. /*! @@ -86,16 +93,18 @@ LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::str \param AttributeValue The variable into which to place the contents of the XML attribute. \return If successful returns true, otherwise false */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, blitz::Array& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + blitz::Array& attributeValue); //! Assigns the value of an XML attribute to a std::string object. /*! \param DomElement The Dom element containing the given attribute. \param AttributeName The singular name of the attribute. - \param AttributeValue The variable into which to place the contents of the XML attribute (if it hadn't been specified, then returns "notSet"). - \return If the variable has been set returns true, otherwise false. + \param AttributeValue The variable into which to place the contents of the XML attribute (if it hadn't been + specified, then returns "notSet"). \return If the variable has been set returns true, otherwise false. */ -LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, std::string& attributeValue); +LIBRARY_API bool getAttributeValue(const QDomElement& domElement, const std::string& attributeName, + std::string& attributeValue); /*! \file utilities.h @@ -119,7 +128,7 @@ LIBRARY_API std::string getEfitVersion(); infinity. Nw we divid the number by itself, and the result is a "quiet" NaN. \return value NaN. */ -LIBRARY_API double getNaN() ; +LIBRARY_API double getNaN(); //! Function opens an XML file, parses it and returns a reference to the DOM document. LIBRARY_API bool openAndParseXmlFile(const std::string& xmlFileName, QDomDocument& domDocument); @@ -132,7 +141,7 @@ LIBRARY_API bool openAndParseXmlFile(const std::string& xmlFileName, QDomDocumen \param value The scalar value to be converted to a std::string. \return Std::String value. */ -template std::string valueToString( T value ) +template std::string valueToString(T value) { std::ostringstream oss; @@ -147,47 +156,56 @@ template std::string valueToString( T value ) // are a set of three overloaded functions. // -//! Overloaded template function converts a scalar of type Typ (permissible types are std::string or QString) to an integer scalar. +//! Overloaded template function converts a scalar of type Typ (permissible types are std::string or QString) to an +//! integer scalar. /*! - \param stringValue The scalar value to be converted. If entered as type \e std::string it is converted to type \e QString - \param datavalue If conversion is successful then on exit contains the result. - \return If not successful contains the value "integer", otherwise it is empty. + \param stringValue The scalar value to be converted. If entered as type \e std::string it is converted to type \e + QString \param datavalue If conversion is successful then on exit contains the result. \return If not + successful contains the value "integer", otherwise it is empty. */ -template std::string convertStringToValue(const Typ& stringValue, int& intValue) { +template std::string convertStringToValue(const Typ& stringValue, int& intValue) +{ bool ok; - std::string expectedType=""; - QString qStringValue=stringValue; - intValue= qStringValue.toInt(&ok) ; - if (ok == false) expectedType="integer"; + std::string expectedType = ""; + QString qStringValue = stringValue; + intValue = qStringValue.toInt(&ok); + if (ok == false) { + expectedType = "integer"; + } return expectedType; } -//! Overloaded template function converts a scalar of type Typ (permissible types are std::string QString) to a double float scalar. +//! Overloaded template function converts a scalar of type Typ (permissible types are std::string QString) to a double +//! float scalar. /*! - \param stringValue The scalar value to be converted. If entered as type \e std::string it is converted to type \e QString - \param datavalue If conversion is successful then on exit contains the result. - \return If not successful contains the value "double", otherwise it is empty. + \param stringValue The scalar value to be converted. If entered as type \e std::string it is converted to type \e + QString \param datavalue If conversion is successful then on exit contains the result. \return If not + successful contains the value "double", otherwise it is empty. */ -template std::string convertStringToValue(const Typ& stringValue, double& doubleValue) { +template std::string convertStringToValue(const Typ& stringValue, double& doubleValue) +{ bool ok; - std::string expectedType=""; - QString qStringValue=stringValue; - doubleValue= qStringValue.toDouble(&ok); - if (ok == false) expectedType="double"; + std::string expectedType = ""; + QString qStringValue = stringValue; + doubleValue = qStringValue.toDouble(&ok); + if (ok == false) { + expectedType = "double"; + } return expectedType; } -//! Overloaded template function "converts" a scalar of type (permissible types are std::string or QString) to a QString scalar (included for completeness). +//! Overloaded template function "converts" a scalar of type (permissible types are std::string or QString) to a QString +//! scalar (included for completeness). /*! - \param stringValue The scalar value to be "converted". If entered as type \e std::string it is converted to type \e QString - \param std::stringOutvalue On exit contains the result. - \return On exit is empty (i.e. contains the value ""). + \param stringValue The scalar value to be "converted". If entered as type \e std::string it is converted to type + \e QString \param std::stringOutvalue On exit contains the result. \return On exit is empty (i.e. contains + the value ""). */ template std::string convertStringToValue(const Typ& stringValue, QString& stringOutValue) { - std::string expectedType=""; - QString qStringValue=stringValue; - stringOutValue= qStringValue; + std::string expectedType = ""; + QString qStringValue = stringValue; + stringOutValue = qStringValue; return expectedType; } @@ -209,32 +227,33 @@ template std::string convertStringToValue(const Typ& stringValue, QS allocated prior to entry or within the routine; in any case the array will be enlarged if it is too small. */ -template void convertStringToVector( const QString& dataIn, blitz::Array& dataOut) +template void convertStringToVector(const QString& dataIn, blitz::Array& dataOut) { Typ dataValue; - int index=-1; - int pos=0 ; + int index = -1; + int pos = 0; // This reg expression captures anything between one or more commas and/or spaces - QRegExp parseVar("\\s*\\[?\\s*,?\\s*" // "\\s*"=0 or more spaces; "\\[?"= 0 or 1 [ ; ",?" =0 or 1 comma. - "(" // start capture group - "[^\\[\\],\\s]" // the capture group matches anything other than "[],"and whitespace - "+" // can have one or more characters in the capture group. - ")" // end of capture cgroup - ",?\\]?"); // if possible match: ",?"=0 or 1 comma; "]?"=0 or 1 ]. + QRegExp parseVar("\\s*\\[?\\s*,?\\s*" // "\\s*"=0 or more spaces; "\\[?"= 0 or 1 [ ; ",?" =0 or 1 comma. + "(" // start capture group + "[^\\[\\],\\s]" // the capture group matches anything other than "[],"and whitespace + "+" // can have one or more characters in the capture group. + ")" // end of capture cgroup + ",?\\]?"); // if possible match: ",?"=0 or 1 comma; "]?"=0 or 1 ]. dataOut.resize(0); - while(pos >=0 ) { - pos=parseVar.search( dataIn, pos ); // search for next item of a comma or space-separated list + while (pos >= 0) { + pos = parseVar.search(dataIn, pos); // search for next item of a comma or space-separated list if (pos > -1) { // found a values, so convert it to a real number and store it. - QString dataString=parseVar.cap(1); - std::string expectedType = convertStringToValue(dataString, dataValue) ; + QString dataString = parseVar.cap(1); + std::string expectedType = convertStringToValue(dataString, dataValue); // if array needs to be increased in size, then do so, preserving existing contents. - if(++index >dataOut.size()-1) dataOut.resizeAndPreserve(index+1); + if (++index > dataOut.size() - 1) { + dataOut.resizeAndPreserve(index + 1); + } // and store value dataOut(index) = dataValue; - pos += parseVar.matchedLength(); - + pos += parseVar.matchedLength(); } } } @@ -261,84 +280,77 @@ template void convertStringToVector( const QString& dataIn, blitz::A allocated prior to entry or within the routine; in any case the array will be enlarged if it is too small. */ -template void convertStringToArray( const QString& dataIn, blitz::Array& dataOut) +template void convertStringToArray(const QString& dataIn, blitz::Array& dataOut) { - int row=-1; - int pos=0 ; - blitz::Array dataRow; - blitz::Array dataShape; - - // define a regular expression to identify the data "preamble". This may be " [" or " 1 4[". The numbers are optional and define - // the size of the array - QRegExp preamble("\\s*" // "\\s*"=0 or more spaces. - "(" // start capture group - "[^\\[\\]]*" // the capture group matches anything other than "[],"and whitespace - ")" // end of capture group - "\\["); // match to a [. + int row = -1; + int pos = 0; + blitz::Array dataRow; + blitz::Array dataShape; + + // define a regular expression to identify the data "preamble". This may be " [" or " 1 4[". The numbers are + // optional and define the size of the array + QRegExp preamble("\\s*" // "\\s*"=0 or more spaces. + "(" // start capture group + "[^\\[\\]]*" // the capture group matches anything other than "[],"and whitespace + ")" // end of capture group + "\\["); // match to a [. // define a regular expression to identify a single row, eg [[ 1.,2.3.4,6]] - QRegExp singleRow("\\s*\\[\\s*\\[?" // "\\s*"=0 or more spaces; "\\["= [. - "(" // start capture group - "[^\\[\\]]" // the capture group matches anything other than "[]" - "+" // can have one or more characters in the capture group. - ")" // end of capture group - "\\]\\s*"); // if possible match: ",?"=0 or 1 comma; "]?"=0 or 1 ]. - - + QRegExp singleRow("\\s*\\[\\s*\\[?" // "\\s*"=0 or more spaces; "\\["= [. + "(" // start capture group + "[^\\[\\]]" // the capture group matches anything other than "[]" + "+" // can have one or more characters in the capture group. + ")" // end of capture group + "\\]\\s*"); // if possible match: ",?"=0 or 1 comma; "]?"=0 or 1 ]. // // in the first part of the routine we process the data preamble // - bool outputArraySizeIsSet =false; - pos=preamble.search( dataIn, pos ); // search for integer list followied by a [; If present, set the intial array dimensions to these values. + bool outputArraySizeIsSet = false; + pos = preamble.search( + dataIn, + pos); // search for integer list followied by a [; If present, set the intial array dimensions to these values. if (pos > -1) { // extract the captured std::string, and convert it to numbers. QString dataString = preamble.cap(1); - convertStringToVector(dataString,dataShape); - if(dataShape.size() > 0) { - dataOut.resize(dataShape(0),dataShape(1)); - outputArraySizeIsSet =true; + convertStringToVector(dataString, dataShape); + if (dataShape.size() > 0) { + dataOut.resize(dataShape(0), dataShape(1)); + outputArraySizeIsSet = true; } - pos += preamble.matchedLength(); + pos += preamble.matchedLength(); } // // Now process the data itself. // - while(pos >=0 ) { - pos=singleRow.search( dataIn, pos ); // search for the next row + while (pos >= 0) { + pos = singleRow.search(dataIn, pos); // search for the next row if (pos > -1) { // found data for a new row so increment row counter. row++; // extract the captured std::string, and convert it to numbers. - QString dataString=singleRow.cap(1); - convertStringToVector(dataString,dataRow); + QString dataString = singleRow.cap(1); + convertStringToVector(dataString, dataRow); // resize the array if required, preserving existing contents. - if(outputArraySizeIsSet) { - int columnCount = max(dataRow.size(),dataOut.ubound(blitz::secondDim)+1); - int rowCount = max(row+1,dataOut.ubound(blitz::firstDim)+1); - dataOut.resizeAndPreserve(rowCount,columnCount); - } - else { + if (outputArraySizeIsSet) { + int columnCount = max(dataRow.size(), dataOut.ubound(blitz::secondDim) + 1); + int rowCount = max(row + 1, dataOut.ubound(blitz::firstDim) + 1); + dataOut.resizeAndPreserve(rowCount, columnCount); + } else { int columnCount = dataRow.size(); - int rowCount = row+1; - dataOut.resize(rowCount,columnCount); - outputArraySizeIsSet =true; + int rowCount = row + 1; + dataOut.resize(rowCount, columnCount); + outputArraySizeIsSet = true; } // assign values in this row to dataOut. - dataOut(row,blitz::Range(0,dataRow.ubound(blitz::firstDim))) = dataRow; + dataOut(row, blitz::Range(0, dataRow.ubound(blitz::firstDim))) = dataRow; // move position marker along the orginal string in preparation for the next parse - pos += singleRow.matchedLength(); + pos += singleRow.matchedLength(); } } } - - - - - - // // convertStringToArray converts a QString variable to a 1-D array of values // @@ -358,114 +370,125 @@ template void convertStringToArray( const QString& dataIn, blitz::Ar allocated prior to entry or within the routine; in any case the array will be enlarged if it is too small. */ -template void convertStringToArray( const QString& dataIn, blitz::Array& dataOut) +template void convertStringToArray(const QString& dataIn, blitz::Array& dataOut) { - int pos=0 ; - blitz::Array dataRow; - blitz::Array dataShape; - - // define a regular expression to identify the data "preamble". This may be " [" or " 1 4[". The numbers are optional and define - // the size of the array - QRegExp preamble("\\s*" // "\\s*"=0 or more spaces. - "(" // start capture group - "[^\\[\\]]" // the capture group matches anything other than "[],"and whitespace - ")" // end of capture group - "\\["); // match to a [. + int pos = 0; + blitz::Array dataRow; + blitz::Array dataShape; + + // define a regular expression to identify the data "preamble". This may be " [" or " 1 4[". The numbers are + // optional and define the size of the array + QRegExp preamble("\\s*" // "\\s*"=0 or more spaces. + "(" // start capture group + "[^\\[\\]]" // the capture group matches anything other than "[],"and whitespace + ")" // end of capture group + "\\["); // match to a [. // define a regular expression to identify a single row, eg [[ 1.,2.3.4,6]] - QRegExp singleRow("\\s*\\[?" // "\\s*"=0 or more spaces; "\\["= [. - "(" // start capture group - "[^\\[\\]]" // the capture group matches anything other than "[]" - "+" // can have one or more characters in the capture group. - ")"); // end of capture group + QRegExp singleRow("\\s*\\[?" // "\\s*"=0 or more spaces; "\\["= [. + "(" // start capture group + "[^\\[\\]]" // the capture group matches anything other than "[]" + "+" // can have one or more characters in the capture group. + ")"); // end of capture group // // in the first part of the routine we process the data preamble // - pos=preamble.search( dataIn, pos ); // search for integer list followied by a [; If present, set the intial array dimensions to these values. + pos = preamble.search( + dataIn, + pos); // search for integer list followied by a [; If present, set the intial array dimensions to these values. if (pos > -1) { // extract the captured std::string, and convert it to numbers. QString dataString = preamble.cap(1); - convertStringToVector(dataString,dataShape); - if(dataShape.size() > 0) dataOut.resize(dataShape(0)); - pos += preamble.matchedLength(); - } - else { + convertStringToVector(dataString, dataShape); + if (dataShape.size() > 0) { + dataOut.resize(dataShape(0)); + } + pos += preamble.matchedLength(); + } else { // didn't find any preamble, so reset position index. - pos=0; + pos = 0; dataOut.resize(0); } // // Now process the data itself. // - pos=singleRow.search( dataIn, pos ); // search for the next row + pos = singleRow.search(dataIn, pos); // search for the next row if (pos > -1) { // found data so extract the captured std::string, and convert it to numbers. - QString dataString=singleRow.cap(1); - convertStringToVector(dataString,dataOut); + QString dataString = singleRow.cap(1); + convertStringToVector(dataString, dataOut); } } - - // -// XmlVerifyAndAllocate performs some basic checks on the XML and the storage array, and allocates space if everything is fine +// XmlVerifyAndAllocate performs some basic checks on the XML and the storage array, and allocates space if everything +// is fine // /*! - Performs some basic checks when reading a collection of identical structures (for example magnetic probes or flux loops) - into a 1-D storage array from an XML file. + Performs some basic checks when reading a collection of identical structures (for example magnetic probes or flux + loops) into a 1-D storage array from an XML file. -# If the detectorArray has already been allocated, it checks that the \e id's of detectors in the detectorArrayList are within the range of the detectorArray. -# If the detectorArray has not yet been defined, it checks that the \e id's of detectors in the detectorArrayList form a continuous set 1,2,3.... If everyting is fine and the detectorArray has not yet been allocated it is allocated in this routine. - \param detectorArrayList A reference to an array of XML nodes. The data in each node must contain at least an attribute called \e id. - \param detectorName A reference to the detector name, used if there is an error. - \param detectorArray A reference to a 1-D array to hold the data. The operation of the routine depends on whether on entry to - the routine detectorArray is already allocated (see above). - \return Return bool=\e true if there were no errors otherwise false. + \param detectorArrayList A reference to an array of XML nodes. The data in each node must contain at least an + attribute called \e id. \param detectorName A reference to the detector name, used if there is an error. \param + detectorArray A reference to a 1-D array to hold the data. The operation of the routine depends on whether on + entry to the routine detectorArray is already allocated (see above). \return Return bool=\e true if there were no + errors otherwise false. */ -template bool XmlVerifyAndAllocate(const QDomNodeList& detectorArrayList, const std::string& detectorName, blitz::Array& detectorArray) +template +bool XmlVerifyAndAllocate(const QDomNodeList& detectorArrayList, const std::string& detectorName, + blitz::Array& detectorArray) { // obtain the set of id's bool success; - blitz::Array detectorArrayId(detectorArrayList.count()); + blitz::Array detectorArrayId(detectorArrayList.count()); for (uint i = 0; i < detectorArrayList.count(); i++) { QDomElement detectorArrayElement = detectorArrayList.item(i).toElement(); detectorArrayId(i) = atoi(detectorArrayElement.attribute("id")); } - int maxIdValue = blitz::max(detectorArrayId); - int minIdValue = blitz::min(detectorArrayId); + int maxIdValue = blitz::max(detectorArrayId); + int minIdValue = blitz::min(detectorArrayId); - if (detectorArray.size() !=0) { + if (detectorArray.size() != 0) { // the detectorArray array has already been defined, so check that the id values are in range. - if(maxIdValue - minIdValue +1 > detectorArray.size() | minIdValue <= 0) { + if (maxIdValue - minIdValue + 1 > detectorArray.size() | minIdValue <= 0) { std::cout << "Error: An 'id' value of a " << detectorName << " node is out of range." << std::endl; std::cout << " Valid 'id' values must be positive and contiguous." << std::endl; - std::cout << " === The full list of id's for the " << detectorName << " nodes is: ===" << std::endl; + std::cout << " === The full list of id's for the " << detectorName + << " nodes is: ===" << std::endl; std::cout << detectorArrayId << std::endl; return success = false; + } else { + success = true; } - else - success=true; - } - else { + } else { // the detectorArray array has not yet been defined, so check that the id values form a continuous set. // if they do then allocate an array to hold the data. int arraySize = detectorArrayId.size(); - if (minIdValue != 1) success=false; - else { - gsl_sort_int (detectorArrayId.data(),1, arraySize); - blitz::Array detectorSequence(detectorArrayId(blitz::Range(1,arraySize-1)) - detectorArrayId(blitz::Range(0,arraySize-2))); - if(any(abs(detectorSequence) != 1)) success=false; - else success=true; + if (minIdValue != 1) { + success = false; + } else { + gsl_sort_int(detectorArrayId.data(), 1, arraySize); + blitz::Array detectorSequence(detectorArrayId(blitz::Range(1, arraySize - 1)) - + detectorArrayId(blitz::Range(0, arraySize - 2))); + if (any(abs(detectorSequence) != 1)) { + success = false; + } else { + success = true; + } } if (!success) { // the set of id's of the detectorArray do not form a continuous set. - std::cout << "Error: The set of 'id's of the " << detectorName << " nodes do not form continous set between 1 and =" << maxIdValue << std::endl; - std::cout << " === The full list of id's for the " << detectorName << " nodes is: ===" << std::endl; + std::cout << "Error: The set of 'id's of the " << detectorName + << " nodes do not form continous set between 1 and =" << maxIdValue << std::endl; + std::cout << " === The full list of id's for the " << detectorName + << " nodes is: ===" << std::endl; std::cout << detectorArrayId << std::endl; return success = false; } @@ -474,7 +497,6 @@ template bool XmlVerifyAndAllocate(const QDomNodeList& detectorArray return success; } - //////////////////////////////////////////////////////////////// //! template function converts from a 1-D index to multiDimensional indices (Column-major ordering). @@ -486,17 +508,19 @@ template bool XmlVerifyAndAllocate(const QDomNodeList& detectorArray \param arrayExtents Shape of array for which multidimensional scripts are required. \return Array of indices. */ -template blitz::TinyVector convertToMultiDIndicesColumn(const int index, const blitz::TinyVector& arrayExtents) +template +blitz::TinyVector convertToMultiDIndicesColumn(const int index, + const blitz::TinyVector& arrayExtents) // converts from a 1-D index to multi-dimensional indices { - blitz::TinyVector multiDimensionIndices; - multiDimensionIndices(0)=index % arrayExtents(0); - for (int k=1; k < rank; k++) { - int baseProduct=1; - for(int j=0; j < k; j++) { - baseProduct=baseProduct*arrayExtents(j); + blitz::TinyVector multiDimensionIndices; + multiDimensionIndices(0) = index % arrayExtents(0); + for (int k = 1; k < rank; k++) { + int baseProduct = 1; + for (int j = 0; j < k; j++) { + baseProduct = baseProduct * arrayExtents(j); } - multiDimensionIndices(k)=index/baseProduct % arrayExtents(k); + multiDimensionIndices(k) = index / baseProduct % arrayExtents(k); } return multiDimensionIndices; } @@ -510,23 +534,23 @@ template blitz::TinyVector convertToMultiDIndicesColumn(con \param arrayExtents Shape of array for which multidimensional scripts are required. \return Array of indices. */ -template blitz::TinyVector convertToMultiDIndicesRow(const int index, const blitz::TinyVector& arrayExtents) +template +blitz::TinyVector convertToMultiDIndicesRow(const int index, + const blitz::TinyVector& arrayExtents) // converts from a 1-D index to multi-dimensional indices { - blitz::TinyVector multiDimensionIndices; - multiDimensionIndices(rank-1)=index % arrayExtents(rank-1); - for (int k=rank-2; k >= 0; k--) { - int baseProduct=1; - for(int j=rank-1; j > k; j--) { - baseProduct=baseProduct*arrayExtents(j); + blitz::TinyVector multiDimensionIndices; + multiDimensionIndices(rank - 1) = index % arrayExtents(rank - 1); + for (int k = rank - 2; k >= 0; k--) { + int baseProduct = 1; + for (int j = rank - 1; j > k; j--) { + baseProduct = baseProduct * arrayExtents(j); } - multiDimensionIndices(k)=index/baseProduct % arrayExtents(k); + multiDimensionIndices(k) = index / baseProduct % arrayExtents(k); } return multiDimensionIndices; } - - //! overloaded template function outputs a single variable /*! The routine can be called successively for dumping the data contained in an object. @@ -535,15 +559,15 @@ template blitz::TinyVector convertToMultiDIndicesRow(const \param parameterName Text std::string contains the name of the parameter. \param value The variable containing the data. */ -template void dumpStructure(const bool isSet, const std::string parameterName, const SingleValueNs::SingleValue value) +template +void dumpStructure(const bool isSet, const std::string parameterName, const SingleValueNs::SingleValue value) { std::cout.width(25); std::cout << std::left << parameterName + " : "; - if(isSet) { - std::cout << std::left << value.getVal() < void dumpStructure(const bool isSet, const std::string para \param parameterName Text std::string contains the name of the parameter. \param value The variable containing the data. */ -template void dumpStructure(const bool isSet, const std::string parameterName, const blitz::Array value) +template +void dumpStructure(const bool isSet, const std::string parameterName, const blitz::Array value) { std::cout.width(25); std::cout << std::left << parameterName + " : "; - if(isSet) { - std::cout << value < void dumpStructure(const bool isSet, const std::s \param parameterName Text std::string contains the name of the parameter. \param value The variable containing the data. */ -template void dumpStructure(const std::string parameterName, const blitz::Array,1> value) +template +void dumpStructure(const std::string parameterName, const blitz::Array, 1> value) { std::cout.width(25); std::cout << std::left << parameterName + " : "; - for (int i=0; i < value.size(); i++ ) { - if(value(i).isSet()) { - std::cout << i << " " << value(i).getVal() < void dumpStructure(const std::string parameterName, const b template void dumpStructure(const bool isSet, const std::string parameterName, const Typ value) { std::cout.width(25); - std::cout << std::left << parameterName + " : "; - if(isSet) { - std::cout << std::left << value <