Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3553_Regression / Bug_3553_Regression_server.cpp
blob03804c90c661c7dbe6188466941409c5bf6103b5
1 #include "Hello.h"
2 #include "ace/Get_Opt.h"
3 #include "tao/IORTable/IORTable.h"
5 int cache_size = 512;
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("c:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'c':
17 cache_size = ACE_OS::atoi (get_opts.opt_arg ());
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-c <transport_cache_size> "
25 "\n",
26 argv [0]),
27 -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 if (parse_args(argc, argv) != 0)
41 return 1;
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 if (CORBA::is_nil (root_poa.in ()))
50 ACE_ERROR_RETURN ((LM_ERROR,
51 " (%P|%t) Panic: nil RootPOA\n"),
52 1);
54 Hello *hello_impl = 0;
55 ACE_NEW_RETURN (hello_impl,
56 Hello (orb.in ()),
57 1);
59 PortableServer::ObjectId_var id =
60 root_poa->activate_object (hello_impl);
62 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
64 Test::Hello_var hello = Test::Hello::_narrow (object.in ());
66 CORBA::Object_var table_obj = orb->resolve_initial_references("IORTable");
67 IORTable::Table_var table = IORTable::Table::_narrow(table_obj.in());
68 for (int i = 1; i <= cache_size; ++i)
70 CORBA::String_var ior_string = orb->object_to_string (object.in());
71 ACE_DEBUG((LM_DEBUG, ACE_TEXT("Registering object %d with IOR string: %C\n"),
72 i, ior_string.in ()));
73 char identifier[256];
74 ACE_OS::sprintf (identifier, "TransportCacheTest%d", i);
75 table->bind(identifier, ior_string.in());
78 PortableServer::POAManager_var poa_manager = root_poa->the_POAManager ();
79 poa_manager->activate ();
81 orb->run ();
83 ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n"));
85 root_poa->destroy (true, true);
87 orb->destroy ();
89 catch (const CORBA::Exception& ex)
91 ex._tao_print_exception ("Exception caught:");
92 return 1;
95 return 0;