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/ThreadLibrary.hpp>
26 
27 namespace RCF {
28 
29  class RCF_EXPORT AmiNotification
30  {
31  public:
32 
33  typedef boost::function0<void> Cb;
34 
35  // Need mutexPtr so that the mutex doesn't die before the lock.
36  void set(Cb cb, LockPtr lockPtr, MutexPtr mutexPtr);
37  void run();
38  void clear();
39 
40  private:
41  Cb mCb;
42  MutexPtr mMutexPtr;
43  LockPtr mLockPtr;
44  };
45 
46 
47  class OverlappedAmi;
48  typedef boost::shared_ptr<OverlappedAmi> OverlappedAmiPtr;
49 
50  class ConnectionOrientedClientTransport;
51 
52  class OverlappedAmi :
53  public boost::enable_shared_from_this<OverlappedAmi>
54  {
55  public:
56 
57  enum AsyncOpType
58  {
59  None,
60  Wait,
61  Connect,
62  Write,
63  Read
64  };
65 
66  OverlappedAmi(ConnectionOrientedClientTransport *pTcpClientTransport) :
67  mpTransport(pTcpClientTransport),
68  mIndex(0),
69  mOpType(None)
70  {
71  }
72 
73  ~OverlappedAmi()
74  {
75  }
76 
77  void onCompletion(
78  std::size_t index,
79  const AsioErrorCode & ec,
80  std::size_t bytesTransferred);
81 
82  void onTimerExpired(
83  std::size_t index,
84  const AsioErrorCode & ec);
85 
86  RecursiveMutex mMutex;
87  ConnectionOrientedClientTransport * mpTransport;
88  std::size_t mIndex;
89  AsyncOpType mOpType;
90  };
91 
92 
93 } // namespace RCF
94 
95 #endif // ! INCLUDE_RCF_OVERLAPPEDAMI_HPP