OpenASIP  2.0
ProximRuntimeErrorHandler.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file ProximRuntimeErrorHandler.cc
26  *
27  * Implementation of ProximRuntimeErrorHandler class.
28  *
29  * @author Veli-Pekka Jääskeläinen 2005 (vjaaskel-no.spam-cs.tut.fi)
30  * @author Pekka Jääskeläinen 2009 (pjaaskel-no.spam-cs.tut.fi)
31  * @note rating: red
32  */
33 
34 #include <string>
37 #include "SimulatorEvent.hh"
38 
39 using std::string;
40 
41 /**
42  * The Constructor.
43  *
44  * The created error handler is registered automatically as simulator
45  * event handler listener.
46  *
47  * @param frontend Simulator frontend to stop when a fatal error occurs.
48  * @param gui GUI to send the error events to.
49  */
51  SimulatorFrontend& frontend,
52  wxEvtHandler& gui):
53  Listener(),
54  frontend_(frontend),
55  gui_(gui) {
56 
57  frontend.eventHandler().registerListener(
59 }
60 
61 /**
62  * The Destructor.
63  */
67 }
68 
69 
70 /**
71  * Handles simulator runtime errors.
72  *
73  * This event handler sends a SimulatorEvent to the GUI when a runtime error
74  * occurs. An error message explaining the error is sent as the event
75  * string payload. If a fatal error occured, the simulator is stopped.
76  */
77 void
79 
80  size_t minorErrors = frontend_.programErrorReportCount(
82  size_t fatalErrors = frontend_.programErrorReportCount(
84 
85  // Send runtime warning event if minor errors occured.
86  if (minorErrors > 0) {
87  string message;
88  for (size_t i = 0; i < minorErrors; ++i) {
89  message += "warning: runtime error: \n";
90  message += frontend_.programErrorReport(
91  SimulatorFrontend::RES_MINOR, i) + "\n\n";
92  }
93  SimulatorEvent simEvent(
95  wxPostEvent(&gui_, simEvent);
96  }
97 
98  // Send runtime error event if fatal errors occured.
99  if (fatalErrors > 0) {
100  string message;
101  for (size_t i = 0; i < fatalErrors; ++i) {
102  message += "error: runtime error: \n";
103  message +=
105  SimulatorFrontend::RES_FATAL, i) + "\n";
106 
107  }
108 
109  SimulatorEvent simEvent(
111  wxPostEvent(&gui_, simEvent);
112 
113  // Stop simulation.
115  }
116 
118 }
119 
ProximRuntimeErrorHandler::~ProximRuntimeErrorHandler
~ProximRuntimeErrorHandler()
Definition: ProximRuntimeErrorHandler.cc:64
SimulatorEvent.hh
Listener
Definition: Listener.hh:40
SimulatorEvent::EVT_SIMULATOR_RUNTIME_WARNING
static const wxEventType EVT_SIMULATOR_RUNTIME_WARNING
Runtime warning event.
Definition: SimulatorEvent.hh:66
ProximRuntimeErrorHandler.hh
SimulationEventHandler.hh
ProximRuntimeErrorHandler::frontend_
SimulatorFrontend & frontend_
Simulator frontend to stop when a fatal error occurs.
Definition: ProximRuntimeErrorHandler.hh:58
Informer::unregisterListener
virtual bool unregisterListener(int event, Listener *listener)
Definition: Informer.cc:104
SimulatorEvent::EVT_SIMULATOR_RUNTIME_ERROR
static const wxEventType EVT_SIMULATOR_RUNTIME_ERROR
Runtime error event.
Definition: SimulatorEvent.hh:64
SimulatorFrontend::programErrorReport
std::string programErrorReport(RuntimeErrorSeverity severity, std::size_t index)
Definition: SimulatorFrontend.cc:2321
Informer::registerListener
virtual bool registerListener(int event, Listener *listener)
Definition: Informer.cc:87
SRE_RUNTIME_ERROR
@ SRE_RUNTIME_ERROR
A fatal runtime error occured in the simulated program.
Definition: SimulatorConstants.hh:68
SimulatorFrontend::RES_MINOR
@ RES_MINOR
Minor runtime error, no abort necessary.
Definition: SimulatorFrontend.hh:94
SimulatorFrontend::RES_FATAL
@ RES_FATAL
Fatal runtime error, there is a serious error in the simulated program, thus it makes no sense to go ...
Definition: SimulatorFrontend.hh:95
SimulationEventHandler::SE_RUNTIME_ERROR
@ SE_RUNTIME_ERROR
Sent when a runtime error is detected in the simulated program.
Definition: SimulationEventHandler.hh:52
SimulatorFrontend::programErrorReportCount
std::size_t programErrorReportCount(RuntimeErrorSeverity severity)
Definition: SimulatorFrontend.cc:2344
SimulatorFrontend::clearProgramErrorReports
void clearProgramErrorReports()
Definition: SimulatorFrontend.cc:2360
ProximRuntimeErrorHandler::handleEvent
virtual void handleEvent()
Definition: ProximRuntimeErrorHandler.cc:78
SimulatorFrontend::eventHandler
SimulationEventHandler & eventHandler()
Definition: SimulatorFrontend.cc:2260
ProximRuntimeErrorHandler::gui_
wxEvtHandler & gui_
GUI to send the simulator events to.
Definition: ProximRuntimeErrorHandler.hh:60
ProximRuntimeErrorHandler::ProximRuntimeErrorHandler
ProximRuntimeErrorHandler(SimulatorFrontend &frontend, wxEvtHandler &gui)
Definition: ProximRuntimeErrorHandler.cc:50
SimulatorEvent
Definition: SimulatorEvent.hh:42
SimulatorFrontend
Definition: SimulatorFrontend.hh:89
SimulatorFrontend::prepareToStop
void prepareToStop(StopReason reason)
Definition: SimulatorFrontend.cc:1331