Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2247_Regression / server.cpp
blobf61cada2e74d01b50b0fc13bd8c7ca4b531644da
1 #include "test_i.h"
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;
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
19 case 'k':
20 key = get_opts.opt_arg ();
21 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <iorfile>"
28 "-k <key>"
29 "\n",
30 argv [0]),
31 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 try
42 CORBA::ORB_var orb =
43 CORBA::ORB_init (argc, argv);
45 // We do the command line parsing first
46 if (parse_args (argc, argv) != 0)
47 return 1;
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"),
54 1);
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;
63 policies.length (3);
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");
98 if (output_file == 0)
99 ACE_ERROR_RETURN ((LM_ERROR,
100 "Cannot open output file for writing IOR: %s",
101 ior_output_file),
103 ACE_OS::fprintf (output_file, "%s", ior.in ());
104 ACE_OS::fclose (output_file);
107 poa_manager->activate ();
109 orb->run ();
111 catch (const CORBA::Exception& ex)
113 ex._tao_print_exception ("Caught exception:");
114 return 1;
116 return 0;