Fawkes API  Fawkes Development Version
shm_image.h
1 
2 /***************************************************************************
3  * shm_image.h - shared memory image buffer
4  *
5  * Created: Thu Jan 12 13:12:24 2006
6  * Copyright 2005-2009 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
25 #define __FIREVISION_FVUTILS_IPC_SHM_IMAGE_H_
26 
27 #include <utils/ipc/shm.h>
28 #include <utils/ipc/shm_lister.h>
29 #include <utils/time/time.h>
30 
31 #include <fvutils/ipc/defs.h>
32 #include <fvutils/color/colorspaces.h>
33 
34 #include <string>
35 
36 // Magic token to identify FireVision shared memory images
37 #define FIREVISION_SHM_IMAGE_MAGIC_TOKEN "FireVision Image"
38 
39 namespace firevision {
40 #if 0 /* just to make Emacs auto-indent happy */
41 }
42 #endif
43 
44 // Not that there is a relation to ITPimage_packet_header_t
45 /** Shared memory header struct for FireVision images. */
46 typedef struct {
47  char image_id[IMAGE_ID_MAX_LENGTH];/**< image ID */
48  char frame_id[FRAME_ID_MAX_LENGTH];/**< coordinate frame ID */
49  unsigned int colorspace; /**< color space */
50  unsigned int width; /**< width */
51  unsigned int height; /**< height */
52  unsigned int roi_x; /**< ROI start x */
53  unsigned int roi_y; /**< ROI start y */
54  unsigned int roi_width; /**< ROI width */
55  unsigned int roi_height; /**< ROI height */
56  // Circle relative to ROI
57  int circle_x; /**< ROI circle center x */
58  int circle_y; /**< ROI circle center y */
59  unsigned int circle_radius; /**< ROI circle radius */
60  long int capture_time_sec; /**< Time in seconds since the epoch when
61  * the image was captured. */
62  long int capture_time_usec; /**< Addendum to capture_time_sec in
63  * micro seconds. */
64  unsigned int flag_circle_found : 1; /**< 1 if circle found */
65  unsigned int flag_image_ready : 1; /**< 1 if image ready */
66  unsigned int flag_reserved : 30; /**< reserved for future use */
68 
71 {
72  public:
75  colorspace_t colorspace,
76  unsigned int width,
77  unsigned int height);
80 
81  virtual fawkes::SharedMemoryHeader * clone() const;
82  virtual bool matches(void *memptr);
83  virtual size_t size();
84  virtual void print_info();
85  virtual bool create();
86  virtual void initialize(void *memptr);
87  virtual void set(void *memptr);
88  virtual void reset();
89  virtual size_t data_size();
90  virtual bool operator==(const fawkes::SharedMemoryHeader &s) const;
91 
92  void set_image_id(const char *image_id);
93  void set_frame_id(const char *frame_id);
94  colorspace_t colorspace() const;
95  unsigned int width() const;
96  unsigned int height() const;
97  const char * image_id() const;
98  const char * frame_id() const;
99 
101 
102  private:
103  char *_image_id;
104  char *_frame_id;
105  colorspace_t _colorspace;
106  unsigned int _width;
107  unsigned int _height;
108 
109  char *_orig_image_id;
110  char *_orig_frame_id;
111  colorspace_t _orig_colorspace;
112  unsigned int _orig_width;
113  unsigned int _orig_height;
114 
116 };
117 
120 {
121  public:
124 
125  virtual void print_header();
126  virtual void print_footer();
127  virtual void print_no_segments();
128  virtual void print_no_orphaned_segments();
129  virtual void print_info(const fawkes::SharedMemoryHeader *header,
130  int shm_id, int semaphore,
131  unsigned int mem_size,
132  const void *memptr);
133 };
134 
136 {
137  public:
138  std::string image_id; ///< Image buffer ID
139  std::string frame_id; ///< Coordinate frame ID
140  colorspace_t colorspace; ///< Colorspace
141  unsigned int width; ///< Image width
142  unsigned int height; ///< Image height
143 
144  size_t mem_size; ///< Shared memory buffer size
145  bool mem_swapable; ///< True if memory might be moved to swap space
146  bool mem_destroyed; ///< True if memory has already been marked destroyed
147 
149  SharedMemoryImageBufferMetaData(const char *image_id, const char *frame_id,
150  colorspace_t colorspace, unsigned int width, unsigned int height,
151  size_t mem_size, bool mem_swapable, bool mem_destroyed);
152 };
153 
154 
157 {
158  public:
161 
162  virtual void print_header();
163  virtual void print_footer();
164  virtual void print_no_segments();
165  virtual void print_no_orphaned_segments();
166  virtual void print_info(const fawkes::SharedMemoryHeader *header,
167  int shm_id, int semaphore,
168  unsigned int mem_size,
169  const void *memptr);
170 
171  /** Get meta data.
172  * @return image buffer meta data */
173  std::list<SharedMemoryImageBufferMetaData> &
174  meta_data() { return meta_data_; }
175 
176  private:
177  std::list<SharedMemoryImageBufferMetaData> meta_data_;
178 };
179 
180 
182 {
183 
184  public:
185  SharedMemoryImageBuffer(const char *image_id,
186  colorspace_t cspace,
187  unsigned int width, unsigned int height);
188  SharedMemoryImageBuffer(const char *image_id, bool is_read_only = true);
190 
191  const char * image_id() const;
192  const char * frame_id() const;
193  unsigned char * buffer() const;
194  colorspace_t colorspace() const;
195  unsigned int width() const;
196  unsigned int height() const;
197  unsigned int roi_x() const;
198  unsigned int roi_y() const;
199  unsigned int roi_width() const;
200  unsigned int roi_height() const;
201  int circle_x() const;
202  int circle_y() const;
203  unsigned int circle_radius() const;
204  bool circle_found() const;
205  void set_roi_x(unsigned int roi_x);
206  void set_roi_y(unsigned int roi_y);
207  void set_roi_width(unsigned int roi_w);
208  void set_roi_height(unsigned int roi_h);
209  void set_roi(unsigned int roi_x, unsigned int roi_y,
210  unsigned int roi_w, unsigned int roi_h);
211  void set_circle_x(int circle_x);
212  void set_circle_y(int circle_y);
213  void set_circle_radius(unsigned int circle_radius);
214  void set_circle(int x, int y, unsigned int r);
215  void set_circle_found(bool found);
216  bool set_image_id(const char *image_id);
217  void set_frame_id(const char *frame_id);
218 
219  fawkes::Time capture_time() const;
220  void capture_time(long int *sec, long int *usec) const;
221  void set_capture_time(fawkes::Time *time);
222  void set_capture_time(long int sec, long int usec);
223 
224  static void list();
225  static void cleanup(bool use_lister = true);
226  static bool exists(const char *image_id);
227  static void wipe(const char *image_id);
228 
229  static std::list<SharedMemoryImageBufferMetaData> list_meta_data();
230 
231  private:
232  void constructor(const char *image_id, colorspace_t cspace,
233  unsigned int width, unsigned int height,
234  bool is_read_only);
235 
236  SharedMemoryImageBufferHeader *priv_header;
238 
239  char * _image_id;
240  colorspace_t _colorspace;
241  unsigned int _width;
242  unsigned int _height;
243 
244 
245 };
246 
247 
248 } // end namespace firevision
249 
250 #endif
void set_frame_id(const char *frame_id)
Set frame ID.
Definition: shm_image.cpp:912
virtual bool create()
Create if colorspace, width and height have been supplied.
Definition: shm_image.cpp:763
long int capture_time_sec
Time in seconds since the epoch when the image was captured.
Definition: shm_image.h:60
Shared memory image buffer header.
Definition: shm_image.h:69
virtual void initialize(void *memptr)
Initialize the header.
Definition: shm_image.cpp:772
const char * frame_id() const
Get frame ID.
Definition: shm_image.cpp:891
unsigned int circle_radius
ROI circle radius.
Definition: shm_image.h:59
virtual void reset()
Reset information previously set with set().
Definition: shm_image.cpp:821
virtual ~SharedMemoryImageBufferHeader()
Destructor.
Definition: shm_image.cpp:650
long int capture_time_usec
Addendum to capture_time_sec in micro seconds.
Definition: shm_image.h:62
virtual bool matches(void *memptr)
Method to check if the given memptr matches this header.
Definition: shm_image.cpp:685
A class for handling time.
Definition: time.h:91
Shared memory image buffer meta data container.
Definition: shm_image.h:135
unsigned int roi_height
ROI height.
Definition: shm_image.h:55
unsigned int flag_image_ready
1 if image ready
Definition: shm_image.h:65
unsigned int height() const
Get height.
Definition: shm_image.cpp:870
unsigned int height
Image height.
Definition: shm_image.h:142
Shared memory header struct for FireVision images.
Definition: shm_image.h:46
unsigned int colorspace
color space
Definition: shm_image.h:49
Collect meta data about shared memory segments.
Definition: shm_image.h:155
unsigned int flag_reserved
reserved for future use
Definition: shm_image.h:66
const char * image_id() const
Get image number.
Definition: shm_image.cpp:881
unsigned int flag_circle_found
1 if circle found
Definition: shm_image.h:64
virtual void print_info()
Print some info.
Definition: shm_image.cpp:736
Shared memory image buffer.
Definition: shm_image.h:181
std::string image_id
Image buffer ID.
Definition: shm_image.h:138
Format list output for shared memory segments.
Definition: shm_lister.h:38
std::string frame_id
Coordinate frame ID.
Definition: shm_image.h:139
unsigned int width() const
Get width.
Definition: shm_image.cpp:859
colorspace_t colorspace() const
Get colorspace.
Definition: shm_image.cpp:848
std::list< SharedMemoryImageBufferMetaData > & meta_data()
Get meta data.
Definition: shm_image.h:174
virtual bool operator==(const fawkes::SharedMemoryHeader &s) const
Check for equality of headers.
Definition: shm_image.cpp:720
Shared memory segment.
Definition: shm.h:49
bool mem_destroyed
True if memory has already been marked destroyed.
Definition: shm_image.h:146
Shared memory image buffer lister.
Definition: shm_image.h:118
size_t mem_size
Shared memory buffer size.
Definition: shm_image.h:144
virtual size_t data_size()
Return the size of the data.
Definition: shm_image.cpp:674
bool mem_swapable
True if memory might be moved to swap space.
Definition: shm_image.h:145
virtual size_t size()
Size of the header.
Definition: shm_image.cpp:660
colorspace_t colorspace
Colorspace.
Definition: shm_image.h:140
void set_image_id(const char *image_id)
Set image id.
Definition: shm_image.cpp:901
Interface for shared memory header.
Definition: shm.h:33
virtual fawkes::SharedMemoryHeader * clone() const
Clone this shared memory header.
Definition: shm_image.cpp:667
SharedMemoryImageBuffer_header_t * raw_header()
Get raw header.
Definition: shm_image.cpp:923