Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / orbsvcs / tests / ImplRepo / ReconnectServer / serverA.cpp
blobc5c6d6847681628af4efee8ef9c80f8eeb5f5ed0
1 #include "test_i.h"
2 #include "tao/ImR_Client/ImR_Client.h"
3 #include <ace/Task.h>
4 #include <ace/Get_Opt.h>
6 const ACE_TCHAR * ior_output_file = ACE_TEXT ("serverA.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, "o:");
12 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-o <iorfile>"
26 "\n",
27 argv [0]),
28 -1);
31 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
40 if (parse_args (argc, argv) != 0)
42 return 1;
45 CORBA::Object_var object =
46 orb->resolve_initial_references ("RootPOA");
47 PortableServer::POA_var rootPOA =
48 PortableServer::POA::_narrow (object.in ());
49 PortableServer::POAManager_var poa_manager =
50 rootPOA->the_POAManager ();
52 CORBA::PolicyList policies (5);
53 policies.length (5);
55 // Lifespan policy
56 policies[0] =
57 rootPOA->create_lifespan_policy (PortableServer::PERSISTENT);
59 // Servant Retention Policy
60 policies[1] =
61 rootPOA->create_servant_retention_policy (PortableServer::RETAIN);
63 // ID Assignment Policy
64 policies[2] =
65 rootPOA->create_id_assignment_policy (PortableServer::USER_ID);
67 // Request Processing Policy
68 policies[3] =
69 rootPOA->create_request_processing_policy (PortableServer::USE_ACTIVE_OBJECT_MAP_ONLY);
71 // Threading policy
72 policies[4] =
73 rootPOA->create_thread_policy (PortableServer::ORB_CTRL_MODEL);
75 PortableServer::POA_var poa_a = rootPOA->create_POA ("poaA",
76 poa_manager.in (),
77 policies);
78 PortableServer::POA_var poa_c = rootPOA->create_POA ("poaC",
79 poa_manager.in (),
80 policies);
82 for (CORBA::ULong i = 0;
83 i < policies.length ();
84 ++i)
86 CORBA::Policy_ptr policy = policies[i];
87 policy->destroy ();
90 Test_Time_i* time = new Test_Time_i();
92 PortableServer::ObjectId_var oid =
93 PortableServer::string_to_ObjectId ("Server_A");
94 poa_a->activate_object_with_id (oid.in (), time);
95 CORBA::Object_var time_obj = poa_a->id_to_reference(oid.in());
96 CORBA::String_var ior =
97 orb->object_to_string (time_obj.in ());
99 poa_manager->activate ();
101 // Output the IOR to the <ior_output_file>
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 orb->run ();
113 rootPOA->destroy (1, 1);
114 orb->destroy ();
116 catch (const CORBA::Exception &ex)
118 ex._tao_print_exception ("Exception caught by serverA:");
119 return 1;
122 return 0;