Fawkes API  Fawkes Development Version
shm_lut.h
1 
2 /***************************************************************************
3  * shm_lut.h - shared memory lookup table
4  *
5  * Generated: Thu Feb 09 16:57:40 2006
6  * Copyright 2005-2007 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_LUT_H_
25 #define __FIREVISION_FVUTILS_IPC_SHM_LUT_H_
26 
27 #include <utils/ipc/shm.h>
28 #include <utils/ipc/shm_lister.h>
29 #include <fvutils/ipc/defs.h>
30 #include <stdint.h>
31 
32 // Magic token to identify FireVision shared memory LUTs
33 #define FIREVISION_SHM_LUT_MAGIC_TOKEN "FireVision LUT"
34 
35 namespace firevision {
36 #if 0 /* just to make Emacs auto-indent happy */
37 }
38 #endif
39 
40 /** Shared memory lookup table header struct. */
41 typedef struct {
42  char lut_id[LUT_ID_MAX_LENGTH]; /**< LUT ID */
43  uint32_t width; /**< LUT width */
44  uint32_t height; /**< LUT height */
45  uint32_t depth; /**< LUT depth */
46  uint32_t bytes_per_cell; /**< Bytes per cell */
48 
49 
51 {
52  public:
55  unsigned int width,
56  unsigned int height,
57  unsigned int bytes_per_cell);
58  SharedMemoryLookupTableHeader(const char *lut_id,
59  unsigned int width,
60  unsigned int height,
61  unsigned int depth,
62  unsigned int bytes_per_cell);
65 
66  virtual fawkes::SharedMemoryHeader * clone() const;
67  virtual bool matches(void *memptr);
68  virtual size_t size();
69  virtual bool create();
70  virtual void initialize(void *memptr);
71  virtual void set(void *memptr);
72  virtual void reset();
73  virtual size_t data_size();
74  virtual bool operator==(const fawkes::SharedMemoryHeader & s) const;
75 
76  virtual void print_info();
77 
78  const char * lut_id() const;
79  void set_lut_id(const char *lut_id);
80  unsigned int width() const;
81  unsigned int height() const;
82  unsigned int depth() const;
83  unsigned int bytes_per_cell() const;
84 
86 
87  private:
89 
90  char *__lut_id;
91  unsigned int __width;
92  unsigned int __height;
93  unsigned int __depth;
94  unsigned int __bytes_per_cell;
95 };
96 
98 {
99  public:
102 
103  virtual void print_header();
104  virtual void print_footer();
105  virtual void print_no_segments();
106  virtual void print_no_orphaned_segments();
107  virtual void print_info(const fawkes::SharedMemoryHeader *header,
108  int shm_id, int semaphore, unsigned int mem_size,
109  const void *memptr);
110 };
111 
112 
114 {
115 
116  public:
117 
118  SharedMemoryLookupTable( const char *lut_id,
119  unsigned int width, unsigned int height,
120  unsigned int depth = 1,
121  unsigned int bytes_per_cell = 1
122  );
123  SharedMemoryLookupTable(const char *lut_id , bool is_read_only = true);
125 
126  const char * lut_id() const;
127  bool set_lut_id(const char *lut_id);
128  unsigned char * buffer() const;
129  unsigned int width() const;
130  unsigned int height() const;
131  unsigned int depth() const;
132  unsigned int bytes_per_cell() const;
133 
134  static void list();
135  static void cleanup(bool use_lister = true);
136  static bool exists(const char *lut_id);
137  static void wipe(const char *lut_id);
138 
139  private:
140  void constructor(const char *lut_id,
141  unsigned int width, unsigned int height, unsigned int depth,
142  unsigned int bytes_per_cell,
143  bool is_read_only);
144 
145  SharedMemoryLookupTableHeader *__priv_header;
146  SharedMemoryLookupTable_header_t *__raw_header;
147 
148  char *__lut_id;
149  unsigned int __width;
150  unsigned int __height;
151  unsigned int __depth;
152  unsigned int __bytes_per_cell;
153 
154 };
155 
156 } // end namespace firevision
157 
158 #endif
uint32_t bytes_per_cell
Bytes per cell.
Definition: shm_lut.h:46
const char * lut_id() const
Get LUT ID.
Definition: shm_lut.cpp:531
virtual bool matches(void *memptr)
Method to check if the given memptr matches this header.
Definition: shm_lut.cpp:371
virtual void initialize(void *memptr)
Initialize the header.
Definition: shm_lut.cpp:431
unsigned int height() const
Get LUT height.
Definition: shm_lut.cpp:498
Shared memory lookup table header.
Definition: shm_lut.h:50
virtual bool operator==(const fawkes::SharedMemoryHeader &s) const
Check for equality of headers.
Definition: shm_lut.cpp:468
virtual size_t size()
Size of the header.
Definition: shm_lut.cpp:353
virtual ~SharedMemoryLookupTableHeader()
Destructor.
Definition: shm_lut.cpp:335
virtual void print_info()
Print Info.
Definition: shm_lut.cpp:402
unsigned int width() const
Get LUT width.
Definition: shm_lut.cpp:487
SharedMemoryLookupTable_header_t * raw_header()
Get raw header.
Definition: shm_lut.cpp:553
unsigned int bytes_per_cell() const
Get bytes per cell.
Definition: shm_lut.cpp:520
Format list output for shared memory segments.
Definition: shm_lister.h:38
virtual size_t data_size()
Return the size of the data.
Definition: shm_lut.cpp:360
virtual void reset()
Reset information previously set with set().
Definition: shm_lut.cpp:452
Shared memory lookup table header struct.
Definition: shm_lut.h:41
Shared memory segment.
Definition: shm.h:49
virtual bool create()
Check if buffer should be created.
Definition: shm_lut.cpp:421
void set_lut_id(const char *lut_id)
Set LUT ID.
Definition: shm_lut.cpp:542
Shared memory lookup table lister.
Definition: shm_lut.h:97
virtual fawkes::SharedMemoryHeader * clone() const
Clone this shared memory header.
Definition: shm_lut.cpp:346
Interface for shared memory header.
Definition: shm.h:33
Shared memory lookup table.
Definition: shm_lut.h:113
unsigned int depth() const
Get LUT depth.
Definition: shm_lut.cpp:509