Statistics
| Branch: | Revision:

root / src / sim / parsim / cispeventlogger.cc @ e1750c09

History | View | Annotate | Download (2.83 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  CISPEVENTLOGGER.CC - 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

17
  This file is distributed WITHOUT ANY WARRANTY. See the file
18
  `license' for details on this and other legal matters.
19
*--------------------------------------------------------------*/
20
21
22
#include <stdio.h>
23
#include "cispeventlogger.h"
24
#include "cidealsimulationprot.h"
25
#include "cparsimcomm.h"
26
#include "cplaceholdermod.h"
27
#include "cmodule.h"
28
#include "globals.h"
29
#include "regmacros.h"
30
31
USING_NAMESPACE
32
33
Register_Class(cISPEventLogger);
34
35
36
cISPEventLogger::cISPEventLogger() : cNullMessageProtocol()
37
{
38
    fout = NULL;
39
}
40
41
cISPEventLogger::~cISPEventLogger()
42
{
43
}
44
45
void cISPEventLogger::startRun()
46
{
47
    cNullMessageProtocol::startRun();
48
49
    char fname[200];
50
    sprintf(fname, "ispeventlog-%d.dat", comm->getProcId());
51
    fout = fopen(fname,"wb");
52
    if (!fout)
53
        throw cRuntimeError("cISPEventLogger error: cannot open file `%s' for write", fname);
54
}
55
56
void cISPEventLogger::endRun()
57
{
58
    cNullMessageProtocol::endRun();
59
    fclose(fout);
60
}
61
62
void cISPEventLogger::processReceivedMessage(cMessage *msg, int destModuleId, int destGateId, int sourceProcId)
63
{
64
    msg->setSchedulingPriority(sourceProcId);
65
    cParsimProtocolBase::processReceivedMessage(msg, destModuleId, destGateId, sourceProcId);
66
}
67
68
void cISPEventLogger::processOutgoingMessage(cMessage *msg, int procId, int moduleId, int gateId, void *data)
69
{
70
    if (msg->getSchedulingPriority()!=0)
71
        throw cRuntimeError("cISPEventLogger: outgoing message (%s)%s has nonzero priority set -- "
72
                            "this conflicts with ISP which uses priority for its own purposes",
73
                            msg->getClassName(), msg->getName());
74
    cParsimProtocolBase::processOutgoingMessage(msg, procId, moduleId, gateId, data);
75
}
76
77
cMessage *cISPEventLogger::getNextEvent()
78
{
79
    cMessage *msg = cNullMessageProtocol::getNextEvent();
80
81
    if (msg->getSrcProcId()!=-1)  // received from another partition
82
    {
83
        // restore original priority
84
        msg->setSchedulingPriority(0);
85
86
        // log event to file
87
        cIdealSimulationProtocol::ExternalEvent e;
88
        e.t = msg->getArrivalTime();
89
        e.srcProcId = msg->getSrcProcId();
90
91
        if (fwrite(&e, sizeof(cIdealSimulationProtocol::ExternalEvent), 1, fout)<1)
92
            throw cRuntimeError("cISPEventLogger error: file write failed (disk full?)");
93
    }
94
95
    return msg;
96
}
97