Remote Call Framework 3.0
OverlappedAmi.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2018, 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: 3.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 <functional>
23 #include <memory>
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 std::function<void()> Cb;
36 
37  // Need mutexPtr so that the mutex doesn't get destroyed 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 std::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
51 
52  class ConnectedClientTransport;
53 
54  class OverlappedAmi :
55  public std::enable_shared_from_this<OverlappedAmi>
56  {
57  public:
58 
59  OverlappedAmi(ConnectedClientTransport *pTcpClientTransport);
60 
61  ~OverlappedAmi();
62 
63  void onCompletion(
64  std::size_t index,
65  const AsioErrorCode & ec,
66  std::size_t bytesTransferred);
67 
68  void onTimerExpired(
69  std::size_t index,
70  const AsioErrorCode & ec);
71 
72  void ensureLifetime(const ByteBuffer & byteBuffer);
73  void ensureLifetime(const std::vector<ByteBuffer> & byteBuffers);
74 
75  // TODO: should make these private.
76 
77  RecursiveMutex mMutex;
78  ConnectedClientTransport * mpTransport;
79  std::size_t mIndex;
80  AsyncOpType mOpType;
81 
82  private:
83 
84  // This is the underlying memory for the asio buffers. This memory has to
85  // be held on to, until the async op completes.
86  std::vector<ByteBuffer> mByteBuffers;
87  };
88 
89 } // namespace RCF
90 
91 #endif // ! INCLUDE_RCF_OVERLAPPEDAMI_HPP
Definition: AmiIoHandler.hpp:24