diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5720785..695eb12 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,5 +1,5 @@ -add_library(Core OBJECT EventBus.cpp ConfigManager.cpp Logger.cpp) +add_library(Core OBJECT EventBus.cpp ConfigManager.cpp Logger.cpp Exception.cpp) target_include_directories(Core PUBLIC include) diff --git a/src/core/EventBus.cpp b/src/core/EventBus.cpp index fce99d7..4b458f9 100644 --- a/src/core/EventBus.cpp +++ b/src/core/EventBus.cpp @@ -31,7 +31,7 @@ Event& EventBus::registerEvent(const string& eventID) { } void EventBus::run() { - //_logger.debug.ln("Hi from EventBus run method! From within Event Thread!"); + _logger.warn.ln("Hi from EventBus run method! From within Event Thread! Dont forget to make Logger class thread-safe!"); } // =============================== Event Class ================================ diff --git a/src/core/Exception.cpp b/src/core/Exception.cpp new file mode 100644 index 0000000..f674de6 --- /dev/null +++ b/src/core/Exception.cpp @@ -0,0 +1,16 @@ +#include "Exception.hpp" + +namespace Plains { +namespace Core { + +using std::string; + +Exception::Exception(const char* msg) : _msg(msg) {} + +const char* Exception::what() const noexcept { return _msg; } + + + + + +}} diff --git a/src/core/include/Core.hpp b/src/core/include/Core.hpp index 14304ac..ca0f5e4 100644 --- a/src/core/include/Core.hpp +++ b/src/core/include/Core.hpp @@ -3,5 +3,6 @@ #include "EventBus.hpp" #include "Logger.hpp" #include "ConfigManager.hpp" +#include "Exception.hpp" //Include further classes here #endif diff --git a/src/core/include/Exception.hpp b/src/core/include/Exception.hpp new file mode 100644 index 0000000..ffdc6d3 --- /dev/null +++ b/src/core/include/Exception.hpp @@ -0,0 +1,24 @@ +#ifndef EXCEPTION_HPP +#define EXCEPTION_HPP +#include +#include + +namespace Plains { +namespace Core { + +using std::exception; +using std::string; + +class Exception: public exception +{ + public: + Exception(const char* msg); + const char* what() const noexcept; + + private: + const char* _msg; +}; + +}} + +#endif diff --git a/src/core/include/Logger.hpp b/src/core/include/Logger.hpp index e556691..8ac0a6a 100644 --- a/src/core/include/Logger.hpp +++ b/src/core/include/Logger.hpp @@ -38,7 +38,6 @@ class Logger { bool _lineIsPrefixed; Logger& _parent; const Logger::Level _level; - const char* _colorCode; void prefixLine(bool resetToFalse = false); public: Sink(const Level level, Logger& parent); diff --git a/src/core/main.cpp b/src/core/main.cpp index 324b6d5..4cb318e 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -13,11 +13,6 @@ using std::string; int main(int args, char **argv) { Logger logger(Logger::DEBUG); - //logger.debug.ln ("Debug message"); - //logger.info.ln ("Info message"); - //logger.warn.ln ("Warning message"); - //logger.fatal.ln ("Fatal message"); - logger.info.ln ("Starting PlaiNS..."); try @@ -31,7 +26,7 @@ int main(int args, char **argv) { EventBus eventBus(logger); Resolver::Server resolver(logger, eventBus); - + /* // Some test code below: class Testi : public EventSubscriber { public: @@ -51,11 +46,9 @@ int main(int args, char **argv) { e2.subscribe(&testi2); e1.fire(); - + */ //Record testrec = ARecord(); - //logger.debug.ln ("Running DNS resolver..."); - // End of Testcode //resolver.run(); @@ -63,9 +56,15 @@ int main(int args, char **argv) { // Run something on main thread... logger.info.ln ("Shutting down PlaiNS. Good Bye!"); } - catch (std::exception& e) + catch (Exception& e) { - logger.debug << "Exception: " << e.what() << Logger::commit; + logger.fatal << "Uncaught Exception: " << e.what() << Logger::commit; + return 1; + } + catch (int e) + { + logger.fatal << "Uncaught Exception with error code " << e << Logger::commit; + return 1; } return 0; } diff --git a/src/resolver/Server.cpp b/src/resolver/Server.cpp index c1de42e..2e763e4 100644 --- a/src/resolver/Server.cpp +++ b/src/resolver/Server.cpp @@ -2,7 +2,6 @@ #include "Message.hpp" #include -#include #include #include #include @@ -54,6 +53,7 @@ Server::Server(Logger& logger, EventBus& eventBus) _eventBus(eventBus) { _logger.debug.ln ("Starting Resolver..."); + //throw Exception("Testi"); /* _logger.debug << "Testing some stuff..." << Logger::commit; _logger.debug << "Message header overall size: " << sizeof(Message::Header) << Logger::commit; diff --git a/src/resolver/include/Server.hpp b/src/resolver/include/Server.hpp index 9d462ad..b7a953c 100644 --- a/src/resolver/include/Server.hpp +++ b/src/resolver/include/Server.hpp @@ -10,6 +10,7 @@ namespace Resolver { using Core::EventBus; using Core::Logger; +using Core::Exception; class Server @@ -35,10 +36,6 @@ class Server - - - - }} #endif