Commit 5103ba49 authored by jcacerec's avatar jcacerec
Browse files

all debug comments removed

parent b19eb31b
......@@ -136,10 +136,7 @@ public:
/// \brief Stops the execution of the Thread
virtual void stop() {
QMutexLocker lock(&mMutex);
std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!STOPPING DATA PROTOCOL" << std::endl;
mStopped = true;
std::cout << "mStopped in stop dataprotocol: " << mStopped << std::endl;
std::cout << "!!!!!!!!!!!!!!!!!!!!!!!!AFTER mStopped true" << std::endl;
}
/** \brief Sets the size of the audio part of the packets
......
......@@ -225,15 +225,12 @@ int JackAudioInterface::startProcess() const
//*******************************************************************************
int JackAudioInterface::stopProcess() const
{
cout << "---> BEFORE JackAudioInterface::stopProcess()" << endl;
QMutexLocker locker(&sJackMutex);
cout << "---> AFTER JackAudioInterface::stopProcess() MUTEX" << endl;
if ( int code = (jack_client_close(mClient)) )
{
std::cerr << "Cannot disconnect client" << std::endl;
return(code);
}
cout << "---> AFTER JackAudioInterface::stopProcess()" << endl;
return(0);
}
......
......@@ -317,7 +317,7 @@ void JackTrip::startProcess() throw(std::invalid_argument)
clientPingToServerStart();
break;
case SERVERPINGSERVER :
if ( serverStart(true) == -1 ) {
if ( serverStart(true) == -1 ) { // if error on server start (-1) we return inmediatly
return;
}
break;
......@@ -327,7 +327,6 @@ void JackTrip::startProcess() throw(std::invalid_argument)
}
// Start Threads
cout << "---> STARTING THREADS mAudioInterface->startProcess();" << endl;
mAudioInterface->startProcess();
for (int i = 0; i < mProcessPlugins.size(); ++i) {
......@@ -335,32 +334,24 @@ void JackTrip::startProcess() throw(std::invalid_argument)
}
mAudioInterface->connectDefaultPorts();
mDataProtocolReceiver->start();
cout << "---> AFTER THREADS mDataProtocolReceiver->start();" << endl;
QThread::msleep(1);
mDataProtocolSender->start();
cout << "---> AFTER THREADS mDataProtocolSender->start();" << endl;
}
//*******************************************************************************
void JackTrip::stop()
{
cout << "INIT STOP-----------" << endl;
// Stop The Sender
mDataProtocolSender->stop();
cout << "Stop The Sender 1-----------" << endl;
mDataProtocolSender->wait();
cout << "Stop The Sender 2-----------" << endl;
// Stop The Receiver
mDataProtocolReceiver->stop();
cout << "Stop The Receiver 1-----------" << endl;
mDataProtocolReceiver->wait();
cout << "Stop The Receiver 2-----------" << endl;
// Stop the jack process callback
mAudioInterface->stopProcess();
cout << "Stop the jack process callback-----------" << endl;
cout << "JackTrip Processes STOPPED!" << endl;
cout << gPrintSeparator << endl;
......@@ -408,7 +399,6 @@ int JackTrip::serverStart(bool timeout, int udpTimeout)
// Get the client address when it connects
cout << "Waiting for Connection From Client..." << endl;
cout << "TIME OUT ----> " << timeout << endl;
QHostAddress peerHostAddress;
uint16_t peer_port;
QUdpSocket UdpSockTemp;// Create socket to wait for client
......@@ -431,7 +421,7 @@ int JackTrip::serverStart(bool timeout, int udpTimeout)
}
if (!UdpSockTemp.hasPendingDatagrams()) {
emit signalUdpTimeOut();
cout << "---> JackTrip::serverStart TIMEOUT" << endl;
cout << "JackTrip Server Timed Out!" << endl;
return -1;
}
} else {
......
......@@ -352,10 +352,8 @@ public slots:
virtual void slotStopProcesses()
{
std::cout << "Stopping JackTrip..." << std::endl;
std::cout << "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" << std::endl;
mStopped = true;
this->stop();
std::cout << "AFTER Stopping JackTrip..." << std::endl;
}
/** \brief This slot emits in turn the signal signalNoUdpPacketsForSeconds
......
......@@ -108,10 +108,7 @@ void JackTripWorker::run()
This is not supported, exceptions thrown in worker threads must be
caught before control returns to Qt Concurrent.'*/
cout << "---> BEFORE QMutexLocker locker(&mMutex); mSpawning = true; " << endl;
{ QMutexLocker locker(&mMutex); mSpawning = true; }
cout << "---> AFTER QMutexLocker locker(&mMutex); mSpawning = true; " << endl;
QHostAddress ClientAddress;
......@@ -133,20 +130,16 @@ void JackTripWorker::run()
// Connect signals and slots
// -------------------------
cout << "---> BEFORE SIGNAL SLOTS 1 " << endl;
// Connection to terminate JackTrip when packets haven't arrive for
// a certain amount of time
QObject::connect(&jacktrip, SIGNAL(signalNoUdpPacketsForSeconds()),
&jacktrip, SLOT(slotStopProcesses()), Qt::QueuedConnection);
cout << "---> BEFORE SIGNAL SLOTS 2 " << endl;
// Connection to terminate the local eventloop when jacktrip is done
QObject::connect(&jacktrip, SIGNAL(signalProcessesStopped()),
&event_loop, SLOT(quit()), Qt::QueuedConnection);
cout << "---> BEFORE SIGNAL SLOTS 3 " << endl;
QObject::connect(this, SIGNAL(signalRemoveThread()),
&jacktrip, SLOT(slotStopProcesses()), Qt::QueuedConnection);
cout << "---> BEFORE ClientAddress.setAddress(mClientAddress) " << endl;
ClientAddress.setAddress(mClientAddress);
// If I don't type this line, I get a bus error in the next line.
// I still haven't figure out why
......@@ -155,7 +148,6 @@ void JackTripWorker::run()
jacktrip.setBindPorts(mServerPort);
//jacktrip.setPeerPorts(mClientPort);
cout << "---> BEFORE PeerConnectionMode " << endl;
int PeerConnectionMode = setJackTripFromClientHeader(jacktrip);
if ( PeerConnectionMode == -1 ) {
mUdpMasterListener->releaseThread(mID);
......@@ -166,17 +158,11 @@ void JackTripWorker::run()
// Start Threads and event loop
cout << "---> BEFORE jacktrip.startProcess() " << endl;
jacktrip.startProcess();
cout << "---> BEFORE jacktrip.start()" << endl;
jacktrip.start(); // ########### JamTest Only #################
cout << "@@@@@@@@@@@@@@@@@> AFTER JACKTRIPWORKER jacktrip.start()" << endl;
cout << "---> BEFORE QMutexLocker locker(&mMutex);" << endl;
{ // Thread is already spawning, so release the lock
QMutexLocker locker(&mMutex);
mSpawning = false;
}
// Thread is already spawning, so release the lock
{ QMutexLocker locker(&mMutex); mSpawning = false; }
event_loop.exec(); // Excecution will block here until exit() the QEventLoop
//--------------------------------------------------------------------------
......@@ -239,12 +225,11 @@ int JackTripWorker::setJackTripFromClientHeader(JackTrip& jacktrip)
while ( (!UdpSockTemp.hasPendingDatagrams()) && (elapsedTime <= udpTimeout) ) {
sleep.wait(&mutex,sleepTime);
elapsedTime += sleepTime;
cout << "---------> ELAPSED TIME: " << elapsedTime << endl;
//cout << "---------> ELAPSED TIME: " << elapsedTime << endl;
}
}
if (!UdpSockTemp.hasPendingDatagrams()) {
UdpSockTemp.close();
cout << "---> UdpSockTemp.hasPendingDatagrams() returning error" << endl;
return -1;
}
int packet_size = UdpSockTemp.pendingDatagramSize();
......@@ -284,6 +269,5 @@ bool JackTripWorker::isSpawning()
void JackTripWorker::stopThread()
{
QMutexLocker locker(&mMutex);
cout << "---> EMIT SIGNAL STOP THREADS JackTripWorker::stopThread()" << endl;
emit signalRemoveThread();
}
......@@ -304,14 +304,6 @@ void UdpDataProtocol::getPeerAddressFromFirstPacket(QUdpSocket& UdpSocket,
//*******************************************************************************
void UdpDataProtocol::run()
{
cout << "===> STARTING UdpDataProtocol::run()" << endl;
/*
{
QMutexLocker lock(&mMutex);
mStopped = false;
}
*/
//QObject::connect(this, SIGNAL(signalError(const char*)),
// mJackTrip, SLOT(slotStopProcesses()),
// Qt::QueuedConnection);
......@@ -322,9 +314,6 @@ void UdpDataProtocol::run()
bindSocket(UdpSocket); // Bind Socket
} catch ( const std::exception & e ) {
emit signalError( e.what() );
//this->terminate();
//this->wait();
cout << "AFTER EMITING" << endl;
return;
}
......@@ -397,7 +386,6 @@ void UdpDataProtocol::run()
uint16_t last_seq_num = 0; // Store last package sequence number
uint16_t newer_seq_num = 0; // Store newer sequence number
cout << "-----------------------> BEFORE WHILE" << endl;
while ( !mStopped )
{
// Timer to report packets arriving too late
......@@ -427,9 +415,7 @@ void UdpDataProtocol::run()
current_seq_num,
last_seq_num,
newer_seq_num);
//cout << "----------> receivePacketRedundancy" << endl;
}
cout << "-----------------------> AFTER WHILE" << endl;
break; }
case SENDER : {
......@@ -467,7 +453,6 @@ bool UdpDataProtocol::waitForReady(QUdpSocket& UdpSocket, int timeout_msec)
while ( ( !(UdpSocket.hasPendingDatagrams()) && (ellaped_time_usec <= timeout_usec) )
&& !mStopped ){
//cout << mStopped << endl;
if (mStopped) { return false; }
QThread::usleep(loop_resolution_usec);
ellaped_time_usec += loop_resolution_usec;
......
......@@ -179,33 +179,26 @@ void UdpMasterListener::run()
// Close and Delete the socket
// ---------------------------
clientConnection->close();
cout << "---> BEFORE DELETE clientConnection" << endl;
delete clientConnection;
cout << "JackTrip MULTI-THREADED SERVER: Client TCP Socket Closed!" << endl;
// Spawn Thread to Pool
// --------------------
// Register JackTripWorker with the master listener
cout << "BEFORE DELETE mJTWorkers" << endl;
delete mJTWorkers->at(id); // just in case the Worker was previously created
mJTWorkers->insert(id, NULL);
mJTWorkers->replace(id, new JackTripWorker(this));
cout << "---> AFTER new" << endl;
// redirect port and spawn listener
{
QMutexLocker lock(&mMutex);
cout << "---> AFTER QMutexLocker" << endl;
mJTWorkers->at(id)->setJackTrip(id, mActiveAddress[id][0],
server_udp_port, mActiveAddress[id][1],
1); /// \todo temp default to 1 channel
}
cout << "---> AFTER setJackTrip" << endl;
//send one thread to the pool
mThreadPool.start(mJTWorkers->at(id), QThread::TimeCriticalPriority);
cout << "---> AFTER mThreadPool.start" << endl;
// wait until one is complete before another spawns
while (mJTWorkers->at(id)->isSpawning()) { QThread::msleep(10); }
cout << "---> AFTER while (mJTWorkers->at(id)->isSpawning())" << endl;
//mTotalRunningThreads++;
cout << "JackTrip MULTI-THREADED SERVER: Total Running Threads: " << mTotalRunningThreads << endl;
cout << "===============================================================" << endl;
......@@ -301,8 +294,6 @@ int UdpMasterListener::sendUdpPort(QTcpSocket* clientConnection, int udp_port)
std::memcpy(port_buf, &udp_port, sizeof(udp_port));
clientConnection->write(port_buf, sizeof(udp_port));
while ( clientConnection->bytesToWrite() > 0 ) {
cout << "----> clientConnection->isValid(): " << clientConnection->isValid() << "STATE: " << clientConnection->state() << endl;
//if ( clientConnection->isValid() ) {
if ( clientConnection->state() == QAbstractSocket::ConnectedState ) {
clientConnection->waitForBytesWritten(-1);
}
......@@ -348,7 +339,6 @@ void UdpMasterListener::bindUdpSocket(QUdpSocket& udpsocket, int port) throw(std
int UdpMasterListener::isNewAddress(uint32_t address, uint16_t port)
{
QMutexLocker lock(&mMutex);
//cout << "######################INIT isNewAddress"<< endl;
bool busyAddress = false;
int id = 0;
......@@ -363,7 +353,6 @@ int UdpMasterListener::isNewAddress(uint32_t address, uint16_t port)
if ( address==mActiveAddress[i][0] && port==mActiveAddress[i][1]) {
id = i;
busyAddress = true;
//cout << i << "##########################BUSY############################"<< endl;
}
}
if ( !busyAddress ) {
......@@ -381,11 +370,9 @@ int UdpMasterListener::isNewAddress(uint32_t address, uint16_t port)
mActiveAddress[id][1] = port;
} else {
id++;
cout << id << endl;
}
}
}
//cout << "ID -------------------------------> " << id << "BUSYADDRESS " << busyAddress << endl;
if (!busyAddress) {
mTotalRunningThreads++;
}
......@@ -410,9 +397,7 @@ int UdpMasterListener::getPoolID(uint32_t address, uint16_t port)
//*******************************************************************************
int UdpMasterListener::releaseThread(int id)
{
cout << "---> UdpMasterListener::releaseThread(int id)" << endl;
QMutexLocker lock(&mMutex);
cout << "---> AFTER UdpMasterListener::releaseThread(int id) MUTEX" << endl;
mActiveAddress[id][0] = 0;
mActiveAddress[id][1] = 0;
mTotalRunningThreads--;
......
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