summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/AVStreams/server.cpp
blob: 68a926f3ec0fa8d6ebcc8d7a2429a5909c5d3f4d (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
// $Id$

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

#include "server.h"
#include "Property_Exporter.h"
#include "Machine_Properties.h"
#include "orbsvcs/Trader/Dynamic_Property.h"

// Callbacks made by the AVStreams library into the application.

Video_Server_StreamEndPoint::Video_Server_StreamEndPoint (void)
{
}

int 
Video_Server_StreamEndPoint::handle_stop (const AVStreams::flowSpec &the_spec,
                                          CORBA::Environment &env)
{
  return -1;
}

int 
Video_Server_StreamEndPoint::handle_start (const AVStreams::flowSpec &the_spec,  
                                           CORBA::Environment &env)
{
  return -1;
}

int 
Video_Server_StreamEndPoint::handle_destroy (const AVStreams::flowSpec &the_spec,  
                                             CORBA::Environment &env)
{
  return -1;
}

CORBA::Boolean 
Video_Server_StreamEndPoint::handle_connection_requested (AVStreams::StreamEndPoint_ptr initiator, 
                                                          CORBA::Boolean is_mcast, 
                                                          AVStreams::streamQoS &qos, 
                                                          AVStreams::flowSpec &the_spec,  
                                                          CORBA::Environment &env)
{
  return 1;
} 

void
fill_service_type (CosTradingRepos::ServiceTypeRepository::PropStructSeq& prop_seq)
{
  prop_seq.length (10);

  for (int i = 0; i <= TAO_Machine_Properties::LOAD; i++)
    {
      prop_seq[i].name = TAO_Machine_Properties::PROP_NAMES[i];
      prop_seq[i].value_type = TAO_Machine_Properties::PROP_TYPE;
      prop_seq[i].mode = CosTradingRepos::ServiceTypeRepository::PROP_NORMAL;
    }
}

int
export_properties (CORBA::ORB_ptr orb,
		   CORBA::Object_ptr mmdevice,
		   TAO_Machine_Properties& mach_props,
		   TAO_DP_Dispatcher& dprop)
{
  // Bootstrap to the Lookup interface.
  ACE_DEBUG ((LM_ERROR, "Bootstrap to the Lookup interface.\n"));
  CORBA::Object_var trading_obj =
    orb->resolve_initial_references ("TradingService");
  
  if (CORBA::is_nil (trading_obj.in ()))
    ACE_ERROR_RETURN ((LM_ERROR,
		       " (%P|%t) Unable to initialize the POA.\n"),
		      -1);

  TAO_TRY
    {
      ACE_DEBUG ((LM_ERROR, "Narrow the Lookup interface.\n"));
      // Narrow the lookup interface.
      ACE_DEBUG ((LM_DEBUG, "Narrowing the lookup interface.\n"));
      CosTrading::Lookup_var lookup_if = 
	CosTrading::Lookup::_narrow (trading_obj.in (), TAO_TRY_ENV);
      TAO_CHECK_ENV;

      // Narrow the mmdevice to a property set reference. 
      CORBA::Any extra_info;
      CosPropertyService::PropertySet_ptr prop_set =
	CosPropertyService::PropertySet::_narrow (mmdevice, TAO_TRY_ENV);
      TAO_CHECK_ENV;

      // Instantiate the property exporter helper class.
#if defined TAO_HAS_DYNAMIC_PROPERTY_BUG
      TAO_Property_Exporter prop_exporter (lookup_if, prop_set, orb);
#else
      TAO_Property_Exporter prop_exporter (lookup_if, prop_set);
#endif /* TAO_HAS_DYNAMIC_PROPERTY_BUG */
      
      // Add properties to server description.

      
      // Add the machine properties.
      ACE_DEBUG ((LM_ERROR, "Adding machine properties.\n"));
      for (int i = (int) TAO_Machine_Properties::CPU;
	   i <= (int) TAO_Machine_Properties::LOAD; i++)
	{
	  CORBA::Any extra_info;
	  const char* name = TAO_Machine_Properties::PROP_NAMES[i];
	  const CORBA::TypeCode_ptr prop_type = TAO_Machine_Properties::PROP_TYPE;

#if defined TAO_HAS_DYNAMIC_PROPERTY_BUG
	  CosTradingDynamic::DynamicProp* dp_struct = 
	    dprop.construct_dynamic_prop (name, prop_type, extra_info, orb);
#else
	  CosTradingDynamic::DynamicProp* dp_struct = 
	    dprop.construct_dynamic_prop (name, prop_type, extra_info);
#endif /* TAO_HAS_DYNAMIC_PROPERTY_BUG */
	  
	  dprop.register_handler (name, &mach_props);
	  prop_exporter.add_dynamic_property (name, *dp_struct);
	}
      
      ACE_DEBUG ((LM_ERROR, "Exporting to the Trader.\n"));
      CosTradingRepos::ServiceTypeRepository::PropStructSeq prop_struct_seq;
      CosTradingRepos::ServiceTypeRepository::ServiceTypeNameSeq type_name_seq;

      ::fill_service_type (prop_struct_seq);
      CosTrading::OfferId_var offer_id =
	prop_exporter.export (mmdevice,
			      "MMDevice",
			      prop_struct_seq,
			      type_name_seq,
			      TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("export_properties");
    }
  TAO_ENDTRY;
}

// Main program.

int
main (int argc, char *argv[])
{
  TAO_TRY
    {
      TAO_ORB_Manager orb_manager;

      // Initialize the ORB.
      orb_manager.init (argc, 
                        argv,
                        TAO_TRY_ENV);
      TAO_CHECK_ENV;

      // Create server-side MMDevice.
      TAO_Server_MMDevice <Video_Server_StreamEndPoint> *mmdevice_impl;
      ACE_NEW_RETURN (mmdevice_impl,
                      TAO_Server_MMDevice <Video_Server_StreamEndPoint>,
                      -1);

      // Activate the MMDevice, i.e., register with POA.
      CORBA::Object_var obj_ptr = mmdevice_impl->_this (TAO_TRY_ENV);
      TAO_CHECK_ENV;

      // Add properties
      TAO_DP_Dispatcher dprop_dispatcher;
      TAO_Machine_Properties mach_props;
      ::export_properties (orb_manager.orb (),
			   obj_ptr,
			   mach_props,
			   dprop_dispatcher);
      
      // Activate Dynamic Properties
      CORBA::String_var dp_ior =
	orb_manager.activate (&dprop_dispatcher, TAO_TRY_ENV);
      
      // Print the IOR.
      ACE_DEBUG ((LM_DEBUG,
		  "\nThe IOR is: <%s>\n", 
		  orb_manager.orb ()-> object_to_string (obj_ptr, TAO_TRY_ENV)));      
      TAO_CHECK_ENV;
	 
      // Run the ORB Event loop.
      orb_manager.run (TAO_TRY_ENV);
      TAO_CHECK_ENV;
    }
  TAO_CATCH (CORBA::SystemException, sysex)
    {
      TAO_TRY_ENV.print_exception ("System Exception");
      return -1;
    }
  TAO_CATCH (CORBA::UserException, userex)
    {
      TAO_TRY_ENV.print_exception ("User Exception");
      return -1;
    }
  TAO_ENDTRY;
  ACE_DEBUG ((LM_DEBUG,
              "\nServer is terminating"));
  return 0;
}