summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/AV/AVStreams_i_T.cpp
blob: 64f8fb3cf7c3648b9d7e74679627d5b9b6445023 (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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
// $Id$

#ifndef TAO_AV_AVSTREAMS_I_T_C
#define TAO_AV_AVSTREAMS_I_T_C

#include "AVStreams_i.h"

// ----------------------------------------------------------------------
// TAO_StreamEndPoint
// ----------------------------------------------------------------------

// constructor.
template <class IF>
TAO_StreamEndPoint<IF>::TAO_StreamEndPoint (void)
  :flow_count_ (1)
{
  //  this->handle_open ();
}

// Stop the physical flow of data on the stream
// Empty the_spec --> apply to all flows
template <class IF>
void
TAO_StreamEndPoint<IF>::stop (const AVStreams::flowSpec &the_spec,
                          CORBA::Environment &ACE_TRY_ENV)
{
  // Make the upcall into the app
  this->handle_stop (the_spec, ACE_TRY_ENV);
}

// Start the physical flow of data on the stream
// Empty the_spec --> apply to all flows
template <class IF>
void
TAO_StreamEndPoint<IF>::start (const AVStreams::flowSpec &flow_spec,
                           CORBA::Environment &ACE_TRY_ENV)
{
  // Make the upcall into the app
  this->handle_start (flow_spec, ACE_TRY_ENV);
}

// Close the connection
template <class IF>
void
TAO_StreamEndPoint<IF>::destroy (const AVStreams::flowSpec &the_spec,
                                 CORBA::Environment &ACE_TRY_ENV)
{
//   // Make the upcall into the app
//   this->handle_destroy (the_spec, ACE_TRY_ENV);
  //
  // Remove self from POA.  Because of reference counting, the POA
  // will automatically delete the servant when all pending requests
  // on this servant are complete.
  //
  PortableServer::POA_var poa = this->_default_POA (ACE_TRY_ENV);
  ACE_CHECK;

  PortableServer::ObjectId_var id = poa->servant_to_id (this,
                                                        ACE_TRY_ENV);
  ACE_CHECK;

  poa->deactivate_object (id.in (),
                          ACE_TRY_ENV);
  ACE_CHECK;
}

// Called by our peer endpoint, requesting us to establish
// a connection
template <class IF>
CORBA::Boolean
TAO_StreamEndPoint<IF>::request_connection (AVStreams::StreamEndPoint_ptr initiator,
                                        CORBA::Boolean is_mcast,
                                        AVStreams::streamQoS &qos,
                                        AVStreams::flowSpec &the_spec,
                                        CORBA::Environment &)
{
  ACE_UNUSED_ARG (initiator);
  ACE_UNUSED_ARG (is_mcast);
  ACE_UNUSED_ARG (qos);

  ACE_DEBUG ((LM_DEBUG, "\n(%P|%t) TAO_StreamEndPoint::request_connection called"));
  ACE_DEBUG ((LM_DEBUG,
              "\n(%P|%t) TAO_StreamEndPoint::request_connection: "
              "flowspec has length = %d"
              "and the strings are:",
              the_spec.length ()));
  for (u_int i = 0; i < the_spec.length (); i++)
    ACE_DEBUG ((LM_DEBUG,
                the_spec [i]));

  return 0;
}

// @@ Need to throw not-supported exception here
template <class IF>
CORBA::Boolean
TAO_StreamEndPoint<IF>::modify_QoS (AVStreams::streamQoS &new_qos,
                                const AVStreams::flowSpec &the_flows,
                                CORBA::Environment &ACE_TRY_ENV)
{
  ACE_UNUSED_ARG (new_qos);
  ACE_UNUSED_ARG (the_flows);
  ACE_UNUSED_ARG (ACE_TRY_ENV);
  return 0;
}

// @@ Need to throw not-supported exception here
template <class IF>
CORBA::Boolean
TAO_StreamEndPoint<IF>::set_protocol_restriction (const AVStreams::protocolSpec &the_pspec,
                                              CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {
      CORBA::Any protocol_restriction_any;

      protocol_restriction_any <<= the_pspec;
      this->define_property ("ProtocolRestriction",
                             protocol_restriction_any,
                             ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_StreamEndPoint::set_protocol_restriction");
      return 0;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (0);
  return 1;
}

template <class IF>
void
TAO_StreamEndPoint<IF>::disconnect (const AVStreams::flowSpec &the_spec,
                                CORBA::Environment &ACE_TRY_ENV)
{
  ACE_UNUSED_ARG (the_spec);
  ACE_UNUSED_ARG (ACE_TRY_ENV);
}

// @@ Need to throw not-supported exception here
template <class IF>
void
TAO_StreamEndPoint<IF>::set_FPStatus (const AVStreams::flowSpec &the_spec,
                                  const char *fp_name,
                                  const CORBA::Any &fp_settings,
                                  CORBA::Environment &ACE_TRY_ENV)
{
  ACE_UNUSED_ARG (the_spec);
  ACE_UNUSED_ARG (fp_name);
  ACE_UNUSED_ARG (fp_settings);
  ACE_UNUSED_ARG (ACE_TRY_ENV);
}

template <class IF>
CORBA::Object_ptr
TAO_StreamEndPoint<IF>::get_fep (const char *flow_name,
                             CORBA::Environment &)
{
  TAO_String_Hash_Key fep_name_key (flow_name);
  FlowEndPoint_Map::ENTRY *fep_entry = 0;
  if (this->fep_map_.find (fep_name_key,fep_entry) == 0)
    return fep_entry->int_id_;
  return 0;
}

template <class IF>
char *
TAO_StreamEndPoint<IF>::add_fep (CORBA::Object_ptr the_fep,
                                 CORBA::Environment &ACE_TRY_ENV)
{
  char *flow_name = 0;
  ACE_TRY_EX (flow_name);
  {
    ACE_NEW_RETURN (flow_name,char [BUFSIZ],0);
    CORBA::Any_ptr flow_name_any;
    AVStreams::FlowEndPoint_ptr fep =
      AVStreams::FlowEndPoint::_narrow (the_fep,ACE_TRY_ENV);
    ACE_TRY_CHECK_EX (flow_name);
    flow_name_any = fep->get_property_value ("FlowName",ACE_TRY_ENV);
    ACE_TRY_CHECK_EX (flow_name);
    *flow_name_any >>= flow_name;
  }
  ACE_CATCHANY
    {
      // exception implies the flow name is not defined and is system generated.
      ACE_OS::sprintf (flow_name,"flow%d",flow_num_++);
    }
  ACE_ENDTRY;
  // Add it to the sequence of flowNames supported.
  // put the flowname and the flowendpoint in a hashtable.
  TAO_String_Hash_Key fep_name_key (flow_name);
  if (this->fep_map_.bind (fep_name_key,the_fep) != 0)
    {
      ACE_THROW_RETURN (AVStreams::streamOpFailed (),0);
    }
  ACE_TRY_EX (flows)
    {
      // increment the flow count.
      this->flow_count_++;
      this->flows_.length (this->flow_count_);
      this->flows_ [this->flow_count_-1] = flow_name;
      // define/modify the "Flows" property.
      CORBA::Any flows_any;
      flows_any <<= this->flows_;
      this->define_property ("Flows",
                             flows_any,
                             ACE_TRY_ENV);
      ACE_TRY_CHECK_EX (flows);
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_StreamEndPoint::add_fep");
      return 0;
    }
  ACE_ENDTRY;
  ACE_CHECK_RETURN (0);
  return flow_name;
}

template <class IF>
void
TAO_StreamEndPoint<IF>::remove_fep (const char *flow_name,
                                CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {
      TAO_String_Hash_Key fep_name_key (flow_name);
      CORBA::Object_ptr fep_entry = 0;
      // Remove the fep from the hash table.
      if (this->fep_map_.unbind (fep_name_key,fep_entry)!= 0)
        TAO_THROW_ENV (AVStreams::streamOpFailed (),ACE_TRY_ENV);
      // redefine the "Flows" property
      AVStreams::flowSpec new_flows (this->flows_.length ());
      for (u_int i=0,j=0 ; i <this->flows_.length (); i++)
        if (ACE_OS::strcmp (flow_name,this->flows_[i]) != 0)
          new_flows[j++] = this->flows_[i];

      CORBA::Any flows;
      flows <<= new_flows;
      this->flows_ = new_flows;
      this->define_property ("Flows",
                             flows,
                             ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_StreamEndPoint::remove_fep");
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

// @@ Need to throw not-supported exception here
template <class IF>
void
TAO_StreamEndPoint<IF>::set_negotiator (AVStreams::Negotiator_ptr new_negotiator,
                                        CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {
      CORBA::Any negotiator;
      negotiator <<= new_negotiator;
      this->define_property ("Negotiator",
                             negotiator,
                             ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_StreamEndPoint::set_negotiator");
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

// Sets the public key used for this streamendpoint.
template <class IF>
void
TAO_StreamEndPoint<IF>::set_key (const char *flow_name,
                             const AVStreams::key & the_key,
                             CORBA::Environment &ACE_TRY_ENV)
{
  ACE_TRY
    {

      CORBA::Any PublicKey;
      PublicKey <<= the_key;
      char PublicKey_property [BUFSIZ];
      ACE_OS::sprintf (PublicKey_property,"%s_PublicKey",flow_name);
      this->define_property (PublicKey_property,
                             PublicKey,
                             ACE_TRY_ENV);
      ACE_TRY_CHECK;
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION,"TAO_StreamEndPoint::set_key");
    }
  ACE_ENDTRY;
  ACE_CHECK;
}

// Set the source id.
template <class IF>
void
TAO_StreamEndPoint<IF>::set_source_id (CORBA::Long source_id,
                                   CORBA::Environment &)
{
  this->source_id_ = source_id;
}

template <class IF>
TAO_StreamEndPoint<IF>::~TAO_StreamEndPoint (void)
{
  //this->handle_close ();
}

#endif /*TAO_AV_AVSTREAMS_I_T_C*/