Remote Call Framework 3.3
UdpServerTransport.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_UDPSERVERTRANSPORT_HPP
19 #define INCLUDE_RCF_UDPSERVERTRANSPORT_HPP
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <RCF/Export.hpp>
26 #include <RCF/IpAddress.hpp>
27 #include <RCF/Service.hpp>
28 #include <RCF/ServerTransport.hpp>
30 #include <RCF/Tools.hpp>
31 
32 namespace RCF {
33 
34  class UdpServerTransport;
35  class UdpNetworkSession;
36 
37  typedef std::shared_ptr<UdpServerTransport> UdpServerTransportPtr;
38  typedef std::shared_ptr<UdpNetworkSession> UdpNetworkSessionPtr;
39 
40  class ReallocBuffer;
41  typedef std::shared_ptr<ReallocBuffer> ReallocBufferPtr;
42 
43  class RCF_EXPORT UdpNetworkSession : public NetworkSession
44  {
45  public:
46 
47  UdpNetworkSession(UdpServerTransport & transport);
48 
49  int getNativeHandle() const;
50 
51  typedef UdpNetworkSessionPtr NetworkSessionPtr;
52 
53  private:
54 
55  ReallocBufferPtr mReadVecPtr;
56  ReallocBufferPtr mWriteVecPtr;
57  IpAddress mRemoteAddress;
58  UdpServerTransport & mTransport;
59  SessionPtr mRcfSessionPtr;
60 
61  friend class UdpServerTransport;
62 
63  private:
64 
65  // I_NetworkSession
66  const RemoteAddress & getRemoteAddress() const;
67  ServerTransport & getServerTransport();
68  const RemoteAddress & getRemoteAddress();
69 
70  void setTransportFilters(
71  const std::vector<FilterPtr> &filters);
72 
73  void getTransportFilters(
74  std::vector<FilterPtr> &filters);
75 
76  ByteBuffer getReadByteBuffer();
77  void postRead();
78 
79  void postWrite(
80  std::vector<ByteBuffer> &byteBuffers);
81 
82  void postClose();
83 
84  bool isConnected();
85  };
86 
87  class RCF_EXPORT UdpServerTransport :
88  public ServerTransport,
89  public IpServerTransport,
90  public I_Service,
91  Noncopyable
92  {
93  private:
94 
95  typedef UdpNetworkSession NetworkSession;
96  typedef UdpNetworkSessionPtr NetworkSessionPtr;
97 
98  public:
99 
100  UdpServerTransport(
101  const IpAddress & ipAddress,
102  const IpAddress & multicastIpAddress = IpAddress());
103 
104  TransportType getTransportType();
105 
107  clone();
108 
109  RcfServer &
110  getSessionManager();
111 
112  void setSessionManager(RcfServer & sessionManager);
113  int getPort() const;
114  void open();
115  void close();
116  void cycle(int timeoutMs);
117 
118  void tryReadMessage(NetworkSessionPtr networkSessionPtr);
119 
120  void cycleTransportAndServer(int timeoutMs);
121 
122  UdpServerTransport & enableSharedAddressBinding();
123 
124  // I_Service implementation
125  private:
126  void onServiceAdded(RcfServer &server);
127  void onServiceRemoved(RcfServer &server);
128  void onServerStart(RcfServer &server);
129  void onServerStop(RcfServer &server);
130 
131  RcfServer * mpRcfServer;
132  IpAddress mIpAddress;
133  IpAddress mMulticastIpAddress;
134  int mFd;
135  unsigned int mPollingDelayMs;
136  bool mEnableSharedAddressBinding;
137 
138  friend class UdpNetworkSession;
139 
140  };
141 
142 } // namespace RCF
143 
144 #endif // ! INCLUDE_RCF_UDPSERVERTRANSPORT_HPP
Definition: AmiIoHandler.hpp:23
TransportType
Describes the transport types used by a RCF connection.
Definition: Enums.hpp:33
std::shared_ptr< ServerTransport > ServerTransportPtr
Unique pointer wrapper for RCF::ServerTransport.
Definition: RcfFwd.hpp:46