Add JackWaitCallbackDriver

This wrapper driver has the same usage as its parent JackWaitThreadedDriver,
but for non-threaded (callback) drivers. After waiting for Initialize to
return, its main thread simply ends instead of calling the driver's Process
method in a loop. The decorated driver, which must extends JackRestarerDriver
instead of JackWaiterDriver, can restart the wait cycle by calling its
RestartWait method.
This commit is contained in:
Cédric Schieli 2014-10-30 10:24:58 +01:00
parent c1ae33f934
commit 1cd25cb975
5 changed files with 130 additions and 0 deletions

View File

@ -86,4 +86,18 @@ int JackWaiterDriver::ProcessNull()
return 0;
}
void JackRestarterDriver::SetRestartDriver(JackDriver* driver)
{
fRestartDriver = driver;
}
int JackRestarterDriver::RestartWait()
{
if (!fRestartDriver) {
jack_error("JackRestartedDriver::RestartWait driver not set");
return -1;
}
return fRestartDriver->Start();
}
} // end of namespace

View File

@ -75,6 +75,32 @@ class SERVER_EXPORT JackWaiterDriver : public JackTimedDriver
};
/*!
\brief A restartable driver.
When wrapped into a JackWaitCallbackDriver, this driver can restart the
wrapper thread which will wait again for the Initialize method to return.
*/
class SERVER_EXPORT JackRestarterDriver : public JackWaiterDriver
{
private:
JackDriver* fRestartDriver; /*!< The wrapper driver */
public:
JackRestarterDriver(const char* name, const char* alias, JackLockedEngine* engine, JackSynchro* table)
: JackWaiterDriver(name, alias, engine, table), fRestartDriver(NULL)
{}
virtual ~JackRestarterDriver()
{}
void SetRestartDriver(JackDriver* driver); /*!< Let the wrapper register itself */
int RestartWait(); /*!< Restart the wrapper thread */
};
} // end of namespace
#endif

View File

@ -0,0 +1,39 @@
/*
Copyright (C) 2014 Cédric Schieli
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "JackWaitCallbackDriver.h"
namespace Jack
{
JackWaitCallbackDriver::JackWaitCallbackDriver(JackRestarterDriver* driver)
: JackWaitThreadedDriver(driver)
{
// Self register with the decorated driver so it can restart us
assert(driver);
driver->SetRestartDriver((JackDriver*)this);
}
bool JackWaitCallbackDriver::ExecuteReal()
{
// End the thread and let the callback driver do its job
return false;
}
} // end of namespace

View File

@ -0,0 +1,50 @@
/*
Copyright (C) 2014 Cédric Schieli
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.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef __JackWaitCallbackDriver__
#define __JackWaitCallbackDriver__
#include "JackWaitThreadedDriver.h"
namespace Jack
{
/*!
\brief Wrapper for a restartable non-threaded driver (e.g. JackProxyDriver).
Simply ends its thread when the decorated driver Initialize method returns.
Self register with the supplied JackRestarterDriver so it can restart the thread.
*/
class SERVER_EXPORT JackWaitCallbackDriver : public JackWaitThreadedDriver
{
public:
JackWaitCallbackDriver(JackRestarterDriver* driver);
protected:
bool ExecuteReal();
};
} // end of namespace
#endif

View File

@ -223,6 +223,7 @@ def build(bld):
'JackThreadedDriver.cpp',
'JackRestartThreadedDriver.cpp',
'JackWaitThreadedDriver.cpp',
'JackWaitCallbackDriver.cpp',
'JackServerAPI.cpp',
'JackDriverLoader.cpp',
'JackServerGlobals.cpp',