Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Single_Read / server.cpp
blob9c2ecff44774746394c1d176ec0c22556c15329a
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT("ior");
6 const ACE_TCHAR *client_done_file = ACE_TEXT("client_done.ior");
8 int
9 parse_args (int argc, ACE_TCHAR *argv[])
11 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:s:"));
12 int c;
14 while ((c = get_opts ()) != -1)
15 switch (c)
17 case 'o':
18 ior_output_file = get_opts.opt_arg ();
19 break;
20 case 's':
21 client_done_file = get_opts.opt_arg ();
22 break;
23 case '?':
24 default:
25 ACE_ERROR_RETURN ((LM_ERROR,
26 "usage: %s "
27 "-o <iorfile>"
28 "-s <file_in_servant>"
29 "\n",
30 argv [0]),
31 -1);
34 // Indicates successful parsing of the command line
35 return 0;
38 int
39 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
41 try
43 CORBA::ORB_var orb =
44 CORBA::ORB_init (argc,
45 argv);
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references ("RootPOA");
50 PortableServer::POA_var root_poa =
51 PortableServer::POA::_narrow (poa_object.in ());
53 PortableServer::POAManager_var poa_manager =
54 root_poa->the_POAManager ();
56 if (parse_args (argc, argv) != 0)
57 return -1;
59 test_i servant (orb.in (), client_done_file);
61 PortableServer::ObjectId_var id =
62 root_poa->activate_object (&servant);
64 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
66 test_var server =
67 test::_narrow (object.in ());
69 CORBA::String_var ior =
70 orb->object_to_string (server.in ());
72 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
74 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
75 if (output_file == 0)
76 ACE_ERROR_RETURN ((LM_ERROR,
77 "Cannot open output file for writing IOR: %s",
78 ior_output_file),
79 -1);
80 ACE_OS::fprintf (output_file, "%s", ior.in ());
81 ACE_OS::fclose (output_file);
83 poa_manager->activate ();
85 orb->run ();
87 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
89 root_poa->destroy (1,
90 1);
92 catch (const CORBA::Exception& ex)
94 ex._tao_print_exception ("Exception caught:");
95 return -1;
98 return 0;