summaryrefslogtreecommitdiff
path: root/TAO/tests/Mixed_Sync_ASync_Events
diff options
context:
space:
mode:
authormcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2011-11-11 11:24:51 +0000
committermcorino <mcorino@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2011-11-11 11:24:51 +0000
commit9b3f4b6f409cf7ed6e6f0121be975586be76bd56 (patch)
treec7ef2d6305f7766c4614a81c9e837363480d1880 /TAO/tests/Mixed_Sync_ASync_Events
parent40d36e28446e7f60c95f243bda6fa51c47e6d0fb (diff)
downloadATCD-9b3f4b6f409cf7ed6e6f0121be975586be76bd56.tar.gz
Wed Nov 9 08:24:29 UTC 2011 Martin Corino <mcorino@remedy.nl>
* tests/Mixed_Sync_ASync_Events/MixedSyncASyncEvents.mpc: * tests/Mixed_Sync_ASync_Events/main.cpp: * tests/Mixed_Sync_ASync_Events/run_test.pl: * tests/Mixed_Sync_ASync_Events/test.idl: * tests/Mixed_Sync_ASync_Events/test_i.cpp: * tests/Mixed_Sync_ASync_Events/test_i.h: Added new regression test mixing Synch requests with Asynch (AMI) and timer and notification events in a (semi) random order. * tests/Mixed_Sync_ASync_Events/exclusive_rw.conf: * tests/Mixed_Sync_ASync_Events/exclusive_rw.conf.xml: * tests/Mixed_Sync_ASync_Events/run_exclusive_rw.pl: Config and script to run the new test in full blocking mode (RW, Exclusive TMS, blocking connect and flushing). * bin/tao_orb_tests.lst: Added new regression tests.
Diffstat (limited to 'TAO/tests/Mixed_Sync_ASync_Events')
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/MixedSyncASyncEvents.mpc23
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf4
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf.xml9
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/main.cpp186
-rwxr-xr-xTAO/tests/Mixed_Sync_ASync_Events/run_exclusive_rw.pl122
-rwxr-xr-xTAO/tests/Mixed_Sync_ASync_Events/run_test.pl110
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/test.idl42
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/test_i.cpp265
-rw-r--r--TAO/tests/Mixed_Sync_ASync_Events/test_i.h125
9 files changed, 886 insertions, 0 deletions
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/MixedSyncASyncEvents.mpc b/TAO/tests/Mixed_Sync_ASync_Events/MixedSyncASyncEvents.mpc
new file mode 100644
index 00000000000..6b827c26acc
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/MixedSyncASyncEvents.mpc
@@ -0,0 +1,23 @@
+// -*- MPC -*-
+// $Id $
+
+project(*idl): taoidldefaults, ami {
+ IDL_Files {
+ test.idl
+ }
+ custom_only = 1
+}
+
+project(*Exe): taoserver, messaging, ami {
+ exename = tester
+ after += *idl
+ Source_Files {
+ test_i.cpp
+ testS.cpp
+ testC.cpp
+ main.cpp
+ }
+ IDL_Files {
+ }
+}
+
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf b/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf
new file mode 100644
index 00000000000..d7ed9ec9d14
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf
@@ -0,0 +1,4 @@
+# $Id$
+
+static Client_Strategy_Factory "-ORBTransportMuxStrategy EXCLUSIVE -ORBClientConnectionHandler RW -ORBConnectStrategy blocked"
+static Resource_Factory "-ORBFlushingStrategy blocking"
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf.xml b/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf.xml
new file mode 100644
index 00000000000..d9fdac7d3ae
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/exclusive_rw.conf.xml
@@ -0,0 +1,9 @@
+<?xml version='1.0'?>
+<!-- Converted from ./tests/AMI/exclusive.conf by svcconf-convert.pl -->
+<ACE_Svc_Conf>
+ <!-- -->
+ <!-- $Id$ -->
+ <!-- -->
+ <static id="Client_Strategy_Factory" params="-ORBTransportMuxStrategy EXCLUSIVE -ORBclientconnectionhandler RW -ORBConnectStrategy blocked"/>
+ <static id="Resource_Factory" params="-ORBFlushingStrategy blocking"/>
+</ACE_Svc_Conf>
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/main.cpp b/TAO/tests/Mixed_Sync_ASync_Events/main.cpp
new file mode 100644
index 00000000000..1800ee8cac2
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/main.cpp
@@ -0,0 +1,186 @@
+
+//=============================================================================
+/**
+ * @file server.cpp
+ *
+ * $Id$
+ *
+ * Implementation of the server.
+ *
+ *
+ * @author Alexander Babu Arulanthu <alex@cs.wustl.edu>
+ * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
+ */
+//=============================================================================
+
+
+#include "test_i.h"
+#include "tao/debug.h"
+#include "ace/OS_NS_stdio.h"
+#include "ace/Get_Opt.h"
+
+const ACE_TCHAR *ior_output_file = 0;
+const ACE_TCHAR *input_ior = 0;
+A::RunMode mode_flag = A::SLAVE;
+CORBA::ULong max_count = 20;
+
+int
+parse_args (int argc, ACE_TCHAR *argv[])
+{
+ ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("o:k:c:dm"));
+ int c;
+
+ while ((c = get_opts ()) != -1)
+ switch (c)
+ {
+ case 'o':
+ ior_output_file = get_opts.opt_arg ();
+ break;
+ case 'k':
+ input_ior = get_opts.opt_arg ();
+ break;
+ case 'm':
+ mode_flag = A::MASTER;
+ if (ior_output_file == 0)
+ ior_output_file = ACE_TEXT ("master.ior");
+ break;
+ case 'c':
+ max_count = ACE_OS::atoi (get_opts.opt_arg ());
+ break;
+ case 'd':
+ TAO_debug_level++;
+ break;
+ case '?':
+ default:
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "usage: %s "
+ "-o <iorfile>"
+ "\n",
+ argv [0]),
+ -1);
+ break;
+ }
+
+ if (ior_output_file == 0)
+ ior_output_file = "slave.ior";
+
+ if (input_ior == 0)
+ input_ior = (mode_flag == A::SLAVE ? ACE_TEXT ("file://master.ior") : ACE_TEXT ("file://slave.ior"));
+
+ // Indicates successful 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 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 ();
+
+ if (parse_args (argc, argv) != 0)
+ return 1;
+
+ // create, activate and initialize AMI reply handler
+ Test_Reply_i test_i_rh_srv(orb.in (),
+ max_count,
+ mode_flag);
+ PortableServer::ObjectId_var id =
+ root_poa->activate_object (&test_i_rh_srv);
+
+ CORBA::Object_var object = root_poa->id_to_reference (id.in ());
+
+ A::AMI_TestHandler_var rh =
+ A::AMI_TestHandler::_narrow (object.in ());
+
+ test_i_rh_srv.test_handler ().set_reply_handler (rh.in ());
+
+ // create and activate test servant
+ Test_i test_i_srv (orb.in (), rh.in (), max_count, mode_flag);
+
+ id = root_poa->activate_object (&test_i_srv);
+
+ object = root_poa->id_to_reference (id.in ());
+
+ A::Test_var test_var =
+ A::Test::_narrow (object.in ());
+
+ CORBA::String_var ior =
+ orb->object_to_string (test_var.in ());
+
+ ACE_DEBUG ((LM_DEBUG, "Servant activated\n"));
+
+ // If the ior_output_file exists, output the ior to it
+ if (ior_output_file != 0)
+ {
+ FILE *output_file= ACE_OS::fopen (ior_output_file, "w");
+ if (output_file == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot open output file for writing IOR: %s",
+ ior_output_file),
+ 1);
+ ACE_OS::fprintf (output_file, "%s", ior.in ());
+ ACE_OS::fclose (output_file);
+ }
+
+ poa_manager->activate ();
+
+ A::Test_var opponent;
+ do {
+ if (mode_flag == A::SLAVE)
+ ACE_OS::sleep (ACE_Time_Value (0, 100));
+
+ // get object reference for opponent
+ object = orb->string_to_object (input_ior);
+ opponent = A::Test::_narrow (object.in ());
+ } while (mode_flag == A::SLAVE && CORBA::is_nil (opponent));
+
+ if (CORBA::is_nil (opponent))
+ {
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Cannot resolve opponent IOR: %s",
+ input_ior),
+ 1);
+ }
+
+ // register opponent
+ test_i_srv.set_opponent (opponent.in ());
+ test_i_rh_srv.test_handler ().set_opponent (opponent.in ());
+
+ // start the show
+ if (mode_flag == A::MASTER)
+ test_i_rh_srv.test_handler ().start ();
+
+ orb->run ();
+
+ root_poa->destroy (1, // ethernalize objects
+ 0 // wait for completion
+ );
+
+ orb->destroy ();
+
+ ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
+ }
+ catch (const CORBA::Exception& ex)
+ {
+ ex._tao_print_exception ("Caught exception:");
+ return 1;
+ }
+
+ return 0;
+}
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/run_exclusive_rw.pl b/TAO/tests/Mixed_Sync_ASync_Events/run_exclusive_rw.pl
new file mode 100755
index 00000000000..04c2c4777d9
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/run_exclusive_rw.pl
@@ -0,0 +1,122 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib "$ENV{ACE_ROOT}/bin";
+use PerlACE::TestTarget;
+
+my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
+my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
+
+$client_conf_base = "exclusive_rw$PerlACE::svcconf_ext";
+$client_conf = $client->LocalFile ($client_conf_base);
+if ($client->PutFile ($client_conf_base) == -1) {
+ print STDERR "ERROR: cannot set file <$client_conf>\n";
+ exit 1;
+}
+$server_conf = $server->LocalFile ($client_conf_base);
+if ($server->PutFile ($client_conf_base) == -1) {
+ print STDERR "ERROR: cannot set file <$server_conf>\n";
+ exit 1;
+}
+
+$server_debug_level = '0';
+$client_debug_level = '0';
+
+foreach $i (@ARGV) {
+ if ($i eq '-debug') {
+ $server_debug_level = '10';
+ $client_debug_level = '10';
+ }
+}
+
+my $iorbase_master = "master.ior";
+my $iorbase_slave = "slave.ior";
+my $server_master_iorfile = $server->LocalFile ($iorbase_master);
+my $server_slave_iorfile = $server->LocalFile ($iorbase_slave);
+my $client_master_iorfile = $client->LocalFile ($iorbase_master);
+my $client_slave_iorfile = $client->LocalFile ($iorbase_slave);
+$server->DeleteFile($iorbase_master);
+$server->DeleteFile($iorbase_slave);
+$client->DeleteFile($iorbase_master);
+$client->DeleteFile($iorbase_slave);
+
+$SV = $server->CreateProcess ("tester", "-ORBsvcconf $server_conf -ORBdebuglevel $server_debug_level -o $server_slave_iorfile -k file://$server_master_iorfile");
+
+$server_status = $SV->Spawn ();
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ exit 1;
+}
+
+if ($server->WaitForFileTimed ($iorbase_slave,
+ $server->ProcessStartWaitInterval()) == -1) {
+ print STDERR "ERROR: cannot find file <$server_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+if ($server->GetFile ($iorbase_slave) == -1) {
+ print STDERR "ERROR: cannot get file <$server_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+if ($client->PutFile ($iorbase_slave) == -1) {
+ print STDERR "ERROR: cannot set file <$client_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$CL = $client->CreateProcess ("tester",
+ "-ORBsvcconf $client_conf "
+ . "-ORBdebuglevel $client_debug_level"
+ . " -o $client_master_iorfile"
+ . " -m -k file://$client_slave_iorfile ");
+
+$client_status = $CL->Spawn ();
+
+if ($client_status != 0) {
+ print STDERR "ERROR: client returned $client_status\n";
+ $status = 1;
+}
+
+if ($client->WaitForFileTimed ($iorbase_master,
+ $client->ProcessStartWaitInterval()) == -1) {
+ print STDERR "ERROR: cannot find file <$client_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+if ($client->GetFile ($iorbase_master) == -1) {
+ print STDERR "ERROR: cannot get file <$client_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+if ($server->PutFile ($iorbase_master) == -1) {
+ print STDERR "ERROR: cannot set file <$server_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+
+$client_status = $CL->WaitKill ($client->ProcessStartWaitInterval());
+
+if ($client_status != 0) {
+ print STDERR "ERROR: client returned $client_status\n";
+ $status = 1;
+}
+
+$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ $status = 1;
+}
+
+$server->DeleteFile($iorbase_master);
+$server->DeleteFile($iorbase_slave);
+$client->DeleteFile($iorbase_master);
+$client->DeleteFile($iorbase_slave);
+
+exit $status;
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/run_test.pl b/TAO/tests/Mixed_Sync_ASync_Events/run_test.pl
new file mode 100755
index 00000000000..6e5b4b10765
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/run_test.pl
@@ -0,0 +1,110 @@
+eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
+ & eval 'exec perl -S $0 $argv:q'
+ if 0;
+
+# $Id$
+# -*- perl -*-
+
+use lib "$ENV{ACE_ROOT}/bin";
+use PerlACE::TestTarget;
+
+my $server = PerlACE::TestTarget::create_target (1) || die "Create target 1 failed\n";
+my $client = PerlACE::TestTarget::create_target (2) || die "Create target 2 failed\n";
+
+
+$server_debug_level = '0';
+$client_debug_level = '0';
+
+foreach $i (@ARGV) {
+ if ($i eq '-debug') {
+ $server_debug_level = '10';
+ $client_debug_level = '10';
+ }
+}
+
+my $iorbase_master = "master.ior";
+my $iorbase_slave = "slave.ior";
+my $server_master_iorfile = $server->LocalFile ($iorbase_master);
+my $server_slave_iorfile = $server->LocalFile ($iorbase_slave);
+my $client_master_iorfile = $client->LocalFile ($iorbase_master);
+my $client_slave_iorfile = $client->LocalFile ($iorbase_slave);
+$server->DeleteFile($iorbase_master);
+$server->DeleteFile($iorbase_slave);
+$client->DeleteFile($iorbase_master);
+$client->DeleteFile($iorbase_slave);
+
+$SV = $server->CreateProcess ("tester", "-ORBdebuglevel $server_debug_level -o $server_slave_iorfile -k file://$server_master_iorfile");
+
+$server_status = $SV->Spawn ();
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ exit 1;
+}
+
+if ($server->WaitForFileTimed ($iorbase_slave,
+ $server->ProcessStartWaitInterval()) == -1) {
+ print STDERR "ERROR: cannot find file <$server_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+if ($server->GetFile ($iorbase_slave) == -1) {
+ print STDERR "ERROR: cannot get file <$server_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+if ($client->PutFile ($iorbase_slave) == -1) {
+ print STDERR "ERROR: cannot set file <$client_slave_iorfile>\n";
+ $SV->Kill (); $SV->TimedWait (1);
+ exit 1;
+}
+
+$CL = $client->CreateProcess ("tester",
+ "-ORBdebuglevel $client_debug_level"
+ . " -o $client_master_iorfile"
+ . " -m -k file://$client_slave_iorfile ");
+
+$client_status = $CL->Spawn ();
+
+if ($client_status != 0) {
+ print STDERR "ERROR: client returned $client_status\n";
+ $status = 1;
+}
+
+if ($client->WaitForFileTimed ($iorbase_master,
+ $client->ProcessStartWaitInterval()) == -1) {
+ print STDERR "ERROR: cannot find file <$client_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+if ($client->GetFile ($iorbase_master) == -1) {
+ print STDERR "ERROR: cannot get file <$client_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+if ($server->PutFile ($iorbase_master) == -1) {
+ print STDERR "ERROR: cannot set file <$server_master_iorfile>\n";
+ $CL->Kill (); $CL->TimedWait (1);
+ exit 1;
+}
+
+$client_status = $CL->WaitKill ($client->ProcessStartWaitInterval());
+
+if ($client_status != 0) {
+ print STDERR "ERROR: client returned $client_status\n";
+ $status = 1;
+}
+
+$server_status = $SV->WaitKill ($server->ProcessStopWaitInterval());
+
+if ($server_status != 0) {
+ print STDERR "ERROR: server returned $server_status\n";
+ $status = 1;
+}
+
+$server->DeleteFile($iorbase_master);
+$server->DeleteFile($iorbase_slave);
+$client->DeleteFile($iorbase_master);
+$client->DeleteFile($iorbase_slave);
+
+exit $status;
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/test.idl b/TAO/tests/Mixed_Sync_ASync_Events/test.idl
new file mode 100644
index 00000000000..5402d100461
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/test.idl
@@ -0,0 +1,42 @@
+
+//=============================================================================
+/**
+ * @file test.idl
+ *
+ * $Id $
+ *
+ * IDL description of the Test interface
+ *
+ * @author Martin Corino <mcorino@remedy.nl>
+ */
+//=============================================================================
+
+module A
+ {
+ enum RunMode
+ {
+ SLAVE,
+ MASTER
+ };
+
+ enum RequestMode
+ {
+ SYNCH,
+ ASYNCH
+ };
+
+ enum FollowUp
+ {
+ TIMER,
+ NOTIFICATION
+ };
+
+ interface Test
+ {
+ void request (in RequestMode mode, inout unsigned long counter, out FollowUp follow_up);
+
+ void report (in string msg);
+
+ oneway void shutdown ();
+ };
+ };
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/test_i.cpp b/TAO/tests/Mixed_Sync_ASync_Events/test_i.cpp
new file mode 100644
index 00000000000..b058896accd
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/test_i.cpp
@@ -0,0 +1,265 @@
+
+//=============================================================================
+/**
+ * @file test_i.cpp
+ *
+ * $Id $
+ *
+ * Implementation of the Test interface.
+ *
+ */
+//=============================================================================
+
+#include "test_i.h"
+#include "tao/debug.h"
+#include "tao/ORB_Core.h"
+#include "ace/Reactor.h"
+#include "ace/OS_NS_time.h"
+
+Test_i::Test_i (CORBA::ORB_ptr orb,
+ A::AMI_TestHandler_ptr rh,
+ CORBA::ULong max_count,
+ A::RunMode mode)
+ : orb_ (CORBA::ORB::_duplicate (orb)),
+ rh_ (A::AMI_TestHandler::_duplicate (rh)),
+ max_count_ (max_count),
+ mode_(mode)
+{
+ this->seed_ = ACE_OS::time ();
+}
+
+void
+Test_i::set_opponent (A::Test_ptr opp)
+{
+ this->opponent_ = A::Test::_duplicate (opp);
+}
+
+void
+Test_i::request (
+ ::A::RequestMode reqmode,
+ ::CORBA::ULong & counter,
+ ::A::FollowUp_out follow_up)
+{
+ ++counter;
+
+ ACE_DEBUG ((LM_DEBUG,
+ "%N:%l:(%P:%t):Test_i::request: (%C) %C - %d\n",
+ (reqmode == A::SYNCH ? "SYNCH" : "ASYNCH"),
+ (this->mode_ == A::MASTER ? "master" : "slave"),
+ counter));
+
+ const char* follow_up_str;
+ switch (ACE_OS::rand_r (static_cast<unsigned int*> (&this->seed_)) % 2)
+ {
+ case 0:
+ follow_up = (reqmode == A::SYNCH ? A::TIMER : A::NOTIFICATION);
+ follow_up_str = (reqmode == A::SYNCH ? "TIMER" : "NOTIFICATION");
+ break;
+ case 1:
+ default:
+ follow_up = (reqmode == A::ASYNCH ? A::TIMER : A::NOTIFICATION);
+ follow_up_str = (reqmode == A::ASYNCH ? "TIMER" : "NOTIFICATION");
+ break;
+ }
+
+ if (!CORBA::is_nil(this->opponent_))
+ {
+ char buf[1024];
+ ACE_OS::snprintf (buf, sizeof(buf), "request #%d followup [%s]", counter, follow_up_str);
+
+ if (reqmode == A::SYNCH)
+ {
+ if (!CORBA::is_nil (this->rh_))
+ this->opponent_->sendc_report(this->rh_.in (), buf);
+ }
+ else
+ {
+ this->opponent_->report (buf);
+ }
+ }
+}
+
+void
+Test_i::report (
+ const char * msg)
+{
+ ACE_DEBUG ((LM_DEBUG,
+ "%N:%l:(%P:%t):Test_i::report: %C - %C\n",
+ (this->mode_ == A::MASTER ? "master" : "slave"),
+ msg));
+}
+
+void
+Test_i::shutdown (void)
+{
+ if (this->mode_ == A::SLAVE && !CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->shutdown ();
+ }
+ this->orb_->shutdown (0);
+}
+
+Test_Reply_i::Test_Reply_i (CORBA::ORB_ptr orb,
+ CORBA::ULong max_count,
+ A::RunMode mode)
+ : evh_ (orb, max_count, mode)
+{
+}
+
+void
+Test_Reply_i::request (
+ ::CORBA::ULong counter,
+ ::A::FollowUp follow_up)
+{
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "%N:%l:(%P:%t):Test_Reply_i::request\n"));
+
+ this->evh_.handle_followup (follow_up, counter);
+}
+
+void Test_Reply_i::request_excep (
+ ::Messaging::ExceptionHolder * )
+{
+ ACE_DEBUG ((LM_ERROR,
+ "%N:%l:(%P:%t):Test_Reply_i::request_excep: %C - unexpected exception\n",
+ (this->evh_.mode () == A::MASTER ? "master" : "slave")));
+ if (!CORBA::is_nil (this->evh_.opponent ()))
+ this->evh_.opponent ()->shutdown ();
+ if (this->evh_.mode () == A::SLAVE)
+ this->evh_.orb ()->shutdown (0);
+}
+
+void
+Test_Reply_i::report (
+ void)
+{
+ if (TAO_debug_level > 0)
+ ACE_DEBUG ((LM_DEBUG,
+ "%N:%l:(%P:%t):Test_Reply_i::report\n"));
+}
+
+void
+Test_Reply_i::report_excep (
+ ::Messaging::ExceptionHolder * )
+{
+ ACE_DEBUG ((LM_ERROR,
+ "%N:%l:(%P:%t):Test_Reply_i::report_excep: %C - unexpected exception\n",
+ (this->evh_.mode () == A::MASTER ? "master" : "slave")));
+ if (!CORBA::is_nil (this->evh_.opponent ()))
+ this->evh_.opponent ()->shutdown ();
+ if (this->evh_.mode () == A::SLAVE)
+ this->evh_.orb ()->shutdown (0);
+}
+
+TestHandler::TestHandler (CORBA::ORB_ptr orb,
+ CORBA::ULong max_count,
+ A::RunMode mode)
+ : orb_ (CORBA::ORB::_duplicate (orb)),
+ max_count_ (max_count),
+ mode_ (mode),
+ counter_ (0)
+{
+ this->seed_ = ACE_OS::time ();
+}
+
+void
+TestHandler::set_counter (CORBA::ULong counter)
+{
+ this->counter_ = counter;
+}
+
+void
+TestHandler::set_opponent (A::Test_ptr opp)
+{
+ this->opponent_ = A::Test::_duplicate (opp);
+}
+
+void
+TestHandler::set_reply_handler (A::AMI_TestHandler_ptr rh)
+{
+ this->rh_ = A::AMI_TestHandler::_duplicate (rh);
+}
+
+int
+TestHandler::handle_timeout (const ACE_Time_Value &,
+ const void *)
+{
+ this->orb_->orb_core ()->reactor ()->cancel_timer (this);
+ if ((ACE_OS::rand_r (static_cast<unsigned int*> (&this->seed_)) % 2) == 0)
+ {
+ A::FollowUp followup;
+ if (!CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->request(A::SYNCH, this->counter_, followup);
+ this->handle_followup (followup, this->counter_);
+ }
+ }
+ else
+ {
+ if (!CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->sendc_request(this->rh_, A::ASYNCH, this->counter_);
+ }
+ }
+ return 0;
+}
+
+int
+TestHandler::handle_exception (ACE_HANDLE)
+{
+ if ((ACE_OS::rand_r (static_cast<unsigned int*> (&this->seed_)) % 2) == 0)
+ {
+ A::FollowUp followup;
+ if (!CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->request(A::SYNCH, this->counter_, followup);
+ this->handle_followup (followup, this->counter_);
+ }
+ }
+ else
+ {
+ if (!CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->sendc_request(this->rh_, A::ASYNCH, this->counter_);
+ }
+ }
+ return 0;
+}
+
+void TestHandler::start ()
+{
+ this->orb_->orb_core ()->reactor ()->notify (this);
+}
+
+void
+TestHandler::handle_followup (A::FollowUp fup, CORBA::ULong counter)
+{
+ if (counter > this->max_count_)
+ {
+ if (this->mode_ == A::MASTER && !CORBA::is_nil (this->opponent_))
+ {
+ this->opponent_->shutdown ();
+ }
+ }
+ else
+ {
+ if (TAO_debug_level > 0)
+ {
+ ACE_DEBUG ((LM_DEBUG,
+ "%N:%l:(%P:%t):TestHandler::handle_followup\n"));
+ }
+
+ this->set_counter (counter);
+ if (fup == A::TIMER)
+ {
+ this->orb_->orb_core ()->reactor ()->schedule_timer (this, 0,
+ ACE_Time_Value (0, 100),
+ ACE_Time_Value (0, 100));
+ }
+ else
+ {
+ this->orb_->orb_core ()->reactor ()->notify (this);
+ }
+ }
+}
diff --git a/TAO/tests/Mixed_Sync_ASync_Events/test_i.h b/TAO/tests/Mixed_Sync_ASync_Events/test_i.h
new file mode 100644
index 00000000000..92e4f7779db
--- /dev/null
+++ b/TAO/tests/Mixed_Sync_ASync_Events/test_i.h
@@ -0,0 +1,125 @@
+
+//=============================================================================
+/**
+ * @file test_i.h
+ *
+ * $Id$
+ *
+ */
+//=============================================================================
+
+#ifndef TAO_MSAE_TEST_I_H
+#define TAO_MSAE_TEST_I_H
+
+#include "testS.h"
+
+/**
+ * @class Test_i
+ *
+ * @brief Test implementation
+ *
+ * Implements the Test interface in test.idl
+ */
+class Test_i : public POA_A::Test
+{
+public:
+ /// ctor
+ Test_i (CORBA::ORB_ptr orb,
+ A::AMI_TestHandler_ptr rh,
+ CORBA::ULong max_count = 10,
+ A::RunMode mode = A::SLAVE);
+
+ void set_opponent (A::Test_ptr opp);
+
+ virtual void request (
+ ::A::RequestMode mode,
+ ::CORBA::ULong & counter,
+ ::A::FollowUp_out follow_up);
+
+ virtual void report (
+ const char * msg);
+
+ void shutdown (void);
+
+private:
+ CORBA::ORB_var orb_;
+
+ A::AMI_TestHandler_var rh_;
+
+ A::Test_var opponent_;
+
+ CORBA::ULong max_count_;
+
+ A::RunMode mode_;
+
+ unsigned int seed_;
+};
+
+class TestHandler
+ : public ACE_Event_Handler
+{
+public:
+ TestHandler (CORBA::ORB_ptr orb,
+ CORBA::ULong max_count,
+ A::RunMode mode);
+
+ void set_counter (CORBA::ULong counter);
+
+ void set_opponent (A::Test_ptr opp);
+
+ void set_reply_handler (A::AMI_TestHandler_ptr rh);
+
+ virtual int handle_timeout (const ACE_Time_Value &tv,
+ const void *arg);
+
+ virtual int handle_exception (ACE_HANDLE fc = ACE_INVALID_HANDLE);
+
+ void handle_followup (A::FollowUp fup, CORBA::ULong counter);
+
+ void start ();
+
+ CORBA::ORB_ptr orb () { return this->orb_.in (); }
+ A::Test_ptr opponent () { return this->opponent_.in (); }
+ CORBA::ULong max_count () { return this->max_count_; }
+ A::RunMode mode () { return this->mode_; }
+
+private:
+ CORBA::ORB_var orb_;
+ A::Test_var opponent_;
+ A::AMI_TestHandler_var rh_;
+ CORBA::ULong max_count_;
+ A::RunMode mode_;
+ CORBA::ULong counter_;
+ unsigned int seed_;
+};
+
+class Test_Reply_i : public POA_A::AMI_TestHandler
+{
+public:
+ Test_Reply_i (CORBA::ORB_ptr orb,
+ CORBA::ULong max_count,
+ A::RunMode mode);
+
+ virtual void request (
+ ::CORBA::ULong counter,
+ ::A::FollowUp follow_up);
+
+ virtual void request_excep (
+ ::Messaging::ExceptionHolder * excep_holder);
+
+ virtual void report (
+ void);
+
+ virtual void report_excep (
+ ::Messaging::ExceptionHolder * excep_holder);
+
+ TestHandler& test_handler () { return this->evh_; }
+
+private:
+ TestHandler evh_;
+};
+
+
+
+#endif /* TAO_MSAE_TEST_I_H */
+