=default for generated implementation copy ctor
[ACE_TAO.git] / TAO / tests / AMI_Timeouts / server.cpp
blob7946d4ae2cf5ab9d0a96bf0c1bde0fbbf2764693
2 //=============================================================================
3 /**
4 * @file server.cpp
6 * Implementation of the server running the Timeout object.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "timeout_client.h"
14 #include "tao/debug.h"
15 #include "ace/Get_Opt.h"
17 const ACE_TCHAR *ior_output_file = 0;
19 int
20 parse_args (int argc, ACE_TCHAR *argv[])
22 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:d"));
23 int c;
25 while ((c = get_opts ()) != -1)
26 switch (c)
28 case 'o':
29 ior_output_file = get_opts.opt_arg ();
30 break;
31 case 'd':
32 ++TAO_debug_level;
33 break;
34 case '?':
35 default:
36 ACE_ERROR_RETURN ((LM_ERROR,
37 "usage: %s "
38 "-o <iorfile>"
39 "\n",
40 argv [0]),
41 -1);
43 // Indicates successful parsing of the command line
44 return 0;
47 int
48 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
50 try
52 CORBA::ORB_var orb =
53 CORBA::ORB_init (argc, argv);
55 CORBA::Object_var poa_object =
56 orb->resolve_initial_references ("RootPOA");
58 if (CORBA::is_nil (poa_object.in ()))
59 ACE_ERROR_RETURN ((LM_ERROR,
60 " (%P|%t) Unable to initialize the POA.\n"),
61 1);
63 PortableServer::POA_var root_poa =
64 PortableServer::POA::_narrow (poa_object.in ());
66 PortableServer::POAManager_var poa_manager =
67 root_poa->the_POAManager ();
69 if (parse_args (argc, argv) != 0)
70 return 1;
72 Timeout_i timeout_i (orb.in ());
74 PortableServer::ObjectId_var id =
75 root_poa->activate_object (&timeout_i);
77 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
79 TimeoutObj_var timeout_var =
80 TimeoutObj::_narrow (object.in ());
82 CORBA::String_var ior =
83 orb->object_to_string (timeout_var.in ());
85 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
87 // If the ior_output_file exists, output the ior to it
88 if (ior_output_file != 0)
90 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
91 if (output_file == 0)
92 ACE_ERROR_RETURN ((LM_ERROR,
93 "Cannot open output file for writing IOR: %s",
94 ior_output_file),
95 1);
96 ACE_OS::fprintf (output_file, "%s", ior.in ());
97 ACE_OS::fclose (output_file);
100 poa_manager->activate ();
102 // Instantiate reply handler
103 TimeoutHandler_i timeoutHandler_i;
105 PortableServer::ObjectId_var idu =
106 root_poa->activate_object (&timeoutHandler_i);
108 CORBA::Object_var objectu = root_poa->id_to_reference (idu.in ());
110 AMI_TimeoutObjHandler_var timeoutHandler_var =
111 AMI_TimeoutObjHandler::_narrow (objectu.in ());
113 // Instantiate client
115 TimeoutClient* client = new TimeoutClient (orb,
116 timeout_var.in (),
117 timeoutHandler_var.in (),
118 &timeoutHandler_i);
120 client->activate ();
123 orb->run ();
125 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
127 root_poa->destroy (true, // ethernalize objects
128 false); // wait for completion
130 orb->destroy ();
132 //delete client;
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Caught exception:");
137 return 1;
140 return 0;