cnamedpipecomm.h

00001 //=========================================================================
00002 //  CNAMEDPIPECOMM.H - part of
00003 //
00004 //                  OMNeT++/OMNEST
00005 //           Discrete System Simulation in C++
00006 //
00007 //   Written by:  Andras Varga, 2003
00008 //
00009 //=========================================================================
00010 
00011 /*--------------------------------------------------------------*
00012   Copyright (C) 2003-2005 Andras Varga
00013   Monash University, Dept. of Electrical and Computer Systems Eng.
00014   Melbourne, Australia
00015 
00016   This file is distributed WITHOUT ANY WARRANTY. See the file
00017   `license' for details on this and other legal matters.
00018 *--------------------------------------------------------------*/
00019 
00020 
00021 #ifndef __CNAMEDPIPECOMM_H__
00022 #define __CNAMEDPIPECOMM_H__
00023 
00024 
00025 #include <stdio.h>
00026 
00027 #ifdef _MSC_VER
00028 #pragma warning(disable:4786)
00029 #endif
00030 
00031 #include <deque>
00032 
00033 #include "util.h"
00034 #include "opp_string.h"
00035 #include "cparsimcomm.h"
00036 
00037 
00038 // decide platform
00039 #if defined(_WIN32)
00040 #define USE_WINDOWS_PIPES
00041 #endif
00042 
00043 
00044 #ifdef USE_WINDOWS_PIPES
00045 #define MEAN_AND_LEAN
00046 #include <windows.h>
00047 typedef HANDLE PIPE;
00048 #else
00049 typedef int PIPE;
00050 #endif
00051 
00052 
00060 class cNamedPipeCommunications : public cParsimCommunications
00061 {
00062   protected:
00063     int numPartitions;
00064     int myProcId;
00065 
00066     // pipes
00067     opp_string prefix;
00068     PIPE *rpipes;
00069     PIPE *wpipes;
00070     int maxFdPlus1;
00071     int rrBase;
00072 
00073     // reordering buffer needed because of tag filtering support (filtTag)
00074     std::deque<cCommBuffer*> storedBuffers;
00075 
00076   protected:
00077     // common impl. for receiveBlocking() and receiveNonblocking()
00078     bool receive(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
00079     bool doReceive(cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
00080 
00081   public:
00085     cNamedPipeCommunications();
00086 
00090     virtual ~cNamedPipeCommunications();
00091 
00097     virtual void init();
00098 
00102     virtual void shutdown();
00103 
00107     virtual int getNumPartitions();
00108 
00112     virtual int getProcId();
00113 
00117     virtual cCommBuffer *createCommBuffer();
00118 
00122     virtual void recycleCommBuffer(cCommBuffer *buffer);
00123 
00127     virtual void send(cCommBuffer *buffer, int tag, int destination);
00128 
00133     virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId);
00134 
00140     virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer,  int& receivedTag, int& sourceProcId);
00142 };
00143 
00144 #endif
00145 
00146 

Generated on Sat Oct 21 17:48:01 2006 for OMNeT++ Parallel Simulation Support by  doxygen 1.4.6