KoMo2  1.0.0
A modern ARM emulator GUI.
Functions | Variables
main.cpp File Reference

The entry point of the program. Should have as little logic as possible. More...

#include <glib.h>
#include <glibmm/optioncontext.h>
#include <gtkmm/application.h>
#include <libgen.h>
#include <sys/signal.h>
#include <unistd.h>
#include <array>
#include <fstream>
#include <iostream>
#include <regex>
#include <sstream>
#include <utility>
#include "../../libs/rapidjson/document.h"
#include "models/KoMo2Model.h"
#include "views/MainWindowView.h"

Go to the source code of this file.

Functions

void initJimulator (std::string argv0)
 Initialises Jimulator in a separate child process. More...
 
void initCompilerPipes (KoMo2Model *mainModel)
 Initialises the communication pipes between the compiler process & the main KoMo2 GUI. More...
 
const std::string getAbsolutePathToRootDirectory (const char *const arg)
 get the absolute path to the directory of the binary. More...
 
const int initialiseCommandLine (const Glib::RefPtr< Gio::ApplicationCommandLine > &cmd, const Glib::RefPtr< Gtk::Application > &app)
 Sets up and parses custom command line arguments. To add more command line arguments, create a new boolean and a new Glib::OptionEntry object, and then add a longname, shortname, and description, then add it to the group. Then pass the boolean into the handleCommandLine function. More...
 
const bool receivedCompilerOutput (GIOChannel *source, GIOCondition condition, gpointer data)
 This callback function is called when the compiler communication pipe receives a change in state (meaning the compiler process has sent some data). This function will then send that data to the integrated terminal within KoMo2. More...
 
void readProgramVariables (const std::string argv0)
 Reads the program variables from the "variables.json" file and populates global variables with the values read.
 
int main (int argc, char *argv[])
 The program entry point. More...
 
const int handleCommandLine (const bool isVersion, const bool isHelp, const bool isMnemonics)
 Handles if a command line flag is set. More...
 

Variables

int emulator_PID = -1
 This variable will store the PID of the Jimulator process.
 
int communicationFromJimulator [2]
 The pipe which will be used by KoMo2 to read from Jimulator (i.e. Jimulator will write to it, KoMo2 will read)
 
int communicationToJimulator [2]
 The pipe which will be used by KoMo2 to write to Jimulator (i.e. Jimulator will read from it, KoMo2 will write)
 
int compilerCommunication [2]
 The pipe that handles communication between the compiler process and KoMo2.
 
int writeToJimulator
 Stores the file descriptor used for writing to Jimulator.
 
int readFromJimulator
 Stores the file descriptor used for reading from Jimulator.
 
std::string version = "1.0.0"
 Version information read from variables.json is stored here.
 
std::string manual = "https://github.com/LawrenceWarren/KoMo2#user-manual"
 Manual information read from variables.json is stored here.
 
std::string help = "Please view the user manual (" + manual + ") for help."
 Help information read from variables.json is stored here.
 
int refresh = 200
 Refresh rate information read from variables.json is stored here.
 
void * model
 Used as a reference to the master KoMo2Model.
 

Detailed Description

The entry point of the program. Should have as little logic as possible.

Author
Lawrence Warren (lawre.nosp@m.ncew.nosp@m.arren.nosp@m.2@gm.nosp@m.ail.c.nosp@m.om)
Version
1.0.0
Date
10-04-2021

LICENSE

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details at https://www.gnu.org/copyleft/gpl.html

Definition in file main.cpp.

Function Documentation

const std::string getAbsolutePathToRootDirectory ( const char *const  arg)

get the absolute path to the directory of the binary.

Returns
std::string the directory of the KoMo2 binary - if the binary is at /home/user/demo/kmd, return /home/user/demo.

Definition at line 188 of file main.cpp.

const int handleCommandLine ( const bool  isVersion,
const bool  isHelp,
const bool  isMnemonics 
)

Handles if a command line flag is set.

Parameters
isVersionIf the version flag has been set.
isHelpIf the help flag has been set.
isMnemonicsIf the mnemonics flag is set.
Returns
int status code.

Definition at line 256 of file main.cpp.

void initCompilerPipes ( KoMo2Model mainModel)

Initialises the communication pipes between the compiler process & the main KoMo2 GUI.

Parameters
mainModelA pointer to the main KoMo2 model.

Definition at line 128 of file main.cpp.

const int initialiseCommandLine ( const Glib::RefPtr< Gio::ApplicationCommandLine > &  cmd,
const Glib::RefPtr< Gtk::Application > &  app 
)

Sets up and parses custom command line arguments. To add more command line arguments, create a new boolean and a new Glib::OptionEntry object, and then add a longname, shortname, and description, then add it to the group. Then pass the boolean into the handleCommandLine function.

Parameters
cmdThe apps command line object.
appThe GTK application itself.
Returns
int status code.

Definition at line 287 of file main.cpp.

void initJimulator ( std::string  argv0)

Initialises Jimulator in a separate child process.

Parameters
argv0A path to the directory where the KoMo2 executable exists. It is assumed that all other files required by the program at run time (executables and resources) live in the same directory. For example, if the KoMo2 executable exists at /home/user/demo/kmd then argv0 will have the value /home/user/demo and it will be assumed that the Jimulator executable lives at /home/user/demo/jimulator.

Definition at line 152 of file main.cpp.

int main ( int  argc,
char *  argv[] 
)

The program entry point.

Parameters
argcThe number of command line arguments.
argvAn array of command line arguments.
Returns
int exit code.

Definition at line 94 of file main.cpp.

const bool receivedCompilerOutput ( GIOChannel *  source,
GIOCondition  condition,
gpointer  data 
)

This callback function is called when the compiler communication pipe receives a change in state (meaning the compiler process has sent some data). This function will then send that data to the integrated terminal within KoMo2.

Parameters
sourceA pointer to the file descriptor which had a change of state and caused this callback function to fire.
conditionThe type of state that changed to cause this callback to fire - for example, new data is to be read from the file descriptor, or data can be written to the file descriptor.
dataAny additional data - in this case, a pointer to the KoMo2 model is sent.
Returns
true There is more to be handled - this function can be called again to handle a related state change.
false The function is done handling the state change.

Definition at line 349 of file main.cpp.