[a21201]: kwave / PluginManager.cpp Maximize Restore History

Download this file

PluginManager.cpp    816 lines (692 with data), 25.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/***************************************************************************
PluginManager.cpp - manager class for Kwave's plugins
-------------------
begin : Sun Aug 27 2000
copyright : (C) 2000 by Thomas Eschenbacher
email : Thomas.Eschenbacher@gmx.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <dlfcn.h>
#include <errno.h>
#include <pthread.h>
#include "qobject.h"
#include <kglobal.h>
#include <kconfig.h>
#include <kmainwindow.h>
#include <kstddirs.h>
#include <kmessagebox.h>
#include <klocale.h>
#include "mt/SignalProxy.h"
#ifdef HAVE_ARTS_SUPPORT
#include "libkwave/ArtsMultiPlaybackSink.h"
#endif /* HAVE_ARTS_SUPPORT */
#include "libkwave/LineParser.h"
#include "libkwave/FileLoader.h"
#include "libkwave/KwavePlugin.h"
#include "libkwave/MultiTrackReader.h"
#include "libkwave/MultiTrackWriter.h"
#include "libkwave/Parser.h"
#include "libkwave/PlayBackDevice.h"
#include "libkwave/PlaybackDeviceFactory.h"
#include "libkwave/PluginContext.h"
#include "libkwave/SampleReader.h"
#include "libkwave/SampleWriter.h"
#include "KwaveApp.h"
#include "TopWidget.h"
#include "SignalManager.h"
#include "UndoAction.h"
#include "UndoModifyAction.h"
#include "UndoTransactionGuard.h"
#include "PluginManager.h"
//***************************************************************************
//***************************************************************************
PluginManager::PluginDeleter::PluginDeleter(KwavePlugin *plugin, void *handle)
:QObject(), m_plugin(plugin), m_handle(handle)
{
}
//***************************************************************************
PluginManager::PluginDeleter::~PluginDeleter()
{
// delete the plugin, this should also remove everything it has allocated
delete m_plugin;
// now the handle of the shared object can be cleared too
dlclose(m_handle);
}
//***************************************************************************
//***************************************************************************
// static initializers
QMap<QString, QString> PluginManager::m_plugin_files;
QPtrList<KwavePlugin> PluginManager::m_unique_plugins;
static QPtrList<PlaybackDeviceFactory> m_playback_factories;
//***************************************************************************
PluginManager::PluginManager(TopWidget &parent)
:m_spx_name_changed(this, SLOT(emitNameChanged())),
m_spx_command(this, SLOT(forwardCommand())),
m_loaded_plugins(), m_running_plugins(),
m_top_widget(parent)
{
// use all unique plugins
// this does nothing on the first instance, all other instances
// will probably find a non-empty list
QPtrListIterator<KwavePlugin> itp(m_unique_plugins);
for ( ; itp.current(); ++itp ) {
KwavePlugin *p = itp.current();
Q_ASSERT(p && p->isUnique());
if (p && p->isUnique()) {
p->use();
// maybe we will become responsible for releasing
// the plugin (when it is in use but the plugin manager
// who has created it is already finished)
connect(p, SIGNAL(sigClosed(KwavePlugin *)),
this, SLOT(pluginClosed(KwavePlugin *)));
}
}
}
//***************************************************************************
bool PluginManager::isOK()
{
return true;
}
//***************************************************************************
PluginManager::~PluginManager()
{
// inform all plugins and client windows that we close now
emit sigClosed();
// wait until all plugins are really closed
this->sync();
// release all unique plugins
QPtrListIterator<KwavePlugin> itu(m_unique_plugins);
for (itu.toLast() ; itu.current(); ) {
KwavePlugin *p = itu.current();
--itu;
Q_ASSERT(p && p->isUnique());
if (p && p->isUnique()) {
p->release();
}
}
// release all own persisiten plugins
QPtrListIterator<KwavePlugin> itp(m_loaded_plugins);
for (itp.toLast() ; itp.current(); ) {
KwavePlugin *p = itp.current();
--itp;
Q_ASSERT(p);
if (p && p->isPersistent()) p->release();
}
// release all own plugins that are left
QPtrListIterator<KwavePlugin> it(m_loaded_plugins);
for (it.toLast() ; it.current(); ) {
KwavePlugin *p = it.current();
--it;
Q_ASSERT(p);
if (p) p->release();
}
}
//***************************************************************************
void PluginManager::loadAllPlugins()
{
// Try to load all plugins. This has to be called only once per
// instance of the main window!
// NOTE: this also implicitely makes it resident if it is persistent or unique
QMap<QString, QString>::Iterator it;
for (it=m_plugin_files.begin(); it != m_plugin_files.end(); ++it) {
QString name = it.key();
KwavePlugin *plugin = loadPlugin(name);
if (plugin) {
// QString state = "";
// if (plugin->isPersistent()) state += "(persistent)";
// if (plugin->isUnique()) state += "(unique)";
// if (!state.length()) state = "(normal)";
// qDebug("PluginManager::loadAllPlugins(): plugin '"+
// plugin->name()+"' "+state);
if (!plugin->isUnique() && !plugin->isPersistent()) {
// remove it again if it is neither unique nor persistent
plugin->release();
}
} else {
// loading failed => remove it from the list
qWarning("PluginManager::loadAllPlugins(): removing '%s' "\
"from list", name.data());
m_plugin_files.remove(name);
}
}
}
//***************************************************************************
KwavePlugin *PluginManager::loadPlugin(const QString &name)
{
// first find out if the plugin is already loaded and persistent
QPtrListIterator<KwavePlugin> itp(m_loaded_plugins);
for ( ; itp.current(); ++itp ) {
KwavePlugin *p = itp.current();
if (p->isPersistent() && (p->name() == name)) {
Q_ASSERT(p->isPersistent());
qDebug("PluginManager::loadPlugin('%s')"\
"-> returning pointer to persistent",
name.local8Bit().data());
return p;
}
}
// find out if the plugin is already loaded and unique
QPtrListIterator<KwavePlugin> it(m_unique_plugins);
for ( ; it.current(); ++it ) {
KwavePlugin *p = it.current();
if (p->name() == name) {
Q_ASSERT(p->isUnique());
Q_ASSERT(p->isPersistent());
qDebug("PluginManager::loadPlugin('%s')"\
"-> returning pointer to unique+persistent",
name.local8Bit().data());
return p;
}
}
// show a warning and abort if the plugin is unknown
if (!(m_plugin_files.contains(name))) {
QString message =i18n("oops, plugin '%1' is unknown or invalid!");
message = message.arg(name);
KMessageBox::error(&m_top_widget, message,
i18n("error on loading plugin"));
return 0;
}
QString &filename = m_plugin_files[name];
// try to get the file handle of the plugin's binary
void *handle = dlopen(filename, RTLD_NOW);
if (!handle) {
QString message = i18n("unable to load the file \n'%1'\n"\
" that contains the plugin '%2' !");
message = message.arg(filename).arg(name);
KMessageBox::error(&m_top_widget, message,
i18n("error on loading plugin"));
return 0;
}
// get the loader function
KwavePlugin *(*plugin_loader)(const PluginContext *c) = 0;
// hardcoded, should always work when the
// symbols are declared as extern "C"
const char *sym_version = "version";
const char *sym_author = "author";
const char *sym_loader = "load";
// get the plugin's author
const char *author = "";
const char **pauthor = (const char **)dlsym(handle, sym_author);
Q_ASSERT(pauthor);
if (pauthor) author=*pauthor;
if (!author) author = i18n("(unknown)");
// get the plugin's version string
const char *version = "";
const char **pver = (const char **)dlsym(handle, sym_version);
Q_ASSERT(pver);
if (pver) version=*pver;
if (!version) version = i18n("(unknown)");
plugin_loader =
(KwavePlugin *(*)(const PluginContext *))dlsym(handle, sym_loader);
Q_ASSERT(plugin_loader);
if (!plugin_loader) {
// plugin is null, out of memory or not found
qWarning("PluginManager::loadPlugin('%s'): "\
"plugin does not contain a loader, "\
"maybe it is damaged or the wrong version?",
name.local8Bit().data());
dlclose(handle);
return 0;
}
PluginContext context(
m_top_widget.getKwaveApp(),
*this,
0, // LabelManager *label_mgr,
0, // MenuManager *menu_mgr,
m_top_widget,
handle,
name,
version,
author
);
// call the loader function to create an instance
KwavePlugin *plugin = (*plugin_loader)(&context);
Q_ASSERT(plugin);
if (!plugin) {
qWarning("PluginManager::loadPlugin('%s'): out of memory",
name.local8Bit().data());
dlclose(handle);
return 0;
}
if (plugin->isUnique()) {
// append unique plugins to the global list of unique plugins
m_unique_plugins.append(plugin);
plugin->use();
} else {
// append the plugin into our list of loaded plugins
m_loaded_plugins.append(plugin);
if (plugin->isPersistent()) {
// increment the usage if it is persistent, we will
// only load it once in this instance
plugin->use();
}
}
// connect all necessary signals/slots
connectPlugin(plugin);
// get the last settings and call the "load" function
// now the plugin is present and loaded
QStringList last_params = loadPluginDefaults(name, plugin->version());
plugin->load(last_params);
return plugin;
}
//***************************************************************************
int PluginManager::executePlugin(const QString &name, QStringList *params)
{
QString command;
int result = 0;
// synchronize: wait until any currently running plugins are done
sync();
// load the new plugin
KwavePlugin *plugin = loadPlugin(name);
if (!plugin) return -ENOMEM;
if (params) {
// parameters were specified -> call directly
// without setup dialog
result = plugin->start(*params);
// maybe the start() function has called close() ?
if (m_loaded_plugins.findRef(plugin) == -1) {
qDebug("PluginManager: plugin closed itself in start()"); // ###
result = -1;
plugin = 0;
}
if (plugin && (result >= 0)) {
plugin->use(); // plugin->release() will be called after run()
plugin->execute(*params);
}
} else {
// load previous parameters from config
QStringList last_params = loadPluginDefaults(name, plugin->version());
// call the plugin's setup function
params = plugin->setup(last_params);
if (params) {
// we have a non-zero parameter list, so
// the setup function has not been aborted.
// Now we can create a command string and
// emit a new command.
// store parameters for the next time
savePluginDefaults(name, plugin->version(), *params);
// We DO NOT call the plugin's "execute"
// function directly, as it should be possible
// to record all function calls in the
// macro recorder
command = "plugin:execute(";
command += name;
for (unsigned int i=0; i < params->count(); i++) {
command += ", ";
command += *(params->at(i));
}
delete params;
command += ")";
// qDebug("PluginManager: command='%s'",command.data());
}
}
// now the plugin is no longer needed here, so delete it
// if it has not already been detached
if (plugin && !plugin->isPersistent()) plugin->release();
// emit a command, let the toplevel window (and macro recorder) get
// it and call us again later...
if (command.length()) emit sigCommand(command);
return result;
}
//***************************************************************************
bool PluginManager::onePluginRunning()
{
QPtrListIterator<KwavePlugin> it(m_loaded_plugins);
for (; it.current(); ++it) {
KwavePlugin *plugin = it.current();
if (plugin->isRunning()) return true;
}
return false;
}
//***************************************************************************
void PluginManager::sync()
{
while (onePluginRunning()) {
qApp->processEvents();
pthread_yield();
}
}
//***************************************************************************
int PluginManager::setupPlugin(const QString &name)
{
// load the plugin
KwavePlugin* plugin = loadPlugin(name);
if (!plugin) return -ENOMEM;
// now the plugin is present and loaded
QStringList last_params = loadPluginDefaults(name, plugin->version());
// call the plugin's setup function
QStringList *params = plugin->setup(last_params);
if (params) {
// we have a non-zero parameter list, so
// the setup function has not been aborted.
savePluginDefaults(name, plugin->version(), *params);
delete params;
} else return -1;
// now the plugin is no longer needed here, so delete it
// if it has not already been detached and is not persistent
if (!plugin->isPersistent()) plugin->release();
return 0;
}
//***************************************************************************
FileInfo &PluginManager::fileInfo()
{
return m_top_widget.signalManager().fileInfo();
}
//***************************************************************************
QStringList PluginManager::loadPluginDefaults(const QString &name,
const QString &version)
{
QString def_version;
QString section("plugin ");
QStringList list;
section += name;
KConfig *cfg = KGlobal::config();
Q_ASSERT(cfg);
if (!cfg) return list;
cfg->sync();
cfg->setGroup(section);
def_version = cfg->readEntry("version");
if (!def_version.length()) {
return list;
}
if (!(def_version == version)) {
qDebug("PluginManager::loadPluginDefaults: "\
"plugin '%s': defaults for version '%s' not loaded, found "\
"old ones of version '%s'.", name.local8Bit().data(),
version.local8Bit().data(), def_version.local8Bit().data());
return list;
}
list = cfg->readListEntry("defaults", ',');
return list;
}
//***************************************************************************
void PluginManager::savePluginDefaults(const QString &name,
const QString &version,
QStringList &params)
{
QString section("plugin ");
section += name;
KConfig *cfg = KGlobal::config();
Q_ASSERT(cfg);
if (!cfg) return;
cfg->sync();
cfg->setGroup(section);
cfg->writeEntry("version", version);
cfg->writeEntry("defaults", params);
cfg->sync();
}
//***************************************************************************
unsigned int PluginManager::signalLength()
{
return m_top_widget.signalManager().length();
}
//***************************************************************************
double PluginManager::signalRate()
{
return m_top_widget.signalManager().rate();
}
//***************************************************************************
const QMemArray<unsigned int> PluginManager::selectedTracks()
{
return m_top_widget.signalManager().selectedTracks();
}
//***************************************************************************
unsigned int PluginManager::selectionStart()
{
return m_top_widget.signalManager().selection().first();
}
//***************************************************************************
unsigned int PluginManager::selectionEnd()
{
return m_top_widget.signalManager().selection().last();
}
//***************************************************************************
void PluginManager::selectRange(unsigned int offset, unsigned int length)
{
m_top_widget.signalManager().selectRange(offset, length);
}
//***************************************************************************
SampleWriter *PluginManager::openSampleWriter(unsigned int track,
InsertMode mode, unsigned int left, unsigned int right)
{
SignalManager &manager = m_top_widget.signalManager();
return manager.openSampleWriter(track, mode, left, right, true);
}
//***************************************************************************
void PluginManager::openMultiTrackReader(MultiTrackReader &readers,
const QMemArray<unsigned int> &track_list,
unsigned int first, unsigned int last)
{
SignalManager &manager = m_top_widget.signalManager();
manager.openMultiTrackReader(readers, track_list, first, last);
}
//***************************************************************************
void PluginManager::openMultiTrackWriter(MultiTrackWriter &writers,
const QMemArray<unsigned int> &track_list, InsertMode mode,
unsigned int left, unsigned int right)
{
SignalManager &manager = m_top_widget.signalManager();
manager.openMultiTrackWriter(writers, track_list, mode, left, right);
}
//***************************************************************************
void PluginManager::openMultiTrackWriter(MultiTrackWriter &writers,
InsertMode mode)
{
SignalManager &manager = m_top_widget.signalManager();
QMemArray<unsigned int> tracks = manager.selectedTracks();
unsigned int left = 0;
unsigned int right = 0;
if (signalLength()) {
// default if signal is present: current selection
left = selectionStart();
right = selectionEnd();
if (left == right) {
// if no selection: whole signal
left = 0;
right = signalLength();
}
}
openMultiTrackWriter(writers, tracks, mode, left, right);
}
//***************************************************************************
#ifdef HAVE_ARTS_SUPPORT
ArtsMultiSink *PluginManager::openMultiTrackPlayback(unsigned int tracks,
const QString *name)
{
QString device_name;
// locate the corresponding playback device factory (plugin)
device_name = (name) ? QString(*name) : QString("");
PlayBackDevice *device = 0;
PlaybackDeviceFactory *factory = 0;
QPtrListIterator<PlaybackDeviceFactory> it(m_playback_factories);
for (; it.current(); ++it) {
PlaybackDeviceFactory *f = it.current();
Q_ASSERT(f);
if (f && f->supportsDevice(device_name)) {
factory = f;
break;
}
}
Q_ASSERT(factory);
if (!factory) return 0;
// open the playback device with it's default parameters
device = factory->openDevice(device_name, 0);
Q_ASSERT(device);
if (!device) return 0;
// create the multi track playback sink
ArtsMultiSink *sink = new ArtsMultiPlaybackSink(tracks, device);
Q_ASSERT(sink);
if (!sink) return 0;
return sink;
}
#endif /* HAVE_ARTS_SUPPORT */
//***************************************************************************
PlaybackController &PluginManager::playbackController()
{
return m_top_widget.signalManager().playbackController();
}
//***************************************************************************
void PluginManager::enqueueCommand(const QString &command)
{
m_spx_command.enqueue(command);
}
//***************************************************************************
void PluginManager::forwardCommand()
{
const QString *command = m_spx_command.dequeue();
if (command) {
m_top_widget.executeCommand(*command);
delete command;
}
}
//***************************************************************************
void PluginManager::signalClosed()
{
emit sigClosed();
}
//***************************************************************************
void PluginManager::pluginClosed(KwavePlugin *p)
{
Q_ASSERT(p);
Q_ASSERT(!m_loaded_plugins.isEmpty() || !m_unique_plugins.isEmpty());
if (!p) return;
// disconnect the signals to avoid recursion
disconnectPlugin(p);
if (m_loaded_plugins.findRef(p) != -1) {
m_loaded_plugins.setAutoDelete(false);
m_loaded_plugins.removeRef(p);
}
if (m_unique_plugins.findRef(p) != -1) {
m_unique_plugins.setAutoDelete(false);
m_unique_plugins.removeRef(p);
}
// schedule the deferred delete/unload of the plugin
void *handle = p->handle();
Q_ASSERT(handle);
PluginDeleter *delete_later = new PluginDeleter(p, handle);
Q_ASSERT(delete_later);
if (delete_later) delete_later->deleteLater();
// qDebug("PluginManager::pluginClosed(): done");
}
//***************************************************************************
void PluginManager::pluginStarted(KwavePlugin *p)
{
Q_ASSERT(p);
if (!p) return;
// the plugin is running -> increase the usage count in order to
// prevent our lists from containing invalid entries
p->use();
// add the plugin to the list of running plugins
m_running_plugins.append(p);
}
//***************************************************************************
void PluginManager::pluginDone(KwavePlugin *p)
{
Q_ASSERT(p);
if (!p) return;
// remove the plugin from the list of running plugins
m_running_plugins.setAutoDelete(false);
m_running_plugins.removeRef(p);
// release the plugin, at least we do no longer need it
p->release();
}
//***************************************************************************
void PluginManager::connectPlugin(KwavePlugin *plugin)
{
Q_ASSERT(plugin);
if (!plugin) return;
if (!plugin->isUnique()) {
connect(this, SIGNAL(sigClosed()),
plugin, SLOT(close()));
}
connect(plugin, SIGNAL(sigClosed(KwavePlugin *)),
this, SLOT(pluginClosed(KwavePlugin *)));
connect(plugin, SIGNAL(sigRunning(KwavePlugin *)),
this, SLOT(pluginStarted(KwavePlugin *)));
connect(plugin, SIGNAL(sigDone(KwavePlugin *)),
this, SLOT(pluginDone(KwavePlugin *)));
}
//***************************************************************************
void PluginManager::disconnectPlugin(KwavePlugin *plugin)
{
Q_ASSERT(plugin);
if (!plugin) return;
disconnect(plugin, SIGNAL(sigDone(KwavePlugin *)),
this, SLOT(pluginDone(KwavePlugin *)));
disconnect(plugin, SIGNAL(sigRunning(KwavePlugin *)),
this, SLOT(pluginStarted(KwavePlugin *)));
disconnect(this, SIGNAL(sigClosed()),
plugin, SLOT(close()));
if (!plugin->isUnique()) {
disconnect(plugin, SIGNAL(sigClosed(KwavePlugin *)),
this, SLOT(pluginClosed(KwavePlugin *)));
}
}
//***************************************************************************
void PluginManager::emitNameChanged()
{
const QString *name = m_spx_name_changed.dequeue();
Q_ASSERT(name);
if (name) {
emit sigSignalNameChanged(*name);
delete name;
}
}
//***************************************************************************
void PluginManager::setSignalName(const QString &name)
{
m_spx_name_changed.enqueue(name);
}
//***************************************************************************
void PluginManager::findPlugins()
{
QStringList files = KGlobal::dirs()->findAllResources("module",
"plugins/kwave/*", false, true);
/* fallback: search also in the old location (useful for developers) */
files += KGlobal::dirs()->findAllResources("data",
"kwave/plugins/*", false, true);
QStringList::Iterator it;
for (it=files.begin(); it != files.end(); ++it) {
QString file = *it;
void *handle = dlopen(file, RTLD_NOW);
if (handle) {
const char **name = (const char **)dlsym(handle, "name");
const char **version = (const char **)dlsym(handle, "version");
const char **author = (const char **)dlsym(handle, "author");
// skip it if something is missing or null
if (!name || !version || !author) continue;
if (!*name || !*version || !*author) continue;
m_plugin_files.insert(*name, file);
qDebug(i18n("%16s %5s written by %s"), *name, *version, *author);
dlclose (handle);
} else {
qWarning(i18n("error in '%s':\n\t %s"), file.data(),
dlerror());
}
}
qDebug(i18n("--- \n found %d plugins\n"), m_plugin_files.count());
}
//***************************************************************************
void PluginManager::registerPlaybackDeviceFactory(
PlaybackDeviceFactory *factory)
{
m_playback_factories.append(factory);
}
//***************************************************************************
void PluginManager::unregisterPlaybackDeviceFactory(
PlaybackDeviceFactory *factory)
{
m_playback_factories.setAutoDelete(false);
m_playback_factories.removeRef(factory);
}
//***************************************************************************
#include "PluginManager.moc"
//***************************************************************************
//***************************************************************************