kwave  18.07.70
Kwave::PluginManager Class Reference

#include <PluginManager.h>

Inheritance diagram for Kwave::PluginManager:
Inheritance graph
Collaboration diagram for Kwave::PluginManager:
Collaboration graph

Classes

struct  PluginModule
 

Public Slots

void signalClosed ()
 
void setSignalName (const QString &name)
 

Signals

void sigCommand (const QString &command)
 
void sigClosed ()
 
void sigSignalNameChanged (const QString &name)
 
void sigProgress (const QString &message)
 

Public Member Functions

 PluginManager (QWidget *parent, Kwave::SignalManager &signal_manager)
 
virtual ~PluginManager ()
 
bool loadAllPlugins ()
 
void stopAllPlugins ()
 
int executePlugin (const QString &name, QStringList *params)
 
bool canClose ()
 
bool onePluginRunning ()
 
void sync ()
 
int setupPlugin (const QString &name, const QStringList &params)
 
QStringList defaultParams (const QString &name)
 
sample_index_t signalLength ()
 
double signalRate ()
 
sample_index_t selectionStart ()
 
sample_index_t selectionEnd ()
 
void selectRange (sample_index_t offset, sample_index_t length)
 
Kwave::SampleSinkopenMultiTrackPlayback (unsigned int tracks, const Kwave::PlayBackParam *playback_params=Q_NULLPTR)
 
Kwave::PlaybackControllerplaybackController ()
 
void setParentWidget (QWidget *new_parent)
 
QPointer< QWidget > parentWidget ()
 
Kwave::SignalManagersignalManager ()
 
void insertView (Kwave::SignalView *view, QWidget *controls)
 
void registerViewManager (Kwave::ViewManager *view_manager)
 
void enqueueCommand (const QString &command)
 
void searchPluginModules ()
 
const QList< PluginModulepluginInfoList () const
 
void migratePluginToActiveContext (Kwave::Plugin *plugin)
 
void setActive ()
 

Private Types

typedef QPointer< Kwave::PluginKwavePluginPointer
 
typedef QList< KwavePluginPointerPluginList
 
typedef QMutableListIterator< KwavePluginPointerPluginListMutableIterator
 
typedef QListIterator< KwavePluginPointerPluginListIterator
 

Private Slots

void pluginClosed (Kwave::Plugin *p)
 
void pluginStarted (Kwave::Plugin *p)
 
void pluginDone (Kwave::Plugin *p)
 

Private Member Functions

Kwave::PlugincreatePluginInstance (const QString &name)
 
void savePluginDefaults (const QString &name, QStringList &params)
 
void connectPlugin (Kwave::Plugin *plugin)
 
void disconnectPlugin (Kwave::Plugin *plugin)
 

Private Attributes

PluginList m_plugin_instances
 
PluginList m_running_plugins
 
QPointer< QWidget > m_parent_widget
 
Kwave::SignalManagerm_signal_manager
 
ViewManagerm_view_manager
 

Static Private Attributes

static Kwave::PluginManagerm_active_instance = Q_NULLPTR
 
static QMap< QString, PluginModulem_plugin_modules
 

Detailed Description

Manages the loading, initializing, starting, running and closing of the plugins of kwave. Each instance of a TopWidget creates a new instance of the PluginManager to be independent from other toplevel widgets.

Definition at line 59 of file PluginManager.h.

Member Typedef Documentation

◆ KwavePluginPointer

typedef: QPointer to a Kwave::Plugin

Definition at line 319 of file PluginManager.h.

◆ PluginList

typedef: list of pointers to kwave plugins

Definition at line 322 of file PluginManager.h.

◆ PluginListIterator

typedef: const iterator for PluginList

Definition at line 330 of file PluginManager.h.

◆ PluginListMutableIterator

typedef: mutable iterator for PluginList

Definition at line 326 of file PluginManager.h.

Constructor & Destructor Documentation

◆ PluginManager()

Kwave::PluginManager::PluginManager ( QWidget *  parent,
Kwave::SignalManager signal_manager 
)

Constructor.

Parameters
parentreference to the toplevel widget (our parent)
signal_managerreference to a SignalManager

Definition at line 63 of file PluginManager.cpp.

67  m_parent_widget(parent),
68  m_signal_manager(signal_manager),
69  m_view_manager(Q_NULLPTR)
70 {
71 }
ViewManager * m_view_manager
PluginList m_plugin_instances
Kwave::SignalManager & m_signal_manager
QPointer< QWidget > m_parent_widget
PluginList m_running_plugins

◆ ~PluginManager()

Kwave::PluginManager::~PluginManager ( )
virtual

Default destructor

Definition at line 74 of file PluginManager.cpp.

References m_active_instance, Kwave::PluginManager::PluginModule::m_factory, m_plugin_instances, m_plugin_modules, Kwave::PluginManager::PluginModule::m_use_count, name, sigClosed(), and sync().

