blob: 069664b64c3ee67d4bb243eb0e65b389c70818fc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
#include "tao/Strategies/advanced_resource.h"
// Stock Quoter Stub
#include "Stock_QuoterC.h"
#include "UDPTestC.h"
#include "ace/streams.h"
#include "ace/Task.h"
class OrbTask : public ACE_Task_Base
{
public:
OrbTask(const CORBA::ORB_ptr orb)
: orb_(CORBA::ORB::_duplicate(orb))
{
}
virtual int svc()
{
try
{
this->orb_->run ();
}
catch (const CORBA::Exception&)
{
}
return 0;
}
private:
CORBA::ORB_var orb_;
};
static int n_threads = 1;
unsigned char Msg[1000] = { 0 } ;
int ACE_TMAIN (int argc, ACE_TCHAR *argv[])
{
try
{
// Initialize the ORB
CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
// Use a simple ObjectKey to access the Stock Quoter.
// (Client ORB must be initialized with
// -ORBInitRef MyStockQuoter=corbaloc:...)
CORBA::Object_var udp_obj =
orb->resolve_initial_references ("UDPTest");
CORBA::Object_var stock_quoter_obj =
orb->resolve_initial_references ("MyStockQuoter");
OrbTask task(orb.in());
if (task.activate (THR_NEW_LWP | THR_JOINABLE,
n_threads) != 0)
ACE_ERROR_RETURN ((LM_ERROR,
"Cannot activate threads\n"),
1);
UDPTestI_var server = UDPTestI::_narrow (udp_obj.in ());
Stock_Quoter_var quoter = Stock_Quoter::_narrow (stock_quoter_obj.in());
memset( Msg, 1, 1000 ) ;
//UDP->send( 10 ) ;
server->send( Msg ) ;
try
{
CORBA::Float current_stock_price = quoter->get_quote ("BA");
cout << "Stock Id: BA, Price = " << current_stock_price << endl;
}
catch (Bad_Ticker_Symbol& e)
{
cerr << "Caught a bad ticker symbol exception: "
<< e.symbol << endl;;
}
quoter->shutdown ();
task.wait();
orb->destroy ();
}
catch (const CORBA::Exception& e)
{
e._tao_print_exception ("Exception caught:");
return 1;
}
return 0;
}
|