summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/tests/Concurrency/NS_client.cpp
diff options
context:
space:
mode:
authortworm <tworm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-05-04 14:23:13 +0000
committertworm <tworm@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1998-05-04 14:23:13 +0000
commitdafafdddbcce29557f589a57af4485c15d1105d4 (patch)
treead4791f61c4a01422086ae528fa4b9e717798f40 /TAO/orbsvcs/tests/Concurrency/NS_client.cpp
parent770eddece2a5a7f12dc42a9b471ce16378043ecf (diff)
downloadATCD-dafafdddbcce29557f589a57af4485c15d1105d4.tar.gz
First version
Diffstat (limited to 'TAO/orbsvcs/tests/Concurrency/NS_client.cpp')
-rw-r--r--TAO/orbsvcs/tests/Concurrency/NS_client.cpp161
1 files changed, 161 insertions, 0 deletions
diff --git a/TAO/orbsvcs/tests/Concurrency/NS_client.cpp b/TAO/orbsvcs/tests/Concurrency/NS_client.cpp
new file mode 100644
index 00000000000..6ef7299e4d3
--- /dev/null
+++ b/TAO/orbsvcs/tests/Concurrency/NS_client.cpp
@@ -0,0 +1,161 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// TAO/orbsvcs/bin/Naming_Service/TAO
+//
+// = FILENAME
+// clnt.cpp
+//
+// = DESCRIPTION
+// This class implements a simple CORBA client for the CosNaming
+// example using stubs generated by the TAO ORB IDL compiler.
+//
+// = AUTHORS
+// Sergio Flores-Gaitan <sergio@cs.wustl.edu>
+// Torben Worm <tworm@cs.wustl.edu>
+//
+// ============================================================================
+
+#include "NS_client.h"
+
+// constructor
+
+CosNaming_Client::CosNaming_Client (void)
+ : argc_ (0),
+ argv_ (0),
+ exit_later_ (0),
+ resolve_name_ (0),
+ name_to_resolve_ (0)
+{
+}
+
+// Parses the command line arguments and returns an error status.
+
+int
+CosNaming_Client::parse_args (void)
+{
+ ACE_Get_Opt get_opts (argc_, argv_, "dxn:");
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'd': // debug flag
+ TAO_debug_level++;
+ break;
+ case 'x':
+ this->exit_later_++;
+ break;
+ case 'n':
+ this->resolve_name_ = 1;
+ this->name_to_resolve_ = get_opts.optarg;
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s"
+ " [-d]"
+ " [-x]"
+ "\n",
+ this->argv_ [0]),
+ -1);
+ }
+
+ // Indicates successful parsing of command line.
+ return 0;
+}
+
+// Execute client example code.
+
+int
+CosNaming_Client::run (void)
+{
+ // @@ TODO, add some interesting test here, maybe creating some
+ // nested naming contexts and registering a number of objreferences
+ // in there.
+ // We could even use the iterators.
+
+ if(this->resolve_name_)
+ resolve_name(this->name_to_resolve_);
+ return 0;
+}
+
+CosNaming_Client::~CosNaming_Client (void)
+{
+}
+
+int CosNaming_Client::resolve_name(char *n)
+{
+ TAO_TRY
+ {
+ CosNaming::Name name (2);
+ name.length (2);
+ name[0].id = CORBA::string_dup ("CosConcurrency");
+ name[1].id = CORBA::string_dup ("LockSetFactory");
+ CORBA::Object_var obj = this->naming_context_->resolve (name,TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ if (CORBA::is_nil (obj.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Could not resolve name in Naming service <%s>\n"),
+ -1);
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("init");
+ return -1;
+ }
+ TAO_ENDTRY;
+}
+
+int
+CosNaming_Client::init (int argc, char **argv)
+{
+ this->argc_ = argc;
+ this->argv_ = argv;
+
+ TAO_TRY
+ {
+ // Initialize ORB.
+ this->orb_ = CORBA::ORB_init (argc, argv, "internet", TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ CORBA::Object_var naming_obj =
+ orb_->resolve_initial_references ("NameService");
+ if (CORBA::is_nil (naming_obj.in ()))
+ ACE_ERROR_RETURN ((LM_ERROR,
+ " (%P|%t) Unable to initialize the POA.\n"),
+ -1);
+
+ naming_context_ = CosNaming::NamingContext::_narrow (naming_obj.in (),
+ TAO_TRY_ENV);
+ TAO_CHECK_ENV;
+
+ // Parse command line and verify parameters.
+ if (this->parse_args () == -1)
+ return -1;
+ }
+ TAO_CATCHANY
+ {
+ TAO_TRY_ENV.print_exception ("init");
+ return -1;
+ }
+ TAO_ENDTRY;
+
+ return 0;
+}
+
+// This function runs the test.
+
+int
+main (int argc, char **argv)
+{
+ CosNaming_Client cosnaming_client;
+
+ if (cosnaming_client.init (argc, argv) == -1)
+ return 1;
+
+ return cosnaming_client.run ();
+}