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
95
96
97
98
99
100
101
|
// $Id$
// ===========================================================
//
//
// = LIBRARY
// TAO/examples/Callback_Quoter
//
// = FILENAME
// Supplier_Time _Handler.cpp
//
// = DESCRIPTION
// Implementation of the Supplier_Time_Handler class.
//
// = AUTHOR
// Kirthika Parameswaran <kirthika@cs.wustl.edu>
//
// ===========================================================
#include "ace/OS.h"
#include "ace/ACE.h"
#include "Supplier_Timer_Handler.h"
ACE_RCSID(Callback_Quoter, Supplier, "$Id$")
// The supplier refernce is got so that the mathods in the supplier
// can be accessed.
Supplier_Timer_Handler:: Supplier_Timer_Handler (Supplier *supplier,
ACE_Reactor *reactor,
FILE *file_ptr)
:supplier_obj_ (supplier),
reactor_ (reactor),
file_ptr_ (file_ptr)
{
// No-op.
}
// Destructor.
Supplier_Timer_Handler::~Supplier_Timer_Handler (void)
{
// No-op.
}
// Method which will be called by the reactor on timeout.
int
Supplier_Timer_Handler:: handle_timeout (const ACE_Time_Value & /* tv */,
const void * /* arg */)
{
ACE_DEBUG ((LM_DEBUG,
"Sending Stock Market Information to Notifier...\n"));
// The next current stock rates are obtained from a file.
if (this->get_stock_information () == -1)
return 0;
// Send the stock information to the notifier. Graceful exit when
// the notifier doesnt accept the information.
if (this->supplier_obj_->send_market_status (stockname_,
value_) < 0)
{
this->reactor_->end_event_loop ();
ACE_ERROR_RETURN ((LM_ERROR,
"handle_timeout: send_market_status failed! %p\n",
"send_market_status"),
-1);
}
return 0;
}
// Get the stock information from a file.
int
Supplier_Timer_Handler::get_stock_information (void)
{
// Scan the file and obtain the stock information.
if (fscanf (file_ptr_,
"%s %ld\n",
stockname_,
&value_) != EOF)
{
ACE_DEBUG ((LM_DEBUG,
"Stockname: %s, Stockvalue: %d\n",
stockname_,
value_));
return 0;
}
else
{
// Close down the Reactor.
this->reactor_->end_event_loop ();
return -1;
}
}
|