diff options
author | Johnny Willemsen <jwillemsen@remedy.nl> | 2008-11-17 12:02:06 +0000 |
---|---|---|
committer | Johnny Willemsen <jwillemsen@remedy.nl> | 2008-11-17 12:02:06 +0000 |
commit | 024dcf2ec7a4ae36a5314fdadacbd843e2dc6476 (patch) | |
tree | 0ae4f34f4521cb5e2d61ab686255c061893dbccd /TAO/orbsvcs/DevGuideExamples | |
parent | ac5c2ae24122d585787fba28a321d901dc5234b4 (diff) | |
download | ATCD-024dcf2ec7a4ae36a5314fdadacbd843e2dc6476.tar.gz |
Mon Nov 17 12:01:12 UTC 2008 Johnny Willemsen <jwillemsen@remedy.nl>
Diffstat (limited to 'TAO/orbsvcs/DevGuideExamples')
16 files changed, 825 insertions, 0 deletions
diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp new file mode 100644 index 00000000000..3278f25b1cb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp @@ -0,0 +1,72 @@ +// $Id$ + +#include "ClientInitializer.h" +#include "ClientInterceptor.h" +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +ClientInitializer::ClientInitializer (void) + : slot_ (0), + current_ (PortableInterceptor::Current::_nil()) +{ +} + +void +ClientInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr) +{ +} + +void +ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info) +{ + // Find the Naming Service + CORBA::Object_var naming_obj = + info->resolve_initial_references("NameService"); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(naming_obj.in()); + if( CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + ACE_ASSERT(false); + } + + // Resolve the Messenger object + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup( "Messenger" ); + CORBA::Object_var obj = root->resolve( name ); + + Messenger_var messenger = Messenger::_narrow( obj.in() ); + if( CORBA::is_nil( messenger.in() ) ) { + std::cerr << "Not a Messenger reference" << std::endl; + ACE_ASSERT(false); + } + + // allocate slot + slot_ = info->allocate_slot_id(); + + // get PICurrent + CORBA::Object_var current_obj = info->resolve_initial_references("PICurrent"); + + current_ = + PortableInterceptor::Current::_narrow(current_obj.in()); + + // Create and register the request interceptors. + PortableInterceptor::ClientRequestInterceptor_var ci = + new ClientInterceptor(messenger, current_.in(), slot_); + info->add_client_request_interceptor (ci.in()); +} + +void +ClientInitializer::set_slot_data (void) +{ + // Set the recursion flag + CORBA::Any flag; + CORBA::Boolean x = 0; + flag <<= CORBA::Any::from_boolean(x); + current_->set_slot(slot_, flag); + + // Now that we're done with the PICurrent, we will release + // our reference to it. + current_ = PortableInterceptor::Current::_nil(); +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h new file mode 100644 index 00000000000..1bd687a032f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h @@ -0,0 +1,27 @@ +// $Id$ + +#ifndef CLIENTINITIALIZER_H +#define CLIENTINITIALIZER_H + +#include "tao/PortableInterceptorC.h" +#include "tao/LocalObject.h" +#include "tao/PI/PI.h" +#include "tao/PI/PICurrentC.h" + +class ClientInitializer : + public virtual PortableInterceptor::ORBInitializer, + public virtual ::CORBA::LocalObject +{ + public: + ClientInitializer (void); + virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info); + virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info); + void set_slot_data (void); + + private: + PortableInterceptor::SlotId slot_; + PortableInterceptor::Current_var current_; +}; + +#endif + diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp new file mode 100644 index 00000000000..0133711c16a --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp @@ -0,0 +1,116 @@ +// $Id$ + +#include "ClientInterceptor.h" +#include "tao/OctetSeqC.h" +#include "tao/PI/ClientRequestInfo.h" +#include "MessengerC.h" +#include "ace/OS_NS_string.h" +#include <iostream> + +const CORBA::ULong service_ctx_id = 0xdeed; + +ClientInterceptor:: +ClientInterceptor (Messenger_var theMessenger, + PortableInterceptor::Current_ptr thePic, + PortableInterceptor::SlotId theSlot) + : myname_ ("Client_Authentication_Interceptor") +{ + std::cout << "Calling ClientInterceptor constructor." << std::endl; + this->messenger = theMessenger; + this->pic = thePic; + this->slot = theSlot; +} + +ClientInterceptor::~ClientInterceptor (void) +{ +} + +char * +ClientInterceptor::name () +{ + std::cout << "Calling ClientInterceptor name() method" << std::endl; + return CORBA::string_dup (this->myname_); +} + +void +ClientInterceptor::destroy () +{ +} + +void +ClientInterceptor::send_poll ( + PortableInterceptor::ClientRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling send_poll()." << std::endl; +} + + +void +ClientInterceptor::send_request ( + PortableInterceptor::ClientRequestInfo_ptr ri) +{ + std::cout << "Calling send_request()." << std::endl; + + IOP::ServiceContext sc; + sc.context_id = service_ctx_id; + + const char user_name[] = "Ron Klein"; + std::cout << "User's Name: " << user_name << std::endl; + CORBA::ULong string_len = sizeof (user_name) + 1; + CORBA::Octet *buf = 0; + buf = new CORBA::Octet [string_len]; + + ACE_OS::strcpy (reinterpret_cast<char*> (buf), user_name); + + sc.context_data.replace (string_len, string_len, buf, 1); + + // recursive call setup + CORBA::Any *recurse = ri->get_slot(slot); + CORBA::Long x; + *recurse >>= x; + + CORBA::Any flag; + if (x == 0) + { + flag <<= 1; + + pic->set_slot(slot, flag); + + // get server time + std::cout << "Server Time = " << messenger->get_time() << std::endl; + } + // Add this context to the service context list. + ri->add_request_service_context (sc, 0); + + // reset recursion test + flag <<= 0; + pic->set_slot(slot,flag); + +} + +void +ClientInterceptor::receive_reply ( + PortableInterceptor::ClientRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling receive_reply()." << std::endl; +} + +void +ClientInterceptor::receive_other ( + PortableInterceptor::ClientRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling receive_other()." << std::endl; +} + +void +ClientInterceptor::receive_exception ( + PortableInterceptor::ClientRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling receive_exception()." << std::endl; +} + + diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h new file mode 100644 index 00000000000..15b0129df95 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h @@ -0,0 +1,45 @@ +// $Id$ + +#ifndef CLIENTINTERCEPTOR_H +#define CLIENTINTERCEPTOR_H + +#include "tao/PortableInterceptorC.h" +#include "tao/LocalObject.h" +#include "tao/PI/ClientRequestInterceptorA.h" +#include "tao/PI/PICurrentC.h" +#include "MessengerC.h" + +class ClientInterceptor: + public virtual PortableInterceptor::ClientRequestInterceptor, + public virtual ::CORBA::LocalObject +{ + + public: + ClientInterceptor (Messenger_var theMessage, + PortableInterceptor::Current_ptr thePic, + PortableInterceptor::SlotId theSlot); + + virtual ~ClientInterceptor (); + + virtual char * name (); + + virtual void destroy (); + + virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr ri); + + virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri); + + virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri); + + virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr ri); + + virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri); + + private: + const char *myname_; + Messenger_var messenger; + PortableInterceptor::Current_ptr pic; + PortableInterceptor::SlotId slot; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl new file mode 100644 index 00000000000..4474bcc36f9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl @@ -0,0 +1,12 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + + string get_time (); + }; diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp new file mode 100644 index 00000000000..3edbc5d2284 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp @@ -0,0 +1,65 @@ +// $Id$ + +#include "MessengerC.h" +#include "ClientInitializer.h" + +#include "tao/ORBInitializer_Registry.h" +// Ensure that the PI library is linked in when building statically +#include "tao/PI/PI.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + ClientInitializer* temp_initializer = new ClientInitializer; + + PortableInterceptor::ORBInitializer_var orb_initializer = + temp_initializer; + + PortableInterceptor::register_orb_initializer (orb_initializer.in ()); + + CORBA::ORB_var orb = CORBA::ORB_init (argc, argv, "Client ORB"); + + // Now that the ORB is initialized (and subsequently the + // PICurrent), we can set the slot data on the PICurrent for our + // interceptor initializer. + temp_initializer->set_slot_data (); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references( "NameService" ); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow( naming_obj.in() ); + if ( CORBA::is_nil(root.in() ) ) { + std::cerr << "Couldn't find Naming Service." << std::endl; + return 1; + } + + // get Messenger + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup( "Messenger" ); + + CORBA::Object_var obj = root->resolve( name ); + + Messenger_var messenger = Messenger::_narrow( obj.in() ); + if( CORBA::is_nil( messenger.in() ) ) { + std::cerr << "Not a Messenger reference" << std::endl; + return 1; + } + + CORBA::String_var message = CORBA::string_dup( "Hello!" ); + messenger->send_message( "TAO User", "TAO Test", message.inout() ); + + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp new file mode 100644 index 00000000000..4d57232a4ef --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp @@ -0,0 +1,75 @@ +// $Id$ + +#include "Messenger_i.h" +#include "MessengerS.h" +#include "ServerInitializer.h" + +#include "tao/ORBInitializer_Registry.h" +// Ensure that the PI_Server library is linked in when building statically +#include "tao/PI_Server/PI_Server.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + ServerInitializer *temp_initializer = 0; + temp_initializer = new ServerInitializer; + + PortableInterceptor::ORBInitializer_var orb_initializer = + temp_initializer; + + PortableInterceptor::register_orb_initializer (orb_initializer.in ()); + + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv, "Server ORB"); + + //Get reference to Root POA + CORBA::Object_var obj = orb->resolve_initial_references( "RootPOA" ); + PortableServer::POA_var poa = PortableServer::POA::_narrow( obj.in() ); + + // Activate POA Manager + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + // Create an object + Messenger_i messenger_servant; + + // Find the Naming Service + CORBA::Object_var naming_obj = + orb->resolve_initial_references( "NameService" ); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow( naming_obj.in() ); + if( CORBA::is_nil( root.in() ) ) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Bind Messenger + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup( "Messenger" ); + + PortableServer::ObjectId_var oid = + poa->activate_object( &messenger_servant ); + CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() ); + + root->rebind(name, messenger_obj.in()); + + std::cout << "Messenger bound in Naming Service" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp new file mode 100644 index 00000000000..f82e4a0decb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp @@ -0,0 +1,55 @@ +/* -*- C++ -*- $Id$ */ + +// ****** Code generated by the The ACE ORB (TAO) IDL Compiler ******* +// TAO and the TAO IDL Compiler have been developed by the Center for +// Distributed Object Computing at Washington University, St. Louis. +// +// Information about TAO is available at: +// http://www.cs.wustl.edu/~schmidt/TAO.html + +#include "Messenger_i.h" +#include "ace/OS_NS_time.h" +#if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY == 1) +#include <iostream> +#else +#include <iostream.h> +#endif + +// Implementation skeleton constructor +Messenger_i::Messenger_i (void) + { + } + +// Implementation skeleton destructor +Messenger_i::~Messenger_i (void) + { + } + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message + ) + + { + //Add your implementation here + std::cerr << "Message from: " << user_name << std::endl; + std::cerr << "Subject: " << subject << std::endl; + std::cerr << "Message: " << message << std::endl; + return 1; + } + +char * Messenger_i::get_time ( + + ) + +{ + time_t thetime; + struct tm * timeinfo; + + ACE_OS::time(&thetime); + timeinfo = ACE_OS::localtime(&thetime); + char *timestring = CORBA::string_dup(ACE_OS::asctime(timeinfo)); + + return timestring; +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h new file mode 100644 index 00000000000..b072109812c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h @@ -0,0 +1,41 @@ +/* -*- C++ -*- $Id$ */ + +// ****** Code generated by the The ACE ORB (TAO) IDL Compiler ******* +// TAO and the TAO IDL Compiler have been developed by the Center for +// Distributed Object Computing at Washington University, St. Louis. +// +// Information about TAO is available at: +// http://www.cs.wustl.edu/~schmidt/TAO.html + +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include "MessengerS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +//Class Messenger_i +class Messenger_i : public virtual POA_Messenger +{ +public: + //Constructor + Messenger_i (void); + + //Destructor + virtual ~Messenger_i (void); + +virtual CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ); + +virtual char * get_time ( + + ); + +}; + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc new file mode 100644 index 00000000000..3b5134a0f34 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc @@ -0,0 +1,40 @@ +// $Id$ + +project(*idl): taoidldefaults { + IDL_Files { + Messenger.idl + } + custom_only = 1 +} + +project(*Server): taoserver, namingexe, pi_server, avoids_minimum_corba { + exename = MessengerServer + after += *idl + Source_Files { + Messenger_i.cpp + ServerInitializer.cpp + ServerInterceptor.cpp + MessengerServer.cpp + } + Source_Files { + MessengerC.cpp + MessengerS.cpp + } + IDL_Files { + } +} + +project(*Client): taoclient, namingexe, pi, avoids_minimum_corba, interceptors { + exename = MessengerClient + after += *idl + Source_Files { + MessengerClient.cpp + ClientInitializer.cpp + ClientInterceptor.cpp + } + Source_Files { + MessengerC.cpp + } + IDL_Files { + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README new file mode 100644 index 00000000000..4c3a74fe759 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README @@ -0,0 +1,44 @@ +// $Id$ + +Portable Interceptors + + +File: DevGuideExamples/PortableInterceptor/PICurrent_NameService/README + + +This directory contains an example that shows how the PICurrent can +be used to stop client-side interceptor recursions. This example is +identical to the ../PICurrent example but uses the Naming Service. + +This example is based on the Messenger example in GettingStarted +directory. A message is send by MessengerClient and displayed by +MessengerServer. When the client receives a reply, it asks the server +for the current time. This causes a recursive call at the receive_reply() +interception point. A flag is passed in the PICurrent to let the client +know the call is recursive. + +How to Run +---------- + +Start the Naming Service: +------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service \ + -ORBEndpoint iiop://localhost:9876 + +To start the server: +------------------ +./MessengerServer \ + -ORBInitRef NameService=iioploc://localhost:9876/NameService + +To start the client: +------------------ +./MessengerClient \ + -ORBInitRef NameService=iioploc://localhost:9876/NameService + +Execution via Perl Script +------------------------- + +A Perl script has been created to automate the steps shown +above. This script can be run via the following command: + +./run_test.pl diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp new file mode 100644 index 00000000000..95cb35a442e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp @@ -0,0 +1,24 @@ +// $Id$ + +#include "ServerInitializer.h" +#include "ServerInterceptor.h" + +ServerInitializer::ServerInitializer () +{ +} + +void +ServerInitializer::pre_init ( + PortableInterceptor::ORBInitInfo_ptr) +{ +} + +void +ServerInitializer::post_init ( + PortableInterceptor::ORBInitInfo_ptr info) +{ + // Create and register the request interceptors. + PortableInterceptor::ServerRequestInterceptor_var si = + new ServerInterceptor(); + info->add_server_request_interceptor (si.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h new file mode 100644 index 00000000000..bb8a55b1b8a --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h @@ -0,0 +1,23 @@ +// $Id$ + +#ifndef SERVERINITIALIZER_H +#define SERVERINITIALIZER_H + +#include "tao/PortableInterceptorC.h" +#include "tao/PI/PI.h" + +class ServerInitializer : +public virtual PortableInterceptor::ORBInitializer +{ + public: + ServerInitializer (); + + virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info); + + virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info); + + private: + int interceptor_type_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp new file mode 100644 index 00000000000..18367d88c3e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp @@ -0,0 +1,102 @@ +// $Id$ + +#include "ServerInterceptor.h" +#include "tao/PI_Server/ServerRequestInfoA.h" +#include "ace/OS_NS_string.h" +#include <iostream> + +const IOP::ServiceId service_id = 0xdeed; +const unsigned int num_allowed_users = 4; +static const char* allowed_users[num_allowed_users+1] = + {"Ron Klein", "Scott Case", "Mark Hodge", "Greg Black", 0}; +const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"}; + +ServerInterceptor::ServerInterceptor (void) + : myname_ ("Server_Authentication_Interceptor") +{ + std::cout << "Calling ServerInterceptor constructor." << std::endl; +} + +ServerInterceptor::~ServerInterceptor () +{ +} + +char * +ServerInterceptor::name () +{ + std::cout << "Calling ServerInterceptor name() method" << std::endl; + return CORBA::string_dup (this->myname_); +} + +void +ServerInterceptor::destroy () +{ + std::cout << "Calling destroy()." << std::endl; +} + +void +ServerInterceptor::receive_request_service_contexts ( + PortableInterceptor::ServerRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling receive_request_service_contexts()." << std::endl; +} + +void +ServerInterceptor::receive_request ( + PortableInterceptor::ServerRequestInfo_ptr ri) +{ + bool permission_granted = false; + std::cout << "Calling receive_request()." << std::endl; + + if (ri->target_is_a(restricted_interfaces[0])){ + IOP::ServiceId id = service_id; + // Check that the request service context can be retrieved. + IOP::ServiceContext_var sc = + ri->get_request_service_context (id); + + CORBA::OctetSeq ocSeq = sc->context_data; + + const char * buf = + reinterpret_cast<const char *> (ocSeq.get_buffer ()); + + for (unsigned int i=0; i<num_allowed_users; ++i) { + if (ACE_OS::strcmp (buf, allowed_users[i]) == 0) + { + permission_granted = true; + } + } + } + + if (permission_granted == true) { + std::cout << "Permission Granted " << std::endl; + } + else { + std::cout << "Permission Denied " << std::endl;; + } +} + +void +ServerInterceptor::send_reply ( + PortableInterceptor::ServerRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling send_reply()." << std::endl; +} + +void +ServerInterceptor::send_exception ( + PortableInterceptor::ServerRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling send_exception()." << std::endl; +} + +void +ServerInterceptor::send_other ( + PortableInterceptor::ServerRequestInfo_ptr ri) +{ + ACE_UNUSED_ARG(ri); + std::cout << "Calling send_other()." << std::endl; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h new file mode 100644 index 00000000000..ca4732c5075 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h @@ -0,0 +1,36 @@ +// $Id$ + +#ifndef SERVERINTERCEPTOR_H +#define SERVERINTERCEPTOR_H + +#include "tao/PortableInterceptorC.h" +#include "tao/PI_Server/ServerRequestInterceptorA.h" + +class ServerInterceptor +: public PortableInterceptor::ServerRequestInterceptor +{ + public: + ServerInterceptor (void); + + ~ServerInterceptor (); + + virtual char * name (); + + virtual void destroy (); + + virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri); + + virtual void receive_request_service_contexts ( + PortableInterceptor::ServerRequestInfo_ptr ri); + + virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri); + + virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri); + + virtual void send_other (PortableInterceptor::ServerRequestInfo_ptr ri); + + private: + const char *myname_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl new file mode 100644 index 00000000000..a69fe278929 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl @@ -0,0 +1,48 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +unlink $nsiorfile; +$PORT=9876; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile -ORBEndpoint iiop://localhost:$PORT"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, $PerlACE::wait_interval_for_process_creation) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start MessengerServer +$IREF = "-ORBInitRef NameService=iioploc://localhost:$PORT/NameService"; + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $IREF); +$S->Spawn(); + +# start MessengerClient +sleep(1); +$C = new PerlACE::Process("MessengerClient", $IREF); +if ($C->SpawnWaitKill(15) != 0) { + $S->Kill(); + $NS->Kill(); + exit(1); +} +# clean-up + +$S->Kill(); +$NS->Kill(); + +exit 0; + + + |