Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: d36b4c87c6ea6909c9bc8773dd1c35900353fbb6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*******************************************************************************
 * Copyright (c) 2012 Draeger Medical GmbH (http://www.draeger.com).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * CONTRIBUTORS:
 * 		Peter Karlitschek (initial contribution)
 *
 *******************************************************************************/

#include "MSCLogger.h"

namespace etRuntime {

MSCLogger::MSCLogger()
: commandList(),
  filter(0),
  path(),
  msc_name(),
is_open(false)
{
}

MSCLogger::~MSCLogger() {
	delete filter;
	filter = 0;
}

void MSCLogger::setMSC(const std::string& msc_name_, const std::string& path_) {
	msc_name = msc_name_;
	path = path_;
	delete filter;
	filter = new MSCFilter();
}

void MSCLogger::addMessageAsyncOut(const std::string& source, const std::string& target,
		const std::string& message) {
	createLine(source, " >-- ", target, message);
}

void MSCLogger::addMessageAsyncIn(const std::string& source, const std::string& target,
		const std::string& message) {
	createLine(source, " --> ", target, message);
}

void MSCLogger::addMessageSyncCall(const std::string& source, const std::string& target,
		const std::string& message) {
	createLine(source, " ==> ", target, message);
}

void MSCLogger::addMessageSyncReturn(const std::string& source, const std::string& target,
		const std::string& message) {
	createLine(source, " <== ", target, message);
}

void MSCLogger::addActorState(const std::string& actor, const std::string& state) {
	if (filter->applyTo(actor))
		commandList.push_back("\t" + filter->reduceString(actor) + " >>> " + state);
}

void MSCLogger::createLine(const std::string& source, const std::string& mid, const std::string& target, const std::string& message) {
	if (filter->applyTo(source) && filter->applyTo(target)) {
		commandList.push_back( "\t"+filter->reduceString(source)+mid+filter->reduceString(target)+ " " + message);
	}
}

void MSCLogger::close() {
	if (is_open) {
//		try {
		//TODO: error handling
			// Create file
			std::ofstream myfile;
			//TODO: where to create the file
			// std::string dir = "tmp/log"; doesn't work on windows
			std::string dir = "";
			myfile.open (std::string(dir + path + msc_name + ".seq").c_str(), std::ios::out);
			if (myfile.is_open()) { /* ok, proceed with output */
				saveMSCforTrace2UML(myfile);
				myfile.close();
			}
//		};
	}
	is_open = false;
}

void MSCLogger::saveMSCforTrace2UML(std::ofstream& out) {
	//try {
	//TODO: errorhandling
		out << "#generated MSC for Trace2UML";
		out << std::endl ;
		std::list<std::string>::iterator it = commandList.begin();
		for ( ; it != commandList.end(); ++it) {
			out << (*it) << std::endl;
		}
//	} catch (IOException e) {
//		System.err.println("Error: " + e.getMessage());
//	}

}


}

Back to the top