Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_3444_Regression / server.cpp
blob4eb878ed19efb408b2d18214e2cdecaeb2245027
1 #include "Test_impl.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "ace/Get_Opt.h"
4 #include "orbsvcs/PortableGroup/GOA.h"
7 const ACE_TCHAR *uipmc_url = 0;
8 const ACE_TCHAR *ior_output_file = 0;
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("o:u:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'u':
20 uipmc_url = get_opts.opt_arg ();
21 break;
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "usage: %s "
29 "-o <iorfile>"
30 "-u <miop_url>"
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
46 if (parse_args (argc, argv) != 0)
47 ACE_ERROR_RETURN ((LM_ERROR, "Wrong arguments\n"), -1);
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references("RootPOA");
52 Server_impl* server_obj = 0;
53 ACE_NEW_RETURN (server_obj,
54 Server_impl(orb.in()),
55 -1);
56 PortableServer::ServantBase_var owner (server_obj);
58 CORBA::String_var ior;
59 if (uipmc_url)
61 PortableGroup::GOA_var root_poa =
62 PortableGroup::GOA::_narrow (poa_object.in ());
64 if (CORBA::is_nil (root_poa.in ()))
65 ACE_ERROR_RETURN ((LM_ERROR,
66 " (%P|%t) Panic: nil RootPOA\n"),
67 1);
69 PortableServer::POAManager_var poa_manager =
70 root_poa->the_POAManager ();
72 // create UIPMC reference
73 CORBA::Object_var ref =
74 orb->string_to_object (uipmc_url);
76 // create id
77 PortableServer::ObjectId_var id =
78 root_poa->create_id_for_reference (ref.in ());
80 // activate object
81 root_poa->activate_object_with_id (id.in (),
82 server_obj);
84 ior =
85 orb->object_to_string (ref.in ());
87 poa_manager->activate ();
89 else
91 PortableServer::POA_var root_poa =
92 PortableServer::POA::_narrow (poa_object.in ());
94 if (CORBA::is_nil (root_poa.in ()))
95 ACE_ERROR_RETURN ((LM_ERROR,
96 " (%P|%t) Panic: nil RootPOA\n"),
97 1);
99 PortableServer::POAManager_var poa_manager =
100 root_poa->the_POAManager ();
102 CORBA::Object_var ref =
103 server_obj->_this ();
105 ior =
106 orb->object_to_string (ref.in ());
108 poa_manager->activate ();
111 if (ior_output_file != 0)
113 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
114 ACE_OS::fprintf (output_file, "%s", ior.in ());
115 ACE_OS::fclose (output_file);
118 orb->run ();
120 orb->destroy ();
122 catch (const ::CORBA::Exception &ex)
124 ex._tao_print_exception ("Exception in server.cpp:\n");
125 return -1;
128 return 0;