basicmsgqueuemux.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 BASICMSGQUEUEMUX_H
00029 #define BASICMSGQUEUEMUX_H
00030 
00031 #include <BasicUtils/BasicThread.h>
00032 #include <BasicUtils/BasicFunctor.h>
00033 #include "basicipcmsgqueue.h"
00034 #include "basicmuxmessage.h"
00035 
00036 #include <map>
00037 #include <list>
00038 
00039 class BasicMUXChannelBase;
00040 
00041 class BasicMsgQueueMUX {
00042   typedef enum {MSGQ_OWNER = 1, MSGQ_CLIENT} message_types;
00043 
00044   BasicIPCMsgQueue msgQueue;
00045 
00046   bool writerFlushAndExit;
00047 
00048   BasicFunctor<BasicMsgQueueMUX> readFunctor;
00049   BasicFunctor<BasicMsgQueueMUX> writeFunctor;
00050 
00051   BasicThread readerThread;
00052   BasicThread writerThread;
00053 
00054   typedef std::map<int, BasicMUXChannelBase *> channelMap_t;
00055   channelMap_t channelMap;
00056 
00057   typedef std::list<BasicMUXChannelBase *> channelList_t;
00058   channelList_t channelList;
00059 
00060   typedef std::list<int> msgClearedList_t;
00061   msgClearedList_t msgClearedList;
00062 
00063   typedef struct {
00064     long type;
00065     long key;
00066   } clear_message_t;
00067 
00068  public:
00069 
00070   BasicMsgQueueMUX();
00071   virtual ~BasicMsgQueueMUX();
00072 
00073   bool addChannel(BasicMUXChannelBase *channel);
00074   void removeChannel(BasicMUXChannelBase *channel);
00075 
00076   bool isOpen();
00077   bool open(key_t key);
00078   key_t create(key_t key);
00079   void close(bool flushFirst = true);
00080 
00081  protected:
00082   void msgCleared(int key);
00083   void wakeWriter();
00084 
00085   void writeRun();
00086   void readRun();
00087 
00088  private:
00089   bool writesAllClear();
00090   int sendClears(int max);
00091   int sendMessages(int max);
00092 
00093   void readClear(clear_message_t *clearMsg);
00094   void readMessage(BasicMUXMessageBase::message_t *msg, int len);
00095 
00096   friend class BasicMUXChannelBase;
00097   friend class BasicFunctor<BasicMsgQueueMUX>;
00098 };
00099 #endif

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