milk
1.01
Modular Image processing Library toolKit
|
Go to the documentation of this file.
25 #ifndef _POSIX_C_SOURCE
26 #define _POSIX_C_SOURCE 200809L
35 #include <sys/types.h>
37 #include <semaphore.h>
39 #include <gsl/gsl_rng.h>
50 #ifndef __STDC_LIB_EXT1__
55 typedef long variableID;
71 #define PI 3.14159265358979323846264338328
74 #define SZ_CLICOREVARRAY 1000
76 #define STRINGMAXLEN_DEFAULT 1000
77 #define STRINGMAXLEN_ERRORMSG 1000
78 #define STRINGMAXLEN_CLICMDLINE 1000 // CPU input command line
79 #define STRINGMAXLEN_COMMAND 1000
80 #define STRINGMAXLEN_STREAMNAME 100
81 #define STRINGMAXLEN_IMGNAME 100
82 #define STRINGMAXLEN_FILENAME 200 // without directory, includes extension
83 #define STRINGMAXLEN_DIRNAME 800
84 #define STRINGMAXLEN_FULLFILENAME 1000 // includes directory name
85 #define STRINGMAXLEN_FUNCTIONNAME 200
86 #define STRINGMAXLEN_FUNCTIONARGS 1000
87 #define STRINGMAXLEN_SHMDIRNAME 200
89 #define STRINGMAXLEN_FPSPROCESSTYPE 64
94 extern char DocDir[200];
95 extern char SrcDir[200];
96 extern char BuildFile[200];
97 extern char BuildDate[200];
98 extern char BuildTime[200];
103 #define CFITSEXIT printf("Program abnormally terminated, File \"%s\", line %d\n", __FILE__, __LINE__);exit(0)
106 #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");}
107 #define nfree(f) free(f);printf("\nMALLOC: \""#f"\" freed\n");
109 #define nmalloc(f,type,n) f = (type*) malloc(sizeof(type)*n);if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
110 #define nfree(f) free(f);
113 #define TEST_ALLOC(f) if(f==NULL){printf("ERROR: pointer \"" #f "\" allocation failed\n");exit(0);}
116 #define NB_ARG_MAX 20
128 #define INIT_MODULE_LIB(modname) \
129 static errno_t init_module_CLI(); \
130 static int INITSTATUS_##modname = 0; \
131 void __attribute__ ((constructor)) libinit_##modname() \
133 if ( INITSTATUS_##modname == 0 ) \
135 strcpy(data.moduleshortname_default, MODULE_SHORTNAME_DEFAULT); \
136 strcpy(data.moduledatestring, __DATE__); \
137 strcpy(data.moduletimestring, __TIME__); \
138 strcpy(data.modulename, (#modname)); \
139 RegisterModule(__FILE__, PROJECT_NAME, MODULE_DESCRIPTION, VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); \
141 INITSTATUS_##modname = 1; \
142 strcpy(data.modulename, ""); \
143 strcpy(data.moduleshortname_default, ""); \
144 strcpy(data.moduleshortname, ""); \
147 void __attribute__ ((destructor)) libclose_##modname() \
149 if ( INITSTATUS_##modname == 1 ) \
167 #define PRINT_ERROR(...) do { \
168 sprintf(data.testpoint_msg, __VA_ARGS__); \
169 printf("ERROR: %c[%d;%dm %s %c[%d;m\n", (char) 27, 1, 31, data.testpoint_msg, (char) 27, 0); \
170 sprintf(data.testpoint_file, "%s", __FILE__); \
171 sprintf(data.testpoint_func, "%s", __func__); \
172 data.testpoint_line = __LINE__; \
173 clock_gettime(CLOCK_REALTIME, &data.testpoint_time); \
176 #define PRINT_ERROR(...) printf("ERROR: %c[%d;%dm %s %c[%d;m\n", (char) 27, 1, 31, __VA_ARGS__, (char) 27, 0)
185 #define PRINT_WARNING(...) do { \
186 char warnmessage[1000]; \
187 sprintf(warnmessage, __VA_ARGS__); \
189 "%c[%d;%dm WARNING [ FILE: %s FUNCTION: %s LINE: %d ] %c[%d;m\n", \
190 (char) 27, 1, 35, __FILE__, __func__, __LINE__, (char) 27, 0); \
194 if( strerror_r( errno, buff, 256 ) == 0 ) { \
195 fprintf(stderr,"C Error: %s\n", buff ); \
197 fprintf(stderr,"Unknown C Error\n"); \
200 fprintf(stderr,"No C error (errno = 0)\n"); } \
201 fprintf(stderr, "%c[%d;%dm ", (char) 27, 1, 35); \
202 fprintf(stderr, "%s", warnmessage); \
203 fprintf(stderr, " %c[%d;m\n", (char) 27, 0); \
214 #if defined NDEBUG || defined STANDALONE
215 #define DEBUG_TRACEPOINT(...)
217 #define DEBUG_TRACEPOINT(...) do { \
218 sprintf(data.testpoint_file, "%s", __FILE__); \
219 sprintf(data.testpoint_func, "%s", __func__); \
220 data.testpoint_line = __LINE__; \
221 clock_gettime(CLOCK_REALTIME, &data.testpoint_time); \
222 sprintf(data.testpoint_msg, __VA_ARGS__); \
231 #if defined NDEBUG || defined STANDALONE
232 #define DEBUG_TRACEPOINTLOG(...)
234 #define DEBUG_TRACEPOINTLOG(...) do { \
235 sprintf(data.testpoint_file, "%s", __FILE__); \
236 sprintf(data.testpoint_func, "%s", __func__); \
237 data.testpoint_line = __LINE__; \
238 clock_gettime(CLOCK_REALTIME, &data.testpoint_time); \
239 sprintf(data.testpoint_msg, __VA_ARGS__); \
240 write_process_log(); \
258 #define EXECUTE_SYSTEM_COMMAND(...) do { \
259 char syscommandstring[STRINGMAXLEN_COMMAND]; \
260 int slen = snprintf(syscommandstring, STRINGMAXLEN_COMMAND, __VA_ARGS__); \
262 PRINT_ERROR("snprintf wrote <1 char"); \
265 if(slen >= STRINGMAXLEN_COMMAND) { \
266 PRINT_ERROR("snprintf string truncation"); \
269 data.retvalue = system(syscommandstring); \
279 #define SNPRINTF_CHECK(string, maxlen, ...) do { \
280 int slen = snprintf(string, maxlen, __VA_ARGS__); \
282 PRINT_ERROR("snprintf wrote <1 char"); \
285 if(slen >= maxlen) { \
286 PRINT_ERROR("snprintf string truncation"); \
309 #define WRITE_IMAGENAME(imname, ...) do { \
310 int slen = snprintf(imname, STRINGMAXLEN_IMGNAME, __VA_ARGS__); \
312 PRINT_ERROR("snprintf wrote <1 char"); \
315 if(slen >= STRINGMAXLEN_IMGNAME) { \
316 PRINT_ERROR("snprintf string truncation"); \
322 #define CREATE_IMAGENAME(imname, ...) \
323 char imname[STRINGMAXLEN_IMGNAME]; \
325 int slen = snprintf(imname, STRINGMAXLEN_IMGNAME, __VA_ARGS__); \
327 PRINT_ERROR("snprintf wrote <1 char"); \
330 if(slen >= STRINGMAXLEN_IMGNAME) { \
331 PRINT_ERROR("snprintf string truncation"); \
353 #define WRITE_DIRNAME(dirname, ...) do { \
354 int slen = snprintf(dirname, STRINGMAXLEN_DIRNAME, __VA_ARGS__); \
356 PRINT_ERROR("snprintf wrote <1 char"); \
359 if(slen >= STRINGMAXLEN_DIRNAME) { \
360 PRINT_ERROR("snprintf string truncation"); \
382 #define WRITE_FILENAME(fname, ...) do { \
383 int slen = snprintf(fname, STRINGMAXLEN_FILENAME, __VA_ARGS__); \
385 PRINT_ERROR("snprintf wrote <1 char"); \
388 if(slen >= STRINGMAXLEN_FILENAME) { \
389 PRINT_ERROR("snprintf string truncation"); \
412 #define WRITE_FULLFILENAME(ffname, ...) do { \
413 int slen = snprintf(ffname, STRINGMAXLEN_FULLFILENAME, __VA_ARGS__); \
415 PRINT_ERROR("snprintf wrote <1 char"); \
418 if(slen >= STRINGMAXLEN_FULLFILENAME) { \
419 PRINT_ERROR("snprintf string truncation"); \
440 #define WRITE_STRING_TO_FILE(fname, ...) do { \
442 fptmp = fopen(fname, "w"); \
443 if (fptmp == NULL) { \
444 int errnum = errno; \
445 PRINT_ERROR("fopen() returns NULL"); \
446 fprintf(stderr, "Error opening file %s: %s\n", fname, strerror( errnum )); \
449 fprintf(fptmp, __VA_ARGS__); \
466 #define RETURN_SUCCESS 0
467 #define RETURN_FAILURE 1 // generic error code
468 #define RETURN_MISSINGFILE 2
471 #define MAX_NB_FRAMENAME_CHAR 500
472 #define MAX_NB_EXCLUSIONS 40
479 #define CLIARG_FLOAT 1 // floating point number
480 #define CLIARG_LONG 2 // integer (int or long)
481 #define CLIARG_STR_NOT_IMG 3 // string, not existing image
482 #define CLIARG_IMG 4 // existing image
483 #define CLIARG_STR 5 // string
485 #define CLICMD_SUCCESS 0
486 #define CLICMD_INVALID_ARG 1
487 #define CLICMD_ERROR 2
493 typedef uint_fast8_t BOOL;
500 #define DATA_NB_MAX_COMMAND 1000
501 #define DATA_NB_MAX_MODULE 100
506 #define STATIC_NB_MAX_IMAGE 520
507 #define STATIC_NB_MAX_VARIABLE 5030
512 extern uid_t euid_real;
513 extern uid_t euid_called;
587 #define CMDARG_TYPE_UNSOLVED 0
588 #define CMDARG_TYPE_FLOAT 1
589 #define CMDARG_TYPE_LONG 2
590 #define CMDARG_TYPE_STRING 3
591 #define CMDARG_TYPE_EXISTINGIMAGE 4
592 #define CMDARG_TYPE_COMMAND 5
593 #define CMDARG_TYPE_RAWSTRING 6
608 int CLI_checkarg(
int argnum,
int argtype);
609 int CLI_checkarg_noerrmsg(
int argnum,
int argtype);
616 extern uint8_t TYPESIZE[32];
643 char package_name[100];
644 int package_version_major;
645 int package_version_minor;
646 int package_version_patch;
647 char package_version[100];
652 char shmsemdirname[100];
658 struct sigaction sigact;
677 char testpoint_file[STRINGMAXLEN_FILENAME];
678 char testpoint_func[STRINGMAXLEN_FUNCTIONNAME];
679 char testpoint_msg[STRINGMAXLEN_FUNCTIONARGS];
680 struct timespec testpoint_time;
720 char CLIlogname[200];
722 int processinfoActive;
731 char processname[100];
732 char processname0[100];
740 char CLIcmdline[STRINGMAXLEN_CLICMDLINE];
741 int CLIexecuteCMDready;
752 long calctmp_imindex;
765 char modulename[100];
766 char moduleshortname[80];
767 char moduleshortname_default[80];
768 char moduledatestring[20];
769 char moduletimestring[20];
782 char FPS_name[STRINGMAXLEN_FPS_NAME];
785 char FPS_PROCESS_TYPE[STRINGMAXLEN_FPSPROCESSTYPE];
787 uint32_t FPS_CMDCODE;
788 errno_t (*FPS_CONFfunc)();
789 errno_t (*FPS_RUNfunc)();
798 #ifdef DATA_STATIC_ALLOC
800 IMAGE image[STATIC_NB_MAX_IMAGE];
817 long NB_MAX_VARIABLE;
818 #ifdef DATA_STATIC_ALLOC
820 VARIABLE variable[STATIC_NB_MAX_VARIABLE];
831 float FLOATARRAY[1000];
832 double DOUBLEARRAY[1000];
859 errno_t RegisterModule(
860 const char *restrict FileName,
861 const char *restrict PackageName,
862 const char *restrict InfoString,
868 uint32_t RegisterCLIcommand(
869 const char *restrict CLIkey,
870 const char *restrict CLImodulesrc,
871 errno_t (*CLIfptr)(),
872 const char *restrict CLIinfo,
873 const char *restrict CLIsyntax,
874 const char *restrict CLIexample,
875 const char *restrict CLICcall
879 errno_t runCLItest(
int argc,
char *argv[],
char *promptstring);
881 errno_t
runCLI(
int argc,
char *argv[],
char *promptstring);
883 errno_t CLI_execute_line();
888 #endif // ifndef STANDALONE
Definition: processtools.h:92
Definition: CLIcore.h:547
Definition: function_parameters.h:502
errno_t set_signal_catch()
signal catching
Definition: CLIcore_signals.c:104
IMAGE structure The IMAGE structure includes :
Definition: ImageStruct.h:366
errno_t runCLI(int argc, char *argv[], char *promptstring)
Command Line Interface (CLI) main .
Definition: CLIcore.c:567
Function prototypes for ImageStreamIO.
Data streams control panel.
Definition: CLIcore.h:530
Definition: CLIcore.h:621
Image structure definition.
errno_t write_process_log()
Write entry into debug log.
Definition: CLIcore_signals.c:28
void sig_handler(int signo)
Signal handler.
Definition: CLIcore_signals.c:249
Definition: CLIcore.h:641
Definition: CLIcore.h:595
Tools to help expose and control function parameters.
pid_t CLIPID
important directories and info
Definition: CLIcore.c:109