forked from degauden/Elements
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSystem.h
More file actions
178 lines (153 loc) · 6.1 KB
/
Copy pathSystem.h
File metadata and controls
178 lines (153 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/**
* @file ElementsKernel/System.h
*
* @brief This file is intended to iron out all the
* differences between systems (currently Linux and MacOSX)
*
* @copyright 2012-2020 Euclid Science Ground Segment
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation; either version 3.0 of the License, or (at your option)
* any later version.
*
* This library 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 Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @details All the compilation system dependent parts (\#if, \#ifdef etc)
* should be located in this file. This should clear the need of these
* entities in all other C++ files.
*
*/
/**
* @addtogroup ElementsKernel ElementsKernel
* @{
*/
#ifndef ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
#define ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
// STL include files
#include <memory>
#include <string>
#include <typeinfo>
#include <vector>
// Framework include files
#include "ElementsKernel/Export.h" // ELEMENTS_API
#include "ElementsKernel/Stringify.h" // _str"
#include "ElementsKernel/Unused.h" // ELEMENTS_UNUSED
namespace Elements::System {
// --------------------------------------------------------------------------------------
// various constants
// --------------------------------------------------------------------------------------
/**
* @brief name of the shared dynamic library path
*/
#if defined(__APPLE__)
const std::string SHLIB_VAR_NAME{"DYLD_LIBRARY_PATH"};
#else
const std::string SHLIB_VAR_NAME{"LD_LIBRARY_PATH"};
#endif
/**
* @brief constant that represent the common prefix of the libraries
*/
const std::string LIB_PREFIX{"lib"};
/**
* @brief constant that represent the common extension of the libraries
*/
#ifdef __APPLE__
const std::string LIB_EXTENSION{"dylib"};
#else
const std::string LIB_EXTENSION{"so"};
#endif
/**
* @brief constant that represents the standard suffix of
* the libraries: usually "."+LIB_EXTENSION
*/
const std::string LIB_SUFFIX{"." + LIB_EXTENSION};
/**
* @brief alias for LIB_SUFFIX
*/
const std::string SHLIB_SUFFIX{LIB_SUFFIX};
/**
* @brief constant for the canonical installation prefix
* (on Linux and MacOSX at least)
*/
const std::string DEFAULT_INSTALL_PREFIX{"/usr"};
constexpr int STACK_OFFSET{2};
#if defined(__linux__) || defined(__APPLE__)
#define TEMPLATE_SPECIALIZATION
#endif
#ifndef HOST_NAME_MAX
#ifdef _POSIX_HOST_NAME_MAX
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
#else
#define HOST_NAME_MAX 255
#endif
#endif
#ifdef __aarch64__
#define Float128 _Float128
#define Float128_str _str(_Float128)
#else
#define Float128 __float128
#define Float128_str _str(__float128)
#endif
/// Definition of an image handle
using ImageHandle = void*;
using ConstImageHandle = const void*;
/// Definition of the process handle
using ProcessHandle = void*;
/// Definition of the "generic" DLL entry point function
using EntryPoint = unsigned long (*)(const unsigned long iid, void** ppvObject);
/// Definition of the "generic" DLL entry point function
using Creator = void* (*)();
/// Load dynamic link library
ELEMENTS_API unsigned long loadDynamicLib(const std::string& name, ImageHandle* handle);
/// unload dynamic link library
ELEMENTS_API unsigned long unloadDynamicLib(ImageHandle handle);
/// Get a specific function defined in the DLL
ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, EntryPoint* pFunction);
/// Get a specific function defined in the DLL
ELEMENTS_API unsigned long getProcedureByName(ImageHandle handle, const std::string& name, Creator* pFunction);
/// Get last system known error
ELEMENTS_API unsigned long getLastError();
/// Get last system error as string
ELEMENTS_API std::string getLastErrorString();
/// Retrieve error code as string for a given error
ELEMENTS_API std::string getErrorString(unsigned long error);
/// Get platform independent information about the class type
ELEMENTS_API std::string typeinfoName(const std::type_info&);
ELEMENTS_API std::string typeinfoName(const char*);
/// Host name
ELEMENTS_API const std::string& hostName();
/// OS name
ELEMENTS_API const std::string& osName();
/// OS version
ELEMENTS_API const std::string& osVersion();
/// Machine type
ELEMENTS_API const std::string& machineType();
/// get a particular environment variable
ELEMENTS_API std::string getEnv(const std::string& var);
/// get a particular environment variable, storing the value in the variable_value string if the
/// variable is set. Returns true if the variable is set, false otherwise.
ELEMENTS_API bool getEnv(const std::string& variable_name, std::string& variable_value);
/// get all environment variables
ELEMENTS_API std::vector<std::string> getEnv();
/// Set an environment variables.
/// If value is empty, the variable is removed from the environment.
/// When overwrite is 0, the variable is not set if already present.
/// Returns 0 on success, -1 on failure.
/// See man 3 setenv.
ELEMENTS_API int setEnv(const std::string& name, const std::string& value, bool overwrite = true);
/// Simple wrap around unsetenv for strings
ELEMENTS_API int unSetEnv(const std::string& name);
/// Check if an environment variable is set or not.
ELEMENTS_API bool isEnvSet(const std::string& variable_name);
ELEMENTS_API int backTrace(ELEMENTS_UNUSED const std::shared_ptr<void*>& addresses, ELEMENTS_UNUSED const int depth);
ELEMENTS_API std::vector<std::string> backTrace(const int depth, const int offset = 0);
ELEMENTS_API bool getStackLevel(ELEMENTS_UNUSED const void* addresses, ELEMENTS_UNUSED void*& addr,
ELEMENTS_UNUSED std::string& fnc, ELEMENTS_UNUSED std::string& lib);
} // namespace Elements::System
#endif // ELEMENTSKERNEL_ELEMENTSKERNEL_SYSTEM_H_
/**@}*/