diff options
author | msmit <msmit@remedy.nl> | 2009-02-03 13:57:28 +0000 |
---|---|---|
committer | msmit <msmit@remedy.nl> | 2009-02-03 13:57:28 +0000 |
commit | 74b918f22bb0ea012d981f3bcf785e685ff4ea67 (patch) | |
tree | 3a15f6de6f09bbfe795ed535bcd2208e83c900e0 /TAO | |
parent | 1cb1931f08a86ee6fa8d43250a5c5088a198ce7f (diff) | |
download | ATCD-74b918f22bb0ea012d981f3bcf785e685ff4ea67.tar.gz |
Tue Feb 3 13:49:37 UTC 2009 Marcel Smit <msmit@remedy.nl>
* bin/tao_orb_tests.lst
* tests/Bug_3558_Regression
* tests/Bug_3558_Regression/Bug_3558_Regression.mpc
* tests/Bug_3558_Regression/client.cpp
* tests/Bug_3558_Regression/Hello.cpp
* tests/Bug_3558_Regression/Hello.h
* tests/Bug_3558_Regression/Makefile.am
* tests/Bug_3558_Regression/README
* tests/Bug_3558_Regression/run_test.pl
* tests/Bug_3558_Regression/server.cpp
* tests/Bug_3558_Regression/Test.idl
Added regression test for bug #3558
Diffstat (limited to 'TAO')
-rw-r--r-- | TAO/ChangeLog | 16 | ||||
-rw-r--r-- | TAO/bin/tao_orb_tests.lst | 1 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/Bug_3558_Regression.mpc | 37 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/Hello.cpp | 26 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/Hello.h | 31 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/Makefile.am | 105 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/README | 26 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/Test.idl | 20 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/client.cpp | 242 | ||||
-rwxr-xr-x | TAO/tests/Bug_3558_Regression/run_test.pl | 94 | ||||
-rw-r--r-- | TAO/tests/Bug_3558_Regression/server.cpp | 105 |
11 files changed, 703 insertions, 0 deletions
diff --git a/TAO/ChangeLog b/TAO/ChangeLog index 50b42a24c0a..0a5c9c8b4c0 100644 --- a/TAO/ChangeLog +++ b/TAO/ChangeLog @@ -1,3 +1,19 @@ +Tue Feb 3 13:49:37 UTC 2009 Marcel Smit <msmit@remedy.nl> + + * bin/tao_orb_tests.lst + * tests/Bug_3558_Regression + * tests/Bug_3558_Regression/Bug_3558_Regression.mpc + * tests/Bug_3558_Regression/client.cpp + * tests/Bug_3558_Regression/Hello.cpp + * tests/Bug_3558_Regression/Hello.h + * tests/Bug_3558_Regression/Makefile.am + * tests/Bug_3558_Regression/README + * tests/Bug_3558_Regression/run_test.pl + * tests/Bug_3558_Regression/server.cpp + * tests/Bug_3558_Regression/Test.idl + + Added regression test for bug #3558 + Tue Feb 3 12:34:17 UTC 2009 Johnny Willemsen <jwillemsen@remedy.nl> * tao/IIOP_Connector.cpp: diff --git a/TAO/bin/tao_orb_tests.lst b/TAO/bin/tao_orb_tests.lst index 338ebc88fcb..de9a2860deb 100644 --- a/TAO/bin/tao_orb_tests.lst +++ b/TAO/bin/tao_orb_tests.lst @@ -143,6 +143,7 @@ TAO/tests/Bug_3542_Regression/run_test.pl: !ST !NO_MESSAGING !MINIMUM !CORBA_E_C #TAO/tests/Bug_3543_Regression/run_test.pl: !ST TAO/tests/Bug_3548_Regression/run_test.pl: TAO/tests/Bug_3559_Regression/run_test.pl: +TAO/tests/Bug_3558_Regression/run_test.pl: TAO/tests/Bug_3552_Regression/run_test.pl: TAO/tests/DIOP/run_test.pl: !ST !NO_DIOP !ACE_FOR_TAO !CORBA_E_MICRO !LabVIEW_RT !WinCE !FUZZ TAO/tests/DIOP/run_test_ipv6.pl: IPV6 !ST !NO_DIOP !ACE_FOR_TAO !CORBA_E_MICRO !LabVIEW_RT !WinCE !FUZZ diff --git a/TAO/tests/Bug_3558_Regression/Bug_3558_Regression.mpc b/TAO/tests/Bug_3558_Regression/Bug_3558_Regression.mpc new file mode 100644 index 00000000000..fbab84719e4 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/Bug_3558_Regression.mpc @@ -0,0 +1,37 @@ +// -*- MPC -*- +// $Id$ + +project(*idl): taoidldefaults { + idlflags += -Sp + IDL_Files { + Test.idl + } + custom_only = 1 +} + +project(*Server): taoserver { + after += *idl + Source_Files { + Hello.cpp + server.cpp + } + Source_Files { + TestC.cpp + TestS.cpp + } + IDL_Files { + } +} + +project(*Client): taoclient { + after += *idl + Source_Files { + client.cpp + } + Source_Files { + TestC.cpp + } + IDL_Files { + } +} + diff --git a/TAO/tests/Bug_3558_Regression/Hello.cpp b/TAO/tests/Bug_3558_Regression/Hello.cpp new file mode 100644 index 00000000000..ec8f6d2e485 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/Hello.cpp @@ -0,0 +1,26 @@ +// +// $Id$ +// +#include "Hello.h" +#include "ace/OS_NS_unistd.h" + +ACE_RCSID(Hello, Hello, "$Id$") + +Hello::Hello (CORBA::ORB_ptr orb) + : orb_ (CORBA::ORB::_duplicate (orb)) +{ +} + +char * +Hello::get_string (void) +{ + ACE_DEBUG((LM_DEBUG, ACE_TEXT("%D get_string: sleep 5 seconds before returning\n"))); + ACE_OS::sleep (5); + return CORBA::string_dup ("Hello there!"); +} + +void +Hello::shutdown (void) +{ + this->orb_->shutdown (0); +} diff --git a/TAO/tests/Bug_3558_Regression/Hello.h b/TAO/tests/Bug_3558_Regression/Hello.h new file mode 100644 index 00000000000..f87205c3011 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/Hello.h @@ -0,0 +1,31 @@ +// +// $Id$ +// + +#ifndef HELLO_H +#define HELLO_H +#include /**/ "ace/pre.h" + +#include "TestS.h" + +/// Implement the Test::Hello interface +class Hello + : public virtual POA_Test::Hello +{ +public: + /// Constructor + Hello (CORBA::ORB_ptr orb); + + // = The skeleton methods + virtual char * get_string (void); + + virtual void shutdown (void); + +private: + /// Use an ORB reference to conver strings to objects and shutdown + /// the application. + CORBA::ORB_var orb_; +}; + +#include /**/ "ace/post.h" +#endif /* HELLO_H */ diff --git a/TAO/tests/Bug_3558_Regression/Makefile.am b/TAO/tests/Bug_3558_Regression/Makefile.am new file mode 100644 index 00000000000..a0e2286e095 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/Makefile.am @@ -0,0 +1,105 @@ +## Process this file with automake to create Makefile.in +## +## $Id$ +## +## This file was generated by MPC. Any changes made directly to +## this file will be lost the next time it is generated. +## +## MPC Command: +## ../bin/mwc.pl -type automake -noreldefs TAO.mwc + +ACE_BUILDDIR = $(top_builddir)/.. +ACE_ROOT = $(top_srcdir)/.. +TAO_BUILDDIR = $(top_builddir) +TAO_IDL = ACE_ROOT=$(ACE_ROOT) TAO_ROOT=$(TAO_ROOT) $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDL_DEP = $(TAO_BUILDDIR)/TAO_IDL/tao_idl +TAO_IDLFLAGS = -Wb,pre_include=ace/pre.h -Wb,post_include=ace/post.h -I$(TAO_ROOT) -I$(srcdir) -g $(ACE_BUILDDIR)/apps/gperf/src/ace_gperf +TAO_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.Hello_Idl.am + +BUILT_SOURCES = \ + TestC.cpp \ + TestC.h \ + TestC.inl \ + TestS.cpp \ + TestS.h \ + TestS.inl + +CLEANFILES = \ + Test-stamp \ + TestC.cpp \ + TestC.h \ + TestC.inl \ + TestS.cpp \ + TestS.h \ + TestS.inl + +TestC.cpp TestC.h TestC.inl TestS.cpp TestS.h TestS.inl: Test-stamp + +Test-stamp: $(srcdir)/Test.idl $(TAO_IDL_DEP) + $(TAO_IDL) $(TAO_IDLFLAGS) -Sa -St -Sp $(srcdir)/Test.idl + @touch $@ + +noinst_HEADERS = \ + Test.idl + +## Makefile.Hello_Client.am + +if BUILD_EXCEPTIONS + +noinst_PROGRAMS += client + +client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +client_SOURCES = \ + TestC.cpp \ + client.cpp \ + Hello.h + +client_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_EXCEPTIONS + +## Makefile.Hello_Server.am + +if BUILD_EXCEPTIONS + +noinst_PROGRAMS += server + +server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(TAO_ROOT) \ + -I$(TAO_BUILDDIR) + +server_SOURCES = \ + Hello.cpp \ + TestC.cpp \ + TestS.cpp \ + server.cpp \ + Hello.h + +server_LDADD = \ + $(TAO_BUILDDIR)/tao/libTAO_PortableServer.la \ + $(TAO_BUILDDIR)/tao/libTAO_AnyTypeCode.la \ + $(TAO_BUILDDIR)/tao/libTAO.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_EXCEPTIONS + +## Clean up template repositories, etc. +clean-local: + -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.* + -rm -f gcctemp.c gcctemp so_locations *.ics + -rm -rf cxx_repository ptrepository ti_files + -rm -rf templateregistry ir.out + -rm -rf ptrepository SunWS_cache Templates.DB diff --git a/TAO/tests/Bug_3558_Regression/README b/TAO/tests/Bug_3558_Regression/README new file mode 100644 index 00000000000..9c57d7f4d03 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/README @@ -0,0 +1,26 @@ +/** + +@page Bug_3558_Regression Test README File + + Test written for Bugzilla #3558 + + This test is based on the Hello TAO test. + + The goal of writing this test is: + +- Provide a way to test whether transport cache behaves correctly. + ORBConnectionCacheMax is programmatically set to 1. When a second + connection is esthablished, we expect an exception. However, it seems that + the transport cache adjusts itself (no exception is thrown). + + To run the test use the run_test.pl script: + +$ ./run_test.pl + +or, with debug information: + +$ ./run_test.pl -debug + + the script returns 0 if the test was successful. + +*/ diff --git a/TAO/tests/Bug_3558_Regression/Test.idl b/TAO/tests/Bug_3558_Regression/Test.idl new file mode 100644 index 00000000000..3c0976e106d --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/Test.idl @@ -0,0 +1,20 @@ +// +// $Id$ +// + +/// Put the interfaces in a module, to avoid global namespace pollution +module Test +{ + /// A very simple interface + interface Hello + { + /// Return a simple string + string get_string (); + + /// A method to shutdown the ORB + /** + * This method is used to simplify the test shutdown process + */ + oneway void shutdown (); + }; +}; diff --git a/TAO/tests/Bug_3558_Regression/client.cpp b/TAO/tests/Bug_3558_Regression/client.cpp new file mode 100644 index 00000000000..a2c89c4482d --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/client.cpp @@ -0,0 +1,242 @@ +// $Id$ + +#include "TestC.h" +#include "ace/Get_Opt.h" +#include "ace/Task.h" +#include "ace/Barrier.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_strings.h" + +#include "tao/ORB_Core.h" +#include "tao/Transport_Cache_Manager.h" +#include "tao/Thread_Lane_Resources.h" + + + +ACE_RCSID(Hello, client, "$Id$") + +ACE_TCHAR *ior1 = ACE_TEXT ("file://server1.ior"); +ACE_TCHAR *ior2 = ACE_TEXT ("file://server2.ior"); + +int debug_level = 0; + +CORBA::ORB_var orb; + +ACE_Barrier barrier(2); + +int +parse_args (int argc, ACE_TCHAR *argv[]) +{ + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT ("k:l:d:")); + int c; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'k': + ior1 = get_opts.opt_arg (); + break; + + case 'l': + ior2 = get_opts.opt_arg (); + break; + case 'd': + debug_level = ACE_OS::atoi( get_opts.opt_arg ()); + break; + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("usage: %s ") + ACE_TEXT ("-k <ior1>\n") + ACE_TEXT ("-l <ior2>\n"), + ACE_TEXT ("-d <debug_level>\n"), + argv [0]), + -1); + } + // Indicates sucessful parsing of the command line + return 0; +} + + +static void * +test_server (void *arg) +{ +#if defined (ACE_OPENVMS) && (!defined (__INITIAL_POINTER_SIZE) || (__INITIAL_POINTER_SIZE < 64)) + int server_nr = reinterpret_cast<int> (arg); +#else + intptr_t server_nr = reinterpret_cast<intptr_t> (arg); +#endif + + ACE_TCHAR ior[256]; + + if (server_nr == 1) + ACE_OS::sprintf(ior, ACE_TEXT ("%s"), ior1); + else if (server_nr == 2) + { + ACE_OS::sprintf(ior, ACE_TEXT ("%s"), ior2); + ACE_DEBUG((LM_DEBUG, + ACE_TEXT("%D Expecting an exception for server %d\n"), + server_nr)); + } + + Test::Hello_var hello; + try + { + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%D Starting connection with server %d\n"), + server_nr)); + + CORBA::Object_var server = orb->string_to_object(ior); + + hello = Test::Hello::_narrow(server.in ()); + + if (CORBA::is_nil (hello.in ())) + { + ACE_Thread::exit (); + ACE_ERROR ((LM_ERROR, + ACE_TEXT ("%D (%t) Nil Test::Hello reference <%s> for server %d\n"), + ior, server_nr)); + return 0; + } + + ACE_DEBUG((LM_DEBUG, + ACE_TEXT ("%D Transport data before invocation to server %d: current size: %d\n"), + server_nr, + orb->orb_core ()->lane_resources ().transport_cache ().current_size ())); + + CORBA::String_var the_string = hello->get_string (); + + ACE_DEBUG((LM_DEBUG, + ACE_TEXT ("%D Transport data after invocation to server %d: current size: %d\n"), + server_nr, + orb->orb_core ()->lane_resources ().transport_cache ().current_size ())); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%D (%P|%t) - string <%C> returned from server %d\n"), + the_string.in (), server_nr)); + } + catch (const CORBA::TRANSIENT &) + { + if (server_nr == 2) + { + ACE_DEBUG((LM_DEBUG, + ACE_TEXT ("%D Expected exception for server %d\n"), + server_nr)); + } + else + ACE_ERROR((LM_ERROR, + ACE_TEXT ("%D Unexpected exception for server %d\n"), + server_nr)); + } + catch (...) + { + ACE_ERROR((LM_ERROR, + ACE_TEXT ("%D Unexpected exception for server %d\n"), + server_nr)); + } + + + if (server_nr == 2) + barrier.wait(); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%D Shutdown server %d\n"), + server_nr)); + + if (!CORBA::is_nil(hello)) + hello->shutdown (); + + if (server_nr == 1) + barrier.wait(); + + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("%D Thread ended for server %d\n"), + server_nr)); + + return 0; +} + +int +ACE_TMAIN(int argc, ACE_TCHAR *argv[]) +{ + int extra_argc = 4; + + try + { + if (parse_args (argc, argv) != 0) + return 1; + + if (debug_level > 0) + extra_argc = 6; + + ACE_TCHAR **extra = 0; + ACE_NEW_RETURN (extra, ACE_TCHAR *[extra_argc], -1); + extra[0] = ACE::strnew (ACE_TEXT ("-ORBSvcConfDirective")); + extra[1] = ACE::strnew (ACE_TEXT ("static Resource_Factory \"-ORBConnectionCacheMax 1\"")); + extra[2] = ACE::strnew (ACE_TEXT ("-ORBSvcConfDirective")); + extra[3] = ACE::strnew (ACE_TEXT ("static Client_Strategy_Factory \"-ORBTransportMuxStrategy EXCLUSIVE\"")); + if (debug_level > 0) + { + extra[4] = ACE::strnew (ACE_TEXT ("-ORBdebuglevel")); + extra[5] = ACE::strnew (ACE_TEXT ("10")); + } + + ACE_TCHAR **largv = new ACE_TCHAR *[argc+extra_argc]; + for (int i = 0; i < argc; i++) + largv[i] = argv[i]; + + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%D client adding args: \n"))); + for (int i = 0; i < extra_argc; i++) + { + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\t\t%s\n"), extra[i])); + largv[argc+i] = extra[i]; + } + + argc += extra_argc; + + orb = CORBA::ORB_init (argc, largv); + + if (ACE_Thread_Manager::instance ()->spawn + ((ACE_THR_FUNC) test_server, + (void *) 1, + THR_NEW_LWP | THR_JOINABLE, + 0) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error spawning thread 1\n")), + 1); + } + + ACE_OS::sleep(2); + + if (ACE_Thread_Manager::instance ()->spawn + ((ACE_THR_FUNC) test_server, + (void *) 2, + THR_NEW_LWP | THR_JOINABLE, + 0) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("Error spawning thread 2")), + 1); + } + + ACE_Thread_Manager::instance()->wait (); + + ACE_DEBUG((LM_DEBUG, + ACE_TEXT ("%D Transport data when done: current size: %d\n"), + orb->orb_core ()->lane_resources ().transport_cache ().current_size ())); + + orb->destroy (); + for (int i = 0; i < extra_argc; i++) + ACE::strdelete (extra[i]); + delete [] extra; + delete [] largv; + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} diff --git a/TAO/tests/Bug_3558_Regression/run_test.pl b/TAO/tests/Bug_3558_Regression/run_test.pl new file mode 100755 index 00000000000..d05b43a6239 --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/run_test.pl @@ -0,0 +1,94 @@ +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; + +$status = 0; +$debug_level = '0'; + +foreach $i (@ARGV) { + if ($i eq '-debug') { + $debug_level = '10'; + } +} + +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"; + +my $iorbase1 = "server1.ior"; +my $iorbase2 = "server2.ior"; +my $server1_iorfile = $server->LocalFile ($iorbase1); +my $server2_iorfile = $server->LocalFile ($iorbase2); +my $client1_iorfile = $client->LocalFile ($iorbase1); +my $client2_iorfile = $client->LocalFile ($iorbase2); + +$server->DeleteFile($iorbase1); +$server->DeleteFile($iorbase2); +$client->DeleteFile($iorbase1); +$client->DeleteFile($iorbase2); + +$SV1 = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server1_iorfile"); +$SV2 = $server->CreateProcess ("server", "-ORBdebuglevel $debug_level -o $server2_iorfile"); +$CL = $client->CreateProcess ("client", "-k file://$server1_iorfile -l file://$server2_iorfile -d $debug_level"); + +$server1_status = $SV1->Spawn (); + +if ($server1_status != 0) { + print STDERR "ERROR: server returned $server1_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase1, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server1_iorfile>\n"; + $SV1->Kill (); $SV1->TimedWait (1); + exit 1; +} + +$server2_status = $SV2->Spawn (); + +if ($server2_status != 0) { + print STDERR "ERROR: server returned $server2_status\n"; + exit 1; +} + +if ($server->WaitForFileTimed ($iorbase2, + $server->ProcessStartWaitInterval()) == -1) { + print STDERR "ERROR: cannot find file <$server2_iorfile>\n"; + $SV1->Kill (); $SV1->TimedWait (1); + $SV2->Kill (); $SV2->TimedWait (1); + exit 1; +} + +$client_status = $CL->SpawnWaitKill ($client->ProcessStartWaitInterval()); + +if ($client_status != 0) { + print STDERR "ERROR: client returned $client_status\n"; + $status = 1; +} + +$server1_status = $SV1->WaitKill ($server->ProcessStopWaitInterval()); + +if ($server1_status != 0) { + print STDERR "ERROR: server returned $server1_status\n"; + $status = 1; +} + +$server2_status = $SV2->WaitKill ($server->ProcessStopWaitInterval()); + +if ($server2_status != 0) { + print STDERR "ERROR: server returned $server2_status\n"; + $status = 1; +} + +$server->DeleteFile($iorbase1); +$server->DeleteFile($iorbase2); +$client->DeleteFile($iorbase1); +$client->DeleteFile($iorbase2); + +exit $status; diff --git a/TAO/tests/Bug_3558_Regression/server.cpp b/TAO/tests/Bug_3558_Regression/server.cpp new file mode 100644 index 00000000000..97455f4ef9b --- /dev/null +++ b/TAO/tests/Bug_3558_Regression/server.cpp @@ -0,0 +1,105 @@ +// $Id$ + +#include "Hello.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" + +ACE_RCSID (Hello, + server, + "$Id: ") + +const ACE_TCHAR *ior_output_file = ACE_TEXT ("server.ior"); + +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.opt_arg (); + break; + + case '?': + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s " + "-o <iorfile>" + "\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 poa_object = + orb->resolve_initial_references("RootPOA"); + + PortableServer::POA_var root_poa = + PortableServer::POA::_narrow (poa_object.in ()); + + if (CORBA::is_nil (root_poa.in ())) + ACE_ERROR_RETURN ((LM_ERROR, + " (%P|%t) Panic: nil RootPOA\n"), + 1); + + PortableServer::POAManager_var poa_manager = root_poa->the_POAManager (); + + if (parse_args (argc, argv) != 0) + return 1; + + Hello *hello_impl = 0; + ACE_NEW_RETURN (hello_impl, + Hello (orb.in ()), + 1); + PortableServer::ServantBase_var owner_transfer(hello_impl); + + PortableServer::ObjectId_var id = + root_poa->activate_object (hello_impl); + + CORBA::Object_var object = root_poa->id_to_reference (id.in ()); + + Test::Hello_var hello = Test::Hello::_narrow (object.in ()); + + CORBA::String_var ior = orb->object_to_string (hello.in ()); + + // Output the IOR to the <ior_output_file> + 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\n", + ior_output_file), + 1); + ACE_OS::fprintf (output_file, "%s", ior.in ()); + ACE_OS::fclose (output_file); + + poa_manager->activate (); + + orb->run (); + + ACE_DEBUG ((LM_DEBUG, "(%P|%t) server - event loop finished\n")); + + root_poa->destroy (1, 1); + + orb->destroy (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("Exception caught:"); + return 1; + } + + return 0; +} |