ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcppAPP.hpp
Go to the documentation of this file.
1
8#ifndef ngcppAPP_H
9#define ngcppAPP_H
10
11
12#ifndef __cplusplus
13#error This is a C++ include file and cannot be used from plain C
14#endif
15
16/*
17 * System Headers
18 */
19#include <stdlib.h>
20#include <stdio.h>
21#include <string.h>
22#include <math.h>
23
24/*
25 * Local Headers
26 */
27#include <ngc/core/ngcpp.h>
29
32 ngcbSEM *semSync; //< Sync semaphpore
33 ngcbSEM *semAck; //< Acknowledge semaphore
34 pthread_t thid; //< Thread id
35 int idx; //< Process index
36
39 // cppcheck-suppress useInitializationList
40 thid = 0;
41 idx = 0;
42 semSync = new ngcbSEM(0);
43 semAck = new ngcbSEM(0);
44 }
45
47 ngcpp_thr_t(const ngcpp_thr_t &other) : thid(other.thid), idx(other.idx) {
48 semSync = new ngcbSEM(0);
49 semAck = new ngcbSEM(0);
50 }
51
54 if (this != &other)
55 {
56 thid = other.thid;
57 idx = other.idx;
58 if (semSync != NULL) delete semSync;
59 semSync = new ngcbSEM(0);
60 if (semAck != NULL) delete semAck;
61 semAck = new ngcbSEM(0);
62 }
63 return (*this);
64 }
65
67 virtual ~ngcpp_thr_t() {
68 if (semSync != NULL) delete semSync;
69 if (semAck != NULL) delete semAck;
70 }
71};
72
76
79 // cppcheck-suppress memsetClassFloat
80 memset(&frame, 0, sizeof(ngcppFRAME));
81 frame.fbuf = NULL;
82 }
83
85 ngcppFRAME_QUEUE(int ftype, int dtype, int nx, int ny, int nq, int scal = 1) {
86 char **queue = static_cast<char **>(malloc(nq * sizeof(char **)));
87
88 if (queue != NULL)
89 {
90 int i;
91 size_t size = static_cast<size_t>(nx) * static_cast<size_t>(ny);
92 switch (dtype)
93 {
96 size *= 2; break;
99 size *= 4; break;
100 case ngcppDTYPE_INT64:
102 size *= 8; break;
103 default:
104 break;
105 }
106 for (i=0;i<nq;i++)
107 {
108 queue[i] = static_cast<char *>(ngcppMalloc(size));
109 if (queue[i] == NULL)
110 {
111 int j;
112 for (j=0;j<i;j++) free(queue[j]);
113 free(queue);
114
115 // cppcheck-suppress memsetClassFloat
116 memset(&frame, 0, sizeof(ngcppFRAME));
117 frame.fbuf = NULL;
118 return;
119 }
120 }
121
122 // Initialize frame structure
123 frame.h.start_x = 0;
124 frame.h.start_y = 0;
125 frame.h.nx = nx;
126 frame.h.ny = ny;
127 frame.h.scal = scal;
128 frame.h.dtype = dtype;
129 frame.h.ftype = ftype;
130 ngcppInitFrame(&frame, queue, nq);
131 free(queue);
132 }
133 else
134 {
135 // cppcheck-suppress memsetClassFloat
136 memset(&frame, 0, sizeof(ngcppFRAME));
137 frame.fbuf = NULL;
138 return;
139 }
140 }
141
143 virtual ~ngcppFRAME_QUEUE() {}
144
146 int Valid() {return (frame.fbuf != NULL);}
147
149 char *Ptr() {return (frame.fbuf[frame.dptr]);}
150
152 void Publish(int flag) {ngcppPublish(flag, &frame);}
153
154};
155
158{
159public:
161 int nx;
162
164 int ny;
165
168
171
174
177
179 ngcppAPP();
180
182 virtual ~ngcppAPP();
183
185 virtual int Configure(char *erms);
186
188 virtual int Connect(const char *name, char *erms);
189
191 virtual int Disconnect(char *erms);
192
194 virtual int Alloc(unsigned char **buffer, int n, size_t size, char *erms);
195
197 virtual void Free(unsigned char **buffer, int n);
198
200 virtual int Clear(char *erms);
201
203 virtual int StartAcquisition(char *erms);
204
206 virtual int StopAcquisition(char *erms);
207
209 virtual void SkipData();
210
212 virtual int NextData(unsigned char *buffer, size_t size, uint64_t *ts,
213 char *erms);
214
216 virtual int Process(int instance, void *buffer, char *erms);
217
219 virtual void Publish();
220
222 virtual void ResetCounters(int cnt);
223
225 virtual int CheckParam(int *param, int running, int *idx);
226
228 virtual void Command(const char *command, char *reply);
229
231 virtual void AppStart();
232
234 int RunApp(int argc, char **argv, char *erms);
235
237 void TerminateProcesses();
238
240 void AddLog(const char *msg);
241
243 void Failure(const char *msg);
244
246 void FailureOverrun(const char *msg);
247
248protected:
249private:
251 void MainLoop_();
252
254 ngcpp_thr_t *thr_[8];
255};
256
257#endif
Definition ngcbTHREAD.hpp:68
int numProc
Number of processors.
Definition ngcppAPP.hpp:167
virtual int Clear(char *erms)
Clear data fifos.
Definition ngcppAPP.cpp:416
virtual void AppStart()
Enter main loop callback.
Definition ngcppAPP.cpp:586
void TerminateProcesses()
Terminate application processes.
Definition ngcppAPP.cpp:555
void FailureOverrun(const char *msg)
Signal buffer overrun (error condition)
Definition ngcppAPP.cpp:581
virtual int Disconnect(char *erms)
Disconnect from camera.
Definition ngcppAPP.cpp:369
virtual int Process(int instance, void *buffer, char *erms)
Process data (multithreaded, if numProc is greater than 1)
Definition ngcppAPP.cpp:437
ngcppAPP()
Application constructor.
Definition ngcppAPP.cpp:350
ngcbSEM * semData
Counting data buffer semaphore.
Definition ngcppAPP.hpp:173
void Failure(const char *msg)
Signal error condition.
Definition ngcppAPP.cpp:576
virtual int StopAcquisition(char *erms)
Stop image acquisition.
Definition ngcppAPP.cpp:420
int RunApp(int argc, char **argv, char *erms)
Run the application.
Definition ngcppAPP.cpp:458
virtual int NextData(unsigned char *buffer, size_t size, uint64_t *ts, char *erms)
Get next data buffer from camera.
Definition ngcppAPP.cpp:428
virtual int Configure(char *erms)
Configuration call-back.
Definition ngcppAPP.cpp:365
virtual int Connect(const char *name, char *erms)
Connect to camera.
Definition ngcppAPP.cpp:367
virtual int StartAcquisition(char *erms)
Start image acquisition.
Definition ngcppAPP.cpp:418
virtual void Free(unsigned char **buffer, int n)
Free circular buffer.
Definition ngcppAPP.cpp:401
virtual ~ngcppAPP()
Destructor.
Definition ngcppAPP.cpp:363
virtual void ResetCounters(int cnt)
Call-back to reset the application counters.
Definition ngcppAPP.cpp:445
virtual int CheckParam(int *param, int running, int *idx)
Check parameter range.
Definition ngcppAPP.cpp:447
virtual void Command(const char *command, char *reply)
Command handler.
Definition ngcppAPP.cpp:453
virtual void SkipData()
Skip next data buffer.
Definition ngcppAPP.cpp:422
bool mainLoopRunning
Main loop is running.
Definition ngcppAPP.hpp:176
int nx
x-dimension
Definition ngcppAPP.hpp:161
virtual void Publish()
Publisher call-back, executed after all data-processes have finished.
Definition ngcppAPP.cpp:443
int ny
y-dimension
Definition ngcppAPP.hpp:164
virtual int Alloc(unsigned char **buffer, int n, size_t size, char *erms)
Allocate circular buffer.
Definition ngcppAPP.cpp:371
int skipData
Enable data-skip call-back.
Definition ngcppAPP.hpp:170
void AddLog(const char *msg)
Add a message to the logging service.
Definition ngcppAPP.cpp:571
#define ngcppDTYPE_UINT16
Definition ngcppInt.h:221
#define ngcppDTYPE_INT64
Definition ngcppInt.h:219
#define ngcppDTYPE_REAL64
Definition ngcppInt.h:216
#define ngcppDTYPE_INT16
Definition ngcppInt.h:217
#define ngcppDTYPE_INT32
Definition ngcppInt.h:218
#define ngcppDTYPE_REAL32
Definition ngcppInt.h:215
int ngcppPublish(int syncMode, ngcppFRAME *frame)
Definition ngcppTransferQueue.c:688
void * ngcppMalloc(size_t size)
Definition ngcppOpen.c:478
void ngcppInitFrame(ngcppFRAME *frame, char **array, int n)
Definition ngcppTransferQueue.c:1155
char * Ptr()
Return current data pointer.
Definition ngcppAPP.hpp:149
void Publish(int flag)
Publish.
Definition ngcppAPP.hpp:152
ngcppFRAME frame
Definition ngcppAPP.hpp:75
ngcppFRAME_QUEUE()
Constructor.
Definition ngcppAPP.hpp:78
virtual ~ngcppFRAME_QUEUE()
Destructor.
Definition ngcppAPP.hpp:143
ngcppFRAME_QUEUE(int ftype, int dtype, int nx, int ny, int nq, int scal=1)
Initializing Constructor.
Definition ngcppAPP.hpp:85
int Valid()
Check if frame is valid.
Definition ngcppAPP.hpp:146
Definition ngcpp.h:279
Process synchronization structure.
Definition ngcppAPP.hpp:31
ngcbSEM * semAck
Definition ngcppAPP.hpp:33
pthread_t thid
Definition ngcppAPP.hpp:34
virtual ~ngcpp_thr_t()
Destructor.
Definition ngcppAPP.hpp:67
ngcpp_thr_t()
Constructor.
Definition ngcppAPP.hpp:38
int idx
Definition ngcppAPP.hpp:35
ngcpp_thr_t(const ngcpp_thr_t &other)
Copy constructor.
Definition ngcppAPP.hpp:47
ngcbSEM * semSync
Definition ngcppAPP.hpp:32
ngcpp_thr_t & operator=(const ngcpp_thr_t &other)
Operator =.
Definition ngcppAPP.hpp:53