Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Multiple / server.cpp
blobcedcde206be047ff91a8a525fe8aee4ef3276cd7
1 #include "Multiple_Impl.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
5 const ACE_TCHAR *ior_output_file = ACE_TEXT("test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'o':
17 ior_output_file = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-o <iorfile>"
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
34 int
35 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
37 try
39 // Orb Initialization
40 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "TAO");
42 CORBA::Object_var object;
43 object = orb->resolve_initial_references ("RootPOA");
45 PortableServer::POA_var poa = PortableServer::POA::_narrow(object.in());
47 // Get the POAManager
48 PortableServer::POAManager_var poa_manager = poa->the_POAManager();
50 if (parse_args (argc, argv) != 0)
51 return 1;
53 // Create the servant.
54 Bottom_Impl servant (orb.in ());
56 // Create the delegated servant and intialize it
57 // with the "real" servant.
58 PortableServer::ObjectId_var id = poa->activate_object (&servant);
59 CORBA::Object_var object_act = poa->id_to_reference (id.in ());
60 Delegated_Bottom_Impl delegated_servant(
61 Multiple::Bottom::_narrow (object_act.in ()),
62 orb.in ());
64 // Create the CORBA Object that is incarnated by the
65 // delegated servant.
66 id = poa->activate_object (&delegated_servant);
67 object_act = poa->id_to_reference (id.in ());
69 Multiple::Bottom_var bottom =
70 Multiple::Bottom::_narrow (object_act.in ());
72 // Now we stringify the object reference.
73 CORBA::String_var ior =
74 orb->object_to_string (bottom.in ());
76 ACE_DEBUG ((LM_DEBUG, "Activated as <%C>\n", ior.in ()));
78 // If the ior_output_file exists, output the ior to it
80 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
82 if (output_file == 0)
83 ACE_ERROR_RETURN ((LM_ERROR,
84 "Cannot open output file for writing IOR: %s",
85 ior_output_file),
86 1);
87 ACE_OS::fprintf (output_file, "%s", ior.in ());
88 ACE_OS::fclose (output_file);
90 // Activate the POAManager
91 poa_manager->activate();
93 orb->run();
95 catch (const CORBA::Exception& ex)
97 ex._tao_print_exception (
98 "Multiple Execution Interrupted Exception!\n");
99 return 1;
101 return 0;