summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/client.cpp
blob: 4d122ce03892205b2922a214b3d74438e7d00a39 (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
// $Id$

// ============================================================================
//
// = LIBRARY
//    TAO/orbsvcs/tests/AVStreams
//
// = FILENAME
//    client.cpp
//
// = DESCRIPTION 
//    Test client for the AVStreams demo
//   
// = AUTHORS
//   Sumedh Mungee <sumedh@cs.wustl.edu>
//
// ============================================================================

#include "client.h"

Video_Client_StreamEndPoint::Video_Client_StreamEndPoint ()
{
}

void 
Video_Client_StreamEndPoint::handle_stop (const AVStreams::flowSpec &the_spec,
                                          CORBA::Environment &env)
{
  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Client_StreamEndPoint::handle_stop: called\n"));
}

void 
Video_Client_StreamEndPoint::handle_start (const AVStreams::flowSpec &the_spec,  
                                           CORBA::Environment &env)
{
  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Client_StreamEndPoint::handle_start: called\n"));
}

void 
Video_Client_StreamEndPoint::handle_destroy (const AVStreams::flowSpec &the_spec,  
                                             CORBA::Environment &env)
{
  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Client_StreamEndPoint::handle_destroy: called\n"));
}

CORBA::Boolean 
Video_Client_StreamEndPoint::handle_connection_established (AVStreams::StreamEndPoint_ptr responder, 
                                                            AVStreams::streamQoS &qos_spec, 
                                                            const AVStreams::flowSpec &the_spec,  
                                                            CORBA::Environment &env) 
{
  ACE_DEBUG ((LM_DEBUG, 
              "(%P|%t) Video_Client_StreamEndPoint::handle_connection_established: called\n"));
  return 1;
}

Client::Client (void)
{
}

// initialize the ORB, get a grip on the remote mmdevice, and store it
// in this->remote_mmdevice_
// Also create a stream controlller and a local mmdevice

int
Client::init (int argc, 
              char **argv,
              CORBA::Environment &env)
{
  // init the ORB
  manager_.init (argc,
                 argv,
                 env);
  TAO_CHECK_ENV_RETURN (env, 1);

  // create the local mmdevice
  TAO_Client_MMDevice <Video_Client_StreamEndPoint> *mmdevice_impl = 
    new TAO_Client_MMDevice <Video_Client_StreamEndPoint>;
    this->local_mmdevice_ = mmdevice_impl->_this (env);
  TAO_CHECK_ENV_RETURN (env, 1);

  // create the local streamctrl
  TAO_StreamCtrl *stream_ctrl = new TAO_StreamCtrl (manager_.orb ());
  this->stream_ctrl_ = stream_ctrl->_this (env);
  TAO_CHECK_ENV_RETURN (env, 1);
  
  // bind to a remote mmdevice, as supplied by argc argv
  this->bind_to_remote_mmdevice (argc, argv, env);

  manager_.orb ()->open ();
  // create a local mmdevice for now..
  //  mmdevice_impl = new TAO_MMDevice;
  //  this->remote_mmdevice_ = mmdevice_impl->_this (env);

  TAO_CHECK_ENV_RETURN (env, 1);
}

// Use stream_ctrl_ to bind local_mmdevice_ and remote_mmdevice_
int
Client::run (CORBA::Environment &env)
{
  // initialize the in parameters
  AVStreams::streamQoS_var the_qos (new AVStreams::streamQoS);
  AVStreams::flowSpec_var the_flows (new AVStreams::flowSpec);

  // allocate the qos_list
  struct AVStreams::QoS qos_list;
  qos_list.QoSType = CORBA::string_alloc (64);
  qos_list.QoSParams = CORBA::string_alloc (64);
  strcpy (qos_list.QoSType, "foo");
  strcpy (qos_list.QoSParams, "bar");

  the_qos->length (1);
  the_qos [0] = qos_list;

  // allocate the flow_list
  const char *flow_list [] =
  {
    "alpha",
    "beta",
    "gamma"
  };

  CORBA::ULong len = sizeof (flow_list)/sizeof (char *);

  // set the length of the sequence
  the_flows->length (len);


  // now set each individual element
  for (CORBA::ULong i=0; i < the_flows->length (); i++)
    {
      // generate some arbitrary string to be filled into the ith location in
      // the sequence
      //      char *str = gen->gen_string ();
      //this->in_[i] = str;
      the_flows [i] = flow_list [i];
    }

  // Bind the devices together
  this->stream_ctrl_->bind_devs (local_mmdevice_,
                                 remote_mmdevice_,
                                 the_qos.inout (),
                                 the_flows.in (),
                                 env);
  
  TAO_CHECK_ENV_RETURN (env, 1);
  ACE_DEBUG ((LM_DEBUG, "(%P|%t) Devices bound successfully!\n"));
  
  // Start the flow of the stream
  this->stream_ctrl_-> start (the_flows.in (),
                              env);

  TAO_CHECK_ENV_RETURN (env, 1);
  return 0;
}

// bind to a remote mmdevice, as given by the command line arguments.
int
Client::bind_to_remote_mmdevice (int argc,
                                 char **argv,
                                 CORBA::Environment &env)
{
  ACE_Get_Opt get_opts (argc, argv, "k:");
  int c;
  char *ior = 0;
  
  // Parse the command line
  while ((c = get_opts ()) != -1)
    switch (c)
      {
      case 'k':
	ior = 
          ACE_OS::strdup (get_opts.optarg);
	break;
      case '?':
      default:
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s"
                           " [-k mmdevice_key]"
                           "\n",
                           argv [0]),
                          -1);
      }
  // We didnt get an IOR from the command line!
  if (ior == 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "usage:  %s"
                           " [-k mmdevice_key]"
                           "\n",
                           argv [0]),
                          -1);
  
  // get the object reference
  CORBA::Object_var mmdevice_object = 
    this->manager_.orb ()->string_to_object (ior,
                                             env);
  TAO_CHECK_ENV_RETURN (env, 1);

  // narrow the reference
  this->remote_mmdevice_ = 
    AVStreams::MMDevice::_narrow (mmdevice_object.in (),
                                  env);
  TAO_CHECK_ENV_RETURN (env, 1);

  if (CORBA::is_nil (this->remote_mmdevice_.in ()))
    {
      ACE_ERROR_RETURN ((LM_ERROR,
                         "invalid key <%s>\n",
                         ior),
                        -1);
    }

  ACE_DEBUG ((LM_DEBUG, "Object received OK\n"));
  
  ACE_DEBUG ((LM_DEBUG, 
              "\n(%P|%t) Bound to remote mmdevice"));

  return 0;
}

int
main (int argc, char **argv)
{
  TAO_TRY
    {
      Client client;
      if (client.init (argc, 
                       argv, 
                       TAO_TRY_ENV) == -1)
        return 1;
      TAO_CHECK_ENV;
      client.run (TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("AVStreams: client");
      return -1;
    }
  TAO_ENDTRY;
}