1 /* $Id: session.hpp,v 1.10 2005-10-25 21:32:01 adam Exp $
2 Copyright (c) 2005, Index Data.
10 //#include <stdexcept>
12 #include <boost/thread/mutex.hpp>
18 //typedef unsigned long type;
21 /// create new session with new unique id
23 boost::mutex::scoped_lock scoped_lock(m_mutex);
29 /// copy session including old id
30 Session(const Session &s) : m_id(s.m_id), m_close(s.m_close) {};
32 Session& operator=(const Session &s) {
41 bool operator<(const Session &s) const {
42 return m_id < s.m_id ? true : false;
45 unsigned long id() const {
49 bool is_closed() const {
53 /// mark session closed, can not be unset
58 bool operator == (Session &ses) const {
59 return ses.m_id == m_id;
63 unsigned long int m_id;
66 /// static mutex to lock static m_id
67 static boost::mutex m_mutex;
69 /// static m_id to make sure that there is only one id counter
70 static unsigned long int m_global_id;
74 template <class T> class session_map {
76 void create(T &t, const yp2::Session &s) {
77 boost::mutex::scoped_lock lock(m_mutex);
80 void release(const yp2::Session &s) {
81 boost::mutex::scoped_lock lock(m_mutex);
85 bool active(const yp2::Session &s) {
86 typename std::map<yp2::Session,T>::const_iterator it;
88 return it == m_map.end() ? false : true;
92 std::map<yp2::Session,T>m_map;
101 * indent-tabs-mode: nil
102 * c-file-style: "stroustrup"
104 * vim: shiftwidth=4 tabstop=8 expandtab