diff options
author | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-07-07 01:53:28 +0000 |
---|---|---|
committer | doccvs <doccvs@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2000-07-07 01:53:28 +0000 |
commit | efecd46810155fee77711468cb1cc3aa4dc0bdf3 (patch) | |
tree | 2c118a42d36fabdf61db61c87be21d4a6e945a04 | |
parent | 97cbab62fae3096f0d6efb93ceae4c1208ef8a40 (diff) | |
download | ATCD-efecd46810155fee77711468cb1cc3aa4dc0bdf3.tar.gz |
Thu Jul 6 18:48:06 2000 Priyanka Gontla <pgontla@ece.uci.edu>
-rw-r--r-- | TAO/tao/ior_corbaname/CORBANAME_Parser.cpp | 175 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/CORBANAME_Parser.h | 65 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/CORBANAME_Parser.i | 6 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/Makefile | 52 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/ior_corbaname_export.h | 40 |
5 files changed, 338 insertions, 0 deletions
diff --git a/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp b/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp new file mode 100644 index 00000000000..d23ac3c25df --- /dev/null +++ b/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp @@ -0,0 +1,175 @@ +// $Id$ + +#include "CORBANAME_Parser.h" +#include "ace/Profile_Timer.h" +#include "tao/ior_dll/Object_Loader.h" +#include "tao/Object.h" +#include "tao/corba.h" +#include "tao/ORB.h" +#include "tao/Exception.h" +#include "tao/Environment.h" +#include "ace/Read_Buffer.h" + +#include "orbsvcs/orbsvcs/CosNamingC.h" + +#if !defined(__ACE_INLINE__) +#include "CORBANAME_Parser.i" +#endif /* __ACE_INLINE__ */ + +ACE_RCSID(tao, CORBANAME_Parser, "$Id$") + +TAO_CORBANAME_Parser::~TAO_CORBANAME_Parser (void) +{ +} + +static const char corbaname_prefix[] = "corbaname:"; + +int +TAO_CORBANAME_Parser::match_prefix (const char *ior_string) const +{ + return (ACE_OS::strncmp (ior_string, + corbaname_prefix, + sizeof corbaname_prefix - 1) == 0); +} + +void +TAO_CORBANAME_Parser::parse_string_count_helper (const char * &corbaname, + CORBA::ULong &pos_seperator) +{ + + CORBA::Boolean start_key_string = 1; + + for (const char *i = corbaname; *i != '\0'; ++i) + { + if (*i == '/') + { + if (*(i+1) == '/') + { + ++i; + ++pos_seperator; + } + else if (*(i+1) != '/') + { + // Indication that the obj_addr ends here + start_key_string = 0; + } + } + + if (start_key_string == 1) + { + ++pos_seperator; + } + else if (start_key_string == 0) + { + return; + } + } + +} + +CORBA::Object_ptr +TAO_CORBANAME_Parser::parse_string (const char *ior, + CORBA::ORB_ptr orb, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Skip the prefix, we know it is there because this method in only + // called if <match_prefix> returns 1. + const char *corbaname = + ior + sizeof corbaname_prefix - 1; + CORBA::Object_var obj = CORBA::Object::_nil (); + + cout << "The corbaname is:" << corbaname << endl; + ACE_TRY + { + + CORBA::ULong pos_seperator = 0; + + // Get the position of the seperator between the obj_addr and the + // key_String + parse_string_count_helper (corbaname, + pos_seperator); + + cout << "The pos seperator is:" << pos_seperator << endl; + + ACE_CString corbaname_str (corbaname, 0, 1); + + // Get the obj_addr + ACE_CString obj_addr = corbaname_str.substring (0, pos_seperator); + cout << "The obj_addr is:" << obj_addr << endl; + // Get the Key String + ACE_CString key_string = corbaname_str.substring (pos_seperator, -1); + cout << "The key string is:" << key_string << endl; + + ACE_CString name_service ("/NameService", 0, 1); + // Make it in a form understandable by <corbaloc> scheme + ACE_CString corbaloc_addr ("corbaloc:", 0, 1); + corbaloc_addr += obj_addr; + corbaloc_addr += name_service; + cout << "The corbaloc name is:" << corbaloc_addr << endl; + + // Obtain a reference to the naming context + CORBA::Object_var name_context_obj = + orb->string_to_object (corbaloc_addr.c_str (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (name_context_obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot resolve Naming Service: CORBANAME_Parser\n"), + 0); + + // Narrow to get the correct reference + CosNaming::NamingContextExt_var naming_context = + CosNaming::NamingContextExt::_narrow (name_context_obj.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (naming_context.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot narrow Naming Service: CORBANAME_Parser\n"), + 0); + + // Now that you got a reference to the naming context, use + // resolve_str. + CORBA::Request_var rs_req (naming_context->_request ("resolve_str", + ACE_TRY_ENV)); + ACE_TRY_CHECK; + + // resolve_str takes a str as an argument: so we must include + // that in the request + rs_req->add_in_arg () <<= key_string.c_str (); + + // Set the return type + rs_req->set_return_type (CORBA::_tc_Object); + + // Finally invoke the <resolve_str> operation. + rs_req->invoke (ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Extract the returned object reference from the request + rs_req->return_value () >>= CORBA::Any::to_object (obj.out ()); + + if (CORBA::is_nil (obj.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " could not obtain object <%s>\n"), + 0); + + } + ACE_CATCH (CORBA::SystemException, ex) + { + ACE_PRINT_EXCEPTION (ex, "CORBANAME_Parser"); + } + ACE_ENDTRY; + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + return obj.in (); +} + +ACE_FACTORY_DEFINE (TAO_IOR_CORBANAME, TAO_CORBANAME_Parser) + +#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION) + +#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA) + +#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */ diff --git a/TAO/tao/ior_corbaname/CORBANAME_Parser.h b/TAO/tao/ior_corbaname/CORBANAME_Parser.h new file mode 100644 index 00000000000..ceb78b800a6 --- /dev/null +++ b/TAO/tao/ior_corbaname/CORBANAME_Parser.h @@ -0,0 +1,65 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO +// +// = FILENAME +// CORBANAME_Parser.h +// +// = AUTHOR +// Priyanka Gontla (pgontla@uci.edu) +// +// ============================================================================ + +#ifndef TAO_CORBANAME_PARSER_H +#define TAO_CORBANAME_PARSER_H +#include "ace/pre.h" + +#include "tao/IOR_Parser.h" +#include "ior_corbaname_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +class TAO_IOR_CORBANAME_Export TAO_CORBANAME_Parser : public TAO_IOR_Parser +{ + // = TITLE + // Implements the <corbaname:> IOR format + // + // = DESCRIPTION + // This class implements the <corbaname:> IOR format. + // It is dynamically loaded by the ORB and used to get reference + // to a naming service at the given address and port and then resolve an + // object in that context. + // +public: + TAO_CORBANAME_Parser (void); + // Constructor + + virtual ~TAO_CORBANAME_Parser (void); + // The destructor + + // = The IOR_Parser methods, please read the documentation in + // IOR_Parser.h + virtual int match_prefix (const char *ior_string) const; + virtual CORBA::Object_ptr parse_string (const char *ior, + CORBA::ORB_ptr orb, + CORBA::Environment &) + ACE_THROW_SPEC ((CORBA::SystemException)); + + private: + virtual void parse_string_count_helper (const char * &corbaname, + CORBA::ULong &pos_seperator); +}; + +#if defined (__ACE_INLINE__) +# include "CORBANAME_Parser.i" +#endif /* __ACE_INLINE__ */ + +ACE_FACTORY_DECLARE (TAO_IOR_CORBANAME, TAO_CORBANAME_Parser) + +#include "ace/post.h" +#endif /* TAO_CORBANAME_PARSER_H */ diff --git a/TAO/tao/ior_corbaname/CORBANAME_Parser.i b/TAO/tao/ior_corbaname/CORBANAME_Parser.i new file mode 100644 index 00000000000..1139a868437 --- /dev/null +++ b/TAO/tao/ior_corbaname/CORBANAME_Parser.i @@ -0,0 +1,6 @@ +// $Id$ + +ACE_INLINE +TAO_CORBANAME_Parser::TAO_CORBANAME_Parser (void) +{ +} diff --git a/TAO/tao/ior_corbaname/Makefile b/TAO/tao/ior_corbaname/Makefile new file mode 100644 index 00000000000..cb4ba3461e8 --- /dev/null +++ b/TAO/tao/ior_corbaname/Makefile @@ -0,0 +1,52 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- + +MAKEFILE = Makefile +LIBNAME = libTAO_IOR_CORBANAME +LIB = $(LIBNAME).a +SHLIB = $(LIBNAME).$(SOEXT) + +ifndef TAO_ROOT +TAO_ROOT = $(ACE_ROOT)/TAO +endif + +# These are headers for things which are exported and must be +# installed. (Currently not used). +PUB_HDRS = \ + CORBANAME_Parser +FILES= \ + CORBANAME_Parser + +LSRC = $(addsuffix .cpp,$(FILES)) + +DEFS = $(addsuffix .h,$(PUB_HDRS)) + +ACE_SHLIBS = -lACE + +#---------------------------------------------------------------------------- +# Include macros and targets +#---------------------------------------------------------------------------- + +include $(ACE_ROOT)/include/makeinclude/wrapper_macros.GNU +include $(TAO_ROOT)/rules.tao.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.local.GNU +include $(TAO_ROOT)/taoconfig.mk + +#---------------------------------------------------------------------------- +# Local targets (and local hacks) +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Dependencies +#---------------------------------------------------------------------------- + +# 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/tao/ior_corbaname/ior_corbaname_export.h b/TAO/tao/ior_corbaname/ior_corbaname_export.h new file mode 100644 index 00000000000..ce34717dbb2 --- /dev/null +++ b/TAO/tao/ior_corbaname/ior_corbaname_export.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by +// generate_export_file.pl +// ------------------------------ +#if !defined (TAO_IOR_CORBANAME_EXPORT_H) +#define TAO_IOR_CORBANAME_EXPORT_H + +#include "ace/config-all.h" + +#if !defined (TAO_IOR_CORBANAME_HAS_DLL) +#define TAO_IOR_CORBANAME_HAS_DLL 1 +#endif /* ! TAO_IOR_CORBANAME_HAS_DLL */ + +#if defined (TAO_IOR_CORBANAME_HAS_DLL) +# if (TAO_IOR_CORBANAME_HAS_DLL == 1) +# if defined (TAO_IOR_CORBANAME_BUILD_DLL) +# define TAO_IOR_CORBANAME_Export ACE_Proper_Export_Flag +# define TAO_IOR_CORBANAME_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define TAO_IOR_CORBANAME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else +# define TAO_IOR_CORBANAME_Export ACE_Proper_Import_Flag +# define TAO_IOR_CORBANAME_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define TAO_IOR_CORBANAME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* TAO_IOR_CORBANAME_BUILD_DLL */ +# else +# define TAO_IOR_CORBANAME_Export +# define TAO_IOR_CORBANAME_SINGLETON_DECLARATION(T) +# define TAO_IOR_CORBANAME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* ! TAO_IOR_CORBANAME_HAS_DLL == 1 */ +#else +# define TAO_IOR_CORBANAME_Export +# define TAO_IOR_CORBANAME_SINGLETON_DECLARATION(T) +# define TAO_IOR_CORBANAME_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* TAO_IOR_CORBANAME_HAS_DLL */ + +#endif /* TAO_IOR_CORBANAME_EXPORT_H */ + +// End of auto generated file. |