diff options
author | vishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-16 00:12:59 +0000 |
---|---|---|
committer | vishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1998-09-16 00:12:59 +0000 |
commit | 044e612dcbb068bdeb2feab77ddd284ed24869fb (patch) | |
tree | 5e70a0342788faa5d811c3f1e6dd2789c1fe159f /TAO | |
parent | a0f2a0c58788e2ea568d653705895aa4cf20b45e (diff) | |
download | ATCD-044e612dcbb068bdeb2feab77ddd284ed24869fb.tar.gz |
*** empty log message ***
Diffstat (limited to 'TAO')
-rw-r--r-- | TAO/tests/Simple/bank/AccountManager_i.cpp | 112 | ||||
-rw-r--r-- | TAO/tests/Simple/bank/AccountManager_i.h | 17 | ||||
-rw-r--r-- | TAO/tests/Simple/bank/Account_i.cpp | 11 | ||||
-rw-r--r-- | TAO/tests/Simple/bank/Client_i.cpp | 118 | ||||
-rw-r--r-- | TAO/tests/Simple/bank/Client_i.h | 5 | ||||
-rw-r--r-- | TAO/tests/Simple/bank/Server_i.cpp | 57 |
6 files changed, 197 insertions, 123 deletions
diff --git a/TAO/tests/Simple/bank/AccountManager_i.cpp b/TAO/tests/Simple/bank/AccountManager_i.cpp index a82bff6fc02..b96b4bbbe8c 100644 --- a/TAO/tests/Simple/bank/AccountManager_i.cpp +++ b/TAO/tests/Simple/bank/AccountManager_i.cpp @@ -28,6 +28,18 @@ AccountManager_i::orb (CORBA::ORB_ptr o) this->orb_ = CORBA::ORB::_duplicate (o); } +void +AccountManager_i::poa (PortableServer::POA_ptr poa) +{ + this->poa_ = poa; +} + +void +AccountManager_i::set_orb_manager (TAO_ORB_Manager *orb_manager) +{ + this->orb_manager_ = orb_manager; +} + // Open an account for the given name. Bank::Account_ptr @@ -35,82 +47,86 @@ AccountManager_i::open (const char *name, CORBA::Float initial_balance, CORBA::Environment &_env) { - Account_i *result; + Bank::Account_ptr result = 0; // If name is already in the map, <find> will assign <result> to the // appropriate value. - - if (hash_map_.find (name, result) != 0) + TAO_TRY { - ACE_DEBUG ((LM_DEBUG, - "\nOpening a new Account for %s with balance %f\n", - name, - initial_balance)); - - ACE_NEW_THROW_RETURN (result, - Account_i (name,initial_balance), - CORBA::NO_MEMORY (CORBA::COMPLETED_NO), - Bank::Account::_nil ()); - // Enter the new Account in the hash map. If the <bind> fails - // throw an UNKNOWN exception. <result> may be valid but since - // it is not properly bound, it's behaviour may be off, so - // delete it to be safe. - - if (hash_map_.bind (name, result) == -1) + if (hash_map_.find (name, result) != 0) { - delete result; - TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), - Bank::Account::_nil ()); + ACE_DEBUG ((LM_DEBUG, + "\nOpening a new Account for %s with balance %f\n", + name, + initial_balance)); + + ACE_NEW_THROW_RETURN (result, + Account_i (name,initial_balance), + CORBA::NO_MEMORY (CORBA::COMPLETED_NO), + Bank::Account::_nil ()); + + // Enter the new Account in the hash map. If the <bind> + // fails throw an UNKNOWN exception. <result> may be valid + // but since it is not properly bound, it's behaviour may be + // off, so delete it to be safe. + + if (hash_map_.bind (name, result) == -1) + { + delete result; + TAO_THROW_RETURN (CORBA::UNKNOWN (CORBA::COMPLETED_NO), + Bank::Account::_nil ()); + } } - } - else - if (TAO_debug_level > 0) - ACE_DEBUG ((LM_DEBUG, - "\nAccount already exists for %s\n", - name)); + else + if (TAO_debug_level > 0) + ACE_DEBUG ((LM_DEBUG, + "\nAccount already exists for %s\n", + name)); - // Generate an IOR for the result object and register it with the - // POA. In case the object already exists then the previously - // generated IOR is returned. + // Generate an IOR for the result object and register it with + // the POA. In case the object already exists then the + // previously generated IOR is returned. + return result->_this (); - return result->_this (_env); + } + TAO_CATCHANY + { + _env.print_exception("Exception in OPen"); + } + TAO_ENDTRY; } // Shutdown. void AccountManager_i::close (Bank::Account_ptr account, - CORBA::Environment &env) + CORBA::Environment &TAO_TRY_ENV) { TAO_TRY { - const char *name = - // @@ I don't think you need to do a string_dup() here. I - // think that is automatically handled by name(). Moreover, I - // don't think you are correctly freeing the name pointer... - // Make sure you free this up correctly regardless of which - // exception path is taken... - CORBA::string_dup (account->name (TAO_TRY_ENV)); - + // @@ Please take a look at the CORBA::String_var and see if you + // can use that... + const char *name = account->name (TAO_TRY_ENV); TAO_CHECK_ENV; if (hash_map_.unbind (name) == -1) { if (TAO_debug_level > 0) ACE_DEBUG((LM_DEBUG, - "Unable to close account\n")); + "Unable to close account\n")); } else if (TAO_debug_level > 0) ACE_DEBUG((LM_DEBUG, "Closing Account for %s\n", name)); - } - TAO_CATCHANY - { - TAO_TRY_ENV.print_exception ("Unable to close Account\n"); - } - TAO_ENDTRY; - // @@ I suspect you'll want to do a CORBA::string_free (name) here... + + CORBA::string_free ((char *) name); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("Unable to close Account\n"); + } + TAO_ENDTRY; } void diff --git a/TAO/tests/Simple/bank/AccountManager_i.h b/TAO/tests/Simple/bank/AccountManager_i.h index e37f87c786a..93e23917cb0 100644 --- a/TAO/tests/Simple/bank/AccountManager_i.h +++ b/TAO/tests/Simple/bank/AccountManager_i.h @@ -22,6 +22,7 @@ #include "ace/ACE.h" #include "ace/OS.h" +#include "tao/TAO.h" #include "BankS.h" #include "Account_i.h" @@ -34,7 +35,6 @@ class AccountManager_i : public POA_Bank::AccountManager // Implementation of a simple object that has two methods, one // that returns an Account Interface and the other that shuts // down the server. - public: // = Initialization and termination methods. AccountManager_i (void); @@ -59,10 +59,25 @@ public: void orb (CORBA::ORB_ptr o); // Set the ORB pointer. + void poa (PortableServer::POA_ptr poa); + // Set the POA pointer. + + void set_orb_manager (TAO_ORB_Manager *orb_manager); + // Set the ORB Manager. + + TAO_ORB_Manager *orb_manager_; + // The ORB manager. + private: CORBA::ORB_var orb_; // ORB pointer. + PortableServer::POA_ptr poa_; + // POA pointer. + + //TAO_ORB_Manager orb_manager_; + // The ORB manager. + ACE_Hash_Map_Manager<ACE_CString, Account_i *, ACE_Null_Mutex> hash_map_; diff --git a/TAO/tests/Simple/bank/Account_i.cpp b/TAO/tests/Simple/bank/Account_i.cpp index 68f38cc4d17..b35ed2ad370 100644 --- a/TAO/tests/Simple/bank/Account_i.cpp +++ b/TAO/tests/Simple/bank/Account_i.cpp @@ -23,11 +23,7 @@ Account_i::Account_i (const char *name, Account_i::~Account_i (void) { - // @@ Make sure that you do a CORBA::string_free() on name_ when - // this exits. - - // @@ Make sure that you run Purify on your program when you've got - // it working. + CORBA::string_free (name_); } // Set the ORB pointer. @@ -50,16 +46,15 @@ void Account_i::deposit (CORBA::Float deposit, CORBA::Environment &env) { - balance_ = balance_ + deposit ; + balance_ += deposit; } void Account_i::withdraw (CORBA::Float withdrawl, CORBA::Environment &env) { - // @@ Here's where you'd handle the exception... if (balance_ >= withdrawl) - balance_ = balance_ - withdrawl; + balance_ -= withdrawl; else env.exception (new Bank::Account::Overdraft("Exception from server::Overdraft")); } diff --git a/TAO/tests/Simple/bank/Client_i.cpp b/TAO/tests/Simple/bank/Client_i.cpp index a0de5cac9d4..cf2e6aa5af6 100644 --- a/TAO/tests/Simple/bank/Client_i.cpp +++ b/TAO/tests/Simple/bank/Client_i.cpp @@ -90,6 +90,7 @@ Client_i::parse_args (void) ACE_ERROR_RETURN ((LM_ERROR, "usage: %s" " [-d]" + " [-b Initial Balance]" " [-n loopcount]" " [-f ior-file]" " [-k ior]" @@ -119,23 +120,16 @@ Client_i::withdraw (CORBA::Float withdrawl_amount) server_->withdraw (withdrawl_amount, TAO_TRY_ENV); TAO_CHECK_ENV; - - ACE_DEBUG ((LM_DEBUG, - "Pass\n")); } TAO_CATCHANY { - // @@ Please check to make sure that you aren't incurring a - // memory leak here... For instance, can you use - // Bank::Account::Overdraft_var instead of - // Bank::Account::Overdraft *? - Bank::Account::Overdraft *except = + Bank::Account::Overdraft_ptr except = Bank::Account::Overdraft::_narrow (TAO_TRY_ENV.exception ()); - ACE_DEBUG((LM_DEBUG, - "exception%s", - (char *) except->reason)); + ACE_DEBUG ((LM_DEBUG, + "exception%s", + (char *) except->reason)); } TAO_ENDTRY; } @@ -150,6 +144,14 @@ Client_i::open (const char *name, env); } +void +Client_i::close (Bank::Account_ptr account, + CORBA::Environment &env) +{ + this->accountmanager_server_->close (account, + env); +} + CORBA::Float Client_i::balance (CORBA::Environment &env) { @@ -164,73 +166,83 @@ Client_i::check_accounts (void) { TAO_TRY { - this->server_ = open ("Vishal", - initial_balance_, - this->env_); + this->server_ = this->open ("Vishal", + this->initial_balance_, + this->env_); TAO_CHECK_ENV; - CORBA::Float my_balance = balance (this->env_); + CORBA::Float my_balance = this->balance (this->env_); - ACE_ASSERT (initial_balance_ == my_balance); + ACE_ASSERT (this->initial_balance_ == my_balance); - deposit (100.00, this->env_); + this->deposit (100.00, this->env_); TAO_CHECK_ENV; - my_balance = balance (this->env_); + my_balance = this->balance (this->env_); - ACE_ASSERT (my_balance == initial_balance_ + 100.00); + ACE_ASSERT (my_balance == this->initial_balance_ + 100.00); - withdraw (50.00); + this->withdraw (50.00); + my_balance = this->balance (this->env_); TAO_CHECK_ENV; - my_balance = balance (this->env_); - ACE_ASSERT (my_balance == initial_balance_ + 50.00); ACE_DEBUG ((LM_DEBUG, "Opening an account for Kachroo\n")); Bank::Account_var server = open ("Kachroo", - initial_balance_, + this->initial_balance_, this->env_); TAO_CHECK_ENV; - ACE_ASSERT (server.in () != server_.in ()); - - ACE_DEBUG((LM_DEBUG, - "%s,%s\n", - server_->name(), - server->name())); + ACE_DEBUG ((LM_DEBUG, + "%s,%s\n", + // @@ Please rename this server1_ and server2_. + this->server_->name (), + this->server->name ())); Bank::Account_var server2 = open ("Vishal", - initial_balance_, + this->initial_balance_, this->env_); - ACE_DEBUG((LM_DEBUG, - "%s,%s\n", - server_->name(), - server2->name())); + ACE_DEBUG ((LM_DEBUG, + "%s,%s\n", + ths->server_->name(), + this->server2->name())); TAO_CHECK_ENV; // Make sure we get back the same object reference! - ACE_ASSERT (server2->_is_equivalent (server_.in (), TAO_TRY_ENV)); - + ACE_ASSERT (server2->_is_equivalent (server_.in (), + TAO_TRY_ENV)); TAO_CHECK_ENV; - deposit (150.00, this->env_); + this->deposit (150.00, this->env_); + TAO_CHECK_ENV; + my_balance = this->balance (this->env_); TAO_CHECK_ENV; - my_balance = balance (this->env_); + ACE_ASSERT (my_balance = this->initial_balance_ + 200.00); + + // Following assertion checks if we get back a DIFFERENT object + // reference for a different account. - ACE_ASSERT (my_balance = initial_balance_ + 200.00); + ACE_ASSERT (server_->_is_equivalent (server.in (), + TAO_TRY_ENV) == FALSE); + TAO_CHECK_ENV; - // @@ Finally, I recommend that you also check to make sure that - // you get back a DIFFERENT object reference if you open a - // different account. + // Close the Account for "Kachroo". + this->close (server.in (), + this->env_); + TAO_CHECK_ENV; + + this->open ("Kachroo", + initial_balance_, + this->env_); TAO_CHECK_ENV; } TAO_CATCHANY @@ -252,11 +264,21 @@ Client_i::run (void) this->check_accounts (); - // @@ Please update this when you've got it done. - if (this->shutdown_) - ACE_DEBUG ((LM_DEBUG, - "Operation Shutdown not defined\n")); - return 0; + TAO_TRY + { + if (this->shutdown_) + this->accountmanager_server_->shutdown (TAO_TRY_ENV); + TAO_CHECK_ENV; + } + TAO_CATCHANY + { + ACE_DEBUG ((LM_DEBUG, + "Unable to shut down the server\n")); + } + TAO_ENDTRY; + +return 0; + } Client_i::~Client_i (void) @@ -279,7 +301,7 @@ Client_i::obtain_initial_references (void) CosNaming::Name account_manager_name (1); account_manager_name.length (1); account_manager_name[0].id = - CORBA::string_dup ("AccountManager"); + CORBA::string_dup ("AccountManager"); CORBA::Object_var account_manager_obj = my_name_client_->resolve (account_manager_name, diff --git a/TAO/tests/Simple/bank/Client_i.h b/TAO/tests/Simple/bank/Client_i.h index 95ac20734d5..5f4d13ac7a5 100644 --- a/TAO/tests/Simple/bank/Client_i.h +++ b/TAO/tests/Simple/bank/Client_i.h @@ -66,6 +66,11 @@ private: CORBA::Environment &env); // Open a new account with the given name and initial balance. + + void close (Bank::Account_ptr account, + CORBA::Environment &env); + // Close a given Account. + CORBA::Float balance (CORBA::Environment &env); // Returns the current balance in the account. diff --git a/TAO/tests/Simple/bank/Server_i.cpp b/TAO/tests/Simple/bank/Server_i.cpp index 12e6ec71ecd..6b41ee296b7 100644 --- a/TAO/tests/Simple/bank/Server_i.cpp +++ b/TAO/tests/Simple/bank/Server_i.cpp @@ -53,6 +53,7 @@ Server_i::parse_args (void) "\n", argv_ [0]), 1); + break; } // Indicates successful parsing of command line. @@ -66,22 +67,47 @@ Server_i::init_naming_service (CORBA::Environment& env) { CORBA::ORB_var orb; - PortableServer::POA_var child_poa; + PortableServer::POA_ptr child_poa; orb = this->orb_manager_.orb (); + this->orb_manager_.init_child_poa (this->argc_, + this->argv_, + "my_child_poa", + env); + child_poa = this->orb_manager_.child_poa (); int result = this->my_name_server_.init (orb.in (), - child_poa.in ()); + child_poa); if (result == -1) - return result; + { + ACE_DEBUG((LM_DEBUG, + "Result=%d", + result)); + return result; + } // Generate an IOR for the AccountManager Object and register it // with POA. + CORBA::String_var str = + this->orb_manager_.activate_under_child_poa ("AccountManager", + this->account_manager_impl_, + env); + + // @@ Please add relevant comments here explaining what you're doing. Bank::AccountManager_var account_manager = - this->account_manager_impl_->_this (env); + Bank::AccountManager::_narrow (orb->string_to_object (str,env)); + // Pass the Account Manager an ORB reference to use. + account_manager_impl_->orb (orb.in ()); + + // Pass the Account Manager a POA reference to use. + account_manager_impl_->poa (child_poa); + + account_manager_impl_->set_orb_manager (&orb_manager_); + + // Convert an Account Manager reference to a string. CORBA::String_var objref = orb->object_to_string (account_manager.in (), env); @@ -92,7 +118,6 @@ Server_i::init_naming_service (CORBA::Environment& env) "The IOR is: <%s>\n", (const char *) objref)); - // Print the Account Manager IOR to a file. if (this->ior_output_file_) { @@ -102,15 +127,13 @@ Server_i::init_naming_service (CORBA::Environment& env) ACE_OS::fclose (this->ior_output_file_); } - - // Bind the Account Manager with the naming Service - + // Bind the Account Manager with the Naming Service. CosNaming::Name account_manager_name (1); account_manager_name.length (1); account_manager_name[0].id = CORBA::string_dup ("AccountManager"); this->my_name_server_->bind (account_manager_name, - account_manager.in (), - env); + account_manager.in (), + env); TAO_CHECK_ENV_RETURN (env, -1); return 0; @@ -123,6 +146,9 @@ Server_i::init (int argc, char *argv[], CORBA::Environment &env) { + this->argc_ = argc; + this->argv_ = argv; + // Call the init of <TAO_ORB_Manager> to initialize the ORB and // create a child POA under the root POA. if (this->orb_manager_.init_child_poa (argc, @@ -135,15 +161,10 @@ Server_i::init (int argc, -1); TAO_CHECK_ENV_RETURN (env, -1); - this->argc_ = argc; - this->argv_ = argv; - - int retval = this->parse_args (); + int result = this->parse_args (); - if (retval != 0) - return retval; - - CORBA::ORB_var orb = this->orb_manager_.orb (); + if (result != 0) + return result; // Now create the implementation for the Account Manager. ACE_NEW_RETURN (this->account_manager_impl_, |