Commit e9269c34 authored by sletz's avatar sletz
Browse files

More client debug code: check if the client is still valid in every...

More client debug code: check if the client is still valid in every JackDebugClient method, check if the library context is still valid in every API call.

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1358 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 145b67bb
......@@ -2,6 +2,10 @@
Jackdmp changes log
---------------------------
2007-01-21 Stephane Letz <letz@grame.fr>
* More client debug code: check if the client is still valid in every JackDebugClient method, check if the library context is still valid in every API call.
2007-01-14 Stephane Letz <letz@grame.fr>
* Implement thread.h API.
......
This diff is collapsed.
......@@ -76,8 +76,8 @@ JackDebugClient::~JackDebugClient()
int JackDebugClient::Open(const char* name)
{
int Tidport;
Tidport = fClient->Open(name);
int res;
res = fClient->Open(name);
char provstr[256];
char buffer[256];
time_t curtime;
......@@ -90,36 +90,47 @@ int JackDebugClient::Open(const char* name)
sprintf(provstr, "JackClientDebug-%s-%s.log", name, buffer);
fStream = new ofstream(provstr, ios_base::ate);
if (fStream->is_open()) {
if (Tidport == -1) {
*fStream << "Trying to Open Client with name '" << name << "' with bad result (client not opened)." << Tidport << endl;
if (res == -1) {
*fStream << "Trying to open client with name '" << name << "' with bad result (client not opened)." << res << endl;
} else {
*fStream << "Open Client with name '" << name << "'." << endl;
*fStream << "Open client with name '" << name << "'." << endl;
}
} else {
JackLog("JackDebugClient::Open : cannot open log file\n");
}
strcpy(fClientName, name);
return Tidport;
return res;
}
int JackDebugClient::Close()
{
fIsClosed++;
*fStream << "Client '" << fClientName << "' was Closed" << endl;
*fStream << "Client '" << fClientName << "' was closed" << endl;
return fClient->Close();
}
void JackDebugClient::CheckClient() const
{
if (fIsClosed > 0) {
*fStream << "!!! ERROR !!! : Accessing a client '" << fClientName << "' already closed !" << endl;
*fStream << "This is likely to cause crash !'" << endl;
}
}
pthread_t JackDebugClient::GetThreadID()
{
CheckClient();
return fClient->GetThreadID();
}
JackGraphManager* JackDebugClient::GetGraphManager() const
{
CheckClient();
return fClient->GetGraphManager();
}
JackEngineControl* JackDebugClient::GetEngineControl() const
{
CheckClient();
return fClient->GetEngineControl();
}
/*!
......@@ -128,33 +139,36 @@ JackEngineControl* JackDebugClient::GetEngineControl() const
int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value)
{
CheckClient();
return fClient->ClientNotify( refnum, name, notify, sync, value);
}
int JackDebugClient::Activate()
{
int Tidport;
Tidport = fClient->Activate();
CheckClient();
int res;
res = fClient->Activate();
fIsActivated++;
if (fIsDeactivated)
*fStream << "Client '" << fClientName << "' call activate a new time (it already call 'activate' previously)." << endl;
*fStream << "Client '" << fClientName << "' Activated" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to activate but server return " << Tidport << " ." << endl;
return Tidport;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to activate but server return " << res << " ." << endl;
return res;
}
int JackDebugClient::Deactivate()
{
int Tidport;
Tidport = fClient->Deactivate();
CheckClient();
int res;
res = fClient->Deactivate();
fIsDeactivated++;
if (fIsActivated == 0)
*fStream << "Client '" << fClientName << "' deactivate while it hasn't been previoulsy activated !" << endl;
*fStream << "Client '" << fClientName << "' Deactivated" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to deactivate but server return " << Tidport << " ." << endl;
return Tidport;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to deactivate but server return " << res << " ." << endl;
return res;
}
//-----------------
......@@ -163,13 +177,14 @@ int JackDebugClient::Deactivate()
int JackDebugClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
{
int Tidport;
Tidport = fClient->PortRegister(port_name, port_type, flags, buffer_size);
if (Tidport <= 0) {
*fStream << "Client '" << fClientName << "' try port Register ('" << port_name << "') and server return error " << Tidport << " ." << endl;
CheckClient();
int res;
res = fClient->PortRegister(port_name, port_type, flags, buffer_size);
if (res <= 0) {
*fStream << "Client '" << fClientName << "' try port register ('" << port_name << "') and server return error " << res << " ." << endl;
} else {
if (fTotalPortNumber < MAX_PORT_HISTORY) {
fPortList[fTotalPortNumber].idport = Tidport;
fPortList[fTotalPortNumber].idport = res;
strcpy(fPortList[fTotalPortNumber].name, port_name);
fPortList[fTotalPortNumber].IsConnected = 0;
fPortList[fTotalPortNumber].IsUnregistrated = 0;
......@@ -178,15 +193,16 @@ int JackDebugClient::PortRegister(const char* port_name, const char* port_type,
}
fTotalPortNumber++;
fOpenPortNumber++;
*fStream << "Client '" << fClientName << "' port Register with portname '" << port_name << " port " << Tidport << "' ." << endl;
*fStream << "Client '" << fClientName << "' port register with portname '" << port_name << " port " << res << "' ." << endl;
}
return Tidport;
return res;
}
int JackDebugClient::PortUnRegister(jack_port_id_t port_index)
{
int Tidport;
Tidport = fClient->PortUnRegister(port_index);
CheckClient();
int res;
res = fClient->PortUnRegister(port_index);
fOpenPortNumber--;
int i;
for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
......@@ -199,19 +215,20 @@ int JackDebugClient::PortUnRegister(jack_port_id_t port_index)
}
if (i == 0) // Port is not found
*fStream << "JackClientDebug : PortUnregister : port " << port_index << " was not previously registered !" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to do PortUnregister and server return " << Tidport << " )." << endl;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to do PortUnregister and server return " << res << " )." << endl;
*fStream << "Client '" << fClientName << "' unregister port '" << port_index << "'." << endl;
return Tidport;
return res;
}
int JackDebugClient::PortConnect(const char* src, const char* dst)
{
if (!(fIsActivated))
CheckClient();
if (!fIsActivated)
*fStream << "!!! ERROR !!! Trying to connect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
int Tidport;
int res;
int i;
Tidport = fClient->PortConnect( src, dst);
res = fClient->PortConnect( src, dst);
for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
if (strcmp(fPortList[i].name, src) == 0) { // We found the last record in sources
if (fPortList[i].IsUnregistrated != 0)
......@@ -229,18 +246,19 @@ int JackDebugClient::PortConnect(const char* src, const char* dst)
}
if (i == 0) // Port is not found
*fStream << "JackClientDebug : PortConnect : port was not found in debug database !" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to do PortConnect but server return " << Tidport << " ." << endl;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to do PortConnect but server return " << res << " ." << endl;
//*fStream << "Client Port Connect done with names" << endl;
return Tidport;
return res;
}
int JackDebugClient::PortDisconnect(const char* src, const char* dst)
{
if (!(fIsActivated))
CheckClient();
if (!fIsActivated)
*fStream << "!!! ERROR !!! Trying to disconnect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
int Tidport;
Tidport = fClient->PortDisconnect( src, dst);
int res;
res = fClient->PortDisconnect( src, dst);
int i;
for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
if (strcmp(fPortList[i].name, src) == 0) { // We found the record in sources
......@@ -259,18 +277,19 @@ int JackDebugClient::PortDisconnect(const char* src, const char* dst)
}
if (i == 0) // Port is not found
*fStream << "JackClientDebug : PortDisConnect : port was not found in debug database !" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << Tidport << " ." << endl;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << res << " ." << endl;
//*fStream << "Client Port Disconnect done." << endl;
return Tidport;
return res;
}
int JackDebugClient::PortConnect(jack_port_id_t src, jack_port_id_t dst)
{
if (!(fIsActivated))
{
CheckClient();
if (!fIsActivated)
*fStream << "!!! ERROR !!! : Trying to connect port " << src << " to " << dst << " while the client has not been activated !" << endl;
int Tidport;
Tidport = fClient->PortConnect(src, dst);
int res;
res = fClient->PortConnect(src, dst);
int i;
for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
if (fPortList[i].idport == src) { // We found the record in sources
......@@ -289,18 +308,19 @@ int JackDebugClient::PortConnect(jack_port_id_t src, jack_port_id_t dst)
}
if (i == 0) // Port is not found
*fStream << "JackClientDebug : PortConnect : port was not found in debug database !" << endl;
if (Tidport == -1)
*fStream << "Client '" << fClientName << "' try to do Portconnect but server return " << Tidport << " ." << endl;
if (res == -1)
*fStream << "Client '" << fClientName << "' try to do Portconnect but server return " << res << " ." << endl;
//*fStream << "Client Port Connect with ID done." << endl;
return Tidport;
return res;
}
int JackDebugClient::PortDisconnect(jack_port_id_t src)
{
if (!(fIsActivated))
CheckClient();
if (!fIsActivated)
*fStream << "!!! ERROR !!! : Trying to disconnect port " << src << " while that client has not been activated !" << endl;
int Tidport;
Tidport = fClient->PortDisconnect(src);
int res;
res = fClient->PortDisconnect(src);
int i;
for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
if (fPortList[i].idport == src) { // We found the record in sources
......@@ -313,14 +333,15 @@ int JackDebugClient::PortDisconnect(jack_port_id_t src)
}
if (i == 0) // Port is not found
*fStream << "JackClientDebug : PortDisconnect : port was not found in debug database !" << endl;
if (Tidport != 0)
*fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << Tidport << " ." << endl;
if (res != 0)
*fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << res << " ." << endl;
//*fStream << "Client Port Disconnect with ID done." << endl;
return Tidport;
return res;
}
int JackDebugClient::PortIsMine(jack_port_id_t port_index)
{
CheckClient();
return fClient->PortIsMine(port_index);
}
......@@ -330,11 +351,13 @@ int JackDebugClient::PortIsMine(jack_port_id_t port_index)
int JackDebugClient::SetBufferSize(jack_nframes_t buffer_size)
{
CheckClient();
return fClient->SetBufferSize(buffer_size);
}
int JackDebugClient::SetFreeWheel(int onoff)
{
CheckClient();
return fClient->SetFreeWheel(onoff);
}
......@@ -356,51 +379,61 @@ void JackDebugClient::ShutDown()
int JackDebugClient::ReleaseTimebase()
{
CheckClient();
return fClient->ReleaseTimebase();
}
int JackDebugClient::SetSyncCallback(JackSyncCallback sync_callback, void* arg)
{
CheckClient();
return fClient->SetSyncCallback(sync_callback, arg);
}
int JackDebugClient::SetSyncTimeout(jack_time_t timeout)
{
CheckClient();
return fClient->SetSyncTimeout(timeout);
}
int JackDebugClient::SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg)
{
CheckClient();
return fClient->SetTimebaseCallback( conditional, timebase_callback, arg);
}
int JackDebugClient::TransportLocate(jack_nframes_t frame)
{
CheckClient();
return fClient->TransportLocate(frame);
}
jack_transport_state_t JackDebugClient::TransportQuery(jack_position_t* pos)
{
CheckClient();
return fClient->TransportQuery(pos);
}
jack_nframes_t JackDebugClient::GetCurrentTransportFrame()
{
CheckClient();
return fClient->GetCurrentTransportFrame();
}
int JackDebugClient::TransportReposition(jack_position_t* pos)
{
CheckClient();
return fClient->TransportReposition(pos);
}
void JackDebugClient::TransportStart()
{
CheckClient();
fClient->TransportStart();
}
void JackDebugClient::TransportStop()
{
CheckClient();
fClient->TransportStop();
}
......@@ -410,46 +443,55 @@ void JackDebugClient::TransportStop()
void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg)
{
CheckClient();
fClient->OnShutdown(callback, arg);
}
int JackDebugClient::SetProcessCallback(JackProcessCallback callback, void *arg)
{
CheckClient();
return fClient->SetProcessCallback( callback, arg);
}
int JackDebugClient::SetXRunCallback(JackXRunCallback callback, void *arg)
{
CheckClient();
return fClient->SetXRunCallback(callback, arg);
}
int JackDebugClient::SetInitCallback(JackThreadInitCallback callback, void *arg)
{
CheckClient();
return fClient->SetInitCallback(callback, arg);
}
int JackDebugClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg)
{
CheckClient();
return fClient->SetGraphOrderCallback(callback, arg);
}
int JackDebugClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg)
{
CheckClient();
return fClient->SetBufferSizeCallback(callback, arg);
}
int JackDebugClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg)
{
CheckClient();
return fClient->SetFreewheelCallback(callback, arg);
}
int JackDebugClient::SetPortRegistrationCallback(JackPortRegistrationCallback callback, void *arg)
{
CheckClient();
return fClient->SetPortRegistrationCallback(callback, arg);
}
JackClientControl* JackDebugClient::GetClientControl() const
{
CheckClient();
return fClient->GetClientControl();
}
......
......@@ -53,6 +53,7 @@ class JackDebugClient : public JackClient
std::ofstream* fStream;
protected:
PortFollower fPortList[MAX_PORT_HISTORY]; // Arbitrary value... To be tuned...
int fTotalPortNumber; // The total number of port opened and maybe closed. Historical view.
int fOpenPortNumber; // The current number of opened port.
......@@ -64,7 +65,6 @@ class JackDebugClient : public JackClient
public:
JackDebugClient(JackClient *fTheClient);
virtual ~JackDebugClient();
virtual int Open(const char* name);
......@@ -118,6 +118,8 @@ class JackDebugClient : public JackClient
int SetFreewheelCallback(JackFreewheelCallback callback, void* arg);
int SetPortRegistrationCallback(JackPortRegistrationCallback callback, void* arg);
JackClientControl* GetClientControl() const;
void CheckClient() const;
};
......
......@@ -88,6 +88,12 @@ struct JackLibGlobals
JackGlobals::Destroy();
}
}
static void CheckContext()
{
if (!(fClientCount > 0 && fGlobals))
jack_error("Error !!! : client accessing an already desallocated library context");
}
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment