Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3384_Regression / server.cpp
blob88f9948a5f09519c84cfe7a6b1a335f40c73179f
1 #include "Server_i.h"
2 #include "tao/Messaging/Messaging.h"
3 #include "tao/AnyTypeCode/Any.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 CORBA::Object_var object =
44 orb->resolve_initial_references ("PolicyCurrent");
46 CORBA::PolicyCurrent_var policy_current =
47 CORBA::PolicyCurrent::_narrow (object.in ());
49 if (CORBA::is_nil (policy_current.in ()))
51 ACE_ERROR ((LM_ERROR, "ERROR: Nil policy current\n"));
52 return 1;
54 CORBA::Any scope_as_any;
55 scope_as_any <<= Messaging::SYNC_NONE;
57 CORBA::PolicyList policies(1); policies.length (1);
58 policies[0] =
59 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
60 scope_as_any);
62 policy_current->set_policy_overrides (policies, CORBA::ADD_OVERRIDE);
64 policies[0]->destroy ();
66 CORBA::Object_var poa_object =
67 orb->resolve_initial_references("RootPOA");
69 PortableServer::POA_var root_poa =
70 PortableServer::POA::_narrow (poa_object.in ());
72 if (CORBA::is_nil (root_poa.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR,
74 " (%P|%t) Panic: nil RootPOA\n"),
75 1);
77 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
79 if (parse_args (argc, argv) != 0)
80 return 1;
82 Server *server_impl = 0;
83 ACE_NEW_RETURN (server_impl,
84 Server (orb.in ()),
85 1);
86 PortableServer::ServantBase_var owner_transfer(server_impl);
88 PortableServer::ObjectId_var id =
89 root_poa->activate_object (server_impl);
91 object = root_poa->id_to_reference (id.in ());
93 Test::Server_var test_server = Test::Server::_narrow (object.in ());
95 CORBA::String_var ior = orb->object_to_string (test_server.in ());
97 // Output the IOR to the <ior_output_file>
98 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
99 if (output_file == 0)
100 ACE_ERROR_RETURN ((LM_ERROR,
101 "Cannot open output file for writing IOR: %s\n",
102 ior_output_file),
104 ACE_OS::fprintf (output_file, "%s", ior.in ());
105 ACE_OS::fclose (output_file);
107 poa_manager->activate ();
109 orb->run ();
111 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
113 root_poa->destroy (true, true);
115 orb->destroy ();
117 catch (const CORBA::Exception& ex)
119 ex._tao_print_exception ("Exception caught:");
120 return 1;
123 return 0;