75 {
76  // inform all plugins and client windows that we close now
77  emit sigClosed();
78 
79  // wait until all plugins are really closed
80  this->sync();
81 
82  // give all plugins that still are loaded the chance to do some cleanups
83  // or unregistration tasks. Ideally this should also trigger a "release"
84  // of these remaining plugins, so that afterwards we have no more
85  // plugin instances left.
86  while (!m_plugin_instances.isEmpty()) {
88  Q_ASSERT(p);
89  if (p) p->unload();
90  }
91 
92  // this should make the cleanup handlers run (deferred delete)
93  QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
94 
95  // release all loaded modules
96  foreach (const QString &name, m_plugin_modules.keys()) {
97  PluginModule &p = m_plugin_modules[name];
98  p.m_use_count--;
99 
100 // qDebug("PluginManager: releasing module '%s' [refcnt=%d]",
101 // DBG(name), p.m_use_count);
102  if (p.m_use_count == 0) {
103  // take out the pointer to the loadable module
104  KPluginFactory *factory = p.m_factory;
105  p.m_factory = Q_NULLPTR;
106 
107  // remove the module from the list
108  m_plugin_modules.remove(name);
109 
110  // now the handle of the shared object can be released too
111  if (factory) delete factory;
112  } else {
113  // still in use
114  }
115  }
116 
117  // we are no longer the active instance
118  if (m_active_instance == this)
119  m_active_instance = Q_NULLPTR;
120 }
QPointer< Kwave::Plugin > KwavePluginPointer
PluginList m_plugin_instances
const char name[16]
Definition: memcpy.c:510
static Kwave::PluginManager * m_active_instance
static QMap< QString, PluginModule > m_plugin_modules
Here is the call graph for this function:

Member Function Documentation

◆ canClose()

bool Kwave::PluginManager::canClose ( )

Returns true if there is no running plugin that blocks a "close" operation.

Definition at line 288 of file PluginManager.cpp.

References m_plugin_instances.

289 {
290  // check: this must be called from the GUI thread only!
291  Q_ASSERT(this->thread() == QThread::currentThread());
292  Q_ASSERT(this->thread() == qApp->thread());
293 
294  if (!m_plugin_instances.isEmpty())
295  foreach (const KwavePluginPointer &plugin, m_plugin_instances)
296  if (plugin && !plugin->canClose()) return false;
297 
298  return true;
299 }
QPointer< Kwave::Plugin > KwavePluginPointer
PluginList m_plugin_instances

◆ connectPlugin()

void Kwave::PluginManager::connectPlugin ( Kwave::Plugin plugin)
private

connects all signals of and for a plugin

Definition at line 557 of file PluginManager.cpp.

References Kwave::connect(), pluginClosed(), pluginDone(), pluginStarted(), and sigClosed().

Referenced by createPluginInstance(), and migratePluginToActiveContext().

558 {
559  Q_ASSERT(plugin);
560  if (!plugin) return;
561 
562  connect(this, SIGNAL(sigClosed()),
563  plugin, SLOT(close()));
564 
565  connect(plugin, SIGNAL(sigClosed(Kwave::Plugin*)),
566  this, SLOT(pluginClosed(Kwave::Plugin*)),
567  Qt::QueuedConnection);
568 
569  connect(plugin, SIGNAL(sigRunning(Kwave::Plugin*)),
570  this, SLOT(pluginStarted(Kwave::Plugin*)),
571  Qt::DirectConnection);
572 
573  connect(plugin, SIGNAL(sigDone(Kwave::Plugin*)),
574  this, SLOT(pluginDone(Kwave::Plugin*)),
575  Qt::QueuedConnection);
576 }
void pluginClosed(Kwave::Plugin *p)
void pluginStarted(Kwave::Plugin *p)
bool connect(Kwave::StreamObject &source, const char *output, Kwave::StreamObject &sink, const char *input)
Definition: Connect.cpp:48
void pluginDone(Kwave::Plugin *p)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ createPluginInstance()

Kwave::Plugin * Kwave::PluginManager::createPluginInstance ( const QString &  name)
private

Creates an instance of a plugin.

Parameters
namethe name of the plugin (filename)
Returns
pointer to the loaded plugin or zero if the plugin was not found or invalid

Definition at line 173 of file PluginManager.cpp.

References connectPlugin(), DBG, Kwave::MessageBox::error(), Kwave::PluginManager::PluginModule::m_description, Kwave::PluginManager::PluginModule::m_factory, Kwave::PluginManager::PluginModule::m_name, m_parent_widget, m_plugin_instances, m_plugin_modules, and name.

Referenced by executePlugin(), loadAllPlugins(), and setupPlugin().

174 {
175  // check: this must be called from the GUI thread only!
176  Q_ASSERT(this->thread() == QThread::currentThread());
177  Q_ASSERT(this->thread() == qApp->thread());
178 
179  // show an error message and abort if the plugin is unknown
180  if (!(m_plugin_modules.contains(name))) {
182  i18n("The plugin '%1' is unknown or invalid.", name),
183  i18n("Error On Loading Plugin"));
184  return Q_NULLPTR;
185  }
186 
187  PluginModule &info = m_plugin_modules[name];
188 // qDebug("loadPlugin(%s) [module use count=%d]",
189 // DBG(name), info.m_use_count);
190 
191  KPluginFactory *factory = info.m_factory;
192  Q_ASSERT(factory);
193 
194  // call the loader function to create an instance
195  QVariantList args;
196  args << info.m_name;
197  args << info.m_description;
198  Kwave::Plugin *plugin = factory->create<Kwave::Plugin>(this, args);
199  Q_ASSERT(plugin);
200  if (!plugin) {
201  qWarning("PluginManager::loadPlugin('%s'): out of memory", DBG(name));
202  return Q_NULLPTR;
203  }
204  // now we have a newly created plugin, the use count is 1
205 
206  // append to our list of loaded plugins
207  m_plugin_instances.append(plugin);
208 
209  // connect all necessary signals/slots
210  connectPlugin(plugin);
211 
212  return plugin;
213 }
PluginList m_plugin_instances
const char name[16]
Definition: memcpy.c:510
void connectPlugin(Kwave::Plugin *plugin)
static int error(QWidget *widget, QString message, QString caption=QString())
Definition: MessageBox.cpp:126
static QMap< QString, PluginModule > m_plugin_modules
#define DBG(qs)
Definition: String.h:55
QPointer< QWidget > m_parent_widget
Here is the call graph for this function:
Here is the caller graph for this function:

