diff options
author | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-21 20:33:21 +0000 |
---|---|---|
committer | schmidt <douglascraigschmidt@users.noreply.github.com> | 1998-11-21 20:33:21 +0000 |
commit | afce6e0ff6099470fd515cb92c13b232f48203ce (patch) | |
tree | b43b73c0ba995750d935fc7c4f21bed078d73b58 /ace | |
parent | 3d043f0e1aaa77f1b4b310c7078e31477bb39c17 (diff) | |
download | ATCD-afce6e0ff6099470fd515cb92c13b232f48203ce.tar.gz |
.
Diffstat (limited to 'ace')
-rw-r--r-- | ace/DLL.cpp | 71 | ||||
-rw-r--r-- | ace/DLL.h | 57 |
2 files changed, 73 insertions, 55 deletions
diff --git a/ace/DLL.cpp b/ace/DLL.cpp index b044e04e0cd..997067432f9 100644 --- a/ace/DLL.cpp +++ b/ace/DLL.cpp @@ -6,24 +6,31 @@ ACE_RCSID(ace, DLL, "$Id$") -// Implementation of the methods which provide an abstraction of -// dynamically linked library. +ACE_DLL::ACE_DLL (int close_on_destruction) + : handle_ (ACE_SHLIB_INVALID_HANDLE), + close_on_destruction_ (close_on_destruction) +{ +} -// If the library name and the opening mode are specified than on object -// creation the library is implicitly opened. +// If the library name and the opening mode are specified than on +// object creation the library is implicitly opened. ACE_DLL::ACE_DLL (ACE_DL_TYPE dll_name, - int mode) - :close_mode_ (0) + int open_mode, + int close_on_destruction) + : close_on_destruction_ (close_on_destruction) { - // If the library name is not given dont open the file. - if (dll_name !=0) + // If the library name is not given don't open the file. + if (dll_name != 0) { - this->handle_ = ACE_OS::dlopen (dll_name, mode); + this->handle_ = ACE_OS::dlopen (dll_name, open_mode); + // The ACE_SHLIB_HANDLE object is obtained. + if (this->handle_ == 0) ACE_ERROR ((LM_ERROR, - "%s\n", this->error ())); + "%s\n", + this->error ())); } } @@ -33,8 +40,9 @@ ACE_DLL::ACE_DLL (ACE_DL_TYPE dll_name, ACE_DLL::~ACE_DLL (void) { - // CLose the library only if it hasnt been already. - if (this->close_mode_ == 0 && this->handle_ != ACE_SHLIB_INVALID_HANDLE) + // CLose the library only if it hasn't been already. + if (this->close_on_destruction_ != 0 + && this->handle_ != ACE_SHLIB_INVALID_HANDLE) this->close (); } @@ -51,16 +59,17 @@ ACE_DLL::~ACE_DLL (void) int ACE_DLL::open (ACE_DL_TYPE dll_name, - int mode) + int open_mode, + int close_on_destruction) { - // This check is necessary as the library could be opened - // more than once without closing it which would cause handle - // memory leaks. - if (this->handle_ != ACE_SHLIB_INVALID_HANDLE) - this->close (); + // This check is necessary as the library could be opened more than + // once without closing it which would cause handle memory leaks. + this->close (); + + this->close_on_destruction_ = close_on_destruction; // The ACE_SHLIB_HANDLE object is obtained. - this->handle_ = ACE_OS::dlopen (dll_name, mode); + this->handle_ = ACE_OS::dlopen (dll_name, open_mode); if (this->handle_ == 0) ACE_ERROR_RETURN ((LM_ERROR, @@ -84,8 +93,8 @@ int ACE_DLL::close (void) { // The handle is checked to see whether the library is closed - // already. If not, it is closed and the handle is made invalid which - // portrays that it is closed. + // already. If not, it is closed and the handle is made invalid + // which portrays that it is closed. if (this->handle_ != ACE_SHLIB_INVALID_HANDLE) { int retval = ACE_OS::dlclose (this->handle_); @@ -104,19 +113,19 @@ ACE_DLL::error (void) return ACE_OS::dlerror(); } -// Return the handle to the user either temporarily or forever, -// thus orphaning it. If 0 means the user wants the handle forever -// and if 1 means the user temporarily wants to take the handle. +// Return the handle to the user either temporarily or forever, thus +// orphaning it. If 0 means the user wants the handle forever and if 1 +// means the user temporarily wants to take the handle. ACE_SHLIB_HANDLE -ACE_DLL::get_handle (int orphan_mode) +ACE_DLL::get_handle (int become_owner) { - // Since the handle is getting orphaned we lose rights to close - // it on destruction. The new controller has to do it explicitly. - - if (orphan_mode == 0) - this->close_mode_ = 1; + // Since the caller is becoming the owner of the handle we lose + // rights to close it on destruction. The new controller has to do + // it explicitly. + if (become_owner == 0) + this->close_on_destruction_ = 0; - // Return the handle as requested by the user. + // Return the handle requested by the user. return this->handle_; } diff --git a/ace/DLL.h b/ace/DLL.h index cc00d5b3924..79abdc0f616 100644 --- a/ace/DLL.h +++ b/ace/DLL.h @@ -37,48 +37,57 @@ class ACE_Export ACE_DLL public: // = Initialization and termination methods. + ACE_DLL (int close_on_destruction = 0); + // Default constructor. + ACE_DLL (ACE_DL_TYPE dll_name = 0, - int mode = ACE_DEFAULT_SHLIB_MODE); - // Another way of initialisation wherein the user gives the - // library name and mode and thus the opening of the library is - // done implicitly along with the auto_close feature. - - ~ACE_DLL (void); - // Called when object is destroyed. + int open_mode = ACE_DEFAULT_SHLIB_MODE, + int close_on_destruction = 0); + // This is the library open operation that uses ACE_SHLIB_HANDLE + // object internally to open the library. The default mode is + // RTLD_LAZY which means that the identifier symbols are loaded but + // not the symbols for the functions. They are loaded dynamically + // on need. The other modes include: RTLD_NOW All necessary + // relocations are performed when the object is first loaded. + // RTLD_GLOBAL The object symbols are made available for the + // relocation processing of any other object. int open (ACE_DL_TYPE dll_name, - int mode = ACE_DEFAULT_SHLIB_MODE); - // This is the library open operation which uses ACE_SHLIB_HANDLE + int open_mode = ACE_DEFAULT_SHLIB_MODE, + int close_on_destruction = 0); + // This is the library open operation that uses ACE_SHLIB_HANDLE // object internally to open the library. The default mode is // RTLD_LAZY which means that the identifier symbols are loaded but - // not the symbols for the functions. - // They are loaded dynamically on need. - // The other modes include: - // RTLD_NOW All necessary relocations are performed when the - // object is first loaded. - // RTLD_GLOBAL The object symbols are made available for the - // relocation processing of any other object. + // not the symbols for the functions. They are loaded dynamically + // on need. The other modes include: RTLD_NOW All necessary + // relocations are performed when the object is first loaded. + // RTLD_GLOBAL The object symbols are made available for the + // relocation processing of any other object. - void *symbol (ACE_DL_TYPE sym_name); - // The symbol reference is returned corresponding to the symbol - // name. + ~ACE_DLL (void); + // Called when object is destroyed. int close (void); // The library is closed. + void *symbol (ACE_DL_TYPE sym_name); + // The symbol reference is returned corresponding to the symbol + // name. + char *error (void); // The error on any of the dl-procedures. - ACE_SHLIB_HANDLE get_handle (int orphan_mode); - // Return the handle to the user either forever or for temporary use. + ACE_SHLIB_HANDLE get_handle (int become_owner = 0); + // Return the handle to the user either forever or for temporary + // use. private: ACE_SHLIB_HANDLE handle_; // This is the reference to the library. - int close_mode_; - // This is the flag representing the special close_on_destruction - // feature. + int close_on_destruction_; + // This flag keeps track of whether we should close the handle + // automatically when the destructor is run. }; #endif /* ACE_DLL_H */ |