2 //=============================================================================
8 //=============================================================================
11 #include "alt_mapping_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 PortableServer::POA_var oa_ptr
;
54 Alt_Mapping_i
*svnt
= 0;
58 const char *orb_name
= "";
59 CORBA::ORB_var orb_ptr
=
60 CORBA::ORB_init (argc
, argv
, orb_name
);
62 CORBA::Object_var temp
; // holder for the myriad of times we get
63 // an object which we then have to narrow.
67 temp
= orb_ptr
->resolve_initial_references ("RootPOA");
69 if (CORBA::is_nil (temp
.in()))
70 ACE_ERROR_RETURN ((LM_ERROR
,
71 "(%P|%t) Unable to get root poa reference.\n"),
74 oa_ptr
= PortableServer::POA::_narrow (temp
.in());
76 PortableServer::POAManager_var poa_manager
=
77 oa_ptr
->the_POAManager ();
79 // Parse remaining command line and verify parameters.
80 parse_args (argc
, argv
);
82 // initialize a param_test target object and register it with the object
85 // Create the implementation object
87 Alt_Mapping_i (orb_ptr
.in ()),
90 // Register with GoodPOA with a specific name
91 PortableServer::ObjectId_var id
=
92 PortableServer::string_to_ObjectId ("alt_mapping");
93 oa_ptr
->activate_object_with_id (id
.in (),
96 // Stringify the objref we'll be implementing, and print it to
97 // stdout. Someone will take that string and give it to a
98 // client. Then release the object.
100 temp
= oa_ptr
->id_to_reference (id
.in ());
102 CORBA::String_var str
=
103 orb_ptr
->object_to_string (temp
.in ());
105 if (TAO_debug_level
> 0)
107 ACE_DEBUG ((LM_DEBUG
,
108 "(%P|%t) The IOR is <%s>\n",
112 ior_output_file
= ACE_OS::fopen (ior_output_filename
, "w");
114 if (ior_output_file
== 0)
116 ACE_ERROR_RETURN ((LM_ERROR
,
117 "Unable to open %s for writing: %p\n",
118 ior_output_filename
),
122 ACE_OS::fprintf (ior_output_file
,
125 ACE_OS::fclose (ior_output_file
);
128 // Make the POAs controlled by this manager active
129 poa_manager
->activate ();
133 oa_ptr
->destroy (true, true);
135 catch (const CORBA::SystemException
& sysex
)
137 sysex
._tao_print_exception ("System Exception");
140 catch (const CORBA::UserException
& userex
)
142 userex
._tao_print_exception ("User Exception");