AdaptiveOpticsControl
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 
32 #include "ImageStruct.h"
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 //Need to install process with setuid. Then, so you aren't running privileged all the time do this:
68 extern uid_t euid_real;
69 extern uid_t euid_called;
70 extern uid_t suid;
71 
72 
73 
74 
75 
76 
77 
78 
79 
80 /*^-----------------------------------------------------------------------------
81 | commands available through the CLI
82 +-----------------------------------------------------------------------------*/
83 
84 
85 
86 typedef struct {
87  char key[100]; // command keyword
88  char module[50]; // module name
89  int_fast8_t (* fp) (); // command function pointer
90  char info [1000]; // short description/help
91  char syntax [1000]; // command syntax
92  char example[1000]; // command example
93  char Ccall[1000];
94 } CMD;
95 
96 
97 
98 typedef struct {
99  char name[50]; // module name
100  char info[1000]; // short description
101 } MODULE;
102 
103 
104 
105 
106 /* ---------------------------------------------------------- */
107 /* */
108 /* */
109 /* COMMAND LINE ARGs / TOKENS */
110 /* */
111 /* */
112 /* ---------------------------------------------------------- */
113 
114 
115 // The command line is parsed and
116 
117 // cmdargtoken type
118 // 0 : unsolved
119 // 1 : floating point (double precision)
120 // 2 : long
121 // 3 : string
122 // 4 : existing image
123 // 5 : command
124 typedef struct
125 {
126  int type;
127  union
128  {
129  double numf;
130  long numl;
131  char string[200];
132  } val;
133 } CMDARGTOKEN;
134 
135 
136 
137 int CLI_checkarg(int argnum, int argtype);
138 int CLI_checkarg_noerrmsg(int argnum, int argtype);
139 
140 
141 
142 
143 
144 
145 extern uint8_t TYPESIZE[32];
146 
147 
148 
149 
150 typedef struct
151 {
152  int used;
153  char name[80];
154  int type;
155  union
156  {
157  double f;
158  long l;
159  char s[80];
160  } value;
161  char comment[200];
162 } VARIABLE;
163 
164 
165 
166 
167 
168 // THIS IS WHERE EVERYTHING THAT NEEDS TO BE WIDELY ACCESSIBLE GETS STORED
169 typedef struct
170 {
171  struct sigaction sigact;
172  // signals toggle flags
182 
183  int Debug;
184  int quiet;
185  int overwrite; // automatically overwrite FITS files
186  double INVRANDMAX;
187  gsl_rng *rndgen; // random number generator
188  int precision; // default precision: 0 for float, 1 for double
189 
190  // logging
191  int CLIlogON;
192  char CLIlogname[200];
193 
194  // Command Line Interface (CLI) INPUT
195  int fifoON;
196  char processname[100];
197  char fifoname[100];
198  uint_fast16_t NBcmd;
201  int parseerror; // 1 if error, 0 otherwise
202  long cmdNBarg; // number of arguments in last command line
203  CMDARGTOKEN cmdargtoken[NB_ARG_MAX];
204  long cmdindex; // when command is found in command line, holds index of command
205  long calctmp_imindex; // used to create temporary images
206  int CMDexecuted; // 0 if command has not been executed, 1 otherwise
207  long NBmodule;
210 
211 
212  // shared memory default
214 
215  // Number of keyword per iamge default
217 
218  // images, variables
220  IMAGE *image;
221 
224  /*
225  long NB_MAX_VARIABLELONG;
226  VARIABLELONG *variablelong;
227 
228  long NB_MAX_VARIABLESTRING;
229  VARIABLESTRING *variablestring;
230  */
231 
232  float FLOATARRAY[1000]; // array to store temporary variables
233  double DOUBLEARRAY[1000]; // for convenience
234  char SAVEDIR[500];
235 
236  // status counter (used for profiling)
237  int status0;
238  int status1;
239 } DATA;
240 
241 
242 
243 
244 
245 
246 #define MAX_NB_FRAMES 500
247 #define MAX_NB_FRAMENAME_CHAR 500
248 #define MAX_NB_EXCLUSIONS 40
249 
250 
251 void sig_handler(int signo);
252 
253 uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t (*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall);
254 
255 
256 
257 #endif
int status0
Definition: CLIcore.h:237
int NBKEWORD_DFT
Definition: CLIcore.h:216
Definition: CLIcore.h:169
long l
Definition: CLIcore.h:158
int precision
Definition: CLIcore.h:188
int CLI_checkarg(int argnum, int argtype)
Definition: CLIcore.c:1942
char SrcDir[200]
Definition: CLIcore.c:100
uint_fast16_t RegisterCLIcommand(char *CLIkey, char *CLImodule, int_fast8_t(*CLIfptr)(), char *CLIinfo, char *CLIsyntax, char *CLIexample, char *CLICcall)
Definition: CLIcore.c:579
MODULE * module
Definition: CLIcore.h:209
long numl
Definition: CLIcore.h:130
int status1
Definition: CLIcore.h:238
long NB_MAX_VARIABLE
Definition: CLIcore.h:222
gsl_rng * rndgen
Definition: CLIcore.h:187
int signal_USR1
Definition: CLIcore.h:173
int C_ERRNO
Definition: CLIcore.c:111
double INVRANDMAX
Definition: CLIcore.h:186
long NB_MAX_MODULE
Definition: CLIcore.h:208
Definition: CLIcore.h:86
int Debug
Definition: CLIcore.h:183
double numf
Definition: CLIcore.h:129
int type
Definition: CLIcore.h:154
long cmdindex
Definition: CLIcore.h:204
int signal_PIPE
Definition: CLIcore.h:181
int type
Definition: CLIcore.h:126
int parseerror
Definition: CLIcore.h:201
int CLIlogON
Definition: CLIcore.h:191
char BuildTime[200]
Definition: CLIcore.c:103
int signal_BUS
Definition: CLIcore.h:179
long calctmp_imindex
Definition: CLIcore.h:205
VARIABLE * variable
Definition: CLIcore.h:223
long NB_MAX_IMAGE
Definition: CLIcore.h:219
int signal_ABRT
Definition: CLIcore.h:178
long cmdNBarg
Definition: CLIcore.h:202
int signal_HUP
Definition: CLIcore.h:180
uint8_t TYPESIZE[32]
Definition: CLIcore.c:109
int CLI_checkarg_noerrmsg(int argnum, int argtype)
Definition: CLIcore.c:1951
Definition: CLIcore.h:150
int CMDexecuted
Definition: CLIcore.h:206
Image structure definition.
uid_t suid
Definition: CLIcore.c:107
uint_fast16_t NBcmd
Definition: CLIcore.h:198
IMAGE * image
Definition: CLIcore.h:220
CMD * cmd
Definition: CLIcore.h:200
int signal_TERM
Definition: CLIcore.h:175
uid_t euid_called
Definition: CLIcore.c:106
int signal_SEGV
Definition: CLIcore.h:177
long NB_MAX_COMMAND
Definition: CLIcore.h:199
Definition: CLIcore.h:98
uid_t euid_real
Definition: CLIcore.c:105
int SHARED_DFT
Definition: CLIcore.h:213
char DocDir[200]
Definition: CLIcore.c:99
int signal_USR2
Definition: CLIcore.h:174
double f
Definition: CLIcore.h:157
int signal_INT
Definition: CLIcore.h:176
void sig_handler(int signo)
signal catching
Definition: CLIcore.c:179
long NBmodule
Definition: CLIcore.h:207
int quiet
Definition: CLIcore.h:184
pid_t CLIPID
important directories and info
Definition: CLIcore.c:98
int used
Definition: CLIcore.h:152
char BuildDate[200]
Definition: CLIcore.c:102
int overwrite
Definition: CLIcore.h:185
char BuildFile[200]
Definition: CLIcore.c:101
Definition: CLIcore.h:124
int fifoON
Definition: CLIcore.h:195