Fawkes API
Fawkes Development Version
|
24 #include <fvutils/ipc/shm_exceptions.h>
25 #include <fvutils/ipc/shm_lut.h>
26 #include <utils/system/console_colors.h>
36 namespace firevision {
55 SharedMemoryLookupTable::SharedMemoryLookupTable(
const char * lut_id,
59 unsigned int bytes_per_cell)
60 :
SharedMemory(FIREVISION_SHM_LUT_MAGIC_TOKEN, false, true, true)
75 :
SharedMemory(FIREVISION_SHM_LUT_MAGIC_TOKEN, is_read_only, false, false)
81 SharedMemoryLookupTable::constructor(
const char * lut_id,
85 unsigned int bytes_per_cell,
102 throw Exception(
"Could not create shared memory segment");
143 return (
unsigned char *)
_memptr;
152 return raw_header_->
width;
161 return raw_header_->
height;
170 return raw_header_->
depth;
189 SharedMemory::list(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, lister);
209 SharedMemory::erase_orphaned(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, lister);
223 bool ex = SharedMemory::exists(FIREVISION_SHM_LUT_MAGIC_TOKEN, h);
235 SharedMemory::erase(FIREVISION_SHM_LUT_MAGIC_TOKEN, h, NULL);
263 unsigned int bytes_per_cell)
284 unsigned int bytes_per_cell)
300 if (h->lut_id_ != NULL) {
301 lut_id_ = strdup(h->lut_id_);
306 height_ = h->height_;
308 bytes_per_cell_ = h->bytes_per_cell_;
317 if (lut_id_ != NULL) {
338 if (header_ == NULL) {
339 return (
size_t)width_ * height_ * depth_ * bytes_per_cell_;
350 if (lut_id_ == NULL) {
353 }
else if (strncmp(h->
lut_id, lut_id_, LUT_ID_MAX_LENGTH) == 0) {
354 if ((width_ == 0) || (height_ == 0) || (depth_ == 0) || (bytes_per_cell_ == 0)
370 if (header_ == NULL) {
371 cout <<
"No image set" << endl;
374 cout <<
"SharedMemory Lookup Table Info: " << endl
375 <<
" LUT ID: " << header_->
lut_id << endl
376 <<
" dimensions: " << header_->
width <<
"x" << header_->
height <<
"x"
377 << header_->
depth << endl
388 return ((width_ > 0) && (height_ > 0) && (depth_ > 0) && (bytes_per_cell_ > 0));
397 strncpy(header_->
lut_id, lut_id_, LUT_ID_MAX_LENGTH - 1);
398 header_->
width = width_;
399 header_->
height = height_;
400 header_->
depth = depth_;
432 return ((strncmp(lut_id_, h->lut_id_, LUT_ID_MAX_LENGTH) == 0) && (width_ == h->width_)
433 && (height_ == h->height_) && (depth_ == h->depth_)
434 && (bytes_per_cell_ == h->bytes_per_cell_));
446 return header_->
width;
468 return header_->
depth;
531 << cgreen <<
"FireVision Shared Memory Segments - Lookup Tables" << cnormal << endl
532 <<
"========================================================================================"
535 printf(
"%-23s %-10s %-10s %-10s %-9s %-9s %-9s\n",
544 <<
"----------------------------------------------------------------------------------------"
556 cout <<
"No FireVision shared memory segments containing lookup tables found" << endl;
562 cout <<
"No orphaned FireVision shared memory segments containing lookup tables found" << endl;
569 unsigned int mem_size,
574 printf(
"%-23s %-10d %-10d %-10u %-9u %-9u %s%s\n",
581 (SharedMemory::is_swapable(shm_id) ?
"S" :
""),
582 (SharedMemory::is_destroyed(shm_id) ?
"D" :
""));
bool _is_read_only
Read-only.
unsigned char * buffer() const
Get LUT buffer.
Shared memory lookup table lister.
bool set_lut_id(const char *lut_id)
Set LUT ID.
void attach()
Attach to the shared memory segment.
bool is_read_only() const
Check for read-only mode.
void free()
Detach from and maybe destroy the shared memory segment.
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
static void wipe(const char *lut_id)
Erase a specific shared memory segment that contains a LUT.
Throw if an inconsistent LUT was found.
static void list()
List shared memory LUT segments.
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
SharedMemoryLookupTableLister()
Constructor.
SharedMemoryHeader * _header
Data-specific header.
virtual ~SharedMemoryLookupTableLister()
Destructor.
Fawkes library namespace.
static bool exists(const char *lut_id)
Check LUT availability.
const char * lut_id() const
Get LUT ID.
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_no_segments()
Print this if no matching segment was found.
unsigned int width() const
Get LUT width.
unsigned int bytes_per_cell() const
Get bytes per cell.
unsigned int depth() const
Get LUT depth.
virtual void print_footer()
Print footer of the table.
unsigned int height() const
Get LUT height.
void * _memptr
Pointer to the data segment.
~SharedMemoryLookupTable()
Destructor.
virtual void print_header()
Print header of the table.
static void cleanup(bool use_lister=true)
Erase all shared memory segments that contain FireVision LUTs.
Base class for exceptions in Fawkes.