OMNeT++ Parallel Simulation Support  6.0.3
cnamedpipecomm.h
1 //=========================================================================
2 // CNAMEDPIPECOMM.H - part of
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 //=========================================================================
8 
9 /*--------------------------------------------------------------*
10  Copyright (C) 1992-2017 Andras Varga
11  Copyright (C) 2006-2017 OpenSim Ltd.
12 
13  This file is distributed WITHOUT ANY WARRANTY. See the file
14  `license' for details on this and other legal matters.
15 *--------------------------------------------------------------*/
16 
17 #ifndef __OMNETPP_CNAMEDPIPECOMM_H
18 #define __OMNETPP_CNAMEDPIPECOMM_H
19 
20 
21 #include <cstdio>
22 #include <list>
23 #include "omnetpp/simutil.h"
24 #include "omnetpp/opp_string.h"
25 #include "omnetpp/cparsimcomm.h"
26 #include "omnetpp/platdep/platmisc.h" // for <windows.h>
27 
28 // decide platform
29 #if defined(_WIN32)
30 #define USE_WINDOWS_PIPES
31 #endif
32 
33 namespace omnetpp {
34 
35 #ifdef USE_WINDOWS_PIPES
36 typedef HANDLE PIPE;
37 #else
38 typedef int PIPE;
39 #endif
40 
41 class cMemCommBuffer;
42 
51 {
52  protected:
53  int numPartitions;
54  int myProcId;
55 
56  // pipes
57  opp_string prefix;
58  PIPE *rpipes = nullptr;
59  PIPE *wpipes = nullptr;
60  int maxFdPlus1;
61  int rrBase = 0;
62 
63  // reordering buffer needed because of tag filtering support (filtTag)
64  struct ReceivedBuffer {int receivedTag; int sourceProcId; cMemCommBuffer *buffer;};
65  std::list<ReceivedBuffer> receivedBuffers;
66 
67  protected:
68  // common impl. for receiveBlocking() and receiveNonblocking()
69  bool receive(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
70  bool doReceive(cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
71 
72  public:
77 
81  virtual ~cNamedPipeCommunications();
82 
88  virtual void init(int numPartitions) override;
89 
93  virtual void shutdown() override;
94 
98  virtual int getNumPartitions() const override;
99 
103  virtual int getProcId() const override;
104 
108  virtual cCommBuffer *createCommBuffer() override;
109 
113  virtual void recycleCommBuffer(cCommBuffer *buffer) override;
114 
118  virtual void send(cCommBuffer *buffer, int tag, int destination) override;
119 
124  virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) override;
125 
131  virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) override;
133 };
134 
135 } // namespace omnetpp
136 
137 
138 #endif
139 
140 
omnetpp::cNamedPipeCommunications
Implementation of the communications layer which uses named pipes. Pipes are created at initializatio...
Definition: cnamedpipecomm.h:50
omnetpp::cMemCommBuffer
Communication buffer that packs data into a memory buffer without any transformation.
Definition: cmemcommbuffer.h:31
omnetpp::opp_string
omnetpp::cParsimCommunications
omnetpp::cCommBuffer