From dafafdddbcce29557f589a57af4485c15d1105d4 Mon Sep 17 00:00:00 2001 From: tworm Date: Mon, 4 May 1998 14:23:13 +0000 Subject: First version --- .../Concurrency_Service/Concurrency_Service.cpp | 210 +++++++++++++++ .../Concurrency_Service/Concurrency_Service.h | 101 ++++++++ TAO/orbsvcs/Concurrency_Service/Makefile | 48 ++++ TAO/orbsvcs/Concurrency_Service/svc.conf | 49 ++++ .../orbsvcs/Concurrency/Concurrency_Utils.cpp | 97 +++++++ .../orbsvcs/Concurrency/Concurrency_Utils.h | 65 +++++ 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 ++ 12 files changed, 1242 insertions(+) create mode 100644 TAO/orbsvcs/Concurrency_Service/Concurrency_Service.cpp create mode 100644 TAO/orbsvcs/Concurrency_Service/Concurrency_Service.h create mode 100644 TAO/orbsvcs/Concurrency_Service/Makefile create mode 100644 TAO/orbsvcs/Concurrency_Service/svc.conf create mode 100644 TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.cpp create mode 100644 TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.h 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 diff --git a/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.cpp b/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.cpp new file mode 100644 index 00000000000..2f4634973ae --- /dev/null +++ b/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.cpp @@ -0,0 +1,210 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// orbsvcs/Concurrecy_Service/Concurrency_Service +// +// = FILENAME +// Concurrency_Service.cpp +// +// = DESCRIPTION +// This class implements a Concurrency_Service object. +// +// = AUTHORS +// Torben Worm +// +// ============================================================================ + +#include "Concurrency_Service.h" + +// Default Constructor. + +Concurrency_Service::Concurrency_Service (void) + : use_naming_service_ (1), + ior_output_file_ (0) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::Concurrency_Service(void)\n")); +} + +// Constructor taking command-line arguments + +Concurrency_Service::Concurrency_Service (int argc, + char** argv, + CORBA::Environment& _env) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::Concurrency_Service(...)\n")); + this->init (argc, argv, _env); +} + +Concurrency_Service::parse_args(void) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::parse_args\n")); + ACE_Get_Opt get_opts (argc_, argv_, "do:s"); + 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 's': + this->use_naming_service_ = 0; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-d]" + " [-o] " + "\n", + argv_[0]), + 1); + } + // Indicates sucessfull persing of command line. + return 0; +} + +// Initialize the state of the Concurrency_Service object +int +Concurrency_Service::init (int argc, + char** argv, + CORBA::Environment& _env) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::init\n")); + 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; + + if(this->parse_args()!=0) + ACE_ERROR_RETURN((LM_ERROR, + "Could not parse command line\n"), + -1); + CORBA::String_var str = + this->orb_manager_.activate(this->my_concurrency_server_.GetLockSetFactory(), + _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_); + } + + if(this->use_naming_service_) + return this->init_naming_service (_env); + + return 0; +} + +int +Concurrency_Service::init_naming_service(CORBA::Environment& _env) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::init_naming_service(...)\n")); + CORBA::ORB_var orb; + PortableServer::POA_var child_poa; + + orb = this->orb_manager_.orb(); + child_poa = this->orb_manager_.child_poa(); + + ACE_DEBUG((LM_DEBUG, "****1\n")); + int result = this->my_name_server_.init (orb.in(), + child_poa.in()); + ACE_DEBUG((LM_DEBUG, "****2\n")); + if(result<0) + return result; + lockset_factory_ = this->my_concurrency_server_.GetLockSetFactory()->_this(_env); + TAO_CHECK_ENV_RETURN(_env, -1); + + CosNaming::Name concurrency_context_name (1); + concurrency_context_name.length(1); + concurrency_context_name[0].id = CORBA::string_dup ("CosConcurrency"); + this->concurrency_context_ = + this->my_name_server_->bind_new_context (concurrency_context_name, + _env); + TAO_CHECK_ENV_RETURN(_env, -1); + + CosNaming::Name lockset_name (1); + lockset_name.length(1); + lockset_name[0].id = CORBA::string_dup ("LockSetFactory"); + this->concurrency_context_->bind(lockset_name, + lockset_factory_.in(), + _env); + TAO_CHECK_ENV_RETURN(_env, -1); + return 0; +} + +// Run the ORB event loop +int +Concurrency_Service::run (CORBA_Environment& _env) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::run(...)\n")); + if(this->orb_manager_.run(_env) == -1) + ACE_ERROR_RETURN((LM_ERROR, + "Concurrency_Service::run"), + -1); + return 0; +} + +// Destructor. + +Concurrency_Service::~Concurrency_Service (void) +{ + ACE_DEBUG((LM_DEBUG, "Concurrency_Service::~Concurrency_Service(void)\n")); +} + + +int +main (int argc, char ** argv) +{ + Concurrency_Service concurrency_service; + + ACE_DEBUG ((LM_DEBUG, + "\n \t Concurrency Service:SERVER \n \n")); + + TAO_TRY + { + if( concurrency_service.init (argc,argv,TAO_TRY_ENV) == -1) + return 1; + else + { + concurrency_service.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; +} + diff --git a/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.h b/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.h new file mode 100644 index 00000000000..32cf316ddcf --- /dev/null +++ b/TAO/orbsvcs/Concurrency_Service/Concurrency_Service.h @@ -0,0 +1,101 @@ +// $Id$ +// ============================================================================ +// +// = LIBRARY +// orbsvcs/Concurrency_Service/Concurency_Service +// +// = FILENAME +// Concurrency_Service.h +// +// = DESCRIPTION +// This class implements the functionality of the Concurrency_Service. +// +// = AUTHORS +// Torben Worm +// +// ============================================================================ + +#if !defined (_CONCURRENCY_SERVICE_H) +#define _CONCURRENCY_SERVICE_H + +//#include "ace/streams.h" +//#include "tao/tao_util.h" +#include "ace/Get_Opt.h" +#include "ace/Log_Msg.h" +#include "tao/TAO.h" +#include "orbsvcs/Concurrency/Concurrency_Utils.h" +#include "orbsvcs/Concurrency/CC_LockSetFactory.h" +#include "orbsvcs/Naming/Naming_Utils.h" + +class Concurrency_Service:public TAO_ORB_Manager +{ + // =TITLE + // Defines a class that encapsulates the implementation of the + // concurrency service. + // =DESCRIPTION + // + // + +public: + Concurrency_Service (void); + // Default Constructor. + + Concurrency_Service (int argc, + char** argv, + CORBA::Environment& _env); + // Constructor taking the command-line arguments. + + ~Concurrency_Service (void); + // Destructor. + + int init (int argc, + char** argv, + CORBA::Environment& _env); + // Initialize the Concurrency Service with the arguments. + + int run (CORBA_Environment& _env); + // Run the Concurrency_Service. + +private: + int parse_args(void); + // Parses the commandline arguments. + + int init_naming_service (CORBA::Environment& _env); + // Initialize the name server and register the concurency server + // factory with it. Maybe later it will be convinient to register + // the individual lock sets with the naming service. At present the + // clients must keep track of the reference and pass 'by hand' + + int use_naming_service_; + // Flag to tell wheter the naming service will be used. + + FILE *ior_output_file_; + // File to output the concurrency server IOR. + + TAO_ORB_Manager orb_manager_; + // The ORB manager + + TAO_Naming_Server my_name_server_; + // An instance of the name server used for registering the factory + // objects. + + TAO_Concurrency_Server my_concurrency_server_; + // An instance of the concurrency server + + CosConcurrencyControl::LockSetFactory_var lockset_factory_; + // Factory var to register with the naming service + + CosNaming::NamingContext_var concurrency_context_; + // Naming context for the concurrency service + + CosNaming::NamingContext_var naming_context_; + // Naming context for the naming service + + int argc_; + // Number of commandline arguments + + char **argv_; + // Commandline arguments +}; + +#endif /* _CONCURRENCY_SERVICE_H */ diff --git a/TAO/orbsvcs/Concurrency_Service/Makefile b/TAO/orbsvcs/Concurrency_Service/Makefile new file mode 100644 index 00000000000..50561227ebf --- /dev/null +++ b/TAO/orbsvcs/Concurrency_Service/Makefile @@ -0,0 +1,48 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +BIN = Concurrency_Service + +SVR_SRCS=Concurrency_Service.cpp + +LDLIBS = -lorbsvcs -lTAO + +VLDLIBS = $(LDLIBS:%=%$(VAR)) + +BUILD = $(VLIB) $(VSHLIB) $(SHLIBA) $(VBIN) + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(ACE_ROOT)/include/makeinclude/macros.GNU +include $(ACE_ROOT)/include/makeinclude/rules.common.GNU +include $(ACE_ROOT)/include/makeinclude/rules.nonested.GNU +include $(ACE_ROOT)/include/makeinclude/rules.lib.GNU +include $(ACE_ROOT)/include/makeinclude/rules.bin.GNU +include $(ACE_ROOT)/include/makeinclude/rules.local.GNU + +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif + +#TSS_ORB_FLAG = #-DTAO_HAS_TSS_ORBCORE + +DCFLAGS = -g +LDFLAGS += -L$(TAO_ROOT)/orbsvcs/orbsvcs -L$(TAO_ROOT)/tao +CPPFLAGS += -I$(TAO_ROOT)/orbsvcs -I$(TAO_ROOT) -I$(TAO_ROOT)/tao/compat $(TSS_ORB_FLAG)#-H + +# 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/orbsvcs/Concurrency_Service/svc.conf b/TAO/orbsvcs/Concurrency_Service/svc.conf new file mode 100644 index 00000000000..da10b90ce7a --- /dev/null +++ b/TAO/orbsvcs/Concurrency_Service/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 thread-per-connection -ORBdemuxstrategy dynamic -ORBtablesize 128" diff --git a/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.cpp b/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.cpp new file mode 100644 index 00000000000..4e091c60467 --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.cpp @@ -0,0 +1,97 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/orbsvcs/Concurrency_Service +// +// = FILENAME +// Concurrency_Utils.cpp +// +// = DESCRIPTION +// +// +// +// = AUTHOR +// Torben Worm +// +// ============================================================================ + +#include "ace/streams.h" +#include "orbsvcs/CosConcurrencyControlC.h" +#include "tao/corba.h" +#include "Concurrency_Utils.h" + +// Default constructor + +TAO_Concurrency_Server::TAO_Concurrency_Server (void) +{ +} + +// Constructor which takes an ORB and POA. + +TAO_Concurrency_Server::TAO_Concurrency_Server (CORBA::ORB_var &orb, + PortableServer::POA_var &poa) +{ + this->init (orb, poa); +} + +// Function to initialize the concurrency server object under the passed orb +// and poa + +int +TAO_Concurrency_Server::init (CORBA::ORB_var &orb, + PortableServer::POA_var &poa) +{ + TAO_TRY + { + // Get the naming context ptr to NameService. + TAO_CHECK_ENV; + + PortableServer::ObjectId_var id = + PortableServer::string_to_ObjectId ("ConcurrencyService"); + + poa->activate_object_with_id (id.in (), + &lock_set_factory_, + TAO_TRY_ENV); + TAO_CHECK_ENV; + + // Stringify the objref we'll be implementing, and print it to + // stdout. Someone will take that string and give it to a + // client. Then release the object. + CORBA::Object_var obj = + poa->id_to_reference (id.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + CORBA::String_var str = + orb->object_to_string (obj.in (), + TAO_TRY_ENV); + TAO_CHECK_ENV; + + ACE_DEBUG ((LM_DEBUG, + "listening as object <%s>\n", + str.in ())); + } + TAO_CATCHANY + { + TAO_TRY_ENV.print_exception ("Concurrency Service"); + } + TAO_ENDTRY; + return 0; +} + +// Get the lock set factory +CC_LockSetFactory * +TAO_Concurrency_Server::GetLockSetFactory(void) +{ + return &this->lock_set_factory_; +} + +// Destructor. + +TAO_Concurrency_Server::~TAO_Concurrency_Server (void) +{ +} + + diff --git a/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.h b/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.h new file mode 100644 index 00000000000..5f2599a078e --- /dev/null +++ b/TAO/orbsvcs/orbsvcs/Concurrency/Concurrency_Utils.h @@ -0,0 +1,65 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/orbsvcs/Concurrency_Service +// +// = FILENAME +// Concurrency_Utils.h +// +// = DESCRIPTION +// This class implements a Concurrency Server wrapper class which holds +// a number of lock sets +// The server must run in the thread per request concurrency model in +// order to let the clients block on the semaphores. +// +// = AUTHORS +// Torben Worm +// +// ============================================================================ + +#if !defined (_CONCURRENCY_SERVER_H) +#define _CONCURRENCY_SERVER_H + +#include "tao/corba.h" +#include "orbsvcs/CosConcurrencyControlC.h" +#include "CC_LockSetFactory.h" + +class TAO_ORBSVCS_Export TAO_Concurrency_Server +{ + // = TITLE + // Defines a wrapper class for the implementation of the + // concurrency server. + // + // = DESCRIPTION + // + // + // + // +public: + TAO_Concurrency_Server (void); + //Default constructor. + + TAO_Concurrency_Server (CORBA::ORB_var &orb, + PortableServer::POA_var &poa); + // Takes the POA under which to register the Concurrency Service + // implementation object. + + int init (CORBA::ORB_var &orb, + PortableServer::POA_var &poa); + // Initialize the concurrency server under the given ORB and POA. + + CC_LockSetFactory *GetLockSetFactory(void); + // Get the lock set factory + + ~TAO_Concurrency_Server (void); + // Destructor. + +private: + CC_LockSetFactory lock_set_factory_; +}; + +#endif /* _CONCURRENCY_SERVER_H */ + 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