summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/klibloader.cpp
Unidiff
Diffstat (limited to 'microkde/kdecore/klibloader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klibloader.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp
index 6d0475a..0b54eb6 100644
--- a/microkde/kdecore/klibloader.cpp
+++ b/microkde/kdecore/klibloader.cpp
@@ -11,50 +11,53 @@
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details. 12 Library General Public License for more details.
13 13
14 You should have received a copy of the GNU Library General Public License 14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to 15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 16 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA. 17 Boston, MA 02111-1307, USA.
18*/ 18*/
19//US #include <config.h> 19//US #include <config.h>
20#include <qclipboard.h> 20#include <qclipboard.h>
21#include <qfile.h> 21#include <qfile.h>
22#include <qtimer.h> 22#include <qtimer.h>
23#include <qobjectdict.h> 23#include <q3objectdict.h>
24#include <qwidgetlist.h>
25#include <qwidget.h> 24#include <qwidget.h>
25#include <qwidget.h>
26//Added by qt3to4:
27#include <Q3CString>
28#include <Q3PtrList>
26 29
27#include "kapplication.h" 30#include "kapplication.h"
28#include "klibloader.h" 31#include "klibloader.h"
29#include "kstandarddirs.h" 32#include "kstandarddirs.h"
30#include "kdebug.h" 33#include "kdebug.h"
31#include "klocale.h" 34#include "klocale.h"
32 35
33/*US 36/*US
34#ifndef NDEBUG 37#ifndef NDEBUG
35#include "ltdl.h" 38#include "ltdl.h"
36#endif 39#endif
37*/ 40*/
38 41
39//US do everything through qlibrary 42//US do everything through qlibrary
40#ifndef DESKTOP_VERSION 43#ifndef DESKTOP_VERSION
41#include <qpe/qpeapplication.h> 44#include <qpe/qpeapplication.h>
42#include <qtopia/qlibrary.h> 45#include <qtopia/qlibrary.h>
43#else 46#else
44#include <qlibrary.h> 47#include <qlibrary.h>
45#endif 48#endif
46 49
47 50
48template class QAsciiDict<KLibrary>; 51template class Q3AsciiDict<KLibrary>;
49 52
50#include <stdlib.h> //getenv 53#include <stdlib.h> //getenv
51 54
52/*US 55/*US
53#if HAVE_DLFCN_H 56#if HAVE_DLFCN_H
54# include <dlfcn.h> 57# include <dlfcn.h>
55#endif 58#endif
56 59
57#ifdef RTLD_GLOBAL 60#ifdef RTLD_GLOBAL
58# define LT_GLOBAL RTLD_GLOBAL 61# define LT_GLOBAL RTLD_GLOBAL
59#else 62#else
60# ifdef DL_GLOBAL 63# ifdef DL_GLOBAL
@@ -111,25 +114,25 @@ KLibrary::KLibrary( const QString& libname, const QString& filename, QLibrary* h
111 m_timer = 0; 114 m_timer = 0;
112} 115}
113 116
114KLibrary::~KLibrary() 117KLibrary::~KLibrary()
115{ 118{
116// kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl; 119// kdDebug(150) << "Deleting KLibrary " << this << " " << m_libname << endl;
117 if ( m_timer && m_timer->isActive() ) 120 if ( m_timer && m_timer->isActive() )
118 m_timer->stop(); 121 m_timer->stop();
119 122
120 // If any object is remaining, delete 123 // If any object is remaining, delete
121 if ( m_objs.count() > 0 ) 124 if ( m_objs.count() > 0 )
122 { 125 {
123 QPtrListIterator<QObject> it( m_objs ); 126 Q3PtrListIterator<QObject> it( m_objs );
124 for ( ; it.current() ; ++it ) 127 for ( ; it.current() ; ++it )
125 { 128 {
126 kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl; 129 kdDebug(150) << "Factory still has object " << it.current() << " " << it.current()->name () << " Library = " << m_libname << endl;
127 disconnect( it.current(), SIGNAL( destroyed() ), 130 disconnect( it.current(), SIGNAL( destroyed() ),
128 this, SLOT( slotObjectDestroyed() ) ); 131 this, SLOT( slotObjectDestroyed() ) );
129 } 132 }
130 m_objs.setAutoDelete(true); 133 m_objs.setAutoDelete(true);
131 m_objs.clear(); 134 m_objs.clear();
132 } 135 }
133 136
134 if ( m_factory ) { 137 if ( m_factory ) {
135 //kdDebug(150) << " ... deleting the factory " << m_factory << endl; 138 //kdDebug(150) << " ... deleting the factory " << m_factory << endl;
@@ -143,25 +146,25 @@ QString KLibrary::name() const
143} 146}
144 147
145QString KLibrary::fileName() const 148QString KLibrary::fileName() const
146{ 149{
147 return m_filename; 150 return m_filename;
148} 151}
149 152
150KLibFactory* KLibrary::factory() 153KLibFactory* KLibrary::factory()
151{ 154{
152 if ( m_factory ) 155 if ( m_factory )
153 return m_factory; 156 return m_factory;
154 157
155 QCString symname; 158 Q3CString symname;
156 symname.sprintf("init_%s", name().latin1() ); 159 symname.sprintf("init_%s", name().latin1() );
157 160
158 void* sym = symbol( symname ); 161 void* sym = symbol( symname );
159 if ( !sym ) 162 if ( !sym )
160 { 163 {
161 qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data()); 164 qDebug("KLibrary: The library %s does not offer an %s function", name().latin1(), symname.data());
162#ifndef NDEBUG 165#ifndef NDEBUG
163//US qDebug("KLibrary: errorcode: %s", lt_dlerror()); 166//US qDebug("KLibrary: errorcode: %s", lt_dlerror());
164#endif 167#endif
165 kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl; 168 kdWarning(150) << "KLibrary: The library " << name().latin1() << " does not offer an init_" << name().latin1() << " function" << endl;
166 return 0; 169 return 0;
167 } 170 }
@@ -296,26 +299,26 @@ KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h)
296//US use instead: 299//US use instead:
297 if (h->resolve("__kde_do_not_unload") != 0) { 300 if (h->resolve("__kde_do_not_unload") != 0) {
298// kdDebug(150) << "Will not unload " << name << endl; 301// kdDebug(150) << "Will not unload " << name << endl;
299 unload_mode = DONT_UNLOAD; 302 unload_mode = DONT_UNLOAD;
300 } else if (h->resolve("__kde_do_unload") != 0) { 303 } else if (h->resolve("__kde_do_unload") != 0) {
301 unload_mode = UNLOAD; 304 unload_mode = UNLOAD;
302 } 305 }
303} 306}
304 307
305class KLibLoaderPrivate 308class KLibLoaderPrivate
306{ 309{
307public: 310public:
308 QPtrList<KLibWrapPrivate> loaded_stack; 311 Q3PtrList<KLibWrapPrivate> loaded_stack;
309 QPtrList<KLibWrapPrivate> pending_close; 312 Q3PtrList<KLibWrapPrivate> pending_close;
310 enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; 313 enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode;
311 314
312 QString errorMessage; 315 QString errorMessage;
313}; 316};
314 317
315KLibLoader* KLibLoader::s_self = 0; 318KLibLoader* KLibLoader::s_self = 0;
316 319
317KLibLoader* KLibLoader::self() 320KLibLoader* KLibLoader::self()
318{ 321{
319 if ( !s_self ) 322 if ( !s_self )
320 s_self = new KLibLoader; 323 s_self = new KLibLoader;
321 return s_self; 324 return s_self;
@@ -339,41 +342,41 @@ KLibLoader::KLibLoader( QObject* parent, const char* name )
339 d->unload_mode = KLibLoaderPrivate::UNKNOWN; 342 d->unload_mode = KLibLoaderPrivate::UNKNOWN;
340 if (getenv("KDE_NOUNLOAD") != 0) 343 if (getenv("KDE_NOUNLOAD") != 0)
341 d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; 344 d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD;
342 else if (getenv("KDE_DOUNLOAD") != 0) 345 else if (getenv("KDE_DOUNLOAD") != 0)
343 d->unload_mode = KLibLoaderPrivate::UNLOAD; 346 d->unload_mode = KLibLoaderPrivate::UNLOAD;
344 d->loaded_stack.setAutoDelete( true ); 347 d->loaded_stack.setAutoDelete( true );
345} 348}
346 349
347KLibLoader::~KLibLoader() 350KLibLoader::~KLibLoader()
348{ 351{
349// kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; 352// kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl;
350 353
351 QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); 354 Q3AsciiDictIterator<KLibWrapPrivate> it( m_libs );
352 for (; it.current(); ++it ) 355 for (; it.current(); ++it )
353 { 356 {
354 kdDebug(150) << "The KLibLoader contains the library " << it.current()->name 357 kdDebug(150) << "The KLibLoader contains the library " << it.current()->name
355 << " (" << it.current()->lib << ")" << endl; 358 << " (" << it.current()->lib << ")" << endl;
356 d->pending_close.append(it.current()); 359 d->pending_close.append(it.current());
357 } 360 }
358 361
359 close_pending(0); 362 close_pending(0);
360 363
361 delete d; 364 delete d;
362} 365}
363 366
364//static 367//static
365QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) 368QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ )
366{ 369{
367 QCString libname( name ); 370 Q3CString libname( name );
368 371
369 // only append ".la" if there is no extension 372 // only append ".la" if there is no extension
370 // this allows to load non-libtool libraries as well 373 // this allows to load non-libtool libraries as well
371 // (mhk, 20000228) 374 // (mhk, 20000228)
372 int pos = libname.findRev('/'); 375 int pos = libname.findRev('/');
373 if (pos < 0) 376 if (pos < 0)
374 pos = 0; 377 pos = 0;
375/*US 378/*US
376 if (libname.find('.', pos) < 0) { 379 if (libname.find('.', pos) < 0) {
377 libname += ".la"; 380 libname += ".la";
378 } 381 }
379*/ 382*/
@@ -412,25 +415,25 @@ QString KLibLoader::findLibrary( const char * name/*US , const KInstance * insta
412//US libfile = instance->dirs()->findResource( "lib", libname ); 415//US libfile = instance->dirs()->findResource( "lib", libname );
413 libfile = KGlobal::dirs()->findResource( "lib", libname ); 416 libfile = KGlobal::dirs()->findResource( "lib", libname );
414 //qDebug("libfile2 = %s ",libfile.latin1() ); 417 //qDebug("libfile2 = %s ",libfile.latin1() );
415#ifndef NDEBUG 418#ifndef NDEBUG
416 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules 419 if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules
417 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; 420 kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl;
418#endif 421#endif
419 } 422 }
420 if ( libfile.isEmpty() ) 423 if ( libfile.isEmpty() )
421 { 424 {
422#ifndef NDEBUG 425#ifndef NDEBUG
423 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; 426 kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl;
424 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); 427 self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(QString(libname));
425 428
426 qDebug("KLibLoader::library could not find library: %s", libname.data()); 429 qDebug("KLibLoader::library could not find library: %s", libname.data());
427#endif 430#endif
428 431
429 } 432 }
430 else 433 else
431 self()->d->errorMessage = QString::null; 434 self()->d->errorMessage = QString::null;
432 } 435 }
433 436
434 //qDebug("return libfile = %s ",libfile.latin1() ); 437 //qDebug("return libfile = %s ",libfile.latin1() );
435 return libfile; 438 return libfile;
436} 439}
@@ -460,25 +463,25 @@ KLibrary* KLibLoader::library( const char *name )
460 if (!name) 463 if (!name)
461 return 0; 464 return 0;
462 465
463 KLibWrapPrivate* wrap = m_libs[name]; 466 KLibWrapPrivate* wrap = m_libs[name];
464 if (wrap) { 467 if (wrap) {
465 /* Nothing to do to load the library. */ 468 /* Nothing to do to load the library. */
466 wrap->ref_count++; 469 wrap->ref_count++;
467 return wrap->lib; 470 return wrap->lib;
468 } 471 }
469 472
470 /* Test if this library was loaded at some time, but got 473 /* Test if this library was loaded at some time, but got
471 unloaded meanwhile, whithout being dlclose()'ed. */ 474 unloaded meanwhile, whithout being dlclose()'ed. */
472 QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); 475 Q3PtrListIterator<KLibWrapPrivate> it(d->loaded_stack);
473 for (; it.current(); ++it) { 476 for (; it.current(); ++it) {
474 if (it.current()->name == name) 477 if (it.current()->name == name)
475 wrap = it.current(); 478 wrap = it.current();
476 } 479 }
477 480
478 if (wrap) { 481 if (wrap) {
479 d->pending_close.removeRef(wrap); 482 d->pending_close.removeRef(wrap);
480 if (!wrap->lib) { 483 if (!wrap->lib) {
481 /* This lib only was in loaded_stack, but not in m_libs. */ 484 /* This lib only was in loaded_stack, but not in m_libs. */
482 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); 485 wrap->lib = new KLibrary( name, wrap->filename, wrap->handle );
483 } 486 }
484 wrap->ref_count++; 487 wrap->ref_count++;
@@ -541,44 +544,44 @@ KLibFactory* KLibLoader::factory( const char* name )
541{ 544{
542 KLibrary* lib = library( name ); 545 KLibrary* lib = library( name );
543 if ( !lib ) 546 if ( !lib )
544 return 0; 547 return 0;
545 548
546 return lib->factory(); 549 return lib->factory();
547} 550}
548 551
549void KLibLoader::slotLibraryDestroyed() 552void KLibLoader::slotLibraryDestroyed()
550{ 553{
551 const KLibrary *lib = static_cast<const KLibrary *>( sender() ); 554 const KLibrary *lib = static_cast<const KLibrary *>( sender() );
552 555
553 QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); 556 Q3AsciiDictIterator<KLibWrapPrivate> it( m_libs );
554 for (; it.current(); ++it ) 557 for (; it.current(); ++it )
555 if ( it.current()->lib == lib ) 558 if ( it.current()->lib == lib )
556 { 559 {
557 KLibWrapPrivate *wrap = it.current(); 560 KLibWrapPrivate *wrap = it.current();
558 wrap->lib = 0; /* the KLibrary object is already away */ 561 wrap->lib = 0; /* the KLibrary object is already away */
559 m_libs.remove( it.currentKey() ); 562 m_libs.remove( it.currentKey() );
560 close_pending( wrap ); 563 close_pending( wrap );
561 return; 564 return;
562 } 565 }
563} 566}
564 567
565void KLibLoader::close_pending(KLibWrapPrivate *wrap) 568void KLibLoader::close_pending(KLibWrapPrivate *wrap)
566{ 569{
567 if (wrap && !d->pending_close.containsRef( wrap )) 570 if (wrap && !d->pending_close.containsRef( wrap ))
568 d->pending_close.append( wrap ); 571 d->pending_close.append( wrap );
569 572
570 /* First delete all KLibrary objects in pending_close, but _don't_ unload 573 /* First delete all KLibrary objects in pending_close, but _don't_ unload
571 the DSO behind it. */ 574 the DSO behind it. */
572 QPtrListIterator<KLibWrapPrivate> it(d->pending_close); 575 Q3PtrListIterator<KLibWrapPrivate> it(d->pending_close);
573 for (; it.current(); ++it) { 576 for (; it.current(); ++it) {
574 wrap = it.current(); 577 wrap = it.current();
575 if (wrap->lib) { 578 if (wrap->lib) {
576 disconnect( wrap->lib, SIGNAL( destroyed() ), 579 disconnect( wrap->lib, SIGNAL( destroyed() ),
577 this, SLOT( slotLibraryDestroyed() ) ); 580 this, SLOT( slotLibraryDestroyed() ) );
578 delete wrap->lib; 581 delete wrap->lib;
579 wrap->lib = 0; 582 wrap->lib = 0;
580 } 583 }
581 } 584 }
582 585
583 if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; 586 if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return;
584 587