Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Crashed_Callback / server.cpp
bloba56060e900cdcf590baf64a487b22745561b6166
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 = 0;
85 ACE_NEW_RETURN (service_impl,
86 Service,
87 1);
88 PortableServer::ServantBase_var owner_transfer(service_impl);
90 service_impl->orb_ = CORBA::ORB::_duplicate (orb.in());
92 PortableServer::ObjectId_var id =
93 root_poa->activate_object (service_impl);
95 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
97 Test::Service_var service =
98 Test::Service::_narrow (object.in ());
100 CORBA::String_var ior =
101 orb->object_to_string (service.in ());
103 // If the ior_output_file exists, output the ior to it
104 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
105 if (output_file == 0)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "Cannot open output file for writing IOR: %s",
108 ior_output_file),
110 ACE_OS::fprintf (output_file, "%s", ior.in ());
111 ACE_OS::fclose (output_file);
113 poa_manager->activate ();
115 ACE_Time_Value tv (50, 0);
116 orb->run (tv);
118 ACE_DEBUG ((LM_DEBUG, "Event loop finished\n"));
120 service_impl->dump_results ();
122 root_poa->destroy (1, 1);
124 orb->destroy ();
126 catch (const CORBA::Exception& ex)
128 ex._tao_print_exception ("Exception caught:");
129 return 1;
132 return 0;