diff options
Diffstat (limited to 'TAO')
264 files changed, 13204 insertions, 0 deletions
diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..79a2ef70181 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumerMain.cpp @@ -0,0 +1,85 @@ +// $Id$ + +// EchoEventConsumerMain.cpp +// Main program for a PushConsumer of Echo events. + + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/CosEventCommC.h" +#include "orbsvcs/CosEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> + +const int EVENTS_TILL_SHUTDOWN = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("CosEventService"); + + // Downcast the object reference to an EventChannel reference. + CosEventChannelAdmin::EventChannel_var echoEC = + CosEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(echoEC.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "Found the EchoEventChannel." << std::endl; + + // Get a ConsumerAdmin object from the EventChannel. + CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin = + echoEC->for_consumers(); + + // Get a ProxyPushSupplier from the ConsumerAdmin. + CosEventChannelAdmin::ProxyPushSupplier_var supplier = + consumerAdmin->obtain_push_supplier(); + + // Instantiate an EchoEventConsumer_i servant. + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENTS_TILL_SHUTDOWN); + + // Register it with the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + CosEventComm::PushConsumer_var consumer = + CosEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect to the ProxyPushSupplier, passing our PushConsumer object + // reference to it. + supplier->connect_push_consumer(consumer.in()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + orb->destroy(); + + std::cout << "Test complete." << std::endl; + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Consumer: Caught CORBA::Exception: " << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..e586269cfd7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.cpp @@ -0,0 +1,44 @@ +// $Id$ + +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(CosEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ +} + +// Override the push() operation. +void EchoEventConsumer_i::push(const CORBA::Any & data) +{ + // Extract event data from the any. + const char* eventData; + if (data >>= eventData) + { + std::cout << "EchoEventConsumer_i::push(): Received event: " + << eventData << std::endl; + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Override the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.h new file mode 100644 index 00000000000..8a17a07ca08 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/CosEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/CosEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_CosEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const CORBA::Any & data); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + CosEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..1d66e52a524 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/EchoEventSupplierMain.cpp @@ -0,0 +1,72 @@ +// $Id$ + +// Main program for a PushSupplier of Echo events. + +#include "orbsvcs/CosEventCommC.h" +#include "orbsvcs/CosEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> + +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EventChannel. + obj = root_context->resolve_str("CosEventService"); + + // Downcast the object reference to an EventChannel reference. + CosEventChannelAdmin::EventChannel_var echoEC = + CosEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(echoEC.in())) { + std::cerr << "Could not resolve EchoEventChannel." << std::endl; + return 1; + } + + // Get a SupplierAdmin object from the EventChannel. + CosEventChannelAdmin::SupplierAdmin_var supplierAdmin = + echoEC->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + CosEventChannelAdmin::ProxyPushConsumer_var consumer = + supplierAdmin->obtain_push_consumer(); + + // Connect to the ProxyPushConsumer as a PushSupplier + // (passing a nil PushSupplier object reference to it because + // we don't care to be notified about disconnects). + consumer->connect_push_supplier(CosEventComm::PushSupplier::_nil()); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); + + // Send one event per second. (approx) + while (1) { + // Insert the event data into an any. + CORBA::Any any; + any <<= eventData; + + // Now push the event to the consumer + consumer->push(any); + + ACE_Time_Value event_delay(0, 1000 * EVENT_DELAY_MS); + orb->run(event_delay); + } + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Supplier Caught CORBA::Exception. " << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/OMG_Basic.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/OMG_Basic.mpc new file mode 100644 index 00000000000..ce1e164120f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/OMG_Basic.mpc @@ -0,0 +1,20 @@ +// $Id$ + +project(*Supplier): namingexe, event_skel { + exename = EchoEventSupplier + includes += ../common + Source_Files { + EchoEventSupplierMain.cpp + } +} + +project(*Consumer): namingexe, event_skel { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/README b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/README new file mode 100644 index 00000000000..42db0c2a7c1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/README @@ -0,0 +1,64 @@ +// $Id$ + +OMG Event Service + + +File: DevGuideExamples/EventServices/OMG_Basic/README + + +This directory contains a simple example of using the CosEvent service. +This example uses the push/push model: + + EchoEventSupplier ----> CosEvent_Service ----> EchoEventConsumer + +This example also works fine with the CosEvent_Service server. + +------------------------------------------------------------------------- + +Note: To test this, you must first run the Naming Service and the +CosEvent Service, e.g.: + +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior & +$TAO_ROOT/orbsvcs/CosEvent_Service/CosEvent_Service -ORBInitRef NameService=file://ns.ior& + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier -ORBInitRef NameService=file://ns.ior + + It will publish an event to the event channel every second. + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ORBInitRef NameService=file://ns.ior + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the CosEventComm::PushConsumer interface. + + + +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 -ExeSubDir <Release> + + + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/run_test.pl new file mode 100755 index 00000000000..a452c9efb65 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_Basic/run_test.pl @@ -0,0 +1,63 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$esiorfile = PerlACE::LocalFile ("es.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; + +unlink $nsiorfile; +unlink $esiorfile; + +# start Naming Service + +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start Event Service +$EventService = "$ENV{TAO_ROOT}/orbsvcs/CosEvent_Service/CosEvent_Service"; +$ES = new PerlACE::Process($EventService, "-o $esiorfile $arg_ns_ref"); +$ES->Spawn(); +if (PerlACE::waitforfile_timed ($esiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$esiorfile>\n"; + $ES->Kill(); + unlink $nsiorfile; + exit 1; +} + +# start EchoEventSupplier +$S = new PerlACE::Process("EchoEventSupplier", $arg_ns_ref); +$S->Spawn(); + +# start EchoEventConsumer +$C = new PerlACE::Process("EchoEventConsumer", $arg_ns_ref); +$C->Spawn(); + +$CRET = $C->WaitKill(60); +$S->Kill(); +$NS->Kill(); +$ES->Kill(); + +unlink $nsiorfile; +unlink $esiorfile; + +if ($CRET != 0) { + print STDERR "ERROR: Client returned <$CRET>\n"; + exit 1 ; +} + +exit 0; + + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..448984bef77 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumerMain.cpp @@ -0,0 +1,83 @@ +// $Id$ + +// EchoEventConsumerMain.cpp +// Main program for a PushConsumer of Echo events. + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/CosEventCommC.h" +#include "orbsvcs/CosEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const int EVENT_LIMIT = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("CosEventService"); + + // Downcast the object reference to an EventChannel reference. + CosEventChannelAdmin::EventChannel_var echoEC = + CosEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(echoEC.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "Found the EchoEventChannel." << std::endl; + + // Get a ConsumerAdmin object from the EventChannel. + CosEventChannelAdmin::ConsumerAdmin_var consumerAdmin = + echoEC->for_consumers(); + + // Get a ProxyPushSupplier from the ConsumerAdmin. + CosEventChannelAdmin::ProxyPushSupplier_var supplier = + consumerAdmin->obtain_push_supplier(); + + // Instantiate an EchoEventConsumer_i servant. + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENT_LIMIT); + + // Register it with the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + CosEventComm::PushConsumer_var consumer = + CosEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect to the ProxyPushSupplier, passing our PushConsumer object + // reference to it. + supplier->connect_push_consumer(consumer.in()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + orb->destroy(); + + std::cout << "Test completed." << std::endl; + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..e586269cfd7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.cpp @@ -0,0 +1,44 @@ +// $Id$ + +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(CosEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ +} + +// Override the push() operation. +void EchoEventConsumer_i::push(const CORBA::Any & data) +{ + // Extract event data from the any. + const char* eventData; + if (data >>= eventData) + { + std::cout << "EchoEventConsumer_i::push(): Received event: " + << eventData << std::endl; + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Override the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.h new file mode 100644 index 00000000000..8a17a07ca08 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/CosEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/CosEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_CosEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const CORBA::Any & data); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + CosEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..e616a556368 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/EchoEventSupplierMain.cpp @@ -0,0 +1,90 @@ +// $Id$ + +// Main program for a PushSupplier of Echo events. + +#include "orbsvcs/CosEventCommC.h" +#include "orbsvcs/CosEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/CosEvent/CEC_EventChannel.h" +#include "orbsvcs/CosEvent/CEC_Default_Factory.h" + +#include <iostream> +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the CEC Factory so we can customize the CEC + TAO_CEC_Default_Factory::init_svcs (); + + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Get the root POA + CORBA::Object_var poa_object = orb->resolve_initial_references("RootPOA"); + if (CORBA::is_nil (poa_object.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Unable to initialize the POA.\n"), + -1); + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); + poa_manager->activate (); + + // Create and activate the event channel servant + CosEventChannelAdmin::EventChannel_var echoEC; + + TAO_CEC_EventChannel_Attributes attr(root_poa.in(), root_poa.in()); + TAO_CEC_EventChannel* ec = new TAO_CEC_EventChannel(attr); + ec->activate(); + PortableServer::ObjectId_var oid = root_poa->activate_object(ec); + CORBA::Object_var ec_obj = root_poa->id_to_reference(oid.in()); + echoEC = CosEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); + + // Bind the EventChannel. + CosNaming::Name_var name = root_context->to_name("CosEventService"); + root_context->rebind(name.in(), echoEC.in()); + + // Get a SupplierAdmin object from the EventChannel. + CosEventChannelAdmin::SupplierAdmin_var supplierAdmin = + echoEC->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + CosEventChannelAdmin::ProxyPushConsumer_var consumer = + supplierAdmin->obtain_push_consumer(); + + // Connect to the ProxyPushConsumer as a PushSupplier + // (passing a nil PushSupplier object reference to it because + // we don't care to be notified about disconnects). + consumer->connect_push_supplier(CosEventComm::PushSupplier::_nil()); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); + + while (1) { + // Insert the event data into an any. + CORBA::Any any; + any <<= eventData; + + // Now push the event to the consumer + consumer->push(any); + + ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); + orb->run(tv); + } + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught unknown CORBA::Exception exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/OMG_SupplierSideEC.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/OMG_SupplierSideEC.mpc new file mode 100644 index 00000000000..cbdbc4a21cd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/OMG_SupplierSideEC.mpc @@ -0,0 +1,21 @@ +// $Id$ + +project(*Supplier): namingexe, event_serv { + exename = EchoEventSupplier + includes += ../common + + Source_Files { + EchoEventSupplierMain.cpp + } +} + +project(*Consumer): namingexe, event_skel { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/README b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/README new file mode 100644 index 00000000000..a4db5d42ba2 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/README @@ -0,0 +1,63 @@ +// $Id$ + +OMG Event Service + + +File: DevGuideExamples/EventServices/OMG_SupplierSideEC/README + + +This directory contains an example that extends the previous examples +so that the event supplier creates its own local event channel. All +other code is identical to that in EventServices/OMG_Basic. + + EchoEventSupplier (contains EC) ------> EchoEventConsumer + +By default, the supplier will create a "Native" EC. Passing -wrapper +will force creation of a "Wrapper" EC that will utilize a Real-Time +Event Channel (RTEC) as the underlying implementation. + +------------------------------------------------------------------------- + +Note: To test this, you must first run the Naming Service + +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier -ORBInitRef NameService=file://ns.ior + + It will create an event channel and publish an event to it every + second. + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ORBInitRef NameService=file://ns.ior + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the CosEventComm::PushConsumer interface. + + + +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/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/run_test.pl new file mode 100755 index 00000000000..10e527f7fc4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_SupplierSideEC/run_test.pl @@ -0,0 +1,50 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("ns.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$iorfile"; + +unlink $iorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $iorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($iorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start EchoEventSupplier +$S = new PerlACE::Process("EchoEventSupplier", $arg_ns_ref); +$S->Spawn(); + +# Allow time for the supplier to register with the Naming Service +sleep(2); + +# start EchoEventConsumer +$C = new PerlACE::Process("EchoEventConsumer", $arg_ns_ref); +$CRET = $C->SpawnWaitKill(60); + +$S->Kill(); +$NS->Kill(); + +unlink $iorfile; + +if ($CRET != 0) { + print STDERR "ERROR: Client returned <$CRET>\n"; + exit 1 ; +} + + +exit 0; + + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/ConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/ConsumerMain.cpp new file mode 100644 index 00000000000..904c8ff3da7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/ConsumerMain.cpp @@ -0,0 +1,105 @@ +// $Id$ + +// ConsumerMain.cpp +// Main program for a TypedPushConsumer of Messenger objects. + + +#include "Messenger_i.h" +#include "Consumer_i.h" + +#include "orbsvcs/CosTypedEventCommC.h" +#include "orbsvcs/CosTypedEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" +#include "tao/AnyTypeCode/TypeCode.h" +#include "ace/OS_NS_stdio.h" +#include <iostream> + +const int EVENTS_TILL_SHUTDOWN = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EventChannel. + obj = root_context->resolve_str("CosEventService"); + + // Downcast the object reference to an TypedEventChannel reference. + CosTypedEventChannelAdmin::TypedEventChannel_var ec = + CosTypedEventChannelAdmin::TypedEventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not narrow TypedEventChannel." << std::endl; + return 1; + } + std::cout << "Found the TypedEventChannel." << std::endl; + + // Get a ConsumerAdmin object from the EventChannel. + CosTypedEventChannelAdmin::TypedConsumerAdmin_var consumerAdmin = + ec->for_consumers(); + + // Get a ProxyPushSupplier from the ConsumerAdmin. + CosEventChannelAdmin::ProxyPushSupplier_var supplier = + consumerAdmin->obtain_typed_push_supplier(::_tc_Messenger->id()); + + // Instantiate an Messenger_i servant. + Messenger_i servant(orb.in(), supplier.in(), EVENTS_TILL_SHUTDOWN); + + // Register it with the RootPOA. + // Activate the POA here before we connect our consumer. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var messenger_obj = poa->id_to_reference(oid.in()); + Consumer_i consumer_servant(orb.in(), messenger_obj.in()); + PortableServer::ObjectId_var cons_oid = + poa->activate_object(&consumer_servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(cons_oid.in()); + CosTypedEventComm::TypedPushConsumer_var consumer = + CosTypedEventComm::TypedPushConsumer::_narrow(consumer_obj.in()); + + // Connect to the ProxyPushSupplier, passing our PushConsumer object + // reference to it. + supplier->connect_push_consumer(consumer.in()); + + std::cout << "Ready to receive events..." << std::endl; + + CORBA::String_var str = orb->object_to_string (consumer.in ()); + const char* ior_file_name = "Consumer.ior"; + FILE *output_file= ACE_OS::fopen (ACE_TEXT_CHAR_TO_TCHAR(ior_file_name), + ACE_LIB_TEXT("w")); + if (output_file == 0) { + ACE_ERROR_RETURN ((LM_ERROR, + "Cannot open output file for writing IOR: %s", + ior_file_name), + 1); + } + ACE_OS::fprintf (output_file, "%s", str.in ()); + ACE_OS::fclose (output_file); + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + orb->destroy(); + + std::cout << "Test complete." << std::endl; + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught CORBA::Exception. " << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.cpp new file mode 100644 index 00000000000..4d6ea9515a0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.cpp @@ -0,0 +1,38 @@ +// $Id$ + +// Implements a PushConsumer. + +#include "Consumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +Consumer_i::Consumer_i(CORBA::ORB_ptr orb, + CORBA::Object_ptr obj) + : orb_(CORBA::ORB::_duplicate(orb)) + , object_(CORBA::Object::_duplicate(obj)) +{ +} + + +CORBA::Object_ptr +Consumer_i::get_typed_consumer () +{ + return CORBA::Object::_duplicate(object_.in()); +} + +// Override the push() operation. +void Consumer_i::push(const CORBA::Any &) +{ + throw CORBA::NO_IMPLEMENT (); +} + +// Override the disconnect_push_consumer() operation. +void Consumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.h new file mode 100644 index 00000000000..6af0ab7bc63 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Consumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// Consumer_i.h +// Implements a TypedPushConsumer. + +#ifndef _Consumer_i_h_ +#define _Consumer_i_h_ + +#include "orbsvcs/CosTypedEventCommS.h"// for POA_CosTypedEventComm::TypedPushConsumer + +class Consumer_i +: public virtual POA_CosTypedEventComm::TypedPushConsumer +{ + public: + // Constructor + Consumer_i(CORBA::ORB_ptr orb, + CORBA::Object_ptr obj); + + // Override operations from TypedPushConsumer interface. + virtual CORBA::Object_ptr get_typed_consumer (); + + virtual void push(const CORBA::Any & data) ; + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + CORBA::Object_var object_; +}; + +#endif // _Consumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger.idl new file mode 100644 index 00000000000..bac20c4abe1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger.idl @@ -0,0 +1,12 @@ +// $Id$ + +// Messenger.idl + +interface Messenger +{ + // Modified to make message an in parameter and + // remove the return value. + void send_message(in string user_name, + in string subject, + in string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.cpp new file mode 100644 index 00000000000..5357c914909 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.cpp @@ -0,0 +1,39 @@ +/* -*- 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 <iostream> +// Implementation skeleton constructor +Messenger_i::Messenger_i (CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(CosEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ +} + +// Implementation skeleton destructor +Messenger_i::~Messenger_i (void) +{ +} + +void Messenger_i::send_message (const char * user_name, + const char * subject, + const char * message) +{ + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.h new file mode 100644 index 00000000000..4b11a93e683 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/Messenger_i.h @@ -0,0 +1,45 @@ +/* -*- 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 MESSENGER_I_H_ +#define MESSENGER_I_H_ + +#include "MessengerS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "orbsvcs/CosTypedEventChannelAdminC.h" + +//Class Messenger_i +class Messenger_i : public virtual POA_Messenger +{ +public: + //Constructor + Messenger_i (CORBA::ORB_ptr orb, + CosEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + //Destructor + virtual ~Messenger_i (void); + + virtual void send_message (const char * user_name, + const char * subject, + const char * message); + +private: + CORBA::ORB_var orb_; + CosEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; + +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/OMG_TypedEC.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/OMG_TypedEC.mpc new file mode 100644 index 00000000000..72a8d1e8b9f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/OMG_TypedEC.mpc @@ -0,0 +1,21 @@ +// $Id$ + +project(*Supplier): namingexe, event_skel { + exename = Supplier + includes += ../common + Source_Files { + SupplierMain.cpp + MessengerC.cpp + } +} + +project(*Consumer): namingexe, event_skel { + exename = Consumer + includes += ../common + + Source_Files { + ConsumerMain.cpp + Consumer_i.cpp + Messenger_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/README b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/README new file mode 100644 index 00000000000..abeca498b09 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/README @@ -0,0 +1,18 @@ +// $Id$ + +$TAO_ROOT/DevGuideExamples/EventServices/OMG_TypedEC + +This example is a simple demonstration of Typed Event Channel usage. +The Messenger interface is slightly modified for use in this example +to allow suppliers to send messages to all connected consumers. To +run the example, execute the following commands: + +export InterfaceRepositoryIOR=file://ifr.ior +export NameServiceIOR=file://ns.ior +$TAO_ROOT/orbsvcs/IFR_Service/IFR_Service -o ifr.ior & +$ACE_ROOT/bin/tao_ifr Messenger.idl +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior & +$TAO_ROOT/orbsvcs/CosEvent_Service/CosEvent_Service -t & +./Consumer & +./Supplier + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/SupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/SupplierMain.cpp new file mode 100644 index 00000000000..8162a6bf508 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/SupplierMain.cpp @@ -0,0 +1,76 @@ +// $Id$ + +// Main program for a TypedPushSupplier of Messenger objects. + +#include "orbsvcs/CosTypedEventCommC.h" +#include "orbsvcs/CosTypedEventChannelAdminC.h" +#include "orbsvcs/CosNamingC.h" +#include "tao/AnyTypeCode/TypeCode.h" + +#include <iostream> +#include "MessengerC.h" + +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EventChannel. + obj = root_context->resolve_str("CosEventService"); + + // Downcast the object reference to a TypedEventChannel reference. + CosTypedEventChannelAdmin::TypedEventChannel_var ec = + CosTypedEventChannelAdmin::TypedEventChannel::_narrow(obj.in ()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not resolve TypedEventChannel." << std::endl; + return 1; + } + + // Get a SupplierAdmin object from the EventChannel. + CosTypedEventChannelAdmin::TypedSupplierAdmin_var supplierAdmin = + ec->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + CosTypedEventChannelAdmin::TypedProxyPushConsumer_var consumer = + supplierAdmin->obtain_typed_push_consumer(::_tc_Messenger->id()); + + // Connect to the ProxyPushConsumer as a PushSupplier + // (passing a nil PushSupplier object reference to it because + // we don't care to be notified about disconnects). + consumer->connect_push_supplier(CosEventComm::PushSupplier::_nil()); + + // Obtain the interface from the event channel + CORBA::Object_var messenger_obj = consumer->get_typed_consumer(); + + // Narrow the interface + Messenger_var messenger = Messenger::_narrow(messenger_obj.in () ); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); + + // Send one event per second. (approx) + while (1) { + messenger->send_message("King Lizard", + "Proclamations", + eventData.in()); + + ACE_Time_Value event_delay(0, 1000 * EVENT_DELAY_MS); + orb->run(event_delay); + } + + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught CORBA::Exception. " << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/run_test.pl new file mode 100755 index 00000000000..3089a483280 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/OMG_TypedEC/run_test.pl @@ -0,0 +1,96 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$ifriorfile = PerlACE::LocalFile ("ifr.ior"); +$esiorfile = PerlACE::LocalFile ("es.ior"); +$consiorfile = PerlACE::LocalFile ("Consumer.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +$arg_ifr_ref = "-ORBInitRef InterfaceRepository=file://$ifriorfile"; + +unlink $nsiorfile; +unlink $ifriorfile; +unlink $esiorfile; +unlink $consiorfile; + +# start the Interface Repository Service +$IFRService = "$ENV{TAO_ROOT}/orbsvcs/IFR_Service/IFR_Service"; +$IF = new PerlACE::Process ($IFRService, "-o $ifriorfile"); +$IF->Spawn (); +if (PerlACE::waitforfile_timed ($ifriorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$ifriorfile>\n"; + $IF->Kill (); + exit 1; +} + +# load the IFR with the Messenger interface info +$TAO_IFR = "$ENV{ACE_ROOT}/bin/tao_ifr"; +$TI = new PerlACE::Process ($TAO_IFR, + "$arg_ifr_ref Messenger.idl"); +$TI->SpawnWaitKill (60); + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + $IF->Kill (); + exit 1; +} + +# start Event Service +$EventService = "$ENV{TAO_ROOT}/orbsvcs/CosEvent_Service/CosEvent_Service"; +$ES = new PerlACE::Process($EventService, + "-t -o $esiorfile $arg_ns_ref $arg_ifr_ref"); +$ES->Spawn(); +if (PerlACE::waitforfile_timed ($esiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$esiorfile>\n"; + $ES->Kill(); + $NS->Kill (); + $IF->Kill (); + unlink $nsiorfile; + exit 1; +} + +# start Consumer +$C = new PerlACE::Process("Consumer", "$arg_ns_ref"); +$C->Spawn(); +if (PerlACE::waitforfile_timed ($consiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$consiorfile>\n"; + $ES->Kill(); + $NS->Kill (); + $IF->Kill (); + $C->Kill (); + exit 1; +} + +# start Supplier +$S = new PerlACE::Process("Supplier", "$arg_ns_ref"); +$S->Spawn(); + +$CRET = $C->WaitKill(60); +$S->Kill(); +$NS->Kill(); +$ES->Kill(); +$IF->Kill(); + +unlink $nsiorfile; +unlink $ifriorfile; +unlink $esiorfile; +unlink $consiorfile; + +if ($CRET != 0) { + print STDERR "ERROR: Client returned <$CRET>\n"; + exit 1 ; +} + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..37695b39784 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumerMain.cpp @@ -0,0 +1,90 @@ +// $Id$ + +// Main program for a PushConsumer of Echo events. + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const int EVENT_LIMIT = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("EventService"); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventConsumer_i servant. + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENT_LIMIT); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (1); + qos.insert_type (ACE_ES_EVENT_ANY, // Event Type + 0); // handle to the rt_info + supplier->connect_push_consumer (consumer.in (), + qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + orb->destroy(); + + std::cout << "Test completed." << std::endl; + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught CORBA::Exception" << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..083875fe173 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.cpp @@ -0,0 +1,56 @@ +// $Id$ + +// EchoEventConsumer_i.cpp +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include "ace/OS_NS_stdio.h" +#include <sstream> + +// Constructor duplicates the ORB reference. +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(RtecEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ + // Nothing to do. +} + +// Implement the push() operation. +void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events) +{ + // Loop through the events, looking for shutdown events. + for (u_int i = 0; i < events.length (); ++i) { + //ACE_OS::printf("."); + // Extract event data from the any. + const char* eventData; + std::ostringstream out; + out << "Received event," + << " type: " << events[i].header.type + << " source: " << events[i].header.source; + if (events[i].data.any_value >>= eventData) { + out << " text: " << eventData; + } + + ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Implement the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.h new file mode 100644 index 00000000000..4e846e79f47 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/RtecEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_RtecEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const RtecEventComm::EventSet& events); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + RtecEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..76d9ee6e3bd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplierMain.cpp @@ -0,0 +1,109 @@ +// $Id$ + +// EchoEventSupplierMain.cpp +// Main program for a PushSupplier of Echo events. + +#include "EchoEventSupplier_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Get the Event Channel using Naming Services + obj = root_context->resolve_str("EventService"); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not resolve EchoEventChannel." << std::endl; + return 1; + } + + // Get a SupplierAdmin object from the EventChannel. + RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + RtecEventChannelAdmin::ProxyPushConsumer_var consumer = + admin->obtain_push_consumer(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventSupplier_i servant. + EchoEventSupplier_i servant(orb.in()); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushSupplier_var supplier = + RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); + + // Publish the events the supplier provides. + ACE_SupplierQOS_Factory qos; + qos.insert (MY_SOURCE_ID, // Supplier's unique id + MY_EVENT_TYPE, // Event type + 0, // handle to the rt_info structure + 1); // number of calls + + // Connect as a supplier of the published events. + consumer->connect_push_supplier (supplier.in (), + qos.get_SupplierQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); + + // Create an event set for one event + RtecEventComm::EventSet events (1); + events.length (1); + + // Initialize event header. + events[0].header.source = MY_SOURCE_ID; + events[0].header.type = MY_EVENT_TYPE; + + // Initialize data fields in event. + events[0].data.any_value <<= eventData; + + std::cout << "Supplier starting sending of events" << std::endl; + + while (1) { + consumer->push (events); + ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); + orb->run(tv); + } + + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Supplier::main() Caught CORBA::Exception" << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.cpp new file mode 100644 index 00000000000..647b2545ef1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.cpp @@ -0,0 +1,25 @@ +// $Id$ + +// EchoEventSupplier_i.cpp +// Implements a PushSupplier. + +#include "EchoEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +// Constructor duplicates the ORB reference. +EchoEventSupplier_i::EchoEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ + // Nothing to do. +} + +// Override the disconnect_push_Supplier() operation. +void EchoEventSupplier_i::disconnect_push_supplier() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.h new file mode 100644 index 00000000000..06d39ff04bd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/EchoEventSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +// EchoEventSupplier_i.h +// Implements a PushSupplier. + +#ifndef _EchoEventSupplier_i_h_ +#define _EchoEventSupplier_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushSupplier + +class EchoEventSupplier_i : public virtual POA_RtecEventComm::PushSupplier +{ + public: + // Constructor + EchoEventSupplier_i(CORBA::ORB_ptr orb); + + virtual void disconnect_push_supplier(); + + private: + CORBA::ORB_var orb_; +}; + +#endif // _EchoEventSupplier_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/README b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/README new file mode 100644 index 00000000000..e2c3aae04e1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/README @@ -0,0 +1,59 @@ +// $Id$ + +Real-Time Event Service + + +File: DevGuideExamples/EventServices/RTEC_Basic/README + + +This directory contains a simple example of using the RT Event service. +This example uses the push/push model: + + EchoEventSupplier ------> Event_Service ------> EchoEventConsumer + +------------------------------------------------------------------------- + +Note: To test this, you must first run the Naming Service and the +Event Service, e.g.: + +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& +$TAO_ROOT/orbsvcs/Event_Service/Event_Service -ORBInitRef NameService=file://ns.ior& + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier -ORBInitRef NameService=file://ns.ior + + It will publish an event to the event channel every 1 second. + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ORBInitRef NameService=file://ns.ior + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the RtecEventComm::PushConsumer interface. + + + +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/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/RTEC_Basic.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/RTEC_Basic.mpc new file mode 100644 index 00000000000..d1a621f3c70 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/RTEC_Basic.mpc @@ -0,0 +1,22 @@ +// $Id$ + +project(*Supplier): namingexe, rteventexe, { + exename = EchoEventSupplier + includes += ../common + + Source_Files { + EchoEventSupplierMain.cpp + EchoEventSupplier_i.cpp + } +} + +project(*Consumer): namingexe, rteventexe, { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/run_test.pl new file mode 100755 index 00000000000..4a256b9dbef --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Basic/run_test.pl @@ -0,0 +1,62 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$esiorfile = PerlACE::LocalFile ("es.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; + +unlink $nsiorfile; +unlink $esiorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start Event Service +$EventService = "$ENV{TAO_ROOT}/orbsvcs/Event_Service/Event_Service"; +$ES = new PerlACE::Process($EventService, "-o $esiorfile $arg_ns_ref"); +$ES->Spawn(); +if (PerlACE::waitforfile_timed ($esiorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$esiorfile>\n"; + $ES->Kill(); + unlink $nsiorfile; + exit 1; +} + +# start EchoEventSupplier +$S = new PerlACE::Process("EchoEventSupplier", $arg_ns_ref); +$S->Spawn(); + +# start EchoEventConsumer +$C = new PerlACE::Process("EchoEventConsumer", $arg_ns_ref); +$CRET = $C->SpawnWaitKill(60); + +$S->Kill(); +$NS->Kill(); +$ES->Kill(); + +unlink $nsiorfile; +unlink $esiorfile; + +if ($CRET != 0) { + print STDERR "ERROR: Client returned <$CRET>\n"; + exit 1 ; +} + + +exit 0; + + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..dcb4ef19d7f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumerMain.cpp @@ -0,0 +1,105 @@ +// $Id$ + +// EchoEventConsumerMain.cpp +// Main program for a PushConsumer of Echo events. + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +const int EVENT_LIMIT = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + const char* ecname = "EventService"; + for (int i = 0; argv[i] != 0; i++) { + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { + if (argv[i+1] != 0) { + ecname = argv[i+1]; + } else { + std::cerr << "Missing Event channel name" << std::endl; + } + } + } + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context + = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str(ecname); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventConsumer_i servant and register it + // with the RootPOA + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENT_LIMIT); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (); + qos.insert (MY_SOURCE_ID, // Source ID + MY_EVENT_TYPE, // Event Type + 0); // handle to the rt_info + supplier->connect_push_consumer (consumer.in (), + qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + orb->destroy(); + + std::cout << "Test completed." << std::endl; + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..083875fe173 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.cpp @@ -0,0 +1,56 @@ +// $Id$ + +// EchoEventConsumer_i.cpp +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include "ace/OS_NS_stdio.h" +#include <sstream> + +// Constructor duplicates the ORB reference. +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(RtecEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ + // Nothing to do. +} + +// Implement the push() operation. +void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events) +{ + // Loop through the events, looking for shutdown events. + for (u_int i = 0; i < events.length (); ++i) { + //ACE_OS::printf("."); + // Extract event data from the any. + const char* eventData; + std::ostringstream out; + out << "Received event," + << " type: " << events[i].header.type + << " source: " << events[i].header.source; + if (events[i].data.any_value >>= eventData) { + out << " text: " << eventData; + } + + ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Implement the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.h new file mode 100644 index 00000000000..4e846e79f47 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/RtecEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_RtecEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const RtecEventComm::EventSet& events); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + RtecEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..4735d2e9682 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplierMain.cpp @@ -0,0 +1,206 @@ +// $Id$ + +// EchoEventSupplierMain.cpp +// Main program for a PushSupplier of Echo events. + +#include "EchoEventSupplier_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/Event/EC_Event_Channel.h" +#include "orbsvcs/Event/EC_Gateway_IIOP.h" +#include "orbsvcs/Event/EC_Default_Factory.h" + +#include "ace/Thread_Manager.h" +#include <iostream> +#include <fstream> + +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +const int EVENT_DELAY_MS = 10; + +ACE_THR_FUNC_RETURN orb_thread(void *orb_ptr) +{ + CORBA::ORB_var orb = CORBA::ORB::_duplicate((CORBA::ORB_ptr) orb_ptr); + orb->run(); + return 0; +} + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the EC Factory so we can customize the EC + TAO_EC_Default_Factory::init_svcs (); + + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + const char* ecname = "EventService"; + const char* remote_ecname = 0; + const char* iorfile = 0; + for (int i = 0; argv[i] != 0; i++) { + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { + if (argv[i+1] != 0) { + i++; + ecname = argv[i]; + } else { + std::cerr << "Missing Event channel name" << std::endl; + } + } + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-gateway")) == 0) { + if (argv[i+1] != 0) { + i++; + remote_ecname = argv[i]; + } else { + std::cerr << "Missing Event channel name" << std::endl; + } + } + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { + if (argv[i+1] != 0) { + i++; + iorfile = argv[i]; + } + } + } + + // Get the POA + CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); + PortableServer::POAManager_var poa_manager = poa->the_POAManager (); + poa_manager->activate (); + + // Spawn a thread for the orb + ACE_Thread_Manager *thread_mgr = ACE_Thread_Manager::instance(); + thread_mgr->spawn(orb_thread, orb.in()); + + // Create a local event channel and register it with the RootPOA. + TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); + TAO_EC_Event_Channel ec_impl (attributes); + ec_impl.activate (); + PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); + CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); + + // Find the Naming Service. + object = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(object.in()); + CosNaming::Name_var name = root_context->to_name(ecname); + root_context->rebind(name.in(), ec.in()); + + // Get a SupplierAdmin object from the EventChannel. + RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + RtecEventChannelAdmin::ProxyPushConsumer_var consumer = + admin->obtain_push_consumer(); + + // Instantiate an EchoEventSupplier_i servant. + EchoEventSupplier_i servant(orb.in()); + + // Register it with the RootPOA. + oid = poa->activate_object(&servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushSupplier_var supplier = + RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); + + // Publish the events the supplier provides. + ACE_SupplierQOS_Factory qos; + qos.insert (MY_SOURCE_ID, // Supplier's unique id + MY_EVENT_TYPE, // Event type + 0, // handle to the rt_info structure + 1); // number of calls + + // Connect as a supplier of the published events. + consumer->connect_push_supplier (supplier.in (), + qos.get_SupplierQOS ()); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup(ecname); + + // Create an event set for one event + RtecEventComm::EventSet event (1); + event.length (1); + // Initialize event header. + event[0].header.source = MY_SOURCE_ID; + event[0].header.ttl = 1; + event[0].header.type = MY_EVENT_TYPE; + // Initialize data fields in event. + event[0].data.any_value <<= eventData; + + TAO_EC_Gateway_IIOP gateway; + int gateway_initialized = 0; + + std::cout << "Supplier starting sending of events.\n"; + + while (1) { + + consumer->push (event); + ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); + orb->run(tv); + + if ((remote_ecname != 0) && (!gateway_initialized)) { + + try { + // Get the remote event channel object + CORBA::Object_var obj = root_context->resolve_str(remote_ecname); + RtecEventChannelAdmin::EventChannel_var remote_ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + + int ok = 0; + if (!CORBA::is_nil(remote_ec.in())) { + // Now check if we can talk to it... + try { + RtecEventChannelAdmin::SupplierAdmin_var adm = + remote_ec->for_suppliers(); + ok = 1; + } catch(const CORBA::UserException&) { + // What is the correct exception(s) to catch here? + } + } + + // There is a good remote event channel so initialize the + // gateway. + if (ok) { + gateway.init(remote_ec.in(), ec.in()); + + PortableServer::ObjectId_var gateway_oid = + poa->activate_object(&gateway); + CORBA::Object_var gateway_obj = + poa->id_to_reference(gateway_oid.in()); + RtecEventChannelAdmin::Observer_var obs = + RtecEventChannelAdmin::Observer::_narrow(gateway_obj.in()); + RtecEventChannelAdmin::Observer_Handle local_ec_obs_handle = + ec->append_observer (obs.in ()); + ACE_UNUSED_ARG (local_ec_obs_handle); + gateway_initialized = 1; + std::cout << "Gateway initialized\n"; + if (iorfile != 0) { + CORBA::String_var str = orb->object_to_string( ec.in() ); + std::ofstream iorFile( iorfile ); + iorFile << str.in() << std::endl; + iorFile.close(); + } + } + } catch(const CosNaming::NamingContext::NotFound&) { + // Try again later... + } + } + } + + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.cpp new file mode 100644 index 00000000000..647b2545ef1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.cpp @@ -0,0 +1,25 @@ +// $Id$ + +// EchoEventSupplier_i.cpp +// Implements a PushSupplier. + +#include "EchoEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +// Constructor duplicates the ORB reference. +EchoEventSupplier_i::EchoEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ + // Nothing to do. +} + +// Override the disconnect_push_Supplier() operation. +void EchoEventSupplier_i::disconnect_push_supplier() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.h new file mode 100644 index 00000000000..06d39ff04bd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/EchoEventSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +// EchoEventSupplier_i.h +// Implements a PushSupplier. + +#ifndef _EchoEventSupplier_i_h_ +#define _EchoEventSupplier_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushSupplier + +class EchoEventSupplier_i : public virtual POA_RtecEventComm::PushSupplier +{ + public: + // Constructor + EchoEventSupplier_i(CORBA::ORB_ptr orb); + + virtual void disconnect_push_supplier(); + + private: + CORBA::ORB_var orb_; +}; + +#endif // _EchoEventSupplier_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/README b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/README new file mode 100644 index 00000000000..f905a2717da --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/README @@ -0,0 +1,86 @@ +// $Id$ + +Real-Time Event Service + + +File: DevGuideExamples/EventServices/RTEC_Federated/README + + +This directory contains an example that shows how to create and +federate real-time event channels. + +------------------------------------------------------------------------- + +Note: To test this, you must first run the Naming Service, e.g.: + + $TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +After running the naming service, start a couple of suppliers: + + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -ORBSvcConf supplier.conf -ecname name1 -gateway name2 + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -ORBSvcConf supplier.conf -ecname name2 -gateway name1 + +Now start some consumers: + + ./EchoEventConsumer -ORBInitRef NameService=file://ns.ior -ecname name1 + ./EchoEventConsumer -ORBInitRef NameService=file://ns.ior -ecname name2 + +It may be easiest to start these in separate windows. You should +see events from both suppliers on both event channels. + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier -ORBInitRef NameService=file://ns.ior -ORBSvcConf supplier.conf -ecname <name> -gateway <rname> -iorfile <file> + + This will create a local RTEC event channel and bind it under + the root context of the naming service with the name <name>. + It will also create a gateway that links from the remote event + channel bound under <rname> to the locally created event channel. + After initializing the local event channel, it will idle until + it locates the remote event channel, initialize the gateway, + and then publish an event to the local event channel every 10 + milliseconds. This event will contain the string <name> in the + any_value field. When the gateway is initialized, you'll see a + message stating "Gateway initialized". If you pass the -iorfile + parameter, this server also writes the EC's IOR to <file> when + the gateway is initialized. + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ORBInitRef NameService=file://ns.ior -ecname <name> + + This will look for an event channel bound to <name> in the Root context + of the Naming Service. It will consume events from this channel and + print the type, source, and string contents contained in any_value. + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the RtecEventComm::PushConsumer interface. + + +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/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/RTEC_Federated.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/RTEC_Federated.mpc new file mode 100644 index 00000000000..74545e5f7fd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/RTEC_Federated.mpc @@ -0,0 +1,22 @@ +// $Id$ + +project(*Supplier): namingexe, rteventexe, rtevent_serv { + exename = EchoEventSupplier + includes += ../common + + Source_Files { + EchoEventSupplierMain.cpp + EchoEventSupplier_i.cpp + } +} + +project(*Consumer): namingexe, rteventexe { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/run_test.pl new file mode 100755 index 00000000000..59a8f65a7e6 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/run_test.pl @@ -0,0 +1,96 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("ns.ior"); +$ec1iorfile = PerlACE::LocalFile ("ec1.ior"); +$ec2iorfile = PerlACE::LocalFile ("ec2.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$iorfile"; + +unlink $iorfile; +unlink $ec1iorfile; +unlink $ec2iorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $iorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($iorfile, 10) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start Supplier +if ( -e "supplier.conf" ) +{ + $supplier_conf_file = "supplier.conf"; +} +else{ + $supplier_conf_file = "../supplier.conf"; +} +$args1 = "-ORBSvcConf $supplier_conf_file -ecname ec1 -gateway ec2 -iorfile $ec1iorfile"; +$S1 = new PerlACE::Process("EchoEventSupplier", "$arg_ns_ref $args1"); +$S1->Spawn(); + +$args2 = "-ORBSvcConf $supplier_conf_file -ecname ec2 -gateway ec1 -iorfile $ec2iorfile"; +$S2 = new PerlACE::Process("EchoEventSupplier", "$arg_ns_ref $args2"); +$S2->Spawn(); + +if ((PerlACE::waitforfile_timed ($ec1iorfile, 15) == -1) || + (PerlACE::waitforfile_timed ($ec2iorfile, 2) == -1)) { + print STDERR "ERROR: cannot find files <$ec1iorfile> and <$ec2iorfile>\n"; + $NS->Kill(); + $S1->Kill(); + $S2->Kill(); + exit 1; +} + +$args3 = "-ecname ec1"; +$C1 = new PerlACE::Process("EchoEventConsumer", "$arg_ns_ref $args3"); +$C1->Spawn(); + +$args4 = "-ecname ec2"; +$C2 = new PerlACE::Process("EchoEventConsumer", "$arg_ns_ref $args4"); +$C2->Spawn(); + +if ($C1->WaitKill(60) == -1) { + print STDERR "consumer1 timedout \n"; + + $C2->Kill(); + $S1->Kill(); + $S2->Kill(); + $NS->Kill(); + + unlink $iorfile; + + exit 1; +} + +if ($C2->WaitKill(10) == -1) { + print STDERR "consumer2 timedout \n"; + + $S1->Kill(); + $S2->Kill(); + $NS->Kill(); + + unlink $iorfile; + + exit 1; +} + +$NS->Kill(); +$S1->Kill(); +$S2->Kill(); + +unlink $iorfile; +unlink $ec1iorfile; +unlink $ec2iorfile; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/supplier.conf b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/supplier.conf new file mode 100644 index 00000000000..87ebf02489e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Federated/supplier.conf @@ -0,0 +1,6 @@ +# $Id +# Use 5 dispatching threads and the rw wait strategy to resolve deadlock +# issues in the gateway at disconnect time. +static Resource_Factory "-ORBFlushingStrategy blocking" +static EC_Factory "-ECobserver basic -ECDispatching mt -ECDispatchingThreads 5" +static Client_Strategy_Factory "-ORBWaitStrategy rw -ORBTransportMuxStrategy exclusive" diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..66bd74c77fe --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumerMain.cpp @@ -0,0 +1,93 @@ +// $Id$ + +// EchoEventConsumerMain.cpp +// Main program for a PushConsumer of Echo events. + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const RtecEventComm::EventSourceID MY_SUPPLIER_ID_START = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventSourceID MY_SUPPLIER_ID_END = ACE_ES_EVENT_SOURCE_ANY + 3; +const RtecEventComm::EventType MY_EVENT_START = ACE_ES_EVENT_UNDEFINED + 1; +const RtecEventComm::EventType MY_EVENT_END = ACE_ES_EVENT_UNDEFINED + 4; + +const int EVENT_LIMIT = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = + CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str("EventService"); + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventConsumer_i servant and register it + // with the RootPOA + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENT_LIMIT); + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (1); + qos.insert_type (MY_EVENT_START, // Event Type + 0); // handle to the rt_info + supplier->connect_push_consumer (consumer.in (), + qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..083875fe173 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.cpp @@ -0,0 +1,56 @@ +// $Id$ + +// EchoEventConsumer_i.cpp +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include "ace/OS_NS_stdio.h" +#include <sstream> + +// Constructor duplicates the ORB reference. +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(RtecEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ + // Nothing to do. +} + +// Implement the push() operation. +void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events) +{ + // Loop through the events, looking for shutdown events. + for (u_int i = 0; i < events.length (); ++i) { + //ACE_OS::printf("."); + // Extract event data from the any. + const char* eventData; + std::ostringstream out; + out << "Received event," + << " type: " << events[i].header.type + << " source: " << events[i].header.source; + if (events[i].data.any_value >>= eventData) { + out << " text: " << eventData; + } + + ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Implement the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.h new file mode 100644 index 00000000000..4e846e79f47 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/RtecEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_RtecEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const RtecEventComm::EventSet& events); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + RtecEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..4f0830bc17f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplierMain.cpp @@ -0,0 +1,120 @@ +// $Id$ + +// EchoEventSupplierMain.cpp +// Main program for a PushSupplier of Echo events. + +#include "EchoEventSupplier_i.h" + +#include "orbsvcs/RtecEventCommC.h"// for Event Communication interfaces +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h"// for Naming Service interfaces + +#include <iostream> +const RtecEventComm::EventSourceID MY_SOURCE_ID_START = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventSourceID MY_SOURCE_ID_END = ACE_ES_EVENT_SOURCE_ANY + 3; +const RtecEventComm::EventType MY_EVENT_START = ACE_ES_EVENT_UNDEFINED + 1; +const RtecEventComm::EventType MY_EVENT_END = ACE_ES_EVENT_UNDEFINED + 4; + +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Get the Event Channel using Naming Services + obj = root_context->resolve_str("EventService"); + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not resolve EchoEventChannel." << std::endl; + return 1; + } + + // Get a SupplierAdmin object from the EventChannel. + RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); + + // Get a ProxyPushConsumer from the SupplierAdmin. + RtecEventChannelAdmin::ProxyPushConsumer_var consumer = + admin->obtain_push_consumer(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventConsumer_i servant. + EchoEventSupplier_i servant(orb.in()); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushSupplier_var supplier = + RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); + + // Publish the events the supplier provides. + ACE_SupplierQOS_Factory qos; + RtecEventComm::EventSourceID supplier_id = MY_SOURCE_ID_START; + for (; supplier_id <= MY_SOURCE_ID_END; ++supplier_id) { + RtecEventComm::EventType event_type = MY_EVENT_START; + for (; event_type <= MY_EVENT_END; ++event_type) + { + qos.insert (supplier_id, event_type, + 0, // handle to the rt_info structure + 1); // number of calls + } + } + + // Connect as a supplier of the published events. + consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup("Hello, world."); + + // Create an event set for one event + RtecEventComm::EventSet event (1); + event.length (1); + + // Initialize event header. + event[0].header.source = MY_SOURCE_ID_START; + event[0].header.type = MY_EVENT_START; + + // Initialize data fields in event. + event[0].data.any_value <<= eventData; + + std::cout << "Supplier starting sending events.\n"; + while (1) { + + event[0].header.type++; + if (event[0].header.type > MY_EVENT_END) { + event[0].header.type = MY_EVENT_START; + } + event[0].header.source++; + if (event[0].header.source > MY_SOURCE_ID_END) { + event[0].header.source = MY_SOURCE_ID_START; + } + consumer->push (event); + + ACE_Time_Value tv(0, EVENT_DELAY_MS * 1000); + orb->run(tv); + } + + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.cpp new file mode 100644 index 00000000000..70271836d2e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.cpp @@ -0,0 +1,26 @@ +// $Id$ + +// EchoEventSupplier_i.cpp +// Implements a PushSupplier. + +#include "EchoEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +// Constructor duplicates the ORB reference. +EchoEventSupplier_i::EchoEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ + // Nothing to do. +} + +// Override the disconnect_push_Supplier() operation. +void EchoEventSupplier_i::disconnect_push_supplier() +{ + + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.h new file mode 100644 index 00000000000..06d39ff04bd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/EchoEventSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +// EchoEventSupplier_i.h +// Implements a PushSupplier. + +#ifndef _EchoEventSupplier_i_h_ +#define _EchoEventSupplier_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushSupplier + +class EchoEventSupplier_i : public virtual POA_RtecEventComm::PushSupplier +{ + public: + // Constructor + EchoEventSupplier_i(CORBA::ORB_ptr orb); + + virtual void disconnect_push_supplier(); + + private: + CORBA::ORB_var orb_; +}; + +#endif // _EchoEventSupplier_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/README b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/README new file mode 100644 index 00000000000..74f2f79cd5a --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/README @@ -0,0 +1,59 @@ +// $Id$ + +Real-Time Event Service + + +File: DevGuideExamples/EventServices/RTEC_Filter/README + + +This directory contains some example code for the filters, correlations, +and timeouts features of the RT Event service. For now the code is all +in the EchoEventConsumerMain.cpp file. Simply, comment out the filters/ +timeouts/correlations required, remake, and run as below. + +------------------------------------------------------------------------- + +Note: To test this, you must first run the Naming Service and the +Event Service, e.g.: + +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& +$TAO_ROOT/orbsvcs/Event_Service/Event_Service -ORBSvcConf ec.conf -ORBInitRef NameService=file://ns.ior& + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier -ORBInitRef NameService=file://ns.ior + + It will publish an event to the event channel every 1 second. + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ORBInitRef NameService=file://ns.ior + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the RtecEventComm::PushConsumer interface. + + + +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/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/RTEC_Filter.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/RTEC_Filter.mpc new file mode 100644 index 00000000000..d1a621f3c70 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/RTEC_Filter.mpc @@ -0,0 +1,22 @@ +// $Id$ + +project(*Supplier): namingexe, rteventexe, { + exename = EchoEventSupplier + includes += ../common + + Source_Files { + EchoEventSupplierMain.cpp + EchoEventSupplier_i.cpp + } +} + +project(*Consumer): namingexe, rteventexe, { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/ec.conf b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/ec.conf new file mode 100644 index 00000000000..0d41159fbd9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/ec.conf @@ -0,0 +1,2 @@ +# $Id$ +static EC_Factory "-ECFiltering prefix" diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/run_test.pl new file mode 100755 index 00000000000..204135e8346 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_Filter/run_test.pl @@ -0,0 +1,63 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$esiorfile = PerlACE::LocalFile ("es.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; + +unlink $nsiorfile; +unlink $esiorfile; + +# start Naming Service + +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start Event Service +$EventService = "$ENV{TAO_ROOT}/orbsvcs/Event_Service/Event_Service"; +$ES = new PerlACE::Process($EventService, "-o $esiorfile $arg_ns_ref"); +$ES->Spawn(); +if (PerlACE::waitforfile_timed ($esiorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$esiorfile>\n"; + $ES->Kill(); + unlink $nsiorfile; + exit 1; +} + +# start EchoEventSupplier +$S = new PerlACE::Process("EchoEventSupplier", $arg_ns_ref); +$S->Spawn(); + +# start EchoEventConsumer +$C = new PerlACE::Process("EchoEventConsumer", $arg_ns_ref); +$C->Spawn(); + +$CRET = $C->WaitKill(60); +$S->Kill(); +$NS->Kill(); +$ES->Kill(); + +unlink $nsiorfile; +unlink $esiorfile; + +if ($CRET != 0) { + print STDERR "ERROR: Client returned <$CRET>\n"; + exit 1 ; +} + +exit 0; + + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumerMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumerMain.cpp new file mode 100644 index 00000000000..9bd23fbe075 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumerMain.cpp @@ -0,0 +1,105 @@ +// $Id$ + +// EchoEventConsumerMain.cpp +// Main program for a PushConsumer of Echo events. + +#include "EchoEventConsumer_i.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" + +#include <iostream> +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +const int EVENT_LIMIT = 20; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + const char* ecname = "EventService"; + for (int i = 0; argv[i] != 0; i++) { + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { + if (argv[i+1] != 0) { + ecname = argv[i+1]; + } else { + std::cerr << "Missing Event channel name" << std::endl; + } + } + } + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Find the EchoEventChannel. + obj = root_context->resolve_str(ecname); + + // Downcast the object reference to an EventChannel reference. + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(obj.in()); + if (CORBA::is_nil(ec.in())) { + std::cerr << "Could not narrow EchoEventChannel." << std::endl; + return 1; + } + std::cout << "EchoEventConsumerMain.cpp: Found the EchoEventChannel." << std::endl; + + // Obtain a reference to the consumer administration object. + RtecEventChannelAdmin::ConsumerAdmin_var admin = ec->for_consumers(); + + // Obtain a reference to the push supplier proxy. + RtecEventChannelAdmin::ProxyPushSupplier_var supplier = + admin->obtain_push_supplier(); + + // Get the RootPOA. + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + + // Instantiate an EchoEventConsumer_i servant. + EchoEventConsumer_i servant(orb.in(), supplier.in(), EVENT_LIMIT); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushConsumer_var consumer = + RtecEventComm::PushConsumer::_narrow(consumer_obj.in()); + + // Connect as a consumer. + ACE_ConsumerQOS_Factory qos; + qos.start_disjunction_group (); + qos.insert (MY_SOURCE_ID, // Source ID + MY_EVENT_TYPE, // Event Type + 0); // handle to the rt_info + supplier->connect_push_consumer (consumer.in (), + qos.get_ConsumerQOS ()); + + // Activate the POA via its POAManager. + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + poa_manager->activate(); + + std::cout << "EchoEventConsumerMain.cpp: Ready to receive events..." << std::endl; + + // Enter the ORB event loop. + orb->run(); + + // If we have reached this, we must be shutting down... + // Disconnect the ProxyPushSupplier. + orb->destroy(); + + return 0; + + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.cpp new file mode 100644 index 00000000000..083875fe173 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.cpp @@ -0,0 +1,56 @@ +// $Id$ + +// EchoEventConsumer_i.cpp +// Implements a PushConsumer. + +#include "EchoEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include "ace/OS_NS_stdio.h" +#include <sstream> + +// Constructor duplicates the ORB reference. +EchoEventConsumer_i::EchoEventConsumer_i( + CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit) + : orb_(CORBA::ORB::_duplicate(orb)) + , supplier_(RtecEventChannelAdmin::ProxyPushSupplier::_duplicate(supplier)) + , event_limit_(event_limit) +{ + // Nothing to do. +} + +// Implement the push() operation. +void EchoEventConsumer_i::push(const RtecEventComm::EventSet& events) +{ + // Loop through the events, looking for shutdown events. + for (u_int i = 0; i < events.length (); ++i) { + //ACE_OS::printf("."); + // Extract event data from the any. + const char* eventData; + std::ostringstream out; + out << "Received event," + << " type: " << events[i].header.type + << " source: " << events[i].header.source; + if (events[i].data.any_value >>= eventData) { + out << " text: " << eventData; + } + + ACE_OS::printf("%s\n", out.str().c_str()); // printf is synchronized + } + if (--event_limit_ <= 0) { + supplier_->disconnect_push_supplier(); + orb_->shutdown(0); + } +} + +// Implement the disconnect_push_consumer() operation. +void EchoEventConsumer_i::disconnect_push_consumer() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.h new file mode 100644 index 00000000000..4e846e79f47 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventConsumer_i.h @@ -0,0 +1,31 @@ +// $Id$ + +// EchoEventConsumer_i.h +// Implements a PushConsumer. + +#ifndef _EchoEventConsumer_i_h_ +#define _EchoEventConsumer_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushConsumer +#include "orbsvcs/RtecEventChannelAdminC.h" + +class EchoEventConsumer_i : public virtual POA_RtecEventComm::PushConsumer +{ + public: + // Constructor + EchoEventConsumer_i(CORBA::ORB_ptr orb, + RtecEventChannelAdmin::ProxyPushSupplier_ptr supplier, + int event_limit); + + // Override operations from PushConsumer interface. + virtual void push(const RtecEventComm::EventSet& events); + + virtual void disconnect_push_consumer(); + + private: + CORBA::ORB_var orb_; + RtecEventChannelAdmin::ProxyPushSupplier_var supplier_; + int event_limit_; +}; + +#endif // _EchoEventConsumer_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplierMain.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplierMain.cpp new file mode 100644 index 00000000000..d6f3314dc7e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplierMain.cpp @@ -0,0 +1,245 @@ +// $Id$ + +// EchoEventSupplierMain.cpp +// Main program for a PushSupplier of Echo events. + +#include "EchoEventSupplier_i.h" +#include "SimpleAddressServer.h" + +#include "orbsvcs/RtecEventCommC.h" +#include "orbsvcs/RtecEventChannelAdminC.h" +#include "orbsvcs/Time_Utilities.h" +#include "orbsvcs/Event_Utilities.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/Event/EC_Event_Channel.h" +#include "orbsvcs/Event/EC_Default_Factory.h" +#include "orbsvcs/Event/ECG_Mcast_EH.h" +#include "orbsvcs/Event/ECG_UDP_Sender.h" +#include "orbsvcs/Event/ECG_UDP_Receiver.h" +#include "orbsvcs/Event/ECG_UDP_Out_Endpoint.h" +#include "orbsvcs/Event/ECG_UDP_EH.h" + +#include "tao/ORB_Core.h" + +#include "ace/Auto_Ptr.h" +#include <iostream> +#include <fstream> + +const RtecEventComm::EventSourceID MY_SOURCE_ID = ACE_ES_EVENT_SOURCE_ANY + 1; +const RtecEventComm::EventType MY_EVENT_TYPE = ACE_ES_EVENT_UNDEFINED + 1; + +const int EVENT_DELAY_MS = 10; + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + // Initialize the EC Factory so we can customize the EC + TAO_EC_Default_Factory::init_svcs (); + + // Initialize the ORB. + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + const char* ecname = "EventService"; + const char* address = "localhost"; + const char* iorfile = 0; + u_short port = 12345; + u_short listenport = 12345; + int mcast = 1; + + for (int i = 0; argv[i] != 0; i++) { + if (ACE_OS::strcmp(argv[i], ACE_TEXT("-ecname")) == 0) { + if (argv[i+1] != 0) { + i++; + ecname = argv[i]; + } else { + std::cerr << "Missing Event channel name" << std::endl; + } + } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-address")) == 0) { + if (argv[i+1] != 0) { + i++; + address = argv[i]; + } else { + std::cerr << "Missing address" << std::endl; + } + } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-port")) == 0) { + if (argv[i+1] != 0) { + i++; + port = ACE_OS::atoi(argv[i]); + } else { + std::cerr << "Missing port" << std::endl; + } + } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-listenport")) == 0) { + if (argv[i+1] != 0) { + i++; + listenport = ACE_OS::atoi(argv[i]); + } else { + std::cerr << "Missing port" << std::endl; + } + } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-iorfile")) == 0) { + if (argv[i+1] != 0) { + i++; + iorfile = argv[i]; + } + } else if (ACE_OS::strcmp(argv[i], ACE_TEXT("-udp")) == 0) { + mcast = 0; + } + } + + // Get the POA + CORBA::Object_var object = orb->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (object.in ()); + PortableServer::POAManager_var poa_manager = poa->the_POAManager (); + poa_manager->activate (); + + // Create a local event channel and register it + TAO_EC_Event_Channel_Attributes attributes (poa.in (), poa.in ()); + TAO_EC_Event_Channel ec_impl (attributes); + ec_impl.activate (); + PortableServer::ObjectId_var oid = poa->activate_object(&ec_impl); + CORBA::Object_var ec_obj = poa->id_to_reference(oid.in()); + RtecEventChannelAdmin::EventChannel_var ec = + RtecEventChannelAdmin::EventChannel::_narrow(ec_obj.in()); + + // Find the Naming Service. + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root_context = CosNaming::NamingContextExt::_narrow(obj.in()); + + // Bind the Event Channel using Naming Services + CosNaming::Name_var name = root_context->to_name(ecname); + root_context->rebind(name.in(), ec.in()); + + // Get a proxy push consumer from the EventChannel. + RtecEventChannelAdmin::SupplierAdmin_var admin = ec->for_suppliers(); + RtecEventChannelAdmin::ProxyPushConsumer_var consumer = + admin->obtain_push_consumer(); + + // Instantiate an EchoEventSupplier_i servant. + EchoEventSupplier_i servant(orb.in()); + + // Register it with the RootPOA. + oid = poa->activate_object(&servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + RtecEventComm::PushSupplier_var supplier = + RtecEventComm::PushSupplier::_narrow(supplier_obj.in()); + + // Connect to the EC. + ACE_SupplierQOS_Factory qos; + qos.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); + consumer->connect_push_supplier (supplier.in (), qos.get_SupplierQOS ()); + + // Initialize the address server with the desired address. + // This will be used by the sender object and the multicast + // receiver. + ACE_INET_Addr send_addr (port, address); + SimpleAddressServer addr_srv_impl (send_addr); + + PortableServer::ObjectId_var addr_srv_oid = + poa->activate_object(&addr_srv_impl); + CORBA::Object_var addr_srv_obj = poa->id_to_reference(addr_srv_oid.in()); + RtecUDPAdmin::AddrServer_var addr_srv = + RtecUDPAdmin::AddrServer::_narrow(addr_srv_obj.in()); + + // Create and initialize the sender object + TAO_EC_Servant_Var<TAO_ECG_UDP_Sender> sender = + TAO_ECG_UDP_Sender::create(); + TAO_ECG_UDP_Out_Endpoint endpoint; + if (endpoint.dgram ().open (ACE_Addr::sap_any) == -1) { + std::cerr << "Cannot open send endpoint" << std::endl; + return 1; + } + + // TAO_ECG_UDP_Sender::init() takes a TAO_ECG_Refcounted_Endpoint. + // If we don't clone our endpoint and pass &endpoint, the sender will + // attempt to delete endpoint during shutdown. + TAO_ECG_UDP_Out_Endpoint* clone; + ACE_NEW_RETURN (clone, + TAO_ECG_UDP_Out_Endpoint (endpoint), + -1); + sender->init (ec.in (), addr_srv.in (), clone); + + // Setup the subscription and connect to the EC + ACE_ConsumerQOS_Factory cons_qos_fact; + cons_qos_fact.start_disjunction_group (); + cons_qos_fact.insert (ACE_ES_EVENT_SOURCE_ANY, ACE_ES_EVENT_ANY, 0); + RtecEventChannelAdmin::ConsumerQOS sub = cons_qos_fact.get_ConsumerQOS (); + sender->connect (sub); + + // Create and initialize the receiver + TAO_EC_Servant_Var<TAO_ECG_UDP_Receiver> receiver = + TAO_ECG_UDP_Receiver::create(); + + // TAO_ECG_UDP_Receiver::init() takes a TAO_ECG_Refcounted_Endpoint. + // If we don't clone our endpoint and pass &endpoint, the receiver will + // attempt to delete endpoint during shutdown. + ACE_NEW_RETURN (clone, + TAO_ECG_UDP_Out_Endpoint (endpoint), + -1); + receiver->init (ec.in (), clone, addr_srv.in ()); + + // Setup the registration and connect to the event channel + ACE_SupplierQOS_Factory supp_qos_fact; + supp_qos_fact.insert (MY_SOURCE_ID, MY_EVENT_TYPE, 0, 1); + RtecEventChannelAdmin::SupplierQOS pub = supp_qos_fact.get_SupplierQOS (); + receiver->connect (pub); + + // Create the appropriate event handler and register it with the reactor + auto_ptr<ACE_Event_Handler> eh; + if (mcast) { + auto_ptr<TAO_ECG_Mcast_EH> mcast_eh(new TAO_ECG_Mcast_EH (receiver.in())); + mcast_eh->reactor (orb->orb_core ()->reactor ()); + mcast_eh->open (ec.in()); + ACE_AUTO_PTR_RESET(eh,mcast_eh.release(),ACE_Event_Handler); + //eh.reset(mcast_eh.release()); + } else { + auto_ptr<TAO_ECG_UDP_EH> udp_eh (new TAO_ECG_UDP_EH (receiver.in())); + udp_eh->reactor (orb->orb_core ()->reactor ()); + ACE_INET_Addr local_addr (listenport); + if (udp_eh->open (local_addr) == -1) { + std::cerr << "Cannot open EH" << std::endl; + } + ACE_AUTO_PTR_RESET(eh,udp_eh.release(),ACE_Event_Handler); + //eh.reset(udp_eh.release()); + } + + // Create an event (just a string in this case). + const CORBA::String_var eventData = CORBA::string_dup(ecname); + + // Create an event set for one event + RtecEventComm::EventSet event (1); + event.length (1); + + // Initialize event header. + event[0].header.source = MY_SOURCE_ID; + event[0].header.ttl = 1; + event[0].header.type = MY_EVENT_TYPE; + + // Initialize data fields in event. + event[0].data.any_value <<= eventData; + + if (iorfile != 0) { + CORBA::String_var str = orb->object_to_string( ec.in() ); + std::ofstream iorFile( iorfile ); + iorFile << str.in() << std::endl; + iorFile.close(); + } + std::cout << "Starting main loop" << std::endl; + + const int EVENT_DELAY_MS = 10; + + while (1) { + consumer->push (event); + + ACE_Time_Value tv(0, 1000 * EVENT_DELAY_MS); + orb->run(tv); + } + + orb->destroy(); + return 0; + } + catch(const CORBA::Exception& exc) + { + std::cerr << "Caught CORBA::Exception" << std::endl << exc << std::endl; + } + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.cpp new file mode 100644 index 00000000000..647b2545ef1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.cpp @@ -0,0 +1,25 @@ +// $Id$ + +// EchoEventSupplier_i.cpp +// Implements a PushSupplier. + +#include "EchoEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +// Constructor duplicates the ORB reference. +EchoEventSupplier_i::EchoEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ + // Nothing to do. +} + +// Override the disconnect_push_Supplier() operation. +void EchoEventSupplier_i::disconnect_push_supplier() +{ + // Deactivate this object. + CORBA::Object_var obj = orb_->resolve_initial_references("POACurrent"); + PortableServer::Current_var current = PortableServer::Current::_narrow(obj.in()); + PortableServer::POA_var poa = current->get_POA(); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.h new file mode 100644 index 00000000000..06d39ff04bd --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/EchoEventSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +// EchoEventSupplier_i.h +// Implements a PushSupplier. + +#ifndef _EchoEventSupplier_i_h_ +#define _EchoEventSupplier_i_h_ + +#include "orbsvcs/RtecEventCommS.h"// for POA_CosEventComm::PushSupplier + +class EchoEventSupplier_i : public virtual POA_RtecEventComm::PushSupplier +{ + public: + // Constructor + EchoEventSupplier_i(CORBA::ORB_ptr orb); + + virtual void disconnect_push_supplier(); + + private: + CORBA::ORB_var orb_; +}; + +#endif // _EchoEventSupplier_i_h_ diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/README b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/README new file mode 100644 index 00000000000..c1540c193f3 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/README @@ -0,0 +1,140 @@ +// $Id$ + +Real-Time Event Service + + +File: DevGuideExamples/EventServices/RTEC_MCast_Federated/README + + +This directory contains an example that shows how to create and +federate real-time event channels using the classes in EC_Gateway_UDP.h. +Depending on the options, it will use either UDP or multicast to link +the event channels. + +------------------------------------------------------------------------- + +Note: To run this example, you must first run the Naming Service, e.g.: + + $TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +------------------------------------------------------------------------- + +To start the supplier/EC processes on a single host and federate them +using UDP, do the following (after starting the Naming_Service): + + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -udp -ecname name1 -port 1233 -listenport 1234 + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -udp -ecname name2 -port 1234 -listenport 1233 + +This will start two EC/supplier processes on the same node. One (name1) +will listen on port 1234 and send on port 1233. The other (name2) will +do the opposite. You should be able to use any available port as long as +the port and listenport options are symmetric (listenport of one process +must be the port of the other). The -address option can be used to +specify a supplier/EC process on another host. Here is an example of two +processes on different hosts: + +On node1: + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -udp -ecname name1 -port 1233 -listenport 1234 -address node2 +On node2: + ./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -udp -ecname name2 -port 1234 -listenport 1233 -address node1 + +When using UDP, this example is limited to federating two ECs. + +------------------------------------------------------------------------- + +To start the supplier/EC processes and federate them using multicast, do the +following (after starting the Naming_Service): + +./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -ORBSvcConf supplier.conf -ecname name1 -address 224.9.9.2 -port 1234 +./EchoEventSupplier -ORBInitRef NameService=file://ns.ior -ORBSvcConf supplier.conf -ecname name2 -address 224.9.9.2 -port 1234 + +The -address and -port options should be passed a valid and available +multicast address and port. + +------------------------------------------------------------------------- + +To start the consumers, simply do the following (this works the same for +both types of federations): + +./EchoEventConsumer -ORBInitRef NameService=file://ns.ior -ecname name1 +./EchoEventConsumer -ORBInitRef NameService=file://ns.ior -ecname name2 + +It may be easiest to start these in separate windows. Each consumer +connects to one EC (specified by the -ecname option). You should see +events from both suppliers on each event channel (each supplier passes +events containing with the name of the EC they are using). + +------------------------------------------------------------------------- + +EchoEventSupplerMain.cpp + + Main program for a PushSupplier. + + EchoEventSupplier [ -ORBSvcConf supplier.conf ] [ -udp ] -ecname <name> + [ -address <address> ] [ -port <port> ] + [ -listenport <lport> ] + + This will create a local RTEC event channel and bind it under + the root context of the naming service with the name <name>. + It will also federate with remote event channels specified via + the other options. By default, it uses multicast to federate + the ECs (specifying -udp forces use of UDP). <address> is + the address of the remote EC when using UDP and the multicast + address when using multicast. <port> is the port to send + to when using UDP and the multicast port when using multicast. + <lport> is the port to listen on for UDP (and not used by + multicast. You must pass -ORBSvcConf supplier.conf when + using multicast so as to enable Observers. + + After initializing the local event channel and setting up the + connection for the federation, it publishes an event to the + local event channel every 10 milliseconds. This event will + contain the string <name> in the any_value field. + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumerMain.cpp + + Main program for a PushConsumer. + + To run it: + + EchoEventConsumer -ecname <name> + + This will look for an event channel bound to <name> in the Root context + of the Naming Service. It will consume events from this channel and + print the type, source, and string contents contained in any_value. + + Use Control-C to kill the process. + +------------------------------------------------------------------------- + +EchoEventConsumer_i.{h,cpp} + + Call which implements the RtecEventComm::PushConsumer interface. + +------------------------------------------------------------------------- + +SimpleAddressServer.{h,cpp} + + This is a servant class that implements the RtecUDPAdmin::AddrServer + interface. It is used by the UDP/multicast senders to return an + address that they will send out particular events on. It is also + used by the multicast event handler, to determine which addresses + to listen to based on consumer subscriptions. This simple + implementation always returns the same address. + + + +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 + +By default, this script uses multicast; pass -udp to the +script to use udp. diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/RTEC_MCast_Federated.mpc b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/RTEC_MCast_Federated.mpc new file mode 100644 index 00000000000..9f3dd500486 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/RTEC_MCast_Federated.mpc @@ -0,0 +1,23 @@ +// $Id$ + +project(*_Dev_Supplier): namingexe, rteventexe, rtevent_serv { + exename = EchoEventSupplier + includes += ../common + + Source_Files { + EchoEventSupplierMain.cpp + EchoEventSupplier_i.cpp + SimpleAddressServer.cpp + } +} + +project(*_Dev_Consumer): namingexe, rteventexe { + exename = EchoEventConsumer + includes += ../common + + Source_Files { + EchoEventConsumerMain.cpp + EchoEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.cpp b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.cpp new file mode 100644 index 00000000000..44433fb5a00 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.cpp @@ -0,0 +1,42 @@ +// $Id$ + +// SimpleAddressServer.cpp + +#include "SimpleAddressServer.h" +#include "ace/INET_Addr.h" +#include "ace/OS_NS_string.h" + +SimpleAddressServer::SimpleAddressServer (const ACE_INET_Addr& address) { +#if defined (ACE_HAS_IPV6) + if (address.get_type() == PF_INET6) + { + RtecUDPAdmin::UDP_Addr_v6 v6; + sockaddr_in6 *in6 = + reinterpret_cast<sockaddr_in6 *>(address.get_addr()); + ACE_OS::memcpy (v6.ipaddr,&in6->sin6_addr,16); + v6.port = address.get_port_number(); + this->address_.v6_addr (v6); + return; + } +#endif /* ACE_HAS_IPV6 */ + RtecUDPAdmin::UDP_Addr v4; + v4.ipaddr = address.get_ip_address (); + v4.port = address.get_port_number (); + this->address_.v4_addr (v4); +} + +void +SimpleAddressServer::get_addr (const RtecEventComm::EventHeader&, + RtecUDPAdmin::UDP_Addr& address) +{ + if (this->address_._d() == RtecUDPAdmin::Rtec_inet6) + throw CORBA::DATA_CONVERSION(0, CORBA::COMPLETED_YES); + address = this->address_.v4_addr(); +} + +void +SimpleAddressServer::get_address(const RtecEventComm::EventHeader&, + RtecUDPAdmin::UDP_Address& address) +{ + address = this->address_; +} diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.h b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.h new file mode 100644 index 00000000000..9c346d87a81 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/SimpleAddressServer.h @@ -0,0 +1,27 @@ +// $Id$ + +// SimpleAddressServer.h + +#ifndef SIMPLEADDRESSSERVER_H +#define SIMPLEADDRESSSERVER_H + +#include "orbsvcs/RtecUDPAdminS.h" + +ACE_BEGIN_VERSIONED_NAMESPACE_DECL +class ACE_INET_Addr; +ACE_END_VERSIONED_NAMESPACE_DECL + +class SimpleAddressServer : public POA_RtecUDPAdmin::AddrServer { +public: + SimpleAddressServer (const ACE_INET_Addr& address); + virtual void get_addr (const RtecEventComm::EventHeader& header, + RtecUDPAdmin::UDP_Addr& address); + + virtual void get_address(const RtecEventComm::EventHeader& header, + RtecUDPAdmin::UDP_Address& address); + +private: + RtecUDPAdmin::UDP_Address address_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/run_test.pl b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/run_test.pl new file mode 100755 index 00000000000..176c6327f8f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/run_test.pl @@ -0,0 +1,146 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +if (!defined $ENV{TAO_ROOT}) { + $ENV{TAO_ROOT} = "$ENV{ACE_ROOT}/TAO"; +} + +sub usage() { + print "Usage:\n"; + print " run_test [-h] [-debug]\n\n"; + print " -udp -- Federate using udp\n"; + print " -mcast -- Federate using multicast (the default)\n"; + print " -h -- Prints this information\n"; + print " -debug -- Sets the debug flag for the test\n"; + exit; +} + +my $udp = 0; +my $i = 0; +my $flags = ""; +while ($i <= $#ARGV) { + if ($ARGV[$i] eq "-h" || $ARGV[$i] eq "-help" || + $ARGV[$i] eq "--help" || $ARGV[$i] eq "-?") { + usage (); + } elsif ($ARGV[$i] eq "-debug") { + $flags .= " -ORBDebugLevel 10 "; + } elsif ($ARGV[$i] eq "-udp") { + $udp = 1; + } elsif ($ARGV[$i] eq "-mcast") { + $udp = 0; + } else { + print "ERROR: Unknown Option: ".$ARGV[$i]."\n\n"; + usage (); + } + $i++; +} + +if ($udp) { + print "Using UDP to link the event channels.\n\n"; +} else { + print "Using multicast to link the event channels.\n\n"; +} + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$ec1iorfile = PerlACE::LocalFile ("ec1.ior"); +$ec2iorfile = PerlACE::LocalFile ("ec2.ior"); + +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +$end_point = "-ORBEndpoint iiop://localhost"; +$ns_port = PerlACE::random_port(); + +unlink $nsiorfile; +unlink $ec1iorfile; +unlink $ec2iorfile; + +# start Naming Service + +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "$flags -o $nsiorfile $end_point:$ns_port"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start EchoEventSupplier +my($port1) = 10001 + PerlACE::uniqueid() ; +my($port2) = 10001 + PerlACE::uniqueid() ; +my($mport) = 10001 + PerlACE::uniqueid() ; +if ( -e "supplier.conf" ) +{ + $supplier_conf_file = "supplier.conf"; +} +else{ + $supplier_conf_file = "../supplier.conf"; +} + +$args1 = "$flags $arg_ns_ref -ORBSvcConf $supplier_conf_file $end_point -iorfile $ec1iorfile"; +if ($udp) { + $args1 .= " -udp -ecname ec1 -port $port1 -listenport $port2 "; +} else { + $args1 .= " -ecname ec1 -address 224.9.9.2 -port $mport "; +} +$S1 = new PerlACE::Process("EchoEventSupplier", $args1); +$S1->Spawn(); + +$args2 = "$flags $arg_ns_ref -ORBSvcConf $supplier_conf_file $end_point -iorfile $ec2iorfile"; +if ($udp) { + $args2 .= " -udp -ecname ec2 -port $port2 -listenport $port1 "; +} else { + $args2 .= " -ecname ec2 -address 224.9.9.2 -port $mport "; +} +$S2 = new PerlACE::Process("EchoEventSupplier", $args2); +$S2->Spawn(); + +if ((PerlACE::waitforfile_timed ($ec1iorfile, 15) == -1) || + (PerlACE::waitforfile_timed ($ec2iorfile, 2) == -1)) { + print STDERR "ERROR: cannot find files <$ec1iorfile> and <$ec2iorfile>\n"; + $NS->Kill(); + $S1->Kill(); + $S2->Kill(); + exit 1; +} + +$args3 = "$flags $arg_ns_ref -ecname ec1 $end_point"; +$C1 = new PerlACE::Process("EchoEventConsumer", $args3); +$C1->Spawn(); + + +$args4 = "$flags $arg_ns_ref -ecname ec2 $end_point"; +$C2 = new PerlACE::Process("EchoEventConsumer", $args4); +$C2->Spawn(); + +if ($C1->WaitKill(30) == -1) { + $S1->Kill(); + $S2->Kill(); + $NS->Kill(); + $C2->Kill(); + + exit 1; +} + +if ($C2->WaitKill(5) == -1) { + $S1->Kill(); + $S2->Kill(); + $NS->Kill(); + exit 1; +} + +$NS->Kill(); +$S1->Kill(); +$S2->Kill(); + +unlink $nsiorfile; +unlink $ec1iorfile; +unlink $ec2iorfile; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/supplier.conf b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/supplier.conf new file mode 100644 index 00000000000..d9eeea24f43 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/EventServices/RTEC_MCast_Federated/supplier.conf @@ -0,0 +1,2 @@ +# $Id$ +static EC_Factory "-ECobserver basic" diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp new file mode 100644 index 00000000000..944aef0f190 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/IFRBrowser.cpp @@ -0,0 +1,279 @@ +// $Id$ + +// +// IFRBrowser.cpp +// +// A rudimentary interface repository +// browser, very rudimentary +// + +#include "tao/IFR_Client/IFR_BasicC.h" +#include "tao/ORB.h" +#include "ace/Log_Msg.h" + +#include <iostream> + +const char* programLabel = "IFR Browser"; + +void listContents(const CORBA::ContainedSeq &repoContents); +void listInterface(CORBA::InterfaceDef_ptr interfaceDef); +void listOperation(CORBA::OperationDescription* operationDescr); +void listParameter(CORBA::ParameterDescription* parameterDescr); + +const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode); +const char* decodeParameterMode(CORBA::ParameterMode mode); +const char* decodeOperationMode(CORBA::OperationMode mode); + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = + orb->resolve_initial_references("InterfaceRepository"); + + CORBA::Repository_var ifrRepo = CORBA::Repository::_narrow(obj.in()); + + if (CORBA::is_nil(ifrRepo.in())) + { + ACE_DEBUG((LM_ERROR, + ACE_TEXT("(%N) failed to narrow interface repository referece.\n") + )); + return -1; + } + + CORBA::ContainedSeq_var repoContents = ifrRepo->contents(CORBA::dk_all, 1); + + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: the interface repository contains %d elements.\n"), + programLabel, + repoContents->length() + )); + listContents(repoContents.in()); + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "main() Caught CORBA::Exception : " << ex << std::endl; + } + return 1; +} + +void listContents(const CORBA::ContainedSeq& repoContents) +{ + // + // List the contents of each element. + // + for(unsigned int i = 0; i < repoContents.length(); ++i) + { + CORBA::Contained::Description_var desc = repoContents[i]->describe(); + switch(desc->kind) + { + case CORBA::dk_Constant: + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: element[%d] is a constant definition.\n"), + programLabel, + i + 1 + )); + break; + case CORBA::dk_Typedef: + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: element[%d] is a typedef definition.\n"), + programLabel, + i + 1 + )); + break; + case CORBA::dk_Exception: + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: element[%d] is an exception definition.\n"), + programLabel, + i + 1 + )); + break; + case CORBA::dk_Interface: + { + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: element[%d] is an interface definition.\n") + ACE_TEXT("%s: listing element[%d]...\n"), + programLabel, + i + 1, + programLabel, + i + 1 + )); + CORBA::InterfaceDef_var interfaceDef = + CORBA::InterfaceDef::_narrow(repoContents[i]); + listInterface(interfaceDef.in()); + break; + } + case CORBA::dk_Module: { + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: element[%d] is a module definition.\n"), + programLabel, + i + 1 + )); + CORBA::ModuleDef_var moduleDef = + CORBA::ModuleDef::_narrow(repoContents[i]); + CORBA::ContainedSeq_var moduleContents = + moduleDef->contents(CORBA::dk_all,1); + CORBA::String_var moduleId = moduleDef->id(); + CORBA::String_var moduleName = moduleDef->name(); + + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s:\n// %s\nmodule %s\n{\n") + ACE_TEXT("%s: the module contains %d elements.\n"), + programLabel, + moduleId.in(), + moduleName.in(), + programLabel, + moduleContents->length() + )); + listContents(moduleContents.in()); + ACE_DEBUG((LM_INFO, ACE_TEXT("}\n"))); + break; + } + default: + break; + } + } +} + +void listInterface(CORBA::InterfaceDef_ptr interfaceDef) +{ + CORBA::InterfaceDef::FullInterfaceDescription_var fullDescr = + interfaceDef->describe_interface(); + + const char* interfaceName = + fullDescr->name; + const char* interfaceRepoId = + fullDescr->id; + + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s:\n\t// %s\n\tinterface %s\n\t{"), + programLabel, + interfaceRepoId, + interfaceName + )); + + + unsigned int operationsCount; + if ((operationsCount = fullDescr->operations.length()) > 0) + { + for(unsigned int i = 0; i < operationsCount; ++i) + { + listOperation(&(fullDescr->operations[i])); + } + } + + unsigned int attributesCount; + if ((attributesCount = fullDescr->attributes.length()) > 0) + { + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s: %s has %d attribute(s).\n"), + programLabel, + interfaceName, + attributesCount + )); + } + + ACE_DEBUG((LM_INFO, "\n\t}\n")); +} + +void listOperation(CORBA::OperationDescription* operationDescr) +{ + const char* operationName = + operationDescr->name; + const char* operationRepoId = + operationDescr->id; + const char* operationResult = + decodeTypeCode(operationDescr->result.in()); + const char* operationMode = + decodeOperationMode(operationDescr->mode); + + ACE_DEBUG((LM_INFO, + ACE_TEXT("\n\t\t// %s \n\t\t%s %s %s"), + operationRepoId, + operationResult, + operationName, + operationMode + )); + + CORBA::ParDescriptionSeq* params = &(operationDescr->parameters); + CORBA::ULong paramsCount = params->length(); + if (paramsCount > 0) + { + ACE_DEBUG((LM_INFO, "\n\t\t(\n\t\t")); + for(CORBA::ULong i =0; i < paramsCount; ++i) + { + listParameter(&((*params)[i])); + if(i < (paramsCount - 1)) + { + ACE_DEBUG((LM_INFO, ",\n\t\t")); + } + } + ACE_DEBUG((LM_INFO, "\n\t\t);\n")); + } + else + { + ACE_DEBUG((LM_INFO, "();\n")); + } +} + +void listParameter(CORBA::ParameterDescription *parameterDescr) +{ + const char *typCode = + decodeTypeCode(parameterDescr->type.in()); + const char *paramMode = + decodeParameterMode(parameterDescr->mode); + ACE_DEBUG((LM_INFO, + ACE_TEXT("%s %s %s"), + paramMode, + typCode, + parameterDescr->name.in() + )); +} + +const char* decodeTypeCode(const CORBA::TypeCode_ptr typeCode) +{ + const char* code = ""; + if (typeCode->equivalent(CORBA::_tc_void)) { + code = "void"; + } else if (typeCode->equivalent(CORBA::_tc_boolean)) { + code = "boolean"; + } else if (typeCode->equivalent(CORBA::_tc_string)) { + code = "string"; + } + return code; +} + +const char* decodeParameterMode(CORBA::ParameterMode mode) +{ + const char* paramMode; + switch(mode) + { + case CORBA::PARAM_IN: + { + paramMode = "in"; + break; + } + case CORBA::PARAM_OUT: + { + paramMode = "out"; + break; + } + case CORBA::PARAM_INOUT: + { + paramMode = "inout"; + break; + } + default: + paramMode = ""; + } + return paramMode; +} + +const char* decodeOperationMode(CORBA::OperationMode mode) +{ + return (mode == CORBA::OP_NORMAL) ? "synchronous" : "asynchronous"; +} diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc new file mode 100644 index 00000000000..84c40a3a130 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/InterfaceRepo.mpc @@ -0,0 +1,5 @@ +// $Id$ + +project(*Browser): taoexe, portableserver, ifr_client { + exename = IFRBrowser +} diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl new file mode 100755 index 00000000000..70c47951eb8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl @@ -0,0 +1,86 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use Env (TAO_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$status = 0; + +$ifr_iorfile= "if_repo.ior"; + +$ifr_server = "$ENV{TAO_ROOT}/orbsvcs/IFR_Service/IFR_Service"; +$tao_ifr = "$ENV{ACE_ROOT}/bin/tao_ifr"; +$test_idl = "test.idl"; + +$lookup_by_name = ""; +$other = ""; + +for ($i = 0; $i <= $#ARGV; $i++) { + if ($ARGV[$i] eq "-n") { + $lookup_by_name = "-n"; + } + else { + $other .= $ARGV[$i]; + } +} + +$TAO_IFR = new PerlACE::Process ($tao_ifr); +$IFR = new PerlACE::Process ($ifr_server); +$CL = new PerlACE::Process ("IFRBrowser", "-ORBInitRef InterfaceRepository=file://$ifr_iorfile $lookup_by_name"); + +# We want the tao_ifr executable to be found exactly in the path +# given, without being modified by the value of -ExeSubDir. +# So, we tell its Process object to ignore the setting of -ExeSubDir. + +$TAO_IFR->IgnoreExeSubDir (1); + +unlink $ifr_iorfile; + +$IFR->Spawn (); + +if (PerlACE::waitforfile_timed ($ifr_iorfile, 15) == -1) { + print STDERR "ERROR: cannot find file <$ifr_iorfile>\n"; + $IFR->Kill (); + exit 1; +} + +$TAO_IFR->Arguments ("-ORBInitRef InterfaceRepository=file://$ifr_iorfile $test_idl"); + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (test.idl) returned $tresult\n"; + exit 1; +} + +$client = $CL->SpawnWaitKill (5); +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +# remove the interface from the Interface Repository. +$TAO_IFR->Arguments ("-ORBInitRef InterfaceRepository=file://$ifr_iorfile -r $test_idl"); + +$tresult = $TAO_IFR->SpawnWaitKill (30); + +if ($tresult != 0) { + print STDERR "ERROR: tao_ifr (-r test.idl) returned $tresult\n"; + $status = 1; +} + +$server = $IFR->TerminateWaitKill (5); +if ($server != 0) { + print STDERR "ERROR: IFR returned $server\n"; + $status = 1; +} + +unlink $ifr_iorfile; + +exit $status; + diff --git a/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl new file mode 100644 index 00000000000..8ac11a758fb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/InterfaceRepo/test.idl @@ -0,0 +1,14 @@ +// -*- C++ -*- +// $Id$ + +module warehouse +{ + interface inventory + { + boolean getCDinfo (in string artist, + inout string title, + out float price); + }; +}; + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.mpc new file mode 100644 index 00000000000..46552c8a086 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(NamingService*Server): namingexe, naming_skel { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(NamingService*Client): namingexe { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerClient.cpp new file mode 100644 index 00000000000..4f56c28b581 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerClient.cpp @@ -0,0 +1,51 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + // Find the Naming Service + CORBA::Object_var naming_obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root = + CosNaming::NamingContextExt::_narrow(naming_obj.in()); + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Resolve the Messenger object + CosNaming::Name name; + name.length( 2 ); + name[0].id = CORBA::string_dup( "example" ); + name[1].id = CORBA::string_dup( "Messenger" ); + CORBA::Object_var obj = root->resolve_str("example/Messenger"); + + // Narrow the Messenger object reference + 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!"); + + // Send a message + messenger->send_message("TAO User", "TAO Test", message.inout()); + + std::cout << "Message was sent" << std::endl; + + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerServer.cpp new file mode 100644 index 00000000000..4566177938b --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/MessengerServer.cpp @@ -0,0 +1,64 @@ +// $Id$ + +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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(); + + // 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 the example Naming Context, if necessary + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup( "example" ); + try { + CORBA::Object_var dummy = root->resolve( name ); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = root->bind_new_context( name ); + } + + // Bind the Messenger object + name.length( 2 ); + name[1].id = CORBA::string_dup( "Messenger" ); + + // Create an object + Messenger_i messenger_servant; + PortableServer::ObjectId_var oid = poa->activate_object(&messenger_servant); + obj = poa->id_to_reference( oid.in() ); + root->rebind(name, obj.in()); + + std::cout << "Messenger object bound in Naming Service" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.cpp new file mode 100644 index 00000000000..8215d5e4cef --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.cpp @@ -0,0 +1,34 @@ +/* -*- 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 <iostream> +// 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; + } + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.h new file mode 100644 index 00000000000..e386c4c71da --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/Messenger_i.h @@ -0,0 +1,36 @@ +/* -*- 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); +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/README b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/README new file mode 100644 index 00000000000..68eec11fbc1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/README @@ -0,0 +1,45 @@ +// $Id$ + +OMG Naming Service + +File: DevGuideExamples/NamingService/Messenger/README + + +The Original Messenger example, introduced in Chapters 4 and 5 +(GettingStartedUNIX and GettingStartedVC), is modified to utilize the +Naming Service. The client now uses the Naming Service rather than +reading the server object's IOR as a string from a file. + +The Client code is stored in: + +DevGuideExamples/NamingService/Messenger/MessengerClient.cpp + +The Server code is stored in: + +DevGuideExamples/NamingService/Messenger/MessengerServer.cpp + + +How to Run +---------- + +To start the Naming_Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the server: +------------------ +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the client: +------------------ +./MessengerClient -ORBInitRef NameService=file://ns.ior + + +Exeuction via Perl Script +------------------------- + +A Perl script has been created to automate the three steps shown +above. This script can be run via the following command: + +./run_test.pl + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/run_test.pl new file mode 100755 index 00000000000..4a2f39045a4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Messenger/run_test.pl @@ -0,0 +1,60 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + + +$TARGETHOSTNAME = "localhost"; +$def_port = 2809; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; + +unlink $nsiorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Give the server some time +# to bind the object reference +# with the Naming Service +sleep 3; + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); + +if ($C->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $S->Kill(); + $NS->Kill(); + exit 1; +} + +# clean-up + +$C->Kill(); +$S->Kill(); +$NS->Kill(); + +unlink $nsiorfile; + +exit 0; + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerClient.cpp new file mode 100644 index 00000000000..bcb73045e27 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerClient.cpp @@ -0,0 +1,47 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/Naming/Naming_Client.h" +#include <iostream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + // Find the Naming Service + TAO_Naming_Client naming_client; + + if (naming_client.init (orb.in ()) != 0) { + std::cerr << "Could not initialize naming client." << std::endl; + return 1; + } + + // Resolve the Messenger object + CosNaming::Name name; + name.length( 2 ); + name[0].id = CORBA::string_dup( "example" ); + name[1].id = CORBA::string_dup( "Messenger" ); + CORBA::Object_var obj = naming_client->resolve(name); + + // 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() ); + + std::cout << "Message was sent" << std::endl; + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerServer.cpp new file mode 100644 index 00000000000..40e46da5588 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/MessengerServer.cpp @@ -0,0 +1,63 @@ +// $Id$ + +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/Naming/Naming_Client.h" +#include <iostream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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(); + + // Find the Naming Service + TAO_Naming_Client naming_client; + + if(naming_client.init(orb.in()) != 0){ + std::cerr << "Could not initialize naming client." << std::endl; + return 1; + } + + // Bind the example Naming Context, if necessary + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup("example"); + try { + CORBA::Object_var dummy = naming_client->resolve(name); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = naming_client->bind_new_context( name ); + } + + // Bind the Messenger object + name.length( 2 ); + name[1].id = CORBA::string_dup( "Messenger" ); + + // Create an object + Messenger_i servant; + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + obj = poa->id_to_reference(oid.in()); + naming_client->rebind(name, obj.in()); + + std::cout << "Messenger object bound in Naming Service" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.cpp new file mode 100644 index 00000000000..106a8da3630 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.cpp @@ -0,0 +1,35 @@ +/* -*- 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 <iostream> + +// Implementation skeleton constructor +Messenger_i::Messenger_i (void) +{ + std::cout << "Hello"; +} + +// 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; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.h new file mode 100644 index 00000000000..e386c4c71da --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Messenger_i.h @@ -0,0 +1,36 @@ +/* -*- 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); +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Naming_Client.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Naming_Client.mpc new file mode 100644 index 00000000000..042d4c4b5fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/Naming_Client.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): namingexe, naming_skel { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): namingexe { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/README b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/README new file mode 100644 index 00000000000..d3b94d1a528 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/README @@ -0,0 +1,47 @@ +// $Id$ + +OMG Naming Service + +File: DevGuideExamples/NamingService/Naming_Client/README + + +The example in this directory is a modification of the code given +in the NamingService/Messenger example. It illustrates how to use the +TAO_Naming_Client class for accessing the Naming Service. This class +simplifies the interface for accessing and using the Naming Service. +The TAO_Naming_Client class is used by both the Client and +Server to access the Naming Service. + +The Client code is stored in: + +DevGuideExamples/NamingService/Naming_Client/MessengerClient.cpp + +The Server code is stored in: + +DevGuideExamples/NamingService/Naming_Client/MessengerServer.cpp + + +How to Run +---------- + +To start the Naming_Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior + +To start the server: +------------------ +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the client: +------------------ +./MessengerClient -ORBInitRef NameService=file://ns.ior + + +Exeuction via Perl Script +------------------------- + +A Perl script has been created to automate the three steps shown +above. This script can be run via the following command: + +./run_test.pl + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/run_test.pl new file mode 100755 index 00000000000..8bae3ffa518 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Client/run_test.pl @@ -0,0 +1,63 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + + +$TARGETHOSTNAME = "localhost"; +$def_port = 2809; + +$nsiorfile = PerlACE::LocalFile ("ns.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; + +unlink $nsiorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$nsiorfile>\n"; + $NS->Kill(); + exit 1; +} + +# start MessengerServer +$MessengerServer = "MessengerServer"; +$S = new PerlACE::Process($MessengerServer, $arg_ns_ref); +$S->Spawn(); + +# Give the server some time +# to bind the object reference +# with the Naming Service +sleep 3; + +# start MessengerClient +$MessengerClient = "MessengerClient"; +$C = new PerlACE::Process($MessengerClient, $arg_ns_ref ); + +if ($C->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $S->Kill(); + $NS->Kill(); + exit 1; +} + + +# clean-up + +$C->Kill(); +$S->Kill(); +$NS->Kill(); + +unlink $nsiorfile; + +exit 0; + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerClient.cpp new file mode 100644 index 00000000000..e942c7b662b --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerClient.cpp @@ -0,0 +1,51 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +#include <fstream> +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + char url[200]; + std::ifstream iorFile( "url.ior" ); + iorFile >> url; + iorFile.close(); + + std::cout << "url: " << url << std::endl; + + // Find the Naming Service & the Message Server name in it + CORBA::Object_var obj = orb->string_to_object(url); + + // 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()); + + std::cout << "Message was sent" << std::endl; + + std::cout << "Now try the same thing with the simple name." << std::endl; + obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root = + CosNaming::NamingContextExt::_narrow(obj.in()); + obj = root->resolve_str("Simple/Messenger"); + messenger = Messenger::_narrow(obj.in()); + messenger->send_message( "ACE User", "TAO Test", message.inout()); + + std::cout << "Message was sent" << std::endl; + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerServer.cpp new file mode 100644 index 00000000000..95880c8d32f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/MessengerServer.cpp @@ -0,0 +1,128 @@ +// $Id$ + +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +#include <fstream> +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + + try { + // 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(); + + // Find the Naming Service + obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var root = + CosNaming::NamingContextExt::_narrow(obj.in()); + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Bind a new context. + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup( "root.esc-dot" ); + name[0].kind = CORBA::string_dup( "kind1" ); + + try { + obj = root->resolve(name); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = root->bind_new_context(name); + } + + name.length( 2 ); + name[1].id = CORBA::string_dup( "leaf/esc-slash" ); + name[1].kind = CORBA::string_dup( "kind2" ); + + // Create an object + Messenger_i servant; + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var messenger_obj = poa->id_to_reference(oid.in()); + root->rebind(name, messenger_obj.in()); + + // Also try rebinding to a simple path. + CosNaming::Name_var simp_name = root->to_name("Simple"); + try { + obj = root->resolve(simp_name.in()); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = + root->bind_new_context(simp_name.in()); + } + simp_name = root->to_name("Simple/Messenger"); + root->rebind(simp_name.in(), messenger_obj.in()); + + // Convert Name to String Name. + CORBA::String_var str_name = root->to_string(name); + std::cout << "str_name: " << str_name.in() << std::endl; + CORBA::String_var str_simple = root->to_string(simp_name.in()); + std::cout << "simple: " << str_simple.in() << std::endl; + + // Convert String Name to Name. + CosNaming::Name_var tname = root->to_name(str_name.in()); + + std::cout << "converted back to a CosNaming::Name: " << std::endl; + std::cout << " name[0] = " << (* tname)[0].id.in() << " , " + << (* tname)[0].kind.in() << std::endl; + std::cout << " name[1] = " << (* tname)[1].id.in() << " , " + << (* tname)[1].kind.in() << std::endl; + + // Find the application object by resolve_str. + try { + obj = root->resolve_str(str_name.in()); + } + catch(const CosNaming::NamingContext::NotFound&) { + std::cerr<<"Couldn't resolve the string name: " << str_name << std::endl; + return 1; + } + + // Create an URL string for application object. + CORBA::String_var address = CORBA::string_dup (":localhost:2809/key/str"); + + std::cout << "call to_url(\"" << address.in() << "\"" << std::endl; + std::cout << " ,\"" << str_simple.in() << "\")"<< std::endl; + + CORBA::String_var url_string = root->to_url(address.in(), str_simple.in()); + + std::cout << "to_url result: " << url_string.in() << std::endl; + + + // Write NS url to a file to let client read NS URL to get + // NamingContext reference. + CORBA::String_var ns_addr = CORBA::string_dup(":localhost:2809"); + + std::cout << "call to_url(\"" <<ns_addr.in() << "\",\"" + << str_simple.in() << "\")"<< std::endl; + + CORBA::String_var url = root->to_url(ns_addr.in(), str_simple.in()); + std::cout << "to_url result: " << url.in() << std::endl; + + + std::ofstream iorFile("url.ior"); + iorFile << url.in() << std::endl; + iorFile.close(); + + std::cout << "Naming Service URL written to file url.ior" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.cpp new file mode 100644 index 00000000000..d40e8496387 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.cpp @@ -0,0 +1,34 @@ +/* -*- 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 <iostream> +// 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; + } + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.h new file mode 100644 index 00000000000..b021dcaa44c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Messenger_i.h @@ -0,0 +1,38 @@ +/* -*- 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 + ); + +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Naming_Context_Ext.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Naming_Context_Ext.mpc new file mode 100644 index 00000000000..042d4c4b5fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/Naming_Context_Ext.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): namingexe, naming_skel { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): namingexe { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/README b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/README new file mode 100644 index 00000000000..c816b68c778 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/README @@ -0,0 +1,33 @@ +// $Id$ + +DevGuideExamples/NamingService/Naming_Context_Ext/README + +The example in this directory illustratues how to convert between CosNames, +Stringified Names, and URLs. + +A Name can be converted to a stringified Name by to_string operation. A stringified +Name can be converted to a Name by to_name operation. The resolve_str operation +resolves an object by passing a strigified Name. + +The MessengerServer writes its corbaname URL to a file by calling to_url and +the MessengerClient reads the URL file to get the MessengerServer object reference. + + + +How to Run: +----------- +To start the Naming_Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -ORBEndPoint iiop://localhost:2809 & + + +To start the server: +------------------ +./MessengerServer -ORBInitRef NameService=iiop://localhost:2809/NameService + + +To start the client: +------------------ +./MessengerClient + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/run_test.pl new file mode 100755 index 00000000000..5c62e4de560 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Context_Ext/run_test.pl @@ -0,0 +1,56 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsref="-ORBInitRef NameService=iiop://localhost:2809/NameService"; +$nsior = "ns.ior"; +$ior="url.ior"; +unlink $ior; + +# start Naming Service +unlink($nsior); +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-ORBEndPoint iiop://localhost:2809 -o $nsior"); +$NS->Spawn(); + +if (PerlACE::waitforfile_timed ($nsior, 10) == -1) { + print STDERR "ERROR: cannot find IOR file <$nsior>\n"; + $NS->Kill (); + exit 1; +} + +# start MessengerServer +$MessengerServer = "MessengerServer"; +$S = new PerlACE::Process($MessengerServer, $nsref ); +$S->Spawn(); +if (PerlACE::waitforfile_timed ($ior, 15) == -1) { + print STDERR "ERROR: cannot find file $ior\n"; + $NS->Kill(); + $S->Kill(); + exit 1; +} + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $nsref); +if ($C->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $S->Kill(); + $NS->Kill(); + exit 1; +} + +# clean-up +$S->Kill(); +$NS->Kill(); +unlink $ior; + +exit 0; + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.cpp new file mode 100644 index 00000000000..030214872d7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.cpp @@ -0,0 +1,84 @@ +// $Id$ + +#include "MessengerTask.h" +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +MessengerTask::MessengerTask() +{ + // cast away constness to make Sun CC family of compilers happy. + char* argv[] = {const_cast<char *>("Messenger"), 0 }; + int argc = 1; + orb_ = CORBA::ORB_init(argc, argv, "ServerORB"); +} + +void MessengerTask::end() +{ + orb_->shutdown(0); + this->wait(); +} + +int MessengerTask::svc() +{ + + try { + // 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(); + + // Find the Naming Service + obj = orb_->resolve_initial_references("NameService"); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(obj.in()); + + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + // Bind the example Naming Context, if necessary + CosNaming::Name name; + name.length(1); + name[0].id = CORBA::string_dup("example"); + try { + root->resolve(name); + } + catch(const CosNaming::NamingContext::NotFound&) { + root->bind_new_context(name); + } + + // Bind the Messenger object + name.length(2); + name[1].id = CORBA::string_dup("Messenger"); + + // Create an object + Messenger_i servant; + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + obj = poa->id_to_reference(oid.in()); + root->rebind(name, obj.in()); + + std::cout << "Messenger object bound in Naming Service" << std::endl; + + // Normally we run the orb and the orb is shutdown by + // calling MessengerTask::end(). To simplify the coordination + // between the main thread and this Messenger thread, specify + // the time period to let the Messenger thread finish by itself. + // Accept requests + ACE_Time_Value tv(1); + orb_->run(tv); + orb_->destroy(); + + return 0; + } + catch(const CORBA::Exception& ex) { + std::cerr << "CORBA exception: " << ex << std::endl; + } + + return -1; +} + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.h new file mode 100644 index 00000000000..bc5cdebca15 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/MessengerTask.h @@ -0,0 +1,20 @@ +// $Id$ + +#ifndef MESSENGERTASK_H +#define MESSENGERTASK_H + +#include "tao/corba.h" +#include "ace/Task.h" + +class MessengerTask : public ACE_Task_Base +{ +public: + MessengerTask(); + virtual int svc(); + + void end(); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.cpp new file mode 100644 index 00000000000..21edede8773 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.cpp @@ -0,0 +1,35 @@ +/* -*- 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 <iostream> +// 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; + } + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.h new file mode 100644 index 00000000000..b021dcaa44c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Messenger_i.h @@ -0,0 +1,38 @@ +/* -*- 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 + ); + +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingMessenger.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingMessenger.cpp new file mode 100644 index 00000000000..35c41b37b58 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingMessenger.cpp @@ -0,0 +1,25 @@ +// $Id$ + +#include "NamingTask.h" +#include "MessengerTask.h" +#include "ace/OS.h" + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + // Start the Naming Service task + NamingTask namingService(argc, argv); + namingService.activate(); + // Wait for the Naming Service initialized. + namingService.waitInit(); + + // Start the Messenger task + MessengerTask messenger; + messenger.activate(); + + // Wait the Messenger task finish. + messenger.wait(); + // Shutdown the Naming Service. + namingService.end(); + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.cpp new file mode 100644 index 00000000000..6f2c99971e9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.cpp @@ -0,0 +1,66 @@ +// $Id$ + +#include "NamingTask.h" +#include "orbsvcs/Naming/Naming_Server.h" +#include "ace/OS_NS_unistd.h" +#include <iostream> + +NamingTask::NamingTask (int argc, ACE_TCHAR** argv) +: argc_ (argc), + argv_ (argv), + initialized_(false) +{ + orb_ = CORBA::ORB_init(argc, argv, "NamingORB"); +} + +void NamingTask::waitInit () +{ + // Wait for Naming Service initialized. + while (! initialized_) { + ACE_OS::sleep(ACE_Time_Value(0, 100 * 1000)); + } +} + +void NamingTask::end() +{ + orb_->shutdown(0); + this->wait(); +} + +int NamingTask::svc() +{ + try { + // 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 poaManager = poa->the_POAManager(); + poaManager->activate(); + + // Initialize the naming service + // We are not going to look for other naming servers + TAO_Naming_Server naming; + if (naming.init(orb_.in(), + poa.in(), + ACE_DEFAULT_MAP_SIZE, + 0, + 0) == 0) { + std::cout << "The Naming Service Task is ready." << std::endl; + initialized_ = true; + // Accept requests + orb_->run(); + orb_->destroy(); + return 0; + } + else { + std::cerr << "Unable to initialize the Naming Service." << std::endl; + } + } + catch(const CORBA::Exception& ex) { + std::cerr << "NamingTask::svc() CORBA::Exception: " << ex << std::endl; + } + + return -1; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.h b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.h new file mode 100644 index 00000000000..647b32f0a8f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/NamingTask.h @@ -0,0 +1,24 @@ +// $Id$ + +#ifndef NAMINGTASK_H +#define NAMINGTASK_H + +#include "tao/corba.h" +#include "ace/Task.h" + +class NamingTask : public ACE_Task<ACE_MT_SYNCH> +{ +public: + NamingTask (int argc, ACE_TCHAR** argv); + virtual int svc(); + void waitInit (); + void end(); + +private: + int argc_; + ACE_TCHAR **argv_; + CORBA::ORB_var orb_; + bool initialized_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Naming_Server.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Naming_Server.mpc new file mode 100644 index 00000000000..6a91c764766 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/Naming_Server.mpc @@ -0,0 +1,5 @@ +// $Id$ + +project(*Messenger): namingexe, naming_serv { + requires += threads +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/README b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/README new file mode 100644 index 00000000000..b98ba3a2ee3 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/README @@ -0,0 +1,41 @@ +// $Id$ + +OMG Naming Service + +File: DevGuideExamples/NamingService/Naming_Server/README + +The example in NamingService/Naming_Client is modified to utilize +the TAO_Naming_Server class. This class enables the Naming Service +to easily be collocated within an application. In this example, +the Naming Service is collocated with a server that supports the +Messenger Interface described in GettingStartedUNIX (or GettingStartedVC). + +The Server code is stored in: + +DevGuideExamples/NamingService/Naming_Server/MessengerServer.cpp + + +How to Run +---------- + +To start the server: +------------------ +./MessengerServer -o ns.ior + +To start the client: +------------------ +./MessengerClient -ORBInitRef NameService=file://ns.ior + + +Exeuction via Perl Script +------------------------- + +A Perl script has been created to automate the three steps shown +above. This script can be run via the following command: + +./run_test.pl + + +NOTE: This example has been changed from the example that appears in the +dev-guide in order to pass command line parameters to the thread +that runs the naming server. diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/run_test.pl new file mode 100755 index 00000000000..e0733c60dc9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/Naming_Server/run_test.pl @@ -0,0 +1,20 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$CS = new PerlACE::Process("NamingMessenger"); + +if ($CS->SpawnWaitKill(10) != 0) { + exit 1; +} + +exit 0; + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerClient.cpp new file mode 100644 index 00000000000..e71d7dc2b36 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerClient.cpp @@ -0,0 +1,54 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + const ACE_TCHAR* url = ACE_TEXT("corbaloc:rir:/NameService"); // default URL to InitRef + if ( argc < 2 ) { + std::cout << "Defaulting URL to " << url << std::endl; + std::cout << "Usage: " << argv[0] + << " [corbaloc URL] [-ORB options]" << std::endl; + } + else { + url = argv[1]; + } + + // Find the Naming Service + CORBA::Object_var obj = orb->string_to_object(url); + + CosNaming::NamingContextExt_var root = + CosNaming::NamingContextExt::_narrow(obj.in()); + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Resolve the Messenger object + obj = root->resolve_str("example/Messenger"); + + // 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()); + + std::cout << "Message was sent" << std::endl; + } + catch(const CORBA::Exception& ex) { + std::cerr << "client:Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerServer.cpp new file mode 100644 index 00000000000..ab882806879 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/MessengerServer.cpp @@ -0,0 +1,64 @@ +// $Id$ + +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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(); + + + // Find the Naming Service + obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(obj.in()); + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Bind the example Naming Context, if necessary + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup("example"); + try { + obj = root->resolve(name); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = root->bind_new_context(name); + } + + // Bind the Messenger object + name.length(2); + name[1].id = CORBA::string_dup("Messenger"); + + // Create an object + Messenger_i servant; + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + obj = poa->id_to_reference(oid.in()); + Messenger_var messenger = Messenger::_narrow(obj.in()); + root->rebind(name, messenger.in()); + + std::cout << "Messenger object bound in Naming Service" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "server: Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.cpp new file mode 100644 index 00000000000..8f75d589951 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.cpp @@ -0,0 +1,33 @@ +/* -*- 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 <iostream> +// 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; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.h new file mode 100644 index 00000000000..e386c4c71da --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/Messenger_i.h @@ -0,0 +1,36 @@ +/* -*- 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); +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/README b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/README new file mode 100644 index 00000000000..72ac810d00f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/README @@ -0,0 +1,173 @@ +// $Id$ + +DevGuideExamples/NamingService/corbaloc_Messenger/README +// $Id$ + +The example in this directory extends the example in GettingStartedUNIX +(or GettingStartedVC) to use the Naming_Service +and calling string_to_object instead of calling resolve_initial_references +to get the NameService object reference. + +This example only differs from the NamingService/Messenger example by a few lines +in the MessengerClient.cpp. (All other source files should be the same.) + +How to Run: +----------- +To start the Naming_Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -m 1 & + +Note: Must start the Naming_Service using multicast (-m 1) + for the default initial reference for NameService to work. + +To start the server: +------------------ +./MessengerServer +To start the client: +------------------ +./MessengerClient + + +This MessengerClient will optionally take parameter that is a URL (corbaloc:) +that addresses the Naming_Service. + +The MessengerServer and MessengerClient may also take an -ORBInitRef option +to help qualify the address of the Naming_Service. + +Here are some examples: + +REM start the name server +cd/d %TAO_ROOT%\orbsvcs\Naming_Service +title NS +Naming_Service -ORBEndpoint iiop://localhost:2809 -m 0 + +REM start the example server +cd/d %EXAMPLES%\NamingService\corbaloc_Messenger\Debug +title server +REM use -ORBInitRef with IIOP +MessengerServer -ORBInitRef NameService=iiop://localhost:2809/NameService + +REM use -ORBDefaultInitRef with specific host and port +MessengerServer -ORBDefaultInitRef iiop://localhost:2809 + +REMuse -ORBDefaultInitRef <port 2809 is the default if not specified. +MessengerServer -ORBDefaultInitRef corbaloc::localhost + +REM crashes - ? is this a bug? +MessengerServer -ORBDefaultInitRef corbaloc:rir:/ + +REM -ORBInitRef with corbaloc and default port +MessengerServer -ORBInitRef NameService=corbaloc::localhost/NameService +REM and specific port +MessengerServer -ORBInitRef NameService=corbaloc::localhost:2809/NameService + +REM crashes +MessengerServer -ORBInitRef NameService=corbaloc:rir/NameService + +REM start the client +cd/d %EXAMPLES%\NamingService\corbaloc_Messenger\Debug +title client +MessengerClient -ORBInitRef NameService=iiop://localhost:2809/NameService corbaloc:rir:/NameService + + +REM use -ORBDefaultInitRef with specific host and default port == 2809 +MessengerClient -ORBDefaultInitRef corbaloc::localhost corbaloc:rir:/NameService + +REM use a corbaloc that does not require -ORBDefaultInitRef (port defaults) +MessengerClient corbaloc::localhost/NameService + +=========================== +REM !!! kill the previous Naming_Service and MessengerServer !!! + +REM start the name server (at another address) +cd/d %TAO_ROOT%\orbsvcs\Naming_Service +Naming_Service -ORBEndpoint iiop://localhost:9999 -m 0 + +REM start the example server +cd/d %EXAMPLES%\NamingService\corbaloc_Messenger\Debug +MessengerServer -ORBInitRef NameService=iiop://localhost:9999/NameService + + + +REM start the client +cd/d %EXAMPLES%\NamingService\corbaloc_Messenger\Debug +MessengerClient -ORBInitRef NameService=iiop://localhost:9999/NameService + + + +MessengerClient -ORBInitRef NameService=iiop://localhost:9999/NameService +Usage: MessengerClient [-ORB options] [corbaname URL for the name service] + +MessengerClient -ORBInitRef NameService=iiop://localhost:9999/NameService corbaloc:rir:/NameService +Message was sent + +MessengerClient -ORBInitRef NameService=iiop://localhost:9999/NameService corbaloc:rir:/ +Message was sent + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc:rir:/ +Caught a CORBA exception: TRANSIENT (IDL:omg.org/CORBA/TRANSIENT:1.0) + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc:iiop:localhost:9999/NameService +Message was sent + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc:localhost:9999/NameService +TAO (249|231) no usable transport protocol was found. +Caught a CORBA exception: BAD_PARAM (IDL:omg.org/CORBA/BAD_PARAM:1.0) + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc::localhost:9999/NameService +Message was sent + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc::1.0\localhost:9999/NameService +Caught a CORBA exception: TRANSIENT (IDL:omg.org/CORBA/TRANSIENT:1.0) + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc::1.0\@localhost:9999/NameService +Caught a CORBA exception: TRANSIENT (IDL:omg.org/CORBA/TRANSIENT:1.0) + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc::localhost:9999/NameService +Message was sent + +MessengerClient -ORBInitRef NameService=iiop://localhost:9669/NameService corbaloc::localhost/NameService +Caught a CORBA exception: TRANSIENT (IDL:omg.org/CORBA/TRANSIENT:1.0) + + + +===================== IIOPLOC ================= +REM iioploc: is TAO specific and deprecated + +REM start the name server +cd/d %TAO_ROOT%\orbsvcs\Naming_Service +title NS +Naming_Service -ORBEndpoint iiop://localhost:2809 -m 0 + +REM -ORBInitRef with iioploc (TAO specific and deprecated) +MessengerServer -ORBInitRef NameService=iioploc://localhost:2809/NameService + +cd/d %EXAMPLES%\NamingService\corbaloc_Messenger\Debug +title client +MessengerClient iioploc://localhost:2809/NameService + +===== MCAST example ====== +!!! only on platforms supporting multicast (not Windows) !!! + + +# start the name server using MultiCast +cd $TAO_ROOT/orbsvcs/Naming_Service +Naming_Service -m 1 + +# start the example server +cd $EXAMPLES/NamingService/corbaloc_Messenger +MessengerServer + +cd $EXAMPLES/NamingService/corbaloc_Messenger +MessengerClient + + +--- specify the multicast address. +Naming_Service -m 1 -ORBNameServicePort 12345 +# -ORBNameServicePort 12345 is ingored if -m 1 is not specified. + + +MessengerServer -ORBInitRef NameService=mcast://:12345::/NameService + + +<TBD more using URL parameter> diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/corbaloc_Messenger.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/corbaloc_Messenger.mpc new file mode 100644 index 00000000000..042d4c4b5fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/corbaloc_Messenger.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): namingexe, naming_skel { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): namingexe { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/run_test.pl new file mode 100755 index 00000000000..6df4159cd9f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaloc_Messenger/run_test.pl @@ -0,0 +1,111 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + + +$TARGETHOSTNAME = "localhost"; +$def_port = 2809; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-ORBEndpoint iiop://$TARGETHOSTNAME:$def_port"); +$NS->Spawn(); + +sleep(1); + +# List of tests to test corbaloc URL syntax. +@corbaloc_servers = ( "-ORBDefaultInitRef corbaloc::$TARGETHOSTNAME", + "-ORBInitRef NameService=corbaloc::$TARGETHOSTNAME/NameService", + "-ORBInitRef NameService=corbaloc::$TARGETHOSTNAME:$def_port/NameService"); + + +@servers_comments = ( "Using -ORBDefaultInitRef with default port $def_port and default transport IIOP: \n", + "Using -ORBInitRef with corbaloc URL: \n", + "Using -ORBInitRef with corbaloc URL and specified port: \n"); + +@corbaloc_clients = ( "corbaloc::$TARGETHOSTNAME/NameService", + "-ORBInitRef NameService=iiop://$TARGETHOSTNAME:$def_port/NameService corbaloc:rir:/NameService"); + +@clients_comments = ( "Using the URL parameter: \n"); + "Using a corbaloc:rir form URL(must specify initial reference): \n", + + + + +$MessengerServer= "MessengerServer"; +$MessengerClient= "MessengerClient"; + +$test_number = 0; + +foreach $o (@corbaloc_servers) { + + # Run messenger server for each test. + #print "Start $MessengerServer $o \n"; + $SR = new PerlACE::Process($MessengerServer, $o); + $SR->Spawn(); + + sleep(1); + + #print "Start $MessengerClient \n"; + $CL = new PerlACE::Process($MessengerClient, "-ORBDefaultInitRef iiop://$TARGETHOSTNAME:$def_port"); + $test_number++; + + if ($CL->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $SR->Kill(); + $NS->Kill(); + exit 1; + } + + print "======================================\n"; + print "Finish Test $test_number: $servers_comments[$test_number] \n"; + print " $MessengerServer $o\n"; + print "======================================\n\n"; + + $SR->Kill(1); +} + + +#print "Start $MessengerServer \n"; +$SR = new PerlACE::Process($MessengerServer, "-ORBDefaultInitRef iiop://$TARGETHOSTNAME:$def_port"); +$SR->Spawn(); + +sleep(1); + +$i = 0; +foreach $o (@corbaloc_clients) { + + # Run the client for each test. + #print "Start $MessengerClient $o \n"; + $CL = new PerlACE::Process($MessengerClient, $o); + + + if ($CL->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $SR->Kill(); + $NS->Kill(); + exit 1; + } + + $test_number++; + print "======================================\n"; + print "Finish Test $test_number: $clients_comments[$i]\n"; + print " $MessengerClient $o"; + print "\n======================================\n\n"; + + $i ++; +} + + +# clean up + +$SR->Kill(); +$NS->Kill(); + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger.idl new file mode 100644 index 00000000000..0af8b9e9c0f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerClient.cpp new file mode 100644 index 00000000000..9c8104ebaa5 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerClient.cpp @@ -0,0 +1,44 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + const ACE_TCHAR *url = ACE_TEXT("corbaname:rir:#example/Messenger"); // default URL to InitRef + if ( argc < 2 ) { + std::cout << "Defaulting URL to " << url << std::endl; + std::cout << "Usage: " << argv[0] + << " [-ORB options] [corbaname URL for message server]" << std::endl; + } + else { + url = argv[1]; + } + + // Find the Naming Service & the Message Server name in it + CORBA::Object_var obj = orb->string_to_object(url); + + // 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() ); + + std::cout << "Message was sent" << std::endl; + } + catch(const CORBA::Exception& ex) { + std::cerr << "client:Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerServer.cpp new file mode 100644 index 00000000000..dfabdf2746e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/MessengerServer.cpp @@ -0,0 +1,63 @@ +// $Id$ + +#include "Messenger_i.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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(); + + // Find the Naming Service + obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var root = + CosNaming::NamingContext::_narrow(obj.in()); + if (CORBA::is_nil(root.in())) { + std::cerr << "Nil Naming Context reference" << std::endl; + return 1; + } + + // Bind the example Naming Context, if necessary + CosNaming::Name name; + name.length( 1 ); + name[0].id = CORBA::string_dup("example"); + try { + CORBA::Object_var dummy = root->resolve(name); + } + catch(const CosNaming::NamingContext::NotFound&) { + CosNaming::NamingContext_var dummy = root->bind_new_context( name ); + } + + // Bind the Messenger object + name.length( 2 ); + name[1].id = CORBA::string_dup("Messenger"); + + // Create an object + Messenger_i servant; + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + obj = poa->id_to_reference(oid.in()); + Messenger_var messenger = Messenger::_narrow(obj.in()); + root->rebind(name, messenger.in()); + + std::cout << "Messenger object bound in Naming Service" << std::endl; + + // Accept requests + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "server:Caught a CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.cpp new file mode 100644 index 00000000000..fd6a487bd02 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.cpp @@ -0,0 +1,33 @@ +/* -*- 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 <iostream> +// 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; + } + diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.h new file mode 100644 index 00000000000..0a3c9f1a2e8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/Messenger_i.h @@ -0,0 +1,36 @@ +/* -*- 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); +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/README b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/README new file mode 100644 index 00000000000..4f530421b08 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/README @@ -0,0 +1,65 @@ +// $Id$ + +DevGuideExamples/NamingService/corbaname_Messenger/README + +The example in this directory extends the example in GettingStartedUNIX +(or GettingStartedVC) to use the Naming_Service +and calling string_to_object instead of calling resolve_initial_references +to get the NameService object reference and look up the service in the Naming_Service. + +This example only differs from the NamingService/Messenger example by a few lines +in the MessengerClient.cpp. (All other source files should be the same.) + +How to Run: +----------- +To start the Naming_Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service & + +To start the server: +------------------ +./MessengerServer + +To start the client: +------------------ +./MessengerClient + + +This MessengerClient will optionally take parameter that is a URL (corbaname:) +that addresses the Naming_Service and the MessengerServer within it. + +The MessengerServer and MessengerClient may also take an -ORBInitRef option +to help qualify the address of the Naming_Service. + +Here are some examples: + +REM start the name server +cd/d %TAO_ROOT%\orbsvcs\Naming_Service +title NS +Naming_Service -ORBEndpoint iiop://localhost:2809 -m 0 + +REM start the example server +cd/d %EXAMPLES%\NamingService\corbaname_Messenger\Debug +title server +REM use -ORBInitRef with IIOP +MessengerServer -ORBInitRef NameService=iiop://localhost:2809/NameService + + + +REM start the client +cd/d %EXAMPLES%\NamingService\corbaname_Messenger\Debug +title client + +REM use a corbaname that does not require -ORBDefaultInitRef +MessengerClient corbaname:iiop:localhost:2809#example/Messenger + +REM defaults to iiop protocol +MessengerClient corbaname::localhost:2809#example/Messenger + +REM default protocol (iiop) and default port (2809) +MessengerClient corbaname::localhost#example/Messenger + + + +REM use RIR +MessengerClient -ORBInitRef NameService=iiop://localhost:2809/NameService corbaname:rir:#example/Messenger diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/corbaname_Messenger.mpc b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/corbaname_Messenger.mpc new file mode 100644 index 00000000000..042d4c4b5fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/corbaname_Messenger.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): namingexe, naming_skel { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): namingexe { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/run_test.pl new file mode 100755 index 00000000000..8aa19b03646 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NamingService/corbaname_Messenger/run_test.pl @@ -0,0 +1,72 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + + +$TARGETHOSTNAME = "localhost"; +$def_port = 2809; +$nsior = "ns.ior"; + +# start Naming Service +unlink($nsior); +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-ORBEndpoint iiop://$TARGETHOSTNAME:$def_port -o $nsior"); +$NS->Spawn(); + +if (PerlACE::waitforfile_timed ($nsior, 10) == -1) { + print STDERR "ERROR: cannot find IOR file <$nsior>\n"; + $NS->Kill (); + exit 1; +} + +# start the server +print "Start Messenger Server \n"; +$SR = new PerlACE::Process("MessengerServer", + "-ORBInitRef NameService=iiop://$TARGETHOSTNAME:$def_port/NameService"); +$SR->Spawn(); +sleep(2); + + +@corbaname_clients = ("corbaname:iiop:$TARGETHOSTNAME:2809#example/Messenger", + "corbaname::$TARGETHOSTNAME:2809#example/Messenger", + "corbaname::$TARGETHOSTNAME#example/Messenger", + "-ORBInitRef NameService=iiop://$TARGETHOSTNAME:2809/NameService corbaname:rir:#example/Messenger"); + +@clients_comments = ( "Using a corbaname that does not require -ORBDefaultInitRef: \n", + "Using defaults to iiop protocol: \n", + "Using default protocol (iiop) and default port ($def_port): \n", + "Using Resolve Initial Reference form(must tell ORB where NS is located with -ORBInitRef)\n"); + +# Run the client for each of the corbaname test. +$test_number = 0; +foreach $o (@corbaname_clients) { + + $CL = new PerlACE::Process("MessengerClient", $o); + + if ($CL->SpawnWaitKill(15) != 0) { + print STDERR "ERROR: client failed\n"; + $SR->Kill(); + $NS->Kill(); + exit 1; + } + + $test_number++; + + print "======================================\n"; + print "Finish Test $test_number: $clients_comments[$test_number]\n"; + print " $CL_NAME $o\n"; + print "======================================\n\n"; + +} + +# clean up +$SR->Kill (); +$NS->Kill (); + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequence.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequence.mpc new file mode 100644 index 00000000000..7cd986e6a2d --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequence.mpc @@ -0,0 +1,26 @@ +// $Id$ + +project(*Server): portableserver, orbsvcsexe, notification_skel, naming { + Source_Files { + EventSequenceSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): orbsvcsexe, notification, naming { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): portableserver, orbsvcsexe, notification_skel, naming { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + EventSequenceConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.cpp new file mode 100644 index 00000000000..90be87592af --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.cpp @@ -0,0 +1,49 @@ +// $Id$ + +#include "EventSequenceConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +EventSequenceConsumer_i::EventSequenceConsumer_i(CORBA::ORB_ptr orb) +: orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +EventSequenceConsumer_i::push_structured_events ( + const CosNotification::EventBatch& events + ) +{ + + std::cout << "events received " << std::endl; + + const char* value = 0; + + for (unsigned int n = 0; n < events.length(); ++n) { + for (unsigned int i = 0; i < events[n].filterable_data.length(); ++i) { + events[n].filterable_data[i].value >>= value; + std::cout << events[n].filterable_data[i].name.in() << "\t" << value << std::endl; + } + } +} + +void +EventSequenceConsumer_i::disconnect_sequence_push_consumer () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id(); + poa->deactivate_object(objectId.in()); + +} + +void +EventSequenceConsumer_i::offer_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.h new file mode 100644 index 00000000000..e8bdfef2775 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceConsumer_i.h @@ -0,0 +1,27 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class EventSequenceConsumer_i : public POA_CosNotifyComm::SequencePushConsumer +{ +public: + EventSequenceConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_events ( + const CosNotification::EventBatch & events + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_sequence_push_consumer (); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.cpp new file mode 100644 index 00000000000..4bd0dee0204 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.cpp @@ -0,0 +1,31 @@ +// $Id$ + +#include "EventSequenceSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +EventSequenceSupplier_i::EventSequenceSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +EventSequenceSupplier_i::disconnect_sequence_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +EventSequenceSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.h new file mode 100644 index 00000000000..3a5a153a42e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/EventSequenceSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class EventSequenceSupplier_i : public POA_CosNotifyComm::SequencePushSupplier +{ +public: + // Constructor + EventSequenceSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_sequence_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger.idl new file mode 100644 index 00000000000..c7e25db57d8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger.idl @@ -0,0 +1,9 @@ +// $Id$ + +// messenger.idl +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerClient.cpp new file mode 100644 index 00000000000..eeea6d8701a --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerClient.cpp @@ -0,0 +1,42 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + 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; + } + + CORBA::String_var message = + CORBA::string_dup("Where can I get TAO?"); + + messenger->send_message ( + "person@company.com", + "OCI's Distribution of TAO", + message.inout()); + } + catch(const CORBA::Exception& ex) + { + std::cerr << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerConsumer.cpp new file mode 100644 index 00000000000..1196078a73f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerConsumer.cpp @@ -0,0 +1,86 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "EventSequenceConsumer_i.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + + CosNaming::NamingContextExt_var naming_context = + CosNaming::NamingContextExt::_narrow(obj.in()); + + obj = naming_context->resolve_str("MyEventChannel"); + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(obj.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + obj = orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var poa = PortableServer::POA::_narrow (obj.in()); + + EventSequenceConsumer_i servant(orb.in()); + + PortableServer::ObjectId_var objectId = poa->activate_object(&servant); + + obj = poa->id_to_reference (objectId.in()); + CosNotifyComm::SequencePushConsumer_var consumer = + CosNotifyComm::SequencePushConsumer::_narrow(obj.in()); + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::SEQUENCE_EVENT, + consumeradmin_proxy_id); + + CosNotifyChannelAdmin::SequenceProxyPushSupplier_var supplier_proxy = + CosNotifyChannelAdmin::SequenceProxyPushSupplier::_narrow(proxy_supplier.in()); + + supplier_proxy->connect_sequence_push_consumer(consumer.in()); + + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + supplier_proxy->subscription_change(added, removed); + + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + + poa_manager->activate(); + + orb->run(); + + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + } + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerServer.cpp new file mode 100644 index 00000000000..640f0013c6e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/MessengerServer.cpp @@ -0,0 +1,54 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContextExt_var rootNC = + CosNaming::NamingContextExt::_narrow(obj.in()); + + obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + Messenger_i messenger_servant (orb.in()); + PortableServer::ObjectId_var oid = poa->activate_object (&messenger_servant); + obj = poa->id_to_reference(oid.in()); + CORBA::String_var str = orb->object_to_string (obj.in()); + + std::ofstream iorFile ("Messenger.ior"); + iorFile << str.in() << std::endl; + iorFile.close(); + std::cout << "IOR written to file Messenger.ior " << std::endl; + + orb->run(); + orb->destroy(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << " Caught Exception: " << ex << std::endl; + return 1; + } + + return 0; + +} + + + + + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.cpp new file mode 100644 index 00000000000..17dea7b9aff --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.cpp @@ -0,0 +1,126 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "Messenger_i.h" +#include "EventSequenceSupplier_i.h" + +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) +: orb_ (CORBA::ORB::_duplicate (orb)) +, supplier_(new EventSequenceSupplier_i(orb)) +{ + + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + CosNaming::NamingContextExt_var naming_context = + CosNaming::NamingContextExt::_narrow (naming_obj.in()); + + CORBA::Object_var obj = naming_context->resolve_str("NotifyEventChannelFactory"); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + CosNaming::Name_var name = naming_context->to_name("MyEventChannel"); + naming_context->rebind(name.in(), ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::SEQUENCE_EVENT, + supplieradmin_proxy_id); + + CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in()); + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate (); + + PortableServer::ObjectId_var objectId = poa->activate_object(supplier_.get()); + CORBA::Object_var supplier_obj = poa->id_to_reference(objectId.in()); + + CosNotifyComm::SequencePushSupplier_var supplier = + CosNotifyComm::SequencePushSupplier::_narrow(supplier_obj.in()); + + consumer_proxy_ = + CosNotifyChannelAdmin::SequenceProxyPushConsumer::_narrow(proxy_consumer.in()); + + consumer_proxy_->connect_sequence_push_supplier(supplier.in()); +} + + +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message + ) +{ + + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // OptionalHeaderFields + // PropertySeq + + // sequence<Property>: string name, any value + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + std::cout << "pushing " << std::endl; + CosNotification::EventBatch events; + events.length(4); + events[0] = event; + events[1] = event; + events[2] = event; + events[3] = event; + + consumer_proxy_->push_structured_events(events); + + return 1; + +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.h new file mode 100644 index 00000000000..949f5c87dc6 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/Messenger_i.h @@ -0,0 +1,37 @@ +// $Id$ + +#ifndef MESSENGER_H_ +#define MESSENGER_H_ + +#include "MessengerS.h" + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "ace/Auto_Ptr.h" + +class EventSequenceSupplier_i; + +class Messenger_i : public POA_Messenger +{ + public: + Messenger_i (CORBA::ORB_ptr orb); + + virtual ~Messenger_i (void); + + CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ); + + private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::SequenceProxyPushConsumer_var consumer_proxy_; + auto_ptr<EventSequenceSupplier_i> supplier_; +}; + +#endif + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/README new file mode 100644 index 00000000000..4a60c213d06 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/README @@ -0,0 +1,65 @@ +// $Id$ + +Event Notification Service + + +File: examples/NotifyService/EventSequence/README + +This directory contains an example which transmits an EventBatch using the Notification Service. + +This example extends the Messenger example in GettingStarted directory +to illustrate how the Notification channel can be used to push event batches +from the supplier to the consumer. The example uses the push/push model. + +The MessengerServer in this example plays the role of a server for +the MessengerClient and the role of a supplier for the MessengerConsumer. +The flow of messages is shown below: + +MessengerClient->MessengerSupplier->NotificationChannel->MessengerConsumer. + + +The Client code is stored in: + +examples/NotifyService/EventSequence/MessengerClient.cpp + +The Server code is stored in: + +examples/NotifyService/EventSequence/MessengerServer.cpp + +The Consumer code is stored in: + +examples/NotifyService/EventSequence/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.ior& + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/EventSequence/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/run_test.pl new file mode 100755 index 00000000000..b787dd9f8c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/EventSequence/run_test.pl @@ -0,0 +1,77 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, "$arg_ns_ref -IORoutput $notify_ior"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Filtering.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Filtering.mpc new file mode 100644 index 00000000000..88a7660808e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Filtering.mpc @@ -0,0 +1,29 @@ +// $Id$ + +project(*Server): portableserver, orbsvcsexe, notification_skel, naming { + exename = MessengerServer + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): orbsvcsexe, notification, naming { + exename = MessengerClient + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): portableserver, orbsvcsexe, notification_skel, naming { + exename = MessengerConsumer + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger.idl new file mode 100644 index 00000000000..657fea8c323 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger.idl @@ -0,0 +1,11 @@ +// $Id$ + + +// messenger.idl + +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerClient.cpp new file mode 100644 index 00000000000..8d52a5af557 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerClient.cpp @@ -0,0 +1,64 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "MessengerC.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var rootObj = + orb->resolve_initial_references("NameService"); + + CosNaming::NamingContext_var rootContext = + CosNaming::NamingContext::_narrow(rootObj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("MessengerService"); + + CORBA::Object_var messengerObj = rootContext->resolve(name); + + if (CORBA::is_nil(messengerObj.in())) { + std::cerr << "Nil Messenger reference" << std::endl; + return 1; + } + + // Narrow + Messenger_var messenger = Messenger::_narrow(messengerObj.in()); + if (CORBA::is_nil(messenger.in ())) { + std::cerr << "Argument is not a Messenger reference" << std::endl; + return 1; + } + + CORBA::String_var message = CORBA::string_dup( + "We are experiencing network problems."); + messenger->send_message ("sysadmin@company.com", + "urgent", + message.inout()); + + message = CORBA::string_dup("Where can I get TAO?"); + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + + message = CORBA::string_dup( + "Please contact sales@company.com regarding your request."); + messenger->send_message ("sysadmin@company.com", + "OCI's Distribution of TAO", + message.inout()); + + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + std::cout << "MessengerClient: success" << std::endl; + return 0; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerConsumer.cpp new file mode 100644 index 00000000000..035b72b23c0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerConsumer.cpp @@ -0,0 +1,158 @@ +// $Id$ + +#include "ace/Get_Opt.h" + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "StructuredEventConsumer_i.h" +#include <iostream> + +#define CA_FILTER "($.From == 'sysadmin@company.com') and ($.Subject == 'urgent') " +#define TCL_GRAMMAR "EXTENDED_TCL" + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + return 1; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name(1); + name.length (1); + name[0].id = CORBA::string_dup("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in()); + + if (CORBA::is_nil(notify_factory.in())) { + std::cerr << "Unable to find notify factory" << std::endl; + return 1; + } + + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to find event channel" << std::endl; + return 1; + } + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::AND_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + if (CORBA::is_nil (consumer_admin.in())) { + std::cerr << "Unable to find consumer admin" << std::endl; + return 1; + } + + CosNotifyFilter::FilterFactory_var ffact = + ec->default_filter_factory (); + + // setup a filter at the consumer admin + CosNotifyFilter::Filter_var ca_filter = + ffact->create_filter (TCL_GRAMMAR); + + if (CORBA::is_nil (ca_filter.in())) { + std::cerr << "Unable to create filetr object" << std::endl; + return 1; + } + + CosNotifyFilter::ConstraintExpSeq constraint_list (1); + constraint_list.length (1); + constraint_list[0].event_types.length (0); + constraint_list[0].constraint_expr = CORBA::string_dup (CA_FILTER); + + ca_filter->add_constraints (constraint_list); + + consumer_admin ->add_filter (ca_filter.in()); + + CosNotification::EventTypeSeq added(1); + CosNotification::EventTypeSeq removed (0); + added.length (1); + removed.length (0); + + added[0].domain_name = CORBA::string_dup ("*"); + added[0].type_name = CORBA::string_dup ("*"); + + consumer_admin->subscription_change (added, removed); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in())) { + std::cerr << "Unable to initialize the POA." << std::endl; + return 1; + } + + PortableServer::POA_var poa = + PortableServer::POA::_narrow(poa_object.in()); + + StructuredEventConsumer_i servant(orb.in()); + /* + CosNotifyComm::StructuredPushConsumer_var consumer = + servant._this(); + */ + + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + CosNotifyComm::StructuredPushConsumer_var consumer = + CosNotifyComm::StructuredPushConsumer::_narrow(consumer_obj.in()); + + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + + // The proxy that we are connected to. + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: + _narrow(proxy_supplier.in()); + + if (CORBA::is_nil (supplier_proxy.in())) { + std::cerr << "Unable to create structured push supplier proxy" << std::endl; + return 1; + } + + supplier_proxy->connect_structured_push_consumer(consumer.in()); + + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + + poa_manager->activate(); + + orb->run(); + orb->destroy (); + + } + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + return 1; + } + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerServer.cpp new file mode 100644 index 00000000000..a26fb9a60c4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/MessengerServer.cpp @@ -0,0 +1,94 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include "ace/Argv_Type_Converter.h" +#include "ace/Get_Opt.h" +#include <iostream> +#include <fstream> + +ACE_TString ior_output_file; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'o': + ior_output_file = get_opts.optarg; + break; + + case '?': + default: + std::cerr << "usage: " << argv[0] << " -o <ior>" << std::endl; + return -1; + break; + } + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR* argv[]) +{ + try + { + // Initialize orb + ACE_Argv_Type_Converter conv(argc, argv); + CORBA::ORB_var orb = CORBA::ORB_init(conv.get_argc(), + conv.get_TCHAR_argv()); + + if (parse_args(argc, argv) != 0) { + return 1; + } + + // Find the Naming Service. + CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var rootNC = + CosNaming::NamingContext::_narrow(rootObj.in()); + + // Get the 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 our Messenger servant. + Messenger_i messenger_servant(orb.in()); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = + poa->activate_object( &messenger_servant ); + CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() ); + + // Generating the ior file is just for the purpose of synchronize the + // the startup of the server and consumer. + CORBA::String_var ior = orb->object_to_string(messenger_obj.in()); + if (ior_output_file != ACE_TEXT("")) { + std::ofstream outfile(ACE_TEXT_ALWAYS_CHAR(ior_output_file.c_str())); + outfile << ior.in(); + } + + // Bind it in the Naming Service. + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MessengerService"); + rootNC->rebind(name, messenger_obj.in()); + + // Accept requests + orb->run(); + orb->destroy(); + + } + catch(const CORBA::Exception& ex) + { + std::cerr << ex << std::endl; + return 1; + } + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.cpp new file mode 100644 index 00000000000..f63bc493769 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.cpp @@ -0,0 +1,162 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" + +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate(orb)) + +{ + try + { + CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj.in()); + + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name(1); + name.length (1); + name[0].id = CORBA::string_dup("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in()); + + if (CORBA::is_nil(notify_factory.in())) { + std::cerr << "Unable to find notify factory" << std::endl; + } + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to crete event channel" << std::endl; + } + + name.length(1); + name[0].id = CORBA::string_dup("MyEventChannel"); + + naming_context->rebind(name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::AND_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + if (CORBA::is_nil (supplier_admin.in())) { + std::cerr << "Unable to find supplier admin" << std::endl; + } + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + PortableServer::ObjectId_var oid = poa->activate_object(servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + CosNotifyComm::StructuredPushSupplier_var supplier = + CosNotifyComm::StructuredPushSupplier::_narrow(supplier_obj.in()); + + consumer_proxy_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer:: + _narrow(proxy_consumer.in()); + + if (CORBA::is_nil (consumer_proxy_.in())) { + std::cerr << "Unable to find structured proxy push consumer" << std::endl; + } + + consumer_proxy_->connect_structured_push_supplier(supplier.in()); + + } + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + } + +} + + +// Implementation skeleton destructor +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message + ) +{ + + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + try + { + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // sequence<Property>: string name, any value + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("From"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message"); + event.filterable_data[2].value <<= (const char *)message; + + consumer_proxy_->push_structured_event(event); + } + + catch(const CosNotifyComm::InvalidEventType&) { + std::cerr << "Invalid Event Type Exception " << std::endl; + return 1; + } + + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + return 1; + } + return 0; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.h new file mode 100644 index 00000000000..087c07b3aba --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/Messenger_i.h @@ -0,0 +1,34 @@ +// $Id$ + +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "MessengerS.h" + +//Class Messenger_i +class Messenger_i : public virtual POA_Messenger +{ +public: + //Constructor + Messenger_i (CORBA::ORB_ptr orb); + + //Destructor + virtual ~Messenger_i (void); + + CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ); + +private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy_; + +}; + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/README new file mode 100644 index 00000000000..c91cd77888d --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/README @@ -0,0 +1,64 @@ +// $Id$ + +Event Notification Service + + +File: DevGuideExamples/NotifyService/Filtering/README + + +This example extends the NotifyService/Messenger example by +demonstrating how filtering can be incorporated into the utilization +of the Notification channel. Supplier-side, and consumer-side +filtering can be implemented, but only consumer_side filtering is +demonstrated in this example. + +Filters are configured to guarantee that only certain events are +passed to the consumer. The criteria is specified by imposing constraints +on the appropriate fields of a structured event. + + +The Client code is stored in: + +DevGuideExamples/NotifyService/Filtering/MessengerClient.cpp + +The Server code is stored in: + +DevGuideExamples/NotifyService/Filtering/MessengerServer.cpp + +The Consumer code is stored in: + +DevGuideExamples/NotifyService/Filtering/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.ior& + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..bcf2f8ceeaf --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.cpp @@ -0,0 +1,49 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event + ) +{ + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name << "\t" <<value<< std::endl; + } + + std::cerr << "MessengerConsumer: success" << std::endl; +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer( + ) +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ + //Noop +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..2cee3e77fd8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventConsumer_i.h @@ -0,0 +1,30 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventConsumer_i : + public virtual POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_structured_push_consumer( + ); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..4d086d17e7e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.cpp @@ -0,0 +1,29 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq &) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..9f18951c030 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/StructuredEventSupplier_i.h @@ -0,0 +1,26 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventSupplier_i : + public virtual POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier ( + ); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/run_test.pl new file mode 100755 index 00000000000..7a52de8ba1d --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Filtering/run_test.pl @@ -0,0 +1,77 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, "$arg_ns_ref -IORoutput $notify_ior"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", "$arg_ns_ref -o $messiorfile"); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger.idl new file mode 100644 index 00000000000..e2b13b5a3e4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger.idl @@ -0,0 +1,10 @@ +// $Id$ + +// messenger.idl + +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerClient.cpp new file mode 100644 index 00000000000..226fd6b54c6 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerClient.cpp @@ -0,0 +1,41 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + 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; + } + + CORBA::String_var message = CORBA::string_dup( + "Where can I get TAO?"); + for (int i=0; i<3; i++) { + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + } + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerConsumer.cpp new file mode 100644 index 00000000000..63a9956ca80 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerConsumer.cpp @@ -0,0 +1,93 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "StructuredEventConsumer_i.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var poa = + PortableServer::POA::_narrow (poa_object.in()); + + StructuredEventConsumer_i servant (orb.in()); + + PortableServer::ObjectId_var objectId = poa->activate_object (&servant); + + CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushConsumer_var consumer = + CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: + _narrow(proxy_supplier.in()); + + supplier_proxy->connect_structured_push_consumer(consumer.in()); + + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + supplier_proxy->subscription_change(added, removed); + + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + + poa_manager->activate(); + + orb->run(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerServer.cpp new file mode 100644 index 00000000000..aa3ad6bb744 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/MessengerServer.cpp @@ -0,0 +1,50 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + Messenger_i messenger_servant (orb.in ()); + 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; + + orb->run (); + orb->destroy (); + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; + +} + + + + + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.cpp new file mode 100644 index 00000000000..91addf9f407 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.cpp @@ -0,0 +1,124 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" +#include "ace/OS_NS_stdio.h" + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ + + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve (name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + name[0].id = CORBA::string_dup ("MyEventChannel"); + + naming_context->rebind (name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); + PortableServer::POAManager_var mgr = poa->the_POAManager (); + + mgr->activate (); + PortableServer::ObjectId_var objectId = poa->activate_object (servant); + + CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushSupplier_var supplier = + CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ()); + + consumer_proxy_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in()); + + consumer_proxy_-> + connect_structured_push_supplier (supplier.in()); +} + +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message) +{ + ACE_OS::printf("Message from: %s\nSubject: %s\nMessage: %s\n", + user_name, subject, message); + //cout << "Message from: " << user_name << endl; + //cout << "Subject: " << subject << endl; + //cout << "Message: " << message << endl; + + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // OptionalHeaderFields + // PropertySeq + + // sequence<Property>: string name, any value + event.filterable_data.length (3); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + std::cout << "pushing " << std::endl; + consumer_proxy_->push_structured_event(event); + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.h new file mode 100644 index 00000000000..38fa49c29e9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/Messenger_i.h @@ -0,0 +1,30 @@ +// $Id$ + +#ifndef MESSENGER_H_ +#define MESSENGER_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "MessengerS.h" + +class Messenger_i : public POA_Messenger +{ + public: + Messenger_i (CORBA::ORB_ptr orb); + + virtual ~Messenger_i (void); + + CORBA::Boolean send_message (const char * user_name, + const char * subject, + char *& message); + + private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy_; +}; + +#endif + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/NotifyServiceMessenger.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/NotifyServiceMessenger.mpc new file mode 100644 index 00000000000..c6cd2f3d24c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/NotifyServiceMessenger.mpc @@ -0,0 +1,25 @@ +// $Id$ + +project(*Server): taoexe, portableserver, namingexe, notification_skel { + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): taoexe, namingexe, notification { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): taoexe, portableserver, namingexe, notification_skel { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/README new file mode 100644 index 00000000000..29688714703 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/README @@ -0,0 +1,66 @@ +// $Id$ + +Event Notification Service + + +File: examples/NotifyService/Messenger/README + +This directory contains a simple example of using the Notification Service. + +This example extends the Messenger example in GettingStarted directory +to illustrate how the Notification channel can be used to push messages +from the supplier to the consumer. Structured events are used to demonstrate +the operation of the channel. The example uses the push/push model. + +The MessengerServer in this example plays the role of a server for +the MessengerClient and the role of a supplier for the MessengerConsumer. +The flow of messages is shown below: + +MessengerClient->MessengerSupplier->NotificationChannel->MessengerConsumer. + + +The Client code is stored in: + +examples/NotifyService/Messenger/MessengerClient.cpp + +The Server code is stored in: + +examples/NotifyService/Messenger/MessengerServer.cpp + +The Consumer code is stored in: + +examples/NotifyService/Messenger/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.ior& + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..74c54474e14 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.cpp @@ -0,0 +1,48 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event + ) +{ + + std::cout << "event received " << std::endl; + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name.in() << "\t" << value << std::endl; + } + +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer() +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..adb5bd999c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventConsumer_i.h @@ -0,0 +1,29 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyCommS.h" + +class StructuredEventConsumer_i : + public virtual POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_structured_push_consumer(); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..18fd224aa8e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.cpp @@ -0,0 +1,31 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..6df2455fcb0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/StructuredEventSupplier_i.h @@ -0,0 +1,24 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyCommS.h" + +class StructuredEventSupplier_i : + public virtual POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/run_test.pl new file mode 100755 index 00000000000..b787dd9f8c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/Messenger/run_test.pl @@ -0,0 +1,77 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, "$arg_ns_ref -IORoutput $notify_ior"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger.idl new file mode 100644 index 00000000000..e2b13b5a3e4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger.idl @@ -0,0 +1,10 @@ +// $Id$ + +// messenger.idl + +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerClient.cpp new file mode 100644 index 00000000000..cf6f2cec87c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerClient.cpp @@ -0,0 +1,54 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var rootObj = + orb->resolve_initial_references("NameService"); + + CosNaming::NamingContext_var rootContext = + CosNaming::NamingContext::_narrow(rootObj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("MessengerService"); + + CORBA::Object_var messengerObj = rootContext->resolve(name); + + Messenger_var messenger = Messenger::_narrow(messengerObj.in()); + + if (CORBA::is_nil(messenger.in ())) { + std::cerr << "Argument is not a Messenger reference" << std::endl; + } + + CORBA::String_var message = CORBA::string_dup("Where can I get TAO?"); + + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + std::cout << "MessengerClient: success" << std::endl; + return 0; + +} + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerConsumer.cpp new file mode 100644 index 00000000000..589b6a37c70 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerConsumer.cpp @@ -0,0 +1,115 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "StructuredEventConsumer_i.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in())) { + std::cerr << "Unable to initialize the POA." << std::endl; + return 1; + } + + PortableServer::POA_var poa = + PortableServer::POA::_narrow(poa_object.in()); + + // Activate POA manager + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + return 1; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name(1); + + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to find event channel" << std::endl; + return 1; + } + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + if (CORBA::is_nil (consumer_admin.in())) { + std::cerr << "Unable to find consumer admin" << std::endl; + return 1; + } + + StructuredEventConsumer_i servant(orb.in()); + + CosNotifyComm::StructuredPushConsumer_var consumer = + servant._this(); + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + // The proxy that we are connected to. + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: + _narrow(proxy_supplier.in()); + + if (CORBA::is_nil (supplier_proxy.in())) { + std::cerr << "Unable to create structured push supplier proxy" << std::endl; + return 1; + } + + supplier_proxy->connect_structured_push_consumer(consumer.in()); + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + supplier_proxy->subscription_change(added, removed); + + orb->run(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << "MessengerConsumer:: Caught exception: " << ex << std::endl; + return 1; + } + std::cerr << "MessengerConsumer: success" << std::endl; + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerServer.cpp new file mode 100644 index 00000000000..e64d6a4b4c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/MessengerServer.cpp @@ -0,0 +1,65 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); + + CosNaming::NamingContext_var rootNC = + CosNaming::NamingContext::_narrow(rootObj.in()); + + // 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(orb.in()); + + Messenger_var messenger = messenger_servant._this(); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MessengerService"); + + rootNC->rebind(name, messenger.in()); + + CORBA::String_var str = orb->object_to_string (messenger.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(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << "MessengerServer::Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} + + + + + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.cpp new file mode 100644 index 00000000000..b362f3ba60e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.cpp @@ -0,0 +1,155 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ + CORBA::Object_var poa_object = + orb_->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in())) { + std::cerr << "Unable to initialize the POA." << std::endl; + } + + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow(obj.in()); + + if (CORBA::is_nil(notify_factory.in())) { + std::cerr << "Unable to find notify factory" << std::endl; + } + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to crete event channel" << std::endl; + } + + // name.length(1); + name[0].id = CORBA::string_dup("MyEventChannel"); + + naming_context->rebind(name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + if (CORBA::is_nil (supplier_admin.in())) { + std::cerr << "Unable to find supplier admin" << std::endl; + } + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + CosNotifyComm::StructuredPushSupplier_var supplier = + servant->_this(); + + s_proxy_consumer_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer:: + _narrow(proxy_consumer.in()); + + if (CORBA::is_nil (s_proxy_consumer_.in())) { + std::cerr << "Unable to find structured proxy push consumer" << std::endl; + } + + s_proxy_consumer_-> + connect_structured_push_supplier(supplier.in()); + + + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + s_proxy_consumer_->offer_change(added, removed); +} + +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message) +{ + + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // OptionalHeaderFields + // PropertySeq + + // sequence<Property>: string name, any value + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + s_proxy_consumer_->push_structured_event(event); + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.h new file mode 100644 index 00000000000..401201354b4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/Messenger_i.h @@ -0,0 +1,25 @@ +// $Id$ + +#ifndef MESSENGER_H_ +#define MESSENGER_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "MessengerS.h" + +class Messenger_i : public POA_Messenger +{ +public: + Messenger_i (CORBA::ORB_ptr orb); + virtual ~Messenger_i (void); + + CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message); + +private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var s_proxy_consumer_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/OfferSubscriptions.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/OfferSubscriptions.mpc new file mode 100644 index 00000000000..c6cd2f3d24c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/OfferSubscriptions.mpc @@ -0,0 +1,25 @@ +// $Id$ + +project(*Server): taoexe, portableserver, namingexe, notification_skel { + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): taoexe, namingexe, notification { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): taoexe, portableserver, namingexe, notification_skel { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/README new file mode 100644 index 00000000000..90edd9fa6a0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/README @@ -0,0 +1,68 @@ +// $Id$ + +Event Notification Service + + +File: examples/NotifyService/OfferSubscriptions/README + + +This example extends the NotifyService/Messenger example by incorporating +"offers" and "subscriptions" into the utilization of the Notification +channel. + +The publication of "offers" by a supplier, informs consumers of the +Notification channel about the types of events it will be producing. This +is accomplished via the 'offer_change()' operation. + +Moreover, the example demonstrates how consumers can inform Notification +channel suppliers about the types of events in which they are interested. +The set of events in which a consumer is interested is called a "subscription" +and can be communicated via the 'subscription_change()' operation. + + + +The Client code is stored in: + +examples/NotifyService/OfferSubscriptions/MessengerClient.cpp + +The Server code is stored in: + +examples/NotifyService/OfferSubscriptions/MessengerServer.cpp + +The Consumer code is stored in: + +examples/NotifyService/OfferSubscriptions/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.ior& + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..684122ac49f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.cpp @@ -0,0 +1,47 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event + ) +{ + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name << "\t" <<value<< std::endl; + } + +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer( + ) +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..86c10e74910 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventConsumer_i.h @@ -0,0 +1,27 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventConsumer_i : public POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_structured_push_consumer(); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..e6cf9911d12 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.cpp @@ -0,0 +1,29 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq &) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..aac055fad6c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/StructuredEventSupplier_i.h @@ -0,0 +1,22 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventSupplier_i : public POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/run_test.pl new file mode 100755 index 00000000000..b787dd9f8c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/OfferSubscriptions/run_test.pl @@ -0,0 +1,77 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, "$arg_ns_ref -IORoutput $notify_ior"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger.idl new file mode 100644 index 00000000000..e2b13b5a3e4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger.idl @@ -0,0 +1,10 @@ +// $Id$ + +// messenger.idl + +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerClient.cpp new file mode 100644 index 00000000000..21c6615ea95 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerClient.cpp @@ -0,0 +1,42 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + 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; + } + + CORBA::String_var message = CORBA::string_dup( + "Where can I get TAO?"); + for (int i=0; i<3; i++) { + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + } + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerConsumer.cpp new file mode 100644 index 00000000000..ca63f55d999 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerConsumer.cpp @@ -0,0 +1,99 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "StructuredEventConsumer_i.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, adminid); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var poa = + PortableServer::POA::_narrow (poa_object.in()); + + StructuredEventConsumer_i servant (orb.in()); + + PortableServer::ObjectId_var objectId = poa->activate_object (&servant); + + CORBA::Object_var consumer_obj = poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushConsumer_var consumer = + CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = + CosNotifyChannelAdmin::StructuredProxyPushSupplier::_narrow(proxy_supplier.in()); + + CosNotification::QoSProperties properties (1); + + properties.length (1); + properties[0].name = CORBA::string_dup (CosNotification::OrderPolicy); + properties[0].value <<= CosNotification::FifoOrder; + + supplier_proxy->set_qos (properties); + supplier_proxy->connect_structured_push_consumer(consumer.in()); + + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + supplier_proxy->subscription_change(added, removed); + + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + + poa_manager->activate(); + + orb->run(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerServer.cpp new file mode 100644 index 00000000000..94ec2c65574 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/MessengerServer.cpp @@ -0,0 +1,46 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +#include <fstream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var rootNC = + CosNaming::NamingContext::_narrow(rootObj.in()); + + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + Messenger_i messenger_servant (orb.in ()); + 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; + + orb->run (); + orb->destroy (); + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.cpp new file mode 100644 index 00000000000..e5d99375ae4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.cpp @@ -0,0 +1,137 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve (name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + initial_admin.length (4); + + initial_admin[0].name = CORBA::string_dup (CosNotification::MaxQueueLength); + initial_admin[0].value <<= (CORBA::Long)7; + + initial_admin[1].name = CORBA::string_dup (CosNotification::MaxSuppliers); + initial_admin[1].value <<= (CORBA::Long)1; + + initial_admin[2].name = CORBA::string_dup (CosNotification::MaxConsumers); + initial_admin[2].value <<= (CORBA::Long)1; + + initial_admin[3].name = CORBA::string_dup (CosNotification::RejectNewEvents); + initial_admin[3].value <<= CORBA::Any::from_boolean((CORBA::Boolean)1); + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + name[0].id = CORBA::string_dup ("MyEventChannel"); + + naming_context->rebind (name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); + PortableServer::POAManager_var mgr = poa->the_POAManager (); + + mgr->activate (); + PortableServer::ObjectId_var objectId = poa->activate_object (servant); + + CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushSupplier_var supplier = + CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ()); + + consumer_proxy_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in()); + + consumer_proxy_-> + connect_structured_push_supplier (supplier.in()); +} + + +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message) +{ + + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // OptionalHeaderFields + // PropertySeq + + // sequence<Property>: string name, any value + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + std::cout << "pushing " << std::endl; + consumer_proxy_->push_structured_event(event); + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.h new file mode 100644 index 00000000000..38fa49c29e9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/Messenger_i.h @@ -0,0 +1,30 @@ +// $Id$ + +#ifndef MESSENGER_H_ +#define MESSENGER_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "MessengerS.h" + +class Messenger_i : public POA_Messenger +{ + public: + Messenger_i (CORBA::ORB_ptr orb); + + virtual ~Messenger_i (void); + + CORBA::Boolean send_message (const char * user_name, + const char * subject, + char *& message); + + private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy_; +}; + +#endif + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/QoSProperties.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/QoSProperties.mpc new file mode 100644 index 00000000000..c6cd2f3d24c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/QoSProperties.mpc @@ -0,0 +1,25 @@ +// $Id$ + +project(*Server): taoexe, portableserver, namingexe, notification_skel { + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): taoexe, namingexe, notification { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): taoexe, portableserver, namingexe, notification_skel { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/README new file mode 100644 index 00000000000..d35c3106746 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/README @@ -0,0 +1,57 @@ +// $Id$ + +Event Notification Service + + +File: DevGuideExamples/NotifyService/QoSProperties/README + + +This example extends the NotifyService/Messenger example by +demonstrating how QoS features can be incorporated into the utilization +of the Notification channel. + +The Client code is stored in: + +DevGuideExamples/NotifyService/QoSProperties/MessengerClient.cpp + +The Server code is stored in: + +DevGuideExamples/NotifyService/QoSProperties/MessengerServer.cpp + +The Consumer code is stored in: + +DevGuideExamples/NotifyService/QoSProperties/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.ior& + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..74c54474e14 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.cpp @@ -0,0 +1,48 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event + ) +{ + + std::cout << "event received " << std::endl; + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name.in() << "\t" << value << std::endl; + } + +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer() +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..567e8e1a57c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventConsumer_i.h @@ -0,0 +1,29 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventConsumer_i : + public virtual POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_structured_push_consumer(); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..18fd224aa8e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.cpp @@ -0,0 +1,31 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..01fad5fb2d0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/StructuredEventSupplier_i.h @@ -0,0 +1,24 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventSupplier_i : + public virtual POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/run_test.pl new file mode 100755 index 00000000000..b787dd9f8c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/QoSProperties/run_test.pl @@ -0,0 +1,77 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, "$arg_ns_ref -IORoutput $notify_ior"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger.idl new file mode 100644 index 00000000000..e2b13b5a3e4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger.idl @@ -0,0 +1,10 @@ +// $Id$ + +// messenger.idl + +interface Messenger +{ + boolean send_message(in string user_name, + in string subject, + inout string message); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerClient.cpp new file mode 100644 index 00000000000..226fd6b54c6 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerClient.cpp @@ -0,0 +1,41 @@ +// $Id$ + +#include "MessengerC.h" +#include "orbsvcs/CosNamingC.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + 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; + } + + CORBA::String_var message = CORBA::string_dup( + "Where can I get TAO?"); + for (int i=0; i<3; i++) { + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + } + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerConsumer.cpp new file mode 100644 index 00000000000..9f981295a41 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerConsumer.cpp @@ -0,0 +1,175 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/NotifyExtC.h" +#include "tao/RTCORBA/RTCORBA.h" + +#include "StructuredEventConsumer_i.h" +#include "Priorities.h" +#include <iostream> + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var poa = + PortableServer::POA::_narrow (poa_object.in()); + + CORBA::Object_var rtorb_obj = orb->resolve_initial_references ("RTORB"); + RTCORBA::RTORB_var rt_orb = RTCORBA::RTORB::_narrow (rtorb_obj.in ()); + + // Create an RT POA with a lane at the given priority. + CORBA::Policy_var priority_model_policy = + rt_orb->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED, + DEFAULT_PRIORITY); + + RTCORBA::ThreadpoolLanes lanes (2); + lanes.length (2); + + lanes[0].lane_priority = LOW_PRIORITY; + lanes[0].static_threads = 2; + lanes[0].dynamic_threads = 0; + lanes[1].lane_priority = HIGH_PRIORITY; + lanes[1].static_threads = 2; + lanes[1].dynamic_threads = 0; + + + // Create a thread-pool. + CORBA::ULong stacksize = 0; + CORBA::Boolean allow_request_buffering = 0; + CORBA::ULong max_buffered_requests = 0; + CORBA::ULong max_request_buffer_size = 0; + CORBA::Boolean allow_borrowing = 0; + + // Create the thread-pool. + RTCORBA::ThreadpoolId threadpool_id = + rt_orb->create_threadpool_with_lanes (stacksize, + lanes, + allow_borrowing, + allow_request_buffering, + max_buffered_requests, + max_request_buffer_size); + + // Create a thread-pool policy. + CORBA::Policy_var lanes_policy = + rt_orb->create_threadpool_policy (threadpool_id); + + CORBA::PolicyList poa_policy_list(2); + poa_policy_list.length (2); + poa_policy_list[0] = priority_model_policy; + poa_policy_list[1] = lanes_policy; + + PortableServer::POAManager_var poa_manager = poa->the_POAManager (); + + PortableServer::POA_var rt_poa = poa->create_POA ("RT POA", + poa_manager.in (), + poa_policy_list); + + StructuredEventConsumer_i servant (orb.in()); + + PortableServer::ObjectId_var objectId = + rt_poa->activate_object (&servant); + + CORBA::Object_var consumer_obj = + rt_poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushConsumer_var consumer = + CosNotifyComm::StructuredPushConsumer::_narrow (consumer_obj.in ()); + + NotifyExt::ThreadPoolLanesParams tpl_params; + + tpl_params.priority_model = NotifyExt::CLIENT_PROPAGATED; + tpl_params.server_priority = DEFAULT_PRIORITY; + tpl_params.stacksize = 0; + tpl_params.allow_borrowing = 0; + tpl_params.allow_request_buffering = 0; + tpl_params.max_buffered_requests = 0; + tpl_params.max_request_buffer_size = 0; + tpl_params.lanes.length (2); + tpl_params.lanes[0].lane_priority = LOW_PRIORITY; + tpl_params.lanes[0].static_threads = 2; + tpl_params.lanes[0].dynamic_threads = 0; + tpl_params.lanes[1].lane_priority = HIGH_PRIORITY; + tpl_params.lanes[1].static_threads = 2; + tpl_params.lanes[1].dynamic_threads = 0; + CosNotification::QoSProperties qos; + qos.length(1); + qos[0].name = CORBA::string_dup (NotifyExt::ThreadPoolLanes); + qos[0].value <<= tpl_params; + + consumer_admin->set_qos(qos); + CORBA::Object_var current_obj = + orb->resolve_initial_references ("RTCurrent"); + + RTCORBA::Current_var current = + RTCORBA::Current::_narrow (current_obj.in ()); + current->the_priority(HIGH_PRIORITY); + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: + _narrow(proxy_supplier.in()); + + supplier_proxy->connect_structured_push_consumer(consumer.in()); + + CosNotification::EventTypeSeq added (1); + CosNotification::EventTypeSeq removed (1); + added.length (1); + removed.length (1); + + added[0].domain_name = CORBA::string_dup ("OCI_TAO"); + added[0].type_name = CORBA::string_dup ("examples"); + + removed[0].domain_name = CORBA::string_dup ("*"); + removed[0].type_name = CORBA::string_dup ("*"); + + supplier_proxy->subscription_change(added, removed); + + poa_manager->activate(); + + orb->run(); + } + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerServer.cpp new file mode 100644 index 00000000000..aa3ad6bb744 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/MessengerServer.cpp @@ -0,0 +1,50 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var mgr = poa->the_POAManager(); + mgr->activate(); + + Messenger_i messenger_servant (orb.in ()); + 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; + + orb->run (); + orb->destroy (); + } + + catch(const CORBA::Exception& ex) + { + std::cerr << "Caught exception: " << ex << std::endl; + return 1; + } + + return 0; + +} + + + + + + + + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.cpp new file mode 100644 index 00000000000..c6dc34bc7e1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.cpp @@ -0,0 +1,154 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/NotifyExtC.h" +#include "ace/OS_NS_stdio.h" + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" +#include "Priorities.h" +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow (naming_obj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("NotifyEventChannelFactory"); + + CORBA::Object_var obj = naming_context->resolve (name); + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + CosNotifyChannelAdmin::EventChannelFactory::_narrow (obj.in ()); + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + name[0].id = CORBA::string_dup ("MyEventChannel"); + + naming_context->rebind (name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + NotifyExt::ThreadPoolLanesParams tpl_params; + + tpl_params.priority_model = NotifyExt::CLIENT_PROPAGATED; + tpl_params.server_priority = DEFAULT_PRIORITY; + tpl_params.stacksize = 0; + tpl_params.allow_borrowing = 0; + tpl_params.allow_request_buffering = 0; + tpl_params.max_buffered_requests = 0; + tpl_params.max_request_buffer_size = 0; + tpl_params.lanes.length (2); + tpl_params.lanes[0].lane_priority = LOW_PRIORITY; + tpl_params.lanes[0].static_threads = 2; + tpl_params.lanes[0].dynamic_threads = 0; + tpl_params.lanes[1].lane_priority = HIGH_PRIORITY; + tpl_params.lanes[1].static_threads = 2; + tpl_params.lanes[1].dynamic_threads = 0; + CosNotification::QoSProperties qos; + qos.length(1); + qos[0].name = CORBA::string_dup (NotifyExt::ThreadPoolLanes); + qos[0].value <<= tpl_params; + + supplier_admin->set_qos(qos); + CORBA::Object_var current_obj = + this->orb_->resolve_initial_references ("RTCurrent"); + + current_ = RTCORBA::Current::_narrow (current_obj.in ()); + current_->the_priority(HIGH_PRIORITY); + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + CORBA::Object_var poa_obj = orb_->resolve_initial_references ("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow (poa_obj.in ()); + PortableServer::POAManager_var mgr = poa->the_POAManager (); + + mgr->activate (); + PortableServer::ObjectId_var objectId = poa->activate_object (servant); + + CORBA::Object_var supplier_obj = poa->id_to_reference (objectId.in ()); + + CosNotifyComm::StructuredPushSupplier_var supplier = + CosNotifyComm::StructuredPushSupplier::_narrow (supplier_obj.in ()); + + consumer_proxy_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow (proxy_consumer.in()); + + consumer_proxy_-> + connect_structured_push_supplier (supplier.in()); +} + + +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message) +{ + ACE_OS::printf("Message from: %s\nSubject: %s\nMessage: %s\n", + user_name, subject, message); + //cout << "Message from: " << user_name << endl; + //cout << "Subject: " << subject << endl; + //cout << "Message: " << message << endl; + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // OptionalHeaderFields + // PropertySeq + + // sequence<Property>: string name, any value + event.filterable_data.length (3); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + std::cout << "pushing " << std::endl; + current_->the_priority(HIGH_PRIORITY); + consumer_proxy_->push_structured_event(event); + + return 1; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.h new file mode 100644 index 00000000000..9eb0591df2e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Messenger_i.h @@ -0,0 +1,27 @@ +// $Id$ + +#ifndef MESSENGER_H_ +#define MESSENGER_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "MessengerS.h" +#include "tao/RTCORBA/RTCORBA.h" + +class Messenger_i : public POA_Messenger +{ + public: + Messenger_i (CORBA::ORB_ptr orb); + + virtual ~Messenger_i (void); + + CORBA::Boolean send_message (const char * user_name, + const char * subject, + char *& message); + + private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy_; + RTCORBA::Current_var current_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Priorities.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Priorities.h new file mode 100644 index 00000000000..581af1cb221 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/Priorities.h @@ -0,0 +1,10 @@ +// $Id$ + +#ifndef _PRIORITIES_H_ +#define _PRIORITIES_H_ + +#define LOW_PRIORITY 0 +#define HIGH_PRIORITY 0 +#define DEFAULT_PRIORITY LOW_PRIORITY + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/README new file mode 100644 index 00000000000..b2308f5b781 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/README @@ -0,0 +1,69 @@ +// $Id$ + +Event Notification Service + + +File: examples/NotifyService/RTNotify/README + +This directory contains a simple example of using the Notification Service +with Real-Time CORBA. + +This example extends the basic Messenger notify service example to illustrate +how the Notification channel can be used with RT CORBA features. The supplier +and consumer both set up their proxies to use a thread pool with lanes and +the Notify_Service executable is configured to load the RT_Notification library +and associated features. A priority is set in the supplier and propagetd through +the channel into the consumer. + +The MessengerServer in this example plays the role of a server for +the MessengerClient and the role of a supplier for the MessengerConsumer. +The flow of messages is shown below: + +MessengerClient->MessengerSupplier->NotificationChannel->MessengerConsumer. + + +The Client code is stored in: + +examples/NotifyService/Messenger/MessengerClient.cpp + +The Server code is stored in: + +examples/NotifyService/Messenger/MessengerServer.cpp + +The Consumer code is stored in: + +examples/NotifyService/Messenger/MessengerConsumer.cpp + + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service -o ns.ior& + +To start the Notification Service: +--------------------------------- +$TAO_ROOT/orbsvcs/Notify_Service/Notify_Service -ORBInitRef NameService=file://ns.iori -ORBSvcConf notify.conf & + +To start the server/supplier +---------------------------- +./MessengerServer -ORBInitRef NameService=file://ns.ior -ORBSvcConf nsclient.conf + +To start the consumer +--------------------- +./MessengerConsumer -ORBInitRef NameService=file://ns.ior -ORBSvcConf nsclient.conf + +To start the client +------------------- +./MessengerClient -ORBInitRef NameService=file://ns.ior + + + +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/orbsvcs/DevGuideExamples/NotifyService/RTNotify/RTNotify.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/RTNotify.mpc new file mode 100644 index 00000000000..cc01e7483d9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/RTNotify.mpc @@ -0,0 +1,25 @@ +// $Id$ + +project(*Server): taoexe, portableserver, namingexe, notification_skel, rtcorba { + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): taoexe, namingexe, notification { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): taoexe, portableserver, namingexe, notification_skel, rtportableserver { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..74c54474e14 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.cpp @@ -0,0 +1,48 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event + ) +{ + + std::cout << "event received " << std::endl; + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name.in() << "\t" << value << std::endl; + } + +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer() +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..adb5bd999c8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventConsumer_i.h @@ -0,0 +1,29 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyCommS.h" + +class StructuredEventConsumer_i : + public virtual POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification + ); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); + + virtual void disconnect_structured_push_consumer(); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..0747d830bbf --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.cpp @@ -0,0 +1,30 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq & + ) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..6df2455fcb0 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/StructuredEventSupplier_i.h @@ -0,0 +1,24 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyCommS.h" + +class StructuredEventSupplier_i : + public virtual POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed + ); +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/notify.conf b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/notify.conf new file mode 100644 index 00000000000..837d36af6c7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/notify.conf @@ -0,0 +1,6 @@ +dynamic TAO_RT_ORB_Loader Service_Object *TAO_RTCORBA:_make_TAO_RT_ORB_Loader () "-ORBPriorityMapping continuous" + +# Uncomment this line to use SCHED_FIFO +#dynamic TAO_RT_ORB_Loader Service_Object *TAO_RTCORBA:_make_TAO_RT_ORB_Loader () "-ORBSchedPolicy SCHED_FIFO -ORBScopePolicy PROCESS -ORBPriorityMapping continuous" + +dynamic TAO_Notify_Service Service_Object * TAO_RT_Notification:_make_TAO_RT_Notify_Service () "" diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/nsclient.conf b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/nsclient.conf new file mode 100644 index 00000000000..c121382ee7d --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/nsclient.conf @@ -0,0 +1,4 @@ +dynamic TAO_RT_ORB_Loader Service_Object *TAO_RTCORBA:_make_TAO_RT_ORB_Loader () "-ORBPriorityMapping continuous" + +# Uncomment this line to use SCHED_FIFO +#dynamic TAO_RT_ORB_Loader Service_Object *TAO_RTCORBA:_make_TAO_RT_ORB_Loader () "-ORBSchedPolicy SCHED_FIFO -ORBScopePolicy PROCESS -ORBPriorityMapping continuous" diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/run_test.pl new file mode 100755 index 00000000000..9c17b7055f1 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/RTNotify/run_test.pl @@ -0,0 +1,82 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$notify_ior = PerlACE::LocalFile("notify.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start Notification Service + +$NotifyService = "$ENV{TAO_ROOT}/orbsvcs/Notify_Service/Notify_Service"; +$NFS = new PerlACE::Process($NotifyService, + "$arg_ns_ref -IORoutput $notify_ior " . + "-ORBSvcConf notify.conf"); +$NFS->Spawn(); +# the ior file is only used to wait for the service to start +if (PerlACE::waitforfile_timed ($notify_ior, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $notify_ior\n"; + $NS->Kill (); + $NFS->Kill (); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", + "$arg_ns_ref -ORBSvcConf nsclient.conf"); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 15) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + $NFS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", + "$arg_ns_ref -ORBSvcConf nsclient.conf"); +$MC->Spawn(); + +sleep(2); +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", ""); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NFS->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NFS->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; +unlink $notify_ior; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger.idl new file mode 100644 index 00000000000..a3bd8c12943 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger.idl @@ -0,0 +1,16 @@ +// $Id$ + +// messenger.idl + + +interface Messenger +{ + + boolean send_message(in string user_name, + + in string subject, + + inout string message); + +}; + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerClient.cpp new file mode 100644 index 00000000000..5d3cb836453 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerClient.cpp @@ -0,0 +1,58 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "MessengerC.h" +#include <iostream> +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var rootObj = + orb->resolve_initial_references("NameService"); + + CosNaming::NamingContext_var rootContext = + CosNaming::NamingContext::_narrow(rootObj.in()); + + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup ("MessengerService"); + + CORBA::Object_var messengerObj = rootContext->resolve(name); + + if (CORBA::is_nil(messengerObj.in())) { + std::cerr << "Nil Messenger reference" << std::endl; + return 1; + } + + // Narrow + Messenger_var messenger = Messenger::_narrow(messengerObj.in()); + if (CORBA::is_nil(messenger.in ())) { + std::cerr << "Argument is not a Messenger reference" << std::endl; + return 1; + } + + CORBA::String_var message = + CORBA::string_dup("Where can I get TAO?"); + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + + message = CORBA::string_dup("I need TAO now."); + messenger->send_message ("person@company.com", + "OCI's Distribution of TAO", + message.inout()); + + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + std::cout << "MessengerClient: success" << std::endl; + return 0; +} + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerConsumer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerConsumer.cpp new file mode 100644 index 00000000000..6d286da5e63 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerConsumer.cpp @@ -0,0 +1,141 @@ +// $Id$ + +#include "ace/Get_Opt.h" + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "StructuredEventConsumer_i.h" +#include <iostream> + +#define CA_FILTER "Subject == 'OCI_TAO'" +#define TCL_GRAMMAR "TCL" + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var naming_obj = + orb->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + return 1; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + CosNaming::Name name(1); + name.length (1); + name[0].id = CORBA::string_dup("MyEventChannel"); + CORBA::Object_var ecObj = naming_context->resolve(name); + + CosNotifyChannelAdmin::EventChannel_var ec = + CosNotifyChannelAdmin::EventChannel::_narrow(ecObj.in()); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to find event channel" << std::endl; + return 1; + } + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::AND_OP; + + CosNotifyChannelAdmin::ConsumerAdmin_var consumer_admin = + ec->new_for_consumers(ifgop, + adminid); + + if (CORBA::is_nil (consumer_admin.in())) { + std::cerr << "Unable to find consumer admin" << std::endl; + return 1; + } + + CosNotifyFilter::FilterFactory_var ffact = + ec->default_filter_factory (); + + // setup a filter at the consumer admin + CosNotifyFilter::Filter_var ca_filter = + ffact->create_filter (TCL_GRAMMAR); + + if (CORBA::is_nil (ca_filter.in())) { + std::cerr << "Unable to create filetr object" << std::endl; + return 1; + } + + CosNotifyFilter::ConstraintExpSeq constraint_list (1); + constraint_list.length (1); + constraint_list[0].event_types.length (0); + constraint_list[0].constraint_expr = CORBA::string_dup (CA_FILTER); + + ca_filter->add_constraints (constraint_list); + + consumer_admin ->add_filter (ca_filter.in()); + + CosNotification::EventTypeSeq added(1); + CosNotification::EventTypeSeq removed (0); + added.length (1); + removed.length (0); + + added[0].domain_name = CORBA::string_dup ("*"); + added[0].type_name = CORBA::string_dup ("*"); + + consumer_admin->subscription_change (added, removed); + + CORBA::Object_var poa_object = + orb->resolve_initial_references("RootPOA"); + + if (CORBA::is_nil (poa_object.in())) { + std::cerr << "Unable to initialize the POA." << std::endl; + return 1; + } + + PortableServer::POA_var poa = + PortableServer::POA::_narrow(poa_object.in()); + + StructuredEventConsumer_i servant(orb.in()); + + PortableServer::ObjectId_var oid = poa->activate_object(&servant); + CORBA::Object_var consumer_obj = poa->id_to_reference(oid.in()); + CosNotifyComm::StructuredPushConsumer_var consumer = + CosNotifyComm::StructuredPushConsumer::_narrow(consumer_obj.in()); + + + CosNotifyChannelAdmin::ProxyID consumeradmin_proxy_id; + + CosNotifyChannelAdmin::ProxySupplier_var proxy_supplier = + consumer_admin->obtain_notification_push_supplier( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + consumeradmin_proxy_id); + + + // The proxy that we are connected to. + CosNotifyChannelAdmin::StructuredProxyPushSupplier_var supplier_proxy; + supplier_proxy = CosNotifyChannelAdmin::StructuredProxyPushSupplier:: + _narrow(proxy_supplier.in()); + + if (CORBA::is_nil (supplier_proxy.in())) { + std::cerr << "Unable to create structured push supplier proxy" << std::endl; + return 1; + } + + supplier_proxy->connect_structured_push_consumer(consumer.in()); + + PortableServer::POAManager_var poa_manager = poa->the_POAManager(); + + poa_manager->activate(); + + orb->run(); + orb->destroy (); + + } + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + return 1; + } + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerServer.cpp new file mode 100644 index 00000000000..1e214673971 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerServer.cpp @@ -0,0 +1,61 @@ +// $Id$ + +#include "orbsvcs/CosNamingC.h" +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv []) +{ + try + { + // Initialize orb + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + // Find the Naming Service. + CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var rootNC = + CosNaming::NamingContext::_narrow(rootObj.in()); + + // Get the 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 our Messenger servant. + Messenger_i messenger_servant(orb.in()); + + // Register it with the RootPOA. + PortableServer::ObjectId_var oid = + poa->activate_object( &messenger_servant ); + CORBA::Object_var messenger_obj = poa->id_to_reference( oid.in() ); + + // Bind it in the Naming Service. + CosNaming::Name name; + name.length (1); + name[0].id = CORBA::string_dup("MessengerService"); + rootNC->rebind(name, messenger_obj.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 << ex << std::endl; + return 1; + } + return 0; + +} + + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerSupplier.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerSupplier.cpp new file mode 100644 index 00000000000..e1468ab0c93 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/MessengerSupplier.cpp @@ -0,0 +1,97 @@ +// $Id$ + +#include "orbsvcs/Notify/Notify_EventChannelFactory_i.h" +#include "orbsvcs/CosNamingC.h" +#include "ace/Profile_Timer.h" +#include "StructuredEventSupplier_i.h" +#include <iostream> + +int ACE_TMAIN(int argc, ACE_TCHAR * argv[]) +{ + try + { + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + CORBA::Object_var rootObj = orb->resolve_initial_references("NameService"); + CosNaming::NamingContext_var rootNC = + CosNaming::NamingContext::_narrow(rootObj.in()); + + // 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 Event Channel factory. + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + TAO_Notify_EventChannelFactory_i::create(poa.in()); + ACE_ASSERT (!CORBA::is_nil (notify_factory.in ())); + + // Create an Event Channel. + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, initial_admin, id); + + // Bind it in the Naming Service. + CosNaming::Name name(1); + name.length(1); + name[0].id = CORBA::string_dup("MyEventChannel"); + rootNC->rebind(name, ec.in()); + + // Become a structured push supplier. + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::OR_OP; + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb.in()); + CosNotifyComm::StructuredPushSupplier_var supplier = servant->_this(); + + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy = + CosNotifyChannelAdmin::StructuredProxyPushConsumer::_narrow( + proxy_consumer.in()); + consumer_proxy->connect_structured_push_supplier(supplier.in()); + + // Set up events to push. + CosNotification::StructuredEvent event; + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + event.header.fixed_header.event_name = CORBA::string_dup("myevent"); + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("Message from:"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject:"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message:"); + event.filterable_data[2].value <<= (const char *)message; + + // Push events. + while (1) { + std::cout << "pushing " << std::endl; + consumer_proxy->push_structured_event (event); + ACE_OS::sleep (1); + } + } + catch(const CORBA::Exception& ex) { + return 1; + } + + return 0; +} + diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.cpp new file mode 100644 index 00000000000..5b5f93e2167 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.cpp @@ -0,0 +1,172 @@ +// $Id$ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/Notify/Notify_EventChannelFactory_i.h" + +// The static initialization trick doesn't work with static builds. +// On SunOS 5.8 and MacOS X, the static initialization trick used +// in the CosNotification_Serv library does not work. Including the +// initializer class here works around the problem. +#if defined (TAO_AS_STATIC_LIBS) || defined (sun) || defined (__APPLE__) +#include "orbsvcs/Notify/CosNotify_Initializer.h" +#endif /* sun || __APPLE__ */ + +#include "Messenger_i.h" +#include "StructuredEventSupplier_i.h" +#include <iostream> + +Messenger_i::Messenger_i (CORBA::ORB_ptr orb) +: orb_ (CORBA::ORB::_duplicate(orb)) + +{ + try + { + CORBA::Object_var poa_obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_obj.in()); + + CORBA::Object_var naming_obj = + orb_->resolve_initial_references ("NameService"); + + if (CORBA::is_nil(naming_obj.in())) { + std::cerr << "Unable to find naming service" << std::endl; + } + + CosNaming::NamingContext_var naming_context = + CosNaming::NamingContext::_narrow(naming_obj.in()); + + + // + // Create an instance of TAO's notification event channel + // + + CosNotifyChannelAdmin::EventChannelFactory_var notify_factory = + TAO_Notify_EventChannelFactory_i::create(poa.in()); + + if (CORBA::is_nil (notify_factory.in ())) { + std::cerr << "Unable to create the notify event channel" << std::endl; + return; + } + + CosNotifyChannelAdmin::ChannelID id; + CosNotification::QoSProperties initial_qos; + CosNotification::AdminProperties initial_admin; + + CosNotifyChannelAdmin::EventChannel_var ec = + notify_factory->create_channel (initial_qos, + initial_admin, + id); + + if (CORBA::is_nil (ec.in())) { + std::cerr << "Unable to create event channel" << std::endl; + return; + } + + + CosNaming::Name name(1); + name.length(1); + name[0].id = CORBA::string_dup("MyEventChannel"); + + naming_context->rebind(name, ec.in()); + + CosNotifyChannelAdmin::AdminID adminid; + CosNotifyChannelAdmin::InterFilterGroupOperator ifgop = + CosNotifyChannelAdmin::AND_OP; + + CosNotifyChannelAdmin::SupplierAdmin_var supplier_admin = + ec->new_for_suppliers (ifgop, adminid); + + if (CORBA::is_nil (supplier_admin.in())) { + std::cerr << "Unable to find supplier admin" << std::endl; + } + + CosNotifyChannelAdmin::ProxyID supplieradmin_proxy_id; + + CosNotifyChannelAdmin::ProxyConsumer_var proxy_consumer = + supplier_admin->obtain_notification_push_consumer( + CosNotifyChannelAdmin::STRUCTURED_EVENT, + supplieradmin_proxy_id); + + StructuredEventSupplier_i *servant = + new StructuredEventSupplier_i(orb_.in()); + + PortableServer::ObjectId_var oid = poa->activate_object(servant); + CORBA::Object_var supplier_obj = poa->id_to_reference(oid.in()); + CosNotifyComm::StructuredPushSupplier_var supplier = + CosNotifyComm::StructuredPushSupplier::_narrow(supplier_obj.in()); + + consumer_proxy_ = + CosNotifyChannelAdmin::StructuredProxyPushConsumer:: + _narrow(proxy_consumer.in()); + + if (CORBA::is_nil (consumer_proxy_.in())) { + std::cerr << "Unable to find structured proxy push consumer" << std::endl; + } + + consumer_proxy_->connect_structured_push_supplier(supplier.in()); + + } + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + } + +} + + +// Implementation skeleton destructor +Messenger_i::~Messenger_i (void) +{ +} + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message + ) +{ + + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + + try + { + + // Event Definition + CosNotification::StructuredEvent event; + + event.header.fixed_header.event_type.domain_name = + CORBA::string_dup("OCI_TAO"); + // string + event.header.fixed_header.event_type.type_name = + CORBA::string_dup("examples"); + // string + event.header.fixed_header.event_name = + CORBA::string_dup("myevent"); + + // sequence<Property>: string name, any value + event.filterable_data.length (1); + event.filterable_data[0].name = CORBA::string_dup("From"); + event.filterable_data[0].value <<= (const char *)user_name; + event.filterable_data.length (2); + event.filterable_data[1].name = CORBA::string_dup("Subject"); + event.filterable_data[1].value <<= (const char *)subject; + event.filterable_data.length (3); + event.filterable_data[2].name = CORBA::string_dup("Message"); + event.filterable_data[2].value <<= (const char *)message; + + consumer_proxy_->push_structured_event(event); + } + + catch(const CosNotifyComm::InvalidEventType&) { + std::cerr << "Invalid Event Type Exception " << std::endl; + return 1; + } + + catch(const CORBA::Exception& ex) { + std::cerr << ex << std::endl; + return 1; + } + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.h new file mode 100644 index 00000000000..15471aaedde --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/Messenger_i.h @@ -0,0 +1,33 @@ +// $Id$ + +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include "orbsvcs/CosNotifyChannelAdminC.h" +#include "orbsvcs/CosNotifyCommC.h" +#include "orbsvcs/CosNamingC.h" + +#include "MessengerS.h" + +//Class Messenger_i +class Messenger_i : public virtual POA_Messenger +{ +public: + //Constructor + Messenger_i (CORBA::ORB_ptr orb); + + //Destructor + virtual ~Messenger_i (void); + + CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ); + +private: + CORBA::ORB_var orb_; + CosNotifyChannelAdmin::StructuredProxyPushConsumer_var consumer_proxy_; +}; + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/README b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/README new file mode 100644 index 00000000000..74ca8f88ca8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/README @@ -0,0 +1,44 @@ +// $Id$ + +examples/NotifyService/SupplierSideNC/README + +This directory contains a simple example of using the Notification Service. + +This example extends the Messenger example in Filtering directory +to illustrate how the Notification channel can be used to push messages +from the supplier to the consumer. Furthermore, this example shows +how you could set up filters so that only a certain events are +passed to the consumer. + +This example uses the push/push model. + +In this example, the Notify Service initiation is incorporated into the +MessengerServer. + +The MessengerSupplier in this example plays the role of a server for +the MessengerClient and the role of a supplier for the MessengerConsumer. +The flow of messages is shown below: + +MessengerClient->(MessengerSupplier->NotificationChannel)->MessengerConsumer. + +How to Run +---------- + +To start the Naming Service: +---------------------------- +$TAO_ROOT/orbsvcs/Naming_Service/Naming_Service & + +To start the supplier: +------------------ +./MessengerServer + +To start the consumer +--------------------- +./MessengerConsumer + +To start the client +------------------- +./MessengerClient +To start the client: +------------------ +./MessengerClient diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.cpp new file mode 100644 index 00000000000..7f4d6bc3524 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.cpp @@ -0,0 +1,46 @@ +// $Id$ + +#include "StructuredEventConsumer_i.h" +#include "tao/PortableServer/PS_CurrentC.h" +#include <iostream> + +StructuredEventConsumer_i::StructuredEventConsumer_i(CORBA::ORB_ptr orb) + : orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventConsumer_i::push_structured_event( + const CosNotification::StructuredEvent &event) +{ + + const char *value; + + for (unsigned int i=0; i<event.filterable_data.length(); i++) { + event.filterable_data[i].value >>= value; + std::cout << event.filterable_data[i].name << "\t" <<value<< std::endl; + } + + std::cerr << "MessengerConsumer: success" << std::endl; +} + +void +StructuredEventConsumer_i::disconnect_structured_push_consumer() +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventConsumer_i::offer_change( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq &) +{ + //Noop +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.h new file mode 100644 index 00000000000..6dd45e0b20c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventConsumer_i.h @@ -0,0 +1,26 @@ +// $Id$ + +#ifndef _EVENTCONSUMER_I_H_ +#define _EVENTCONSUMER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventConsumer_i : public POA_CosNotifyComm::StructuredPushConsumer +{ +public: + StructuredEventConsumer_i(CORBA::ORB_ptr orb); + + virtual void push_structured_event( + const CosNotification::StructuredEvent ¬ification); + + virtual void offer_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed); + + virtual void disconnect_structured_push_consumer(); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.cpp b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.cpp new file mode 100644 index 00000000000..0bd7c8a5ccb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.cpp @@ -0,0 +1,29 @@ +// $Id$ + +#include "StructuredEventSupplier_i.h" +#include "tao/PortableServer/PS_CurrentC.h" + +StructuredEventSupplier_i::StructuredEventSupplier_i(CORBA::ORB_ptr orb) +: orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +void +StructuredEventSupplier_i::disconnect_structured_push_supplier () +{ + + CORBA::Object_var obj = orb_->resolve_initial_references ("POACurrent"); + PortableServer::Current_var current = + PortableServer::Current::_narrow (obj.in()); + PortableServer::POA_var poa = current->get_POA (); + PortableServer::ObjectId_var objectId = current->get_object_id (); + poa->deactivate_object (objectId.in()); + +} + +void +StructuredEventSupplier_i::subscription_change ( + const CosNotification::EventTypeSeq &, + const CosNotification::EventTypeSeq &) +{ +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.h b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.h new file mode 100644 index 00000000000..37d97731643 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/StructuredEventSupplier_i.h @@ -0,0 +1,23 @@ +// $Id$ + +#ifndef _EVENTSUPPLIER_I_H_ +#define _EVENTSUPPLIER_I_H_ + +#include "orbsvcs/CosNotifyChannelAdminS.h" + +class StructuredEventSupplier_i : public POA_CosNotifyComm::StructuredPushSupplier +{ +public: + // Constructor + StructuredEventSupplier_i(CORBA::ORB_ptr orb); + virtual void disconnect_structured_push_supplier (); + + virtual void subscription_change ( + const CosNotification::EventTypeSeq & added, + const CosNotification::EventTypeSeq & removed); + +private: + CORBA::ORB_var orb_; +}; + +#endif diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/SupplierSideNC.mpc b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/SupplierSideNC.mpc new file mode 100644 index 00000000000..5458a3127b2 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/SupplierSideNC.mpc @@ -0,0 +1,25 @@ +// $Id$ + +project(*Server): taoexe, portableserver, namingexe, notification_serv { + Source_Files { + StructuredEventSupplier_i.cpp + MessengerServer.cpp + Messenger_i.cpp + } +} + +project(*Client): taoexe, namingexe, notification { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} + +project(*Consumer): taoexe, portableserver, namingexe, notification_skel { + IDL_Files { + } + Source_Files { + MessengerConsumer.cpp + StructuredEventConsumer_i.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/run_test.pl b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/run_test.pl new file mode 100755 index 00000000000..f0656a34a6c --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/NotifyService/SupplierSideNC/run_test.pl @@ -0,0 +1,58 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$nsiorfile = PerlACE::LocalFile("ns.ior"); +$messiorfile = PerlACE::LocalFile("Messenger.ior"); +$arg_ns_ref = "-ORBInitRef NameService=file://$nsiorfile"; +unlink $nsiorfile; +unlink $messiorfile; + +# start Naming Service +$NameService = "$ENV{TAO_ROOT}/orbsvcs/Naming_Service/Naming_Service"; +$NS = new PerlACE::Process($NameService, "-o $nsiorfile"); +$NS->Spawn(); +if (PerlACE::waitforfile_timed ($nsiorfile, 10) == -1) { + print STDERR "ERROR: cannot find file $nsiorfile\n"; + $NS->Kill(); + exit 1; +} + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", $arg_ns_ref); +$S->Spawn(); + +# Wait for the MessengerServer +if (PerlACE::waitforfile_timed ($messiorfile, 10) == -1) { + print STDERR "ERROR: Timed out waiting for $messiorfile\n"; + $S->Kill(); + $NS->Kill (); + exit 1; +} +# start MessengerConsumer +$MC = new PerlACE::Process("MessengerConsumer", $arg_ns_ref); +$MC->Spawn(); + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", $arg_ns_ref); +if ($C->SpawnWaitKill(10) != 0) { + $MC->Kill(); + $S->Kill(); + $NS->Kill(); + exit (1); +} + +$MC->Kill(); +$S->Kill(); +$NS->Kill(); + +unlink $nsiorfile; +unlink $messiorfile; + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger.idl new file mode 100644 index 00000000000..e492f3c79ab --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger.idl @@ -0,0 +1,12 @@ +/* -*- C++ -*- $Id$ */ + +// messenger.idl + +interface Messenger +{ + boolean send_message ( in string user_name, + in string subject, + inout string message ); + + void shutdown ( in string user_name ); +}; diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerClient.cpp new file mode 100644 index 00000000000..7e6551a08a8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerClient.cpp @@ -0,0 +1,115 @@ +/* -*- C++ -*- $Id$ */ + +#include "orbsvcs/SecurityC.h" +#include "MessengerC.h" + +#if 0 +The servers service configuration file +for this example is: +--------------------------------------- +# server.conf +dynamic SSLIOP_Factory Service_Object * + TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() + "-SSLNoProtection \ + -SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +--------------------------------------- + +The clients service configuration file +for this example is: +--------------------------------------- +# client.conf +dynamic SSLIOP_Factory Service_Object * + TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() + "-SSLNoProtection \ + -SSLAuthenticate SERVER \ + -SSLPrivateKey PEM:clientkey.pem \ + -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +--------------------------------------- +#endif + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + + CORBA::ORB_var orb = + CORBA::ORB_init( argc, argv ); + + CORBA::Object_var obj = + orb->string_to_object( "file://Messenger.ior" ); + + Messenger_var messenger = + Messenger::_narrow( obj.in() ); + + CORBA::String_var message = + CORBA::string_dup( "Terminating messenger service!" ); + + messenger->send_message( "Chief of Security", + "New Directive", + message.inout() ); + + messenger->shutdown("Chief of Security"); + + Security::QOP qop = + Security::SecQOPIntegrityAndConfidentiality; + + CORBA::Any want_protection; + want_protection <<= qop; + + CORBA::Policy_var policy = + orb->create_policy (Security::SecQOPPolicy, + want_protection); + + Security::EstablishTrust establish_trust; + establish_trust.trust_in_client = 0; + establish_trust.trust_in_target = 1; + + CORBA::Any want_trust; + want_trust <<= establish_trust; + + CORBA::Policy_var policy2 = + orb->create_policy (Security::SecEstablishTrustPolicy, + want_trust); + + + CORBA::PolicyList policy_list (2); + policy_list.length (1); + policy_list[0] = + CORBA::Policy::_duplicate (policy.in ()); + policy_list.length (2); + policy_list[1] = + CORBA::Policy::_duplicate (policy2.in ()); + + + CORBA::Object_var object = + obj->_set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE); + + Messenger_var messenger2 = + Messenger::_narrow( object.in() ); + + message = + CORBA::string_dup( "Terminating messenger service!" ); + + messenger2->send_message( "Chief of Security", + "New Directive", + message.inout() ); + + messenger2->shutdown("Chief of Security"); + + orb->destroy(); + } + catch(const CORBA::Exception& ex) + { + ex._tao_print_exception("Client: main block"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerServer.cpp new file mode 100644 index 00000000000..5f4b7573a9e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/MessengerServer.cpp @@ -0,0 +1,64 @@ +/* -*- C++ -*- $Id$ */ + +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + + CORBA::ORB_var orb = CORBA::ORB_init( argc, argv ); + + + CORBA::Object_var obj = + orb->resolve_initial_references( "RootPOA" ); + + PortableServer::POA_var poa = + PortableServer::POA::_narrow( obj.in() ); + + PortableServer::POAManager_var mgr = + poa->the_POAManager(); + mgr->activate(); + + obj = + orb->resolve_initial_references ("SSLIOPCurrent"); + + SSLIOP::Current_var ssliop_current = + SSLIOP::Current::_narrow (obj.in ()); + + Messenger_i messenger_servant(orb.in(), + ssliop_current.in() + ); + + 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; + + orb->run(); + poa->destroy (1, 1); + orb->destroy (); + + std::cout << "Messenger Server is shut down!" + << std::endl; + std::cout << std::endl; + + } + catch(const CORBA::Exception& ex) { + ex._tao_print_exception("Server Error: main block"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.cpp new file mode 100644 index 00000000000..6b414ea4a80 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.cpp @@ -0,0 +1,151 @@ +/* -*- C++ -*- $Id$ */ + +#include "Messenger_i.h" +#include "ace/OS_NS_string.h" +#include <iostream> + +Messenger_i::Messenger_i ( + CORBA::ORB_ptr orb, + SSLIOP::Current_ptr ssliop_current +) +: orb_(CORBA::ORB::_duplicate(orb)), + ssliop_current_(SSLIOP::Current::_duplicate(ssliop_current)) + { + } + +Messenger_i::~Messenger_i (void) + { + } + +CORBA::Boolean Messenger_i::send_message ( + const char * user_name, + const char * subject, + char *& message + ) + { + if (ssliop_current_->no_context()) + std::cout << "Message from: " << user_name << std::endl; + else + std::cout << "SECURE message from: " << user_name << std::endl; + + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + std::cout << std::endl; + return 1; + } + + +void Messenger_i::shutdown ( + const char * user_name + ) +{ + if ( ! (ssliop_current_->no_context()) ) + { + // requestor is authentic, go ahead and + // shut the server down. Report access + // ID of requestor prior to shutdown. + + std::cout << "Shutdown command from: " << user_name << std::endl; + std::cout << "Status: User authenticated." << std::endl; + std::cout << "Action: Sever shutdown in progress..." << std::endl; + std::cout << std::endl; + +#if 0 + char name_buf[BUFSIZ]; + + // + // Populate an attribute type list + // to request the initiating principal's + // AccessId. + // + Security::AttributeTypeList requested_attributes; + requested_attributes.length(0); + Security::AttributeType desired_attribute; + desired_attribute.attribute_family.family_definer = 0; // OMG + desired_attribute.attribute_family.family = 1; // Privilege + // Attributes + desired_attribute.attribute_type = Security::AccessId; + requested_attributes.length(1); + requested_attributes[0] = desired_attribute; + // + // Request the attribtue + // + Security::AttributeList_var attrib_list = + this->current_->get_attributes(requested_attributes); + + if(attrib_list->length() > 0) + { + // + // Copy the values out + // + Security::SecAttribute attribute_returned; + + attribute_returned.defining_authority = + (attrib_list.in())[0].defining_authority ; + attribute_returned.value = + (attrib_list.in())[0].value; + + // Certificates are returned in + // X.509 format + // + const char x509[] = "x509"; + // + // Setup a Security::OID (sequence<octet>) + // to hold the attribute's defining authority. + // + Security::OID x509_defining_authority; + x509_defining_authority.length(sizeof (x509)); + // + // Populate the defining authority value. + // + CORBA::Octet *buf = + x509_defining_authority.get_buffer(); + ACE_OS_String::memcpy( buf, x509, sizeof(x509)); + // + // Confirm the defining authority is "x509". + // + if(attribute_returned.defining_authority == + x509_defining_authority) + { + // + // Get the buffer holding the certificate + // + CORBA::Octet *der_cert = + attribute_returned.value.get_buffer(); + // + // Convert the DER encoded certificate into + // OpenSSL's internal format. + // + X509 *peer = ::d2i_X509 (0, + &der_cert, + attribute_returned.value.length()); + + ::X509_NAME_oneline(::X509_get_subject_name (peer), + name_buf, + BUFSIZ); + + ::X509_free(peer); + } + } + // + // Report the certificate's subject name + // and terminate the server + // + std::cout << "Shutdown commanded by: " + << name_buf + << std::endl; + std::cout << std::endl; +#endif + + orb_->shutdown (0); + } + else + { + // requestor is not secure, + // ignore shutdown command + std::cout << "Shutdown command from: " << user_name << std::endl; + std::cout << "Status: User *NOT* authenticated." << std::endl; + std::cout << "Action: Ignored." << std::endl; + std::cout << std::endl; + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.h new file mode 100644 index 00000000000..9dfb7ce0ff3 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/Messenger_i.h @@ -0,0 +1,38 @@ +/* -*- C++ -*- $Id$ */ + +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include <openssl/ssl.h> +#include <openssl/x509.h> +#include "orbsvcs/SecurityC.h" +#include "orbsvcs/SSLIOPC.h" + +#include "MessengerS.h" + +class Messenger_i : public virtual POA_Messenger +{ +public: + Messenger_i ( + CORBA::ORB_ptr orb, + SSLIOP::Current_ptr ssliop_current + ); + + virtual ~Messenger_i (void); + + virtual CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ); + + virtual void shutdown ( + const char * user_name + ); + +protected: + CORBA::ORB_var orb_; + SSLIOP::Current_var ssliop_current_; +}; + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/ParticipatingApp.mpc b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/ParticipatingApp.mpc new file mode 100644 index 00000000000..a0025ee06d6 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/ParticipatingApp.mpc @@ -0,0 +1,17 @@ +// $Id$ + +project(*Server): portableserver, orbsvcsexe, security, ssliop { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(ParticipatingApp_Client): orbsvcsexe, security, ssliop { + exename = MessengerClient + + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/README b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/README new file mode 100644 index 00000000000..5d001721f0b --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/README @@ -0,0 +1,47 @@ +TAO Security + +DevGuideExamples/Security/ParticipatingApp/README + +This directory contains an illustration of a security +aware application that accepts secured and unsecured +requests and provides access to certain operations +only for secured requests. + +This example uses a single set of service configuration +files and takes a single path through the application +code. + +For simplicity, the pass phrases have been stripped from the +private keys included with these examples in the 1.2a release. +This *should not* be construed as a recommended practice. Instead, +OCI strongly recommends that the security requirements of each +real-world application be evaluated carefully and that appropriate +procedures and practice be established accordingly. Private keys +without pass phrase protection are easily compromised and may +allow an unauthorized party to masquerade as an authorized system +user. + +Prior to running the server in these examples, the SSL_CERT_FILE +environment variable must be set, e.g., + # /bin/bash + export SSL_CERT_FILE=cacert.pem +or + rem Windows + set SSL_CERT_FILE=cacert.pem + +To run the server: + ./MessengerServer -ORBSvcConf server.conf + +To run the client: + ./MessengerClient -ORBSvcConf client.conf + + +----------------------------------------- +Files: DevGuideExamples/Security/ParticipatingApp + +Messenger.idl - Messenger interface definition. +Messenger_i.h - Messenger servant class definition. +Messenger_i.cpp - Messenger servant implementation. +MessengerServer.cpp - MessengerServer process main. +MessengerClient.cpp - MessengerClient process main. + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/cacert.pem b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/cacert.pem new file mode 100644 index 00000000000..c493d28a523 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/cacert.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDujCCAyOgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBoDELMAkGA1UEBhMCVVMx +ETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNVBAoT +Fk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMU +Q2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5j +b20wHhcNMDMwNzIzMjAyNDIwWhcNMTMwNzIwMjAyNDIwWjCBoDELMAkGA1UEBhMC +VVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNV +BAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UE +AxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdl +Yi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO4QS4bqrXVuBnHsOg1/ +gijXjiWhFTngG/sDLWAA52fHIobyFo5//7UaLedke0fkwqsmky8hjzSbXGJsGI5g +Yjp2Va7WeJhRQNr8VYWobCq00f//drHN2NF5M23Cx0JF9WfyfWpqq5TQRGtVZ+We ++q4S6wH1exZrVGHfkp5Xq5FvAgMBAAGjggEAMIH9MB0GA1UdDgQWBBQvTY0YWmHq +o2TMOKba/ECH9ayXZzCBzQYDVR0jBIHFMIHCgBQvTY0YWmHqo2TMOKba/ECH9ayX +Z6GBpqSBozCBoDELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYD +VQQHEwlTdC4gTG91aXMxHzAdBgNVBAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4x +DDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAa +BgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkq +hkiG9w0BAQQFAAOBgQBgjn97nbyyjFxyHC8vheAiDCQRblI4lZbZC6vSmxxqEGze +eAMiTYL2iK3vj2Ot3V2/o5VdLyEYV4RBP2iq1XuMYXjmL2ni+NVgepyXceynH8/b +72yciZZcDE5FVUaMUHAgZUpxsGSDyD70LnOFwBxuvxtlMtG5vXYNvwF/FJPs1g== +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/client.conf b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/client.conf new file mode 100644 index 00000000000..cffba696b54 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/client.conf @@ -0,0 +1,6 @@ +# $Id$ + +# client.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLNoProtection -SSLAuthenticate SERVER -SSLPrivateKey PEM:clientkey.pem -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientcert.pem b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientcert.pem new file mode 100644 index 00000000000..56616fcd469 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientcert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQQwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjIwN1oXDTEzMDgwNTAwMjIwN1owgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBmNs +aWVudDEgMB4GCSqGSIb3DQEJARYRY2xpZW50QG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAMYaaQgEmp2zv0t+MAEGf5GIsKSIB1YFrkkVR6Qv +LP0t9FHDPGFawh/aK3Yq+l7RiNpK1H5SSOaIavm4xV/3tpHxzuRjd0H3fdhaoAgD +xvcYZ75l662PEa25MCJsp40tACO0hGNOQCJ8kWVmT4xEhKcFl3xm+1OvNbwDM/pA +t4WpAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEArs6S6qud6D9t6AcGJS91XWqbBY1G +rSgmv9yFbvUyrGAQuMpyNuYTGlZA+Nd3EAjYlwP4fWbzUMM0MEtd3Xl0Aep0O39W +Cgp9HxDaJi3b4h63cd/B0su+2CNd4P6+NOX+IxgrrioCgKSnu6Nxy14fb03RQhjl +a3vOY5Juf8ySB/M= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientkey.pem new file mode 100644 index 00000000000..2b4af2322ad --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/clientkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQDGGmkIBJqds79LfjABBn+RiLCkiAdWBa5JFUekLyz9LfRRwzxh +WsIf2it2Kvpe0YjaStR+UkjmiGr5uMVf97aR8c7kY3dB933YWqAIA8b3GGe+Zeut +jxGtuTAibKeNLQAjtIRjTkAifJFlZk+MRISnBZd8ZvtTrzW8AzP6QLeFqQIDAQAB +AoGAJx1X16lxDepLvxAvUkSCM64Vkqb5K9b7TprRBm36KBNGxk4SQfa1laxyIGbk +AIzGxLM5uadtlXciCCSfdA9pEJbjtxSRJt2RbOWioT3sfIzXO7SCMHuuRjnPK3P8 +rgFmOOpo/ldVZ3mBJajxzWTEFXMUTAC4tB2j2B6of7MG5fECQQDu+uKzI2QjiTpW +5WFd/vzpS2SpDHks4sEu0F6zk1Zhbsc3KoJd3xxSLhKFLLoRDVZsDKE3opr7WRNT ++sjoGRY3AkEA1DZArJqLeWuB8L8GjC/AtMXsxlSe3Iy9X+4uffZ/y5A1JbYidLJl +3FlejMoQqp0EpbHO+mRCMSHyJqAFW1ZTHwJBANjv3oMHiYvIsrDXIQAWzLdqvUHI +FOfuH7fDZ3RUN4HS8fzeFeHo+uiO8jj6VR3NoboL7P14GoA4aBc//MjUnRkCQQCH +KZ770NtxFKaIvkLfWzL0cPQkRpWAiCu+RChclnpDH7CaOm2rwkzakhmEttbytFvX +ZW8dUGpQfPyM2XNP/6WlAkEAoOQ5UI1WREbjoJs5mTwTG1gTrQjShQwjC0dqt66s +bOS5os5EePGdctm//Xq7uR4/6hB6T7npPYqiyfWix1SINQ== +-----END RSA PRIVATE KEY----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/run_test.pl b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/run_test.pl new file mode 100755 index 00000000000..95c461a7f20 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/run_test.pl @@ -0,0 +1,40 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$ENV{'SSL_CERT_FILE'} = 'cacert.pem'; + +$file = PerlACE::LocalFile("Messenger.ior"); + +unlink $file; + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", + "-ORBSvcConf server.conf"); +$S->Spawn(); +if (PerlACE::waitforfile_timed ($file, 15) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $S->Kill (); + exit 1; +} + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient", + "-ORBSvcConf client.conf"); + +if ($C->SpawnWaitKill(10) != 0) { + exit (1); +} + +if ($S->WaitKill(10) == -1) { + $S->Kill(); +} + +exit 0; + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/server.conf b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/server.conf new file mode 100644 index 00000000000..380312b03fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/server.conf @@ -0,0 +1,5 @@ +# $Id$ + +# server.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLNoProtection -SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey PEM:serverkey.pem -SSLCertificate PEM:servercert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/servercert.pem b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/servercert.pem new file mode 100644 index 00000000000..9659fb07334 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/servercert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQMwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjAyOVoXDTEzMDgwNTAwMjAyOVowgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBlNl +cnZlcjEgMB4GCSqGSIb3DQEJARYRc2VydmVyQG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAKw+tjwQz/stcesfm6WvnB6D/FTYu79tHzGUDlSV +N+kycFYcZfsRmIEo5afG+epOwlp1f9Wpij23AMY4BcdcSP9R4yhH46uMFThQhkn9 +fraZ8slcgVog5G6MwXmsWb5gThjgiT0KPSQHkEU0bryw+CiM4oV+9dSaFBLa3Uqc +iQZdAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAur+t7sIqGjqAPgFtFcgByAJTvNYb +UDZ43AGd22tCtT/usoy/x9qsQv8jwd8kA8yUNQUmjRxR4vEkZ06L6HF8Ii1QmU/E +fZ7YcjXjWxgnCEQGSXuHLhmlIMAlXNvX1XzNddu/NuRbSP3lYS/j32W8gTb6MdyL +8bOkIqRpVY0ek80= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/serverkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/serverkey.pem new file mode 100644 index 00000000000..c61b8152649 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/ParticipatingApp/serverkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCsPrY8EM/7LXHrH5ulr5weg/xU2Lu/bR8xlA5UlTfpMnBWHGX7 +EZiBKOWnxvnqTsJadX/VqYo9twDGOAXHXEj/UeMoR+OrjBU4UIZJ/X62mfLJXIFa +IORujMF5rFm+YE4Y4Ik9Cj0kB5BFNG68sPgojOKFfvXUmhQS2t1KnIkGXQIDAQAB +AoGBAKjg08wQr9qVtBvT4ceRZoCE5+JIncwSMYNqpqJHq4n46iuDrHl9xwjcEE9v +x5jzn5sRmUTj9aaMxzWRuBi/YtFVmgsl8lNiBOniIkFYqIyXfzNgX+2qyRzgOtAo +0ByWFsqkLmW9cUXWaICkM49b9Jz7SnmPs+9VWGiNrjgJSiABAkEA4eFIc82mP2KJ +wap8LJV7GLBA3iiVRmOgVb0TvRMitFWPGdGKFcsAVVkogQ/zIixKeZKc5enMhAI9 +i3Q2tmolZQJBAMM2hlSbJZncMjooKBlp2VZgUpEjbBPpD9XGgA5BO2RfKi3B29T9 +2v8I3m9WbCxbtFKlHcjNT3GToGCoi4S1qZkCQDcn7qwwZE8H/cFnoui0G5ncuApH +eKP2gdlN0TsTKB9G4SmZzBEkP9GXcteJEIKgtBLZpSxTGdiGP4cE+rMyWi0CQDam +TgbjhCxFq74CPe+XZWO8BYFiREByr58uOe1Dr8fSqHE040EGbEeXiQXsUM4+QgYc ++XCcoY/vPyewJ5bYcIkCQERqwlO9/JUiX2w01l82tMxVK8DmN3QwHWJxNexD5Ewf +QFG6FYFPNHCR2f+MUSMFp1djUSVpCrWbppmlr96uZ48= +-----END RSA PRIVATE KEY----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger.idl new file mode 100644 index 00000000000..05cf30bf5f9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger.idl @@ -0,0 +1,11 @@ +/* -*- C++ -*- $Id$ */ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerClient.cpp new file mode 100644 index 00000000000..d5ac902909d --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerClient.cpp @@ -0,0 +1,186 @@ +/* -*- C++ -*- $Id$ */ + +#include "ace/OS.h" +#include "ace/Get_Opt.h" + +#include "MessengerC.h" +#include "orbsvcs/SecurityC.h" + +// Policy Example 1 +// ================ +// +// Example of a client that downgrades +// from message protection to no message +// protection and upgrades from no +// peer authentication to authentication +// of targets, i.e., authentication of +// servers. +// +// The server's service configuration file +// for this example is +// +// # server.conf +// dynamic SSLIOP_Factory Service_Object * +// TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() +// "-SSLNoProtection +// -SSLAuthenticate SERVER_AND_CLIENT +// -SSLPrivateKey PEM:serverkey.pem +// -SSLCertificate PEM:servercert.pem" +// +// static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +// +// The clients service configuration file +// for this example is: +// +// # client.conf +// dynamic SSLIOP_Factory Service_Object * +// TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() +// "-SSLAuthenticate NONE +// -SSLPrivateKey PEM:clientkey.pem +// -SSLCertificate PEM:clientcert.pem" +// +// static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +// +// Policy Example 2 +// ================ +// +// Example of client upgrading from +// no message protection and no +// no authentication to message +// protection and authentication +// of targets, i.e., authentication +// of servers. +// +// The server's service configuration file for this example is +// +// # server.conf +// dynamic SSLIOP_Factory Service_Object * +// TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() +// "-SSLAuthenticate SERVER_AND_CLIENT +// -SSLPrivateKey PEM:serverkey.pem +// -SSLCertificate PEM:servercert.pem" +// +// static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +// +// The client's service configuration file +// for this example is: +// +// # client.conf +// dynamic SSLIOP_Factory Service_Object * +// TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() +// "-SSLNoProtection +// -SSLAuthenticate NONE +// -SSLPrivateKey PEM:clientkey.pem +// -SSLCertificate PEM:clientcert.pem" +// +// static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +// + + +int which = 0; + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, "e:"); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'e': + which = ACE_OS::atoi(get_opts.optarg); + if(which < 1 || 2 < which) + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s " + "-e [12]" + "\n", + argv [0]), + -1); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "Usage: %s " + "-e [12]" + "\n", + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + + CORBA::ORB_var orb = + CORBA::ORB_init( argc, argv ); + + CORBA::Object_var obj = + orb->string_to_object( "file://Messenger.ior" ); + + if (parse_args (argc, argv) != 0) + return 1; + else if(which < 1 || 2 < which) + return 1; + + Security::QOP qop; + CORBA::Any protection; + Security::EstablishTrust establish_trust; + CORBA::Any trust; + CORBA::PolicyList policy_list (2); + + if (which == 1) + { + qop = Security::SecQOPNoProtection; + //qop = Security::SecQOPIntegrity; + + establish_trust.trust_in_client = 0; + establish_trust.trust_in_target = 1; + } + else + { + qop = Security::SecQOPIntegrityAndConfidentiality; + + establish_trust.trust_in_client = 0; + establish_trust.trust_in_target = 1; + } + + protection <<= qop; + trust <<= establish_trust; + + CORBA::Policy_var policy = + orb->create_policy (Security::SecQOPPolicy, protection); + + CORBA::Policy_var policy2 = + orb->create_policy (Security::SecEstablishTrustPolicy, trust); + + policy_list.length (1); + policy_list[0] = CORBA::Policy::_duplicate (policy.in ()); + policy_list.length (2); + policy_list[1] = CORBA::Policy::_duplicate (policy2.in ()); + + CORBA::Object_var object = + obj->_set_policy_overrides (policy_list, + CORBA::SET_OVERRIDE); + + Messenger_var messenger = + Messenger::_narrow( object.in() ); + + CORBA::String_var message = + CORBA::string_dup( "Implementing security policy now!" ); + + messenger->send_message( "Chief of Security", + "New Directive", + message.inout() ); + } + catch(const CORBA::Exception& ex) { + ex._tao_print_exception("Client: main block"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerServer.cpp new file mode 100644 index 00000000000..c6fdabeeb1e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/MessengerServer.cpp @@ -0,0 +1,46 @@ +/* -*- C++ -*- $Id$ */ + +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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) { + ex._tao_print_exception("Server Error: main block"); + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.cpp new file mode 100644 index 00000000000..a92cea8879f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.cpp @@ -0,0 +1,25 @@ +/* -*- C++ -*- $Id$ */ + +#include "Messenger_i.h" +#include <iostream> +// 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 + ) + { + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + return 1; + } diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.h new file mode 100644 index 00000000000..ef9b4a759a2 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/Messenger_i.h @@ -0,0 +1,31 @@ +/* -*- C++ -*- $Id$ */ + +#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 + ); + +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/PolicyControllingApp.mpc b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/PolicyControllingApp.mpc new file mode 100644 index 00000000000..e79645474db --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/PolicyControllingApp.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): portableserver, orbsvcsexe, security, ssliop { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): orbsvcsexe, security, ssliop { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/README b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/README new file mode 100644 index 00000000000..bf3b57390a4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/README @@ -0,0 +1,144 @@ +TAO Security + +DevGuideExamples/Security/PolicyControllingApp/README + +This directory contains an illustration of a security aware +application that modifies security service policies. Similar +to the security unaware application example, these examples +vary the client and server's configurations. However, there +are also different paths through the client application that +demonstrate different policy settings. + +For readability, long text lines from the example's service +configuration files are split into multiple lines. A backslash +indicates the end of partial line except for the final fragment. +The backslashes should be removed and the fragments joined for +use with the example programs. + +For simplicity, the pass phrases have been stripped from the +private keys included with these examples in the 1.2a release. +This *should not* be construed as a recommended practice. Instead, +OCI strongly recommends that the security requirements of each +real-world application be evaluated carefully and that appropriate +procedures and practice be established accordingly. Private keys +without pass phrase protection are easily compromised and may +allow an unauthorized party to masquerade as an authorized system +user. + +Prior to running the server in these examples, the SSL_CERT_FILE +environment variable must be set, e.g., + # /bin/bash + export SSL_CERT_FILE=cacert.pem +or + rem Windows + set SSL_CERT_FILE=cacert.pem + +Example 1: Client sets Quality of Protection to NoProtection +------------------------------------------------------------ +The server is configured to accept both secured and unsecured +invocations (by setting -SSLNoProtection). The client is +configured to make secured invocations only. The client +application sets the quality of protection policy to +no protection to make an unsecured invocation to the server. + +The server's configuration is: + +# +# server.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLNoProtection \ + -SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of server.conf +# + +The client's configuration is: + +# +# client.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate NONE \ + -SSLPrivateKey PEM:clientkey.pem \ + -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of client.conf +# + +To run the server: + ./MessengerServer -ORBSvcConf server.conf + +To run the client: + ./MessengerClient -e 1 -ORBSvcConf client.conf + +Note: as presented in the 1.2a Developer's Guide, the client code +for this first example also manipulates the establish trust +policy. After the text went to print, changes in TAO have required +a change to this example such that the establish trust policy can't +be modified as shown in the text without causing an exception. This +example has been modified accordingly to execute without causing an +exception. + +Example 2: Client sets Quality of Protection to IntegrityAndConfidentiality +and EstablishTrust to authenticate the server +--------------------------------------------------------------------------- +The server is configured to accept secured invocations only. The client +is configured to issue unsecured invocations by default (-SSLNoProtection is +set). The client sets the quality of protection policy to integrity and +confidentiality and establish trust policy to authenticate the server. This +can only be achieved via a secured invocation. + +The server's configuration is: + +# +# server1.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of server1.conf +# + +The client's configuration is: + +# +# client1.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLNoProtection \ + -SSLAuthenticate NONE \ + -SSLPrivateKey PEM:clientkey.pem \ + -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of client1.conf +# + +To run the server: + ./MessengerServer -ORBSvcConf server1.conf + +To run the client: + ./MessengerClient -e 2 -ORBSvcConf client1.conf + + +-------------------------------------------------- +Files: DevGuideExamples/Security/PolicyControllingApp + +Messenger.idl - Messenger interface definition. +Messenger_i.h - Messenger servant class definition. +Messenger_i.cpp - Messenger servant implementation. +MessengerServer.cpp - MessengerServer process main. +MessengerClient.cpp - MessengerClient process main. + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/cacert.pem b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/cacert.pem new file mode 100644 index 00000000000..c493d28a523 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/cacert.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDujCCAyOgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBoDELMAkGA1UEBhMCVVMx +ETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNVBAoT +Fk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMU +Q2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5j +b20wHhcNMDMwNzIzMjAyNDIwWhcNMTMwNzIwMjAyNDIwWjCBoDELMAkGA1UEBhMC +VVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNV +BAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UE +AxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdl +Yi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO4QS4bqrXVuBnHsOg1/ +gijXjiWhFTngG/sDLWAA52fHIobyFo5//7UaLedke0fkwqsmky8hjzSbXGJsGI5g +Yjp2Va7WeJhRQNr8VYWobCq00f//drHN2NF5M23Cx0JF9WfyfWpqq5TQRGtVZ+We ++q4S6wH1exZrVGHfkp5Xq5FvAgMBAAGjggEAMIH9MB0GA1UdDgQWBBQvTY0YWmHq +o2TMOKba/ECH9ayXZzCBzQYDVR0jBIHFMIHCgBQvTY0YWmHqo2TMOKba/ECH9ayX +Z6GBpqSBozCBoDELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYD +VQQHEwlTdC4gTG91aXMxHzAdBgNVBAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4x +DDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAa +BgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkq +hkiG9w0BAQQFAAOBgQBgjn97nbyyjFxyHC8vheAiDCQRblI4lZbZC6vSmxxqEGze +eAMiTYL2iK3vj2Ot3V2/o5VdLyEYV4RBP2iq1XuMYXjmL2ni+NVgepyXceynH8/b +72yciZZcDE5FVUaMUHAgZUpxsGSDyD70LnOFwBxuvxtlMtG5vXYNvwF/FJPs1g== +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client.conf b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client.conf new file mode 100644 index 00000000000..1130e620d7b --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client.conf @@ -0,0 +1,6 @@ +# $Id$ + +# client.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLAuthenticate NONE -SSLPrivateKey PEM:clientkey.pem -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client1.conf b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client1.conf new file mode 100644 index 00000000000..23f4e0a5859 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/client1.conf @@ -0,0 +1,6 @@ +# $Id$ + +# client.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLNoProtection -SSLAuthenticate NONE -SSLPrivateKey PEM:clientkey.pem -SSLCertificate PEM:clientcert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientcert.pem b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientcert.pem new file mode 100644 index 00000000000..56616fcd469 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientcert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQQwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjIwN1oXDTEzMDgwNTAwMjIwN1owgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBmNs +aWVudDEgMB4GCSqGSIb3DQEJARYRY2xpZW50QG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAMYaaQgEmp2zv0t+MAEGf5GIsKSIB1YFrkkVR6Qv +LP0t9FHDPGFawh/aK3Yq+l7RiNpK1H5SSOaIavm4xV/3tpHxzuRjd0H3fdhaoAgD +xvcYZ75l662PEa25MCJsp40tACO0hGNOQCJ8kWVmT4xEhKcFl3xm+1OvNbwDM/pA +t4WpAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEArs6S6qud6D9t6AcGJS91XWqbBY1G +rSgmv9yFbvUyrGAQuMpyNuYTGlZA+Nd3EAjYlwP4fWbzUMM0MEtd3Xl0Aep0O39W +Cgp9HxDaJi3b4h63cd/B0su+2CNd4P6+NOX+IxgrrioCgKSnu6Nxy14fb03RQhjl +a3vOY5Juf8ySB/M= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientkey.pem new file mode 100644 index 00000000000..2b4af2322ad --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/clientkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQDGGmkIBJqds79LfjABBn+RiLCkiAdWBa5JFUekLyz9LfRRwzxh +WsIf2it2Kvpe0YjaStR+UkjmiGr5uMVf97aR8c7kY3dB933YWqAIA8b3GGe+Zeut +jxGtuTAibKeNLQAjtIRjTkAifJFlZk+MRISnBZd8ZvtTrzW8AzP6QLeFqQIDAQAB +AoGAJx1X16lxDepLvxAvUkSCM64Vkqb5K9b7TprRBm36KBNGxk4SQfa1laxyIGbk +AIzGxLM5uadtlXciCCSfdA9pEJbjtxSRJt2RbOWioT3sfIzXO7SCMHuuRjnPK3P8 +rgFmOOpo/ldVZ3mBJajxzWTEFXMUTAC4tB2j2B6of7MG5fECQQDu+uKzI2QjiTpW +5WFd/vzpS2SpDHks4sEu0F6zk1Zhbsc3KoJd3xxSLhKFLLoRDVZsDKE3opr7WRNT ++sjoGRY3AkEA1DZArJqLeWuB8L8GjC/AtMXsxlSe3Iy9X+4uffZ/y5A1JbYidLJl +3FlejMoQqp0EpbHO+mRCMSHyJqAFW1ZTHwJBANjv3oMHiYvIsrDXIQAWzLdqvUHI +FOfuH7fDZ3RUN4HS8fzeFeHo+uiO8jj6VR3NoboL7P14GoA4aBc//MjUnRkCQQCH +KZ770NtxFKaIvkLfWzL0cPQkRpWAiCu+RChclnpDH7CaOm2rwkzakhmEttbytFvX +ZW8dUGpQfPyM2XNP/6WlAkEAoOQ5UI1WREbjoJs5mTwTG1gTrQjShQwjC0dqt66s +bOS5os5EePGdctm//Xq7uR4/6hB6T7npPYqiyfWix1SINQ== +-----END RSA PRIVATE KEY----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/run_test.pl b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/run_test.pl new file mode 100755 index 00000000000..1e1ac789af7 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/run_test.pl @@ -0,0 +1,69 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$file = PerlACE::LocalFile("Messenger.ior"); + +unlink $file; + +$ENV{'SSL_CERT_FILE'} = 'cacert.pem'; + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", + "-ORBSvcConf server.conf"); + +$S1 = new PerlACE::Process("MessengerServer", + "-ORBSvcConf server1.conf"); + +$C = new PerlACE::Process("MessengerClient", + "-e 1 -ORBSvcConf client.conf"); + +$C1 = new PerlACE::Process("MessengerClient", + "-e 2 -ORBSvcConf client1.conf"); + + +print STDERR "\n\nSecurity Policy Controlling Application Examples\n"; +print STDERR "------------------------------------------------\n"; + +print STDERR "Starting Messenger Server, example 1...\n\n"; +$S->Spawn(); +if (PerlACE::waitforfile_timed ($file, 5) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $SV->Kill (); + exit 1; +} + +print STDERR "\nStarting MessengerClient, example 1...\n\n"; +if ($C->SpawnWaitKill(10) != 0) { + $S->Kill(); + exit (1); +} + +unlink $file; +$S->Kill(); + +print STDERR "\nStarting Messenger Server, example 2...\n\n"; +$S1->Spawn(); +if (PerlACE::waitforfile_timed ($file, 5) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $SV->Kill (); + exit 1; +} + +print STDERR "\nStarting MessengerClient, example 2...\n\n"; +if ($C1->SpawnWaitKill(10) != 0) { + $S->Kill(); + exit (1); +} + +# clean-up +$S1->Kill(); + +exit 0; + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server.conf b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server.conf new file mode 100644 index 00000000000..380312b03fc --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server.conf @@ -0,0 +1,5 @@ +# $Id$ + +# server.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLNoProtection -SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey PEM:serverkey.pem -SSLCertificate PEM:servercert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server1.conf b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server1.conf new file mode 100644 index 00000000000..f975ec687f8 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/server1.conf @@ -0,0 +1,5 @@ +# $Id$ + +# server.conf +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey PEM:serverkey.pem -SSLCertificate PEM:servercert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/servercert.pem b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/servercert.pem new file mode 100644 index 00000000000..9659fb07334 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/servercert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQMwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjAyOVoXDTEzMDgwNTAwMjAyOVowgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBlNl +cnZlcjEgMB4GCSqGSIb3DQEJARYRc2VydmVyQG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAKw+tjwQz/stcesfm6WvnB6D/FTYu79tHzGUDlSV +N+kycFYcZfsRmIEo5afG+epOwlp1f9Wpij23AMY4BcdcSP9R4yhH46uMFThQhkn9 +fraZ8slcgVog5G6MwXmsWb5gThjgiT0KPSQHkEU0bryw+CiM4oV+9dSaFBLa3Uqc +iQZdAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAur+t7sIqGjqAPgFtFcgByAJTvNYb +UDZ43AGd22tCtT/usoy/x9qsQv8jwd8kA8yUNQUmjRxR4vEkZ06L6HF8Ii1QmU/E +fZ7YcjXjWxgnCEQGSXuHLhmlIMAlXNvX1XzNddu/NuRbSP3lYS/j32W8gTb6MdyL +8bOkIqRpVY0ek80= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/serverkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/serverkey.pem new file mode 100644 index 00000000000..c61b8152649 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/PolicyControllingApp/serverkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCsPrY8EM/7LXHrH5ulr5weg/xU2Lu/bR8xlA5UlTfpMnBWHGX7 +EZiBKOWnxvnqTsJadX/VqYo9twDGOAXHXEj/UeMoR+OrjBU4UIZJ/X62mfLJXIFa +IORujMF5rFm+YE4Y4Ik9Cj0kB5BFNG68sPgojOKFfvXUmhQS2t1KnIkGXQIDAQAB +AoGBAKjg08wQr9qVtBvT4ceRZoCE5+JIncwSMYNqpqJHq4n46iuDrHl9xwjcEE9v +x5jzn5sRmUTj9aaMxzWRuBi/YtFVmgsl8lNiBOniIkFYqIyXfzNgX+2qyRzgOtAo +0ByWFsqkLmW9cUXWaICkM49b9Jz7SnmPs+9VWGiNrjgJSiABAkEA4eFIc82mP2KJ +wap8LJV7GLBA3iiVRmOgVb0TvRMitFWPGdGKFcsAVVkogQ/zIixKeZKc5enMhAI9 +i3Q2tmolZQJBAMM2hlSbJZncMjooKBlp2VZgUpEjbBPpD9XGgA5BO2RfKi3B29T9 +2v8I3m9WbCxbtFKlHcjNT3GToGCoi4S1qZkCQDcn7qwwZE8H/cFnoui0G5ncuApH +eKP2gdlN0TsTKB9G4SmZzBEkP9GXcteJEIKgtBLZpSxTGdiGP4cE+rMyWi0CQDam +TgbjhCxFq74CPe+XZWO8BYFiREByr58uOe1Dr8fSqHE040EGbEeXiQXsUM4+QgYc ++XCcoY/vPyewJ5bYcIkCQERqwlO9/JUiX2w01l82tMxVK8DmN3QwHWJxNexD5Ewf +QFG6FYFPNHCR2f+MUSMFp1djUSVpCrWbppmlr96uZ48= +-----END RSA PRIVATE KEY----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger.idl b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger.idl new file mode 100644 index 00000000000..05cf30bf5f9 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger.idl @@ -0,0 +1,11 @@ +/* -*- C++ -*- $Id$ */ + +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerClient.cpp b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerClient.cpp new file mode 100644 index 00000000000..76f812e7cff --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerClient.cpp @@ -0,0 +1,39 @@ +/* -*- C++ -*- $Id$ */ + +#include "MessengerC.h" +#include <iostream> +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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; + } + + CORBA::String_var message = CORBA::string_dup( + "Implementing security policy now!" ); + messenger->send_message( "Chief of Security", + "New Directive", + message.inout() ); + std::cout << "message was sent" << std::endl; + } + + catch(const CORBA::Exception& ex) { + std::cerr << "Caught CORBA excepti.o.n: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerI.cpp b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerI.cpp new file mode 100644 index 00000000000..dea865aa6f4 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerI.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: +// Center for Distributed Object Computing +// Washington University +// St. Louis, MO +// USA +// http://www.cs.wustl.edu/~schmidt/doc-center.html +// and +// Distributed Object Computing Laboratory +// University of California at Irvine +// Irvine, CA +// USA +// http://doc.ece.uci.edu/ +// +// Information about TAO is available at: +// http://www.cs.wustl.edu/~schmidt/TAO.html + +#include "MessengerI.h" + +// 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 + } + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerServer.cpp b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerServer.cpp new file mode 100644 index 00000000000..8cdfce1b28e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/MessengerServer.cpp @@ -0,0 +1,46 @@ +/* -*- C++ -*- $Id$ */ + +#include "Messenger_i.h" +#include <iostream> +#include <fstream> +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + try { + // 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 << "Caught a CORBA exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.cpp b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.cpp new file mode 100644 index 00000000000..809cfcc584f --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.cpp @@ -0,0 +1,32 @@ +/* -*- 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 <iostream> +// 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 + ) + { + std::cout << "Message from: " << user_name << std::endl; + std::cout << "Subject: " << subject << std::endl; + std::cout << "Message: " << message << std::endl; + return 1; + } diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.h b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.h new file mode 100644 index 00000000000..ef9b4a759a2 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/Messenger_i.h @@ -0,0 +1,31 @@ +/* -*- C++ -*- $Id$ */ + +#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 + ); + +}; + + +#endif /* MESSENGERI_H_ */ diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/README b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/README new file mode 100644 index 00000000000..7eebb03ebfb --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/README @@ -0,0 +1,172 @@ +TAO Security + +DevGuideExamples/Security/SecurityUnawareApp/README + +This directory contains an illustration of a security unaware +application. The examples vary the client's configuration to +demonstrate different features. For each of these examples, +however, the client and server process code remains the same. + +For readability, long text lines from the example's service +configuration files are split into multiple lines. A backslash +indicates the end of partial line except for the final fragment. +The backslashes should be removed and the fragments joined for +use with the example programs. + +For simplicity, the pass phrases have been stripped from the +private keys included with these examples in the 1.2a release. +This *should not* be construed as a recommended practice. Instead, +OCI strongly recommends that the security requirements of each +real-world application be evaluated carefully and that appropriate +procedures and practice be established accordingly. Private keys +without pass phrase protection are easily compromised and may +allow an unauthorized party to masquerade as an authorized system +user. + +Prior to running the server in these examples, the SSL_CERT_FILE +environment variable must be set, e.g., + # /bin/bash + export SSL_CERT_FILE=cacert.pem +or + rem Windows + set SSL_CERT_FILE=cacert.pem + +For examples 1 and 2, the client's environment should also +define SSL_CERT_FILE appropriately. The final example +demonstrates how to establish a connection between a client +and server such that the client does not authenticate the +server and therefore does not need a value for SSL_CERT_FILE. + + + +Example 1: Secured server and unsecured client +---------------------------------------------- +The server is configured to accept requests only via secured +connections. No specific configurationi is provided for the +client so it has the default configuration. + +The server's configuration is: + +# +# server.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of server.conf +# + +To run the server: + ./MessengerServer -ORBSvcConf server.conf + +To run the client: + ./MessengerClient + + + +Example 2: Secured server and unsecured client +---------------------------------------------- +Both server and client are configured to issue and accept +requests via secured connections. + +The server's configuration is: + +# +# server.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of server.conf +# + +The client's configuration is: + +# +# client.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of client.conf +# + +To run the server: + ./MessengerServer -ORBSvcConf server.conf + +To run the client: + ./MessengerClient -ORBSvcConf client.conf + + + +Example 3: client doesn't authenticate server +--------------------------------------------- +The client is configured such that it doesn't authenticate +the server. It still employs an encrypted connection but, +since it doesn't need a CA certificate, no value for +SSL_CERT_FILE is required. + +The server's configuration is: + +# +# server.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate SERVER_AND_CLIENT \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of server.conf +# + +The client's configuration is: + +# +# client.conf +# +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() \ + "-SSLAuthenticate NONE \ + -SSLPrivateKey PEM:serverkey.pem \ + -SSLCertificate PEM:servercert.pem" + +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" +# +# end of client.conf +# + +To run the server: + ./MessengerServer -ORBSvcConf server.conf + +To run the client: + ./MessengerClient -ORBSvcConf client.conf + +If a value for SSL_CERT_FILE has already been placed in the +client's environment, the client may be executed as follows (on +Unix platforms): + SSL_CERT_FILE= ./MessengerClient -ORBSvcConf client.conf + + + +-------------------------------------------------- +Files: DevGuideExamples/Security/SecurityUnawareApp/ + +Messenger.idl - Messenger interface definition. +Messenger_i.h - Messenger servant class definition. +Messenger_i.cpp - Messenger servant implementation. +MessengerServer.cpp - MessengerServer process main. +MessengerClient.cpp - MessengerClient process main. + diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/SecurityUnawareApp.mpc b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/SecurityUnawareApp.mpc new file mode 100644 index 00000000000..09a2598b354 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/SecurityUnawareApp.mpc @@ -0,0 +1,15 @@ +// $Id$ + +project(*Server): taoexe, portableserver, security, ssl { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): taoexe, security, ssl { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/cacert.pem b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/cacert.pem new file mode 100644 index 00000000000..c493d28a523 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/cacert.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDujCCAyOgAwIBAgIBADANBgkqhkiG9w0BAQQFADCBoDELMAkGA1UEBhMCVVMx +ETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNVBAoT +Fk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMU +Q2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5j +b20wHhcNMDMwNzIzMjAyNDIwWhcNMTMwNzIwMjAyNDIwWjCBoDELMAkGA1UEBhMC +VVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYDVQQHEwlTdC4gTG91aXMxHzAdBgNV +BAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4xDDAKBgNVBAsTA1RBTzEdMBsGA1UE +AxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAaBgkqhkiG9w0BCQEWDWNhQG9jaXdl +Yi5jb20wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAO4QS4bqrXVuBnHsOg1/ +gijXjiWhFTngG/sDLWAA52fHIobyFo5//7UaLedke0fkwqsmky8hjzSbXGJsGI5g +Yjp2Va7WeJhRQNr8VYWobCq00f//drHN2NF5M23Cx0JF9WfyfWpqq5TQRGtVZ+We ++q4S6wH1exZrVGHfkp5Xq5FvAgMBAAGjggEAMIH9MB0GA1UdDgQWBBQvTY0YWmHq +o2TMOKba/ECH9ayXZzCBzQYDVR0jBIHFMIHCgBQvTY0YWmHqo2TMOKba/ECH9ayX +Z6GBpqSBozCBoDELMAkGA1UEBhMCVVMxETAPBgNVBAgTCE1pc3NvdXJpMRIwEAYD +VQQHEwlTdC4gTG91aXMxHzAdBgNVBAoTFk9iamVjdCBDb21wdXRpbmcsIEluYy4x +DDAKBgNVBAsTA1RBTzEdMBsGA1UEAxMUQ2VydGlmeWluZyBBdXRob3JpdHkxHDAa +BgkqhkiG9w0BCQEWDWNhQG9jaXdlYi5jb22CAQAwDAYDVR0TBAUwAwEB/zANBgkq +hkiG9w0BAQQFAAOBgQBgjn97nbyyjFxyHC8vheAiDCQRblI4lZbZC6vSmxxqEGze +eAMiTYL2iK3vj2Ot3V2/o5VdLyEYV4RBP2iq1XuMYXjmL2ni+NVgepyXceynH8/b +72yciZZcDE5FVUaMUHAgZUpxsGSDyD70LnOFwBxuvxtlMtG5vXYNvwF/FJPs1g== +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client.conf b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client.conf new file mode 100644 index 00000000000..78e939b5c7e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey PEM:clientkey.pem -SSLCertificate PEM:clientcert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client1.conf b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client1.conf new file mode 100644 index 00000000000..daafe5fdf58 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/client1.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLAuthenticate NONE -SSLPrivateKey PEM:clientkey.pem -SSLCertificate PEM:clientcert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientcert.pem b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientcert.pem new file mode 100644 index 00000000000..56616fcd469 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientcert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQQwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjIwN1oXDTEzMDgwNTAwMjIwN1owgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBmNs +aWVudDEgMB4GCSqGSIb3DQEJARYRY2xpZW50QG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAMYaaQgEmp2zv0t+MAEGf5GIsKSIB1YFrkkVR6Qv +LP0t9FHDPGFawh/aK3Yq+l7RiNpK1H5SSOaIavm4xV/3tpHxzuRjd0H3fdhaoAgD +xvcYZ75l662PEa25MCJsp40tACO0hGNOQCJ8kWVmT4xEhKcFl3xm+1OvNbwDM/pA +t4WpAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEArs6S6qud6D9t6AcGJS91XWqbBY1G +rSgmv9yFbvUyrGAQuMpyNuYTGlZA+Nd3EAjYlwP4fWbzUMM0MEtd3Xl0Aep0O39W +Cgp9HxDaJi3b4h63cd/B0su+2CNd4P6+NOX+IxgrrioCgKSnu6Nxy14fb03RQhjl +a3vOY5Juf8ySB/M= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientkey.pem new file mode 100644 index 00000000000..2b4af2322ad --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/clientkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXgIBAAKBgQDGGmkIBJqds79LfjABBn+RiLCkiAdWBa5JFUekLyz9LfRRwzxh +WsIf2it2Kvpe0YjaStR+UkjmiGr5uMVf97aR8c7kY3dB933YWqAIA8b3GGe+Zeut +jxGtuTAibKeNLQAjtIRjTkAifJFlZk+MRISnBZd8ZvtTrzW8AzP6QLeFqQIDAQAB +AoGAJx1X16lxDepLvxAvUkSCM64Vkqb5K9b7TprRBm36KBNGxk4SQfa1laxyIGbk +AIzGxLM5uadtlXciCCSfdA9pEJbjtxSRJt2RbOWioT3sfIzXO7SCMHuuRjnPK3P8 +rgFmOOpo/ldVZ3mBJajxzWTEFXMUTAC4tB2j2B6of7MG5fECQQDu+uKzI2QjiTpW +5WFd/vzpS2SpDHks4sEu0F6zk1Zhbsc3KoJd3xxSLhKFLLoRDVZsDKE3opr7WRNT ++sjoGRY3AkEA1DZArJqLeWuB8L8GjC/AtMXsxlSe3Iy9X+4uffZ/y5A1JbYidLJl +3FlejMoQqp0EpbHO+mRCMSHyJqAFW1ZTHwJBANjv3oMHiYvIsrDXIQAWzLdqvUHI +FOfuH7fDZ3RUN4HS8fzeFeHo+uiO8jj6VR3NoboL7P14GoA4aBc//MjUnRkCQQCH +KZ770NtxFKaIvkLfWzL0cPQkRpWAiCu+RChclnpDH7CaOm2rwkzakhmEttbytFvX +ZW8dUGpQfPyM2XNP/6WlAkEAoOQ5UI1WREbjoJs5mTwTG1gTrQjShQwjC0dqt66s +bOS5os5EePGdctm//Xq7uR4/6hB6T7npPYqiyfWix1SINQ== +-----END RSA PRIVATE KEY----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/run_test.pl b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/run_test.pl new file mode 100755 index 00000000000..0b3a2b0446e --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/run_test.pl @@ -0,0 +1,64 @@ +# $Id$ + +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +use Env (ACE_ROOT); +use lib "$ACE_ROOT/bin"; +use PerlACE::Run_Test; + +$file = PerlACE::LocalFile("Messenger.ior"); + +unlink $file; + +$ENV{'SSL_CERT_FILE'} = 'cacert.pem'; + +# start MessengerServer +$S = new PerlACE::Process("MessengerServer", + "-ORBSvcConf server.conf"); + +print STDERR "\n\nSecurity Unaware Application Examples\n"; +print STDERR "-------------------------------------\n"; +print STDERR "Starting Messenger Server...\n\n"; + +$S->Spawn(); +if (PerlACE::waitforfile_timed ($file, 5) == -1) { + print STDERR "ERROR: cannot find file <$file>\n"; + $SV->Kill (); + exit 1; +} + +# start MessengerClient +$C = new PerlACE::Process("MessengerClient"); + +$C1 = new PerlACE::Process("MessengerClient", + "-ORBSvcConf client.conf"); + +$C2 = new PerlACE::Process("MessengerClient", + "-ORBSvcConf client1.conf"); + +print STDERR "\nStarting MessengerClient, example 1...\n\n"; +if ($C->SpawnWaitKill(10) == 0) { + $S->Kill(); + exit (1); +} + +print STDERR "\nStarting MessengerClient, example 2...\n\n"; +if ($C1->SpawnWaitKill(10) != 0) { + $S->Kill(); + exit (1); +} + +$ENV{'SSL_CERT_FILE'} = ''; + +print STDERR "\nStarting MessengerClient, example 3...\n\n"; +if ($C2->SpawnWaitKill(10) != 0) { + $S->Kill(); + exit (1); +} + +# clean-up +$S->Kill(); + +exit 0; diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/server.conf b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/server.conf new file mode 100644 index 00000000000..200fbd6cb8b --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/server.conf @@ -0,0 +1,4 @@ +# $Id$ + +dynamic SSLIOP_Factory Service_Object * TAO_SSLIOP:_make_TAO_SSLIOP_Protocol_Factory() "-SSLAuthenticate SERVER_AND_CLIENT -SSLPrivateKey PEM:serverkey.pem -SSLCertificate PEM:servercert.pem" +static Resource_Factory "-ORBProtocolFactory SSLIOP_Factory" diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/servercert.pem b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/servercert.pem new file mode 100644 index 00000000000..9659fb07334 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/servercert.pem @@ -0,0 +1,17 @@ +-----BEGIN CERTIFICATE----- +MIICpzCCAhACAQMwDQYJKoZIhvcNAQEEBQAwgaAxCzAJBgNVBAYTAlVTMREwDwYD +VQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZPYmpl +Y3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xHTAbBgNVBAMTFENlcnRp +ZnlpbmcgQXV0aG9yaXR5MRwwGgYJKoZIhvcNAQkBFg1jYUBvY2l3ZWIuY29tMB4X +DTAzMDgwODAwMjAyOVoXDTEzMDgwNTAwMjAyOVowgZYxCzAJBgNVBAYTAlVTMREw +DwYDVQQIEwhNaXNzb3VyaTESMBAGA1UEBxMJU3QuIExvdWlzMR8wHQYDVQQKExZP +YmplY3QgQ29tcHV0aW5nLCBJbmMuMQwwCgYDVQQLEwNUQU8xDzANBgNVBAMTBlNl +cnZlcjEgMB4GCSqGSIb3DQEJARYRc2VydmVyQG9jaXdlYi5jb20wgZ8wDQYJKoZI +hvcNAQEBBQADgY0AMIGJAoGBAKw+tjwQz/stcesfm6WvnB6D/FTYu79tHzGUDlSV +N+kycFYcZfsRmIEo5afG+epOwlp1f9Wpij23AMY4BcdcSP9R4yhH46uMFThQhkn9 +fraZ8slcgVog5G6MwXmsWb5gThjgiT0KPSQHkEU0bryw+CiM4oV+9dSaFBLa3Uqc +iQZdAgMBAAEwDQYJKoZIhvcNAQEEBQADgYEAur+t7sIqGjqAPgFtFcgByAJTvNYb +UDZ43AGd22tCtT/usoy/x9qsQv8jwd8kA8yUNQUmjRxR4vEkZ06L6HF8Ii1QmU/E +fZ7YcjXjWxgnCEQGSXuHLhmlIMAlXNvX1XzNddu/NuRbSP3lYS/j32W8gTb6MdyL +8bOkIqRpVY0ek80= +-----END CERTIFICATE----- diff --git a/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/serverkey.pem b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/serverkey.pem new file mode 100644 index 00000000000..c61b8152649 --- /dev/null +++ b/TAO/orbsvcs/DevGuideExamples/Security/SecurityUnawareApp/serverkey.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXAIBAAKBgQCsPrY8EM/7LXHrH5ulr5weg/xU2Lu/bR8xlA5UlTfpMnBWHGX7 +EZiBKOWnxvnqTsJadX/VqYo9twDGOAXHXEj/UeMoR+OrjBU4UIZJ/X62mfLJXIFa +IORujMF5rFm+YE4Y4Ik9Cj0kB5BFNG68sPgojOKFfvXUmhQS2t1KnIkGXQIDAQAB +AoGBAKjg08wQr9qVtBvT4ceRZoCE5+JIncwSMYNqpqJHq4n46iuDrHl9xwjcEE9v +x5jzn5sRmUTj9aaMxzWRuBi/YtFVmgsl8lNiBOniIkFYqIyXfzNgX+2qyRzgOtAo +0ByWFsqkLmW9cUXWaICkM49b9Jz7SnmPs+9VWGiNrjgJSiABAkEA4eFIc82mP2KJ +wap8LJV7GLBA3iiVRmOgVb0TvRMitFWPGdGKFcsAVVkogQ/zIixKeZKc5enMhAI9 +i3Q2tmolZQJBAMM2hlSbJZncMjooKBlp2VZgUpEjbBPpD9XGgA5BO2RfKi3B29T9 +2v8I3m9WbCxbtFKlHcjNT3GToGCoi4S1qZkCQDcn7qwwZE8H/cFnoui0G5ncuApH +eKP2gdlN0TsTKB9G4SmZzBEkP9GXcteJEIKgtBLZpSxTGdiGP4cE+rMyWi0CQDam +TgbjhCxFq74CPe+XZWO8BYFiREByr58uOe1Dr8fSqHE040EGbEeXiQXsUM4+QgYc ++XCcoY/vPyewJ5bYcIkCQERqwlO9/JUiX2w01l82tMxVK8DmN3QwHWJxNexD5Ewf +QFG6FYFPNHCR2f+MUSMFp1djUSVpCrWbppmlr96uZ48= +-----END RSA PRIVATE KEY----- |