2 //=============================================================================
6 * @author Aniruddha Gokhale
8 //=============================================================================
11 #include "param_test_i.h"
12 #include "tao/Codeset/Codeset.h"
13 #include "tao/debug.h"
14 #include "ace/Get_Opt.h"
15 #include "ace/Log_Msg.h"
16 #include "ace/OS_NS_stdio.h"
18 // Parses the command line arguments and returns an error status.
19 static FILE *ior_output_file
= 0;
20 static const ACE_TCHAR
*ior_output_filename
= ACE_TEXT("test.ior");
23 parse_args (int argc
, ACE_TCHAR
*argv
[])
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("do:"));
28 while ((c
= get_opts ()) != -1)
31 case 'd': // debug flag
35 ior_output_filename
= get_opts
.opt_arg ();
39 ACE_ERROR_RETURN ((LM_ERROR
,
45 return 0; // Indicates successful parsing of command line
48 // Standard command line parsing utilities used.
51 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
53 Param_Test_i
*param_test
= 0;
57 const char *orb_name
= "";
58 CORBA::ORB_var orb_ptr
=
59 CORBA::ORB_init (argc
, argv
, orb_name
);
61 CORBA::Object_var temp
; // holder for the myriad of times we get
62 // an object which we then have to narrow.
65 temp
= orb_ptr
->resolve_initial_references ("RootPOA");
67 if (CORBA::is_nil (temp
.in()))
68 ACE_ERROR_RETURN ((LM_ERROR
,
69 "(%P|%t) Unable to get root poa reference.\n"),
72 PortableServer::POA_var oa_ptr
= PortableServer::POA::_narrow (temp
.in());
74 PortableServer::POAManager_var poa_manager
=
75 oa_ptr
->the_POAManager ();
77 CORBA::PolicyList
policies (2);
80 oa_ptr
->create_id_assignment_policy (PortableServer::USER_ID
);
83 oa_ptr
->create_lifespan_policy (PortableServer::PERSISTENT
);
85 // We use a different POA, otherwise the user would have to
86 // change the object key each time it invokes the server.
87 PortableServer::POA_var good_poa
=
88 oa_ptr
->create_POA ("child_poa",
92 // Parse remaining command line and verify parameters.
93 parse_args (argc
, argv
);
95 // initialize a param_test target object and register it with the object
98 // Create the implementation object
99 ACE_NEW_RETURN (param_test
,
100 Param_Test_i ("unknown",
103 // Register with GoodPOA with a specific name
104 PortableServer::ObjectId_var id
=
105 PortableServer::string_to_ObjectId ("param_test");
106 good_poa
->activate_object_with_id (id
.in (),
109 // Stringify the objref we'll be implementing, and print it to
110 // stdout. Someone will take that string and give it to a
111 // client. Then release the object.
113 temp
= good_poa
->id_to_reference (id
.in ());
115 CORBA::String_var str
=
116 orb_ptr
->object_to_string (temp
.in ());
118 if (TAO_debug_level
> 0)
120 ACE_DEBUG ((LM_DEBUG
,
121 "(%P|%t) The IOR is <%s>\n",
125 ior_output_file
= ACE_OS::fopen (ior_output_filename
, "w");
127 if (ior_output_file
== 0)
129 ACE_ERROR_RETURN ((LM_ERROR
,
130 "Unable to open %s for writing: %p\n",
131 ior_output_filename
),
135 ACE_OS::fprintf (ior_output_file
,
138 ACE_OS::fclose (ior_output_file
);
141 // Make the POAs controlled by this manager active
142 poa_manager
->activate ();
146 good_poa
->destroy (true, true);
148 oa_ptr
->destroy (1, 1);
150 catch (const CORBA::SystemException
& sysex
)
152 sysex
._tao_print_exception ("System Exception");
155 catch (const CORBA::UserException
& userex
)
157 userex
._tao_print_exception ("User Exception");