rllib  1
rlsharedmemory.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                           rlsharedmemory.h  -  description
00003                              -------------------
00004     begin                : Tue Jan 02 2001
00005     copyright            : (C) 2001 by Rainer Lehrig
00006     email                : lehrig@t-online.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE as        *
00013  *   published by the Free Software Foundation                             *
00014  *                                                                         *
00015  ***************************************************************************/
00016 #ifndef _RL_SHARED_MEMORY_H_
00017 #define _RL_SHARED_MEMORY_H_
00018 
00019 #include "rldefine.h"
00020 #include "rlwthread.h"
00021 
00030 class rlSharedMemory
00031 {
00032 public:
00033   enum SharedMemoryEnum
00034   {
00035     OK = 0,
00036     ERROR_FILE,
00037     ERROR_SHMGET,
00038     ERROR_SHMAT,
00039     ERROR_SHMCTL
00040   };
00041 
00043   rlSharedMemory(const char *name, unsigned long size, int rwmode=0600);
00044   virtual ~rlSharedMemory();
00045   int   deleteSharedMemory();
00046   int   write(unsigned long offset, const void *buf, int len);
00047   int   read (unsigned long offset, void *buf, int len);
00048   int   readInt(unsigned long offset, int index);
00049   int   readShort(unsigned long offset, int index);
00050   int   readByte(unsigned long offset, int index);
00051   float readFloat(unsigned long offset, int index);
00052   int   writeInt(unsigned long offset, int index, int val);
00053   int   writeShort(unsigned long offset, int index, int val);
00054   int   writeByte(unsigned long offset, int index, unsigned char val);
00055   int   writeFloat(unsigned long offset, int index, float val);
00056   void  *getUserAdr();
00057   int   shmKey();
00058   int   shmId();
00059   int   status;
00060   char *name;
00061 private:
00062   int id;
00063   int shmkey;
00064   char *base_adr;
00065   char *user_adr;
00066   unsigned long size;
00067   pthread_mutex_t *mutex;
00068 };
00069 
00070 #endif