-rw-r--r-- | microkde/kdecore/klibloader.cpp | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/microkde/kdecore/klibloader.cpp b/microkde/kdecore/klibloader.cpp index 9eee912..1394154 100644 --- a/microkde/kdecore/klibloader.cpp +++ b/microkde/kdecore/klibloader.cpp | |||
@@ -189,399 +189,406 @@ void* KLibrary::symbol( const char* symname ) const | |||
189 | if ( !sym ) | 189 | if ( !sym ) |
190 | { | 190 | { |
191 | //US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl; | 191 | //US kdWarning(150) << "KLibrary: " << lt_dlerror() << endl; |
192 | return 0; | 192 | return 0; |
193 | } | 193 | } |
194 | 194 | ||
195 | return sym; | 195 | return sym; |
196 | } | 196 | } |
197 | 197 | ||
198 | bool KLibrary::hasSymbol( const char* symname ) const | 198 | bool KLibrary::hasSymbol( const char* symname ) const |
199 | { | 199 | { |
200 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); | 200 | //US void* sym = lt_dlsym( (lt_dlhandle) m_handle, symname ); |
201 | void* sym = m_handle->resolve( symname ); | 201 | void* sym = m_handle->resolve( symname ); |
202 | return (sym != 0L ); | 202 | return (sym != 0L ); |
203 | } | 203 | } |
204 | 204 | ||
205 | void KLibrary::unload() const | 205 | void KLibrary::unload() const |
206 | { | 206 | { |
207 | if (KLibLoader::s_self) | 207 | if (KLibLoader::s_self) |
208 | KLibLoader::s_self->unloadLibrary(QFile::encodeName(name())); | 208 | KLibLoader::s_self->unloadLibrary(QFile::encodeName(name())); |
209 | } | 209 | } |
210 | 210 | ||
211 | void KLibrary::slotObjectCreated( QObject *obj ) | 211 | void KLibrary::slotObjectCreated( QObject *obj ) |
212 | { | 212 | { |
213 | if ( !obj ) | 213 | if ( !obj ) |
214 | return; | 214 | return; |
215 | 215 | ||
216 | if ( m_timer && m_timer->isActive() ) | 216 | if ( m_timer && m_timer->isActive() ) |
217 | m_timer->stop(); | 217 | m_timer->stop(); |
218 | 218 | ||
219 | if ( m_objs.containsRef( obj ) ) | 219 | if ( m_objs.containsRef( obj ) ) |
220 | return; // we know this object already | 220 | return; // we know this object already |
221 | 221 | ||
222 | connect( obj, SIGNAL( destroyed() ), | 222 | connect( obj, SIGNAL( destroyed() ), |
223 | this, SLOT( slotObjectDestroyed() ) ); | 223 | this, SLOT( slotObjectDestroyed() ) ); |
224 | 224 | ||
225 | m_objs.append( obj ); | 225 | m_objs.append( obj ); |
226 | } | 226 | } |
227 | 227 | ||
228 | void KLibrary::slotObjectDestroyed() | 228 | void KLibrary::slotObjectDestroyed() |
229 | { | 229 | { |
230 | m_objs.removeRef( sender() ); | 230 | m_objs.removeRef( sender() ); |
231 | 231 | ||
232 | if ( m_objs.count() == 0 ) | 232 | if ( m_objs.count() == 0 ) |
233 | { | 233 | { |
234 | // kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!" | 234 | // kdDebug(150) << "KLibrary: shutdown timer for " << name() << " started!" |
235 | // << endl; | 235 | // << endl; |
236 | 236 | ||
237 | if ( !m_timer ) | 237 | if ( !m_timer ) |
238 | { | 238 | { |
239 | m_timer = new QTimer( this, "klibrary_shutdown_timer" ); | 239 | m_timer = new QTimer( this, "klibrary_shutdown_timer" ); |
240 | connect( m_timer, SIGNAL( timeout() ), | 240 | connect( m_timer, SIGNAL( timeout() ), |
241 | this, SLOT( slotTimeout() ) ); | 241 | this, SLOT( slotTimeout() ) ); |
242 | } | 242 | } |
243 | 243 | ||
244 | // as long as it's not stable make the timeout short, for debugging | 244 | // as long as it's not stable make the timeout short, for debugging |
245 | // pleasure (matz) | 245 | // pleasure (matz) |
246 | //m_timer->start( 1000*60, true ); | 246 | //m_timer->start( 1000*60, true ); |
247 | m_timer->start( 1000*10, true ); | 247 | m_timer->start( 1000*10, true ); |
248 | } | 248 | } |
249 | } | 249 | } |
250 | 250 | ||
251 | void KLibrary::slotTimeout() | 251 | void KLibrary::slotTimeout() |
252 | { | 252 | { |
253 | if ( m_objs.count() != 0 ) | 253 | if ( m_objs.count() != 0 ) |
254 | return; | 254 | return; |
255 | 255 | ||
256 | /* Don't go through KLibLoader::unloadLibrary(), because that uses the | 256 | /* Don't go through KLibLoader::unloadLibrary(), because that uses the |
257 | ref counter, but this timeout means to unconditionally close this library | 257 | ref counter, but this timeout means to unconditionally close this library |
258 | The destroyed() signal will take care to remove us from all lists. | 258 | The destroyed() signal will take care to remove us from all lists. |
259 | */ | 259 | */ |
260 | delete this; | 260 | delete this; |
261 | } | 261 | } |
262 | 262 | ||
263 | // ------------------------------------------------- | 263 | // ------------------------------------------------- |
264 | 264 | ||
265 | /* This helper class is needed, because KLibraries can go away without | 265 | /* This helper class is needed, because KLibraries can go away without |
266 | being unloaded. So we need some info about KLibraries even after its | 266 | being unloaded. So we need some info about KLibraries even after its |
267 | death. */ | 267 | death. */ |
268 | class KLibWrapPrivate | 268 | class KLibWrapPrivate |
269 | { | 269 | { |
270 | public: | 270 | public: |
271 | //US KLibWrapPrivate(KLibrary *l, lt_dlhandle h); | 271 | //US KLibWrapPrivate(KLibrary *l, lt_dlhandle h); |
272 | KLibWrapPrivate(KLibrary *l, QLibrary* h); | 272 | KLibWrapPrivate(KLibrary *l, QLibrary* h); |
273 | 273 | ||
274 | KLibrary *lib; | 274 | KLibrary *lib; |
275 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; | 275 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; |
276 | int ref_count; | 276 | int ref_count; |
277 | //US lt_dlhandle handle; | 277 | //US lt_dlhandle handle; |
278 | QLibrary *handle; | 278 | QLibrary *handle; |
279 | QString name; | 279 | QString name; |
280 | QString filename; | 280 | QString filename; |
281 | }; | 281 | }; |
282 | 282 | ||
283 | //US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h) | 283 | //US KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, lt_dlhandle h) |
284 | KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) | 284 | KLibWrapPrivate::KLibWrapPrivate(KLibrary *l, QLibrary* h) |
285 | : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) | 285 | : lib(l), ref_count(1), handle(h), name(l->name()), filename(l->fileName()) |
286 | { | 286 | { |
287 | unload_mode = UNKNOWN; | 287 | unload_mode = UNKNOWN; |
288 | /*US | 288 | /*US |
289 | if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { | 289 | if (lt_dlsym(handle, "__kde_do_not_unload") != 0) { |
290 | // kdDebug(150) << "Will not unload " << name << endl; | 290 | // kdDebug(150) << "Will not unload " << name << endl; |
291 | unload_mode = DONT_UNLOAD; | 291 | unload_mode = DONT_UNLOAD; |
292 | } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { | 292 | } else if (lt_dlsym(handle, "__kde_do_unload") != 0) { |
293 | unload_mode = UNLOAD; | 293 | unload_mode = UNLOAD; |
294 | } | 294 | } |
295 | */ | 295 | */ |
296 | //US use instead: | 296 | //US use instead: |
297 | if (h->resolve("__kde_do_not_unload") != 0) { | 297 | if (h->resolve("__kde_do_not_unload") != 0) { |
298 | // kdDebug(150) << "Will not unload " << name << endl; | 298 | // kdDebug(150) << "Will not unload " << name << endl; |
299 | unload_mode = DONT_UNLOAD; | 299 | unload_mode = DONT_UNLOAD; |
300 | } else if (h->resolve("__kde_do_unload") != 0) { | 300 | } else if (h->resolve("__kde_do_unload") != 0) { |
301 | unload_mode = UNLOAD; | 301 | unload_mode = UNLOAD; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | class KLibLoaderPrivate | 305 | class KLibLoaderPrivate |
306 | { | 306 | { |
307 | public: | 307 | public: |
308 | QPtrList<KLibWrapPrivate> loaded_stack; | 308 | QPtrList<KLibWrapPrivate> loaded_stack; |
309 | QPtrList<KLibWrapPrivate> pending_close; | 309 | QPtrList<KLibWrapPrivate> pending_close; |
310 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; | 310 | enum {UNKNOWN, UNLOAD, DONT_UNLOAD} unload_mode; |
311 | 311 | ||
312 | QString errorMessage; | 312 | QString errorMessage; |
313 | }; | 313 | }; |
314 | 314 | ||
315 | KLibLoader* KLibLoader::s_self = 0; | 315 | KLibLoader* KLibLoader::s_self = 0; |
316 | 316 | ||
317 | KLibLoader* KLibLoader::self() | 317 | KLibLoader* KLibLoader::self() |
318 | { | 318 | { |
319 | if ( !s_self ) | 319 | if ( !s_self ) |
320 | s_self = new KLibLoader; | 320 | s_self = new KLibLoader; |
321 | return s_self; | 321 | return s_self; |
322 | } | 322 | } |
323 | 323 | ||
324 | void KLibLoader::cleanUp() | 324 | void KLibLoader::cleanUp() |
325 | { | 325 | { |
326 | if ( !s_self ) | 326 | if ( !s_self ) |
327 | return; | 327 | return; |
328 | 328 | ||
329 | delete s_self; | 329 | delete s_self; |
330 | s_self = 0; | 330 | s_self = 0; |
331 | } | 331 | } |
332 | 332 | ||
333 | KLibLoader::KLibLoader( QObject* parent, const char* name ) | 333 | KLibLoader::KLibLoader( QObject* parent, const char* name ) |
334 | : QObject( parent, name ) | 334 | : QObject( parent, name ) |
335 | { | 335 | { |
336 | s_self = this; | 336 | s_self = this; |
337 | d = new KLibLoaderPrivate; | 337 | d = new KLibLoaderPrivate; |
338 | //US lt_dlinit(); | 338 | //US lt_dlinit(); |
339 | d->unload_mode = KLibLoaderPrivate::UNKNOWN; | 339 | d->unload_mode = KLibLoaderPrivate::UNKNOWN; |
340 | if (getenv("KDE_NOUNLOAD") != 0) | 340 | if (getenv("KDE_NOUNLOAD") != 0) |
341 | d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; | 341 | d->unload_mode = KLibLoaderPrivate::DONT_UNLOAD; |
342 | else if (getenv("KDE_DOUNLOAD") != 0) | 342 | else if (getenv("KDE_DOUNLOAD") != 0) |
343 | d->unload_mode = KLibLoaderPrivate::UNLOAD; | 343 | d->unload_mode = KLibLoaderPrivate::UNLOAD; |
344 | d->loaded_stack.setAutoDelete( true ); | 344 | d->loaded_stack.setAutoDelete( true ); |
345 | } | 345 | } |
346 | 346 | ||
347 | KLibLoader::~KLibLoader() | 347 | KLibLoader::~KLibLoader() |
348 | { | 348 | { |
349 | // kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; | 349 | // kdDebug(150) << "Deleting KLibLoader " << this << " " << name() << endl; |
350 | 350 | ||
351 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); | 351 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); |
352 | for (; it.current(); ++it ) | 352 | for (; it.current(); ++it ) |
353 | { | 353 | { |
354 | kdDebug(150) << "The KLibLoader contains the library " << it.current()->name | 354 | kdDebug(150) << "The KLibLoader contains the library " << it.current()->name |
355 | << " (" << it.current()->lib << ")" << endl; | 355 | << " (" << it.current()->lib << ")" << endl; |
356 | d->pending_close.append(it.current()); | 356 | d->pending_close.append(it.current()); |
357 | } | 357 | } |
358 | 358 | ||
359 | close_pending(0); | 359 | close_pending(0); |
360 | 360 | ||
361 | delete d; | 361 | delete d; |
362 | } | 362 | } |
363 | 363 | ||
364 | //static | 364 | //static |
365 | QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) | 365 | QString KLibLoader::findLibrary( const char * name/*US , const KInstance * instance*/ ) |
366 | { | 366 | { |
367 | QCString libname( name ); | 367 | QCString libname( name ); |
368 | 368 | ||
369 | // only append ".la" if there is no extension | 369 | // only append ".la" if there is no extension |
370 | // this allows to load non-libtool libraries as well | 370 | // this allows to load non-libtool libraries as well |
371 | // (mhk, 20000228) | 371 | // (mhk, 20000228) |
372 | int pos = libname.findRev('/'); | 372 | int pos = libname.findRev('/'); |
373 | if (pos < 0) | 373 | if (pos < 0) |
374 | pos = 0; | 374 | pos = 0; |
375 | /*US | 375 | /*US |
376 | if (libname.find('.', pos) < 0) { | 376 | if (libname.find('.', pos) < 0) { |
377 | libname += ".la"; | 377 | libname += ".la"; |
378 | } | 378 | } |
379 | */ | 379 | */ |
380 | //US in the microedition we work only with shared libraries. | 380 | //US in the microedition we work only with shared libraries. |
381 | |||
381 | if (libname.find('.', pos) < 0) { | 382 | if (libname.find('.', pos) < 0) { |
383 | #ifdef _WIN32_ | ||
384 | libname += ".dll"; | ||
385 | #else | ||
382 | libname += ".so"; | 386 | libname += ".so"; |
387 | #endif | ||
383 | } | 388 | } |
384 | 389 | ||
385 | // only look up the file if it is not an absolute filename | 390 | // only look up the file if it is not an absolute filename |
386 | // (mhk, 20000228) | 391 | // (mhk, 20000228) |
387 | QString libfile; | 392 | QString libfile; |
388 | if (libname[0] == '/') | 393 | if (libname[0] == '/') |
389 | libfile = libname; | 394 | libfile = libname; |
390 | else | 395 | else |
391 | { | 396 | { |
392 | //US at this point the libname must exist as real filesname. No expansions will be made later | 397 | //US at this point the libname must exist as real filesname. No expansions will be made later |
393 | // in findResources. Because of that we prepend the lib prefix here to the name | 398 | // in findResources. Because of that we prepend the lib prefix here to the name |
394 | //US I add also the "lib" prefix. I do not how could this could have worked before without it? | 399 | //US I add also the "lib" prefix. I do not how could this could have worked before without it? |
400 | #ifndef _WIN32_ | ||
395 | libname.insert(pos, "lib"); | 401 | libname.insert(pos, "lib"); |
402 | #endif | ||
396 | 403 | ||
397 | 404 | ||
398 | //US libfile = instance->dirs()->findResource( "module", libname ); | 405 | //US libfile = instance->dirs()->findResource( "module", libname ); |
399 | //qDebug("libname = %s ",libname.data() ); | 406 | //qDebug("libname = %s ",libname.data() ); |
400 | libfile = KGlobal::dirs()->findResource( "module", libname ); | 407 | libfile = KGlobal::dirs()->findResource( "module", libname ); |
401 | //qDebug("libfile = %s ",libfile.latin1() ); | 408 | //qDebug("libfile = %s ",libfile.latin1() ); |
402 | 409 | ||
403 | if ( libfile.isEmpty() ) | 410 | if ( libfile.isEmpty() ) |
404 | { | 411 | { |
405 | //US libfile = instance->dirs()->findResource( "lib", libname ); | 412 | //US libfile = instance->dirs()->findResource( "lib", libname ); |
406 | libfile = KGlobal::dirs()->findResource( "lib", libname ); | 413 | libfile = KGlobal::dirs()->findResource( "lib", libname ); |
407 | //qDebug("libfile2 = %s ",libfile.latin1() ); | 414 | //qDebug("libfile2 = %s ",libfile.latin1() ); |
408 | #ifndef NDEBUG | 415 | #ifndef NDEBUG |
409 | if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules | 416 | if ( !libfile.isEmpty() && libname.left(3) == "lib" ) // don't warn for kdeinit modules |
410 | kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; | 417 | kdDebug(150) << "library " << libname << " not found under 'module' but under 'lib'" << endl; |
411 | #endif | 418 | #endif |
412 | } | 419 | } |
413 | if ( libfile.isEmpty() ) | 420 | if ( libfile.isEmpty() ) |
414 | { | 421 | { |
415 | #ifndef NDEBUG | 422 | #ifndef NDEBUG |
416 | kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; | 423 | kdDebug(150) << "library=" << libname << ": No file names " << libname.data() << " found in paths." << endl; |
417 | self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); | 424 | self()->d->errorMessage = i18n("Library files for \"%1\" not found in paths").arg(libname); |
418 | 425 | ||
419 | qDebug("KLibLoader::library could not find library: %s", libname.data()); | 426 | qDebug("KLibLoader::library could not find library: %s", libname.data()); |
420 | #endif | 427 | #endif |
421 | 428 | ||
422 | } | 429 | } |
423 | else | 430 | else |
424 | self()->d->errorMessage = QString::null; | 431 | self()->d->errorMessage = QString::null; |
425 | } | 432 | } |
426 | 433 | ||
427 | //qDebug("return libfile = %s ",libfile.latin1() ); | 434 | //qDebug("return libfile = %s ",libfile.latin1() ); |
428 | return libfile; | 435 | return libfile; |
429 | } | 436 | } |
430 | 437 | ||
431 | 438 | ||
432 | KLibrary* KLibLoader::globalLibrary( const char *name ) | 439 | KLibrary* KLibLoader::globalLibrary( const char *name ) |
433 | { | 440 | { |
434 | KLibrary *tmp; | 441 | KLibrary *tmp; |
435 | /*US | 442 | /*US |
436 | int olt_dlopen_flag = lt_dlopen_flag; | 443 | int olt_dlopen_flag = lt_dlopen_flag; |
437 | 444 | ||
438 | lt_dlopen_flag |= LT_GLOBAL; | 445 | lt_dlopen_flag |= LT_GLOBAL; |
439 | kdDebug(150) << "Loading the next library global with flag " | 446 | kdDebug(150) << "Loading the next library global with flag " |
440 | << lt_dlopen_flag | 447 | << lt_dlopen_flag |
441 | << "." << endl; | 448 | << "." << endl; |
442 | */ | 449 | */ |
443 | tmp = library(name); | 450 | tmp = library(name); |
444 | /*US | 451 | /*US |
445 | lt_dlopen_flag = olt_dlopen_flag; | 452 | lt_dlopen_flag = olt_dlopen_flag; |
446 | */ | 453 | */ |
447 | return tmp; | 454 | return tmp; |
448 | } | 455 | } |
449 | 456 | ||
450 | 457 | ||
451 | KLibrary* KLibLoader::library( const char *name ) | 458 | KLibrary* KLibLoader::library( const char *name ) |
452 | { | 459 | { |
453 | if (!name) | 460 | if (!name) |
454 | return 0; | 461 | return 0; |
455 | 462 | ||
456 | KLibWrapPrivate* wrap = m_libs[name]; | 463 | KLibWrapPrivate* wrap = m_libs[name]; |
457 | if (wrap) { | 464 | if (wrap) { |
458 | /* Nothing to do to load the library. */ | 465 | /* Nothing to do to load the library. */ |
459 | wrap->ref_count++; | 466 | wrap->ref_count++; |
460 | return wrap->lib; | 467 | return wrap->lib; |
461 | } | 468 | } |
462 | 469 | ||
463 | /* Test if this library was loaded at some time, but got | 470 | /* Test if this library was loaded at some time, but got |
464 | unloaded meanwhile, whithout being dlclose()'ed. */ | 471 | unloaded meanwhile, whithout being dlclose()'ed. */ |
465 | QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); | 472 | QPtrListIterator<KLibWrapPrivate> it(d->loaded_stack); |
466 | for (; it.current(); ++it) { | 473 | for (; it.current(); ++it) { |
467 | if (it.current()->name == name) | 474 | if (it.current()->name == name) |
468 | wrap = it.current(); | 475 | wrap = it.current(); |
469 | } | 476 | } |
470 | 477 | ||
471 | if (wrap) { | 478 | if (wrap) { |
472 | d->pending_close.removeRef(wrap); | 479 | d->pending_close.removeRef(wrap); |
473 | if (!wrap->lib) { | 480 | if (!wrap->lib) { |
474 | /* This lib only was in loaded_stack, but not in m_libs. */ | 481 | /* This lib only was in loaded_stack, but not in m_libs. */ |
475 | wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); | 482 | wrap->lib = new KLibrary( name, wrap->filename, wrap->handle ); |
476 | } | 483 | } |
477 | wrap->ref_count++; | 484 | wrap->ref_count++; |
478 | } else { | 485 | } else { |
479 | QString libfile = findLibrary( name ); | 486 | QString libfile = findLibrary( name ); |
480 | if ( libfile.isEmpty() ) | 487 | if ( libfile.isEmpty() ) |
481 | return 0; | 488 | return 0; |
482 | #ifdef DESKTOP_VERSION | 489 | #ifdef DESKTOP_VERSION |
483 | QLibrary *qlib = new QLibrary( libfile.latin1() ); | 490 | QLibrary *qlib = new QLibrary( libfile.latin1() ); |
484 | #else | 491 | #else |
485 | QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); | 492 | QLibrary *qlib = new QLibrary( libfile.latin1(), QLibrary::Immediately ); |
486 | #endif | 493 | #endif |
487 | 494 | ||
488 | //US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); | 495 | //US lt_dlhandle handle = lt_dlopen( libfile.latin1() ); |
489 | //US if ( !handle ) | 496 | //US if ( !handle ) |
490 | if ( !qlib ) | 497 | if ( !qlib ) |
491 | { | 498 | { |
492 | //US const char* errmsg = lt_dlerror(); | 499 | //US const char* errmsg = lt_dlerror(); |
493 | char* errmsg; | 500 | char* errmsg; |
494 | sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1()); | 501 | sprintf(errmsg, "KLibLoader::library could not load library: %s", libfile.latin1()); |
495 | qDebug(errmsg); | 502 | qDebug(errmsg); |
496 | 503 | ||
497 | if(errmsg) | 504 | if(errmsg) |
498 | d->errorMessage = QString::fromLatin1(errmsg); | 505 | d->errorMessage = QString::fromLatin1(errmsg); |
499 | else | 506 | else |
500 | d->errorMessage = QString::null; | 507 | d->errorMessage = QString::null; |
501 | kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl; | 508 | kdWarning(150) << "library=" << name << ": file=" << libfile << ": " << d->errorMessage << endl; |
502 | return 0; | 509 | return 0; |
503 | } | 510 | } |
504 | else | 511 | else |
505 | d->errorMessage = QString::null; | 512 | d->errorMessage = QString::null; |
506 | 513 | ||
507 | KLibrary *lib = new KLibrary( name, libfile, qlib ); | 514 | KLibrary *lib = new KLibrary( name, libfile, qlib ); |
508 | wrap = new KLibWrapPrivate(lib, qlib); | 515 | wrap = new KLibWrapPrivate(lib, qlib); |
509 | d->loaded_stack.prepend(wrap); | 516 | d->loaded_stack.prepend(wrap); |
510 | } | 517 | } |
511 | m_libs.insert( name, wrap ); | 518 | m_libs.insert( name, wrap ); |
512 | 519 | ||
513 | connect( wrap->lib, SIGNAL( destroyed() ), | 520 | connect( wrap->lib, SIGNAL( destroyed() ), |
514 | this, SLOT( slotLibraryDestroyed() ) ); | 521 | this, SLOT( slotLibraryDestroyed() ) ); |
515 | 522 | ||
516 | return wrap->lib; | 523 | return wrap->lib; |
517 | } | 524 | } |
518 | 525 | ||
519 | QString KLibLoader::lastErrorMessage() const | 526 | QString KLibLoader::lastErrorMessage() const |
520 | { | 527 | { |
521 | return d->errorMessage; | 528 | return d->errorMessage; |
522 | } | 529 | } |
523 | 530 | ||
524 | void KLibLoader::unloadLibrary( const char *libname ) | 531 | void KLibLoader::unloadLibrary( const char *libname ) |
525 | { | 532 | { |
526 | KLibWrapPrivate *wrap = m_libs[ libname ]; | 533 | KLibWrapPrivate *wrap = m_libs[ libname ]; |
527 | if (!wrap) | 534 | if (!wrap) |
528 | return; | 535 | return; |
529 | if (--wrap->ref_count) | 536 | if (--wrap->ref_count) |
530 | return; | 537 | return; |
531 | 538 | ||
532 | // kdDebug(150) << "closing library " << libname << endl; | 539 | // kdDebug(150) << "closing library " << libname << endl; |
533 | 540 | ||
534 | m_libs.remove( libname ); | 541 | m_libs.remove( libname ); |
535 | 542 | ||
536 | disconnect( wrap->lib, SIGNAL( destroyed() ), | 543 | disconnect( wrap->lib, SIGNAL( destroyed() ), |
537 | this, SLOT( slotLibraryDestroyed() ) ); | 544 | this, SLOT( slotLibraryDestroyed() ) ); |
538 | close_pending( wrap ); | 545 | close_pending( wrap ); |
539 | } | 546 | } |
540 | 547 | ||
541 | KLibFactory* KLibLoader::factory( const char* name ) | 548 | KLibFactory* KLibLoader::factory( const char* name ) |
542 | { | 549 | { |
543 | KLibrary* lib = library( name ); | 550 | KLibrary* lib = library( name ); |
544 | if ( !lib ) | 551 | if ( !lib ) |
545 | return 0; | 552 | return 0; |
546 | 553 | ||
547 | return lib->factory(); | 554 | return lib->factory(); |
548 | } | 555 | } |
549 | 556 | ||
550 | void KLibLoader::slotLibraryDestroyed() | 557 | void KLibLoader::slotLibraryDestroyed() |
551 | { | 558 | { |
552 | const KLibrary *lib = static_cast<const KLibrary *>( sender() ); | 559 | const KLibrary *lib = static_cast<const KLibrary *>( sender() ); |
553 | 560 | ||
554 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); | 561 | QAsciiDictIterator<KLibWrapPrivate> it( m_libs ); |
555 | for (; it.current(); ++it ) | 562 | for (; it.current(); ++it ) |
556 | if ( it.current()->lib == lib ) | 563 | if ( it.current()->lib == lib ) |
557 | { | 564 | { |
558 | KLibWrapPrivate *wrap = it.current(); | 565 | KLibWrapPrivate *wrap = it.current(); |
559 | wrap->lib = 0; /* the KLibrary object is already away */ | 566 | wrap->lib = 0; /* the KLibrary object is already away */ |
560 | m_libs.remove( it.currentKey() ); | 567 | m_libs.remove( it.currentKey() ); |
561 | close_pending( wrap ); | 568 | close_pending( wrap ); |
562 | return; | 569 | return; |
563 | } | 570 | } |
564 | } | 571 | } |
565 | 572 | ||
566 | void KLibLoader::close_pending(KLibWrapPrivate *wrap) | 573 | void KLibLoader::close_pending(KLibWrapPrivate *wrap) |
567 | { | 574 | { |
568 | if (wrap && !d->pending_close.containsRef( wrap )) | 575 | if (wrap && !d->pending_close.containsRef( wrap )) |
569 | d->pending_close.append( wrap ); | 576 | d->pending_close.append( wrap ); |
570 | 577 | ||
571 | /* First delete all KLibrary objects in pending_close, but _don't_ unload | 578 | /* First delete all KLibrary objects in pending_close, but _don't_ unload |
572 | the DSO behind it. */ | 579 | the DSO behind it. */ |
573 | QPtrListIterator<KLibWrapPrivate> it(d->pending_close); | 580 | QPtrListIterator<KLibWrapPrivate> it(d->pending_close); |
574 | for (; it.current(); ++it) { | 581 | for (; it.current(); ++it) { |
575 | wrap = it.current(); | 582 | wrap = it.current(); |
576 | if (wrap->lib) { | 583 | if (wrap->lib) { |
577 | disconnect( wrap->lib, SIGNAL( destroyed() ), | 584 | disconnect( wrap->lib, SIGNAL( destroyed() ), |
578 | this, SLOT( slotLibraryDestroyed() ) ); | 585 | this, SLOT( slotLibraryDestroyed() ) ); |
579 | delete wrap->lib; | 586 | delete wrap->lib; |
580 | wrap->lib = 0; | 587 | wrap->lib = 0; |
581 | } | 588 | } |
582 | } | 589 | } |
583 | 590 | ||
584 | if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; | 591 | if (d->unload_mode == KLibLoaderPrivate::DONT_UNLOAD) return; |
585 | 592 | ||
586 | bool deleted_one = false; | 593 | bool deleted_one = false; |
587 | while ((wrap = d->loaded_stack.first())) { | 594 | while ((wrap = d->loaded_stack.first())) { |