Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / Bug_3080 / server.cpp
blob5ecdaf7cb1395642685f51f85ea148adcb851cfa
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
4 #include "test_i.h"
6 const ACE_TCHAR *ior_file = 0;
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:c:n:s:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_file = get_opts.opt_arg ();
19 break;
20 default:
21 ACE_ERROR_RETURN ((LM_ERROR,
22 "Usage: %s "
23 "-o <IOR> ",
24 argv[0]),
25 -1);
28 return 0;
31 int
32 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
34 try
36 CORBA::ORB_var orb =
37 CORBA::ORB_init (argc, argv, "Server ORB");
39 CORBA::Object_var poa_object =
40 orb->resolve_initial_references ("RootPOA");
42 if (CORBA::is_nil (poa_object.in ()))
43 ACE_ERROR_RETURN ((LM_ERROR,
44 " (%P|%t) Unable to initialize the POA.\n"),
45 1);
47 PortableServer::POA_var root_poa =
48 PortableServer::POA::_narrow (poa_object.in ());
50 PortableServer::POAManager_var poa_manager =
51 root_poa->the_POAManager ();
53 if (::parse_args (argc, argv) != 0)
54 return -1;
56 test_i *test_impl = 0;
57 ACE_NEW_RETURN (test_impl, test_i (1, orb.in ()), 1);
58 PortableServer::ServantBase_var owner_transfer (test_impl);
60 PortableServer::ObjectId_var id =
61 root_poa->activate_object (test_impl);
63 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
65 RedirectionTest::test_var test =
66 RedirectionTest::test::_narrow (object.in ());
68 CORBA::String_var ior =
69 orb->object_to_string (test.in ());
71 FILE *output_file= ACE_OS::fopen (ior_file, "w");
72 if (output_file == 0)
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "Cannot open output file <%s> for writing "
75 "IOR: %s",
76 ior.in ()),
77 1);
78 ACE_OS::fprintf (output_file, "%s", ior.in ());
79 ACE_OS::fclose (output_file);
81 root_poa->destroy (1, 1 );
83 orb->destroy ();
85 ACE_DEBUG ((LM_DEBUG, "Server event loop finished.\n"));
87 catch (const CORBA::Exception& ex)
89 ex._tao_print_exception ("Caught exception:");
90 return -1;
93 return 0;