From 0bce1c2e97ede2b7adce08ecbfab0d46f6813827 Mon Sep 17 00:00:00 2001 From: nanbor Date: Sun, 29 Aug 1999 21:00:47 +0000 Subject: Added New Interceptor test. --- TAO/tests/Interceptors/Interceptors.dsw | 41 +++++++ TAO/tests/Interceptors/Makefile | 54 +++++++++ TAO/tests/Interceptors/README | 10 ++ TAO/tests/Interceptors/client.cpp | 119 +++++++++++++++++++ TAO/tests/Interceptors/client.dsp | 185 +++++++++++++++++++++++++++++ TAO/tests/Interceptors/interceptors.cpp | 182 +++++++++++++++++++++++++++++ TAO/tests/Interceptors/interceptors.h | 81 +++++++++++++ TAO/tests/Interceptors/run_test.pl | 47 ++++++++ TAO/tests/Interceptors/server.cpp | 114 ++++++++++++++++++ TAO/tests/Interceptors/server.dsp | 201 ++++++++++++++++++++++++++++++++ TAO/tests/Interceptors/test.idl | 48 ++++++++ TAO/tests/Interceptors/test_i.cpp | 46 ++++++++ TAO/tests/Interceptors/test_i.h | 50 ++++++++ 13 files changed, 1178 insertions(+) create mode 100644 TAO/tests/Interceptors/Interceptors.dsw create mode 100644 TAO/tests/Interceptors/Makefile create mode 100644 TAO/tests/Interceptors/README create mode 100644 TAO/tests/Interceptors/client.cpp create mode 100644 TAO/tests/Interceptors/client.dsp create mode 100644 TAO/tests/Interceptors/interceptors.cpp create mode 100644 TAO/tests/Interceptors/interceptors.h create mode 100755 TAO/tests/Interceptors/run_test.pl create mode 100644 TAO/tests/Interceptors/server.cpp create mode 100644 TAO/tests/Interceptors/server.dsp create mode 100644 TAO/tests/Interceptors/test.idl create mode 100644 TAO/tests/Interceptors/test_i.cpp create mode 100644 TAO/tests/Interceptors/test_i.h diff --git a/TAO/tests/Interceptors/Interceptors.dsw b/TAO/tests/Interceptors/Interceptors.dsw new file mode 100644 index 00000000000..3e035ae5da7 --- /dev/null +++ b/TAO/tests/Interceptors/Interceptors.dsw @@ -0,0 +1,41 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "Interceptors Client"=.\client.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Project: "Interceptors Server"=.\server.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/TAO/tests/Interceptors/Makefile b/TAO/tests/Interceptors/Makefile new file mode 100644 index 00000000000..1a1efae1c1b --- /dev/null +++ b/TAO/tests/Interceptors/Makefile @@ -0,0 +1,54 @@ +#---------------------------------------------------------------------------- +# +# $Id$ +# +#---------------------------------------------------------------------------- + +#---------------------------------------------------------------------------- +# Local macros +#---------------------------------------------------------------------------- + +ifndef TAO_ROOT + TAO_ROOT = $(ACE_ROOT)/TAO +endif # ! TAO_ROOT + +LDLIBS = -lTAO + +IDLFILES = testC testS +BIN = client server + +SRC = $(addsuffix .cpp, $(BIN) $(IDLFILES) test_i) + +CLIENT_OBJS = client.o testC.o interceptors.o +SERVER_OBJS = server.o test_i.o testC.o testS.o interceptors.o + +TAO_IDLFLAGS += -Ge 1 +#---------------------------------------------------------------------------- +# 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), test$(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), test$(ext)) + +# DO NOT DELETE THIS LINE -- g++dep uses it. +# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY. diff --git a/TAO/tests/Interceptors/README b/TAO/tests/Interceptors/README new file mode 100644 index 00000000000..06b8ef50cf9 --- /dev/null +++ b/TAO/tests/Interceptors/README @@ -0,0 +1,10 @@ +# $Id$ + += server, client + +This test allows you to visually check the correct invocation of +TAO's pseudo-portable interceptors. To run the test, try: + + server -o test.ior + + client diff --git a/TAO/tests/Interceptors/client.cpp b/TAO/tests/Interceptors/client.cpp new file mode 100644 index 00000000000..da4adbb15f2 --- /dev/null +++ b/TAO/tests/Interceptors/client.cpp @@ -0,0 +1,119 @@ +// $Id$ + +#include "ace/Get_Opt.h" +#include "testC.h" +#include "interceptors.h" + +ACE_RCSID(Interceptors, client, "$Id$") + +const char *ior = "file://test.ior"; +POA_PortableInterceptor::ClientRequestInterceptor *interceptor_impl = 0; +PortableInterceptor::ClientRequestInterceptor_ptr interceptor = 0; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "e"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'e': + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-v " + "\n", + argv [0]), + -1); + } + return 0; +} + +void +run_test (Test_Interceptors::Visual_ptr server, + CORBA::Environment &ACE_TRY_ENV) +{ + server->normal (10, ACE_TRY_ENV); + ACE_CHECK; + + server->nothing (ACE_TRY_ENV); + ACE_CHECK; + + ACE_TRY + { + server->user (ACE_TRY_ENV); + 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_TRY_ENV); + ACE_TRY_CHECK_EX (SYS); + } + ACE_CATCH (CORBA::INV_OBJREF, sysex) + { + ACE_DEBUG ((LM_DEBUG, "Caught Inv_Objref\n")); + } + ACE_ENDTRY; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "", ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return 1; + + // Installing the Echo interceptor + ACE_NEW_RETURN (interceptor_impl, + Echo_Client_Request_Interceptor, + -1); + interceptor = interceptor_impl->_this (); + orb->_register_client_interceptor (interceptor); + + CORBA::Object_var object = + orb->string_to_object (ior, ACE_TRY_ENV); + ACE_TRY_CHECK; + + Test_Interceptors::Visual_var server = + Test_Interceptors::Visual::_narrow (object.in (), ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (CORBA::is_nil (server.in ())) + { + ACE_ERROR_RETURN ((LM_ERROR, + "Object reference <%s> is nil\n", + ior), + 1); + } + + run_test (server.in (), ACE_TRY_ENV); + + server->shutdown (ACE_TRY_ENV); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Catched exception:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Interceptors/client.dsp b/TAO/tests/Interceptors/client.dsp new file mode 100644 index 00000000000..64af13e94b1 --- /dev/null +++ b/TAO/tests/Interceptors/client.dsp @@ -0,0 +1,185 @@ +# Microsoft Developer Studio Project File - Name="Interceptors Client" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Interceptors Client - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "client.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "client.mak" CFG="Interceptors Client - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Interceptors Client - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Interceptors Client - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Interceptors Client - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "client___Win32_Release" +# PROP BASE Intermediate_Dir "client___Win32_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 ace.lib tao.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\tao" /libpath:"..\..\..\ace" + +!ELSEIF "$(CFG)" == "Interceptors Client - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "client___Win32_Debug" +# PROP BASE Intermediate_Dir "client___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\.." /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 aced.lib TAOd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\tao" /libpath:"..\..\..\ace" + +!ENDIF + +# Begin Target + +# Name "Interceptors Client - Win32 Release" +# Name "Interceptors Client - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\client.cpp +# End Source File +# Begin Source File + +SOURCE=.\interceptors.cpp +# End Source File +# Begin Source File + +SOURCE=.\testC.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\interceptors.h +# End Source File +# Begin Source File + +SOURCE=.\testC.h +# End Source File +# End Group +# Begin Group "IDL Files" + +# PROP Default_Filter "" +# Begin Source File + +SOURCE=.\test.idl + +!IF "$(CFG)" == "Interceptors Client - Win32 Release" + +USERDEP__TEST_="..\..\..\bin\Release\tao_idl.exe" +# Begin Custom Build - Invoking TAO's IDL Compiler on $(InputPath) +InputPath=.\test.idl +InputName=test + +BuildCmds= \ + ..\..\..\bin\Release\tao_idl -Ge 1 $(InputName).idl + +"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ELSEIF "$(CFG)" == "Interceptors Client - Win32 Debug" + +USERDEP__TEST_="..\..\..\bin\tao_idl.exe" +# Begin Custom Build - Invoking TAO's IDL Compiler on $(InputPath) +InputPath=.\test.idl +InputName=test + +BuildCmds= \ + ..\..\..\bin\tao_idl -Ge 1 $(InputName).idl + +"$(InputName)C.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)C.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)C.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ENDIF + +# End Source File +# End Group +# End Target +# End Project diff --git a/TAO/tests/Interceptors/interceptors.cpp b/TAO/tests/Interceptors/interceptors.cpp new file mode 100644 index 00000000000..7ceed998fb8 --- /dev/null +++ b/TAO/tests/Interceptors/interceptors.cpp @@ -0,0 +1,182 @@ +// $Id$ + +#include "interceptors.h" + +ACE_RCSID(Interceptors, interceptors, "$Id$") + +const CORBA::ULong request_ctx_id = 0xdead; +const CORBA::ULong reply_ctx_id = 0xbeef; +const char *request_msg = "The Echo_Request_Interceptor request message"; +const char *reply_msg = "The Echo_Request_Interceptor reply message"; + +Echo_Client_Request_Interceptor::Echo_Client_Request_Interceptor (void) + : myname_ ("Echo_Client_Interceptor") +{ +} + +char * +Echo_Client_Request_Interceptor::name (CORBA::Environment &) +{ + return CORBA::string_dup (this->myname_); +} + +void +Echo_Client_Request_Interceptor::preinvoke (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char *op, + IOP::ServiceContextList &sc, + CORBA::NVList_ptr &, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::preinvoke from \"%s\" request_id: %l\n", + op, + rid)); + +#if defined (TEST_SERVICECONTEXT) + CORBA::ULong length = sc.length (); + sc.length (length + 1); + + sc[length].context_id = request_ctx_id; + + CORBA::ULong string_len = ACE_OS::strlen (request_msg) + 1; + CORBA::Octet *buf = 0; + ACE_NEW (buf, + CORBA::Octet [string_len]); + + sc[length].context_data.replace (string_len, string_len, buf, 1); +#else + ACE_UNUSED_ARG (sc); +#endif /* TEST_SERVICECONTEXT */ +} + +void +Echo_Client_Request_Interceptor::postinvoke (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char * op, + IOP::ServiceContextList &sc, + CORBA::NVList_ptr &, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::postinvoke from \"%s\" request_id: %l\n", + op, + rid)); + +#if defined (TEST_SERVICECONTEXT) + for (CORBA::ULong size = 0; size < sc.length (); ++size) + if (sc[size].context_id == request_ctx_id) + { + const char *buf = ACE_static_cast (const char *, sc[size].context_data.get_buffer ()); + ACE_DEBUG ((LM_DEBUG, + " Received service context: %s\n", + buf)); + } +#else + ACE_UNUSED_ARG (sc); +#endif /* TEST_SERVICECONTEXT */ +} + +void +Echo_Client_Request_Interceptor::exception_occurred (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char * op, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Client_Request_Interceptor::exception_occurred from \"%s\" request_id: %l\n", + op, + rid)); +} + +Echo_Server_Request_Interceptor::Echo_Server_Request_Interceptor (void) + : myname_ ("Echo_Server_Interceptor") +{ +} + +char * +Echo_Server_Request_Interceptor::name (CORBA::Environment &) +{ + return CORBA::string_dup (this->myname_); +} + +void +Echo_Server_Request_Interceptor::preinvoke (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char *op, + IOP::ServiceContextList &sc, + CORBA::NVList_ptr &, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::preinvoke from \"%s\" request_id: %l\n", + op, + rid)); + +#if defined (TEST_SERVICECONTEXT) + for (CORBA::ULong size = 0; size < sc.length (); ++size) + if (sc[size].context_id == request_ctx_id) + { + const char *buf = ACE_static_cast (const char *, sc[size].context_data.get_buffer ()); + ACE_DEBUG ((LM_DEBUG, + " Received service context: %s\n", + buf)); + } +#else + ACE_UNUSED_ARG (sc); +#endif /* TEST_SERVICECONTEXT */ +} + +void +Echo_Server_Request_Interceptor::postinvoke (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char * op, + IOP::ServiceContextList &sc, + CORBA::NVList_ptr &, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::postinvoke from \"%s\" request_id: %l\n", + op, + rid)); + +#if defined (TEST_SERVICECONTEXT) + CORBA::ULong length = sc.length (); + sc.length (length + 1); + + sc[length].context_id = reply_ctx_id; + + CORBA::ULong string_len = ACE_OS::strlen (reply_msg) + 1; + CORBA::Octet *buf = 0; + ACE_NEW (buf, + CORBA::Octet [string_len]); + + sc[length].context_data.replace (string_len, string_len, buf, 1); +#else + ACE_UNUSED_ARG (sc); +#endif /* TEST_SERVICECONTEXT */ +} + +void +Echo_Server_Request_Interceptor::exception_occurred (CORBA::ULong rid, + CORBA::Boolean, + CORBA::Object_ptr, + const char * op, + PortableInterceptor::Cookies &, + CORBA::Environment &) +{ + ACE_DEBUG ((LM_DEBUG, + "Echo_Server_Request_Interceptor::exception_occurred from \"%s\" request_id: %l\n", + op, + rid)); +} diff --git a/TAO/tests/Interceptors/interceptors.h b/TAO/tests/Interceptors/interceptors.h new file mode 100644 index 00000000000..e86bbf358d3 --- /dev/null +++ b/TAO/tests/Interceptors/interceptors.h @@ -0,0 +1,81 @@ +// $Id$ + +#include "tao/Interceptor.h" + +class Echo_Client_Request_Interceptor : public POA_PortableInterceptor::ClientRequestInterceptor +{ + // = Client-side echo interceptor. For checking interceptor visually only. +public: + Echo_Client_Request_Interceptor (void); + // ctor. + + virtual char * name (CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + // Canonical name of the interceptor. + + virtual void preinvoke (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + IOP::ServiceContextList & sc, + CORBA::NVList_ptr &args, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + + virtual void postinvoke (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + IOP::ServiceContextList & sc, + CORBA::NVList_ptr &args, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + + virtual void exception_occurred (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + +private: + const char *myname_; +}; + +class Echo_Server_Request_Interceptor : public POA_PortableInterceptor::ServerRequestInterceptor +{ + // = Server-side echo interceptor. For checking interceptor visually only. +public: + Echo_Server_Request_Interceptor (void); + // cotr. + + virtual char * name (CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + // Canonical name of the interceptor. + + virtual void preinvoke (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + IOP::ServiceContextList & sc, + CORBA::NVList_ptr &args, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + + virtual void postinvoke (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + IOP::ServiceContextList & sc, + CORBA::NVList_ptr &args, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + + virtual void exception_occurred (CORBA::ULong request_id, + CORBA::Boolean response_expected, + CORBA::Object_ptr objref, + const char * operation_name, + PortableInterceptor::Cookies & ck, + CORBA::Environment &ACE_TRY_ENV = TAO_default_environment ()); + +private: + const char *myname_; +}; diff --git a/TAO/tests/Interceptors/run_test.pl b/TAO/tests/Interceptors/run_test.pl new file mode 100755 index 00000000000..044270ff454 --- /dev/null +++ b/TAO/tests/Interceptors/run_test.pl @@ -0,0 +1,47 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +unshift @INC, '../../../bin'; +require Process; +require ACEutils; + +print STDERR "\n\n==== Octet sequence passing test\n"; + +$file="test.ior"; + +unlink $file; + +$SV = Process::Create ($EXEPREFIX."server".$EXE_EXT, + "-o $file"); +if (ACE::waitforfile_timed ($file, 15) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $SV->Kill (); $SV->TimedWait (1); + exit 1; +} + +$CL = Process::Create ($EXEPREFIX."client".$EXE_EXT, ""); + + +$client = $CL->TimedWait (60); +if ($client == -1) { + print STDERR "ERROR: client timedout\n"; + $CL->Kill (); $CL->TimedWait (1); +} + +$server = $SV->TimedWait (5); +if ($server == -1) { + print STDERR "ERROR: server timedout\n"; + $SV->Kill (); $SV->TimedWait (1); +} + +if ($client == -1 || $server == -1) { + exit 1; +} + +unlink $file; + +exit 0; diff --git a/TAO/tests/Interceptors/server.cpp b/TAO/tests/Interceptors/server.cpp new file mode 100644 index 00000000000..a4ce777e994 --- /dev/null +++ b/TAO/tests/Interceptors/server.cpp @@ -0,0 +1,114 @@ +// $Id$ + +#include "ace/Get_Opt.h" +#include "test_i.h" +#include "interceptors.h" + +ACE_RCSID(Interceptors, server, "$Id$") + +const char *ior_output_file = 0; +POA_PortableInterceptor::ServerRequestInterceptor *interceptor_impl = 0; +PortableInterceptor::ServerRequestInterceptor_ptr interceptor = 0; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "o:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.optarg; + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o " + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_TRY_NEW_ENV + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "", ACE_TRY_ENV); + ACE_TRY_CHECK; + + // Installing the Echo interceptor + ACE_NEW_RETURN (interceptor_impl, + Echo_Server_Request_Interceptor, + -1); + interceptor = interceptor_impl->_this (); + orb->_register_server_interceptor (interceptor); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + 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_TRY_ENV); + ACE_TRY_CHECK; + + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return 1; + + Visual_i server_impl (orb.in ()); + + + Test_Interceptors::Visual_var server = + server_impl._this (ACE_TRY_ENV); + ACE_TRY_CHECK; + + CORBA::String_var ior = + orb->object_to_string (server.in (), ACE_TRY_ENV); + 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 (ior_output_file != 0) + { + FILE *output_file= ACE_OS::fopen (ior_output_file, "w"); + if (output_file == 0) + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + } + + poa_manager->activate (ACE_TRY_ENV); + ACE_TRY_CHECK; + + if (orb->run () == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "orb->run"), -1); + ACE_DEBUG ((LM_DEBUG, "event loop finished\n")); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "Catched exception:"); + return 1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/tests/Interceptors/server.dsp b/TAO/tests/Interceptors/server.dsp new file mode 100644 index 00000000000..e527bffdebb --- /dev/null +++ b/TAO/tests/Interceptors/server.dsp @@ -0,0 +1,201 @@ +# Microsoft Developer Studio Project File - Name="Interceptors Server" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=Interceptors Server - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "server.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "server.mak" CFG="Interceptors Server - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "Interceptors Server - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "Interceptors Server - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "Interceptors Server - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "server___Win32_Release" +# PROP BASE Intermediate_Dir "server___Win32_Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MD /W3 /GX /O2 /I "..\.." /I "..\..\.." /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 +# ADD LINK32 ace.lib tao.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\tao" /libpath:"..\..\..\ace" + +!ELSEIF "$(CFG)" == "Interceptors Server - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "server___Win32_Debug" +# PROP BASE Intermediate_Dir "server___Win32_Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "" +# PROP Intermediate_Dir "Debug" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD CPP /nologo /MDd /W3 /Gm /GX /Zi /Od /I "..\.." /I "..\..\.." /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 aced.lib TAOd.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\tao" /libpath:"..\..\..\ace" + +!ENDIF + +# Begin Target + +# Name "Interceptors Server - Win32 Release" +# Name "Interceptors Server - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=.\interceptors.cpp +# End Source File +# Begin Source File + +SOURCE=.\server.cpp +# End Source File +# Begin Source File + +SOURCE=.\test_i.cpp +# End Source File +# Begin Source File + +SOURCE=.\testC.cpp +# End Source File +# Begin Source File + +SOURCE=.\testS.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# Begin Source File + +SOURCE=.\interceptors.h +# End Source File +# Begin Source File + +SOURCE=.\test_i.h +# End Source File +# Begin Source File + +SOURCE=.\testC.h +# End Source File +# Begin Source File + +SOURCE=.\testS.h +# End Source File +# End Group +# Begin Group "IDL Files" + +# PROP Default_Filter "idl" +# Begin Source File + +SOURCE=.\test.idl + +!IF "$(CFG)" == "Interceptors Server - Win32 Release" + +USERDEP__TEST_="..\..\..\bin\Release\tao_idl.exe" +# Begin Custom Build - Invoking TAO's IDL Compiler on $(InputPath) +InputPath=.\test.idl +InputName=test + +BuildCmds= \ + ..\..\..\bin\Release\tao_idl -Ge 1 $(InputName).idl + +"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ELSEIF "$(CFG)" == "Interceptors Server - Win32 Debug" + +USERDEP__TEST_="..\..\..\bin\tao_idl.exe" +# Begin Custom Build - Invoking TAO's IDL Compiler on $(InputPath) +InputPath=.\test.idl +InputName=test + +BuildCmds= \ + ..\..\..\bin\tao_idl -Ge 1 $(InputName).idl + +"$(InputName)C.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)C.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)C.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.i" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) + +"$(InputName)S_T.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" + $(BuildCmds) +# End Custom Build + +!ENDIF + +# End Source File +# End Group +# End Target +# End Project diff --git a/TAO/tests/Interceptors/test.idl b/TAO/tests/Interceptors/test.idl new file mode 100644 index 00000000000..9a89e6f698b --- /dev/null +++ b/TAO/tests/Interceptors/test.idl @@ -0,0 +1,48 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Interceptors +// +// = FILENAME +// test.idl +// +// = DESCRIPTION +// Simple IDL file to test portable interceptor support. +// +// = AUTHORS +// Nanbor Wang +// +// ============================================================================ + +module Test_Interceptors +{ + exception Silly + {}; + + interface Visual + { + // = TITLE + // A test idl for checking interceptor visually. + // + // = DESCRIPTION + // + + void normal (in long arg); + // Normal operation. + + void nothing (); + // Normal operation without return. + + void user () + raises (Silly); + // throws a user exception. + + void system (); + // thows a system exception. + + oneway void shutdown (); + // shutdown the ORB + }; +}; diff --git a/TAO/tests/Interceptors/test_i.cpp b/TAO/tests/Interceptors/test_i.cpp new file mode 100644 index 00000000000..4bf1fcc368e --- /dev/null +++ b/TAO/tests/Interceptors/test_i.cpp @@ -0,0 +1,46 @@ +// $Id$ + +#include "test_i.h" + +ACE_RCSID(Interceptors, test_i, "$Id$"); + +Visual_i::Visual_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + // ctor + +void +Visual_i::normal (CORBA::Long arg, + CORBA::Environment&) +{ + ACE_DEBUG ((LM_DEBUG, "Visual::normal called with %d\n", arg)); +} + +void +Visual_i::nothing (CORBA::Environment&) +{ + ACE_DEBUG ((LM_DEBUG, "Visual::nothing\n")); +} + +void +Visual_i::user (CORBA::Environment &ACE_TRY_ENV) + 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 (CORBA::Environment &ACE_TRY_ENV) +{ + ACE_DEBUG ((LM_DEBUG, "Visual::user, throwning INV_OBJREF\n")); + ACE_THROW (CORBA::INV_OBJREF ()); +} + +void +Visual_i::shutdown (CORBA::Environment&) + ACE_THROW_SPEC (()) +{ + this->orb_->shutdown (); +} diff --git a/TAO/tests/Interceptors/test_i.h b/TAO/tests/Interceptors/test_i.h new file mode 100644 index 00000000000..75d2283834f --- /dev/null +++ b/TAO/tests/Interceptors/test_i.h @@ -0,0 +1,50 @@ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// TAO/tests/Interceptors +// +// = 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, + CORBA::Environment&); + + void nothing (CORBA::Environment&); + + void user (CORBA::Environment&) + ACE_THROW_SPEC ((CORBA::SystemException,Test_Interceptors::Silly)); + + void system (CORBA::Environment&); + + void shutdown (CORBA::Environment&) + ACE_THROW_SPEC (()); + +private: + CORBA::ORB_var orb_; + // The ORB pointer (for shutdown.) +}; + +#endif /* TAO_INTERCEPTOR_TEST_I_H */ -- cgit v1.2.1