Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / Bug_3547_Regression / Stock_Quoter_Client.cpp
blob358363115d0245d605472732c70c21b86691ce61
1 #include "tao/Strategies/advanced_resource.h"
3 // Stock Quoter Stub
4 #include "Stock_QuoterC.h"
5 #include "UDPTestC.h"
6 #include "ace/streams.h"
7 #include "ace/Task.h"
9 class OrbTask : public ACE_Task_Base
11 public:
12 OrbTask(const CORBA::ORB_ptr orb)
13 : orb_(CORBA::ORB::_duplicate(orb))
17 virtual int svc()
19 try
21 this->orb_->run ();
23 catch (const CORBA::Exception&)
26 return 0;
29 private:
30 CORBA::ORB_var orb_;
33 static int n_threads = 1;
35 unsigned char Msg[1000] = { 0 } ;
37 int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
39 try
41 // Initialize the ORB
42 CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
44 // Use a simple ObjectKey to access the Stock Quoter.
45 // (Client ORB must be initialized with
46 // -ORBInitRef MyStockQuoter=corbaloc:...)
47 CORBA::Object_var udp_obj =
48 orb->resolve_initial_references ("UDPTest");
50 CORBA::Object_var stock_quoter_obj =
51 orb->resolve_initial_references ("MyStockQuoter");
53 OrbTask task(orb.in());
55 if (task.activate (THR_NEW_LWP | THR_JOINABLE,
56 n_threads) != 0)
57 ACE_ERROR_RETURN ((LM_ERROR,
58 "Cannot activate threads\n"),
59 1);
61 UDPTestI_var server = UDPTestI::_narrow (udp_obj.in ());
63 Stock_Quoter_var quoter = Stock_Quoter::_narrow (stock_quoter_obj.in());
65 memset(Msg, 1, 1000);
66 //UDP->send( 10 );
68 server->send(Msg);
70 try
72 CORBA::Float current_stock_price = quoter->get_quote ("BA");
73 cout << "Stock Id: BA, Price = " << current_stock_price << endl;
75 catch (Bad_Ticker_Symbol& e)
77 cerr << "Caught a bad ticker symbol exception: "
78 << e.symbol << endl;
81 quoter->shutdown ();
83 task.wait();
85 orb->destroy ();
87 catch (const CORBA::Exception& e)
89 e._tao_print_exception ("Exception caught:");
90 return 1;
93 return 0;