From d0f75ccda1f4cddb7c629e807fb2cf2c137a9b4f Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Sat, 25 May 2013 09:04:16 -0700 Subject: [PATCH] Add UptimeTimer class --- .../events/ripple_UptimeTimer.cpp | 66 +++++++++++++++++++ .../ripple_basics/events/ripple_UptimeTimer.h | 44 +++++++++++++ modules/ripple_basics/ripple_basics.cpp | 6 +- modules/ripple_basics/ripple_basics.h | 4 ++ newcoin.vcxproj | 7 ++ newcoin.vcxproj.filters | 9 +++ 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 modules/ripple_basics/events/ripple_UptimeTimer.cpp create mode 100644 modules/ripple_basics/events/ripple_UptimeTimer.h diff --git a/modules/ripple_basics/events/ripple_UptimeTimer.cpp b/modules/ripple_basics/events/ripple_UptimeTimer.cpp new file mode 100644 index 0000000000..22200efd4a --- /dev/null +++ b/modules/ripple_basics/events/ripple_UptimeTimer.cpp @@ -0,0 +1,66 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +UptimeTimer::UptimeTimer () + : m_shadowPointer (0) + , m_startTime (::time (0)) +{ +} + +UptimeTimer::~UptimeTimer () +{ +} + +void UptimeTimer::initializeShadowPointerIfNecessary (int* shadowPointer) +{ + if (m_shadowPointer == 0) + { + m_shadowPointer = static_cast (shadowPointer); + } + +} + +void UptimeTimer::resetShadowPointerIfSet (int* shadowPointer) +{ + if (m_shadowPointer == shadowPointer) + { + m_shadowPointer = 0; + } +} + +int UptimeTimer::getElapsedSeconds () +{ + int result; + + if (m_shadowPointer != 0) + { + result = *m_shadowPointer; + } + else + { + result = static_cast (::time (0) - m_startTime); + } + + return result; +} + +UptimeTimer& UptimeTimer::getInstance () +{ + static UptimeTimer instance; + return instance; +} diff --git a/modules/ripple_basics/events/ripple_UptimeTimer.h b/modules/ripple_basics/events/ripple_UptimeTimer.h new file mode 100644 index 0000000000..6eb59382df --- /dev/null +++ b/modules/ripple_basics/events/ripple_UptimeTimer.h @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +/* + Copyright (c) 2011-2013, OpenCoin, Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef RIPPLE_UPTIMETIMER_H +#define RIPPLE_UPTIMETIMER_H + +/** Singleton for tracking uptime. +*/ +class UptimeTimer +{ +private: + UptimeTimer (); + ~UptimeTimer (); + +public: + void initializeShadowPointerIfNecessary (int* shadowPointer); + + void resetShadowPointerIfSet (int* shadowPointer); + + int getElapsedSeconds (); + + static UptimeTimer& getInstance (); + +private: + time_t m_startTime; + int volatile* m_shadowPointer; +}; + +#endif diff --git a/modules/ripple_basics/ripple_basics.cpp b/modules/ripple_basics/ripple_basics.cpp index 6a2d8445ae..e6aaf9c349 100644 --- a/modules/ripple_basics/ripple_basics.cpp +++ b/modules/ripple_basics/ripple_basics.cpp @@ -27,10 +27,12 @@ // VFALCO: TODO, fix these warnings! #ifdef _MSC_VER //#pragma warning (push) // Causes spurious C4503 "decorated name exceeds maximum length" -#pragma warning (disable: 4018) // signed/unsigned mismatch -#pragma warning (disable: 4244) // conversion, possible loss of data +//#pragma warning (disable: 4018) // signed/unsigned mismatch +//#pragma warning (disable: 4244) // conversion, possible loss of data #endif +#include "events/ripple_UptimeTimer.cpp" + #ifdef _MSC_VER //#pragma warning (pop) #endif diff --git a/modules/ripple_basics/ripple_basics.h b/modules/ripple_basics/ripple_basics.h index 7525a8cbe7..3713ed0d9f 100644 --- a/modules/ripple_basics/ripple_basics.h +++ b/modules/ripple_basics/ripple_basics.h @@ -32,6 +32,10 @@ #ifndef RIPPLE_BASICS_H #define RIPPLE_BASICS_H +#include + #include "src/cpp/ripple/IntegerTypes.h" +#include "events/ripple_UptimeTimer.h" + #endif diff --git a/newcoin.vcxproj b/newcoin.vcxproj index 72ea344526..bfef258fe4 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -173,6 +173,12 @@ true true + + true + true + true + true + @@ -1163,6 +1169,7 @@ + diff --git a/newcoin.vcxproj.filters b/newcoin.vcxproj.filters index 87e0f5e023..c7db7fa28e 100644 --- a/newcoin.vcxproj.filters +++ b/newcoin.vcxproj.filters @@ -124,6 +124,9 @@ {96cbc9ff-0118-4844-bb4c-05aef58a60b5} + + {f585ac4d-1867-4f3d-b0a2-eceae4d7e7e7} + @@ -738,6 +741,9 @@ 1. Modules\ripple_mess + + 1. Modules\ripple_basics\events + @@ -1379,6 +1385,9 @@ 1. Modules\ripple_basics\containers + + 1. Modules\ripple_basics\events +