CAEN Utility  2.0.2
Utilities for CAEN projects
CAENMultiplatformTypes.h
Go to the documentation of this file.
1 /******************************************************************************
2 *
3 * CAEN SpA - Software Division
4 * Via Vetraia, 11 - 55049 - Viareggio ITALY
5 * +39 0594 388 398 - www.caen.it
6 *
7 *******************************************************************************
8 *
9 * Copyright (C) 2019-2022 CAEN SpA
10 *
11 * This file is part of the CAEN Utility.
12 *
13 * The CAEN Utility is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 3 of the License, or (at your option) any later version.
17 *
18 * The CAEN Utility is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with the CAEN Utility; if not, see
25 * https://www.gnu.org/licenses/.
26 *
27 * SPDX-License-Identifier: LGPL-3.0-or-later
28 *
29 ***************************************************************************/
37 #ifndef CAEN_INCLUDE_TYPES_CAENMULTIPLATFORMTYPES_H_
38 #define CAEN_INCLUDE_TYPES_CAENMULTIPLATFORMTYPES_H_
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #include <stdbool.h>
45 #include <string.h> // memcpy, memmove, memset
46 #include <CAENMap.h>
47 
48 #ifdef _WIN32
49 #include <WinSock2.h>
50 #include <Windows.h>
51 #include <io.h> // _finddata_t
52 #else
53 #include <netinet/in.h> // useful to expose macros like INADDR_ANY to users
54 #include <sys/types.h> // pid_t
55 #include <dirent.h> // DIR
56 #include <endian.h> // be16toh, be32toh, be64toh, ...
57 #include <getopt.h> // opterr, optopt, optind, ...
58 #endif
59 
60 #ifdef _WIN32
61 typedef HMODULE c_libhandle_t;
62 typedef FARPROC c_fcnhandle_t;
63 #else
64 typedef void* c_libhandle_t;
65 typedef void* c_fcnhandle_t;
66 #endif
67 
68 #define MAX_PROC_NARGS 100
69 
70 #ifndef __cplusplus
71 #ifndef max
72 #define max(a,b) (((a) > (b)) ? (a) : (b))
73 #endif
74 
75 #ifndef min
76 #define min(a,b) (((a) < (b)) ? (a) : (b))
77 #endif
78 #endif
79 
80 #ifndef TRUE
81 #define TRUE true // defined in stdbool.h
82 #endif
83 #ifndef FALSE
84 #define FALSE false // defined in stdbool.h
85 #endif
86 
87 #ifndef INFINITE
88 #define INFINITE INT32_C(-1)
89 #endif
90 
94 typedef enum {
95  MP_code_Success = 0, //<! Success
96  MP_code_Generic = 1, //<! Invalid Command or Command List
97  MP_code_LibLoad = 2, //<! Error loading dynamic library
98  MP_code_LibClose = 3, //<! Error closing dynamic library
99 } c_MP_code_t;
100 
101 #ifdef _WIN32
102 #define DIRSEP0 "\\"
103 #define DIRSEP1 "/"
104 #define DIRSEPS {DIRSEP0, DIRSEP1}
105 #define DIRSEPS_CHAR {'\\', '/'}
106 #define DIRSEPS_STR {'\\', '/', '\0'}
107 #else
108 #define DIRSEP0 "/"
109 #define DIRSEPS {DIRSEP0}
110 #define DIRSEPS_CHAR {'/'}
111 #define DIRSEPS_STR {'/', '\0'}
112 #endif
113 #define DIRSEP DIRSEP0
114 
115 #ifdef _WIN32 // Windows
116 //time struct and functions
117 typedef SYSTEMTIME c_systemtime_t;
118 
119 typedef ptrdiff_t handle_type;
120 
121 struct dirent {
122  char *d_name;
123 };
124 
125 typedef struct {
126  handle_type handle;
127  struct _finddata_t info;
128  struct dirent result;
129  char *name;
130 } DIR;
131 
132 #else // LINUX
133 
134 //time struct
135 typedef struct {
136  unsigned short wYear;
137  unsigned short wMonth;
138  unsigned short wDayOfWeek;
139  unsigned short wDay;
140  unsigned short wHour;
141  unsigned short wMinute;
142  unsigned short wSecond;
143  unsigned short wMilliseconds;
144 } c_systemtime_t;
145 #endif
146 
147 typedef enum {
153 
154 typedef c_map_t(char*) c_environment_t;
155 
156 typedef struct {
157  char *execName;
158  char *argv[MAX_PROC_NARGS + 1];
159  int32_t argc;
160  c_environment_t environment;
161 #ifdef _WIN32
162  DWORD lastErr;
163  HANDLE jobObject;
164  PROCESS_INFORMATION procInfo;
165 #else
166  pid_t pid;
167 #endif
168 } c_Process_t;
169 
170 typedef enum {
177 
178 #ifdef __cplusplus
179 }
180 #endif
181 
182 #endif // CAEN_INCLUDE_TYPES_CAENMULTIPLATFORMTYPES_H_
Corresponds to FP_INFINITE defined by math.h.
unsigned short wMilliseconds
void * c_fcnhandle_t
Corresponds to FP_SUBNORMAL defined by math.h.
Corresponds to FP_NORMAL defined by math.h.
Hash table. Implementation from rxi&#39;s "map" project.
unsigned short wSecond
c_environment_t environment
#define c_map_t(T)
Definition: CAENMapTypes.h:69
unsigned short wMinute
Corresponds to FP_ZERO defined by math.h.
Corresponds to FP_NAN defined by math.h.
void * c_libhandle_t
c_Float_Classification_t
unsigned short wDayOfWeek
#define MAX_PROC_NARGS