Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_3000_Regression / server.cpp
blob5280034874c6fd2b2ba59c97a3b888e5df5e3206
1 #include "Service.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/AnyTypeCode/Any.h"
5 #include "ace/Get_Opt.h"
6 #include "ace/OS_NS_stdio.h"
8 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'o':
20 ior_output_file = get_opts.opt_arg ();
21 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 poa_object =
44 orb->resolve_initial_references("RootPOA");
46 PortableServer::POA_var root_poa =
47 PortableServer::POA::_narrow (poa_object.in ());
49 if (CORBA::is_nil (root_poa.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR,
51 " (%P|%t) Panic: nil RootPOA\n"),
52 1);
54 PortableServer::POAManager_var poa_manager =
55 root_poa->the_POAManager ();
57 // Make all oneways "reliable."
59 CORBA::Object_var manager_object =
60 orb->resolve_initial_references("ORBPolicyManager");
61 CORBA::PolicyManager_var policy_manager =
62 CORBA::PolicyManager::_narrow(manager_object.in());
64 if (CORBA::is_nil (policy_manager.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR,
66 " (%P|%t) Panic: nil PolicyManager\n"),
67 1);
68 CORBA::Any policy_value;
69 policy_value <<= Messaging::SYNC_WITH_SERVER;
70 CORBA::PolicyList policies(1); policies.length(1);
71 policies[0] =
72 orb->create_policy (Messaging::SYNC_SCOPE_POLICY_TYPE,
73 policy_value);
75 policy_manager->set_policy_overrides (policies,
76 CORBA::ADD_OVERRIDE);
78 policies[0]->destroy ();
81 if (parse_args (argc, argv) != 0)
82 return 1;
84 Service *service_impl;
85 ACE_NEW_RETURN (service_impl,
86 Service(orb.in ()),
87 1);
88 PortableServer::ServantBase_var owner_transfer(service_impl);
90 PortableServer::ObjectId_var id =
91 root_poa->activate_object (service_impl);
93 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
95 Test::Service_var service =
96 Test::Service::_narrow (object.in ());
98 CORBA::String_var ior =
99 orb->object_to_string (service.in ());
101 // If the ior_output_file exists, output the ior to it
102 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
103 if (output_file == 0)
104 ACE_ERROR_RETURN ((LM_ERROR,
105 "Cannot open output file for writing IOR: %s",
106 ior_output_file),
108 ACE_OS::fprintf (output_file, "%s", ior.in ());
109 ACE_OS::fclose (output_file);
111 poa_manager->activate ();
113 orb->run ();
115 ACE_DEBUG ((LM_DEBUG, "Event loop finished\n"));
117 root_poa->destroy (true, true);
119 orb->destroy ();
121 catch (const CORBA::Exception& ex)
123 ex._tao_print_exception ("Exception caught:");
124 return 1;
127 return 0;