OpenASIP 2.2
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
Proxim Class Reference

#include <Proxim.hh>

Inheritance diagram for Proxim:
Inheritance graph
Collaboration diagram for Proxim:
Collaboration graph

Public Member Functions

 Proxim ()
 
virtual ~Proxim ()
 
virtual bool OnInit ()
 
virtual int OnExit ()
 
ProximSimulationThreadsimulation ()
 
CommandRegistrycommandRegistry ()
 
GUIOptionsoptions ()
 

Private Member Functions

void loadOptions ()
 
void createDefaultOptions ()
 

Private Attributes

ProximMainFramemainFrame_
 The application main frame.
 
CommandRegistrycommandRegistry_
 The application command registry.
 
ProximSimulationThreadsimulation_
 The simulation thread running the simulator backend.
 
GUIOptionsoptions_
 Options defining toolbar, keyboard shortcuts etc.
 

Static Private Attributes

static const std::string CONFIG_FILE_NAME = "Proxim.conf"
 Name of the config file.
 
static const std::string SCHEMA_FILE_NAME = "confschema.xsd"
 Name of the xml-schema file.
 

Detailed Description

Represents the Proxim application.

This is the top level class of the application. Derived from the wxApp class, which does the low level initialization of wxWidgets. This class is responsible for the application initialization and termination.

Definition at line 53 of file Proxim.hh.

Constructor & Destructor Documentation

◆ Proxim()

Proxim::Proxim ( )

The constructor.

Definition at line 67 of file Proxim.cc.

67 :
68 wxApp(), mainFrame_(NULL), commandRegistry_(NULL), simulation_(NULL),
69 options_(NULL) {
70}
CommandRegistry * commandRegistry_
The application command registry.
Definition Proxim.hh:70
GUIOptions * options_
Options defining toolbar, keyboard shortcuts etc.
Definition Proxim.hh:74
ProximSimulationThread * simulation_
The simulation thread running the simulator backend.
Definition Proxim.hh:72
ProximMainFrame * mainFrame_
The application main frame.
Definition Proxim.hh:68

◆ ~Proxim()

Proxim::~Proxim ( )
virtual

The Destructor.

Definition at line 76 of file Proxim.cc.

76 {
77 delete commandRegistry_;
78}

References commandRegistry_.

Member Function Documentation

◆ commandRegistry()

CommandRegistry & Proxim::commandRegistry ( )

Returns reference to the application command registry.

The command registry stores all commands available for execution in the main fram menubar and toolbar.

Returns
Reference to the application command registry.

Definition at line 216 of file Proxim.cc.

216 {
217 return *commandRegistry_;
218}

References commandRegistry_.

◆ createDefaultOptions()

void Proxim::createDefaultOptions ( )
private

Creates a default set of options if the configuration file is erroneous or not found.

Definition at line 270 of file Proxim.cc.

