2 #include "Stock_Factory_i.h"
3 #include "orbsvcs/CosNamingC.h"
4 #include "ace/streams.h"
5 #include "ace/OS_NS_unistd.h"
7 int ACE_TMAIN (int argc
, ACE_TCHAR
* argv
[])
10 // First initialize the ORB, that will remove some arguments...
12 CORBA::ORB_init (argc
, argv
);
13 CORBA::Object_var poa_object
=
14 orb
->resolve_initial_references ("RootPOA");
15 PortableServer::POA_var poa
=
16 PortableServer::POA::_narrow (poa_object
.in ());
17 PortableServer::POAManager_var poa_manager
=
18 poa
->the_POAManager ();
19 poa_manager
->activate ();
22 Quoter_Stock_Factory_i stock_factory_i
;
24 // Activate it to obtain the object reference
25 Quoter::Stock_Factory_var stock_factory
=
26 stock_factory_i
._this ();
28 // Get the Naming Context reference
29 CORBA::Object_var naming_context_object
=
30 orb
->resolve_initial_references ("NameService");
31 CosNaming::NamingContext_var naming_context
=
32 CosNaming::NamingContext::_narrow (naming_context_object
.in ());
34 // Create and initialize the name.
35 CosNaming::Name
name (1);
37 name
[0].id
= CORBA::string_dup ("Stock_Factory");
40 naming_context
->rebind (name
, stock_factory
.in ());
42 // Resolve the Event Service
43 name
[0].id
= CORBA::string_dup ("CosEventService");
45 CORBA::Object_var ec_object
=
46 naming_context
->resolve (name
);
48 // Now downcast the object reference to the appropriate type
49 CosEventChannelAdmin::EventChannel_var ec
=
50 CosEventChannelAdmin::EventChannel::_narrow (ec_object
.in ());
52 CosEventChannelAdmin::SupplierAdmin_var supplier_admin
=
55 stock_factory_i
.load_stock_objects (poa
.in (),
57 supplier_admin
.in ());
59 // ****************************************************************
61 for (int j
= 0; j
!= 1000; ++j
) {
62 for (int i
= 1; i
!= argc
; ++i
) {
64 // Get the stock object
65 Quoter::Stock_var stock
=
66 stock_factory
->get_stock (ACE_TEXT_ALWAYS_CHAR (argv
[i
]));
68 CORBA::String_var full_name
= stock
->full_name ();
71 CORBA::Double price
= stock
->price ();
73 Quoter::Modify_Stock_var modify_stock
=
74 Quoter::Modify_Stock::_narrow (stock
.in ());
75 modify_stock
->set_price (price
+ 1);
77 cout
<< "Set the price of "
79 << " to " << price
+ 1 << endl
;
81 catch (Quoter::Invalid_Stock_Symbol
&) {
82 cerr
<< "Invalid stock symbol <"
83 << argv
[i
] << ">" << endl
;
85 ACE_Time_Value
tv (0, 500000);
90 stock_factory_i
.destroy_stock_objects ();
92 // Destroy the POA, waiting until the destruction terminates
93 poa
->destroy (true, true);
96 catch (const CORBA::Exception
&) {
97 cerr
<< "CORBA exception raised!" << endl
;