00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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