diff options
author | Abdullah Sowayan <sowayan@users.noreply.github.com> | 2008-10-21 20:47:43 +0000 |
---|---|---|
committer | Abdullah Sowayan <sowayan@users.noreply.github.com> | 2008-10-21 20:47:43 +0000 |
commit | d2911d5b9eb897d3da7d458ebf5ba8b998bc7763 (patch) | |
tree | 3158327d3787df5b439329fac177f20a12857c62 /TAO/DevGuideExamples/BiDirectionalGIOP | |
parent | f8ea2bc5a4d98525f6f290d8272663e46aa1de74 (diff) | |
download | ATCD-d2911d5b9eb897d3da7d458ebf5ba8b998bc7763.tar.gz |
Tue Oct 21 19:10:21 UTC 2008 Abdullah Sowayan <abdullah.sowayan@lmco.com>
Diffstat (limited to 'TAO/DevGuideExamples/BiDirectionalGIOP')
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/BiDirectionalGIOP.mpc | 23 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/README | 27 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.cpp | 1 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.h | 15 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/callback.idl | 10 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.cpp | 26 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.h | 22 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/client.cpp | 101 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/run_test.pl | 39 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/server.cpp | 115 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/simple.idl | 14 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.cpp | 77 | ||||
-rw-r--r-- | TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.h | 46 |
13 files changed, 516 insertions, 0 deletions
diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/BiDirectionalGIOP.mpc b/TAO/DevGuideExamples/BiDirectionalGIOP/BiDirectionalGIOP.mpc new file mode 100644 index 00000000000..d75d57f1c56 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/BiDirectionalGIOP.mpc @@ -0,0 +1,23 @@ +project(*Server): taoexe, portableserver, avoids_minimum_corba, bidir_giop, avoids_corba_e_micro { + exename = server + idlflags += -Wb,pch_include=bidir_giop_pch.h + Source_Files { + callbackC.cpp + simpleC.cpp + simpleS.cpp + simple_i.cpp + server.cpp + } +} + +project(*Client): taoexe, portableserver, avoids_minimum_corba, bidir_giop, avoids_corba_e_micro { + exename = client + idlflags += -Wb,pch_include=bidir_giop_pch.h + Source_Files { + simpleC.cpp + callbackC.cpp + callbackS.cpp + callback_i.cpp + client.cpp + } +} diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/README b/TAO/DevGuideExamples/BiDirectionalGIOP/README new file mode 100644 index 00000000000..6314e1cd301 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/README @@ -0,0 +1,27 @@ +This example is a copy of the $TAO_ROOT/test/BiDirerectional test +but it does not use ACE_TRY/ENVIRONMENT macros. + +This example exercises the birectional GIOP connection +implementation in TAO. + +Start like this: + +$ server -o <file.ior> -i <no_iterations> +$ client -k file://<file.ior> + +The server starts up writing the IOR to the file. The client then +starts up, creates its own object and passes the reference to the +server. Then it invokes a method on the server to indicate that it is +ready for callback. The server then callsback the client on the same +connection <no_iterations> times. If the server creates a new +connection the server will crash itself. + +Each time the client recieves a callback, it outputs: +Callback method called. + + + + + + + diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.cpp b/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.cpp new file mode 100644 index 00000000000..570337d5803 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.cpp @@ -0,0 +1 @@ +#include "bidir_giop_pch.h" diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.h b/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.h new file mode 100644 index 00000000000..cc3b7dd664f --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/bidir_giop_pch.h @@ -0,0 +1,15 @@ +#ifndef BIDIR_GIOP_PCH_H +#define BIDIR_GIOP_PCH_H + +// See the Devguide chapter on Getting Started With Visual C++ for +// more information on how to correctly use precompiled headers. +// Currently only Windows VC++ defines USING_PCH so this file +// is effectively empty for other platforms. + +#ifdef USING_PCH +#include "tao/corba.h" +#include "tao/ORB_Core.h" +#include "tao/Stub.h" +#endif + +#endif diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/callback.idl b/TAO/DevGuideExamples/BiDirectionalGIOP/callback.idl new file mode 100644 index 00000000000..ddb989750a2 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/callback.idl @@ -0,0 +1,10 @@ +interface Callback +{ + // A safe way to shutdown the client, using either clean shutdowns + // or "catastrophic failures". + oneway void shutdown(); + + // A simple remote call + void callback_method(); +}; + diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.cpp b/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.cpp new file mode 100644 index 00000000000..cc4d9d3977b --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.cpp @@ -0,0 +1,26 @@ +#include "bidir_giop_pch.h" + +#include "callback_i.h" +#include <iostream> + +Callback_i::Callback_i (CORBA::ORB_ptr orb) +: orb_(CORBA::ORB::_duplicate(orb)) +{ +} + +Callback_i::~Callback_i (void) +{ +} + +void Callback_i::shutdown () +{ + std::cout << "Performing clean shutdown." << std::endl; + const int wait = 0; + orb_->shutdown(wait); +} + +void Callback_i::callback_method () +{ + std::cout << "Callback method called." << std::endl; +} + diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.h b/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.h new file mode 100644 index 00000000000..dc70a79ed39 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/callback_i.h @@ -0,0 +1,22 @@ +#ifndef CALLBACKI_H_ +#define CALLBACKI_H_ + +#include "callbackS.h" + +class Callback_i : public virtual POA_Callback +{ +public: + Callback_i (CORBA::ORB_ptr orb); + + virtual ~Callback_i (void); + + virtual void shutdown (void); + + virtual void callback_method (void); + +private: + CORBA::ORB_var orb_; +}; + + +#endif /* CALLBACKI_H_ */ diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/client.cpp b/TAO/DevGuideExamples/BiDirectionalGIOP/client.cpp new file mode 100644 index 00000000000..d935c5e1b5e --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/client.cpp @@ -0,0 +1,101 @@ +#include "bidir_giop_pch.h" + +#include "callback_i.h" +#include "simpleC.h" + +#include <ace/Get_Opt.h> +#include <ace/Argv_Type_Converter.h> +#include <tao/BiDir_GIOP/BiDirGIOP.h> + +#include <iostream> + +ACE_TString ior = ACE_TEXT ("file://test.ior"); + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior = get_opts.optarg; + break; + + case '?': + default: + std::cerr << "usage: " << argv[0] << " -k <ior>" << std::endl; + return -1; + break; + } + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + + if (parse_args (argc, argv) != 0) { + return 1; + } + + try { + ACE_Argv_Type_Converter conv(argc, argv); + CORBA::ORB_var orb = CORBA::ORB_init(conv.get_argc(), + conv.get_TCHAR_argv (), ""); + + // Create a bidirectional POA + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); + // Policies for the childPOA to be created. + CORBA::PolicyList policies(1); + policies.length(1); + CORBA::Any pol; + pol <<= BiDirPolicy::BOTH; + policies[0] = + orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); + // Create POA as child of RootPOA with the above policies. This POA + // will receive request in the same connection in which it sent + // the request + PortableServer::POA_var poa = root_poa->create_POA("bidirPOA", poa_manager.in(), policies); + // Creation of bidirPOA is over. Destroy the Policy objects. + for (CORBA::ULong i = 0; i < policies.length (); ++i) { + policies[i]->destroy (); + } + poa_manager->activate (); + + // get server object + obj = orb->string_to_object(ACE_TEXT_ALWAYS_CHAR(ior.c_str())); + Simple_var server = Simple::_narrow (obj.in()); + + Callback_i callback_svt(orb.in()); + + // Register and activate callback servant + PortableServer::ObjectId_var id = poa->activate_object(&callback_svt); + obj = poa->id_to_reference(id.in()); + Callback_var callback = Callback::_narrow(obj.in()); + + server->callback_object (callback.in()); + + CORBA::Long r = server->test_method(1); // Tell the server to call us back. + if (r != 0) { + std::cout << "unexpected result = " << r << std::endl; + } + + orb->run(); + + int etherealize = 1, wait = 1; + poa->destroy(etherealize, wait); + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught CORBA::Exception: " << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/run_test.pl b/TAO/DevGuideExamples/BiDirectionalGIOP/run_test.pl new file mode 100644 index 00000000000..f126f2865ef --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/run_test.pl @@ -0,0 +1,39 @@ +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 = "test.ior"; +unlink $iorfile; + +$SV = new PerlACE::Process ("server", "-o $iorfile -i 100"); +$CL = new PerlACE::Process ("client", "-k file://$iorfile"); + +$SV->Spawn (); + +if (PerlACE::waitforfile_timed ($iorfile, 5) == -1) { + print STDERR "ERROR: cannot find file <$iorfile>\n"; + $SV->Kill (); + exit 1; +} + +$status = 0; + +$client = $CL->SpawnWaitKill (15); +if ($client != 0) { + print STDERR "ERROR: client returned $client\n"; + $status = 1; +} + +$server = $SV->WaitKill (5); +if ($server != 0) { + print STDERR "ERROR: server returned $server\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/server.cpp b/TAO/DevGuideExamples/BiDirectionalGIOP/server.cpp new file mode 100644 index 00000000000..a9af3367bfa --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/server.cpp @@ -0,0 +1,115 @@ +#include "bidir_giop_pch.h" + +#include "simple_i.h" +#include "callbackC.h" + +#include <ace/Get_Opt.h> +#include <ace/Argv_Type_Converter.h> +#include <tao/BiDir_GIOP/BiDirGIOP.h> +#include <iostream> +#include <fstream> + +ACE_TString ior_output_file; +int callback_count = 10; + +int +parse_args(int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts(argc, argv, ACE_TEXT("o:i:")); + int c; + + while((c = get_opts()) != -1) + switch(c) + { + case 'o': + ior_output_file = get_opts.optarg; + break; + case 'i': + callback_count = ACE_OS::atoi(get_opts.optarg); + break; + case '?': + default: + std::cerr << "usage: " << argv[0] << "-o <iorfile> -i <no_iterations>" << std::endl; + return -1; + break; + } + // Indicates sucessful parsing of the command line + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + if (parse_args(argc, argv) != 0) { + return 1; + } + + try + { + ACE_Argv_Type_Converter conv(argc, argv); + CORBA::ORB_var orb = CORBA::ORB_init(conv.get_argc(), + conv.get_TCHAR_argv(), ""); + + // Create a bidirectional POA + CORBA::Object_var obj = orb->resolve_initial_references("RootPOA"); + PortableServer::POA_var root_poa = PortableServer::POA::_narrow(obj.in()); + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager(); + // Policies for the childPOA to be created. + CORBA::PolicyList policies(1); + policies.length(1); + CORBA::Any pol; + pol <<= BiDirPolicy::BOTH; + policies[0] = + orb->create_policy(BiDirPolicy::BIDIRECTIONAL_POLICY_TYPE, pol); + // Create POA as child of RootPOA with the above policies. This POA + // will receive request in the same connection in which it sent + // the request + PortableServer::POA_var poa = root_poa->create_POA("bidirPOA", poa_manager.in(), policies); + // Creation of bidirPOA is over. Destroy the Policy objects. + for (CORBA::ULong i = 0; i < policies.length (); ++i) { + policies[i]->destroy (); + } + poa_manager->activate (); + + Simple_i svt(orb.in(), callback_count); + + // Register and activate Simple servant + PortableServer::ObjectId_var id = poa->activate_object(&svt); + obj = poa->id_to_reference(id.in()); + Simple_var server = Simple::_narrow(obj.in()); + + CORBA::String_var ior = orb->object_to_string(server.in()); + if (ior_output_file != ACE_TEXT("")) { + std::ofstream outfile(ACE_TEXT_ALWAYS_CHAR(ior_output_file.c_str())); + outfile << ior.in(); + } + std::cout << "Activated as " << ior.in() << std::endl; + + // Our own special orb->run() that knows how to callback clients + while (true) { + + // returns 1 as soon as it has successfully called back. + if (svt.call_client()) { + break; + } + + // We don't want to check for work pending, because we really want + // to simulate a normal orb->run() while adding the ability to call + // our routine which calls back to the client. + orb->perform_work(); + } + + std::cout << "Event loop finished." << std::endl; + + int etherealize = 1, wait = 1; + poa->destroy(etherealize, wait); + orb->destroy(); + + return 0; + } + catch(const CORBA::Exception& ex) { + std::cerr << "Caught CORBA::Exception: " << std::endl << ex << std::endl; + } + + return 1; +} diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/simple.idl b/TAO/DevGuideExamples/BiDirectionalGIOP/simple.idl new file mode 100644 index 00000000000..e6ef4fffa86 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/simple.idl @@ -0,0 +1,14 @@ +#include "callback.idl" + +interface Simple +{ + // Just call a method on the server, + long test_method(in boolean do_callback); + + // send the callback object to the server + void callback_object(in Callback cb); + + // A safe way to shutdown the server, it is a oneway function so we + // will never get a COMM_FAILURE error + oneway void shutdown(); +}; diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.cpp b/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.cpp new file mode 100644 index 00000000000..be05be761e9 --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.cpp @@ -0,0 +1,77 @@ +#include "bidir_giop_pch.h" + +#include "simple_i.h" + +#include <tao/ORB_Core.h> +#include <tao/Transport_Cache_Manager.h> +#include <tao/Thread_Lane_Resources.h> + +#include <iostream> + +Simple_i::Simple_i (CORBA::ORB_ptr orb, int callback_count) +: orb_(CORBA::ORB::_duplicate(orb)) +, ready_for_callback_(0) +, callback_count_(callback_count) +, callback_(0) +{ +} + +Simple_i::~Simple_i (void) +{ +} + +CORBA::Long Simple_i::test_method (CORBA::Boolean do_callback) +ACE_THROW_SPEC (( + CORBA::SystemException +)) +{ + if (do_callback) { + ready_for_callback_ = 1; + } + return 0; +} + +void Simple_i::callback_object (Callback_ptr cb) +ACE_THROW_SPEC (( + CORBA::SystemException +)) +{ + callback_ = Callback::_duplicate(cb); +} + +void Simple_i::shutdown () +ACE_THROW_SPEC (( + CORBA::SystemException +)) +{ + const int wait = 0; + orb_->shutdown(wait); +} + +int +Simple_i::call_client() +{ + if (ready_for_callback_) { + + ready_for_callback_ = 0; + + for (int times = 0; times < callback_count_; ++times) { + + callback_->callback_method(); + + if (orb_->orb_core()->lane_resources().transport_cache().current_size() > 1) + { + std::cerr << "The connection cache has grown. " + << "BiDirection did not work. aborting..." << std::endl; + ACE_OS::abort(); // Should probably define and throw a UserException + } + } + + callback_->shutdown(); + + return 1; + } + + return 0; +} + diff --git a/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.h b/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.h new file mode 100644 index 00000000000..feb107e351f --- /dev/null +++ b/TAO/DevGuideExamples/BiDirectionalGIOP/simple_i.h @@ -0,0 +1,46 @@ +#ifndef SIMPLEI_H_ +#define SIMPLEI_H_ + +#include "simpleS.h" + +class Simple_i : public virtual POA_Simple +{ +public: + Simple_i (CORBA::ORB_ptr orb, int iterations); + + virtual ~Simple_i (void); + +virtual CORBA::Long test_method ( + CORBA::Boolean do_callback + ) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + +virtual void callback_object ( + Callback_ptr cb + ) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + +virtual void shutdown ( + + ) + ACE_THROW_SPEC (( + CORBA::SystemException + )); + + /// Not part of the CORBA interface. This method is called + /// by our special orb event loop in server main(). + int call_client(); + +private: + CORBA::ORB_var orb_; + int ready_for_callback_; + int callback_count_; + Callback_var callback_; +}; + + +#endif /* SIMPLEI_H_ */ |