summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbd <bdunahu@operationnull.com>2025-03-10 20:55:21 -0400
committerbd <bdunahu@operationnull.com>2025-03-10 20:55:21 -0400
commitaf103123a90eaf34437b7979eee2579bab8b4b36 (patch)
treefbf6219eb7b38cd41b2fbc2544dc2410f2df13cf
parenta69b57c4e850e55167424d890a7a2e7a46460e71 (diff)
before error with catch crashing with global singleton logger
-rw-r--r--inc/definitions.h1
-rw-r--r--src/cli/cli.cc19
-rw-r--r--src/main.cc17
3 files changed, 17 insertions, 20 deletions
diff --git a/inc/definitions.h b/inc/definitions.h
index 8cafab3..98c4575 100644
--- a/inc/definitions.h
+++ b/inc/definitions.h
@@ -1,5 +1,6 @@
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
+#include "logger.h"
#include <cmath>
/**
diff --git a/src/cli/cli.cc b/src/cli/cli.cc
index a5706fb..2126798 100644
--- a/src/cli/cli.cc
+++ b/src/cli/cli.cc
@@ -3,9 +3,7 @@
#include "definitions.h"
#include "dram.h"
#include "response.h"
-#include <iostream>
-#include <sstream>
-#include <vector>
+#include <stdio.h>
Cli::Cli()
{
@@ -95,10 +93,7 @@ void Cli::help()
<< " q - Quits the program\n";
}
-void Cli::load(int memory_address)
-{
- std::cout << "Loading data from memory address " << memory_address;
-}
+void Cli::load(int memory_address) { ; }
void Cli::store(Accessor accessor, int data, int address)
{
@@ -142,11 +137,12 @@ void Cli::run()
{
std::cout << "Memory Command Processor Started. Type 'h' for a list of "
"commands.\n";
-
std::string input;
+
while (true) {
std::cout << "> ";
std::getline(std::cin, input);
+
std::istringstream iss(input);
std::vector<std::string> tokens;
std::string word;
@@ -168,15 +164,16 @@ void Cli::run()
if (it != commands.end()) {
it->second(tokens);
} else {
- std::cout
- << "Unknown command. Type 'help' for available commands.\n";
+ std::cout << "Unknown command: '" << command
+ << "'. Type 'help' for available commands.\n";
}
}
}
void Cli::initialize()
{
- std::cout << "Resetting memory configuration.\n";
+ Logger *global_log = Logger::getInstance();
+ global_log->log(INFO, "Resetting memory configuration.\n");
if (this->cache == nullptr)
delete this->cache;
Dram *d = new Dram(MEM_SIZE, MEM_DELAY);
diff --git a/src/main.cc b/src/main.cc
index 520a7e1..8a24fdb 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,10 +1,10 @@
#include "cli.h"
#include "logger.h"
+#include "definitions.h"
#include <getopt.h>
#include <iostream>
static std::string version_number = "v0.1";
-
static std::string banner =
" _/_/_/ _/_/_/ _/_/_/ _/_/_/ \n"
" _/ _/ _/ _/ _/ \n"
@@ -20,7 +20,6 @@ static std::string banner =
" _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ _/ \n"
" _/ _/ _/_/_/_/ _/_/_/ _/ _/_/ _/ _/ _/ \n"
" _/_/ _/_/ \n";
-
static void print_version_number() { std::cout << banner << version_number << '\n'; }
static void err()
@@ -33,7 +32,7 @@ static void err()
static void parseArguments(int argc, char **argv, bool &python)
{
- Logger *logger = Logger::getInstance();
+ Logger *global_log = Logger::getInstance();
struct option long_options[] = {
{"debug", no_argument, 0, 'd'},
{"no-python", no_argument, 0, 'p'},
@@ -46,11 +45,11 @@ static void parseArguments(int argc, char **argv, bool &python)
while ((opt = getopt_long(argc, argv, "d:p", long_options, NULL)) != -1) {
switch (opt) {
case 'd':
- logger->setLevel(DEBUG);
- logger->log(DEBUG, "DEBUG output enabled.");
+ global_log->setLevel(DEBUG);
+ global_log->log(DEBUG, "DEBUG output enabled.");
break;
case 'p':
- logger->log(INFO, "Python will NOT be started!");
+ global_log->log(INFO, "Python will NOT be started!");
python = false;
break;
case 'v':
@@ -65,10 +64,10 @@ static void parseArguments(int argc, char **argv, bool &python)
int main(int argc, char **argv)
{
+ Logger *global_log = Logger::getInstance();
print_version_number();
- Logger *logger = Logger::getInstance();
Cli cli;
- logger->log(INFO, "Initializing...");
+ global_log->log(INFO, "Initializing...");
bool python = true;
parseArguments(argc, argv, python);
@@ -76,7 +75,7 @@ int main(int argc, char **argv)
if (python) {
// fork off python here
;
- logger->log(INFO, "Python started.");
+ global_log->log(INFO, "Python started.");
}
cli.run();