13#error This is a C++ include file and cannot be used from plain C
28#define ngcbPP_SUCCESS 0x0000
29#define ngcbPP_SKIP 0x0001
30#define ngcbPP_FAILURE 0x0100
31#define ngcbPP_ERR_FATAL 0x1100
36#define ngcbPPLOG(...) do {char s[320]; snprintf(s, 320, __VA_ARGS__); Log(s);} while (0)
41#define ngcbPP_MAX_LIB 32
102typedef void *(*ngcb_pp_thr)(
void *arg);
121 strcpy(
ErrMsg(),
"semaphore creation failed");
127 strcpy(
ErrMsg(),
"semaphore creation failed");
220 if (
next->proc != NULL)
227 else if (
next->psync != NULL)
236 delete next->psync;
next->psync = NULL;
254 void Id(
int id) {id_ = id;}
257 int Id() {
return (id_);}
293 if ((
next->proc != NULL) || (
next->psync != NULL))
303 if (
next->proc != NULL)
308 sprintf(
ErrMsg(),
"processer %d thread synchronization failed",
320 tmpDescr_ =
next->procDescr;
321 next->procDescr = *descr;
339 next->procDescr = *descr;
346 next->procDescr.result = 0x0;
347 if (
next->proc != NULL)
353 sprintf(
ErrMsg(),
"processor %d thread creation failed",
Id());
360 next->psync->Start();
369 out =
next->Execute(in, descr);
420 void Log(
const char *msg) {
426 unsigned char *m = (
unsigned char *)malloc(size);
430 int pageSize = (int)sysconf(_SC_PAGESIZE);
431 if (pageSize < 1) pageSize = 4096;
436 for (i=0;i<size;i+=pageSize) m[i] = (
unsigned char)0;
458static void *ngcbPP_Proc(
void *arg)
467 pthread_sigmask(SIG_BLOCK, &set, (sigset_t *)NULL);
480static void *ngcpPP_ProcSync(
void *arg)
489 pthread_sigmask(SIG_BLOCK, &set, (sigset_t *)NULL);
562#define NGC_REGISTER_PP_MOD(type, name) extern "C" { type name; \
563 int _ngcb_pp_ ## name = 1 ; }
607 if (dlclose(dl_[i]) != 0)
ngcbPPLOG(
"failure - %s\n", dlerror());
624 if (newProc->
Id() < 0)
653 int Lib(
const char *name) {
659 strcpy(
ErrMsg(),
"maximum number of external libraries reached");
666 snprintf(libName,
sizeof(libName),
"lib%s.so", name);
667 ngcbPPLOG(
"loading library <%s>\n", libName);
668 dl = dlopen(libName, RTLD_NOW|RTLD_LOCAL);
671 strcpy(
ErrMsg(), dlerror());
680 int Add(
const char *module) {
691 newProc =
new ngcbPP(idx_++);
708 snprintf(cookie,
sizeof(cookie),
"_ngcb_pp_%s", module);
725 if (dlsym(dl_[i], cookie) != NULL)
727 ngcbPPLOG(
"module <%s> identified\n", module);
736 char *err = dlerror();
743 ngcbPPLOG(
"invalid factory symbol <%s>\n", module);
748 ngcbPPLOG(
"module <%s> registered\n", module);
763 ngcbPPLOG(
"loading module <%s>\n", module);
764 snprintf(libName,
sizeof(libName),
"lib%s.so", module);
765 dl = dlopen(libName, RTLD_NOW|RTLD_LOCAL);
768 strcpy(
ErrMsg(), dlerror());
775 if (dlsym(dl, cookie) == NULL)
777 ngcbPPLOG(
"unloading module <%s>\n", module);
778 if (dlclose(dl) != 0)
782 sprintf(
ErrMsg(),
"module <%s> rejected - identification failed",
794 char *err = dlerror();
795 if (err != NULL) strcpy(
ErrMsg(), err);
796 else sprintf(
ErrMsg(),
"invalid factory symbol <%s>", module);
801 ngcbPPLOG(
"unloading module <%s>\n", module);
802 if (dlclose(dl) != 0)
813 ngcbPPLOG(
"creating processor for module <%s>\n", module);
814 newProc = f->
Create(idx_++);
822 ngcbPPLOG(
"unloading module <%s>\n", module);
823 if (dlclose(dl) != 0)
851 out = first_->Execute(buffer, descr);
864 for (p = first_; p != NULL; p = p->
next)
877 for (p = first_; p != NULL; p = p->
next)
906 ngcbPPLOG(
"fast-sync not available - thread creation failed\n");
934 for (p = first_; p != NULL; p = p->
next) p->
logLevel = level;
939 void Log(
const char *msg) {
ngcbPIPELINE()
Constructor.
Definition ngcbPP.hpp:578
int Lib(const char *name)
Load external library.
Definition ngcbPP.hpp:653
virtual ~ngcbPIPELINE()
Destructor.
Definition ngcbPP.hpp:589
void LogLevel(int level)
Set logging level.
Definition ngcbPP.hpp:931
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:615
int logLevel
Logging level.
Definition ngcbPP.hpp:575
void Log(const char *msg)
Logging function.
Definition ngcbPP.hpp:939
void Parallelize(int fastSync=0)
Parallelize processing pipeline.
Definition ngcbPP.hpp:858
int verboseLevel
Verbose level.
Definition ngcbPP.hpp:572
void VerboseLevel(int level)
Set verbose level.
Definition ngcbPP.hpp:924
int Add(const char *module)
Load processor from module and add it to the end of the pipeline.
Definition ngcbPP.hpp:680
void Add(ngcbPP *newProc)
Add processor to the end of the pipeline.
Definition ngcbPP.hpp:618
void * Execute(void *buffer, ngcb_pp_descr *descr)
Execute processing pipeline.
Definition ngcbPP.hpp:840
Definition ngcbPP.hpp:516
ngcbPP_FACTORY()
Constructor.
Definition ngcbPP.hpp:519
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:527
ngcbPP * Create(int id)
Creator.
Definition ngcbPP.hpp:530
virtual ~ngcbPP_FACTORY()
Destructor.
Definition ngcbPP.hpp:524
virtual ngcbPP * Make(int id)
Maker with id.
Definition ngcbPP.hpp:552
Definition ngcbPP.hpp:178
int rdOnly
Input buffer read-only flag.
Definition ngcbPP.hpp:398
ngcb_pp_descr procDescr
Processing thread buffer descriptor (forward)
Definition ngcbPP.hpp:202
virtual ~ngcbPP()
Destructor.
Definition ngcbPP.hpp:211
int NumBuf()
Return number of frame buffers.
Definition ngcbPP.hpp:260
void Init_(int id)
Initialization function.
Definition ngcbPP.hpp:401
int numBuf
Number of frame buffers.
Definition ngcbPP.hpp:395
int verboseLevel
Verbose level.
Definition ngcbPP.hpp:181
int logLevel
Logging level.
Definition ngcbPP.hpp:184
int RdOnly()
Return input buffer read-only flag.
Definition ngcbPP.hpp:263
void * Execute(void *buffer, ngcb_pp_descr *descr)
Execute Processor.
Definition ngcbPP.hpp:266
int Initialized()
Return initialization flag.
Definition ngcbPP.hpp:248
int Id()
Return processor ID.
Definition ngcbPP.hpp:257
void Id(int id)
Assign id.
Definition ngcbPP.hpp:254
ngcbPP(int id)
Constructor.
Definition ngcbPP.hpp:208
ngcbPP()
Constructor.
Definition ngcbPP.hpp:205
int initialized
Initialization flag.
Definition ngcbPP.hpp:392
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:251
void * Malloc(size_t size)
Preferred buffer allocation.
Definition ngcbPP.hpp:425
ngcb_pp_thr proc
Built-in processing thread.
Definition ngcbPP.hpp:193
ngcbPP * next
Next processor.
Definition ngcbPP.hpp:187
pthread_t thid
Thread id.
Definition ngcbPP.hpp:196
void * procBuf
Processing thread buffer (forward)
Definition ngcbPP.hpp:199
void Log(const char *msg)
Logging function.
Definition ngcbPP.hpp:420
virtual void * Process(void *buffer, ngcb_pp_descr *descr)
Pixel-Processor.
Definition ngcbPP.hpp:385
ngcb_pp_sync * psync
Thread synchronization primitive.
Definition ngcbPP.hpp:190
Definition ngcbPP.hpp:108
int Initialized()
Return initialization flag.
Definition ngcbPP.hpp:143
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:146
pthread_t thid
Thread id.
Definition ngcbPP.hpp:111
ngcb_pp_sync()
Constructor.
Definition ngcbPP.hpp:114
void Wait()
Wait.
Definition ngcbPP.hpp:155
virtual ~ngcb_pp_sync()
Destructor.
Definition ngcbPP.hpp:134
void Start()
Start.
Definition ngcbPP.hpp:149
void Ack()
Acknowledge.
Definition ngcbPP.hpp:158
void Join()
Join.
Definition ngcbPP.hpp:152
#define ngcbPP_ERR_FATAL
Definition ngcbPP.hpp:31
#define ngcbPP_MAX_LIB
Definition ngcbPP.hpp:41
#define ngcbPPLOG(...)
Definition ngcbPP.hpp:36
void *(* ngcb_pp_thr)(void *arg)
Definition ngcbPP.hpp:102
#define ngcbPP_FAILURE
Definition ngcbPP.hpp:30
#define ngcbPP_SUCCESS
Definition ngcbPP.hpp:28
#define ngcbPP_SKIP
Definition ngcbPP.hpp:29
ngcb_thread_t ngcbThrId(void)
Definition ngcbSchedThread.c:95
int ngcbSemPost(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:123
int ngcbSemInit(ngcb_sema_t *sp, unsigned int count, int type, void *arg)
Definition ngcbSchedSem.c:19
int ngcbSemDestroy(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:70
int ngcbSemWait(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:161
#define ngcbSEM_FAST
Definition ngcbSched.h:68
int ngcbThrJoin(ngcb_thread_t thread)
Definition ngcbSchedThread.c:83
int ngcbThrCreate(void *(*startFunc)(void *), void *arg, size_t stack, ngcb_thread_t *thread)
Definition ngcbSchedThread.c:19
int ngcbThrCancel(ngcb_thread_t thread)
Definition ngcbSchedThread.c:59
size_t NumPix()
Return frame size (pixels)
Definition ngcbPP.hpp:93
int sx
Lower left corner (x-direction)
Definition ngcbPP.hpp:66
int ftype
Frame type.
Definition ngcbPP.hpp:51
ngcb_pp_descr()
Constructor.
Definition ngcbPP.hpp:84
int result
Result code.
Definition ngcbPP.hpp:48
int ny
Dimension in y-direction.
Definition ngcbPP.hpp:75
int nx
Dimension in x-direction.
Definition ngcbPP.hpp:72
int bitPix
Bits per pixel as defined in the FITS-standard.
Definition ngcbPP.hpp:57
double crpix1
Reference pixel in x-direction.
Definition ngcbPP.hpp:78
double bscale
Scaling factor to be applied.
Definition ngcbPP.hpp:60
double bzero
Offset value to be added.
Definition ngcbPP.hpp:63
int fcnt
Frame counter.
Definition ngcbPP.hpp:54
size_t Size()
Return frame size (bytes)
Definition ngcbPP.hpp:96
double crpix2
Reference pixel in y-direction.
Definition ngcbPP.hpp:81
int sy
Lower left corner (y-direction)
Definition ngcbPP.hpp:69
Definition ngcbSched.h:78