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