3 #include "ace/streams.h"
5 int ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
8 // First initialize the ORB, that will remove some arguments...
10 CORBA::ORB_init (argc
, argv
);
12 // There must be at least two arguments, the first is the factory
13 // name, the rest are the names of the stock symbols we want to
16 cerr
<< "Usage: " << argv
[0]
17 << " Factory_IOR symbol symbol..." << endl
;
21 CORBA::Object_var poa_object
=
22 orb
->resolve_initial_references ("RootPOA");
23 PortableServer::POA_var poa
=
24 PortableServer::POA::_narrow (poa_object
.in ());
25 PortableServer::POAManager_var poa_manager
=
26 poa
->the_POAManager ();
27 poa_manager
->activate ();
29 // Use the first argument to create the factory object reference,
30 // in real applications we use the naming service, but let's do
31 // the easy part first!
32 CORBA::Object_var factory_object
=
33 orb
->string_to_object (argv
[1]);
35 // Now downcast the object reference to the appropriate type
36 Quoter::Stock_Factory_var factory
=
37 Quoter::Stock_Factory::_narrow (factory_object
.in ());
39 // Create and activate the handler...
40 int response_count
= 0;
41 Single_Query_Stock_Handler_i
handler_i (&response_count
);
42 Quoter::AMI_Single_Query_StockHandler_var handler
=
45 // Send all the requests, careful with error handling
46 int request_count
= 0;
47 for (int i
= 2; i
!= argc
; ++i
) {
49 // Get the stock object
50 Quoter::Stock_var tmp
=
51 factory
->get_stock (ACE_TEXT_ALWAYS_CHAR (argv
[i
]));
52 Quoter::Single_Query_Stock_var stock
=
53 Quoter::Single_Query_Stock::_narrow (tmp
.in ());
54 if (CORBA::is_nil (stock
.in ())) {
55 cerr
<< "Cannot get single query interface for <"
56 << argv
[i
] << ">" << endl
;
59 stock
->sendc_get_price_and_names (handler
.in ());
62 catch (Quoter::Invalid_Stock_Symbol
&) {
63 cerr
<< "Invalid stock symbol <"
64 << argv
[i
] << ">" << endl
;
68 while (response_count
< request_count
69 && orb
->work_pending ()) {
73 // Destroy the POA, waiting until the destruction terminates
74 poa
->destroy (true, true);
77 catch (const CORBA::Exception
&) {
78 cerr
<< "CORBA exception raised!" << endl
;