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)
#ifndef _MESSAGE_STORE_H_
#define _MESSAGE_STORE_H_
+#include <pthread.h>
+
/** Permanent storage for messages and their states.
*/
/** Destructor.
*/
- ~ID();
+ ~ID() {};
/** Assignment operator.
*/
/** Comparison operator
*/
- int operator==();
+ int operator==(const ID& second);
/** Get size needed for storage (from Storable).
*/
/** 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;
};
};
--- /dev/null
+#include <pthread.h>
+#include <sys/time.h>
+#include <sstream>
+
+#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();
+}
+
#define _PROPERTIES_H_
#include <map>
+#include <string>
class Properties {
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<string,string>::iterator iterator;
+ typedef std::map<std::string,std::string>::iterator iterator;
iterator begin()
{ return properties.begin(); }
private:
- std::map<string,string> properties;
+ std::map<std::string,std::string> properties;
};
#endif