ngc 1.5.0
 
Loading...
Searching...
No Matches
ngcdcsSHM.hpp
Go to the documentation of this file.
1
8#ifndef ngcdcsSHM_H
9#define ngcdcsSHM_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#include <stdio.h>
18#include <stdlib.h>
19#include <string.h>
20#include <unistd.h>
21#include <errno.h>
22#include <sys/shm.h>
23
24#include <ngc/core/ngcb.h>
26
30#define ngcdcsSHM_NAME_DEFAULT "NGC"
31
35#define ngcdcsSHM_NUM_BUF 2
36
37
41class ngcdcsSHM {
42public:
44 char name[64];
45
47 char type[64];
48
50 void *spare;
51
53 ngcdcsSHM();
54
56 explicit ngcdcsSHM(FILE *wd);
57
59 ngcdcsSHM(FILE *wd, int n);
60
62 ngcdcsSHM(FILE *wd, const char *s);
63
65 ngcdcsSHM(FILE *wd, const char *s, int n);
66
67 // Destructor
68 virtual ~ngcdcsSHM();
69
71 int Initialized() {return (initialized_);}
72
74 char *ErrMsg() {return (erms_);}
75
77 int NumBuf(int n);
78
80 int NumBuf() {return (numBuf_);}
81
83 void *Buffer(int noWait=1);
84
86 int Update(const ngcdcs_finfo_t &finfo, int endian, int fullFrame = 0);
87
89 void Next();
90
92 int Export(const ngcdcs_finfo_t &finfo, int endian);
93
95 void Wait();
96
98 int TryWait();
99
101 int Locked();
102
104 int LockNext(int noWait = 1);
105
107 void Unlock(int noWait);
108
110 virtual void *Alloc(size_t size);
111
113 virtual void Free();
114
116 virtual int SetName(const char *newName);
117
118protected:
120 FILE *watchdog;
121
123 void **buffer;
124
126 size_t bufferSize;
127
129 char thisHost[46];
130
132 void Initialized(int flag) {
133 if (flag) initialized_ = 1;
134 else initialized_ = 0;
135 }
136
138 void Reset() {idx_ = 0;}
139
141 void InvalidateBuffers() {idx_ = -1;}
142
144 virtual void InvalidateEvent() {};
145
147 virtual void BufferWait(int idx);
148
150 virtual int BufferLocked(int idx);
151
153 virtual int BufferLock(int idx);
154
156 virtual int BufferTryLock(int idx);
157
159 virtual void BufferUnlock(int idx) {};
160
162 virtual int Publish(int idx, const ngcdcs_finfo_t &finfo, int endian,
163 int fullFrame);
164
165private:
167 void Init_();
168
170 char erms_[256];
171
173 int initialized_;
174
176 int numBuf_;
177
179 int idx_;
180
182 int spare_;
183
184};
185
186#endif
int NumBuf()
Return number of buffers.
Definition ngcdcsSHM.hpp:80
virtual int BufferTryLock(int idx)
Try to lock buffer[idx].
Definition ngcdcsSHM.cpp:497
void ** buffer
Pointers to shared memory buffers.
Definition ngcdcsSHM.hpp:123
virtual void BufferWait(int idx)
Wait for buffer[idx].
Definition ngcdcsSHM.cpp:480
size_t bufferSize
Buffer size.
Definition ngcdcsSHM.hpp:126
ngcdcsSHM()
Constructor.
Definition ngcdcsSHM.cpp:30
void * spare
Spare buffer.
Definition ngcdcsSHM.hpp:50
virtual int Publish(int idx, const ngcdcs_finfo_t &finfo, int endian, int fullFrame)
Publish buffer.
Definition ngcdcsSHM.cpp:503
virtual int BufferLocked(int idx)
Check if buffer[idx] is locked.
Definition ngcdcsSHM.cpp:485
int TryWait()
Return zero when current buffer is not locked.
Definition ngcdcsSHM.cpp:334
virtual int SetName(const char *newName)
Set new interface name.
Definition ngcdcsSHM.cpp:474
char type[64]
Interface type.
Definition ngcdcsSHM.hpp:47
char * ErrMsg()
Error message.
Definition ngcdcsSHM.hpp:74
int Initialized()
Check if initialization was OK.
Definition ngcdcsSHM.hpp:71
virtual void BufferUnlock(int idx)
Unlock buffer.
Definition ngcdcsSHM.hpp:159
void Wait()
Wait until current buffer is unlocked.
Definition ngcdcsSHM.cpp:309
void Initialized(int flag)
Set initialization flag.
Definition ngcdcsSHM.hpp:132
char thisHost[46]
This host.
Definition ngcdcsSHM.hpp:129
void Reset()
Reset buffer index.
Definition ngcdcsSHM.hpp:138
virtual void * Alloc(size_t size)
Allocate shared memory area.
Definition ngcdcsSHM.cpp:397
int Export(const ngcdcs_finfo_t &finfo, int endian)
Update the current buffer and switch to the next item.
Definition ngcdcsSHM.cpp:291
void Unlock(int noWait)
Unlock resources.
Definition ngcdcsSHM.cpp:320
int Update(const ngcdcs_finfo_t &finfo, int endian, int fullFrame=0)
Update the current buffer.
Definition ngcdcsSHM.cpp:263
char name[64]
Interface name for attachment.
Definition ngcdcsSHM.hpp:44
void * Buffer(int noWait=1)
Get pointer to current buffer.
Definition ngcdcsSHM.cpp:221
int LockNext(int noWait=1)
Lock next buffer.
Definition ngcdcsSHM.cpp:366
virtual ~ngcdcsSHM()
Definition ngcdcsSHM.cpp:81
void InvalidateBuffers()
Invalidate buffers.
Definition ngcdcsSHM.hpp:141
virtual void Free()
Release allocated resources.
Definition ngcdcsSHM.cpp:447
void Next()
Switch to the next buffer.
Definition ngcdcsSHM.cpp:285
virtual void InvalidateEvent()
Invalidate last event.
Definition ngcdcsSHM.hpp:144
int Locked()
Check if next buffer is locked.
Definition ngcdcsSHM.cpp:350
virtual int BufferLock(int idx)
Lock buffer[idx].
Definition ngcdcsSHM.cpp:491
FILE * watchdog
Watchdog stream.
Definition ngcdcsSHM.hpp:120
Definition ngcdcsFINFO.hpp:468