diff options
Diffstat (limited to 'TAO/DevGuideExamples/ImplRepo')
23 files changed, 1032 insertions, 0 deletions
diff --git a/TAO/DevGuideExamples/ImplRepo/Activator/run_test.pl b/TAO/DevGuideExamples/ImplRepo/Activator/run_test.pl new file mode 100644 index 00000000000..da22251c496 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Activator/run_test.pl @@ -0,0 +1,121 @@ +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; +use Sys::Hostname; + +my $WAIT_TIMEOUT = 2; +my $DEBUG_LEVEL = 1; +my $OBJ_REF_STYLE = "-orbobjrefstyle url"; + +my $implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImplRepo_Service"; +my $imr_activator = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImR_Activator"; +my $tao_imr = "$ENV{ACE_ROOT}/bin/tao_imr"; + +my $implrepo_ior = "imr.ior"; +my $activator_ior = "activator.ior"; +my $messenger_ior = "messenger.ior"; + +my $imr_init_ref = "-ORBInitRef ImplRepoService=file://$implrepo_ior"; + +my $Svr = new PerlACE::Process('../Basic/MessengerServer', "-orbuseimr 1 $OBJ_REF_STYLE $imr_init_ref"); +my $Cli = new PerlACE::Process('../Basic/MessengerClient'); + +my $server_cmd = $Svr->Executable(); + +sub CleanupOutput { + unlink $messenger_ior; + unlink $implrepo_ior; + unlink $activator_ior; +} + +sub SpawnWait { + my $process = shift; + my $file = shift; + + print ">>> " . $process->CommandLine() . "\n"; + $process->Spawn(); + my $ret = PerlACE::waitforfile_timed($file, $WAIT_TIMEOUT); + if ($ret == -1) { + print STDERR "ERROR: Cannot find file <$file>\n"; + } + return $ret; +} + +# Use url object reference style for readability, and startup timeout of 2 seconds. +# Unlike the chapter we'll forgo using -m, because we want to be able to run this +# as a test in our nightly builds, and multicast could interfere with other machines. +my $ImR = new PerlACE::Process ($implrepo_server, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -t 2 -o $implrepo_ior"); +my $Act = new PerlACE::Process ($imr_activator, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -o $activator_ior $imr_init_ref"); + +my $imr_util = new PerlACE::Process ("$tao_imr"); +# We want the tao_imr 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. +$imr_util->IgnoreExeSubDir(1); + +sub RunImRUtil { + my $cmd = shift; + print ">>> " . $imr_util->CommandLine() . "\n"; + $imr_util->Arguments("$imr_init_ref $cmd"); + return $imr_util->SpawnWaitKill(5); +} + +CleanupOutput(); + +#### Start the example + +if (SpawnWait($ImR, $implrepo_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +if (SpawnWait($Act, $activator_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +#instead of using tao_imr add, we'll use tao_imr update, because +#we want to run the server once to generate the ior file. + +if (SpawnWait($Svr, $messenger_ior) != 0) { + $Act->Kill(); + $ImR->Kill(); + exit 1; +} + +RunImRUtil("list -v"); + +RunImRUtil("shutdown MessengerService"); +$Svr->WaitKill($WAIT_TIMEOUT); + +RunImRUtil("list -v"); + +# Note : If the server registers itself, then it won't set the +# activator name. If we don't set it here, then the activator +# won't be able to start the server. +my $actname = hostname; +RunImRUtil("update MessengerService -l $actname -c \"$server_cmd $OBJ_REF_STYLE -ORBUseIMR 1 $imr_init_ref\""); + +RunImRUtil("list -v"); + +if ($Cli->SpawnWaitKill(1000) != 0) { + print STDERR "Error : Client failed to run correctly."; +} + +$Act->Kill(); + +RunImRUtil("list -v"); + +RunImRUtil("shutdown MessengerService"); + +$ImR->Kill(); + +#### Clean up any output files + +CleanupOutput(); + +exit 0; diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/ImplRepo_Basic.mpc b/TAO/DevGuideExamples/ImplRepo/Basic/ImplRepo_Basic.mpc new file mode 100644 index 00000000000..4bd5d1438bd --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/ImplRepo_Basic.mpc @@ -0,0 +1,13 @@ +project(*Server): taoexe, portableserver, avoids_minimum_corba, avoids_corba_e_micro { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): taoexe, anytypecode, avoids_minimum_corba { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/Messenger.idl b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger.idl new file mode 100644 index 00000000000..2c75f1cb614 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger.idl @@ -0,0 +1,3 @@ +interface Messenger { + boolean send_message (in string user_name, in string subject, inout string message); +}; diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/MessengerClient.cpp b/TAO/DevGuideExamples/ImplRepo/Basic/MessengerClient.cpp new file mode 100644 index 00000000000..550b6acc92e --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/MessengerClient.cpp @@ -0,0 +1,26 @@ +#include "MessengerC.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->string_to_object("file://messenger.ior"); + + Messenger_var messenger = Messenger::_narrow(obj.in()); + if (CORBA::is_nil(messenger.in())) { + std::cerr << "Unable to get 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 << "Reply was : " << message.in() << std::endl; + + return 0; + } catch(const CORBA::Exception& ex) { + std::cerr << "Client main() Caught Exception: " << ex << std::endl; + } + return 1; +} diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/MessengerServer.cpp b/TAO/DevGuideExamples/ImplRepo/Basic/MessengerServer.cpp new file mode 100644 index 00000000000..97acc809411 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/MessengerServer.cpp @@ -0,0 +1,74 @@ +#include "Messenger_i.h" +#include <iostream> +#include <fstream> + + +PortableServer::POA_ptr +createPersistentPOA(PortableServer::POA_ptr root_poa, + const char* poa_name) +{ + CORBA::PolicyList policies; + policies.length(2); + + policies[0] = root_poa->create_lifespan_policy(PortableServer::PERSISTENT); + policies[1] = root_poa->create_id_assignment_policy(PortableServer::USER_ID); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + PortableServer::POA_var poa = + root_poa->create_POA(poa_name, mgr.in(), policies); + + policies[0]->destroy(); + policies[1]->destroy(); + + return poa._retn(); +} + +void writeIORFile(const char* ior) { + std::ofstream out("messenger.ior"); + out << ior; +} + +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 root_poa = PortableServer::POA::_narrow(obj.in()); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + + const char* poa_name = "MessengerService"; + + PortableServer::POA_var poa = createPersistentPOA(root_poa.in(), poa_name); + + Messenger_i servant; + + PortableServer::ObjectId_var object_id = + PortableServer::string_to_ObjectId("object"); + + poa->activate_object_with_id(object_id.in(), &servant); + + obj = poa->id_to_reference(object_id.in()); + CORBA::String_var ior = orb->object_to_string(obj.in()); + + writeIORFile(ior.in()); + + mgr->activate(); + + std::cout << "Messenger server ready." << std::endl; + + orb->run(); + + std::cout << "Messenger server shutting down." << std::endl; + + root_poa->destroy(1,1); + orb->destroy(); + + return 0; + } catch(const CORBA::Exception& ex) { + std::cerr << "Server main() Caught Exception" << ex << std::endl; + } + return 1; +} diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.cpp b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.cpp new file mode 100644 index 00000000000..c224376be09 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.cpp @@ -0,0 +1,16 @@ +#include "Messenger_i.h" +#include <iostream> +#include <exception> + +CORBA::Boolean Messenger_i::send_message( + const char * user_name, + const char * subject, + char *& message) +{ + std::cout << "Message from: " << user_name << std::endl + << "Subject: " << subject << std::endl + << "Message: " << message << std::endl; + message = CORBA::string_dup("A reply."); + return 1; +} + diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.h b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.h new file mode 100644 index 00000000000..af61f133d87 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/Messenger_i.h @@ -0,0 +1,17 @@ +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include "MessengerS.h" + +class Messenger_i : public virtual POA_Messenger +{ + int count; +public: + Messenger_i() : count(0) {} + virtual CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message); +}; + +#endif diff --git a/TAO/DevGuideExamples/ImplRepo/Basic/run_test.pl b/TAO/DevGuideExamples/ImplRepo/Basic/run_test.pl new file mode 100644 index 00000000000..e6f49f05aad --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Basic/run_test.pl @@ -0,0 +1,92 @@ +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; + +my $WAIT_TIMEOUT = 2; +my $DEBUG_LEVEL = 1; +my $OBJ_REF_STYLE = "-orbobjrefstyle url"; + +my $implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImplRepo_Service"; +my $imr_activator = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImR_Activator"; +my $tao_imr = "$ENV{ACE_ROOT}/bin/tao_imr"; + +my $implrepo_ior = "imr.ior"; +my $activator_ior = "activator.ior"; +my $messenger_ior = "messenger.ior"; + +my $imr_init_ref = "-ORBInitRef ImplRepoService=file://$implrepo_ior"; + +my $Svr = new PerlACE::Process('MessengerServer', "-orbuseimr 1 $OBJ_REF_STYLE $imr_init_ref"); +my $Cli = new PerlACE::Process('MessengerClient'); + +sub CleanupOutput { + unlink $messenger_ior; + unlink $implrepo_ior; + unlink $activator_ior; +} + +sub SpawnWait { + my $process = shift; + my $file = shift; + + print ">>> " . $process->CommandLine() . "\n"; + $process->Spawn(); + my $ret = PerlACE::waitforfile_timed($file, $WAIT_TIMEOUT); + if ($ret == -1) { + print STDERR "ERROR: Cannot find file <$file>\n"; + } + return $ret; +} + +# Use url object reference style for readability, and startup timeout of 2 seconds. +# Unlike the chapter we'll forgo using -m, because we want to be able to run this +# as a test in our nightly builds, and multicast could interfere with other machines. +my $ImR = new PerlACE::Process ($implrepo_server, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -t 2 -o $implrepo_ior"); +my $Act = new PerlACE::Process ($imr_activator, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -o $activator_ior $imr_init_ref"); + +my $imr_util = new PerlACE::Process ("$tao_imr", + "$imr_init_ref add MessengerService -c \"$Svr->Executable() $OBJ_REF_STYLE -ORBUseIMR 1 $imr_init_ref\""); + +# We want the tao_imr 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. +$imr_util->IgnoreExeSubDir(1); + +sub RunImRUtil { + my $cmd = shift; + print ">>> " . $imr_util->CommandLine() . "\n"; + $imr_util->Arguments("$imr_init_ref $cmd"); + return $imr_util->SpawnWaitKill(5); +} + +CleanupOutput(); + +#### Start the example + +if (SpawnWait($ImR, $implrepo_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +if (SpawnWait($Svr, $messenger_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +if ($Cli->SpawnWaitKill($WAIT_TIMEOUT) != 0) { + print STDERR "Error : Client failed to run correctly."; +} + +$Svr->Kill(); +$ImR->Kill(); + + +#### Clean up any output files + +CleanupOutput(); + +exit 0; diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/ImplRepo_IORTable.mpc b/TAO/DevGuideExamples/ImplRepo/IORTable/ImplRepo_IORTable.mpc new file mode 100644 index 00000000000..881362f4ab3 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/ImplRepo_IORTable.mpc @@ -0,0 +1,13 @@ +project(*Server): taoexe, portableserver, avoids_minimum_corba, iortable, avoids_corba_e_micro { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): taoexe, anytypecode, avoids_minimum_corba { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger.idl b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger.idl new file mode 100644 index 00000000000..2c75f1cb614 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger.idl @@ -0,0 +1,3 @@ +interface Messenger { + boolean send_message (in string user_name, in string subject, inout string message); +}; diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerClient.cpp b/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerClient.cpp new file mode 100644 index 00000000000..2fe9f2239fe --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerClient.cpp @@ -0,0 +1,35 @@ +#include "MessengerC.h" +#include <ace/SString.h> +#include <iostream> + + +int ACE_TMAIN (int argc, ACE_TCHAR *argv[]) { + try { + if (argc <= 1) { + std::cerr << "Error: Must specify the name of an IOR file." << std::endl; + return 1; + } + ACE_CString ior = "file://"; + ior += argv[1]; + + CORBA::ORB_var orb = CORBA::ORB_init(argc, argv); + + CORBA::Object_var obj = orb->string_to_object(ior.c_str()); + + Messenger_var messenger = Messenger::_narrow(obj.in()); + if (CORBA::is_nil(messenger.in())) { + std::cerr << "Unable to get 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 << "Reply was : " << message.in() << std::endl; + + return 0; + } catch(const CORBA::Exception& ex) { + std::cerr << "Client main() Caught Exception: " << ex << std::endl; + } + return 1; +} diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerServer.cpp b/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerServer.cpp new file mode 100644 index 00000000000..893ce40442c --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/MessengerServer.cpp @@ -0,0 +1,93 @@ +#include "Messenger_i.h" +#include <tao/PortableServer/Root_POA.h> +#include <tao/IORTable/IORTable.h> +#include <iostream> +#include <fstream> +#include <fstream> + +PortableServer::POA_ptr +createPersistentPOA(PortableServer::POA_ptr root_poa, + const char* poa_name) { + + PortableServer::LifespanPolicy_var life = + root_poa->create_lifespan_policy(PortableServer::PERSISTENT); + + PortableServer::IdAssignmentPolicy_var assign = + root_poa->create_id_assignment_policy(PortableServer::USER_ID); + + CORBA::PolicyList pols; + pols.length(2); + pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in()); + pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in()); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + PortableServer::POA_var poa = + root_poa->create_POA(poa_name, mgr.in(), pols); + + life->destroy(); + assign->destroy(); + + return poa._retn(); +} + +void writeIORFile(const char* ior, const char* name) { + std::ofstream out(name); + out << ior; +} + +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 root_poa = PortableServer::POA::_narrow(obj.in()); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + + const char* poa_name = "MessengerService"; + + PortableServer::POA_var poa = createPersistentPOA(root_poa.in(), poa_name); + + Messenger_i servant1, servant2; + + PortableServer::ObjectId_var id1 = PortableServer::string_to_ObjectId("Object1"); + poa->activate_object_with_id(id1.in(), &servant1); + PortableServer::ObjectId_var id2 = PortableServer::string_to_ObjectId("Object2"); + poa->activate_object_with_id(id2.in(), &servant2); + + obj = poa->id_to_reference(id1.in()); + CORBA::String_var ior1 = orb->object_to_string(obj.in()); + obj = poa->id_to_reference(id2.in()); + CORBA::String_var ior2 = orb->object_to_string(obj.in()); + + TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(poa.in()); + obj = tpoa->id_to_reference_i(id1.in(), false); + CORBA::String_var direct_ior1 = orb->object_to_string(obj.in()); + + obj = orb->resolve_initial_references("IORTable"); + IORTable::Table_var ior_table = IORTable::Table::_narrow(obj.in()); + ior_table->bind("MessengerService/Object1", direct_ior1.in()); + ior_table->bind("MessengerService/Object2", ior2.in()); + + writeIORFile(ior1.in(), "messenger1.ior"); + writeIORFile(ior2.in(), "messenger2.ior"); + + mgr->activate(); + + std::cout << "Messenger server ready." << std::endl; + + orb->run(); + + std::cout << "Messenger server shutting down." << std::endl; + + root_poa->destroy(1,1); + orb->destroy(); + + return 0; + } catch(const CORBA::Exception& ex) { + std::cerr << "Server main() Caught Exception" << ex << std::endl; + } + return 1; +} diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.cpp b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.cpp new file mode 100644 index 00000000000..800d00fc5c0 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.cpp @@ -0,0 +1,17 @@ +#include "Messenger_i.h" +#include <iostream> + + +CORBA::Boolean Messenger_i::send_message( + const char * user_name, + const char * subject, + char *& message) + throw (CORBA::SystemException) +{ + std::cout << "Message from: " << user_name << std::endl + << "Subject: " << subject << std::endl + << "Message: " << message << std::endl; + message = CORBA::string_dup("A reply."); + return 1; +} + diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.h b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.h new file mode 100644 index 00000000000..ec79e9d3d3c --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/Messenger_i.h @@ -0,0 +1,17 @@ +#ifndef MESSENGERI_H_ +#define MESSENGERI_H_ + +#include "MessengerS.h" + +class Messenger_i : public virtual POA_Messenger +{ +public: + virtual CORBA::Boolean send_message ( + const char * user_name, + const char * subject, + char *& message + ) + ACE_THROW_SPEC ((CORBA::SystemException)); +}; + +#endif diff --git a/TAO/DevGuideExamples/ImplRepo/IORTable/run_test.pl b/TAO/DevGuideExamples/ImplRepo/IORTable/run_test.pl new file mode 100644 index 00000000000..6fa9bb20774 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/IORTable/run_test.pl @@ -0,0 +1,129 @@ +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; + +my $WAIT_TIMEOUT = 2; +my $DEBUG_LEVEL = 1; +my $OBJ_REF_STYLE = "-orbobjrefstyle url"; + +my $implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImplRepo_Service"; +my $imr_activator = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImR_Activator"; +my $tao_imr = "$ENV{ACE_ROOT}/bin/tao_imr"; + +my $implrepo_ior = "imr.ior"; +my $activator_ior = "activator.ior"; +my $messenger1_ior = "messenger1.ior"; +my $messenger2_ior = "messenger2.ior"; +my $messenger3_ior = "messenger3.ior"; +my $messenger4_ior = "messenger4.ior"; + +my $imr_init_ref = "-ORBInitRef ImplRepoService=file://$implrepo_ior"; + +my $Svr = new PerlACE::Process('MessengerServer', "-orbuseimr 1 $OBJ_REF_STYLE $imr_init_ref"); +my $Cli = new PerlACE::Process('MessengerClient'); + +sub CleanupOutput { + unlink $messenger1_ior; + unlink $messenger2_ior; + unlink $messenger3_ior; + unlink $messenger4_ior; + unlink $implrepo_ior; + unlink $activator_ior; +} + +sub SpawnWait { + my $process = shift; + my $file = shift; + + print ">>> " . $process->CommandLine() . "\n"; + $process->Spawn(); + my $ret = PerlACE::waitforfile_timed($file, $WAIT_TIMEOUT); + if ($ret == -1) { + print STDERR "ERROR: Cannot find file <$file>\n"; + } + return $ret; +} + +sub SpawnWaitKill { + my $process = shift; + + print ">>> " . $process->CommandLine() . "\n"; + return $process->SpawnWaitKill($WAIT_TIMEOUT); +} + +# Use url object reference style for readability, and startup timeout of 2 seconds. +# Unlike the chapter we'll forgo using -m, because we want to be able to run this +# as a test in our nightly builds, and multicast could interfere with other machines. +my $ImR = new PerlACE::Process ($implrepo_server, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -t 2 -o $implrepo_ior"); +my $Act = new PerlACE::Process ($imr_activator, "-d $DEBUG_LEVEL $OBJ_REF_STYLE -o $activator_ior $imr_init_ref"); + +my $imr_util = new PerlACE::Process ("$tao_imr", + "$imr_init_ref add MessengerService -c \"$Svr->Executable() $OBJ_REF_STYLE -ORBUseIMR 1 $imr_init_ref\""); + +# We want the tao_imr 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. +$imr_util->IgnoreExeSubDir(1); + +sub RunImRUtil { + my $cmd = shift; + print ">>> " . $imr_util->CommandLine() . "\n"; + $imr_util->Arguments("$imr_init_ref $cmd"); + return $imr_util->SpawnWaitKill(5); +} + +CleanupOutput(); + +#### Start the example + +if (SpawnWait($ImR, $implrepo_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +if (SpawnWait($Svr, $messenger2_ior) != 0) { + $ImR->Kill(); + exit 1; +} + +$Cli->Arguments($messenger1_ior); +if (SpawnWaitKill($Cli, $WAIT_TIMEOUT) != 0) { + print STDERR "Error : Client 1 failed to run correctly."; +} + +$Cli->Arguments($messenger2_ior); +if (SpawnWaitKill($Cli, $WAIT_TIMEOUT) != 0) { + print STDERR "Error : Client 2 failed to run correctly."; +} + +#Since we didn't start the ImR with a known endpoint, we'll +#have to use the tao_imr utility to create a our urls. +RunImRUtil("ior MessengerService/Object1 -f $messenger3_ior"); +RunImRUtil("ior MessengerService/Object2 -f $messenger4_ior"); + +$Cli->Arguments($messenger3_ior); +if (SpawnWaitKill($Cli, $WAIT_TIMEOUT) != 0) { + print STDERR "Error : Client 3 failed to run correctly."; +} + +# Notice that this one results in two calls through the ImR, because +# we bound an indirect reference in the IORTable. If we were using +# PER_CLIENT activation, this would be bad. +$Cli->Arguments($messenger4_ior); +if (SpawnWaitKill($Cli, $WAIT_TIMEOUT) != 0) { + print STDERR "Error : Client 4 failed to run correctly."; +} + +$Svr->Kill(); +$ImR->Kill(); + + +#### Clean up any output files + +CleanupOutput(); + +exit 0; diff --git a/TAO/DevGuideExamples/ImplRepo/ImplRepo.mpc b/TAO/DevGuideExamples/ImplRepo/ImplRepo.mpc new file mode 100644 index 00000000000..67e78b8f0c2 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/ImplRepo.mpc @@ -0,0 +1,13 @@ +project(*Server): taoexe, portableserver, iortable, avoids_minimum_corba, avoids_corba_e_micro { + Source_Files { + Messenger_i.cpp + MessengerServer.cpp + } +} + +project(*Client): taoexe, anytypecode, avoids_minimum_corba { + Source_Files { + MessengerC.cpp + MessengerClient.cpp + } +} diff --git a/TAO/DevGuideExamples/ImplRepo/Messenger.idl b/TAO/DevGuideExamples/ImplRepo/Messenger.idl new file mode 100644 index 00000000000..aaedd932648 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/Messenger.idl @@ -0,0 +1,9 @@ +// messenger.idl + +interface Messenger + { + boolean send_message ( in string user_name, + in string subject, + inout string message ); + }; + diff --git a/TAO/DevGuideExamples/ImplRepo/MessengerClient.cpp b/TAO/DevGuideExamples/ImplRepo/MessengerClient.cpp new file mode 100644 index 00000000000..4791f8f3c7c --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/MessengerClient.cpp @@ -0,0 +1,36 @@ + +#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( "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 main() Caught CORBA::Exception: " << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/DevGuideExamples/ImplRepo/MessengerServer.cpp b/TAO/DevGuideExamples/ImplRepo/MessengerServer.cpp new file mode 100644 index 00000000000..6699a412342 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/MessengerServer.cpp @@ -0,0 +1,101 @@ +// MessengerServer.cpp +// This version uses the Implementation Repository. + +#include "Messenger_i.h" +#include <tao/IORTable/IORTable.h> +#include <tao/PortableServer/Root_POA.h> +#include <iostream> + +PortableServer::POA_ptr +createPOA(PortableServer::POA_ptr root_poa, const char* poa_name) +{ + PortableServer::LifespanPolicy_var life = + root_poa->create_lifespan_policy(PortableServer::PERSISTENT); + + PortableServer::IdAssignmentPolicy_var assign = + root_poa->create_id_assignment_policy(PortableServer::USER_ID); + + CORBA::PolicyList pols; + pols.length(2); + pols[0] = PortableServer::LifespanPolicy::_duplicate(life.in()); + pols[1] = PortableServer::IdAssignmentPolicy::_duplicate(assign.in()); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + PortableServer::POA_var poa = + root_poa->create_POA(poa_name, mgr.in(), pols); + + life->destroy(); + assign->destroy(); + + return poa._retn(); +} + +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 root_poa = PortableServer::POA::_narrow(obj.in()); + + PortableServer::POAManager_var mgr = root_poa->the_POAManager(); + + const char* poa_name = "MessengerService"; + + PortableServer::POA_var messenger_poa = createPOA(root_poa.in(), poa_name); + + Messenger_i messenger_servant; + + PortableServer::ObjectId_var object_id = + PortableServer::string_to_ObjectId("messenger_object"); + + // + // Activate the servant with the messenger POA, + // obtain its object reference, and get a + // stringified IOR. + // + messenger_poa->activate_object_with_id(object_id.in(), &messenger_servant); + + // + // Create binding between "MessengerService" and + // the messenger object reference in the IOR Table. + // Use a TAO extension to get the non imrified poa + // to avoid forwarding requests back to the ImR. + + TAO_Root_POA* tpoa = dynamic_cast<TAO_Root_POA*>(messenger_poa.in()); + obj = tpoa->id_to_reference_i(object_id.in(), false); + CORBA::String_var messenger_ior = orb->object_to_string(obj.in()); + obj = orb->resolve_initial_references("IORTable"); + IORTable::Table_var table = IORTable::Table::_narrow(obj.in()); + table->bind(poa_name, messenger_ior.in()); + + // + // This server is now ready to run. + // This version does not create an IOR + // file as demonstrated in the + // Developer's Guide. It assumes that + // users create IORs for the client using + // the tao_imr utility. + // + // + // Stop discarding requests. + // + mgr->activate(); + + std::cout << "Messenger server ready." << std::endl; + + orb->run(); + + std::cout << "Messenger server shutting down." << std::endl; + + root_poa->destroy(1,1); + orb->destroy(); + } + catch(const CORBA::Exception& ex) { + std::cerr << "Server main() Caught CORBA::Exception" << ex << std::endl; + return 1; + } + + return 0; +} diff --git a/TAO/DevGuideExamples/ImplRepo/Messenger_i.cpp b/TAO/DevGuideExamples/ImplRepo/Messenger_i.cpp new file mode 100644 index 00000000000..de1edefd4fa --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/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 + << "Subject: " << subject << std::endl + << "Message: " << message << std::endl; + return 1; +} + diff --git a/TAO/DevGuideExamples/ImplRepo/Messenger_i.h b/TAO/DevGuideExamples/ImplRepo/Messenger_i.h new file mode 100644 index 00000000000..e386c4c71da --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/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/DevGuideExamples/ImplRepo/README b/TAO/DevGuideExamples/ImplRepo/README new file mode 100644 index 00000000000..d255104cc4c --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/README @@ -0,0 +1,28 @@ + +DevGuideExamples/ImplRepo/README + +This directory contains a CORBA example illustrating use of the TAO +Implementation Repository with a simple server (MessengerServer) and +a client (MessengerClient). + +How to Run +---------- + +Start the Implementation Repository (ImplRepo) server: +------------------------------------------------------ +$TAO_ROOT/orbsvcs/ImplRepo_Service/ImplRepo_Service -o implrepo.ior + +Register the server's POA name and start-up command with the ImplRepo: +---------------------------------------------------------------------- +$TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr -ORBInitRef \ + ImplRepoService=file://implrepo.ior add MessengerService \ + -c "MessengerServer -ORBUseIMR 1 -ORBInitRef ImplRepoService=file://implrepo.ior" + +Generate an IMRified Object Reference for the MessengerService: +--------------------------------------------------------------- +$TAO_ROOT/orbsvcs/ImplRepo_Service/tao_imr -ORBInitRef \ + ImplRepoService=file://implrepo.ior ior MessengerService -f Messenger.ior + +Run the client (ImplRepo should automatically start the server): +---------------------------------------------------------------- +./MessengerClient diff --git a/TAO/DevGuideExamples/ImplRepo/run_test.pl b/TAO/DevGuideExamples/ImplRepo/run_test.pl new file mode 100644 index 00000000000..e97deca65b0 --- /dev/null +++ b/TAO/DevGuideExamples/ImplRepo/run_test.pl @@ -0,0 +1,108 @@ +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; + +$implrepo_server = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImplRepo_Service"; +$imr_activator = "$ENV{TAO_ROOT}/orbsvcs/ImplRepo_Service/ImR_Activator"; +$tao_imr = "$ENV{ACE_ROOT}/bin/tao_imr"; + +# Note : We don't actually use SVR, but we need a way to get the +# path to the -ExeSubDir +my $SVR = new PerlACE::Process ('MessengerServer'); +my $server = $SVR->Executable (); + +# The Tests +$implrepo_ior = "implrepo.ior"; +$activator_ior = "activator.ior"; +$messenger_ior = "Messenger.ior"; + +# Make sure the files are gone, so we can wait on them. +unlink $messenger_ior; +unlink $implrepo_ior; +unlink $activator_ior; + +$IR = new PerlACE::Process ($implrepo_server, "-d 1 -orbobjrefstyle url -t 5 -o $implrepo_ior"); +print ">>> " . $IR->CommandLine() . "\n"; +$IR->Spawn(); +if (PerlACE::waitforfile_timed ($implrepo_ior, 10) == -1) { + print STDERR "ERROR: cannot find file <$implrepo_ior>\n"; + $IR->Kill(); + exit 1; +} + +$imr_init_ref = "-ORBInitRef ImplRepoService=file://$implrepo_ior"; + +$ACT = new PerlACE::Process ($imr_activator, "-d 1 -orbobjrefstyle url -o $activator_ior $imr_init_ref"); +print ">>> " . $ACT->CommandLine() . "\n"; +$ACT->Spawn(); +if (PerlACE::waitforfile_timed ($activator_ior, 15) == -1) { + print STDERR "ERROR: cannot find file <$activator_ior>\n"; + $IR->Kill(); + $ACT->Kill(); + exit 1; +} + + +$add_imr = new PerlACE::Process ("$tao_imr", + "$imr_init_ref add MessengerService -c \"$server -orbobjrefstyle url -ORBUseIMR 1 $imr_init_ref\""); +print ">>> " . $add_imr->CommandLine() . "\n"; +# We want the tao_imr 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. + +$add_imr->IgnoreExeSubDir (1); + +## Note : Instead of using tao_imr to generate the ior, it's easy enough +## to just create one by hand. The ior is just a normal corbaloc ior with +## the poa_name of the server and ip address of the imr. +## (ie corbaloc::localhost:8888/Messengerservice) +## Of course, to do this, you'd have to start the imr on port 8888. +## We use the "tao_imr ior" command, because we don't know which port was used. +$add_imr->SpawnWaitKill(10); +$set_ior = new PerlACE::Process ("$tao_imr", + "$imr_init_ref ior MessengerService -f $messenger_ior"); +print ">>> " . $set_ior->CommandLine() . "\n"; +$set_ior->IgnoreExeSubDir (1); +$set_ior->SpawnWaitKill(10); +if (PerlACE::waitforfile_timed ($messenger_ior, 5) == -1) { + print STDERR "ERROR: cannot find file <$messenger_ior>\n"; + $IR->Kill(); + $ACT->Kill(); + exit 1; +} + +$C1 = new PerlACE::Process("MessengerClient"); +print ">>> " . $C1->CommandLine() . "\n"; +if ($C1->SpawnWaitKill(10) != 0) { + print "client 1 timed failed\n"; + $IR->Kill (); + $ACT->Kill(); + exit 1; +} + +$shutdown = new PerlACE::Process ("$tao_imr", + "$imr_init_ref shutdown MessengerService"); +$shutdown->IgnoreExeSubDir (1); +$shutdown->SpawnWaitKill(5); + +$C2 = new PerlACE::Process("MessengerClient"); +if ($C2->SpawnWaitKill(5) != 0) { + $IR->Kill (); + $ACT->Kill(); + exit 1; +} + +$shutdown->SpawnWaitKill(5); + +$IR->Kill(); +$ACT->Kill(); + +unlink $messenger_ior; +unlink $implrepo_ior; +unlink $activator_ior; + +exit 0; |