Elements  5.8
A C++ base framework for the Euclid Software.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 <vector>
36 #include <typeinfo>
37 #include <string>
38 #include <memory>
39 #include <climits>
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
72  const std::string LIB_EXTENSION { "so" };
73 #endif
74 
80 
85 
91 
92 #if defined(__OPTIMIZE__) && defined(__clang__)
93  const int STACK_OFFSET {1};
94 #else
95 # ifdef __APPLE__
96  const int STACK_OFFSET {4};
97 # else
98  const int STACK_OFFSET {2};
99 # endif
100 #endif
101 
102 #if defined(__linux__) || defined(__APPLE__)
103 #define TEMPLATE_SPECIALIZATION
104 #endif
105 
106 #ifndef HOST_NAME_MAX
107 
108 #ifdef _POSIX_HOST_NAME_MAX
109 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
110 #else
111 #define HOST_NAME_MAX 255
112 #endif
113 
114 #endif
115 
116 
118 using ImageHandle = void*;
120 using ProcessHandle = void*;
122 using EntryPoint = unsigned long (*)(const unsigned long iid, void** ppvObject);
124 using Creator = void* (*)();
125 
126 
128 ELEMENTS_API unsigned long loadDynamicLib(const std::string& name,
129  ImageHandle* handle);
131 ELEMENTS_API unsigned long unloadDynamicLib(ImageHandle handle);
133 ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle,
134  const std::string& name, EntryPoint* pFunction);
136 ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle,
137  const std::string& name, Creator* pFunction);
139 ELEMENTS_API unsigned long getLastError();
143 ELEMENTS_API const std::string getErrorString(unsigned long error);
146 ELEMENTS_API const std::string typeinfoName(const char*);
159 ELEMENTS_API bool getEnv(const std::string& var, std::string &value);
167 ELEMENTS_API int setEnv(const std::string &name, const std::string &value,
168  bool overwrite = true);
170 ELEMENTS_API int unSetEnv(const std::string& name);
172 ELEMENTS_API bool isEnvSet(const std::string& var);
173 
175 ELEMENTS_API bool backTrace(std::string& btrace, const int depth, const int offset = 0);
176 ELEMENTS_API const std::vector<std::string> backTrace(const int depth, const int offset = 0);
177 
178 ELEMENTS_API bool getStackLevel(ELEMENTS_UNUSED void* addresses, ELEMENTS_UNUSED void*& addr,
180 
181 } // namespace System
182 } // namespace Elements
183 
184 #endif // ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
185 
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 getLastError()
Get last system known error.
Definition: System.cpp:157
const std::string LIB_EXTENSION
constant that represent the common extension of the libraries
Definition: System.h:72
Macro to silence unused variables warnings from the compiler.
ELEMENTS_API unsigned long unloadDynamicLib(ImageHandle handle)
unload dynamic link library
Definition: System.cpp:116
ELEMENTS_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:163
void *(*)( Creator)
Definition of the &quot;generic&quot; DLL entry point function.
Definition: System.h:124
ELEMENTS_API int setEnv(const std::string &name, const std::string &value, bool overwrite=true)
set an environment variables.
Definition: System.cpp:377
const std::string LIB_SUFFIX
constant that represents the standard suffix of the libraries: usually &quot;.&quot;+LIB_EXTENSION ...
Definition: System.h:79
STL class.
ELEMENTS_API bool isEnvSet(const std::string &var)
Check if an environment variable is set or not.
Definition: System.cpp:355
defines the macros to be used for explicit export of the symbols
void * ImageHandle
Definition of an image handle.
Definition: System.h:118
ELEMENTS_API std::string getEnv(const std::string &var)
get a particular environment variable
Definition: System.cpp:331
ELEMENTS_API const std::string & osVersion()
OS version.
Definition: System.cpp:308
ELEMENTS_API int unSetEnv(const std::string &name)
Simple wrap around unsetenv for strings.
Definition: System.cpp:388
#define ELEMENTS_API
Dummy definitions for the backward compatibility mode.
Definition: Export.h:74
ELEMENTS_API const std::string getErrorString(unsigned long error)
Retrieve error code as string for a given error.
Definition: System.cpp:169
const int STACK_OFFSET
Definition: System.h:98
ELEMENTS_API int backTrace(ELEMENTS_UNUSED std::shared_ptr< void * > addresses, ELEMENTS_UNUSED const int depth)
Definition: System.cpp:396
const std::string SHLIB_VAR_NAME
name of the shared dynamic library path
Definition: System.h:58
ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string &name, EntryPoint *pFunction)
Get a specific function defined in the DLL.
Definition: System.cpp:125
ELEMENTS_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
Definition: System.cpp:191
void * ProcessHandle
Definition of the process handle.
Definition: System.h:120
const std::string LIB_PREFIX
constant that represent the common prefix of the libraries
Definition: System.h:64
const std::string DEFAULT_INSTALL_PREFIX
constant for the canonical installation prefix (on Linux and MacOSX at least)
Definition: System.h:90
ELEMENTS_API const std::string & hostName()
Host name.
Definition: System.cpp:285
ELEMENTS_API const std::string & osName()
OS name.
Definition: System.cpp:296
#define ELEMENTS_UNUSED
Definition: Unused.h:39
unsigned long(*)(const unsigned long iid, void **ppvObject) EntryPoint
Definition of the &quot;generic&quot; DLL entry point function.
Definition: System.h:122
ELEMENTS_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:89
const std::string SHLIB_SUFFIX
alias for LIB_SUFFIX
Definition: System.h:84
ELEMENTS_API const std::string & machineType()
Machine type.
Definition: System.cpp:320