RCFProto
 All Classes Functions Typedefs
CurrentSession.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2013, Delta V Software. All rights reserved.
6 // http://www.deltavsoft.com
7 //
8 // RCF is distributed under dual licenses - closed source or GPL.
9 // Consult your particular license for conditions of use.
10 //
11 // If you have not purchased a commercial license, you are using RCF
12 // under GPL terms.
13 //
14 // Version: 2.0
15 // Contact: support <at> deltavsoft.com
16 //
17 //******************************************************************************
18 
19 #ifndef INCLUDE_RCF_CURRENTSESSION_HPP
20 #define INCLUDE_RCF_CURRENTSESSION_HPP
21 
22 #include <boost/shared_ptr.hpp>
23 
24 #include <RCF/RcfSession.hpp>
25 #include <RCF/ThreadLibrary.hpp>
26 #include <RCF/ThreadLocalData.hpp>
27 
28 namespace RCF {
29 
30 
31 
32  class CurrentRcfSessionSentry
33  {
34  public:
35  CurrentRcfSessionSentry(RcfSession & session)
36  {
37  RcfSession * pPrev = getTlsRcfSessionPtr();
38  getRcfSessionSentryStack().push_back(pPrev);
39 
40  setTlsRcfSessionPtr(& session);
41  }
42 
43  CurrentRcfSessionSentry(RcfSessionPtr sessionPtr)
44  {
45  RcfSession * pPrev = getTlsRcfSessionPtr();
46  getRcfSessionSentryStack().push_back(pPrev);
47 
48  RcfSession * pSession = sessionPtr.get();
49  setTlsRcfSessionPtr(pSession);
50  }
51 
52  ~CurrentRcfSessionSentry()
53  {
54  RcfSession * pPrev = getRcfSessionSentryStack().back();
55  getRcfSessionSentryStack().pop_back();
56  setTlsRcfSessionPtr(pPrev);
57  }
58 
59 
60  };
61 
62 } // namespace RCF
63 
64 #endif // ! INCLUDE_RCF_CURRENTSESSION_HPP