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 <fvutils/ipc/defs.h>
28 #include <utils/ipc/shm.h>
29 #include <utils/ipc/shm_lister.h>
30 
31 #include <stdint.h>
32 
33 // Magic token to identify FireVision shared memory LUTs
34 #define FIREVISION_SHM_LUT_MAGIC_TOKEN "FireVision LUT"
35 
36 namespace firevision {
37 
38 /** Shared memory lookup table header struct. */
39 typedef struct
40 {
41  char lut_id[LUT_ID_MAX_LENGTH]; /**< LUT ID */
42  uint32_t width; /**< LUT width */
43  uint32_t height; /**< LUT height */
44  uint32_t depth; /**< LUT depth */
45  uint32_t bytes_per_cell; /**< Bytes per cell */
47 
49 {
50 public:
53  unsigned int width,
54  unsigned int height,
55  unsigned int bytes_per_cell);
57  unsigned int width,
58  unsigned int height,
59  unsigned int depth,
60  unsigned int bytes_per_cell);
63 
64  virtual fawkes::SharedMemoryHeader *clone() const;
65  virtual bool matches(void *memptr);
66  virtual size_t size();
67  virtual bool create();
68  virtual void initialize(void *memptr);
69  virtual void set(void *memptr);
70  virtual void reset();
71  virtual size_t data_size();
72  virtual bool operator==(const fawkes::SharedMemoryHeader &s) const;
73 
74  virtual void print_info();
75 
76  const char * lut_id() const;
77  void set_lut_id(const char *lut_id);
78  unsigned int width() const;
79  unsigned int height() const;
80  unsigned int depth() const;
81  unsigned int bytes_per_cell() const;
82 
84 
85 private:
87 
88  char * lut_id_;
89  unsigned int width_;
90  unsigned int height_;
91  unsigned int depth_;
92  unsigned int bytes_per_cell_;
93 };
94 
96 {
97 public:
100 
101  virtual void print_header();
102  virtual void print_footer();
103  virtual void print_no_segments();
104  virtual void print_no_orphaned_segments();
105  virtual void print_info(const fawkes::SharedMemoryHeader *header,
106  int shm_id,
107  int semaphore,
108  unsigned int mem_size,
109  const void * memptr);
110 };
111 
113 {
114 public:
115  SharedMemoryLookupTable(const char * lut_id,
116  unsigned int width,
117  unsigned int height,
118  unsigned int depth = 1,
119  unsigned int bytes_per_cell = 1);
120  SharedMemoryLookupTable(const char *lut_id, bool is_read_only = true);
122 
123  const char * lut_id() const;
124  bool set_lut_id(const char *lut_id);
125  unsigned char *buffer() const;
126  unsigned int width() const;
127  unsigned int height() const;
128  unsigned int depth() const;
129  unsigned int bytes_per_cell() const;
130 
131  static void list();
132  static void cleanup(bool use_lister = true);
133  static bool exists(const char *lut_id);
134  static void wipe(const char *lut_id);
135 
136 private:
137  void constructor(const char * lut_id,
138  unsigned int width,
139  unsigned int height,
140  unsigned int depth,
141  unsigned int bytes_per_cell,
142  bool is_read_only);
143 
144  SharedMemoryLookupTableHeader * priv_header_;
146 
147  char * lut_id_;
148  unsigned int width_;
149  unsigned int height_;
150  unsigned int depth_;
151  unsigned int bytes_per_cell_;
152 };
153 
154 } // end namespace firevision
155 
156 #endif
Interface for shared memory header.
Definition: shm.h:34
Format list output for shared memory segments.
Definition: shm_lister.h:38
Shared memory segment.
Definition: shm.h:53
bool is_read_only() const
Check for read-only mode.
Definition: shm.cpp:706
Shared memory lookup table header.
Definition: shm_lut.h:49
virtual ~SharedMemoryLookupTableHeader()
Destructor.
Definition: shm_lut.cpp:314
const char * lut_id() const
Get LUT ID.
Definition: shm_lut.cpp:486
virtual bool operator==(const fawkes::SharedMemoryHeader &s) const
Check for equality of headers.
Definition: shm_lut.cpp:426
SharedMemoryLookupTable_header_t * raw_header()
Get raw header.
Definition: shm_lut.cpp:508
virtual void set(void *memptr)
Set information from memptr.
Definition: shm_lut.cpp:405
virtual void print_info()
Print Info.
Definition: shm_lut.cpp:368
virtual bool create()
Check if buffer should be created.
Definition: shm_lut.cpp:386
virtual bool matches(void *memptr)
Method to check if the given memptr matches this header.
Definition: shm_lut.cpp:346
void set_lut_id(const char *lut_id)
Set LUT ID.
Definition: shm_lut.cpp:497
unsigned int height() const
Get LUT height.
Definition: shm_lut.cpp:453
virtual size_t size()
Size of the header.
Definition: shm_lut.cpp:330
virtual fawkes::SharedMemoryHeader * clone() const
Clone this shared memory header.
Definition: shm_lut.cpp:324
unsigned int depth() const
Get LUT depth.
Definition: shm_lut.cpp:464
virtual size_t data_size()
Return the size of the data.
Definition: shm_lut.cpp:336
virtual void reset()
Reset information previously set with set().
Definition: shm_lut.cpp:411
unsigned int bytes_per_cell() const
Get bytes per cell.
Definition: shm_lut.cpp:475
unsigned int width() const
Get LUT width.
Definition: shm_lut.cpp:442
virtual void initialize(void *memptr)
Initialize the header.
Definition: shm_lut.cpp:392
Shared memory lookup table lister.
Definition: shm_lut.h:96
virtual void print_header()
Print header of the table.
Definition: shm_lut.cpp:528
virtual void print_info(const fawkes::SharedMemoryHeader *header, int shm_id, int semaphore, unsigned int mem_size, const void *memptr)
Print info about segment.
Definition: shm_lut.cpp:566
virtual void print_no_segments()
Print this if no matching segment was found.
Definition: shm_lut.cpp:554
virtual ~SharedMemoryLookupTableLister()
Destructor.
Definition: shm_lut.cpp:523
virtual void print_footer()
Print footer of the table.
Definition: shm_lut.cpp:549
virtual void print_no_orphaned_segments()
Print this if no matching orphaned segment was found.
Definition: shm_lut.cpp:560
Shared memory lookup table.
Definition: shm_lut.h:113
SharedMemoryLookupTable(const char *lut_id, unsigned int width, unsigned int height, unsigned int depth=1, unsigned int bytes_per_cell=1)
Write Constructor.
Definition: shm_lut.cpp:55
unsigned int bytes_per_cell() const
Get bytes per cell.
Definition: shm_lut.cpp:177
static void list()
List shared memory LUT segments.
Definition: shm_lut.cpp:184
unsigned int width() const
Get LUT width.
Definition: shm_lut.cpp:150
bool set_lut_id(const char *lut_id)
Set LUT ID.
Definition: shm_lut.cpp:127
unsigned int depth() const
Get LUT depth.
Definition: shm_lut.cpp:168
static void wipe(const char *lut_id)
Erase a specific shared memory segment that contains a LUT.
Definition: shm_lut.cpp:232
static bool exists(const char *lut_id)
Check LUT availability.
Definition: shm_lut.cpp:220
static void cleanup(bool use_lister=true)
Erase all shared memory segments that contain FireVision LUTs.
Definition: shm_lut.cpp:200
unsigned char * buffer() const
Get LUT buffer.
Definition: shm_lut.cpp:141
const char * lut_id() const
Get LUT ID.
Definition: shm_lut.cpp:117
unsigned int height() const
Get LUT height.
Definition: shm_lut.cpp:159
Shared memory lookup table header struct.
Definition: shm_lut.h:40
uint32_t bytes_per_cell
Bytes per cell.
Definition: shm_lut.h:45