summaryrefslogtreecommitdiff
path: root/TAO/DevGuideExamples/PortableInterceptors
diff options
context:
space:
mode:
authorAbdullah Sowayan <sowayan@users.noreply.github.com>2008-10-21 20:47:43 +0000
committerAbdullah Sowayan <sowayan@users.noreply.github.com>2008-10-21 20:47:43 +0000
commitd2911d5b9eb897d3da7d458ebf5ba8b998bc7763 (patch)
tree3158327d3787df5b439329fac177f20a12857c62 /TAO/DevGuideExamples/PortableInterceptors
parentf8ea2bc5a4d98525f6f290d8272663e46aa1de74 (diff)
downloadATCD-d2911d5b9eb897d3da7d458ebf5ba8b998bc7763.tar.gz
Tue Oct 21 19:10:21 UTC 2008 Abdullah Sowayan <abdullah.sowayan@lmco.com>
Diffstat (limited to 'TAO/DevGuideExamples/PortableInterceptors')
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/Auth.mpc17
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.cpp36
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.h19
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.cpp96
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.h46
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger.idl9
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerClient.cpp50
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerServer.cpp59
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.cpp43
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.h41
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/README36
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.cpp44
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.h23
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.cpp116
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.h45
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/Auth/run_test.pl36
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.cpp45
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.h21
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.cpp123
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.h48
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/IOR.mpc18
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger.idl6
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerClient.cpp84
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerServer.cpp59
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.cpp75
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.h29
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/README35
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.cpp40
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.h50
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.cpp32
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.h23
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.cpp125
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.h47
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/IOR/run_test.pl37
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.cpp56
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.h25
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.cpp109
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.h43
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger.idl10
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerClient.cpp52
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerServer.cpp63
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.cpp51
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.h37
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/PICurrent.mpc17
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/README34
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.cpp22
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.h21
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.cpp98
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.h34
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent/run_test.pl37
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp70
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h25
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp124
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h53
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl10
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp62
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp72
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp61
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h47
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc17
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README42
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp24
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h23
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp112
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h45
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl46
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.cpp31
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.h21
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.cpp106
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.h49
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger.idl6
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerClient.cpp85
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerServer.cpp61
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.cpp74
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.h28
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/README36
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.cpp27
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.h23
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.cpp126
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.h47
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/SimpleCode.mpc17
-rw-r--r--TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/run_test.pl36
82 files changed, 3928 insertions, 0 deletions
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/Auth.mpc b/TAO/DevGuideExamples/PortableInterceptors/Auth/Auth.mpc
new file mode 100644
index 00000000000..eefa89004eb
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/Auth.mpc
@@ -0,0 +1,17 @@
+project(*Server): taoexe, portableserver, namingexe, pi_server, avoids_minimum_corba {
+ Source_Files {
+ Messenger_i.cpp
+ ServerInitializer.cpp
+ ServerInterceptor.cpp
+ MessengerServer.cpp
+ }
+}
+
+project(*Client): taoexe, namingexe, pi, avoids_minimum_corba, interceptors {
+ Source_Files {
+ MessengerC.cpp
+ MessengerClient.cpp
+ ClientInitializer.cpp
+ ClientInterceptor.cpp
+ }
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.cpp
new file mode 100644
index 00000000000..816f42d67e0
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.cpp
@@ -0,0 +1,36 @@
+#include "ClientInitializer.h"
+#include "ClientInterceptor.h"
+#include <iostream>
+
+ClientInitializer::ClientInitializer (void)
+{
+}
+
+void
+ClientInitializer::pre_init (PortableInterceptor::ORBInitInfo_ptr)
+{
+}
+
+void
+ClientInitializer::post_init (PortableInterceptor::ORBInitInfo_ptr info)
+{
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ClientRequestInterceptor_ptr ci =
+ PortableInterceptor::ClientRequestInterceptor::_nil ();
+
+ try
+ {
+ ci = new ClientInterceptor();
+ }
+ catch(...)
+ {
+ std::cerr << "Exception ocurred creating ClientInterceptor" << std::endl;
+ }
+
+ PortableInterceptor::ClientRequestInterceptor_var ci_interceptor =
+ ci;
+
+ info->add_client_request_interceptor (ci_interceptor.in ());
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.h
new file mode 100644
index 00000000000..ffd77584d39
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInitializer.h
@@ -0,0 +1,19 @@
+#ifndef CLIENTINITIALIZER_H
+#define CLIENTINITIALIZER_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/PI.h"
+
+class ClientInitializer :
+ public virtual PortableInterceptor::ORBInitializer,
+ public virtual TAO_Local_RefCounted_Object
+{
+public:
+ ClientInitializer (void);
+ virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info);
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info);
+};
+
+#endif
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.cpp
new file mode 100644
index 00000000000..21cd2e19be7
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.cpp
@@ -0,0 +1,96 @@
+#include "ClientInterceptor.h"
+#include <tao/OctetSeqC.h>
+#include <tao/PI/ClientRequestInfo.h>
+#include <ace/OS_NS_string.h>
+#include <iostream>
+
+const CORBA::ULong service_ctx_id = 0xdeed;
+
+ClientInterceptor::
+ClientInterceptor (void)
+ : myname_ ("Client_Authentication_Interceptor")
+{
+ std::cout << "Calling ClientInterceptor constructor." << std::endl;
+}
+
+ClientInterceptor::~ClientInterceptor (void)
+{
+}
+
+char *
+ClientInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ClientInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ClientInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInterceptor::send_poll (
+ PortableInterceptor::ClientRequestInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling send_poll()." << std::endl;
+}
+
+
+void
+ClientInterceptor::send_request (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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);
+
+ // Add this context to the service context list.
+ ri->add_request_service_context (sc, 0);
+
+}
+
+void
+ClientInterceptor::receive_reply (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_reply()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_other (
+ PortableInterceptor::ClientRequestInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ std::cout << "Calling receive_other()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_exception (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_exception()." << std::endl;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.h
new file mode 100644
index 00000000000..4882eaac54c
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ClientInterceptor.h
@@ -0,0 +1,46 @@
+#ifndef CLIENTINTERCEPTOR_H
+#define CLIENTINTERCEPTOR_H
+
+#include <tao/PortableInterceptorC.h>
+#include <tao/LocalObject.h>
+#include <tao/PI/PI.h>
+
+class ClientInterceptor
+: public virtual PortableInterceptor::ClientRequestInterceptor,
+ public virtual TAO_Local_RefCounted_Object
+{
+
+ public:
+ ClientInterceptor (void);
+
+ virtual ~ClientInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger.idl b/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger.idl
new file mode 100644
index 00000000000..aaedd932648
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger.idl
@@ -0,0 +1,9 @@
+// messenger.idl
+
+interface Messenger
+ {
+ boolean send_message ( in string user_name,
+ in string subject,
+ inout string message );
+ };
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerClient.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerClient.cpp
new file mode 100644
index 00000000000..9c3ddf77134
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerClient.cpp
@@ -0,0 +1,50 @@
+#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
+main (int argc, char *argv[])
+{
+ try
+ {
+ PortableInterceptor::ORBInitializer_ptr temp_initializer =
+ PortableInterceptor::ORBInitializer::_nil ();
+
+ 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");
+
+ CORBA::Object_var obj = orb->string_to_object( "file://Messenger.ior" );
+
+ if ( CORBA::is_nil(obj.in() ) ) {
+ std::cerr << "Nil Messenger reference" << std::endl;
+ return 1;
+ }
+
+ 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/DevGuideExamples/PortableInterceptors/Auth/MessengerServer.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerServer.cpp
new file mode 100644
index 00000000000..5a9757a9655
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/MessengerServer.cpp
@@ -0,0 +1,59 @@
+#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 <iostream>
+#include <fstream>
+int
+main (int argc, char *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;
+
+ PortableServer::ObjectId_var oid =
+ poa->activate_object( &messenger_servant );
+ CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
+
+ CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
+ std::ofstream iorFile ( "Messenger.ior" );
+ iorFile << str.in() << std::endl;
+ iorFile.close();
+ std::cout << std::endl << "IOR written to file Messenger.ior" << 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/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.cpp
new file mode 100644
index 00000000000..41786a4e1c8
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.cpp
@@ -0,0 +1,43 @@
+/* -*- 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"
+#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
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+
+{
+ //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;
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.h b/TAO/DevGuideExamples/PortableInterceptors/Auth/Messenger_i.h
new file mode 100644
index 00000000000..99ceb257dfd
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/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
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ));
+
+};
+
+
+#endif /* MESSENGERI_H_ */
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/README b/TAO/DevGuideExamples/PortableInterceptors/Auth/README
new file mode 100644
index 00000000000..6b6ce299369
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/README
@@ -0,0 +1,36 @@
+Portable Interceptors
+
+
+File: DevGuideExamples/PortableInterceptor/Auth/README
+
+
+This directory contains an example illustrating client and server
+Request Interceptors.
+
+This is a simple insecure authentication example that is based on
+the Messenger example in GettingStarted directory. A message is
+sent by MessengerClient and displayed by MessengerServer. A client-side
+portable interceptor adds a username to each request sent to the server.
+A server-side interceptor verifies that the supplied username is valid.
+
+How to Run
+----------
+
+To start the server:
+------------------
+./MessengerServer
+
+
+To start the client:
+------------------
+./MessengerClient
+
+
+
+Exeuction 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/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.cpp
new file mode 100644
index 00000000000..e22e1af87f0
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.cpp
@@ -0,0 +1,44 @@
+#include "ServerInitializer.h"
+#include "ServerInterceptor.h"
+
+#if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY == 1)
+#include <iostream>
+#else
+#include <iostream.h>
+#endif
+
+ServerInitializer::ServerInitializer ()
+{
+}
+
+void
+ServerInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ServerInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ServerRequestInterceptor_ptr si =
+ PortableInterceptor::ServerRequestInterceptor::_nil ();
+
+ try
+ {
+ si = new ServerInterceptor ();
+ }
+ catch(...)
+ {
+ std::cerr << "Exception occured trying to create ServerInterceptor." << std::endl;
+ }
+
+ PortableInterceptor::ServerRequestInterceptor_var si_interceptor =
+ si;
+
+ info->add_server_request_interceptor (si_interceptor.in ());
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.h
new file mode 100644
index 00000000000..f07b7821cb2
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInitializer.h
@@ -0,0 +1,23 @@
+#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)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ private:
+ int interceptor_type_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.cpp
new file mode 100644
index 00000000000..04b4e47f498
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.cpp
@@ -0,0 +1,116 @@
+#include "ServerInterceptor.h"
+#include <tao/PI_Server/ServerRequestInfoA.h>
+#include <ace/OS_NS_string.h>
+#if defined (ACE_HAS_STANDARD_CPP_LIBRARY) && (ACE_HAS_STANDARD_CPP_LIBRARY == 1)
+#include <iostream>
+#else
+#include <iostream.h>
+#endif
+
+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 ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ServerInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ServerInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling destroy()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_request_service_contexts()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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;
+ throw CORBA::NO_PERMISSION();
+ }
+}
+
+void
+ServerInterceptor::send_reply (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_reply()." << std::endl;
+}
+
+void
+ServerInterceptor::send_exception (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_exception()." << std::endl;
+}
+
+void
+ServerInterceptor::send_other (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_other()." << std::endl;
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.h
new file mode 100644
index 00000000000..d0eb11ee704
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/ServerInterceptor.h
@@ -0,0 +1,45 @@
+#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 ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/Auth/run_test.pl b/TAO/DevGuideExamples/PortableInterceptors/Auth/run_test.pl
new file mode 100644
index 00000000000..8804f7ba6d8
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/Auth/run_test.pl
@@ -0,0 +1,36 @@
+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;
+
+# start MessengerServer
+my($iorfile) = 'Messenger.ior';
+$S = new PerlACE::Process("MessengerServer");
+$S->Spawn();
+if (PerlACE::waitforfile_timed (
+ $iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill();
+ exit(1);
+}
+
+# start MessengerClient
+select undef, undef, undef, .5;
+$C = new PerlACE::Process("MessengerClient");
+
+if ($C->SpawnWaitKill(15) != 0) {
+ $S->Kill();
+ exit (1);
+}
+
+# clean-up
+$S->Kill();
+
+exit 0;
+
+
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.cpp
new file mode 100644
index 00000000000..6abd46ca4c0
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.cpp
@@ -0,0 +1,45 @@
+#include "ClientInitializer.h"
+#include "ClientInterceptor.h"
+#include <iostream>
+
+ClientInitializer::ClientInitializer (void)
+{
+}
+
+void
+ClientInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr
+ )
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info
+ )
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+
+ // get Codec factory
+ IOP::CodecFactory_var codec_factory = info->codec_factory();
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ClientRequestInterceptor_ptr ci =
+ PortableInterceptor::ClientRequestInterceptor::_nil ();
+
+ try
+ {
+ ci = new ClientInterceptor (codec_factory);
+ }
+ catch(...)
+ {
+ std::cerr << "Exception occurred trying to create ClientInterceptor." << std::endl;
+ }
+
+ PortableInterceptor::ClientRequestInterceptor_var ci_interceptor =
+ ci;
+
+ info->add_client_request_interceptor (ci_interceptor.in ());
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.h
new file mode 100644
index 00000000000..9536c6ce776
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInitializer.h
@@ -0,0 +1,21 @@
+#ifndef CLIENTINITIALIZER_H
+#define CLIENTINITIALIZER_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/PI.h"
+
+class ClientInitializer :
+ public virtual PortableInterceptor::ORBInitializer,
+ public virtual TAO_Local_RefCounted_Object
+{
+ public:
+ ClientInitializer (void);
+ virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+};
+
+#endif
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.cpp
new file mode 100644
index 00000000000..c919423a0eb
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.cpp
@@ -0,0 +1,123 @@
+#include "ClientInterceptor.h"
+#include "tao/OctetSeqC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/ClientRequestInfo.h"
+
+#include <iostream>
+
+const CORBA::ULong service_ctx_id = 0xdeed;
+
+ClientInterceptor::
+ClientInterceptor (IOP::CodecFactory_var cf)
+ : myname_ ("Client_Authentication_Interceptor")
+{
+ std::cout << "Calling ClientInterceptor constructor." << std::endl;
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ this->codec = cf->create_codec (encoding);
+}
+
+ClientInterceptor::~ClientInterceptor (void)
+{
+}
+
+char *
+ClientInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ClientInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ClientInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInterceptor::send_poll (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_poll()." << std::endl;
+}
+
+
+void
+ClientInterceptor::send_request (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ std::cout << "Calling send_request()." << std::endl;
+
+ const CORBA::ULong tagID = 9654;
+
+ try
+ {
+ IOP::TaggedComponent_var myTag = ri->get_effective_component(tagID);
+ char *tag =
+ reinterpret_cast<char*> (myTag->component_data.get_buffer());
+
+ std::cout << "IOR Tag is : " << tag << std::endl;
+ }
+ catch(...)
+ {
+ std::cerr << "Tagged Component not found" << std::endl;
+ }
+
+ IOP::ServiceContext sc;
+ sc.context_id = service_ctx_id;
+
+ const CORBA::Long gid = 9007;
+
+ std::cout << "GID: " << gid << std::endl;
+
+ CORBA::Any gid_as_any;
+ gid_as_any <<= gid;
+
+ sc.context_data = reinterpret_cast<CORBA::OctetSeq&>(
+ *codec->encode(gid_as_any));
+
+ // Add this context to the service context list.
+ ri->add_request_service_context (sc, 0);
+
+}
+
+void
+ClientInterceptor::receive_reply (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_reply()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_other (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_other()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_exception (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_exception()." << std::endl;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.h
new file mode 100644
index 00000000000..445a601d082
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ClientInterceptor.h
@@ -0,0 +1,48 @@
+#ifndef CLIENTINTERCEPTOR_H
+#define CLIENTINTERCEPTOR_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/ClientRequestInterceptorA.h"
+#include "tao/PI/ORBInitInfo.h"
+
+class ClientInterceptor:
+ public virtual PortableInterceptor::ClientRequestInterceptor,
+ public virtual TAO_Local_RefCounted_Object
+{
+
+ public:
+ ClientInterceptor (IOP::CodecFactory_var) ;
+
+ virtual ~ClientInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+ IOP::Codec_var codec;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/IOR.mpc b/TAO/DevGuideExamples/PortableInterceptors/IOR/IOR.mpc
new file mode 100644
index 00000000000..cc7e4118767
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/IOR.mpc
@@ -0,0 +1,18 @@
+project(*Server): taoexe, portableserver, pi_server, avoids_minimum_corba, iorinterceptor {
+ Source_Files {
+ Messenger_i.cpp
+ MessengerServer.cpp
+ ServerInitializer.cpp
+ ServerInterceptor.cpp
+ ServerIORInterceptor.cpp
+ }
+}
+
+project(*Client): taoexe, pi, avoids_minimum_corba, interceptors {
+ Source_Files {
+ MessengerC.cpp
+ MessengerClient.cpp
+ ClientInitializer.cpp
+ ClientInterceptor.cpp
+ }
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger.idl b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger.idl
new file mode 100644
index 00000000000..f2a0074c1e8
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger.idl
@@ -0,0 +1,6 @@
+#include "orb.idl"
+
+interface Messenger
+{
+ void send_message(in CORBA::OctetSeq user_name);
+};
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerClient.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerClient.cpp
new file mode 100644
index 00000000000..f60cd3143ed
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerClient.cpp
@@ -0,0 +1,84 @@
+#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 <iostream>
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ PortableInterceptor::ORBInitializer_ptr temp_initializer =
+ PortableInterceptor::ORBInitializer::_nil ();
+
+ temp_initializer = new ClientInitializer;
+
+ PortableInterceptor::ORBInitializer_var orb_initializer =
+ temp_initializer;
+
+ PortableInterceptor::register_orb_initializer (orb_initializer.in ());
+
+ // Initialize orb
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
+
+ // Destringify ior
+ CORBA::Object_var obj = orb->string_to_object( "file://Messenger.ior" );
+ if( CORBA::is_nil( obj.in() ) ) {
+ std::cerr << "Nil Messenger reference" << std::endl;
+ return 1;
+ }
+
+ // Narrow
+ Messenger_var messenger = Messenger::_narrow( obj.in() );
+ if( CORBA::is_nil( messenger.in() ) ) {
+ std::cerr << "Argument is not a Messenger reference" << std::endl;
+ return 1;
+ }
+
+ // Obtain a reference to the CodecFactory.
+ CORBA::Object_var obj2 =
+ orb->resolve_initial_references ("CodecFactory");
+
+ IOP::CodecFactory_var codec_factory;
+
+ if(CORBA::is_nil(obj2.in()))
+ {
+ std::cerr << "Error: codec_factory" << std::endl;
+ ACE_OS::exit(1);
+ }
+ else
+ {
+ codec_factory = IOP::CodecFactory::_narrow (obj2.in ());
+ std::cout << "got codec factory" << std::endl;
+ }
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ IOP::Codec_var codec =
+ codec_factory->create_codec (encoding);
+
+ CORBA::Long uid = 64321;
+
+ CORBA::Any uid_as_any;
+
+ uid_as_any <<= uid;
+ CORBA::OctetSeq client_uid = *codec->encode (uid_as_any);
+ messenger->send_message( client_uid );
+ }
+
+ catch(const CORBA::Exception& ex)
+ {
+ std::cerr << "Exception in MessengerClient: " << ex << std::endl;
+ return 1;
+ }
+
+ std::cout << "message was sent" << std::endl;
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerServer.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerServer.cpp
new file mode 100644
index 00000000000..03493a5c5af
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/MessengerServer.cpp
@@ -0,0 +1,59 @@
+#include "Messenger_i.h"
+#include "MessengerC.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 <iostream>
+#include <fstream>
+
+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 ());
+
+ // Initialize orb
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
+
+ //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;
+
+ // Register the servant with the RootPOA, obtain its object
+ // reference, stringify it, and write it to a file.
+ PortableServer::ObjectId_var oid =
+ poa->activate_object( &messenger_servant );
+ CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
+ CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
+ std::ofstream iorFile( "Messenger.ior" );
+ iorFile << str.in() << std::endl;
+ iorFile.close();
+ std::cout << "IOR written to file Messenger.ior" << std::endl;
+
+ // Accept requests
+ orb->run();
+ orb->destroy();
+ }
+
+ catch(const CORBA::Exception& ex)
+ {
+ std::cerr << "Exception in MessengerServer: " << ex << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.cpp
new file mode 100644
index 00000000000..eb4520c600b
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.cpp
@@ -0,0 +1,75 @@
+#include <tao/CodecFactory/CodecFactory.h>
+#include <ace/OS_NS_string.h>
+#include <iostream>
+#include "Messenger_i.h"
+
+
+// Implementation skeleton constructor
+Messenger_i::Messenger_i (void)
+{
+}
+
+// Implementation skeleton destructor
+Messenger_i::~Messenger_i (void)
+{
+}
+
+
+void Messenger_i::send_message (const CORBA::OctetSeq & user_name)
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+{
+ try
+ {
+ int argc = 1;
+ char **argv = new char *[argc];
+ argv[0] = new char[ACE_OS::strlen ("MessengerServer")];
+ strcpy (argv[0], "MessengerServer");
+
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
+
+ // Obtain a reference to the CodecFactory.
+ CORBA::Object_var obj =
+ orb->resolve_initial_references ("CodecFactory");
+
+ IOP::CodecFactory_var codec_factory;
+
+ if(CORBA::is_nil(obj.in()))
+ {
+ std::cerr << "Error: codec_factory" << std::endl;
+ ACE_OS::exit(1);
+ }
+ else
+ {
+ codec_factory = IOP::CodecFactory::_narrow (obj.in ());
+ std::cout << "Server got codec factory" << std::endl;
+ }
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ IOP::Codec_var codec =
+ codec_factory->create_codec (encoding);
+
+ CORBA::Any uid_as_any;
+ uid_as_any = *(codec->decode(user_name));
+
+ CORBA::Long uid;
+ uid_as_any >>= uid;
+ std::cout << "UID: " << uid << std::endl;
+
+ }
+
+ catch(...)
+ {
+ std::cerr << "exception received" << std::endl;
+ ACE_OS::exit(1);
+ }
+
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.h
new file mode 100644
index 00000000000..dc3e46058f5
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/Messenger_i.h
@@ -0,0 +1,29 @@
+#ifndef MESSENGER_I_H_
+#define MESSENGER_I_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 void send_message (const CORBA::OctetSeq & user_name)
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ));
+
+};
+
+
+#endif /* MESSENGERI_H_ */
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/README b/TAO/DevGuideExamples/PortableInterceptors/IOR/README
new file mode 100644
index 00000000000..1fc72cbf7f4
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/README
@@ -0,0 +1,35 @@
+Portable Interceptors
+
+
+File: DevGuideExamples/PortableInterceptor/IOR/README
+
+
+This directory contains an example of using portable interceptors to add
+tagged information to an IOR.
+
+This example is based on the Messenger example in GettingStarted
+directory. A message is send by MessengerClient and displayed by
+MessengerServer. On IOR creation, the server has added a special
+tag "ServerRequiresAuth". The client is able to extract this tag.
+
+
+How to Run
+----------
+
+To start the server:
+------------------
+./MessengerServer
+
+
+To start the client:
+------------------
+./MessengerClient
+
+
+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/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.cpp
new file mode 100644
index 00000000000..43ad1333ee6
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.cpp
@@ -0,0 +1,40 @@
+#include "ServerIORInterceptor.h"
+#include <iostream>
+char *
+ServerIORInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ return CORBA::string_dup ("ServerIORInterceptor");
+}
+
+void
+ServerIORInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ServerIORInterceptor::establish_components (
+ PortableInterceptor::IORInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+
+ const char * permission = "ServerRequiresAuth";
+
+ // arbitrary tag.
+ CORBA::ULong tagID = 9654;
+
+ IOP::TaggedComponent myTag;
+
+ myTag.tag = tagID;
+ myTag.component_data.length (ACE_OS::strlen(permission) + 1 );
+
+ CORBA::Octet *buf = myTag.component_data.get_buffer();
+
+ ACE_OS::memcpy (buf, permission, ACE_OS::strlen(permission) + 1);
+
+ // add tagged component
+ info->add_ior_component (myTag);
+
+ std::cout << "Created Tagged IOR." << std::endl;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.h
new file mode 100644
index 00000000000..9dd6c080b45
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerIORInterceptor.h
@@ -0,0 +1,50 @@
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/IORInterceptor_Adapter.h"
+#include "tao/IORInterceptor/IORInterceptor.h"
+
+class ServerIORInterceptor :
+public virtual PortableInterceptor::IORInterceptor,
+public virtual TAO_Local_RefCounted_Object
+{
+ public:
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void establish_components (
+ PortableInterceptor::IORInfo_ptr info
+ )
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void components_established (
+ PortableInterceptor::IORInfo_ptr /*info*/
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+ {
+ }
+
+ virtual void adapter_manager_state_changed (
+ PortableInterceptor::AdapterManagerId /*id*/,
+ PortableInterceptor::AdapterState /*state*/
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+ {
+ }
+
+ virtual void adapter_state_changed (
+ const PortableInterceptor::ObjectReferenceTemplateSeq& /*templates*/,
+ PortableInterceptor::AdapterState /*state*/
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+ {
+ }
+};
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.cpp
new file mode 100644
index 00000000000..b275cf004ea
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.cpp
@@ -0,0 +1,32 @@
+#include "ServerInitializer.h"
+#include "ServerInterceptor.h"
+#include "ServerIORInterceptor.h"
+
+ServerInitializer::ServerInitializer ()
+{
+}
+
+void
+ServerInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ServerInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ // get reference to the codec_factory
+ IOP::CodecFactory_var codec_factory = info->codec_factory();
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ServerRequestInterceptor_var si =
+ new ServerInterceptor (codec_factory);
+ info->add_server_request_interceptor (si.in());
+
+ // add IOR Interceptor
+ PortableInterceptor::IORInterceptor_var iori = new ServerIORInterceptor;
+ info->add_ior_interceptor (iori.in());
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.h
new file mode 100644
index 00000000000..f07b7821cb2
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInitializer.h
@@ -0,0 +1,23 @@
+#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)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ private:
+ int interceptor_type_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.cpp
new file mode 100644
index 00000000000..c70299b8523
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.cpp
@@ -0,0 +1,125 @@
+#include "ServerInterceptor.h"
+#include <tao/PI_Server/ServerRequestInfoA.h>
+#include <tao/OctetSeqC.h>
+#include <iostream>
+
+const IOP::ServiceId service_id = 0xdeed;
+const CORBA::Long allowed_gid[4] = { 9006, 9007, 9008 };
+const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"};
+
+ServerInterceptor::ServerInterceptor (IOP::CodecFactory_var cf)
+ : myname_ ("Server_Authentication_Interceptor")
+{
+ std::cout << "Calling ServerInterceptor constructor." << std::endl;
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ this->codec = cf->create_codec (encoding);
+}
+
+ServerInterceptor::~ServerInterceptor ()
+{
+}
+
+char *
+ServerInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ServerInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ServerInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling destroy()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_request_service_contexts()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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);
+ // need to construct an octet seq for decoding
+ CORBA::OctetSeq ocSeq = CORBA::OctetSeq(
+ sc->context_data.length(),
+ sc->context_data.length(),
+ sc->context_data.get_buffer(),
+ 0);
+
+ CORBA::Any gid_as_any;
+ gid_as_any = *codec->decode(ocSeq);
+
+ CORBA::Long gid;
+ gid_as_any >>= gid;
+ for (int i=0; i<3; ++i) {
+ if ( gid == allowed_gid[i] )
+ {
+ permission_granted = true;
+ }
+ }
+ }
+
+ if (permission_granted == true) {
+ std::cout << "Permission Granted " << std::endl;
+ }
+ else {
+ std::cout << "Permission Denied " << std::endl;
+ ACE_THROW_SPEC (CORBA::NO_PERMISSION());
+ }
+}
+
+void
+ServerInterceptor::send_reply (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_reply()." << std::endl;
+}
+
+void
+ServerInterceptor::send_exception (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_exception()." << std::endl;
+}
+
+void
+ServerInterceptor::send_other (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_other()." << std::endl;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.h
new file mode 100644
index 00000000000..abcac4bc9f5
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/ServerInterceptor.h
@@ -0,0 +1,47 @@
+#ifndef SERVERINTERCEPTOR_H
+#define SERVERINTERCEPTOR_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/PI_Server/ServerRequestInterceptorA.h"
+#include "tao/PI/ORBInitInfo.h"
+
+class ServerInterceptor
+: public PortableInterceptor::ServerRequestInterceptor
+{
+ public:
+ ServerInterceptor (IOP::CodecFactory_var);
+
+ ~ServerInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+ IOP::Codec_var codec;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/IOR/run_test.pl b/TAO/DevGuideExamples/PortableInterceptors/IOR/run_test.pl
new file mode 100644
index 00000000000..2bd452196e4
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/IOR/run_test.pl
@@ -0,0 +1,37 @@
+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;
+
+# start MessengerServer
+my($iorfile) = 'Messenger.ior';
+unlink $iorfile;
+
+$S = new PerlACE::Process("MessengerServer");
+$S->Spawn();
+if (PerlACE::waitforfile_timed (
+ $iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill();
+ exit(1);
+}
+
+# start MessengerClient
+select undef, undef, undef, .5;
+$C = new PerlACE::Process("MessengerClient");
+
+if ($C->SpawnWaitKill(15) != 0) {
+ $S->Kill();
+ exit (1);
+}
+
+# clean-up
+$S->Kill();
+
+unlink $iorfile;
+
+exit 0;
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.cpp
new file mode 100644
index 00000000000..0b81911048d
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.cpp
@@ -0,0 +1,56 @@
+#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)
+{
+ // resolve Messenger object
+ CORBA::Object_var obj = info->resolve_initial_references( "Messenger" );
+ 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/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.h
new file mode 100644
index 00000000000..33131f3c1cc
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInitializer.h
@@ -0,0 +1,25 @@
+#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 TAO_Local_RefCounted_Object
+{
+ 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/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.cpp
new file mode 100644
index 00000000000..52454103c10
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.cpp
@@ -0,0 +1,109 @@
+#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::Boolean x;
+ *recurse >>= CORBA::Any::to_boolean(x);
+
+ CORBA::Any flag;
+ if (x == 0)
+ {
+ x = 1;
+ flag <<= CORBA::Any::from_boolean(x);
+
+ 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
+ x = 0;
+ flag <<= CORBA::Any::from_boolean(x);
+ 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/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.h
new file mode 100644
index 00000000000..538460c6e71
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ClientInterceptor.h
@@ -0,0 +1,43 @@
+#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 TAO_Local_RefCounted_Object
+{
+
+ 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/DevGuideExamples/PortableInterceptors/PICurrent/Messenger.idl b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger.idl
new file mode 100644
index 00000000000..ceda3e3e52b
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger.idl
@@ -0,0 +1,10 @@
+// messenger.idl
+
+interface Messenger
+ {
+ boolean send_message ( in string user_name,
+ in string subject,
+ inout string message );
+
+ string get_time ();
+ };
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerClient.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerClient.cpp
new file mode 100644
index 00000000000..f5115a69efb
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerClient.cpp
@@ -0,0 +1,52 @@
+#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
+main (int argc, char *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 obj = orb->string_to_object( "file://Messenger.ior" );
+ if ( CORBA::is_nil(obj.in() ) ) {
+ std::cerr << "Nil Messenger reference" << std::endl;
+ return 1;
+ }
+ // Narrow
+ 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 << "client Caught CORBA exception: " << ex << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerServer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerServer.cpp
new file mode 100644
index 00000000000..ef2f97614c1
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/MessengerServer.cpp
@@ -0,0 +1,63 @@
+#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>
+#include <fstream>
+#include <fstream>
+
+int
+main (int argc, char *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;
+
+ PortableServer::ObjectId_var oid =
+ poa->activate_object( &messenger_servant );
+ CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
+
+ CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
+ std::ofstream iorFile ( "Messenger.ior" );
+ iorFile << str.in() << std::endl;
+ iorFile.close();
+ std::cout << std::endl << "IOR written to file Messenger.ior" << std::endl;
+
+ // Accept requests
+ orb->run();
+ orb->destroy();
+ }
+
+ catch(const CORBA::Exception& ex)
+ {
+ std::cerr << "server Caught CORBA exception: " << ex << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.cpp
new file mode 100644
index 00000000000..866a54c890f
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.cpp
@@ -0,0 +1,51 @@
+/* -*- 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 (void)
+{
+ time_t thetime;
+ struct tm * timeinfo = 0;
+
+ ACE_OS::time(&thetime);
+ timeinfo = ACE_OS::localtime(&thetime);
+ char *timestring = CORBA::string_dup(ACE_OS::asctime(timeinfo));
+
+ return timestring;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.h
new file mode 100644
index 00000000000..c1f0e3daa84
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/Messenger_i.h
@@ -0,0 +1,37 @@
+/* -*- 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 (void);
+};
+
+#endif /* MESSENGERI_H_ */
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/PICurrent.mpc b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/PICurrent.mpc
new file mode 100644
index 00000000000..53d7b4c1085
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/PICurrent.mpc
@@ -0,0 +1,17 @@
+project(*Server): taoexe, portableserver, pi_server, namingexe {
+ Source_Files {
+ Messenger_i.cpp
+ ServerInitializer.cpp
+ ServerInterceptor.cpp
+ MessengerServer.cpp
+ }
+}
+
+project(*Client): taoexe, pi, namingexe, interceptors {
+ Source_Files {
+ MessengerC.cpp
+ MessengerClient.cpp
+ ClientInitializer.cpp
+ ClientInterceptor.cpp
+ }
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent/README b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/README
new file mode 100644
index 00000000000..89211ca7106
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/README
@@ -0,0 +1,34 @@
+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 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
+----------
+
+To start the server:
+------------------
+./MessengerServer
+
+To start the client:
+------------------
+./MessengerClient -ORBInitRef Messenger=file://Messenger.ior
+
+Execuction 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/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.cpp
new file mode 100644
index 00000000000..fc609c531c5
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.cpp
@@ -0,0 +1,22 @@
+#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/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.h
new file mode 100644
index 00000000000..fb880e8b5f4
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInitializer.h
@@ -0,0 +1,21 @@
+#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/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.cpp
new file mode 100644
index 00000000000..8dfb951ba97
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.cpp
@@ -0,0 +1,98 @@
+#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;
+ ACE_THROW_SPEC (CORBA::NO_PERMISSION());
+ }
+}
+
+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/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.h
new file mode 100644
index 00000000000..a8da1affe95
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/ServerInterceptor.h
@@ -0,0 +1,34 @@
+#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/DevGuideExamples/PortableInterceptors/PICurrent/run_test.pl b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/run_test.pl
new file mode 100644
index 00000000000..d31c1b8a2f5
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent/run_test.pl
@@ -0,0 +1,37 @@
+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;
+
+$ior = "Messenger.ior";
+unlink $ior;
+
+# start MessengerServer
+$S = new PerlACE::Process("MessengerServer");
+$S->Spawn();
+if (PerlACE::waitforfile_timed ($ior, 5) == -1) {
+ print STDERR "ERROR: cannot find file $ior\n";
+ $S->Kill();
+ exit 1;
+}
+
+# start MessengerClient
+select undef, undef, undef, .5;
+$C = new PerlACE::Process("MessengerClient", " -ORBInitRef Messenger=file://$ior");
+
+if ($C->SpawnWaitKill(15) != 0) {
+ $S->Kill();
+ exit (1);
+}
+
+# clean-up
+$S->Kill();
+#unlink $ior;
+
+exit 0;
+
+
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp
new file mode 100644
index 00000000000..920ab847cf4
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.cpp
@@ -0,0 +1,70 @@
+#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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h
new file mode 100644
index 00000000000..33131f3c1cc
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInitializer.h
@@ -0,0 +1,25 @@
+#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 TAO_Local_RefCounted_Object
+{
+ 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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp
new file mode 100644
index 00000000000..77792427eba
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.cpp
@@ -0,0 +1,124 @@
+#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 ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ClientInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ClientInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInterceptor::send_poll (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_poll()." << std::endl;
+}
+
+
+void
+ClientInterceptor::send_request (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_reply()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_other (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_other()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_exception (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_exception()." << std::endl;
+}
+
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h
new file mode 100644
index 00000000000..c65e5f0c6df
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ClientInterceptor.h
@@ -0,0 +1,53 @@
+#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 TAO_Local_RefCounted_Object
+{
+
+ public:
+ ClientInterceptor (Messenger_var theMessage,
+ PortableInterceptor::Current_ptr thePic,
+ PortableInterceptor::SlotId theSlot);
+
+ virtual ~ClientInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+ Messenger_var messenger;
+ PortableInterceptor::Current_ptr pic;
+ PortableInterceptor::SlotId slot;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl
new file mode 100644
index 00000000000..ceda3e3e52b
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger.idl
@@ -0,0 +1,10 @@
+// messenger.idl
+
+interface Messenger
+ {
+ boolean send_message ( in string user_name,
+ in string subject,
+ inout string message );
+
+ string get_time ();
+ };
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp
new file mode 100644
index 00000000000..6e2128ba16c
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerClient.cpp
@@ -0,0 +1,62 @@
+#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
+main (int argc, char *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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp
new file mode 100644
index 00000000000..6f7c1f7c21e
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/MessengerServer.cpp
@@ -0,0 +1,72 @@
+#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
+main (int argc, char *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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp
new file mode 100644
index 00000000000..b69a42ab285
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.cpp
@@ -0,0 +1,61 @@
+/* -*- 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
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+
+ {
+ //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 (
+
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+
+{
+ 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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h
new file mode 100644
index 00000000000..46135bf7dd9
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/Messenger_i.h
@@ -0,0 +1,47 @@
+/* -*- 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
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ));
+
+virtual char * get_time (
+
+ )
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ));
+
+};
+
+#endif /* MESSENGERI_H_ */
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc
new file mode 100644
index 00000000000..eefa89004eb
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/PICurrent_NameService.mpc
@@ -0,0 +1,17 @@
+project(*Server): taoexe, portableserver, namingexe, pi_server, avoids_minimum_corba {
+ Source_Files {
+ Messenger_i.cpp
+ ServerInitializer.cpp
+ ServerInterceptor.cpp
+ MessengerServer.cpp
+ }
+}
+
+project(*Client): taoexe, namingexe, pi, avoids_minimum_corba, interceptors {
+ Source_Files {
+ MessengerC.cpp
+ MessengerClient.cpp
+ ClientInitializer.cpp
+ ClientInterceptor.cpp
+ }
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README
new file mode 100644
index 00000000000..04a008c682e
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/README
@@ -0,0 +1,42 @@
+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/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp
new file mode 100644
index 00000000000..4ead54b7746
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.cpp
@@ -0,0 +1,24 @@
+#include "ServerInitializer.h"
+#include "ServerInterceptor.h"
+
+ServerInitializer::ServerInitializer ()
+{
+}
+
+void
+ServerInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ServerInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ // Create and register the request interceptors.
+ PortableInterceptor::ServerRequestInterceptor_var si =
+ new ServerInterceptor();
+ info->add_server_request_interceptor (si.in());
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h
new file mode 100644
index 00000000000..f07b7821cb2
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInitializer.h
@@ -0,0 +1,23 @@
+#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)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ private:
+ int interceptor_type_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp
new file mode 100644
index 00000000000..db1004b8a2f
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.cpp
@@ -0,0 +1,112 @@
+#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 ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ServerInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ServerInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling destroy()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_request_service_contexts()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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;
+ ACE_THROW_SPEC (CORBA::NO_PERMISSION());
+ }
+}
+
+void
+ServerInterceptor::send_reply (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_reply()." << std::endl;
+}
+
+void
+ServerInterceptor::send_exception (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_exception()." << std::endl;
+}
+
+void
+ServerInterceptor::send_other (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_other()." << std::endl;
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h
new file mode 100644
index 00000000000..d0eb11ee704
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/ServerInterceptor.h
@@ -0,0 +1,45 @@
+#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 ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl
new file mode 100644
index 00000000000..4664541b8a4
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl
@@ -0,0 +1,46 @@
+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, 5) == -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;
+
+
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.cpp
new file mode 100644
index 00000000000..8049968e6e6
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.cpp
@@ -0,0 +1,31 @@
+#include "ClientInitializer.h"
+#include "ClientInterceptor.h"
+
+ClientInitializer::ClientInitializer (void)
+{
+}
+
+void
+ClientInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr
+ )
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info
+ )
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+
+ // get Codec factory
+ IOP::CodecFactory_var codec_factory = info->codec_factory();
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ClientRequestInterceptor_var ci =
+ new ClientInterceptor (codec_factory);
+ info->add_client_request_interceptor (ci.in());
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.h
new file mode 100644
index 00000000000..9536c6ce776
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInitializer.h
@@ -0,0 +1,21 @@
+#ifndef CLIENTINITIALIZER_H
+#define CLIENTINITIALIZER_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/PI.h"
+
+class ClientInitializer :
+ public virtual PortableInterceptor::ORBInitializer,
+ public virtual TAO_Local_RefCounted_Object
+{
+ public:
+ ClientInitializer (void);
+ virtual void pre_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+};
+
+#endif
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.cpp
new file mode 100644
index 00000000000..16112bba847
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.cpp
@@ -0,0 +1,106 @@
+#include "ClientInterceptor.h"
+#include "tao/OctetSeqC.h"
+#include "tao/PI/ClientRequestInfo.h"
+#include <iostream>
+
+const CORBA::ULong service_ctx_id = 0xdeed;
+
+ClientInterceptor::
+ClientInterceptor (IOP::CodecFactory_var cf)
+ : myname_ ("Client_Authentication_Interceptor")
+{
+ std::cout << "Calling ClientInterceptor constructor." << std::endl;
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ this->codec = cf->create_codec (encoding);
+
+}
+
+ClientInterceptor::~ClientInterceptor (void)
+{
+}
+
+char *
+ClientInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ClientInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ClientInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ClientInterceptor::send_poll (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_poll()." << std::endl;
+}
+
+
+void
+ClientInterceptor::send_request (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ std::cout << "Calling send_request()." << std::endl;
+
+ IOP::ServiceContext sc;
+ sc.context_id = service_ctx_id;
+
+ const CORBA::Long gid = 9007;
+ std::cout << "GID: " << gid << std::endl;
+
+ CORBA::Any gid_as_any;
+ gid_as_any <<= gid;
+
+ sc.context_data = reinterpret_cast<CORBA::OctetSeq&> (
+ *codec->encode(gid_as_any));
+
+ // Add this context to the service context list.
+ ri->add_request_service_context (sc, 0);
+
+}
+
+void
+ClientInterceptor::receive_reply (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_reply()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_other (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_other()." << std::endl;
+}
+
+void
+ClientInterceptor::receive_exception (
+ PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling receive_exception()." << std::endl;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.h
new file mode 100644
index 00000000000..a8bed32eb50
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ClientInterceptor.h
@@ -0,0 +1,49 @@
+#ifndef CLIENTINTERCEPTOR_H
+#define CLIENTINTERCEPTOR_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/LocalObject.h"
+#include "tao/PI/ClientRequestInterceptorA.h"
+#include "tao/PI/ORBInitInfo.h"
+
+class ClientInterceptor:
+ public virtual PortableInterceptor::ClientRequestInterceptor,
+ public virtual TAO_Local_RefCounted_Object
+{
+
+ public:
+ ClientInterceptor (IOP::CodecFactory_var) ;
+
+ virtual ~ClientInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_poll (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_request (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_other (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+ IOP::Codec_var codec;
+
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger.idl b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger.idl
new file mode 100644
index 00000000000..f2a0074c1e8
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger.idl
@@ -0,0 +1,6 @@
+#include "orb.idl"
+
+interface Messenger
+{
+ void send_message(in CORBA::OctetSeq user_name);
+};
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerClient.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerClient.cpp
new file mode 100644
index 00000000000..3ee545b3f3a
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerClient.cpp
@@ -0,0 +1,85 @@
+#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 <iostream>
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR *argv[])
+{
+ try
+ {
+ PortableInterceptor::ORBInitializer_ptr temp_initializer =
+ PortableInterceptor::ORBInitializer::_nil ();
+
+ temp_initializer = new ClientInitializer;
+
+ PortableInterceptor::ORBInitializer_var orb_initializer =
+ temp_initializer;
+
+ PortableInterceptor::register_orb_initializer (orb_initializer.in ());
+
+ // Initialize orb
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
+
+ // Destringify ior
+ CORBA::Object_var obj = orb->string_to_object( "file://Messenger.ior" );
+ if( CORBA::is_nil( obj.in() ) ) {
+ std::cerr << "Nil Messenger reference" << std::endl;
+ return 1;
+ }
+
+ // Narrow
+ Messenger_var messenger = Messenger::_narrow( obj.in() );
+ if( CORBA::is_nil( messenger.in() ) ) {
+ std::cerr << "Argument is not a Messenger reference" << std::endl;
+ return 1;
+ }
+
+ // Obtain a reference to the CodecFactory.
+ CORBA::Object_var obj2 =
+ orb->resolve_initial_references ("CodecFactory");
+
+ IOP::CodecFactory_var codec_factory;
+
+ if(CORBA::is_nil(obj2.in()))
+ {
+ std::cerr << "Error: codec_factory" << std::endl;
+ ACE_OS::exit(1);
+ }
+ else
+ {
+ codec_factory = IOP::CodecFactory::_narrow (obj2.in ());
+ std::cout << "got codec factory" << std::endl;
+ }
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ IOP::Codec_var codec =
+ codec_factory->create_codec (encoding);
+
+ CORBA::Long uid = 64321;
+
+ CORBA::Any uid_as_any;
+
+ uid_as_any <<= uid;
+ CORBA::OctetSeq client_uid = *codec->encode (uid_as_any);
+ messenger->send_message( client_uid );
+ }
+
+ catch(const CORBA::Exception& ex)
+ {
+ std::cerr << "Exception in MessengerClient: " << ex << std::endl;
+ return 1;
+ }
+
+ std::cout << "Message was sent" << std::endl;
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerServer.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerServer.cpp
new file mode 100644
index 00000000000..43be05f3d32
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/MessengerServer.cpp
@@ -0,0 +1,61 @@
+#include "Messenger_i.h"
+#include "MessengerC.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 <iostream>
+#include <fstream>
+
+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 ());
+
+ // Initialize orb
+ CORBA::ORB_var orb = CORBA::ORB_init( argc, argv );
+
+ //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;
+
+ // Register the servant with the RootPOA, obtain its object
+ // reference, stringify it, and write it to a file.
+ PortableServer::ObjectId_var oid =
+ poa->activate_object( &messenger_servant );
+ CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() );
+ CORBA::String_var str = orb->object_to_string( messenger_obj.in() );
+ std::ofstream iorFile( "Messenger.ior" );
+ iorFile << str.in() << std::endl;
+ iorFile.close();
+ std::cout << "IOR written to file Messenger.ior" << std::endl;
+
+ // Accept requests
+ orb->run();
+ orb->destroy();
+ }
+
+ catch(const CORBA::Exception& ex)
+ {
+ std::cerr << "Exception in MessengerServer: " << ex << std::endl;
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.cpp
new file mode 100644
index 00000000000..995ce6f626e
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.cpp
@@ -0,0 +1,74 @@
+#include "Messenger_i.h"
+#include <ace/OS_NS_string.h>
+#include <tao/CodecFactory/CodecFactory.h>
+#include <iostream>
+
+// Implementation skeleton constructor
+Messenger_i::Messenger_i (void)
+{
+}
+
+// Implementation skeleton destructor
+Messenger_i::~Messenger_i (void)
+{
+}
+
+
+void Messenger_i::send_message (const CORBA::OctetSeq & user_name)
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ))
+{
+ try
+ {
+ int argc = 1;
+ char **argv = new char *[argc];
+ argv[0] = new char[ACE_OS::strlen ("MessengerServer")];
+ strcpy (argv[0], "MessengerServer");
+
+ CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);
+
+ // Obtain a reference to the CodecFactory.
+ CORBA::Object_var obj =
+ orb->resolve_initial_references ("CodecFactory");
+
+ IOP::CodecFactory_var codec_factory;
+
+ if(CORBA::is_nil(obj.in()))
+ {
+ std::cerr << "Error: codec_factory" << std::endl;
+ ACE_OS::exit(1);
+ }
+ else
+ {
+ codec_factory = IOP::CodecFactory::_narrow (obj.in ());
+ std::cout << "Server got codec factory" << std::endl;
+ }
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ IOP::Codec_var codec =
+ codec_factory->create_codec (encoding);
+
+ CORBA::Any uid_as_any;
+ uid_as_any = *(codec->decode(user_name));
+
+ CORBA::Long uid;
+ uid_as_any >>= uid;
+ std::cout << "UID: " << uid << std::endl;
+
+ }
+ catch(...)
+ {
+ std::cerr << "exception received" << std::endl;
+ ACE_OS::exit(1);
+ }
+
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.h b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.h
new file mode 100644
index 00000000000..fac0e58921c
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/Messenger_i.h
@@ -0,0 +1,28 @@
+#ifndef MESSENGER_I_H_
+#define MESSENGER_I_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 void send_message (const CORBA::OctetSeq & user_name)
+ ACE_THROW_SPEC ((
+ CORBA::SystemException
+ ));
+
+};
+
+#endif /* MESSENGERI_H_ */
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/README b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/README
new file mode 100644
index 00000000000..2300d5ad16f
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/README
@@ -0,0 +1,36 @@
+Portable Interceptors
+
+
+File: DevGuideExamples/PortableInterceptor/SimpleCodec/README
+
+
+This directory contains an example illustrating marshaling of data in
+client and server Request Interceptors.
+
+This example extends the authentication example in ../Auth. It is based on
+the Messenger example in GettingStarted directory. A message is
+sent by MessengerClient and displayed by MessengerServer. A client-side
+portable interceptor adds an encoded (marshaled) GID to each request
+sent to the server. A server-side interceptor verifies that the supplied
+GID is valid.
+
+How to Run
+----------
+
+To start the server:
+------------------
+./MessengerServer
+
+
+To start the client:
+------------------
+./MessengerClient
+
+
+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/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.cpp
new file mode 100644
index 00000000000..066634498f6
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.cpp
@@ -0,0 +1,27 @@
+#include "ServerInitializer.h"
+#include "ServerInterceptor.h"
+
+ServerInitializer::ServerInitializer ()
+{
+}
+
+void
+ServerInitializer::pre_init (
+ PortableInterceptor::ORBInitInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+}
+
+void
+ServerInitializer::post_init (
+ PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ // get reference to the codec_factory
+ IOP::CodecFactory_var codec_factory = info->codec_factory();
+
+ // Create and register the request interceptors.
+ PortableInterceptor::ServerRequestInterceptor_var si =
+ new ServerInterceptor (codec_factory);
+ info->add_server_request_interceptor (si.in());
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.h b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.h
new file mode 100644
index 00000000000..f07b7821cb2
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInitializer.h
@@ -0,0 +1,23 @@
+#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)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void post_init (PortableInterceptor::ORBInitInfo_ptr info)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ private:
+ int interceptor_type_;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.cpp b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.cpp
new file mode 100644
index 00000000000..08ddc68dca7
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.cpp
@@ -0,0 +1,126 @@
+#include "ServerInterceptor.h"
+#include <tao/PI_Server/ServerRequestInfoA.h>
+#include <tao/OctetSeqC.h>
+#include <iostream>
+
+const IOP::ServiceId service_id = 0xdeed;
+const CORBA::Long allowed_gid[4] = { 9006, 9007, 9008 };
+const char* restricted_interfaces[1] = {"IDL:Messenger:1.0"};
+
+ServerInterceptor::ServerInterceptor (IOP::CodecFactory_var cf)
+ : myname_ ("Server_Authentication_Interceptor")
+{
+ std::cout << "Calling ServerInterceptor constructor." << std::endl;
+
+ // Set up a structure that contains information necessary to
+ // create a GIOP 1.2 CDR encapsulation Codec.
+ IOP::Encoding encoding;
+ encoding.format = IOP::ENCODING_CDR_ENCAPS;
+ encoding.major_version = 1;
+ encoding.minor_version = 2;
+
+ // Obtain the CDR encapsulation Codec.
+ this->codec = cf->create_codec (encoding);
+
+}
+
+ServerInterceptor::~ServerInterceptor ()
+{
+}
+
+char *
+ServerInterceptor::name ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling ServerInterceptor name() method" << std::endl;
+ return CORBA::string_dup (this->myname_);
+}
+
+void
+ServerInterceptor::destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ std::cout << "Calling destroy()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ std::cout << "Calling receive_request_service_contexts()." << std::endl;
+}
+
+void
+ServerInterceptor::receive_request (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ 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);
+ // need to construct an octet seq for decoding
+ CORBA::OctetSeq ocSeq = CORBA::OctetSeq(
+ sc->context_data.length(),
+ sc->context_data.length(),
+ sc->context_data.get_buffer(),
+ 0);
+
+ CORBA::Any gid_as_any;
+ gid_as_any = *codec->decode(ocSeq);
+
+ CORBA::Long gid;
+ gid_as_any >>= gid;
+ for (int i=0; i<3; ++i) {
+ if ( gid == allowed_gid[i] )
+ {
+ permission_granted = true;
+ }
+ }
+ }
+
+ if (permission_granted == true) {
+ std::cout << "Permission Granted " << std::endl;
+ }
+ else {
+ std::cout << "Permission Denied " << std::endl;
+ ACE_THROW_SPEC (CORBA::NO_PERMISSION());
+ }
+}
+
+void
+ServerInterceptor::send_reply (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_reply()." << std::endl;
+}
+
+void
+ServerInterceptor::send_exception (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_exception()." << std::endl;
+}
+
+void
+ServerInterceptor::send_other (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest))
+{
+ ACE_UNUSED_ARG(ri);
+ std::cout << "Calling send_other()." << std::endl;
+}
+
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.h b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.h
new file mode 100644
index 00000000000..abcac4bc9f5
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/ServerInterceptor.h
@@ -0,0 +1,47 @@
+#ifndef SERVERINTERCEPTOR_H
+#define SERVERINTERCEPTOR_H
+
+#include "tao/PortableInterceptorC.h"
+#include "tao/PI_Server/ServerRequestInterceptorA.h"
+#include "tao/PI/ORBInitInfo.h"
+
+class ServerInterceptor
+: public PortableInterceptor::ServerRequestInterceptor
+{
+ public:
+ ServerInterceptor (IOP::CodecFactory_var);
+
+ ~ServerInterceptor ();
+
+ virtual char * name ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void destroy ()
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void receive_request (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void receive_request_service_contexts (
+ PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_reply (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException));
+
+ virtual void send_exception (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ virtual void send_other (PortableInterceptor::ServerRequestInfo_ptr ri)
+ ACE_THROW_SPEC ((CORBA::SystemException,
+ PortableInterceptor::ForwardRequest));
+
+ private:
+ const char *myname_;
+ IOP::Codec_var codec;
+};
+
+#endif
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/SimpleCode.mpc b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/SimpleCode.mpc
new file mode 100644
index 00000000000..051dea85fcd
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/SimpleCode.mpc
@@ -0,0 +1,17 @@
+project(*Server): taoexe, portableserver, pi_server, avoids_minimum_corba {
+ Source_Files {
+ Messenger_i.cpp
+ ServerInitializer.cpp
+ ServerInterceptor.cpp
+ MessengerServer.cpp
+ }
+}
+
+project(*Client): taoexe, pi, avoids_minimum_corba, interceptors {
+ Source_Files {
+ MessengerC.cpp
+ MessengerClient.cpp
+ ClientInitializer.cpp
+ ClientInterceptor.cpp
+ }
+}
diff --git a/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/run_test.pl b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/run_test.pl
new file mode 100644
index 00000000000..8804f7ba6d8
--- /dev/null
+++ b/TAO/DevGuideExamples/PortableInterceptors/SimpleCodec/run_test.pl
@@ -0,0 +1,36 @@
+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;
+
+# start MessengerServer
+my($iorfile) = 'Messenger.ior';
+$S = new PerlACE::Process("MessengerServer");
+$S->Spawn();
+if (PerlACE::waitforfile_timed (
+ $iorfile,
+ $PerlACE::wait_interval_for_process_creation) == -1) {
+ print STDERR "ERROR: cannot find file <$iorfile>\n";
+ $SV->Kill();
+ exit(1);
+}
+
+# start MessengerClient
+select undef, undef, undef, .5;
+$C = new PerlACE::Process("MessengerClient");
+
+if ($C->SpawnWaitKill(15) != 0) {
+ $S->Kill();
+ exit (1);
+}
+
+# clean-up
+$S->Kill();
+
+exit 0;
+
+
+