Fawkes API
Fawkes Development Version
|
24 #include <core/exception.h>
25 #include <fvutils/ipc/shm_exceptions.h>
26 #include <fvutils/ipc/shm_image.h>
27 #include <utils/ipc/shm_exceptions.h>
28 #include <utils/misc/strndup.h>
29 #include <utils/system/console_colors.h>
40 namespace firevision {
61 SharedMemoryImageBuffer::SharedMemoryImageBuffer(
const char * image_id,
94 SharedMemoryImageBuffer::constructor(
const char * image_id,
103 _colorspace = cspace;
113 e.
append(
"SharedMemoryImageBuffer: could not attach to '%s'\n",
image_id);
201 throw Exception(
"Buffer is read-only. Not setting capture time.");
217 throw Exception(
"Buffer is read-only. Not setting capture time.");
230 return (
unsigned char *)
_memptr;
248 return raw_header->
width;
257 return raw_header->
height;
266 return raw_header->
roi_x;
275 return raw_header->
roi_y;
330 throw Exception(
"Buffer is read-only. Not setting ROI X.");
342 throw Exception(
"Buffer is read-only. Not setting ROI Y.");
354 throw Exception(
"Buffer is read-only. Not setting ROI width.");
366 throw Exception(
"Buffer is read-only. Not setting ROI height.");
384 throw Exception(
"Buffer is read-only. Not setting ROI X/Y.");
399 throw Exception(
"Buffer is read-only. Not setting circle X.");
411 throw Exception(
"Buffer is read-only. Not setting circle Y.");
423 throw Exception(
"Buffer is read-only. Not setting circle radius.");
437 throw Exception(
"Buffer is read-only. Not setting circle X/Y/radius.");
469 SharedMemory::list(FIREVISION_SHM_IMAGE_MAGIC_TOKEN, h, lister);
478 std::list<SharedMemoryImageBufferMetaData>
481 #if __cplusplus >= 201103L
482 std::unique_ptr<SharedMemoryImageBufferMetaDataCollector> lister(
486 std::auto_ptr<SharedMemoryImageBufferMetaDataCollector> lister(
491 SharedMemory::list(FIREVISION_SHM_IMAGE_MAGIC_TOKEN, h.get(), lister.get());
492 return lister->meta_data();
509 SharedMemory::erase_orphaned(FIREVISION_SHM_IMAGE_MAGIC_TOKEN, h, lister);
524 bool ex = SharedMemory::exists(FIREVISION_SHM_IMAGE_MAGIC_TOKEN, h);
538 SharedMemory::erase(FIREVISION_SHM_IMAGE_MAGIC_TOKEN, h, NULL);
550 _colorspace = CS_UNKNOWN;
556 _orig_image_id = NULL;
557 _orig_frame_id = NULL;
567 colorspace_t colorspace,
578 _orig_image_id = NULL;
579 _orig_frame_id = NULL;
582 _orig_colorspace = CS_UNKNOWN;
590 if (h->_image_id != NULL) {
591 _image_id = strdup(h->_image_id);
595 if (h->_frame_id != NULL) {
596 _frame_id = strdup(h->_frame_id);
600 _colorspace = h->_colorspace;
602 _height = h->_height;
603 _header = h->_header;
605 _orig_image_id = NULL;
606 _orig_frame_id = NULL;
609 _orig_colorspace = CS_UNKNOWN;
615 if (_image_id != NULL)
617 if (_frame_id != NULL)
619 if (_orig_image_id != NULL)
620 free(_orig_image_id);
621 if (_orig_frame_id != NULL)
622 free(_orig_frame_id);
640 if (_header == NULL) {
641 return colorspace_buffer_size(_colorspace, _width, _height);
643 return colorspace_buffer_size((colorspace_t)_header->
colorspace,
654 if (_image_id == NULL) {
657 }
else if (strncmp(h->
image_id, _image_id, IMAGE_ID_MAX_LENGTH) == 0) {
658 if ((_colorspace == CS_UNKNOWN)
659 || (((colorspace_t)h->
colorspace == _colorspace) && (h->
width == _width)
661 && (!_frame_id || (strncmp(h->
frame_id, _frame_id, FRAME_ID_MAX_LENGTH) == 0)))) {
687 return ((strncmp(_image_id, h->_image_id, IMAGE_ID_MAX_LENGTH) == 0)
688 && (!_frame_id || (strncmp(_frame_id, h->_frame_id, FRAME_ID_MAX_LENGTH) == 0))
689 && (_colorspace == h->_colorspace) && (_width == h->_width) && (_height == h->_height));
697 if (_image_id == NULL) {
698 cout <<
"No image set" << endl;
701 cout <<
"SharedMemory Image Info: " << endl;
702 printf(
" address: %p\n", _header);
703 cout <<
" image id: " << _image_id << endl
704 <<
" frame id: " << (_frame_id ? _frame_id :
"NOT SET") << endl
705 <<
" colorspace: " << _colorspace << endl
706 <<
" dimensions: " << _width <<
"x" << _height << endl;
723 return ((_colorspace != CS_UNKNOWN) && (_width > 0) && (_height > 0));
732 strncpy(header->
image_id, _image_id, IMAGE_ID_MAX_LENGTH - 1);
734 strncpy(header->
frame_id, _frame_id, FRAME_ID_MAX_LENGTH - 1);
737 header->
width = _width;
747 if (NULL != _orig_image_id)
748 free(_orig_image_id);
749 if (NULL != _image_id) {
750 _orig_image_id = strdup(_image_id);
753 _orig_image_id = NULL;
755 if (NULL != _orig_frame_id)
756 free(_orig_frame_id);
757 if (NULL != _frame_id) {
758 _orig_frame_id = strdup(_frame_id);
761 _orig_frame_id = NULL;
763 _orig_width = _width;
764 _orig_height = _height;
765 _orig_colorspace = _colorspace;
768 _image_id = strndup(header->
image_id, IMAGE_ID_MAX_LENGTH);
769 _frame_id = strndup(header->
frame_id, FRAME_ID_MAX_LENGTH);
770 _width = header->
width;
772 _colorspace = (colorspace_t)header->
colorspace;
778 if (NULL != _image_id) {
782 if (_orig_image_id != NULL) {
783 _image_id = strdup(_orig_image_id);
785 if (NULL != _frame_id) {
789 if (_orig_frame_id != NULL) {
790 _frame_id = strdup(_orig_frame_id);
792 _width = _orig_width;
793 _height = _orig_height;
794 _colorspace = _orig_colorspace;
817 return _header->
width;
858 if (_image_id != NULL)
869 if (_frame_id != NULL)
901 << cgreen <<
"FireVision Shared Memory Segments - Images" << cnormal << endl
902 <<
"========================================================================================"
905 printf(
"%-20s %-20s %-10s %-10s %-9s %-16s %-5s %-5s %s\n",
916 <<
"----------------------------------------------------------------------------------------"
928 cout <<
"No FireVision shared memory segments found" << endl;
934 cout <<
"No orphaned FireVision shared memory segments found" << endl;
941 unsigned int mem_size,
946 const char *colorspace = colorspace_to_string(h->
colorspace());
948 printf(
"%-20s %-20s %-10d %-10d %-9u %-16s %-5u %-5u %s%s\n",
957 (SharedMemory::is_swapable(shm_id) ?
"S" :
""),
958 (SharedMemory::is_destroyed(shm_id) ?
"D" :
""));
987 const char * frame_id,
988 colorspace_t colorspace,
1043 unsigned int mem_size,
1044 const void * memptr)
1054 SharedMemory::is_swapable(shm_id),
1055 SharedMemory::is_destroyed(shm_id)));
unsigned int roi_height() const
Get ROI height.
bool _is_read_only
Read-only.
colorspace_t colorspace() const
Get color space.
bool set_image_id(const char *image_id)
Set image number.
void set_circle_found(bool found)
Set circle found.
void attach()
Attach to the shared memory segment.
bool is_read_only() const
Check for read-only mode.
int circle_y() const
Get circle Y.
unsigned int width() const
Get image width.
void free()
Detach from and maybe destroy the shared memory segment.
void set_capture_time(fawkes::Time *time)
Set the capture time.
void set_roi_y(unsigned int roi_y)
Set ROI Y.
const timeval * get_timeval() const
Obtain the timeval where the time is stored.
static void wipe(const char *image_id)
Erase a specific shared memory segment that contains an image.
void set_roi_height(unsigned int roi_h)
Set ROI height.
unsigned int roi_width() const
Get ROI width.
static bool exists(const char *image_id)
Check image availability.
bool circle_found() const
Check if circle was found .
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
unsigned int height() const
Get image height.
void append(const char *format,...)
Append messages to the message list.
Shared memory image buffer lister.
SharedMemoryImageBuffer(const char *image_id, colorspace_t cspace, unsigned int width, unsigned int height)
Write Constructor.
SharedMemoryHeader * _header
Data-specific header.
~SharedMemoryImageBuffer()
Destructor.
void set_frame_id(const char *frame_id)
Set frame ID.
const char * frame_id() const
Get frame ID.
unsigned int circle_radius() const
Get circle radius.
static void list()
List all shared memory segments that contain a FireVision image.
Fawkes library namespace.
fawkes::Time capture_time() const
Get the time when the image was captured.
void set_circle_x(int circle_x)
Set circle X.
void set_circle(int x, int y, unsigned int r)
Set circle data.
void set_roi_width(unsigned int roi_w)
Set ROI width.
SharedMemoryImageBufferLister()
Constructor.
unsigned char * buffer() const
Get image buffer.
Throw if an inconsistent image was found.
void set_roi_x(unsigned int roi_x)
Set ROI X.
A class for handling time.
virtual void print_footer()
Print footer of the table.
const char * image_id() const
Get Image ID.
void set_roi(unsigned int roi_x, unsigned int roi_y, unsigned int roi_w, unsigned int roi_h)
Set ROI data.
unsigned int roi_x() const
Get ROI X.
virtual void print_header()
Print header of the table.
static std::list< SharedMemoryImageBufferMetaData > list_meta_data()
Get meta data about image buffers.
void set_circle_radius(unsigned int circle_radius)
Set circle radius.
void * _memptr
Pointer to the data segment.
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
void set_circle_y(int circle_y)
Set circle Y.
static void cleanup(bool use_lister=true)
Erase all shared memory segments that contain FireVision images.
unsigned int roi_y() const
Get ROI Y.
virtual ~SharedMemoryImageBufferLister()
Destructor.
void add_semaphore()
Add semaphore to shared memory segment.
virtual void print_no_segments()
Print this if no matching segment was found.
int circle_x() const
Get circle X.
Base class for exceptions in Fawkes.