270 {
271
272 ToolbarButton* buttonMachine = new ToolbarButton(
274
275 ToolbarButton* buttonProgram = new ToolbarButton(
277
278 ToolbarButton* buttonRun = new ToolbarButton(
280
281 ToolbarButton* buttonResume = new ToolbarButton(
283
284 ToolbarButton* buttonKill = new ToolbarButton(
286
287 ToolbarButton* buttonStepi = new ToolbarButton(
289
290 ToolbarButton* buttonNexti = new ToolbarButton(
292
293 // F2 -> run
295 ProximConstants::COMMAND_NAME_RUN, 2, false, false, 0);
296
297 // F4 -> kill
299 ProximConstants::COMMAND_NAME_KILL, 4, false, false, 0);
300
301 // F5 -> stepi
302 KeyboardShortcut* scStepi = new KeyboardShortcut(
303 ProximConstants::COMMAND_NAME_STEPI, 5, false, false, 0);
304
305 // F6 -> nexti
306 KeyboardShortcut* scNexti = new KeyboardShortcut(
307 ProximConstants::COMMAND_NAME_NEXTI, 6, false, false, 0);
308
309 // F9 -> resume
310 KeyboardShortcut* scResume = new KeyboardShortcut(
311 ProximConstants::COMMAND_NAME_RESUME, 9, false, false, 0);
312
313 // Ctrl + F -> find operation in assembly code window
315 ProximConstants::COMMAND_NAME_FIND, 0, true, false, int('F'));
316
319
320 options_->setFileName(fileName);
321
322 options_->addToolbarButton(buttonMachine);
323 options_->addToolbarButton(buttonProgram);
324 options_->addToolbarButton(buttonRun);
325 options_->addToolbarButton(buttonResume);
326 options_->addToolbarButton(buttonKill);
327 options_->addToolbarButton(buttonStepi);
328 options_->addToolbarButton(buttonNexti);
332
336 options_->addKeyboardShortcut(scResume);
339}
static TCEString userConfPath(const std::string &fileName)
void addKeyboardShortcut(KeyboardShortcut *shortcut)
void setToolbarVisibility(bool visible)
void addToolbarButton(ToolbarButton *button)
void addSeparator(int position)
@ TEXT
Buttons contains only text.
Definition GUIOptions.hh:65
void setFileName(const std::string &fileName)
void setToolbarLayout(ToolbarLayout layout)
static const std::string COMMAND_NAME_RESUME
Name of the resume command.
static const std::string COMMAND_NAME_RUN
Name of the run command.
static const std::string COMMAND_NAME_OPEN_PROGRAM
Name of the open program command.
static const std::string COMMAND_NAME_NEXTI
Name of the next instruction command.
static const std::string COMMAND_NAME_KILL
Name of the kill command.
static const std::string CONFIGURATION_NAME
Configuration file top-level element name.
static const std::string COMMAND_NAME_STEPI
Name of the step instruction command.
static const std::string COMMAND_NAME_FIND
Name of the find command.
static const std::string COMMAND_NAME_OPEN_MACHINE
Name of the open machine command.
static const std::string CONFIG_FILE_NAME
Name of the config file.
Definition Proxim.hh:77

References GUIOptions::addKeyboardShortcut(), GUIOptions::addSeparator(), GUIOptions::addToolbarButton(), ProximConstants::COMMAND_NAME_FIND, ProximConstants::COMMAND_NAME_KILL, ProximConstants::COMMAND_NAME_NEXTI, ProximConstants::COMMAND_NAME_OPEN_MACHINE, ProximConstants::COMMAND_NAME_OPEN_PROGRAM, ProximConstants::COMMAND_NAME_RESUME, ProximConstants::COMMAND_NAME_RUN, ProximConstants::COMMAND_NAME_STEPI, CONFIG_FILE_NAME, ProximConstants::CONFIGURATION_NAME, options_, GUIOptions::setFileName(), GUIOptions::setToolbarLayout(), GUIOptions::setToolbarVisibility(), GUIOptions::TEXT, and Environment::userConfPath().

Referenced by loadOptions().

Here is the call graph for this function:

◆ loadOptions()

void Proxim::loadOptions ( )
private

Loads GUIOptions for Proxim from the configuration file.

If the configuration file is erroneous or not found, default options will be used.

Definition at line 227 of file Proxim.cc.

227 {
228
229 if (options_ != NULL) {
230 delete options_;
231 }
232
233 bool optionsOK = false;
234
235 string configFile = Environment::confPath(CONFIG_FILE_NAME);
236
237 string schemaFile = Environment::dataDirPath("Proxim") +
239
241 reader.setSourceFile(configFile);
242 reader.setSchemaFile(schemaFile);
243 reader.setUseSchema(true);
244
245 try {
246 ObjectState* optionsState = reader.readState();
247 options_ = new GUIOptions(optionsState);
248 delete optionsState;
250 options_->setFileName(configFile);
251 optionsOK = true;
252 } catch (Exception& e) {
253 cerr << "Error loading config file " << configFile << ":" << endl
254 << e.errorMessage() << endl
255 << "Default options will be used." << endl;
256 }
257
258 if (!optionsOK) {
260 } else {
262 }
263}
static std::string dataDirPath(const std::string &prog)
static TCEString confPath(const std::string &fileName)
std::string errorMessage() const
Definition Exception.cc:123
static const std::string DIRECTORY_SEPARATOR
virtual void validate() const
void clearModified()
void createDefaultOptions()
Definition Proxim.cc:270
static const std::string SCHEMA_FILE_NAME
Name of the xml-schema file.
Definition Proxim.hh:79

References GUIOptions::clearModified(), CONFIG_FILE_NAME, ProximConstants::CONFIGURATION_NAME, Environment::confPath(), createDefaultOptions(), Environment::dataDirPath(), FileSystem::DIRECTORY_SEPARATOR, Exception::errorMessage(), options_, GUIOptionsSerializer::readState(), SCHEMA_FILE_NAME, GUIOptions::setFileName(), XMLSerializer::setSchemaFile(), XMLSerializer::setSourceFile(), XMLSerializer::setUseSchema(), and GUIOptions::validate().

Referenced by OnInit().

Here is the call graph for this function:

◆ OnExit()

int Proxim::OnExit ( )
virtual

Deletes the simulation thread when the application exits.

Returns
Exit code.

Definition at line 188 of file Proxim.cc.

188 {
189 simulation_->Delete();
190 simulation_->Wait();
191 delete simulation_;
192 return EXIT_SUCCESS;
193}

References simulation_.

◆ OnInit()

bool Proxim::OnInit ( )
virtual

Initializes the application.

Creates command registry, application main frame and a simulation thread. The main frame console linereader is set as the linereader for the simulator thread.

Returns
True, if the application was succesfully initialized.

Definition at line 92 of file Proxim.cc.

92 {
93
95
96 const wxCmdLineEntryDesc cmdLineDesc[] = {
97
98#if wxCHECK_VERSION(3,0,0)
99 { wxCMD_LINE_PARAM, NULL, NULL, "input file",
100#else
101 { wxCMD_LINE_PARAM, NULL, NULL, _T("input file"),
102#endif
103
104 wxCMD_LINE_VAL_STRING,
105 (wxCMD_LINE_PARAM_MULTIPLE | wxCMD_LINE_PARAM_OPTIONAL) },
106 { wxCMD_LINE_NONE, NULL, NULL, NULL, wxCMD_LINE_VAL_NONE, 0 }
107 };
108
109 wxCmdLineParser parser(cmdLineDesc);
110 parser.SetCmdLine(argc, argv);
111 parser.Parse();
112
113 std::string machineToLoad = "";
114 std::string programToLoad = "";
115
116 if (parser.GetParamCount() == 1) {
117 programToLoad = WxConversion::toString(parser.GetParam(0));
118 } else if (parser.GetParamCount() == 2) {
119 machineToLoad = WxConversion::toString(parser.GetParam(0));
120 programToLoad = WxConversion::toString(parser.GetParam(1));
121 } else if (parser.GetParamCount() > 2) {
122 std::cout << ProximConstants::PROXIM_TITLE << " "
123 << Application::TCEVersionString() << std::endl;
124 std::cout << "Usage: proxim [program file]" << endl;
125 std::cout << " proxim [machine file] [program file]" << endl;
126
127 return false;
128 }
129
130
131 // load image handler for pngs
132 wxImage::AddHandler(new wxPNGHandler);
133
136 options_ = new GUIOptions("proxim-configuration");
137
138 loadOptions();
139
141 _T("TTA Processor Simulator"), wxDefaultPosition, wxSize(800, 600));
142
143 simulation_->Create();
145 simulation_->Run();
146
147 mainFrame_->Show(true);
148 SetTopWindow(mainFrame_);
149
151
152 if (machineToLoad != "") {
153 interpreter->interpret(
154 ProximConstants::SCL_LOAD_MACHINE + " " + machineToLoad);
155 if (interpreter->result().size() > 0) {
156 wxString message = _T("Error loading machine file '");
157 message.Append(WxConversion::toWxString(machineToLoad));
158 message.Append(_T("'.\n"));
159 message.Append(WxConversion::toWxString(interpreter->result()));
160 ErrorDialog dialog(mainFrame_, message);
161 dialog.ShowModal();
162 return true;
163 }
164 }
165
166 if (programToLoad != "") {
167 interpreter->interpret(
168 ProximConstants::SCL_LOAD_PROGRAM + " " + programToLoad);
169 if (interpreter->result().size() > 0) {
170 wxString message = _T("Error loading program file '");
171 message.Append(WxConversion::toWxString(programToLoad));
172 message.Append(_T("'.\n"));
173 message.Append(WxConversion::toWxString(interpreter->result()));
174 ErrorDialog dialog(mainFrame_, message);
175 dialog.ShowModal();
176 }
177 }
178 return true;
179}
static std::string TCEVersionString()
static void initialize()
static const std::string SCL_LOAD_PROGRAM
Command for loading a new program in the simulator.
static const std::string SCL_LOAD_MACHINE
Command for loading a new machine in the simulator.
static const std::string PROXIM_TITLE
Application title.
void initialize(ProximMainFrame *gui)
SimulatorInterpreter * interpreter()
void loadOptions()
Definition Proxim.cc:227
virtual std::string result()
virtual bool interpret(const std::string &commandLine)
static char ** toCStringArray(size_t elements, wxChar **source)
static wxString toWxString(const std::string &source)
static std::string toString(const wxString &source)

References commandRegistry_, Application::initialize(), ProximSimulationThread::initialize(), TclInterpreter::interpret(), ProximSimulationThread::interpreter(), loadOptions(), mainFrame_, options_, ProximConstants::PROXIM_TITLE, ScriptInterpreter::result(), ProximConstants::SCL_LOAD_MACHINE, ProximConstants::SCL_LOAD_PROGRAM, simulation_, Application::TCEVersionString(), WxConversion::toCStringArray(), WxConversion::toString(), and WxConversion::toWxString().

Here is the call graph for this function:

◆ options()

GUIOptions & Proxim::options ( )

Returns references to the application options.

Returns
GUIOptions of the application.

Definition at line 347 of file Proxim.cc.

347 {
348 return *options_;
349}

References options_.

◆ simulation()

ProximSimulationThread * Proxim::simulation ( )

Returns pointer to the simulation thread.

Returns
Pointer to the simulation thread.

Definition at line 202 of file Proxim.cc.

202 {
203 return simulation_;
204}

References simulation_.

Member Data Documentation

◆ commandRegistry_

CommandRegistry* Proxim::commandRegistry_
private

The application command registry.

Definition at line 70 of file Proxim.hh.

Referenced by commandRegistry(), OnInit(), and ~Proxim().

◆ CONFIG_FILE_NAME

const std::string Proxim::CONFIG_FILE_NAME = "Proxim.conf"
staticprivate

Name of the config file.

Definition at line 77 of file Proxim.hh.

Referenced by createDefaultOptions(), and loadOptions().

◆ mainFrame_

ProximMainFrame* Proxim::mainFrame_
private

The application main frame.

Definition at line 68 of file Proxim.hh.

Referenced by OnInit().

◆ options_

GUIOptions* Proxim::options_
private

Options defining toolbar, keyboard shortcuts etc.

Definition at line 74 of file Proxim.hh.

Referenced by createDefaultOptions(), loadOptions(), OnInit(), and options().

◆ SCHEMA_FILE_NAME

const std::string Proxim::SCHEMA_FILE_NAME = "confschema.xsd"
staticprivate

Name of the xml-schema file.

Definition at line 79 of file Proxim.hh.

Referenced by loadOptions().

◆ simulation_

ProximSimulationThread* Proxim::simulation_
private

The simulation thread running the simulator backend.

Definition at line 72 of file Proxim.hh.

Referenced by OnExit(), OnInit(), and simulation().


The documentation for this class was generated from the following files: