RCFProto
 All Classes Functions Typedefs
OverlappedAmi.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_OVERLAPPEDAMI_HPP
20 #define INCLUDE_RCF_OVERLAPPEDAMI_HPP
21 
22 #include <boost/function.hpp>
23 #include <boost/shared_ptr.hpp>
24 
25 #include <RCF/Asio.hpp>
26 #include <RCF/Enums.hpp>
27 #include <RCF/ThreadLibrary.hpp>
28 
29 namespace RCF {
30 
31  class RCF_EXPORT AmiNotification
32  {
33  public:
34 
35  typedef boost::function0<void> Cb;
36 
37  // Need mutexPtr so that the mutex doesn't die before the lock.
38  void set(Cb cb, LockPtr lockPtr, MutexPtr mutexPtr);
39  void run();
40  void clear();
41 
42  private:
43  Cb mCb;
44  MutexPtr mMutexPtr;
45  LockPtr mLockPtr;
46  };
47 
48 
49  class OverlappedAmi;
50  typedef boost::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
51 
52  class ConnectedClientTransport;
53 
54  class OverlappedAmi :
55  public boost::enable_shared_from_this<OverlappedAmi>
56  {
57  public:
58 
59  OverlappedAmi(ConnectedClientTransport *pTcpClientTransport) :
60  mpTransport(pTcpClientTransport),
61  mIndex(0),
62  mOpType(None)
63  {
64  }
65 
66  ~OverlappedAmi()
67  {
68  }
69 
70  void onCompletion(
71  std::size_t index,
72  const AsioErrorCode & ec,
73  std::size_t bytesTransferred);
74 
75  void onTimerExpired(
76  std::size_t index,
77  const AsioErrorCode & ec);
78 
79  void ensureLifetime(const ByteBuffer & byteBuffer);
80  void ensureLifetime(const std::vector<ByteBuffer> & byteBuffers);
81 
82  // TODO: should make these private.
83 
84  RecursiveMutex mMutex;
85  ConnectedClientTransport * mpTransport;
86  std::size_t mIndex;
87  AsyncOpType mOpType;
88 
89  private:
90 
91  // This is the underlying memory for the asio buffers. This memory has to
92  // be held on to, until the async op completes.
93  std::vector<ByteBuffer> mByteBuffers;
94  };
95 
96 } // namespace RCF
97 
98 #endif // ! INCLUDE_RCF_OVERLAPPEDAMI_HPP