summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-08-31 21:47:52 +0000
committervishal <vishal@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-08-31 21:47:52 +0000
commit6b0e81a60a355da12918967ac15da539d94abaef (patch)
tree3b459024d6df864839ee344892da6f072d6e3634
parente050feb447359fd460519c4c3df0e1f52d5da369 (diff)
downloadATCD-6b0e81a60a355da12918967ac15da539d94abaef.tar.gz
*** empty log message ***
-rw-r--r--TAO/tests/Simple/bank/AccountManager_i.cpp53
-rw-r--r--TAO/tests/Simple/bank/AccountManager_i.h57
-rwxr-xr-xTAO/tests/Simple/bank/Bank.idl24
-rw-r--r--TAO/tests/Simple/bank/Bank_i.cpp47
-rw-r--r--TAO/tests/Simple/bank/Bank_i.h57
-rw-r--r--TAO/tests/Simple/bank/Client_i.cpp275
-rw-r--r--TAO/tests/Simple/bank/Client_i.h90
-rw-r--r--TAO/tests/Simple/bank/Makefile86
-rw-r--r--TAO/tests/Simple/bank/README61
-rw-r--r--TAO/tests/Simple/bank/Server_i.cpp192
-rw-r--r--TAO/tests/Simple/bank/Server_i.h91
-rw-r--r--TAO/tests/Simple/bank/client.cpp21
-rw-r--r--TAO/tests/Simple/bank/server.cpp42
13 files changed, 1096 insertions, 0 deletions
diff --git a/TAO/tests/Simple/bank/AccountManager_i.cpp b/TAO/tests/Simple/bank/AccountManager_i.cpp
new file mode 100644
index 00000000000..51938bb0fe1
--- /dev/null
+++ b/TAO/tests/Simple/bank/AccountManager_i.cpp
@@ -0,0 +1,53 @@
+// $Id$
+
+#include "AccountManager_i.h"
+#include "Bank_i.h"
+
+ACE_RCSID(AccountManager, AccountManager_i, "$Id$")
+
+// Constructor
+
+AccountManager_i::AccountManager_i (void)
+{
+ // no-op
+}
+
+// Destructor
+
+AccountManager_i::~AccountManager_i (void)
+{
+ // no-op
+}
+
+// Set the ORB pointer.
+
+void
+AccountManager_i::orb (CORBA::ORB_ptr o)
+{
+ this->orb_ = CORBA::ORB::_duplicate (o);
+}
+
+// Open an account for the given name
+
+Bank::Account_ptr
+AccountManager_i::open (const char * name,CORBA::Environment &env)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "%s %s\n",
+ "Opening an Account for",name));
+ Bank_i* bank;
+ ACE_NEW_RETURN (bank, Bank_i, Bank::Account::_nil ());
+ return bank->_this (env);
+}
+
+// Shutdown.
+
+void AccountManager_i::shutdown (CORBA::Environment &)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "%s\n",
+ "AccountManager_i is shutting down"));
+
+ // Instruct the ORB to shutdown.
+ this->orb_->shutdown ();
+}
diff --git a/TAO/tests/Simple/bank/AccountManager_i.h b/TAO/tests/Simple/bank/AccountManager_i.h
new file mode 100644
index 00000000000..a65dfcfa5c7
--- /dev/null
+++ b/TAO/tests/Simple/bank/AccountManager_i.h
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Simple/Bank
+//
+// = FILENAME
+// AccountManager_i.h
+//
+// = DESCRIPTION
+// This class implements the Bank::AccountManager IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#if !defined (ACCOUNTMANAGER_I_H)
+#define ACCOUNTMANAGER_I_H
+
+#include "BankS.h"
+
+class AccountManager_i:
+ public POA_Bank::AccountManager
+{
+ // = TITLE
+ // Bank Object Implementation
+ //
+ // = DESCRIPTION
+ // 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);
+ // Constructor
+
+ ~AccountManager_i (void);
+ // Destructor
+
+ Bank::Account_ptr open (const char *,CORBA::Environment &env);
+ // Return the Account interface with the given name from the server.
+
+ virtual void shutdown (CORBA::Environment &env);
+ // Shutdown the server
+
+ void orb (CORBA::ORB_ptr o);
+ // Set the ORB pointer.
+
+private:
+ CORBA::ORB_var orb_;
+ // ORB pointer.
+};
+
+#endif /* ACCOUNTMANAGER_I_H */
diff --git a/TAO/tests/Simple/bank/Bank.idl b/TAO/tests/Simple/bank/Bank.idl
new file mode 100755
index 00000000000..96e768b4c7c
--- /dev/null
+++ b/TAO/tests/Simple/bank/Bank.idl
@@ -0,0 +1,24 @@
+// $Id$
+// Bank.idl
+
+module Bank
+{
+ // = TITLE
+ // @@ Give a brief explain of what this module does.
+
+ interface Account
+ {
+ // = TITLE
+ // @@ Give a brief explain of what this interface does.
+
+ float balance ();
+ };
+
+ interface AccountManager
+ {
+ // = TITLE
+ // @@ Give a brief explain of what this interface does.
+
+ Account open (in string name);
+ };
+};
diff --git a/TAO/tests/Simple/bank/Bank_i.cpp b/TAO/tests/Simple/bank/Bank_i.cpp
new file mode 100644
index 00000000000..70341f2ba69
--- /dev/null
+++ b/TAO/tests/Simple/bank/Bank_i.cpp
@@ -0,0 +1,47 @@
+// $Id$
+
+#include "Bank_i.h"
+
+ACE_RCSID(Bank, Bank_i, "$Id$")
+
+// Constructor
+
+Bank_i::Bank_i (void)
+{
+ // no-op
+}
+
+// Destructor
+
+Bank_i::~Bank_i (void)
+{
+ // no-op
+}
+
+// Set the ORB pointer.
+
+void
+Bank_i::orb (CORBA::ORB_ptr o)
+{
+ this->orb_ = CORBA::ORB::_duplicate (o);
+}
+
+// Return the current balance on the server.
+
+CORBA::Float
+Bank_i::balance (CORBA::Environment &)
+{
+ return CORBA::Float (100);
+}
+
+// Shutdown.
+
+void Bank_i::shutdown (CORBA::Environment &)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "%s\n",
+ "Bank_i is shutting down"));
+
+ // Instruct the ORB to shutdown.
+ this->orb_->shutdown ();
+}
diff --git a/TAO/tests/Simple/bank/Bank_i.h b/TAO/tests/Simple/bank/Bank_i.h
new file mode 100644
index 00000000000..57dd47d7965
--- /dev/null
+++ b/TAO/tests/Simple/bank/Bank_i.h
@@ -0,0 +1,57 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Simple/Bank
+//
+// = FILENAME
+// Bank_i.h
+//
+// = DESCRIPTION
+// This class implements the Bank IDL interface.
+//
+// = AUTHOR
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#if !defined (BANK_I_H)
+#define BANK_I_H
+
+#include "BankS.h"
+
+class Bank_i:
+ public POA_Bank::Account
+{
+ // = TITLE
+ // Bank Object Implementation
+ //
+ // = DESCRIPTION
+ // Implementation of a simple object that has two methods, one that
+ // return the current balance on the server and the other that
+ // shuts down the server.
+public:
+ // = Initialization and termination methods.
+ Bank_i (void);
+ // Constructor
+
+ ~Bank_i (void);
+ // Destructor
+
+ virtual CORBA::Float balance (CORBA::Environment &env);
+ // Return the current time/date on the server.
+
+ virtual void shutdown (CORBA::Environment &env);
+ // Shutdown the server.
+
+ void orb (CORBA::ORB_ptr o);
+ // Set the ORB pointer.
+
+private:
+ CORBA::ORB_var orb_;
+ // ORB pointer.
+};
+
+#endif /* BANK_I_H */
diff --git a/TAO/tests/Simple/bank/Client_i.cpp b/TAO/tests/Simple/bank/Client_i.cpp
new file mode 100644
index 00000000000..b2f0294cf37
--- /dev/null
+++ b/TAO/tests/Simple/bank/Client_i.cpp
@@ -0,0 +1,275 @@
+// $Id$
+
+#include "Client_i.h"
+#include "ace/Get_Opt.h"
+#include "ace/Read_Buffer.h"
+
+ACE_RCSID(Bank, Client_i, "$Id$")
+
+// Constructor.
+Client_i::Client_i (void)
+ : ior_ (0),
+ loop_count_ (10),
+ shutdown_ (0),
+ server_ ()
+{
+}
+
+// Reads the Server factory ior from a file
+
+int
+Client_i::read_ior (char *filename)
+{
+ // Open the file for reading.
+ ACE_HANDLE f_handle = ACE_OS::open (filename, 0);
+
+ if (f_handle == ACE_INVALID_HANDLE)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Unable to open %s for writing: %p\n",
+ filename),
+ -1);
+
+ ACE_Read_Buffer ior_buffer (f_handle);
+ char *data = ior_buffer.read ();
+
+ if (data == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Unable to read ior: %p\n"),
+ -1);
+
+ this->ior_ = ACE_OS::strdup (data);
+ ior_buffer.alloc ()->free (data);
+
+ ACE_OS::close (f_handle);
+
+ return 0;
+}
+
+// Parses the command line arguments and returns an error status.
+
+int
+Client_i::parse_args (void)
+{
+ ACE_Get_Opt get_opts (argc_, argv_, "dn:f:xk:");
+ int c;
+ int result;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'd': // debug flag
+ TAO_debug_level++;
+ break;
+ case 'n': // loop count
+ this->loop_count_ = (u_int) ACE_OS::atoi (get_opts.optarg);
+ break;
+ case 'k': // ior provide on command line
+ this->ior_ = ACE_OS::strdup (get_opts.optarg);
+ break;
+ case 'f': // read the IOR from the file.
+ result = this->read_ior (get_opts.optarg);
+ if (result < 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Unable to read ior from %s : %p\n",
+ get_opts.optarg),
+ -1);
+ break;
+ case 'x':
+ this->shutdown_ = 1;
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s"
+ " [-d]"
+ " [-n loopcount]"
+ " [-f ior-file]"
+ " [-k ior]"
+ " [-x]"
+ "\n",
+ this->argv_ [0]),
+ -1);
+ }
+
+ // Indicates successful parsing of command line.
+ return 0;
+}
+
+// Call the remote methods on the Account and AccountManager interface
+
+CORBA::Float
+Client_i::balance (void)
+{
+ // Make the RMI.
+
+ CORBA::Float My_balance = 200.00;
+
+ My_balance = this->server_->balance (this->env_);
+
+ this->accountmanager_server_->open("Vishal",this->env_);
+
+ if (this->env_.exception () != 0)
+ this->env_.print_exception ("from balance");
+ else
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "balance is %f\n",
+ My_balance));
+ }
+
+return 0;
+}
+
+// Execute client example code.
+
+int
+Client_i::run (void)
+{
+ u_int i;
+
+ for (i = 0; i < this->loop_count_; i++)
+ {
+ this->balance ();
+ ACE_OS::sleep (1);
+ }
+
+ if (this->shutdown_)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "Operation Shutdown not defined\n"
+ ));
+
+ }
+
+ return 0;
+}
+
+Client_i::~Client_i (void)
+{
+ ACE_OS::free (this->ior_);
+}
+
+
+int
+Client_i::init_naming_service (void)
+{
+ TAO_TRY
+ {
+
+ // Initialize the naming services
+ if (my_name_client_.init (orb_.in (), argc_, argv_) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize "
+ "the TAO_Naming_Client. \n"),
+ -1);
+
+ CosNaming::Name bank_context_name (2);
+ bank_context_name.length (2);
+ bank_context_name[0].id =
+ CORBA::string_dup ("IDL_Bank");
+ bank_context_name[1].id =
+ CORBA::string_dup ("Bank");
+
+ CORBA::Object_var account_obj =
+ my_name_client_->resolve (bank_context_name,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ this->server_ =
+ Bank::Account::_narrow (account_obj.in (),
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ if (CORBA::is_nil (this->server_.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " could not resolve IDL_Bank:Bank in the Naming service" "<%s>\n"),
+ -1);
+
+
+ bank_context_name[1].id =
+ CORBA::string_dup ("AccountManager");
+
+ CORBA::Object_var account_manager_obj =
+ my_name_client_->resolve (bank_context_name,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ this->accountmanager_server_ =
+ Bank::AccountManager::_narrow (account_manager_obj.in (),
+ TAO_TRY_ENV);
+
+ TAO_CHECK_ENV;
+
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("Bank::init_naming_service");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+}
+
+
+// This method uses the IOR if specified on the command line or in a file, else
+// it uses the Naming Service
+
+int
+Client_i::init (int argc, char **argv)
+{
+ this->argc_ = argc;
+ this->argv_ = argv;
+
+ TAO_TRY
+ {
+ // Retrieve the ORB.
+ this->orb_ = CORBA::ORB_init (this->argc_,
+ this->argv_,
+ 0,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Parse command line and verify parameters.
+ if (this->parse_args () == -1)
+ return -1;
+
+
+ if (this->ior_)
+ { // An ior is specified for the client through a
+ // commandline option or a file
+
+ CORBA::Object_var server_object =
+ this->orb_->string_to_object (this->ior_,
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ if (CORBA::is_nil (server_object.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "invalid ior <%s>\n",
+ this->ior_),
+ -1);
+
+ this->server_ = Bank::Account::_narrow (server_object.in (),
+ TAO_TRY_ENV);
+
+ ACE_DEBUG((LM_DEBUG,"Using the IOR provided\n"));
+ TAO_CHECK_ENV;
+ }
+ else
+ { // No IOR specified. Use the Naming Service
+ ACE_DEBUG((LM_DEBUG,"Using the Naming Service\n"));
+
+ init_naming_service();
+ TAO_CHECK_ENV;
+ }
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("Client_i::init");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+}
diff --git a/TAO/tests/Simple/bank/Client_i.h b/TAO/tests/Simple/bank/Client_i.h
new file mode 100644
index 00000000000..c74b262bef2
--- /dev/null
+++ b/TAO/tests/Simple/bank/Client_i.h
@@ -0,0 +1,90 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Simple
+//
+// = FILENAME
+// Client_i.h
+//
+// = DESCRIPTION
+// This class implements a simple CORBA client that accesses a Bank
+// server.
+//
+// = AUTHORS
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#include "BankC.h"
+#include "orbsvcs/Naming/Naming_Utils.h"
+
+class Client_i
+{
+ // = TITLE
+ // Simple Client implementation.
+ //
+ // = DESCRIPTION
+ // Class wrapper for a client that gets the server IOR and then
+ // makes several calls to the server before optionally shutting
+ // it down.
+public:
+ // = Initialization and termination methods.
+ Client_i (void);
+ // Constructor.
+
+ ~Client_i (void);
+ // Destructor.
+
+ int run (void);
+ // Execute client example code.
+
+ int init (int argc, char *argv[]);
+ // Initialize the client communication endpoint with server.
+
+private:
+ int read_ior (char *filename);
+ // Function to read the server IOR from a file.
+
+ int parse_args (void);
+ // Parses the arguments passed on the command line.
+
+ CORBA::Float balance (void);
+ // Return the balance in the account
+
+ int init_naming_service (void);
+ // To initialize the naming service and get a ptr. to server
+
+ int argc_;
+ // # of arguments on the command line.
+
+ char **argv_;
+ // arguments from command line.
+
+ char *ior_;
+ // IOR of the obj ref of the server.
+
+ u_int loop_count_;
+ // Number of times to invoke the <time> operation.
+
+ int shutdown_;
+ // Flag for server shutdown.
+
+ CORBA::Environment env_;
+ // Environment variable.
+
+ Bank::Account_var server_;
+ // Account Server object ptr.
+
+ Bank::AccountManager_var accountmanager_server_;
+ // Account Manager server object ptr.
+
+ TAO_Naming_Client my_name_client_;
+ // An instance of the name client used for resolving the factory
+ // objects
+
+ CORBA::ORB_var orb_;
+ // Remember our orb.
+};
diff --git a/TAO/tests/Simple/bank/Makefile b/TAO/tests/Simple/bank/Makefile
new file mode 100644
index 00000000000..9a0a38d92a4
--- /dev/null
+++ b/TAO/tests/Simple/bank/Makefile
@@ -0,0 +1,86 @@
+#----------------------------------------------------------------------------
+#
+# $Id$
+#
+#----------------------------------------------------------------------------
+
+#----------------------------------------------------------------------------
+# Local macros
+#----------------------------------------------------------------------------
+
+ifndef TAO_ROOT
+ TAO_ROOT = $(ACE_ROOT)/TAO
+endif # ! TAO_ROOT
+
+LDLIBS = -lorbsvcs -lTAO
+
+IDL_SRC = BankC.cpp BankS.cpp
+
+PROG_SRCS = \
+ cli/projectent.cpp \
+ Client_i.cpp \
+ server.cpp \
+ Server_i.cpp \
+ Bank_i.cpp \
+ AccountManager_i.cpp \
+
+SRC = $(IDL_SRC) $(PROG_SRCS)
+
+SIMPLE_CLT_OBJS = \
+ BankC.o \
+ BankS.o \
+ Client_i.o \
+ client.o
+SIMPLE_SVR_OBJS = \
+ BankC.o \
+ BankS.o \
+ Bank_i.o \
+ AccountManager_i.o \
+ Server_i.o \
+ server.o
+
+BIN = server \
+ client
+BUILD = $(BIN)
+VLDLIBS = $(LDLIBS:%=%$(VAR))
+VBIN = $(BIN:%=%$(VAR))
+
+#----------------------------------------------------------------------------
+# Include macros and targets
+#----------------------------------------------------------------------------
+
+include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU
+include $(ACE_ROOT)/include/makeinclude/macros.GNU
+include $(TAO_ROOT)/rules.tao.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.common.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU
+include $(ACE_ROOT)/include/makeinclude/rules.local.GNU
+include $(TAO_ROOT)/taoconfig.mk
+
+#----------------------------------------------------------------------------
+# Local targets
+#----------------------------------------------------------------------------
+
+
+LDFLAGS += -L$(TAO_ROOT)/orbsvcs/orbsvcs -L$(TAO_ROOT)/tao -L$(TAO_ROOT)/orbsvcs/Naming_Service
+CPPFLAGS += -I$(TAO_ROOT)/orbsvcs
+
+.PRECIOUS: BankC.cpp BankC.i BankC.h
+.PRECIOUS: BankS.cpp BankS.i BankS.h
+.PRECIOUS: BankS_T.cpp BankS_T.i BankS_T.h
+
+server: $(addprefix $(VDIR),$(SIMPLE_SVR_OBJS))
+ $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)
+
+client: $(addprefix $(VDIR),$(SIMPLE_CLT_OBJS))
+ $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK)
+
+realclean: clean
+ -/bin/rm -rf BankC.* BankS.* BankS_T.*
+
+# DO NOT DELETE THIS LINE -- g++dep uses it.
+# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
+
+
+
+# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
diff --git a/TAO/tests/Simple/bank/README b/TAO/tests/Simple/bank/README
new file mode 100644
index 00000000000..97d7a49e5f8
--- /dev/null
+++ b/TAO/tests/Simple/bank/README
@@ -0,0 +1,61 @@
+$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 the server.
+
+server:
+-------
+
+server [-d]
+
+Options:
+-------
+-d Debug flag (It is additive more -d flags will give debugging).
+
+When the server is started, you should see as the first line of output
+something that looks like
+ iiop:1.0//danzon.cs.wustl.edu:10015/P35ad159600081a38/child_poa/server
+ (-ORBobjrefstyle url)
+or
+ IOR:000000000000001649444c3a43756269745...
+ (-ORBobjrefstyle ior)
+
+Using -d turns on debugging messages. This option is additive, i.e.,
+the more -d options provided, the more debugging you can get. At the
+moment, only 2 levels of debugging are implemented, and more than 2 -d
+options are ignored.
+
+client:
+-------
+
+client [-d] [-x] [-n iterations]
+
+Options:
+-------
+-d Debug flag
+-x Tells the server to shutdown at the end of the test.
+-n no. of iterations
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/TAO/tests/Simple/bank/Server_i.cpp b/TAO/tests/Simple/bank/Server_i.cpp
new file mode 100644
index 00000000000..29f5918cd3a
--- /dev/null
+++ b/TAO/tests/Simple/bank/Server_i.cpp
@@ -0,0 +1,192 @@
+// $Id$
+
+#include "Server_i.h"
+#include "ace/Get_Opt.h"
+
+ACE_RCSID(Bank, Server_i, "$Id$")
+
+// Constructor.
+
+Server_i::Server_i (void)
+ : ior_output_file_ (0)
+{
+ // no-op.
+}
+
+// Destructor.
+
+Server_i::~Server_i (void)
+{
+ // no-op.
+}
+
+// Parse the command-line arguments and set options.
+
+int
+Server_i::parse_args (void)
+{
+ ACE_Get_Opt get_opts (this->argc_, this->argv_, "do:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'd': // debug flag.
+ TAO_debug_level++;
+ break;
+ case 'o': // output the IOR to a file.
+ this->ior_output_file_ = ACE_OS::fopen (get_opts.optarg, "w");
+ if (this->ior_output_file_ == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Unable to open %s for writing: %p\n",
+ get_opts.optarg), -1);
+ break;
+ case '?': // display help for use of the server.
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s"
+ " [-d]"
+ " [-o] <ior_output_file>"
+ "\n",
+ argv_ [0]),
+ 1);
+ }
+
+ // Indicates successful parsing of command line.
+ return 0;
+}
+
+// Initialize the server.
+
+int
+Server_i::init (int argc, char *argv[], CORBA::Environment &env)
+{
+ // 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,
+ argv,
+ "child_poa",
+ env) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "init_child_poa"),
+ -1);
+ TAO_CHECK_ENV_RETURN (env, -1);
+
+ this->argc_ = argc;
+ this->argv_ = argv;
+
+ int retval = this->parse_args ();
+
+ if (retval != 0)
+ return retval;
+
+ CORBA::ORB_var orb = this->orb_manager_.orb ();
+
+ // Stash our ORB pointer for later reference.
+ this->servant_.orb (orb.in ());
+
+ // Now create the implementations
+ this->bank_impl_ = new Bank_i();
+
+ this->account_manager_impl_ = new AccountManager_i();
+
+ // Activate the servant in its own child POA.
+ CORBA::String_var str =
+ this->orb_manager_.activate_under_child_poa ("Bank",
+ &this->servant_,
+ env);
+ ACE_DEBUG ((LM_DEBUG,
+ "The IOR is: <%s>\n",
+ str.in ()));
+
+ if (this->ior_output_file_)
+ {
+ ACE_OS::fprintf (this->ior_output_file_,
+ "%s",
+ str.in ());
+ ACE_OS::fclose (this->ior_output_file_);
+ }
+
+ this->init_naming_service (env);
+
+ return 0;
+}
+
+
+int
+Server_i::run (CORBA::Environment &env)
+{
+ // Run the main event loop for the ORB.
+ if (this->orb_manager_.run (env) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Server_i::run"),
+ -1);
+
+ return 0;
+}
+
+
+// Initialisation of Naming Service and register IDL_Bank Context and
+// the Account and Account Manager objects.
+
+int
+Server_i::init_naming_service (CORBA::Environment& env)
+{
+ int result;
+ CORBA::ORB_var orb;
+ PortableServer::POA_var child_poa;
+
+ orb = this->orb_manager_.orb ();
+ child_poa = this->orb_manager_.child_poa ();
+
+ result = this->my_name_server_.init (orb.in (),
+ child_poa.in ());
+ if (result < 0)
+ return result;
+
+
+ // Generate an IOR for the Account Object and register it with POA
+
+ Bank::Account_var account = this->bank_impl_->_this (env);
+ TAO_CHECK_ENV_RETURN (env,-1);
+
+
+ // Generate an IOR for the AccountManager Object and register it with POA
+
+ Bank::AccountManager_var accountManager = this->account_manager_impl_->_this (env);
+ TAO_CHECK_ENV_RETURN (env,-1);
+
+
+ // Bind the Bank Context with the naming service
+
+ CosNaming::Name bank_context_name (1);
+ bank_context_name.length (1);
+ bank_context_name[0].id = CORBA::string_dup ("IDL_Bank");
+ this->bank_context_ =
+ this->my_name_server_->bind_new_context (bank_context_name,
+ env);
+ TAO_CHECK_ENV_RETURN (env,-1);
+
+
+ //Bind the Account object with the Bank Context
+
+ CosNaming::Name account_name (1);
+ account_name.length (1);
+ account_name[0].id = CORBA::string_dup ("Bank");
+ this->bank_context_->bind (account_name,
+ account.in (),
+ env);
+
+ //Bind the AccountManager object with the Bank Context
+
+ CosNaming::Name account_manager_name (1);
+ account_manager_name.length (1);
+ account_manager_name[0].id = CORBA::string_dup ("AccountManager");
+ this->bank_context_->bind (account_manager_name,
+ accountManager.in (),
+ env);
+ //TAO_CHECK_ENV_RETURN (env,-1);
+
+ return 0;
+}
diff --git a/TAO/tests/Simple/bank/Server_i.h b/TAO/tests/Simple/bank/Server_i.h
new file mode 100644
index 00000000000..a771b930fb6
--- /dev/null
+++ b/TAO/tests/Simple/bank/Server_i.h
@@ -0,0 +1,91 @@
+// -*- C++ -*-
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/tests/Simple
+//
+// = FILENAME
+// Server_i.h
+//
+// = DESCRIPTION
+// A CORBA server that initializes the Account and AccountManager server
+// implementations and the ORB.
+//
+// = AUTHORS
+// Vishal Kachroo <vishal@cs.wustl.edu>
+//
+// ============================================================================
+
+#if !defined (SERVER_I_H)
+#define SERVER_I_H
+
+#include "Bank_i.h"
+#include "AccountManager_i.h"
+#include "tao/TAO.h"
+
+#include "ace/Get_Opt.h"
+#include "ace/Log_Msg.h"
+#include "orbsvcs/CosNamingC.h"
+#include "orbsvcs/Naming/Naming_Utils.h"
+
+
+class Server_i
+{
+ // = TITLE
+ // CORBA Server implementation.
+public:
+ // = Initialization and termination methods.
+ Server_i (void);
+ // Constructor.
+
+ ~Server_i (void);
+ // Destructor.
+
+ int init (int argc, char *argv[], CORBA::Environment &env);
+ // Initialize the Server state - parsing arguments and waiting.
+
+ int run (CORBA::Environment &env);
+ // Run the orb.
+
+private:
+ Bank_i servant_;
+ // Servant for the Account interface.
+
+ int parse_args (void);
+ // Parses the commandline arguments.
+
+ TAO_ORB_Manager orb_manager_;
+ // The ORB manager.
+
+ FILE *ior_output_file_;
+ // File where the IOR of the server object is stored.
+
+ int init_naming_service (CORBA::Environment &env);
+ // Initialises the name server and registers the Account and AccountManager
+ // objects with it.
+
+ TAO_Naming_Server my_name_server_;
+ // An instance of the name server used for registering the Account and Accoun // tManager objects
+
+ Bank_i *bank_impl_;
+ // Implementation of the Account object.
+
+ AccountManager_i *account_manager_impl_;
+ // Implementation of the Account Manager Object
+
+ CosNaming::NamingContext_var bank_context_;
+ // Naming context for the Account and AccountManager Objects.
+
+ CosNaming::NamingContext_var naming_context_;
+ // Naming context for the Naming Service
+
+ int argc_;
+ // Number of command line arguments.
+
+ char **argv_;
+ // The command line arguments.
+};
+
+#endif /* TIME_IMPL_H */
diff --git a/TAO/tests/Simple/bank/client.cpp b/TAO/tests/Simple/bank/client.cpp
new file mode 100644
index 00000000000..00cb9e5a9fc
--- /dev/null
+++ b/TAO/tests/Simple/bank/client.cpp
@@ -0,0 +1,21 @@
+// $Id$
+
+#include "Client_i.h"
+
+ACE_RCSID(Time, client, "$Id$")
+
+// This function runs the Bank test.
+
+int
+main (int argc, char **argv)
+{
+ Client_i client;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\n\tBank client\n\n"));
+
+ if (client.init (argc, argv) == -1)
+ return -1;
+ else
+ return client.run ();
+}
diff --git a/TAO/tests/Simple/bank/server.cpp b/TAO/tests/Simple/bank/server.cpp
new file mode 100644
index 00000000000..182c6c24b4f
--- /dev/null
+++ b/TAO/tests/Simple/bank/server.cpp
@@ -0,0 +1,42 @@
+// $Id$
+
+#include "Server_i.h"
+
+ACE_RCSID(Time, server, "$Id$")
+
+// This is the main driver program for the Bank server.
+
+int
+main (int argc, char *argv[])
+{
+ Server_i server;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "\n\t Bank server\n\n"));
+
+ TAO_TRY
+ {
+ if (server.init (argc, argv, TAO_TRY_ENV) == -1)
+ return 1;
+ else
+ {
+ server.run (TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+ }
+ }
+ TAO_CATCH (CORBA::SystemException, sysex)
+ {
+ ACE_UNUSED_ARG (sysex);
+ TAO_TRY_ENV.print_exception ("System Exception");
+ return -1;
+ }
+ TAO_CATCH (CORBA::UserException, userex)
+ {
+ ACE_UNUSED_ARG (userex);
+ TAO_TRY_ENV.print_exception ("User Exception");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+}