shm_lut.h

00001
00002 /***************************************************************************
00003  *  shm_lut.h - shared memory lookup table
00004  *
00005  *  Generated: Thu Feb 09 16:57:40 2006
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __FIREVISION_FVUTILS_IPC_SHM_LUT_H_
00025 #define __FIREVISION_FVUTILS_IPC_SHM_LUT_H_
00026 
00027 #include <utils/ipc/shm.h>
00028 #include <utils/ipc/shm_lister.h>
00029 #include <fvutils/ipc/defs.h>
00030 #include <stdint.h>
00031
00032 // Magic token to identify FireVision shared memory LUTs
00033 #define FIREVISION_SHM_LUT_MAGIC_TOKEN "FireVision LUT"
00034 
00035 /** Shared memory lookup table header struct. */
00036 typedef struct {
00037   char      lut_id[LUT_ID_MAX_LENGTH];          /**< LUT ID */
00038   uint32_t  width;              /**< LUT width */
00039   uint32_t  height;             /**< LUT height */
00040   uint32_t  depth;              /**< LUT depth */
00041   uint32_t  bytes_per_cell;     /**< Bytes per cell */
00042 } SharedMemoryLookupTable_header_t;
00043
00044
00045 class SharedMemoryLookupTableHeader : public fawkes::SharedMemoryHeader
00046 {
00047  public:
00048   SharedMemoryLookupTableHeader();
00049   SharedMemoryLookupTableHeader(const char *lut_id,
00050                                 unsigned int width,
00051                                 unsigned int height,
00052                                 unsigned int bytes_per_cell);
00053   SharedMemoryLookupTableHeader(const char *lut_id,
00054                                 unsigned int width,
00055                                 unsigned int height,
00056                                 unsigned int depth,
00057                                 unsigned int bytes_per_cell);
00058   SharedMemoryLookupTableHeader(const SharedMemoryLookupTableHeader *h);
00059   virtual ~SharedMemoryLookupTableHeader();
00060
00061   virtual fawkes::SharedMemoryHeader *  clone() const;
00062   virtual bool         matches(void *memptr);
00063   virtual size_t       size();
00064   virtual bool         create();
00065   virtual void         initialize(void *memptr);
00066   virtual void         set(void *memptr);
00067   virtual void         reset();
00068   virtual size_t       data_size();
00069   virtual bool         operator==(const fawkes::SharedMemoryHeader & s) const;
00070
00071   virtual void         print_info();
00072
00073   const char *  lut_id() const;
00074   void          set_lut_id(const char *lut_id);
00075   unsigned int  width() const;
00076   unsigned int  height() const;
00077   unsigned int  depth() const;
00078   unsigned int  bytes_per_cell() const;
00079
00080   SharedMemoryLookupTable_header_t * raw_header();
00081
00082  private:
00083   SharedMemoryLookupTable_header_t *__header;
00084
00085   char          *__lut_id;
00086   unsigned int   __width;
00087   unsigned int   __height;
00088   unsigned int   __depth;
00089   unsigned int   __bytes_per_cell;
00090 };
00091
00092 class SharedMemoryLookupTableLister : public fawkes::SharedMemoryLister
00093 {
00094  public:
00095   SharedMemoryLookupTableLister();
00096   virtual ~SharedMemoryLookupTableLister();
00097
00098   virtual void print_header();
00099   virtual void print_footer();
00100   virtual void print_no_segments();
00101   virtual void print_no_orphaned_segments();
00102   virtual void print_info(const fawkes::SharedMemoryHeader *header,
00103                           int shm_id, int semaphore, unsigned int mem_size,
00104                           const void *memptr);
00105 };
00106
00107
00108 class SharedMemoryLookupTable : public fawkes::SharedMemory
00109 {
00110
00111  public:
00112
00113   SharedMemoryLookupTable( const char *lut_id,
00114                            unsigned int width, unsigned int height,
00115                            unsigned int depth = 1,
00116                            unsigned int bytes_per_cell = 1
00117                            );
00118   SharedMemoryLookupTable(const char *lut_id , bool is_read_only = true);
00119   ~SharedMemoryLookupTable();
00120
00121   const char *     lut_id() const;
00122   bool             set_lut_id(const char *lut_id);
00123   unsigned char *  buffer() const;
00124   unsigned int     width() const;
00125   unsigned int     height() const;
00126   unsigned int     depth() const;
00127   unsigned int     bytes_per_cell() const;
00128
00129   static void      list();
00130   static void      cleanup(bool use_lister = true);
00131   static bool      exists(const char *lut_id);
00132   static void      wipe(const char *lut_id);
00133
00134  private:
00135   void constructor(const char *lut_id,
00136                    unsigned int width, unsigned int height, unsigned int depth,
00137                    unsigned int bytes_per_cell,
00138                    bool is_read_only);
00139
00140   SharedMemoryLookupTableHeader    *__priv_header;
00141   SharedMemoryLookupTable_header_t *__raw_header;
00142
00143   char          *__lut_id;
00144   unsigned int   __width;
00145   unsigned int   __height;
00146   unsigned int   __depth;
00147   unsigned int   __bytes_per_cell;
00148
00149 };
00150
00151
00152 #endif