diff options
-rw-r--r-- | TAO/ChangeLogs/ChangeLog-02a | 51 | ||||
-rw-r--r-- | TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp | 144 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/CORBANAME_Parser.cpp | 168 | ||||
-rw-r--r-- | TAO/tao/ior_corbaname/CORBANAME_Parser.h | 8 | ||||
-rw-r--r-- | TAO/tests/ior_corbaloc/corbaloc.idl | 4 | ||||
-rw-r--r-- | TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp | 20 | ||||
-rw-r--r-- | TAO/tests/ior_corbaloc/status_i.cpp | 12 | ||||
-rw-r--r-- | TAO/tests/ior_corbaloc/status_i.h | 5 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/Makefile | 56 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/README | 32 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/client.cpp | 48 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/corbaname.idl | 20 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/ior_corbaname_client_i.cpp | 149 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/ior_corbaname_client_i.h | 64 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/server.cpp | 87 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/status_i.cpp | 19 | ||||
-rw-r--r-- | TAO/tests/ior_corbaname/status_i.h | 21 |
17 files changed, 741 insertions, 167 deletions
diff --git a/TAO/ChangeLogs/ChangeLog-02a b/TAO/ChangeLogs/ChangeLog-02a index d920f6e3e4d..3a8000e2de2 100644 --- a/TAO/ChangeLogs/ChangeLog-02a +++ b/TAO/ChangeLogs/ChangeLog-02a @@ -1,3 +1,54 @@ +Tue Jul 11 14:16:17 2000 Priyanka Gontla <pgontla@ece.uci.edu> + + * tests/ior_corbaloc/corbaloc.idl: + + * tests/ior_corbaloc/status_i.h: + * tests/ior_corbaloc/status_i.cpp: + * tests/ior_corbaloc/ior_corbaloc_client_i.cpp: + Changed the test so that the server returns a boolean on + receiving a request from the client. + + * tests/ior_corbaname/README: + * tests/ior_corbaname/corbaname.idl: + * tests/ior_corbaname/Makefile: + + * tests/ior_corbaname/status_i.h: + * tests/ior_corbaname/status_i.cpp: + * tests/ior_corbaname/server.cpp: + + * tests/ior_corbaname/ior_corbaname_client_i.h: + * tests/ior_corbaname/ior_corbaname_client_i.cpp: + * tests/ior_corbaname/client.cpp: + Added to example to test the corbaname: style URL. When the + server receives a request from the client, returns a boolean + :true=0 value. + + * tao/ior_corbaname/CORBANAME_Parser.h: + * tao/ior_corbaname/CORBANAME_Parser.cpp: + Implemented the corbaname: style URL. + + * tao/ior_corbaloc/CORBALOC_Parser.h + * tao/ior_corbaloc/CORBALOC_Parser.cpp: + Changed the value of a const iiop_prefix from <iiop://> to + <iiop:> + +Thu Jul 6 18:48:06 2000 Priyanka Gontla <pgontla@ece.uci.edu> + + * tao/ior_corbaname/Makefile: + * tao/ior_corbaname/ior_corbaname_export.h: + + * tao/ior_corbaname/CORBANAME_Parser.i: + * tao/ior_corbaname/CORBANAME_Parser.h: + * tao/ior_corbaname/CORBANAME_Parser.cpp: + Implemented part of the corbaname: style IOR parser. Done till + obtaining a reference to the naming context. + +Thu Jul 6 12:38:36 2000 Priyanka Gontla <pgontla@ece.uci.edu> + + * tao/ior_corbaloc/CORBALOC_Parser.h: + * tao/ior_corbaloc/CORBALOC_Parser.cpp: + Further split the TAO_CORBALOC_Parser::parse_string function. + Thu Jun 29 18:19:16 2000 Priyanka Gontla <pgontla@ece.uci.edu> * tao/ior_corbaloc/CORBALOC_Parser.h: diff --git a/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp b/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp index 2ab161fc017..249fbcfc59f 100644 --- a/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp +++ b/TAO/tao/ior_corbaloc/CORBALOC_Parser.cpp @@ -29,11 +29,11 @@ TAO_CORBALOC_Parser::match_prefix (const char *ior_string) const } void -TAO_CORBALOC_Parser::parse_string_count_helper (const char * &corbaloc_name, - CORBA::ULong &addr_list_length, +TAO_CORBALOC_Parser::parse_string_count_helper (const char * &corbaloc_name, + CORBA::ULong &addr_list_length, CORBA::ULong &count_addr) { - + CORBA::Boolean start_key_string = 1; for (const char *i = corbaloc_name; *i != '\0'; ++i) @@ -43,7 +43,7 @@ TAO_CORBALOC_Parser::parse_string_count_helper (const char * &corbaloc_name, // Increment the count of the addresses in the list ++count_addr; } - + if (*i == '/') { if (*(i+1) == '/') @@ -54,24 +54,24 @@ TAO_CORBALOC_Parser::parse_string_count_helper (const char * &corbaloc_name, else if (*(i+1) != '/') { // This is the last addr and will not be terminated with a - // ',' ..but need to count it too. - ++count_addr; - + // ',' ..but need to count it too. + ++count_addr; + // Indication that the next characters are to be // assigned to key_string start_key_string = 0; } } - + if (start_key_string == 1) { ++addr_list_length; } } - + } -void +void TAO_CORBALOC_Parser::parse_string_assign_helper (ACE_Array_Base <char *> &addr, CORBA::ULong &addr_list_length, ACE_CString &key_string, @@ -79,53 +79,57 @@ TAO_CORBALOC_Parser::parse_string_assign_helper (ACE_Array_Base <char *> &addr, CORBA::Environment &) ACE_THROW_SPEC ((CORBA::SystemException)) { - char *cloc_name_ptr = 0; CORBA::ULong current_addr = 0; - + // Tokenize using "," as the seperator char *last_addr = 0; cloc_name_ptr = ACE_OS::strtok_r (ACE_const_cast (char *, cloc_name.c_str ()), ",", &last_addr); - - const char iiop_prefix[] = "iiop://"; - + + const char iiop_prefix[] = "iiop:"; + while (cloc_name_ptr != 0) { - // Allocation of memory - addr [current_addr] = CORBA::string_alloc (addr_list_length + - key_string.length ()); - + // Loop till we get all the endpoints. if (ACE_OS::strncmp (cloc_name_ptr, iiop_prefix, sizeof (iiop_prefix)-1) != 0) { // If there is no explicit protocol specified, prepend the - // default "iiop://" + // default "iiop:" + + // Allocation of memory + addr [current_addr] = + CORBA::string_alloc (addr_list_length + + sizeof (iiop_prefix) + + key_string.length ()); + ACE_OS::strcpy (addr [current_addr], iiop_prefix); ACE_OS::strcat (addr [current_addr], cloc_name_ptr); - } else { + // Allocation of memory + addr [current_addr] = CORBA::string_alloc (addr_list_length + + key_string.length ()); // If the protocol is <iiop:> - ACE_OS::strcpy (addr [current_addr], + ACE_OS::strcpy (addr [current_addr], cloc_name_ptr); } - ACE_OS::strcat (addr [current_addr], + ACE_OS::strcat (addr [current_addr], key_string.c_str ()); ++current_addr; // Get the next token. - cloc_name_ptr = ACE_OS::strtok_r (NULL, + cloc_name_ptr = ACE_OS::strtok_r (NULL, ",", &last_addr); - } } @@ -137,21 +141,20 @@ TAO_CORBALOC_Parser::parse_string_mprofile_helper (ACE_Array_Base <char *> &add CORBA::Environment &ACE_TRY_ENV) ACE_THROW_SPEC ((CORBA::SystemException)) { - CORBA::Object_ptr obj = CORBA::Object::_nil (); - + // Make one MProfile for all of these endpoints TAO_MProfile mprofile; - + for (CORBA::ULong j = 0; j != count_addr; ++j) { int retv = orb->orb_core ()->connector_registry ()->make_mprofile (addr [j], mprofile, ACE_TRY_ENV); - + ACE_CHECK_RETURN (CORBA::Object::_nil ()); // Return nil. - + if (retv != 0) { ACE_THROW_RETURN (CORBA::INV_OBJREF ( @@ -161,7 +164,7 @@ TAO_CORBALOC_Parser::parse_string_mprofile_helper (ACE_Array_Base <char *> &add CORBA::COMPLETED_NO), CORBA::Object::_nil ()); } - + // Now make the TAO_Stub. TAO_Stub *data = 0; ACE_NEW_THROW_EX (data, @@ -173,19 +176,19 @@ TAO_CORBALOC_Parser::parse_string_mprofile_helper (ACE_Array_Base <char *> &add 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; - + // Create the CORBA level proxy. This will increase the ref_count // on data by one ACE_NEW_THROW_EX (obj, @@ -198,12 +201,12 @@ TAO_CORBALOC_Parser::parse_string_mprofile_helper (ACE_Array_Base <char *> &add 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; } @@ -212,20 +215,27 @@ TAO_CORBALOC_Parser::parse_string_rir_helper (const char * &corbaloc_name, CORBA::ORB_ptr orb, CORBA::Environment &ACE_TRY_ENV) - ACE_THROW_SPEC ((CORBA::SystemException)) + ACE_THROW_SPEC ((CORBA::SystemException)) { const char rir_prefix [] = "rir:/"; CORBA::Object_ptr rir_obj = CORBA::Object::_nil (); - + ACE_TRY { // "rir" protocol. Pass the key string as an // argument to the resolve_initial_references () const char *key_string = corbaloc_name + sizeof (rir_prefix) -1; - - rir_obj = orb->resolve_initial_references (key_string, + + if (ACE_OS::strcmp (key_string, "") == 0) + { + // If the key string is empty, assume the default + // "NameService". + key_string = "NameService"; + } + + rir_obj = orb->resolve_initial_references (key_string, ACE_TRY_ENV); ACE_TRY_CHECK; } @@ -235,18 +245,18 @@ TAO_CORBALOC_Parser::parse_string_rir_helper (const char * } ACE_ENDTRY; ACE_CHECK_RETURN (CORBA::Object::_nil ()); - + return rir_obj; } 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; @@ -274,46 +284,46 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, 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 *corbaloc_name = ior + sizeof corbaloc_prefix - 1; - + CORBA::Object_ptr object = CORBA::Object::_nil (); ACE_TRY { // No of endpoints CORBA::ULong count_addr = 0; - + // Length of obj_addr_list CORBA::ULong addr_list_length = 0; - - // If the protocol is "iiop:", + + // If the protocol is "iiop:", if (this->check_prefix (corbaloc_name) == 0) - { + { // Count the length of the obj_addr_list and number of // endpoints in the obj_addr_list - this->parse_string_count_helper (corbaloc_name, - addr_list_length, + this->parse_string_count_helper (corbaloc_name, + addr_list_length, count_addr); - + // Convert corbaloc_name as a ACE_CString ACE_CString corbaloc_name_str (corbaloc_name, 0, 1); // Get the key_string which is a substring of corbaloc_name_str ACE_CString key_string = corbaloc_name_str.substring (addr_list_length, -1); + // Array of <obj_addr> + ACE_Array_Base<char*> addr (count_addr); + // Copy the <obj_addr_list> to cloc_name. - ACE_CString cloc_name (corbaloc_name, + ACE_CString cloc_name (corbaloc_name, addr_list_length, - 0, + 0, 1); - // Array of <obj_addr> - ACE_Array_Base<char*> addr (count_addr); - // Assign the <obj_addr> to the array elements this->parse_string_assign_helper (addr, addr_list_length, @@ -321,32 +331,32 @@ TAO_CORBALOC_Parser::parse_string (const char *ior, cloc_name, ACE_TRY_ENV); ACE_TRY_CHECK; - + // Get the Ptr to the NameService object = this->parse_string_mprofile_helper (addr, - count_addr, + count_addr, orb, ACE_TRY_ENV); ACE_TRY_CHECK; } - else + else { - // RIR case: + // RIR case: object = this->parse_string_rir_helper (corbaloc_name, orb, ACE_TRY_ENV); ACE_TRY_CHECK; } - - } + + } ACE_CATCH (CORBA::SystemException, ex) { - ACE_PRINT_EXCEPTION (ex, "CORBALOC_Parser:RIR:"); + ACE_PRINT_EXCEPTION (ex, "CORBALOC_Parser"); } ACE_ENDTRY; ACE_CHECK_RETURN (CORBA::Object::_nil ()); - + return object; } diff --git a/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp b/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp index d23ac3c25df..bd3cb6f9262 100644 --- a/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp +++ b/TAO/tao/ior_corbaname/CORBANAME_Parser.cpp @@ -1,7 +1,9 @@ // $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" @@ -10,8 +12,6 @@ #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__ */ @@ -32,129 +32,135 @@ TAO_CORBANAME_Parser::match_prefix (const char *ior_string) const sizeof corbaname_prefix - 1) == 0); } -void -TAO_CORBANAME_Parser::parse_string_count_helper (const char * &corbaname, - CORBA::ULong &pos_seperator) +CORBA::Object_ptr +TAO_CORBANAME_Parser:: +parse_string_dynamic_request_helper (CosNaming::NamingContextExt_var + &naming_context, + ACE_CString &key_string, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)) { - - CORBA::Boolean start_key_string = 1; - for (const char *i = corbaname; *i != '\0'; ++i) + CORBA::Object_ptr obj = CORBA::Object::_nil (); + ACE_TRY { - 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; - } + // 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); + + if (CORBA::is_nil (obj)) + 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; } CORBA::Object_ptr TAO_CORBANAME_Parser::parse_string (const char *ior, - CORBA::ORB_ptr orb, - CORBA::Environment &ACE_TRY_ENV) + 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; + CORBA::Object_ptr obj = CORBA::Object::_nil (); + ACE_TRY { + char rir_prot [] = "rir:"; + // The position of the seperator between the obj_addr and key + // string 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); + + pos_seperator = corbaname_str.find ("#", 0); + + // Get the Key String + ACE_CString key_string = + corbaname_str.substring (pos_seperator + 1, + -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; + + if (ACE_OS::strncmp (corbaname, + rir_prot, + sizeof (rir_prot)) != 0) + { + // Implies that <iiop:> protocol is to be used. + // So .. we need to get the host address where an object of + // type NamingContext can be found. + // Get the obj_addr + ACE_CString obj_addr = corbaname_str.substring (0, + pos_seperator); + + corbaloc_addr += obj_addr; + } + + ACE_CString name_service ("/NameService", 0, 1); + corbaloc_addr += name_service; + // Obtain a reference to the naming context - CORBA::Object_var name_context_obj = + CORBA::Object_var name_context_obj = orb->string_to_object (corbaloc_addr.c_str (), ACE_TRY_ENV); ACE_TRY_CHECK; - + + // Check if the Object reference is nil. 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; + ACE_TRY_CHECK; + // Check if the object reference is nil. 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); + // Make a dynamic request for resolve_str in this naming context + obj = this->parse_string_dynamic_request_helper (naming_context, + key_string, + 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) { @@ -162,8 +168,8 @@ TAO_CORBANAME_Parser::parse_string (const char *ior, } ACE_ENDTRY; ACE_CHECK_RETURN (CORBA::Object::_nil ()); - - return obj.in (); + + return obj; } ACE_FACTORY_DEFINE (TAO_IOR_CORBANAME, TAO_CORBANAME_Parser) diff --git a/TAO/tao/ior_corbaname/CORBANAME_Parser.h b/TAO/tao/ior_corbaname/CORBANAME_Parser.h index ceb78b800a6..18fbd61424d 100644 --- a/TAO/tao/ior_corbaname/CORBANAME_Parser.h +++ b/TAO/tao/ior_corbaname/CORBANAME_Parser.h @@ -19,6 +19,7 @@ #include "tao/IOR_Parser.h" #include "ior_corbaname_export.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once @@ -51,8 +52,11 @@ public: ACE_THROW_SPEC ((CORBA::SystemException)); private: - virtual void parse_string_count_helper (const char * &corbaname, - CORBA::ULong &pos_seperator); + virtual CORBA::Object_ptr + parse_string_dynamic_request_helper (CosNaming::NamingContextExt_var &naming_context, + ACE_CString &key_string, + CORBA::Environment &ACE_TRY_ENV) + ACE_THROW_SPEC ((CORBA::SystemException)); }; #if defined (__ACE_INLINE__) diff --git a/TAO/tests/ior_corbaloc/corbaloc.idl b/TAO/tests/ior_corbaloc/corbaloc.idl index 2d01e59af1c..296ae9adde0 100644 --- a/TAO/tests/ior_corbaloc/corbaloc.idl +++ b/TAO/tests/ior_corbaloc/corbaloc.idl @@ -12,8 +12,8 @@ module corbaloc // = DESCRIPTION // Prints out the status. - void print_status (); - // Print <connected> if the server received the + boolean print_status (); + // Return <true == 0> 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 index 3d611d2ce86..144855bc048 100644 --- a/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp +++ b/TAO/tests/ior_corbaloc/ior_corbaloc_client_i.cpp @@ -63,8 +63,16 @@ IOR_corbaloc_Client_i::run (CORBA::Environment &ACE_TRY_ENV) } // Invoke a request on the server - factory->print_status (ACE_TRY_ENV); + CORBA::Boolean ret_value = + factory->print_status (ACE_TRY_ENV); ACE_TRY_CHECK; + + if (ret_value == 0) + { + ACE_DEBUG ((LM_DEBUG, + "The server has been contacted !!\n", + 0)); + } } ACE_CATCH (CosNaming::NamingContext::NotFound, ex) { @@ -103,17 +111,15 @@ IOR_corbaloc_Client_i::init (int argc, char **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 (argv[1], ACE_TRY_ENV); + orb->string_to_object (this->argv_[1], + ACE_TRY_ENV); ACE_TRY_CHECK; if (CORBA::is_nil (naming_context_object.in ())) ACE_ERROR_RETURN ((LM_ERROR, - "Cannot resolve Naming Service\n"), + "Cannot resolve Naming Service\n : client"), 1); // Narrow to get the correct reference @@ -124,7 +130,7 @@ IOR_corbaloc_Client_i::init (int argc, char **argv) if (CORBA::is_nil (this->naming_context_.in ())) ACE_ERROR_RETURN ((LM_ERROR, - "Cannot narrow Naming Service\n"), + "Cannot narrow Naming Service\n :client"), 1); } ACE_CATCHANY diff --git a/TAO/tests/ior_corbaloc/status_i.cpp b/TAO/tests/ior_corbaloc/status_i.cpp index 9f0ff4972a0..00a61400cfb 100644 --- a/TAO/tests/ior_corbaloc/status_i.cpp +++ b/TAO/tests/ior_corbaloc/status_i.cpp @@ -9,13 +9,13 @@ corbaloc_Status_i::corbaloc_Status_i (CORBA::Environment & = TAO_default_environ // Constructor } -void -corbaloc_Status_i::print_status (CORBA::Environment & = TAO_default_environment()) +CORBA::Boolean +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")); - + // If the server received the request from the client, + // return true == 0; + + return 0; } - diff --git a/TAO/tests/ior_corbaloc/status_i.h b/TAO/tests/ior_corbaloc/status_i.h index b1227f215df..28e4d1ce9fc 100644 --- a/TAO/tests/ior_corbaloc/status_i.h +++ b/TAO/tests/ior_corbaloc/status_i.h @@ -13,8 +13,9 @@ public: corbaloc_Status_i (CORBA::Environment & = TAO_default_environment()); - void print_status (CORBA::Environment & = TAO_default_environment()) throw (CORBA::SystemException); - + CORBA::Boolean print_status (CORBA::Environment & = TAO_default_environment()) + throw (CORBA::SystemException); + }; #endif /* STATUS_I_H */ diff --git a/TAO/tests/ior_corbaname/Makefile b/TAO/tests/ior_corbaname/Makefile new file mode 100644 index 00000000000..344f39658f2 --- /dev/null +++ b/TAO/tests/ior_corbaname/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 = corbanameC corbanameS +BIN = server client + +SRC = $(addsuffix .cpp, $(BIN) $(IDLFILES) status_i) + +SERVER_OBJS = $(addsuffix .o, server status_i $(IDLFILES)) +CLIENT_OBJS = $(addsuffix .o, client ior_corbaname_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), corbaname$(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), corbaname$(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_corbaname/README b/TAO/tests/ior_corbaname/README new file mode 100644 index 00000000000..fda661070be --- /dev/null +++ b/TAO/tests/ior_corbaname/README @@ -0,0 +1,32 @@ +// $Id$ + +Here is a simple to test the corbaname: style URL. The simple way to +test is to run the run_test.pl. + +To test manually: + +1. Run the NamingService at a specified endpoint. + + $NamingService -ORBEndPoint iiop://doc.ece.uci.edu:12345 & + +2. Run the server. + + ./server & + +3. Run the client as one of these. + + a) ./client corbaname://doc.ece.uci.edu:12345 + + CORBANAME style URL is used and the protocol used to + contact the naming context is <iiop> implicitly. + + b) ./client corbaname:iiop://doc.ece.uci.edu:12345 + + CORBANAME style URL is used and the protocol used to + contact the naming context is <iiop>. + + + c) ./client corbaname:rir: + + CORBANAME style URL is used and the protocol used to + contact the naming context is <rir>. diff --git a/TAO/tests/ior_corbaname/client.cpp b/TAO/tests/ior_corbaname/client.cpp new file mode 100644 index 00000000000..2c4a30a83f5 --- /dev/null +++ b/TAO/tests/ior_corbaname/client.cpp @@ -0,0 +1,48 @@ +// $Id$ +// + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/ior_corbaname/ +// +// = FILENAME +// client.cpp +// +// = DESCRIPTION +// This implements a simple CORBA client for the +// corbaname: style IOR parser +// +// = AUTHOR +// Priyanka Gontla <pgontla@ece.uci.edu> +// +// +// ============================================================================ + +#include "ior_corbaname_client_i.h" + +int main (int argc, char *argv []) +{ + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + + IOR_corbaname_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_corbaname/corbaname.idl b/TAO/tests/ior_corbaname/corbaname.idl new file mode 100644 index 00000000000..d0650d5d6b9 --- /dev/null +++ b/TAO/tests/ior_corbaname/corbaname.idl @@ -0,0 +1,20 @@ +// $Id$ + +module corbaname +{ + + interface Status + { + // = TITLE + // A simple interface to check the status of + // connection between the client and the server. + // + // = DESCRIPTION + // Prints out the status. + + boolean print_status (); + // Return <true> if the server received the + // request from the client. + + }; +}; diff --git a/TAO/tests/ior_corbaname/ior_corbaname_client_i.cpp b/TAO/tests/ior_corbaname/ior_corbaname_client_i.cpp new file mode 100644 index 00000000000..584c4243460 --- /dev/null +++ b/TAO/tests/ior_corbaname/ior_corbaname_client_i.cpp @@ -0,0 +1,149 @@ +// $Id$ +// + +// =========================================================== +// +// = LIBRARY +// TAO/tests/ior_corbaname/ +// +// = FILENAME +// ior_corbaname_client_i.cpp +// +// = DESCRIPTION +// This example implements a simple client which sends a corbaname: +// style url to the server and gets a response from the +// server to indicate that the server has received the request. +// +// = AUTHORS +// Priyanka Gontla <pgontla@ece.uci.edu> +// +//============================================================ + +#include "ior_corbaname_client_i.h" +#include "ace/Get_Opt.h" +#include "ace/Read_Buffer.h" + +// Constructor +IOR_corbaname_Client_i::IOR_corbaname_Client_i (void) +{ +} + +// Destructor +IOR_corbaname_Client_i::~IOR_corbaname_Client_i (void) +{ +} + +int +IOR_corbaname_Client_i::run (CORBA::Environment &ACE_TRY_ENV) +{ + + ACE_TRY + { + CosNaming::Name name (1); + + name.length (1); + name[0].id = CORBA::string_dup ("STATUS"); + + // The corbaname URL contains the host at which an NamingContext + // Object can be found and also the stringified form of an entry + // in the Naming Service seperated by '#'. For simplicity, + // in this example, we are specifying the stringified form of + // the binding directly without using <to_string> method on + // <name>. "#" refers to the seperator between the host and the + // entry. + + ACE_CString corbaname_url (this->argv_[1], 0, 1); + + // Append the seperator '#' to the host. + corbaname_url += "#"; + + // Append the stringified name to the resultant. + corbaname_url += "STATUS"; + + // Resolve the stringified name. + CORBA::Object_var factory_object = + this->orb_->string_to_object (corbaname_url.c_str (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Narrow + corbaname::Status_var factory = + corbaname::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 + CORBA::Boolean ret_value = + factory->print_status (ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (ret_value == 0) + { + ACE_DEBUG ((LM_DEBUG, + "The server has been successfully contacted.\n", + 0)); + } + } + 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 on 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_corbaname_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... + this->orb_ = + CORBA::ORB_init (this->argc_, + this->argv_, + "" /* the ORB name, it can be anything! */, + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // There must be at least one argument, the file that has to be + // retrieved + if (this->argc_ < 2) + ACE_ERROR_RETURN ((LM_ERROR, + "Address of naming context not specified\n", + this->argv_[0]), + -1); + + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "client"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/ior_corbaname/ior_corbaname_client_i.h b/TAO/tests/ior_corbaname/ior_corbaname_client_i.h new file mode 100644 index 00000000000..223dcb307ba --- /dev/null +++ b/TAO/tests/ior_corbaname/ior_corbaname_client_i.h @@ -0,0 +1,64 @@ +// -*- C++ -*- +// $Id$ + +// =========================================================== +// +// = LIBRARY +// TAO/tests/ior_corbaname/ +// +// = FILENAME +// ior_corbaname_client_i.h +// +// = DESCRIPTION +// This class implements a simple client which sends a corbaname: +// style url to the server and gets a response from the +// server to indicate that the server has received the request. +// +// = AUTHORS +// Priyanka Gontla <pgontla@ece.uci.edu> +// +//============================================================ + + +#if !defined (IOR_CORBANAME_CLIENT_I_H) +#define IOR_CORBANAME_CLIENT_I_H + +#include "corbanameC.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" + +class IOR_corbaname_Client_i +{ + // = TITLE + // NContextExt Client Implementation + // + // = DESCRIPTION + // + + public: + // = COnstructor and destructor. + IOR_corbaname_Client_i (void); + ~IOR_corbaname_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. + + CORBA::ORB_var orb_; + // ORB + + CosNaming::NamingContextExt_var naming_context_; + // Naming context + +}; + +#endif /* IOR_CORBANAME_CLIENT_I_H */ diff --git a/TAO/tests/ior_corbaname/server.cpp b/TAO/tests/ior_corbaname/server.cpp new file mode 100644 index 00000000000..51db359bd57 --- /dev/null +++ b/TAO/tests/ior_corbaname/server.cpp @@ -0,0 +1,87 @@ +// $Id$ +// server.cpp +// + +#include "status_i.h" +#include "orbsvcs/orbsvcs/CosNamingC.h" +#include <iostream> + +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 + corbaname_Status_i status_i; + + // Activate it to obtain the reference + corbaname::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 Status to the Naming Context + CosNaming::Name name (1); + name.length (1); + name[0].id = CORBA::string_dup ("STATUS"); + + naming_context->bind (name, + status.in (), + ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Run the orb + orb->run (ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Destroy the POA, waiting until the destruction terminates + poa->destroy (1, 1); + orb->destroy (); + + } + ACE_CATCH (CORBA::SystemException, ex) + { + ACE_PRINT_EXCEPTION (ex, "CORBA exception raised in server!"); + } + ACE_ENDTRY; + ACE_CHECK_RETURN (-1); + + return 0; +} diff --git a/TAO/tests/ior_corbaname/status_i.cpp b/TAO/tests/ior_corbaname/status_i.cpp new file mode 100644 index 00000000000..ed924dd9956 --- /dev/null +++ b/TAO/tests/ior_corbaname/status_i.cpp @@ -0,0 +1,19 @@ +// +// $Id$ +// + +#include "status_i.h" + +corbaname_Status_i::corbaname_Status_i (CORBA::Environment & = TAO_default_environment()) +{ + // Constructor +} + +CORBA::Boolean +corbaname_Status_i::print_status (CORBA::Environment & = TAO_default_environment()) + throw (CORBA::SystemException) +{ + // If the client makes a succesful request, return a true value + // indicating that it has successfully reached the server. + return 0; +} diff --git a/TAO/tests/ior_corbaname/status_i.h b/TAO/tests/ior_corbaname/status_i.h new file mode 100644 index 00000000000..4ffbf10bd5d --- /dev/null +++ b/TAO/tests/ior_corbaname/status_i.h @@ -0,0 +1,21 @@ +// +// $Id$ +// + +#ifndef STATUS_I_H +#define STATUS_I_H + +#include "corbanameS.h" +#include <string> + +class corbaname_Status_i : public POA_corbaname::Status { +public: + corbaname_Status_i (CORBA::Environment & = + TAO_default_environment()); + + CORBA::Boolean print_status (CORBA::Environment & = TAO_default_environment()) + throw (CORBA::SystemException); + +}; + +#endif /* STATUS_I_H */ |