Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_2174_Regression / server.cpp
blob6558436e9de372d7a75a2718308cb6bb21fe0c7d
1 #include "test_i.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR *ior_output_file = 0;
6 bool remove_object = false;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:r"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.opt_arg ();
19 break;
21 case 'r':
22 remove_object = true;
23 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile>"
30 "\n",
31 argv [0]),
32 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 if (parse_args (argc, argv) != 0)
48 return 1;
50 CORBA::Object_var poa_object =
51 orb->resolve_initial_references("RootPOA");
53 if (CORBA::is_nil (poa_object.in ()))
54 ACE_ERROR_RETURN ((LM_ERROR,
55 " (%P|%t) Unable to initialize the POA.\n"),
56 1);
58 PortableServer::POA_var root_poa =
59 PortableServer::POA::_narrow (poa_object.in ());
61 PortableServer::POAManager_var poa_manager =
62 root_poa->the_POAManager ();
64 Simple_Server_i server_impl (orb.in ());
66 PortableServer::ObjectId_var id =
67 root_poa->activate_object (&server_impl);
69 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
71 Simple_Server_var server =
72 Simple_Server::_narrow (object.in ());
74 CORBA::String_var ior =
75 orb->object_to_string (server.in ());
77 if (remove_object)
79 PortableServer::ObjectId_var oid = root_poa->reference_to_id(server.in());
80 root_poa->deactivate_object(oid.in());
81 ACE_DEBUG ((LM_DEBUG,
82 "server (%P) deactivated object immediately\n"
83 ));
87 // ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
89 // If the ior_output_file exists, output the ior to it
90 if (ior_output_file != 0)
92 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s",
96 ior_output_file),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
102 poa_manager->activate ();
104 orb->run ();
106 catch (const CORBA::Exception& ex)
108 ex._tao_print_exception ("Caught exception:");
109 return 1;
111 return 0;