summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/AV/Transport.h
blob: 5610ce541cd72793645c39dfdd6c4d33a383e6a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/* -*- C++ -*- */

// $Id$
// ============================================================================
//
// = LIBRARY
//   ORBSVCS AVStreams
//
// = FILENAME
//   Transport.h
//
// = AUTHOR
//    Nagarajan Surendran <naga@cs.wustl.edu>
//
//
// ============================================================================

#if !defined TAO_AV_TRANSPORT_H
#define TAO_AV_TRANSPORT_H

#include "ace/Acceptor.h"
#include "ace/SOCK_Acceptor.h"
#include "ace/Connector.h"
#include "ace/SOCK_Connector.h"
#include "ace/Addr.h"
#include "ace/SOCK_Dgram.h"
#include "orbsvcs/AV/AV_export.h"
#include "AV_Core.h"
#include "FlowSpec_Entry.h"

// Forward declarations.
class TAO_AV_Protocol_Object;
class TAO_AV_Callback;
class TAO_AV_Transport;

class TAO_AV_Flow_Handler
{
public:
  TAO_AV_Flow_Handler (void);
  // Constructor.

  virtual int start (TAO_FlowSpec_Entry::Role role);
  virtual int stop  (TAO_FlowSpec_Entry::Role role);
  // Start/stop the flow handler.

  virtual int schedule_timer (void);
  // Schedule timer. Uses the get_timeout method on the callback.

  TAO_AV_Transport *transport (void);
  // get the transport.

  TAO_AV_Protocol_Object* protocol_object (void);
  void protocol_object (TAO_AV_Protocol_Object *protocol_object);
  // set/get protocol_object.

  void callback (TAO_AV_Callback *callback);
  // set the callback.

  int handle_timeout (const ACE_Time_Value &tv, const void *arg = 0);
  // Handle timeout. called from reactor.

  virtual int set_remote_address (ACE_Addr *address);
  // set the remote address.

  virtual ACE_Event_Handler* event_handler (void) = 0;
  // get the underlying event handler. To be overridden by the derived clases.

protected:
  TAO_AV_Transport *transport_;
  TAO_AV_Callback *callback_;
  TAO_AV_Protocol_Object *protocol_object_;
  long timer_id_;
  ACE_Reactor *reactor_;
  void *timeout_arg_;
};

//  Transports
class TAO_AV_Export TAO_AV_Transport
{
  // TITLE
  //   = A Base class for the different transport protocols.
  //
  // DESCRIPTION
  //   = All the different transports should derive and implement
  //     the open,close,send and recv methods.
public:
  TAO_AV_Transport (void);

  virtual ~TAO_AV_Transport (void);

  virtual int open (ACE_Addr *address) = 0;

  virtual int close (void) = 0;

  virtual int mtu (void) = 0;
  virtual ACE_Addr *get_peer_addr (void) = 0;
  virtual ACE_Addr *get_local_addr (void);
  virtual ssize_t send (const ACE_Message_Block *mblk,
                        ACE_Time_Value *s = 0) = 0;
  // Write the complete Message_Block chain to the connection.

  virtual ssize_t send (const char *buf,
                        size_t len,
                        ACE_Time_Value *s = 0) = 0;
  // Write the contents of the buffer of length len to the connection.

  virtual ssize_t send (const iovec *iov,
                        int iovcnt,
                        ACE_Time_Value *s = 0) = 0;
  // Write the contents of iovcnt iovec's to the connection.

  virtual ssize_t recv (char *buf,
                        size_t len,
                        ACE_Time_Value *s = 0) = 0;
  // Read len bytes from into buf.

  virtual ssize_t recv (char *buf,
                        size_t len,
                        int flags,
                        ACE_Time_Value *s = 0) = 0;
  // Read len bytes from into buf using flags.

  virtual ssize_t recv (iovec *iov,
                        int iovcnt,
                        ACE_Time_Value *s = 0) = 0;
  //  Read received data into the iovec buffers.

};

class TAO_Base_StreamEndPoint;
class TAO_AV_Core;
class TAO_FlowSpec_Entry;

class TAO_AV_Acceptor
{
public:
  TAO_AV_Acceptor (void);
  virtual ~TAO_AV_Acceptor (void);
  virtual int open (TAO_Base_StreamEndPoint *endpoint,
                    TAO_AV_Core *av_core,
                    TAO_FlowSpec_Entry *entry,
                    TAO_AV_Flow_Protocol_Factory *factory) = 0;

  virtual int open_default (TAO_Base_StreamEndPoint *endpoint,
                            TAO_AV_Core *av_core,
                            TAO_FlowSpec_Entry *entry,
                            TAO_AV_Flow_Protocol_Factory *factory) = 0;

  const char *flowname ();
  virtual int close (void) = 0;
protected:
  ACE_CString flowname_;
  TAO_AV_Core *av_core_;
  ACE_Addr *address_;
};

class TAO_AV_Connector
{
public:
  TAO_AV_Connector (void);
  virtual ~TAO_AV_Connector (void);
  const char *flowname (void);

  virtual int open (TAO_Base_StreamEndPoint *endpoint,
                    TAO_AV_Core *av_core,
                    TAO_AV_Flow_Protocol_Factory *factory) = 0;

  virtual int connect (TAO_FlowSpec_Entry *entry,
                       TAO_AV_Transport *&transport) = 0;

  virtual int close (void) = 0;
protected:
  ACE_CString flowname_;
};


typedef ACE_Unbounded_Set<TAO_AV_Connector*> TAO_AV_ConnectorSet;
typedef ACE_Unbounded_Set_Iterator<TAO_AV_Connector*> TAO_AV_ConnectorSetItor;

class TAO_AV_Export TAO_AV_Connector_Registry
{
public:
  TAO_AV_Connector_Registry (void);
  ~TAO_AV_Connector_Registry (void);
  int open (TAO_Base_StreamEndPoint *endpoint,
            TAO_AV_Core *av_core,
            TAO_AV_FlowSpecSet &flow_spec_set);
  //  int connect (TAO_FlowSpec_Entry *flowspec,
  //               TAO_AV_Transport *&transport);
  int close_all (void);
  //  TAO_AV_Connector *get_connector (TAO_AV_Core::Protocol protocol);
  // Return the connector bridges
  TAO_AV_ConnectorSetItor begin (void);
  TAO_AV_ConnectorSetItor end (void);
protected:
  TAO_AV_ConnectorSet connectors_;
};

typedef ACE_Unbounded_Set<TAO_AV_Acceptor*>
        TAO_AV_AcceptorSet;
typedef ACE_Unbounded_Set_Iterator<TAO_AV_Acceptor*>
        TAO_AV_AcceptorSetItor;

class TAO_AV_Export TAO_AV_Acceptor_Registry
{
public:
  TAO_AV_Acceptor_Registry (void);
  ~TAO_AV_Acceptor_Registry (void);
  int open (TAO_Base_StreamEndPoint *endpoint,
            TAO_AV_Core *av_core,
            TAO_AV_FlowSpecSet &flow_spec_set);
  int close_all (void);
  TAO_AV_AcceptorSetItor begin (void);
  TAO_AV_AcceptorSetItor end (void);
protected:
  int open_default (TAO_Base_StreamEndPoint *endpoint,
                    TAO_AV_Core *av_core,
                    TAO_FlowSpec_Entry *entry);
  TAO_AV_AcceptorSet acceptors_;
};

#if defined (__ACE_INLINE__)
#include "Transport.i"
#endif /* __ACE_INLINE__ */

#endif /* TAO_AV_TRANSPORT_H */