From 8084ff1b466f764eee94039bdb25b957803a2935 Mon Sep 17 00:00:00 2001 From: doccvs Date: Wed, 28 Jun 2000 00:47:26 +0000 Subject: ChangeLogTag: Tue Jun 27 17:45:47 2000 Priyanka Gontla --- TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp | 113 ++++++++++++++++++- TAO/tao/ior_corbaloc/CORBALOC_Parser.h | 37 ++++++ TAO/tests/ior_corbaloc/Makefile | 56 +++++++++ TAO/tests/ior_corbaloc/client.cpp | 51 +++++++++ TAO/tests/ior_corbaloc/corbaloc.idl | 21 ++++ TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp | 138 +++++++++++++++++++++++ TAO/tests/ior_corbaloc/ior_corbaloc_client_i.h | 61 ++++++++++ TAO/tests/ior_corbaloc/server.cpp | 82 ++++++++++++++ TAO/tests/ior_corbaloc/status_i.cpp | 21 ++++ TAO/tests/ior_corbaloc/status_i.h | 20 ++++ 10 files changed, 594 insertions(+), 6 deletions(-) create mode 100644 TAO/tests/ior_corbaloc/Makefile create mode 100644 TAO/tests/ior_corbaloc/client.cpp create mode 100644 TAO/tests/ior_corbaloc/corbaloc.idl create mode 100644 TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp create mode 100644 TAO/tests/ior_corbaloc/ior_corbaloc_client_i.h create mode 100644 TAO/tests/ior_corbaloc/server.cpp create mode 100644 TAO/tests/ior_corbaloc/status_i.cpp create mode 100644 TAO/tests/ior_corbaloc/status_i.h diff --git a/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp b/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp index e4679c67469..8cd89f42e55 100644 --- a/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp +++ b/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp @@ -57,13 +57,12 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, // If the protocol is "rir:", there is no need to do any of this. // - if (ACE_OS::strncmp (corbaloc_name, rir_prefix, - sizeof (rir_prefix)-1) != 0) + if (this->check_prefix (corbaloc_name) == 0) { char *key_string = CORBA::string_alloc (sizeof (corbaloc_name)); char *key_stringPtr = key_string; - + cout << "lets see" << endl; for (const char *i = corbaloc_name; *i != '\0'; ++i) { if (*i == ',') @@ -153,10 +152,82 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, addr [current_addr] = CORBA::string_alloc (pos); cloc_namePtr = ACE_OS::strtok (NULL, ","); } + + // Now We have an array of obtained from the + // . Now, we define an MProfile and then use + // make_mprofile ().... + // + TAO_MProfile mprofile; + + for (CORBA::ULong i=0; i != count_addr; ++i) + { + int retv = + orb->orb_core ()->connector_registry ()->make_mprofile (addr [i], + mprofile, + ACE_TRY_ENV); + + ACE_CHECK_RETURN (CORBA::Object::_nil ()); // Return nil. + + if (retv != 0) + { + ACE_THROW_RETURN (CORBA::INV_OBJREF ( + CORBA_SystemException::_tao_minor_code ( + TAO_DEFAULT_MINOR_CODE, + EINVAL), + CORBA::COMPLETED_NO), + CORBA::Object::_nil ()); + } + + // Now make the TAO_Stub. + TAO_Stub *data = 0; + ACE_NEW_THROW_EX (data, + TAO_Stub ((char *) 0, mprofile, + orb->orb_core ()), + CORBA::NO_MEMORY ( + CORBA_SystemException::_tao_minor_code ( + TAO_DEFAULT_MINOR_CODE, + ENOMEM), + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + TAO_Stub_Auto_Ptr safe_data (data); + + // Figure out if the servant is collocated. + TAO_ServantBase *servant = 0; + TAO_SERVANT_LOCATION servant_location = + orb->_get_collocated_servant (safe_data.get (), + servant); + + int collocated = 0; + if (servant_location != TAO_SERVANT_NOT_FOUND) + collocated = 1; + + CORBA::Object_ptr obj = CORBA::Object::_nil (); + + // Create the CORBA level proxy. This will increase the ref_count + // on data by one + ACE_NEW_THROW_EX (obj, + CORBA_Object (safe_data.get (), + servant, + (CORBA::Boolean) collocated), + CORBA::NO_MEMORY ( + CORBA_SystemException::_tao_minor_code ( + TAO_DEFAULT_MINOR_CODE, + ENOMEM), + CORBA::COMPLETED_NO)); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + // All is well, so release the stub object from its auto_ptr. + data = safe_data.release (); + + return obj; + + } + } CORBA::Object_ptr object = CORBA::Object::_nil (); - + if (ACE_OS::strncmp (corbaloc_name, rir_prefix, sizeof (rir_prefix)-1) == 0) { @@ -164,7 +235,7 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, // argument to the resolve_initial_references () const char *key_string = corbaloc_name + sizeof (rir_prefix) -1; - + ACE_TRY { ACE_DEBUG ((LM_DEBUG, "The key string is %s\n", key_string)); @@ -176,12 +247,42 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, ACE_PRINT_EXCEPTION (ex, "CORBALOC_Parser"); } ACE_ENDTRY; - + } return object; + } +int +TAO_CORBALOC_Parser::check_prefix (const char *endpoint) +{ + + // Check for a valid string + if (!endpoint || !*endpoint) + return -1; // Failure + + const char *protocol[] = { "iiop", "" }; + + size_t slot = ACE_OS::strchr (endpoint, '/') - endpoint; + + size_t len0 = ACE_OS::strlen (protocol[0]); + size_t len1 = ACE_OS::strlen (protocol[1]); + + // Check for the proper prefix in the IOR. If the proper prefix + // isn't in the IOR then it is not an IOR we can use. + if (slot == len0 + && ACE_OS::strncasecmp (endpoint, protocol[0], len0) == 0) + return 0; + else if (slot == len1 + && ACE_OS::strncasecmp (endpoint, protocol[1], len1) == 0) + return 0; + + return -1; + // Failure: not an IIOP IOR + // DO NOT throw an exception here. +} + ACE_FACTORY_DEFINE (TAO_IOR_CORBALOC, TAO_CORBALOC_Parser) #if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) diff --git a/TAO/tao/ior_corbaloc/CORBALOC_Parser.h b/TAO/tao/ior_corbaloc/CORBALOC_Parser.h index fe0637e5ab4..508334bd328 100644 --- a/TAO/tao/ior_corbaloc/CORBALOC_Parser.h +++ b/TAO/tao/ior_corbaloc/CORBALOC_Parser.h @@ -10,6 +10,7 @@ // // = AUTHOR // Carlos O'Ryan (coryan@cs.wustl.edu) +// Priyanka Gontla (pgontla@uci.edu) // // ============================================================================ @@ -17,7 +18,41 @@ #define TAO_CORBALOC_PARSER_H #include "ace/pre.h" +#include "tao/ORB.h" +#include "tao/Acceptor_Registry.h" +#include "tao/Connector_Registry.h" #include "tao/IOR_Parser.h" +#include "tao/Parser_Registry.h" + +#include "ace/Dynamic_Service.h" +#include "ace/Service_Repository.h" +#include "ace/Object_Manager.h" +#include "ace/SOCK_Dgram_Mcast.h" +#include "ace/SOCK_Acceptor.h" +#include "ace/Thread_Manager.h" +#include "ace/Read_Buffer.h" +#include "ace/Auto_Ptr.h" +#include "ace/Arg_Shifter.h" + +#include "tao/Object.h" +#include "tao/Typecode.h" +#include "tao/NVList.h" +#include "tao/Stub.h" +#include "tao/DynAny_i.h" +#include "tao/ORB_Core.h" +#include "tao/Server_Strategy_Factory.h" +#include "tao/debug.h" +#include "tao/TAO_Internal.h" +#include "tao/CDR.h" +#include "tao/IOR_LookupTable.h" +#include "tao/Object_Adapter.h" +#include "tao/POA.h" +#include "tao/Request.h" +#include "tao/MProfile.h" + +#include "tao/IOR_Parser.h" +#include "tao/Pluggable.h" + #include "ior_corbaloc_export.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) @@ -49,6 +84,8 @@ public: CORBA::ORB_ptr orb, CORBA::Environment &) ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual int check_prefix (const char *endpoint); }; #if defined (__ACE_INLINE__) diff --git a/TAO/tests/ior_corbaloc/Makefile b/TAO/tests/ior_corbaloc/Makefile new file mode 100644 index 00000000000..5df7eaf5119 --- /dev/null +++ b/TAO/tests/ior_corbaloc/Makefile @@ -0,0 +1,56 @@ + +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif # ! TAO_ROOT + +LDLIBS = -lTAO -lTAO_CosNaming +CPPFLAGS += -I$(TAO_ROOT)/orbsvcs + +IDLFILES = corbalocC corbalocS +BIN = server client + +SRC = $(addsuffix .cpp, $(BIN) $(IDLFILES) status_i) + +SERVER_OBJS = $(addsuffix .o, server status_i $(IDLFILES)) +CLIENT_OBJS = $(addsuffix .o, client ior_corbaloc_client_i status_i $(IDLFILES)) + +#---------------------------------------------------------------------------- +# 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 +#---------------------------------------------------------------------------- + +.PRECIOUS: $(foreach ext, $(IDL_EXT), corbaloc$(ext)) + +server: $(addprefix $(VDIR),$(SERVER_OBJS)) + $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK) + +client: $(addprefix $(VDIR),$(CLIENT_OBJS)) + $(LINK.cc) $(LDFLAGS) -o $@ $^ $(VLDLIBS) $(POSTLINK) + +realclean: clean + -$(RM) $(foreach ext, $(IDL_EXT), corbaloc$(ext)) + +# 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/ior_corbaloc/client.cpp b/TAO/tests/ior_corbaloc/client.cpp new file mode 100644 index 00000000000..e2138732ba3 --- /dev/null +++ b/TAO/tests/ior_corbaloc/client.cpp @@ -0,0 +1,51 @@ +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/ior_corbaloc/ +// +// = FILENAME +// client.cpp +// +// = DESCRIPTION +// This implements a simple CORBA client for the +// corbaloc: style IOR parser +// +// = AUTHOR +// Priyanka Gontla +// +// +// ============================================================================ + +#include "ior_corbaloc_client_i.h" + +int main (int argc, char *argv []) +{ + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + + IOR_corbaloc_Client_i client; + + if (client.init (argc, argv) == -1) + return 1; + else + { + return client.run (ACE_TRY_ENV); + ACE_TRY_CHECK; + } + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "client"); + ACE_RE_THROW; + } + ACE_ENDTRY; + return 0; +} + + + diff --git a/TAO/tests/ior_corbaloc/corbaloc.idl b/TAO/tests/ior_corbaloc/corbaloc.idl new file mode 100644 index 00000000000..2d01e59af1c --- /dev/null +++ b/TAO/tests/ior_corbaloc/corbaloc.idl @@ -0,0 +1,21 @@ +// $Id$ + +module corbaloc +{ + + interface Status + { + // = TITLE + // A simple interface to check the status of + // connection between the client and the server. + // + // = DESCRIPTION + // Prints out the status. + + void print_status (); + // Print if the server received the + // request from the client. + + }; +}; + diff --git a/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp b/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp new file mode 100644 index 00000000000..802e2a6d0fc --- /dev/null +++ b/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp @@ -0,0 +1,138 @@ +// $Id$ +// + +// =========================================================== +// +// = LIBRARY +// TAO/tests/ior_corbaloc/ +// +// = FILENAME +// ior_corbaloc_client_i.cpp +// +// = DESCRIPTION +// This example implements a simple client which sends a corbaloc: +// style url to the server and gets a response from the +// server to indicate that the server has received the request. +// +// = AUTHORS +// Priyanka Gontla +// +//============================================================ + +#include "ior_corbaloc_client_i.h" +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" + +// Constructor +IOR_corbaloc_Client_i::IOR_corbaloc_Client_i (void) +{ +} + +IOR_corbaloc_Client_i::~IOR_corbaloc_Client_i (void) +{ +} + +int +IOR_corbaloc_Client_i::run (CORBA::Environment &ACE_TRY_ENV) +{ + + ACE_TRY + { + CosNaming::Name name (1); + + name.length (1); + name[0].id = CORBA::string_dup ("STATUS"); + + // Resolve the name + CORBA::Object_var factory_object = + this->naming_context_->resolve (name, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Narrow + corbaloc::Status_var factory = + corbaloc::Status::_narrow (factory_object.in (), ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (factory.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Object reference <%s> is nil\n", + this->argv_[1]), + 1); + } + + // Invoke a request on the server + factory->print_status (ACE_TRY_ENV); + ACE_TRY_CHECK; + } + ACE_CATCH (CosNaming::NamingContext::NotFound, ex) + { + ACE_PRINT_EXCEPTION (ex, "CosNaming::NamingContext::NotFound"); + } + ACE_CATCH (CORBA::SystemException, ex) + { + ACE_PRINT_EXCEPTION (ex, "A system exception oc client side"); + return -1; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "client"); + return -1; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); + + return 0; +} + +int +IOR_corbaloc_Client_i::init (int argc, char **argv) +{ + this->argc_ = argc; + this->argv_ = argv; + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + + // First initialize the ORB, that will remove some arguments... + CORBA::ORB_var orb = + CORBA::ORB_init (this->argc_, + this->argv_, + "" /* the ORB name, it can be anything! */, + ACE_TRY_ENV); + + // There must be at least one argument, the file that has to be + // retrieved + + // Get a reference to the Naming Service + CORBA::Object_var naming_context_object = + orb->string_to_object ("corbaloc:rir:/NameService", ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (naming_context_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot resolve Naming Service\n"), + 1); + + // Narrow to get the correct reference + this->naming_context_ = + CosNaming::NamingContextExt::_narrow (naming_context_object.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (this->naming_context_.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot narrow Naming Service\n"), + 1); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "client"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.h b/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.h new file mode 100644 index 00000000000..e4656c7d7c3 --- /dev/null +++ b/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +// $Id$ + +// =========================================================== +// +// = LIBRARY +// TAO/tests/ior_corbaloc/ +// +// = FILENAME +// ior_corbaloc_client_i.h +// +// = DESCRIPTION +// This class implements a simple client which sends a corbaloc: +// style url to the server and gets a response from the +// server to indicate that the server has received the request. +// +// = AUTHORS +// Priyanka Gontla +// +//============================================================ + + +#if !defined (IOR_CORBALOC_CLIENT_I_H) +#define IOR_CORBALOC_CLIENT_I_H + +#include "corbalocC.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" + +class IOR_corbaloc_Client_i +{ + // = TITLE + // NContextExt Client Implementation + // + // = DESCRIPTION + // + + public: + // = COnstructor and destructor. + IOR_corbaloc_Client_i (void); + ~IOR_corbaloc_Client_i (void); + + int run (CORBA::Environment &ACE_TRY_ENV); + // Execute the client example code. + + int init (int argc, char **argv); + // Initialize the client communication endpoint with the server. + + private: + + int argc_; + // # of arguments on the command line. + + char **argv_; + // arguments from command line. + + CosNaming::NamingContextExt_var naming_context_; + // Naming context + +}; + +#endif /* IOR_CORBALOC_CLIENT_I_H */ diff --git a/TAO/tests/ior_corbaloc/server.cpp b/TAO/tests/ior_corbaloc/server.cpp new file mode 100644 index 00000000000..f57bb9e3648 --- /dev/null +++ b/TAO/tests/ior_corbaloc/server.cpp @@ -0,0 +1,82 @@ +// $Id$ +// server.cpp +// + +#include "status_i.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" +#include + +int main (int argc, char* argv[]) +{ + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + + // First initialize the ORB, that will remove some arguments... + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, + "" /* the ORB name, it can be anything! */, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Get a reference to the RootPOA + CORBA::Object_var poa_object = + orb->resolve_initial_references ("RootPOA", ACE_TRY_ENV); + ACE_TRY_CHECK; + + // narrow down to the correct reference + PortableServer::POA_var poa = + PortableServer::POA::_narrow (poa_object.in (), ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Set a POA Manager + PortableServer::POAManager_var poa_manager = + poa->the_POAManager (ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Activate the POA Manager + poa_manager->activate (ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Create the servant + corbaloc_Status_i status_i; + + // Activate it to obtain the reference + corbaloc::Status_var status = + status_i._this (); + + // Get a reference to Naming Context + CORBA::Object_var naming_context_object = + orb->resolve_initial_references ("NameService", ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Narrow down the reference + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_context_object.in(), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Bind Iterator_Factory to the Naming Context + CosNaming::Name name (1); + name.length (1); + name[0].id = CORBA::string_dup ("STATUS"); + + naming_context->bind (name, status.in ()); + + // Run the orb + orb->run (); + + // Destroy the POA, waiting until the destruction terminates + poa->destroy (1, 1); + orb->destroy (); + + } + ACE_CATCH (CORBA::SystemException, ex) { + std::cerr << "CORBA exception raised! " << ex << std::endl; + } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); + + return 0; +} diff --git a/TAO/tests/ior_corbaloc/status_i.cpp b/TAO/tests/ior_corbaloc/status_i.cpp new file mode 100644 index 00000000000..9f0ff4972a0 --- /dev/null +++ b/TAO/tests/ior_corbaloc/status_i.cpp @@ -0,0 +1,21 @@ +// +// $Id$ +// + +#include "status_i.h" + +corbaloc_Status_i::corbaloc_Status_i (CORBA::Environment & = TAO_default_environment()) +{ + // Constructor +} + +void +corbaloc_Status_i::print_status (CORBA::Environment & = TAO_default_environment()) + throw (CORBA::SystemException) +{ + + ACE_DEBUG ((LM_DEBUG, + "The connection between the server and client is setup\n")); + +} + diff --git a/TAO/tests/ior_corbaloc/status_i.h b/TAO/tests/ior_corbaloc/status_i.h new file mode 100644 index 00000000000..b1227f215df --- /dev/null +++ b/TAO/tests/ior_corbaloc/status_i.h @@ -0,0 +1,20 @@ +// +// $Id$ +// + +#ifndef STATUS_I_H +#define STATUS_I_H + +#include "corbalocS.h" +#include + +class corbaloc_Status_i : public POA_corbaloc::Status { +public: + corbaloc_Status_i (CORBA::Environment & = + TAO_default_environment()); + + void print_status (CORBA::Environment & = TAO_default_environment()) throw (CORBA::SystemException); + +}; + +#endif /* STATUS_I_H */ -- cgit v1.2.1