coffee
Coronagraph Optimization For Fast Exoplanet Exploration
CLIcore.h
Go to the documentation of this file.
1 
14 #define _GNU_SOURCE
15 
16 
17 #ifndef _CLICORE_H
18 #define _CLICORE_H
19 
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <semaphore.h>
27 #include <fftw3.h>
28 #include <gsl/gsl_rng.h> // for random numbers
29 #include <signal.h>
30 
31 
33 
34 
35 #define PI 3.14159265358979323846264338328
36 
38 #define SZ_CLICOREVARRAY 1000
39 
41 extern pid_t CLIPID;
42 extern char DocDir[200]; // location of documentation
43 extern char SrcDir[200]; // location of source
44 extern char BuildFile[200]; // file name for source
45 extern char BuildDate[200];
46 extern char BuildTime[200];
47 
48 extern int C_ERRNO; // C errno (from errno.h)
49 
50 /* #define DEBUG */
51 #define CFITSEXIT printf("Program abnormally terminated, File \"%s\", line %d\n", __FILE__, __LINE__);exit(0)
52 
53 #ifdef DEBUG
54 #define nmalloc(f,type,n) f = (type*) malloc(sizeof(type)*n);if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}else{printf("\nMALLOC: \""#f "\" allocated\n");}
55 #define nfree(f) free(f);printf("\nMALLOC: \""#f"\" freed\n");
56 #else
57 #define nmalloc(f,type,n) f = (type*) malloc(sizeof(type)*n);if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
58 #define nfree(f) free(f);
59 #endif
60 
61 #define TEST_ALLOC(f) if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
62 
63 
64 #define NB_ARG_MAX 20
65 
66 
67 
68 // declare a boolean type "BOOL"
69 // TRUE and FALSE improve code readability
70 //
71 typedef uint_fast8_t BOOL;
72 #define FALSE 0
73 #define TRUE 1
74 
75 
76 
77 
78 #define DATA_NB_MAX_COMMAND 1000
79 #define DATA_NB_MAX_MODULE 100
80 
81 // In STATIC allocation mode, IMAGE and VARIABLE arrays are allocated statically
82 
83 //#define DATA_STATIC_ALLOC // comment if DYNAMIC
84 #define STATIC_NB_MAX_IMAGE 5020
85 #define STATIC_NB_MAX_VARIABLE 5030
86 
87 
88 //Need to install process with setuid. Then, so you aren't running privileged all the time do this:
89 extern uid_t euid_real;
90 extern uid_t euid_called;
91 extern uid_t suid;
92 
93 
94 
95 
96 
97 
98 
99 
100 
101 /*^-----------------------------------------------------------------------------
102 | commands available through the CLI
103 +-----------------------------------------------------------------------------*/
104 
105 
106 
107 typedef struct {
108  char key[100]; // command keyword
109  char module[200]; // module name
110  int_fast8_t (* fp) (); // command function pointer
111  char info [1000]; // short description/help
112  char syntax [1000]; // command syntax
113  char example[1000]; // command example
114  char Ccall[1000];
115 } CMD;
116 
117 
118 
119 typedef struct {
120  char name[50]; // module name
121  char package[50]; // package to which module belongs
122  char info[1000]; // short description
123 } MODULE;
124 
125 
126 
127 
128 /* ---------------------------------------------------------- */
129 /* */
130 /* */
131 /* COMMAND LINE ARGs / TOKENS */
132 /* */
133 /* */
134 /* ---------------------------------------------------------- */
135 
136 
137 // The command line is parsed and
138 
139 // cmdargtoken type
140 // 0 : unsolved
141 // 1 : floating point (double precision)
142 // 2 : long
143 // 3 : string
144 // 4 : existing image
145 // 5 : command
146 typedef struct
147 {
148  int type;
149  union
150  {
151  double numf;
152  long numl;
153  char string[200];
154  } val;
155 } CMDARGTOKEN;
156 
157 
158 
159 int CLI_checkarg(int argnum, int argtype);
160 int CLI_checkarg_noerrmsg(int argnum, int argtype);
161 
162 
163 
164 
165 
166 
167 extern uint8_t TYPESIZE[32];
168 
169 
170 
171 
172 typedef struct
173 {
174  int used;
175  char name[80];
176  int type;
177  union
178  {
179  double f;
180  long l;
181  char s[80];
182  } value;
183  char comment[200];
184 } VARIABLE;
185 
186 
187 
188 
189 
190 // THIS IS WHERE EVERYTHING THAT NEEDS TO BE WIDELY ACCESSIBLE GETS STORED
191 typedef struct
192 {
193  char package_name[100];
194  char package_version[100];
195  char configdir[100];
196  char sourcedir[100];
197 
198 
199  struct sigaction sigact;
200  // signals toggle flags
201  int signal_USR1;
202  int signal_USR2;
203  int signal_TERM;
204  int signal_INT;
205  int signal_SEGV;
206  int signal_ABRT;
207  int signal_BUS;
208  int signal_HUP;
209  int signal_PIPE;
210 
211  int progStatus; // main program status
212  // 0: before automatic loading of shared objects
213  // 1: after automatic loading of shared objects
214 
215  uid_t ruid; // Real UID (= user launching process at startup)
216  uid_t euid; // Effective UID (= owner of executable at startup)
217  uid_t suid; // Saved UID (= owner of executable at startup)
218  // system permissions are set by euid
219  // at startup, euid = owner of executable (meant to be root)
220  // -> we first drop privileges by setting euid to ruid
221  // when root privileges needed, we set euid <- suid
222  // when reverting to user privileges : euid <- ruid
223 
224  int Debug;
225  int quiet;
226  int overwrite; // automatically overwrite FITS files
227  double INVRANDMAX;
228  gsl_rng *rndgen; // random number generator
229  int precision; // default precision: 0 for float, 1 for double
230 
231  // logging
232  int CLIlogON;
233  char CLIlogname[200];
234 
235  // Command Line Interface (CLI) INPUT
236  int fifoON;
237  char processname[100];
238  char fifoname[100];
239  uint_fast16_t NBcmd;
240 
241  long NB_MAX_COMMAND;
242  CMD cmd[1000];
243 
244  int parseerror; // 1 if error, 0 otherwise
245  long cmdNBarg; // number of arguments in last command line
246  CMDARGTOKEN cmdargtoken[NB_ARG_MAX];
247  long cmdindex; // when command is found in command line, holds index of command
248  long calctmp_imindex; // used to create temporary images
249  int CMDexecuted; // 0 if command has not been executed, 1 otherwise
250  long NBmodule;
251 
252  long NB_MAX_MODULE;
253  MODULE module[100];
254 
255  // shared memory default
256  int SHARED_DFT;
257 
258  // Number of keyword per iamge default
259  int NBKEWORD_DFT;
260 
261  // images, variables
262  long NB_MAX_IMAGE;
263  #ifdef DATA_STATIC_ALLOC
264  IMAGE image[STATIC_NB_MAX_IMAGE]; // image static allocation mode
265  #else
266  IMAGE *image;
267  #endif
268 
269  long NB_MAX_VARIABLE;
270  #ifdef DATA_STATIC_ALLOC
271  VARIABLE variable[STATIC_NB_MAX_VARIABLE]; // variable static allocation mode
272  #else
273  VARIABLE *variable;
274  #endif
275 
276 
277 
278  float FLOATARRAY[1000]; // array to store temporary variables
279  double DOUBLEARRAY[1000]; // for convenience
280  char SAVEDIR[500];
281 
282  // status counter (used for profiling)
283  int status0;
284  int status1;
285 } DATA;
286 
287 extern DATA data;
288 
289 
290 
291 #define MAX_NB_FRAMENAME_CHAR 500
292 #define MAX_NB_EXCLUSIONS 40
293 
294 
295 void sig_handler(int signo);
296 
297 int_fast8_t RegisterModule(char *FileName, char *PackageName, char *InfoString);
298 
299 uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t (*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall);
300 
301 int_fast8_t runCLI(int argc, char *argv[], char *promptstring);
302 
303 #endif
uint8_t TYPESIZE[32]
Definition: CLIcore.c:169
Definition: CLIcore.h:191
void sig_handler(int signo)
signal catching
Definition: CLIcore.c:257
char BuildTime[200]
Definition: CLIcore.c:165
int_fast8_t RegisterModule(char *FileName, char *PackageName, char *InfoString)
Definition: CLIcore.c:717
pid_t CLIPID
important directories and info
Definition: CLIcore.c:160
uint_fast8_t BOOL
Definition: CLIcore.h:71
Definition: CLIcore.h:107
char BuildFile[200]
Definition: CLIcore.c:163
uid_t euid_called
int CLI_checkarg_noerrmsg(int argnum, int argtype)
Definition: CLIcore.c:2361
uid_t suid
uid_t euid_real
char BuildDate[200]
Definition: CLIcore.c:164
int CLI_checkarg(int argnum, int argtype)
Definition: CLIcore.c:2352
DATA data
Definition: CLImain.c:21
Definition: CLIcore.h:172
char SrcDir[200]
Definition: CLIcore.c:162
IMAGE
Definition: ImageStruct.h:432
Definition: CLIcore.h:119
char DocDir[200]
Definition: CLIcore.c:161
int C_ERRNO
Definition: CLIcore.c:171
uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t(*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall)
Definition: CLIcore.c:755
int_fast8_t runCLI(int argc, char *argv[], char *promptstring)
Command Line Interface (CLI) main .
Definition: CLIcore.c:784
Definition: CLIcore.h:146