From dafafdddbcce29557f589a57af4485c15d1105d4 Mon Sep 17 00:00:00 2001 From: tworm Date: Mon, 4 May 1998 14:23:13 +0000 Subject: First version --- TAO/orbsvcs/tests/Concurrency/CC_client.cpp | 286 ++++++++++++++++++++++++++++ TAO/orbsvcs/tests/Concurrency/CC_client.h | 86 +++++++++ TAO/orbsvcs/tests/Concurrency/NS_client.cpp | 161 ++++++++++++++++ TAO/orbsvcs/tests/Concurrency/NS_client.h | 75 ++++++++ TAO/orbsvcs/tests/Concurrency/svc.conf | 49 +++++ TAO/orbsvcs/tests/Concurrency/tmplinst.cpp | 15 ++ 6 files changed, 672 insertions(+) create mode 100644 TAO/orbsvcs/tests/Concurrency/CC_client.cpp create mode 100644 TAO/orbsvcs/tests/Concurrency/CC_client.h create mode 100644 TAO/orbsvcs/tests/Concurrency/NS_client.cpp create mode 100644 TAO/orbsvcs/tests/Concurrency/NS_client.h create mode 100644 TAO/orbsvcs/tests/Concurrency/svc.conf create mode 100644 TAO/orbsvcs/tests/Concurrency/tmplinst.cpp (limited to 'TAO/orbsvcs/tests/Concurrency') diff --git a/TAO/orbsvcs/tests/Concurrency/CC_client.cpp b/TAO/orbsvcs/tests/Concurrency/CC_client.cpp new file mode 100644 index 00000000000..ab081be0d48 --- /dev/null +++ b/TAO/orbsvcs/tests/Concurrency/CC_client.cpp @@ -0,0 +1,286 @@ +// $Id$ + +//#include "ace/Profile_Timer.h" +//#include "ace/Env_Value_T.h" +#include "ace/Read_Buffer.h" +#include "CC_client.h" +#include "orbsvcs/CosNamingC.h" + +// Constructor. +CC_Client::CC_Client (void) + : cc_factory_key_ (0), + shutdown_ (0), + cc_lock_set_ (CosConcurrencyControl::LockSet::_nil ()), + cc_factory_ior_file_ (0), + f_handle_ (ACE_INVALID_HANDLE), + use_naming_service_ (1) +{ +} + +// Reads the lock set factory ior from a file + +int +CC_Client::read_ior (char *filename) +{ + // Open the file for reading. + this->f_handle_ = ACE_OS::open (filename,0); + + if (this->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 (this->f_handle_); + this->cc_factory_key_ = ior_buffer.read (); + + if (this->cc_factory_key_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to allocate memory to read ior: %p\n"), + -1); + return 0; +} + +// Parses the command line arguments and returns an error status. + +int +CC_Client::parse_args (void) +{ + ACE_Get_Opt get_opts (argc_, argv_, "dsf:k:x"); + int c; + int result; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'd': // debug flag + TAO_debug_level++; + 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 'k': // read the cubit IOR from the command-line. + this->cc_factory_key_ = + ACE_OS::strdup (get_opts.optarg); + break; + case 'x': + this->shutdown_ = 1; + break; + case 's': // Don't use the TAO Naming Service. + this->use_naming_service_ = 0; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-f cc_factory-obj-ref-key-file]" + " [-k cc-obj-ref-key]" + " [-x]" + " [-s]" + "\n", + this->argv_ [0]), + -1); + } + + // Indicates successful parsing of command line. + return 0; +} + +// Execute client example code. + +int +CC_Client::run (void) +{ + CORBA::Environment _env; + CORBA::Boolean lock_held; + + this->cc_lock_set_->lock(CosConcurrencyControl::read, _env); + ACE_DEBUG((LM_DEBUG, "Read lock set\n")); + lock_held = this->cc_lock_set_->try_lock(CosConcurrencyControl::read, _env); + if(lock_held) + ACE_DEBUG((LM_DEBUG, "Read lock not held\n")); + else + ACE_DEBUG((LM_DEBUG, "Read lock held\n")); + this->cc_lock_set_->unlock(CosConcurrencyControl::read, _env); + ACE_DEBUG((LM_DEBUG, "Read lock released\n")); + this->cc_lock_set_->lock(CosConcurrencyControl::write, _env); + ACE_DEBUG((LM_DEBUG, "Write lock set\n")); + + + + if (this->shutdown_) + { + // @@TAO is this needed?? + } + + return 0; +} + +CC_Client::~CC_Client (void) +{ + // Free resources + // Close the ior files + if (this->cc_factory_ior_file_) + ACE_OS::fclose (this->cc_factory_ior_file_); + if (this->f_handle_ != ACE_INVALID_HANDLE) + ACE_OS::close (this->f_handle_); + + CORBA::release (this->cc_lock_set_); + + if (this->cc_factory_key_ != 0) + ACE_OS::free (this->cc_factory_key_); +} + +int +CC_Client::init_naming_service (void) +{ + TAO_TRY + { + CORBA::Object_var naming_obj = + this->orb_->resolve_initial_references ("NameService"); + if (CORBA::is_nil (naming_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to resolve the Name Service.\n"), + -1); + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + CosNaming::Name cc_factory_name (2); + cc_factory_name.length (2); + cc_factory_name[0].id = CORBA::string_dup ("CosConcurrency"); + cc_factory_name[1].id = CORBA::string_dup ("LockSetFactory"); + CORBA::Object_var factory_obj = + naming_context->resolve (cc_factory_name,TAO_TRY_ENV); + TAO_CHECK_ENV; + + this->factory_ = + CosConcurrencyControl::LockSetFactory::_narrow + (factory_obj.in (),TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (this->factory_.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " could not resolve lock set factory in Naming service <%s>\n"), + -1); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("CC_Client::init_naming_service"); + return -1; + } + TAO_ENDTRY; + + return 0; +} + +int +CC_Client::init (int argc, char **argv) +{ + int naming_result; + this->argc_ = argc; + this->argv_ = argv; + + TAO_TRY + { + // Retrieve the ORB. + this->orb_ = CORBA::ORB_init (this->argc_, + this->argv_, + "internet", + TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Parse command line and verify parameters. + if (this->parse_args () == -1) + return -1; + + if (this->use_naming_service_) + { + naming_result = this->init_naming_service (); + if (naming_result < 0) + return naming_result; + } + else + { + if (this->cc_factory_key_ == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "%s: no lock set factory key specified\n", + this->argv_[0]), + -1); + + + CORBA::Object_var factory_object = + this->orb_->string_to_object (this->cc_factory_key_, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + this->factory_ = + CosConcurrencyControl::LockSetFactory::_narrow + (factory_object.in(), TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (this->factory_.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "invalid factory key <%s>\n", + this->cc_factory_key_), + -1); + } + + ACE_DEBUG ((LM_DEBUG, "Factory received OK\n")); + + // Now create the lock set and return an obj ref corresponding + // to the key. + this->cc_lock_set_ = + this->factory_->create (TAO_TRY_ENV); + TAO_CHECK_ENV; + + if (CORBA::is_nil (this->cc_lock_set_)) + ACE_ERROR_RETURN ((LM_ERROR, + "null lock set objref returned by factory\n"), + -1); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("CC_Client::init"); + return -1; + } + TAO_ENDTRY; + + return 0; +} + +// This function runs the test. + +int +main (int argc, char **argv) +{ + CC_Client cc_client; + + ACE_DEBUG ((LM_DEBUG, + "\n \t CosConcurrencyControl: client \n\n")); + + if (cc_client.init (argc, argv) == -1) + { + ACE_DEBUG((LM_DEBUG, "Did not initialize correctly\n")); + return 1; + } + else + { + ACE_DEBUG((LM_DEBUG, "Running the test\n")); + return cc_client.run (); + } +} + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class ACE_Env_Value; +template class ACE_Env_Value; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate ACE_Env_Value +#pragma instantiate ACE_Env_Value +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/orbsvcs/tests/Concurrency/CC_client.h b/TAO/orbsvcs/tests/Concurrency/CC_client.h new file mode 100644 index 00000000000..3d8bf0fa911 --- /dev/null +++ b/TAO/orbsvcs/tests/Concurrency/CC_client.h @@ -0,0 +1,86 @@ +// -*- c++ -*- +// $Id$ +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Concurrency +// +// = FILENAME +// CC_client.h +// +// = DESCRIPTION +// This class implements a client used to test the CosConcuurency +// service. +// +// = AUTHORS +// Torben Worm +// +// ============================================================================ + +#include "ace/Get_Opt.h" +#include "tao/corba.h" +#include "orbsvcs/orbsvcs/CosConcurrencyControlC.h" + +class CC_Client +{ + // = TITLE + // Defines a class that encapsulates the behaviour of a clien of the + // concurrency service. + // + // = DESCRIPTION + // This class declares an interface to run the test client for the + // concurrency service. + // +public: + CC_Client(void); + // Default constructor + + ~CC_Client(void); + + int run(void); + // Run the test + + int init(int argc, char **argv); + // Initialize the test with the parameters from the command line + +private: + int init_naming_service(void); + // Function to initialize the naming service. + + int parse_args(void); + // Function to parse the command line arguments + + int read_ior(char *filename); + // Function to read the ior from the given file + + FILE *cc_factory_ior_file_; + // File from which to obtain the IOR. + + ACE_HANDLE f_handle_; + // File handle to read the IOR. + + char *cc_factory_key_; + // Key of factory obj ref. + + int shutdown_; + // Flag to tell server to shutdown. + + CosConcurrencyControl::LockSet_ptr cc_lock_set_; + // Pointer to the lock set + + CORBA::ORB_var orb_; + // Remember our orb. + + CosConcurrencyControl::LockSetFactory_var factory_; + // factory pointer for the lock set. + + int argc_; + // The number of arguments passed on the command line + + char **argv_; + // The arguments from the command line + + int use_naming_service_; + // Flag to tell the client whether to use the naming service or not + // to find the concurrency control factory. +}; 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 +// Torben Worm +// +// ============================================================================ + +#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 (); +} diff --git a/TAO/orbsvcs/tests/Concurrency/NS_client.h b/TAO/orbsvcs/tests/Concurrency/NS_client.h new file mode 100644 index 00000000000..34ab4917f50 --- /dev/null +++ b/TAO/orbsvcs/tests/Concurrency/NS_client.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/orbsvcs/tests +// +// = FILENAME +// NS_client.h +// +// = DESCRIPTION +// This class tests the facilities to connect to the naming service +// and to resolve the name for the concurrency service client. +// +// = AUTHORS +// Sergio Flores-Gaitan +// Torben Worm +// +// ============================================================================ + +#include "ace/Get_Opt.h" +#include "tao/corba.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" + +class CosNaming_Client + // = TITLE + // Defines a class that encapsulates behaviour of the CosNaming client + // example. Provides a better understanding of the logic in an + // object oriented way. + // + // = DESCRIPTION + // This class declares an interface to run the example client for + // CosNaming CORBA server. All the complexity for initializing the + // server is hidden in the class. Just the run() interface is needed. +{ +public: + // = Constructor and destructor. + CosNaming_Client (void); + ~CosNaming_Client (void); + + int run (void); + // Execute client example code. + + int init (int argc, char **argv); + // Initialize the client communication endpoint with server. + +private: + int parse_args (void); + // Parses the arguments passed on the command line. + + int resolve_name(char *n); + // Resolves the name given on the commandlinn (-n option) + + CORBA::ORB_var orb_; + // Our ORB + + CosNaming::NamingContext_var naming_context_; + // Our naming context + + int resolve_name_; + // Flag set by the -n option + + char *name_to_resolve_; + // Parameter given to the -n option + + int argc_; + // # of arguments on the command line. + + char **argv_; + // arguments from command line. + + int exit_later_; + // Flag to tell server to not exit immediately. +}; diff --git a/TAO/orbsvcs/tests/Concurrency/svc.conf b/TAO/orbsvcs/tests/Concurrency/svc.conf new file mode 100644 index 00000000000..43c6a486c92 --- /dev/null +++ b/TAO/orbsvcs/tests/Concurrency/svc.conf @@ -0,0 +1,49 @@ +# $Id$ +# +# This file contains a sample ACE_Service_Config configuration +# file specifying the strategy factories utilized by an application +# using TAO. There are currently only two possible factories: +# Client_Strategy_Factory and Server_Strategy_Factory. These names +# must be used as the second argument to their corresponding line, +# because that's what the ORB uses to find the desired factory. +# +# Note that there are two unordinary characteristics of the way *this* +# file is set up: +# - both client and server strategies are specified in the same +# file, which would only make sense for co-located clients & servers +# - both of the factories are actually sourced out of libTAO.so +# (TAO.DLL on Win32), and they would normally be in a separate +# dll from the TAO ORB Core. +# +# The options which can be passed to the Resource Factory are: +# +# -ORBresources +# where can be 'global' to specify globally-held resources, +# or 'tss' to specify thread-specific resources. +# +# The options which can be passed to the Client are: +# +# +# The options which can be passed to the Server are: +# +# -ORBconcurrency +# where can be 'thread-per-connection' to specify +# use of the ACE_Threaded_Strategy concurrency strategy, +# or 'reactive' to specify use of the ACE_Reactive_Strategy +# concurrency strategy. +# +# -ORBthreadflags +# specifies the default thread flags to use, where is a +# logical OR'ing of the flags THR_DETACHED, THR_BOUND, THR_NEW_LWP, +# THR_SUSPENDED, or THR_DAEMON. Note that not every flag may be valid +# on every platform. +# +# -ORBdemuxstrategy +# where can be one of 'dynamic', 'linear', 'active', or 'user', +# and specifies the type of object lookup strategy used internally. +# -ORBtablesize +# specifies the size of the object table +# +dynamic Resource_Factory Service_Object * TAO:_make_TAO_Resource_Factory() "-ORBresources global" +dynamic Client_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Client_Strategy_Factory() +dynamic Server_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Server_Strategy_Factory() "-ORBconcurrency reactive -ORBdemuxstrategy dynamic -ORBtablesize 128" diff --git a/TAO/orbsvcs/tests/Concurrency/tmplinst.cpp b/TAO/orbsvcs/tests/Concurrency/tmplinst.cpp new file mode 100644 index 00000000000..e8d0681532d --- /dev/null +++ b/TAO/orbsvcs/tests/Concurrency/tmplinst.cpp @@ -0,0 +1,15 @@ +// +// $Id$ +// + +// The contents of this file REALLY should be generated by the IDL +// compiler, but that functionality isn't available yet. + +#include "orbsvcs/orbsvcs/CosConcurrencyControlC.h" + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) +template class TAO_Unbounded_Sequence; +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) +#pragma instantiate TAO_Unbounded_Sequence +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ + -- cgit v1.2.1