Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1020_Regression / server.cpp
blobc8e74a999a7c967644519616eee5d4f87badc0db
1 #include "Server_i.h"
2 #include "ORB_Task.h"
3 #include "tao/Messaging/Messaging.h"
4 #include "tao/ORB_Core.h"
5 #include "ace/Get_Opt.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 #if defined (ACE_OPENVMS)
10 // need this to circumvent link error on OpenVMS
11 // has to do with interference in template instantiations
12 // for the server build by previous compilation of TestX
13 // components in client build which are reused by server
14 // without recompilation
15 ACE_Time_Value dum = ACE_Time_Value::zero;
16 #endif
18 int
19 parse_args (int argc, ACE_TCHAR *argv[]);
21 int
22 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
24 try
26 CORBA::ORB_var orb =
27 CORBA::ORB_init (argc, argv);
29 CORBA::Object_var poa_object =
30 orb->resolve_initial_references("RootPOA");
32 PortableServer::POA_var root_poa =
33 PortableServer::POA::_narrow (poa_object.in ());
35 if (CORBA::is_nil (root_poa.in ()))
36 ACE_ERROR_RETURN ((LM_ERROR,
37 " (%P|%t) Panic: nil RootPOA\n"),
38 1);
40 PortableServer::POAManager_var poa_manager =
41 root_poa->the_POAManager ();
43 CORBA::Object_var object =
44 orb->resolve_initial_references ("PolicyCurrent");
46 if (parse_args (argc, argv) != 0)
47 return 1;
49 PortableServer::Servant_var<Server> impl;
51 Server * tmp;
52 // ACE_NEW_RETURN is the worst possible way to handle
53 // exceptions (think: what if the constructor allocates memory
54 // and fails?), but I'm not in the mood to fight for a more
55 // reasonable way to handle allocation errors in ACE.
56 ACE_NEW_RETURN (tmp,
57 Server(orb.in()),
58 1);
59 impl = tmp;
62 PortableServer::ObjectId_var id =
63 root_poa->activate_object (impl.in ());
65 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
67 Test::Server_var server =
68 Test::Server::_narrow (object_act.in ());
70 CORBA::String_var ior =
71 orb->object_to_string (server.in ());
73 // If the ior_output_file exists, output the ior to it
74 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
75 if (output_file == 0)
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "Cannot open output file for writing IOR: %s",
78 ior_output_file),
79 1);
80 ACE_OS::fprintf (output_file, "%s", ior.in ());
81 ACE_OS::fclose (output_file);
83 poa_manager->activate ();
85 ORB_Task task(orb.in());
86 task.activate(THR_NEW_LWP | THR_JOINABLE, 4, 1);
88 task.wait();
90 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
92 root_poa->destroy (1, 1);
94 orb->destroy ();
96 catch (const CORBA::Exception& ex)
98 ex._tao_print_exception ("Exception caught:");
99 return 1;
102 return 0;
106 parse_args (int argc, ACE_TCHAR *argv[])
108 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
109 int c;
111 while ((c = get_opts ()) != -1)
112 switch (c)
114 case 'o':
115 ior_output_file = get_opts.opt_arg ();
116 break;
118 case '?':
119 default:
120 ACE_ERROR_RETURN ((LM_ERROR,
121 "usage: %s "
122 "-o <iorfile> "
123 "\n",
124 argv [0]),
125 -1);
127 // Indicates successful parsing of the command line
128 return 0;