diff options
Diffstat (limited to 'TAO/orbsvcs/examples/ORT')
22 files changed, 1677 insertions, 0 deletions
diff --git a/TAO/orbsvcs/examples/ORT/Gateway.idl b/TAO/orbsvcs/examples/ORT/Gateway.idl new file mode 100644 index 00000000000..7f97783707c --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Gateway.idl @@ -0,0 +1,16 @@ +// $Id$ + +#ifndef GATEWAY_IDL +#define GATEWAY_IDL + +module Gateway +{ + interface Object_Factory + { + Object create_object (in string interface_repository_id, + in Object gatewayed_object); + }; + +}; + +#endif /* GATEWAY_IDL */ diff --git a/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.cpp b/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.cpp new file mode 100644 index 00000000000..ecc1d6e1055 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.cpp @@ -0,0 +1,35 @@ +// $Id$ + +#include "Gateway_ObjRef_Factory.h" + +Gateway_ObjRef_Factory:: +Gateway_ObjRef_Factory ( + Gateway::Object_Factory_ptr gateway_object_factory, + PortableInterceptor::ObjectReferenceFactory *old_factory) + : gateway_object_factory_ (gateway_object_factory), + old_factory_ (old_factory) +{ + CORBA::add_ref (old_factory); +} + +CORBA::Object_ptr +Gateway_ObjRef_Factory:: +make_object (const char *interface_repository_id, + const PortableInterceptor::ObjectId & id + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::Object_var object = + this->old_factory_->make_object (interface_repository_id, + id + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + CORBA::Object_ptr object_ptr = + this->gateway_object_factory_->create_object (interface_repository_id, + object.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + return object_ptr; +} diff --git a/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.h b/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.h new file mode 100644 index 00000000000..3af0da985b3 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Gateway_ObjRef_Factory.h @@ -0,0 +1,40 @@ +// -*- C++ -*- +// +// $Id$ + +#ifndef GATEWAY_OBJREF_FACTORY_H +#define GATEWAY_OBJREF_FACTORY_H + +#include "ObjectReferenceFactoryC.h" +#include "GatewayC.h" + + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +class Gateway_ObjRef_Factory + : public CORBA::DefaultValueRefCountBase, + public virtual OBV_ORT::ObjectReferenceFactory +{ +public: + + Gateway_ObjRef_Factory ( + Gateway::Object_Factory_ptr gateway_object_factory, + PortableInterceptor::ObjectReferenceFactory *old_factory); + + virtual CORBA::Object_ptr make_object ( + const char *repository_id, + const PortableInterceptor::ObjectId &id + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +private: + + Gateway::Object_Factory_var gateway_object_factory_; + + PortableInterceptor::ObjectReferenceFactory_var old_factory_; +}; + +#endif /* GATEWAY_OBJREF_FACTORY_H */ diff --git a/TAO/orbsvcs/examples/ORT/Gateway_i.cpp b/TAO/orbsvcs/examples/ORT/Gateway_i.cpp new file mode 100644 index 00000000000..f4ce9754556 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Gateway_i.cpp @@ -0,0 +1,181 @@ +//$Id$ + +#include "Gateway_i.h" + +#include "tao/AnyTypeCode/Any.h" +#include "tao/AnyTypeCode/NVList.h" +#include "tao/AnyTypeCode/ExceptionA.h" + +#include "tao/IFR_Client/IFR_BasicC.h" + +#include "tao/DynamicInterface/Server_Request.h" +#include "tao/DynamicInterface/Request.h" +#include "tao/DynamicInterface/Unknown_User_Exception.h" + +#include "tao/ORB.h" +#include "tao/LocalObject.h" + +ACE_RCSID (ORT, + Gateway_i, + "$Id$") + +Gateway_i:: +Gateway_i (CORBA::ORB_ptr orb, + PortableServer::Current_ptr poa_current) + : orb_ (orb), + poa_current_ (poa_current) +{ + /// Constructor +} + +void +Gateway_i::invoke (CORBA::ServerRequest_ptr request + ACE_ENV_ARG_DECL) +{ + PortableServer::ObjectId_var target_id = + this->poa_current_->get_object_id (); + + CORBA::String_var stringified_object_id = + PortableServer::ObjectId_to_string (target_id.in ()); + + CORBA::Object_var target_object = + this->orb_->string_to_object (stringified_object_id.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // Use the IfR interfaces to query the NVList for this object... + CORBA::InterfaceDef_var target_interface = + target_object->_get_interface (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + if (CORBA::is_nil (target_interface.in ())) + { + /// + } + + // This is the target operation... + CORBA::String_var operation_name = + request->operation (); + + CORBA::Contained_var contained_operation = + target_interface->lookup (operation_name.in ()); + + CORBA::OperationDef_var operation = + CORBA::OperationDef::_narrow (contained_operation.in ()); + + // Save the result typecode... + CORBA::TypeCode_var result_typecode = + operation.in ()->result (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + CORBA::ParDescriptionSeq_var parameters = + operation.in ()->params (); + + // Build the NVList based on the info from the IfR + CORBA::NVList_ptr arguments; + this->orb_->create_list (parameters->length (), + arguments + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::Flags flags = 0; + + CORBA::ULong length = parameters->length (); + + CORBA::ULong i = 0; + + for (i = 0; i < length; ++i) + { + switch (parameters[i].mode) + { + case CORBA::PARAM_IN: + flags = CORBA::ARG_IN; + break; + case CORBA::PARAM_OUT: + flags = CORBA::ARG_OUT; + break; + case CORBA::PARAM_INOUT: + flags = CORBA::ARG_INOUT; + break; + } + } + + for (i = 0; i != length; ++i) + { + CORBA::Any any; + any._tao_set_typecode (parameters[i].type.in ()); + + arguments->add_value (parameters[i].name, + any, + flags + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + } + + // Extract the values of the arguments from the DSI ServerRequest + request->arguments (arguments ACE_ENV_ARG_PARAMETER); + + // Use the NVList (with values) to create a DII Request... + CORBA::Request_var dii_request; + + CORBA::NamedValue *named_value = 0; + + this->orb_->create_named_value (named_value + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + CORBA::ContextList *context_list = 0; + CORBA::ExceptionList *exceptions = 0; + + target_object->_create_request (CORBA::Context::_nil (), + operation_name.in (), + arguments, + named_value, /* Result */ + exceptions, + context_list, /* Context List */ + dii_request.inout (), + CORBA::Flags (0) + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + // Set the return type... + dii_request->set_return_type (result_typecode.in ()); + + ACE_TRY + { + // Make the DII request + dii_request->invoke (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // At this point the NVList contains all the out and inout + // arguments, but we need to extract the return value... + } + ACE_CATCH (CORBA::UnknownUserException, user_ex) + { + // Pass the exception back to the server request... + request->set_exception (user_ex.exception ()); + return; + } + ACE_CATCH (CORBA::SystemException, sys_ex) + { + CORBA::Any any; + any <<= sys_ex; + // Pass the exception back to the server request... + request->set_exception (any); + return; + } + ACE_CATCHANY; + ACE_ENDTRY; + + request->set_result (dii_request->return_value ()); + // Using the same NVList for both the DSI Server Request and the DII + // Request takes care of the out and inout arguments (whew!) +} + +CORBA::RepositoryId +Gateway_i::_primary_interface (const PortableServer::ObjectId &, + PortableServer::POA_ptr + ACE_ENV_ARG_DECL_NOT_USED) +{ + return 0; +} diff --git a/TAO/orbsvcs/examples/ORT/Gateway_i.h b/TAO/orbsvcs/examples/ORT/Gateway_i.h new file mode 100644 index 00000000000..a49d7a1e73a --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Gateway_i.h @@ -0,0 +1,50 @@ +// -*- C++ -*- +// +// $Id$ + +//============================================================================= +/** + * @file Gateway_i.h + * + * $Id$ + * + * Implementation header used for forwarding the requests from the + * gateway to the server and reply to the client + * + * @author Carlos O'Ryan <coryan@uci.edu> + * @author Priyanka Gontla <gontla_p@ociweb.com> + */ +//============================================================================= + +#ifndef GATEWAY_I_H +#define GATEWAY_I_H + +#include "tao/IFR_Client/IFR_Client_Adapter_Impl.h" +#include "tao/AnyTypeCode/AnyTypeCode_methods.h" +#include "tao/DynamicInterface/DII_CORBA_methods.h" +#include "tao/DynamicInterface/Dynamic_Implementation.h" +#include "tao/PortableServer/PortableServer.h" + +class Gateway_i + : public virtual PortableServer::DynamicImplementation +{ +public: + Gateway_i (CORBA::ORB_ptr orb, + PortableServer::Current_ptr poa_current); + + virtual void invoke (CORBA::ServerRequest_ptr request + ACE_ENV_ARG_DECL); + + virtual CORBA::RepositoryId _primary_interface ( + const PortableServer::ObjectId &oid, + PortableServer::POA_ptr poa + ACE_ENV_ARG_DECL); + + private: + + CORBA::ORB_ptr orb_; + + PortableServer::Current_ptr poa_current_; +}; + +#endif /* GATEWAY_I_H */ diff --git a/TAO/orbsvcs/examples/ORT/Makefile.am b/TAO/orbsvcs/examples/ORT/Makefile.am new file mode 100644 index 00000000000..03e2618d646 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Makefile.am @@ -0,0 +1,225 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +ACE_BUILDDIR = $(top_builddir)/.. +ACE_ROOT = $(top_srcdir)/.. +TAO_BUILDDIR = $(top_builddir) +TAO_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDLFLAGS = -Ge 1 -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/gperf +TAO_ROOT = $(top_srcdir) + +CLEANFILES = +noinst_PROGRAMS = +BUILT_SOURCES = + +## Makefile.ORT_Idl.am + +if !BUILD_MINIMUM_CORBA + +BUILT_SOURCES += \ + GatewayC.cpp \ + GatewayC.h \ + GatewayC.inl \ + GatewayS.cpp \ + GatewayS.h \ + GatewayS.inl + +CLEANFILES += \ + Gateway-stamp \ + GatewayC.cpp \ + GatewayC.h \ + GatewayC.inl \ + GatewayS.cpp \ + GatewayS.h \ + GatewayS.inl + +GatewayC.cpp GatewayC.h GatewayC.inl GatewayS.cpp GatewayS.h GatewayS.inl: Gateway-stamp + +Gateway-stamp: $(srcdir)/Gateway.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/Gateway.idl + @touch $@ + +BUILT_SOURCES += \ + ObjectReferenceFactoryC.cpp \ + ObjectReferenceFactoryC.h \ + ObjectReferenceFactoryC.inl \ + ObjectReferenceFactoryS.cpp \ + ObjectReferenceFactoryS.h \ + ObjectReferenceFactoryS.inl + +CLEANFILES += \ + ObjectReferenceFactory-stamp \ + ObjectReferenceFactoryC.cpp \ + ObjectReferenceFactoryC.h \ + ObjectReferenceFactoryC.inl \ + ObjectReferenceFactoryS.cpp \ + ObjectReferenceFactoryS.h \ + ObjectReferenceFactoryS.inl + +ObjectReferenceFactoryC.cpp ObjectReferenceFactoryC.h ObjectReferenceFactoryC.inl ObjectReferenceFactoryS.cpp ObjectReferenceFactoryS.h ObjectReferenceFactoryS.inl: ObjectReferenceFactory-stamp + +ObjectReferenceFactory-stamp: $(srcdir)/ObjectReferenceFactory.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/ObjectReferenceFactory.idl + @touch $@ + +BUILT_SOURCES += \ + sum_serverC.cpp \ + sum_serverC.h \ + sum_serverC.inl \ + sum_serverS.cpp \ + sum_serverS.h \ + sum_serverS.inl + +CLEANFILES += \ + sum_server-stamp \ + sum_serverC.cpp \ + sum_serverC.h \ + sum_serverC.inl \ + sum_serverS.cpp \ + sum_serverS.h \ + sum_serverS.inl + +sum_serverC.cpp sum_serverC.h sum_serverC.inl sum_serverS.cpp sum_serverS.h sum_serverS.inl: sum_server-stamp + +sum_server-stamp: $(srcdir)/sum_server.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St $(srcdir)/sum_server.idl + @touch $@ + + +noinst_HEADERS = \ + Gateway.idl \ + ObjectReferenceFactory.idl \ + sum_server.idl + +endif !BUILD_MINIMUM_CORBA + +## Makefile.ORT_Gateway.am + +if BUILD_CORBA_MESSAGING +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += gateway_server + +gateway_server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +gateway_server_SOURCES = \ + GatewayC.cpp \ + GatewayS.cpp \ + Gateway_i.cpp \ + Object_Factory_i.cpp \ + gateway_server.cpp \ + Gateway_i.h \ + Object_Factory_i.h + +gateway_server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_IFR_Client.la \ + $(TAO_BUILDDIR)/tao/libTAO_DynamicInterface.la \ + $(TAO_BUILDDIR)/tao/libTAO_Messaging.la \ + $(TAO_BUILDDIR)/tao/libTAO_PI.la \ + $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_Valuetype.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA +endif BUILD_CORBA_MESSAGING + +## Makefile.ORT_Server.am + +if BUILD_CORBA_MESSAGING +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += server + +server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +server_SOURCES = \ + GatewayC.cpp \ + Gateway_ObjRef_Factory.cpp \ + ObjectReferenceFactoryC.cpp \ + Server_IORInterceptor.cpp \ + Server_IORInterceptor_ORBInitializer.cpp \ + server.cpp \ + sum_serverC.cpp \ + sum_serverS.cpp \ + sum_server_i.cpp \ + Gateway_ObjRef_Factory.h \ + Server_IORInterceptor.h \ + Server_IORInterceptor_ORBInitializer.h \ + sum_server_i.h + +server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_IORInterceptor.la \ + $(TAO_BUILDDIR)/tao/libTAO_ObjRefTemplate.la \ + $(TAO_BUILDDIR)/tao/libTAO_IFR_Client.la \ + $(TAO_BUILDDIR)/tao/libTAO_DynamicInterface.la \ + $(TAO_BUILDDIR)/tao/libTAO_Messaging.la \ + $(TAO_BUILDDIR)/tao/libTAO_PI.la \ + $(TAO_BUILDDIR)/tao/libTAO_CodecFactory.la \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_Valuetype.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA +endif BUILD_CORBA_MESSAGING + +## Makefile.ORT_Client.am + +if !BUILD_MINIMUM_CORBA + +noinst_PROGRAMS += client + +client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) \ + -I$(TAO_ROOT)/orbsvcs \ + -I$(TAO_BUILDDIR)/orbsvcs \ + -DTAO_HAS_TYPED_EVENT_CHANNEL + +client_SOURCES = \ + client.cpp \ + sum_serverC.cpp \ + Gateway_ObjRef_Factory.h \ + Gateway_i.h \ + Object_Factory_i.h \ + Server_IORInterceptor.h \ + Server_IORInterceptor_ORBInitializer.h \ + sum_server_i.h + +client_LDADD = \ + $(TAO_BUILDDIR)/orbsvcs/orbsvcs/libTAO_CosEvent.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_MINIMUM_CORBA + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/TAO/orbsvcs/examples/ORT/ORT.mpc b/TAO/orbsvcs/examples/ORT/ORT.mpc new file mode 100644 index 00000000000..82fc927aab8 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/ORT.mpc @@ -0,0 +1,52 @@ +// $Id$ + +project(*idl): taoidldefaults, minimum_corba { + idl_files { + Gateway.idl + ObjectReferenceFactory.idl + sum_server.idl + } + custom_only = 1 +} + +project(*Gateway) : orbsvcsexe, dynamicinterface, ifr_client, minimum_corba { + after += *idl + + source_files { + GatewayC.cpp + GatewayS.cpp + gateway_server.cpp + Gateway_i.cpp + Object_Factory_i.cpp + } + idl_files { + } +} + +project(*Server) : orbsvcsexe, dynamicinterface, ifr_client, minimum_corba, iorinterceptor { + exename = server + after += *Gateway + source_files { + server.cpp + GatewayC.cpp + Gateway_ObjRef_Factory.cpp + sum_serverC.cpp + sum_serverS.cpp + sum_server_i.cpp + Server_IORInterceptor_ORBInitializer.cpp + Server_IORInterceptor.cpp + ObjectReferenceFactoryC.cpp + } + idl_files { + } +} + +project(*Client) : orbsvcsexe, event, minimum_corba { + after += *Idl *Server + source_files { + client.cpp + sum_serverC.cpp + } + idl_files { + } +} diff --git a/TAO/orbsvcs/examples/ORT/ObjectReferenceFactory.idl b/TAO/orbsvcs/examples/ORT/ObjectReferenceFactory.idl new file mode 100644 index 00000000000..0b7c8d10bee --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/ObjectReferenceFactory.idl @@ -0,0 +1,16 @@ +// -*- IDL -*- +// +// $Id$ + +#ifndef OBJECT_REFERENCE_FACTORY_IDL +#define OBJECT_REFERENCE_FACTORY_IDL + +#include "tao/ObjRefTemplate/ObjectReferenceTemplate_include.pidl" + +module ORT +{ + valuetype ObjectReferenceFactory + : PortableInterceptor::ObjectReferenceFactory {}; +}; + +#endif /* OBJECT_REFERENCE_FACTORY_IDL */ diff --git a/TAO/orbsvcs/examples/ORT/Object_Factory_i.cpp b/TAO/orbsvcs/examples/ORT/Object_Factory_i.cpp new file mode 100644 index 00000000000..32c4e9ce579 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Object_Factory_i.cpp @@ -0,0 +1,49 @@ +// $Id$ + +#include "Object_Factory_i.h" +#include "tao/PortableServer/Root_POA.h" + +Object_Factory_i::Object_Factory_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr gateway_poa) + : orb_ (CORBA::ORB::_duplicate (orb)), + gateway_poa_ (gateway_poa) +{ + /// Constructor +} + + +CORBA::Object_ptr +Object_Factory_i::create_object (const char *interface_repository_id, + CORBA::Object_ptr gatewayed_object + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::String_var stringified_object = + this->orb_->object_to_string (gatewayed_object ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + const PortableServer::ObjectId_var id = + PortableServer::string_to_ObjectId (stringified_object.in ()); + + const PortableInterceptor::ObjectId *obj_id = + reinterpret_cast<const PortableInterceptor::ObjectId *> (&id.in ()); + ACE_UNUSED_ARG(obj_id); + ACE_UNUSED_ARG(interface_repository_id); +/* + TAO_POA *poa = dynamic_cast <TAO_POA *> (this->gateway_poa_); + ACE_CHECK_RETURN (CORBA::Object::_nil ()); + + PortableInterceptor::ObjectReferenceTemplate *ort_template = + poa->get_adapter_template(); + + TAO_ObjectReferenceTemplate *ort = + dynamic_cast <TAO_ObjectReferenceTemplate *> (ort_template); + + CORBA::Object_ptr object_ptr = + ort->make_object (interface_repository_id, + *obj_id + ACE_ENV_ARG_PARAMETER); + ACE_CHECK_RETURN (CORBA::Object::_nil ());*/ + + return CORBA::Object::_nil(); +} diff --git a/TAO/orbsvcs/examples/ORT/Object_Factory_i.h b/TAO/orbsvcs/examples/ORT/Object_Factory_i.h new file mode 100644 index 00000000000..add32112dbd --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Object_Factory_i.h @@ -0,0 +1,45 @@ +// $Id$ + +//============================================================================= +/** + * @file Object_Factory_i.h + * + * $Id$ + * + * Implementation header for the "Gateway" IDL interface for the + * ORT example. + * + * @author Carlos O'Ryan <coryan@uci.edu> + * @author Priyanka Gontla <gontla_p@ociweb.com> + */ +//============================================================================= + +#ifndef OBJECT_FACTORY_I_H +#define OBJECT_FACTORY_I_H + +#include "GatewayS.h" + +#include "tao/PortableServer/PortableServerC.h" +#include "tao/ORB.h" + +class Object_Factory_i : public virtual POA_Gateway::Object_Factory +{ + public: + + /// Constructor + Object_Factory_i (CORBA::ORB_ptr orb, + PortableServer::POA_ptr gateway_poa); + + CORBA::Object_ptr + create_object (const char *interface_repository_id, + CORBA::Object_ptr gatewayed_object + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + + private: + + CORBA::ORB_ptr orb_; + PortableServer::POA_ptr gateway_poa_; +}; + +#endif /* OBJECT_FACTORY_I_H */ diff --git a/TAO/orbsvcs/examples/ORT/README b/TAO/orbsvcs/examples/ORT/README new file mode 100644 index 00000000000..2b1b313b3e6 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/README @@ -0,0 +1,69 @@ +$Id$ + +This example shows the use of ORT Template by a simple application. + +Scenario: +======== + +1. There's a server which has a dummy method that adds the two 'in' variables + and return the sum to the client. + +2. There is a Gateway which receives the requests on behalf of the + server and redirects to the server. So the client never knows about + the actual server but only the gateway. + +3. And, as always we will have a client that invokes the server + method. + +Files and Small Description +===================== + + +Gateway.idl IDL for the Gateway + +Gateway_IORInterceptor IORInterceptor for the Gateway. + +Gateway_i Implementation of the Gateway which changes the DSI to DII. + +Object_Factory_i Implementation for the + Gateway IDL method. This method + creates a reference which points to the gateway + instead of the server. + +gateway_server As the name means, gateway server + implementation. + +sum_server.idl idl for the sum_server. + +server The main server which is being + gatewayed by the gateway + +sum_server_i Implementation of sum_server.idl methods. + +client Simple client which invokes the sum_server + method add_variables. + +How to run the example +====================== + +1. First run the IFR_Service. + +% $IFR_Service + + It generates an ior in if_repo.ior by default. + +2. Then, run the tao_ifr passing sum_server.idl as its argument, + +% $tao_ifr sum_server.idl + +3. Run the gateway server + +% ./gateway_server -o gateway_ior -ORBInitRef IFR_Service=file://if_repo.ior + +4. Run the actual server. + +% ./server -o server_ior -ORBInitRef Gateway_Object_Factory=file://gateway_ior + +5. Run the client + +% ./client -k file://server_ior diff --git a/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.cpp b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.cpp new file mode 100644 index 00000000000..2cd8117b443 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.cpp @@ -0,0 +1,85 @@ +// $Id$ + +#include "Server_IORInterceptor.h" +#include "Gateway_ObjRef_Factory.h" + +ACE_RCSID (ORT, + Server_IORInterceptor, + "$Id$") + + +Server_IORInterceptor:: +Server_IORInterceptor (Gateway::Object_Factory_ptr factory) + : gateway_object_factory_ (Gateway::Object_Factory::_duplicate (factory)) +{ +} + +Server_IORInterceptor::~Server_IORInterceptor (void) +{ + CORBA::release (this->gateway_object_factory_); +} + + +char * +Server_IORInterceptor::name (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return CORBA::string_dup ("Server_IORInterceptor"); +} + +void +Server_IORInterceptor::destroy (ACE_ENV_SINGLE_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::release (this->gateway_object_factory_); + this->gateway_object_factory_ = Gateway::Object_Factory::_nil (); +} + +void +Server_IORInterceptor::establish_components ( + PortableInterceptor::IORInfo_ptr + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Server_IORInterceptor::components_established ( + PortableInterceptor::IORInfo_ptr ior_info + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + Gateway_ObjRef_Factory *my_factory = 0; + + PortableInterceptor::ObjectReferenceFactory_var current_factory = + ior_info->current_factory (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_CHECK; + + ACE_NEW_THROW_EX (my_factory, + Gateway_ObjRef_Factory (this->gateway_object_factory_, + current_factory.in ()), + CORBA::NO_MEMORY ()); + ACE_CHECK; + + ior_info->current_factory (my_factory + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} + +void +Server_IORInterceptor::adapter_manager_state_changed ( + const char *, + PortableInterceptor::AdapterState + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Server_IORInterceptor:: adapter_state_changed ( + const PortableInterceptor::ObjectReferenceTemplateSeq &, + PortableInterceptor::AdapterState + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} diff --git a/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.h b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.h new file mode 100644 index 00000000000..da243325d05 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor.h @@ -0,0 +1,85 @@ +// -*- C++ -*- +// +//$Id$ + +#ifndef SERVER_IORINTERCEPTOR_H +#define SERVER_IORINTERCEPTOR_H + +#include "GatewayC.h" +#include "tao/IORInterceptor/IORInterceptor.h" +#include "tao/LocalObject.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4250) +#endif /* _MSC_VER */ + +class Server_IORInterceptor + : public virtual PortableInterceptor::IORInterceptor_3_0, + public virtual TAO_Local_RefCounted_Object +{ +public: + + Server_IORInterceptor (Gateway::Object_Factory_ptr gateway_object_factory); + + /** + * @name Methods Required by the IOR Interceptor Interface + * + * These are methods that must be implemented since they are pure + * virtual in the abstract base class. They are the canonical + * methods required for all IOR interceptors. + */ + //@{ + /// Return the name of this IORInterceptor. + virtual char * name (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Cleanup resources acquired by this IORInterceptor. + virtual void destroy (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// Add the tagged components to the IOR. + virtual void establish_components ( + PortableInterceptor::IORInfo_ptr info + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void components_established ( + PortableInterceptor::IORInfo_ptr info + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void adapter_manager_state_changed ( + const char * id, + PortableInterceptor::AdapterState state + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + virtual void adapter_state_changed ( + const PortableInterceptor::ObjectReferenceTemplateSeq & templates, + PortableInterceptor::AdapterState state + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + //@} + +protected: + + ~Server_IORInterceptor (void); + +private: + + Gateway::Object_Factory_ptr gateway_object_factory_; + +}; + +#if defined(_MSC_VER) +#pragma warning(pop) +#endif /* _MSC_VER */ + +#endif /* SERVER_IORINTERCEPTOR_H */ diff --git a/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.cpp b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.cpp new file mode 100644 index 00000000000..93fd158c07b --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.cpp @@ -0,0 +1,59 @@ +// $Id$ + +#include "Server_IORInterceptor_ORBInitializer.h" +#include "Server_IORInterceptor.h" +#include "tao/ORB_Constants.h" + +#include "GatewayC.h" + +ACE_RCSID (ORT, + Server_IORInterceptor_ORBInitializer, + "$Id: ") + +void +Server_IORInterceptor_ORBInitializer::pre_init ( + PortableInterceptor::ORBInitInfo_ptr /* info */ + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ +} + +void +Server_IORInterceptor_ORBInitializer::post_init ( + PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + CORBA::Object_var obj = + info->resolve_initial_references ("Gateway_Object_Factory" + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + /// Narrow it down correctly. + Gateway::Object_Factory_var gateway_object_factory = + Gateway::Object_Factory::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; + + /// Check for nil reference + if (CORBA::is_nil (gateway_object_factory.in ())) + ACE_ERROR ((LM_ERROR, + "Unable to obtain reference to Gateway::Object_Factory " + "object.\n")); + + PortableInterceptor::IORInterceptor_ptr gateway; + ACE_NEW_THROW_EX (gateway, + Server_IORInterceptor (gateway_object_factory.in ()), + CORBA::NO_MEMORY ( + CORBA::SystemException::_tao_minor_code ( + TAO::VMCID, + ENOMEM), + CORBA::COMPLETED_NO)); + ACE_CHECK; + + PortableInterceptor::IORInterceptor_var ior_interceptor = gateway; + + info->add_ior_interceptor (ior_interceptor.in () + ACE_ENV_ARG_PARAMETER); + ACE_CHECK; +} diff --git a/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.h b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.h new file mode 100644 index 00000000000..5fd0887f014 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/Server_IORInterceptor_ORBInitializer.h @@ -0,0 +1,44 @@ +// $Id$ + +#ifndef SERVER_IOR_INTERCEPTOR_ORB_INITIALIZER_H +#define SERVER_IOR_INTERCEPTOR_ORB_INITIALIZER_H + +#include "ace/config-all.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "tao/PI/PI.h" +#include "tao/LocalObject.h" + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4250) +#endif /* _MSC_VER */ + +class Server_IORInterceptor_ORBInitializer + : public virtual PortableInterceptor::ORBInitializer, + public virtual TAO_Local_RefCounted_Object +{ + public: + + //@{ + /// The pre-initialization hook. + virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info + ACE_ENV_ARG_DECL_WITH_DEFAULTS) + ACE_THROW_SPEC ((CORBA::SystemException)); + + /// The post-initialization hook. + 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 */ + +#endif /* SERVER_IOR_INTERCEPTOR_ORB_INITIALIZER_H */ diff --git a/TAO/orbsvcs/examples/ORT/client.cpp b/TAO/orbsvcs/examples/ORT/client.cpp new file mode 100644 index 00000000000..699985a1993 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/client.cpp @@ -0,0 +1,85 @@ +// -*- C++ -*- + +#include "sum_serverC.h" +#include "ace/Get_Opt.h" + +ACE_RCSID (ORT, + client, + "$Id$") + +const char *ior = "file://test.ior"; + +int +parse_args (int argc, char *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "k:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.optarg; + break; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s " + "-k IOR " + "\n", + argv[0]), + -1); + } + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "client_sum_orb" ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return 1; + + CORBA::Object_var obj = + orb->string_to_object (ior ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + ORT::sum_server_var server = + ORT::sum_server::_narrow (obj.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", + ior), + 1); + } + + CORBA::ULong a = 5; + CORBA::ULong b = 3; + + CORBA::ULong result = server->add_variables (a, + b + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (result != 8) + ACE_DEBUG ((LM_DEBUG, + "Error: Add Variables did not return the right value\n")); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "ORT example on client side :"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/examples/ORT/gateway_server.cpp b/TAO/orbsvcs/examples/ORT/gateway_server.cpp new file mode 100644 index 00000000000..d52bc63f0f2 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/gateway_server.cpp @@ -0,0 +1,189 @@ +// $Id$ + +#include "Object_Factory_i.h" +#include "Gateway_i.h" + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +const char *ior_output_file = 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; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s " + "-o <iorfile>" + "\n", + argv[0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { + /// Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "gateway_server_orb" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return -1; + + /// Resolve reference to RootPOA + CORBA::Object_var obj = + orb->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + /// Narrow it down correctly. + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + /// Check for nil references + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to obtain RootPOA reference.\n"), + -1); + + /// Get poa_manager reference + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + /// Activate it. + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ///@} + + CORBA::PolicyList policies (3); + policies.length (3); + + policies [0] = + root_poa->create_servant_retention_policy (PortableServer::RETAIN + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + policies [1] = + root_poa->create_request_processing_policy (PortableServer::USE_DEFAULT_SERVANT + ACE_ENV_ARG_PARAMETER); + + ACE_TRY_CHECK; + + policies [2] = + root_poa->create_id_uniqueness_policy (PortableServer::MULTIPLE_ID + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + PortableServer::POA_var gateway_poa = + root_poa->create_POA ("Gateway_POA", + poa_manager.in (), + policies + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + for (CORBA::ULong i = 0; i != policies.length (); ++i) { + policies[i]->destroy (); + } + + // Get the POA Current object reference + obj = + orb->resolve_initial_references ("POACurrent" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Narrow the object reference to a POA Current reference + PortableServer::Current_var poa_current = + PortableServer::Current::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + Gateway_i *gateway; + + ACE_NEW_THROW_EX (gateway, + Gateway_i (orb.in (), + poa_current.in ()), + CORBA::NO_MEMORY ()); + ACE_TRY_CHECK; + + gateway_poa->set_servant (gateway ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + /// Get the ObjectID + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId ("Object_Factory"); + + /// This class is used to create a object reference. + Object_Factory_i *object_factory; + + ACE_NEW_THROW_EX (object_factory, + Object_Factory_i (orb.in (), + gateway_poa.in ()), + CORBA::NO_MEMORY ()); + ACE_TRY_CHECK; + + /// Activate the Object_Factory_i Object + gateway_poa->activate_object_with_id (oid.in (), + object_factory + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Get the object reference. + CORBA::Object_var gateway_object_factory = + gateway_poa->id_to_reference (oid.in ()); + + /// Convert the object reference to a string format. + CORBA::String_var ior = + orb->object_to_string (gateway_object_factory.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + /// 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); + } + + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "ORT test (gateway_server):"); + + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/examples/ORT/run_test.pl b/TAO/orbsvcs/examples/ORT/run_test.pl new file mode 100755 index 00000000000..9554ac4bc46 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/run_test.pl @@ -0,0 +1,130 @@ +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; + +$ifr_iorfile= "if_repo.ior"; +$srv_iorfile = "iorfile.ior"; +$gateway_iorfile = "gateway_ior.ior"; +$test_idl = PerlACE::LocalFile ("sum_server.idl"); + +# find the tao_ifr executable. +# Its placement is dependent upon the OS and if MPC generated makefiles are used. +my $exec_extn=""; +if ($^O eq "MSWin32") { + $exec_extn=".exe"; +} + +$tao_ifr = "../../../../bin/tao_ifr"; +if (! -e $tao_ifr . $exec_extn ) { + $tao_ifr = "../../../IFR_Service/tao_ifr"; + if (! -e $tao_ifr . $exec_extn ) { + print STDERR "ERROR: tao_ifr compiler not found.\n"; + exit 1; + } +} + +$lookup_by_name = ""; +$other = ""; + +for ($i = 0; $i <= $#ARGV; $i++) { + if ($ARGV[$i] eq "-n") { + $lookup_by_name = "-n"; + } + else { + $other .= $ARGV[$i]; + } +} + +$TAO_IFR = new PerlACE::Process ($tao_ifr); +$IFR = new PerlACE::Process ("../../IFR_Service/IFR_Service", " -o $ifr_iorfile"); +$GATEWAYSV = new PerlACE::Process ("gateway_server", "-o $gateway_iorfile -ORBInitRef IFR_Service=file://$ifr_iorfile"); +$SV = new PerlACE::Process ("server", "-o $srv_iorfile -ORBInitRef Gateway_Object_Factory=file://$gateway_iorfile"); +$CL2 = new PerlACE::Process ("client", "-k file://$srv_iorfile"); + +unlink $ifr_iorfile; +unlink $svr_iorfile; +unlink $gateway_iorfile; + +$IFR->Spawn (); + +if (PerlACE::waitforfile_timed ($ifr_iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$ifr_iorfile>\n"; + $IFR->Kill (); + exit 1; +} + +$TAO_IFR->Arguments ("-ORBInitRef InterfaceRepository=file://$ifr_iorfile $test_idl"); + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +$GATEWAYSV->Spawn (); + +if (PerlACE::waitforfile_timed ($gateway_iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$gateway_iorfile>\n"; + $IFR->Kill (); + $GATEWAYSV->Kill (); + exit 1; +} + +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($svr_iorfile, 1500) == -1) { + print STDERR "ERROR: cannot find file <$srv_iorfile>\n"; + $IFR->Kill (); + $GATEWAYSV->Kill (); + $SV->Kill (); + exit 1; +} + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (test.idl) returned $tresult\n"; + $status = 1; +} + +$client = $CL->SpawnWaitKill (60); + +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (-r test.idl) returned $tresult\n"; + $status = 1; +} + +$gatewayserver = $GATEWAYSV->TerminateWaitKill (5); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +$server = $SV->TerminateWaitKill (5); + +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} +$server = $IFR->TerminateWaitKill (5); + +if ($server != 0) { + print STDERR "ERROR: IFR returned $server\n"; + $status = 1; +} + +unlink $ifr_iorfile; +unlink $srv_iorfile; +unlink $gateway_iorfile; + +exit $status; diff --git a/TAO/orbsvcs/examples/ORT/server.cpp b/TAO/orbsvcs/examples/ORT/server.cpp new file mode 100644 index 00000000000..1b76cecb393 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/server.cpp @@ -0,0 +1,152 @@ +// $Id$ + +#include "sum_server_i.h" +#include "Server_IORInterceptor_ORBInitializer.h" +#include "tao/ORBInitializer_Registry.h" + +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +const char *ior_output_file = 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; + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s " + "-o <iorfile>" + "\n", + argv[0]), + -1); + } + + // Indicates sucessful parsing of the command line + return 0; +} + +int +main (int argc, char *argv[]) +{ + ACE_DECLARE_NEW_CORBA_ENV; + ACE_TRY + { +#if TAO_HAS_INTERCEPTORS == 1 + + PortableInterceptor::ORBInitializer_ptr orb_initializer = + PortableInterceptor::ORBInitializer::_nil (); + + ACE_NEW_RETURN (orb_initializer, + Server_IORInterceptor_ORBInitializer, + -1); // No CORBA exceptions yet! + + PortableInterceptor::ORBInitializer_var orb_initializer_var = + orb_initializer; + + PortableInterceptor::register_orb_initializer (orb_initializer_var.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + +#endif /* TAO_HAS_INTERCEPTORS == 1 */ + + // The usual initialization stuff + + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init (argc, + argv, + "server_sum_orb" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + if (parse_args (argc, argv) != 0) + return -1; + + // Resolve reference to RootPOA + CORBA::Object_var obj = + orb->resolve_initial_references ("RootPOA" + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Narrow it down correctly. + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (obj.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Check for nil references + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to obtain RootPOA reference.\n"), + -1); + + // Get poa_manager reference + PortableServer::POAManager_var poa_manager = + root_poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Activate it. + poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // initialize the sum_server + sum_server_i sum_server_impl; + + // Activate + obj = sum_server_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Narrow it down. + ORT::sum_server_var sum_server = + ORT::sum_server::_narrow (obj.in () + ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // Check for nil reference + if (CORBA::is_nil (sum_server.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to obtain reference to ORT::sum_server " + "object.\n"), + -1); + + // Convert the object reference to a string format. + CORBA::String_var ior = + orb->object_to_string (sum_server.in () ACE_ENV_ARG_PARAMETER); + ACE_TRY_CHECK; + + // 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); + } + + orb->run (ACE_ENV_SINGLE_ARG_PARAMETER); + ACE_TRY_CHECK; + + ACE_DEBUG ((LM_INFO, "Successful.\n")); + } + ACE_CATCHANY + { + ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, + "ORT example server:"); + return -1; + } + ACE_ENDTRY; + + return 0; +} diff --git a/TAO/orbsvcs/examples/ORT/sum_server.idl b/TAO/orbsvcs/examples/ORT/sum_server.idl new file mode 100644 index 00000000000..31c599c88e4 --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/sum_server.idl @@ -0,0 +1,10 @@ +// $Id$ + +module ORT +{ + interface sum_server + { + long add_variables (in long a, + in long b); + }; +}; diff --git a/TAO/orbsvcs/examples/ORT/sum_server_i.cpp b/TAO/orbsvcs/examples/ORT/sum_server_i.cpp new file mode 100644 index 00000000000..9b14117125e --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/sum_server_i.cpp @@ -0,0 +1,20 @@ +// $Id$ + +#include "sum_server_i.h" + +ACE_RCSID (ORT, + sum_server_i, + "$Id$") + +sum_server_i::sum_server_i () +{ +} + +CORBA::Long +sum_server_i::add_variables (CORBA::Long a, + CORBA::Long b + ACE_ENV_ARG_DECL_NOT_USED) + ACE_THROW_SPEC ((CORBA::SystemException)) +{ + return a+b; +} diff --git a/TAO/orbsvcs/examples/ORT/sum_server_i.h b/TAO/orbsvcs/examples/ORT/sum_server_i.h new file mode 100644 index 00000000000..ea38c4ae7ab --- /dev/null +++ b/TAO/orbsvcs/examples/ORT/sum_server_i.h @@ -0,0 +1,40 @@ +// $Id$ + +//============================================================================= +/** + * @file sum_server_i.h + * + * $Id$ + * + * Implementation header for the "server" IDL interface for the + * ORT example. + * + * @author Priyanka Gontla <gontla_p@ociweb.com> + */ +//============================================================================= + +#ifndef SUM_SERVER_I_H +#define SUM_SERVER_I_H + +#include "sum_serverS.h" + +// Must include this header file and link to TAO_IFR_Client.lib +// to dynamically load this necessary library. +#include "tao/IFR_Client/IFR_Client_Adapter_Impl.h" + +class sum_server_i : public virtual POA_ORT::sum_server +{ + public: + + /// Constructor + sum_server_i (); + + /// add variables method + CORBA::Long add_variables (CORBA::Long a, + CORBA::Long b + ACE_ENV_ARG_DECL) + ACE_THROW_SPEC ((CORBA::SystemException)); + +}; + +#endif /* SUM_SERVER_I_H */ |