Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Portable_Interceptors / IORInterceptor / server.cpp
blobe5228446bdd7d74a6e66aab5bf84686811eb5ff8
1 // -*- C++ -*-
2 #include "ace/Get_Opt.h"
4 #include "test_i.h"
5 #include "FOO_IORInterceptor_ORBInitializer.h"
7 #include "tao/ORBInitializer_Registry.h"
8 #include "ace/OS_NS_stdio.h"
10 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'o':
22 ior_output_file = get_opts.opt_arg ();
23 break;
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "Usage: %s "
27 "-o <iorfile>"
28 "\n",
29 argv[0]),
30 -1);
33 // Indicates successful parsing of the command line
34 return 0;
37 int
38 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
40 try
42 #if TAO_HAS_INTERCEPTORS == 1
43 PortableInterceptor::ORBInitializer_ptr temp_initializer =
44 PortableInterceptor::ORBInitializer::_nil ();
46 ACE_NEW_RETURN (temp_initializer,
47 FOO_IORInterceptor_ORBInitializer,
48 -1); // No CORBA exceptions yet!
49 PortableInterceptor::ORBInitializer_var orb_initializer =
50 temp_initializer;
52 PortableInterceptor::register_orb_initializer (orb_initializer.in ());
54 #endif /* TAO_HAS_INTERCEPTORS == 1 */
56 CORBA::ORB_var orb = CORBA::ORB_init (argc,
57 argv,
58 "test_orb");
60 CORBA::Object_var obj =
61 orb->resolve_initial_references ("RootPOA");
63 PortableServer::POA_var root_poa =
64 PortableServer::POA::_narrow (obj.in ());
66 if (CORBA::is_nil (root_poa.in ()))
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "Unable to obtain RootPOA reference.\n"),
69 -1);
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 poa_manager->activate ();
76 if (parse_args (argc, argv) != 0)
77 return -1;
79 test_i server_impl (orb.in ());
81 obj = server_impl._this ();
83 FOO::test_var server = FOO::test::_narrow (obj.in ());
85 if (CORBA::is_nil (server.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR,
87 "Unable to obtain reference to FOO::test "
88 "object.\n"),
89 -1);
91 CORBA::String_var ior =
92 orb->object_to_string (server.in ());
94 ACE_DEBUG ((LM_INFO, "FOO::test: <%C>\n", ior.in ()));
96 // If the ior_output_file exists, output the IOR to it.
97 if (ior_output_file != 0)
99 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
100 if (output_file == 0)
101 ACE_ERROR_RETURN ((LM_ERROR,
102 "Cannot open output file for writing "
103 "IOR: %s",
104 ior_output_file),
106 ACE_OS::fprintf (output_file, "%s", ior.in ());
107 ACE_OS::fclose (output_file);
110 orb->run ();
112 ACE_DEBUG ((LM_INFO, "Event loop finished.\n"));
114 // The interceptors will be destroyed when we call this
115 orb->destroy ();
117 catch (const CORBA::Exception& ex)
119 ex._tao_print_exception ("IORInterceptor test (server-side):");
121 return -1;
124 return 0;