diff --git a/include/RemotePlugin.h b/include/RemotePlugin.h index fb60a06f2..0cb662b65 100644 --- a/include/RemotePlugin.h +++ b/include/RemotePlugin.h @@ -1,7 +1,7 @@ /* * RemotePlugin.h - base class providing RPC like mechanisms * - * Copyright (c) 2008-2009 Tobias Doerffel + * Copyright (c) 2008-2010 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -603,6 +603,14 @@ public: RemotePluginBase( shmFifo * _in, shmFifo * _out ); virtual ~RemotePluginBase(); + void reset( shmFifo *in, shmFifo *out ) + { + delete m_in; + delete m_out; + m_in = in; + m_out = out; + } + void sendMessage( const message & _m ); message receiveMessage(); @@ -696,8 +704,7 @@ private: class EXPORT RemotePlugin : public RemotePluginBase { public: - RemotePlugin( const QString & _plugin_executable, - bool _wait_for_init_done = true ); + RemotePlugin(); virtual ~RemotePlugin(); inline bool isRunning() @@ -709,6 +716,8 @@ public: #endif } + bool init( const QString &pluginExecutable, bool waitForInitDoneMsg ); + inline void waitForInitDone( bool _busyWaiting = true ) { m_failed = waitForMessage( IdInitDone, _busyWaiting ).id != IdInitDone; diff --git a/src/core/RemotePlugin.cpp b/src/core/RemotePlugin.cpp index b60e386c8..08a082d59 100644 --- a/src/core/RemotePlugin.cpp +++ b/src/core/RemotePlugin.cpp @@ -1,7 +1,7 @@ /* * RemotePlugin.cpp - base class providing RPC like mechanisms * - * Copyright (c) 2008-2009 Tobias Doerffel + * Copyright (c) 2008-2010 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * @@ -68,10 +68,10 @@ void ProcessWatcher::run() -RemotePlugin::RemotePlugin( const QString & _plugin_executable, - bool _wait_for_init_done ) : +RemotePlugin::RemotePlugin() : RemotePluginBase( new shmFifo(), new shmFifo() ), m_failed( true ), + m_process(), m_watcher( this ), m_commMutex( QMutex::Recursive ), m_splitChannels( false ), @@ -85,29 +85,6 @@ RemotePlugin::RemotePlugin( const QString & _plugin_executable, m_inputCount( DEFAULT_CHANNELS ), m_outputCount( DEFAULT_CHANNELS ) { - lock(); - QString exec = configManager::inst()->pluginDir() + - QDir::separator() + _plugin_executable; - QStringList args; - // swap in and out for bidirectional communication - args << QString::number( out()->shmKey() ); - args << QString::number( in()->shmKey() ); - m_process.setProcessChannelMode( QProcess::MergedChannels ); -#ifndef DEBUG_REMOTE_PLUGIN - m_process.start( exec, args ); - - m_watcher.start( QThread::LowestPriority ); -#else - qDebug() << exec << args; -#endif - - resizeSharedProcessingMemory(); - - if( _wait_for_init_done ) - { - waitForInitDone(); - } - unlock(); } @@ -144,6 +121,43 @@ RemotePlugin::~RemotePlugin() +bool RemotePlugin::init( const QString &pluginExecutable, + bool waitForInitDoneMsg ) +{ + lock(); + if( m_failed ) + { + reset( new shmFifo(), new shmFifo() ); + m_failed = false; + } + QString exec = configManager::inst()->pluginDir() + + QDir::separator() + pluginExecutable; + + QStringList args; + // swap in and out for bidirectional communication + args << QString::number( out()->shmKey() ); + args << QString::number( in()->shmKey() ); +#ifndef DEBUG_REMOTE_PLUGIN + m_process.setProcessChannelMode( QProcess::ForwardedChannels ); + m_process.start( exec, args ); + m_watcher.start( QThread::LowestPriority ); +#else + qDebug() << exec << args; +#endif + + resizeSharedProcessingMemory(); + + if( waitForInitDoneMsg ) + { + waitForInitDone(); + } + unlock(); + + return failed(); +} + + + bool RemotePlugin::process( const sampleFrame * _in_buf, sampleFrame * _out_buf )