Project

General

Profile

Statistics
| Branch: | Revision:

root / src / sim / parsim / cnamedpipecomm.h @ e1750c09

History | View | Annotate | Download (3.63 KB)

1 01873262 Georg Kunz
//=========================================================================
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-2008 Andras Varga
15
  Copyright (C) 2006-2008 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 __CNAMEDPIPECOMM_H__
25
#define __CNAMEDPIPECOMM_H__
26
27
28
#include <stdio.h>
29
#include <deque>
30
#include "simutil.h"
31
#include "opp_string.h"
32
#include "cparsimcomm.h"
33
#include "platdep/platmisc.h"  // for <windows.h>
34
35
// decide platform
36
#if defined(_WIN32)
37
#define USE_WINDOWS_PIPES
38
#endif
39
40
NAMESPACE_BEGIN
41
42
#ifdef USE_WINDOWS_PIPES
43
typedef HANDLE PIPE;
44
#else
45
typedef int PIPE;
46
#endif
47
48
49
/**
50
 * Implementation of the communications layer which uses named pipes.
51
 * Pipes are created at initialization time, and are used throughout
52
 * the whole simulation.
53
 *
54
 * @ingroup Parsim
55
 */
56
class SIM_API cNamedPipeCommunications : public cParsimCommunications
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:
78
    /**
79
     * Constructor.
80
     */
81
    cNamedPipeCommunications();
82
83
    /**
84
     * Destructor.
85
     */
86
    virtual ~cNamedPipeCommunications();
87
88
    /** @name Redefined methods from cParsimCommunications */
89
    //@{
90
    /**
91
     * Init the library. Here we create and open the named pipes.
92
     */
93
    virtual void init();
94
95
    /**
96
     * Shutdown the communications library. Closes and removes the named pipes.
97
     */
98
    virtual void shutdown();
99
100
    /**
101
     * Returns total number of partitions.
102
     */
103
    virtual int getNumPartitions() const;
104
105
    /**
106
     * Returns the id of this partition.
107
     */
108
    virtual int getProcId() const;
109
110
    /**
111
     * Creates an empty buffer of type cMemCommBuffer.
112
     */
113
    virtual cCommBuffer *createCommBuffer();
114
115
    /**
116
     * Recycle communication buffer after use.
117
     */
118
    virtual void recycleCommBuffer(cCommBuffer *buffer);
119
120
    /**
121
     * Sends packed data with given tag to destination.
122
     */
123
    virtual void send(cCommBuffer *buffer, int tag, int destination);
124
125
    /**
126
     * Receives packed data, and also returns tag and source procId.
127
     * Normally returns true; false is returned if blocking was interrupted by the user.
128
     */
129
    virtual bool receiveBlocking(int filtTag, cCommBuffer *buffer, int& receivedTag, int& sourceProcId);
130
131
    /**
132
     * Receives packed data, and also returns tag and source procId.
133
     * Call is non-blocking -- it returns true if something has been
134
     * received, false otherwise.
135
     */
136
    virtual bool receiveNonblocking(int filtTag, cCommBuffer *buffer,  int& receivedTag, int& sourceProcId);
137
    //@}
138
};
139
140
NAMESPACE_END
141
142
143
#endif
144