◆ defaultParams()

QStringList Kwave::PluginManager::defaultParams ( const QString &  name)

loads a plugin's default parameters from the user's configuration file. If nothing is found in the config file, the return value will be 0. If the current version number of the plugin does not match the version number in the config file, the return value will also be 0.

Parameters
namethe name of the plugin
Returns
list of strings

Definition at line 363 of file PluginManager.cpp.

References _, DBG, m_plugin_modules, Kwave::PluginManager::PluginModule::m_version, and name.

Referenced by executePlugin(), loadAllPlugins(), Kwave::RecordPlugin::setup(), and setupPlugin().

364 {
365  QString def_version;
366  QString section = _("plugin ");
367  QStringList list;
368  section += name;
369 
370  // get the plugin version
371  if (!m_plugin_modules.contains(name)) return list;
372  const PluginModule &info = m_plugin_modules[name];
373  QString version = info.m_version;
374 
375  Q_ASSERT(KSharedConfig::openConfig());
376  if (!KSharedConfig::openConfig()) return list;
377  KConfigGroup cfg = KSharedConfig::openConfig()->group(section);
378 
379  cfg.sync();
380 
381  def_version = cfg.readEntry("version");
382  if (!def_version.length()) {
383  return list;
384  }
385  if (!(def_version == version)) {
386  qDebug("PluginManager::defaultParams: "
387  "plugin '%s': defaults for version '%s' not loaded, found "
388  "old ones of version '%s'.",
389  DBG(name), DBG(version), DBG(def_version));
390 
391  // delete the old settings
392  cfg.deleteEntry("version");
393  cfg.deleteEntry("defaults");
394 
395  return list;
396  }
397 
398  list = cfg.readEntry("defaults").split(QLatin1Char(','));
399  return list;
400 }
const char name[16]
Definition: memcpy.c:510
static QMap< QString, PluginModule > m_plugin_modules
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55
Here is the caller graph for this function:

◆ disconnectPlugin()

void Kwave::PluginManager::disconnectPlugin ( Kwave::Plugin plugin)
private

connects all signals from and to a plugin

Definition at line 579 of file PluginManager.cpp.

References pluginClosed(), pluginDone(), pluginStarted(), and sigClosed().

Referenced by migratePluginToActiveContext(), and pluginClosed().

580 {
581  Q_ASSERT(plugin);
582  if (!plugin) return;
583 
584  disconnect(plugin, SIGNAL(sigDone(Kwave::Plugin*)),
585  this, SLOT(pluginDone(Kwave::Plugin*)));
586 
587  disconnect(plugin, SIGNAL(sigRunning(Kwave::Plugin*)),
588  this, SLOT(pluginStarted(Kwave::Plugin*)));
589 
590  disconnect(this, SIGNAL(sigClosed()),
591  plugin, SLOT(close()));
592 
593  disconnect(plugin, SIGNAL(sigClosed(Kwave::Plugin*)),
594  this, SLOT(pluginClosed(Kwave::Plugin*)));
595 
596 }
void pluginClosed(Kwave::Plugin *p)
void pluginStarted(Kwave::Plugin *p)
void pluginDone(Kwave::Plugin *p)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueueCommand()

void Kwave::PluginManager::enqueueCommand ( const QString &  command)

Enqueues a command that will be processed threadsafe in the X11 thread.

Definition at line 494 of file PluginManager.cpp.

References sigCommand().

Referenced by Kwave::Plugin::emitCommand(), and Kwave::UndoReverseAction::undo().

495 {
496  emit sigCommand(command);
497 }
void sigCommand(const QString &command)
Here is the caller graph for this function:

◆ executePlugin()

int Kwave::PluginManager::executePlugin ( const QString &  name,
QStringList *  params 
)

Executes a plugin in the context of a given parent widget.

Parameters
namethe name of the plugin
paramspointer to a parameter list or null if defaults should be used
Returns
zero on success or negative error code

Definition at line 216 of file PluginManager.cpp.

References _, createPluginInstance(), defaultParams(), m_plugin_instances, name, savePluginDefaults(), sigCommand(), and sync().

Referenced by Kwave::K3BExportPlugin::saveBlocks().

