ACE+TAO-6_5_17
[ACE_TAO.git] / TAO / examples / Buffered_Oneways / server.cpp
blob87d910c12b9a92b128f63f99a30b471303386244
1 #include "ace/Get_Opt.h"
2 #include "test_i.h"
3 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR *ior_output_file = ACE_TEXT("ior");
9 int
10 parse_args (int argc, ACE_TCHAR *argv[])
12 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
13 int c;
15 while ((c = get_opts ()) != -1)
16 switch (c)
18 case 'o':
19 ior_output_file = get_opts.opt_arg ();
20 break;
21 case '?':
22 default:
23 ACE_ERROR_RETURN ((LM_ERROR,
24 "usage: %s "
25 "-o <iorfile>"
26 "\n",
27 argv [0]),
28 -1);
31 // Indicates successful parsing of the command line
32 return 0;
35 int
36 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
38 try
40 CORBA::ORB_var orb =
41 CORBA::ORB_init (argc, argv);
43 CORBA::Object_var poa_object =
44 orb->resolve_initial_references ("RootPOA");
46 PortableServer::POA_var root_poa =
47 PortableServer::POA::_narrow (poa_object.in ());
49 PortableServer::POAManager_var poa_manager =
50 root_poa->the_POAManager ();
52 if (parse_args (argc, argv) != 0)
53 return -1;
55 test_i servant (orb.in ());
57 test_var server =
58 servant._this ();
60 CORBA::String_var ior =
61 orb->object_to_string (server.in ());
63 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
65 FILE *output_file = ACE_OS::fopen (ior_output_file, "w");
66 if (output_file == 0)
67 ACE_ERROR_RETURN ((LM_ERROR,
68 "Cannot open output file for writing IOR: %s",
69 ior_output_file),
70 -1);
71 ACE_OS::fprintf (output_file, "%s", ior.in ());
72 ACE_OS::fclose (output_file);
74 poa_manager->activate ();
76 orb->run ();
78 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
80 root_poa->destroy (1,
81 1);
83 catch (const CORBA::Exception& ex)
85 ex._tao_print_exception ("Exception caught:");
86 return -1;
89 return 0;