Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7651e09e4a0d81fbbb92b808dd6d51f48bca18be (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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*******************************************************************************
 * 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 "common/debugging/MSCFilter.h"
#include "common/debugging/MSCLogger.h"
#include "debugging/etLogger.h"
#include "etDatatypes.h"

namespace etRuntime {

MSCLogger::MSCLogger() :
		m_commandList(),
		m_filter(0),
		m_path(),
		m_msc_name(),
		m_is_open(false),
		m_objectName() {
	etMutex_construct(&m_mutex);
}

MSCLogger::~MSCLogger() {
	if(m_filter != NULL)
		delete m_filter;
	m_filter = 0;
	etMutex_destruct(&m_mutex);
}

void MSCLogger::setMSC(const String& msc_name, const String& path) {
	m_msc_name = msc_name;
	m_path = path;
	if(m_filter != NULL)
		delete m_filter;
	m_filter = new MSCFilter();
}

void MSCLogger::open() {
	etMutex_enter(&m_mutex);
	m_is_open = true;
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageAsyncOut(const String& source, const String& target, const String& message) {
	etMutex_enter(&m_mutex);
	createLine(source, " >-- ", target, message);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageAsyncIn(const String& source, const String& target, const String& message) {
	etMutex_enter(&m_mutex);
	createLine(source, " --> ", target, message);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageSyncCall(const String& source, const String& target, const String& message) {
	etMutex_enter(&m_mutex);
	createLine(source, " ==> ", target, message);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageSyncReturn(const String& source, const String& target, const String& message) {
	etMutex_enter(&m_mutex);
	createLine(source, " <== ", target, message);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageActorCreate(const String& source, const String& target) {
	etMutex_enter(&m_mutex);
	createLine(source, " (!) ", target, "");
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageActorDestroy(const String& source, const String& target) {
	etMutex_enter(&m_mutex);
	createLine(source, " (X) ", target, "");
	etMutex_leave(&m_mutex);
}

void MSCLogger::addNote(const String& actor, const String& note) {
	etMutex_enter(&m_mutex);
	//if (filter.applyTo(actor))
	String reduced = m_filter->reduceString(actor.c_str());
	getCommandList().push_back("\t" + reduced + " note: " + note);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addMessageCreate(const String& source, const String& target) {
	etMutex_enter(&m_mutex);
	createLine(source, " (!) ", target, "");
	etMutex_leave(&m_mutex);
}

void MSCLogger::addActorState(const String& actor, const String& state) {
	etMutex_enter(&m_mutex);
	//if (filter->applyTo(actor))
	String reduced = m_filter->reduceString(actor.c_str());
	getCommandList().push_back("\t" + reduced + " >>> " + state);
	etMutex_leave(&m_mutex);
}

void MSCLogger::addVisibleComment(const String& comment) {
	etMutex_enter(&m_mutex);
	getCommandList().push_back("# " + comment);
	etMutex_leave(&m_mutex);
}

void MSCLogger::createLine(const String& source, const String& mid, const String& target,
		const String& message) {
	//if (filter->applyTo(source) && filter->applyTo(target)) {
	String reduced_src = m_filter->reduceString(source.c_str());
	String reduced_tgt = m_filter->reduceString(target.c_str());
	getCommandList().push_back(
			"\t" + reduced_src + mid + reduced_tgt + " " + message);
}

void MSCLogger::close() {
	if (m_is_open) {
		String path = m_path + m_msc_name + ".seq";
		etFileHandle handle = etLogger_fopen(path.c_str(), "w+");
		etMutex_enter(&m_mutex);
		if (handle != 0) {
			saveMSCforTrace2UML(handle);
			etLogger_fclose(handle);
		}
	}
	m_is_open = false;
	etMutex_leave(&m_mutex);
}

void MSCLogger::saveMSCforTrace2UML(etFileHandle handle) {
	etLogger_fprintf(handle, "; generated MSC for Trace2UML\n");

	Vector<String>::iterator it = getCommandList().begin();
	for (; it != getCommandList().end(); ++it){
		etLogger_fprintf(handle, (*it).c_str());
		etLogger_fprintf(handle, "\n");
	}
}

}

Back to the top