20 #define ERROR_REPORT(er) if(global_error_report) (*global_error_report)(er,__FILE__,__LINE__);
24 #define LOG_INFO(li) if(global_log_info) (*global_log_info)(li);
55 header->max_n_images = mni;
69 return header->max_n_images;
89 if(imno >
header->n_images)
91 ERROR_REPORT(
"Can't calculate image offset without previous image.");
104 size_t offset = (
sizeof(
sharedim) + (previm->nx*previm->ny*
sizeof(IMDATA_TYPE)));
115 std::ostringstream oss;
118 if((
shmemid = shmget(mkey, sz, IPC_CREAT | 0666))<0)
120 shmemid = shmget(mkey, 1, 0666);
124 if(shmctl(
shmemid, IPC_RMID, 0) < 0)
126 oss <<
"Could not remove shared memory with key " << mkey <<
".";
127 ERROR_REPORT(oss.str().c_str());
130 oss <<
"Removed shared memory with key " << mkey <<
".";
131 LOG_INFO(oss.str().c_str());
134 if((
shmemid = shmget(mkey, sz, IPC_CREAT | 0666))<0)
136 oss <<
"Could not create shared memory with key " << mkey <<
".";
137 ERROR_REPORT(oss.str().c_str());
142 oss <<
"Shared memory created with key " << mkey <<
".";
143 LOG_INFO(oss.str().c_str());
161 header->last_image_abs = -1;
169 std::ostringstream oss;
170 static int reported = 0;
173 if((
shmemid = shmget(mkey, 0, 0666))<0)
177 oss <<
"Could not get shared memory with key " << mkey;
178 ERROR_REPORT(oss.str().c_str());
187 oss <<
"Could not attach shared memory with key " << mkey;
188 ERROR_REPORT(oss.str().c_str());
194 oss <<
"Could not get shared memory stats with key " << mkey;
195 ERROR_REPORT(oss.str().c_str());
202 oss <<
"Attached to shared memory with key " << mkey <<
" of size: " <<
shmemsz;
203 LOG_INFO(oss.str().c_str());
226 std::cerr <<
"Error in calc_im_pos. Last image " <<
" " <<
header->last_image<< std::endl;
230 offset =
sizeof(
sharedim) + ((intptr_t)nx)*((intptr_t)ny)*
sizeof(IMDATA_TYPE);
234 nextnextim = (
sharedim *)((intptr_t)nextim + offset);
246 if( (intptr_t)nextnextim - (intptr_t)
shmemptr > (intptr_t)(
shmemsz-1))
248 std::cerr <<
"Wrapping " << (
header->last_image) + 1 <<
" " << (intptr_t)nextnextim - (intptr_t)
shmemptr <<
"\n";
258 next_last_image =
header->last_image + 1;
273 nextim->imdata = (IMDATA_TYPE *) ((intptr_t)nextim+
sizeof(
sharedim));
280 header->last_image = next_last_image;
281 if(
header->n_images <= next_last_image)
header->n_images++;
297 if(imno < header->n_images)
305 sim.depth = simraw->depth;
306 sim.frameNo = simraw->frameNo;
307 sim.frame_time = simraw->frame_time;
308 sim.imdata = (IMDATA_TYPE *) ((intptr_t)simraw +
sizeof(
sharedim));
key_t shmemkey
The key used to lookup the shared memory.
int enable_next_image()
Increments last_image.
size_t shmemsz
Size of the shared memory block.
int set_max_n_images(int mni)
Sets max_n_images in the header.
struct shmid_ds shmstats
Used to retrieve shared memory block size.
sharedim_stack_header * header
Convenient pointer to the stack header, has same value as shmemptr.
sharedim< IMDATA_TYPE > * calc_im_pos(int imno)
Calculates the offset of the image given by imno, takes into account max_n_images and available space...
sharedim< IMDATA_TYPE > * set_next_image(int nx, int ny)
Sets the next image, and returns a pointer to it, but does not increment last_image.
int attach_shm(key_t mkey)
Attachess the shared memory. A Reader process should start here.
int shmemid
The shared memory id.
sharedim< IMDATA_TYPE > get_image(int imno)
Gets an image, as a sharedim structure, with the imdata pointer properly set for the calling process...
void * shmemptr
The pointer to the shared memory block.
Convenience structure for an image.
int create_shm(key_t mkey, size_t sz)
For the writer process, creates then attaches the shared memory.
Declarations for the shared image circular buffer.
intptr_t * image_list
Convenient pointer to the list of image offsets.
sharedim_stack()
Constructor.
int get_n_images()
Returns the value of n_images currently in the header.
int get_last_image()
Returns the value of last_image currently in the header.
int get_max_n_images()
Returns the value of max_n_images currently in the header.