diff options
author | Henri Herscher <henri@oreka.org> | 2005-12-14 16:38:53 +0000 |
---|---|---|
committer | Henri Herscher <henri@oreka.org> | 2005-12-14 16:38:53 +0000 |
commit | 3cdcd8d2e5bb825d774b461c650cf4af966e06a9 (patch) | |
tree | db180f6abebc55898b996c409ed0c4c7d18e07a8 /orkbasecxx/Utils.h | |
parent | 7e49c9f57ce23cefe98f0655c502277e12e2a8b8 (diff) |
Added tracking ID to RTP sessions
git-svn-id: https://oreka.svn.sourceforge.net/svnroot/oreka/trunk@108 09dcff7a-b715-0410-9601-b79a96267cd0
Diffstat (limited to 'orkbasecxx/Utils.h')
-rw-r--r-- | orkbasecxx/Utils.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/orkbasecxx/Utils.h b/orkbasecxx/Utils.h index b50872a..dcd22f2 100644 --- a/orkbasecxx/Utils.h +++ b/orkbasecxx/Utils.h @@ -19,6 +19,8 @@ // error C2039: 'TryEnterCriticalSection' : is not a member of '`global namespace'' // If seeing this error somewhere, the remedy is to #include "Utils.h" first #include "ace/Thread_Mutex.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_time.h" #include "StdString.h" #include "OrkBase.h" @@ -93,5 +95,47 @@ inline CStdString StripFileExtension(CStdString& filename) typedef ACE_Guard<ACE_Thread_Mutex> MutexSentinel; +/** A counter that generates a "counting" 3 character strings, i.e. aaa, aab, ..., zzz + that represents a number between 0 and 26^3-1 (wrapping counter) + and starts at a random location in this range. + useful for generating debugging IDs +*/ +class AlphaCounter +{ +public: + inline AlphaCounter::AlphaCounter() + { + // Generate pseudo-random number from high resolution time least significant two bytes + ACE_hrtime_t hrtime = ACE_OS::gethrtime(); + unsigned short srandom = (short)hrtime; + double drandom = (double)srandom/65536.0; // 0 <= random < 1 + + m_counter = (unsigned int)(drandom*(26*26*26)); + } + + inline CStdString AlphaCounter::GetNext() + { + m_counter++; + if(m_counter >= (26*26*26) ) + { + m_counter = 0; + } + unsigned int char1val = m_counter/(26*26); + unsigned int remains = m_counter%(26*26); + unsigned int char2val = remains/26; + unsigned int char3val = remains%26; + + char1val += 65; + char2val += 65; + char3val += 65; + + CStdString string; + string.Format("%c%c%c", char1val, char2val, char3val); + return string; + } +private: + unsigned int m_counter; +}; + #endif |