summaryrefslogtreecommitdiff
path: root/TAO/examples
diff options
context:
space:
mode:
authorvishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-21 01:36:32 +0000
committervishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-09-21 01:36:32 +0000
commit540007956cb1f1ad044965fc1cd15ee001aeff92 (patch)
treeb8ee99c8cb6c5c3956277fdfb4c1e7be2b38ec59 /TAO/examples
parente409dbe67fdad4f6db687d3599d725aeab290419 (diff)
downloadATCD-540007956cb1f1ad044965fc1cd15ee001aeff92.tar.gz
*** empty log message ***
Diffstat (limited to 'TAO/examples')
-rw-r--r--TAO/examples/Simple/bank/AccountManager_i.cpp35
-rw-r--r--TAO/examples/Simple/bank/Bank.idl4
-rw-r--r--TAO/examples/Simple/bank/Client_i.cpp154
-rw-r--r--TAO/examples/Simple/bank/Client_i.h32
-rw-r--r--TAO/examples/Simple/bank/README17
-rw-r--r--TAO/examples/Simple/bank/Server_i.cpp5
-rwxr-xr-xTAO/examples/Simple/bank/run_test.pl2
7 files changed, 145 insertions, 104 deletions
diff --git a/TAO/examples/Simple/bank/AccountManager_i.cpp b/TAO/examples/Simple/bank/AccountManager_i.cpp
index 8a9bc36d80f..ea43b1d2141 100644
--- a/TAO/examples/Simple/bank/AccountManager_i.cpp
+++ b/TAO/examples/Simple/bank/AccountManager_i.cpp
@@ -46,7 +46,7 @@ AccountManager_i::open (const char *name,
CORBA::Float initial_balance,
CORBA::Environment &_env)
{
- Account_i* result = 0;
+ Account_i *result = 0;
// If name is already in the map, <find> will assign <result> to the
// appropriate value.
@@ -60,7 +60,8 @@ AccountManager_i::open (const char *name,
initial_balance));
ACE_NEW_THROW_RETURN (result,
- Account_i (name,initial_balance),
+ Account_i (name,
+ initial_balance),
CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
Bank::Account::_nil ());
@@ -85,13 +86,14 @@ AccountManager_i::open (const char *name,
// the POA. In case the object already exists then the
// previously generated IOR is returned.
- return result->_this ();
}
TAO_CATCHANY
{
_env.print_exception("Exception in OPen");
}
TAO_ENDTRY;
+
+ return result->_this ();
}
// Shutdown.
@@ -102,12 +104,12 @@ AccountManager_i::close (Bank::Account_ptr account,
{
TAO_TRY
{
- // @@ Please take a look at the CORBA::String_var and see if you
- // can use that...
- const char *name = account->name (TAO_TRY_ENV);
+ CORBA::String_var name =
+ CORBA::string_dup (account->name (TAO_TRY_ENV));
+
TAO_CHECK_ENV;
- if (hash_map_.unbind (name) == -1)
+ if (hash_map_.unbind ((const char *) name) == -1)
{
if (TAO_debug_level > 0)
ACE_DEBUG((LM_DEBUG,
@@ -116,10 +118,9 @@ AccountManager_i::close (Bank::Account_ptr account,
else if (TAO_debug_level > 0)
ACE_DEBUG((LM_DEBUG,
"Closing Account for %s\n",
- name));
+ (char *) name));
- CORBA::string_free ((char *) name);
- }
+ }
TAO_CATCHANY
{
TAO_TRY_ENV.print_exception ("Unable to close Account\n");
@@ -137,3 +138,17 @@ AccountManager_i::shutdown (CORBA::Environment &)
// Instruct the ORB to shutdown.
this->orb_->shutdown ();
}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class ACE_Hash_Map_Manager <ACE_CString,Account_i *,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Iterator <ACE_CString,Account_i *,ACE_Null_Mutex>;
+template class ACE_Hash_Map_Entry<ACE_CString, Account_i *>;
+template class ACE_Hash_Map_Reverse_Iterator<ACE_CString, Account_i *, ACE_Null_Mutex>;
+template class ACE_Hash_Map_Iterator_Base<ACE_CString, Account_i *, ACE_Null_Mutex>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate ACE_Hash_Map_Manager <ACE_CString,Account_i *,ACE_Null_Mutex>;
+#pragma instantiate ACE_Hash_Map_Iterator <ACE_CString,Account_i *,ACE_Null_Mutex>;
+#pragma instantiate ACE_Hash_Map_Entry<ACE_CString, Account_i *>;
+#pragma instantiate ACE_Hash_Map_Reverse_Iterator<ACE_CString, Account_i *, ACE_Null_Mutex>;
+#pragma instantiate ACE_Hash_Map_Iterator_Base<ACE_CString, Account_i *, ACE_Null_Mutex>;
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/TAO/examples/Simple/bank/Bank.idl b/TAO/examples/Simple/bank/Bank.idl
index 36492ff66eb..3cac2150a85 100644
--- a/TAO/examples/Simple/bank/Bank.idl
+++ b/TAO/examples/Simple/bank/Bank.idl
@@ -29,9 +29,7 @@ module Bank
// Add <amount> to this account.
void withdraw (in float amount) raises (Overdraft);
-
- //void withdraw (in float amount);
- // Withdraw <amount> from this account.
+ // Withdraw <amount from this account.
attribute string name;
// The <name> of this account.
diff --git a/TAO/examples/Simple/bank/Client_i.cpp b/TAO/examples/Simple/bank/Client_i.cpp
index b6549ab8244..18ea6ed48d5 100644
--- a/TAO/examples/Simple/bank/Client_i.cpp
+++ b/TAO/examples/Simple/bank/Client_i.cpp
@@ -12,7 +12,8 @@ Client_i::Client_i (void)
: ior_ (0),
loop_count_ (10),
shutdown_ (0),
- server_ ()
+ server1_ (),
+ server2_ ()
{
}
@@ -51,7 +52,7 @@ Client_i::read_ior (char *filename)
int
Client_i::parse_args (void)
{
- ACE_Get_Opt get_opts (argc_, argv_, "dn:b:o:f:xk:");
+ ACE_Get_Opt get_opts (argc_, argv_, "dn:b:y:z:f:xk:");
int c;
int result;
@@ -71,8 +72,11 @@ Client_i::parse_args (void)
ACE_DEBUG((LM_DEBUG,"bal = %f",
initial_balance_));
break;
- case 'o': // Name of the account holder.
- this->account_holder_name_ = ACE_OS::strdup (get_opts.optarg);
+ case 'y': // Name of one account holder.
+ this->account_holder_name1_ = ACE_OS::strdup (get_opts.optarg);
+ break;
+ case 'z': // Name of another account holder.
+ this->account_holder_name2_ = ACE_OS::strdup (get_opts.optarg);
break;
case 'k': // ior provide on command line
this->ior_ = ACE_OS::strdup (get_opts.optarg);
@@ -94,8 +98,9 @@ Client_i::parse_args (void)
"usage: %s"
" [-d]"
" [-b Initial Balance]"
- " [-o Account Holder's Name]"
- " [-n loopcount]"
+ " [-y First Account Holder's Name]"
+ " [-z Second Account Holder's Name]"
+ " [-n loopcount]"
" [-f ior-file]"
" [-k ior]"
" [-x]"
@@ -109,20 +114,22 @@ Client_i::parse_args (void)
}
void
-Client_i::deposit (CORBA::Float deposit_amount,
+Client_i::deposit (Bank::Account_ptr server,
+ CORBA::Float deposit_amount,
CORBA::Environment &env)
{
- server_->deposit (deposit_amount,
- this->env_);
+ server->deposit (deposit_amount,
+ this->env_);
}
void
-Client_i::withdraw (CORBA::Float withdrawl_amount)
+Client_i::withdraw (Bank::Account_ptr server,
+ CORBA::Float withdrawl_amount)
{
TAO_TRY
{
- server_->withdraw (withdrawl_amount,
- TAO_TRY_ENV);
+ server->withdraw (withdrawl_amount,
+ TAO_TRY_ENV);
TAO_CHECK_ENV;
}
TAO_CATCHANY
@@ -132,7 +139,7 @@ Client_i::withdraw (CORBA::Float withdrawl_amount)
(TAO_TRY_ENV.exception ());
ACE_DEBUG ((LM_DEBUG,
- "exception%s",
+ "Exception : %s",
(char *) except->reason));
}
TAO_ENDTRY;
@@ -156,82 +163,81 @@ Client_i::close (Bank::Account_ptr account,
env);
}
-CORBA::Float
-Client_i::balance (CORBA::Environment &env)
+
+// This method tests if opening an account with the same name returns
+// the same IOR.
+
+void
+Client_i::test_for_same_name (CORBA::Environment &env)
{
- return server_->balance (env);
+ this->server1_ = this->open (this->account_holder_name1_,
+ this->initial_balance_,
+ this->env_);
+ this->server2_ = this->open (this->account_holder_name1_,
+ this->initial_balance_,
+ this->env_);
+ ACE_ASSERT (server1_->_is_equivalent ((CORBA::Object *) server2_.in ()) != 0);
+
+ this->close (server1_.in (),
+ this->env_);
+ this->close (server2_.in (),
+ this->env_);
+}
+
+// This method tests if opening an account with different names
+// returns a different IOR.
+void
+Client_i::test_for_different_name (CORBA::Environment &env)
+{
+ this->server1_ = this->open (this->account_holder_name1_,
+ this->initial_balance_,
+ this->env_);
+ this->server2_ = this->open (this->account_holder_name2_,
+ this->initial_balance_,
+ this->env_);
+
+ ACE_ASSERT (server1_->_is_equivalent ((CORBA::Object *)server2_.in ()) == 0);
+
+ this->close (server1_.in (),
+ this->env_);
+ this->close (server2_.in (),
+ this->env_);
+}
+
+// This method tests the Overdraft exception.
+
+void
+Client_i::test_for_overdraft (CORBA::Environment &env)
+{
+ this->server1_ = this->open (this->account_holder_name1_,
+ this->initial_balance_,
+ this->env_);
+ this->deposit (server1_.in (),
+ 100.00,
+ this->env_);
+ this->withdraw (server1_.in (),
+ server1_->balance(this->env_) + 20);
+ this->close (server1_.in (),
+ this->env_);
}
-// Call the remote methods on the Account and AccountManager
-// interface.
CORBA::Float
Client_i::check_accounts (void)
{
TAO_TRY
{
- this->server_ = this->open (this->account_holder_name_,
- this->initial_balance_,
- this->env_);
+ this->test_for_same_name (this->env_);
TAO_CHECK_ENV;
-
- CORBA::Float my_balance = this->balance (this->env_);
-
- ACE_ASSERT (this->initial_balance_ == my_balance);
-
- this->deposit (100.00, this->env_);
+ this->test_for_different_name (this->env_);
TAO_CHECK_ENV;
-
- my_balance = this->balance (this->env_);
-
- ACE_ASSERT (my_balance == this->initial_balance_ + 100.00);
-
- this->withdraw (50.00);
-
- my_balance = this->balance (this->env_);
- TAO_CHECK_ENV;
-
- ACE_ASSERT (my_balance == initial_balance_ + 50.00);
-
- ACE_DEBUG ((LM_DEBUG,
- "%s\n",
- this->server_->name()
- ));
-
- TAO_CHECK_ENV;
-
- // Make sure we get back the same object reference!
-
- //ACE_ASSERT (server2->_is_equivalent (server_.in (),
- // TAO_TRY_ENV));
- //TAO_CHECK_ENV;
-
- //this->deposit (150.00, this->env_);
- //TAO_CHECK_ENV;
-
- //my_balance = this->balance (this->env_);
- //TAO_CHECK_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 (server_->_is_equivalent (server.in (),
- // TAO_TRY_ENV) == FALSE);
- //TAO_CHECK_ENV;
-
- // Close the Account.
-
- this->close (server_.in (),
- this->env_);
+ this->test_for_overdraft (this->env_);
TAO_CHECK_ENV;
-
}
TAO_CATCHANY
{
if (this->env_.exception () != 0)
- this->env_.print_exception ("from Client_i::balance");
+ this->env_.print_exception ("From Client_i::check_accounts()");
}
TAO_ENDTRY;
@@ -250,7 +256,7 @@ Client_i::run (void)
TAO_TRY
{
if (this->shutdown_)
- this->accountmanager_server_->shutdown (TAO_TRY_ENV);
+ this->accountmanager_server_->shutdown (TAO_TRY_ENV);
TAO_CHECK_ENV;
}
TAO_CATCHANY
diff --git a/TAO/examples/Simple/bank/Client_i.h b/TAO/examples/Simple/bank/Client_i.h
index 39ccaf258bc..e06369f955f 100644
--- a/TAO/examples/Simple/bank/Client_i.h
+++ b/TAO/examples/Simple/bank/Client_i.h
@@ -54,11 +54,13 @@ private:
CORBA::Float check_accounts (void);
// Checks the various operations of the account.
- void deposit (CORBA::Float deposit_amount,
+ void deposit (Bank::Account_ptr server,
+ CORBA::Float deposit_amount,
CORBA::Environment &env);
// Deposit in the account.
- void withdraw (CORBA::Float withdrawl_amount);
+ void withdraw (Bank::Account_ptr server,
+ CORBA::Float withdrawl_amount);
// Withdraw from the account.
Bank::Account_ptr open (const char *name,
@@ -71,8 +73,15 @@ private:
CORBA::Environment &env);
// Close a given Account.
- CORBA::Float balance (CORBA::Environment &env);
- // Returns the current balance in the account.
+ void test_for_different_name (CORBA::Environment &env);
+ // Tests if accounts opened with different names return a different account reference.
+
+ void test_for_same_name (CORBA::Environment &env);
+ // Tests if accounts opened with the same name return the same object reference.
+
+ void test_for_overdraft (CORBA::Environment &env);
+ // Tests for the Overdraft Exception when the client tries to
+ // withdraw more money than the current balance.
int obtain_initial_references (void);
// To initialize the naming service and get a ptr to server.
@@ -95,8 +104,11 @@ private:
CORBA::Environment env_;
// Environment variable.
- Bank::Account_var server_;
- // Account Server object ptr.
+ Bank::Account_var server1_;
+ // Account Server object ptr #1.
+
+ Bank::Account_var server2_;
+ // Account Serverobject ptr #2.
Bank::AccountManager_var accountmanager_server_;
// Account Manager server object ptr.
@@ -111,6 +123,10 @@ private:
CORBA::Float initial_balance_;
// Filled up by a command line argument.
- char *account_holder_name_;
- // Name of the Account Holder.
+ char *account_holder_name1_;
+ // Name of the first Account Holder.
+
+ char *account_holder_name2_;
+ // Name of the second Account Holder.
+
};
diff --git a/TAO/examples/Simple/bank/README b/TAO/examples/Simple/bank/README
index b6e6e56d07f..8df6a587d9e 100644
--- a/TAO/examples/Simple/bank/README
+++ b/TAO/examples/Simple/bank/README
@@ -1,10 +1,10 @@
$Id$
This is a simple CORBA example that has a module Bank with two
-interfaces Account and AccountManager. The Account interface has a
-method to return the balance in that account. The AccountManager
-interface has a method to create a new Account and return the IORof
-this to the client. The two interfaces also have methods to shutdown
+interfaces Account and AccountManager. The Account interface has a
+method to return the balance in that account. The AccountManager
+interface has a method to create a new Account and return the IOR of
+this to the client. The two interfaces also have methods to shutdown
the server.
server:
@@ -32,10 +32,17 @@ options are ignored.
client:
-------
-client [-d] [-x] [-n iterations]
+client [-d] [-x] [-n iterations] [-b initial_balance] [-o Name_of_account_holder]
+ [-f IOR_file_name ] [-k IOR]
Options:
-------
-d Debug flag
-x Tells the server to shutdown at the end of the test.
-n no. of iterations
+-b initial balance
+-o Name of the Account Holder
+-k Read IOR from the command line
+-f Read IOR from the specified file
+
+
diff --git a/TAO/examples/Simple/bank/Server_i.cpp b/TAO/examples/Simple/bank/Server_i.cpp
index 49b77bb613b..03b976d5aef 100644
--- a/TAO/examples/Simple/bank/Server_i.cpp
+++ b/TAO/examples/Simple/bank/Server_i.cpp
@@ -1,7 +1,6 @@
// $Id$
#include "ace/Get_Opt.h"
-//#include "tao/ORB.h"
#include "Server_i.h"
ACE_RCSID(Bank, Server_i, "$Id$")
@@ -91,7 +90,8 @@ Server_i::init_naming_service (CORBA::Environment& env)
this->account_manager_impl_,
env);
- // @@ Please add relevant comments here explaining what you're doing.
+ // @@ Converting the stringified IOR to an IOR.
+
Bank::AccountManager_var account_manager =
Bank::AccountManager::_narrow (orb->string_to_object (str,env));
@@ -131,7 +131,6 @@ Server_i::init_naming_service (CORBA::Environment& env)
account_manager.in (),
env);
TAO_CHECK_ENV_RETURN (env, -1);
-
return 0;
}
diff --git a/TAO/examples/Simple/bank/run_test.pl b/TAO/examples/Simple/bank/run_test.pl
index 382b6933626..e567d989d86 100755
--- a/TAO/examples/Simple/bank/run_test.pl
+++ b/TAO/examples/Simple/bank/run_test.pl
@@ -12,7 +12,7 @@ require Process;
$SV = Process::Create ("server$Process::EXE_EXT", " ");
sleep(10);
-$status = system ("client$Process::EXE_EXT -x -b 100 -o vishal");
+$status = system ("client$Process::EXE_EXT -x -b 100 -y Vishal -z Kachroo");
#sleep($ACE::sleeptime);
$SV->Kill (); $SV->Wait ();