Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / channel.cc @ a3be1d55

History | View | Annotate | Download (1.32 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  CHANNEL.CC - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//=========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17
18
#include "channel.h"
19
20
USING_NAMESPACE
21
22
23
Channel::Channel()
24
{
25
    consumernode = producernode = NULL;
26
    consumerfinished = producerfinished = false;
27
}
28
29
const Datum *Channel::peek() const
30
{
31
    if (buffer.size()==0)
32
        return NULL;
33
    return &(buffer.front());
34
}
35
36
37
int Channel::read(Datum *a, int max)
38
{
39
    Assert(!consumerfinished);
40
    int n = buffer.size();
41
    if (n>max)
42
        n = max;
43
    for (int i=0; i<n; i++)
44
    {
45
        a[i] = buffer.front();
46
        buffer.pop_front();
47
    }
48
    return n;
49
}
50
51
void Channel::write(Datum *a, int n)
52
{
53
    Assert(!producerfinished);
54
    if (consumerfinished)
55
        return;  // discard data if consumer finished
56
    for (int i=0; i<n; i++)
57
        buffer.push_back(a[i]);
58
}
59