/*\r
* Copyright 2001-2007 Internet2\r
- * \r
+ *\r
* Licensed under the Apache License, Version 2.0 (the "License");\r
* you may not use this file except in compliance with the License.\r
* You may obtain a copy of the License at\r
\r
/**\r
* MemoryStorageService.cpp\r
- * \r
+ *\r
* In-memory "persistent" storage, suitable for simple applications.\r
*/\r
\r
public:\r
MemoryStorageService(const DOMElement* e);\r
virtual ~MemoryStorageService();\r
- \r
+\r
bool createString(const char* context, const char* key, const char* value, time_t expiration);\r
int readString(const char* context, const char* key, string* pvalue=NULL, time_t* pexpiration=NULL, int version=0);\r
int updateString(const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0);\r
bool deleteString(const char* context, const char* key);\r
- \r
+\r
bool createText(const char* context, const char* key, const char* value, time_t expiration) {\r
return createString(context, key, value, expiration);\r
}\r
bool deleteText(const char* context, const char* key) {\r
return deleteString(context, key);\r
}\r
- \r
+\r
void reap(const char* context);\r
void updateContext(const char* context, time_t expiration);\r
void deleteContext(const char* context) {\r
\r
private:\r
void cleanup();\r
- \r
+\r
struct XMLTOOL_DLLLOCAL Record {\r
Record() : expiration(0), version(1) {}\r
Record(const string& s, time_t t) : data(s), expiration(t), version(1) {}\r
time_t expiration;\r
int version;\r
};\r
- \r
+\r
struct XMLTOOL_DLLLOCAL Context {\r
Context() {}\r
Context(const Context& src) {\r
shutdown_wait->signal();\r
cleanup_thread->join(NULL);\r
\r
+ delete cleanup_thread;\r
delete shutdown_wait;\r
delete m_lock;\r
}\r
MemoryStorageService* cache = reinterpret_cast<MemoryStorageService*>(cache_p);\r
\r
#ifndef WIN32\r
- // First, let's block all signals \r
+ // First, let's block all signals\r
Thread::mask_all_signals();\r
#endif\r
\r
shutdown_wait->timedwait(mutex.get(), m_cleanupInterval);\r
if (shutdown)\r
break;\r
- \r
+\r
unsigned long count=0;\r
time_t now = time(NULL);\r
m_lock->wrlock();\r
SharedLock locker(m_lock, false);\r
for (map<string,Context>::iterator i=m_contextMap.begin(); i!=m_contextMap.end(); ++i)\r
count += i->second.reap(now);\r
- \r
+\r
if (count)\r
m_log.info("purged %d expired record(s) from storage", count);\r
}\r
// It's dead, so we can just remove it now and create the new record.\r
ctx.m_dataMap.erase(i);\r
}\r
- \r
+\r
ctx.m_dataMap[key]=Record(value,expiration);\r
- \r
+\r
m_log.debug("inserted record (%s) in context (%s)", key, context);\r
return true;\r
}\r
return 0;\r
else if (time(NULL) >= i->second.expiration)\r
return 0;\r
- \r
+\r
if (version > 0 && version != i->second.version)\r
return -1; // caller's out of sync\r
\r
i->second.data = value;\r
++(i->second.version);\r
}\r
- \r
+\r
if (expiration && expiration != i->second.expiration)\r
i->second.expiration = expiration;\r
\r
{\r
Context& ctx = writeContext(context);\r
SharedLock locker(m_lock, false);\r
- \r
+\r
// Find the record.\r
map<string,Record>::iterator i=ctx.m_dataMap.find(key);\r
if (i!=ctx.m_dataMap.end()) {\r