Merge pull request #2222 from jwillemsen/jwi-dllexportwarning
[ACE_TAO.git] / TAO / tests / Bug_2356_Regression / server.cpp
blobb437333e5a65b7d44a9d785358f58e23884051ab
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * Implementation of the server.
8 * @author Johnny Willemsen <jwillemsen@remedy.nl>
9 */
10 //=============================================================================
13 #include "ami_test_i.h"
14 #include "tao/Codeset/Codeset.h"
15 #include "tao/debug.h"
16 #include "ace/OS_NS_stdio.h"
17 #include "ace/Get_Opt.h"
19 const ACE_TCHAR *ior_output_file = 0;
21 int
22 parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:d"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'o':
31 ior_output_file = get_opts.opt_arg ();
32 break;
33 case 'd':
34 TAO_debug_level++;
35 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "usage: %s "
40 "-o <iorfile>"
41 "\n",
42 argv [0]),
43 -1);
45 // Indicates successful parsing of the command line
46 return 0;
49 int
50 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
52 try
54 CORBA::ORB_var orb =
55 CORBA::ORB_init (argc, argv);
57 CORBA::Object_var poa_object =
58 orb->resolve_initial_references("RootPOA");
60 if (CORBA::is_nil (poa_object.in ()))
61 ACE_ERROR_RETURN ((LM_ERROR,
62 " (%P|%t) Unable to initialize the POA.\n"),
63 1);
65 PortableServer::POA_var root_poa =
66 PortableServer::POA::_narrow (poa_object.in ());
68 PortableServer::POAManager_var poa_manager =
69 root_poa->the_POAManager ();
71 if (parse_args (argc, argv) != 0)
72 return 1;
74 AMI_Test_i ami_test_i (orb.in ());
76 PortableServer::ObjectId_var id =
77 root_poa->activate_object (&ami_test_i);
79 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
81 A::AMI_Test_var ami_test_var =
82 A::AMI_Test::_narrow (object.in ());
84 CORBA::String_var ior =
85 orb->object_to_string (ami_test_var.in ());
87 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
89 // If the ior_output_file exists, output the ior to it
90 if (ior_output_file != 0)
92 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
93 if (output_file == 0)
94 ACE_ERROR_RETURN ((LM_ERROR,
95 "Cannot open output file for writing IOR: %s",
96 ior_output_file),
97 1);
98 ACE_OS::fprintf (output_file, "%s", ior.in ());
99 ACE_OS::fclose (output_file);
102 poa_manager->activate ();
104 orb->run ();
106 root_poa->destroy (true, // ethernalize objects
107 false); // wait for completion
109 orb->destroy ();
111 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
113 catch (const CORBA::Exception& ex)
115 ex._tao_print_exception ("Caught exception:");
116 return 1;
119 return 0;