12#error This is a C++ include file and cannot be used from plain C
27#define ngcbPP_SUCCESS 0x0000
28#define ngcbPP_SKIP 0x0001
29#define ngcbPP_FAILURE 0x0100
30#define ngcbPP_ERR_FATAL 0x1100
35#define ngcbPPLOG(...) do {char s[320]; snprintf(s, 320, __VA_ARGS__); Log(s);} while (0)
40#define ngcbPP_MAX_LIB 32
101typedef void *(*ngcb_pp_thr)(
void *arg);
120 strcpy(
ErrMsg(),
"semaphore creation failed");
126 strcpy(
ErrMsg(),
"semaphore creation failed");
219 if (
next->proc != NULL)
226 else if (
next->psync != NULL)
235 delete next->psync;
next->psync = NULL;
253 void Id(
int id) {id_ = id;}
256 int Id() {
return (id_);}
292 if ((
next->proc != NULL) || (
next->psync != NULL))
302 if (
next->proc != NULL)
307 sprintf(
ErrMsg(),
"processer %d thread synchronization failed",
319 tmpDescr_ =
next->procDescr;
320 next->procDescr = *descr;
338 next->procDescr = *descr;
345 next->procDescr.result = 0x0;
346 if (
next->proc != NULL)
352 sprintf(
ErrMsg(),
"processor %d thread creation failed",
Id());
359 next->psync->Start();
368 out =
next->Execute(in, descr);
419 void Log(
const char *msg) {
425 unsigned char *m = (
unsigned char *)malloc(size);
429 int pageSize = (int)sysconf(_SC_PAGESIZE);
430 if (pageSize < 1) pageSize = 4096;
435 for (i=0;i<size;i+=pageSize) m[i] = (
unsigned char)0;
457static void *ngcbPP_Proc(
void *arg)
466 pthread_sigmask(SIG_BLOCK, &set, (sigset_t *)NULL);
479static void *ngcpPP_ProcSync(
void *arg)
488 pthread_sigmask(SIG_BLOCK, &set, (sigset_t *)NULL);
561#define NGC_REGISTER_PP_MOD(type, name) extern "C" { type name; \
562 int _ngcb_pp_ ## name = 1 ; }
606 if (dlclose(dl_[i]) != 0)
ngcbPPLOG(
"failure - %s\n", dlerror());
623 if (newProc->
Id() < 0)
652 int Lib(
const char *name) {
658 strcpy(
ErrMsg(),
"maximum number of external libraries reached");
665 snprintf(libName,
sizeof(libName),
"lib%s.so", name);
666 ngcbPPLOG(
"loading library <%s>\n", libName);
667 dl = dlopen(libName, RTLD_NOW|RTLD_LOCAL);
670 strcpy(
ErrMsg(), dlerror());
679 int Add(
const char *module) {
690 newProc =
new ngcbPP(idx_++);
707 snprintf(cookie,
sizeof(cookie),
"_ngcb_pp_%s", module);
724 if (dlsym(dl_[i], cookie) != NULL)
726 ngcbPPLOG(
"module <%s> identified\n", module);
735 char *err = dlerror();
742 ngcbPPLOG(
"invalid factory symbol <%s>\n", module);
747 ngcbPPLOG(
"module <%s> registered\n", module);
762 ngcbPPLOG(
"loading module <%s>\n", module);
763 snprintf(libName,
sizeof(libName),
"lib%s.so", module);
764 dl = dlopen(libName, RTLD_NOW|RTLD_LOCAL);
767 strcpy(
ErrMsg(), dlerror());
774 if (dlsym(dl, cookie) == NULL)
776 ngcbPPLOG(
"unloading module <%s>\n", module);
777 if (dlclose(dl) != 0)
781 sprintf(
ErrMsg(),
"module <%s> rejected - identification failed",
793 char *err = dlerror();
794 if (err != NULL) strcpy(
ErrMsg(), err);
795 else sprintf(
ErrMsg(),
"invalid factory symbol <%s>", module);
800 ngcbPPLOG(
"unloading module <%s>\n", module);
801 if (dlclose(dl) != 0)
812 ngcbPPLOG(
"creating processor for module <%s>\n", module);
813 newProc = f->
Create(idx_++);
821 ngcbPPLOG(
"unloading module <%s>\n", module);
822 if (dlclose(dl) != 0)
850 out = first_->Execute(buffer, descr);
863 for (p = first_; p != NULL; p = p->
next)
876 for (p = first_; p != NULL; p = p->
next)
905 ngcbPPLOG(
"fast-sync not available - thread creation failed\n");
933 for (p = first_; p != NULL; p = p->
next) p->
logLevel = level;
938 void Log(
const char *msg) {
ngcbPIPELINE()
Constructor.
Definition ngcbPP.hpp:577
int Lib(const char *name)
Load external library.
Definition ngcbPP.hpp:652
virtual ~ngcbPIPELINE()
Destructor.
Definition ngcbPP.hpp:588
void LogLevel(int level)
Set logging level.
Definition ngcbPP.hpp:930
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:614
int logLevel
Logging level.
Definition ngcbPP.hpp:574
void Log(const char *msg)
Logging function.
Definition ngcbPP.hpp:938
void Parallelize(int fastSync=0)
Parallelize processing pipeline.
Definition ngcbPP.hpp:857
int verboseLevel
Verbose level.
Definition ngcbPP.hpp:571
void VerboseLevel(int level)
Set verbose level.
Definition ngcbPP.hpp:923
int Add(const char *module)
Load processor from module and add it to the end of the pipeline.
Definition ngcbPP.hpp:679
void Add(ngcbPP *newProc)
Add processor to the end of the pipeline.
Definition ngcbPP.hpp:617
void * Execute(void *buffer, ngcb_pp_descr *descr)
Execute processing pipeline.
Definition ngcbPP.hpp:839
Definition ngcbPP.hpp:515
ngcbPP_FACTORY()
Constructor.
Definition ngcbPP.hpp:518
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:526
ngcbPP * Create(int id)
Creator.
Definition ngcbPP.hpp:529
virtual ~ngcbPP_FACTORY()
Destructor.
Definition ngcbPP.hpp:523
virtual ngcbPP * Make(int id)
Maker with id.
Definition ngcbPP.hpp:551
Definition ngcbPP.hpp:177
int rdOnly
Input buffer read-only flag.
Definition ngcbPP.hpp:397
ngcb_pp_descr procDescr
Processing thread buffer descriptor (forward)
Definition ngcbPP.hpp:201
virtual ~ngcbPP()
Destructor.
Definition ngcbPP.hpp:210
int NumBuf()
Return number of frame buffers.
Definition ngcbPP.hpp:259
void Init_(int id)
Initialization function.
Definition ngcbPP.hpp:400
int numBuf
Number of frame buffers.
Definition ngcbPP.hpp:394
int verboseLevel
Verbose level.
Definition ngcbPP.hpp:180
int logLevel
Logging level.
Definition ngcbPP.hpp:183
int RdOnly()
Return input buffer read-only flag.
Definition ngcbPP.hpp:262
void * Execute(void *buffer, ngcb_pp_descr *descr)
Execute Processor.
Definition ngcbPP.hpp:265
int Initialized()
Return initialization flag.
Definition ngcbPP.hpp:247
int Id()
Return processor ID.
Definition ngcbPP.hpp:256
void Id(int id)
Assign id.
Definition ngcbPP.hpp:253
ngcbPP(int id)
Constructor.
Definition ngcbPP.hpp:207
ngcbPP()
Constructor.
Definition ngcbPP.hpp:204
int initialized
Initialization flag.
Definition ngcbPP.hpp:391
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:250
void * Malloc(size_t size)
Preferred buffer allocation.
Definition ngcbPP.hpp:424
ngcb_pp_thr proc
Built-in processing thread.
Definition ngcbPP.hpp:192
ngcbPP * next
Next processor.
Definition ngcbPP.hpp:186
pthread_t thid
Thread id.
Definition ngcbPP.hpp:195
void * procBuf
Processing thread buffer (forward)
Definition ngcbPP.hpp:198
void Log(const char *msg)
Logging function.
Definition ngcbPP.hpp:419
virtual void * Process(void *buffer, ngcb_pp_descr *descr)
Pixel-Processor.
Definition ngcbPP.hpp:384
ngcb_pp_sync * psync
Thread synchronization primitive.
Definition ngcbPP.hpp:189
Definition ngcbPP.hpp:107
int Initialized()
Return initialization flag.
Definition ngcbPP.hpp:142
char * ErrMsg()
Error message.
Definition ngcbPP.hpp:145
pthread_t thid
Thread id.
Definition ngcbPP.hpp:110
ngcb_pp_sync()
Constructor.
Definition ngcbPP.hpp:113
void Wait()
Wait.
Definition ngcbPP.hpp:154
virtual ~ngcb_pp_sync()
Destructor.
Definition ngcbPP.hpp:133
void Start()
Start.
Definition ngcbPP.hpp:148
void Ack()
Acknowledge.
Definition ngcbPP.hpp:157
void Join()
Join.
Definition ngcbPP.hpp:151
#define ngcbPP_ERR_FATAL
Definition ngcbPP.hpp:30
#define ngcbPP_MAX_LIB
Definition ngcbPP.hpp:40
#define ngcbPPLOG(...)
Definition ngcbPP.hpp:35
void *(* ngcb_pp_thr)(void *arg)
Definition ngcbPP.hpp:101
#define ngcbPP_FAILURE
Definition ngcbPP.hpp:29
#define ngcbPP_SUCCESS
Definition ngcbPP.hpp:27
#define ngcbPP_SKIP
Definition ngcbPP.hpp:28
ngcb_thread_t ngcbThrId(void)
Definition ngcbSchedThread.c:94
int ngcbSemPost(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:122
int ngcbSemInit(ngcb_sema_t *sp, unsigned int count, int type, void *arg)
Definition ngcbSchedSem.c:18
int ngcbSemDestroy(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:69
int ngcbSemWait(ngcb_sema_t *sp)
Definition ngcbSchedSem.c:160
#define ngcbSEM_FAST
Definition ngcbSched.h:67
int ngcbThrJoin(ngcb_thread_t thread)
Definition ngcbSchedThread.c:82
int ngcbThrCreate(void *(*startFunc)(void *), void *arg, size_t stack, ngcb_thread_t *thread)
Definition ngcbSchedThread.c:18
int ngcbThrCancel(ngcb_thread_t thread)
Definition ngcbSchedThread.c:58
size_t NumPix()
Return frame size (pixels)
Definition ngcbPP.hpp:92
int sx
Lower left corner (x-direction)
Definition ngcbPP.hpp:65
int ftype
Frame type.
Definition ngcbPP.hpp:50
ngcb_pp_descr()
Constructor.
Definition ngcbPP.hpp:83
int result
Result code.
Definition ngcbPP.hpp:47
int ny
Dimension in y-direction.
Definition ngcbPP.hpp:74
int nx
Dimension in x-direction.
Definition ngcbPP.hpp:71
int bitPix
Bits per pixel as defined in the FITS-standard.
Definition ngcbPP.hpp:56
double crpix1
Reference pixel in x-direction.
Definition ngcbPP.hpp:77
double bscale
Scaling factor to be applied.
Definition ngcbPP.hpp:59
double bzero
Offset value to be added.
Definition ngcbPP.hpp:62
int fcnt
Frame counter.
Definition ngcbPP.hpp:53
size_t Size()
Return frame size (bytes)
Definition ngcbPP.hpp:95
double crpix2
Reference pixel in y-direction.
Definition ngcbPP.hpp:80
int sy
Lower left corner (y-direction)
Definition ngcbPP.hpp:68
Definition ngcbSched.h:77