RCFProto
 All Classes Functions Typedefs
RemoteCallContext.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_REMOTECALLCONTEXT_HPP
20 #define INCLUDE_RCF_REMOTECALLCONTEXT_HPP
21 
22 #include <RCF/AsioServerTransport.hpp>
23 #include <RCF/Export.hpp>
24 #include <RCF/RcfSession.hpp>
25 #include <RCF/ThreadLocalData.hpp>
26 
27 namespace RCF {
28 
29  class I_Parameters;
30 
31  class RCF_EXPORT RemoteCallContextImpl
32  {
33  public:
34 
35  RemoteCallContextImpl(RCF::RcfSession & session) : mCommitted(false)
36  {
37  mRcfSessionPtr = session.shared_from_this();
38  mRcfSessionPtr->mAutoSend = false;
39 
40  mpParametersUntyped = mRcfSessionPtr->mpParameters;
41 
42  AsioSessionState & sessionState =
43  dynamic_cast<AsioSessionState &>(
44  mRcfSessionPtr->getSessionState());
45 
46  mSessionStatePtr = sessionState.sharedFromThis();
47  }
48 
49  void commit()
50  {
51  RCF_ASSERT(!mCommitted);
52 
53  if (mRcfSessionPtr->mRequest.getOneway())
54  {
55  RCF_LOG_3()(this) << "RcfServer - suppressing response to oneway call.";
56  mRcfSessionPtr->mIn.clearByteBuffer();
57  mRcfSessionPtr->clearParameters();
58  setTlsRcfSessionPtr();
59  mRcfSessionPtr->onWriteCompleted();
60  }
61  else
62  {
63  mRcfSessionPtr->sendResponse();
64  }
65 
66  mpParametersUntyped = NULL;
67  mRcfSessionPtr.reset();
68 
69  mSessionStatePtr.reset();
70 
71  mCommitted = true;
72  }
73 
74  void commit(const std::exception &e)
75  {
76  RCF_ASSERT(!mCommitted);
77 
78  if (mRcfSessionPtr->mRequest.getOneway())
79  {
80  RCF_LOG_3()(this) << "RcfServer - suppressing response to oneway call.";
81  mRcfSessionPtr->mIn.clearByteBuffer();
82  mRcfSessionPtr->clearParameters();
83  setTlsRcfSessionPtr();
84  mRcfSessionPtr->onWriteCompleted();
85  }
86  else
87  {
88  mRcfSessionPtr->sendResponseException(e);
89  }
90 
91  mpParametersUntyped = NULL;
92  mRcfSessionPtr.reset();
93 
94  mSessionStatePtr.reset();
95 
96  mCommitted = true;
97  }
98 
99  bool isCommitted() const
100  {
101  return mCommitted;
102  }
103 
104  private:
105  RcfSessionPtr mRcfSessionPtr;
106  AsioSessionStatePtr mSessionStatePtr;
107  bool mCommitted;
108 
109  protected:
110  I_Parameters * mpParametersUntyped;
111 
112  };
113 
114  template<
115  typename R,
116  typename A1 = Void,
117  typename A2 = Void,
118  typename A3 = Void,
119  typename A4 = Void,
120  typename A5 = Void,
121  typename A6 = Void,
122  typename A7 = Void,
123  typename A8 = Void,
124  typename A9 = Void,
125  typename A10 = Void,
126  typename A11 = Void,
127  typename A12 = Void,
128  typename A13 = Void,
129  typename A14 = Void,
130  typename A15 = Void>
131  class RemoteCallContext : public RemoteCallContextImpl
132  {
133  public:
134 
135  // If return type is void, change it to RCF::Void.
136  typedef typename boost::mpl::if_<
137  boost::is_same<R, void>,
138  Void,
139  R>::type R_;
140 
141  typedef ServerParameters<
142  R_,
143  A1, A2, A3, A4, A5, A6, A7, A8,
144  A9, A10, A11, A12, A13, A14, A15> ParametersT;
145 
146  RemoteCallContext(RCF::RcfSession & session) : RemoteCallContextImpl(session)
147  {
148  RCF_ASSERT( dynamic_cast<ParametersT *>(mpParametersUntyped) );
149  }
150 
151  ParametersT &parameters()
152  {
153  return * static_cast<ParametersT *>(mpParametersUntyped);;
154  }
155  };
156 
157 } // namespace RCF
158 
159 #endif // ! INCLUDE_RCF_REMOTECALLCONTEXT_HPP