Merge pull request #1551 from DOCGroup/plm_jira_333
[ACE_TAO.git] / TAO / examples / Callback_Quoter / Supplier_Timer_Handler.cpp
blob23ec944277bd18902cca38d8cf808689abf5271b
1 //=============================================================================
2 /**
3 * Implementation of the Supplier_Time_Handler class.
5 * @author Kirthika Parameswaran <kirthika@cs.wustl.edu>
6 */
7 //=============================================================================
10 #include "ace/ACE.h"
12 #include "Supplier_Timer_Handler.h"
14 // The supplier refernce is got so that the mathods in the supplier
15 // can be accessed.
17 Supplier_Timer_Handler:: Supplier_Timer_Handler (Supplier *supplier,
18 ACE_Reactor *reactor,
19 FILE *file_ptr)
20 :supplier_obj_ (supplier),
21 reactor_ (reactor),
22 file_ptr_ (file_ptr)
24 // No-op.
27 // Destructor.
29 Supplier_Timer_Handler::~Supplier_Timer_Handler (void)
31 // No-op.
34 // Method which will be called by the reactor on timeout.
36 int
37 Supplier_Timer_Handler:: handle_timeout (const ACE_Time_Value & /* tv */,
38 const void * /* arg */)
41 ACE_DEBUG ((LM_DEBUG,
42 "Sending Stock Market Information to Notifier...\n"));
44 // The next current stock rates are obtained from a file.
45 if (this->get_stock_information () == -1)
46 return 0;
49 // Send the stock information to the notifier. Graceful exit when
50 // the notifier doesnt accept the information.
51 if (this->supplier_obj_->send_market_status (stockname_,
52 value_) < 0)
54 this->reactor_->end_event_loop ();
55 ACE_ERROR_RETURN ((LM_ERROR,
56 "handle_timeout: send_market_status failed! %p\n",
57 "send_market_status"),
58 -1);
61 return 0;
64 // Get the stock information from a file.
66 int
67 Supplier_Timer_Handler::get_stock_information (void)
69 // Scan the file and obtain the stock information.
70 if (fscanf (file_ptr_,
71 "%s %ld\n",
72 stockname_,
73 &value_) != EOF)
75 ACE_DEBUG ((LM_DEBUG,
76 "Stockname: %s, Stockvalue: %d\n",
77 stockname_,
78 value_));
79 return 0;
81 else
83 // Close down the Reactor.
84 this->reactor_->end_event_loop ();
85 return -1;