Merge pull request #2301 from sonndinh/remove-dup-reactor-functions
[ACE_TAO.git] / TAO / tests / Bug_3926_Regression / server.cpp
blobd72856f45937a39b177ef5ebd6ea62538be870d5
1 // -*- C++ -*-
2 #include "test_i.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/OS_NS_stdio.h"
7 const ACE_TCHAR *ior_file = 0;
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_file = get_opts.opt_arg ();
20 break;
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 ACE_TEXT ("Usage: %s ")
24 ACE_TEXT ("-o IOR\n"),
25 argv[0]),
26 -1);
29 return 0;
32 int
33 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
35 try
37 CORBA::ORB_var orb =
38 CORBA::ORB_init (argc, argv);
40 CORBA::Object_var poa_object =
41 orb->resolve_initial_references ("RootPOA");
43 if (CORBA::is_nil (poa_object.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 ACE_TEXT ("SERVER: Unable to initialize the POA.\n")),
46 1);
48 PortableServer::POA_var root_poa =
49 PortableServer::POA::_narrow (poa_object.in ());
51 PortableServer::POAManager_var poa_manager =
52 root_poa->the_POAManager ();
54 if (::parse_args (argc, argv) != 0)
55 return -1;
57 // Servant
58 test_i *servant = 0;
59 ACE_NEW_RETURN (servant,
60 test_i (0, orb.in ()),
61 -1);
62 PortableServer::ServantBase_var safe (servant);
64 PortableServer::ObjectId_var oid =
65 root_poa->activate_object (servant);
67 CORBA::Object_var obj =
68 root_poa->servant_to_reference (servant);
70 CORBA::String_var ior =
71 orb->object_to_string (obj.in ());
73 ACE_DEBUG ((LM_DEBUG,
74 ACE_TEXT ("SERVER: test_i servant: <%C>\n"),
75 ior.in ()));
77 poa_manager->activate ();
79 // IOR
80 FILE *output_file= ACE_OS::fopen (ior_file, "w");
81 if (output_file == 0)
82 ACE_ERROR_RETURN ((LM_ERROR,
83 ACE_TEXT ("SERVER: Cannot open output file <%s> ")
84 ACE_TEXT ("for writting IOR: %C"),
85 ior_file,
86 ior.in ()),
87 1);
88 ACE_OS::fprintf (output_file, "%s", ior.in ());
89 ACE_OS::fclose (output_file);
91 // Run the ORB event loop.
92 orb->run ();
94 root_poa->destroy (true, true);
96 orb->destroy ();
98 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("SERVER: Event loop finished.\n")));
100 catch (const CORBA::Exception& ex)
102 ex._tao_print_exception ("Caught exception:");
103 return -1;
106 return 0;