COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
configCosmos.h
Go to the documentation of this file.
1 /********************************************************************
2 * Copyright (C) 2015 by Interstel Technologies, Inc.
3 * and Hawaii Space Flight Laboratory.
4 *
5 * This file is part of the COSMOS/core that is the central
6 * module for COSMOS. For more information on COSMOS go to
7 * <http://cosmos-project.com>
8 *
9 * The COSMOS/core software is licenced under the
10 * GNU Lesser General Public License (LGPL) version 3 licence.
11 *
12 * You should have received a copy of the
13 * GNU Lesser General Public License
14 * If not, go to <http://www.gnu.org/licenses/>
15 *
16 * COSMOS/core is free software: you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public License
18 * as published by the Free Software Foundation, either version 3 of
19 * the License, or (at your option) any later version.
20 *
21 * COSMOS/core is distributed in the hope that it will be useful, but
22 * WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * Refer to the "licences" folder for further information on the
27 * condititons and terms to use this software.
28 ********************************************************************/
29 
30 // ??? change to cosmos.h
31 #ifndef CONFIGCOSMOS_H
32 #define CONFIGCOSMOS_H
33 
34 // NB: EJP 20170403 - added to suppress the ocean of format errors that will never be correct for all
35 // platforms. We will just have to get the formatting right on our own.
36 //pragma GCC diagnostic ignored "-Wformat="
37 
40 
41 // ------------------------------------------------------------------
42 // Building under Windows
43 #ifdef _WIN32
44 
45 #define COSMOS_WIN_OS
46 
48 #ifdef _MSC_BUILD
49 #define COSMOS_WIN_BUILD_MSVC
50 #endif
51 
52 // TODO: Explain the reason why this is here
53 #define NTDDI_VERSION NTDDI_WIN7
54 
55 #ifndef _WIN32_WINNT
56  #define _WIN32_WINNT _WIN32_WINNT_WIN7
57 #endif
58 #define _WIN32_WINNT _WIN32_WINNT_WIN7
59 #endif // Building under Windows
60 
61 // for MSVC
62 #define _CRT_SECURE_NO_DEPRECATE
63 
64 // --------------------- FOR ALL PLATFORMS ------------------------------
65 #define _USE_MATH_DEFINES
66 #include <climits>
67 #include <csignal>
68 #include <cstdint>
69 #include <cinttypes>
70 #include <cstdio>
71 #include <cstddef>
72 #include <cstdlib>
73 #include <cerrno>
74 #include <cstring>
75 #include <cmath>
76 using std::isfinite;
77 //using std::isinf;
78 //using std::isnan;
79 #include <iosfwd>
80 using std::ifstream;
81 using std::ofstream;
82 #include <iostream>
83 using std::cout;
84 using std::cerr;
85 using std::endl;
86 #include <sstream>
87 using std::stringstream;
88 #include <regex>
89 #include <iomanip>
90 using std::fixed;
91 using std::setprecision;
92 using std::setw;
93 using std::left;
94 using std::right;
95 #ifdef COSMOS_WIN_BUILD_MSVC
96 #include <io.h> // replaces in some ways unistd for windows
97 #else
98 #include <unistd.h>
99 #endif
100 #include <fcntl.h>
101 
102 #include <limits>
103 #include <string>
104 using std::string;
105 using std::to_string;
106 #include <vector>
107 using std::vector;
108 #include <stack>
109 using std::stack;
110 #include <deque>
111 using std::deque;
112 #include <mutex>
113 using std::mutex;
114 using std::unique_lock;
115 #include <thread>
116 using std::thread;
117 #include <condition_variable>
118 using std::condition_variable;
119 #include <queue>
120 using std::queue;
121 #include <sstream>
122 using std::istringstream;
123 #include <map>
124 using std::map;
125 using std::pair;
126 
127 //#include "support/cosmos-errno.h"
128 #include "support/cosmos-defs.h"
129 
130 namespace Cosmos { namespace Support {} }
131 
132 using namespace Cosmos;
133 using namespace Cosmos::Support;
134 
139 #define COSMOS_SIZEOF(element) (reinterpret_cast<ptrdiff_t>(((element*)0)+1))
140 
142 
143 // To check the OS Pre-defined Compiler Macros go to
144 // http://sourceforge.net/p/predef/wiki/OperatingSystems/
145 
146 // --------------------- LINUX ------------------------------------
147 // linux definition can be UNIX or __unix__ or LINUX or __linux__.
148 // For GCC on Linux: __GNUC__
149 #ifdef __linux__
150 #define COSMOS_LINUX_OS
153 #define COSMOS_USLEEP(usec) usleep(static_cast<uint32_t>(usec))
154 #define COSMOS_SLEEP(sec) usleep(static_cast<uint32_t>((sec>=0.?sec:0)*1e6)) // this allows decimal seconds
155 #define CLOSE_SOCKET(socket) ::close(socket)
156 #define COSMOS_MKDIR(dtemp, mode) mkdir(const_cast<char *>(dtemp), mode)
157 #include <sys/socket.h>
159 #include <netinet/in.h>
160 #include <netdb.h>
161 #include <arpa/inet.h>
162 #include <sys/select.h>
163 #include <sys/stat.h>
164 #include <sys/types.h>
165 #include <sys/vfs.h>
166 #include <sys/ioctl.h>
167 #include <sys/time.h>
168 #endif
169 
170 // --------------------- WINDOWS ------------------------------------
171 // for c++x0 WIN32 is not defined, use _WIN32 (with underscore)
172 // For MingW on Windows: #ifdef __MINGW32__
173 // Windows (x64 and x86)
174 
175 #ifdef COSMOS_WIN_OS // Defined for both 32-bit and 64-bit environments 1
176 
177 #include <winsock2.h> // must come before <windows.h>
178 
181 #ifdef COSMOS_WIN_BUILD_MSVC
182 #include <direct.h>
183 #define COSMOS_MKDIR(dtemp, mode) _mkdir((char *)dtemp)
184 #else
185 #define COSMOS_MKDIR(dtemp, mode) mkdir((char *)dtemp)
186 #endif
187 
188 #define COSMOS_USLEEP(usec) Sleep((uint32_t)(usec/1000. + .5))
189 #define COSMOS_SLEEP(sec) Sleep((uint32_t)((sec>=0.?sec:0)*1000))
190 #define CLOSE_SOCKET(socket) closesocket(socket)
191 
193 #include <ws2tcpip.h>
194 #define HAVE_BOOLEAN
195 #include <iphlpapi.h>
196 #include <windows.h>
197 #include <mmsystem.h>
198 
199 // for MinGW
200 #ifdef __MINGW32__
201 #include <pthread.h>
202 #include <sys/time.h>
203 #endif
204 
205 #include <thread>
206 #include <io.h>
207 #include <process.h>
208 
209 #endif
210 
211 // --------------------- MAC ------------------------------------
212 // For Mac OS: #ifdef __APPLE__
213 #ifdef __MACH__
214 #define COSMOS_MAC_OS
215 #define COSMOS_USLEEP(usec) usleep((uint32_t)usec)
218 //#define COSMOS_SLEEP(sec) sleep((uint32_t)(sec>=0.?sec:0))
219 #define COSMOS_SLEEP(sec) usleep((uint32_t)((sec>=0.?sec:0)*1e6))
220 #define CLOSE_SOCKET(socket) ::close(socket)
221 #define COSMOS_MKDIR(dtemp, mode) mkdir((char *)dtemp, mode)
222 #include <sys/socket.h>
224 #include <netinet/in.h>
225 #include <netdb.h>
226 #include <arpa/inet.h>
227 #include <sys/select.h>
228 #include <sys/types.h>
229 #include <sys/time.h>
230 #include <sys/param.h>
231 #include <sys/mount.h>
232 #endif
233 
234 // --------------------- CYGWIN ------------------------------------
235 #ifdef __CYGWIN__
236 #define COSMOS_CYGWIN_OS
237 #define COSMOS_USLEEP(usec) usleep((uint32_t)usec)
240 #define COSMOS_SLEEP(sec) sleep((uint32_t)(sec>=0.?sec:0))
241 #define CLOSE_SOCKET(socket) close(socket)
242 #define COSMOS_MKDIR(dtemp, mode) mkdir((char *)dtemp,mode)
243 #include <sys/socket.h>
245 #include <netinet/in.h>
246 #include <netdb.h>
247 #include <arpa/inet.h>
248 #include <sys/select.h>
249 #include <sys/types.h>
250 #include <sys/time.h>
251 #include <sys/vfs.h>
252 #endif // COSMOS_CYGWIN_OS
253 
254 #include "json11.hpp"
255 
256 
257 #endif // CONFIGCOSMOS_H
Definition: agentclass.cpp:54
string to_string(char *value)
Definition: stringlib.cpp:220
COSMOS definitions Definitions specific to the COSMOS environement.
Definition: agentclass.cpp:56