cnamedpipecomm.h

00001 //=========================================================================
00002 //  CNAMEDPIPECOMM.H - part of
00003 //
00004 //                  OMNeT++/OMNEST
00005 //           Discrete System Simulation in C++
00006 //
00007 //  Author: Andras Varga, 2003
00008 //          Dept. of Electrical and Computer Systems Engineering,
00009 //          Monash University, Melbourne, Australia
00010 //
00011 //=========================================================================
00012 
00013 /*--------------------------------------------------------------*
00014   Copyright (C) 2003-2008 Andras Varga
00015   Copyright (C) 2006-2008 OpenSim Ltd.
00016   Monash University, Dept. of Electrical and Computer Systems Eng.
00017   Melbourne, Australia
00018 
00019   This file is distributed WITHOUT ANY WARRANTY. See the file
00020   `license' for details on this and other legal matters.
00021 *--------------------------------------------------------------*/
00022 
00023 
00024 #ifndef __CNAMEDPIPECOMM_H__
00025 #define __CNAMEDPIPECOMM_H__
00026 
00027 
00028 #include <stdio.h>
00029 #include <deque>
00030 #include "simutil.h"
00031 #include "opp_string.h"
00032 #include "cparsimcomm.h"
00033 #include "platdep/platmisc.h"  // for <windows.h>
00034 
00035 // decide platform
00036 #if defined(_WIN32)
00037 #define USE_WINDOWS_PIPES
00038 #endif
00039 
00040 NAMESPACE_BEGIN
00041 
00042 #ifdef USE_WINDOWS_PIPES
00043 typedef HANDLE PIPE;
00044 #else
00045 typedef int PIPE;
00046 #endif
00047 
00048 
00056 class SIM_API cNamedPipeCommunications : public cParsimCommunications
00057 {
00058   protected:
00059     int numPartitions;
00060     int myProcId;
00061 
00062     // pipes
00063     opp_string prefix;
00064     PIPE *rpipes;
00065     PIPE *wpipes;
00066     int maxFdPlus1;
00067     int rrBase;
00068 
00069     // reordering buffer needed because of tag filtering support (filtTag)
00070     std::deque<cCommBuffer*> storedBuffers;
00071 
00072   protected:
00073     // common impl. for receiveBlocking() and receiveNonblocking()
00074     bool receive(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
00075     bool doReceive(cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
00076 
00077   public:
00081     cNamedPipeCommunications();
00082 
00086     virtual ~cNamedPipeCommunications();
00087 
00093     virtual void init();
00094 
00098     virtual void shutdown();
00099 
00103     virtual int getNumPartitions() const;
00104 
00108     virtual int getProcId() const;
00109 
00113     virtual cCommBuffer *createCommBuffer();
00114 
00118     virtual void recycleCommBuffer(cCommBuffer *buffer);
00119 
00123     virtual void send(cCommBuffer *buffer, int tag, int destination);
00124 
00129     virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId);
00130 
00136     virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer,  int& receivedTag, int& sourceProcId);
00138 };
00139 
00140 NAMESPACE_END
00141 
00142 
00143 #endif
00144 
00145 
Generated on Tue Dec 2 11:16:32 2014 for OMNeT++ Parallel Simulation Support by  doxygen 1.6.3