=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / examples / PluggableUDP / tests / SimplePerformance / server.cpp
blob3ce36a8aaba2b32bd6d248acbd86dee8627c45a2
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * Implementation of the server running the UDP object.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "ace/Get_Opt.h"
15 #include "test_i.h"
17 // The following include file forces DIOP to be linked into the
18 // executable and initialized for static builds.
19 #include "tao/Strategies/advanced_resource.h"
22 const ACE_TCHAR *ior_output_file = ACE_TEXT ("test.ior");
24 int
25 parse_args (int argc, ACE_TCHAR *argv[])
27 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
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;
37 case '?':
38 default:
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "usage: %s "
41 "-o <iorfile>"
42 "\n",
43 argv [0]),
44 -1);
46 // Indicates successful parsing of the command line
47 return 0;
50 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
52 try
54 CORBA::ORB_var orb =
55 CORBA::ORB_init (argc,
56 argv,
57 "ORB_Test_Server");
59 if (parse_args (argc, argv) != 0)
60 return 1;
62 CORBA::Object_var poa_object =
63 orb->resolve_initial_references("RootPOA");
65 if (CORBA::is_nil (poa_object.in ()))
66 ACE_ERROR_RETURN ((LM_ERROR,
67 " (%P|%t) Unable to initialize the POA.\n"),
68 1);
70 PortableServer::POA_var root_poa =
71 PortableServer::POA::_narrow (poa_object.in ());
73 PortableServer::POAManager_var poa_manager =
74 root_poa->the_POAManager ();
76 Simple_Server_i server_impl (orb.in ());
78 PortableServer::ObjectId_var oidServer = root_poa->activate_object (&server_impl);
80 CORBA::Object_var objOne = root_poa->id_to_reference (oidServer.in ());
82 Simple_Server_var server = Simple_Server::_narrow (objOne.in ());
84 CORBA::String_var ior =
85 orb->object_to_string (server.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 (ACE_TEXT_ALWAYS_CHAR(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 ACE_TEXT_ALWAYS_CHAR(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 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
108 root_poa->destroy (true, true);
110 orb->destroy ();
112 catch (const CORBA::Exception& ex)
114 ex._tao_print_exception ("Caught exception:");
115 return 1;
118 return 0;