Commit 215dfdd9 authored by sletz's avatar sletz
Browse files

Tim Blechmann patch to remove unnecessary virtual methods : choice of the...

Tim Blechmann patch to remove unnecessary virtual methods : choice of the appropriate platform version is now done at compilation time.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2429 0c269be4-1314-0410-8aa9-9f06e86f4224
parent db50d7eb
......@@ -20,6 +20,10 @@ Fernando Lopez-Lezcano
Jackdmp changes log
---------------------------
2008-06-02 Stephane Letz <letz@grame.fr>
* Tim Blechmann patch to remove unnecessary virtual methods : choice of the appropriate platform version is now done at compilation time.
2008-06-02 Stephane Letz <letz@grame.fr>
* Cleanup and correct wscript for example-clients.
......
......@@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef __JackActivationCount__
#define __JackActivationCount__
#include "JackSynchro.h"
#include "JackPlatformSynchro.h"
#include "JackTime.h"
#include "JackTypes.h"
......
......@@ -40,7 +40,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackAudioDriver::JackAudioDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro** table)
JackAudioDriver::JackAudioDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table)
: JackDriver(name, alias, engine, table),
fCaptureChannels(0),
fPlaybackChannels(0),
......
......@@ -57,7 +57,7 @@ class EXPORT JackAudioDriver : public JackDriver
public:
JackAudioDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro** table);
JackAudioDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table);
virtual ~JackAudioDriver();
virtual int Process();
......
......@@ -31,6 +31,8 @@ class JackServer;
struct JackEngineControl;
class JackGraphManager;
namespace detail
{
/*!
\brief Inter process channel for server/client bidirectionnal communication : request and (receiving) notifications.
*/
......@@ -120,91 +122,9 @@ class JackClientChannelInterface
virtual void InternalClientUnload(int refnum, int int_ref, int* status, int* result)
{}
};
/*!
\brief Inter process channel for server to client notifications.
*/
class JackNotifyChannelInterface
{
public:
JackNotifyChannelInterface()
{}
virtual ~JackNotifyChannelInterface()
{}
// Open the Server/Client connection
virtual int Open(const char* name)
{
return 0;
}
// Close the Server/Client connection
virtual void Close()
{}
/*
The "sync" parameter allows to choose between "synchronous" and "asynchronous" notification
*/
virtual void ClientNotify(int refnum, const char* name, int notify, int sync, int value1, int value2, int* result)
{}
};
/*!
\brief Entry point channel for client/server communication.
*/
class JackServerChannelInterface
{
public:
JackServerChannelInterface()
{}
virtual ~JackServerChannelInterface()
{}
// Open the Server/Client connection
virtual int Open(const char* server_name, JackServer* server)
{
return 0;
}
// Close the Server/Client connection
virtual void Close()
{}
};
/*!
\brief Channel for server RT thread to request server thread communication.
*/
class JackServerNotifyChannelInterface
{
public:
JackServerNotifyChannelInterface()
{}
virtual ~JackServerNotifyChannelInterface()
{}
// Open the Server RT/Server connection
virtual int Open(const char* server_name)
{
return 0;
}
// Close the Server RT/Server connection
virtual void Close()
{}
virtual void Notify(int refnum, int notify, int value)
{}
};
}
} // end of namespace
......
......@@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <math.h>
#include <string>
#include <algorithm>
#include "JackPlatformThread.h"
using namespace std;
......@@ -41,12 +42,11 @@ namespace Jack
#define IsRealTime() ((fProcess != NULL) | (fThreadFun != NULL) | (fSync != NULL) | (fTimebase != NULL))
JackClient::JackClient()
JackClient::JackClient():fThread(this)
{}
JackClient::JackClient(JackSynchro** table)
JackClient::JackClient(JackSynchro* table):fThread(this)
{
fThread = JackGlobals::MakeThread(this);
fSynchroTable = table;
fProcess = NULL;
fGraphOrder = NULL;
......@@ -78,7 +78,6 @@ JackClient::JackClient(JackSynchro** table)
JackClient::~JackClient()
{
delete fThread;
}
int JackClient::Close()
......@@ -89,7 +88,7 @@ int JackClient::Close()
fChannel->Stop(); // Channels is stopped first to avoid receiving notifications while closing
fChannel->ClientClose(GetClientControl()->fRefNum, &result);
fChannel->Close();
fSynchroTable[GetClientControl()->fRefNum]->Disconnect();
fSynchroTable[GetClientControl()->fRefNum].Disconnect();
return result;
}
......@@ -100,7 +99,7 @@ bool JackClient::IsActive()
pthread_t JackClient::GetThreadID()
{
return fThread->GetThreadID();
return fThread.GetThreadID();
}
/*!
......@@ -112,14 +111,14 @@ void JackClient::SetupDriverSync(bool freewheel)
{
if (!freewheel && !GetEngineControl()->fSyncMode) {
jack_log("JackClient::SetupDriverSync driver sem in flush mode");
fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(true);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(true);
fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(true);
fSynchroTable[AUDIO_DRIVER_REFNUM].SetFlush(true);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM].SetFlush(true);
fSynchroTable[LOOPBACK_DRIVER_REFNUM].SetFlush(true);
} else {
jack_log("JackClient::SetupDriverSync driver sem in normal mode");
fSynchroTable[AUDIO_DRIVER_REFNUM]->SetFlush(false);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM]->SetFlush(false);
fSynchroTable[LOOPBACK_DRIVER_REFNUM]->SetFlush(false);
fSynchroTable[AUDIO_DRIVER_REFNUM].SetFlush(false);
fSynchroTable[FREEWHEEL_DRIVER_REFNUM].SetFlush(false);
fSynchroTable[LOOPBACK_DRIVER_REFNUM].SetFlush(false);
}
}
......@@ -188,7 +187,7 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
case kStartFreewheelCallback:
jack_log("JackClient::kStartFreewheel");
SetupDriverSync(true);
fThread->DropRealTime();
fThread.DropRealTime();
if (fFreewheel)
fFreewheel(1, fFreewheelArg);
break;
......@@ -198,7 +197,7 @@ int JackClient::ClientNotify(int refnum, const char* name, int notify, int sync,
SetupDriverSync(false);
if (fFreewheel)
fFreewheel(0, fFreewheelArg);
fThread->AcquireRealTime();
fThread.AcquireRealTime();
break;
case kPortRegistrationOnCallback:
......@@ -290,7 +289,7 @@ int JackClient::Deactivate()
// RT thread is stopped only when needed...
if (IsRealTime())
fThread->Kill();
fThread.Kill();
return result;
}
......@@ -318,15 +317,15 @@ int JackClient::StartThread()
long(int64_t(GetEngineControl()->fConstraint) / 1000.0f));
// Will do "something" on OSX only...
fThread->SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
fThread.SetParams(GetEngineControl()->fPeriod, GetEngineControl()->fComputation, GetEngineControl()->fConstraint);
if (fThread->Start() < 0) {
if (fThread.Start() < 0) {
jack_error("Start thread error");
return -1;
}
if (GetEngineControl()->fRealTime) {
if (fThread->AcquireRealTime(GetEngineControl()->fPriority - 1) < 0) {
if (fThread.AcquireRealTime(GetEngineControl()->fPriority - 1) < 0) {
jack_error("AcquireRealTime error");
}
}
......@@ -445,7 +444,7 @@ inline int JackClient::End()
jack_log("JackClient::Execute end name = %s", GetClientControl()->fName);
// Hum... not sure about this, the following "close" code is called in the RT thread...
int result;
fThread->DropRealTime();
fThread.DropRealTime();
GetClientControl()->fActive = false;
fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result);
return 0;
......@@ -456,7 +455,7 @@ inline int JackClient::Error()
jack_error("JackClient::Execute error name = %s", GetClientControl()->fName);
// Hum... not sure about this, the following "close" code is called in the RT thread...
int result;
fThread->DropRealTime();
fThread.DropRealTime();
GetClientControl()->fActive = false;
fChannel->ClientDeactivate(GetClientControl()->fRefNum, &result);
ShutDown();
......
......@@ -30,17 +30,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "varargs.h"
#include <list>
#include "JackPlatformSynchro.h"
#include "JackPlatformThread.h"
#include "JackChannel.h"
namespace Jack
{
class JackClientChannelInterface;
class JackGraphManager;
class JackServer;
class JackEngine;
class JackSynchro;
struct JackClientControl;
struct JackEngineControl;
class JackSyncInterface;
typedef void (*JackShutdownCallback)(void *arg);
......@@ -83,9 +84,9 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
void* fThreadFunArg;
char fServerName[64];
JackThread* fThread; /*! Thread to execute the Process function */
JackClientChannelInterface* fChannel;
JackSynchro** fSynchroTable;
JackThread fThread; /*! Thread to execute the Process function */
detail::JackClientChannelInterface* fChannel;
JackSynchro* fSynchroTable;
std::list<jack_port_id_t> fPortList;
int StartThread();
......@@ -110,7 +111,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
public:
JackClient();
JackClient(JackSynchro** table);
JackClient(JackSynchro* table);
virtual ~JackClient();
virtual int Open(const char* server_name, const char* name, jack_options_t options, jack_status_t* status) = 0;
......@@ -186,7 +187,7 @@ class JackClient : public JackClientInterface, public JackRunnableInterface
// Each "side" server and client will implement this to get the shared graph manager, engine control and inter-process synchro table.
extern JackGraphManager* GetGraphManager();
extern JackEngineControl* GetEngineControl();
extern JackSynchro** GetSynchroTable();
extern JackSynchro* GetSynchroTable();
} // end of namespace
......
......@@ -256,10 +256,10 @@ void JackConnectionManager::ResetGraph(JackClientTiming* timing)
/*!
\brief Wait on the input synchro.
*/
int JackConnectionManager::SuspendRefNum(JackClientControl* control, JackSynchro** table, JackClientTiming* timing, long time_out_usec)
int JackConnectionManager::SuspendRefNum(JackClientControl* control, JackSynchro* table, JackClientTiming* timing, long time_out_usec)
{
bool res;
if ((res = table[control->fRefNum]->TimedWait(time_out_usec))) {
if ((res = table[control->fRefNum].TimedWait(time_out_usec))) {
timing[control->fRefNum].fStatus = Running;
timing[control->fRefNum].fAwakeAt = GetMicroSeconds();
}
......@@ -269,7 +269,7 @@ int JackConnectionManager::SuspendRefNum(JackClientControl* control, JackSynchro
/*!
\brief Signal clients connected to the given client.
*/
int JackConnectionManager::ResumeRefNum(JackClientControl* control, JackSynchro** table, JackClientTiming* timing)
int JackConnectionManager::ResumeRefNum(JackClientControl* control, JackSynchro* table, JackClientTiming* timing)
{
jack_time_t current_date = GetMicroSeconds();
const jack_int_t* outputRef = fConnectionRef.GetItems(control->fRefNum);
......@@ -288,7 +288,7 @@ int JackConnectionManager::ResumeRefNum(JackClientControl* control, JackSynchro*
timing[i].fStatus = Triggered;
timing[i].fSignaledAt = current_date;
if (!fInputCounter[i].Signal(table[i], control)) {
if (!fInputCounter[i].Signal(table + i, control)) {
jack_log("JackConnectionManager::ResumeRefNum error: ref = %ld output = %ld ", control->fRefNum, i);
res = -1;
}
......
......@@ -442,8 +442,8 @@ class JackConnectionManager
// Graph
void ResetGraph(JackClientTiming* timing);
int ResumeRefNum(JackClientControl* control, JackSynchro** table, JackClientTiming* timing);
int SuspendRefNum(JackClientControl* control, JackSynchro** table, JackClientTiming* timing, long time_out_usec);
int ResumeRefNum(JackClientControl* control, JackSynchro* table, JackClientTiming* timing);
int SuspendRefNum(JackClientControl* control, JackSynchro* table, JackClientTiming* timing, long time_out_usec);
};
} // end of namespace
......
......@@ -43,7 +43,7 @@ using namespace std;
namespace Jack
{
JackDriver::JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro** table)
JackDriver::JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table)
{
assert(strlen(name) < JACK_CLIENT_NAME_SIZE);
fSynchroTable = table;
......@@ -149,10 +149,10 @@ void JackDriver::SetupDriverSync(int ref, bool freewheel)
{
if (!freewheel && !fEngineControl->fSyncMode) {
jack_log("JackDriver::SetupDriverSync driver sem in flush mode");
fSynchroTable[ref]->SetFlush(true);
fSynchroTable[ref].SetFlush(true);
} else {
jack_log("JackDriver::SetupDriverSync driver sem in normal mode");
fSynchroTable[ref]->SetFlush(false);
fSynchroTable[ref].SetFlush(false);
}
}
......
......@@ -24,6 +24,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "types.h"
#include "JackClientInterface.h"
#include "JackConstants.h"
#include "JackPlatformSynchro.h"
#include <list>
namespace Jack
......@@ -31,7 +32,6 @@ namespace Jack
class JackEngineInterface;
class JackGraphManager;
class JackSynchro;
struct JackEngineControl;
struct JackClientControl;
......@@ -152,7 +152,7 @@ class EXPORT JackDriver : public JackDriverClient
float fDelayedUsecs;
JackEngineInterface* fEngine;
JackGraphManager* fGraphManager;
JackSynchro** fSynchroTable;
JackSynchro* fSynchroTable;
JackEngineControl* fEngineControl;
JackClientControl* fClientControl;
......@@ -163,7 +163,7 @@ class EXPORT JackDriver : public JackDriverClient
public:
JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro** table);
JackDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table);
JackDriver();
virtual ~JackDriver();
......
......@@ -45,11 +45,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#endif
typedef jack_driver_desc_t * (*JackDriverDescFunction) ();
typedef Jack::JackDriverClientInterface* (*initialize) (Jack::JackEngineInterface*, Jack::JackSynchro**, const JSList *);
typedef Jack::JackDriverClientInterface* (*initialize) (Jack::JackEngineInterface*, Jack::JackSynchro*, const JSList *);
typedef struct _jack_driver_info
{
Jack::JackDriverClientInterface* (*initialize)(Jack::JackEngineInterface*, Jack::JackSynchro**, const JSList *);
Jack::JackDriverClientInterface* (*initialize)(Jack::JackEngineInterface*, Jack::JackSynchro*, const JSList *);
DRIVER_HANDLE handle;
}
jack_driver_info_t;
......
......@@ -138,7 +138,7 @@ extern "C"
return desc;
}
Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngineInterface* engine, Jack::JackSynchro** table, const JSList* params) {
Jack::JackDriverClientInterface* driver_initialize(Jack::JackEngineInterface* engine, Jack::JackSynchro* table, const JSList* params) {
jack_nframes_t sample_rate = 48000;
jack_nframes_t period_size = 1024;
unsigned int capture_ports = 2;
......
......@@ -38,7 +38,7 @@ class JackDummyDriver : public JackAudioDriver
public:
JackDummyDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro** table, unsigned long wait_time)
JackDummyDriver(const char* name, const char* alias, JackEngineInterface* engine, JackSynchro* table, unsigned long wait_time)
: JackAudioDriver(name, alias, engine, table), fWaitTime(wait_time)
{}
virtual ~JackDummyDriver()
......
......@@ -37,21 +37,18 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "JackClientControl.h"
#include "JackGlobals.h"
#include "JackChannel.h"
#include "JackSyncInterface.h"
#include "JackError.h"
namespace Jack
{
JackEngine::JackEngine(JackGraphManager* manager,
JackSynchro** table,
JackSynchro* table,
JackEngineControl* control)
{
fGraphManager = manager;
fSynchroTable = table;
fEngineControl = control;
fChannel = JackGlobals::MakeServerNotifyChannel();
fSignal = JackGlobals::MakeInterProcessSync();
for (int i = 0; i < CLIENT_NUM; i++)
fClientTable[i] = NULL;
}
......@@ -59,8 +56,6 @@ JackEngine::JackEngine(JackGraphManager* manager,
JackEngine::~JackEngine()
{
jack_log("JackEngine::~JackEngine");
delete fChannel;
delete fSignal;
}
int JackEngine::Open()
......@@ -68,7 +63,7 @@ int JackEngine::Open()
jack_log("JackEngine::Open");
// Open audio thread => request thread communication channel
if (fChannel->Open(fEngineControl->fServerName) < 0) {
if (fChannel.Open(fEngineControl->fServerName) < 0) {
jack_error("Cannot connect to server");
return -1;
} else {
......@@ -79,7 +74,7 @@ int JackEngine::Open()
int JackEngine::Close()
{
jack_log("JackEngine::Close");
fChannel->Close();
fChannel.Close();
// Close (possibly) remaining clients (RT is stopped)
for (int i = 0; i < CLIENT_NUM; i++) {
......@@ -94,7 +89,7 @@ int JackEngine::Close()
}
}
fSignal->Destroy();
fSignal.Destroy();
return 0;
}
......@@ -142,8 +137,8 @@ void JackEngine::ProcessNext(jack_time_t callback_usecs)
{
fLastSwitchUsecs = callback_usecs;
if (fGraphManager->RunNextGraph()) // True if the graph actually switched to a new state
fChannel->Notify(ALL_CLIENTS, kGraphOrderCallback, 0);
fSignal->SignalAll(); // Signal for threads waiting for next cycle
fChannel.Notify(ALL_CLIENTS, kGraphOrderCallback, 0);
fSignal.SignalAll(); // Signal for threads waiting for next cycle
}
void JackEngine::ProcessCurrent(jack_time_t callback_usecs)
......@@ -199,12 +194,12 @@ void JackEngine::CheckXRun(jack_time_t callback_usecs) // REVOIR les conditions
if (status != NotTriggered && status != Finished) {
jack_error("JackEngine::XRun: client = %s was not run: state = %ld", client->GetClientControl()->fName, status);
fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
}
if (status == Finished && (long)(finished_date - callback_usecs) > 0) {
jack_error("JackEngine::XRun: client %s finished after current callback", client->GetClientControl()->fName);
fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0); // Notify all clients
}
}
}
......@@ -281,7 +276,7 @@ void JackEngine::NotifyXRun(jack_time_t callback_usecs, float delayed_usecs)
// Use the audio thread => request thread communication channel
fEngineControl->ResetFrameTime(callback_usecs);
fEngineControl->NotifyXRun(delayed_usecs);
fChannel->Notify(ALL_CLIENTS, kXRunCallback, 0);
fChannel.Notify(ALL_CLIENTS, kXRunCallback, 0);
}
void JackEngine::NotifyXRun(int refnum)
......@@ -478,7 +473,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* sha
JackExternalClient* client = new JackExternalClient();
if (!fSynchroTable[refnum]->Allocate(name, fEngineControl->fServerName, 0)) {
if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
jack_error("Cannot allocate synchro");
goto error;
}
......@@ -488,7 +483,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* sha
goto error;
}
if (!fSignal->TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
if (!fSignal.TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
// Failure if RT thread is not running (problem with the driver...)
jack_error("Driver is not running");
goto error;
......@@ -510,7 +505,7 @@ int JackEngine::ClientExternalOpen(const char* name, int pid, int* ref, int* sha
error:
// Cleanup...
fSynchroTable[refnum]->Destroy();
fSynchroTable[refnum].Destroy();
fClientTable[refnum] = 0;
client->Close();
delete client;
......@@ -528,12 +523,12 @@ int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl
goto error;
}
if (!fSynchroTable[refnum]->Allocate(name, fEngineControl->fServerName, 0)) {
if (!fSynchroTable[refnum].Allocate(name, fEngineControl->fServerName, 0)) {
jack_error("Cannot allocate synchro");
goto error;
}
if (wait && !fSignal->TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
if (wait && !fSignal.TimedWait(DRIVER_OPEN_TIMEOUT * 1000000)) {
// Failure if RT thread is not running (problem with the driver...)
jack_error("Driver is not running");
goto error;
......@@ -555,7 +550,7 @@ int JackEngine::ClientInternalOpen(const char* name, int* ref, JackEngineControl
error:
// Cleanup...
fSynchroTable[refnum]->Destroy();
fSynchroTable[refnum].Destroy();
fClientTable[refnum] = 0;
return -1;
}
......@@ -608,7 +603,7 @@ int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wai
// Wait until next cycle to be sure client is not used anymore
if (wait) {
if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 2)) { // Must wait at least until a switch occurs in Process, even in case of graph end failure
if (!fSignal.TimedWait(fEngineControl->fTimeOutUsecs * 2)) { // Must wait at least until a switch occurs in Process, even in case of graph end failure
jack_error("JackEngine::ClientCloseAux wait error ref = %ld", refnum);
}
}
......@@ -617,7 +612,7 @@ int JackEngine::ClientCloseAux(int refnum, JackClientInterface* client, bool wai
NotifyRemoveClient(client->GetClientControl()->fName, client->GetClientControl()->fRefNum);
// Cleanup...
fSynchroTable[refnum]->Destroy();
fSynchroTable[refnum].Destroy();
fEngineControl->ResetRollingUsecs();
return 0;
}
......@@ -632,7 +627,7 @@ int JackEngine::ClientActivate(int refnum, bool state)
fGraphManager->Activate(refnum);
// Wait for graph state change to be effective
if (!fSignal->TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
if (!fSignal.TimedWait(fEngineControl->fTimeOutUsecs * 10)) {
jack_error("JackEngine::ClientActivate wait error ref = %ld name = %s", refnum, client->GetClientControl()->fName);
return -1;
} else {