Remote Call Framework 3.3
OverlappedAmi.hpp
1 
2 //******************************************************************************
3 // RCF - Remote Call Framework
4 //
5 // Copyright (c) 2005 - 2022, Delta V Software. All rights reserved.
6 // https://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 under GPL terms.
12 //
13 // Version: 3.3
14 // Contact: support <at> deltavsoft.com
15 //
16 //******************************************************************************
17 
18 #ifndef INCLUDE_RCF_OVERLAPPEDAMI_HPP
19 #define INCLUDE_RCF_OVERLAPPEDAMI_HPP
20 
21 #include <functional>
22 #include <memory>
23 
24 #include <RCF/Asio.hpp>
25 #include <RCF/Enums.hpp>
26 #include <RCF/ThreadLibrary.hpp>
27 
28 namespace RCF {
29 
30  class RCF_EXPORT AmiNotification
31  {
32  public:
33 
34  typedef std::function<void()> Cb;
35 
36  // Need mutexPtr so that the mutex doesn't get destroyed before the lock.
37  void set(Cb cb, LockPtr lockPtr, MutexPtr mutexPtr);
38  void run();
39  void clear();
40 
41  private:
42  Cb mCb;
43  MutexPtr mMutexPtr;
44  LockPtr mLockPtr;
45  };
46 
47 
48  class OverlappedAmi;
49  typedef std::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
50 
51  class ConnectedClientTransport;
52 
53  class OverlappedAmi :
54  public std::enable_shared_from_this<OverlappedAmi>
55  {
56  public:
57 
58  OverlappedAmi(ConnectedClientTransport *pTcpClientTransport);
59 
60  ~OverlappedAmi();
61 
62  void onCompletion(
63  std::size_t index,
64  const AsioErrorCode & ec,
65  std::size_t bytesTransferred);
66 
67  void onTimerExpired(
68  std::size_t index,
69  const AsioErrorCode & ec);
70 
71  void ensureLifetime(const ByteBuffer & byteBuffer);
72  void ensureLifetime(const std::vector<ByteBuffer> & byteBuffers);
73 
74  // TODO: should make these private.
75 
76  RecursiveMutex mMutex;
77  ConnectedClientTransport * mpTransport;
78  std::size_t mIndex;
79  AsyncOpType mOpType;
80 
81  private:
82 
83  // This is the underlying memory for the asio buffers. This memory has to
84  // be held on to, until the async op completes.
85  std::vector<ByteBuffer> mByteBuffers;
86  };
87 
88 } // namespace RCF
89 
90 #endif // ! INCLUDE_RCF_OVERLAPPEDAMI_HPP
Definition: AmiIoHandler.hpp:23