Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / akoutvectormgr.cc @ e26d3d25

History | View | Annotate | Download (2.86 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  AKOUTVECTORMGR.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
#ifdef WITH_AKAROA
19
20
#include <assert.h>
21
#include <string.h>
22
#include <akaroa.H>
23
#include <akaroa/ak_message.H>
24
#include "cenvir.h"
25
#include "envirbase.h"
26
#include "csimulation.h"
27
#include "cmodule.h"
28
#include "cstatistic.h"
29
#include "regmacros.h"
30
#include "akoutvectormgr.h"
31
#include "cconfiguration.h"
32
#include "cconfigoption.h"
33
34
USING_NAMESPACE
35
36
37
Register_Class(cAkOutputVectorManager);
38
39
40
Register_PerObjectConfigOption(CFGID_WITH_AKAROA, "with-akaroa", CFG_BOOL, "false", "Whether to the output vector should be under Akaroa control.");
41
42
43
cAkOutputVectorManager::cAkOutputVectorManager()
44
{
45
    ak_declared = false;
46
    ak_count = 0;
47
}
48
49
cAkOutputVectorManager::~cAkOutputVectorManager()
50
{
51
}
52
53
void *cAkOutputVectorManager::registerVector(const char *modulename, const char *vectorname)
54
{
55
    sAkVectorData *vp = (sAkVectorData *)cFileOutputVectorManager::registerVector(modulename, vectorname);
56
57
    // see if this vector needs Akaroa control
58
    std::string objectfullpath = std::string(modulename) + "." + vectorname;
59
    vp->ak_controlled = ev.getConfig()->getAsBool(objectfullpath.c_str(), CFGID_WITH_AKAROA);
60
61
    if (vp->ak_controlled)
62
    {
63
        // register vector with Akaroa
64
        if (ak_declared)
65
            throw cRuntimeError("cAkOutputVectorManager: With Akaroa, cannot create new vector after first data have been recorded");
66
67
        // Akaroa starts parameter numbering with one
68
        vp->ak_id = ++ak_count;
69
        AkMessage("Parameter %i is equivalent to vector: %s.\"%s\".", vp->ak_id, modulename, vectorname);
70
    }
71
    return vp;
72
}
73
74
cFileOutputVectorManager::sVectorData *cAkOutputVectorManager::createVectorData()
75
{
76
    return new sAkVectorData;
77
}
78
79
bool cAkOutputVectorManager::record(void *vectorhandle, simtime_t t, double value)
80
{
81
    sAkVectorData *vp = (sAkVectorData *)vectorhandle;
82
    if (vp->ak_controlled)
83
    {
84
        // 1. register the parameters to Akaroa
85
        if (!ak_declared)
86
        {
87
            AkDeclareParameters(ak_count);
88
            AkMessage("Parameters declared:  %i", ak_count);
89
            ak_declared = true;
90
        }
91
92
        // 2. transmit value to Akaroa
93
        AkObservation(vp->ak_id, value);
94
    }
95
96
    // 3. write the vector file too
97
    return cFileOutputVectorManager::record(vectorhandle, t, value);
98
}
99
100
#endif
101