From 7dabb65d28e0174a6814d706095692f57ab9a635 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 16 May 2015 02:38:45 -0400 Subject: [PATCH 001/134] Add Fatal Error Handler, rewrite Error Handler as. This commit adds a Fatal Error Notification Subsystem implementation and rewrites the pre-existing error handler code to be C code with C++ bindings. Do note that the transition to C code means that an API change cannot be avoided. Although attempts have been made to make the transition as easy as possible. Also the error table API version numbers have been updated. In addition to adding an API call to check what those version numbers are. --- CMakeLists.txt | 2 + src/Common/Src/Error_Handler/CMakeLists.txt | 59 ++- .../Src/Error_Handler/Common_Error_Handler.c | 370 ++++++++++++++++++ .../Error_Handler/Common_Error_Handler.cpp | 136 ------- .../Src/Error_Handler/Common_Error_Handler.h | 226 ++++++++++- .../Common_Error_Handler_CPP_Bindings.cpp | 118 ++++++ .../Common_Error_Handler_Internal.h | 12 +- .../Common_Error_Handler_Structures.c | 148 +++++++ .../Common_Error_Handler_Structures.h | 247 +++++++----- ..._Error_Handler_Structures_CPP_Bindings.cpp | 41 ++ src/Common/Src/Error_Handler/Error_Struct.h | 25 +- ...le.cpp => Posix_Error_Translation_Table.c} | 37 +- .../Posix_Error_Translation_Table.h | 162 ++++++-- ...x_Error_Translation_Table_CPP_Bindings.cpp | 45 +++ 14 files changed, 1302 insertions(+), 326 deletions(-) create mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler.c delete mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler.cpp create mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp create mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c create mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler_Structures_CPP_Bindings.cpp rename src/Common/Src/Error_Handler/{Posix_Error_Translation_Table.cpp => Posix_Error_Translation_Table.c} (60%) create mode 100644 src/Common/Src/Error_Handler/Posix_Error_Translation_Table_CPP_Bindings.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e083325..7b86078 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,8 @@ endif() # Option Defaults. option (BUILD_DYNAMIC_LIBRARY_SUBSYSTEM "Whether or not to build the Dynamic Library Subsystem. (Defaults to yes.)" ON) +option (BUILD_COMMON_ERROR_HANDLER "Whether or not to build the Common Error Handler. (Defaults to yes.)" ON) +option (BUILD_FATAL_ERROR_NOTIFY_SUPPORT "Whether or not to build the Common Error Handler's fatal error notification support. (Defaults to yes.)" ON) option (BUILD_INTERNAL_MUTEX_SUPPORT "Whether or not to build the internal mutex support library. (Defaults to yes.)" ON) option (BUILD_INTERNAL_MUTEX_THREAD_SUBSYS_WRAPPER "Whether or not the Threading Subsystem library will have Internal Mutex Support built in. (Defaults to yes, but is disabled currently due to changes to Thread_Utils that have not been commited yet.)" OFF) option (BUILD_INTERNAL_MUTEX_THREAD_SUBSYS_WRAPPER_PLUGIN "Whether or not to build the Threading Subsystem plugin for Internal Mutex Support. (Defaults to yes, but is disabled currently due to changes to Thread_Utils that have not been commited yet.)" OFF) diff --git a/src/Common/Src/Error_Handler/CMakeLists.txt b/src/Common/Src/Error_Handler/CMakeLists.txt index 44119e0..ed2b7e5 100644 --- a/src/Common/Src/Error_Handler/CMakeLists.txt +++ b/src/Common/Src/Error_Handler/CMakeLists.txt @@ -2,8 +2,59 @@ set(LIBRARY_OUTPUT_PATH ${L_OUTPUT_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) -# Create the error handler. -set (COMMON_ERROR_HANDLER_INCLUDES Common_Error_Handler.cpp -Posix_Error_Translation_Table.cpp) +# Build the error handler if needed. +if (BUILD_COMMON_ERROR_HANDLER) + # Check for internal mutex support as the error handler uses it. + if (BUILD_FATAL_ERROR_NOTIFY_SUPPORT) + if (BUILD_INTERNAL_MUTEX_SUPPORT) + # Enable the needed flags. + set (COMMON_ERROR_HANDLER_DEFINES MSYS_BUILD_FATAL_ERROR_SUPPORT) -add_library(Common_Error_Handler_Multiverse_Engine SHARED ${COMMON_ERROR_HANDLER_INCLUDES}) + # Define the link libraries. + set(COMMON_ERROR_HANDLER_LINK_LIBS Common_Mutexes_Multiverse_Engine) + else(BUILD_INTERNAL_MUTEX_SUPPORT) + # No internal mutex support, so skip building the error handler's fatal error notification support. + message(SEND_ERROR "ERROR: Internal mutex support is disabled, and is REQUIRED to build the Common Error Handler's fatal error notification support. Skipping.") + endif(BUILD_INTERNAL_MUTEX_SUPPORT) + endif (BUILD_FATAL_ERROR_NOTIFY_SUPPORT) + + # Create the error handler. (Nasty hack to avoid a warning from GCC about invalid -std:gnu99 flag below....) + set (COMMON_ERROR_HANDLER_C_INCLUDES Common_Error_Handler.c + Posix_Error_Translation_Table.c + ) + set (COMMON_ERROR_HANDLER_CXX_INCLUDES Common_Error_Handler_Structures_CPP_Bindings.cpp + Common_Error_Handler_CPP_Bindings.cpp + Posix_Error_Translation_Table_CPP_Bindings.cpp + ) + + # Because we broke up the object code build from the shared library linking, we need to break up the flags and arguments too. + set (COMMON_ERROR_HANDLER_COMPILER_FLAGS -fPIC) + set (COMMON_ERROR_HANDLER_C_FLAGS ${COMMON_ERROR_HANDLER_COMPILER_FLAGS}) + set (COMMON_ERROR_HANDLER_CXX_FLAGS ${COMMON_ERROR_HANDLER_COMPILER_FLAGS}) + set (COMMON_ERROR_HANDLER_LINK_FLAGS -fPIC) + + # Check for gcc and enable gnu99 extensions if needed. + if (${CMAKE_COMPILER_IS_GNUCC}) + message (STATUS "GCC compiler detected, enabling gnu99 extensions for Common Error Handler.") + set (COMMON_ERROR_HANDLER_C_FLAGS ${COMMON_ERROR_HANDLER_C_FLAGS} -std=gnu99) + endif(${CMAKE_COMPILER_IS_GNUCC}) + + # First add the static C object library... + add_library(Common_Error_Handler_Multiverse_Engine_C OBJECT ${COMMON_ERROR_HANDLER_C_INCLUDES}) + set_property(TARGET Common_Error_Handler_Multiverse_Engine_C APPEND PROPERTY COMPILE_DEFINITIONS ${COMMON_ERROR_HANDLER_DEFINES}) + target_compile_options (Common_Error_Handler_Multiverse_Engine_C BEFORE PRIVATE ${COMMON_ERROR_HANDLER_C_FLAGS}) # Allows us to put the args to the compiler in the correct order. + + # Now add the C++ Bindings object library. + add_library(Common_Error_Handler_Multiverse_Engine_CXX OBJECT ${COMMON_ERROR_HANDLER_CXX_INCLUDES}) + set_property(TARGET Common_Error_Handler_Multiverse_Engine_CXX APPEND PROPERTY COMPILE_DEFINITIONS ${COMMON_ERROR_HANDLER_DEFINES}) + target_compile_options (Common_Error_Handler_Multiverse_Engine_CXX BEFORE PRIVATE ${COMMON_ERROR_HANDLER_CXX_FLAGS}) # Allows us to put the args to the compiler in the correct order. + + # Now the final shared library. (What we really want.) + add_library(Common_Error_Handler_Multiverse_Engine SHARED $ + $ + ) + target_link_libraries(Common_Error_Handler_Multiverse_Engine ${COMMON_ERROR_HANDLER_LINK_LIBS}) + set_property(TARGET Common_Error_Handler_Multiverse_Engine APPEND PROPERTY COMPILE_DEFINITIONS ${COMMON_ERROR_HANDLER_DEFINES}) + set_property(TARGET Common_Error_Handler_Multiverse_Engine APPEND PROPERTY LINK_FLAGS ${COMMON_ERROR_HANDLER_LINK_FLAGS}) + +endif(BUILD_COMMON_ERROR_HANDLER) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.c b/src/Common/Src/Error_Handler/Common_Error_Handler.c new file mode 100644 index 0000000..eb462fe --- /dev/null +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.c @@ -0,0 +1,370 @@ +/*! + Multiverse Engine Project 23/6/2014 Common Common_Error_Handler.c + + Copyright (C) 2014 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// Internal includes. +#include "Common_Error_Handler.h" // Main header. +#include "Common_Error_Handler_Internal.h" // Private internal header that defines the structure used for error logging. + +// Only include the mutex header if needed by the fatal error handler. +#ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT +#ifdef __win32__ +#include "..\Mutexes\MSYS_Mutexes.h" // Internal mutex support. +#else +#include "../Mutexes/MSYS_Mutexes.h" // Internal mutex support. +#endif // __win32__ +#endif // MSYS_BUILD_FATAL_ERROR_SUPPORT + +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*! + * static int Common_commonLastErrorCode + * + * Contains the last error code encountered by a Common namespace function. + * + * Note: Calling Common_GetErrorMessage() or Common_GetErrorTableSize() + * will NOT clear this variable. + * Calling any other Common namespace function WILL clear this variable. + */ +static int Common_commonLastErrorCode = COMMON_ERROR_SUCCESS; + +void Common_Set_Error_Log_Level(const unsigned int logLevel) +{ + // Set the log level. + commonErrorLoggingData.errorLogLevel = logLevel; + + // Exit function. + return; +} + +unsigned int Common_Get_Error_Log_Level() +{ + // Return the current log level. + return commonErrorLoggingData.errorLogLevel; +} + +void Common_Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)) +{ + // Check and see if the pointer is NULL. + if (loggingFunction == NULL) + { + // Set the log level to ERROR_DISABLE. + commonErrorLoggingData.errorLogLevel = ERROR_DISABLE; + commonErrorLoggingData.loggingFunct = NULL; + } + else + { + // Set the pointer. + commonErrorLoggingData.loggingFunct = loggingFunction; + } + + // Exit function. + return; +} + +// Build the Fatal Error Handler if needed. +#ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT +/*! + * static unsigned int registeredFatalErrorCallbackFunctionsSize + * + * This unsigned int is used to remember the allocated size of the registeredFatalErrorCallbackFunctions array. + */ +static unsigned int registeredFatalErrorCallbackFunctionsSize = 0; + +/* + * static Common_pErrorCallBackFunction * registeredFatalErrorCallbackFunctions + * + * This pointer to an array contains the callback functions (registered with Common::Register_Fatal_Error_Callback()) + * used to notify the engine's subsystems and the application that a fatal error has occured and the engine's + * process is about to be terminated by the host system. + */ +static Common_pErrorCallBackFunction * registeredFatalErrorCallbackFunctions = NULL; + +/*! + * static MSYS_Mutex * fatalErrorHandlerMutex + * + * This pointer is to an MSYS_Mutex object that is used to control access to the registered fatal error handler + * function pointer list and it's size value. + */ +static MSYS_Mutex * fatalErrorHandlerMutex = NULL; + +bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) +{ + // Init vars. + bool ret = false; // The result of this function. + size_t previousErrorListSize = registeredFatalErrorCallbackFunctionsSize; // The size of the previous error list. + size_t newErrorListSize = 0; // The size of the new error list we are creating. + Common_pErrorCallBackFunction * previousErrorList = registeredFatalErrorCallbackFunctions; // The previous error list. + Common_pErrorCallBackFunction * newErrorList = NULL; // The new error list we are creating. + MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). + + // Check for a valid mutex. + if (fatalErrorHandlerMutex == NULL) + { + // Allocate the mutex. + fatalErrorHandlerMutex = MSYS_Create_Mutex(); + } + + // Lock the error handler mutex. + retFromLockMutex = MSYS_Lock_Mutex(fatalErrorHandlerMutex); + if ((retFromLockMutex != NULL) && (retFromLockMutex == fatalErrorHandlerMutex)) + { + // Check for valid function pointer. + if (fatalErrorNotifyFunction != NULL) + { + // Check for a error function list. + if ((previousErrorList != NULL) && (previousErrorListSize > 0)) + { + // Re-allocate the error list. + newErrorList = (Common_pErrorCallBackFunction *)malloc((sizeof(Common_pErrorCallBackFunction) * (previousErrorListSize + 1))); + if (newErrorList != NULL) + { + // Update the size info. + newErrorListSize = (previousErrorListSize + 1); + + // Copy the data. + for (size_t x = 0; x < previousErrorListSize; x++) + { + newErrorList[x] = previousErrorList[x]; + } + } + } + else + { + // Allocate the error list. + newErrorList = (Common_pErrorCallBackFunction *)malloc(sizeof(Common_pErrorCallBackFunction)); + if (newErrorList != NULL) + { + // Update the size info. + newErrorListSize = 1; + } + } + + // Check for a valid list. + if ((previousErrorListSize + 1) == newErrorListSize) + { + // Register the function. + newErrorList[(previousErrorListSize)] = fatalErrorNotifyFunction; + + // Copy the new list pointer, and size info. + registeredFatalErrorCallbackFunctions = newErrorList; + registeredFatalErrorCallbackFunctionsSize = newErrorListSize; + + // Check and see if we need to deallocate the previousErrorList. + if ((previousErrorList != NULL) && (previousErrorList != newErrorList) && (previousErrorListSize > 0)) + { + // Null out the old pointer list. + for (size_t x = 0; x < previousErrorListSize; x++) + { + previousErrorList[x] = NULL; + } + + // Deallocate the old array. + free(previousErrorList); + previousErrorList = NULL; + previousErrorListSize = 0; + } + + // We are done. + ret = true; + } + } + + // Release the error handler mutex. + MSYS_Unlock_Mutex(fatalErrorHandlerMutex); + } + + // Return the result. + return ret; +} + +bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) +{ + // Init vars. + bool ret = false; // The result of this function. + size_t previousErrorListSize = registeredFatalErrorCallbackFunctionsSize; // The size of the previous error list. + size_t newErrorListSize = 0; // The size of the new error list we are creating. + Common_pErrorCallBackFunction * previousErrorList = registeredFatalErrorCallbackFunctions; // The previous error list. + Common_pErrorCallBackFunction * newErrorList = NULL; // The new error list we are creating. + MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). + + // Lock the error handler mutex. + retFromLockMutex = MSYS_Lock_Mutex(fatalErrorHandlerMutex); + if ((retFromLockMutex != NULL) && (retFromLockMutex == fatalErrorHandlerMutex)) + { + // Check for valid function pointer. + if (fatalErrorNotifyFunction != NULL) + { + // Check for a error function list. + if ((previousErrorList != NULL) && (previousErrorListSize > 0)) + { + // Check the existing list for that function. + for (size_t x = 0; ((newErrorList == NULL) && (x < previousErrorListSize)); x++) + { + // Check for the correct function, to see if the function was registered previously. + if (previousErrorList[x] == fatalErrorNotifyFunction) + { + // Found the function, so re-allocate the error list so we can remove it. + newErrorList = (Common_pErrorCallBackFunction *)malloc((sizeof(Common_pErrorCallBackFunction) * (previousErrorListSize - 1))); + if (newErrorList != NULL) + { + // Update the size info. + newErrorListSize = (previousErrorListSize - 1); + } + } + } + + // Only continue if the list was reallocated due to us finding the function to remove. + if ((newErrorList != NULL) && (newErrorListSize == (previousErrorListSize - 1))) + { + // Copy the data. + for (size_t x = 0, y = 0; ((x < previousErrorListSize) && (y < newErrorListSize)); x++) + { + // Make sure we don't copy the pointer we are removing. + if (previousErrorList[x] != fatalErrorNotifyFunction) + { + // Copy the pointer, and increment y. (Yes, y can be different than x, because it will not contain every pointer.) + newErrorList[y] = previousErrorList[x]; + y++; + } + } + + // Now that the data is copied, copy the pointers. + registeredFatalErrorCallbackFunctions = newErrorList; + registeredFatalErrorCallbackFunctionsSize = newErrorListSize; + + // Deallocate the old list. + if ((previousErrorList != NULL) && (previousErrorList != newErrorList) && (previousErrorListSize > 0)) + { + // Null out the old pointer list. + for (size_t x = 0; x < previousErrorListSize; x++) + { + previousErrorList[x] = NULL; + } + + free(previousErrorList); + previousErrorList = NULL; + previousErrorListSize = 0; + } + + // Done. + ret = true; + } + } + } + + // Release the error handler mutex. + MSYS_Unlock_Mutex(fatalErrorHandlerMutex); + } + + // Return the result. + return ret; +} + +void Common_Fatal_Error_Notify() +{ + // Init vars. + MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). + + // Lock the error handler mutex. + retFromLockMutex = MSYS_Lock_Mutex(fatalErrorHandlerMutex); + if ((retFromLockMutex != NULL) && (retFromLockMutex == fatalErrorHandlerMutex)) + { + // Check for registered fatal error callbacks. + if (registeredFatalErrorCallbackFunctionsSize > 0) + { + // Begin vector iteration loop. + for (size_t x = 0; (x < registeredFatalErrorCallbackFunctionsSize); x++) + { + // Trigger each function. + if (registeredFatalErrorCallbackFunctions[x] != NULL) + { + registeredFatalErrorCallbackFunctions[x](); + } + } + } + + // Release the error handler mutex. + MSYS_Unlock_Mutex(fatalErrorHandlerMutex); + } + + // Exit function. + return; +} + +#endif // MSYS_BUILD_FATAL_ERROR_SUPPORT + +void COMMON_LOG_ERROR(const unsigned int loggingLevel, const char * errorMsg) +{ + /* + * Only do something if the log is enabled, + * the error is at or below our current log level, + * and the logging callback function is defined. + * + * Note: The lower the log level, the higher severity of the error. + */ + if ((commonErrorLoggingData.errorLogLevel != ERROR_DISABLE) && + (commonErrorLoggingData.loggingFunct != NULL) && + (loggingLevel <= commonErrorLoggingData.errorLogLevel)) + { + // Call the callback. (Hope it returns....) + commonErrorLoggingData.loggingFunct(loggingLevel, errorMsg); + } + + // Exit function. + return; +} + +void COMMON_LOG_CRITICAL(const char * errorMsg) +{ + COMMON_LOG_ERROR(ERROR_CRITICAL, errorMsg); + return; +} + +void COMMON_LOG_WARNING(const char * errorMsg) +{ + COMMON_LOG_ERROR(ERROR_WARNING, errorMsg); + return; +} + +void COMMON_LOG_INFO(const char * errorMsg) +{ + COMMON_LOG_ERROR(ERROR_INFO, errorMsg); + return; +} + +void COMMON_LOG_DEBUG(const char * errorMsg) +{ + COMMON_LOG_ERROR(ERROR_DEBUG, errorMsg); + return; +} + +void COMMON_LOG_VERBOSE(const char * errorMsg) +{ + COMMON_LOG_ERROR(ERROR_VERBOSE, errorMsg); + return; +} + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.cpp b/src/Common/Src/Error_Handler/Common_Error_Handler.cpp deleted file mode 100644 index 1ea3719..0000000 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/*! - Multiverse Engine Project 23/6/2014 Common Common_Error_Handler.cpp - - Copyright (C) 2014 Multiverse Engine Project - - This program is free software; - you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; - either version 2 of the License, or (at your option) any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along with this program; - if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - Official source repository and project information can be found at - https://github.com/codebase7/mengine -*/ - -#include "Common_Error_Handler.h" // Main header. -#include "Common_Error_Handler_Internal.h" // Private internal header that defines the structure used for error logging. - -const unsigned int Common::Get_Error_Table_Size() -{ - return (sizeof(Common::commonErrorTable) / sizeof(Common_Error_Object)); -} - -const char * Common::Get_Error_Message(const int & errorCode) -{ - // Init vars. - const char * result = NULL; // Result of this function. - const size_t errorTableSize = Common::Get_Error_Table_Size(); // Size of the Common error lookup table. - - // Begin lookup loop. - for (size_t x = 0; ((x < errorTableSize) && (result == NULL)); x++) - { - // Check for the correct error code. - if (Common::commonErrorTable[x].errorCode == errorCode) - { - // Found the correct error code. - result = Common::commonErrorTable[x].error; - } - } - - // If we still can't find the error message to return, use COMMON_UNKNOWN_ERROR - if (result == NULL) - { - result = Common::UNKNOWN_ERROR_MSG; - } - - // Return the result. - return result; -} - -void Common::Set_Error_Log_Level(const unsigned int & logLevel) -{ - // Set the log level. - commonErrorLoggingData.errorLogLevel = logLevel; - - // Exit function. - return; -} - -unsigned int Common::Get_Error_Log_Level() -{ - // Return the current log level. - return commonErrorLoggingData.errorLogLevel; -} - -void Common::Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)) -{ - // Check and see if the pointer is NULL. - if (loggingFunction == NULL) - { - // Set the log level to ERROR_DISABLE. - commonErrorLoggingData.errorLogLevel = ERROR_DISABLE; - } - - // Set the pointer. - commonErrorLoggingData.loggingFunct = loggingFunction; - - // Exit function. - return; -} - -void COMMON_LOG_ERROR(const unsigned int loggingLevel, const char * errorMsg) -{ - /* - * Only do something if the log is enabled, - * the error is at or below our current log level, - * and the logging callback function is defined. - * - * Note: The lower the log level, the higher severity of the error. - */ - if ((commonErrorLoggingData.errorLogLevel != ERROR_DISABLE) && - (commonErrorLoggingData.loggingFunct != NULL) && - (loggingLevel <= commonErrorLoggingData.errorLogLevel)) - { - // Call the callback. (Hope it returns....) - commonErrorLoggingData.loggingFunct(loggingLevel, errorMsg); - } - - // Exit function. - return; -} - -void COMMON_LOG_CRITICAL(const char * errorMsg) -{ - COMMON_LOG_ERROR(ERROR_CRITICAL, errorMsg); - return; -} - -void COMMON_LOG_WARNING(const char * errorMsg) -{ - COMMON_LOG_ERROR(ERROR_WARNING, errorMsg); - return; -} - -void COMMON_LOG_INFO(const char * errorMsg) -{ - COMMON_LOG_ERROR(ERROR_INFO, errorMsg); - return; -} - -void COMMON_LOG_DEBUG(const char * errorMsg) -{ - COMMON_LOG_ERROR(ERROR_DEBUG, errorMsg); - return; -} - -void COMMON_LOG_VERBOSE(const char * errorMsg) -{ - COMMON_LOG_ERROR(ERROR_VERBOSE, errorMsg); - return; -} diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.h b/src/Common/Src/Error_Handler/Common_Error_Handler.h index 9292da7..cefe259 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.h @@ -24,6 +24,9 @@ // External includes. #include // Defines NULL. +#ifndef __cplusplus +#include // Defines bool data type. (For C compilers.) +#endif // __cplusplus // Project includes. #ifdef __win32 // Needed for different path seperator in Windows. @@ -35,30 +38,137 @@ #include "Common_Error_Handler_Structures.h" // Defines the error codes, error lookup table error lookup table version number, and Common::commonLastErrorCode. #include "Posix_Error_Translation_Table.h" // Defines the POSIX errno to Common namespace error translation table and functions. +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Define the C bindings for the error handler. + +/*! + * void Common_Set_Error_Log_Level(const unsigned int & logLevel) + * + * Sets the error logging level for the Common namespace functions. + * + * By default it sets the error logging level to ERROR_DISABLE. + * (Disables all logging. See Core/Src/Panic.h for a list of + * valid logging levels.) + */ +void Common_Set_Error_Log_Level(const unsigned int logLevel); + +/*! + * unsigned int Common_Get_Error_Log_Level() + * + * Returns the current error logging level for the Common namespace functions. + * + * See Core/Src/Panic.h for a list of valid logging levels. + */ +unsigned int Common_Get_Error_Log_Level(); + +/*! + * void Common_Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)) + * + * WARNING: The callback function MUST return control back to + * the caller, as the caller will be blocked until the callback + * function returns. + * + * Sets the logging function to call when an error is generated + * by a Common namespace function. + * + * For example, this function can be used to send the generated + * errors to the console in a multi-threaded enviroment. + * + * Passing a NULL pointer to this function (the default) will + * disable calling another function when an error is generated. + * In addition the logging level will be reset to ERROR_DISABLE. + */ +void Common_Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)); +#ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT + +/*! + * typedef void(*Common_pErrorCallBackFunction)(void) + * + * Defines the function pointer type for use as arguments by the Common fatal error handler functions. + */ +typedef void(*Common_pErrorCallBackFunction)(void); + +/*! + * bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) + * + * WARNING: The callback function MUST return control back to + * the caller, as the caller will be blocked until the callback + * function returns. This means any other registered callbacks + * will not be triggered, which may lead to data loss. The only exception + * to this is if the host system will kill the engine's process after a set + * amount of time. In this one specific instance, nothing can be done to + * prevent the host system from killing the engine. As such the function + * registered with this call should attempt to clean up and return as + * fast as possible. + * + * Registers a callback function for notification of an engine subsystem + * triggering the host system to kill the engine's process. + * + * Note: The registered callback is not guaranteed to be called at all prior to + * the engine process being terminated. (The host system reserves the right to + * kill the engine without warning it of the impending termination.) + * As such this should be considered an informal notification and not something + * to be relied on if data preservation / security or proper cleanup is required + * prior to engine shutdown. + * + * Returns true if the regisration completed successfully. + * Returns false otherwise. + */ +bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction); + +/*! + * bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) + * + * Unregisters the given fatal error callback function from the list of fatal error + * callback functions to be triggered in the event of a fatal error being generated. + * + * (I.e. If unregistered, a given callback function will not be called if a fatal + * error occurs.) + * + * The callback function pointer given to this function must match a function pointer + * given to Common_Register_Fatal_Error_Callback() (Or Common::Register_Fatal_Error_Callback()) previously, + * otherwise this function will fail. + * + * Returns true if the unregisration completed successfully. + * Returns false otherwise. + */ +bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction); + +/*! + * void Common_Fatal_Error_Notify() + * + * This function triggers the registered fatal error callback functions + * registered with Common_Register_Fatal_Error_Callback() (Or Common::Register_Fatal_Error_Callback()), + * in an attempt to notify all need to know sections of the engine, and application, that the engine is + * about to be terminated. + * + * When this function returns to it's caller, it is expected that the caller + * will terminate the engine's process if it does not happen automaticly. + * + * This function does not return any data to it's caller. + */ +void Common_Fatal_Error_Notify(); +#endif // MSYS_BUILD_FATAL_ERROR_SUPPORT + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus + +// Define C++ Bindings. +#ifdef __cplusplus // Define namespaces. namespace Common { - /*! - * const unsigned int Common::Get_Error_Table_Size() - * - * Returns the size of the common error table. - */ - const unsigned int Get_Error_Table_Size(); - - /*! - * const char * Common::Get_Error_Message(const int & errorCode) - * - * This function takes the given error code and returns a pointer to a human - * readable string describing the meaning of the given error code. - * - * Returns a valid pointer if the given error code is in the common error table. - * Returns the message for Common::COMMON_UNKNOWN_ERROR otherwise. - */ - const char * Get_Error_Message(const int & errorCode); - /*! * void Common::Set_Error_Log_Level(const unsigned int & logLevel) - * + * + * (C++ Binding) + * * Sets the error logging level for the Common namespace functions. * * By default it sets the error logging level to ERROR_DISABLE. @@ -69,7 +179,9 @@ namespace Common /*! * unsigned int Common::Get_Error_Log_Level() - * + * + * (C++ Binding) + * * Returns the current error logging level for the Common namespace functions. * * See Core/Src/Panic.h for a list of valid logging levels. @@ -78,7 +190,9 @@ namespace Common /*! * void Common::Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)) - * + * + * (C++ Binding) + * * WARNING: The callback function MUST return control back to * the caller, as the caller will be blocked until the callback * function returns. @@ -94,7 +208,77 @@ namespace Common * In addition the logging level will be reset to ERROR_DISABLE. */ void Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg) = NULL); + +#ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT + /*! + * bool Common::Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) + * + * (C++ Binding) + * + * WARNING: The callback function MUST return control back to + * the caller, as the caller will be blocked until the callback + * function returns. This means any other registered callbacks + * will not be triggered, which may lead to data loss. The only exception + * to this is if the host system will kill the engine's process after a set + * amount of time. In this one specific instance, nothing can be done to + * prevent the host system from killing the engine. As such the function + * registered with this call should attempt to clean up and return as + * fast as possible. + * + * Registers a callback function for notification of an engine subsystem + * triggering the host system to kill the engine's process. + * + * Note: The registered callback is not guaranteed to be called at all prior to + * the engine process being terminated. (The host system reserves the right to + * kill the engine without warning it of the impending termination.) + * As such this should be considered an informal notification and not something + * to be relied on if data preservation / security or proper cleanup is required + * prior to engine shutdown. + * + * Returns true if the regisration completed successfully. + * Returns false otherwise. + */ + bool Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction); + + /*! + * bool Common::Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) + * + * (C++ Binding) + * + * Unregisters the given fatal error callback function from the list of fatal error + * callback functions to be triggered in the event of a fatal error being generated. + * + * (I.e. If unregistered, a given callback function will not be called if a fatal + * error occurs.) + * + * The callback function pointer given to this function must match a function pointer + * given to Common_Register_Fatal_Error_Callback() (Or Common::Register_Fatal_Error_Callback()) previously, + * otherwise this function will fail. + * + * Returns true if the unregisration completed successfully. + * Returns false otherwise. + */ + bool Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction); + + /*! + * void Common::Fatal_Error_Notify() + * + * (C++ Binding) + * + * This function triggers the registered fatal error callback functions + * registered with Or Common_Register_Fatal_Error_Callback() (Common::Register_Fatal_Error_Callback()), + * in an attempt to notify all need to know sections of the engine, and application, that the engine is + * about to be terminated. + * + * When this function returns to it's caller, it is expected that the caller + * will terminate the engine's process if it does not happen automaticly. + * + * This function does not return any data to it's caller. + */ + void Fatal_Error_Notify(); +#endif // MSYS_BUILD_FATAL_ERROR_SUPPORT }; +#endif // __cplusplus #endif // COMMON_ERROR_HANDLER_H diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp b/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp new file mode 100644 index 0000000..f880379 --- /dev/null +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp @@ -0,0 +1,118 @@ +/*! + Multiverse Engine Project 13/5/2015 Common Common_Error_Handler_CPP_Bindings.cpp + + Copyright (C) 2014 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// Define C++ Bindings. +#ifdef __cplusplus + +// Internal includes. +#include "Common_Error_Handler.h" // Main header. +#include "Common_Error_Handler_Internal.h" // Private internal header that defines the structure used for error logging. + +// External includes. +#include + +void Common::Set_Error_Log_Level(const unsigned int & logLevel) +{ + Common_Set_Error_Log_Level(logLevel); +} + +unsigned int Common::Get_Error_Log_Level() +{ + return Common_Get_Error_Log_Level(); +} + +void Common::Register_Error_Log_Callback(void (*loggingFunction)(const unsigned int logLevel, const char * errorMsg)) +{ + Common_Register_Error_Log_Callback(loggingFunction); +} + +// Build the Fatal Error Handler if needed. +#ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT + +bool Common::Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) +{ + // Init vars. + bool ret = false; // The result of this function. + + // Begin try block. + try { + // Call real function. + ret = Common_Register_Fatal_Error_Callback(fatalErrorNotifyFunction); + } + catch (...) + { + /* + * Great probably a memory allocation error, if so, we don't do anything as the original list is not modifyed + * unless the operations succeed. + * + * If not, well we just destroyed the list of functions we needed to call when a fatal error happened, + * so maybe we should call terminate() here? + */ + ret = false; + } + + // Return the result. + return ret; +} + +bool Common::Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction fatalErrorNotifyFunction) +{ + // Init vars. + bool ret = false; // The result of this function. + + // Begin try block. + try { + // Call real function. + ret = Common_Unregister_Fatal_Error_Callback(fatalErrorNotifyFunction); + } + catch (...) + { + /* + * Great probably a memory allocation error, if so, we don't do anything as the original list is not modifyed + * unless the operations succeed. + * + * If not, well we just destroyed the list of functions we needed to call when a fatal error happened, + * so maybe we should call terminate() here? + */ + ret = false; + } + + // Return the result. + return ret; +} + +void Common::Fatal_Error_Notify() +{ + // Begin try block. + try { + // Call real function. + Common_Fatal_Error_Notify(); + } + catch (std::exception & ex) + { + // Well, not much to do here, we are terminating anyway. + COMMON_LOG_CRITICAL("Common::Fatal_Error_Notify(): Exception occured while notifying engine subsystems / application that a fatal error occured."); + } +} + +#endif // MSYS_BUILD_FATAL_ERROR_SUPPORT + +#endif // __cplusplus + diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Internal.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Internal.h index 1847783..a1db502 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Internal.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Internal.h @@ -34,6 +34,11 @@ //#error "This header is for internal engine use only. It should not be linked against, as it is NOT a part of the public API." //#endif // COMMON_ERROR_HANDLER_H +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + /* * struct CommonErrorLogData * @@ -57,7 +62,7 @@ struct CommonErrorLogData { * * The actual data structure that contains the error * logging data for the Common namespace functions. - * + * * Once again, DO NOT USE THIS STRUCTURE DIRECTLY! * This structure is NOT a part of the public API, and * is subject to change at anytime. @@ -137,6 +142,11 @@ void COMMON_LOG_DEBUG(const char * errorMsg); */ void COMMON_LOG_VERBOSE(const char * errorMsg); +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus + #endif // COMMON_ERROR_HANDLER_INTERNAL_H // End of Common_Error_Handler_Internal.h diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c new file mode 100644 index 0000000..0c682f4 --- /dev/null +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c @@ -0,0 +1,148 @@ +/*! + Multiverse Engine Project 16/5/2015 Common Common_Error_Handler_Structures.c + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// Internal Includes. +#include "Common_Error_Handler.h" + +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*! + * const char * COMMON_ERROR_UNKNOWN_ERROR_MSG + * + * This is the definition for the generic unknown error + * code. + * + * It is defined here to allow Common_Get_Error_Message() + * to reference it without needing to use another for loop + * to locate it's offset in the error message table. + */ +const char COMMON_ERROR_UNKNOWN_ERROR_MSG[] = COMMON_UNKNOWN_ERROR_MSG_DEF; + +/*! + * const Common_Error_Object Common_commonErrorTable[] + * + * This array contains all of the error codes that a Common namespace + * function may return, in addition to a human readable string describing + * the error code's meaning. (This is a work in progress, some error codes + * conflict with error codes in other functions, as such these are slowly + * being corrected.) + * + * The easiest way of fetching the human readable string from this table + * is to call Common::GetErrorMessage(). + * + * Do not reuse an existing error code. (If the error is generic then use a + * generic error code.) + * + * Do not change an existing error code. (This is to keep the API stable + * between revisions.) + */ +const Common_Error_Object Common_commonErrorTable[] = { + // Define the initilizers for the lookup table. + {COMMON_ERROR_UNKNOWN_ERROR, COMMON_ERROR_UNKNOWN_ERROR_MSG}, + {COMMON_ERROR_SYSTEM_SPECIFIC, "System specific error code. Check log."}, + {COMMON_ERROR_SUCCESS, "Success."}, + {COMMON_ERROR_INVALID_ARGUMENT, "Invalid argument."}, + {COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED, "Function not implemented."}, + {COMMON_ERROR_ACCESS_DENIED, "Access Denied."}, + {COMMON_ERROR_EXCEPTION_THROWN, "Execption thrown."}, + {COMMON_ERROR_INTERNAL_ERROR, "Internal error."}, + {COMMON_ERROR_IO_ERROR, "Input / Output error. (Normally this is a hardware issue.)"}, + {COMMON_ERROR_RANGE_ERROR, "Given range is invalid."}, + {COMMON_ERROR_MEMORY_ERROR, "Memory error (Could not allocate memory / Control loop out of bounds.)"}, + {COMMON_ERROR_INVALID_LIBRARY_ID, "Given LibraryID does not match a supported library or a loaded plugin."}, + {COMMON_ERROR_PEBKAC_INVALID_OPERATION_ORDER, "Caller is attempting to do something that requires another call / process to be completed first. (Check the order in which you are doing things.)"}, + {COMMON_ERROR_CANNOT_GET_SYSTEM_TIME, "Could not get the system's current time."}, + {COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED, "Given object has not been inited yet."}, + {COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED, "Given object has already been inited."}, + // Rendering Subsystem error codes. + {RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF, "Could not allocate memory for overlay image buffer."}, + {RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF, "Could not allocate memory for transparency data buffer."}, + {RENDERER_ERROR_MEM_BUF_ALLOC_EXCEPTION, "Exception thrown while attempting to allocate memory buffer(s)."}, + {RENDERER_ERROR_DUPE_OVERLAY_EXCEPTION, "Exception thrown while duplicating overlay, clearing dest overlay."}, + {RENDERER_ERROR_INVAL_OVERLAY_SELF_OVERWRITE, "Given overlays are the same. Cannot overwrite an overlay with itself."}, + {RENDERER_ERROR_TRANSPARENCY_DISABLED, "Transparency is disabled on given overlay."}, + // Threading Subsystem (Thread_Utils) error codes. + {THREAD_UTILS_ERROR_EXCEPTION_THROWN, "Exception thrown in threading subsystem."}, + {THREAD_UTILS_ERROR_PLUGIN_LOAD_FAILURE, "Unable to load plugin(s). Internal error."}, + {THREAD_UTILS_ERROR_THREAD_COULD_NOT_START, "Could not start new thread."}, + {THREAD_UTILS_ERROR_THREAD_COULD_NOT_DETACH, "Could not detach thread."}, + {THREAD_UTILS_ERROR_THREAD_COULD_NOT_JOIN, "Could not join thread."}, + {THREAD_UTILS_ERROR_MUTEX_ALREADY_LOCKED, "The given mutex is already locked."}, + {THREAD_UTILS_ERROR_CONDITION_WAIT_TIMEOUT_REACHED, "Given timeout period was exceeded while waiting for the condition variable to signal."}, + {THREAD_UTILS_ERROR_CONDITION_CANNOT_LOCK_MUTEX, "Could not lock internal mutex in condition variable object."}, + // FileUtills. + {FILEUTILLS_ERROR_EXISTANT, "The path exists."}, + {FILEUTILLS_ERROR_NON_EXISTANT, "The path (or a component of the path) does not exist."}, + {FILEUTILLS_ERROR_READ_ONLY, "The path is read only."}, + {FILEUTILLS_ERROR_PATH_LENGTH_INVALID, "The path's length is beyond the filesystem's maximum length."}, + {FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY, "The path has a file in it that is being treated as a directory."}, + {FILEUTILLS_ERROR_PATH_IS_A_FILE, "Given path is a file."}, + {FILEUTILLS_ERROR_PATH_IS_A_DIRECTORY, "Given path is a directory."}, + {FILEUTILLS_ERROR_FILESYSTEM_FULL, "Given filesystem is full."}, + {FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED, "User's disk usage quota for the given filesystem has been reached."}, + {FILEUTILLS_ERROR_EMPTY_DIRECTORY, "The given path is an empty directory."}, + {FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY, "The given path is a non-empty directory."}, + // UI Subsystem/ + {UI_SUBSYSTEM_ERROR_EXCEPTION_THROWN, "An exception was thrown in the UI Subsystem."}, + // TODO: Need to add the error codes from all common namespace functions. +}; + +const unsigned int Common_Get_Error_Table_API_Version() +{ + return COMMON_ERROR_TABLE_ABI_VER; +} + +const unsigned int Common_Get_Error_Table_Size() +{ + return (sizeof(Common_commonErrorTable) / sizeof(Common_Error_Object)); +} + +const char * Common_Get_Error_Message(const int errorCode) +{ + // Init vars. + const char * result = COMMON_ERROR_UNKNOWN_ERROR_MSG; // Result of this function. + const size_t errorTableSize = Common_Get_Error_Table_Size(); // Size of the Common error lookup table. + + // Check for COMMON_UNKNOWN_ERROR. + if (errorCode != COMMON_ERROR_UNKNOWN_ERROR) + { + // Begin lookup loop. + for (size_t x = 0; ((x < errorTableSize) && (result == COMMON_ERROR_UNKNOWN_ERROR_MSG)); x++) + { + // Check for the correct error code. + if (Common_commonErrorTable[x].errorCode == errorCode) + { + // Found the correct error code. + result = Common_commonErrorTable[x].error; + } + } + } + + // Return the result. + return result; +} + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h index 24fefa6..ad6bf04 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h @@ -1,128 +1,161 @@ +/*! + Multiverse Engine Project 04/7/2014 Common Common_Error_Handler_Structures.h + Copyright (C) 2014 Multiverse Engine Project + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// Include guard. +#ifndef COMMON_ERROR_ERROR_HANDLER_STRUCTURES_H +#define COMMON_ERROR_ERROR_HANDLER_STRUCTURES_H + +// Internal includes. #include "Error_Struct.h" // Structure used to create error lookup table. -namespace Common { - // Common namespace error code definitions. - // Error code table ABI version. - const unsigned int COMMON_ERROR_ABI_VER = 1; // Increment this if you alter the table. +// Define the Common unknown error message. (It has to be replicated in two places, once for the C code and once for the C++ bindings.) +#define COMMON_UNKNOWN_ERROR_MSG_DEF "Unknown error code." - /*! - * const static char * Common::UNKNOWN_ERROR_MSG - * - * This is the definition for the generic unknown error - * code. - * - * It is defined here to allow Common::Get_Error_Message() - * to reference it without needing to use another for loop - * to locate it's offset in the error message table. - */ - const static char * UNKNOWN_ERROR_MSG = "Unknown error code."; +// Error code table ABI version. +#define COMMON_ERROR_TABLE_ABI_VER 2 // Increment this if you alter the table. - // Error code table. +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +// Common namespace error code definitions. (Human-readable error message translation table is located in Common_Error_Handler_Structures.c) enum { // Generic error codes. - COMMON_SYSTEM_SPECIFIC = 99, - COMMON_SUCCESS = 0, - COMMON_UNKNOWN_ERROR = -1, - COMMON_INVALID_ARGUMENT = -2, - COMMON_FUNCTION_NOT_IMPLEMENTED = -3, - COMMON_ACCESS_DENIED = -4, - COMMON_EXCEPTION_THROWN = -5, - COMMON_INTERNAL_ERROR = -6, - COMMON_IO_ERROR = -7, - COMMON_RANGE_ERROR = -8, - COMMON_MEMORY_ERROR = -9, + COMMON_ERROR_SYSTEM_SPECIFIC = 99, + COMMON_ERROR_SUCCESS = 0, + COMMON_ERROR_UNKNOWN_ERROR = -1, + COMMON_ERROR_INVALID_ARGUMENT = -2, + COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED = -3, + COMMON_ERROR_ACCESS_DENIED = -4, + COMMON_ERROR_EXCEPTION_THROWN = -5, + COMMON_ERROR_INTERNAL_ERROR = -6, + COMMON_ERROR_IO_ERROR = -7, + COMMON_ERROR_RANGE_ERROR = -8, + COMMON_ERROR_MEMORY_ERROR = -9, + COMMON_ERROR_INVALID_LIBRARY_ID = -10, // Formerly THREAD_UTILS_INVALID_LIBRARY_ID. + COMMON_ERROR_PEBKAC_INVALID_OPERATION_ORDER = -11, + COMMON_ERROR_CANNOT_GET_SYSTEM_TIME = -12, + COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED = -13, + COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED = -14, + // Rendering Subsystem error codes. - RENDERER_UNABLE_TO_ALLOC_OI_BUF = -12, // Overlay image buffer. - RENDERER_UNABLE_TO_ALLOC_TD_BUF = -13, // Transparency data buffer. - RENDERER_MEM_BUF_ALLOC_EXCEPTION = -14, - RENDERER_DUPE_OVERLAY_EXCEPTION = -15, - RENDERER_INVAL_OVERLAY_SELF_OVERWRITE = -16, - RENDERER_TRANSPARENCY_DISABLED = -17, + RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF = -21, // Overlay image buffer. + RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF = -22, // Transparency data buffer. + RENDERER_ERROR_MEM_BUF_ALLOC_EXCEPTION = -23, + RENDERER_ERROR_DUPE_OVERLAY_EXCEPTION = -24, + RENDERER_ERROR_INVAL_OVERLAY_SELF_OVERWRITE = -25, + RENDERER_ERROR_TRANSPARENCY_DISABLED = -26, // Threading Subsystem error codes. - THREAD_UTILS_EXCEPTION_THROWN = -31, - THREAD_UTILS_INVALID_LIBRARY_ID = -32, - THREAD_UTILS_PLUGIN_LOAD_FAILURE = -33, + THREAD_UTILS_ERROR_EXCEPTION_THROWN = -31, + THREAD_UTILS_ERROR_PLUGIN_LOAD_FAILURE = -32, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_START = -33, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_DETACH = -34, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_JOIN = -35, + THREAD_UTILS_ERROR_MUTEX_ALREADY_LOCKED = -36, + THREAD_UTILS_ERROR_CONDITION_CANNOT_LOCK_MUTEX = -37, + THREAD_UTILS_ERROR_CONDITION_WAIT_TIMEOUT_REACHED = -38, // FileUtills error codes. - FILEUTILLS_EXISTANT = -60, - FILEUTILLS_NON_EXISTANT = -61, - FILEUTILLS_READ_ONLY = -62, - FILEUTILLS_PATH_LENGTH_INVALID = -63, - FILEUTILLS_PATH_FILE_AS_DIRECTORY = -64, - FILEUTILLS_PATH_IS_A_FILE = -65, - FILEUTILLS_PATH_IS_A_DIRECTORY = -66, - FILEUTILLS_FILESYSTEM_FULL = -67, - FILEUTILLS_FILESYSTEM_QUOTA_REACHED = -68, - FILEUTILLS_EMPTY_DIRECTORY = -69, - FILEUTILLS_NON_EMPTY_DIRECTORY = -70, + FILEUTILLS_ERROR_EXISTANT = -60, + FILEUTILLS_ERROR_NON_EXISTANT = -61, + FILEUTILLS_ERROR_READ_ONLY = -62, + FILEUTILLS_ERROR_PATH_LENGTH_INVALID = -63, + FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY = -64, + FILEUTILLS_ERROR_PATH_IS_A_FILE = -65, + FILEUTILLS_ERROR_PATH_IS_A_DIRECTORY = -66, + FILEUTILLS_ERROR_FILESYSTEM_FULL = -67, + FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED = -68, + FILEUTILLS_ERROR_EMPTY_DIRECTORY = -69, + FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY = -70, + // UI Subsystem. + UI_SUBSYSTEM_ERROR_EXCEPTION_THROWN = -90, }; +/*! + * const unsigned int Common_Get_Error_Table_API_Version() + * + * Returns the API version number of the common error table. + */ +const unsigned int Common_Get_Error_Table_API_Version(); + +/*! + * const unsigned int Common_Get_Error_Table_Size() + * + * Returns the size of the common error table. + */ +const unsigned int Common_Get_Error_Table_Size(); + +/*! + * const char * Common_Get_Error_Message(const int & errorCode) + * + * This function takes the given error code and returns a pointer to a human + * readable string describing the meaning of the given error code. + * + * Returns a valid pointer if the given error code is in the common error table. + * Returns the message for Common_COMMON_UNKNOWN_ERROR otherwise. + */ +const char * Common_Get_Error_Message(const int errorCode); + +// Define C++ Bindings. +#ifdef __cplusplus +// Define namespaces. +namespace Common +{ /*! - * const Common_Error_Object Common::commonErrorTable[] - * - * This array contains all of the error codes that a Common namespace - * function may return, in addition to a human readable string describing - * the error code's meaning. (This is a work in progress, some error codes - * conflict with error codes in other functions, as such these are slowly - * being corrected.) - * - * The easiest way of fetching the human readable string from this table - * is to call Common::GetErrorMessage(). - * - * Do not reuse an existing error code. (If the error is generic then use a - * generic error code.) - * - * Do not change an existing error code. (This is to keep the API stable - * between revisions.) + * const unsigned int Common::Get_Error_Table_API_Version() + * + * (C++ Binding) + * + * Returns the API version number of the common error table. */ - const Common_Error_Object commonErrorTable[] = { - {COMMON_UNKNOWN_ERROR, UNKNOWN_ERROR_MSG}, - {COMMON_SYSTEM_SPECIFIC, "System specific error code. Check log."}, - {COMMON_SUCCESS, "Success."}, - {COMMON_INVALID_ARGUMENT, "Invalid argument."}, - {COMMON_FUNCTION_NOT_IMPLEMENTED, "Function not implemented."}, - {COMMON_ACCESS_DENIED, "Access Denied."}, - {COMMON_EXCEPTION_THROWN, "Execption thrown."}, - {COMMON_INTERNAL_ERROR, "Internal error."}, - {COMMON_IO_ERROR, "Input / Output error. (Normally this is a hardware issue.)"}, - {COMMON_RANGE_ERROR, "Given range is invalid."}, - {COMMON_MEMORY_ERROR, "Memory error (Could not allocate memory / Control loop out of bounds.)"}, - // Rendering Subsystem error codes. - {RENDERER_UNABLE_TO_ALLOC_OI_BUF, "Could not allocate memory for overlay image buffer."}, - {RENDERER_UNABLE_TO_ALLOC_TD_BUF, "Could not allocate memory for transparency data buffer."}, - {RENDERER_MEM_BUF_ALLOC_EXCEPTION, "Exception thrown while attempting to allocate memory buffer(s)."}, - {RENDERER_DUPE_OVERLAY_EXCEPTION, "Exception thrown while duplicating overlay, clearing dest overlay."}, - {RENDERER_INVAL_OVERLAY_SELF_OVERWRITE, "Given overlays are the same. Cannot overwrite an overlay with itself."}, - {RENDERER_TRANSPARENCY_DISABLED, "Transparency is disabled on given overlay."}, - // Threading Subsystem (Thread_Utils) error codes. - {THREAD_UTILS_EXCEPTION_THROWN, "Exception thrown in threading subsystem."}, - {THREAD_UTILS_INVALID_LIBRARY_ID, "Given LibraryID does not match a supported library or a loaded plugin."}, - {THREAD_UTILS_PLUGIN_LOAD_FAILURE, "Unable to load plugin(s). Internal error."}, - // FileUtills. - {FILEUTILLS_EXISTANT, "The path exists."}, - {FILEUTILLS_NON_EXISTANT, "The path (or a component of the path) does not exist."}, - {FILEUTILLS_READ_ONLY, "The path is read only."}, - {FILEUTILLS_PATH_LENGTH_INVALID, "The path's length is beyond the filesystem's maximum length."}, - {FILEUTILLS_PATH_FILE_AS_DIRECTORY, "The path has a file in it that is being treated as a directory."}, - {FILEUTILLS_PATH_IS_A_FILE, "Given path is a file."}, - {FILEUTILLS_PATH_IS_A_DIRECTORY, "Given path is a directory."}, - {FILEUTILLS_FILESYSTEM_FULL, "Given filesystem is full."}, - {FILEUTILLS_FILESYSTEM_QUOTA_REACHED, "User's disk usage quota for the given filesystem has been reached."}, - {FILEUTILLS_EMPTY_DIRECTORY, "The given path is an empty directory."}, - {FILEUTILLS_NON_EMPTY_DIRECTORY, "The given path is a non-empty directory."}, - // TODO: Need to add the error codes from all common namespace functions. - }; + const unsigned int Get_Error_Table_API_Version(); + + /*! + * const unsigned int Common::Get_Error_Table_Size() + * + * (C++ Binding) + * + * Returns the size of the common error table. + */ + const unsigned int Get_Error_Table_Size(); /*! - * static int Common::commonLastErrorCode + * const char * Common::Get_Error_Message(const int & errorCode) + * + * (C++ Binding) * - * Contains the last error code encountered by a Common namespace function. + * This function takes the given error code and returns a pointer to a human + * readable string describing the meaning of the given error code. * - * Note: Calling Common::GetErrorMessage() or Common::GetErrorTableSize() - * will NOT clear this variable. - * Calling any other Common namespace function WILL clear this variable. + * Returns a valid pointer if the given error code is in the common error table. + * Returns the message for Common_COMMON_UNKNOWN_ERROR otherwise. */ - static int commonLastErrorCode = COMMON_SUCCESS; -}; + const char * Get_Error_Message(const int & errorCode); +} +#endif // __cplusplus + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // COMMON_ERROR_ERROR_HANDLER_STRUCTURES_H + +// End of Common_Error_Handler_Structures.h diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures_CPP_Bindings.cpp b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures_CPP_Bindings.cpp new file mode 100644 index 0000000..0fd7237 --- /dev/null +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures_CPP_Bindings.cpp @@ -0,0 +1,41 @@ +/*! + Multiverse Engine Project 16/5/2015 Common Common_Error_Handler_Structures_CPP_Bindings.cpp + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// Internal Includes. +#include "Common_Error_Handler.h" + +// Define C++ Bindings. +#ifdef __cplusplus + +const unsigned int Common::Get_Error_Table_API_Version() +{ + return Common_Get_Error_Table_API_Version(); +} + +const unsigned int Common::Get_Error_Table_Size() +{ + return Common_Get_Error_Table_Size(); +} + +const char * Common::Get_Error_Message(const int & errorCode) +{ + return Common_Get_Error_Message(errorCode); +} +#endif // __cplusplus diff --git a/src/Common/Src/Error_Handler/Error_Struct.h b/src/Common/Src/Error_Handler/Error_Struct.h index d551a0a..e08b1b0 100644 --- a/src/Common/Src/Error_Handler/Error_Struct.h +++ b/src/Common/Src/Error_Handler/Error_Struct.h @@ -18,14 +18,31 @@ https://github.com/codebase7/mengine */ +// Include guard. #ifndef ERROR_STRUCT_H #define ERROR_STRUCT_H -struct Common_Error_Object { +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*! + * typedef struct Common_Error_Object_T + * + * Defines the data structure used by the Common Error Handler functions + * to look up human-readable strings and their assoicated error codes. + */ +typedef struct Common_Error_Object_T { short errorCode; const char * error; -}; +} Common_Error_Object; + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus -#endif +#endif // ERROR_STRUCT_H -// End of Error_Struct.h \ No newline at end of file +// End of Error_Struct.h diff --git a/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.cpp b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.c similarity index 60% rename from src/Common/Src/Error_Handler/Posix_Error_Translation_Table.cpp rename to src/Common/Src/Error_Handler/Posix_Error_Translation_Table.c index edfe8c1..e33fe41 100644 --- a/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.cpp +++ b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.c @@ -1,5 +1,5 @@ /*! - Multiverse Engine Project 05/7/2014 Common Posix_Error_Translation_Table.cpp + Multiverse Engine Project 05/7/2014 Common Posix_Error_Translation_Table.c Copyright (C) 2014 Multiverse Engine Project @@ -22,33 +22,48 @@ #include "Common_Error_Handler_Structures.h" #include "Posix_Error_Translation_Table.h" -unsigned int Common::Get_Posix_Error_Translation_Table_Size() +// Include Extern C if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +const unsigned int Common_Get_Posix_Error_Translation_Table_API_Version() +{ + return COMMON_POSIX_ERROR_TRANSLATION_TABLE_API_VERSION; +} + +const unsigned int Common_Get_Posix_Error_Translation_Table_Size() { - return (sizeof(Common::posixErrorTranslationTable) / sizeof(Common::posixErrnoTableEntry)); + return (sizeof(Common_posixErrorTranslationTable) / sizeof(Common_posixErrnoTableEntry)); } -int Common::Translate_Posix_Errno_To_Common_Error_Code(const int & err) +int Common_Translate_Posix_Errno_To_Common_Error_Code(const int err) { // Init result. - int ret = COMMON_SYSTEM_SPECIFIC; /* - * Default is COMMON_SYSTEM_SPECIFIC, as + int ret = COMMON_ERROR_SYSTEM_SPECIFIC; /* + * Default is COMMON_ERROR_SYSTEM_SPECIFIC, as * not all POSIX errno(s) are / can be * reperesented in the Common namespace * error code table. */ // Run loop. - for (unsigned int x = 0; ((x < Common::Get_Posix_Error_Translation_Table_Size()) && - (ret == COMMON_SYSTEM_SPECIFIC)); x++) + for (unsigned int x = 0; ((x < Common_Get_Posix_Error_Translation_Table_Size()) && + (ret == COMMON_ERROR_SYSTEM_SPECIFIC)); x++) { // Check for a match in the error code translation table. - if (Common::posixErrorTranslationTable[x].posixErrorNo == err) + if (Common_posixErrorTranslationTable[x].posixErrorNo == err) { // Match found, return the Common namespace error code. - ret = Common::posixErrorTranslationTable[x].commonErrorCode; + ret = Common_posixErrorTranslationTable[x].commonErrorCode; } } // Return the result. return ret; -} \ No newline at end of file +} + +// Terminate C linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus diff --git a/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.h b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.h index 25d3ab6..671704b 100644 --- a/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.h +++ b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table.h @@ -25,66 +25,143 @@ // Include POSIX errno header. #include +// Enable C linkage if needed. +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/*! + * #define COMMON_POSIX_ERROR_TRANSLATION_TABLE_API_VERSION + * + * Defines the API version of the posix errno to + * common namespace error code translation table. + * + * If you change the table increment the version + * number. + */ +#define COMMON_POSIX_ERROR_TRANSLATION_TABLE_API_VERSION 1 + +/*! + * typedef struct Common_posixErrnoTableEntry_T Common_posixErrnoTableEntry + * + * (C Binding.) + * + * Used to construct the errno translation table. + * for POSIX compliant systems. + */ +typedef struct Common_posixErrnoTableEntry_T { + int posixErrorNo; + int commonErrorCode; +} Common_posixErrnoTableEntry; + +/*! + * const static Common_posixErrnoTableEntry Common_posixErrorTranslationTable[] + * + * A table that contains (some) POSIX errno codes and their + * Common namespace error code equilivants. + * + * Not all POSIX errno(s) are present in this table, as + * some POSIX errno(s) are specific to POSIX compliant + * systems. As such there is no Common namespace error + * code (beyond COMMON_SYSTEM_SPECIFIC) to represent them. + */ +const static Common_posixErrnoTableEntry Common_posixErrorTranslationTable[] = { + {EACCES, COMMON_ERROR_ACCESS_DENIED}, + {ENOENT, FILEUTILLS_ERROR_NON_EXISTANT}, + {EEXIST, FILEUTILLS_ERROR_EXISTANT}, + {EROFS, FILEUTILLS_ERROR_READ_ONLY}, + {EINVAL, COMMON_ERROR_INVALID_ARGUMENT}, + {ENAMETOOLONG, FILEUTILLS_ERROR_PATH_LENGTH_INVALID}, + {ENOTDIR, FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY}, + {ENOMEM, COMMON_ERROR_MEMORY_ERROR}, + {EFAULT, COMMON_ERROR_INVALID_ARGUMENT}, + {ENOSPC, FILEUTILLS_ERROR_FILESYSTEM_FULL}, + {EDQUOT, FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED}, + {ENOTEMPTY, FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY}, +}; + +/*! + * const unsigned int Common_Get_Posix_Error_Translation_Table_API_Version() + * + * Returns the API Version number of the Common_posixErrorTranslationTable + * array. + */ +const unsigned int Common_Get_Posix_Error_Translation_Table_API_Version(); + +/*! + * const unsigned int Common_Get_Posix_Error_Translation_Table_Size() + * + * Returns the size of the Common::posixErrorTranslationTable + * array. + */ +const unsigned int Common_Get_Posix_Error_Translation_Table_Size(); + +/*! + * int Common_Translate_Posix_Errno_To_Common_Error_Code(const int err) + * + * Translates the given POSIX errno to it's Common namespace + * error code equilivant. (If applicable.) + * + * WARNING: Because the POSIX errno variable is global, you + * should never call this function passing errno directly. + * + * Instead, copy the errno to a temporary variable and then + * pass the temporary variable to this function. + * + * (Otherwise just calling this function could change errno + * before it is checked.) + * + * @pram const int err, the POSIX error code to translate. + * + * Returns the translated Common namespace error code if applicable. + * + * Returns COMMON_SYSTEM_SPECIFIC if the POSIX errno does not have a + * Common namespace error code translation. + */ +int Common_Translate_Posix_Errno_To_Common_Error_Code(const int err); + +// End C Linkage if needed. +#ifdef __cplusplus +} +#endif // __cplusplus + +// Check for a C compiler. +#ifdef __cplusplus namespace Common { /*! - * struct Common::posixErrnoTableEntry - * + * typedef Common_posixErrnoTableEntry Common::posixErrnoTableEntry + * + * (C++ Binding.) + * * Used to construct the errno translation table. * for POSIX compliant systems. */ - struct posixErrnoTableEntry{ - int posixErrorNo; - int commonErrorCode; - }; + typedef Common_posixErrnoTableEntry posixErrnoTableEntry; /*! - * const int posixErrorTranslationTableAPIVersion - * - * Defines the API version of the posix errno to - * common namespace error code translation table. - * - * If you change the table increment the version - * number. - */ - const int posixErrorTranslationTableAPIVersion = 1; - - /*! - * const Common::posixErrnoTableEntry Common::posixErrorTranslationTable[] - * - * A table that contains (some) POSIX errno codes and their - * Common namespace error code equilivants. + * const unsigned int Common::Get_Posix_Error_Translation_Table_API_Version() * - * Not all POSIX errno(s) are present in this table, as - * some POSIX errno(s) are specific to POSIX compliant - * systems. As such there is no Common namespace error - * code (beyond COMMON_SYSTEM_SPECIFIC) to represent them. + * Returns the API Version number of the Common_posixErrorTranslationTable + * array. */ - const posixErrnoTableEntry posixErrorTranslationTable[] = { - {EACCES, Common::COMMON_ACCESS_DENIED}, - {ENOENT, Common::FILEUTILLS_NON_EXISTANT}, - {EEXIST, Common::FILEUTILLS_EXISTANT}, - {EROFS, Common::FILEUTILLS_READ_ONLY}, - {EINVAL, Common::COMMON_INVALID_ARGUMENT}, - {ENAMETOOLONG, Common::FILEUTILLS_PATH_LENGTH_INVALID}, - {ENOTDIR, Common::FILEUTILLS_PATH_FILE_AS_DIRECTORY}, - {ENOMEM, Common::COMMON_MEMORY_ERROR}, - {EFAULT, Common::COMMON_INVALID_ARGUMENT}, - {ENOSPC, Common::FILEUTILLS_FILESYSTEM_FULL}, - {EDQUOT, Common::FILEUTILLS_FILESYSTEM_QUOTA_REACHED}, - }; + const unsigned int Get_Posix_Error_Translation_Table_API_Version(); /*! - * unsigned int Common::Get_Posix_Error_Translation_Table_Size() - * + * const unsigned int Common::Get_Posix_Error_Translation_Table_Size() + * + * (C++ Binding) + * * Returns the size of the Common::posixErrorTranslationTable * array. */ - unsigned int Get_Posix_Error_Translation_Table_Size(); + const unsigned int Get_Posix_Error_Translation_Table_Size(); /*! * int Common::Translate_Posix_Errno_To_Common_Error_Code(const int & err) - * + * + * (C++ Binding) + * * Translates the given POSIX errno to it's Common namespace * error code equilivant. (If applicable.) * @@ -106,6 +183,7 @@ namespace Common */ int Translate_Posix_Errno_To_Common_Error_Code(const int & err); }; +#endif // __cplusplus #endif // POSIX_ERROR_TRANSLATION_TABLE_H diff --git a/src/Common/Src/Error_Handler/Posix_Error_Translation_Table_CPP_Bindings.cpp b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table_CPP_Bindings.cpp new file mode 100644 index 0000000..96c7adb --- /dev/null +++ b/src/Common/Src/Error_Handler/Posix_Error_Translation_Table_CPP_Bindings.cpp @@ -0,0 +1,45 @@ +/*! + Multiverse Engine Project 15/5/2015 Common Posix_Error_Translation_Table_CPP_Bindings.cpp + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +// C++ Bindings. +#ifdef __cplusplus + +// Internal includes. +#include "Common_Error_Handler_Structures.h" +#include "Posix_Error_Translation_Table.h" + +// External includes. +#include + +const unsigned int Common::Get_Posix_Error_Translation_Table_API_Version() +{ + return Common_Get_Posix_Error_Translation_Table_API_Version(); +} + +const unsigned int Common::Get_Posix_Error_Translation_Table_Size() +{ + return Common_Get_Posix_Error_Translation_Table_Size(); +} + +int Common::Translate_Posix_Errno_To_Common_Error_Code(const int & err) +{ + return Common_Translate_Posix_Errno_To_Common_Error_Code(err); +} +#endif // __cplusplus From 93199aa7662b72c19aa42a554de09fa34e82cd86 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 14:18:37 -0400 Subject: [PATCH 002/134] Move fake stdbool.h This commit moves the fake stdbool.h from src/Common/Src/Mutexes to src/Common/Src. --- src/Common/Src/Mutexes/Windows/MSYS_Mutexes_MSVC.h | 2 +- src/Common/Src/{Mutexes => }/stdbool.h | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/Common/Src/{Mutexes => }/stdbool.h (100%) diff --git a/src/Common/Src/Mutexes/Windows/MSYS_Mutexes_MSVC.h b/src/Common/Src/Mutexes/Windows/MSYS_Mutexes_MSVC.h index 83d9af3..f1e625b 100644 --- a/src/Common/Src/Mutexes/Windows/MSYS_Mutexes_MSVC.h +++ b/src/Common/Src/Mutexes/Windows/MSYS_Mutexes_MSVC.h @@ -35,7 +35,7 @@ extern "C" { #endif /* __cplusplus */ /* Define stdbool. */ -#include "..\stdbool.h" +#include "..\..\stdbool.h" /* Define the functions. */ diff --git a/src/Common/Src/Mutexes/stdbool.h b/src/Common/Src/stdbool.h similarity index 100% rename from src/Common/Src/Mutexes/stdbool.h rename to src/Common/Src/stdbool.h From 23ba84692495683be3d86d8fb664034c56533b12 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 15:19:39 -0400 Subject: [PATCH 003/134] MSVC fix for Error_Handler.c This commit is a compile fix for Common_Error_Handler.c under MSVC. Also changes the data type for registeredFatalErrorCallbackFunctionsSize from an unsigned int to a size_t. --- .../Src/Error_Handler/Common_Error_Handler.c | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.c b/src/Common/Src/Error_Handler/Common_Error_Handler.c index eb462fe..ca2aefe 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.c +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.c @@ -84,11 +84,11 @@ void Common_Register_Error_Log_Callback(void (*loggingFunction)(const unsigned i // Build the Fatal Error Handler if needed. #ifdef MSYS_BUILD_FATAL_ERROR_SUPPORT /*! - * static unsigned int registeredFatalErrorCallbackFunctionsSize + * static size_t registeredFatalErrorCallbackFunctionsSize * - * This unsigned int is used to remember the allocated size of the registeredFatalErrorCallbackFunctions array. + * This size_t is used to remember the allocated size of the registeredFatalErrorCallbackFunctions array. */ -static unsigned int registeredFatalErrorCallbackFunctionsSize = 0; +static size_t registeredFatalErrorCallbackFunctionsSize = 0; /* * static Common_pErrorCallBackFunction * registeredFatalErrorCallbackFunctions @@ -113,6 +113,7 @@ bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fa bool ret = false; // The result of this function. size_t previousErrorListSize = registeredFatalErrorCallbackFunctionsSize; // The size of the previous error list. size_t newErrorListSize = 0; // The size of the new error list we are creating. + size_t x = 0; /* Counter used in for loops. */ Common_pErrorCallBackFunction * previousErrorList = registeredFatalErrorCallbackFunctions; // The previous error list. Common_pErrorCallBackFunction * newErrorList = NULL; // The new error list we are creating. MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). @@ -142,7 +143,7 @@ bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fa newErrorListSize = (previousErrorListSize + 1); // Copy the data. - for (size_t x = 0; x < previousErrorListSize; x++) + for (x = 0; x < previousErrorListSize; x++) { newErrorList[x] = previousErrorList[x]; } @@ -173,7 +174,7 @@ bool Common_Register_Fatal_Error_Callback(const Common_pErrorCallBackFunction fa if ((previousErrorList != NULL) && (previousErrorList != newErrorList) && (previousErrorListSize > 0)) { // Null out the old pointer list. - for (size_t x = 0; x < previousErrorListSize; x++) + for (x = 0; x < previousErrorListSize; x++) { previousErrorList[x] = NULL; } @@ -203,6 +204,8 @@ bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction bool ret = false; // The result of this function. size_t previousErrorListSize = registeredFatalErrorCallbackFunctionsSize; // The size of the previous error list. size_t newErrorListSize = 0; // The size of the new error list we are creating. + size_t x = 0; /* Counter used in top level for loops. */ + size_t y = 0; /* Counter used in sub level 1 for loops. */ Common_pErrorCallBackFunction * previousErrorList = registeredFatalErrorCallbackFunctions; // The previous error list. Common_pErrorCallBackFunction * newErrorList = NULL; // The new error list we are creating. MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). @@ -218,7 +221,7 @@ bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction if ((previousErrorList != NULL) && (previousErrorListSize > 0)) { // Check the existing list for that function. - for (size_t x = 0; ((newErrorList == NULL) && (x < previousErrorListSize)); x++) + for (x = 0; ((newErrorList == NULL) && (x < previousErrorListSize)); x++) { // Check for the correct function, to see if the function was registered previously. if (previousErrorList[x] == fatalErrorNotifyFunction) @@ -237,7 +240,7 @@ bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction if ((newErrorList != NULL) && (newErrorListSize == (previousErrorListSize - 1))) { // Copy the data. - for (size_t x = 0, y = 0; ((x < previousErrorListSize) && (y < newErrorListSize)); x++) + for (x = 0, y = 0; ((x < previousErrorListSize) && (y < newErrorListSize)); x++) { // Make sure we don't copy the pointer we are removing. if (previousErrorList[x] != fatalErrorNotifyFunction) @@ -256,7 +259,7 @@ bool Common_Unregister_Fatal_Error_Callback(const Common_pErrorCallBackFunction if ((previousErrorList != NULL) && (previousErrorList != newErrorList) && (previousErrorListSize > 0)) { // Null out the old pointer list. - for (size_t x = 0; x < previousErrorListSize; x++) + for (x = 0; x < previousErrorListSize; x++) { previousErrorList[x] = NULL; } @@ -284,6 +287,7 @@ void Common_Fatal_Error_Notify() { // Init vars. MSYS_Mutex * retFromLockMutex = NULL; // The result from the call to MSYS_Lock_Mutex(). + size_t x = 0; /* Counter used in loops. */ // Lock the error handler mutex. retFromLockMutex = MSYS_Lock_Mutex(fatalErrorHandlerMutex); @@ -293,7 +297,7 @@ void Common_Fatal_Error_Notify() if (registeredFatalErrorCallbackFunctionsSize > 0) { // Begin vector iteration loop. - for (size_t x = 0; (x < registeredFatalErrorCallbackFunctionsSize); x++) + for (x = 0; (x < registeredFatalErrorCallbackFunctionsSize); x++) { // Trigger each function. if (registeredFatalErrorCallbackFunctions[x] != NULL) From 55e9861feda9030111abc5c20c424a163ce6ee22 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 15:20:55 -0400 Subject: [PATCH 004/134] Remove unused exception var This commit removes the unused execption variable from Common::Fatal_Error_Notify(). (Get rid of compile warning.) --- .../Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp b/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp index f880379..f355d93 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_CPP_Bindings.cpp @@ -105,7 +105,7 @@ void Common::Fatal_Error_Notify() // Call real function. Common_Fatal_Error_Notify(); } - catch (std::exception & ex) + catch (...) { // Well, not much to do here, we are terminating anyway. COMMON_LOG_CRITICAL("Common::Fatal_Error_Notify(): Exception occured while notifying engine subsystems / application that a fatal error occured."); From 7b918ff838a218c37f9ed26478d155989c86b284 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 15:22:22 -0400 Subject: [PATCH 005/134] MSVC fix for Error_Handler_Struct This commit is a compile fix for Common_Error_Handler_Structures.c under MSVC. --- src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c index 0c682f4..c693f92 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c @@ -122,12 +122,13 @@ const char * Common_Get_Error_Message(const int errorCode) // Init vars. const char * result = COMMON_ERROR_UNKNOWN_ERROR_MSG; // Result of this function. const size_t errorTableSize = Common_Get_Error_Table_Size(); // Size of the Common error lookup table. + size_t x = 0; /* Counter used in for loop. */ // Check for COMMON_UNKNOWN_ERROR. if (errorCode != COMMON_ERROR_UNKNOWN_ERROR) { // Begin lookup loop. - for (size_t x = 0; ((x < errorTableSize) && (result == COMMON_ERROR_UNKNOWN_ERROR_MSG)); x++) + for (x = 0; ((x < errorTableSize) && (result == COMMON_ERROR_UNKNOWN_ERROR_MSG)); x++) { // Check for the correct error code. if (Common_commonErrorTable[x].errorCode == errorCode) From 4e1f6353ac90824489a1ba1592caff6afe784be4 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 15:31:27 -0400 Subject: [PATCH 006/134] MSVC fix Common_Error_Handler.h This commit is a compile fix for Common_Error_Handler.h under MSVC. (Fix missing stdbool.h with false header.) --- src/Common/Src/Error_Handler/Common_Error_Handler.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.h b/src/Common/Src/Error_Handler/Common_Error_Handler.h index 02f4949..03267f4 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.h @@ -25,8 +25,12 @@ // External includes. #include // Defines NULL. #ifndef __cplusplus -#include // Defines bool data type. (For C compilers.) -#endif // __cplusplus +#ifdef _MSC_FULL_VER /* VC is special. */ +#include "..\stdbool.h" /* Defines bool data type. (For C compilers.) */ +#else +#include +#endif /* _MSC_FULL_VER */ +#endif /* __cplusplus */ // Project includes. #ifdef _WIN32 // Needed for different path seperator in Windows. From ff80017ce633810bbde571239c6fe9a8d82d7c7b Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 21:19:12 -0400 Subject: [PATCH 007/134] Commit missing file. This commit adds the missing Dynamic_Library_Subsystem_Windows.c file. (It's defined to be built in master, but not present. We are creating this branch as it requires the fake stdbool header from the error_handler branch to build under MSVC. Also due to the code being untested, we are moving it here to avoid messing up master.) --- .../Dynamic_Library_Subsystem_Windows.c | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c diff --git a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c new file mode 100644 index 0000000..0691225 --- /dev/null +++ b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c @@ -0,0 +1,212 @@ +/*! + Multiverse Engine Project 28/3/2014 Dynamic_Library_Subsystem Dynamic_Library_Subsystem_Windows.c + + Copyright (C) 2014 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +#include "Dynamic_Library_Subsystem.h" +#include + +#ifdef __cplusplus +// Define extern C. +extern "C" { +#endif + int Common_Dynamic_Library_Subsystem_Load_Library(const char * pathToLibrary, const bool reloadLibrary, Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib) + { + // Init vars. + int result = 0; // The result of this function. + HMODULE callResult = NULL; // The result of the call to LoadLibraryEx(). + + // Check to see if the pointer to the management structure is valid. + if (lib != NULL) + { + // Check to see if pathToLibrary is NULL. + if (pathToLibrary != NULL) + { + // Check to see if the library is loaded. + if ((!lib->bIsLoaded) || (reloadLibrary)) + { + // Check and see if the library is loaded. + if (lib->bIsLoaded) + { + // Call Unload_Library. + result = Common_Dynamic_Library_Subsystem_Unload_Library(lib); + } + + // Only continue if the library was unloaded, or if we did not need to unload the library. + if (result == 0) + { + // Set the values in lib. + lib->bIsLoaded = false; + lib->bLastCallEncounteredAnError = false; + lib->osSpecificPointerData = NULL; + lib->pathToLibrary = pathToLibrary; + + // Call LoadLibraryEx(). + callResult = LoadLibraryEx(lib->pathToLibrary, NULL, 0); + + // Check the callResult. + if (callResult == NULL) + { + // Could not load the library. + result = -1; + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Load_Library(): Could not load the library.\n"); + } + else + { + // Cast the OS specific data structure pointer to void*. + lib->osSpecificPointerData = (void*)callResult; + + // Set bIsLoaded. + lib->bIsLoaded = true; + } + } + else + { + // Encountered an error during the unload. + result = -2; + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Load_Library(): Unable to reload library.\n"); + } + } + else + { + // Library is already loaded. + result = 1; + } + } + else + { + // pathToLibrary is NULL. + result = -3; + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Load_Library(): No path to the library was given. Unable to load a library without the path to it.\n"); + } + } + else + { + // Management structure is invalid. + result = -4; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Load_Library(): The engine's library structure for the given library is invalid. Unable to load a library without a valid library structure.\n"); + } + + // Return result. + return result; + } + + int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib) + { + // Init vars. + int result = 0; // The result of this function. + + // Check to see if the pointer to the management structure is valid. + if (lib != NULL) + { + // Reset bLastCallEncounteredAnError. + lib->bLastCallEncounteredAnError = false; + + // Check and see if the OS specific data structure pointer is valid. + if ((lib->bIsLoaded) && (lib->osSpecificPointerData != NULL)) + { + // Call FreeLibrary. + if (FreeLibrary((HMODULE)lib->osSpecificPointerData)) + { + // The library was unloaded successfully. + lib->bIsLoaded = false; + lib->osSpecificPointerData = NULL; + } + else + { + // Could not unload the library. + result = -2; + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Unload_Library(): Could not unload the library.\n"); + } + } + else + { + // Library is not loaded. + result = -1; + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Unload_Library(): The library is not loaded.\n"); + } + } + else + { + // Management structure is invalid. + result = -4; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Unload_Library(): The engine's library structure for the given library is invalid. Unable to unload a library without a valid library structure.\n"); + } + + // Return result. + return result; + } + + void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib, const char * symbolName) + { + // Init vars. + void * result = NULL; // The result of this function. + + // Check to see if the pointer to the management structure is valid. + if (lib != NULL) + { + // Reset bLastCallEncounteredAnError. + lib->bLastCallEncounteredAnError = false; + + // Check to see if symbolName is NULL. + if (symbolName != NULL) + { + // Check for a loaded library. + if (((lib->bIsLoaded) && (lib->osSpecificPointerData != NULL))) + { + // Get the address. + result = (void*)GetProcAddress((HMODULE)lib->osSpecificPointerData, symbolName); + if (result == NULL) + { + // An error occured fetching the symbol. + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Get_Symbol(): Unable to retrive symbol.\n"); + } + } + else + { + // Library is not loaded. + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Get_Symbol(): The library is not loaded.\n"); + } + } + else + { + // symbolName is NULL. + lib->bLastCallEncounteredAnError = true; + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Get_Symbol(): No symbol name was given, cannot load a symbol without a name to identifiy it.\n"); + } + } + else + { + // Library structure is invalid. + COMMON_LOG_VERBOSE("Common_Dynamic_Library_Subsystem_Get_Symbol(): The engine's library structure for the given library is invalid. Unable to lookup function without a valid library structure.\n"); + } + + // Return result. + return result; + } +#ifdef __cplusplus +} // End of extern C. +#endif + From 9dfbcb97167c0b4394b1a6795de30d011818a21f Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 21:20:10 -0400 Subject: [PATCH 008/134] MSVC Compile Fix This commit is a compile fix for Dynamic_Library_Subsystem.h under MSVC. (Fake bool header.) --- .../Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h index 7042a1e..d972e8f 100644 --- a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h +++ b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h @@ -22,7 +22,12 @@ #ifndef MSYS_DYNAMIC_LIBRARY_SUBSYSTEM_H #define MSYS_DYNAMIC_LIBRARY_SUBSYSTEM_H +/* Check for MSVC. */ +#ifdef _MSC_FULL_VER +#include "..\stdbool.h" /* bool. (MSVC is special.) */ +#else #include // bool. +#endif /* _MSC_FULL_VER */ #include // NULL. #include // Malloc. From 2f65d1903ef8bf2f98a52c5552613528a608a684 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Thu, 11 Jun 2015 21:36:39 -0400 Subject: [PATCH 009/134] Fix warnings. This commit fixes the missing const statement from the function arguments for the following functions: Common_Dynamic_Library_Subsystem_Load_Library(), Common_Dynamic_Library_Subsystem_Unload_Library(), and Common_Dynamic_Library_Subsystem_Get_Symbol() in Dynamic_Library_Subsystem_Windows.c. --- .../Dynamic_Library_Subsystem_Windows.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c index 0691225..4e24acc 100644 --- a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c +++ b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Windows.c @@ -25,7 +25,7 @@ // Define extern C. extern "C" { #endif - int Common_Dynamic_Library_Subsystem_Load_Library(const char * pathToLibrary, const bool reloadLibrary, Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib) + int Common_Dynamic_Library_Subsystem_Load_Library(const char * pathToLibrary, const bool reloadLibrary, Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib) { // Init vars. int result = 0; // The result of this function. @@ -109,7 +109,7 @@ extern "C" { return result; } - int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib) + int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib) { // Init vars. int result = 0; // The result of this function. @@ -157,7 +157,7 @@ extern "C" { return result; } - void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib, const char * symbolName) + void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib, const char * symbolName) { // Init vars. void * result = NULL; // The result of this function. From 22f6a9f111db98f135d8d1310072a037a16ae640 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 11:56:27 -0400 Subject: [PATCH 010/134] Add DLL exports for MSVC to Error Handler Structures. This commit adds the needed MSYS_DLL_EXPORT declarations for the functions in Common_Error_Handler_Structures.h. --- .../Error_Handler/Common_Error_Handler_Structures.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h index 92a5b06..e24c2cf 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h @@ -93,14 +93,14 @@ extern "C" { * * Returns the API version number of the common error table. */ -const unsigned int Common_Get_Error_Table_API_Version(); +MSYS_DLL_EXPORT const unsigned int Common_Get_Error_Table_API_Version(); /*! * const unsigned int Common_Get_Error_Table_Size() * * Returns the size of the common error table. */ -const unsigned int Common_Get_Error_Table_Size(); +MSYS_DLL_EXPORT const unsigned int Common_Get_Error_Table_Size(); /*! * const char * Common_Get_Error_Message(const int & errorCode) @@ -111,7 +111,7 @@ const unsigned int Common_Get_Error_Table_Size(); * Returns a valid pointer if the given error code is in the common error table. * Returns the message for Common_COMMON_UNKNOWN_ERROR otherwise. */ -const char * Common_Get_Error_Message(const int errorCode); +MSYS_DLL_EXPORT const char * Common_Get_Error_Message(const int errorCode); /* End C Linkage if needed. */ #ifdef __cplusplus @@ -130,7 +130,7 @@ namespace Common * * Returns the API version number of the common error table. */ - const unsigned int Get_Error_Table_API_Version(); + MSYS_DLL_EXPORT const unsigned int Get_Error_Table_API_Version(); /*! * const unsigned int Common::Get_Error_Table_Size() @@ -139,7 +139,7 @@ namespace Common * * Returns the size of the common error table. */ - const unsigned int Get_Error_Table_Size(); + MSYS_DLL_EXPORT const unsigned int Get_Error_Table_Size(); /*! * const char * Common::Get_Error_Message(const int & errorCode) @@ -152,7 +152,7 @@ namespace Common * Returns a valid pointer if the given error code is in the common error table. * Returns the message for Common_COMMON_UNKNOWN_ERROR otherwise. */ - const char * Get_Error_Message(const int & errorCode); + MSYS_DLL_EXPORT const char * Get_Error_Message(const int & errorCode); }; #endif /* __cplusplus */ From a383b713458fc257102beee2e3be734ec3eab8ed Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 12:04:13 -0400 Subject: [PATCH 011/134] Fix missing link libraries for Common Error Handler. This commit fixes the CMakeLists.txt for Common Error Handler to include the needed link libraries. (A.K.A. Internal Mutex Support for Fatal Error Support.) --- src/Common/Src/Error_Handler/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Common/Src/Error_Handler/CMakeLists.txt b/src/Common/Src/Error_Handler/CMakeLists.txt index 73a53f6..30966b5 100644 --- a/src/Common/Src/Error_Handler/CMakeLists.txt +++ b/src/Common/Src/Error_Handler/CMakeLists.txt @@ -43,7 +43,9 @@ endif(${CMAKE_COMPILER_IS_GNUCC}) # Create the static library. add_library(Common_Error_Handler_Multiverse_Engine_Static STATIC ${COMMON_ERROR_HANDLER_C_INCLUDES} ${COMMON_ERROR_HANDLER_CXX_INCLUDES}) set_property(TARGET Common_Error_Handler_Multiverse_Engine_Static APPEND PROPERTY COMPILE_DEFINITIONS ${COMMON_ERROR_HANDLER_DEFINES}) +target_link_libraries(Common_Error_Handler_Multiverse_Engine_Static ${COMMON_ERROR_HANDLER_STATIC_LINK_LIBS}) # Now the shared library. add_library(Common_Error_Handler_Multiverse_Engine SHARED ${COMMON_ERROR_HANDLER_C_INCLUDES} ${COMMON_ERROR_HANDLER_CXX_INCLUDES}) set_property(TARGET Common_Error_Handler_Multiverse_Engine_Static APPEND PROPERTY COMPILE_DEFINITIONS ${COMMON_ERROR_HANDLER_DEFINES}) +target_link_libraries(Common_Error_Handler_Multiverse_Engine ${COMMON_ERROR_HANDLER_LINK_LIBS}) From f3294ea925fbdfa7871966c85e7889eeaa109d92 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 12:28:39 -0400 Subject: [PATCH 012/134] Define DLL exports for Dynamic Library Subsystem This commit defines the needed DLL exports for the Dynamic Library Subsystem. --- .../Dynamic_Library_Subsystem.h | 11 +++++++---- .../Dynamic_Library_Subsystem_Data_Structures.h | 4 ++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h index d972e8f..8a03248 100644 --- a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h +++ b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem.h @@ -22,6 +22,9 @@ #ifndef MSYS_DYNAMIC_LIBRARY_SUBSYSTEM_H #define MSYS_DYNAMIC_LIBRARY_SUBSYSTEM_H +/* Internal includes. */ +#include "../../../DLL_PORT.h" /* Defines MSYS_DLL_EXPORT, and MSYS_DLL_IMPORT_TEMPLATE. */ + /* Check for MSVC. */ #ifdef _MSC_FULL_VER #include "..\stdbool.h" /* bool. (MSVC is special.) */ @@ -72,8 +75,8 @@ extern "C" { * Returns -4 if the given Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library pointer was NULL. * Returns 1 if the library was already loaded. (Only possible if reloadLibrary is false.) (The value of lib.bLastCallEncounteredAnError will be false in this case as well.) */ - int Common_Dynamic_Library_Subsystem_Load_Library(const char * pathToLibrary, const bool reloadLibrary, - Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib); + MSYS_DLL_EXPORT int Common_Dynamic_Library_Subsystem_Load_Library(const char * pathToLibrary, const bool reloadLibrary, + Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib); /*! * int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib) @@ -101,7 +104,7 @@ extern "C" { * Returns -2 if the library unload call returned unsuccessful. * Returns -4 if the given Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library pointer was NULL. */ - int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib); + MSYS_DLL_EXPORT int Common_Dynamic_Library_Subsystem_Unload_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib); /*! * void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib, @@ -126,7 +129,7 @@ extern "C" { * Returns a NULL pointer if the lookup failed for some reason. (The value of lib.bLastCallEncounteredAnError will be true in this case.) * Returns a NULL pointer if the given Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library pointer was NULL. */ - void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib, const char * symbolName); + MSYS_DLL_EXPORT void * Common_Dynamic_Library_Subsystem_Get_Symbol(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library *const lib, const char * symbolName); #ifdef __cplusplus } // End of extern C. #endif diff --git a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Data_Structures.h b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Data_Structures.h index f5beb16..1273b4f 100644 --- a/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Data_Structures.h +++ b/src/Common/Src/Dynamic_Library_Subsystem/Dynamic_Library_Subsystem_Data_Structures.h @@ -65,7 +65,7 @@ extern "C" { * Returns a pointer to a Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library data structure if successful. * Otherwise returns NULL. */ - Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * Common_Dynamic_Library_Subsystem_Create_Loaded_Dynamic_Library(); + MSYS_DLL_EXPORT Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * Common_Dynamic_Library_Subsystem_Create_Loaded_Dynamic_Library(); /*! * void Common_Dynamic_Library_Subsystem_Destroy_Loaded_Dynamic_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib) @@ -77,7 +77,7 @@ extern "C" { * * This function has no return. */ - void Common_Dynamic_Library_Subsystem_Destroy_Loaded_Dynamic_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib); + MSYS_DLL_EXPORT void Common_Dynamic_Library_Subsystem_Destroy_Loaded_Dynamic_Library(Common_Dynamic_Library_Subsystem_Loaded_Dynamic_Library * lib); #ifdef __cplusplus } // End of extern C. #endif From 63b9628006e2462d4ad609abaf06637f02128c79 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:05:41 -0400 Subject: [PATCH 013/134] Inital commit to the Byte_Order branch This commit is the initial commit to the Byte_Order branch. --- src/Common/Src/Byte_Order.c | 251 ++++ src/Common/Src/Byte_Order.h | 142 ++ src/Common/Src/Byte_Order_Floating_Points.c | 281 ++++ src/Common/Src/Byte_Order_Floating_Points.h | 176 +++ src/Common/Src/Byte_Order_Integers.c | 1340 +++++++++++++++++++ src/Common/Src/Byte_Order_Integers.h | 752 +++++++++++ 6 files changed, 2942 insertions(+) create mode 100644 src/Common/Src/Byte_Order.c create mode 100644 src/Common/Src/Byte_Order.h create mode 100644 src/Common/Src/Byte_Order_Floating_Points.c create mode 100644 src/Common/Src/Byte_Order_Floating_Points.h create mode 100644 src/Common/Src/Byte_Order_Integers.c create mode 100644 src/Common/Src/Byte_Order_Integers.h diff --git a/src/Common/Src/Byte_Order.c b/src/Common/Src/Byte_Order.c new file mode 100644 index 0000000..9246a9c --- /dev/null +++ b/src/Common/Src/Byte_Order.c @@ -0,0 +1,251 @@ +/*! + Multiverse Engine Project 03/6/2015 Common Byte_Order.c + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include header */ +#include "Byte_Order.h" + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int Common_Byte_Swap(char * data, const size_t dataLength) +{ + /* Init ret. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + size_t x = 0; /* Counter used in the swap loop. */ + char tempByte = '\0'; /* Temporary memory storage for a byte being swapped out. */ + + /* Check for invalid arguments. */ + if ((data != NULL) && ((dataLength % 2) == 0)) + { + /* Begin swap loop. */ + for (x = 0; (x < (dataLength / 2)); x++) + { + /* + * Each bit is swapped with it's partner on the other side of the array. + * I.e. Each byte from x distance from the start of the array is swapped + * with the byte x distance from the end of the array. + */ + tempByte = data[x]; + data[x] = data[((dataLength - 1) - x)]; + data[((dataLength - 1) - x)] = tempByte; + } + + /* Done! */ + ret = COMMON_ERROR_SUCCESS; + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + + /* Exit function. */ + return ret; +} + +int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + size_t x = 0; /* Counter used in the print and spacing loops. */ + size_t byteValueCount = 0; /* Used to keep track of how many bytes we have outputted for the current byte. */ + unsigned char currentByte = '\0'; /* Temporary value used to store the current byte we are working on. */ + char outputValue = '\0'; /* The value that we need to write into the output buffer. (Calculated from currentValue.) */ + char * outputBuffer = NULL; /* Pointer to the c-string that will be outputted to the standard output. */ + char * previousOutputBuffer = NULL; /* Temporary pointer used to copy previously generated data into the current outputBuffer. */ + const char outputValues[17] = "0123456789ABCDEF"; /* C-String used to map a generated value to it's corrosponding character. */ + size_t outputBufferSize = 1; /* Current size of the outputBuffer. Set to one by default to allow the string to be NULL terminated. */ + + /* Check for invalid arguments. */ + if ((data != NULL) && (dataLength > 0) && (retStr != NULL) && (retStrSize != NULL) && (base >= 2) && (base <= 16)) + { + /* Begin data print loop. */ + for (x = 0; ((x < dataLength) && (ret != COMMON_ERROR_MEMORY_ERROR)); x++) + { + /* Copy current value. */ + currentByte = data[((dataLength - 1) - x)]; + + /* Reset byte value count. */ + byteValueCount = 0; + + /* Begin value parsing loop. */ + do + { + /* Read the current byte's value from right to left. (Mod is a reduction operation.) */ + outputValue = (currentByte % base); + + /* Copy the current buffer's pointer because we are about to create a new one. */ + previousOutputBuffer = outputBuffer; + + /* Increment the size of the new buffer. */ + outputBufferSize++; + + /* Allocate the new buffer. */ + outputBuffer = (char*)malloc(outputBufferSize); + + /* Check for successful memory allocation. */ + if (outputBuffer != NULL) + { + /* Blank out the new buffer. */ + memset(outputBuffer, '\0', outputBufferSize); + + /* Set the first value as the previous data comes after it. */ + outputBuffer[0] = outputValues[outputValue]; + + /* If we have any previous data we need to copy it into the new buffer and deallocate the previous one. */ + if (previousOutputBuffer != NULL) + { + memcpy((outputBuffer + 1), previousOutputBuffer, (outputBufferSize - 1)); + free(previousOutputBuffer); + previousOutputBuffer = NULL; + } + + /* Increment byte value count. */ + byteValueCount++; + + /* Get the next value by choping off the "ones place", aka devide by the current base. */ + currentByte /= base; + } + else + { + /* Could not allocate memory for output buffer. */ + ret = COMMON_ERROR_MEMORY_ERROR; + } + }while ((currentByte) && (ret != COMMON_ERROR_MEMORY_ERROR)); + + /* Check and see if the generated values used up all of the requested width. */ + if ((ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && (byteValueCount < width)) + { + /* Copy the current buffer's pointer because we are about to create a new one. */ + previousOutputBuffer = outputBuffer; + + /* Increment the output buffer size by the remaining filler we need to add. */ + outputBufferSize += (width - byteValueCount); + + /* Allocate the new buffer. */ + outputBuffer = (char*)malloc(outputBufferSize); + + /* Check for successful memory allocation. */ + if (outputBuffer != NULL) + { + /* Blank out the new buffer. */ + memset(outputBuffer, '\0', outputBufferSize); + + /* Put in our filler. */ + memset(outputBuffer, fillValue, (width - byteValueCount)); + + /* If we have any previous data we need to copy it into the new buffer and deallocate the previous one. */ + if (previousOutputBuffer != NULL) + { + memcpy((outputBuffer + (width - byteValueCount)), previousOutputBuffer, (outputBufferSize - (width - byteValueCount))); + free(previousOutputBuffer); + previousOutputBuffer = NULL; + } + } + else + { + /* Could not allocate memory for output buffer. */ + ret = COMMON_ERROR_MEMORY_ERROR; + } + } + + /* Insert spacing if needed. */ + if ((spaceBetweenBytes) && (ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && ((x + 1) < dataLength)) + { + /* Copy the current buffer's pointer because we are about to create a new one. */ + previousOutputBuffer = outputBuffer; + + /* Increment the output buffer size. */ + outputBufferSize++; + + /* Allocate the new buffer. */ + outputBuffer = (char*)malloc(outputBufferSize); + + /* Check for successful memory allocation. */ + if (outputBuffer != NULL) + { + /* Blank out the new buffer. */ + memset(outputBuffer, '\0', outputBufferSize); + + /* Insert our space. */ + outputBuffer[0] = ' '; + + /* Copy the original buffer. */ + memcpy((outputBuffer + 1), previousOutputBuffer, (outputBufferSize - 1)); + } + else + { + /* Could not allocate memory for output buffer. */ + ret = COMMON_ERROR_MEMORY_ERROR; + } + } + } + + /* Check for NULL output buffer. */ + if ((ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && (outputBufferSize > 0)) + { + /* Copy the outputBuffer pointer to retStr. */ + (*retStr) = outputBuffer; + + /* Copy outputBufferSize to retStrSize. */ + (*retStrSize) = outputBufferSize; + + /* Done! */ + ret = COMMON_ERROR_SUCCESS; + } + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + + /* Exit function. */ + return ret; +} + +void Common_Deallocate_Print_Bytes_CString(char ** str) +{ + /* Check for NULL. */ + if (str != NULL) + { + free((*str)); + (*str) = NULL; + } + + /* Exit function. */ + return; +} + +int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes) +{ + return Common_Print_Bytes_To_CString(data, dataLength, retStr, retStrSize, 16, 2, '0', spaceBetweenBytes); +} + +int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes) +{ + return Common_Print_Bytes_To_CString(data, dataLength, retStr, retStrSize, 2, 8, '0', spaceBetweenBytes); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ diff --git a/src/Common/Src/Byte_Order.h b/src/Common/Src/Byte_Order.h new file mode 100644 index 0000000..1a1837d --- /dev/null +++ b/src/Common/Src/Byte_Order.h @@ -0,0 +1,142 @@ +/*! + Multiverse Engine Project 03/6/2015 Common Byte_Order.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef MSYS_BYTE_ORDER_H +#define MSYS_BYTE_ORDER_H + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Define Endianness Result Values. */ +#define MSYS_BIG_ENDIAN 0 +#define MSYS_LITTLE_ENDIAN 1 +#define MSYS_UNKNOWN_ENDIANNESS 2 + +/* Internal headers. */ +#include "Byte_Order_Integers.h" +#include "Byte_Order_Floating_Points.h" + +/*! + * int Common_Byte_Swap(char * data, const size_t dataLength) + * + * Swaps the given bytes by swapping each byte + * with it's complement on the other end of the + * byte string. + * + * I.e. Each byte from x distance from the start of the string is swapped + * with the byte x distance from the end of the string. + * + * Note: This function expects that the amount of data given to it + * is a multiple of 2. Also this function will alter the given + * data in-place. (I.e. If an error occurs, the data WILL be altered.) + * + * Returns COMMON_ERROR_SUCCESS if swapping was successful. + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is + * NULL, or if the data length is not a multiple of 2. + * + * Otherwise returns the appropriate error code. + */ +int Common_Byte_Swap(char * data, const size_t dataLength); + +/*! + * int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, + * const size_t width, const char fillValue, const bool spaceBetweenBytes) + * + * Converts a given byte string to a printable (NULL-terminated) and human-readable string in the given base. + * + * @pram data: the byte string to convert. + * @pram dataLength: the length of the byte string. + * @pram retStr: a double pointer that will point to the converted string. + * @pram retStrSize: the size of the generated string. + * @pram base: the numerical base to convert each byte to. + * + * @pram width: the minimal number of values to print for each byte. (Note the minimal keyword. The value will not be truncated if it + * requires more than width characters to represent it. This is solely to make smaller values take up more space for more uniform value + * representation.) + * + * @pram fillValue: the value printed in the converted string to take up the extra space, when a byte's value representation is smaller + * than the given width. (E.x. the byte value is 0, width is 3, and fillValue is '.': "..0" would be the result.) + * + * @pram spaceBetweenBytes: Whether or not to insert a space character after each of the converted byte values. (Readability.) + * + * WARNING: If retStr is non-NULL when this function is called, and this function returns COMMON_ERROR_SUCCESS, then the pointer will + * be overwritten without being deallocated. If you need that pointer to deallocate it later, you should copy it elsewhere before calling + * this function. + * + * Note: To deallocate the returned string from this function, pass the returned string to Common_Deallocate_Print_Bytes_CString(). + * + * Returns COMMON_ERROR_SUCCESS if the conversion is successful. + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointers are NULL, or if the given base is not a value between 2 and 16. + * Returns COMMON_ERROR_MEMORY_ERROR if a memory allocation fails. + * + * In case of error, (the returned error code is not COMMON_ERROR_SUCCESS, then the given arguments will NOT be altered by this function. + */ +int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes); + +/*! + * void Common_Deallocate_Print_Bytes_CString(char ** str) + * + * Deallocates the given c-string and sets the given pointer to char to NULL. + * + * Note: This function is a destructor function for strings made by Common_Print_Bytes_To_CString() and + * should ONLY be used for that purpose. The behaviour for using this function to deallocate other allocations is undefined. + * + * This function has no return. If a given pointer is NULL, this function will silently fail. + */ +void Common_Deallocate_Print_Bytes_CString(char ** str); + +/*! + * int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes) + * + * Wrapper function around Common_Print_Bytes_To_CString() for converting a byte string to a human-readable hexadecimal string. + * Example output: ("001FAC" if spacing is disabled, "00 1F AC" if spacing is enabled.) + * + * Note: This function is to make calls shorter, if you want more control over the output, call Common_Print_Bytes_To_CString() directly. + * + * All arguments and return values are identical to their Common_Print_Bytes_To_CString() counterparts. See Common_Print_Bytes_To_CString() + * for their descriptions. + */ +int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); + +/*! + * int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, + * const bool spaceBetweenBytes) + * + * Wrapper function around Common_Print_Bytes_To_CString() for converting a byte string to a human-readable binary string. + * Example output: ("00000101000001010000010100000101" if spacing is disabled, "00000101 00000101 00000101 00000101" if spacing is enabled.) + * + * Note: This function is to make calls shorter, if you want more control over the output, call Common_Print_Bytes_To_CString() directly. + * + * All arguments and return values are identical to their Common_Print_Bytes_To_CString() counterparts. See Common_Print_Bytes_To_CString() + * for their descriptions. + */ +int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* MSYS_BYTE_ORDER_H */ + +/* End of Byte_Order.h */ diff --git a/src/Common/Src/Byte_Order_Floating_Points.c b/src/Common/Src/Byte_Order_Floating_Points.c new file mode 100644 index 0000000..c6dabe1 --- /dev/null +++ b/src/Common/Src/Byte_Order_Floating_Points.c @@ -0,0 +1,281 @@ +/*! + Multiverse Engine Project 09/6/2015 Common Byte_Order_Floating_Points.c + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include main header. */ +#include "Byte_Order.h" + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int Common_Host_To_Big_Endian_Float(float * f) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_FLOAT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (f != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)f), sizeof (float)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Float(float * f) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_FLOAT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (f != NULL) + { + /* + * Call Common_Byte_Swap(). + * + * (We could call Common_Host_To_Big_Endian_Float() here, but + * that would just repeat the calls above. Plus we may not be able + * to do that on all systems.) + */ + ret = Common_Byte_Swap(((char*)f), sizeof (float)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Double(double * d) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_DOUBLE_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (d != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)d), sizeof (double)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Double(double * d) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_DOUBLE_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (d != NULL) + { + /* + * Call Common_Byte_Swap(). + * + * (We could call Common_Host_To_Big_Endian_Double() here, but + * that would just repeat the calls above. Plus we may not be able + * to do that on all systems.) + */ + ret = Common_Byte_Swap(((char*)d), sizeof (double)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_FLOAT_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + float t = 1.0; /* Variable to check. */ + + /* Cast t to a char string and see if the first 2 values are 0x3F80. */ + if ((((char*)&t)[0] == 0x3F) && ((((char*)&t)[1] == 0x80))) + { + /* The first 2 bytes are 0x3F80 so it's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + else + { + /* + * The first check did not pass, so check and see if the last 2 bytes are 0x803F. + * If they are, then the host is little endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if ((((char*)&t)[(sizeof (float) - 1)] == 0x80) && ((((char*)&t)[(sizeof (float) - 2)] == 0x3F))) + { + /* It's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_DOUBLE_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + double t = 1.0; /* Variable to check. */ + + /* Cast t to a char string and see if the first 2 values are 0x3FF0. */ + if ((((char*)&t)[0] == 0x3F) && ((((char*)&t)[1] == 0xF0))) + { + /* The first 2 bytes are 0x3F80 so it's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + else + { + /* + * The first check did not pass, so check and see if the last 2 bytes are 0xF03F. + * If they are, then the host is little endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if ((((char*)&t)[(sizeof (double) - 1)] == 0xF0) && ((((char*)&t)[(sizeof (double) - 2)] == 0x3F))) + { + /* It's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ diff --git a/src/Common/Src/Byte_Order_Floating_Points.h b/src/Common/Src/Byte_Order_Floating_Points.h new file mode 100644 index 0000000..394abcb --- /dev/null +++ b/src/Common/Src/Byte_Order_Floating_Points.h @@ -0,0 +1,176 @@ +/*! + Multiverse Engine Project 09/6/2015 Common Byte_Order_Floating_Points.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef MSYS_BYTE_ORDER_FLAOTING_POINTS_H +#define MSYS_BYTE_ORDER_FLAOTING_POINTS_H + +/* Make sure we are not included directly. */ +#ifndef MSYS_BYTE_ORDER_H +#error "You should not include __FILE__ directly, it is included automatically by Byte_Order.h, remove this include. Aborting build." +#endif + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/*! + * int Common_Host_To_Big_Endian_Float(float * f) + * + * Converts a given FLOAT value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Float(float * f); + +/*! + * int Common_Big_Endian_To_Host_Float(float * f) + * + * Converts a given FLOAT value from Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Float(float * f); + +/*! + * int Common_Host_To_Big_Endian_DOUBLE(double * d) + * + * Converts a given DOUBLE value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Double(double * d); + +/*! + * int Common_Big_Endian_To_Host_Double(double * d) + * + * Converts a given DOUBLE value from Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Double(double * d); + +/*! + * General Definitions for the Common_*_Endianness_Check() functions: + * + * The functions below all contain the same returns, + * and purpose. + */ + +/*! + * int Common_FLOAT_Endianness_Check() + * + * Template function which checks the host's endianness for the + * FLOAT data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a signed FLOAT argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_FLOAT_Endianness_Check(); + +/*! + * int Common_DOUBLE_Endianness_Check() + * + * Template function which checks the host's endianness for the + * DOUBLE data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a signed DOUBLE argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_DOUBLE_Endianness_Check(); + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* MSYS_BYTE_ORDER_FLAOTING_POINTS_H */ + +/* End of Byte_Order_Floating_Points.h */ diff --git a/src/Common/Src/Byte_Order_Integers.c b/src/Common/Src/Byte_Order_Integers.c new file mode 100644 index 0000000..6d0149d --- /dev/null +++ b/src/Common/Src/Byte_Order_Integers.c @@ -0,0 +1,1340 @@ +/*! + Multiverse Engine Project 09/6/2015 Common Byte_Order_Integers.c + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include main header. */ +#include "Byte_Order.h" + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +int Common_Host_To_Big_Endian_UChar(unsigned char * uc) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_UCHAR_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (uc != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)uc), sizeof (unsigned char)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_UChar(unsigned char * uc) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_UCHAR_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (uc != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)uc), sizeof (unsigned char)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Char(char * c) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_CHAR_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (c != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)c), sizeof (char)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Char(char * c) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_CHAR_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (c != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)c), sizeof (char)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_UShort(unsigned short * us) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_USHORT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (us != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)us), sizeof (unsigned short)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_UShort(unsigned short * us) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_USHORT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (us != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)us), sizeof (unsigned short)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Short(short * s) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_SHORT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (s != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)s), sizeof (short)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Short(short * s) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_SHORT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (s != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)s), sizeof (short)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_UInt(unsigned int * ui) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_UINT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ui != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ui), sizeof (unsigned int)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_UInt(unsigned int * ui) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_UINT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ui != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ui), sizeof (unsigned int)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Int(int * i) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_INT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (i != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)i), sizeof (int)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Int(int * i) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_INT_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (i != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)i), sizeof (int)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_ULong(unsigned long * ul) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_ULONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ul != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ul), sizeof (unsigned long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_ULong(unsigned long * ul) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_ULONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ul != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ul), sizeof (unsigned long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Long(long * l) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (l != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)l), sizeof (long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Long(long * l) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (l != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)l), sizeof (long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_ULONG_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ull != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ull), sizeof (unsigned long long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_ULONG_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ull != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ull), sizeof (unsigned long long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Long_Long(long long * ll) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_LONG_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ll != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ll), sizeof (long long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Long_Long(long long * ll) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_LONG_LONG_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (ll != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)ll), sizeof (long long)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Host_To_Big_Endian_Size_T(size_t * st) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_SIZE_T_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (st != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)st), sizeof (size_t)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_Big_Endian_To_Host_Size_T(size_t * st) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + + /* Check host's endianness. */ + ret = Common_SIZE_T_Endianness_Check(); + if (ret != MSYS_BIG_ENDIAN) + { + /* Check for valid endianness. */ + if (ret == MSYS_LITTLE_ENDIAN) + { + /* Check for invalid arguments. */ + if (st != NULL) + { + /* Call Common_Byte_Swap(). */ + ret = Common_Byte_Swap(((char*)st), sizeof (size_t)); + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + } + else + { + /* Host endianness is unknown. Cannot convert unknown endianness. */ + ret = COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED; + } + } + else + { + /* + * This value should already be in the correct byte order, + * as the host is big endian. + */ + ret = COMMON_ERROR_SUCCESS; + } + + /* Exit function. */ + return ret; +} + +int Common_UCHAR_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + unsigned char t = '\1'; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_CHAR_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + char t = '\1'; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_USHORT_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + unsigned short t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_SHORT_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + short t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_UINT_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + unsigned int t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_INT_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + int t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_ULONG_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + unsigned long t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_LONG_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + long t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_ULONG_LONG_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + unsigned long long t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_LONG_LONG_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + long long t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +int Common_SIZE_T_Endianness_Check() +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + size_t t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ diff --git a/src/Common/Src/Byte_Order_Integers.h b/src/Common/Src/Byte_Order_Integers.h new file mode 100644 index 0000000..429a5ab --- /dev/null +++ b/src/Common/Src/Byte_Order_Integers.h @@ -0,0 +1,752 @@ +/*! + Multiverse Engine Project 09/6/2015 Common Byte_Order_Integers.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef MSYS_BYTE_ORDER_INTEGERS_H +#define MSYS_BYTE_ORDER_INTEGERS_H + +/* Make sure we are not included directly. */ +#ifndef MSYS_BYTE_ORDER_H +#error "You should not include __FILE__ directly, it is included automaticly by Byte_Order.h, remove this include. Aborting build." +#endif + +/* Check for C++ compiler. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/*! + * int Common_Host_To_Big_Endian_UChar(unsigned char * uc) + * + * Converts a given unsigned CHAR value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_UChar(unsigned char * uc); + +/*! + * int Common_Big_Endian_To_Host_UChar(unsigned char * uc) + * + * Converts a given unsigned CHAR value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_UChar(unsigned char * uc); + +/*! + * int Common_Host_To_Big_Endian_Char(char * c) + * + * Converts a given CHAR value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Char(char * c); + +/*! + * int Common_Big_Endian_To_Host_Char(char * c) + * + * Converts a given CHAR value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Char(char * c); + +/*! + * int Common_Host_To_Big_Endian_UShort(unsigned short * us) + * + * Converts a given unsigned SHORT value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_UShort(unsigned short * us); + +/*! + * int Common_Big_Endian_To_Host_UShort(unsigned short * us) + * + * Converts a given unsigned SHORT value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_UShort(unsigned short * us); + +/*! + * int Common_Host_To_Big_Endian_Short(short * s) + * + * Converts a given SHORT value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Short(short * s); + +/*! + * int Common_Big_Endian_To_Host_Short(short * s) + * + * Converts a given SHORT value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Short(short * s); + +/*! + * int Common_Host_To_Big_Endian_UInt(unsigned int * ui) + * + * Converts a given unsigned INT value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_UInt(unsigned int * ui); + +/*! + * int Common_Big_Endian_To_Host_UInt(unsigned int * ui) + * + * Converts a given unsigned INT value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_UInt(unsigned int * ui); + +/*! + * int Common_Host_To_Big_Endian_Int(int * i) + * + * Converts a given INT value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Int(int * i); + +/*! + * int Common_Big_Endian_To_Host_Int(int * i) + * + * Converts a given INT value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Int(int * i); + +/*! + * int Common_Host_To_Big_Endian_ULong(unsigned long * ul) + * + * Converts a given unsigned LONG value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_ULong(unsigned long * ul); + +/*! + * int Common_Big_Endian_To_Host_ULong(unsigned long * ul) + * + * Converts a given unsigned LONG value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_ULong(unsigned long * ul); + +/*! + * int Common_Host_To_Big_Endian_Long(long * l) + * + * Converts a given LONG value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Long(long * l); + +/*! + * int Common_Big_Endian_To_Host_Long(long * l) + * + * Converts a given LONG value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Long(long * l); + +/*! + * int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull) + * + * Converts a given unsigned LONG LONG value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull); + +/*! + * int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull) + * + * Converts a given unsigned LONG LONG value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull); + +/*! + * int Common_Host_To_Big_Endian_Long_Long(long long * ull) + * + * Converts a given LONG LONG value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Long_Long(long long * ll); + +/*! + * int Common_Big_Endian_To_Host_Long_Long(long long * ll) + * + * Converts a given LONG LONG value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Long_Long(long long * ll); + +/*! + * int Common_Host_To_Big_Endian_Size_T(size_t * st) + * + * Converts a given SIZE_T value from the host's endianness + * to Big Endian format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Host_To_Big_Endian_Size_T(size_t * st); + +/*! + * int Common_Big_Endian_To_Host_Size_T(size_t * st) + * + * Converts a given SIZE_T value from the Big Endian format + * to the host's endianness format. + * + * Returns COMMON_ERROR_SUCCESS, if the conversion is successful, + * (data will be converted after call returns), + * or if the host is a Big Endian host. (In such case no data alteration + * is performed.) + * + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer is NULL. + * + * Returns COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED if the given data type's + * byte ordering is unknown for the given host. + * + * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), + * all arguments will be left unaltered. + */ +int Common_Big_Endian_To_Host_Size_T(size_t * st); + +/*! + * General Definitions for the Common_*_Endianness_Check() functions: + * + * The functions below all contain the same returns, + * and purpose. + */ + +/*! + * int Common_UCHAR_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a unsigned CHAR argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_UCHAR_Endianness_Check(); + +/*! + * int Common_CHAR_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a CHAR argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_CHAR_Endianness_Check(); + +/*! + * int Common_USHORT_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a unsigned SHORT argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_USHORT_Endianness_Check(); + +/*! + * int Common_SHORT_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a SHORT argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_SHORT_Endianness_Check(); + +/*! + * int Common_UINT_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a unsigned INT argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_UINT_Endianness_Check(); + +/*! + * int Common_INT_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a INT argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_INT_Endianness_Check(); + +/*! + * int Common_ULONG_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a unsigned LONG argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_ULONG_Endianness_Check(); + +/*! + * int Common_LONG_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a LONG argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_LONG_Endianness_Check(); + +/*! + * int Common_ULONG_LONG_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a unsigned LONG LONG argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_ULONG_LONG_Endianness_Check(); + +/*! + * int Common_LONG_LONG_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a LONG LONG argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_LONG_LONG_Endianness_Check(); + +/*! + * int Common_SIZE_T_Endianness_Check() + * + * Template function which checks the host's endianness for the + * UCHAR data type. + * + * Note: This function is the equivalent of calling + * DataProcess_Endianness_Check() with a SIZE_T argument. + * This function is here for the purpose of making it easier + * to use C code. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +int Common_SIZE_T_Endianness_Check(); + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* MSYS_BYTE_ORDER_INTEGERS_H */ + +/* End of Byte_Order_Integers.h */ From 7087d90bd49cb1a640d5a6d2c776b91e8481eeeb Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:29:59 -0400 Subject: [PATCH 014/134] Move Byte_Order*.* files to their own folder. This commit moves the Byte_Order*.* files to their own folder. --- src/Common/Src/{ => Byte_Order}/Byte_Order.c | 0 src/Common/Src/{ => Byte_Order}/Byte_Order.h | 0 src/Common/Src/{ => Byte_Order}/Byte_Order_Floating_Points.c | 0 src/Common/Src/{ => Byte_Order}/Byte_Order_Floating_Points.h | 0 src/Common/Src/{ => Byte_Order}/Byte_Order_Integers.c | 0 src/Common/Src/{ => Byte_Order}/Byte_Order_Integers.h | 0 6 files changed, 0 insertions(+), 0 deletions(-) rename src/Common/Src/{ => Byte_Order}/Byte_Order.c (100%) rename src/Common/Src/{ => Byte_Order}/Byte_Order.h (100%) rename src/Common/Src/{ => Byte_Order}/Byte_Order_Floating_Points.c (100%) rename src/Common/Src/{ => Byte_Order}/Byte_Order_Floating_Points.h (100%) rename src/Common/Src/{ => Byte_Order}/Byte_Order_Integers.c (100%) rename src/Common/Src/{ => Byte_Order}/Byte_Order_Integers.h (100%) diff --git a/src/Common/Src/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c similarity index 100% rename from src/Common/Src/Byte_Order.c rename to src/Common/Src/Byte_Order/Byte_Order.c diff --git a/src/Common/Src/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h similarity index 100% rename from src/Common/Src/Byte_Order.h rename to src/Common/Src/Byte_Order/Byte_Order.h diff --git a/src/Common/Src/Byte_Order_Floating_Points.c b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c similarity index 100% rename from src/Common/Src/Byte_Order_Floating_Points.c rename to src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c diff --git a/src/Common/Src/Byte_Order_Floating_Points.h b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h similarity index 100% rename from src/Common/Src/Byte_Order_Floating_Points.h rename to src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h diff --git a/src/Common/Src/Byte_Order_Integers.c b/src/Common/Src/Byte_Order/Byte_Order_Integers.c similarity index 100% rename from src/Common/Src/Byte_Order_Integers.c rename to src/Common/Src/Byte_Order/Byte_Order_Integers.c diff --git a/src/Common/Src/Byte_Order_Integers.h b/src/Common/Src/Byte_Order/Byte_Order_Integers.h similarity index 100% rename from src/Common/Src/Byte_Order_Integers.h rename to src/Common/Src/Byte_Order/Byte_Order_Integers.h From 86782e35e1622dcad03e45e773f26139ff6b8b86 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:32:17 -0400 Subject: [PATCH 015/134] Fix comments. This commit is a comment change commit for Byte_Order*.c files. (No code change.) --- src/Common/Src/Byte_Order/Byte_Order.c | 2 +- src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c | 2 +- src/Common/Src/Byte_Order/Byte_Order_Integers.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Common/Src/Byte_Order/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c index 9246a9c..3323cfc 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.c +++ b/src/Common/Src/Byte_Order/Byte_Order.c @@ -18,7 +18,7 @@ https://github.com/codebase7/mengine */ -/* Include header */ +/* Internal includes. */ #include "Byte_Order.h" /* Check for C++ compiler. */ diff --git a/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c index c6dabe1..45d40f9 100644 --- a/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c +++ b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.c @@ -18,7 +18,7 @@ https://github.com/codebase7/mengine */ -/* Include main header. */ +/* Internal includes. */ #include "Byte_Order.h" /* Check for C++ compiler. */ diff --git a/src/Common/Src/Byte_Order/Byte_Order_Integers.c b/src/Common/Src/Byte_Order/Byte_Order_Integers.c index 6d0149d..263e952 100644 --- a/src/Common/Src/Byte_Order/Byte_Order_Integers.c +++ b/src/Common/Src/Byte_Order/Byte_Order_Integers.c @@ -18,7 +18,7 @@ https://github.com/codebase7/mengine */ -/* Include main header. */ +/* Internal includes. */ #include "Byte_Order.h" /* Check for C++ compiler. */ From c8fd818195d8081ebea701bc51d3cf81a4f9858c Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:34:26 -0400 Subject: [PATCH 016/134] Add DLL export declarations for Byte_Order This commit adds the DLL exports for Byte_Order. --- src/Common/Src/Byte_Order/Byte_Order.h | 13 ++-- .../Byte_Order/Byte_Order_Floating_Points.h | 12 ++-- .../Src/Byte_Order/Byte_Order_Integers.h | 66 +++++++++---------- 3 files changed, 47 insertions(+), 44 deletions(-) diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index 1a1837d..e9886b9 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -32,6 +32,9 @@ extern "C" { #define MSYS_LITTLE_ENDIAN 1 #define MSYS_UNKNOWN_ENDIANNESS 2 +/* Pull in DLL_PORT.h */ +#include "../../../DLL_PORT.h" /* Defines MSYS_DLL_EXPORT, and MSYS_DLL_IMPORT_TEMPLATE. */ + /* Internal headers. */ #include "Byte_Order_Integers.h" #include "Byte_Order_Floating_Points.h" @@ -57,7 +60,7 @@ extern "C" { * * Otherwise returns the appropriate error code. */ -int Common_Byte_Swap(char * data, const size_t dataLength); +MSYS_DLL_EXPORT int Common_Byte_Swap(char * data, const size_t dataLength); /*! * int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, @@ -92,7 +95,7 @@ int Common_Byte_Swap(char * data, const size_t dataLength); * * In case of error, (the returned error code is not COMMON_ERROR_SUCCESS, then the given arguments will NOT be altered by this function. */ -int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes); +MSYS_DLL_EXPORT int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes); /*! * void Common_Deallocate_Print_Bytes_CString(char ** str) @@ -104,7 +107,7 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch * * This function has no return. If a given pointer is NULL, this function will silently fail. */ -void Common_Deallocate_Print_Bytes_CString(char ** str); +MSYS_DLL_EXPORT void Common_Deallocate_Print_Bytes_CString(char ** str); /*! * int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes) @@ -117,7 +120,7 @@ void Common_Deallocate_Print_Bytes_CString(char ** str); * All arguments and return values are identical to their Common_Print_Bytes_To_CString() counterparts. See Common_Print_Bytes_To_CString() * for their descriptions. */ -int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); +MSYS_DLL_EXPORT int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); /*! * int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, @@ -131,7 +134,7 @@ int Common_Print_Bytes_In_Hex(const char * data, const size_t dataLength, char * * All arguments and return values are identical to their Common_Print_Bytes_To_CString() counterparts. See Common_Print_Bytes_To_CString() * for their descriptions. */ -int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); +MSYS_DLL_EXPORT int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h index 394abcb..8bcd0c5 100644 --- a/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h +++ b/src/Common/Src/Byte_Order/Byte_Order_Floating_Points.h @@ -51,7 +51,7 @@ extern "C" { * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Float(float * f); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Float(float * f); /*! * int Common_Big_Endian_To_Host_Float(float * f) @@ -72,7 +72,7 @@ int Common_Host_To_Big_Endian_Float(float * f); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Float(float * f); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Float(float * f); /*! * int Common_Host_To_Big_Endian_DOUBLE(double * d) @@ -93,7 +93,7 @@ int Common_Big_Endian_To_Host_Float(float * f); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Double(double * d); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Double(double * d); /*! * int Common_Big_Endian_To_Host_Double(double * d) @@ -114,7 +114,7 @@ int Common_Host_To_Big_Endian_Double(double * d); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Double(double * d); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Double(double * d); /*! * General Definitions for the Common_*_Endianness_Check() functions: @@ -143,7 +143,7 @@ int Common_Big_Endian_To_Host_Double(double * d); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_FLOAT_Endianness_Check(); +MSYS_DLL_EXPORT int Common_FLOAT_Endianness_Check(); /*! * int Common_DOUBLE_Endianness_Check() @@ -165,7 +165,7 @@ int Common_FLOAT_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_DOUBLE_Endianness_Check(); +MSYS_DLL_EXPORT int Common_DOUBLE_Endianness_Check(); #ifdef __cplusplus } /* extern "C" */ diff --git a/src/Common/Src/Byte_Order/Byte_Order_Integers.h b/src/Common/Src/Byte_Order/Byte_Order_Integers.h index 429a5ab..551f883 100644 --- a/src/Common/Src/Byte_Order/Byte_Order_Integers.h +++ b/src/Common/Src/Byte_Order/Byte_Order_Integers.h @@ -51,7 +51,7 @@ extern "C" { * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_UChar(unsigned char * uc); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_UChar(unsigned char * uc); /*! * int Common_Big_Endian_To_Host_UChar(unsigned char * uc) @@ -72,7 +72,7 @@ int Common_Host_To_Big_Endian_UChar(unsigned char * uc); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_UChar(unsigned char * uc); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_UChar(unsigned char * uc); /*! * int Common_Host_To_Big_Endian_Char(char * c) @@ -93,7 +93,7 @@ int Common_Big_Endian_To_Host_UChar(unsigned char * uc); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Char(char * c); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Char(char * c); /*! * int Common_Big_Endian_To_Host_Char(char * c) @@ -114,7 +114,7 @@ int Common_Host_To_Big_Endian_Char(char * c); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Char(char * c); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Char(char * c); /*! * int Common_Host_To_Big_Endian_UShort(unsigned short * us) @@ -135,7 +135,7 @@ int Common_Big_Endian_To_Host_Char(char * c); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_UShort(unsigned short * us); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_UShort(unsigned short * us); /*! * int Common_Big_Endian_To_Host_UShort(unsigned short * us) @@ -156,7 +156,7 @@ int Common_Host_To_Big_Endian_UShort(unsigned short * us); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_UShort(unsigned short * us); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_UShort(unsigned short * us); /*! * int Common_Host_To_Big_Endian_Short(short * s) @@ -177,7 +177,7 @@ int Common_Big_Endian_To_Host_UShort(unsigned short * us); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Short(short * s); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Short(short * s); /*! * int Common_Big_Endian_To_Host_Short(short * s) @@ -198,7 +198,7 @@ int Common_Host_To_Big_Endian_Short(short * s); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Short(short * s); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Short(short * s); /*! * int Common_Host_To_Big_Endian_UInt(unsigned int * ui) @@ -219,7 +219,7 @@ int Common_Big_Endian_To_Host_Short(short * s); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_UInt(unsigned int * ui); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_UInt(unsigned int * ui); /*! * int Common_Big_Endian_To_Host_UInt(unsigned int * ui) @@ -240,7 +240,7 @@ int Common_Host_To_Big_Endian_UInt(unsigned int * ui); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_UInt(unsigned int * ui); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_UInt(unsigned int * ui); /*! * int Common_Host_To_Big_Endian_Int(int * i) @@ -261,7 +261,7 @@ int Common_Big_Endian_To_Host_UInt(unsigned int * ui); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Int(int * i); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Int(int * i); /*! * int Common_Big_Endian_To_Host_Int(int * i) @@ -282,7 +282,7 @@ int Common_Host_To_Big_Endian_Int(int * i); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Int(int * i); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Int(int * i); /*! * int Common_Host_To_Big_Endian_ULong(unsigned long * ul) @@ -303,7 +303,7 @@ int Common_Big_Endian_To_Host_Int(int * i); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_ULong(unsigned long * ul); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_ULong(unsigned long * ul); /*! * int Common_Big_Endian_To_Host_ULong(unsigned long * ul) @@ -324,7 +324,7 @@ int Common_Host_To_Big_Endian_ULong(unsigned long * ul); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_ULong(unsigned long * ul); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_ULong(unsigned long * ul); /*! * int Common_Host_To_Big_Endian_Long(long * l) @@ -345,7 +345,7 @@ int Common_Big_Endian_To_Host_ULong(unsigned long * ul); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Long(long * l); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Long(long * l); /*! * int Common_Big_Endian_To_Host_Long(long * l) @@ -366,7 +366,7 @@ int Common_Host_To_Big_Endian_Long(long * l); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Long(long * l); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Long(long * l); /*! * int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull) @@ -387,7 +387,7 @@ int Common_Big_Endian_To_Host_Long(long * l); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull); /*! * int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull) @@ -408,7 +408,7 @@ int Common_Host_To_Big_Endian_ULong_Long(unsigned long long * ull); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull); /*! * int Common_Host_To_Big_Endian_Long_Long(long long * ull) @@ -429,7 +429,7 @@ int Common_Big_Endian_To_Host_ULong_Long(unsigned long long * ull); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Long_Long(long long * ll); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Long_Long(long long * ll); /*! * int Common_Big_Endian_To_Host_Long_Long(long long * ll) @@ -450,7 +450,7 @@ int Common_Host_To_Big_Endian_Long_Long(long long * ll); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Long_Long(long long * ll); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Long_Long(long long * ll); /*! * int Common_Host_To_Big_Endian_Size_T(size_t * st) @@ -471,7 +471,7 @@ int Common_Big_Endian_To_Host_Long_Long(long long * ll); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Host_To_Big_Endian_Size_T(size_t * st); +MSYS_DLL_EXPORT int Common_Host_To_Big_Endian_Size_T(size_t * st); /*! * int Common_Big_Endian_To_Host_Size_T(size_t * st) @@ -492,7 +492,7 @@ int Common_Host_To_Big_Endian_Size_T(size_t * st); * In case of error, (returned error code is not COMMON_ERROR_SUCCESS), * all arguments will be left unaltered. */ -int Common_Big_Endian_To_Host_Size_T(size_t * st); +MSYS_DLL_EXPORT int Common_Big_Endian_To_Host_Size_T(size_t * st); /*! * General Definitions for the Common_*_Endianness_Check() functions: @@ -521,7 +521,7 @@ int Common_Big_Endian_To_Host_Size_T(size_t * st); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_UCHAR_Endianness_Check(); +MSYS_DLL_EXPORT int Common_UCHAR_Endianness_Check(); /*! * int Common_CHAR_Endianness_Check() @@ -543,7 +543,7 @@ int Common_UCHAR_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_CHAR_Endianness_Check(); +MSYS_DLL_EXPORT int Common_CHAR_Endianness_Check(); /*! * int Common_USHORT_Endianness_Check() @@ -565,7 +565,7 @@ int Common_CHAR_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_USHORT_Endianness_Check(); +MSYS_DLL_EXPORT int Common_USHORT_Endianness_Check(); /*! * int Common_SHORT_Endianness_Check() @@ -587,7 +587,7 @@ int Common_USHORT_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_SHORT_Endianness_Check(); +MSYS_DLL_EXPORT int Common_SHORT_Endianness_Check(); /*! * int Common_UINT_Endianness_Check() @@ -609,7 +609,7 @@ int Common_SHORT_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_UINT_Endianness_Check(); +MSYS_DLL_EXPORT int Common_UINT_Endianness_Check(); /*! * int Common_INT_Endianness_Check() @@ -631,7 +631,7 @@ int Common_UINT_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_INT_Endianness_Check(); +MSYS_DLL_EXPORT int Common_INT_Endianness_Check(); /*! * int Common_ULONG_Endianness_Check() @@ -653,7 +653,7 @@ int Common_INT_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_ULONG_Endianness_Check(); +MSYS_DLL_EXPORT int Common_ULONG_Endianness_Check(); /*! * int Common_LONG_Endianness_Check() @@ -675,7 +675,7 @@ int Common_ULONG_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_LONG_Endianness_Check(); +MSYS_DLL_EXPORT int Common_LONG_Endianness_Check(); /*! * int Common_ULONG_LONG_Endianness_Check() @@ -697,7 +697,7 @@ int Common_LONG_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_ULONG_LONG_Endianness_Check(); +MSYS_DLL_EXPORT int Common_ULONG_LONG_Endianness_Check(); /*! * int Common_LONG_LONG_Endianness_Check() @@ -719,7 +719,7 @@ int Common_ULONG_LONG_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_LONG_LONG_Endianness_Check(); +MSYS_DLL_EXPORT int Common_LONG_LONG_Endianness_Check(); /*! * int Common_SIZE_T_Endianness_Check() @@ -741,7 +741,7 @@ int Common_LONG_LONG_Endianness_Check(); * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering * is unknown for the given host. */ -int Common_SIZE_T_Endianness_Check(); +MSYS_DLL_EXPORT int Common_SIZE_T_Endianness_Check(); #ifdef __cplusplus } /* extern "C" */ From 7d13e411815a7c5f321508df352e36544ed99be4 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:35:51 -0400 Subject: [PATCH 017/134] Forgot to include the Common Error Code header. This commit adds the Common_Error_Handler_Structures.h header to Byte_Order.h. --- src/Common/Src/Byte_Order/Byte_Order.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index e9886b9..46806f0 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -36,6 +36,7 @@ extern "C" { #include "../../../DLL_PORT.h" /* Defines MSYS_DLL_EXPORT, and MSYS_DLL_IMPORT_TEMPLATE. */ /* Internal headers. */ +#include "../Error_Handler/Common_Error_Handler_Structures.h" /* Defines the error codes. */ #include "Byte_Order_Integers.h" #include "Byte_Order_Floating_Points.h" From b58b843b17bbc8caa65dd2fd6188ab2e26c13bf1 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 13:57:29 -0400 Subject: [PATCH 018/134] Add CMake build code. This commit adds Byte_Order's CMakeLists.txt as well as making the needed changes to support it in the build. Note: Building is disabled by default currently, pending the needed merge of error_handler into master. (Error code changes.) --- CMakeLists.txt | 1 + src/Common/Src/Byte_Order/CMakeLists.txt | 14 ++++++++++++++ src/Common/Src/CMakeLists.txt | 5 +++++ 3 files changed, 20 insertions(+) create mode 100644 src/Common/Src/Byte_Order/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 2129543..69b0ef7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(O_OUTPUT_DIR ${T_OUTPUT_DIR}/obj CACHE PATH "Build object output directory") endif() # Option Defaults. +option (BUILD_BYTE_ORDER "Whether or not to build the Byte Ordering code. (Defaults to yes, but is disabled currently due to changes to the Common error handler (error code changes) that have not been commited yet.)" OFF) option (BUILD_DYNAMIC_LIBRARY_SUBSYSTEM "Whether or not to build the Dynamic Library Subsystem. (Defaults to yes.)" ON) option (BUILD_INTERNAL_MUTEX_SUPPORT "Whether or not to build the internal mutex support library. (Defaults to yes.)" ON) option (BUILD_COMMON_ERROR_HANDLER "Whether or not to build the common error handler. (Defaults to yes.)" ON) diff --git a/src/Common/Src/Byte_Order/CMakeLists.txt b/src/Common/Src/Byte_Order/CMakeLists.txt new file mode 100644 index 0000000..d97141a --- /dev/null +++ b/src/Common/Src/Byte_Order/CMakeLists.txt @@ -0,0 +1,14 @@ +# Set output directories. +set(LIBRARY_OUTPUT_PATH ${L_OUTPUT_DIR}) +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) + +# Define includes. +set (BYTE_ORDER_INCLUDES Byte_Order.c +Byte_Order_Floating_Points.c +Byte_Order_Integers.c) + +# Define static library. +add_library (Common_Byte_Order_Multiverse_Engine_Static STATIC ${BYTE_ORDER_INCLUDES}) + +# Define shared library. +add_library (Common_Byte_Order_Multiverse_Engine SHARED ${BYTE_ORDER_INCLUDES}) diff --git a/src/Common/Src/CMakeLists.txt b/src/Common/Src/CMakeLists.txt index cd3b0ff..8c2589d 100644 --- a/src/Common/Src/CMakeLists.txt +++ b/src/Common/Src/CMakeLists.txt @@ -2,6 +2,11 @@ set(LIBRARY_OUTPUT_PATH ${L_OUTPUT_DIR}) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) +# Create the Byte_Order library. +if (BUILD_BYTE_ORDER) + add_subdirectory(Byte_Order) + set (COMMON_BUILT_STATIC_LIBRARY_LIST ${COMMON_BUILT_STATIC_LIBRARY_LIST} Common_Byte_Order_Multiverse_Engine_Static) +endif (BUILD_BYTE_ORDER) # Create the mutexes library. if (BUILD_INTERNAL_MUTEX_SUPPORT) From 90561443ad1a827f6d19159020f0a12c41061c39 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sat, 13 Jun 2015 17:42:32 -0400 Subject: [PATCH 019/134] Enable Byte_Order build This commit enables the Byte_Order build in CMake. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dd69ad7..faa9459 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,7 @@ set(O_OUTPUT_DIR ${T_OUTPUT_DIR}/obj CACHE PATH "Build object output directory") endif() # Option Defaults. -option (BUILD_BYTE_ORDER "Whether or not to build the Byte Ordering code. (Defaults to yes, but is disabled currently due to changes to the Common error handler (error code changes) that have not been commited yet.)" OFF) +option (BUILD_BYTE_ORDER "Whether or not to build the Byte Ordering code. (Defaults to yes.)" ON) option (BUILD_DYNAMIC_LIBRARY_SUBSYSTEM "Whether or not to build the Dynamic Library Subsystem. (Defaults to yes.)" ON) option (BUILD_COMMON_ERROR_HANDLER "Whether or not to build the Common Error Handler. (Defaults to yes.)" ON) option (BUILD_FATAL_ERROR_NOTIFY_SUPPORT "Whether or not to build the Common Error Handler's fatal error notification support. (Defaults to yes.)" ON) From 51fbb9a7b30e253283ca298e861e1915263b72df Mon Sep 17 00:00:00 2001 From: codebase7 Date: Sun, 5 Jul 2015 07:10:30 -0400 Subject: [PATCH 020/134] Move the error codes into their own header. This commit moves the Common namespace error codes to their own header file so that other sections that only need the error code definitions can use them without needing to link in Common_Error_Handler. (I should have done this a long time ago..... but I'm lazy.) --- .../Src/Error_Handler/Common_Error_Handler.h | 3 +- .../Common_Error_Handler_Error_Codes.h | 83 +++++++++++++++++++ .../Common_Error_Handler_Structures.h | 52 +----------- 3 files changed, 86 insertions(+), 52 deletions(-) create mode 100644 src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.h b/src/Common/Src/Error_Handler/Common_Error_Handler.h index e28441e..bf7c7ac 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.h @@ -40,9 +40,10 @@ #include "..\..\..\Core\Src\Panic_Error_Levels.h" // Defines the log levels. #else #include "../../../Core/Src/Panic_Error_Levels.h" // Defines the log levels. -#include "Posix_Error_Translation_Table.h" // Defines the POSIX errno to Common namespace error translation table and functions. +#include "Posix_Error_Translation_Table.h" // Defines the POSIX errno to Common namespace error translation table and functions. #endif // _WIN32 +#include "Common_Error_Handler_Error_Codes.h" /* Defines error codes. */ #include "Common_Error_Handler_Structures.h" // Defines the error codes, error lookup table error lookup table version number, and Common::commonLastErrorCode. // Enable C linkage if needed. diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h new file mode 100644 index 0000000..f2baa3d --- /dev/null +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h @@ -0,0 +1,83 @@ +/*! + Multiverse Engine Project 05/7/2015 Common Common_Error_Handler_Error_Codes.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef COMMON_ERROR_HANDLER_ERROR_CODES_H +#define COMMON_ERROR_HANDLER_ERROR_CODES_H + +/* Common namespace error code definitions. (Human-readable error message translation table is located in Common_Error_Handler_Structures.c) */ + enum { + /* Generic error codes. */ + COMMON_ERROR_SYSTEM_SPECIFIC = 99, + COMMON_ERROR_SUCCESS = 0, + COMMON_ERROR_UNKNOWN_ERROR = -1, + COMMON_ERROR_INVALID_ARGUMENT = -2, + COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED = -3, + COMMON_ERROR_ACCESS_DENIED = -4, + COMMON_ERROR_EXCEPTION_THROWN = -5, + COMMON_ERROR_INTERNAL_ERROR = -6, + COMMON_ERROR_IO_ERROR = -7, + COMMON_ERROR_RANGE_ERROR = -8, + COMMON_ERROR_MEMORY_ERROR = -9, + COMMON_ERROR_INVALID_LIBRARY_ID = -10, /* Formerly THREAD_UTILS_INVALID_LIBRARY_ID. */ + COMMON_ERROR_PEBKAC_INVALID_OPERATION_ORDER = -11, + COMMON_ERROR_CANNOT_GET_SYSTEM_TIME = -12, + COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED = -13, + COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED = -14, + + /* Rendering Subsystem error codes. */ + RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF = -21, /* Overlay image buffer. */ + RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF = -22, /* Transparency data buffer. */ + RENDERER_ERROR_MEM_BUF_ALLOC_EXCEPTION = -23, + RENDERER_ERROR_DUPE_OVERLAY_EXCEPTION = -24, + RENDERER_ERROR_INVAL_OVERLAY_SELF_OVERWRITE = -25, + RENDERER_ERROR_TRANSPARENCY_DISABLED = -26, + /* Threading Subsystem error codes. */ + THREAD_UTILS_ERROR_EXCEPTION_THROWN = -31, + THREAD_UTILS_ERROR_PLUGIN_LOAD_FAILURE = -32, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_START = -33, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_DETACH = -34, + THREAD_UTILS_ERROR_THREAD_COULD_NOT_JOIN = -35, + THREAD_UTILS_ERROR_MUTEX_ALREADY_LOCKED = -36, + THREAD_UTILS_ERROR_CONDITION_CANNOT_LOCK_MUTEX = -37, + THREAD_UTILS_ERROR_CONDITION_WAIT_TIMEOUT_REACHED = -38, + /* FileUtills error codes. */ + FILEUTILLS_ERROR_EXISTANT = -60, + FILEUTILLS_ERROR_NON_EXISTANT = -61, + FILEUTILLS_ERROR_READ_ONLY = -62, + FILEUTILLS_ERROR_PATH_LENGTH_INVALID = -63, + FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY = -64, + FILEUTILLS_ERROR_PATH_IS_A_FILE = -65, + FILEUTILLS_ERROR_PATH_IS_A_DIRECTORY = -66, + FILEUTILLS_ERROR_PATH_IS_A_SYMLINK = -67, + FILEUTILLS_ERROR_PATH_IS_ABSOLUTE = -68, + FILEUTILLS_ERROR_PATH_IS_RELATIVE = -69, + FILEUTILLS_ERROR_FILESYSTEM_FULL = -70, + FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED = -71, + FILEUTILLS_ERROR_EMPTY_DIRECTORY = -72, + FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY = -73, + FILEUTILLS_ERROR_SYMLINK_CHAIN_TOO_DEEP = -74, + /* UI Subsystem. */ + UI_SUBSYSTEM_ERROR_EXCEPTION_THROWN = -90, + }; + +#endif /* COMMON_ERROR_HANDLER_ERROR_CODES_H */ + +/* End of Common_Error_Handler_Error_Codes.h. */ diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h index e24c2cf..e178afc 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.h @@ -36,57 +36,7 @@ extern "C" { #endif /* __cplusplus */ -/* Common namespace error code definitions. (Human-readable error message translation table is located in Common_Error_Handler_Structures.c) */ - enum { - /* Generic error codes. */ - COMMON_ERROR_SYSTEM_SPECIFIC = 99, - COMMON_ERROR_SUCCESS = 0, - COMMON_ERROR_UNKNOWN_ERROR = -1, - COMMON_ERROR_INVALID_ARGUMENT = -2, - COMMON_ERROR_FUNCTION_NOT_IMPLEMENTED = -3, - COMMON_ERROR_ACCESS_DENIED = -4, - COMMON_ERROR_EXCEPTION_THROWN = -5, - COMMON_ERROR_INTERNAL_ERROR = -6, - COMMON_ERROR_IO_ERROR = -7, - COMMON_ERROR_RANGE_ERROR = -8, - COMMON_ERROR_MEMORY_ERROR = -9, - COMMON_ERROR_INVALID_LIBRARY_ID = -10, /* Formerly THREAD_UTILS_INVALID_LIBRARY_ID. */ - COMMON_ERROR_PEBKAC_INVALID_OPERATION_ORDER = -11, - COMMON_ERROR_CANNOT_GET_SYSTEM_TIME = -12, - COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED = -13, - COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED = -14, - - /* Rendering Subsystem error codes. */ - RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF = -21, /* Overlay image buffer. */ - RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF = -22, /* Transparency data buffer. */ - RENDERER_ERROR_MEM_BUF_ALLOC_EXCEPTION = -23, - RENDERER_ERROR_DUPE_OVERLAY_EXCEPTION = -24, - RENDERER_ERROR_INVAL_OVERLAY_SELF_OVERWRITE = -25, - RENDERER_ERROR_TRANSPARENCY_DISABLED = -26, - /* Threading Subsystem error codes. */ - THREAD_UTILS_ERROR_EXCEPTION_THROWN = -31, - THREAD_UTILS_ERROR_PLUGIN_LOAD_FAILURE = -32, - THREAD_UTILS_ERROR_THREAD_COULD_NOT_START = -33, - THREAD_UTILS_ERROR_THREAD_COULD_NOT_DETACH = -34, - THREAD_UTILS_ERROR_THREAD_COULD_NOT_JOIN = -35, - THREAD_UTILS_ERROR_MUTEX_ALREADY_LOCKED = -36, - THREAD_UTILS_ERROR_CONDITION_CANNOT_LOCK_MUTEX = -37, - THREAD_UTILS_ERROR_CONDITION_WAIT_TIMEOUT_REACHED = -38, - /* FileUtills error codes. */ - FILEUTILLS_ERROR_EXISTANT = -60, - FILEUTILLS_ERROR_NON_EXISTANT = -61, - FILEUTILLS_ERROR_READ_ONLY = -62, - FILEUTILLS_ERROR_PATH_LENGTH_INVALID = -63, - FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY = -64, - FILEUTILLS_ERROR_PATH_IS_A_FILE = -65, - FILEUTILLS_ERROR_PATH_IS_A_DIRECTORY = -66, - FILEUTILLS_ERROR_FILESYSTEM_FULL = -67, - FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED = -68, - FILEUTILLS_ERROR_EMPTY_DIRECTORY = -69, - FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY = -70, - /* UI Subsystem. */ - UI_SUBSYSTEM_ERROR_EXCEPTION_THROWN = -90, - }; +/* ERROR CODES MOVED TO Common_Error_Handler_Error_Codes.h */ /*! * const unsigned int Common_Get_Error_Table_API_Version() From 44f4797866f401133d403cd4884b875bbe104a7f Mon Sep 17 00:00:00 2001 From: codebase7 Date: Mon, 6 Jul 2015 02:59:06 -0400 Subject: [PATCH 021/134] Compile Fixes for Byte_Order.h This commit fixes the following with Byte_Order.h: - Fixes include file for Common namespace error codes. (Due to commit 51fbb9a7b30e253283ca298e861e1915263b72df ) - Fixes stdbool header include. (MSVC 2013 includes support for C99's stdbool.h) - Adds missing include headers stdlib.h, stddef.h, and string.h. --- src/Common/Src/Byte_Order/Byte_Order.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index 46806f0..e93e9cc 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -36,10 +36,22 @@ extern "C" { #include "../../../DLL_PORT.h" /* Defines MSYS_DLL_EXPORT, and MSYS_DLL_IMPORT_TEMPLATE. */ /* Internal headers. */ -#include "../Error_Handler/Common_Error_Handler_Structures.h" /* Defines the error codes. */ +#include "../Error_Handler/Common_Error_Handler_Error_Codes.h" /* Defines the error codes. */ #include "Byte_Order_Integers.h" #include "Byte_Order_Floating_Points.h" +/* Define bool. */ +#if _MSC_FULL_VER && _MSC_FULL_VER < 180031101 +#include "../stdbool.h" /* Older versions of Visual C don't support the C99 stdbool header. So we have to fake one. */ +#else +#include +#endif + +/* External headers. */ +#include /* Defines NULL. */ +#include /* Defines malloc(), free(). */ +#include /* Defines memset(), memcpy(). */ + /*! * int Common_Byte_Swap(char * data, const size_t dataLength) * From 0b6045590aa287f5baa73fac2e1ca6f6e48dff35 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:19:23 -0400 Subject: [PATCH 022/134] Fix missing error messages added in 51fbb9a7b30e253283ca298e861e1915263b72df This commit adds the missing human readable error messages needed for the common error codes added in commit 51fbb9a7b30e253283ca298e861e1915263b72df. --- .../Src/Error_Handler/Common_Error_Handler_Structures.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c index c693f92..3dda43f 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c @@ -98,10 +98,14 @@ const Common_Error_Object Common_commonErrorTable[] = { {FILEUTILLS_ERROR_PATH_FILE_AS_DIRECTORY, "The path has a file in it that is being treated as a directory."}, {FILEUTILLS_ERROR_PATH_IS_A_FILE, "Given path is a file."}, {FILEUTILLS_ERROR_PATH_IS_A_DIRECTORY, "Given path is a directory."}, + {FILEUTILLS_ERROR_PATH_IS_A_SYMLINK, "Given path is a symbolic link."}, + {FILEUTILLS_ERROR_PATH_IS_ABSOLUTE, "Given path is in absolute format (Fully resolved)."}, + {FILEUTILLS_ERROR_PATH_IS_RELATIVE, "Given path is in relative format (Needs resolving)."}, {FILEUTILLS_ERROR_FILESYSTEM_FULL, "Given filesystem is full."}, {FILEUTILLS_ERROR_FILESYSTEM_QUOTA_REACHED, "User's disk usage quota for the given filesystem has been reached."}, {FILEUTILLS_ERROR_EMPTY_DIRECTORY, "The given path is an empty directory."}, {FILEUTILLS_ERROR_NON_EMPTY_DIRECTORY, "The given path is a non-empty directory."}, + {FILEUTILLS_ERROR_SYMLINK_CHAIN_TOO_DEEP, "While parsing a host-defined symbolic link chain, the host system indicated the link chain was longer than what it supports."}, // UI Subsystem/ {UI_SUBSYSTEM_ERROR_EXCEPTION_THROWN, "An exception was thrown in the UI Subsystem."}, // TODO: Need to add the error codes from all common namespace functions. From 0db914ff1951f1719090bf8bd5e3d47fa3c94832 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:21:28 -0400 Subject: [PATCH 023/134] Add error code COMMON_ERROR_END_OF_DATA. This commit creates the common namespace error code COMMON_ERROR_END_OF_DATA. --- src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h | 1 + src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h index f2baa3d..8ba7925 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h @@ -41,6 +41,7 @@ COMMON_ERROR_CANNOT_GET_SYSTEM_TIME = -12, COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED = -13, COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED = -14, + COMMON_ERROR_END_OF_DATA = -15, /* Rendering Subsystem error codes. */ RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF = -21, /* Overlay image buffer. */ diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c index 3dda43f..84838dd 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c @@ -74,6 +74,7 @@ const Common_Error_Object Common_commonErrorTable[] = { {COMMON_ERROR_CANNOT_GET_SYSTEM_TIME, "Could not get the system's current time."}, {COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED, "Given object has not been inited yet."}, {COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED, "Given object has already been inited."}, + {COMMON_ERROR_END_OF_DATA, "There is no remaining data to process."}, // Rendering Subsystem error codes. {RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF, "Could not allocate memory for overlay image buffer."}, {RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF, "Could not allocate memory for transparency data buffer."}, From e3decf20e1ea5bb8f1e48d565956af9b7b33ee62 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:23:48 -0400 Subject: [PATCH 024/134] MSVC 2013 fix for Common_Error_Handler.h This commit makes Common_Error_Handler.h use the builtin _Bool in MSVC 2013, instead of using our fake version. --- src/Common/Src/Error_Handler/Common_Error_Handler.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler.h b/src/Common/Src/Error_Handler/Common_Error_Handler.h index bf7c7ac..846b7c8 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler.h @@ -28,11 +28,11 @@ // External includes. #include // Defines NULL. #ifndef __cplusplus -#ifdef _MSC_FULL_VER /* VC is special. */ +#if _MSC_FULL_VER && _MSC_FULL_VER < 180031101 /* Visual C versions less than 2013 are special. (They lack support for C99's bool type.) */ #include "..\stdbool.h" /* Defines bool data type. (For C compilers.) */ #else #include -#endif /* _MSC_FULL_VER */ +#endif /* _MSC_FULL_VER && _MSC_FULL_VER < 180031101 */ #endif /* __cplusplus */ // Project includes. From 64bb173cfe716418bfe2ea7919fcee40be3de42d Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:26:11 -0400 Subject: [PATCH 025/134] Add some safeguards to our fake stdbool header. This commit adds some more preprocessor checks to the internal fake stdbool.h header in an attempt to prevent accidental inclusion when the header is not needed. --- src/Common/Src/stdbool.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Common/Src/stdbool.h b/src/Common/Src/stdbool.h index e7b9d91..6fde9c0 100644 --- a/src/Common/Src/stdbool.h +++ b/src/Common/Src/stdbool.h @@ -23,6 +23,15 @@ #ifndef MSYS_STD_BOOL_H #define MSYS_STD_BOOL_H +/* This is only needed for C. */ +#ifndef __cplusplus + +/* Only define this if STD_BOOL is not defined. */ +#ifndef _STDBOOL + +/* Only define this if __bool_true_false_are_defined is not defined. */ +#ifndef __bool_true_false_are_defined + /* Define true and false. */ #define TRUE 0x01 /* Really this could be anything. */ #define FALSE 0x00 /* Litteral NULL byte to conform to ANYTHING NOT NULL IS TRUE. */ @@ -34,6 +43,9 @@ typedef char bool; /* This is a char to conform to the expectation in C++ that s /* Define __bool_true_false_are_defined (ISO) */ #define __bool_true_false_are_defined 1 +#endif /* __bool_true_false_are_defined */ +#endif /* _STDBOOL */ +#endif /* __cplusplus */ #endif /* MSYS_STD_BOOL_H */ From fc64ac239ffb7c484935f142ff57cc7761bc522e Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:28:00 -0400 Subject: [PATCH 026/134] Add function Common_Print_Bytes_In_Decimal(). This commit adds the Common_Print_Bytes_In_Decimal() function to Byte_Order. --- src/Common/Src/Byte_Order/Byte_Order.c | 5 +++++ src/Common/Src/Byte_Order/Byte_Order.h | 14 ++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Common/Src/Byte_Order/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c index 3323cfc..f19379f 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.c +++ b/src/Common/Src/Byte_Order/Byte_Order.c @@ -246,6 +246,11 @@ int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, cha return Common_Print_Bytes_To_CString(data, dataLength, retStr, retStrSize, 2, 8, '0', spaceBetweenBytes); } +int Common_Print_Bytes_In_Decimal(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes) +{ + return Common_Print_Bytes_To_CString(data, dataLength, retStr, retStrSize, 10, 8, '0', spaceBetweenBytes); +} + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index e93e9cc..3edaf70 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -149,6 +149,20 @@ MSYS_DLL_EXPORT int Common_Print_Bytes_In_Hex(const char * data, const size_t da */ MSYS_DLL_EXPORT int Common_Print_Bytes_In_Binary(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); +/*! +* int Common_Print_Bytes_In_Decimal(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, +* const bool spaceBetweenBytes) +* +* Wrapper function around Common_Print_Bytes_To_CString() for converting a byte string to a human-readable decimal string. +* Example output: ("10012" if spacing is disabled, "10 0 12" if spacing is enabled.) +* +* Note: This function is to make calls shorter, if you want more control over the output, call Common_Print_Bytes_To_CString() directly. +* +* All arguments and return values are identical to their Common_Print_Bytes_To_CString() counterparts. See Common_Print_Bytes_To_CString() +* for their descriptions. +*/ +MSYS_DLL_EXPORT int Common_Print_Bytes_In_Decimal(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const bool spaceBetweenBytes); + #ifdef __cplusplus } /* extern "C" */ #endif /* __cplusplus */ From 3171cb90860ebeb9681babe2dd5c40dd6a579acc Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:31:02 -0400 Subject: [PATCH 027/134] Silence a compiler warning and clean up comments in Common_Print_Bytes_To_CString(). This commit silences a compiler warning about possible loss of data in Common_Print_Bytes_To_CString(). (We expect that loss to happen.) This commit also corrects some spelling mistakes in Common_Print_Bytes_To_CString(). --- src/Common/Src/Byte_Order/Byte_Order.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Common/Src/Byte_Order/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c index f19379f..b664ab6 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.c +++ b/src/Common/Src/Byte_Order/Byte_Order.c @@ -72,7 +72,7 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch char outputValue = '\0'; /* The value that we need to write into the output buffer. (Calculated from currentValue.) */ char * outputBuffer = NULL; /* Pointer to the c-string that will be outputted to the standard output. */ char * previousOutputBuffer = NULL; /* Temporary pointer used to copy previously generated data into the current outputBuffer. */ - const char outputValues[17] = "0123456789ABCDEF"; /* C-String used to map a generated value to it's corrosponding character. */ + const char outputValues[17] = "0123456789ABCDEF"; /* C-String used to map a generated value to it's corresponding character. */ size_t outputBufferSize = 1; /* Current size of the outputBuffer. Set to one by default to allow the string to be NULL terminated. */ /* Check for invalid arguments. */ @@ -122,8 +122,8 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch /* Increment byte value count. */ byteValueCount++; - /* Get the next value by choping off the "ones place", aka devide by the current base. */ - currentByte /= base; + /* Get the next value by chopping off the "ones place", aka divide by the current base. */ + currentByte /= (unsigned char)base; } else { From 39ab3ae2610676fdc00b9475b8938f609faa048b Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:45:25 -0400 Subject: [PATCH 028/134] Fix CMakeLists to include Byte_Order in built shared list. This commit fixes the common CMakeLists.txt to include the Byte_Order shared library in the built common shared libraries list: COMMON_BUILT_SHARED_LIBRARY_LIST. --- src/Common/Src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Common/Src/CMakeLists.txt b/src/Common/Src/CMakeLists.txt index ebb7edb..7ba4e04 100644 --- a/src/Common/Src/CMakeLists.txt +++ b/src/Common/Src/CMakeLists.txt @@ -5,6 +5,7 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) # Create the Byte_Order library. if (BUILD_BYTE_ORDER) add_subdirectory(Byte_Order) + set (COMMON_BUILT_SHARED_LIBRARY_LIST ${COMMON_BUILT_SHARED_LIBRARY_LIST} Common_Byte_Order_Multiverse_Engine) set (COMMON_BUILT_STATIC_LIBRARY_LIST ${COMMON_BUILT_STATIC_LIBRARY_LIST} Common_Byte_Order_Multiverse_Engine_Static) endif (BUILD_BYTE_ORDER) From 85e8dc3185f130f47b7da34195d2db10c637fcbe Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:49:08 -0400 Subject: [PATCH 029/134] Add common error codes COMMON_ERROR_COMPARISON_PASSED COMMON_ERROR_COMPARISON_FAILED This commit adds the common namespace error codes: COMMON_ERROR_COMPARISON_PASSED and COMMON_ERROR_COMPARISON_FAILED. --- src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h | 2 ++ src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h index 8ba7925..9bdc4f4 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Error_Codes.h @@ -42,6 +42,8 @@ COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED = -13, COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED = -14, COMMON_ERROR_END_OF_DATA = -15, + COMMON_ERROR_COMPARISON_PASSED = -16, + COMMON_ERROR_COMPARISON_FAILED = -17, /* Rendering Subsystem error codes. */ RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF = -21, /* Overlay image buffer. */ diff --git a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c index 84838dd..9eee49b 100644 --- a/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c +++ b/src/Common/Src/Error_Handler/Common_Error_Handler_Structures.c @@ -75,6 +75,8 @@ const Common_Error_Object Common_commonErrorTable[] = { {COMMON_ERROR_SUBSYSTEM_OBJECT_NOT_INITED, "Given object has not been inited yet."}, {COMMON_ERROR_SUBSYSTEM_OBJECT_ALREADY_INITED, "Given object has already been inited."}, {COMMON_ERROR_END_OF_DATA, "There is no remaining data to process."}, + {COMMON_ERROR_COMPARISON_PASSED, "A check passed it's requirements."}, + {COMMON_ERROR_COMPARISON_FAILED, "A check failed to pass it's requirements."}, // Rendering Subsystem error codes. {RENDERER_ERROR_UNABLE_TO_ALLOC_OI_BUF, "Could not allocate memory for overlay image buffer."}, {RENDERER_ERROR_UNABLE_TO_ALLOC_TD_BUF, "Could not allocate memory for transparency data buffer."}, From d769a4342410ff89a7ff4997da87bca339206c98 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:52:48 -0400 Subject: [PATCH 030/134] Add function Byte_Order_Bit_Comparison(). This commit adds the Byte_Order_Bit_Comparison() to Byte_Order. --- src/Common/Src/Byte_Order/Byte_Order.c | 77 ++++++++++++++++++++++++++ src/Common/Src/Byte_Order/Byte_Order.h | 43 ++++++++++++++ 2 files changed, 120 insertions(+) diff --git a/src/Common/Src/Byte_Order/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c index b664ab6..17ac3f2 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.c +++ b/src/Common/Src/Byte_Order/Byte_Order.c @@ -26,6 +26,83 @@ extern "C" { #endif /* __cplusplus */ +int Byte_Order_Bit_Comparison(const char * byte, const char bitMask, const char bitValues) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result code of this function. */ + + /* 10000000 wanna check the first two bits, how? + + 11000000 <-- Bit mask of bits to actually check. + + 10 <-- What the two bits should be. + + Do two comparisons. (One for the set (1) bits and one for the unset (0) bits. + + bits should be: BINARY AND BITMASK. BITS THAT ARE ACTUALLY SET TO CHECK. + (1000000) & (11000000) = (1000000) + + BITWISE NOT bits should be: Inverted what bits should be. + ~ (1000000) = (01111111) + + Inverted what bits should be: BINARY AND BITMASK. BITS THAT ARE NOT SET TO CHECK. + (01111111) & (11000000) = (0100000) + + BITS TO CHECK. BINARY AND BITS THAT ARE SET TO CHECK. (Comparison one result) + (10000000) & (1000000) = SUCCESS. (1000000) + + Inverted BITS TO CHECK. BINARY AND BITS THAT ARE NOT SET TO CHECK. (Comparison two result) + (01111111) & (0100000) = SUCCESS. (0100000) + + (Comparison one result) BINARY INCLUSIVE OR (Comparison two result) (Result of both comparisons) + (1000000) | (0100000) = (11000000) + + BITMASK BINARY AND (Result of both comparisons) Final result + (11000000) & (11000000) = SUCCESS (11000000) + + */ + + /* Check for invalid arguments. */ + if (byte != NULL) + { + /* Check for all value comparison. */ + /*ret = (bitMask == UCHAR_MAX) ? + /* Simple equality check, we only need to check for an exact match. Otherwise continue comparison on the next line. / + (((*byte) == bitValues) ? COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED) : \ + /* HARDCODED CHECK: If both bitValues and byte are zero, + and bitMask is non-zero we need to return true. Otherwise continue on the next line. / + ((((*byte) == 0) && (bitValues == 0)) ? ((bitMask != 0) ? COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED) : \ + /* Because it's not a simple equality check, Do first comparison. (Set (1) bits.) / + ((((*byte) & (bitValues & bitMask)) && ((~(*byte)) & ((~bitValues) & bitMask))) ? + /* Do the second comparison. (Unset (0) bits.) / + COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED));*/ + if (bitMask == UCHAR_MAX) + { + ret = ((*byte) == bitValues) ? COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED; + } + else + { + if (((*byte) == 0) && (bitValues == 0)) + { + ret = (bitMask != 0) ? COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED; + } + else + { + ret = ((((*byte) & (bitValues & bitMask)) | ((~(*byte)) & ((~bitValues) & bitMask))) & bitMask) ? + COMMON_ERROR_COMPARISON_PASSED : COMMON_ERROR_COMPARISON_FAILED; + } + } + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + + /* Exit function. */ + return ret; +} + int Common_Byte_Swap(char * data, const size_t dataLength) { /* Init ret. */ diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index 3edaf70..f85bd87 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -52,6 +52,49 @@ extern "C" { #include /* Defines malloc(), free(). */ #include /* Defines memset(), memcpy(). */ +/*! + * int Byte_Order_Bit_Comparison(const char * byte, const char bitMask, const char bitValues) + * + * Compares the given byte's bits to the given bitValues using bitMask to define what bits to compare. + * + * I.e. This function compares bits to see if they are equal, using the bitMask to determine what + * bits to actually compare. + * + * Example: If bitMask is 11000000, then only the first two bits are checked. So to make a truth table: + * + * byte: bitMask: bitValues: Result: + * 11000000 11000000 11000000 TRUE (The checked values in byte and bitValues are identical.) + * 10000000 11000000 10000000 TRUE (The checked first and second bits are identical.) + * 01110010 00110010 10110010 TRUE (The checked 3rd, 4th, and 7th bits are identical.) + * 11000100 11000000 11000000 TRUE (Extra bit in byte is not checked.) + * 11000000 11000000 11000100 TRUE (Extra bit in bitValues is not checked.) + * 01000000 11000000 11000000 FALSE (byte does not match bitValues.) + * 11000000 11000000 10000000 FALSE (bitValues does not match byte.) + * 00000000 00000000 00000000 FALSE (No bits are defined to check.) + * 00000000 00110010 00000000 TRUE (Third, forth, and 7th bits are identical. + * (Hardcoded zero check, for consistancy with other results.)) + * 00000000 11111111 00000000 TRUE (Checking all bits, byte and bitValues are both zero. + * (Hardcoded zero check, for consistancy with other results.)) + * + * A note about checking for zero bits: + * For consistancy with the other results, in the event an all zero byte and bitValues is given + * to this function, a hard coded check is inserted to return COMMON_ERROR_COMPARISON_PASSED if + * the given bitMask is not equal to zero. Otherwise it returns COMMON_ERROR_COMPARISON_FAILED. + * This contradicts what would be expected from a binary AND operation and callers of this + * function should therefore be aware of it and check for this result. + * (Normally, a binary AND operation on an all zero set of operands would give a FALSE result. + * The best antidote I can give to deal with this function's inconsistancy is: + * It checks the given bits to see if they match, if given to a non-programmer, what would they + * think the result should be? + * Answer: (0 == 0) is TRUE, so the function should return TRUE.") + * + * Returns COMMON_ERROR_COMPARISON_PASSED if the checked bits match. + * Returns COMMON_ERROR_COMPARISON_FAILED if the checked bits do NOT match. + * Returns COMMON_ERROR_INVALID_ARGUMENT if the given pointer to char is invalid. + * Otherwise returns the approperite error code. + */ +MSYS_DLL_EXPORT int Byte_Order_Bit_Comparison(const char * byte, const char bitMask, const char bitValues); + /*! * int Common_Byte_Swap(char * data, const size_t dataLength) * From 93a6f478f4ba8ff22d11599269859d086930405b Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 01:59:36 -0400 Subject: [PATCH 031/134] Refactor Common_Print_Bytes_To_CString() This commit is a refactoring of Common_Print_Bytes_To_CString() with the intent of fixing an output bug with a base argument of 2. --- src/Common/Src/Byte_Order/Byte_Order.c | 60 ++++++++++++++++---------- src/Common/Src/Byte_Order/Byte_Order.h | 4 +- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/src/Common/Src/Byte_Order/Byte_Order.c b/src/Common/Src/Byte_Order/Byte_Order.c index 17ac3f2..dbcb25a 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.c +++ b/src/Common/Src/Byte_Order/Byte_Order.c @@ -139,27 +139,30 @@ int Common_Byte_Swap(char * data, const size_t dataLength) return ret; } -int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes) +int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const unsigned int base, const size_t width, const char fillValue, const bool spaceBetweenBytes) { +/* Define the size of the output values array. */ +#define MSYSOUTPUTVALUESSIZE 17 + /* Init vars. */ - int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ - size_t x = 0; /* Counter used in the print and spacing loops. */ - size_t byteValueCount = 0; /* Used to keep track of how many bytes we have outputted for the current byte. */ - unsigned char currentByte = '\0'; /* Temporary value used to store the current byte we are working on. */ - char outputValue = '\0'; /* The value that we need to write into the output buffer. (Calculated from currentValue.) */ - char * outputBuffer = NULL; /* Pointer to the c-string that will be outputted to the standard output. */ - char * previousOutputBuffer = NULL; /* Temporary pointer used to copy previously generated data into the current outputBuffer. */ - const char outputValues[17] = "0123456789ABCDEF"; /* C-String used to map a generated value to it's corresponding character. */ - size_t outputBufferSize = 1; /* Current size of the outputBuffer. Set to one by default to allow the string to be NULL terminated. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result of this function. */ + size_t x = 0; /* Counter used in the print and spacing loops. */ + size_t byteValueCount = 0; /* Used to keep track of how many bytes we have outputted for the current byte. */ + unsigned char currentByte = '\0'; /* Temporary value used to store the current byte we are working on. */ + size_t outputValue = 0; /* The value that we need to write into the output buffer. (Calculated from currentValue.) */ + char * outputBuffer = NULL; /* Pointer to the c-string that will be given back to the caller. */ + char * previousOutputBuffer = NULL; /* Temporary pointer used to copy previously generated data into the current outputBuffer. */ + const char outputValues[MSYSOUTPUTVALUESSIZE] = "0123456789ABCDEF"; /* C-String used to map a generated value to it's corresponding character. */ + size_t outputBufferSize = 1; /* Current size of the outputBuffer. Set to one by default to allow the string to be NULL terminated. */ /* Check for invalid arguments. */ if ((data != NULL) && (dataLength > 0) && (retStr != NULL) && (retStrSize != NULL) && (base >= 2) && (base <= 16)) { /* Begin data print loop. */ - for (x = 0; ((x < dataLength) && (ret != COMMON_ERROR_MEMORY_ERROR)); x++) + for (x = 0; ((x < dataLength) && (ret == COMMON_ERROR_UNKNOWN_ERROR)); x++) { /* Copy current value. */ - currentByte = data[((dataLength - 1) - x)]; + currentByte = (data[((dataLength - 1) - x)]); /* Reset byte value count. */ byteValueCount = 0; @@ -182,35 +185,43 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch /* Check for successful memory allocation. */ if (outputBuffer != NULL) { - /* Blank out the new buffer. */ - memset(outputBuffer, '\0', outputBufferSize); + /* Blank out the new buffer. */ + memset(outputBuffer, '\0', outputBufferSize); - /* Set the first value as the previous data comes after it. */ + /* Set the first value as the previous data comes after it. */ + if ((outputValue >= 0) && (outputValue < MSYSOUTPUTVALUESSIZE)) + { outputBuffer[0] = outputValues[outputValue]; /* If we have any previous data we need to copy it into the new buffer and deallocate the previous one. */ if (previousOutputBuffer != NULL) { - memcpy((outputBuffer + 1), previousOutputBuffer, (outputBufferSize - 1)); - free(previousOutputBuffer); - previousOutputBuffer = NULL; + memcpy((outputBuffer + 1), previousOutputBuffer, (outputBufferSize - 1)); + free(previousOutputBuffer); + previousOutputBuffer = NULL; } /* Increment byte value count. */ byteValueCount++; /* Get the next value by chopping off the "ones place", aka divide by the current base. */ - currentByte /= (unsigned char)base; + currentByte /= base; + } + else + { + /* Invalid byte value. */ + ret = COMMON_ERROR_RANGE_ERROR; + } } else { /* Could not allocate memory for output buffer. */ ret = COMMON_ERROR_MEMORY_ERROR; } - }while ((currentByte) && (ret != COMMON_ERROR_MEMORY_ERROR)); + }while ((currentByte) && (ret == COMMON_ERROR_UNKNOWN_ERROR)); /* Check and see if the generated values used up all of the requested width. */ - if ((ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && (byteValueCount < width)) + if ((ret == COMMON_ERROR_UNKNOWN_ERROR) && (outputBuffer != NULL) && (byteValueCount < width)) { /* Copy the current buffer's pointer because we are about to create a new one. */ previousOutputBuffer = outputBuffer; @@ -246,7 +257,7 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch } /* Insert spacing if needed. */ - if ((spaceBetweenBytes) && (ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && ((x + 1) < dataLength)) + if ((spaceBetweenBytes) && (ret == COMMON_ERROR_UNKNOWN_ERROR) && (outputBuffer != NULL) && ((x + 1) < dataLength)) { /* Copy the current buffer's pointer because we are about to create a new one. */ previousOutputBuffer = outputBuffer; @@ -278,7 +289,7 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch } /* Check for NULL output buffer. */ - if ((ret != COMMON_ERROR_MEMORY_ERROR) && (outputBuffer != NULL) && (outputBufferSize > 0)) + if ((ret == COMMON_ERROR_UNKNOWN_ERROR) && (outputBuffer != NULL) && (outputBufferSize > 0)) { /* Copy the outputBuffer pointer to retStr. */ (*retStr) = outputBuffer; @@ -298,6 +309,9 @@ int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, ch /* Exit function. */ return ret; + +/* Undefine the size of the output values array. */ +#undef MSYSOUTPUTVALUESSIZE } void Common_Deallocate_Print_Bytes_CString(char ** str) diff --git a/src/Common/Src/Byte_Order/Byte_Order.h b/src/Common/Src/Byte_Order/Byte_Order.h index f85bd87..c2aa6af 100644 --- a/src/Common/Src/Byte_Order/Byte_Order.h +++ b/src/Common/Src/Byte_Order/Byte_Order.h @@ -119,7 +119,7 @@ MSYS_DLL_EXPORT int Byte_Order_Bit_Comparison(const char * byte, const char bitM MSYS_DLL_EXPORT int Common_Byte_Swap(char * data, const size_t dataLength); /*! - * int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, + * int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const unsigned int base, * const size_t width, const char fillValue, const bool spaceBetweenBytes) * * Converts a given byte string to a printable (NULL-terminated) and human-readable string in the given base. @@ -151,7 +151,7 @@ MSYS_DLL_EXPORT int Common_Byte_Swap(char * data, const size_t dataLength); * * In case of error, (the returned error code is not COMMON_ERROR_SUCCESS, then the given arguments will NOT be altered by this function. */ -MSYS_DLL_EXPORT int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const size_t base, const size_t width, const char fillValue, const bool spaceBetweenBytes); +MSYS_DLL_EXPORT int Common_Print_Bytes_To_CString(const char * data, const size_t dataLength, char ** retStr, size_t * retStrSize, const unsigned int base, const size_t width, const char fillValue, const bool spaceBetweenBytes); /*! * void Common_Deallocate_Print_Bytes_CString(char ** str) From bc8f43c6e3ce7d5090c9ee106cfb75fa67994384 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 02:05:34 -0400 Subject: [PATCH 032/134] Add Unit_Tests for Byte_Order. This commit is the initial Unit_Tests code for the Byte_Order code. --- src/Tests/CMakeLists.txt | 5 +- src/Tests/Unit_Test_Byte_Order.cpp | 461 +++++++++++++++++++++++++++++ src/Tests/Unit_Test_Common.h | 2 + src/Tests/Unit_Tests.cpp | 4 + src/Tests/Unit_Tests_Byte_Order.h | 80 +++++ 5 files changed, 550 insertions(+), 2 deletions(-) create mode 100644 src/Tests/Unit_Test_Byte_Order.cpp create mode 100644 src/Tests/Unit_Tests_Byte_Order.h diff --git a/src/Tests/CMakeLists.txt b/src/Tests/CMakeLists.txt index d6ed68f..5e78551 100644 --- a/src/Tests/CMakeLists.txt +++ b/src/Tests/CMakeLists.txt @@ -5,11 +5,12 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) # Define Unit Tests base includes. set (UNIT_TESTS_INCLUDES_BASE Unit_Tests.cpp) -# We may make Core an optional subsystem in the future. +# We may make Core and Byte_Order an optional subsystem in the future. set (UNIT_TESTS_INCLUDES ${UNIT_TESTS_INCLUDES_BASE} Test_Base_Header.cpp Unit_Test_Data_Object.cpp -Unit_Test_Data_Object_Insert_Char.cpp) +Unit_Test_Data_Object_Insert_Char.cpp +Unit_Test_Byte_Order.cpp) # Only build the tests for the subsystems that are enabled. if (BUILD_COMMON_ERROR_HANDLER) diff --git a/src/Tests/Unit_Test_Byte_Order.cpp b/src/Tests/Unit_Test_Byte_Order.cpp new file mode 100644 index 0000000..b9011f8 --- /dev/null +++ b/src/Tests/Unit_Test_Byte_Order.cpp @@ -0,0 +1,461 @@ +/*! + Multiverse Engine Project 11/7/2015 Unit Tests Unit_Test_Byte_Order.cpp + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Internal includes. */ +#include "Unit_Tests.h" + +void Print_Random_Bits(const char bits) +{ + /* Init vars. */ + int retFromFunct = COMMON_ERROR_UNKNOWN_ERROR; /* Result code from engine function. */ + char * bitMaskString = NULL; /* The bitmask represented as a human-readable string. */ + size_t bitMaskStringLength = 0; /* The length of the bit mask string. */ + + /* Print the bits. */ + retFromFunct = Common_Print_Bytes_In_Binary(&bits, 1, &bitMaskString, &bitMaskStringLength, 1); + if (retFromFunct == COMMON_ERROR_SUCCESS) + { + /* Print the string. */ + std::cout << bitMaskString << " "; + + /* Deallocate the string. */ + Common_Deallocate_Print_Bytes_CString(&bitMaskString); + } + else + { + std::cout << "< ERROR: Unable to print random bits, Common_Print_Bytes_In_Binary() failed. > "; + } + std::cout.flush(); + + /* Exit function. */ + return; +} + +void Print_Bits_and_BitMask(const char byteToCheck, const char bitMask, const char bitValues) +{ + /* Print the values. */ + std::cout << "DEBUG: BYTE:\t\t"; + Print_Random_Bits(byteToCheck); + std::cout << "\nDEBUG: BITMASK:\t\t"; + Print_Random_Bits(bitMask); + std::cout << "\nDEBUG: BIT_VALUES:\t"; + Print_Random_Bits(bitValues); + std::cout << '\n'; + std::cout.flush(); + + /* Exit function. */ + return; +} + +char Generate_Random_Non_Conforming_Bit_Mask(const char byte1, const char byte2) +{ + /* Init vars. */ + char ret = '\0'; /* The result of this function. */ + + /* Generate a random bit mask to check for. */ + std::cout << "Generating random bit mask. Please Wait.\n"; + std::cout.flush(); + + /* Begin generation loop. */ + do + { + ret = ((char)DataProcess::Trivial_Random_Number_Generator(0, 255)); + } while ((byte1 | byte2) ^ ret); + + /* Exit function. */ + return ret; +} + +char Generate_Random_Bit_Mask(const char bitMask) +{ + /* Init vars. */ + char ret = '\0'; /* The result of this function. */ + + /* Generate a random bit mask to check for. */ + std::cout << "Generating random bit mask. Please Wait.\n"; + std::cout.flush(); + do + { + /* Generate a bit mask. */ + ret = ((char)DataProcess::Trivial_Random_Number_Generator(1, 254)); + } while (ret == bitMask); + + /* Exit function. */ + return ret; +} + +char Generate_Random_Bits(const char notThisValue) +{ + /* Init vars. */ + char ret = '\0'; /* The result of this function. */ + + /* Generate some random bits to check for. */ + std::cout << "Generating random bits. Please Wait.\n"; + std::cout.flush(); + + /* Generate some bits, avoiding the given value if needed. */ + while (ret == notThisValue) + { + ret = ((char)DataProcess::Trivial_Random_Number_Generator(2, 254)); + } + + /* Exit function. */ + return ret; +} + +int Generate_Matching_Bitmask_Random_Data(char * byteToCheck, char * bitMask, char * bitValues) +{ + /* Init vars. */ + int ret = COMMON_ERROR_UNKNOWN_ERROR; /* The result code of this function. */ + + /* Check for invalid arguments. */ + if ((byteToCheck != NULL) && (bitMask != NULL) && (bitValues != NULL)) + { + /* Call bitmask generation function. */ + (*bitMask) = Generate_Random_Bit_Mask(0); + + /* Generate the byteToCheck and bitValues data. (If needed, check memory addresses.) */ + if (byteToCheck != bitMask) + { + (*byteToCheck) = Generate_Random_Bits((*bitMask)); + + /* Bitwise Or the bitMask to the byteToCheck data. */ + (*byteToCheck) |= (*bitMask); + } + if ((bitValues != bitMask) && (bitValues != byteToCheck)) + { + (*bitValues) = Generate_Random_Bits((*byteToCheck)); + + /* Bitwise Or the bitMask to the bitValues data. */ + (*bitValues) |= (*bitMask); + } + + /* Done. */ + ret = COMMON_ERROR_SUCCESS; + } + else + { + /* Invalid arguments. */ + ret = COMMON_ERROR_INVALID_ARGUMENT; + } + + /* Exit function. */ + return ret; +} + +int unit_test_byte_order_Common_Print_Bytes_In_Binary_check() +{ + /* Init vars. */ + int ret = 0; /* The result of this function. */ + + + + /* Exit function. */ + return ret; +} + +int unit_test_byte_order_comparison_check() +{ + /* Init vars. */ + int ret = 0; /* The result of this function. */ + char byteToCheck = '\0'; /* The byte to compare against. */ + char bitMask = '\0'; /* The bits we should compare. */ + char bitValues = '\0'; /* The bits we compare to. */ + char extraBits = '\0'; /* Used to generate extra random bits to test with. */ + + /* Run zero comparison checks. */ + std::cout << "Byte_Order_Bit_Comparison() Test 1: All zero, no bits to check test. (Should result in COMMON_ERROR_COMPARISON_FAILED.): "; + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_FAILED) + { + /* Test 1 successful. */ + std::cout << "PASS\n"; + std::cout << "Byte_Order_Bit_Comparison() Test 2: All zero, check all bits test. (Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + bitMask = CHAR_MIN; + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 2 successful. */ + std::cout << "PASS\n"; + + /* Generate random bit mask. */ + std::cout << "Byte_Order_Bit_Comparison() Test 3: All zero, random bit mask test.\n"; + bitMask = Generate_Random_Bit_Mask(0); + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform all zero test with random bit mask. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 3 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 4: Non-zero matching bits, no bits to check test. (Should result in COMMON_ERROR_COMPARISON_FAILED.): "; + /* Begin checks on non-zero bit values. */ + bitMask = 0; + bitValues = 1; + byteToCheck = 1; + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_FAILED) + { + /* Test 4 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 5: Non-zero matching bits, check bits test. (Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + bitMask = 1; + + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 5 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 6: Non-zero matching bits, extra bits in byte, check bits test.\n"; + Generate_Matching_Bitmask_Random_Data(&byteToCheck, &bitMask, &bitMask); + bitValues = bitMask; /* Only the bits in the bit mask should be set in bitValues. */ + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform Non-zero matching bits, extra bits in byte, check bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 6 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 7: Non-zero matching bits, extra bits in bitValues, check bits test.\n"; + Generate_Matching_Bitmask_Random_Data(&bitMask, &bitMask, &bitValues); + byteToCheck = bitMask; /* Only the bits in the bit mask should be set in byteToCheck. */ + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform Non-zero matching bits, extra bits in bitValues, check bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 7 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 8: Non-zero matching bits, extra bits in byte and bitValues, check bits test.\n"; + Generate_Matching_Bitmask_Random_Data(&byteToCheck, &bitMask, &bitValues); + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform Non-zero matching bits, extra bits in byte and bitValues, check bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 8 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 9: Non-zero matching bits, extra bits in byte and bitValues, random bitmask check bits test.\n"; + extraBits = Generate_Random_Bits(0); + + /* Binary OR the bits together so that the bits we check for will be valid. */ + byteToCheck = 0; + byteToCheck |= extraBits; + extraBits = Generate_Random_Bits(0); + + /* Binary OR the bits together so that the bits we check for will be valid. */ + bitValues = 0; + bitValues |= extraBits; + + /* Generate random bit mask. */ + bitMask = Generate_Random_Bit_Mask(0); + + /* Binary OR the bits together so that the bits we check for will be valid. */ + byteToCheck |= bitMask; + bitValues |= bitMask; + + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform Non-zero matching bits, extra bits in byte and bitValues, random bitmask check bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 9 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 10: Non-zero NON-matching bits, extra bits in byte and bitValues, random bitmask check bits test.\n"; + extraBits = Generate_Random_Bits(0); + + /* Binary OR the bits together so that the bits we check for will be valid. */ + byteToCheck = 0; + byteToCheck |= extraBits; + extraBits = Generate_Random_Bits(byteToCheck); + + /* Binary OR the bits together so that the bits we check for will be valid. */ + bitValues = 0; + bitValues |= extraBits; + + /* Generate random bit mask. */ + bitMask = Generate_Random_Non_Conforming_Bit_Mask(byteToCheck, bitValues); + + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_FAILED.): "; + + /* Perform Non-zero NON-matching bits, extra bits in byte and bitValues, random bitmask check bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_FAILED) + { + /* Test 10 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 11: All bits set, check all bits test. (Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + bitMask = UCHAR_MAX; + byteToCheck = UCHAR_MAX; + bitValues = UCHAR_MAX; + + /* Perform All bits set, check all bits test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 11 successful. */ + std::cout << "PASS\n"; + std::cout << "Byte_Order_Bit_Comparison() Test 12: All bits set, no bits to check test. (Should result in COMMON_ERROR_COMPARISON_FAILED.): "; + bitMask = 0; + + /* Perform All bits set, no bits to check test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_FAILED) + { + /* Test 12 successful. */ + std::cout << "PASS\n"; + + std::cout << "Byte_Order_Bit_Comparison() Test 13: All bits set, random bit mask test.\n"; + bitMask = Generate_Random_Bit_Mask(0); + Print_Bits_and_BitMask(byteToCheck, bitMask, bitValues); + std::cout << "(Should result in COMMON_ERROR_COMPARISON_PASSED.): "; + + /* Perform All bits set, random bit mask test. */ + if (Byte_Order_Bit_Comparison(&byteToCheck, bitMask, bitValues) == COMMON_ERROR_COMPARISON_PASSED) + { + /* Test 13 successful. */ + std::cout << "PASS\n"; + + /* End of tests. */ + ret = 0; + } + else + { + /* All bits set, random bit mask test failed. */ + ret = -13; + std::cout << "FAIL\n"; + } + } + else + { + /* All bits set, no bits to check test failed. */ + ret = -12; + std::cout << "FAIL\n"; + } + } + else + { + /* All bits set, check all bits test failed. */ + ret = -11; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero NON-matching bits, extra bits in byte and bitValues, random bitmask check bits test failed. */ + ret = -10; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, extra bits in byte and bitValues, random bitmask check bits test failed. */ + ret = -9; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, extra bits in byte and bitValues, check bits test failed. */ + ret = -8; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, extra bits in bitValues, check bits test failed. */ + ret = -7; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, extra bits in byte, check bits test failed. */ + ret = -6; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, check bits test failed. */ + ret = -5; + std::cout << "FAIL\n"; + } + } + else + { + /* Non-zero matching bits, no bits to check test failed. */ + ret = -4; + std::cout << "FAIL\n"; + } + } + else + { + /* All zero, random bit mask test failed. */ + ret = -3; + std::cout << "FAIL\n"; + } + } + else + { + /* All zero, check all bits test failed. */ + ret = -2; + std::cout << "FAIL\n"; + } + } + else + { + /* All zero no bits to check test failed. */ + ret = -1; + std::cout << "FAIL\n"; + } + + /* Flush output buffer. */ + std::cout.flush(); + + /* Exit function. */ + return ret; +} + +int Unit_Test_Byte_Order_Main() +{ + /* Init vars. */ + int ret = 0; /* The result of this function. */ + int result_comparision_check = 0; /* The result of the comparison checks. */ + + /* Output START OF TEST SECTION. */ + std::cout << START_TEST_SECTION; + + /* Run comparison checks. */ + result_comparision_check = unit_test_byte_order_comparison_check(); + + /* Output END OF TEST SECTION. */ + std::cout << END_TEST_SECTION; + + /* Exit function. */ + return ret; +} diff --git a/src/Tests/Unit_Test_Common.h b/src/Tests/Unit_Test_Common.h index d72fb95..20c1a9d 100644 --- a/src/Tests/Unit_Test_Common.h +++ b/src/Tests/Unit_Test_Common.h @@ -23,6 +23,8 @@ #define COMMON_UNIT_TESTS_H /* Include headers from Common. (If needed.) */ +#include "Unit_Tests_Byte_Order.h" + #ifdef MSYS_HAVE_FILEUTILLS #include "Unit_Tests_FileUtills.h" #endif /* MSYS_HAVE_FILEUTILLS */ diff --git a/src/Tests/Unit_Tests.cpp b/src/Tests/Unit_Tests.cpp index 56f4df9..e7b52e4 100644 --- a/src/Tests/Unit_Tests.cpp +++ b/src/Tests/Unit_Tests.cpp @@ -27,12 +27,16 @@ int main() short error_code_data_object = 0; short error_code_fileutills = 0; short error_code_thread_utils = 0; + int error_code_byte_order = 0; // Starting Unit tests. std::cout << "Multiverse_Engine_Project_Public Unit Tests Compiled on: " << TESTCOMPILEDATE << " " << TESTCOMPILETIME << "\n"; std::cout << "Starting Unit tests for DataProcess::Data_Object. Please be pacent this can take some time.\n"; error_code_data_object = Unit_Test_Data_Object(); + std::cout << "Starting unit tests for Byte_Order. Please wait.\n"; + error_code_byte_order = Unit_Test_Byte_Order_Main(); + /* Only call FileUtills tests if FileUtills was built. */ #ifdef MSYS_HAVE_FILEUTILLS std::cout << "Starting FileUtills Tests.\n"; diff --git a/src/Tests/Unit_Tests_Byte_Order.h b/src/Tests/Unit_Tests_Byte_Order.h new file mode 100644 index 0000000..6f57575 --- /dev/null +++ b/src/Tests/Unit_Tests_Byte_Order.h @@ -0,0 +1,80 @@ +/*! + Multiverse Engine Project 11/7/2015 Unit Tests Unit_Tests_Byte_Order.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef UNIT_TESTS_BYTE_ORDER_H +#define UNIT_TESTS_BYTE_ORDER_H + +/* Internal includes. */ +#include "../Common/Src/Byte_Order/Byte_Order.h" + +/* Define test functions. */ +/*! + * void Print_Random_Bits(const char bits) + * + * Wrapper around Common_Print_Bytes_In_Binary() and + * Common_Deallocate_Print_Bytes_CString() to print + * the given byte to the standard output. + * + * This function has no return. + */ +void Print_Random_Bits(const char bits); + +/*! + * char Generate_Random_Bit_Mask(const char bitMask) + * + * Generates some random bits between 1 and 254, retrying if it + * generates the given bitMask, while telling the user + * it is doing so. + * + * Returns the generated bit mask. + */ +char Generate_Random_Bit_Mask(const char bitMask); + +/*! + * char Generate_Random_Bits(const char notThisValue) + * + * Generates some random bits between 2 and 254, retrying if it + * generates the given notThisValue, while telling the user + * it is doing so. + * + * Returns the generated bits. + */ +char Generate_Random_Bits(const char notThisValue); + +int unit_test_byte_order_Common_Print_Bytes_In_Binary_check(); + +/*! + * int unit_test_byte_order_comparison_check() + * + * Performs tests on the Byte_Order_Bit_Comparison() function. + */ +int unit_test_byte_order_comparison_check(); + +/*! + * int Unit_Test_Byte_Order_Main() + * + * Main test function for Byte_Order. + */ +int Unit_Test_Byte_Order_Main(); + +#endif /* UNIT_TESTS_BYTE_ORDER_H */ + +/* End of Unit_Tests_Byte_Order.h */ From c7b9ebd95ce9f169fd2cc13395a185ddb6a8a930 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 02:13:13 -0400 Subject: [PATCH 033/134] Move DataProcess_Endianness_Check into it's own headers. This commit adds DataProcess_Endianness_Check into the error_handler branch, while also moving it into it's own files. --- src/Core/Src/CMakeLists.txt | 8 +- src/Core/Src/DataProcess.h | 3 + src/Core/Src/DataProcess_Endianness_Check.cpp | 126 ++++++++++++++++++ src/Core/Src/DataProcess_Endianness_Check.h | 68 ++++++++++ 4 files changed, 203 insertions(+), 2 deletions(-) create mode 100644 src/Core/Src/DataProcess_Endianness_Check.cpp create mode 100644 src/Core/Src/DataProcess_Endianness_Check.h diff --git a/src/Core/Src/CMakeLists.txt b/src/Core/Src/CMakeLists.txt index 800ab92..a77611e 100644 --- a/src/Core/Src/CMakeLists.txt +++ b/src/Core/Src/CMakeLists.txt @@ -6,7 +6,11 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${O_OUTPUT_DIR}) add_library(Panic_Handler_Multiverse_Engine SHARED Panic.cpp) add_library(Panic_Handler_Multiverse_Engine_Static STATIC Panic.cpp) -add_library(Core_Multiverse_Engine SHARED DataProcess.cpp FileStreams.cpp) -add_library(Core_Multiverse_Engine_Static STATIC DataProcess.cpp FileStreams.cpp) +add_library(Core_Multiverse_Engine SHARED DataProcess.cpp +DataProcess_Endianness_Check.cpp +FileStreams.cpp) +add_library(Core_Multiverse_Engine_Static STATIC DataProcess.cpp +DataProcess_Endianness_Check.cpp +FileStreams.cpp) target_link_libraries(Core_Multiverse_Engine Panic_Handler_Multiverse_Engine) target_link_libraries(Core_Multiverse_Engine_Static Panic_Handler_Multiverse_Engine_Static) diff --git a/src/Core/Src/DataProcess.h b/src/Core/Src/DataProcess.h index a7d7fe5..29e5215 100644 --- a/src/Core/Src/DataProcess.h +++ b/src/Core/Src/DataProcess.h @@ -18,11 +18,14 @@ https://github.com/codebase7/mengine */ +/* Include guard. */ #ifndef DATAPROCESS_H #define DATAPROCESS_H +/* Internal includes. */ #include "BaseHeader.h" #include "Panic.h" +#include "DataProcess_Endianness_Check.h" namespace DataProcess{ diff --git a/src/Core/Src/DataProcess_Endianness_Check.cpp b/src/Core/Src/DataProcess_Endianness_Check.cpp new file mode 100644 index 0000000..f30da8f --- /dev/null +++ b/src/Core/Src/DataProcess_Endianness_Check.cpp @@ -0,0 +1,126 @@ +/*! + Multiverse Engine Project 11/7/2015 DataProcess DataProcess_Endianness_Check.cpp + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include internal header. */ +#include "DataProcess_Endianness_Check.h" + +template +int DataProcess_Endianness_Check(const T & a) +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + T t = 1; /* Variable to check. */ + + /* Cast t to a char string and see if the result is 1. */ + if (((char*)&t)[0]) + { + /* The first byte is 1 so it's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + else + { + /* + * The first byte is 0 so, check and see if the last byte is non-zero. + * If it is, then the host is big endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if (((char*)&t)[((sizeof(t)) - 1)]) + { + /* It's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +template<> +int DataProcess_Endianness_Check(const float & a) +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + float t = 1.0; /* Variable to check. */ + + /* Cast t to a char string and see if the first 2 values are 0x3F80. */ + if ((((char*)&t)[0] == 0x3F) && ((((char*)&t)[1] == 0x80))) + { + /* The first 2 bytes are 0x3F80 so it's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + else + { + /* + * The first check did not pass, so check and see if the last 2 bytes are 0x803F. + * If they are, then the host is little endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if ((((char*)&t)[(sizeof (float) - 1)] == 0x80) && ((((char*)&t)[(sizeof (float) - 2)] == 0x3F))) + { + /* It's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +template<> +int DataProcess_Endianness_Check(const double & a) +{ + /* Init vars. */ + int ret = MSYS_UNKNOWN_ENDIANNESS; /* The result of this function. */ + double t = 1.0; /* Variable to check. */ + + /* Cast t to a char string and see if the first 2 values are 0x3FF0. */ + if ((((char*)&t)[0] == 0x3F) && ((((char*)&t)[1] == 0xF0))) + { + /* The first 2 bytes are 0x3F80 so it's big endian. */ + ret = MSYS_BIG_ENDIAN; + } + else + { + /* + * The first check did not pass, so check and see if the last 2 bytes are 0xF03F. + * If they are, then the host is little endian. + * + * Otherwise the host is using something like middle-endian to store + * the value, but we would need more checks to determine what exact + * kind of endianness the host is using. + */ + if ((((char*)&t)[(sizeof (double) - 1)] == 0xF0) && ((((char*)&t)[(sizeof (double) - 2)] == 0x3F))) + { + /* It's little endian. */ + ret = MSYS_LITTLE_ENDIAN; + } + } + + /* Return the result. */ + return ret; +} + +/* End of DataProcess_Endianness_Check.cpp */ diff --git a/src/Core/Src/DataProcess_Endianness_Check.h b/src/Core/Src/DataProcess_Endianness_Check.h new file mode 100644 index 0000000..148e5c5 --- /dev/null +++ b/src/Core/Src/DataProcess_Endianness_Check.h @@ -0,0 +1,68 @@ +/*! + Multiverse Engine Project 11/7/2015 DataProcess DataProcess_Endianness_Check.h + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Include guard. */ +#ifndef DATAPROCESS_ENDIANNESS_CHECK_H +#define DATAPROCESS_ENDIANNESS_CHECK_H + +/* Define Endianness Result Values. */ +#define MSYS_BIG_ENDIAN 0 +#define MSYS_LITTLE_ENDIAN 1 +#define MSYS_UNKNOWN_ENDIANNESS 2 + +/* Define namespace. */ +namespace DataProcess { + +/*! + * template + * int DataProcess_Endianness_Check(T & a) + * + * Template function which checks the host's endianness for the + * given argument's data type. + * + * Note: The given argument is not altered or used by the function. + * It's only used to exploit the C++ template generator. + * + * The specializations for float and double are required as floating + * point data types must be detected differently from integers. + * + * Returns MSYS_BIG_ENDIAN if the given data type is stored as big + * endian on the host machine. + * + * Returns MSYS_LITTLE_ENDIAN if the given data type stored as little + * endian on the host machine. + * + * Returns MSYS_UNKNOWN_ENDIANNESS if the given data type's byte ordering + * is unknown for the given host. + */ +template +int DataProcess_Endianness_Check(const T & a); + +template<> +int DataProcess_Endianness_Check(const float & a); + +template<> +int DataProcess_Endianness_Check(const double & a); + +} /* namespace DataProcess */ + +#endif /* DATAPROCESS_ENDIANNESS_CHECK_H */ + +/* End of DataProcess_Endianness_Check.h */ From 413c012ed34f0dc2c9e8753827bf659c67ed9b04 Mon Sep 17 00:00:00 2001 From: codebase7 Date: Fri, 7 Aug 2015 04:36:52 -0400 Subject: [PATCH 034/134] Create DataProcess.c This commit creates a seperate file (DataProcess.c) for the DataProcess code that can be used by a C program. The point of this is to allow the use of some DataProcess functionality by C programs where possible. To kickoff the new DataProcess.c file, this commit also moves the DataProces::Trivial_Random_Number_Generator() function code to the new C file and renames it to DataProcess_Trivial_Random_Number_Generator(). The original DataProcess::Trivial_Random_Number_Generator() function now acts as a wrapper to the DataProcess_Trivial_Random_Number_Generator() C function. --- src/Core/Src/CMakeLists.txt | 2 ++ src/Core/Src/DataProcess.c | 55 ++++++++++++++++++++++++++++++++++++ src/Core/Src/DataProcess.cpp | 22 ++------------- src/Core/Src/DataProcess.h | 49 +++++++++++++++++++++++--------- 4 files changed, 95 insertions(+), 33 deletions(-) create mode 100644 src/Core/Src/DataProcess.c diff --git a/src/Core/Src/CMakeLists.txt b/src/Core/Src/CMakeLists.txt index a77611e..bfeda7c 100644 --- a/src/Core/Src/CMakeLists.txt +++ b/src/Core/Src/CMakeLists.txt @@ -7,9 +7,11 @@ add_library(Panic_Handler_Multiverse_Engine SHARED Panic.cpp) add_library(Panic_Handler_Multiverse_Engine_Static STATIC Panic.cpp) add_library(Core_Multiverse_Engine SHARED DataProcess.cpp +DataProcess.c DataProcess_Endianness_Check.cpp FileStreams.cpp) add_library(Core_Multiverse_Engine_Static STATIC DataProcess.cpp +DataProcess.c DataProcess_Endianness_Check.cpp FileStreams.cpp) target_link_libraries(Core_Multiverse_Engine Panic_Handler_Multiverse_Engine) diff --git a/src/Core/Src/DataProcess.c b/src/Core/Src/DataProcess.c new file mode 100644 index 0000000..f1f735d --- /dev/null +++ b/src/Core/Src/DataProcess.c @@ -0,0 +1,55 @@ +/*! + Multiverse Engine Project DataProcess DataProcess.c 07/8/2015 + + Copyright (C) 2015 Multiverse Engine Project + + This program is free software; + you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; + either version 2 of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with this program; + if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Official source repository and project information can be found at + https://github.com/codebase7/mengine +*/ + +/* Set extern C. */ +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* Internal includes. */ +#include "DataProcess.h" + +/* External includes. */ +#include