diff options
author | kirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-11-04 03:01:10 +0000 |
---|---|---|
committer | kirthika <kirthika@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-11-04 03:01:10 +0000 |
commit | ad1438c95513d3f9d1098e045f914c8ed1823137 (patch) | |
tree | 4b13f104224ced53bd9a01bccbaf525519663344 /TAO/examples | |
parent | 2dc80b7c323c3d86e5c3bd17780d33156a121721 (diff) | |
download | ATCD-ad1438c95513d3f9d1098e045f914c8ed1823137.tar.gz |
working version
Diffstat (limited to 'TAO/examples')
20 files changed, 331 insertions, 236 deletions
diff --git a/TAO/examples/Callback_Quoter/Consumer.idl b/TAO/examples/Callback_Quoter/Consumer.idl index cca63d1d426..e4a5604b4b2 100644 --- a/TAO/examples/Callback_Quoter/Consumer.idl +++ b/TAO/examples/Callback_Quoter/Consumer.idl @@ -15,11 +15,13 @@ module Callback_Quoter // = TITLE // Requested stock does not exist }; + exception Invalid_Handle { // = TITLE // Requested stock does not exist }; + struct Info { // = TITLE diff --git a/TAO/examples/Callback_Quoter/Consumer_Handler.cpp b/TAO/examples/Callback_Quoter/Consumer_Handler.cpp index 5018ffc709d..9f85f5ea54f 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Handler.cpp +++ b/TAO/examples/Callback_Quoter/Consumer_Handler.cpp @@ -1,4 +1,5 @@ // $Id$ + // =========================================================== // // @@ -25,7 +26,7 @@ #include <ace/Reactor.h> #include <ace/Event_Handler.h> -Consumer_Handler::Consumer_Handler () +Consumer_Handler::Consumer_Handler (void) : stock_name_ ("Unknown"), threshold_value_ (0), server_ (), @@ -37,7 +38,7 @@ Consumer_Handler::Consumer_Handler () } -Consumer_Handler::~Consumer_Handler () +Consumer_Handler::~Consumer_Handler (void) { // Make sure to cleanup the STDIN handler. @@ -47,13 +48,6 @@ Consumer_Handler::~Consumer_Handler () ACE_ERROR ((LM_ERROR, "%p\n", "remove_stdin_handler")); - - /*if (reactor_used()->remove_handler (consumer_signal_handler_, - ACE_Event_Handler::READ_MASK) == -1) - ACE_ERROR ((LM_ERROR, - "%p\n", - "removal of signal handler\n"));*/ - } // Reads the Server factory IOR from a file. @@ -264,12 +258,10 @@ Consumer_Handler::init (int argc, char **argv) "invalid ior <%s>\n", this->ior_), -1); - - // The downcasting from CORBA::Object_var to Notifier_var is done - // using the <_narrow> method. + // The downcasting from CORBA::Object_var to Notifier_var is + // done using the <_narrow> method. this->server_ = Notifier::_narrow (server_object.in (), TAO_TRY_ENV); - TAO_CHECK_ENV; } TAO_CATCHANY @@ -282,7 +274,6 @@ Consumer_Handler::init (int argc, char **argv) return 0; } - int Consumer_Handler::run (void) { @@ -323,5 +314,8 @@ Consumer_Handler::run (void) ACE_Reactor * Consumer_Handler::reactor_used (void) const { - return (TAO_ORB_Core_instance ()->reactor ()); + // @@ Please check with Pradeep and see how to remove the reliance + // on <TAO_ORB_Core_instance()>. This is non-portable and we want + // to try to use only CORBA-compliant code in our examples. + return TAO_ORB_Core_instance ()->reactor (); } diff --git a/TAO/examples/Callback_Quoter/Consumer_Handler.h b/TAO/examples/Callback_Quoter/Consumer_Handler.h index e6ffb32c1a9..ee80fec7576 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Handler.h +++ b/TAO/examples/Callback_Quoter/Consumer_Handler.h @@ -52,14 +52,13 @@ class Consumer_Handler public: // = Initialization and termination methods. - Consumer_Handler (); + Consumer_Handler (void); // Constructor. - ~Consumer_Handler (); + ~Consumer_Handler (void); // Destructor. int init (int argc, char *argv[]); - // Initialize the client communication with the server. int run (void); diff --git a/TAO/examples/Callback_Quoter/Consumer_Input_Handler.cpp b/TAO/examples/Callback_Quoter/Consumer_Input_Handler.cpp index d2c81b50f58..45cd0662f5c 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Input_Handler.cpp +++ b/TAO/examples/Callback_Quoter/Consumer_Input_Handler.cpp @@ -180,27 +180,35 @@ Consumer_Input_Handler::quit_consumer_process () // Only if the consumer is registered and wants to shut // down, its necessary to unregister and then shutdown. - CORBA::Environment TAO_TRY_ENV; - TAO_TRY { if (consumer_handler_->unregistered_ != 1 && consumer_handler_->registered_ == 1) { - this->consumer_handler_->server_->unregister_callback (this->consumer_handler_->consumer_var_.in ()); + // If the notifier has exited and the consumer tries to call + // the unregister_callback method tehn an execption will be + // raised. Hence check for this case using TAO_TRY_ENV. + this->consumer_handler_->server_->unregister_callback (this->consumer_handler_->consumer_var_.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + ACE_DEBUG ((LM_DEBUG, " Consumer Unregistered \n ")); - TAO_CHECK_ENV; consumer_handler_->unregistered_ = 0; consumer_handler_->registered_ = 0; } this->consumer_handler_->consumer_servant_->shutdown (TAO_TRY_ENV); - - + TAO_CHECK_ENV; } TAO_CATCHANY { - TAO_TRY_ENV.print_exception ("Consumer_Input_Handler::quit_consumer_process()"); + // There would be an exception only if there is a communication + // failure between the notifier and consumer. On catching the + // exception proclaim the problem and do a graceful exit. + ACE_DEBUG ((LM_DEBUG, + "Communication failed!\n")); + this->consumer_handler_->consumer_servant_->shutdown (TAO_TRY_ENV); + return -1; } TAO_ENDTRY; diff --git a/TAO/examples/Callback_Quoter/Consumer_Input_Handler.h b/TAO/examples/Callback_Quoter/Consumer_Input_Handler.h index 6d8e350a554..dd98dec4d34 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Input_Handler.h +++ b/TAO/examples/Callback_Quoter/Consumer_Input_Handler.h @@ -47,19 +47,19 @@ class Consumer_Input_Handler : public ACE_Event_Handler // and receives the stock status from the Notifier. public: - - Consumer_Input_Handler (Consumer_Handler *consumer_handler); + Consumer_Input_Handler (Consumer_Handler *consumer_handler); + // Constructor. int handle_input (ACE_HANDLE); // Handle the user input. - int register_consumer (); + int register_consumer (void); // Registration with the notifier. - int unregister_consumer (); + int unregister_consumer (void); // Cancelling the registration with the notifier. - int quit_consumer_process (); + int quit_consumer_process (void); // Ends the consumer process. friend class ACE_Shutup_GPlusPlus; @@ -67,16 +67,30 @@ public: private: - ~Consumer_Input_Handler () + // @@ Please don't put implementations in the class headers... + ~Consumer_Input_Handler (void) { // No-op - } + } Consumer_Handler *consumer_handler_; // The Consumer_Handler object. }; +// @@ Please don't use #defines because they clutter up the global +// namespace. Instead, use enums, e.g., +// enum +// { +// REGISTER = 'r', +// UNREGISTER = 'u', +// EXIT = 'q' +// }; +// +// Please put this enum inside of class Consumer_Input_Handler. Note +// that you'll need to refer to these enumerals as +// Consumer_Input_Handler::REGISTER, etc. in order to be portable. + #define REGISTER 'r' // The character that the user must type to register the consumer with // the Notifier_server. diff --git a/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.cpp b/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.cpp index ad197822cb5..db8763f3dd1 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.cpp +++ b/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.cpp @@ -20,17 +20,19 @@ #include <Consumer_Signal_Handler.h> -Consumer_Signal_Handler:: Consumer_Signal_Handler (Consumer_Handler *consumer_handler) +Consumer_Signal_Handler::Consumer_Signal_Handler (Consumer_Handler *consumer_handler) + : consumer_handler_ (consumer_handler) { - consumer_handler_ = consumer_handler; } -Consumer_Signal_Handler:: ~Consumer_Signal_Handler () +Consumer_Signal_Handler:: ~Consumer_Signal_Handler (void) { } int -Consumer_Signal_Handler::handle_signal (int signum, siginfo_t*, ucontext_t*) +Consumer_Signal_Handler::handle_signal (int signum, + siginfo_t*, + ucontext_t*) { switch (signum) { @@ -51,7 +53,8 @@ Consumer_Signal_Handler::handle_signal (int signum, siginfo_t*, ucontext_t*) } int -Consumer_Signal_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) +Consumer_Signal_Handler::handle_close (ACE_HANDLE, + ACE_Reactor_Mask) { // End of the signal handler. delete this; @@ -61,25 +64,26 @@ Consumer_Signal_Handler::handle_close (ACE_HANDLE, ACE_Reactor_Mask) int -Consumer_Signal_Handler::quit_on_signal () +Consumer_Signal_Handler::quit_on_signal (void) { - // Only if the consumer is registered and wants to shut - // down, its necessary to unregister and then shutdown. + // Only if the consumer is registered and wants to shut down, its + // necessary to unregister and then shutdown. CORBA::Environment TAO_TRY_ENV; TAO_TRY { - if (consumer_handler_->unregistered_ != 1 && consumer_handler_->registered_ == 1) + if (consumer_handler_->unregistered_ != 1 + && consumer_handler_->registered_ == 1) { - this->consumer_handler_->server_->unregister_callback (this->consumer_handler_->consumer_var_.in ()); + this->consumer_handler_->server_->unregister_callback + (this->consumer_handler_->consumer_var_.in ()); ACE_DEBUG ((LM_DEBUG, " Consumer Unregistered \n ")); - TAO_CHECK_ENV; } - this->consumer_handler_->consumer_servant_->shutdown (TAO_TRY_ENV); - + this->consumer_handler_->consumer_servant_->shutdown + (TAO_TRY_ENV); } TAO_CATCHANY diff --git a/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.h b/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.h index e831ac5fa1f..8d35f5f89b5 100644 --- a/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.h +++ b/TAO/examples/Callback_Quoter/Consumer_Signal_Handler.h @@ -3,7 +3,6 @@ // =========================================================== // -// // = LIBRARY // TAO/examples/Callback_Quoter // @@ -26,19 +25,22 @@ #include <ace/Event_Handler.h> #include "Consumer_Handler.h" -// Creating a class to handle signal events. -// Since only signals need to be handled, only the handle_signal -// method is overlaoded. - class Consumer_Handler; class Consumer_Signal_Handler : public ACE_Event_Handler { - public: + // @@ Please make sure that all the other classes are documented. + // = TITLE + // Creating a class to handle signal events. + // + // = DESCRIPTION + // Since only signals need to be handled, only the <handle_signal> method + // is overlaoded. +public: Consumer_Signal_Handler (Consumer_Handler *consumer_handler); - // The consumer_handler refernce will be used to access - // the servant methods. + // The consumer_handler refernce will be used to access the servant + // methods. int handle_signal (int signum, siginfo_t*, @@ -46,28 +48,25 @@ class Consumer_Signal_Handler : public ACE_Event_Handler // This method takes action on an signal event. int handle_close (ACE_HANDLE handle, - ACE_Reactor_Mask close_mask); - // For removal of the signal handler from the dispatch tables. - // When the handle_signal () returns < 0 this method will - // be executed automatically. + ACE_Reactor_Mask close_mask); + // For removal of the signal handler from the dispatch tables. When + // the handle_signal () returns < 0 this method will be executed + // automatically. +private: friend class ACE_Shutup_GPlusPlus; // Turn off g++ warning -private: - - ~Consumer_Signal_Handler (); - // private destructor so that the signal handler is - // always created dynamically and hence the heap doesnt - // get corrupted. + ~Consumer_Signal_Handler (void); + // Private destructor so that the signal handler is always created + // dynamically and hence the heap doesnt get corrupted. - int quit_on_signal (); + int quit_on_signal (void); // Exit gracefully on a signal. Consumer_Handler *consumer_handler_; - // Reference to the Consumer_Handler which is used in - // accessing the servant methods.x - + // Reference to the Consumer_Handler which is used in accessing the + // servant methods. }; #endif /* CONSUMER_SIGNAL_HANDLER_H */ diff --git a/TAO/examples/Callback_Quoter/Consumer_i.cpp b/TAO/examples/Callback_Quoter/Consumer_i.cpp index e11ad6eaad2..b5b534f1b49 100644 --- a/TAO/examples/Callback_Quoter/Consumer_i.cpp +++ b/TAO/examples/Callback_Quoter/Consumer_i.cpp @@ -29,22 +29,22 @@ Consumer_i::~Consumer_i (void) void Consumer_i::push (const Callback_Quoter::Info &data, - CORBA::Environment &env) + CORBA::Environment &env) { // On getting the needed information you now proceed to the next // step, which could be obtaining the shares. + // @@ Please see if you can remove this. this->done_ = 1; ACE_DEBUG ((LM_DEBUG, "Selling 10,000 %s shares at %d!!\n", data.stock_name.in (), data.value)); - } void -Consumer_i::shutdown ( CORBA::Environment &) +Consumer_i::shutdown (CORBA::Environment &) { // Instruct the ORB to shutdown. @@ -58,7 +58,7 @@ Consumer_i::shutdown ( CORBA::Environment &) void Consumer_i::orb (CORBA::ORB_ptr o) { - // makes a copy of the ORB pointer. + // Makes a copy of the ORB pointer. this->orb_ = CORBA::ORB::_duplicate (o); } diff --git a/TAO/examples/Callback_Quoter/Consumer_i.h b/TAO/examples/Callback_Quoter/Consumer_i.h index dc00f6e919a..727eefe947c 100644 --- a/TAO/examples/Callback_Quoter/Consumer_i.h +++ b/TAO/examples/Callback_Quoter/Consumer_i.h @@ -50,6 +50,7 @@ public: // Set the ORB pointer. private: + // @@ Please see if you can remove this. int done_; // Denotes whether the information about the stock has been // received. diff --git a/TAO/examples/Callback_Quoter/Notifier.idl b/TAO/examples/Callback_Quoter/Notifier.idl index e026e52f5b2..9c340c416ef 100644 --- a/TAO/examples/Callback_Quoter/Notifier.idl +++ b/TAO/examples/Callback_Quoter/Notifier.idl @@ -9,17 +9,16 @@ interface Notifier { // = TITLE - // The Notifier interface in the Callback_Quoter example - // which contains the methods by which the consumer can - // register, unregister from the Notifier. - + // The Notifier interface in the Callback_Quoter example which + // contains the methods by which the consumer can register, + // unregister from the Notifier. void register_callback (in string stock_name, in long threshold_value, in Callback_Quoter::Consumer consumer_handler) raises (Callback_Quoter::Invalid_Stock); - // Register a distributed callback handler that is invoked - // when the given stock reaches the desired threshold value. + // Register a distributed callback handler that is invoked when the + // given stock reaches the desired threshold value. void unregister_callback (in Callback_Quoter::Consumer consumer_handler) raises (Callback_Quoter::Invalid_Handle); @@ -28,10 +27,10 @@ interface Notifier void market_status (in string stock_name, in long stock_value) raises (Callback_Quoter::Invalid_Stock); - // get market status. + // Get market status. void shutdown (); - // shuts the server down. + // Shuts the server down. }; #endif /* _NOTIFIER_IDL */ diff --git a/TAO/examples/Callback_Quoter/Notifier_Input_Handler.cpp b/TAO/examples/Callback_Quoter/Notifier_Input_Handler.cpp index 933670eb593..d3d613372fe 100644 --- a/TAO/examples/Callback_Quoter/Notifier_Input_Handler.cpp +++ b/TAO/examples/Callback_Quoter/Notifier_Input_Handler.cpp @@ -245,9 +245,9 @@ Notifier_Input_Handler::handle_input (ACE_HANDLE) if (tolower(buf[0]) == 'q') { - + // @@ Please remove this call if it's not used. // (this->notifier_i_.consumer_map_).close(); - this->notifier_i_.shutdown(TAO_TRY_ENV); + this->notifier_i_.shutdown (TAO_TRY_ENV); TAO_CHECK_ENV; } } @@ -258,5 +258,5 @@ Notifier_Input_Handler::handle_input (ACE_HANDLE) } TAO_ENDTRY; -return 0; + return 0; } diff --git a/TAO/examples/Callback_Quoter/Notifier_Input_Handler.h b/TAO/examples/Callback_Quoter/Notifier_Input_Handler.h index 62e171ba3fe..f2d7e27657c 100644 --- a/TAO/examples/Callback_Quoter/Notifier_Input_Handler.h +++ b/TAO/examples/Callback_Quoter/Notifier_Input_Handler.h @@ -29,8 +29,12 @@ class Notifier_Input_Handler : public ACE_Event_Handler { // = TITLE // The class defines the callback quoter Notifier initialization - // and and run methods. It sets up the Orb manager and registers - // the Notifier servant object. + // and run methods. + // + // = DESCRIPTION + // This class handles initialization tasks, as well, such as + // setting up the Orb manager and registers the Notifier servant + // object. public: // = Initialization and termination methods. Notifier_Input_Handler (void); diff --git a/TAO/examples/Callback_Quoter/Notifier_i.cpp b/TAO/examples/Callback_Quoter/Notifier_i.cpp index cf4f38a3899..b15dfc916e2 100644 --- a/TAO/examples/Callback_Quoter/Notifier_i.cpp +++ b/TAO/examples/Callback_Quoter/Notifier_i.cpp @@ -20,6 +20,7 @@ #include "Notifier_i.h" Notifier_i::Notifier_i (void) + : notifier_exited_(0) { // No-op } @@ -34,9 +35,9 @@ Notifier_i::~Notifier_i (void) void Notifier_i::register_callback (const char *stock_name, - CORBA::Long threshold_value, - Callback_Quoter::Consumer_ptr consumer_handler, - CORBA::Environment &TAO_TRY_ENV) + CORBA::Long threshold_value, + Callback_Quoter::Consumer_ptr consumer_handler, + CORBA::Environment &TAO_TRY_ENV) { // Store the client information. Consumer_Data consumer_data; @@ -46,24 +47,22 @@ Notifier_i::register_callback (const char *stock_name, // after the method invocation is done. consumer_data.consumer_ = Callback_Quoter::Consumer::_duplicate (consumer_handler); - consumer_data.desired_value_= threshold_value; + + consumer_data.desired_value_= threshold_value; CONSUMERS *consumers = 0; - // *done* @@ Please add a comment explaining what you're doing ;-) - // The consumer_map consists of the stockname and various consumers with their - // threshold values. To register a consumer into this map, first the stockname - // is matched with an existing one (if any) and the consumer and the threshold - // value is attached. Else, a new entry is created for the stockname. + // The consumer_map consists of the stockname and various consumers + // with their threshold values. To register a consumer into this + // map, first the stockname is matched with an existing one (if any) + // and the consumer and the threshold value is attached. Else, a new + // entry is created for the stockname. if (this->consumer_map_.find (stock_name, consumers) == 0) { - // @@ Always make sure to check the return values of all - // calls... if ( consumers->insert (consumer_data) == -1) ACE_ERROR ((LM_ERROR, "register_callback: Insert failed!/n")); - else ACE_DEBUG ((LM_DEBUG, "Inserted map entry: stockname %s threshold %d", @@ -76,24 +75,19 @@ Notifier_i::register_callback (const char *stock_name, // CORBA exceptions... consumers = new CONSUMERS; - // *done* @@ Always make sure to check the return values of all - // calls... if (consumers->insert (consumer_data) == -1) ACE_ERROR ((LM_ERROR, "register_callback: Insert failed!/n")); - // *done* @@ Always make sure to check the return values of all - // calls... if (this->consumer_map_.bind (stock_name, consumers) == -1) ACE_ERROR ((LM_ERROR, "register_callback: Bind failed!/n")); else - ACE_DEBUG ((LM_DEBUG, - "new map entry: stockname %s threshold %d", - stock_name, - threshold_value)); + ACE_DEBUG ((LM_DEBUG, + "new map entry: stockname %s threshold %d", + stock_name, + threshold_value)); } - } // Obtain a pointer to the orb. @@ -110,32 +104,34 @@ void Notifier_i::unregister_callback (Callback_Quoter::Consumer_ptr consumer, CORBA::Environment &TAO_TRY_ENV) { - // *done* @@ Make sure to add a comment here. - // The consumer_map consists of a map of stocknames with consumers - // and their threshold values attached to it. To unregister a consumer - // it is necessary to remove that entry from the map. Hence, the map - // is iterated till the consumer entry to be removed is found and then - // removed from the map. + // and their threshold values attached to it. To unregister a + // consumer it is necessary to remove that entry from the + // map. Hence, the map is iterated till the consumer entry to be + // removed is found and then removed from the map. + + // Check to see whether the hash_map still exists. Chances are there + // that the notifier has exited closing the hash map. + if (notifier_exited_ == 1) + return; for (CONSUMER_MAP::ITERATOR iter = this->consumer_map_.begin (); - iter!= this->consumer_map_.end (); - iter ++) + iter != this->consumer_map_.end (); + ++iter) { // The *iter is nothing but the stockname + unbounded set of // consumers+threshold values, i.e a ACE_Hash_Map_Entry. Consumer_Data consumer_to_remove; - // @@ I don't think you need to do this duplicate(), but make - // sure to run purify to double-check this. - consumer_to_remove.consumer_ = Callback_Quoter::Consumer::_duplicate (consumer); + + consumer_to_remove.consumer_ = + Callback_Quoter::Consumer::_duplicate (consumer); // int_id is a member of the ACE_Hash_Map_Entry. The remove // method will do a find internally using operator == which // will check only the consumer pointers. If match found it // will be removed from the set. - // *done* @@ Make sure to check the return value. if ((*iter).int_id_->remove (consumer_to_remove) == -1) ACE_ERROR ((LM_ERROR, "unregister_callback: Remove failed!/n")); @@ -150,8 +146,8 @@ Notifier_i::unregister_callback (Callback_Quoter::Consumer_ptr consumer, void Notifier_i::market_status (const char *stock_name, - CORBA::Long stock_value, - CORBA::Environment &TAO_TRY_ENV) + CORBA::Long stock_value, + CORBA::Environment &TAO_TRY_ENV) { ACE_DEBUG ((LM_DEBUG, "Notifier_i:: The stockname is %s with price %d\n", @@ -162,12 +158,12 @@ Notifier_i::market_status (const char *stock_name, if (this->consumer_map_.find (stock_name, consumers) == 0) { - // Go through the list of <Consumer_Data> to find which registered - // client wants to be notified. + // Go through the list of <Consumer_Data> to find which + // registered client wants to be notified. for (CONSUMERS::ITERATOR iter = consumers->begin (); iter != consumers->end (); - iter++) + ++iter) { // Check whether the stockname is equal before proceeding // further. @@ -175,7 +171,6 @@ Notifier_i::market_status (const char *stock_name, { Callback_Quoter::Info interested_consumer_data; - // @@ Please check this when you run purify. interested_consumer_data.stock_name = CORBA::string_dup (stock_name); interested_consumer_data.value = @@ -184,10 +179,9 @@ Notifier_i::market_status (const char *stock_name, ACE_DEBUG ((LM_DEBUG, "pushing information to consumer\n")); - // *done* @@ Please add a comment. - // The status desired by the consumer is then passed to it. + // The status desired by the consumer is then passed to + // it. (*iter).consumer_->push (interested_consumer_data); - } } } @@ -203,6 +197,9 @@ Notifier_i::market_status (const char *stock_name, void Notifier_i::shutdown (CORBA::Environment &env) { + + // @@ I think you can delete this stuff, as long as it works and + // purify is happy. /* CONSUMERS *consumers; for (CONSUMER_MAP::ITERATOR iter = this->consumer_map_.begin (); @@ -237,6 +234,10 @@ Notifier_i::shutdown (CORBA::Environment &env) if ( this->consumer_map_.close () > 0) ACE_ERROR ((LM_ERROR, "Consumer_map_close error!\n")); + else + // This marks the exit of the notifier. This should be taken care of + // before the consumer tries to unregister after the notifier quits. + notifier_exited_ = 1; ACE_DEBUG ((LM_DEBUG, "The Callback Quoter server is shutting down...")); diff --git a/TAO/examples/Callback_Quoter/Notifier_i.h b/TAO/examples/Callback_Quoter/Notifier_i.h index 2f920c634ef..f9bd634b4ff 100644 --- a/TAO/examples/Callback_Quoter/Notifier_i.h +++ b/TAO/examples/Callback_Quoter/Notifier_i.h @@ -96,7 +96,15 @@ public: CONSUMER_MAP; CONSUMER_MAP consumer_map_; - // @@ Please add a comment. + // This is the hash map with each hash_entry consisting of the stockname + // and an unbounded set of consumer object pointer and the desired stockvalue. + + int notifier_exited_; + //This marks the exit of the notifier. This should be taken care of + // before the consumer tries to unregister after the notifier quits. + + + }; #endif /* NOTIFIER_I_H */ 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; + } +} + diff --git a/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.h b/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.h index 51385d29929..b359a59e40c 100644 --- a/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.h +++ b/TAO/examples/Callback_Quoter/Supplier_Timer_Handler.h @@ -29,40 +29,49 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -// Creating a class to handle timer events. -// Since only timer events need to be handled, only the handle_timeout -// method is overlaoded. - class Supplier; + class Supplier_Timer_Handler : public ACE_Event_Handler { // = TITLE - // Callback Quoter Supplier Timer Handler class. - // - // = Description // Feeds stock information to the Callback Quoter notifier // periodically. - + // + // = Description + // Create a class to handle timer events. Since only timer events + // need to be handled, only the handle_timeout method is overlaoded. public: - - Supplier_Timer_Handler (Supplier *supplier,ACE_Reactor *reactor); - // initilization. + Supplier_Timer_Handler (Supplier *supplier, + ACE_Reactor *reactor, + FILE *file_ptr); + // Initilization. ~Supplier_Timer_Handler (void); - // destructor + // Destructor. virtual int handle_timeout (const ACE_Time_Value &tv, const void *arg = 0); - // Method which will be called by the Reactor when timeout - // occurs. + // Method which will be called by the Reactor when timeout occurs. private: + int get_stock_information (void); + // The values of the stock and its rate are got from the file. + Supplier *supplier_obj_; - // the supplier instance. + // The supplier instance. ACE_Reactor *reactor_; - // reactor used by the supplier. + // Reactor used by the supplier. + + FILE* file_ptr_; + // The file handle of the file from where the stock input is obtained. + + char stockname_[BUFSIZ]; + // The name of the stock. + + long value_; + // The market value of the stock.It will be typecasted to long later. }; #endif /* SUPPLIER_TIMER_HANDLER_H */ diff --git a/TAO/examples/Callback_Quoter/Supplier_i.cpp b/TAO/examples/Callback_Quoter/Supplier_i.cpp index bbeeb5664f6..98162d07bf2 100644 --- a/TAO/examples/Callback_Quoter/Supplier_i.cpp +++ b/TAO/examples/Callback_Quoter/Supplier_i.cpp @@ -28,17 +28,22 @@ Supplier::Supplier (void) : ior_ (0), use_naming_service_ (1), notifier_ (), - loop_count_ (10) + loop_count_ (10), + period_value_ (1) { + // No-op. } Supplier::~Supplier (void) { + // Release the memory allocated for ior_. ACE_OS::free (this->ior_); + + // Close the stream. + ACE_OS::fclose (f_ptr_); + ACE_DEBUG ((LM_DEBUG, "Market Status Supplier daemon exiting!\n")); - - } // Reads the Server factory IOR from a file. @@ -77,7 +82,7 @@ Supplier::read_ior (char *filename) int Supplier::parse_args (void) { - ACE_Get_Opt get_opts (argc_, argv_, "dn:f:xk:xs"); + ACE_Get_Opt get_opts (argc_, argv_, "dn:fi:xk:xs"); int c; int result; @@ -85,19 +90,29 @@ Supplier::parse_args (void) while ((c = get_opts ()) != -1) switch (c) { - case 'd': // debug flag + case 'd': // Debug flag TAO_debug_level++; //**** break; - case 'n': // loop count - this->loop_count_ = (u_int) ACE_OS::atoi (get_opts.optarg); + case 'n': // Period_value: time between two successive stockfeeds. + this->period_value_ = ACE_OS::atoi (get_opts.optarg); + break; + + case 'i': // Stock market information is got from a file. + result = this->read_file (get_opts.optarg); + if (result < 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to read stock information from %s : %p\n", + get_opts.optarg, + "get_args"), + -1); break; - case 'k': // ior provide on command line + case 'k': // Ior provide on command line this->ior_ = ACE_OS::strdup (get_opts.optarg); break; - case 'f': // read the IOR from the file. + case 'f': // Read the IOR from the file. result = this->read_ior (get_opts.optarg); if (result < 0) ACE_ERROR_RETURN ((LM_ERROR, @@ -107,7 +122,7 @@ Supplier::parse_args (void) -1); break; - case 's': // don't use the naming service + case 's': // Don't use the naming service this->use_naming_service_ = 0; break; @@ -116,8 +131,9 @@ Supplier::parse_args (void) ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" " [-d]" - " [-n loopcount]" + " [-n period]" " [-f ior-file]" + " [-i input_filename]" " [-k ior]" " [-x]" " [-s]" @@ -140,10 +156,9 @@ Supplier::send_market_status (const char *stock_name, { // Make the RMI. this->notifier_->market_status (stock_name, - value, - TAO_TRY_ENV); + value, + TAO_TRY_ENV); TAO_CHECK_ENV; - } TAO_CATCHANY { @@ -166,41 +181,29 @@ Supplier::run (void) ACE_DEBUG ((LM_DEBUG, "Market Status Supplier Daemon is running...\n ")); - - ACE_Time_Value period (1); + // This sets the period for the stock-feed. + ACE_Time_Value period (period_value_); - + // "Your time starts now!" ;) the timer is scheduled to begin work. timer_id = reactor_used ()->schedule_timer (supplier_timer_handler_, - "Periodic stockfeed", - period, - period); - if ( timer_id== -1) - ACE_ERROR_RETURN ((LM_DEBUG, "%p\n", "schedule_timer"), -1); + "Periodic stockfeed", + period, + period); + if ( timer_id== -1) + ACE_ERROR_RETURN ((LM_DEBUG, + "%p\n", + "schedule_timer"), + -1); // ACE_DEBUG ((LM_DEBUG, // "cancelling timer\n")); // this->reactor_used ()->cancel_timer (timer_id); - /* - // @@ Ultimately, let's replace this with an ACE_OS::sleep() call or - // something. - for (;;) - { - long value; - char stock_name[BUFSIZ]; - - // Obtain input from the user. - scanf ("%s %ld", stock_name, &value); - - // Make a call to the method which will send the current market - // status. - if (this->send_market_status (stock_name, value) < 0) - break; - } - */ + // The reactor starts executing in a loop. this->reactor_used ()->run_event_loop (); - return 0; + + return 0; } @@ -224,8 +227,8 @@ Supplier::via_naming_service (void) TAO_TRY_ENV); TAO_CHECK_ENV; - // The CORBA::Object_var object is downcast to Notifier_var using - // the <_narrow> method. + // The CORBA::Object_var object is downcast to Notifier_var + // using the <_narrow> method. this->notifier_ = Notifier::_narrow (notifier_obj.in (), TAO_TRY_ENV); @@ -251,13 +254,6 @@ Supplier::init (int argc, char **argv) TAO_TRY { - - // Create the Timer_Handler. - ACE_NEW_RETURN (supplier_timer_handler_, - Supplier_Timer_Handler (this,this->reactor_used ()), - -1); - - // Retrieve the ORB. this->orb_ = CORBA::ORB_init (this->argc_, this->argv_, @@ -269,6 +265,12 @@ Supplier::init (int argc, char **argv) if (this->parse_args () == -1) return -1; + // Create the Timer_Handler. + ACE_NEW_RETURN (supplier_timer_handler_, + Supplier_Timer_Handler (this, + this->reactor_used (), + this->f_ptr_), + -1); if (this->use_naming_service_) return via_naming_service (); @@ -277,7 +279,6 @@ Supplier::init (int argc, char **argv) "%s: no ior specified\n", this->argv_[0]), -1); - CORBA::Object_var notifier_object = this->orb_->string_to_object (this->ior_, TAO_TRY_ENV); @@ -288,9 +289,8 @@ Supplier::init (int argc, char **argv) "invalid ior <%s>\n", this->ior_), -1); - - // The downcasting from CORBA::Object_var to Notifier_var is done - // using the <_narrow> method. + // The downcasting from CORBA::Object_var to Notifier_var is + // done using the <_narrow> method. this->notifier_ = Notifier::_narrow (notifier_object.in (), TAO_TRY_ENV); TAO_CHECK_ENV; @@ -305,9 +305,24 @@ Supplier::init (int argc, char **argv) return 0; } - ACE_Reactor* Supplier::reactor_used (void) const { - return (ACE_Reactor::instance ()); + return ACE_Reactor::instance (); +} + +// The stock market information is read from a file. + +int +Supplier::read_file (char *filename) +{ + f_ptr_ = ACE_OS::fopen ("stocks.st", "rw"); + + // the stock values are to be read from a file. + if (f_ptr_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to open %s for writing: %p\n", + filename), + -1); + return 0; } diff --git a/TAO/examples/Callback_Quoter/Supplier_i.h b/TAO/examples/Callback_Quoter/Supplier_i.h index 7e18acbcf9e..541dd08104b 100644 --- a/TAO/examples/Callback_Quoter/Supplier_i.h +++ b/TAO/examples/Callback_Quoter/Supplier_i.h @@ -22,6 +22,8 @@ #include "orbsvcs/Naming/Naming_Utils.h" #include "orbsvcs/CosNamingC.h" #include "ace/Reactor.h" +#include "ace/Read_Buffer.h" +#include "ace/OS.h" #include "NotifierC.h" #include "Supplier_Timer_Handler.h" @@ -29,8 +31,6 @@ # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ -// This class does the job of feeding the Callback Quoter -// notifier with stock information. class Supplier_Timer_Handler; class Supplier { @@ -38,8 +38,8 @@ class Supplier // Market feed daemon implementation. // // = DESCRIPTION - // Class wrapper for a daemon which keeps sending - // current stock values to the Callback Quoter notifier. + // This class feeds stock information to the Callback Quoter + // notifier. public: // = Initialization and termination methods. Supplier (void); @@ -59,8 +59,8 @@ public: // Sends the stock name and its value. Supplier_Timer_Handler *supplier_timer_handler_; - // The timer handler used to send the market status to the - // notifier periodically. + // The timer handler used to send the market status to the notifier + // periodically. private: int read_ior (char *filename); @@ -73,9 +73,12 @@ private: // This method initialises the naming service and registers the // object with the POA. - ACE_Reactor *reactor_used (void) const; + ACE_Reactor *reactor_used (void) const; // returns the TAO instance of the singleton Reactor. + int read_file (char *filename); + // This method used for getting stock information from a file. + int argc_; // # of arguments on the command line. @@ -84,11 +87,8 @@ private: char *ior_; // IOR of the obj ref of the Notifier. - - u_int feed_time; - // Time period between two succesive market feeds to the Notifier. - - CORBA::Environment env_; + + CORBA::Environment env_; // Environment variable. TAO_Naming_Client naming_services_client_; @@ -98,15 +98,21 @@ private: int use_naming_service_; // This variable denotes whether the naming service // is used or not. - + Notifier_var notifier_; // Notifier object reference. - CORBA::ORB_var orb_; + CORBA::ORB_var orb_; // Remember our orb. + FILE *f_ptr_; + // The pointer for accessing the input stream. + int loop_count_; // Iteration count. + + long period_value_; + // Time period between two succesive market feeds to the Notifier. }; #endif /*SUPPLIER_I_H */ diff --git a/TAO/examples/Callback_Quoter/notifier.cpp b/TAO/examples/Callback_Quoter/notifier.cpp index 25ded4c26bf..77ff46a15e2 100644 --- a/TAO/examples/Callback_Quoter/notifier.cpp +++ b/TAO/examples/Callback_Quoter/notifier.cpp @@ -5,9 +5,6 @@ ACE_RCSID(notifier, Callback_Quoter, "$Id$") // This is the main driver program for the Callback Quoter Notifier. -// @@ I recommend renaming this stuff to notifier.cpp and calling the Notifier_Servant the -// Notifier_Servant, etc. Then, you can rename the Market Feed stuff the "Notifier" since -// It really is the ultimate Notifier for this application. int main (int argc, char *argv[]) diff --git a/TAO/examples/Callback_Quoter/supplier.cpp b/TAO/examples/Callback_Quoter/supplier.cpp index c72b665838b..5d746eb0bc9 100644 --- a/TAO/examples/Callback_Quoter/supplier.cpp +++ b/TAO/examples/Callback_Quoter/supplier.cpp @@ -2,12 +2,12 @@ #include "Supplier_i.h" -// This function runs the Callback Quoter Supplier daemon. +// This function runs the Callback Quoter Supplier daemon. int main (int argc, char **argv) { - Supplier supplier; + Supplier supplier; ACE_DEBUG ((LM_DEBUG, "\n\tMarket Status Supplier Daemon\n\n")); |