Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / TAO / examples / Callback_Quoter / Supplier_Timer_Handler.cpp
blobb984aa94fc71ea4cbbab2125a350207fe34e7a52
1 //=============================================================================
2 /**
3 * Implementation of the Supplier_Time_Handler class.
5 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
6 */
7 //=============================================================================
9 #include "ace/ACE.h"
10 #include "Supplier_Timer_Handler.h"
12 // The supplier refernce is got so that the mathods in the supplier
13 // can be accessed.
14 Supplier_Timer_Handler:: Supplier_Timer_Handler (Supplier *supplier,
15 ACE_Reactor *reactor,
16 FILE *file_ptr)
17 :supplier_obj_ (supplier),
18 reactor_ (reactor),
19 file_ptr_ (file_ptr)
23 // Method which will be called by the reactor on timeout.
24 int
25 Supplier_Timer_Handler:: handle_timeout (const ACE_Time_Value & /* tv */,
26 const void * /* arg */)
28 ACE_DEBUG ((LM_DEBUG,
29 "Sending Stock Market Information to Notifier...\n"));
31 // The next current stock rates are obtained from a file.
32 if (this->get_stock_information () == -1)
33 return 0;
36 // Send the stock information to the notifier. Graceful exit when
37 // the notifier doesnt accept the information.
38 if (this->supplier_obj_->send_market_status (stockname_,
39 value_) < 0)
41 this->reactor_->end_event_loop ();
42 ACE_ERROR_RETURN ((LM_ERROR,
43 "handle_timeout: send_market_status failed! %p\n",
44 "send_market_status"),
45 -1);
48 return 0;
51 // Get the stock information from a file.
52 int
53 Supplier_Timer_Handler::get_stock_information ()
55 // Scan the file and obtain the stock information.
56 if (fscanf (file_ptr_,
57 "%s %ld\n",
58 stockname_,
59 &value_) != EOF)
61 ACE_DEBUG ((LM_DEBUG,
62 "Stockname: %s, Stockvalue: %d\n",
63 stockname_,
64 value_));
65 return 0;
67 else
69 // Close down the Reactor.
70 this->reactor_->end_event_loop ();
71 return -1;