Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Bug_1330_Regression / server.cpp
blobe27dc78b513dc0ea4f0ea644f9cb0acabb8a2376
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_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 'o':
20 ior_file = get_opts.opt_arg ();
21 break;
22 case 'k':
23 object_key = get_opts.opt_arg ();
24 break;
25 case '?':
26 default:
27 ACE_ERROR_RETURN ((LM_ERROR,
28 "SERVER (%P): usage: %s "
29 "-k <object key> "
30 "-o <ior>"
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[])
43 try
45 CORBA::ORB_var orb =
46 CORBA::ORB_init (argc, argv);
48 CORBA::Object_var poa_object =
49 orb->resolve_initial_references ("RootPOA");
51 if (CORBA::is_nil (poa_object.in ()))
52 ACE_ERROR_RETURN ((LM_ERROR,
53 "SERVER (%P): Unable to initialize the POA.\n"),
54 1);
56 PortableServer::POA_var root_poa =
57 PortableServer::POA::_narrow (poa_object.in ());
59 PortableServer::POAManager_var poa_manager =
60 root_poa->the_POAManager ();
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 Test_i *server_impl = 0;
66 ACE_NEW_RETURN (server_impl,
67 Test_i (orb.in ()),
68 1);
69 PortableServer::ServantBase_var owner_transfer(server_impl);
71 PortableServer::ObjectId_var id =
72 root_poa->activate_object (server_impl);
74 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
76 CORBA::Object_var server = CORBA::Object::_narrow (object.in ());
78 CORBA::String_var ior =
79 orb->object_to_string (server.in ());
81 CORBA::Object_var table_object =
82 orb->resolve_initial_references ("IORTable");
84 IORTable::Table_var adapter =
85 IORTable::Table::_narrow (table_object.in ());
87 adapter->bind("Name-with-hyphens", ior.in());
89 FILE *output_file= ACE_OS::fopen (ior_file, "w");
90 if (output_file == 0)
91 ACE_ERROR_RETURN ((LM_ERROR,
92 "SERVER (%P): Cannot open output file "
93 "for writing IOR: %s",
94 ior_file),
95 1);
96 ACE_OS::fprintf (output_file, "%s", ior.in ());
97 ACE_OS::fclose (output_file);
99 ACE_DEBUG ((LM_DEBUG,
100 "SERVER (%P): Activated as file://%s\n",
101 ior_file));
103 poa_manager->activate();
105 orb->run ();
107 root_poa->destroy (1, 1);
109 orb->destroy ();
111 catch (const CORBA::Exception& ex)
113 ex._tao_print_exception ("SERVER (%P): Caught exception:");
114 return 1;
117 return 0;