RemotePlugin: added support for running remote process multiple times

There might be situations where we want to try to run multiple different
remote processes. Therefore introduced RemotePlugin::init(...) which can
be called multiple times even if previous calls failed.
This commit is contained in:
Tobias Doerffel
2010-12-23 22:09:45 +01:00
parent 5143b6ad21
commit 39cc1a8212
2 changed files with 52 additions and 29 deletions

View File

@@ -1,7 +1,7 @@
/*
* RemotePlugin.h - base class providing RPC like mechanisms
*
* Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2008-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* 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;

View File

@@ -1,7 +1,7 @@
/*
* RemotePlugin.cpp - base class providing RPC like mechanisms
*
* Copyright (c) 2008-2009 Tobias Doerffel <tobydox/at/users.sourceforge.net>
* Copyright (c) 2008-2010 Tobias Doerffel <tobydox/at/users.sourceforge.net>
*
* 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 )