00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
00025 #define __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
00026
00027 #include <utils/ipc/shm.h>
00028 #include <utils/ipc/shm_lister.h>
00029 #include <utils/time/time.h>
00030
00031 #include <fvutils/ipc/defs.h>
00032 #include <fvutils/color/colorspaces.h>
00033
00034
00035
00036 #define FIREVISION_SHM_IMAGE_MAGIC_TOKEN "FireVision Image"
00037
00038 namespace firevision {
00039 #if 0
00040 }
00041 #endif
00042
00043
00044
00045 typedef struct {
00046 char image_id[IMAGE_ID_MAX_LENGTH];
00047 unsigned int colorspace;
00048 unsigned int width;
00049 unsigned int height;
00050 unsigned int roi_x;
00051 unsigned int roi_y;
00052 unsigned int roi_width;
00053 unsigned int roi_height;
00054
00055 int circle_x;
00056 int circle_y;
00057 unsigned int circle_radius;
00058 long int capture_time_sec;
00059
00060 long int capture_time_usec;
00061
00062 unsigned int flag_circle_found : 1;
00063 unsigned int flag_image_ready : 1;
00064 unsigned int flag_reserved : 30;
00065 } SharedMemoryImageBuffer_header_t;
00066
00067 class SharedMemoryImageBufferHeader
00068 : public fawkes::SharedMemoryHeader
00069 {
00070 public:
00071 SharedMemoryImageBufferHeader();
00072 SharedMemoryImageBufferHeader(const char *image_id,
00073 colorspace_t colorspace,
00074 unsigned int width,
00075 unsigned int height);
00076 SharedMemoryImageBufferHeader(const SharedMemoryImageBufferHeader *h);
00077 virtual ~SharedMemoryImageBufferHeader();
00078
00079 virtual fawkes::SharedMemoryHeader * clone() const;
00080 virtual bool matches(void *memptr);
00081 virtual size_t size();
00082 virtual void print_info();
00083 virtual bool create();
00084 virtual void initialize(void *memptr);
00085 virtual void set(void *memptr);
00086 virtual void reset();
00087 virtual size_t data_size();
00088 virtual bool operator==(const fawkes::SharedMemoryHeader &s) const;
00089
00090 void set_image_id(const char *image_id);
00091 colorspace_t colorspace() const;
00092 unsigned int width() const;
00093 unsigned int height() const;
00094 const char * image_id() const;
00095
00096 SharedMemoryImageBuffer_header_t * raw_header();
00097
00098 private:
00099 char *_image_id;
00100 colorspace_t _colorspace;
00101 unsigned int _width;
00102 unsigned int _height;
00103
00104 char *_orig_image_id;
00105 colorspace_t _orig_colorspace;
00106 unsigned int _orig_width;
00107 unsigned int _orig_height;
00108
00109 SharedMemoryImageBuffer_header_t *_header;
00110 };
00111
00112 class SharedMemoryImageBufferLister
00113 : public fawkes::SharedMemoryLister
00114 {
00115 public:
00116 SharedMemoryImageBufferLister();
00117 virtual ~SharedMemoryImageBufferLister();
00118
00119 virtual void print_header();
00120 virtual void print_footer();
00121 virtual void print_no_segments();
00122 virtual void print_no_orphaned_segments();
00123 virtual void print_info(const fawkes::SharedMemoryHeader *header,
00124 int shm_id, int semaphore,
00125 unsigned int mem_size,
00126 const void *memptr);
00127 };
00128
00129
00130 class SharedMemoryImageBuffer : public fawkes::SharedMemory
00131 {
00132
00133 public:
00134 SharedMemoryImageBuffer(const char *image_id,
00135 colorspace_t cspace,
00136 unsigned int width, unsigned int height);
00137 SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true);
00138 ~SharedMemoryImageBuffer();
00139
00140 const char * image_id() const;
00141 unsigned char * buffer() const;
00142 colorspace_t colorspace() const;
00143 unsigned int width() const;
00144 unsigned int height() const;
00145 unsigned int roi_x() const;
00146 unsigned int roi_y() const;
00147 unsigned int roi_width() const;
00148 unsigned int roi_height() const;
00149 int circle_x() const;
00150 int circle_y() const;
00151 unsigned int circle_radius() const;
00152 bool circle_found() const;
00153 void set_roi_x(unsigned int roi_x);
00154 void set_roi_y(unsigned int roi_y);
00155 void set_roi_width(unsigned int roi_w);
00156 void set_roi_height(unsigned int roi_h);
00157 void set_roi(unsigned int roi_x, unsigned int roi_y,
00158 unsigned int roi_w, unsigned int roi_h);
00159 void set_circle_x(int circle_x);
00160 void set_circle_y(int circle_y);
00161 void set_circle_radius(unsigned int circle_radius);
00162 void set_circle(int x, int y, unsigned int r);
00163 void set_circle_found(bool found);
00164 bool set_image_id(const char *image_id);
00165
00166 fawkes::Time capture_time() const;
00167 void capture_time(long int *sec, long int *usec) const;
00168 void set_capture_time(fawkes::Time *time);
00169 void set_capture_time(long int sec, long int usec);
00170
00171 static void list();
00172 static void cleanup(bool use_lister = true);
00173 static bool exists(const char *image_id);
00174 static void wipe(const char *image_id);
00175
00176 private:
00177 void constructor(const char *image_id, colorspace_t cspace,
00178 unsigned int width, unsigned int height,
00179 bool is_read_only);
00180
00181 SharedMemoryImageBufferHeader *priv_header;
00182 SharedMemoryImageBuffer_header_t *raw_header;
00183
00184 char * _image_id;
00185 colorspace_t _colorspace;
00186 unsigned int _width;
00187 unsigned int _height;
00188
00189
00190 };
00191
00192
00193 }
00194
00195 #endif