JackDebugClient.cpp

00001 /*
00002 Copyright (C) 2004-2006 Grame
00003 
00004 This program is free software; you can redistribute it and/or modify
00005 it under the terms of the GNU General Public License as published by
00006 the Free Software Foundation; either version 2 of the License, or
00007 (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #include "JackDebugClient.h"
00021 #include "JackError.h"
00022 #include <iostream>
00023 #include <iomanip>
00024 #include <sstream>
00025 #include <fstream>
00026 #include <string>
00027 #include <time.h>
00028 
00029 using namespace std;
00030 
00031 namespace Jack
00032 {
00033 
00034 JackDebugClient::JackDebugClient(JackClient * client)
00035 {
00036     fTotalPortNumber = 1;       // The total number of port opened and maybe closed. Historical view.
00037     fOpenPortNumber = 0;        // The current number of opened port.
00038     fIsActivated = 0;
00039     fIsDeactivated = 0;
00040     fIsClosed = 0;
00041     fClient = client;
00042 }
00043 
00044 JackDebugClient::~JackDebugClient()
00045 {
00046     fTotalPortNumber--; // fTotalPortNumber start at 1
00047     *fStream << endl << endl << "----------------------------------- JackDebugClient summary ------------------------------- " << endl << endl;
00048     *fStream << "Client flags ( 1:yes / 0:no ) :" << endl;
00049     *fStream << setw(5) << "- Client call activated : " << fIsActivated << endl;
00050     *fStream << setw(5) << "- Client call deactivated : " << fIsDeactivated << endl;
00051     *fStream << setw(5) << "- Client call closed : " << fIsClosed << endl;
00052     *fStream << setw(5) << "- Total number of instantiated port : " << fTotalPortNumber << endl;
00053     *fStream << setw(5) << "- Number of port remaining open when exiting client : " << fOpenPortNumber << endl;
00054     if (fOpenPortNumber != 0)
00055         *fStream << "!!! WARNING !!! Some ports have not been unregistrated ! Incorrect exiting !" << endl;
00056     if (fIsDeactivated != fIsActivated)
00057         *fStream << "!!! ERROR !!! Client seem do not perform symetric activation-deactivation ! (not the same number of activate and deactivate)" << endl;
00058     if (fIsClosed == 0)
00059         *fStream << "!!! ERROR !!! Client have not been closed with jack_client_close() !" << endl;
00060 
00061     *fStream << endl << endl << "---------------------------- JackDebugClient detailed port summary ------------------------ " << endl << endl;
00062     //for (int i = 0; i < fTotalPortNumber ; i++) {
00063     for (int i = 1; i <= fTotalPortNumber ; i++) {
00064         *fStream << endl << "Port index (internal debug test value) : " << i << endl;
00065         *fStream << setw(5) << "- Name : " << fPortList[i].name << endl;
00066         *fStream << setw(5) << "- idport : " << fPortList[i].idport << endl;
00067         *fStream << setw(5) << "- IsConnected : " << fPortList[i].IsConnected << endl;
00068         *fStream << setw(5) << "- IsUnregistrated : " << fPortList[i].IsUnregistrated << endl;
00069         if (fPortList[i].IsUnregistrated == 0)
00070             *fStream << "!!! WARNING !!! Port have not been unregistrated ! Incorrect exiting !" << endl;
00071     }
00072     *fStream << "delete object JackDebugClient : end of tracing" << endl;
00073     delete fStream;
00074     delete fClient;
00075 }
00076 
00077 int JackDebugClient::Open(const char* name)
00078 {
00079     int Tidport;
00080     Tidport = fClient->Open(name);
00081     char provstr[256];
00082     char buffer[256];
00083     time_t curtime;
00084     struct tm *loctime;
00085     /* Get the current time. */
00086     curtime = time (NULL);
00087     /* Convert it to local time representation. */
00088     loctime = localtime (&curtime);
00089     strftime (buffer, 256, "%I-%M", loctime);
00090     sprintf(provstr, "JackClientDebug-%s-%s.log", name, buffer);
00091     fStream = new ofstream(provstr, ios_base::ate);
00092     if (fStream->is_open()) {
00093         if (Tidport == -1) {
00094             *fStream << "Trying to Open Client with name '" << name << "' with bad result (client not opened)." << Tidport << endl;
00095         } else {
00096             *fStream << "Open Client with name '" << name << "'." << endl;
00097         }
00098     } else {
00099         JackLog("JackDebugClient::Open : cannot open log file\n");
00100     }
00101     strcpy(fClientName, name);
00102     return Tidport;
00103 }
00104 
00105 int JackDebugClient::Close()
00106 {
00107     fIsClosed++;
00108     *fStream << "Client '" << fClientName << "' was Closed" << endl;
00109     return fClient->Close();
00110 }
00111 
00112 pthread_t JackDebugClient::GetThreadID()
00113 {
00114     return fClient->GetThreadID();
00115 }
00116 
00117 JackGraphManager* JackDebugClient::GetGraphManager() const
00118 {
00119     return fClient->GetGraphManager();
00120 }
00121 JackEngineControl* JackDebugClient::GetEngineControl() const
00122 {
00123     return fClient->GetEngineControl();
00124 }
00129 int JackDebugClient::ClientNotify(int refnum, const char* name, int notify, int sync, int value)
00130 {
00131     return fClient->ClientNotify( refnum, name, notify, sync, value);
00132 }
00133 
00134 int JackDebugClient::Activate()
00135 {
00136     int Tidport;
00137     Tidport = fClient->Activate();
00138     fIsActivated++;
00139     if (fIsDeactivated)
00140         *fStream << "Client '" << fClientName << "' call activate a new time (it already call 'activate' previously)." << endl;
00141     *fStream << "Client '" << fClientName << "' Activated" << endl;
00142     if (Tidport != 0)
00143         *fStream << "Client '" << fClientName << "' try to activate but server return " << Tidport << " ." << endl;
00144     return Tidport;
00145 }
00146 
00147 int JackDebugClient::Deactivate()
00148 {
00149     int Tidport;
00150     Tidport = fClient->Deactivate();
00151     fIsDeactivated++;
00152     if (fIsActivated == 0)
00153         *fStream << "Client '" << fClientName << "' deactivate while it hasn't been previoulsy activated !" << endl;
00154     *fStream << "Client '" << fClientName << "' Deactivated" << endl;
00155     if (Tidport != 0)
00156         *fStream << "Client '" << fClientName << "' try to deactivate but server return " << Tidport << " ." << endl;
00157     return Tidport;
00158 }
00159 
00160 //-----------------
00161 // Port management
00162 //-----------------
00163 
00164 int JackDebugClient::PortRegister(const char* port_name, const char* port_type, unsigned long flags, unsigned long buffer_size)
00165 {
00166     int Tidport;
00167     Tidport = fClient->PortRegister(port_name, port_type, flags, buffer_size);
00168     if (Tidport <= 0) {
00169         *fStream << "Client '" << fClientName << "' try port Register ('" << port_name << "') and server return error  " << Tidport << " ." << endl;
00170     } else {
00171         if (fTotalPortNumber < MAX_PORT_HISTORY) {
00172             fPortList[fTotalPortNumber].idport = Tidport;
00173             strcpy(fPortList[fTotalPortNumber].name, port_name);
00174             fPortList[fTotalPortNumber].IsConnected = 0;
00175             fPortList[fTotalPortNumber].IsUnregistrated = 0;
00176         } else {
00177             *fStream << "!!! WARNING !!! History is full : no more port history will be recorded." << endl;
00178         }
00179         fTotalPortNumber++;
00180         fOpenPortNumber++;
00181         *fStream << "Client '" << fClientName << "' port Register with portname '" << port_name << " port " << Tidport << "' ." << endl;
00182     }
00183     return Tidport;
00184 }
00185 
00186 int JackDebugClient::PortUnRegister(jack_port_id_t port_index)
00187 {
00188     int Tidport;
00189     Tidport = fClient->PortUnRegister(port_index);
00190     fOpenPortNumber--;
00191     int i;
00192     for (i = (fTotalPortNumber - 1); i >= 0; i--) {     // We search the record into the history
00193         if (fPortList[i].idport == port_index) {                // We found the last record
00194             if (fPortList[i].IsUnregistrated != 0)
00195                 *fStream << "!!! ERROR !!! : '" << fClientName << "' id deregistering port '" << fPortList[i].name << "' that have already been unregistered !" << endl;
00196             fPortList[i].IsUnregistrated++;
00197             break;
00198         }
00199     }
00200     if (i == 0) // Port is not found
00201         *fStream << "JackClientDebug : PortUnregister : port " << port_index << " was not previously registered !" << endl;
00202     if (Tidport != 0)
00203         *fStream << "Client '" << fClientName << "' try to do PortUnregister and server return " << Tidport << " )." << endl;
00204     *fStream << "Client '" << fClientName << "' unregister port '" << port_index << "'." << endl;
00205     return Tidport;
00206 }
00207 
00208 int JackDebugClient::PortConnect(const char* src, const char* dst)
00209 {
00210     if (!(fIsActivated))
00211         *fStream << "!!! ERROR !!! Trying to connect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
00212     int Tidport;
00213     int i;
00214     Tidport = fClient->PortConnect( src, dst);
00215     for (i = (fTotalPortNumber - 1); i >= 0; i--) {     // We search the record into the history
00216         if (strcmp(fPortList[i].name, src) == 0) {      // We found the last record in sources
00217             if (fPortList[i].IsUnregistrated != 0)
00218                 *fStream << "!!! ERROR !!! Connecting port " << src << " previoulsy unregistered !" << endl;
00219             fPortList[i].IsConnected++;
00220             *fStream << "Connecting port " << src << " to " << dst << ". ";
00221             break;
00222         } else if (strcmp(fPortList[i].name, dst) == 0 ) { // We found the record in dest
00223             if (fPortList[i].IsUnregistrated != 0)
00224                 *fStream << "!!! ERROR !!! Connecting port  " << dst << " previoulsy unregistered !" << endl;
00225             fPortList[i].IsConnected++;
00226             *fStream << "Connecting port " << src << " to " << dst << ". ";
00227             break;
00228         }
00229     }
00230     if (i == 0) // Port is not found
00231         *fStream << "JackClientDebug : PortConnect : port was not found in debug database !" << endl;
00232     if (Tidport != 0)
00233         *fStream << "Client '" << fClientName << "' try to do PortConnect but server return " << Tidport << " ." << endl;
00234     //*fStream << "Client Port Connect done with names" << endl;
00235     return Tidport;
00236 }
00237 
00238 int JackDebugClient::PortDisconnect(const char* src, const char* dst)
00239 {
00240     if (!(fIsActivated))
00241         *fStream << "!!! ERROR !!! Trying to disconnect a port ( " << src << " to " << dst << ") while the client has not been activated !" << endl;
00242     int Tidport;
00243     Tidport = fClient->PortDisconnect( src, dst);
00244     int i;
00245     for (i = (fTotalPortNumber - 1); i >= 0; i--) { // We search the record into the history
00246         if (strcmp(fPortList[i].name, src) == 0) { // We found the record in sources
00247             if (fPortList[i].IsUnregistrated != 0)
00248                 *fStream << "!!! ERROR !!! : Disconnecting port " << src << " previoulsy unregistered !" << endl;
00249             fPortList[i].IsConnected--;
00250             *fStream << "disconnecting port " << src << ". ";
00251             break;
00252         } else if (strcmp(fPortList[i].name, dst) == 0 ) { // We found the record in dest
00253             if (fPortList[i].IsUnregistrated != 0)
00254                 *fStream << "!!! ERROR !!! : Disonnecting port  " << dst << " previoulsy unregistered !" << endl;
00255             fPortList[i].IsConnected--;
00256             *fStream << "disconnecting port " << dst << ". ";
00257             break;
00258         }
00259     }
00260     if (i == 0) // Port is not found
00261         *fStream << "JackClientDebug : PortDisConnect : port was not found in debug database !" << endl;
00262     if (Tidport != 0)
00263         *fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << Tidport << " ." << endl;
00264     //*fStream << "Client Port Disconnect done." << endl;
00265     return Tidport;
00266 }
00267 
00268 int JackDebugClient::PortConnect(jack_port_id_t src, jack_port_id_t dst)
00269 {
00270     if (!(fIsActivated))
00271         *fStream << "!!! ERROR !!! : Trying to connect port  " << src << " to  " << dst << " while the client has not been activated !" << endl;
00272     int Tidport;
00273     Tidport = fClient->PortConnect(src, dst);
00274     int i;
00275     for (i = (fTotalPortNumber - 1); i >= 0; i--) {     // We search the record into the history
00276         if (fPortList[i].idport == src) {               // We found the record in sources
00277             if (fPortList[i].IsUnregistrated != 0)
00278                 *fStream << "!!! ERROR !!! : Connecting port  " << src << " previoulsy unregistered !" << endl;
00279             fPortList[i].IsConnected++;
00280             *fStream << "Connecting port " << src << ". ";
00281             break;
00282         } else if (fPortList[i].idport == dst) { // We found the record in dest
00283             if (fPortList[i].IsUnregistrated != 0)
00284                 *fStream << "!!! ERROR !!! : Connecting port  " << dst << " previoulsy unregistered !" << endl;
00285             fPortList[i].IsConnected++;
00286             *fStream << "Connecting port " << dst << ". ";
00287             break;
00288         }
00289     }
00290     if (i == 0) // Port is not found
00291         *fStream << "JackClientDebug : PortConnect : port was not found in debug database !" << endl;
00292     if (Tidport == -1)
00293         *fStream << "Client '" << fClientName << "' try to do Portconnect but server return " << Tidport << " ." << endl;
00294     //*fStream << "Client Port Connect with ID done." << endl;
00295     return Tidport;
00296 }
00297 
00298 int JackDebugClient::PortDisconnect(jack_port_id_t src)
00299 {
00300     if (!(fIsActivated))
00301         *fStream << "!!! ERROR !!! : Trying to disconnect port  " << src << " while that client has not been activated !" << endl;
00302     int Tidport;
00303     Tidport = fClient->PortDisconnect(src);
00304     int i;
00305     for (i = (fTotalPortNumber - 1); i >= 0; i--) {             // We search the record into the history
00306         if (fPortList[i].idport == src) {                               // We found the record in sources
00307             if (fPortList[i].IsUnregistrated != 0)
00308                 *fStream << "!!! ERROR !!! : Disconnecting port  " << src << " previoulsy unregistered !" << endl;
00309             fPortList[i].IsConnected--;
00310             *fStream << "Disconnecting port " << src << ". " << endl;
00311             break;
00312         }
00313     }
00314     if (i == 0) // Port is not found
00315         *fStream << "JackClientDebug : PortDisconnect : port was not found in debug database !" << endl;
00316     if (Tidport != 0)
00317         *fStream << "Client '" << fClientName << "' try to do PortDisconnect but server return " << Tidport << " ." << endl;
00318     //*fStream << "Client Port Disconnect with ID done." << endl;
00319     return Tidport;
00320 }
00321 
00322 int JackDebugClient::PortIsMine(jack_port_id_t port_index)
00323 {
00324     return fClient->PortIsMine(port_index);
00325 }
00326 
00327 //--------------------
00328 // Context management
00329 //--------------------
00330 
00331 int JackDebugClient::SetBufferSize(jack_nframes_t buffer_size)
00332 {
00333     return fClient->SetBufferSize(buffer_size);
00334 }
00335 
00336 int JackDebugClient::SetFreeWheel(int onoff)
00337 {
00338     return fClient->SetFreeWheel(onoff);
00339 }
00340 
00341 /*
00342 ShutDown is called:
00343 - from the RT thread when Execute method fails
00344 - possibly from a "closed" notification channel
00345 (Not needed since the synch object used (Sema of Fifo will fails when server quits... see ShutDown))
00346 */
00347 
00348 void JackDebugClient::ShutDown()
00349 {
00350     fClient->ShutDown();
00351 }
00352 
00353 //---------------------
00354 // Transport management
00355 //---------------------
00356 
00357 int JackDebugClient::ReleaseTimebase()
00358 {
00359     return fClient->ReleaseTimebase();
00360 }
00361 
00362 int JackDebugClient::SetSyncCallback(JackSyncCallback sync_callback, void* arg)
00363 {
00364     return fClient->SetSyncCallback(sync_callback, arg);
00365 }
00366 
00367 int JackDebugClient::SetSyncTimeout(jack_time_t timeout)
00368 {
00369     return fClient->SetSyncTimeout(timeout);
00370 }
00371 
00372 int JackDebugClient::SetTimebaseCallback(int conditional, JackTimebaseCallback timebase_callback, void* arg)
00373 {
00374     return fClient->SetTimebaseCallback( conditional, timebase_callback, arg);
00375 }
00376 
00377 int JackDebugClient::TransportLocate(jack_nframes_t frame)
00378 {
00379     return fClient->TransportLocate(frame);
00380 }
00381 
00382 jack_transport_state_t JackDebugClient::TransportQuery(jack_position_t* pos)
00383 {
00384     return fClient->TransportQuery(pos);
00385 }
00386 
00387 jack_nframes_t JackDebugClient::GetCurrentTransportFrame()
00388 {
00389     return fClient->GetCurrentTransportFrame();
00390 }
00391 
00392 int JackDebugClient::TransportReposition(jack_position_t* pos)
00393 {
00394     return fClient->TransportReposition(pos);
00395 }
00396 
00397 void JackDebugClient::TransportStart()
00398 {
00399     fClient->TransportStart();
00400 }
00401 
00402 void JackDebugClient::TransportStop()
00403 {
00404     fClient->TransportStop();
00405 }
00406 
00407 //---------------------
00408 // Callback management
00409 //---------------------
00410 
00411 void JackDebugClient::OnShutdown(JackShutdownCallback callback, void *arg)
00412 {
00413     fClient->OnShutdown(callback, arg);
00414 }
00415 
00416 int JackDebugClient::SetProcessCallback(JackProcessCallback callback, void *arg)
00417 {
00418     return fClient->SetProcessCallback( callback, arg);
00419 }
00420 
00421 int JackDebugClient::SetXRunCallback(JackXRunCallback callback, void *arg)
00422 {
00423     return fClient->SetXRunCallback(callback, arg);
00424 }
00425 
00426 int JackDebugClient::SetInitCallback(JackThreadInitCallback callback, void *arg)
00427 {
00428     return fClient->SetInitCallback(callback, arg);
00429 }
00430 
00431 int JackDebugClient::SetGraphOrderCallback(JackGraphOrderCallback callback, void *arg)
00432 {
00433     return fClient->SetGraphOrderCallback(callback, arg);
00434 }
00435 
00436 int JackDebugClient::SetBufferSizeCallback(JackBufferSizeCallback callback, void *arg)
00437 {
00438     return fClient->SetBufferSizeCallback(callback, arg);
00439 }
00440 
00441 int JackDebugClient::SetFreewheelCallback(JackFreewheelCallback callback, void *arg)
00442 {
00443     return fClient->SetFreewheelCallback(callback, arg);
00444 }
00445 
00446 int JackDebugClient::SetPortRegistrationCallback(JackPortRegistrationCallback callback, void *arg)
00447 {
00448     return fClient->SetPortRegistrationCallback(callback, arg);
00449 }
00450 
00451 JackClientControl* JackDebugClient::GetClientControl() const
00452 {
00453     return fClient->GetClientControl();
00454 }
00455 
00456 } // end of namespace
00457 

Generated on Wed Jan 10 11:42:44 2007 for Jackdmp by  doxygen 1.4.5