summaryrefslogtreecommitdiffstats
path: root/src/app/system.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/system.h')
-rw-r--r--src/app/system.h90
1 files changed, 60 insertions, 30 deletions
diff --git a/src/app/system.h b/src/app/system.h
index e216842..278a4bf 100644
--- a/src/app/system.h
+++ b/src/app/system.h
@@ -22,12 +22,10 @@
#pragma once
+#include "common/singleton.h"
#include <string>
-
-/* Dialog utils */
-
/**
* \enum SystemDialogType
* \brief Type of system dialog
@@ -60,12 +58,10 @@ enum SystemDialogResult
SDR_NO
};
-//! Displays a system dialog
-SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message);
-
-
-/* Time utils */
-
+/**
+ * \enum SystemTimeUnit
+ * \brief Time unit
+ */
enum SystemTimeUnit
{
//! seconds
@@ -76,33 +72,67 @@ enum SystemTimeUnit
STU_USEC
};
-/* Forward declaration of time stamp struct
- * SystemTimeStamp should be used in a pointer context.
- * The implementation details are hidden because of platform dependence. */
+/*
+ * Forward declaration of time stamp struct
+ * SystemTimeStamp should only be used in a pointer context.
+ * The implementation details are hidden because of platform dependence.
+ */
struct SystemTimeStamp;
-//! Creates a new time stamp object
-SystemTimeStamp* CreateTimeStamp();
+/**
+ * \class CSystemUtils
+ * \brief Platform-specific utils
+ *
+ * This class provides system-specific utilities like displaying user dialogs and
+ * querying system timers for exact timestamps.
+ */
+class CSystemUtils : public CSingleton<CSystemUtils>
+{
+protected:
+ CSystemUtils();
+
+public:
+ //! Creates system utils for specific platform
+ static CSystemUtils* Create();
+
+ //! Performs platform-specific initialization
+ virtual void Init() = 0;
+
+ //! Displays a system dialog
+ virtual SystemDialogResult SystemDialog(SystemDialogType, const std::string &title, const std::string &message) = 0;
-//! Destroys a time stamp object
-void DestroyTimeStamp(SystemTimeStamp *stamp);
+ //! Displays a fallback system dialog using console
+ TEST_VIRTUAL SystemDialogResult ConsoleSystemDialog(SystemDialogType type, const std::string& title, const std::string& message);
-//! Copies the time stamp from \a src to \a dst
-void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src);
+ //! Creates a new time stamp object
+ TEST_VIRTUAL SystemTimeStamp* CreateTimeStamp();
-//! Returns a time stamp associated with current time
-void GetCurrentTimeStamp(SystemTimeStamp *stamp);
+ //! Destroys a time stamp object
+ TEST_VIRTUAL void DestroyTimeStamp(SystemTimeStamp *stamp);
-//! Returns the platform's expected time stamp resolution
-float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC);
+ //! Copies the time stamp from \a src to \a dst
+ TEST_VIRTUAL void CopyTimeStamp(SystemTimeStamp *dst, SystemTimeStamp *src);
-//! Returns the platform's exact (in nanosecond units) expected time stamp resolution
-long long GetTimeStampExactResolution();
+ //! Returns a time stamp associated with current time
+ virtual void GetCurrentTimeStamp(SystemTimeStamp *stamp) = 0;
-//! Returns a difference between two timestamps in given time unit
-/** The difference is \a after - \a before. */
-float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC);
+ //! Returns the platform's expected time stamp resolution
+ TEST_VIRTUAL float GetTimeStampResolution(SystemTimeUnit unit = STU_SEC);
-//! Returns the exact (in nanosecond units) difference between two timestamps
-/** The difference is \a after - \a before. */
-long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after);
+ //! Returns the platform's exact (in nanosecond units) expected time stamp resolution
+ virtual long long GetTimeStampExactResolution() = 0;
+
+ //! Returns a difference between two timestamps in given time unit
+ /** The difference is \a after - \a before. */
+ TEST_VIRTUAL float TimeStampDiff(SystemTimeStamp *before, SystemTimeStamp *after, SystemTimeUnit unit = STU_SEC);
+
+ //! Returns the exact (in nanosecond units) difference between two timestamps
+ /** The difference is \a after - \a before. */
+ virtual long long TimeStampExactDiff(SystemTimeStamp *before, SystemTimeStamp *after) = 0;
+};
+
+//! Global function to get CSystemUtils instance
+inline CSystemUtils* GetSystemUtils()
+{
+ return CSystemUtils::GetInstancePointer();
+}