Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / Big_Oneways / client.cpp
blobf0520bcce14196d10f48c9826645235ebabb0b71
1 #include "Peer.h"
2 #include "ace/Get_Opt.h"
3 #include "ace/Thread_Manager.h"
5 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 int
8 parse_args (int argc, ACE_TCHAR *argv[])
10 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:"));
11 int c;
13 while ((c = get_opts ()) != -1)
14 switch (c)
16 case 'k':
17 ior = get_opts.opt_arg ();
18 break;
20 case '?':
21 default:
22 ACE_ERROR_RETURN ((LM_ERROR,
23 "usage: %s "
24 "-k <ior> "
25 "\n",
26 argv [0]),
27 -1);
29 // Indicates successful parsing of the command line
30 return 0;
33 int
34 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
36 try
38 CORBA::ORB_var orb =
39 CORBA::ORB_init (argc, argv);
41 CORBA::Object_var poa_object =
42 orb->resolve_initial_references("RootPOA");
44 PortableServer::POA_var root_poa =
45 PortableServer::POA::_narrow (poa_object.in ());
47 if (CORBA::is_nil (poa_object.in ()))
48 ACE_ERROR_RETURN ((LM_ERROR,
49 " (%P|%t) Panic got a nil RootPOA\n"),
50 1);
52 PortableServer::POAManager_var poa_manager =
53 root_poa->the_POAManager ();
55 if (parse_args (argc, argv) != 0)
56 return 1;
58 CORBA::Object_var tmp =
59 orb->string_to_object(ior);
61 Test::Coordinator_var coordinator =
62 Test::Coordinator::_narrow(tmp.in ());
64 if (CORBA::is_nil (coordinator.in ()))
66 ACE_ERROR_RETURN ((LM_DEBUG,
67 "Nil coordinator reference <%s>\n",
68 ior),
69 1);
72 Peer *peer_impl = 0;
73 ACE_NEW_RETURN (peer_impl,
74 Peer (orb.in ()),
75 1);
76 PortableServer::ServantBase_var peer_owner_transfer(peer_impl);
78 PortableServer::ObjectId_var id =
79 root_poa->activate_object (peer_impl);
81 CORBA::Object_var object = root_poa->id_to_reference (id.in ());
83 Test::Peer_var peer =
84 Test::Peer::_narrow (object.in ());
86 poa_manager->activate ();
88 coordinator->add_peer (peer.in ());
90 orb->run ();
92 // Wait for all the threads.
93 ACE_Thread_Manager::instance ()->wait ();
95 root_poa->destroy (1, 1);
97 orb->destroy ();
99 catch (const CORBA::Exception& ex)
101 ex._tao_print_exception ("Exception caught:");
102 return 1;
105 return 0;