Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / LongUpcalls / ami_client.cpp
blob2d6e7732715d7c97dfae01ce16516bcdcd27fd37
1 #include "ace/Get_Opt.h"
2 #include "Controller.h"
3 #include "Manager_Handler.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;
19 case '?':
20 default:
21 ACE_ERROR_RETURN ((LM_ERROR,
22 "usage: %s "
23 "-k <ior>"
24 "\n",
25 argv [0]),
26 -1);
28 // Indicates successful parsing of the command line
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 CORBA::Object_var object =
41 orb->resolve_initial_references("RootPOA");
43 if (CORBA::is_nil (object.in ()))
44 ACE_ERROR_RETURN ((LM_ERROR,
45 " (%P|%t) Unable to initialize the POA.\n"),
46 1);
48 PortableServer::POA_var root_poa =
49 PortableServer::POA::_narrow (object.in ());
51 PortableServer::POAManager_var poa_manager =
52 root_poa->the_POAManager ();
54 if (parse_args (argc, argv) != 0)
55 return 1;
57 Controller controller_impl;
59 PortableServer::ObjectId_var id =
60 root_poa->activate_object (&controller_impl);
62 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
64 Test::Controller_var controller =
65 Test::Controller::_narrow (object_act.in ());
67 object = orb->string_to_object (ior);
69 Test::Manager_var manager =
70 Test::Manager::_narrow (object.in ());
72 if (CORBA::is_nil (manager.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "Manager is nil\n"),
75 1);
77 Manager_Handler handler_impl (manager.in (),
78 controller.in ());
80 id = root_poa->activate_object (&handler_impl);
82 object_act = root_poa->id_to_reference (id.in ());
84 Test::AMI_ManagerHandler_var handler =
85 Test::AMI_ManagerHandler::_narrow (object_act.in ());
87 poa_manager->activate ();
89 const CORBA::Short worker_count = 10;
90 manager->sendc_start_workers (handler.in (),
91 worker_count,
92 CORBA::Long (1000),
93 controller.in ());
95 ACE_Time_Value tv (30, 0);
96 orb->run (tv);
98 controller_impl.dump_results ();
100 manager->shutdown ();
102 root_poa->destroy (1, 1);
104 orb->destroy ();
106 catch (const CORBA::Exception& ex)
108 ex._tao_print_exception ("Exception caught:");
109 return 1;
112 return 0;