Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / AMI / server.cpp
blob1bb451bf287f9cc4b53908e2da7e14e47a51b898
1 #include "Echo.h"
2 #include "Server_ORBInitializer.h"
3 #include "tao/ORBInitializer_Registry.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
22 case '?':
23 default:
24 ACE_ERROR_RETURN ((LM_ERROR,
25 "usage: %s "
26 "-o <iorfile>"
27 "\n",
28 argv [0]),
29 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
38 try
41 PortableInterceptor::ORBInitializer_var initializer(
42 new Server_ORBInitializer);
43 PortableInterceptor::register_orb_initializer(initializer.in());
46 CORBA::ORB_var orb =
47 CORBA::ORB_init (argc, argv);
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references("RootPOA");
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (poa_object.in ());
55 if (CORBA::is_nil (root_poa.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Panic: nil RootPOA\n"),
58 1);
60 PortableServer::POAManager_var poa_manager =
61 root_poa->the_POAManager ();
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 Echo *echo_impl;
67 ACE_NEW_RETURN (echo_impl,
68 Echo (orb.in ()),
69 1);
70 PortableServer::ServantBase_var owner_transfer(echo_impl);
72 PortableServer::ObjectId_var id =
73 root_poa->activate_object (echo_impl);
75 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
77 Test::Echo_var echo =
78 Test::Echo::_narrow (object.in ());
80 CORBA::String_var ior =
81 orb->object_to_string (echo.in ());
83 // Output the IOR to the <ior_output_file>
84 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
85 if (output_file == 0)
86 ACE_ERROR_RETURN ((LM_ERROR,
87 "Cannot open output file for writing IOR: %s",
88 ior_output_file),
89 1);
90 ACE_OS::fprintf (output_file, "%s", ior.in ());
91 ACE_OS::fclose (output_file);
93 poa_manager->activate ();
95 orb->run ();
97 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
99 root_poa->destroy (true, true);
101 orb->destroy ();
103 catch (const CORBA::Exception& ex)
105 ex._tao_print_exception ("Exception caught:");
106 return 1;
109 return 0;