ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcppAPP.hpp
Go to the documentation of this file.
1
7#ifndef ngcppAPP_H
8#define ngcppAPP_H
9
10
11#ifndef __cplusplus
12#error This is a C++ include file and cannot be used from plain C
13#endif
14
15/*
16 * System Headers
17 */
18#include <stdlib.h>
19#include <stdio.h>
20#include <string.h>
21#include <math.h>
22
23/*
24 * Local Headers
25 */
26#include <ngc/core/ngcpp.h>
28
31 ngcbSEM *semSync; //< Sync semaphpore
32 ngcbSEM *semAck; //< Acknowledge semaphore
33 pthread_t thid; //< Thread id
34 int idx; //< Process index
35
38 // cppcheck-suppress useInitializationList
39 thid = 0;
40 idx = 0;
41 semSync = new ngcbSEM(0);
42 semAck = new ngcbSEM(0);
43 }
44
46 ngcpp_thr_t(const ngcpp_thr_t &other) : thid(other.thid), idx(other.idx) {
47 semSync = new ngcbSEM(0);
48 semAck = new ngcbSEM(0);
49 }
50
53 if (this != &other)
54 {
55 thid = other.thid;
56 idx = other.idx;
57 if (semSync != NULL) delete semSync;
58 semSync = new ngcbSEM(0);
59 if (semAck != NULL) delete semAck;
60 semAck = new ngcbSEM(0);
61 }
62 return (*this);
63 }
64
66 virtual ~ngcpp_thr_t() {
67 if (semSync != NULL) delete semSync;
68 if (semAck != NULL) delete semAck;
69 }
70};
71
75
78 // cppcheck-suppress memsetClassFloat
79 memset(&frame, 0, sizeof(ngcppFRAME));
80 frame.fbuf = NULL;
81 }
82
84 ngcppFRAME_QUEUE(int ftype, int dtype, int nx, int ny, int nq, int scal = 1) {
85 char **queue = static_cast<char **>(malloc(nq * sizeof(char **)));
86
87 if (queue != NULL)
88 {
89 int i;
90 size_t size = static_cast<size_t>(nx) * static_cast<size_t>(ny);
91 switch (dtype)
92 {
95 size *= 2; break;
98 size *= 4; break;
101 size *= 8; break;
102 default:
103 break;
104 }
105 for (i=0;i<nq;i++)
106 {
107 queue[i] = static_cast<char *>(ngcppMalloc(size));
108 if (queue[i] == NULL)
109 {
110 int j;
111 for (j=0;j<i;j++) free(queue[j]);
112 free(queue);
113
114 // cppcheck-suppress memsetClassFloat
115 memset(&frame, 0, sizeof(ngcppFRAME));
116 frame.fbuf = NULL;
117 return;
118 }
119 }
120
121 // Initialize frame structure
122 frame.h.start_x = 0;
123 frame.h.start_y = 0;
124 frame.h.nx = nx;
125 frame.h.ny = ny;
126 frame.h.scal = scal;
127 frame.h.dtype = dtype;
128 frame.h.ftype = ftype;
129 ngcppInitFrame(&frame, queue, nq);
130 free(queue);
131 }
132 else
133 {
134 // cppcheck-suppress memsetClassFloat
135 memset(&frame, 0, sizeof(ngcppFRAME));
136 frame.fbuf = NULL;
137 return;
138 }
139 }
140
142 virtual ~ngcppFRAME_QUEUE() {}
143
145 int Valid() {return (frame.fbuf != NULL);}
146
148 char *Ptr() {return (frame.fbuf[frame.dptr]);}
149
151 void Publish(int flag) {ngcppPublish(flag, &frame);}
152
153};
154
157{
158public:
160 int nx;
161
163 int ny;
164
167
170
173
176
178 ngcppAPP();
179
181 virtual ~ngcppAPP();
182
184 virtual int Configure(char *erms);
185
187 virtual int Connect(const char *name, char *erms);
188
190 virtual int Disconnect(char *erms);
191
193 virtual int Alloc(unsigned char **buffer, int n, size_t size, char *erms);
194
196 virtual void Free(unsigned char **buffer, int n);
197
199 virtual int Clear(char *erms);
200
202 virtual int StartAcquisition(char *erms);
203
205 virtual int StopAcquisition(char *erms);
206
208 virtual void SkipData();
209
211 virtual int NextData(unsigned char *buffer, size_t size, uint64_t *ts,
212 char *erms);
213
215 virtual int Process(int instance, void *buffer, char *erms);
216
218 virtual void Publish();
219
221 virtual void ResetCounters(int cnt);
222
224 virtual int CheckParam(int *param, int running, int *idx);
225
227 virtual void Command(const char *command, char *reply);
228
230 virtual void AppStart();
231
233 int RunApp(int argc, char **argv, char *erms);
234
236 void TerminateProcesses();
237
239 void AddLog(const char *msg);
240
242 void Failure(const char *msg);
243
245 void FailureOverrun(const char *msg);
246
247protected:
248private:
250 void MainLoop_();
251
253 ngcpp_thr_t *thr_[8];
254};
255
256#endif
Definition ngcbTHREAD.hpp:67
int numProc
Number of processors.
Definition ngcppAPP.hpp:166
virtual int Clear(char *erms)
Clear data fifos.
Definition ngcppAPP.cpp:415
virtual void AppStart()
Enter main loop callback.
Definition ngcppAPP.cpp:585
void TerminateProcesses()
Terminate application processes.
Definition ngcppAPP.cpp:554
void FailureOverrun(const char *msg)
Signal buffer overrun (error condition)
Definition ngcppAPP.cpp:580
virtual int Disconnect(char *erms)
Disconnect from camera.
Definition ngcppAPP.cpp:368
virtual int Process(int instance, void *buffer, char *erms)
Process data (multithreaded, if numProc is greater than 1)
Definition ngcppAPP.cpp:436
ngcppAPP()
Application constructor.
Definition ngcppAPP.cpp:349
ngcbSEM * semData
Counting data buffer semaphore.
Definition ngcppAPP.hpp:172
void Failure(const char *msg)
Signal error condition.
Definition ngcppAPP.cpp:575
virtual int StopAcquisition(char *erms)
Stop image acquisition.
Definition ngcppAPP.cpp:419
int RunApp(int argc, char **argv, char *erms)
Run the application.
Definition ngcppAPP.cpp:457
virtual int NextData(unsigned char *buffer, size_t size, uint64_t *ts, char *erms)
Get next data buffer from camera.
Definition ngcppAPP.cpp:427
virtual int Configure(char *erms)
Configuration call-back.
Definition ngcppAPP.cpp:364
virtual int Connect(const char *name, char *erms)
Connect to camera.
Definition ngcppAPP.cpp:366
virtual int StartAcquisition(char *erms)
Start image acquisition.
Definition ngcppAPP.cpp:417
virtual void Free(unsigned char **buffer, int n)
Free circular buffer.
Definition ngcppAPP.cpp:400
virtual ~ngcppAPP()
Destructor.
Definition ngcppAPP.cpp:362
virtual void ResetCounters(int cnt)
Call-back to reset the application counters.
Definition ngcppAPP.cpp:444
virtual int CheckParam(int *param, int running, int *idx)
Check parameter range.
Definition ngcppAPP.cpp:446
virtual void Command(const char *command, char *reply)
Command handler.
Definition ngcppAPP.cpp:452
virtual void SkipData()
Skip next data buffer.
Definition ngcppAPP.cpp:421
bool mainLoopRunning
Main loop is running.
Definition ngcppAPP.hpp:175
int nx
x-dimension
Definition ngcppAPP.hpp:160
virtual void Publish()
Publisher call-back, executed after all data-processes have finished.
Definition ngcppAPP.cpp:442
int ny
y-dimension
Definition ngcppAPP.hpp:163
virtual int Alloc(unsigned char **buffer, int n, size_t size, char *erms)
Allocate circular buffer.
Definition ngcppAPP.cpp:370
int skipData
Enable data-skip call-back.
Definition ngcppAPP.hpp:169
void AddLog(const char *msg)
Add a message to the logging service.
Definition ngcppAPP.cpp:570
#define ngcppDTYPE_UINT16
Definition ngcppInt.h:220
#define ngcppDTYPE_INT64
Definition ngcppInt.h:218
#define ngcppDTYPE_REAL64
Definition ngcppInt.h:215
#define ngcppDTYPE_INT16
Definition ngcppInt.h:216
#define ngcppDTYPE_INT32
Definition ngcppInt.h:217
#define ngcppDTYPE_REAL32
Definition ngcppInt.h:214
int ngcppPublish(int syncMode, ngcppFRAME *frame)
Definition ngcppData.c:687
void * ngcppMalloc(size_t size)
Definition ngcppOpen.c:477
void ngcppInitFrame(ngcppFRAME *frame, char **array, int n)
Definition ngcppData.c:1154
char * Ptr()
Return current data pointer.
Definition ngcppAPP.hpp:148
void Publish(int flag)
Publish.
Definition ngcppAPP.hpp:151
ngcppFRAME frame
Definition ngcppAPP.hpp:74
ngcppFRAME_QUEUE()
Constructor.
Definition ngcppAPP.hpp:77
virtual ~ngcppFRAME_QUEUE()
Destructor.
Definition ngcppAPP.hpp:142
ngcppFRAME_QUEUE(int ftype, int dtype, int nx, int ny, int nq, int scal=1)
Initializing Constructor.
Definition ngcppAPP.hpp:84
int Valid()
Check if frame is valid.
Definition ngcppAPP.hpp:145
Definition ngcpp.h:278
Process synchronization structure.
Definition ngcppAPP.hpp:30
ngcbSEM * semAck
Definition ngcppAPP.hpp:32
pthread_t thid
Definition ngcppAPP.hpp:33
virtual ~ngcpp_thr_t()
Destructor.
Definition ngcppAPP.hpp:66
ngcpp_thr_t()
Constructor.
Definition ngcppAPP.hpp:37
int idx
Definition ngcppAPP.hpp:34
ngcpp_thr_t(const ngcpp_thr_t &other)
Copy constructor.
Definition ngcppAPP.hpp:46
ngcbSEM * semSync
Definition ngcppAPP.hpp:31
ngcpp_thr_t & operator=(const ngcpp_thr_t &other)
Operator =.
Definition ngcppAPP.hpp:52