218 {
219  QString command;
220  int result = 0;
221 
222  // check: this must be called from the GUI thread only!
223  Q_ASSERT(this->thread() == QThread::currentThread());
224  Q_ASSERT(this->thread() == qApp->thread());
225 
226  // synchronize: wait until any currently running plugins are done
227  this->sync();
228 
229  // load the new plugin
231  if (!plugin) return -ENOMEM;
232 
233  if (params) {
234  // parameters were specified -> call directly
235  // without setup dialog
236  result = plugin->start(*params);
237 
238  // maybe the start() function has called close() ?
239  if (!m_plugin_instances.contains(plugin)) {
240  qDebug("PluginManager: plugin closed itself in start()");
241  result = -1;
242  plugin = Q_NULLPTR;
243  }
244 
245  if (plugin && (result >= 0)) {
246  plugin->execute(*params);
247  }
248  } else {
249  // load previous parameters from config
250  QStringList last_params = defaultParams(name);
251 
252  // call the plugin's setup function
253  params = plugin->setup(last_params);
254  if (params) {
255  // we have a non-zero parameter list, so
256  // the setup function has not been aborted.
257  // Now we can create a command string and
258  // emit a new command.
259 
260  // store parameters for the next time
261  savePluginDefaults(name, *params);
262 
263  // We DO NOT call the plugin's "execute"
264  // function directly, as it should be possible
265  // to record all function calls in the
266  // macro recorder
267  command = _("plugin:execute(");
268  command += name;
269  foreach (const QString &p, *params)
270  command += _(", ") + p;
271  delete params;
272  command += _(")");
273 // qDebug("PluginManager: command='%s'",command.data());
274  }
275  }
276 
277  // now the plugin is no longer needed here, release it
278  if (plugin) plugin->release();
279 
280  // emit a command, let the toplevel window (and macro recorder) get
281  // it and call us again later...
282  if (command.length()) emit sigCommand(command);
283 
284  return result;
285 }
void sigCommand(const QString &command)
QPointer< Kwave::Plugin > KwavePluginPointer
void savePluginDefaults(const QString &name, QStringList &params)
Kwave::Plugin * createPluginInstance(const QString &name)
PluginList m_plugin_instances
const char name[16]
Definition: memcpy.c:510
#define _(m)
Definition: memcpy.c:66
QStringList defaultParams(const QString &name)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insertView()

void Kwave::PluginManager::insertView ( Kwave::SignalView view,
QWidget *  controls 
)

Insert a new signal view into this widget (or the upper/lower dock area.

Parameters
viewthe signal view, must not be a null pointer
controlsa widget with controls, optionally, can be null

Definition at line 480 of file PluginManager.cpp.

References Kwave::ViewManager::insertView(), and m_view_manager.

481 {
482  if (m_view_manager)
483  m_view_manager->insertView(view, controls);
484 }
ViewManager * m_view_manager
virtual void insertView(Kwave::SignalView *view, QWidget *controls)=0
Here is the call graph for this function:

◆ loadAllPlugins()

bool Kwave::PluginManager::loadAllPlugins ( )

Tries to load all plugins. If a pesistent plugin is found, it will stay loaded in memory, all other (non-persistent) plugins will be unloaded afterwards. This also filters out all plugins that do not correctly load.

used once by each toplevel window at startup

Returns
true if at least one plugin was loaded, false if none

Definition at line 123 of file PluginManager.cpp.

References createPluginInstance(), DBG, defaultParams(), m_plugin_modules, and name.

124 {
125  // Try to load all plugins. This has to be called only once per
126  // instance of the main window!
127  // NOTE: this also gives each plugin the chance to stay in memory
128  // if necessary (e.g. for codecs)
129  foreach (const QString &name, m_plugin_modules.keys()) {
131  if (plugin) {
132 // qDebug("PluginManager::loadAllPlugins(): plugin '%s'",
133 // DBG(plugin->name()));
134 
135  // get the last settings and call the "load" function
136  // now the plugin is present and loaded
137  QStringList last_params = defaultParams(name);
138  plugin->load(last_params);
139 
140  // reduce use count again, we loaded the plugin only to give
141  // it a chance to register some service if necessary (e.g. a
142  // codec)
143  // Most plugins fall back to use count zero and will be
144  // deleted again.
145  plugin->release();
146  } else {
147  // loading failed => remove it from the list
148  qWarning("PluginManager::loadAllPlugins(): removing '%s' "
149  "from list", DBG(name));
150  m_plugin_modules.remove(name);
151  }
152  }
153 
154  return !m_plugin_modules.isEmpty();
155 }
QPointer< Kwave::Plugin > KwavePluginPointer
Kwave::Plugin * createPluginInstance(const QString &name)
const char name[16]
Definition: memcpy.c:510
static QMap< QString, PluginModule > m_plugin_modules
#define DBG(qs)
Definition: String.h:55
QStringList defaultParams(const QString &name)
Here is the call graph for this function:

◆ migratePluginToActiveContext()

void Kwave::PluginManager::migratePluginToActiveContext ( Kwave::Plugin plugin)

Migrate a plugin to the currently active file context (which might be different from the one that is currently executing the plugin). The plugin will be removed from our lists and inserted into the currently active plugin manager instance.

Parameters
pluginthe plugin to migrate

Definition at line 685 of file PluginManager.cpp.

References connectPlugin(), disconnectPlugin(), m_active_instance, m_plugin_instances, m_running_plugins, and Kwave::Plugin::setPluginManager().

Referenced by Kwave::Plugin::migrateToActiveContext().

686 {
687  // check: this must be called from the GUI thread only!
688  Q_ASSERT(this->thread() == QThread::currentThread());
689  Q_ASSERT(this->thread() == qApp->thread());
690 
691  Q_ASSERT(plugin);
692  if (!plugin) return;
693  if (m_active_instance == this) return; // nothing to do
694  Q_ASSERT(m_active_instance);
695  if (!m_active_instance) return; // should never happen
696 
697  Kwave::PluginManager *old_mgr = this;
698  old_mgr->m_plugin_instances.removeAll(plugin);
699  old_mgr->m_running_plugins.removeAll(plugin);
700  old_mgr->disconnectPlugin(plugin);
701 
703  new_mgr->m_plugin_instances.append(plugin);
704  new_mgr->m_running_plugins.append(plugin);
705  new_mgr->connectPlugin(plugin);
706 
707  plugin->setPluginManager(new_mgr);
708 }
void setPluginManager(Kwave::PluginManager *new_plugin_manager)
Definition: Plugin.cpp:522
PluginList m_plugin_instances
void connectPlugin(Kwave::Plugin *plugin)
static Kwave::PluginManager * m_active_instance
void disconnectPlugin(Kwave::Plugin *plugin)
PluginList m_running_plugins
Here is the call graph for this function:
Here is the caller graph for this function:

◆ onePluginRunning()

bool Kwave::PluginManager::onePluginRunning ( )

Returns true if at least one plugin is currently running

Definition at line 302 of file PluginManager.cpp.

References m_plugin_instances.

Referenced by sync().

303 {
304  // check: this must be called from the GUI thread only!
305  Q_ASSERT(this->thread() == QThread::currentThread());
306  Q_ASSERT(this->thread() == qApp->thread());
307 
308  if (!m_plugin_instances.isEmpty())
309  foreach (const KwavePluginPointer &plugin, m_plugin_instances)
310  if (plugin && plugin->isRunning()) return true;
311 
312  return false;
313 }
QPointer< Kwave::Plugin > KwavePluginPointer
PluginList m_plugin_instances
Here is the caller graph for this function:

◆ openMultiTrackPlayback()

Kwave::SampleSink * Kwave::PluginManager::openMultiTrackPlayback ( unsigned int  tracks,
const Kwave::PlayBackParam playback_params = Q_NULLPTR 
)

Opens a Kwave::MultiTrackSink for playback purposes.

Parameters
tracksnumber of tracks
playback_paramspoints to a class that holds all playback parameters. If null, the default parameters of the current signal will be used
Returns
a multitrack sink that receives the playback stream

Definition at line 457 of file PluginManager.cpp.

References m_signal_manager, Kwave::PlaybackController::openDevice(), and Kwave::SignalManager::playbackController().

Referenced by Kwave::FilterPlugin::startPreListen(), and Kwave::PlayBackPlugin::testPlayBack().

461 {
462  Kwave::PlayBackDevice *device =
464  tracks, playback_params);
465  if (!device) return Q_NULLPTR;
466 
467  // create the multi track playback sink
468  Kwave::SampleSink *sink = new Kwave::MultiPlaybackSink(tracks, device);
469  Q_ASSERT(sink);
470  return sink;
471 }
Kwave::PlaybackController & playbackController()
Kwave::SignalManager & m_signal_manager
Kwave::PlayBackDevice * openDevice(int tracks, const Kwave::PlayBackParam *playback_params)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parentWidget()

