From 5189cf3ed14f846fe3b4338e8b5111b3bb6115a1 Mon Sep 17 00:00:00 2001 From: irfan Date: Fri, 23 Jan 1998 10:08:02 +0000 Subject: *** empty log message *** --- TAO/tao/poa.cpp | 28 ++-- TAO/tao/poaC.cpp | 2 +- TAO/tao/poaC.h | 2 +- TAO/tao/poaS.cpp | 4 +- TAO/tao/poaS.h | 10 +- .../POA/On_Demand_Activation/Servant_Locator.cpp | 43 +++++ .../POA/On_Demand_Activation/Servant_Locator.h | 24 +++ TAO/tests/POA/On_Demand_Activation/server.cpp | 186 +++++++++++++++++++++ TAO/tests/POA/On_Demand_Activation/server.dsp | 99 +++++++++++ TAO/tests/POA/On_Demand_Activation/svc.conf | 49 ++++++ 10 files changed, 422 insertions(+), 25 deletions(-) create mode 100644 TAO/tests/POA/On_Demand_Activation/Servant_Locator.cpp create mode 100644 TAO/tests/POA/On_Demand_Activation/Servant_Locator.h create mode 100644 TAO/tests/POA/On_Demand_Activation/server.cpp create mode 100644 TAO/tests/POA/On_Demand_Activation/server.dsp create mode 100644 TAO/tests/POA/On_Demand_Activation/svc.conf diff --git a/TAO/tao/poa.cpp b/TAO/tao/poa.cpp index 57015f5f4d1..055fd031681 100644 --- a/TAO/tao/poa.cpp +++ b/TAO/tao/poa.cpp @@ -1916,13 +1916,9 @@ TAO_POA::locate_servant_i (const TAO::ObjectKey &key, // return 0. if (poa->policies ().servant_retention () == PortableServer::RETAIN) { - PortableServer::Servant servant = poa->id_to_servant_i (id.in (), env); - - if (env.exception () != 0) - return -1; - - // Success - if (servant != 0) + PortableServer::Servant servant = 0; + if (poa->active_object_map ().find (id.in (), servant) != -1) + // Success return 0; } @@ -1977,23 +1973,15 @@ TAO_POA::locate_poa_and_servant_i (const TAO::ObjectKey &key, if (env.exception () != 0) return 0; - PortableServer::POA_var poa = poa_impl->_this (env); - if (env.exception () != 0) - return 0; - // If the POA has the RETAIN policy, the POA looks in the Active // Object Map to find if there is a servant associated with the // Object Id value from the request. If such a servant exists, the // POA invokes the appropriate method on the servant. if (poa_impl->policies ().servant_retention () == PortableServer::RETAIN) { - PortableServer::Servant servant = poa_impl->id_to_servant_i (*id.ptr (), env); - - if (env.exception () != 0) - return 0; - - // Success - if (servant != 0) + PortableServer::Servant servant = 0; + if (poa_impl->active_object_map ().find (*id.ptr (), servant) != -1) + // Success return servant; } @@ -2058,6 +2046,10 @@ TAO_POA::locate_poa_and_servant_i (const TAO::ObjectKey &key, return 0; } + PortableServer::POA_var poa = poa_impl->_this (env); + if (env.exception () != 0) + return 0; + if (poa_impl->policies ().servant_retention () == PortableServer::RETAIN) { // @@ diff --git a/TAO/tao/poaC.cpp b/TAO/tao/poaC.cpp index bee32caef92..0613457001f 100644 --- a/TAO/tao/poaC.cpp +++ b/TAO/tao/poaC.cpp @@ -1659,7 +1659,7 @@ PortableServer::ServantLocator_ptr PortableServer::ServantLocator::_bind (const return PortableServer::ServantLocator::_narrow (objref, env); } -PortableServer::Servant PortableServer::ServantLocator::preinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr adapter, const char *operation, PortableServer::ServantLocator::Cookie the_cookie, CORBA::Environment &env) +PortableServer::Servant PortableServer::ServantLocator::preinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr adapter, const char *operation, PortableServer::ServantLocator::Cookie & the_cookie, CORBA::Environment &env) { env.exception (new CORBA::MARSHAL (CORBA::COMPLETED_NO)); return 0; diff --git a/TAO/tao/poaC.h b/TAO/tao/poaC.h index b6946166d36..9a2457fc919 100644 --- a/TAO/tao/poaC.h +++ b/TAO/tao/poaC.h @@ -1741,7 +1741,7 @@ class ServantLocator; static ServantLocator_ptr _nil (void); static ServantLocator_ptr _bind (const char *host, CORBA::UShort port, const char *key, CORBA::Environment &env); - virtual Servant preinvoke (const ObjectId &oid, POA_ptr adapter, const char *operation, Cookie the_cookie, CORBA::Environment &env); + virtual Servant preinvoke (const ObjectId &oid, POA_ptr adapter, const char *operation, Cookie & the_cookie, CORBA::Environment &env); virtual void postinvoke (const ObjectId &oid, POA_ptr adapter, const char *operation, Cookie the_cookie, Servant the_servant, CORBA::Environment &env); virtual CORBA::Boolean _is_a (const CORBA::Char *type_id, CORBA::Environment &env); protected: diff --git a/TAO/tao/poaS.cpp b/TAO/tao/poaS.cpp index e65b3070b19..07c5abec71a 100644 --- a/TAO/tao/poaS.cpp +++ b/TAO/tao/poaS.cpp @@ -2083,7 +2083,7 @@ CORBA::Boolean POA_PortableServer::_tao_collocated_ServantLocator::_is_a ( PortableServer::Servant POA_PortableServer::_tao_collocated_ServantLocator::preinvoke ( const PortableServer::ObjectId & oid, PortableServer::POA_ptr adapter, - const PortableServer::Identifier operation, + const char * operation, PortableServer::ServantLocator::Cookie & the_cookie, CORBA::Environment &_tao_environment ) @@ -2100,7 +2100,7 @@ PortableServer::Servant POA_PortableServer::_tao_collocated_ServantLocator::prei void POA_PortableServer::_tao_collocated_ServantLocator::postinvoke ( const PortableServer::ObjectId & oid, PortableServer::POA_ptr adapter, - const PortableServer::Identifier operation, + const char * operation, PortableServer::ServantLocator::Cookie the_cookie, PortableServer::Servant the_servant, CORBA::Environment &_tao_environment diff --git a/TAO/tao/poaS.h b/TAO/tao/poaS.h index 1fd1ad2a680..df00ea827e5 100644 --- a/TAO/tao/poaS.h +++ b/TAO/tao/poaS.h @@ -783,7 +783,11 @@ public: virtual void* _downcast ( const char* logical_type_id ); - virtual PortableServer::Servant preinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr adapter, const char *operation, PortableServer::ServantLocator::Cookie the_cookie, CORBA::Environment &env) = 0; // pure virtual + virtual PortableServer::Servant preinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + const char *operation, + PortableServer::ServantLocator::Cookie & the_cookie, + CORBA::Environment &env) = 0; // pure virtual static void preinvoke_skel (CORBA::ServerRequest &req, void *obj, void *context, CORBA::Environment &env); virtual void postinvoke (const PortableServer::ObjectId &oid, PortableServer::POA_ptr adapter, const char *operation, PortableServer::ServantLocator::Cookie the_cookie, PortableServer::Servant the_servant, CORBA::Environment &env) = 0; // pure virtual @@ -817,14 +821,14 @@ public: virtual PortableServer::Servant preinvoke ( const PortableServer::ObjectId & oid, PortableServer::POA_ptr adapter, - const PortableServer::Identifier operation, + const char * operation, PortableServer::ServantLocator::Cookie & the_cookie, CORBA::Environment &_tao_environment ); virtual void postinvoke ( const PortableServer::ObjectId & oid, PortableServer::POA_ptr adapter, - const PortableServer::Identifier operation, + const char * operation, PortableServer::ServantLocator::Cookie the_cookie, PortableServer::Servant the_servant, CORBA::Environment &_tao_environment diff --git a/TAO/tests/POA/On_Demand_Activation/Servant_Locator.cpp b/TAO/tests/POA/On_Demand_Activation/Servant_Locator.cpp new file mode 100644 index 00000000000..6b5df82f885 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Activation/Servant_Locator.cpp @@ -0,0 +1,43 @@ +#include "Servant_Locator.h" +#include "MyFooServant.h" + +MyFooServantLocator::MyFooServantLocator (void) + : counter_ (0) +{ +} + + +PortableServer::Servant +MyFooServantLocator::preinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa, + const char *operation, + PortableServer::ServantLocator::Cookie &cookie, + CORBA::Environment &env) +{ + CORBA::String_var s = PortableServer::ObjectId_to_string (oid); + if (ACE_OS::strstr (s.in (), "Foo") != 0) + { + PortableServer::Servant servant = new MyFooServant (poa, ++this->counter_); + cookie = servant; + return servant; + } + else + { + CORBA::Exception *exception = new CORBA::OBJECT_NOT_EXIST (CORBA::COMPLETED_NO); + env.exception (exception); + return 0; + } +} + +void +MyFooServantLocator::postinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa, + const char *operation, + PortableServer::ServantLocator::Cookie cookie, + PortableServer::Servant servant, + CORBA::Environment &env) +{ + PortableServer::Servant my_servant = (PortableServer::Servant) cookie; + ACE_ASSERT (servant == my_servant); + delete servant; +} diff --git a/TAO/tests/POA/On_Demand_Activation/Servant_Locator.h b/TAO/tests/POA/On_Demand_Activation/Servant_Locator.h new file mode 100644 index 00000000000..6abfb278eb5 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Activation/Servant_Locator.h @@ -0,0 +1,24 @@ +#include "tao/corba.h" + +class MyFooServantLocator : public POA_PortableServer::ServantLocator +{ +public: + MyFooServantLocator (void); + + virtual PortableServer::Servant preinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + const char *operation, + PortableServer::ServantLocator::Cookie &the_cookie, + CORBA::Environment &env); + + virtual void postinvoke (const PortableServer::ObjectId &oid, + PortableServer::POA_ptr adapter, + const char *operation, + PortableServer::ServantLocator::Cookie the_cookie, + PortableServer::Servant the_servant, + CORBA::Environment &env); +private: + + int counter_; +}; + diff --git a/TAO/tests/POA/On_Demand_Activation/server.cpp b/TAO/tests/POA/On_Demand_Activation/server.cpp new file mode 100644 index 00000000000..a167064d1a2 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Activation/server.cpp @@ -0,0 +1,186 @@ +#include "ace/streams.h" +#include "Servant_Activator.h" +#include "Servant_Locator.h" + +int +main (int argc, char **argv) +{ + CORBA::Environment env; + + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, 0, env); + if (env.exception () != 0) + { + env.print_exception ("CORBA::ORB_init"); + return -1; + } + + CORBA::Object_var obj = orb->resolve_initial_references ("RootPOA"); + + PortableServer::POA_var root_poa = PortableServer::POA::_narrow (obj, env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::_narrow"); + return -1; + } + + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::the_POAManager"); + return -1; + } + + PortableServer::POA_var first_poa; + { + // CORBA::PolicyList policies (4); + PortableServer::PolicyList policies (4); + policies.length (4); + policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID, env); + policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT, env); + policies[2] = root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER, env); + policies[3] = root_poa->create_servant_retention_policy (PortableServer::RETAIN, env); + + ACE_CString name = "firstPOA"; + first_poa = root_poa->create_POA (name.c_str (), + poa_manager.in (), + policies, + env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_POA"); + return -1; + } + + for (CORBA::ULong i = 0; + i < policies.length () && env.exception () == 0; + ++i) + { + PortableServer::Policy_ptr policy = policies[i]; + policy->destroy (env); + } + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_POA"); + return -1; + } + } + + PortableServer::POA_var second_poa; + { + // CORBA::PolicyList policies (4); + PortableServer::PolicyList policies (4); + policies.length (4); + policies[0] = root_poa->create_id_assignment_policy (PortableServer::USER_ID, env); + policies[1] = root_poa->create_lifespan_policy (PortableServer::PERSISTENT, env); + policies[2] = root_poa->create_request_processing_policy (PortableServer::USE_SERVANT_MANAGER, env); + policies[3] = root_poa->create_servant_retention_policy (PortableServer::NON_RETAIN, env); + + ACE_CString name = "secondPOA"; + second_poa = root_poa->create_POA (name.c_str (), + poa_manager.in (), + policies, + env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_POA"); + return -1; + } + + for (CORBA::ULong i = 0; + i < policies.length () && env.exception () == 0; + ++i) + { + PortableServer::Policy_ptr policy = policies[i]; + policy->destroy (env); + } + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_POA"); + return -1; + } + } + + MyFooServantActivator servant_activator_impl; + PortableServer::ServantActivator_var servant_activator = servant_activator_impl._this (env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POAManager::_this"); + return -1; + } + + first_poa->set_servant_manager (servant_activator.in (), env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POAManager::set_servant_manager"); + return -1; + } + + PortableServer::ObjectId_var first_foo_oid = PortableServer::string_to_ObjectId ("firstFoo"); + CORBA::Object_var first_foo = first_poa->create_reference_with_id (first_foo_oid.in (), "IDL:Foo:1.0", env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_reference_with_id"); + return -1; + } + + MyFooServantLocator servant_locator_impl; + PortableServer::ServantLocator_var servant_locator = servant_locator_impl._this (env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POAManager::_this"); + return -1; + } + + second_poa->set_servant_manager (servant_locator.in (), env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POAManager::set_servant_manager"); + return -1; + } + + PortableServer::ObjectId_var second_foo_oid = PortableServer::string_to_ObjectId ("secondFoo"); + CORBA::Object_var second_foo = second_poa->create_reference_with_id (second_foo_oid.in (), "IDL:Foo:1.0", env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::create_reference_with_id"); + return -1; + } + + CORBA::String_var first_foo_ior = orb->object_to_string (first_foo, env); + if (env.exception () != 0) + { + env.print_exception ("CORBA::ORB::object_to_string"); + return -1; + } + + CORBA::String_var second_foo_ior = orb->object_to_string (second_foo, env); + if (env.exception () != 0) + { + env.print_exception ("CORBA::ORB::object_to_string"); + return -1; + } + + cout << first_foo_ior.in () << endl; + cout << second_foo_ior.in () << endl; + + poa_manager->activate (env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POAManager::activate"); + return -1; + } + + if (orb->run () == -1) + ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "CORBA::ORB::run"), -1); + + root_poa->destroy (CORBA::B_TRUE, + CORBA::B_TRUE, + env); + if (env.exception () != 0) + { + env.print_exception ("PortableServer::POA::destroy"); + return -1; + } + + return 0; +} diff --git a/TAO/tests/POA/On_Demand_Activation/server.dsp b/TAO/tests/POA/On_Demand_Activation/server.dsp new file mode 100644 index 00000000000..2d22f5a98a9 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Activation/server.dsp @@ -0,0 +1,99 @@ +# Microsoft Developer Studio Project File - Name="server" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 5.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Console Application" 0x0103 + +CFG=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="server - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "server - Win32 Release" (based on "Win32 (x86) Console Application") +!MESSAGE "server - Win32 Debug" (based on "Win32 (x86) Console Application") +!MESSAGE + +# Begin Project +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +RSC=rc.exe + +!IF "$(CFG)" == "server - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# 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 "..\..\..\.." /I "..\Generic_Servant\\" /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 /nologo /subsystem:console /machine:I386 +# ADD LINK32 tao.lib ace.lib ..\Generic_Servant\server.lib /nologo /subsystem:console /machine:I386 /libpath:"..\..\..\tao" /libpath:"..\..\..\..\ace" +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "server - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "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 "..\..\..\.." /I "..\Generic_Servant\\" /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 /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept +# ADD LINK32 tao.lib aced.lib ..\Generic_Servant\server.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"..\..\..\tao" /libpath:"..\..\..\..\ace" +# SUBTRACT LINK32 /pdb:none + +!ENDIF + +# Begin Target + +# Name "server - Win32 Release" +# Name "server - Win32 Debug" +# Begin Source File + +SOURCE=.\Servant_Activator.cpp +# End Source File +# Begin Source File + +SOURCE=.\Servant_Locator.cpp +# End Source File +# Begin Source File + +SOURCE=.\server.cpp +# End Source File +# End Target +# End Project diff --git a/TAO/tests/POA/On_Demand_Activation/svc.conf b/TAO/tests/POA/On_Demand_Activation/svc.conf new file mode 100644 index 00000000000..43c6a486c92 --- /dev/null +++ b/TAO/tests/POA/On_Demand_Activation/svc.conf @@ -0,0 +1,49 @@ +# $Id$ +# +# This file contains a sample ACE_Service_Config configuration +# file specifying the strategy factories utilized by an application +# using TAO. There are currently only two possible factories: +# Client_Strategy_Factory and Server_Strategy_Factory. These names +# must be used as the second argument to their corresponding line, +# because that's what the ORB uses to find the desired factory. +# +# Note that there are two unordinary characteristics of the way *this* +# file is set up: +# - both client and server strategies are specified in the same +# file, which would only make sense for co-located clients & servers +# - both of the factories are actually sourced out of libTAO.so +# (TAO.DLL on Win32), and they would normally be in a separate +# dll from the TAO ORB Core. +# +# The options which can be passed to the Resource Factory are: +# +# -ORBresources +# where can be 'global' to specify globally-held resources, +# or 'tss' to specify thread-specific resources. +# +# The options which can be passed to the Client are: +# +# +# The options which can be passed to the Server are: +# +# -ORBconcurrency +# where can be 'thread-per-connection' to specify +# use of the ACE_Threaded_Strategy concurrency strategy, +# or 'reactive' to specify use of the ACE_Reactive_Strategy +# concurrency strategy. +# +# -ORBthreadflags +# specifies the default thread flags to use, where is a +# logical OR'ing of the flags THR_DETACHED, THR_BOUND, THR_NEW_LWP, +# THR_SUSPENDED, or THR_DAEMON. Note that not every flag may be valid +# on every platform. +# +# -ORBdemuxstrategy +# where can be one of 'dynamic', 'linear', 'active', or 'user', +# and specifies the type of object lookup strategy used internally. +# -ORBtablesize +# specifies the size of the object table +# +dynamic Resource_Factory Service_Object * TAO:_make_TAO_Resource_Factory() "-ORBresources global" +dynamic Client_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Client_Strategy_Factory() +dynamic Server_Strategy_Factory Service_Object * TAO:_make_TAO_Default_Server_Strategy_Factory() "-ORBconcurrency reactive -ORBdemuxstrategy dynamic -ORBtablesize 128" -- cgit v1.2.1