summaryrefslogtreecommitdiff
path: root/cesar/maximus/utils/inc
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/maximus/utils/inc')
-rw-r--r--cesar/maximus/utils/inc/Error.h36
-rw-r--r--cesar/maximus/utils/inc/ErrorTest.h34
-rw-r--r--cesar/maximus/utils/inc/Logger.h104
-rw-r--r--cesar/maximus/utils/inc/LoggerTest.h34
4 files changed, 208 insertions, 0 deletions
diff --git a/cesar/maximus/utils/inc/Error.h b/cesar/maximus/utils/inc/Error.h
new file mode 100644
index 0000000000..3754f88d93
--- /dev/null
+++ b/cesar/maximus/utils/inc/Error.h
@@ -0,0 +1,36 @@
+
+#ifndef ERROR_H
+#define ERROR_H
+
+#include <iostream>
+#include <stdexcept>
+#include <errno.h>
+using namespace std;
+
+
+class Error : public runtime_error
+{
+
+public:
+
+ Error ( const string & function, const string & msg, const error_t error = ENOTRECOVERABLE );
+
+ virtual ~Error ( ) throw ( );
+
+ inline string getFunction ( ) const { return mFunction; }
+
+ inline error_t getErrno ( ) const { return mErrorId; }
+
+ inline string getMessage ( ) const { return what(); }
+
+ void display ( ) const;
+
+private:
+
+ error_t mErrorId;
+ string mFunction;
+
+};
+
+
+#endif // ERROR_H
diff --git a/cesar/maximus/utils/inc/ErrorTest.h b/cesar/maximus/utils/inc/ErrorTest.h
new file mode 100644
index 0000000000..048cbd3ed2
--- /dev/null
+++ b/cesar/maximus/utils/inc/ErrorTest.h
@@ -0,0 +1,34 @@
+
+#ifndef ERRORTEST_H
+#define ERRORTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class Error;
+
+
+class ErrorTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (ErrorTest);
+ CPPUNIT_TEST (simpleTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void simpleTest (void);
+
+private:
+
+ Error * mpError;
+
+};
+
+
+#endif // ERRORTEST_H
diff --git a/cesar/maximus/utils/inc/Logger.h b/cesar/maximus/utils/inc/Logger.h
new file mode 100644
index 0000000000..414c918640
--- /dev/null
+++ b/cesar/maximus/utils/inc/Logger.h
@@ -0,0 +1,104 @@
+
+#ifndef LOGGER_H
+#define LOGGER_H
+
+#include "networkclock_types.h" // for 'Network_Clock_Tick'
+
+#include <fstream> // for 'std::ostream' and 'std::ofstream'
+
+// Constants defining the six different importance levels of the log messages
+#define LOG_DEBUG 0
+#define LOG_INFO 1
+#define LOG_COM 2
+#define LOG_WARNING 3
+#define LOG_ERROR 4
+#define LOG_FATAL 5
+#define LOG_NONE 6
+
+#define logFunction() clog << logger(LOG_DEBUG) << __PRETTY_FUNCTION__ << endl
+#define logTest() clog << endl << "---" << endl << __PRETTY_FUNCTION__ << endl
+
+
+class Logger
+{
+
+ public:
+
+ // Constructors:
+
+ /**
+ * Empty Constructor
+ * Logs to cout, log level LOG_DEBUG
+ */
+ Logger ( );
+
+ /**
+ * Constructor
+ * Logs to cout, log level specified
+ */
+ Logger ( int log_level );
+
+ /**
+ * Constructor
+ * Logs to a specified stream, log level specified
+ */
+ Logger ( std::ofstream & log_file, int log_level );
+
+ /**
+ * Empty Destructor
+ */
+ virtual ~Logger ( );
+
+ /**
+ * Operator to set the level of a message
+ */
+ Logger & operator() ( int msg_level );
+
+ /**
+ * Operator to pass the message to the stream
+ */
+ friend std::ostream & operator<< ( std::ostream & os, const Logger & logger );
+
+ /**
+ * Function to set the stream
+ */
+ void setLogFile ( std::ofstream & log_file );
+
+ /**
+ * Functions to get and set the log level
+ */
+ int getLogLevel ( ) const;
+ void setLogLevel ( int log_level );
+
+ /**
+ * Functions to get and set the msg level
+ */
+ int getMsgLevel ( ) const;
+ void setMsgLevel ( int msg_level );
+
+ /**
+ * @return Network_Clock_Tick
+ */
+ Network_Clock_Tick getCurrentTickValue ( ) const;
+
+ /**
+ * @return bool
+ * @param current_tick_value
+ */
+ bool updateTickValue ( const Network_Clock_Tick current_tick_value );
+
+private:
+
+ // Current log level
+ int mLogLevel;
+ // Level of message (as set by operator)
+ int mMsgLevel;
+
+ Network_Clock_Tick mCurrentTickValue;
+
+};
+
+
+extern Logger logger;
+
+#endif // LOGGER_H
diff --git a/cesar/maximus/utils/inc/LoggerTest.h b/cesar/maximus/utils/inc/LoggerTest.h
new file mode 100644
index 0000000000..13353a9259
--- /dev/null
+++ b/cesar/maximus/utils/inc/LoggerTest.h
@@ -0,0 +1,34 @@
+
+#ifndef LOGGERTEST_H
+#define LOGGERTEST_H
+
+#include <cppunit/TestFixture.h>
+#include <cppunit/extensions/HelperMacros.h>
+
+class Logger;
+
+
+class LoggerTest : public CPPUNIT_NS::TestFixture
+{
+
+ CPPUNIT_TEST_SUITE (LoggerTest);
+ CPPUNIT_TEST (simpleTest);
+ CPPUNIT_TEST_SUITE_END ();
+
+public:
+
+ void setUp (void);
+ void tearDown (void);
+
+protected:
+
+ void simpleTest (void);
+
+private:
+
+ Logger * mpLogger;
+
+};
+
+
+#endif // LOGGERTEST_H