QPointer<QWidget> Kwave::PluginManager::parentWidget ( )
inline

returns a pointer to the parent widget

Definition at line 198 of file PluginManager.h.

Referenced by Kwave::Plugin::parentWidget(), and Kwave::Plugin::setPluginManager().

199  {
200  return m_parent_widget;
201  }
QPointer< QWidget > m_parent_widget
Here is the caller graph for this function:

◆ playbackController()

Kwave::PlaybackController & Kwave::PluginManager::playbackController ( )

Returns a reference to the current playback controller. This is only needed for plugins doing playback.

Definition at line 474 of file PluginManager.cpp.

References m_signal_manager, and Kwave::SignalManager::playbackController().

475 {
477 }
Kwave::PlaybackController & playbackController()
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:

◆ pluginClosed

void Kwave::PluginManager::pluginClosed ( Kwave::Plugin p)
privateslot

Will be connected to the plugin's "closed" signal.

Parameters
ppointer to the plugin to be closed

Definition at line 506 of file PluginManager.cpp.

References disconnectPlugin(), and m_plugin_instances.

Referenced by connectPlugin(), and disconnectPlugin().

507 {
508  // check: this must be called from the GUI thread only!
509  Q_ASSERT(this->thread() == QThread::currentThread());
510  Q_ASSERT(this->thread() == qApp->thread());
511 
512  Q_ASSERT(p);
513  if (!p) return;
514 
515  // disconnect the signals to avoid recursion
516  disconnectPlugin(p);
517 
518  if (m_plugin_instances.contains(p))
519  m_plugin_instances.removeAll(p);
520 
521  // schedule the deferred delete/unload of the plugin
522  p->deleteLater();
523 }
PluginList m_plugin_instances
void disconnectPlugin(Kwave::Plugin *plugin)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginDone

void Kwave::PluginManager::pluginDone ( Kwave::Plugin p)
privateslot

called when a plugin has finished it's worker thread

Definition at line 540 of file PluginManager.cpp.

References m_running_plugins, and Kwave::Plugin::release().

Referenced by connectPlugin(), and disconnectPlugin().

541 {
542  // check: this must be called from the GUI thread only!
543  Q_ASSERT(this->thread() == QThread::currentThread());
544  Q_ASSERT(this->thread() == qApp->thread());
545 
546  Q_ASSERT(p);
547  if (!p) return;
548 
549  // remove the plugin from the list of running plugins
550  m_running_plugins.removeAll(p);
551 
552  // release the plugin, at least we do no longer need it
553  p->release();
554 }
void release()
Definition: Plugin.cpp:420
PluginList m_running_plugins
Here is the call graph for this function:
Here is the caller graph for this function:

◆ pluginInfoList()

const QList< Kwave::PluginManager::PluginModule > Kwave::PluginManager::pluginInfoList ( ) const

returns a list with info of all known plugins

Todo:
rename to pluginModuleList

Definition at line 679 of file PluginManager.cpp.

References m_plugin_modules.

680 {
681  return m_plugin_modules.values();
682 }
static QMap< QString, PluginModule > m_plugin_modules

◆ pluginStarted

void Kwave::PluginManager::pluginStarted ( Kwave::Plugin p)
privateslot

