Elements  6.0.1
A C++ base framework for the Euclid Software.
System.h
Go to the documentation of this file.
1 
31 #ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
32 #define ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
33 
34 // STL include files
35 #include <climits>
36 #include <memory>
37 #include <string>
38 #include <typeinfo>
39 #include <vector>
40 
41 // Framework include files
42 #include "ElementsKernel/Export.h" // ELEMENTS_API
43 #include "ElementsKernel/Unused.h" // ELEMENTS_UNUSED
44 
45 namespace Elements {
46 namespace System {
47 
48 // --------------------------------------------------------------------------------------
49 // various constants
50 // --------------------------------------------------------------------------------------
51 
55 #if defined(__APPLE__)
56 const std::string SHLIB_VAR_NAME{"DYLD_LIBRARY_PATH"};
57 #else
58 const std::string SHLIB_VAR_NAME{"LD_LIBRARY_PATH"};
59 #endif
60 
64 const std::string LIB_PREFIX{"lib"};
65 
69 #ifdef __APPLE__
70 const std::string LIB_EXTENSION{"dylib"};
71 #else
73 #endif
74 
80 
85 
91 
92 const int STACK_OFFSET{2};
93 
94 #if defined(__linux__) || defined(__APPLE__)
95 #define TEMPLATE_SPECIALIZATION
96 #endif
97 
98 #ifndef HOST_NAME_MAX
99 
100 #ifdef _POSIX_HOST_NAME_MAX
101 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
102 #else
103 #define HOST_NAME_MAX 255
104 #endif
105 
106 #endif
107 
109 using ImageHandle = void*;
111 using ProcessHandle = void*;
113 using EntryPoint = unsigned long (*)(const unsigned long iid, void** ppvObject);
115 using Creator = void* (*)();
116 
118 ELEMENTS_API unsigned long loadDynamicLib(const std::string& name, ImageHandle* handle);
120 ELEMENTS_API unsigned long unloadDynamicLib(ImageHandle handle);
122 ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, EntryPoint* pFunction);
124 ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, Creator* pFunction);
126 ELEMENTS_API unsigned long getLastError();
130 ELEMENTS_API const std::string getErrorString(unsigned long error);
133 ELEMENTS_API const std::string typeinfoName(const char*);
146 ELEMENTS_API bool getEnv(const std::string& var, std::string& value);
154 ELEMENTS_API int setEnv(const std::string& name, const std::string& value, bool overwrite = true);
156 ELEMENTS_API int unSetEnv(const std::string& name);
158 ELEMENTS_API bool isEnvSet(const std::string& var);
159 
161 ELEMENTS_API const std::vector<std::string> backTrace(const int depth, const int offset = 0);
162 
163 ELEMENTS_API bool getStackLevel(ELEMENTS_UNUSED void* addresses, ELEMENTS_UNUSED void*& addr,
165 
166 } // namespace System
167 } // namespace Elements
168 
169 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
170 
defines the macros to be used for explicit export of the symbols
Macro to silence unused variables warnings from the compiler.
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74
#define ELEMENTS_UNUSED
Definition: Unused.h:39
ELEMENTS_API bool isEnvSet(const std::string &var)
Check if an environment variable is set or not.
Definition: System.cpp:348
const std::string SHLIB_SUFFIX
alias for LIB_SUFFIX
Definition: System.h:84
unsigned long(*)(const unsigned long iid, void **ppvObject) EntryPoint
Definition of the "generic" DLL entry point function.
Definition: System.h:113
const std::string DEFAULT_INSTALL_PREFIX
constant for the canonical installation prefix (on Linux and MacOSX at least)
Definition: System.h:90
const std::string LIB_SUFFIX
constant that represents the standard suffix of the libraries: usually "."+LIB_EXTENSION
Definition: System.h:79
ELEMENTS_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:166
void * ImageHandle
Definition of an image handle.
Definition: System.h:109
ELEMENTS_API int setEnv(const std::string &name, const std::string &value, bool overwrite=true)
set an environment variables.
Definition: System.cpp:370
ELEMENTS_API bool getStackLevel(ELEMENTS_UNUSED void *addresses, ELEMENTS_UNUSED void *&addr, ELEMENTS_UNUSED std::string &fnc, ELEMENTS_UNUSED std::string &lib)
ELEMENTS_API unsigned long unloadDynamicLib(ImageHandle handle)
unload dynamic link library
Definition: System.cpp:115
ELEMENTS_API int backTrace(ELEMENTS_UNUSED std::shared_ptr< void * > addresses, ELEMENTS_UNUSED const int depth)
const std::string SHLIB_VAR_NAME
name of the shared dynamic library path
Definition: System.h:58
ELEMENTS_API unsigned long getLastError()
Get last system known error.
Definition: System.cpp:154
ELEMENTS_API const std::string & osName()
OS name.
Definition: System.cpp:290
ELEMENTS_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:88
ELEMENTS_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:187
ELEMENTS_API int unSetEnv(const std::string &name)
Simple wrap around unsetenv for strings.
Definition: System.cpp:380
ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:124
ELEMENTS_API std::string getEnv(const std::string &var)
get a particular environment variable
Definition: System.cpp:325
ELEMENTS_API const std::string & osVersion()
OS version.
Definition: System.cpp:302
ELEMENTS_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:160
ELEMENTS_API const std::string & machineType()
Machine type.
Definition: System.cpp:314
void *(*)() Creator
Definition of the "generic" DLL entry point function.
Definition: System.h:115
const std::string LIB_PREFIX
constant that represent the common prefix of the libraries
Definition: System.h:64
void * ProcessHandle
Definition of the process handle.
Definition: System.h:111
const std::string LIB_EXTENSION
constant that represent the common extension of the libraries
Definition: System.h:72
ELEMENTS_API const std::string & hostName()
Host name.
Definition: System.cpp:279
const int STACK_OFFSET
Definition: System.h:92