RCFProto
 All Classes Functions Typedefs
UdpServerTransport.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_UDPSERVERTRANSPORT_HPP
20 #define INCLUDE_RCF_UDPSERVERTRANSPORT_HPP
21 
22 #include <string>
23 #include <vector>
24 
25 #include <boost/noncopyable.hpp>
26 #include <boost/shared_ptr.hpp>
27 
28 #include <RCF/Export.hpp>
29 #include <RCF/IpAddress.hpp>
30 #include <RCF/Service.hpp>
31 #include <RCF/ServerTransport.hpp>
32 #include <RCF/IpServerTransport.hpp>
33 #include <RCF/ThreadLibrary.hpp>
34 
35 namespace RCF {
36 
37  class UdpServerTransport;
38  class UdpSessionState;
39 
40  typedef boost::shared_ptr<UdpServerTransport> UdpServerTransportPtr;
41  typedef boost::shared_ptr<UdpSessionState> UdpSessionStatePtr;
42 
43  class UdpSessionState : public SessionState
44  {
45  public:
46 
47  UdpSessionState(UdpServerTransport & transport);
48 
49  int getNativeHandle() const;
50 
51  typedef UdpSessionStatePtr SessionStatePtr;
52 
53  private:
54 
55  ReallocBufferPtr mReadVecPtr;
56  ReallocBufferPtr mWriteVecPtr;
57  IpAddress mRemoteAddress;
58  UdpServerTransport & mTransport;
59  SessionPtr mSessionPtr;
60 
61  friend class UdpServerTransport;
62 
63  private:
64 
65  // I_SessionState
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  boost::noncopyable
92  {
93  public:
94 
95  UdpServerTransport(
96  const IpAddress & ipAddress,
97  const IpAddress & multicastIpAddress = IpAddress());
98 
99  TransportType getTransportType();
100 
101  ServerTransportPtr
102  clone();
103 
104  RcfServer &
105  getSessionManager();
106 
107  void setSessionManager(RcfServer & sessionManager);
108  int getPort() const;
109  void open();
110  void close();
111  void cycle(int timeoutMs);
112 
113  void cycleTransportAndServer(int timeoutMs);
114 
115  UdpServerTransport & enableSharedAddressBinding();
116 
117  // I_Service implementation
118  private:
119  void onServiceAdded(RcfServer &server);
120  void onServiceRemoved(RcfServer &server);
121  void onServerStart(RcfServer &server);
122  void onServerStop(RcfServer &server);
123 
124  private:
125 
126  typedef UdpSessionState SessionState;
127  typedef UdpSessionStatePtr SessionStatePtr;
128 
129  RcfServer * mpRcfServer;
130  IpAddress mIpAddress;
131  IpAddress mMulticastIpAddress;
132  int mFd;
133  unsigned int mPollingDelayMs;
134  bool mEnableSharedAddressBinding;
135 
136  friend class UdpSessionState;
137 
138  };
139 
140 } // namespace RCF
141 
142 #endif // ! INCLUDE_RCF_UDPSERVERTRANSPORT_HPP