init
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#if defined TARGET_OS_Windows
|
||||
#include <windows.h>
|
||||
|
||||
namespace System {
|
||||
class System_API WindowsUtilities
|
||||
{
|
||||
public:
|
||||
// Load a library in a matter compliant with non-ascii path
|
||||
// returns the eventual error code
|
||||
static void* utf16CompliantLoadLibrary(const char* path, HANDLE file = nullptr, DWORD flags = LOAD_WITH_ALTERED_SEARCH_PATH);
|
||||
|
||||
static BOOL utf16CompliantSetEnvironmentVariable(const char* name, const char* value);
|
||||
|
||||
// Load a library in a matter compliant with non-ascii path
|
||||
// returns the eventual error code
|
||||
static BOOL utf16CompliantCreateProcess(char* applicationName, char* commandLine, LPSECURITY_ATTRIBUTES processAttributes,
|
||||
LPSECURITY_ATTRIBUTES threadAttributes, BOOL inheritHandles, DWORD creationFlags, LPVOID environment,
|
||||
char* currentDirectory, LPSTARTUPINFO startupInfo, LPPROCESS_INFORMATION processInformation);
|
||||
|
||||
// Load a library in a matter compliant with non-ascii path
|
||||
// returns the eventual error code
|
||||
static HINSTANCE utf16CompliantShellExecute(HWND hwnd, LPCTSTR operation, LPCTSTR file, LPCTSTR parameters, LPCTSTR directory, INT nShowCmd);
|
||||
private:
|
||||
WindowsUtilities() = delete;
|
||||
};
|
||||
} // namespace System
|
||||
|
||||
#endif // TARGET_OS_Windows
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include <ov_common_defines.h>
|
||||
|
||||
#if defined System_Shared
|
||||
# if defined TARGET_OS_Windows
|
||||
# define System_API_Export __declspec(dllexport)
|
||||
# define System_API_Import __declspec(dllimport)
|
||||
# elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
# define System_API_Export __attribute__((visibility("default")))
|
||||
# define System_API_Import __attribute__((visibility("default")))
|
||||
# else
|
||||
# define System_API_Export
|
||||
# define System_API_Import
|
||||
# endif
|
||||
#else
|
||||
# define System_API_Export
|
||||
# define System_API_Import
|
||||
#endif
|
||||
|
||||
#if defined System_Exports
|
||||
# define System_API System_API_Export
|
||||
#else
|
||||
# define System_API System_API_Import
|
||||
#endif
|
||||
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace System {
|
||||
class System_API CChrono final
|
||||
{
|
||||
public:
|
||||
|
||||
CChrono() { }
|
||||
~CChrono();
|
||||
|
||||
bool reset(size_t nStep);
|
||||
|
||||
bool stepIn();
|
||||
bool stepOut();
|
||||
|
||||
uint64_t getTotalStepInDuration() const;
|
||||
uint64_t getTotalStepOutDuration() const;
|
||||
uint64_t getAverageStepInDuration() const;
|
||||
uint64_t getAverageStepOutDuration() const;
|
||||
double getStepInPercentage() const;
|
||||
double getStepOutPercentage() const;
|
||||
|
||||
bool hasNewEstimation() const { return m_hasNewEstimation; }
|
||||
|
||||
private:
|
||||
|
||||
uint64_t* m_stepInTime = nullptr;
|
||||
uint64_t* m_stepOutTime = nullptr;
|
||||
size_t m_nStep = 0;
|
||||
size_t m_stepIdx = 0;
|
||||
bool m_isInStep = false;
|
||||
bool m_hasNewEstimation = false;
|
||||
|
||||
uint64_t m_totalStepInTime = 0;
|
||||
uint64_t m_totalStepOutTime = 0;
|
||||
};
|
||||
} // namespace System
|
||||
@@ -0,0 +1,264 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
#include <shlobj.h>
|
||||
#include <Dbghelp.h>
|
||||
#elif defined TARGET_OS_Linux
|
||||
#include <linux/limits.h>
|
||||
#elif defined TARGET_OS_MacOS
|
||||
#include <sys/syslimits.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace System {
|
||||
class CDynamicModuleSymbolLoader; // forward declare to make function declaration possible
|
||||
|
||||
class System_API CDynamicModule final
|
||||
{
|
||||
public:
|
||||
enum ELogErrorCodes : size_t
|
||||
{
|
||||
LogErrorCodes_NoError = 0,
|
||||
LogErrorCodes_ModuleAlreadyLoaded = 1,
|
||||
LogErrorCodes_NoModuleLoaded = 2,
|
||||
LogErrorCodes_FilenameEmpty = 3,
|
||||
LogErrorCodes_FolderPathInvalid = 4,
|
||||
LogErrorCodes_RegistryQueryFailed = 5,
|
||||
LogErrorCodes_UnloadModuleFailed = 6,
|
||||
LogErrorCodes_FailToLoadModule = 7,
|
||||
LogErrorCodes_InvalidSymbol = 8,
|
||||
LogErrorCodes_EnvironmentVariableInvalid = 9,
|
||||
LogErrorCodes_ModuleNotFound = 10
|
||||
};
|
||||
|
||||
CDynamicModule();
|
||||
~CDynamicModule();
|
||||
|
||||
/**
|
||||
* \brief Load module from a path.
|
||||
*
|
||||
* \param modulePath
|
||||
* \param symbolNameCheck Symbol to check if it is present in the module. It is optionnal and is nullptr by default.
|
||||
*
|
||||
* \retval true If the module loaded successfully.
|
||||
* \retval false If module loading failed.
|
||||
*/
|
||||
bool loadFromPath(const char* modulePath, const char* symbolNameCheck = nullptr);
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
/**
|
||||
* \brief Load existing module that was already loaded by the process.
|
||||
*
|
||||
* \param modulePath The path to the module.
|
||||
* \param symbolNameCheck Symbol to check if it is present in the module. It is optionnal and is nullptr by default.
|
||||
*
|
||||
* \retval true If the module loaded successfully.
|
||||
* \retval false If module loading failed.
|
||||
*/
|
||||
bool loadFromExisting(const char* modulePath, const char* symbolNameCheck = nullptr);
|
||||
/**
|
||||
* \brief Load module from known path. Windows only.
|
||||
*
|
||||
* \param standardPath A CSIDL value that identifies the folder whose path is to be retrieved.
|
||||
* Only real folders are valid. If a virtual folder is specified, this function fails.
|
||||
* You can force creation of a folder by combining the folder's CSIDL with CSIDL_FLAG_CREATE.
|
||||
* \param modulePath Path of the module to load.
|
||||
* \param symbolNameCheck Symbol to check if it is present in the module. It is optional and is nullptr by default.
|
||||
*
|
||||
* \retval true If the module loaded successfully.
|
||||
* \retval false If module loading failed.
|
||||
*/
|
||||
bool loadFromKnownPath(int standardPath, const char* modulePath, const char* symbolNameCheck = nullptr);
|
||||
|
||||
/**
|
||||
* \brief Load module from Windows environment. Windows only.
|
||||
*
|
||||
* \param environmentPath Environment path.
|
||||
* \param modulePath Module file path.
|
||||
* \param symbolNameCheck Symbol to check if it is present in the module. It is optionnal and is nullptr by default.
|
||||
*
|
||||
* \retval true If the module loaded successfully.
|
||||
* \retval false If module loading failed.
|
||||
*/
|
||||
bool loadFromEnvironment(const char* environmentPath, const char* modulePath, const char* symbolNameCheck = nullptr);
|
||||
|
||||
/**
|
||||
* \brief Load module from the registry. Windows only.
|
||||
*
|
||||
* \param key Registry key. Check https://msdn.microsoft.com/en-us/library/windows/desktop/ms724836
|
||||
* \param registryPath Registry path.
|
||||
* \param registryKeyName Key name.
|
||||
* \param samDesired A mask that specifies the desired access rights to the key to be opened.
|
||||
* The function fails if the security descriptor of the key does not permit the requested access for the calling process
|
||||
* Check https://msdn.microsoft.com/fr-fr/library/windows/desktop/ms724878
|
||||
* \param modulePath sModulePath Module path.
|
||||
* \param symbolNameCheck Symbol to check if it is present in the module. It is optionnal and is nullptr by default.
|
||||
*
|
||||
* \retval true If the module loaded successfully.
|
||||
* \retval false If module loading failed.
|
||||
*/
|
||||
bool loadFromRegistry(HKEY key, const char* registryPath, const char* registryKeyName, REGSAM samDesired, const char* modulePath,
|
||||
const char* symbolNameCheck = nullptr);
|
||||
|
||||
/**
|
||||
* \brief Check the module architecture. Windows only.
|
||||
* The architecture type of the computer. An image file can only be run on the specified computer or a system that emulates the specified computer.
|
||||
* This member can be one of the following values.
|
||||
* - x86: 0x014c
|
||||
* - x64: 0x8664
|
||||
* - ia64: 0x0200
|
||||
*
|
||||
* \param filePath Module file path
|
||||
* \param architecture Architecture code
|
||||
*
|
||||
* \retval true If the module architecture is equal to the architecture parameter.
|
||||
* \retval false If the module is unequal to the architecture parameter.
|
||||
*/
|
||||
static bool isModuleCompatible(const char* filePath, int architecture);
|
||||
#endif
|
||||
|
||||
// --------------------------------------
|
||||
|
||||
/**
|
||||
* \brief Unload the module. If setShouldFreeModule(false) is called, the unload() has no effect.
|
||||
*
|
||||
* \retval true In case of success.
|
||||
* \retval false In case of failure.
|
||||
*
|
||||
* \sa setShouldFreeModule
|
||||
* \sa isLoaded
|
||||
*/
|
||||
bool unload();
|
||||
|
||||
/**
|
||||
* \brief Check if the module is loaded.
|
||||
*
|
||||
* \retval true If the module is loaded.
|
||||
* \retval false If no module are loaded.
|
||||
*
|
||||
* \sa unload
|
||||
* \sa setShouldFreeModule
|
||||
*/
|
||||
bool isLoaded() const { return m_Handle != nullptr; }
|
||||
|
||||
/**
|
||||
* \brief Get the filename of the module.
|
||||
*
|
||||
* \return the file name of the module.
|
||||
*/
|
||||
const char* getFilename() const { return m_Filename; }
|
||||
|
||||
/**
|
||||
* \brief Should be used to avoid the warning "Missing dll" when loading acquisition server
|
||||
* This can happen when the loaded library needs a second library that is not detected.
|
||||
*
|
||||
* \param errorMode
|
||||
*/
|
||||
void setDynamicModuleErrorMode(const size_t errorMode) { m_ErrorMode = errorMode; }
|
||||
|
||||
/**
|
||||
* \brief Set if the module should, or not, be free. By default the module will be free.
|
||||
*
|
||||
* \param shouldFreeModule Set to true to free the module when unload is called. False otherwise.
|
||||
*
|
||||
* \sa unload
|
||||
*/
|
||||
void setShouldFreeModule(const bool shouldFreeModule) { m_ShouldFreeModule = shouldFreeModule; }
|
||||
|
||||
/**
|
||||
* \brief Get the last error code.
|
||||
*
|
||||
* \return The error code.
|
||||
*/
|
||||
size_t getLastError() const;
|
||||
|
||||
/**
|
||||
* \brief Get the error message corresponding to the error code.
|
||||
*
|
||||
* \param errorCode The error code.
|
||||
*
|
||||
* \return the message corresponding to the error code.
|
||||
*/
|
||||
static const char* getErrorString(size_t errorCode);
|
||||
|
||||
/**
|
||||
* \brief Get the detailed error
|
||||
*
|
||||
* \return A string with detailed information about the last error.
|
||||
*/
|
||||
const char* getErrorDetails() const;
|
||||
|
||||
private:
|
||||
void* m_Handle = nullptr;
|
||||
|
||||
#if defined TARGET_OS_Windows
|
||||
char m_Filename[MAX_PATH];
|
||||
#elif defined TARGET_OS_Linux || defined TARGET_OS_MacOS
|
||||
char m_Filename[PATH_MAX];
|
||||
#endif
|
||||
|
||||
size_t m_ErrorMode = 0;
|
||||
bool m_ShouldFreeModule = true;
|
||||
typedef void (*symbol_t)();
|
||||
|
||||
char m_ErrorDetails[1024];
|
||||
mutable ELogErrorCodes m_ErrorCode;
|
||||
|
||||
static const size_t m_ErrorModeNull = 0xffffffff;
|
||||
|
||||
friend class CDynamicModuleSymbolLoader;
|
||||
/**
|
||||
* \brief Set the error code and details.
|
||||
*
|
||||
* \param errorCode Error code.
|
||||
* \param details Detailed string error.
|
||||
*/
|
||||
void setError(ELogErrorCodes errorCode, const std::string& details = std::string());
|
||||
|
||||
/**
|
||||
* \brief Get a symbol from the module.
|
||||
*
|
||||
* \param symbolName Symbol name.
|
||||
*
|
||||
* \return The symbol.
|
||||
*/
|
||||
symbol_t getSymbolGeneric(const char* symbolName) const;
|
||||
|
||||
#ifdef TARGET_OS_Windows
|
||||
/**
|
||||
* \brief Get the image file headers. Windows only.
|
||||
*
|
||||
* \param filename The file path.
|
||||
* \param headers [out] The header.
|
||||
*
|
||||
* \retval true In case of success.
|
||||
* \retval false In case of failure.
|
||||
*/
|
||||
static bool getImageFileHeaders(const char* filename, IMAGE_NT_HEADERS& headers);
|
||||
#endif
|
||||
};
|
||||
|
||||
class CDynamicModuleSymbolLoader
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* \brief Get a symbol from the module.
|
||||
*
|
||||
* \param dynamicModule
|
||||
* \param symbolName The symbol name.
|
||||
* \param symbol [out] The symbol.
|
||||
*
|
||||
* \retval true If the symbol exists.
|
||||
* \retval false If the symbol does not exist.
|
||||
*/
|
||||
template <typename T>
|
||||
static bool getSymbol(CDynamicModule& dynamicModule, const char* symbolName, T* symbol)
|
||||
{
|
||||
*symbol = reinterpret_cast<T>(dynamicModule.getSymbolGeneric(symbolName));
|
||||
return *symbol != nullptr;
|
||||
}
|
||||
};
|
||||
} // namespace System
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace System {
|
||||
class System_API Math
|
||||
{
|
||||
public:
|
||||
|
||||
static bool initializeRandomMachine(size_t randomSeed);
|
||||
|
||||
static size_t randomI();
|
||||
// returns a value in [0,upperLimit( -- i.e. upperLimit not included in range
|
||||
static size_t randomWithCeiling(const size_t upperLimit);
|
||||
static double random0To1();
|
||||
static uint64_t random();
|
||||
|
||||
private:
|
||||
Math() = delete;
|
||||
};
|
||||
} // namespace System
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <cstdlib> // fix Unix compatibility
|
||||
|
||||
namespace System {
|
||||
class System_API Memory
|
||||
{
|
||||
public:
|
||||
|
||||
static bool hostToLittleEndian(uint16_t value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(uint32_t value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(uint64_t value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(int16_t value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(int value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(int64_t value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(float value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(double value, uint8_t* buffer);
|
||||
static bool hostToLittleEndian(long double value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(uint16_t value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(uint32_t value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(uint64_t value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(int16_t value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(int value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(int64_t value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(float value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(double value, uint8_t* buffer);
|
||||
static bool hostToBigEndian(long double value, uint8_t* buffer);
|
||||
|
||||
static bool littleEndianToHost(const uint8_t* buffer, uint16_t* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, uint32_t* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, uint64_t* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, int16_t* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, int* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, int64_t* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, float* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, double* value);
|
||||
static bool littleEndianToHost(const uint8_t* buffer, long double* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, uint16_t* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, uint32_t* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, uint64_t* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, int16_t* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, int* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, int64_t* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, float* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, double* value);
|
||||
static bool bigEndianToHost(const uint8_t* buffer, long double* value);
|
||||
|
||||
private:
|
||||
Memory() = delete;
|
||||
};
|
||||
} // namespace System
|
||||
@@ -0,0 +1,72 @@
|
||||
#pragma once
|
||||
|
||||
#include "defines.h"
|
||||
#include <cstdlib> // For Unix Compatibility
|
||||
|
||||
namespace System {
|
||||
/**
|
||||
* \class Time
|
||||
* \brief Static functions to handle time within the framework
|
||||
*
|
||||
*/
|
||||
class System_API Time
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* \brief Make the calling thread sleep
|
||||
* \param milliSeconds : sleep duration in ms
|
||||
* \return Always true
|
||||
*/
|
||||
static bool sleep(const size_t milliSeconds);
|
||||
|
||||
/**
|
||||
* \brief Make the calling thread sleep
|
||||
* \param seconds : sleep duration in fixed point 32:32 seconds
|
||||
* \return Always true
|
||||
*/
|
||||
static bool zsleep(const uint64_t seconds);
|
||||
|
||||
/**
|
||||
* \brief Retrieve time in ms (turn the 32:32 fixed point seconds to milliseconds).
|
||||
* \return Elapsed time in ms since the first call to this function or zgetTime functions
|
||||
*/
|
||||
static uint32_t getTime() { return uint32_t((zgetTime() * 1000) >> 32); }
|
||||
|
||||
/**
|
||||
* \brief Retrieve time in fixed point 32:32 seconds
|
||||
* \return Elapsed time since the first call to the zgetTime functions or getTime.
|
||||
*/
|
||||
static uint64_t zgetTime() { return zgetTimeRaw(true); }
|
||||
|
||||
/**
|
||||
* \brief Retrieve time in fixed point 32:32 seconds
|
||||
* \param sinceFirstCall: If sinceFirstCall is true, returns the time since the first call to the zgetTime function or getTime.
|
||||
* Otherwise, returns time since epoch of the clock.
|
||||
* \return Elapsed time
|
||||
*/
|
||||
static uint64_t zgetTimeRaw(bool sinceFirstCall = true);
|
||||
|
||||
/**
|
||||
* \brief Check if the internal clock used by the framework is steady
|
||||
* \return True if the clock is steady, false otherwise
|
||||
* \note This is a theoretical check that queries the internal
|
||||
* clock implementation for available services
|
||||
*/
|
||||
static bool isClockSteady();
|
||||
|
||||
/**
|
||||
* \brief Check if the internal clock used by the framework has
|
||||
* a resolution higher than the required one
|
||||
* \param milliSeconds : Expected clock resolution (period between ticks) in ms (must be non-zero value)
|
||||
* \return True if the clock meets the requirements, false otherwise
|
||||
* \note This is a theoretical check that queries the internal
|
||||
* clock implementation for available services
|
||||
*/
|
||||
static bool checkResolution(const size_t milliSeconds);
|
||||
|
||||
private:
|
||||
|
||||
Time() = delete;
|
||||
};
|
||||
} // namespace System
|
||||
Reference in New Issue
Block a user