Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / orbsvcs / tests / HTIOP / AMI / server.cpp
blob6c89c1c7b265219fa3d2bfa6f85831b05af8ee43
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * Implementation of the server.
8 * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
9 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
11 //=============================================================================
14 #include "ami_test_i.h"
16 #include "tao/debug.h"
17 #include "ace/Get_Opt.h"
18 #include "ace/OS_NS_sys_socket.h"
22 const ACE_TCHAR *ior_output_file = 0;
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:d"));
28 int c;
30 while ((c = get_opts ()) != -1)
31 switch (c)
33 case 'o':
34 ior_output_file = get_opts.opt_arg ();
35 break;
36 case 'd':
37 TAO_debug_level++;
38 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-o <iorfile>"
44 "\n",
45 argv [0]),
46 -1);
48 // Indicates successful parsing of the command line
49 return 0;
52 int
53 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
55 try
57 CORBA::ORB_var orb =
58 CORBA::ORB_init (argc, argv);
60 CORBA::Object_var poa_object =
61 orb->resolve_initial_references("RootPOA");
63 if (CORBA::is_nil (poa_object.in ()))
64 ACE_ERROR_RETURN ((LM_ERROR,
65 " (%P|%t) Unable to initialize the POA.\n"),
66 1);
68 PortableServer::POA_var root_poa =
69 PortableServer::POA::_narrow (poa_object.in ());
71 PortableServer::POAManager_var poa_manager =
72 root_poa->the_POAManager ();
74 if (parse_args (argc, argv) != 0)
75 return 1;
77 ACE_OS::socket_init ();
79 AMI_Test_i ami_test_i (orb.in ());
81 A::AMI_Test_var ami_test_var =
82 ami_test_i._this ();
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 (1, // ethernalize objects
107 0 // wait for completion
110 orb->destroy ();
112 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
114 catch (const CORBA::Exception& ex)
116 ex._tao_print_exception ("Caught exception:");
117 return 1;
120 return 0;