diff options
Diffstat (limited to 'TAO/tests/Portable_Interceptors/Collocated/Dynamic')
15 files changed, 1275 insertions, 0 deletions
diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/.cvsignore b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/.cvsignore new file mode 100644 index 00000000000..307259b4b57 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/.cvsignore @@ -0,0 +1 @@ +Collocated_Test diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.cpp new file mode 100644 index 00000000000..aa829e678f1 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.cpp @@ -0,0 +1,98 @@ +// +// $Id$ +// + +#include "Client_Task.h" +#include "testC.h" +#include "interceptors.h" + +ACE_RCSID(Muxing, Client_Task, "$Id$") + +Client_Task::Client_Task (const char *ior, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , input_ (ior) + , corb_ (CORBA::ORB::_duplicate (corb)) + +{ +} + +int +Client_Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + + CORBA::Object_var object = + corb_->string_to_object (input_ ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Test_Interceptors::Visual_var server = + Test_Interceptors::Visual::_narrow (object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (server.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Object reference <%s> is nil\n", + this->input_), + 1); + } + + run_test (server.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + server->shutdown (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught in client task:"); + return 1; + } + ACE_ENDTRY; + + return 0; + +} + + +void +Client_Task::run_test (Test_Interceptors::Visual_ptr server + ACE_ENV_ARG_DECL) +{ + server->normal (10 ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long one = 1, two = 1; + (void) server->calculate (one, + two + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + ACE_TRY + { + (void) server->user (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCH (Test_Interceptors::Silly, userex) + { + ACE_DEBUG ((LM_DEBUG, "Caught Silly\n")); + } + ACE_ENDTRY; + ACE_CHECK; + + ACE_TRY_EX (SYS) + { + server->system (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK_EX (SYS); + } + ACE_CATCH (CORBA::INV_OBJREF, sysex) + { + ACE_DEBUG ((LM_DEBUG, "Caught CORBA::INV_OBJREF\n")); + } + ACE_ENDTRY; + ACE_CHECK; +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.h b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.h new file mode 100644 index 00000000000..def1f6d2bb4 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Client_Task.h @@ -0,0 +1,41 @@ +// +// $Id$ +// + +#ifndef COLLOCATED_TEST_CLIENT_TASK_H +#define COLLOCATED_TEST_CLIENT_TASK_H +#include /**/ "ace/pre.h" + +#include "tao/ORB.h" +#include "ace/Task.h" +#include "testS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +/// Implement a Task to run the client as a thread +class Client_Task : public ACE_Task_Base +{ +public: + + /// Constructor + Client_Task (const char *input, + CORBA::ORB_ptr corb, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + + void run_test (Test_Interceptors::Visual_ptr server + ACE_ENV_ARG_DECL); + +private: + const char *input_; + + CORBA::ORB_var corb_; + +}; + +#include /**/ "ace/post.h" +#endif /* COLLOCATED_TEST_CLIENT_TASK_H */ diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Collocated_Test.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Collocated_Test.cpp new file mode 100644 index 00000000000..1aaceae2c8c --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Collocated_Test.cpp @@ -0,0 +1,138 @@ +//$Id$ + +#include "Server_Task.h" +#include "Client_Task.h" +#include "Echo_Collocated_ORBInitializer.h" +#include "interceptors.h" +#include "tao/ORBInitializer_Registry.h" +#include "ace/Get_Opt.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/SString.h" +#include "ace/Manual_Event.h" + +const char *output = "test.ior"; +const char *input = "file://test.ior"; +ACE_CString server_orb; +ACE_CString client_orb; +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:o"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + output = get_opts.opt_arg (); + break; + case 'k': + input = get_opts.opt_arg (); + break; + case '?': + default: + // This is a hack but that is okay! + return 0; + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + if (parse_args (argc, + argv) == -1) + return -1; + + server_orb.set ("server_orb"); + client_orb.set ("client_orb"); + + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + PortableInterceptor::ORBInitializer_ptr temp_initializer = + PortableInterceptor::ORBInitializer::_nil (); + + ACE_NEW_RETURN (temp_initializer, + Echo_Collocated_ORBInitializer, + -1); // No exceptions yet! + PortableInterceptor::ORBInitializer_var orb_initializer = + temp_initializer; + + PortableInterceptor::register_orb_initializer (orb_initializer.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Argv_Type_Converter satc (argc, argv); + CORBA::ORB_var sorb = + CORBA::ORB_init (satc.get_argc (), + satc.get_TCHAR_argv (), + server_orb.c_str () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_Manual_Event me; + Server_Task server_task (output, + sorb.in (), + me, + ACE_Thread_Manager::instance ()); + + if (server_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating server task\n")); + } + + // Wait for the server thread to do some processing + me.wait (); + + ACE_Argv_Type_Converter catc (argc, argv); + CORBA::ORB_var corb = + CORBA::ORB_init (catc.get_argc (), + catc.get_TCHAR_argv (), + client_orb.c_str () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Client_Task client_task (input, + corb.in (), + ACE_Thread_Manager::instance ()); + + if (client_task.activate (THR_NEW_LWP | THR_JOINABLE, + 1, + 1) == -1) + { + ACE_ERROR ((LM_ERROR, "Error activating client task\n")); + } + + ACE_Thread_Manager::instance ()->wait (); + + sorb->destroy (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::ULong number_called = + Echo_Server_Request_Interceptor::server_interceptor_check_; + + if (number_called != 10) + { + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR: Server Side Interceptors not" + " called properly, called %d times, expected 10\n", + number_called)); + } + + if (Echo_Client_Request_Interceptor::client_interceptor_check_ != 10) + ACE_ERROR ((LM_ERROR, + "(%P|%t) ERROR:Client Interceptors not called" + " properly\n")); + + } + ACE_CATCHANY + { + // Ignore exceptions.. + } + ACE_ENDTRY; + return 0; +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.cpp new file mode 100644 index 00000000000..879b3549b22 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.cpp @@ -0,0 +1,69 @@ +// -*- C++ -*- +// +// $Id$ + +#include "Echo_Collocated_ORBInitializer.h" +#include "interceptors.h" + +#include "ace/OS_NS_string.h" + +void +Echo_Collocated_ORBInitializer::pre_init ( + PortableInterceptor::ORBInitInfo_ptr + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Echo_Collocated_ORBInitializer::post_init ( + PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::String_var orb_id = + info->orb_id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + if (!ACE_OS::strcmp (orb_id.in (), "client_orb")) + { + PortableInterceptor::ClientRequestInterceptor_ptr interceptor = + PortableInterceptor::ClientRequestInterceptor::_nil (); + + // Install the Echo client request interceptor + ACE_NEW_THROW_EX (interceptor, + Echo_Client_Request_Interceptor, + CORBA::NO_MEMORY ()); + ACE_CHECK; + + PortableInterceptor::ClientRequestInterceptor_var + client_interceptor = interceptor; + + info->add_client_request_interceptor (client_interceptor.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + else if (!ACE_OS::strcmp (orb_id.in (), "server_orb")) + { + PortableInterceptor::ServerRequestInterceptor_ptr interceptor = + PortableInterceptor::ServerRequestInterceptor::_nil (); + + // Install the Echo server request interceptor + ACE_NEW_THROW_EX (interceptor, + Echo_Server_Request_Interceptor, + CORBA::NO_MEMORY ()); + ACE_CHECK; + + PortableInterceptor::ServerRequestInterceptor_var + server_interceptor = interceptor; + + info->add_server_request_interceptor (server_interceptor.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + else + { + } + +} + diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.h b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.h new file mode 100644 index 00000000000..7a18eb9b37a --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Echo_Collocated_ORBInitializer.h @@ -0,0 +1,47 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef TAO_ECHO_CLIENT_ORB_INITIALIZER_H +#define TAO_ECHO_CLIENT_ORB_INITIALIZER_H + +#include /**/ "ace/pre.h" +#include "tao/orbconf.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PI/PI.h" +#include "tao/LocalObject.h" + +// This is to remove "inherits via dominance" warnings from MSVC. +// MSVC is being a little too paranoid. +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4250) +#endif /* _MSC_VER */ + +/// Echo client ORB initializer. +class Echo_Collocated_ORBInitializer : + public virtual PortableInterceptor::ORBInitializer, + public virtual TAO_Local_RefCounted_Object +{ +public: + + virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); +}; + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /* _MSC_VER */ + +#include /**/ "ace/post.h" + +#endif /* TAO_ECHO_CLIENT_ORB_INITIALIZER_H */ diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/PI_Dynamic.mpc b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/PI_Dynamic.mpc new file mode 100644 index 00000000000..e116424db27 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/PI_Dynamic.mpc @@ -0,0 +1,16 @@ +// -*- MPC -*- +// $Id$ + +project(*Collocated): taoserver, pi, pi_server, interceptors { + exename = Collocated_Test + Source_Files { + testC.cpp + testS.cpp + test_i.cpp + interceptors.cpp + Echo_Collocated_ORBInitializer.cpp + Collocated_Test.cpp + Client_Task.cpp + Server_Task.cpp + } +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.cpp new file mode 100644 index 00000000000..a9db6a71b8a --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.cpp @@ -0,0 +1,109 @@ +// +// $Id$ +// +#include "Server_Task.h" +#include "test_i.h" +#include "interceptors.h" + +#include "ace/Manual_Event.h" + +ACE_RCSID(Collocated_Test, + Server_Task, + "$Id$") + + +Server_Task::Server_Task (const char *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr) + : ACE_Task_Base (thr_mgr) + , output_ (output) + , me_ (me) + , sorb_ (CORBA::ORB::_duplicate (sorb)) +{ +} + +int +Server_Task::svc (void) +{ + ACE_TRY_NEW_ENV + { + + CORBA::Object_var poa_object = + sorb_->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + 1); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + Visual_i * server_impl = 0; + ACE_NEW_RETURN (server_impl, Visual_i (sorb_.in ()), 1); + + PortableServer::ObjectId_var id = + root_poa->activate_object (server_impl + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::Object_var test_obj = + root_poa->id_to_reference (id.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Test_Interceptors::Visual_var server = + Test_Interceptors::Visual::_narrow (test_obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + CORBA::String_var ior = + this->sorb_->object_to_string (server.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "Test_Interceptors::Visual: <%s>\n", ior.in ())); + + // If the ior_output_file exists, output the ior to it + if (output_ != 0) + { + FILE *output_file= ACE_OS::fopen (this->output_, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + this->output_), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + } + + // Signal the main thread before we call orb->run (); + this->me_.signal (); + + this->sorb_->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); + + root_poa->destroy (1, 1 ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Exception caught in server task:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.h b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.h new file mode 100644 index 00000000000..2101f9a9a15 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/Server_Task.h @@ -0,0 +1,48 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef COLLOCATED_SERVER_TASK_H +#define COLLOCATED_SERVER_TASK_H + +#include /**/ "ace/pre.h" + +#include "tao/ORB.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Task.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_Manual_Event; +ACE_END_VERSIONED_NAMESPACE_DECL + +/// Implement a Task to run the server in a single thread +class Server_Task : public ACE_Task_Base +{ +public: + /// Constructor + Server_Task (const char *output, + CORBA::ORB_ptr sorb, + ACE_Manual_Event &me, + ACE_Thread_Manager *thr_mgr); + + /// Thread entry point + int svc (void); + +private: + /// Output file for IOR + const char *output_; + + /// Manual event to wake up the main thread to create a client + /// thread. + ACE_Manual_Event &me_; + + CORBA::ORB_var sorb_; +}; + +#include /**/ "ace/post.h" + +#endif /* COLLOCATED_SERVER_TASK_H */ diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.cpp new file mode 100644 index 00000000000..907a3e1193f --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.cpp @@ -0,0 +1,371 @@ +// $Id$ + +#include "interceptors.h" +#include "tao/AnyTypeCode/AnyTypeCode_Adapter_Impl.h" +#include "tao/AnyTypeCode/DynamicC.h" +#include "tao/AnyTypeCode/TypeCode.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_string.h" + +ACE_RCSID (Dynamic, + interceptors, + "$Id$") + +const char *request_msg = "The Echo_Request_Interceptor request message"; +const char *reply_msg = "The Echo_Request_Interceptor reply message"; +CORBA::ULong Echo_Client_Request_Interceptor::client_interceptor_check_ = 0; +CORBA::ULong Echo_Server_Request_Interceptor::server_interceptor_check_ = 0; + +Echo_Client_Request_Interceptor::Echo_Client_Request_Interceptor (void) + : myname_ ("Echo_Client_Interceptor") +{ +} + +Echo_Client_Request_Interceptor::~Echo_Client_Request_Interceptor () +{ +} + +char * +Echo_Client_Request_Interceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CORBA::string_dup (this->myname_); +} + +void +Echo_Client_Request_Interceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Echo_Client_Request_Interceptor::send_poll ( + PortableInterceptor::ClientRequestInfo_ptr + ACE_ENV_ARG_DECL_NOT_USED + ) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // Do nothing +} + +void +Echo_Client_Request_Interceptor::send_request ( + PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + client_interceptor_check_++; + + CORBA::String_var op = + ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + +#if 0 + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::send_request\n")); + + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::send_request from " + "\"%s\"\n", + op.in ())); + +#endif /*if 0*/ + + if (ACE_OS::strcmp (op.in (), "normal") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i].argument >>= param; + +#if 0 + ACE_DEBUG ((LM_DEBUG, + "The arg is %d\n", + param)); +#endif /*if 0*/ + } +} + +void +Echo_Client_Request_Interceptor::receive_other ( + PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + client_interceptor_check_++; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + +#if 0 + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::receive_other " + "from \"%s\"\n", + op.in ())); +#endif /*if 0*/ +} + +void +Echo_Client_Request_Interceptor::receive_reply ( + PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + client_interceptor_check_++; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + +#if 0 + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::receive_reply " + "from \"%s\"\n", + op.in ())); +#endif /*if 0*/ + + if (ACE_OS::strcmp (op.in (), "normal") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i].argument >>= param; + + } + else if (ACE_OS::strcmp (op.in (), "calculate") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param1, param2, result; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i++].argument >>= param1; + paramlist[i].argument >>= param2; + + CORBA::Any_var result_any = ri->result (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + (result_any.in ()) >>= result; + +#if 0 + ACE_DEBUG ((LM_DEBUG, + "The result of calculate is %d + %d = %d\n", + param1, + param2, + result)); +#endif /*if 0*/ + } +} + +void +Echo_Client_Request_Interceptor::receive_exception ( + PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + client_interceptor_check_++; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::String_var exception_id = + ri->received_exception_id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::received_exception " + "from \"%s\"\n", + op.in ())); + + ACE_DEBUG ((LM_DEBUG, + "Exception ID = %s\n", + exception_id.in ())); +} + +Echo_Server_Request_Interceptor::Echo_Server_Request_Interceptor (void) + : myname_ ("Echo_Server_Interceptor") +{ +} + +Echo_Server_Request_Interceptor::~Echo_Server_Request_Interceptor () +{ +} + +char * +Echo_Server_Request_Interceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CORBA::string_dup (this->myname_); +} + +void +Echo_Server_Request_Interceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Echo_Server_Request_Interceptor::receive_request_service_contexts ( + PortableInterceptor::ServerRequestInfo_ptr + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ +} + +void +Echo_Server_Request_Interceptor::receive_request ( + PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + ++server_interceptor_check_; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + PortableInterceptor::ObjectId_var test_oid = + ri->object_id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::receive_request from \"%s\"\n", + op.in ())); + + if (ACE_OS::strcmp (op.in (), "normal") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i].argument >>= param; + + ACE_DEBUG ((LM_DEBUG, + "The arg is %d\n", + param)); + + } + + CORBA::String_var tmdi = + ri->target_most_derived_interface (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Target most derived interface: %s\n", + tmdi.in ())); +} + +void +Echo_Server_Request_Interceptor::send_reply ( + PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + ++server_interceptor_check_; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::send_reply from \"%s\"\n", + op.in ())); + + if (ACE_OS::strcmp (op.in (), "normal") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i].argument >>= param; + ACE_DEBUG ((LM_DEBUG, + "The arg is %d\n", + param)); + } + + if (ACE_OS::strcmp (op.in (), "calculate") == 0) + { + Dynamic::ParameterList_var paramlist = + ri->arguments (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Long param1, param2, result = 0; + CORBA::ULong i = 0; // index -- explicitly used to avoid + // overloaded operator ambiguity. + paramlist[i++].argument >>= param1; + paramlist[i].argument >>= param2; + + CORBA::Any_var result_any = ri->result (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + (result_any.in ()) >>= result; + + ACE_DEBUG ((LM_DEBUG, + "The result of calculate is %d + %d = %d\n", + param1, + param2, + result)); + } +} + +void +Echo_Server_Request_Interceptor::send_exception ( + PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + ++server_interceptor_check_; + + CORBA::String_var op = ri->operation (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::send_exception " + "from \"%s\"\n", + op.in ())); + + + CORBA::Any_var any = + ri->sending_exception (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::TypeCode_var type = any->type (); + + const char *exception_id = type->id (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_DEBUG ((LM_DEBUG, + "Exception ID = %s\n", + exception_id)); +} + +void +Echo_Server_Request_Interceptor::send_other ( + PortableInterceptor::ServerRequestInfo_ptr + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)) +{ + ++server_interceptor_check_; + + // Do Nothing +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.h b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.h new file mode 100644 index 00000000000..244270d4a37 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/interceptors.h @@ -0,0 +1,139 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef TAO_INTERCEPTORS_H +#define TAO_INTERCEPTORS_H +#include /**/ "ace/pre.h" + +#include "tao/PI/PI.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PI_Server/PI_Server.h" +#include "tao/PortableInterceptorC.h" +#include "tao/LocalObject.h" + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4250) +#endif /* _MSC_VER */ + +class Echo_Client_Request_Interceptor + : public virtual PortableInterceptor::ClientRequestInterceptor, + public virtual TAO_Local_RefCounted_Object +{ + // = Client-side echo interceptor. For checking interceptor visually only. +public: + + Echo_Client_Request_Interceptor (void); + // ctor. + virtual ~Echo_Client_Request_Interceptor (); + // dtor. + + virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + // Canonical name of the interceptor. + + virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void send_poll ( + PortableInterceptor::ClientRequestInfo_ptr + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)); + + virtual void receive_other ( + PortableInterceptor::ClientRequestInfo_ptr + ACE_ENV_ARG_DECL_WITH_DEFAULTS + ) + ACE_THROW_SPEC (( + CORBA::SystemException, + PortableInterceptor::ForwardRequest + )); + + virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void receive_exception ( + PortableInterceptor::ClientRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)); + + // Some identifiers that are used for error checking + static CORBA::ULong client_interceptor_check_; +private: + const char *myname_; +}; + +class Echo_Server_Request_Interceptor + : public PortableInterceptor::ServerRequestInterceptor, + public virtual TAO_Local_RefCounted_Object +{ + // = Server-side echo interceptor. For checking interceptor visually only. +public: + Echo_Server_Request_Interceptor (void); + // cotr. + ~Echo_Server_Request_Interceptor (); + // dotr. + + virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + // Canonical name of the interceptor. + + virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void receive_request_service_contexts ( + PortableInterceptor::ServerRequestInfo_ptr + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC (( + CORBA::SystemException, + PortableInterceptor::ForwardRequest + )); + + virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)); + + virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException, + PortableInterceptor::ForwardRequest)); + + virtual void send_other ( + PortableInterceptor::ServerRequestInfo_ptr + ACE_ENV_ARG_DECL_WITH_DEFAULTS + ) + ACE_THROW_SPEC (( + CORBA::SystemException, + PortableInterceptor::ForwardRequest + )); + + // Some identifiers that are used for error checking + static CORBA::ULong server_interceptor_check_; + +private: + const char *myname_; +}; + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /* _MSC_VER */ + +#include /**/ "ace/post.h" +#endif /* TAO_INTERCEPTORS_H */ diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/run_test.pl b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/run_test.pl new file mode 100755 index 00000000000..011ef650c65 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/run_test.pl @@ -0,0 +1,42 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib '../../../../../bin'; +use PerlACE::Run_Test; + +$status = 0; +$file = PerlACE::LocalFile ("test.ior"); + +unlink $file; + +if (PerlACE::is_vxworks_test()) { + $SV = new PerlACE::ProcessVX ("Collocated_Test", "-ORBObjRefStyle url"); +} +else { + $SV = new PerlACE::Process ("Collocated_Test", "-ORBObjRefStyle url"); +} + +print STDERR "\n\n==== Running interceptor collocated Dynamic test\n"; + +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($file, 15) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $SV->Kill (); + exit 1; +} + +$collocated = $SV->WaitKill (5); + +if ($collocated != 0) { + print STDERR "ERROR: Collocated_Test returned $collocated\n"; + $status = 1; +} + +unlink $file; + +exit $status; diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test.idl b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test.idl new file mode 100644 index 00000000000..8671f9b0a97 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test.idl @@ -0,0 +1,42 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Portable_Interceptors +// +// = FILENAME +// test.idl +// +// = DESCRIPTION +// Simple IDL file to test portable interceptor support. +// +// = AUTHORS +// Nanbor Wang <nanbor@cs.wustl.edu> +// +// ============================================================================ + +module Test_Interceptors +{ + exception Silly + {}; + + interface Visual + { + /// Normal operation. + void normal (in long arg); + + /// Normal operation with a return val. + long calculate (in long one, in long two); + + /// throws a user exception. + void user () + raises (Silly); + + /// throws a system exception. + void system (); + + /// shutdown the ORB + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.cpp b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.cpp new file mode 100644 index 00000000000..949bea21eb6 --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.cpp @@ -0,0 +1,60 @@ +// $Id$ + +#include "test_i.h" +#include "ace/OS_NS_unistd.h" + +ACE_RCSID(Dynamic, test_i, "$Id$") + +Visual_i::Visual_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + // ctor + +void +Visual_i::normal (CORBA::Long + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // ACE_DEBUG ((LM_DEBUG, "Visual::normal called with %d\n", arg)); +} + +CORBA::Long +Visual_i::calculate (CORBA::Long one, + CORBA::Long two + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // ACE_DEBUG ((LM_DEBUG, "Visual::calculate\n")); + return (one + two); +} + +void +Visual_i::user (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException,Test_Interceptors::Silly)) +{ + // ACE_DEBUG ((LM_DEBUG, "Visual::user, throwning Silly\n")); + ACE_THROW (Test_Interceptors::Silly ()); +} + +void +Visual_i::system (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + // ACE_DEBUG ((LM_DEBUG, "Visual::user, throwing INV_OBJREF\n")); + ACE_THROW (CORBA::INV_OBJREF ()); +} + +void +Visual_i::shutdown (ACE_ENV_SINGLE_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + this->_remove_ref (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + // Give the client thread time to return from the collocated + // call to this method before shutting down the ORB. We sleep + // to avoid BAD_INV_ORDER exceptions on fast dual processor machines. + ACE_OS::sleep (1); + this->orb_->shutdown (); +} diff --git a/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.h b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.h new file mode 100644 index 00000000000..f31756fb10a --- /dev/null +++ b/TAO/tests/Portable_Interceptors/Collocated/Dynamic/test_i.h @@ -0,0 +1,54 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Portable_Interceptors/Dynamic +// +// = FILENAME +// test_i.h +// +// = AUTHOR +// Nanbor Wang +// +// ============================================================================ + +#ifndef TAO_INTERCEPTOR_TEST_I_H +#define TAO_INTERCEPTOR_TEST_I_H + +#include "testS.h" + +class Visual_i : public POA_Test_Interceptors::Visual +{ + // = DESCRIPTION + // Implements the Visual interface in test.idl + +public: + Visual_i (CORBA::ORB_ptr orb); + // ctor + + void normal (CORBA::Long arg + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + + CORBA::Long calculate ( + CORBA::Long one, + CORBA::Long two + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + + void user (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException,Test_Interceptors::Silly)); + + void system (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + + void shutdown (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + CORBA::ORB_var orb_; + // The ORB pointer (for shutdown.) +}; + +#endif /* TAO_INTERCEPTOR_TEST_I_H */ |