Statistics
| Branch: | Revision:

napa-baselibs / monl / mon_measure.cpp @ d1e0f2ca

History | View | Annotate | Download (3.2 KB)

1 956892f0 ArpadBakay
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19
#include "mon_measure.h"
20
#include "measure_dispatcher.h"
21
#include "measure_manager.h"
22
#include "mon_event.h"
23
#include        "grapes_log.h"
24
25
MonMeasure::MonMeasure(class MeasurePlugin *mp, MeasurementCapabilities mc, class MeasureDispatcher *ptrDisp) {
26
        measure_plugin = mp;
27
        flags = mc;
28
        used_counter = 0;
29
        auto_loaded = false;
30
        mh_remote = -1;
31
        ptrDispatcher = ptrDisp;
32
33
        /* Initialise default values */
34
        int i;
35
        status = STOPPED;
36
        r_rx_list = r_tx_list = NULL;
37
        param_values = new MonParameterValue[mp->params.size()];
38
39
        for( i = 0; i < mp->params.size(); i++)
40
                param_values[i] =  mp->params[i]->dval;
41
42
        if(!(flags & REMOTE))
43
                rb = new ResultBuffer((int)param_values[P_WINDOW_SIZE], mp->name.c_str(), ptrDispatcher->mm->peer_name, this);
44
        else
45
                rb = NULL;
46
};
47
48
int MonMeasure::sendOobData(char* buf, int buf_len) {
49
        return ptrDispatcher->oobDataTx(this, buf, buf_len);
50
}
51
52
int MonMeasure::scheduleNextIn(struct timeval *tv) {
53
        return schedule_measure(tv, this);
54
}
55
56
void MonMeasure::debugInit(const char *name) {
57
        char sid_string[SOCKETID_STRING_SIZE];
58
        SocketId sid;
59
        int errorstatus;
60
61
        std::string output_name;
62
        
63
        if(output_file.is_open())
64
                output_file.close();
65
66
        output_name = name;
67
68
        switch(flags & (TXONLY | RXONLY | TXRXUNI | TXRXBI)) {
69
        case TXONLY:
70
                        output_name += "TXONLY";
71
                        break;
72
        case RXONLY:
73
                        output_name += "RXONLY";
74
                        break;
75
        case TXRXBI:
76
                        output_name += "TXRXBI";
77 0135d29c RobertBirke
                        break;
78 956892f0 ArpadBakay
        case TXRXUNI:
79
                        output_name += "TXRXUNI";
80
                        break;
81
        }
82
83
        output_name += "-MT:" + msg_type;
84
85
        sid = mlGetLocalSocketID(&errorstatus);
86
        if(errorstatus == 0) {
87
                if(mlSocketIDToString(sid, sid_string, sizeof(sid_string)) == 0)
88
                        output_name += "-A:";
89
                        output_name += sid_string;
90
        }
91
92
        if(dst_socketid != NULL) {
93 d1e0f2ca RobertBirke
                if(mlSocketIDToString((SocketId) dst_socketid, sid_string, sizeof(sid_string)) == 0) {
94 956892f0 ArpadBakay
                        output_name += "-B:";
95
                        output_name += sid_string;
96
                }
97
        }
98
99 0135d29c RobertBirke
        output_file.open (output_name.c_str(), std::fstream::out | std::fstream::app);
100 956892f0 ArpadBakay
        output_file.setf(std::ios::fixed, std::ios::floatfield);
101
        output_file.precision(6);
102
}
103
104
void MonMeasure::debugStop() {
105
        output_file.close();
106
}
107
108
void MonMeasure::debugOutput(char *out) {
109
        switch((int)param_values[P_DEBUG_FILE]) {
110
        case        1:
111
                        output_file << out << std::endl;
112
                        break;
113
        case         3:
114
                        output_file << out << std::endl;
115
        case        2:
116
                        debug("%s",out);
117
                        break;
118
        }
119
}