basicsharedmemqueue.h

Go to the documentation of this file.
00001 /*******************************************************************\
00002 
00003                    SESAME project software license
00004 
00005           Copyright (C) 2002, 2003 University of Amsterdam
00006 
00007     This program is free software; you can redistribute it and/or
00008      modify it under the terms of the GNU General Public License
00009     as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015              GNU General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018      along with this program; if not, write to the Free Software
00019       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020                            02111-1307, USA.
00021 
00022       For information regarding the SESAME software project see
00023               http://sesamesim.sourceforge.net or email
00024                     jcofflan@users.sourceforge.net
00025 
00026 \*******************************************************************/
00027 
00028 #ifndef BASICSHAREDMEMQUEUE_H
00029 #define BASICSHAREDMEMQUEUE_H
00030 
00031 #include <sys/ipc.h>
00032 #include <BasicUtils/BasicThread.h>
00033 #include "basicsemaphore.h"
00034 #include "basiccleanuphandler.h"
00035 
00036 #define BasicSharedMemQueueVersion  1
00037 #define BasicSharedMemQueueMagic (BasicSharedMemQueueVersion |\
00038                                   (unsigned int)'S' << 8 |\
00039                                   (unsigned int)'M' << 16 |\
00040                                   (unsigned int)'Q' << 24)
00041 
00042 class BasicSharedMemQueue : public BasicLockable {
00043   BasicSemaphore sem;
00044   int id;
00045   key_t key;
00046   bool amOwner;
00047 
00048   typedef struct {
00049     int magic;
00050     key_t sem_key;
00051     unsigned long size;
00052     unsigned long read;
00053     unsigned long write;
00054     unsigned long space;
00055     unsigned long filled;
00056     int host_attached;
00057     int client_attached;
00058     unsigned char buffer[];
00059   } control_t;
00060 
00061   control_t *control;
00062 
00063   BasicCleanupFunctor<BasicSharedMemQueue> cleanupFunctor;
00064 
00065  public:
00066   BasicSharedMemQueue();
00067   virtual ~BasicSharedMemQueue();
00068 
00069   virtual bool isOpen();
00070   virtual bool isConnected();
00071   virtual bool isEmpty();
00072   virtual bool isFull();
00073 
00074   virtual key_t open(key_t key);
00075   virtual void close();
00076   virtual key_t create(key_t key, long size);
00077 
00078   virtual int write(const unsigned char *data, unsigned long size);
00079   virtual int read(unsigned char *data, unsigned long size);
00080 };
00081 #endif

Generated on Wed Apr 5 20:57:45 2006 for Sesame by  doxygen 1.4.6