diff options
Diffstat (limited to 'TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp')
-rw-r--r-- | TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp | 73 |
1 files changed, 54 insertions, 19 deletions
diff --git a/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp b/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp index fb543fee388..d86e7b5c4d1 100644 --- a/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp +++ b/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.cpp @@ -17,50 +17,85 @@ // =========================================================== #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) +// 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) + reactor_ (reactor), + file_ptr_ (file_ptr) { + // No-op. } -//destructor. +// 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) { - long value; - char stock_name[BUFSIZ]; - - value = 10; - ACE_OS::strcpy(stock_name,"Ernst&Young"); ACE_DEBUG ((LM_DEBUG, - "sending data from handle_timeout to notifier!\n")); + "Sending Stock Market Information to Notifier... \n")); - if (this->supplier_obj_->send_market_status (stock_name, value) < 0) + // 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); + 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; + } +} + |