Revert "Minor modernization of DynamicAny code"
[ACE_TAO.git] / TAO / tests / Bug_1627_Regression / server.cpp
blobd141443a91ff8a54ed2b8eb1a5535f2d6d1e6e6c
1 #include "ace/Get_Opt.h"
2 #include "ace/OS_NS_stdio.h"
3 #include "Test_i.h"
5 #include "tao/IORTable/IORTable.h"
7 const ACE_TCHAR *object_key = 0;
8 const ACE_TCHAR *ior_output_file = ACE_TEXT("server.ior");
10 int
11 parse_args (int argc, ACE_TCHAR *argv[])
13 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:k:"));
14 int c;
16 while ((c = get_opts ()) != -1)
17 switch (c)
19 case 'k':
20 object_key = get_opts.opt_arg ();
21 break;
22 case 'o':
23 ior_output_file = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "SERVER (%P): usage: %s "
29 "-o <ior output file>"
30 "-k <object key>"
31 "\n",
32 argv [0]),
33 -1);
35 // Indicates successful parsing of the command line
36 return 0;
39 int
40 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
42 try
44 CORBA::ORB_var orb =
45 CORBA::ORB_init (argc, argv);
47 CORBA::Object_var poa_object =
48 orb->resolve_initial_references ("RootPOA");
50 if (CORBA::is_nil (poa_object.in ()))
51 ACE_ERROR_RETURN ((LM_ERROR,
52 "SERVER (%P): Unable to initialize the POA.\n"),
53 1);
55 PortableServer::POA_var root_poa =
56 PortableServer::POA::_narrow (poa_object.in ());
58 PortableServer::POAManager_var poa_manager =
59 root_poa->the_POAManager ();
61 if (parse_args (argc, argv) != 0)
62 return 1;
64 Test_i server_impl;
66 PortableServer::ObjectId_var id =
67 root_poa->activate_object (&server_impl);
69 CORBA::Object_var server = root_poa->id_to_reference (id.in ());
71 CORBA::String_var ior =
72 orb->object_to_string (server.in ());
74 CORBA::Object_var table_object =
75 orb->resolve_initial_references ("IORTable");
77 IORTable::Table_var adapter =
78 IORTable::Table::_narrow (table_object.in ());
80 adapter->bind("Name-with-hyphens", ior.in());
83 FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
84 if (output_file == 0)
85 ACE_ERROR_RETURN ((LM_ERROR,
86 "SERVER (%P): Cannot open output file "
87 "for writing IOR: %s",
88 ior_output_file),
89 1);
90 ACE_OS::fprintf (output_file, "%s", ior.in ());
91 ACE_OS::fclose (output_file);
93 ACE_DEBUG ((LM_DEBUG,
94 "SERVER (%P): Activated as file://%s\n",
95 ior_output_file));
97 poa_manager->activate();
99 orb->run ();
101 root_poa->destroy (true, true);
103 catch (const CORBA::Exception& ex)
105 ex._tao_print_exception ("SERVER (%P): Caught exception:");
106 return 1;
109 return 0;