called when a plugin has started (running) it's worker thread

Definition at line 526 of file PluginManager.cpp.

References m_running_plugins, and Kwave::Plugin::use().

Referenced by connectPlugin(), and disconnectPlugin().

527 {
528  Q_ASSERT(p);
529  if (!p) return;
530 
531  // the plugin is running -> increase the usage count in order to
532  // prevent our lists from containing invalid entries
533  p->use();
534 
535  // add the plugin to the list of running plugins
536  m_running_plugins.append(p);
537 }
void use()
Definition: Plugin.cpp:412
PluginList m_running_plugins
Here is the call graph for this function:
Here is the caller graph for this function:

◆ registerViewManager()

void Kwave::PluginManager::registerViewManager ( Kwave::ViewManager view_manager)

registers a view manager, must only be called once!

Definition at line 487 of file PluginManager.cpp.

References m_view_manager.

Referenced by Kwave::MainWidget::MainWidget(), and Kwave::MainWidget::~MainWidget().

488 {
489  Q_ASSERT(!view_manager || !m_view_manager);
490  m_view_manager = view_manager;
491 }
ViewManager * m_view_manager
Here is the caller graph for this function:

◆ savePluginDefaults()

void Kwave::PluginManager::savePluginDefaults ( const QString &  name,
QStringList &  params 
)
private

Saves a plugin's default parameters to the user's configuration file. The whole section in the configuration file will be deleted before saving the new settings in order to wipe out invalid entries and settings that belong to an older version.

Parameters
namethe name of the plugin
paramsa list of configuration strings

Definition at line 403 of file PluginManager.cpp.

References _, m_plugin_modules, Kwave::PluginManager::PluginModule::m_version, and name.

Referenced by executePlugin(), and setupPlugin().

405 {
406 
407  // get the plugin version
408  if (!m_plugin_modules.contains(name)) return;
409  const PluginModule &info = m_plugin_modules[name];
410  QString version = info.m_version;
411 
412  QString section = _("plugin ");
413  section += name;
414 
415  Q_ASSERT(KSharedConfig::openConfig());
416  if (!KSharedConfig::openConfig()) return;
417  KConfigGroup cfg = KSharedConfig::openConfig()->group(section);
418 
419  cfg.sync();
420  cfg.writeEntry("version", version);
421  cfg.writeEntry("defaults", params.join(QLatin1Char(',')));
422  cfg.sync();
423 }
const char name[16]
Definition: memcpy.c:510
static QMap< QString, PluginModule > m_plugin_modules
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ searchPluginModules()

void Kwave::PluginManager::searchPluginModules ( )

