From: Jiří Filipovič Date: Fri, 19 Oct 2007 12:17:01 +0000 (+0000) Subject: Generating unique ID for messages. X-Git-Tag: org-gridsite-core_R_1_5_3~14 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=17bb631d5303c1fb1e7255e02bfea5c3eaf3eb51;p=jra1mw.git Generating unique ID for messages. --- diff --git a/org.glite.lb.logger/src-nt/Message.H b/org.glite.lb.logger/src-nt/Message.H index 37492bf..725966a 100644 --- a/org.glite.lb.logger/src-nt/Message.H +++ b/org.glite.lb.logger/src-nt/Message.H @@ -43,7 +43,7 @@ public: int getContentLength() const { return m_length; } - std::string getProperty(const std::string &name, std::string &val) const + std::string getProperty(const std::string &name, std::string &val) { return m_properties.getProperty(name); } void setProperty(const std::string &name, std::string &val) diff --git a/org.glite.lb.logger/src-nt/MessageStore.H b/org.glite.lb.logger/src-nt/MessageStore.H index 86c747f..ff03a9b 100644 --- a/org.glite.lb.logger/src-nt/MessageStore.H +++ b/org.glite.lb.logger/src-nt/MessageStore.H @@ -1,6 +1,8 @@ #ifndef _MESSAGE_STORE_H_ #define _MESSAGE_STORE_H_ +#include + /** Permanent storage for messages and their states. */ @@ -43,7 +45,7 @@ public: /** Destructor. */ - ~ID(); + ~ID() {}; /** Assignment operator. */ @@ -55,7 +57,7 @@ public: /** Comparison operator */ - int operator==(); + int operator==(const ID& second); /** Get size needed for storage (from Storable). */ @@ -63,13 +65,19 @@ public: /** Save ID (from Storable) */ - virtual int save(void* &data, int len) const; + virtual int save(void* data, int len) const; /** Load ID (from Storable) */ virtual int load(void* data, int len); + protected: + unsigned long long getID() {return id;} + private: + static pthread_mutex_t counterLock; + static unsigned counter; + unsigned long long id; }; }; diff --git a/org.glite.lb.logger/src-nt/MessageStore.cpp b/org.glite.lb.logger/src-nt/MessageStore.cpp new file mode 100644 index 0000000..eb9de7a --- /dev/null +++ b/org.glite.lb.logger/src-nt/MessageStore.cpp @@ -0,0 +1,24 @@ +#include +#include +#include + +#include "MessageStore.H" + +pthread_mutex_t MessageStore::ID::counterLock = PTHREAD_MUTEX_INITIALIZER; +unsigned MessageStore::ID::counter = 0; + +MessageStore::ID::ID(){ + time_t t; + time(&t); + pthread_mutex_lock(&counterLock); + counter++; + id = ((unsigned long long) counter << 32) + t; + pthread_mutex_unlock(&counterLock); +} + +std::string MessageStore::ID::toString() const{ + std::ostringstream oss; + oss << id; + return oss.str(); +} + diff --git a/org.glite.lb.logger/src-nt/Properties.H b/org.glite.lb.logger/src-nt/Properties.H index a3a18eb..77d216d 100644 --- a/org.glite.lb.logger/src-nt/Properties.H +++ b/org.glite.lb.logger/src-nt/Properties.H @@ -2,6 +2,7 @@ #define _PROPERTIES_H_ #include +#include class Properties { public: @@ -12,14 +13,14 @@ public: {} // accessors - string& getProperty(string &key) + std::string& getProperty(const std::string &key) { return properties[key]; } - void setProperty(string &key, string &val) + void setProperty(const std::string &key, std::string &val) { properties[key] = val; } // iterators - typedef std::map::iterator iterator; + typedef std::map::iterator iterator; iterator begin() { return properties.begin(); } @@ -29,7 +30,7 @@ public: private: - std::map properties; + std::map properties; }; #endif