ngc 1.4.0
 
Loading...
Searching...
No Matches
ngcdcsSHM.hpp
Go to the documentation of this file.
1
7#ifndef ngcdcsSHM_H
8#define ngcdcsSHM_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#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19#include <unistd.h>
20#include <errno.h>
21#include <sys/shm.h>
22
23#include <ngc/core/ngcb.h>
25
29#define ngcdcsSHM_NAME_DEFAULT "NGC"
30
34#define ngcdcsSHM_NUM_BUF 2
35
36
40class ngcdcsSHM {
41public:
43 char name[64];
44
46 char type[64];
47
49 void *spare;
50
52 ngcdcsSHM();
53
55 explicit ngcdcsSHM(FILE *wd);
56
58 ngcdcsSHM(FILE *wd, int n);
59
61 ngcdcsSHM(FILE *wd, const char *s);
62
64 ngcdcsSHM(FILE *wd, const char *s, int n);
65
66 // Destructor
67 virtual ~ngcdcsSHM();
68
70 int Initialized() {return (initialized_);}
71
73 char *ErrMsg() {return (erms_);}
74
76 int NumBuf(int n);
77
79 int NumBuf() {return (numBuf_);}
80
82 void *Buffer(int noWait=1);
83
85 int Update(const ngcdcs_finfo_t &finfo, int endian, int fullFrame = 0);
86
88 void Next();
89
91 int Export(const ngcdcs_finfo_t &finfo, int endian);
92
94 void Wait();
95
97 int TryWait();
98
100 int Locked();
101
103 int LockNext(int noWait = 1);
104
106 void Unlock(int noWait);
107
109 virtual void *Alloc(size_t size);
110
112 virtual void Free();
113
115 virtual int SetName(const char *newName);
116
117protected:
119 FILE *watchdog;
120
122 void **buffer;
123
125 size_t bufferSize;
126
128 char thisHost[46];
129
131 void Initialized(int flag) {
132 if (flag) initialized_ = 1;
133 else initialized_ = 0;
134 }
135
137 void Reset() {idx_ = 0;}
138
140 void InvalidateBuffers() {idx_ = -1;}
141
143 virtual void InvalidateEvent() {};
144
146 virtual void BufferWait(int idx);
147
149 virtual int BufferLocked(int idx);
150
152 virtual int BufferLock(int idx);
153
155 virtual int BufferTryLock(int idx);
156
158 virtual void BufferUnlock(int idx) {};
159
161 virtual int Publish(int idx, const ngcdcs_finfo_t &finfo, int endian,
162 int fullFrame);
163
164private:
166 void Init_();
167
169 char erms_[256];
170
172 int initialized_;
173
175 int numBuf_;
176
178 int idx_;
179
181 int spare_;
182
183};
184
185#endif
int NumBuf()
Return number of buffers.
Definition ngcdcsSHM.hpp:79
virtual int BufferTryLock(int idx)
Try to lock buffer[idx].
Definition ngcdcsSHM.cpp:496
void ** buffer
Pointers to shared memory buffers.
Definition ngcdcsSHM.hpp:122
virtual void BufferWait(int idx)
Wait for buffer[idx].
Definition ngcdcsSHM.cpp:479
size_t bufferSize
Buffer size.
Definition ngcdcsSHM.hpp:125
ngcdcsSHM()
Constructor.
Definition ngcdcsSHM.cpp:29
void * spare
Spare buffer.
Definition ngcdcsSHM.hpp:49
virtual int Publish(int idx, const ngcdcs_finfo_t &finfo, int endian, int fullFrame)
Publish buffer.
Definition ngcdcsSHM.cpp:502
virtual int BufferLocked(int idx)
Check if buffer[idx] is locked.
Definition ngcdcsSHM.cpp:484
int TryWait()
Return zero when current buffer is not locked.
Definition ngcdcsSHM.cpp:333
virtual int SetName(const char *newName)
Set new interface name.
Definition ngcdcsSHM.cpp:473
char type[64]
Interface type.
Definition ngcdcsSHM.hpp:46
char * ErrMsg()
Error message.
Definition ngcdcsSHM.hpp:73
int Initialized()
Check if initialization was OK.
Definition ngcdcsSHM.hpp:70
virtual void BufferUnlock(int idx)
Unlock buffer.
Definition ngcdcsSHM.hpp:158
void Wait()
Wait until current buffer is unlocked.
Definition ngcdcsSHM.cpp:308
void Initialized(int flag)
Set initialization flag.
Definition ngcdcsSHM.hpp:131
char thisHost[46]
This host.
Definition ngcdcsSHM.hpp:128
void Reset()
Reset buffer index.
Definition ngcdcsSHM.hpp:137
virtual void * Alloc(size_t size)
Allocate shared memory area.
Definition ngcdcsSHM.cpp:396
int Export(const ngcdcs_finfo_t &finfo, int endian)
Update the current buffer and switch to the next item.
Definition ngcdcsSHM.cpp:290
void Unlock(int noWait)
Unlock resources.
Definition ngcdcsSHM.cpp:319
int Update(const ngcdcs_finfo_t &finfo, int endian, int fullFrame=0)
Update the current buffer.
Definition ngcdcsSHM.cpp:262
char name[64]
Interface name for attachment.
Definition ngcdcsSHM.hpp:43
void * Buffer(int noWait=1)
Get pointer to current buffer.
Definition ngcdcsSHM.cpp:220
int LockNext(int noWait=1)
Lock next buffer.
Definition ngcdcsSHM.cpp:365
virtual ~ngcdcsSHM()
Definition ngcdcsSHM.cpp:80
void InvalidateBuffers()
Invalidate buffers.
Definition ngcdcsSHM.hpp:140
virtual void Free()
Release allocated resources.
Definition ngcdcsSHM.cpp:446
void Next()
Switch to the next buffer.
Definition ngcdcsSHM.cpp:284
virtual void InvalidateEvent()
Invalidate last event.
Definition ngcdcsSHM.hpp:143
int Locked()
Check if next buffer is locked.
Definition ngcdcsSHM.cpp:349
virtual int BufferLock(int idx)
Lock buffer[idx].
Definition ngcdcsSHM.cpp:490
FILE * watchdog
Watchdog stream.
Definition ngcdcsSHM.hpp:119
Definition ngcdcsFINFO.hpp:462