OpenASIP  2.0
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. More...
 
CommandRegistrycommandRegistry_
 The application command registry. More...
 
ProximSimulationThreadsimulation_
 The simulation thread running the simulator backend. More...
 
GUIOptionsoptions_
 Options defining toolbar, keyboard shortcuts etc. More...
 

Static Private Attributes

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

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 }

◆ ~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
294  KeyboardShortcut* scRun = new KeyboardShortcut(
295  ProximConstants::COMMAND_NAME_RUN, 2, false, false, 0);
296 
297  // F4 -> kill
298  KeyboardShortcut* scKill = new KeyboardShortcut(
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
314  KeyboardShortcut* scFind = new KeyboardShortcut(
315  ProximConstants::COMMAND_NAME_FIND, 0, true, false, int('F'));
316 
318  string fileName = Environment::userConfPath(CONFIG_FILE_NAME);
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 
334  options_->addKeyboardShortcut(scStepi);
335  options_->addKeyboardShortcut(scNexti);
336  options_->addKeyboardShortcut(scResume);
337  options_->addKeyboardShortcut(scKill);
338  options_->addKeyboardShortcut(scFind);
339 }

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;
249  options_->validate();
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 }

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 
150  SimulatorInterpreter* interpreter = simulation_->interpreter();
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 }

References commandRegistry_, ProximSimulationThread::initialize(), Application::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:
ProximConstants::COMMAND_NAME_NEXTI
static const std::string COMMAND_NAME_NEXTI
Name of the next instruction command.
Definition: ProximConstants.hh:122
ProximMainFrame
Definition: ProximMainFrame.hh:58
WxConversion::toWxString
static wxString toWxString(const std::string &source)
Proxim::options_
GUIOptions * options_
Options defining toolbar, keyboard shortcuts etc.
Definition: Proxim.hh:74
GUIOptions::clearModified
void clearModified()
Definition: GUIOptions.cc:502
ScriptInterpreter::result
virtual std::string result()
Definition: ScriptInterpreter.cc:191
GUIOptions::addToolbarButton
void addToolbarButton(ToolbarButton *button)
Definition: GUIOptions.cc:292
ProximConstants::CONFIGURATION_NAME
static const std::string CONFIGURATION_NAME
Configuration file top-level element name.
Definition: ProximConstants.hh:247
ProximSimulationThread
Definition: ProximSimulationThread.hh:55
ProximSimulationThread::interpreter
SimulatorInterpreter * interpreter()
Definition: ProximSimulationThread.cc:244
ObjectState
Definition: ObjectState.hh:59
ToolbarButton
Definition: ToolbarButton.hh:48
Proxim::mainFrame_
ProximMainFrame * mainFrame_
The application main frame.
Definition: Proxim.hh:68
ProximConstants::COMMAND_NAME_OPEN_PROGRAM
static const std::string COMMAND_NAME_OPEN_PROGRAM
Name of the open program command.
Definition: ProximConstants.hh:104
GUIOptions::setToolbarVisibility
void setToolbarVisibility(bool visible)
Definition: GUIOptions.cc:256
Environment::userConfPath
static TCEString userConfPath(const std::string &fileName)
Definition: Environment.cc:303
ProximConstants::PROXIM_TITLE
static const std::string PROXIM_TITLE
Application title.
Definition: ProximConstants.hh:250
ProximConstants::SCL_LOAD_MACHINE
static const std::string SCL_LOAD_MACHINE
Command for loading a new machine in the simulator.
Definition: ProximConstants.hh:147
ProximConstants::COMMAND_NAME_STEPI
static const std::string COMMAND_NAME_STEPI
Name of the step instruction command.
Definition: ProximConstants.hh:120
ProximConstants::COMMAND_NAME_KILL
static const std::string COMMAND_NAME_KILL
Name of the kill command.
Definition: ProximConstants.hh:126
SimulatorInterpreter
Definition: SimulatorInterpreter.hh:49
ErrorDialog
Definition: ErrorDialog.hh:42
ProximConstants::COMMAND_NAME_FIND
static const std::string COMMAND_NAME_FIND
Name of the find command.
Definition: ProximConstants.hh:140
CommandRegistry
Definition: CommandRegistry.hh:47
GUIOptions::addSeparator
void addSeparator(int position)
Definition: GUIOptions.cc:305
TclInterpreter::interpret
virtual bool interpret(const std::string &commandLine)
Definition: TclInterpreter.cc:138
GUIOptions::TEXT
@ TEXT
Buttons contains only text.
Definition: GUIOptions.hh:65
GUIOptions::setFileName
void setFileName(const std::string &fileName)
Definition: GUIOptions.cc:632
GUIOptions::addKeyboardShortcut
void addKeyboardShortcut(KeyboardShortcut *shortcut)
Definition: GUIOptions.cc:280
Exception
Definition: Exception.hh:54
ProximConstants::COMMAND_NAME_OPEN_MACHINE
static const std::string COMMAND_NAME_OPEN_MACHINE
Name of the open machine command.
Definition: ProximConstants.hh:106
GUIOptions::setToolbarLayout
void setToolbarLayout(ToolbarLayout layout)
Definition: GUIOptions.cc:268
GUIOptions::validate
virtual void validate() const
Definition: GUIOptions.cc:529
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
FileSystem::DIRECTORY_SEPARATOR
static const std::string DIRECTORY_SEPARATOR
Definition: FileSystem.hh:189
KeyboardShortcut
Definition: KeyboardShortcut.hh:50
ProximSimulationThread::initialize
void initialize(ProximMainFrame *gui)
Definition: ProximSimulationThread.cc:87
GUIOptions
Definition: GUIOptions.hh:58
ProximConstants::COMMAND_NAME_RUN
static const std::string COMMAND_NAME_RUN
Name of the run command.
Definition: ProximConstants.hh:118
Environment::confPath
static TCEString confPath(const std::string &fileName)
Definition: Environment.cc:277
Proxim::createDefaultOptions
void createDefaultOptions()
Definition: Proxim.cc:270
Proxim::simulation_
ProximSimulationThread * simulation_
The simulation thread running the simulator backend.
Definition: Proxim.hh:72
Application::initialize
static void initialize()
Definition: Application.cc:99
ProximConstants::SCL_LOAD_PROGRAM
static const std::string SCL_LOAD_PROGRAM
Command for loading a new program in the simulator.
Definition: ProximConstants.hh:145
Proxim::loadOptions
void loadOptions()
Definition: Proxim.cc:227
ProximConstants::COMMAND_NAME_RESUME
static const std::string COMMAND_NAME_RESUME
Name of the resume command.
Definition: ProximConstants.hh:128
Proxim::CONFIG_FILE_NAME
static const std::string CONFIG_FILE_NAME
Name of the config file.
Definition: Proxim.hh:77
WxConversion::toString
static std::string toString(const wxString &source)
Application::TCEVersionString
static std::string TCEVersionString()
Definition: Application.cc:510
Proxim::SCHEMA_FILE_NAME
static const std::string SCHEMA_FILE_NAME
Name of the xml-schema file.
Definition: Proxim.hh:79
Environment::dataDirPath
static std::string dataDirPath(const std::string &prog)
Definition: Environment.cc:176
Proxim::commandRegistry_
CommandRegistry * commandRegistry_
The application command registry.
Definition: Proxim.hh:70
GUIOptionsSerializer
Definition: GUIOptionsSerializer.hh:52
WxConversion::toCStringArray
static char ** toCStringArray(size_t elements, wxChar **source)
Definition: WxConversion.cc:123