summaryrefslogtreecommitdiff
path: root/TAO/examples/Simple/bank
diff options
context:
space:
mode:
authorbala <balanatarajan@users.noreply.github.com>1999-02-21 02:58:57 +0000
committerbala <balanatarajan@users.noreply.github.com>1999-02-21 02:58:57 +0000
commitdd51fb3f652fa209c7fc97bdc1323a6ab76826f1 (patch)
tree43c2c660f871e16d4fb2f8e33f58871af5762d9c /TAO/examples/Simple/bank
parent3e551b7ca8c75ddb62aa557144c509a578be6ff0 (diff)
downloadATCD-dd51fb3f652fa209c7fc97bdc1323a6ab76826f1.tar.gz
*** empty log message ***
Diffstat (limited to 'TAO/examples/Simple/bank')
-rw-r--r--TAO/examples/Simple/bank/Bank_Client_i.cpp154
-rw-r--r--TAO/examples/Simple/bank/Bank_Client_i.h66
-rw-r--r--TAO/examples/Simple/bank/client.cpp22
-rw-r--r--TAO/examples/Simple/bank/server.cpp45
4 files changed, 257 insertions, 30 deletions
diff --git a/TAO/examples/Simple/bank/Bank_Client_i.cpp b/TAO/examples/Simple/bank/Bank_Client_i.cpp
new file mode 100644
index 00000000000..63f86ada19e
--- /dev/null
+++ b/TAO/examples/Simple/bank/Bank_Client_i.cpp
@@ -0,0 +1,154 @@
+//$Id$
+
+#include "Bank_Client_i.h"
+#include "ace/Get_Opt.h"
+#include "ace/Read_Buffer.h"
+
+// This is the interface program that accesses the remote object
+
+// Constructor.
+Bank_Client_i::Bank_Client_i (void)
+{
+ //no-op
+}
+
+//Destructor.
+Bank_Client_i::~Bank_Client_i (void)
+{
+ //no-op
+}
+
+
+int
+Bank_Client_i::run (char *name,
+ int argc,
+ char *argv[])
+{
+ // Initialize the client.
+ if (client.init (name,argc, argv) == -1)
+ return -1;
+
+ ACE_TRY_NEW_ENV
+ {
+ this->check_accounts ();
+ if (client.shutdown () == 1)
+ client->shutdown (ACE_TRY_ENV);
+ }
+ ACE_CATCHANY
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "\nException caught in run\n"));
+ }
+ ACE_ENDTRY;
+
+ return 0;
+}
+
+int
+Bank_Client_i::check_accounts (void )
+{
+ ACE_TRY_NEW_ENV
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "\nTests for account with same name"));
+ this->test_for_same_name (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\nTests for account with different names"));
+ this->test_for_different_name (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\nTests for overdrafts"));
+ this->test_for_overdraft (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
+ }
+ ACE_CATCHANY
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "(\nFrom Bank_Client_i::check_accounts()"));
+ }
+ ACE_ENDTRY;
+ return 0;
+}
+
+// This method tests whether an account with a
+// a same name can be opened
+
+void
+Bank_Client_i::test_for_same_name (CORBA::Environment &ACE_TRY_ENV)
+{
+
+ const char *name = "Name";
+ CORBA::Float initial_bal = 0.00;
+
+ Bank::Account_var acct_id1 = client->open (name,
+ initial_bal,
+ ACE_TRY_ENV);
+
+ Bank::Account_var acct_id2 = client->open (name,
+ initial_bal,
+ ACE_TRY_ENV);
+
+ ACE_ASSERT (acct_id1->_is_equivalent ((CORBA::Object *) acct_id2.in ()) != 0);
+
+ client->close (acct_id1.in (),
+ ACE_TRY_ENV);
+
+ client->close (acct_id2.in (),
+ ACE_TRY_ENV);
+}
+
+// This method tests whether an account with different names can be opened
+
+void
+Bank_Client_i::test_for_different_name (CORBA::Environment &ACE_TRY_ENV)
+{
+ const char *name1 = "Name1";
+ const char *name2 = "Name2";
+
+ CORBA::Float initial_bal = 0.0;
+
+ Bank::Account_var acct_id1 = client->open (name1,
+ initial_bal,
+ ACE_TRY_ENV);
+
+ Bank::Account_var acct_id2 = client->open (name2,
+ initial_bal,
+ ACE_TRY_ENV);
+ ACE_ASSERT (acct_id1->_is_equivalent ((CORBA::Object *)acct_id2.in ()) == 0);
+
+ client->close (acct_id1.in (),
+ ACE_TRY_ENV);
+
+ client->close (acct_id2.in (),
+ ACE_TRY_ENV);
+}
+
+// This method tests the Overdraft exception.
+
+void
+Bank_Client_i::test_for_overdraft (CORBA::Environment &ACE_TRY_ENV)
+{
+
+ CORBA::Float initial_bal = 100.0;
+ const char *name = "Name";
+
+ Bank::Account_var acct_id = client->open (name,
+ initial_bal,
+ ACE_TRY_ENV);
+ acct_id->deposit (100.00,
+ ACE_TRY_ENV);
+
+ acct_id->withdraw (acct_id->balance (ACE_TRY_ENV) + 20);
+
+ client->close (acct_id.in (),
+ ACE_TRY_ENV);
+}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class Client<Bank,Bank_var>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate Client<Bank,Bank_var>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
diff --git a/TAO/examples/Simple/bank/Bank_Client_i.h b/TAO/examples/Simple/bank/Bank_Client_i.h
new file mode 100644
index 00000000000..d1a99b7c99f
--- /dev/null
+++ b/TAO/examples/Simple/bank/Bank_Client_i.h
@@ -0,0 +1,66 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Simple/bank
+//
+// = FILENAME
+// Bank_Client_i.h
+//
+// = DESCRIPTION
+// This class implements the interface calls for RMI.
+//
+// = AUTHOR
+//
+// Balachandran Natarajan <bala@cs.wustl.edu>
+//
+// ============================================================================
+
+#ifndef BANK_CLIENT_I_H
+#define BANK_CLIENT_I_H
+
+#include "../Simple_util.h"
+#include "BankC.h"
+
+class Bank_Client_i
+{
+ // = TITLE
+ // Grid_Client interface subclass.
+ //
+ // = DESCRIPTION
+ // This class implements the interface between the interface
+ // objects and the client .
+public:
+ // = Initialization and termination methods.
+ Bank_Client_i (void);
+ // Constructor
+
+ virtual ~Bank_Client_i (void);
+ // Destructor
+
+ virtual int run (char *,int, char *[]);
+ // Execute the methods.
+
+private:
+ Client<Bank::AccountManager, Bank::AccountManager_var> client;
+ // Instantiate the client object.
+
+ int check_accounts (void);
+ // Method that calls all the test functions
+
+ 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.
+};
+
+#endif /* TIME_CLIENT_I_H */
diff --git a/TAO/examples/Simple/bank/client.cpp b/TAO/examples/Simple/bank/client.cpp
index eddf8018816..0f426992f06 100644
--- a/TAO/examples/Simple/bank/client.cpp
+++ b/TAO/examples/Simple/bank/client.cpp
@@ -1,21 +1,23 @@
// $Id$
-#include "Client_i.h"
+# include "Bank_Client_i.h"
-ACE_RCSID(Time, client, "$Id$")
-
-// This function runs the Bank client test.
+// The client program for the application.
int
-main (int argc, char *argv[])
+main (int argc, char **argv)
{
- Client_i client;
+ Bank_Client_i client;
+
ACE_DEBUG ((LM_DEBUG,
- "[CLIENT] Process/Thread Id : (%P/%t) Bank client\n"));
+ "\nBank client\n\n"));
- if (client.init (argc, argv) == -1)
- return -1;
+ if (client.run ("Bank",argc, argv) == -1)
+ return -1;
else
- return client.run ();
+ return 0;
+
}
+
+
diff --git a/TAO/examples/Simple/bank/server.cpp b/TAO/examples/Simple/bank/server.cpp
index e664e0402be..e59fabf22f1 100644
--- a/TAO/examples/Simple/bank/server.cpp
+++ b/TAO/examples/Simple/bank/server.cpp
@@ -1,45 +1,50 @@
// $Id$
+#include "../Simple_util.h"
+#include "AccountManager_i.h"
-#include "Server_i.h"
-
-ACE_RCSID(Time, server, "$Id$")
-
-// This is the main driver program for the Bank server.
+// This is the main driver program for the time and date server.
int
main (int argc, char *argv[])
{
- Server_i server;
+ Server<AccountManager_i> server;
ACE_DEBUG ((LM_DEBUG,
- "[SERVER] Process/Thread Id : (%P/%t) Bank server\n"));
+ "\n\tBank server\n\n"));
- TAO_TRY
+ ACE_TRY_NEW_ENV
{
- if (server.init (argc, argv, TAO_TRY_ENV) == -1)
- {
- TAO_CHECK_ENV;
- return 1;
- }
+ if (server.init ("Bank",
+ argc,
+ argv,
+ ACE_TRY_ENV) == -1)
+ return 1;
else
{
- server.run (TAO_TRY_ENV);
- TAO_CHECK_ENV;
+ server.run (ACE_TRY_ENV);
+ ACE_TRY_CHECK;
}
}
- TAO_CATCH (CORBA::SystemException, sysex)
+ ACE_CATCH (CORBA::SystemException, sysex)
{
ACE_UNUSED_ARG (sysex);
- TAO_TRY_ENV.print_exception ("System Exception");
+ ACE_TRY_ENV.print_exception ("System Exception");
return -1;
}
- TAO_CATCH (CORBA::UserException, userex)
+ ACE_CATCH (CORBA::UserException, userex)
{
ACE_UNUSED_ARG (userex);
- TAO_TRY_ENV.print_exception ("User Exception");
+ ACE_TRY_ENV.print_exception ("User Exception");
return -1;
}
- TAO_ENDTRY;
+ ACE_ENDTRY;
return 0;
}
+
+#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
+template class Server<Account_Manager_i>;
+#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
+#pragma instantiate Server<Account_Manager_i>
+#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+