24 #include <fvutils/ipc/shm_lut.h> 25 #include <fvutils/ipc/shm_exceptions.h> 26 #include <utils/system/console_colors.h> 58 SharedMemoryLookupTable::SharedMemoryLookupTable(
const char *lut_id,
62 unsigned int bytes_per_cell)
63 :
SharedMemory(FIREVISION_SHM_LUT_MAGIC_TOKEN, false, true, true)
65 constructor(lut_id, width, height, depth, bytes_per_cell,
false);
79 :
SharedMemory(FIREVISION_SHM_LUT_MAGIC_TOKEN, is_read_only, false, false)
81 constructor(lut_id, 0, 0, 0, 0, is_read_only);
86 SharedMemoryLookupTable::constructor(
const char *
lut_id,
105 throw Exception(
"Could not create shared memory segment");
113 delete __priv_header;
137 __lut_id = strdup(lut_id);
150 return (
unsigned char *)
_memptr;
160 return __raw_header->
width;
170 return __raw_header->
height;
180 return __raw_header->
depth;
201 SharedMemory::list(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, lister);
222 SharedMemory::erase_orphaned(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, lister);
237 bool ex = SharedMemory::exists(FIREVISION_SHM_LUT_MAGIC_TOKEN, h);
250 SharedMemory::erase(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, NULL);
267 __bytes_per_cell = 0;
283 __lut_id = strdup(lut_id);
305 __lut_id = strdup(lut_id);
320 if( h->__lut_id != NULL ) {
321 __lut_id = strdup(h->__lut_id);
325 __width = h->__width;
326 __height = h->__height;
327 __depth = h->__depth;
328 __bytes_per_cell = h->__bytes_per_cell;
338 if ( __lut_id != NULL ) {
362 if (__header == NULL) {
363 return __width * __height * __depth * __bytes_per_cell;
365 return __header->width * __header->height * __header->depth * __header->bytes_per_cell;
375 if (__lut_id == NULL) {
378 }
else if (strncmp(h->
lut_id, __lut_id, LUT_ID_MAX_LENGTH) == 0) {
380 if ( (__width == 0) ||
383 (__bytes_per_cell == 0) ||
384 ( (h->
width == __width) &&
385 (h->
height == __height) &&
386 (h->
depth == __depth) &&
404 if (__header == NULL) {
405 cout <<
"No image set" << endl;
408 cout <<
"SharedMemory Lookup Table Info: " << endl
409 <<
" LUT ID: " << __header->lut_id << endl
410 <<
" dimensions: " << __header->width <<
"x" << __header->height <<
"x" 411 << __header->depth << endl
412 <<
" bytes per cell: " << __header->bytes_per_cell << endl;
423 return ( (__width > 0) &&
426 (__bytes_per_cell > 0) );
436 strncpy(__header->lut_id, __lut_id, LUT_ID_MAX_LENGTH);
437 __header->width = __width;
438 __header->height = __height;
439 __header->depth = __depth;
440 __header->bytes_per_cell = __bytes_per_cell;
474 return ( (strncmp(__lut_id, h->__lut_id, LUT_ID_MAX_LENGTH) == 0) &&
475 (__width == h->__width) &&
476 (__height == h->__height) &&
477 (__depth == h->__depth) &&
478 (__bytes_per_cell == h->__bytes_per_cell) );
489 if (__header == NULL)
return 0;
490 return __header->width;
500 if (__header == NULL)
return 0;
501 return __header->height;
511 if (__header == NULL)
return 0;
512 return __header->depth;
522 if (__header == NULL)
return 0;
523 return __header->bytes_per_cell;
533 if (__header == NULL)
return NULL;
534 return __header->lut_id;
544 if ( __lut_id )
free(__lut_id);
545 __lut_id = strdup(lut_id);
578 cout << endl << cgreen <<
"FireVision Shared Memory Segments - Lookup Tables" 580 <<
"========================================================================================" << endl
582 printf (
"%-23s %-10s %-10s %-10s %-9s %-9s %-9s\n",
583 "LUT ID",
"ShmID",
"Semaphore",
"Bytes",
"Width",
"Height",
"State");
585 <<
"----------------------------------------------------------------------------------------" << endl;
598 cout <<
"No FireVision shared memory segments containing lookup tables found" << endl;
607 cout <<
"No orphaned FireVision shared memory segments containing lookup tables found" << endl;
612 int shm_id,
int semaphore,
613 unsigned int mem_size,
619 printf(
"%-23s %-10d %-10d %-10u %-9u %-9u %s%s\n",
620 h->
lut_id(), shm_id, semaphore, mem_size,
622 (SharedMemory::is_swapable(shm_id) ?
"S" :
""),
623 (SharedMemory::is_destroyed(shm_id) ?
"D" :
"")
const char * lut_id() const
Get LUT ID.
Fawkes library namespace.
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
virtual void print_header()
Print header of the table.
static void wipe(const char *lut_id)
Erase a specific shared memory segment that contains a LUT.
unsigned int width() const
Get LUT width.
unsigned int bytes_per_cell() const
Get bytes per cell.
bool is_read_only() const
Check for read-only mode.
bool set_lut_id(const char *lut_id)
Set LUT ID.
static bool exists(const char *lut_id)
Check LUT availability.
void free()
Detach from and maybe destroy the shared memory segment.
virtual ~SharedMemoryLookupTableLister()
Destructor.
Base class for exceptions in Fawkes.
void attach()
Attach to the shared memory segment.
unsigned int height() const
Get LUT height.
void * memptr() const
Get a pointer to the shared memory This method returns a pointer to the data-segment of the shared me...
unsigned int depth() const
Get LUT depth.
void * _memptr
Pointer to the data segment.
virtual void print_no_segments()
Print this if no matching segment was found.
SharedMemoryLookupTableLister()
Constructor.
unsigned char * buffer() const
Get LUT buffer.
bool _is_read_only
Read-only.
SharedMemoryHeader * _header
Data-specific header.
~SharedMemoryLookupTable()
Destructor.
static void cleanup(bool use_lister=true)
Erase all shared memory segments that contain FireVision LUTs.
Shared memory lookup table lister.
Throw if an inconsistent LUT was found.
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
SharedMemoryLookupTable(const char *lut_id, unsigned int width, unsigned int height, unsigned int depth=1, unsigned int bytes_per_cell=1)
Write Constructor.
virtual void print_footer()
Print footer of the table.
static void list()
List shared memory LUT segments.