Searches the standard KDE data directories for plugins (through the KDE's standard search algorithm) and creates a map of plugin names and file names. First it collects a list of filenames and then filters it to sort out invalid entries.

Definition at line 605 of file PluginManager.cpp.

References _, DBG, Kwave::PluginManager::PluginModule::m_author, Kwave::PluginManager::PluginModule::m_description, Kwave::PluginManager::PluginModule::m_factory, Kwave::PluginManager::PluginModule::m_name, m_plugin_modules, Kwave::PluginManager::PluginModule::m_use_count, Kwave::PluginManager::PluginModule::m_version, name, and sigProgress().

606 {
607  if (!m_plugin_modules.isEmpty()) {
608  // this is not the first call -> increment module use count only
609  foreach (const QString &name, m_plugin_modules.keys()) {
610  PluginModule &p = m_plugin_modules[name];
611  p.m_use_count++;
612  }
613  return;
614  }
615 
616  KPluginInfo::List plugins = KPluginTrader::self()->query(
617  _("kwave"), _("Kwave/Plugin")
618  );
619  foreach (const KPluginInfo &i, plugins) {
620  QString library = i.libraryPath();
621  QString description = i.name();
622  QString name = i.pluginName();
623  QString version_raw = i.version();
624  QString version;
625  QString settings;
626  QString author = i.author();
627 
628  if (version_raw.contains(_(":"))) {
629  version = version_raw.split(_(":")).at(0);
630  settings = version_raw.split(_(":")).at(1);
631  }
632 
633 // qDebug("file='%s', name='%s', description='%s', binary_version='%s', "
634 // "settings_version='%s', author='%s'",
635 // DBG(library), DBG(name), DBG(description), DBG(version),
636 // DBG(settings), DBG(author)
637 // );
638 
639  if ( library.isEmpty() || description.isEmpty() ||
640  name.isEmpty() || version.isEmpty() ) {
641  qWarning("plugin '%s' has no library, name or version", DBG(name));
642  continue;
643  }
644 
645  if (version != _(KWAVE_VERSION)) {
646  qWarning("plugin '%s' has wrong ABI version: '%s' (should be %s)",
647  DBG(name), DBG(version), KWAVE_VERSION);
648  continue;
649  }
650 
651  KPluginLoader loader(library);
652  KPluginFactory* factory = loader.factory();
653  if (!factory) {
654  qWarning("plugin '%s': loading failed", DBG(name));
655  continue;
656  }
657 
658  emit sigProgress(i18n("Loading plugin %1...", name));
659  QApplication::processEvents();
660 
661  PluginModule info;
662  info.m_name = name;
663  info.m_author = author;
664  info.m_description = i18n(description.toUtf8());
665  info.m_version = settings;
666  info.m_factory = factory;
667  info.m_use_count = 1;
668 
669  m_plugin_modules.insert(info.m_name, info);
670 
671  qDebug("%16s %5s written by %s", DBG(name), DBG(settings), DBG(author));
672  }
673 
674  qDebug("--- \n found %d plugins\n", m_plugin_modules.count());
675 }
void sigProgress(const QString &message)
const char name[16]
Definition: memcpy.c:510
static QMap< QString, PluginModule > m_plugin_modules
#define _(m)
Definition: memcpy.c:66
#define DBG(qs)
Definition: String.h:55

◆ selectionEnd()

sample_index_t Kwave::PluginManager::selectionEnd ( )

Returns the end of the selection. If nothing is currently selected this will be the last sample (length-1).

Definition at line 444 of file PluginManager.cpp.

References Kwave::Selection::last(), m_signal_manager, and Kwave::SignalManager::selection().

Referenced by Kwave::Plugin::selection().

445 {
446  return m_signal_manager.selection().last();
447 }
sample_index_t last() const
Definition: Selection.h:76
Kwave::Selection & selection()
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectionStart()

sample_index_t Kwave::PluginManager::selectionStart ( )

Returns the start of the selection. If nothing is currently selected this will be the first sample (0).

Definition at line 438 of file PluginManager.cpp.

References Kwave::Selection::first(), m_signal_manager, and Kwave::SignalManager::selection().

Referenced by Kwave::Plugin::selection(), and Kwave::SelectRangePlugin::setup().

439 {
440  return m_signal_manager.selection().first();
441 }
sample_index_t first() const
Definition: Selection.h:71
Kwave::Selection & selection()
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:
Here is the caller graph for this function:

◆ selectRange()

void Kwave::PluginManager::selectRange ( sample_index_t  offset,
sample_index_t  length 
)

Sets the current start and length of the selection to new values.

Parameters
offsetindex of the first sample
lengthnumber of samples

Definition at line 450 of file PluginManager.cpp.

References m_signal_manager, and Kwave::SignalManager::selectRange().

Referenced by Kwave::Plugin::selectRange().

452 {
453  m_signal_manager.selectRange(offset, length);
454 }
void selectRange(sample_index_t offset, sample_index_t length)
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setActive()

void Kwave::PluginManager::setActive ( )
inline

Let this instance be the active one

Definition at line 262 of file PluginManager.h.

262 { m_active_instance = this; }
static Kwave::PluginManager * m_active_instance

◆ setParentWidget()

void Kwave::PluginManager::setParentWidget ( QWidget *  new_parent)
inline

assigns a new parent widget, to be used for messages

Parameters
new_parentpointer to a QWidget

Definition at line 193 of file PluginManager.h.

193  {
194  m_parent_widget = new_parent;
195  }
QPointer< QWidget > m_parent_widget

◆ setSignalName

void Kwave::PluginManager::setSignalName ( const QString &  name)
slot

Called if the name of the current signal has changed. This will be forwarded to all plugins by emitting the signal sigSignalNameChanged.

See also
sigSignalNameChanged()

Definition at line 599 of file PluginManager.cpp.

References sigSignalNameChanged().

600 {
602 }
const char name[16]
Definition: memcpy.c:510
void sigSignalNameChanged(const QString &name)

◆ setupPlugin()

int Kwave::PluginManager::setupPlugin ( const QString &  name,
const QStringList &  params 
)

Loads a plugin, calls it's setup function and then closes it again. The parameters will be loaded before the setup and saved if the setup has not been aborted.

Parameters
namethe name of the plugin
paramspointer to a parameter list or null if defaults should be used
Return values
0if succeeded and accepted
1if canceled
-1if failed

Definition at line 335 of file PluginManager.cpp.

References createPluginInstance(), defaultParams(), Kwave::Plugin::release(), savePluginDefaults(), and Kwave::Plugin::setup().

337 {
338  // load the plugin
340  if (!plugin) return -ENOMEM;
341 
342  // now the plugin is present and loaded
343  QStringList prev_params = (params.isEmpty()) ?
344  defaultParams(name) : params;
345 
346  // call the plugins' setup function
347  QStringList *new_params = plugin->setup(prev_params);
348  if (new_params) {
349  // we have a non-zero parameter list, so
350  // the setup function has not been aborted.
351  savePluginDefaults(name, *new_params);
352  delete new_params;
353  } else {
354  plugin->release();
355  return 1;
356  }
357 
358  plugin->release();
359  return 0;
360 }
void savePluginDefaults(const QString &name, QStringList &params)
void release()
Definition: Plugin.cpp:420
Kwave::Plugin * createPluginInstance(const QString &name)
const char name[16]
Definition: memcpy.c:510
virtual QStringList * setup(QStringList &previous_params)
Definition: Plugin.cpp:134
QStringList defaultParams(const QString &name)
Here is the call graph for this function:

◆ sigClosed

void Kwave::PluginManager::sigClosed ( )
signal

Informs all plugins and client windows that we close down

Referenced by connectPlugin(), disconnectPlugin(), signalClosed(), and ~PluginManager().

Here is the caller graph for this function:

◆ sigCommand

void Kwave::PluginManager::sigCommand ( const QString &  command)
signal

Forwards commands to the parent TopWidget execute a command

Referenced by enqueueCommand(), and executePlugin().

Here is the caller graph for this function:

◆ signalClosed

void Kwave::PluginManager::signalClosed ( )
slot

Notify all plugins that the signal or file is to be closed

Definition at line 500 of file PluginManager.cpp.

References sigClosed().

501 {
502  emit sigClosed();
503 }

◆ signalLength()

sample_index_t Kwave::PluginManager::signalLength ( )

Returns the length of the current signal in samples. If no signal is present the return value will be 0.

Definition at line 426 of file PluginManager.cpp.

References Kwave::SignalManager::length(), and m_signal_manager.

Referenced by Kwave::Plugin::selection(), and Kwave::Plugin::signalLength().

427 {
428  return m_signal_manager.length();
429 }
sample_index_t length()
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:
Here is the caller graph for this function:

◆ signalManager()

Kwave::SignalManager& Kwave::PluginManager::signalManager ( )
inline

returns a reference to our signal manager

Definition at line 204 of file PluginManager.h.

Referenced by Kwave::NoisePlugin::createDialog(), Kwave::RecordPlugin::resetRecording(), Kwave::VolumePlugin::setup(), and Kwave::Plugin::signalManager().

205  {
206  return m_signal_manager;
207  }
Kwave::SignalManager & m_signal_manager
Here is the caller graph for this function:

◆ signalRate()

double Kwave::PluginManager::signalRate ( )

Returns the current sample rate in samples per second. If no signal is present the return value will be 0.

Definition at line 432 of file PluginManager.cpp.

References m_signal_manager, and Kwave::SignalManager::rate().

Referenced by Kwave::Plugin::signalRate().

433 {
434  return m_signal_manager.rate();
435 }
double rate() const
Kwave::SignalManager & m_signal_manager
Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigProgress

void Kwave::PluginManager::sigProgress ( const QString &  message)
signal

informs about progress, e.g. for showing a message in a splash screen or status bar.

Referenced by searchPluginModules().

Here is the caller graph for this function:

◆ sigSignalNameChanged

void Kwave::PluginManager::sigSignalNameChanged ( const QString &  name)
signal

Informs the plugins that the name of the signal has changed. This might be used to update the caption of a window.

Referenced by setSignalName().

Here is the caller graph for this function:

◆ stopAllPlugins()

void Kwave::PluginManager::stopAllPlugins ( )

Stops all currently running plugins

Definition at line 158 of file PluginManager.cpp.

References m_plugin_instances, and sync().

159 {
160  // check: this must be called from the GUI thread only!
161  Q_ASSERT(this->thread() == QThread::currentThread());
162  Q_ASSERT(this->thread() == qApp->thread());
163 
164  if (!m_plugin_instances.isEmpty())
165  foreach (const KwavePluginPointer &plugin, m_plugin_instances)
166  if (plugin && plugin->isRunning())
167  plugin->stop() ;
168 
169  sync();
170 }
QPointer< Kwave::Plugin > KwavePluginPointer
PluginList m_plugin_instances
Here is the call graph for this function:

◆ sync()

void Kwave::PluginManager::sync ( )

Waits until all currently running actions have completed.

Definition at line 316 of file PluginManager.cpp.

References onePluginRunning(), and Kwave::yield().

Referenced by executePlugin(), Kwave::TopWidget::forwardCommand(), stopAllPlugins(), and ~PluginManager().

317 {
318  // check: this must be called from the GUI thread only!
319  Q_ASSERT(this->thread() == QThread::currentThread());
320  Q_ASSERT(this->thread() == qApp->thread());
321 
322  // this triggers all kinds of garbage collector (objects queued for
323  // deletion through obj->deleteLater()
324  qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
325 
326  // wait until all plugins have finished their work...
327  while (onePluginRunning()) {
328  Kwave::yield();
329  qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
330  usleep(100000);
331  }
332 }
void Q_DECL_EXPORT yield()
Definition: Utils.cpp:39
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_active_instance

Kwave::PluginManager * Kwave::PluginManager::m_active_instance = Q_NULLPTR
staticprivate

pointer to the currently active instance

Definition at line 362 of file PluginManager.h.

Referenced by migratePluginToActiveContext(), and ~PluginManager().

◆ m_parent_widget

QPointer<QWidget> Kwave::PluginManager::m_parent_widget
private

reference to our parent toplevel widget

Definition at line 377 of file PluginManager.h.

Referenced by createPluginInstance().

◆ m_plugin_instances

PluginList Kwave::PluginManager::m_plugin_instances
private

list of all plugins that were loaded by this instance

Definition at line 371 of file PluginManager.h.

Referenced by canClose(), createPluginInstance(), executePlugin(), migratePluginToActiveContext(), onePluginRunning(), pluginClosed(), stopAllPlugins(), and ~PluginManager().

◆ m_plugin_modules

QMap< QString, Kwave::PluginManager::PluginModule > Kwave::PluginManager::m_plugin_modules
staticprivate

map with plugin information: key = short name of the plugin, data = plugin info (description, author, version etc...)

Definition at line 368 of file PluginManager.h.

Referenced by createPluginInstance(), defaultParams(), loadAllPlugins(), pluginInfoList(), savePluginDefaults(), searchPluginModules(), and ~PluginManager().

◆ m_running_plugins

PluginList Kwave::PluginManager::m_running_plugins
private

list of currently running plugins

Definition at line 374 of file PluginManager.h.

Referenced by migratePluginToActiveContext(), pluginDone(), and pluginStarted().

◆ m_signal_manager

Kwave::SignalManager& Kwave::PluginManager::m_signal_manager
private

reference to our signal manager

Definition at line 380 of file PluginManager.h.

Referenced by openMultiTrackPlayback(), playbackController(), selectionEnd(), selectionStart(), selectRange(), signalLength(), and signalRate().

◆ m_view_manager

ViewManager* Kwave::PluginManager::m_view_manager
private

interface for registering a SignalView

Definition at line 383 of file PluginManager.h.

Referenced by insertView(), and registerViewManager().


The documentation for this class was generated from the following files: