Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_3068_Regression / server.cpp
bloba1ddc8d3806e672fc494181c90c88322af8b8771
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "test_i.h"
4 #include "ace/Task.h"
6 #include "tao/Messaging/Messaging.h"
7 #include "tao/BiDir_GIOP/BiDirGIOP.h"
9 const ACE_TCHAR *ior_output_file = 0;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[])
14 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:"));
15 int c;
17 while ((c = get_opts ()) != -1)
18 switch (c)
20 case 'o':
21 ior_output_file = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT ("usage: %s -o <iorfile>\n"), argv [0]),
26 -1);
28 // Indicates successful parsing of the command line
29 return 0;
32 int
33 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
35 try
37 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
39 CORBA::Object_var object =
40 orb->resolve_initial_references ("ORBPolicyManager");
42 CORBA::PolicyManager_var policy_mgr =
43 CORBA::PolicyManager::_narrow (object.in ());
44 if (CORBA::is_nil (policy_mgr.in ()))
45 ACE_ERROR_RETURN ((LM_ERROR, "failed to get policy manager\n"), 1);
46 CORBA::String_var ref_id = policy_mgr->_interface_repository_id ();
47 ACE_DEBUG ((LM_DEBUG, "Policy MGR intid = %C\n", ref_id.in ()));
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references ("RootPOA");
52 if (CORBA::is_nil (poa_object.in ()))
53 ACE_ERROR_RETURN ((LM_ERROR,
54 " (%P|%t) Unable to initialize the POA.\n"),
55 1);
57 PortableServer::POA_var root_poa =
58 PortableServer::POA::_narrow (poa_object.in ());
59 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
61 // Policies for the childPOA to be created.
62 CORBA::PolicyList policies (1);
63 policies.length (1);
65 CORBA::Any pol;
66 pol <<= BiDirPolicy::BOTH;
67 policies[0] =
68 orb->create_policy (BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol);
70 // Create POA as child of RootPOA with the above policies. This POA
71 // will receive request in the same connection in which it sent
72 // the request
73 PortableServer::POA_var child_poa =
74 root_poa->create_POA ("child", poa_manager.in (), policies);
76 // Creation of childPOA is over. Destroy the Policy objects.
77 for (CORBA::ULong i = 0; i < policies.length (); ++i)
79 policies[i]->destroy ();
82 poa_manager->activate ();
84 if (parse_args (argc, argv) != 0)
85 return 1;
87 Simple_Server_i server_impl (orb.in ());
89 PortableServer::ObjectId_var id =
90 PortableServer::string_to_ObjectId ("simple_server");
92 child_poa->activate_object_with_id (id.in (), &server_impl);
94 CORBA::Object_var obj = child_poa->id_to_reference (id.in ());
96 CORBA::String_var ior = orb->object_to_string (obj.in ());
98 ACE_DEBUG ((LM_DEBUG, "(%P|%t) Server activated as <%C>\n", ior.in ()));
100 // If the ior_output_file exists, output the ior to it
101 if (ior_output_file != 0)
103 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
104 if (output_file == 0)
105 ACE_ERROR_RETURN ((LM_ERROR,
106 "Cannot open output file for writing IOR: %C",
107 ior_output_file),
109 ACE_OS::fprintf (output_file, "%s", ior.in ());
110 ACE_OS::fclose (output_file);
113 orb->run();
115 ACE_Thread_Manager::instance ()->wait ();
117 root_poa->destroy (true, true);
119 catch (const CORBA::Exception &excep)
121 excep._tao_print_exception ("Caught exception:");
122 return 1;
125 return 0;