2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 const ACE_TCHAR
*ior_output_file
= 0;
5 const ACE_TCHAR
*key
= 0;
8 parse_args (int argc
, ACE_TCHAR
*argv
[])
10 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:k:"));
13 while ((c
= get_opts ()) != -1)
17 ior_output_file
= get_opts
.opt_arg ();
20 key
= get_opts
.opt_arg ();
25 ACE_ERROR_RETURN ((LM_ERROR
,
33 // Indicates successful parsing of the command line
38 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
43 CORBA::ORB_init (argc
, argv
);
45 // We do the command line parsing first
46 if (parse_args (argc
, argv
) != 0)
48 CORBA::Object_var poa_object
=
49 orb
->resolve_initial_references("RootPOA");
51 if (CORBA::is_nil (poa_object
.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR
,
53 " (%P|%t) Unable to initialize the POA.\n"),
56 PortableServer::POA_var root_poa
=
57 PortableServer::POA::_narrow (poa_object
.in ());
59 PortableServer::POAManager_var poa_manager
=
60 root_poa
->the_POAManager ();
62 CORBA::PolicyList policies
;
64 policies
[0] = root_poa
->create_id_assignment_policy (
65 PortableServer::USER_ID
);
66 policies
[1] = root_poa
->create_implicit_activation_policy (
67 PortableServer::NO_IMPLICIT_ACTIVATION
);
68 policies
[2] = root_poa
->create_lifespan_policy (
69 PortableServer::PERSISTENT
);
71 PortableServer::POA_var poa
= root_poa
->create_POA (
72 "PERS_POA", poa_manager
.in (), policies
);
74 for (CORBA::ULong i
= 0; i
< policies
.length (); ++i
)
76 policies
[i
]->destroy ();
79 // Instantiate the LCD_Display implementation class
80 Simple_Server_i
display_impl (orb
.in (), ACE_TEXT_ALWAYS_CHAR(key
));
81 PortableServer::ObjectId_var id
=
82 PortableServer::string_to_ObjectId ("IOGR_OID");
84 poa
->activate_object_with_id (id
.in(), &display_impl
);
86 CORBA::Object_var server
=
87 poa
->id_to_reference (id
.in ());
89 CORBA::String_var ior
=
90 orb
->object_to_string (server
.in ());
92 ACE_DEBUG ((LM_DEBUG
, "Activated as <%C>\n", ior
.in ()));
94 // If the ior_output_file exists, output the ior to it
95 if (ior_output_file
!= 0)
97 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
99 ACE_ERROR_RETURN ((LM_ERROR
,
100 "Cannot open output file for writing IOR: %s",
103 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
104 ACE_OS::fclose (output_file
);
107 poa_manager
->activate ();
112 catch (const CORBA::Exception
& ex
)
114 ex
._tao_print_exception ("Caught exception:");