session mutex and id counter made static, now many instances of a Session object...
[metaproxy-moved-to-github.git] / src / session.hpp
1
2 #ifndef SESSION_HPP
3 #define SESSION_HPP
4
5 //#include <stdexcept>
6
7 #include <boost/thread/mutex.hpp>
8
9 namespace yp2 {
10
11   class Session 
12     {
13     public:
14       //Session() {};
15
16       /// returns next id, global state of id protected by boost::mutex
17       long unsigned int id() {
18           boost::mutex::scoped_lock scoped_lock(m_mutex);
19           ++m_id;
20         return m_id;
21       };
22     private:
23       // disabled because class is singleton
24       // Session(const Session &);
25
26       // disabled because class is singleton
27       // Session& operator=(const Session &);
28
29       /// static mutex to lock static m_id
30       static boost::mutex m_mutex;
31
32       /// static m_id to make sure that there is only one id counter
33       static unsigned long int m_id;
34       
35     };
36   
37 }
38
39 // initializing static members
40 boost::mutex yp2::Session::m_mutex;
41 unsigned long int yp2::Session::m_id = 0;
42
43
44 #endif
45 /*
46  * Local variables:
47  * c-basic-offset: 4
48  * indent-tabs-mode: nil
49  * End:
50  * vim: shiftwidth=4 tabstop=8 expandtab
51  */