OMNeT++ Parallel Simulation Support  5.4.1
cnamedpipecomm.h
1 //=========================================================================
2 // CNAMEDPIPECOMM.H - part of
3 //
4 // OMNeT++/OMNEST
5 // Discrete System Simulation in C++
6 //
7 // Author: Andras Varga, 2003
8 // Dept. of Electrical and Computer Systems Engineering,
9 // Monash University, Melbourne, Australia
10 //
11 //=========================================================================
12 
13 /*--------------------------------------------------------------*
14  Copyright (C) 2003-2017 Andras Varga
15  Copyright (C) 2006-2017 OpenSim Ltd.
16  Monash University, Dept. of Electrical and Computer Systems Eng.
17  Melbourne, Australia
18 
19  This file is distributed WITHOUT ANY WARRANTY. See the file
20  `license' for details on this and other legal matters.
21 *--------------------------------------------------------------*/
22 
23 
24 #ifndef __OMNETPP_CNAMEDPIPECOMM_H
25 #define __OMNETPP_CNAMEDPIPECOMM_H
26 
27 
28 #include <cstdio>
29 #include <deque>
30 #include "omnetpp/simutil.h"
31 #include "omnetpp/opp_string.h"
32 #include "omnetpp/cparsimcomm.h"
33 #include "omnetpp/platdep/platmisc.h" // for <windows.h>
34 
35 // decide platform
36 #if defined(_WIN32)
37 #define USE_WINDOWS_PIPES
38 #endif
39 
40 namespace omnetpp {
41 
42 #ifdef USE_WINDOWS_PIPES
43 typedef HANDLE PIPE;
44 #else
45 typedef int PIPE;
46 #endif
47 
48 
57 {
58  protected:
59  int numPartitions;
60  int myProcId;
61 
62  // pipes
63  opp_string prefix;
64  PIPE *rpipes;
65  PIPE *wpipes;
66  int maxFdPlus1;
67  int rrBase;
68 
69  // reordering buffer needed because of tag filtering support (filtTag)
70  std::deque<cCommBuffer*> storedBuffers;
71 
72  protected:
73  // common impl. for receiveBlocking() and receiveNonblocking()
74  bool receive(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
75  bool doReceive(cCommBuffer *buffer, int& receivedTag, int& sourceProcId, bool blocking);
76 
77  public:
82 
86  virtual ~cNamedPipeCommunications();
87 
93  virtual void init() override;
94 
98  virtual void shutdown() override;
99 
103  virtual int getNumPartitions() const override;
104 
108  virtual int getProcId() const override;
109 
113  virtual cCommBuffer *createCommBuffer() override;
114 
118  virtual void recycleCommBuffer(cCommBuffer *buffer) override;
119 
123  virtual void send(cCommBuffer *buffer, int tag, int destination) override;
124 
129  virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) override;
130 
136  virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId) override;
138 };
139 
140 } // namespace omnetpp
141 
142 
143 #endif
144 
145 
Implementation of the communications layer which uses named pipes. Pipes are created at initializatio...
Definition: cnamedpipecomm.h:56
Definition: cadvlinkdelaylookahead.h:26