add some more methods... :-D

JSON-143
Roker 2020-05-14 16:21:38 +02:00
parent e03a99763a
commit 86f591ea01
2 changed files with 19 additions and 1 deletions

View File

@ -36,3 +36,16 @@ void SessionRegistry::remove(std::thread::id tid)
m.erase(q);
}
}
std::string SessionRegistry::to_string() const
{
Lock L(_mtx);
std::stringstream ss;
ss << m.size() << " session" << (m.size()==1?"":"s") << " in registry" << (m.empty()?".\n":":\n");
for(const auto& e:m)
{
ss << "\t" << e.first << ": " << e.second << "\n";
}
return ss.str();
}

View File

@ -18,6 +18,11 @@ public:
PEP_SESSION get(std::thread::id tid = std::this_thread::get_id());
void remove(std::thread::id tid = std::this_thread::get_id());
std::size_t size() const { return m.size(); }
bool empty() const { return m.empty(); }
std::string to_string() const;
private:
std::map<std::thread::id, PEP_SESSION> m;
messageToSend_t mts;
@ -25,7 +30,7 @@ private:
typedef std::recursive_mutex Mutex;
typedef std::unique_lock<Mutex> Lock;
Mutex _mtx;
mutable Mutex _mtx;
};
#endif // JSON_ADAPTER_SESSION_REGISTRY_HH