Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / docs / tutorials / Quoter / RT_Event_Service / server.cpp
blob331ec2bbfddbb5eed22bd6c79b18ba4dded954a7
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[])
9 try {
10 // First initialize the ORB, that will remove some arguments...
11 CORBA::ORB_var orb =
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 ();
21 // Create the servant
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);
36 name.length (1);
37 name[0].id = CORBA::string_dup ("Stock_Factory");
39 // Bind the object
40 naming_context->rebind (name, stock_factory.in ());
42 // Resolve the Event Service
43 name[0].id = CORBA::string_dup ("EventService");
45 CORBA::Object_var ec_object =
46 naming_context->resolve (name);
48 // Now downcast the object reference to the appropriate type
49 RtecEventChannelAdmin::EventChannel_var ec =
50 RtecEventChannelAdmin::EventChannel::_narrow (ec_object.in ());
52 RtecEventChannelAdmin::SupplierAdmin_var supplier_admin =
53 ec->for_suppliers ();
55 stock_factory_i.load_stock_objects (poa.in (),
56 poa_manager.in (),
57 supplier_admin.in ());
59 // ****************************************************************
61 for (int j = 0; j != 1000; ++j) {
62 for (int i = 1; i != argc; ++i) {
63 try {
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 ();
70 // Get the price
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 "
78 << full_name.in ()
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);
86 ACE_OS::sleep (tv);
90 stock_factory_i.destroy_stock_objects ();
92 // Destroy the POA, waiting until the destruction terminates
93 poa->destroy (true, true);
94 orb->destroy ();
96 catch (const CORBA::Exception &) {
97 cerr << "CORBA exception raised!" << endl;
99 return 0;