diff options
author | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-05-18 20:37:47 +0000 |
---|---|---|
committer | dhinton <dhinton@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2002-05-18 20:37:47 +0000 |
commit | 070ba769568f7e5bb3d2a16d24756c43dd74abc2 (patch) | |
tree | 26c013c9325c1d739025c2958cc39e3972d1a95b | |
parent | b9000c21ffa3a2c4807bc042ec6bea2ad3c18b26 (diff) | |
download | ATCD-070ba769568f7e5bb3d2a16d24756c43dd74abc2.tar.gz |
ChangeLogTag:Sat May 18 20:33:02 UTC 2002 Don Hinton <dhinton@ieee.org>
-rw-r--r-- | ChangeLog | 39 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-02a | 39 | ||||
-rw-r--r-- | ChangeLogs/ChangeLog-03a | 39 | ||||
-rw-r--r-- | ace/DLL.cpp | 2 | ||||
-rw-r--r-- | ace/Framework_Component.cpp | 29 | ||||
-rw-r--r-- | ace/Global_Macros.h | 4 | ||||
-rw-r--r-- | ace/Parse_Node.cpp | 27 | ||||
-rw-r--r-- | ace/Parse_Node.h | 6 | ||||
-rw-r--r-- | ace/Service_Object.cpp | 11 | ||||
-rw-r--r-- | ace/Service_Object.h | 13 | ||||
-rw-r--r-- | ace/Service_Object.i | 6 | ||||
-rw-r--r-- | ace/Svc_Conf_y.cpp | 2 | ||||
-rw-r--r-- | tests/Framework_Component_DLL.cpp | 14 | ||||
-rw-r--r-- | tests/Framework_Component_Test.cpp | 15 |
14 files changed, 194 insertions, 52 deletions
diff --git a/ChangeLog b/ChangeLog index 6c165890a2e..46f18f7e29a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,41 @@ +Sat May 18 20:33:02 UTC 2002 Don Hinton <dhinton@ieee.org> + + * ace/Global_Macros.h: + + Defined a new macros, ACE_TRACE_IMPL, and implemented ACE_TRACE + in terms of it if tracing is turned on. This allows you to + easily and selectively turn tracing back on in an individual + file if you want without recompiling everything by just undefining + ACE_TRACE and redefining it as ACE_TRACE_IMPL. + + * ace/Framework_Component.cpp: + + Fixed some errors in the remove* methods. + + * ace/Svc_Conf_y.cpp: + + Made appropriate changes to use new dll methods when + creating an ACE_Service_Type instead of a handle. + + * ace/Parse_Node.{h,cpp}: + + Made the dll_ variable a pointer to an ACE_DLL instance and + added a method to return it and take ownership. + + * ace/Service_Object.{h,cpp,i}: + + Store a pointer to the ACE_DLL instance that loaded the + dll containing the dynamic ACE_Service_Object, not just + a handle to the dll itself. Removed handle() methods. This + means that ACE_DLL's close method will be the one to call + ACE_OS::dlclose() as well as ACE_Framework_Repository:: + remove_dll_components() mentioned below. + + * tests/Framework_Component_DLL.cpp: + * tests/Framework_Component_Test.cpp: + + Minor cleanup mainly in comments and debug statements. + Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.cpp: @@ -18,7 +56,6 @@ Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> method to Simple_Service to make testing easier (this isn't needed by real classes that use the adapter template). - Thu May 16 17:54:49 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.{h,cpp}: diff --git a/ChangeLogs/ChangeLog-02a b/ChangeLogs/ChangeLog-02a index 6c165890a2e..46f18f7e29a 100644 --- a/ChangeLogs/ChangeLog-02a +++ b/ChangeLogs/ChangeLog-02a @@ -1,3 +1,41 @@ +Sat May 18 20:33:02 UTC 2002 Don Hinton <dhinton@ieee.org> + + * ace/Global_Macros.h: + + Defined a new macros, ACE_TRACE_IMPL, and implemented ACE_TRACE + in terms of it if tracing is turned on. This allows you to + easily and selectively turn tracing back on in an individual + file if you want without recompiling everything by just undefining + ACE_TRACE and redefining it as ACE_TRACE_IMPL. + + * ace/Framework_Component.cpp: + + Fixed some errors in the remove* methods. + + * ace/Svc_Conf_y.cpp: + + Made appropriate changes to use new dll methods when + creating an ACE_Service_Type instead of a handle. + + * ace/Parse_Node.{h,cpp}: + + Made the dll_ variable a pointer to an ACE_DLL instance and + added a method to return it and take ownership. + + * ace/Service_Object.{h,cpp,i}: + + Store a pointer to the ACE_DLL instance that loaded the + dll containing the dynamic ACE_Service_Object, not just + a handle to the dll itself. Removed handle() methods. This + means that ACE_DLL's close method will be the one to call + ACE_OS::dlclose() as well as ACE_Framework_Repository:: + remove_dll_components() mentioned below. + + * tests/Framework_Component_DLL.cpp: + * tests/Framework_Component_Test.cpp: + + Minor cleanup mainly in comments and debug statements. + Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.cpp: @@ -18,7 +56,6 @@ Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> method to Simple_Service to make testing easier (this isn't needed by real classes that use the adapter template). - Thu May 16 17:54:49 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.{h,cpp}: diff --git a/ChangeLogs/ChangeLog-03a b/ChangeLogs/ChangeLog-03a index 6c165890a2e..46f18f7e29a 100644 --- a/ChangeLogs/ChangeLog-03a +++ b/ChangeLogs/ChangeLog-03a @@ -1,3 +1,41 @@ +Sat May 18 20:33:02 UTC 2002 Don Hinton <dhinton@ieee.org> + + * ace/Global_Macros.h: + + Defined a new macros, ACE_TRACE_IMPL, and implemented ACE_TRACE + in terms of it if tracing is turned on. This allows you to + easily and selectively turn tracing back on in an individual + file if you want without recompiling everything by just undefining + ACE_TRACE and redefining it as ACE_TRACE_IMPL. + + * ace/Framework_Component.cpp: + + Fixed some errors in the remove* methods. + + * ace/Svc_Conf_y.cpp: + + Made appropriate changes to use new dll methods when + creating an ACE_Service_Type instead of a handle. + + * ace/Parse_Node.{h,cpp}: + + Made the dll_ variable a pointer to an ACE_DLL instance and + added a method to return it and take ownership. + + * ace/Service_Object.{h,cpp,i}: + + Store a pointer to the ACE_DLL instance that loaded the + dll containing the dynamic ACE_Service_Object, not just + a handle to the dll itself. Removed handle() methods. This + means that ACE_DLL's close method will be the one to call + ACE_OS::dlclose() as well as ACE_Framework_Repository:: + remove_dll_components() mentioned below. + + * tests/Framework_Component_DLL.cpp: + * tests/Framework_Component_Test.cpp: + + Minor cleanup mainly in comments and debug statements. + Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.cpp: @@ -18,7 +56,6 @@ Fri May 17 13:24:59 UTC 2002 Don Hinton <dhinton@ieee.org> method to Simple_Service to make testing easier (this isn't needed by real classes that use the adapter template). - Thu May 16 17:54:49 UTC 2002 Don Hinton <dhinton@ieee.org> * tests/Framework_Component_Test.{h,cpp}: diff --git a/ace/DLL.cpp b/ace/DLL.cpp index 4ba4fefa2a7..0b197849011 100644 --- a/ace/DLL.cpp +++ b/ace/DLL.cpp @@ -159,7 +159,7 @@ ACE_DLL::close (void) { ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("ACE_DLL::close(): close_on_destruction\n"))); // First remove any associated Framework Components. - ACE_Framework_Repository::instance () ->remove_dll_components (this->dll_name_); + ACE_Framework_Repository::instance () ->remove_dll_components (this->dll_name_); retval = ACE_OS::dlclose (this->handle_); diff --git a/ace/Framework_Component.cpp b/ace/Framework_Component.cpp index dd147f3ee7a..9a95eada6bb 100644 --- a/ace/Framework_Component.cpp +++ b/ace/Framework_Component.cpp @@ -60,11 +60,14 @@ ACE_Framework_Repository::close (void) // Delete components in reverse order. for (int i = this->current_size_ - 1; i >= 0; i--) { - ACE_Framework_Component *s = ACE_const_cast (ACE_Framework_Component *, - this->component_vector_[i]); - --this->current_size_; - s->close_singleton (); - delete s; + if (this->component_vector_[i]) + { + ACE_Framework_Component *s = ACE_const_cast (ACE_Framework_Component *, + this->component_vector_[i]); + + --this->current_size_; + s->close_singleton (); + } } delete [] this->component_vector_; @@ -147,15 +150,15 @@ ACE_Framework_Repository::remove_component (const ACE_TCHAR *name) for (i = 0; i < this->current_size_; i++) if (this->component_vector_[i] && - ACE_OS_String::strcmp (this->component_vector_[i]->name_, name)) + ACE_OS_String::strcmp (this->component_vector_[i]->name_, name) == 0) { this->component_vector_[i]->close_singleton (); delete this->component_vector_[i]; this->component_vector_[i] = 0; - //return 0; + return 0; } - return 0; + return -1; } int @@ -164,21 +167,21 @@ ACE_Framework_Repository::remove_dll_components (const ACE_TCHAR *dll_name) ACE_TRACE ("ACE_Framework_Repository::register_component"); ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, -1)); int i; + int retval = -1; ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("AFR::remove_dll_components ('%s')\n"), dll_name)); for (i = 0; i < this->current_size_; i++) if (this->component_vector_[i] && - ACE_OS_String::strcmp (this->component_vector_[i]->dll_name_, dll_name)) + ACE_OS_String::strcmp (this->component_vector_[i]->dll_name_, dll_name) == 0) { + ACE_DEBUG ((LM_DEBUG, ACE_LIB_TEXT ("AFR::remove_dll_c...()\n"))); this->component_vector_[i]->close_singleton (); - delete this->component_vector_[i]; this->component_vector_[i] = 0; - return 0; + ++retval; } - return -1; - + return retval == -1 ? -1 : 0; } void diff --git a/ace/Global_Macros.h b/ace/Global_Macros.h index ae079c0b02f..75408223092 100644 --- a/ace/Global_Macros.h +++ b/ace/Global_Macros.h @@ -103,10 +103,12 @@ friend class ace_dewarn_gplusplus // ---------------------------------------------------------------- +# define ACE_TRACE_IMPL(X) ACE_Trace ____ (ACE_LIB_TEXT (X), __LINE__, ACE_LIB_TEXT (__FILE__)) + # if (ACE_NTRACE == 1) # define ACE_TRACE(X) # else -# define ACE_TRACE(X) ACE_Trace ____ (ACE_LIB_TEXT (X), __LINE__, ACE_LIB_TEXT (__FILE__)) +# define ACE_TRACE(X) ACE_TRACE_IMPL(X) # endif /* ACE_NTRACE */ // ---------------------------------------------------------------- diff --git a/ace/Parse_Node.cpp b/ace/Parse_Node.cpp index 3cf9be2ef12..09a830e26c8 100644 --- a/ace/Parse_Node.cpp +++ b/ace/Parse_Node.cpp @@ -329,21 +329,34 @@ ACE_Location_Node::dump (void) const ACE_Location_Node::ACE_Location_Node (void) : pathname_ (0), + delete_dll_ (0), + dll_ (0), symbol_ (0) { ACE_TRACE ("ACE_Location_Node::ACE_Location_Node"); + ACE_NEW (dll_, ACE_DLL); } ACE_Location_Node::~ACE_Location_Node (void) { ACE_TRACE ("ACE_Location_Node::~ACE_Location_Node"); + if (this->delete_dll_) + delete dll_; +} + +ACE_DLL * +ACE_Location_Node::dll (void) +{ + // Now caller owns dll. + this->delete_dll_ = 0; + return this->dll_; } ACE_SHLIB_HANDLE ACE_Location_Node::handle (void) { ACE_TRACE ("ACE_Location_Node::handle"); - return this->dll_.get_handle (1); // Caller now owns the handle + return this->dll_->get_handle (0); // Caller does not own the handle } const ACE_TCHAR * @@ -379,11 +392,11 @@ ACE_Location_Node::open_dll (void) { ACE_TRACE ("ACE_Location_Node::open_dll"); - if (-1 == this->dll_.open (this->pathname ())) + if (-1 == this->dll_->open (this->pathname ())) { ace_yyerrno++; - ACE_TCHAR *errmsg = this->dll_.error (); + ACE_TCHAR *errmsg = this->dll_->error (); ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("ACE_DLL::open failed for %s: %s\n"), this->pathname (), @@ -420,12 +433,12 @@ ACE_Object_Node::symbol (ACE_Service_Object_Exterminator *) { ACE_TCHAR *object_name = ACE_const_cast (ACE_TCHAR *, this->object_name_); - this->symbol_ = this->dll_.symbol (object_name); + this->symbol_ = this->dll_->symbol (object_name); if (this->symbol_ == 0) { ace_yyerrno++; - ACE_TCHAR *errmsg = this->dll_.error (); + ACE_TCHAR *errmsg = this->dll_->error (); ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("ACE_DLL::symbol failed for object %s: %s\n"), object_name, @@ -489,7 +502,7 @@ ACE_Function_Node::symbol (ACE_Service_Object_Exterminator *gobbler) // close to (or, at least claim to conform with) the standard // did not complain about this as an illegal pointer conversion. long temp_ptr = - ACE_reinterpret_cast(long, this->dll_.symbol (function_name)); + ACE_reinterpret_cast(long, this->dll_->symbol (function_name)); func = ACE_reinterpret_cast(void *(*)(ACE_Service_Object_Exterminator *), temp_ptr); @@ -501,7 +514,7 @@ ACE_Function_Node::symbol (ACE_Service_Object_Exterminator *gobbler) { ace_yyerrno++; - ACE_TCHAR *errmsg = this->dll_.error (); + ACE_TCHAR *errmsg = this->dll_->error (); ACE_ERROR ((LM_ERROR, ACE_LIB_TEXT ("ACE_DLL::symbol failed for function %s: %s\n"), function_name, diff --git a/ace/Parse_Node.h b/ace/Parse_Node.h index 967b1813239..c4de9061961 100644 --- a/ace/Parse_Node.h +++ b/ace/Parse_Node.h @@ -202,6 +202,7 @@ public: virtual void *symbol (ACE_Service_Object_Exterminator * = 0) = 0; virtual void set_symbol (void *h); ACE_SHLIB_HANDLE handle (void); + ACE_DLL *dll (void); const ACE_TCHAR *pathname (void) const; void pathname (const ACE_TCHAR *h); int dispose (void) const; @@ -227,8 +228,11 @@ protected: */ int must_delete_; + /// Flag to determine if we should delete the dll. + int delete_dll_; + /// The open shared library. - ACE_DLL dll_; + ACE_DLL *dll_; /// Symbol that we've obtained from the shared library. void *symbol_; diff --git a/ace/Service_Object.cpp b/ace/Service_Object.cpp index 63decf4e9b3..52283e3bdcc 100644 --- a/ace/Service_Object.cpp +++ b/ace/Service_Object.cpp @@ -1,12 +1,14 @@ // $Id$ -#include "ace/Service_Types.h" #include "ace/Service_Object.h" #if !defined (__ACE_INLINE__) #include "ace/Service_Object.i" #endif /* __ACE_INLINE__ */ +#include "ace/Service_Types.h" +#include "ace/DLL.h" + ACE_RCSID(ace, Service_Object, "$Id$") ACE_ALLOC_HOOK_DEFINE(ACE_Service_Object) @@ -20,11 +22,11 @@ ACE_Service_Type::dump (void) const ACE_Service_Type::ACE_Service_Type (const ACE_TCHAR *n, ACE_Service_Type_Impl *t, - const ACE_SHLIB_HANDLE h, + ACE_DLL *dll, int active) : name_ (0), type_ (t), - handle_ (h), + dll_ (dll), active_ (active), fini_already_called_ (0) { @@ -38,8 +40,7 @@ ACE_Service_Type::~ACE_Service_Type (void) this->fini (); - if (this->handle_ != 0) - ACE_OS::dlclose ((ACE_SHLIB_HANDLE) this->handle_); + delete dll_; delete [] (ACE_TCHAR *) this->name_; } diff --git a/ace/Service_Object.h b/ace/Service_Object.h index c5155c0c5c0..3cb9d5af50a 100644 --- a/ace/Service_Object.h +++ b/ace/Service_Object.h @@ -22,7 +22,7 @@ #endif /* ACE_LACKS_PRAGMA_ONCE */ #include "ace/Event_Handler.h" - +#include "ace/DLL.h" #define ACE_Component ACE_Service_Object /** * @class ACE_Service_Object @@ -54,6 +54,7 @@ public: // Forward decl. class ACE_Service_Type_Impl; +class ACE_DLL; /** * @class ACE_Service_Type @@ -86,7 +87,7 @@ public: // = Initialization and termination methods. ACE_Service_Type (const ACE_TCHAR *n, ACE_Service_Type_Impl *o, - const ACE_SHLIB_HANDLE handle, + ACE_DLL *dll, int active); ~ACE_Service_Type (void); @@ -97,8 +98,8 @@ public: void type (const ACE_Service_Type_Impl *, int active = 1); - ACE_SHLIB_HANDLE handle (void) const; - void handle (const ACE_SHLIB_HANDLE); + //ACE_SHLIB_HANDLE handle (void) const; + //void handle (const ACE_SHLIB_HANDLE); void suspend (void) const; void resume (void) const; @@ -124,8 +125,8 @@ private: /// Pointer to C++ object that implements the svc. const ACE_Service_Type_Impl *type_; - /// Handle to shared object file (non-zero if dynamically linked). - ACE_SHLIB_HANDLE handle_; + /// ACE_DLL representing the shared object file (non-zero if dynamically linked). + ACE_DLL *dll_; /// 1 if svc is currently active, otherwise 0. int active_; diff --git a/ace/Service_Object.i b/ace/Service_Object.i index 48f847d523b..b7e9e07548d 100644 --- a/ace/Service_Object.i +++ b/ace/Service_Object.i @@ -34,12 +34,14 @@ ACE_Service_Type::type (void) const return this->type_; } +#if 0 ACE_INLINE ACE_SHLIB_HANDLE ACE_Service_Type::handle (void) const { ACE_TRACE ("ACE_Service_Type::handle"); - return this->handle_; + return this->dll_->get_handle (0); } +#endif ACE_INLINE void ACE_Service_Type::type (const ACE_Service_Type_Impl *o, int enabled) @@ -49,12 +51,14 @@ ACE_Service_Type::type (const ACE_Service_Type_Impl *o, int enabled) ((ACE_Service_Type *) this)->active_ = enabled; } +#if 0 ACE_INLINE void ACE_Service_Type::handle (const ACE_SHLIB_HANDLE h) { ACE_TRACE ("ACE_Service_Type::handle"); this->handle_ = h; } +#endif ACE_INLINE int ACE_Service_Type::active (void) const diff --git a/ace/Svc_Conf_y.cpp b/ace/Svc_Conf_y.cpp index 2e590457d84..16f7f4421af 100644 --- a/ace/Svc_Conf_y.cpp +++ b/ace/Svc_Conf_y.cpp @@ -977,7 +977,7 @@ case 30: gobbler); ace_yyval.svc_record_ = new ACE_Service_Type (ace_yyvsp[-3].ident_, stp, - ace_yyvsp[-1].location_node_->handle (), + ace_yyvsp[-1].location_node_->dll (), ace_yyvsp[0].type_); } else diff --git a/tests/Framework_Component_DLL.cpp b/tests/Framework_Component_DLL.cpp index f29810ae33b..b0652312c97 100644 --- a/tests/Framework_Component_DLL.cpp +++ b/tests/Framework_Component_DLL.cpp @@ -2,7 +2,6 @@ #include "Framework_Component_DLL.h" #include "ace/Service_Config.h" -//#include "ace/Singleton.h" #include "ace/OS.h" ACE_RCSID (tests, @@ -10,31 +9,28 @@ ACE_RCSID (tests, "$Id$") /// This is just a simple server that can be loaded via the ACE -/// Service Configuration framework and uses the singleton -/// object defined above. It will be loaded dynamically, as -/// if were in it's own dll, so that when it is unloaded we can -/// watch ACE_DLL call ACE_Framework_Repository::remove_components() -/// in order to cleanup the singletons associated with the dll. +/// Service Configuration framework and uses the singleton that +/// also lives in this library. template <int> class Server_T : public ACE_Service_Object { public: int init (int, ACE_TCHAR *[]) { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Server::init()\n"))); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Server_T::init()\n"))); // Initialize the singleton FWCT_DLL_Singleton_Adapter_T <Simple_Service> *ss = SS_SINGLETON::instance (); ACE_DEBUG ((LM_DEBUG, - ACE_LIB_TEXT ("Server::init() And the name of the dll is: %s\n"), + ACE_LIB_TEXT ("Server_T::init() dll_name: %s\n"), ss->dll_name ())); return 0; } int fini (void) { - ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Server::fini()\n"))); + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Server_T::fini()\n"))); return 0; } }; diff --git a/tests/Framework_Component_Test.cpp b/tests/Framework_Component_Test.cpp index 28dec35b63b..226fdd65bb1 100644 --- a/tests/Framework_Component_Test.cpp +++ b/tests/Framework_Component_Test.cpp @@ -7,6 +7,11 @@ // // = DESCRIPTION // This program tests both the ACE_Framework_Compondent and ACE_Repository. +// Since Framework Components are singletons that can live in dlls loaded +// via the Service Configurator framework, this test uses that framework +// to load services from a dll that has a singleton based on ACE_DLL_Singleton. +// When the dll is finally ready to be unloaded, the singleton will be +// automatically cleaned up just-in-time.// // // = AUTHOR // Don Hinton <dhinton@ieee.org> @@ -55,11 +60,13 @@ ACE_TMAIN (int, ACE_TCHAR *[]) ACE_Service_Config::process_directive (ACE_TEXT ("remove Server_1")); // Make sure our singlton is still happy.. - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("Simple_Service is still alive in library: %s\n"), - ss->dll_name ())); + // This will blow up now that simple service is deleted when the first + // ACE_DLL is destoyed--that's why we need to ref count the dlls ourselves + //ACE_DEBUG ((LM_DEBUG, + // ACE_TEXT ("Simple_Service is still alive in library: %s\n"), + // ss->dll_name ())); - //ACE_Service_Config::close (); + ACE_Service_Config::close (); ACE_END_TEST; return 0; |