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
|
// $Id$
// ============================================================================
//
// = LIBRARY
// TAO/orbsvcs/tests/AVStreams
//
// = FILENAME
// server.cpp
//
// = DESCRIPTION
// Test server for the AVStreams demo
//
// = AUTHORS
// Sumedh Mungee <sumedh@cs.wustl.edu>
//
// ============================================================================
#include "orbsvcs/AVStreams_i.h"
int
main (int argc, char ** argv)
{
TAO_TRY
{
// Initialize the ORB
CORBA::ORB_ptr orb = CORBA::ORB_init (argc,
argv,
0,
TAO_TRY_ENV);
TAO_CHECK_ENV;
// Initialize the Object Adapter
CORBA::Object_var poa_object =
orb->resolve_initial_references ("RootPOA");
if (CORBA::is_nil (poa_object.in ()))
ACE_ERROR_RETURN ((LM_ERROR,
" (%P|%t) Unable to initialize the POA.\n"),
1);
PortableServer::POA_var root_poa =
PortableServer::POA::_narrow (poa_object, TAO_TRY_ENV);
TAO_CHECK_ENV;
PortableServer::POAManager_var poa_manager =
root_poa->the_POAManager (TAO_TRY_ENV);
TAO_CHECK_ENV;
PortableServer::PolicyList policies (2);
policies.length (2);
policies[0] =
root_poa->create_id_assignment_policy (PortableServer::USER_ID,
TAO_TRY_ENV);
policies[1] =
root_poa->create_lifespan_policy (PortableServer::PERSISTENT,
TAO_TRY_ENV);
// We use a different POA, otherwise the user would have to
// change the object key each time it invokes the server.
PortableServer::POA_var good_poa =
root_poa->create_POA ("RootPOA_is_BAD",
poa_manager.in (),
policies,
TAO_TRY_ENV);
TAO_CHECK_ENV;
// create a streamctrl object
TAO_Basic_StreamCtrl basic_stream_ctrl;
PortableServer::ObjectId_var id =
PortableServer::string_to_ObjectId ("Basic_StreamCtrl");
good_poa->activate_object_with_id (id.in (),
&basic_stream_ctrl,
TAO_TRY_ENV);
TAO_CHECK_ENV;
// Stringify the objref we'll be implementing, and print it to
// stdout. Someone will take that string and give it to a
// client.
CORBA::Object_var obj =
good_poa->id_to_reference (id.in (), TAO_TRY_ENV);
TAO_CHECK_ENV;
CORBA::String_var str =
orb->object_to_string (obj.in (),
TAO_TRY_ENV);
TAO_CHECK_ENV;
ACE_DEBUG ((LM_DEBUG,
"The IOR is: <%s>\n", str.in ()));
poa_manager->activate (TAO_TRY_ENV);
TAO_CHECK_ENV;
// Handle requests for this object until we're killed, or one of
// the methods asks us to exit.
if (orb->run () == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "run"), -1);
root_poa->destroy (CORBA::B_TRUE,
CORBA::B_TRUE,
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, "Server is terminating"));
return 0;
}
|