summaryrefslogtreecommitdiff
path: root/TAO/tests/ORB_Local_Config/Bug_2612
diff options
context:
space:
mode:
authoriliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-12-04 18:07:53 +0000
committeriliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2006-12-04 18:07:53 +0000
commit3ce9f1ceb52da5b8036544531f85dc2a78dbd120 (patch)
tree03be4ac1dcbad42d1721b7690d8b2da4b7308203 /TAO/tests/ORB_Local_Config/Bug_2612
parent5dff7ab8238342f5dc985f03c5aebdee449157fe (diff)
downloadATCD-3ce9f1ceb52da5b8036544531f85dc2a78dbd120.tar.gz
ChangeLogTag: Mon Dec 4 18:01:55 UTC 2006 Iliyan Jeliazkov <iliyan@ociweb.com>
Diffstat (limited to 'TAO/tests/ORB_Local_Config/Bug_2612')
-rw-r--r--TAO/tests/ORB_Local_Config/Bug_2612/Bug_2612.mpc18
-rw-r--r--TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.cpp191
-rw-r--r--TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.h59
-rw-r--r--TAO/tests/ORB_Local_Config/Bug_2612/DllOrb_Export.h58
-rw-r--r--TAO/tests/ORB_Local_Config/Bug_2612/Test.cpp42
-rwxr-xr-xTAO/tests/ORB_Local_Config/Bug_2612/run_test.pl49
6 files changed, 417 insertions, 0 deletions
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/Bug_2612.mpc b/TAO/tests/ORB_Local_Config/Bug_2612/Bug_2612.mpc
new file mode 100644
index 00000000000..9abb91eba67
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/Bug_2612.mpc
@@ -0,0 +1,18 @@
+project (DllOrb) : taolib, portableserver {
+
+ dynamicflags = DLLORB_BUILD_DLL
+
+ source_files {
+ DllOrb.cpp
+ }
+ header_files {
+ DllOrb.h
+ DllOrb_Export.h
+ }
+}
+
+project (sig) : taoexe {
+ source_files {
+ Test.cpp
+ }
+}
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.cpp b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.cpp
new file mode 100644
index 00000000000..a9721864e44
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.cpp
@@ -0,0 +1,191 @@
+/*
+ * Copyright (c) 2005 Tradescape Inc. All rights reserved.
+ *
+ * @author Iliyan jeliazkov <iliyan@ociweb.com>
+ * @author Lothar Werzinger <lothar@tradescape.biz>
+ */
+
+
+#include "ace/Arg_Shifter.h"
+#include "ace/SString.h"
+#include "ace/OS_NS_unistd.h"
+#include "tao/corba.h"
+#include "tao/TAO_Singleton_Manager.h"
+
+#include "DllOrb.h"
+
+
+DllOrb::DllOrb ( )
+:
+ m_failPrePostInit(0),
+ mp_barrier(0),
+ mv_orb(),
+ mv_rootPOA()
+{
+}
+
+DllOrb::~DllOrb ( )
+ throw ()
+{
+ delete mp_barrier;
+}
+
+
+int DllOrb::init (int argc, char *argv[])
+{
+ int result = 0;
+ int threadCnt = 1;
+
+ try
+ {
+ ACE_Arg_Shifter as(argc, argv);
+ const ACE_TCHAR *currentArg = 0;
+ while(as.is_anything_left())
+ {
+ if((currentArg = as.get_the_parameter("-t")))
+ {
+ int num = ACE_OS::atoi(currentArg);
+ if(num >= 1)
+ threadCnt = num;
+ as.consume_arg();
+ }
+ else
+ as.ignore_arg();
+ }
+
+ if (m_failPrePostInit < 3)
+ {
+ ACE_DEBUG((LM_DEBUG, "TEST (%P|%t) Pre-ORB initialization ...\n"));
+ // LOG4CPLUS_TRACE(ms_logger, "Pre-ORB initialization ...");
+ // -----------------------------------------------------------------
+ // Pre-ORB initialization steps necessary for proper DLL ORB
+ // support.
+ // -----------------------------------------------------------------
+ // Make sure TAO's singleton manager is initialized, and set to not
+ // register itself with the ACE_Object_Manager since it is under the
+ // control of the Service Configurator. If we register with the
+ // ACE_Object_Manager, then the ACE_Object_Manager will still hold
+ // (dangling) references to instances of objects created by this
+ // module and destroyed by this object when it is dynamically
+ // unloaded.
+ int register_with_object_manager = 0;
+ TAO_Singleton_Manager * p_tsm = TAO_Singleton_Manager::instance();
+ result = p_tsm->init(register_with_object_manager);
+
+ if (result == -1 && m_failPrePostInit == 0)
+ return -1;
+ }
+
+ // Initialize the ORB
+ mv_orb = CORBA::ORB_init(argc, argv, 0);
+ if (CORBA::is_nil(mv_orb.in()))
+ return -1;
+
+ CORBA::Object_var v_poa = mv_orb->resolve_initial_references("RootPOA");
+
+ mv_rootPOA = PortableServer::POA::_narrow(v_poa.in ());
+ if (CORBA::is_nil(mv_rootPOA.in()))
+ return -1;
+
+ mv_poaManager = mv_rootPOA->the_POAManager();
+ if (CORBA::is_nil(mv_poaManager.in()))
+ return -1;
+
+ mv_poaManager->activate();
+ }
+ catch(...)
+ {
+ return -1;
+ }
+
+ mp_barrier = new ACE_Thread_Barrier(threadCnt + 1);
+
+ this->activate(
+ THR_NEW_LWP|THR_JOINABLE|THR_INHERIT_SCHED,
+ threadCnt
+ );
+ mp_barrier->wait();
+
+ return 0;
+}
+
+
+int DllOrb::fini (void)
+{
+ int result;
+
+ try
+ {
+ mv_poaManager->deactivate(1, 1);
+ mv_poaManager = PortableServer::POAManager::_nil();
+
+ // attempt to protect against sporadic BAD_INV_ORDER exceptions
+ ACE_OS::sleep(ACE_Time_Value(0, 500));
+
+ mv_orb->shutdown(1);
+ }
+ catch(...)
+ {
+ return -1;
+ }
+
+
+ // wait for our threads to finish
+ wait();
+
+ delete mp_barrier;
+ mp_barrier = 0;
+
+ try
+ {
+ mv_orb->destroy();
+ mv_orb = CORBA::ORB::_nil();
+ }
+ catch(CORBA::Exception const & rc_ex)
+ {
+ return -1;
+ }
+
+ if (m_failPrePostInit < 3)
+ {
+ ACE_DEBUG((LM_DEBUG, "TEST (%P|%t) Post-ORB finalization ...\n"));
+ //LOG4CPLUS_TRACE(ms_logger, "Post-ORB finalization ...");
+ // -----------------------------------------------------------------
+ // Post-ORB finalization steps necessary for proper DLL ORB
+ // support.
+ // -----------------------------------------------------------------
+ // Explicitly clean up singletons created by TAO before
+ // unloading this module.
+ TAO_Singleton_Manager * p_tsm = TAO_Singleton_Manager::instance();
+ result = p_tsm->fini();
+ if (result == -1 && m_failPrePostInit == 0)
+ return -1;
+ } /* end of if */
+
+ return 0;
+}
+
+
+int DllOrb::svc (void)
+{
+ mp_barrier->wait();
+ try
+ {
+ mv_orb->run();
+ }
+ catch(CORBA::BAD_INV_ORDER const & rc_ex)
+ {
+ const CORBA::ULong VMCID = rc_ex.minor() & 0xFFFFF000U;
+ const CORBA::ULong minorCode = rc_ex.minor() & 0xFFFU;
+ if (VMCID != CORBA::OMGVMCID || minorCode != 4)
+ return -1;
+ }
+ catch(...)
+ {
+ return -1;
+ }
+ return 0;
+}
+
+
+ACE_FACTORY_DEFINE (DllOrb, DllOrb)
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.h b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.h
new file mode 100644
index 00000000000..9efd8f9885d
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2005 Tradescape Inc. All rights reserved.
+ *
+ * @author Iliyan jeliazkov <iliyan@ociweb.com>
+ * @author Lothar Werzinger <lothar@tradescape.biz>
+ */
+
+#ifndef tradescape_utility_DllOrb_h
+#define tradescape_utility_DllOrb_h
+
+#include "ace/Barrier.h"
+#include "ace/Task.h"
+#include "tao/ORB.h"
+#include "tao/PortableServer/PortableServer.h"
+
+#include "DllOrb_Export.h"
+
+/** The CORBA ORB as a dynamic loadable module.
+ *
+ */
+class DllOrb_Export DllOrb
+:
+ public ACE_Task_Base
+{
+ // public types and methods
+ public:
+ /// Default constructor.
+ DllOrb ( );
+
+ /// Destructor.
+ ~DllOrb ( )
+ throw ();
+
+ CORBA::ORB_ptr orb ( ) const;
+
+ virtual int init (int argc, char *argv[]);
+
+ virtual int fini (void);
+
+ // protected types and methods
+ protected:
+ virtual int svc (void);
+
+ // private methods and instance variables
+ private:
+ // static log4cplus::Logger ms_logger;
+
+ unsigned int m_failPrePostInit;
+ ACE_Thread_Barrier * mp_barrier;
+ CORBA::ORB_var mv_orb;
+ PortableServer::POA_var mv_rootPOA;
+ PortableServer::POAManager_var mv_poaManager;
+}; /* end of DllOrb */
+
+
+ACE_FACTORY_DECLARE (DllOrb, DllOrb)
+
+
+#endif /* tradescape_utility_DllOrb_h */
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb_Export.h b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb_Export.h
new file mode 100644
index 00000000000..9eb5083ea7b
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/DllOrb_Export.h
@@ -0,0 +1,58 @@
+
+// -*- C++ -*-
+// $Id$
+// Definition for Win32 Export directives.
+// This file is generated automatically by generate_export_file.pl DllOrb
+// ------------------------------
+#ifndef DLLORB_EXPORT_H
+#define DLLORB_EXPORT_H
+
+#include "ace/config-all.h"
+
+#if defined (ACE_AS_STATIC_LIBS) && !defined (DLLORB_HAS_DLL)
+# define DLLORB_HAS_DLL 0
+#endif /* ACE_AS_STATIC_LIBS && DLLORB_HAS_DLL */
+
+#if !defined (DLLORB_HAS_DLL)
+# define DLLORB_HAS_DLL 1
+#endif /* ! DLLORB_HAS_DLL */
+
+#if defined (DLLORB_HAS_DLL) && (DLLORB_HAS_DLL == 1)
+# if defined (DLLORB_BUILD_DLL)
+# define DllOrb_Export ACE_Proper_Export_Flag
+# define DLLORB_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T)
+# define DLLORB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# else /* DLLORB_BUILD_DLL */
+# define DllOrb_Export ACE_Proper_Import_Flag
+# define DLLORB_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T)
+# define DLLORB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+# endif /* DLLORB_BUILD_DLL */
+#else /* DLLORB_HAS_DLL == 1 */
+# define DllOrb_Export
+# define DLLORB_SINGLETON_DECLARATION(T)
+# define DLLORB_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK)
+#endif /* DLLORB_HAS_DLL == 1 */
+
+// Set DLLORB_NTRACE = 0 to turn on library specific tracing even if
+// tracing is turned off for ACE.
+#if !defined (DLLORB_NTRACE)
+# if (ACE_NTRACE == 1)
+# define DLLORB_NTRACE 1
+# else /* (ACE_NTRACE == 1) */
+# define DLLORB_NTRACE 0
+# endif /* (ACE_NTRACE == 1) */
+#endif /* !DLLORB_NTRACE */
+
+#if (DLLORB_NTRACE == 1)
+# define DLLORB_TRACE(X)
+#else /* (DLLORB_NTRACE == 1) */
+# if !defined (ACE_HAS_TRACE)
+# define ACE_HAS_TRACE
+# endif /* ACE_HAS_TRACE */
+# define DLLORB_TRACE(X) ACE_TRACE_IMPL(X)
+# include "ace/Trace.h"
+#endif /* (DLLORB_NTRACE == 1) */
+
+#endif /* DLLORB_EXPORT_H */
+
+// End of auto generated file.
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/Test.cpp b/TAO/tests/ORB_Local_Config/Bug_2612/Test.cpp
new file mode 100644
index 00000000000..213c2e47158
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/Test.cpp
@@ -0,0 +1,42 @@
+/*
+ * @author Iliyan jeliazkov <iliyan@ociweb.com>
+ * @author Lothar Werzinger <lothar@tradescape.biz>
+ */
+
+#include "ace/OS.h"
+#include "ace/Service_Config.h"
+#include "tao/corba.h"
+
+char const * const scpc_loadOrb =
+ ACE_DYNAMIC_SERVICE_DIRECTIVE ("testDllOrb",
+ "DllOrb",
+ "_make_DllOrb",
+ "DllOrb -ORBDebugLevel 30 -ORBId testORB -ORBInitRef "
+ "NameService=file:///tmp/test-ns.ior -ORBDottedDecimalAddresses 1"
+ );
+
+char const * const scpc_unloadOrb = ACE_REMOVE_SERVICE_DIRECTIVE ("testDllOrb");
+
+int main(int, char **)
+{
+ if (0 > ACE_Service_Config::process_directive(scpc_loadOrb))
+ return -1;
+
+ ACE_OS::sleep(2);
+
+ if (0 > ACE_Service_Config::process_directive(scpc_unloadOrb))
+ return -1;
+
+ ACE_OS::sleep(2);
+ ACE_DEBUG ((LM_DEBUG, "MAIN (%P|%t) Lather, Rince, Repeat ...\n"));
+
+ if (0 > ACE_Service_Config::process_directive(scpc_loadOrb))
+ return -1;
+
+ ACE_OS::sleep(2);
+
+ if (0 > ACE_Service_Config::process_directive(scpc_unloadOrb))
+ return -1;
+
+ return 0;
+}
diff --git a/TAO/tests/ORB_Local_Config/Bug_2612/run_test.pl b/TAO/tests/ORB_Local_Config/Bug_2612/run_test.pl
new file mode 100755
index 00000000000..672625fa515
--- /dev/null
+++ b/TAO/tests/ORB_Local_Config/Bug_2612/run_test.pl
@@ -0,0 +1,49 @@
+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::Run_Test;
+
+sub add_path {
+ my($name) = shift;
+ my($value) = shift;
+ if (defined $ENV{$name}) {
+ $ENV{$name} .= ':' . $value
+ }
+ else {
+ $ENV{$name} = $value;
+ }
+}
+
+# Set the library path for the client to be able to load
+# the Time_Date library.
+add_path('LD_LIBRARY_PATH', '../lib');
+add_path('LIBPATH', '../lib');
+add_path('SHLIB_PATH', '../lib');
+
+sub test($)
+{
+ (my $executable, my $arguments) = @_;
+ my $t1 = new PerlACE::Process ($executable, ($arguments ? $arguments : ""));
+ my $status = $t1->SpawnWaitKill (10);
+ if ($status != 0) {
+ print STDERR "ERROR: test failed, status=$status\n";
+ }
+ return $status;
+}
+
+my $status = 0;
+$status |= test("Test");
+
+if ($status == 0) {
+ print STDERR "SUCCESS: All tests passed\n";
+}
+else {
+ print STDERR "ERROR: Some test failed, status=$status\n";
+}
+exit $status;
+