[Sofaswitch-svn] [commit] r395 - in sofaswitch/trunk: sofa/src voip
Author: derek Date: Fri Aug 24 01:14:41 2007 New Revision: 395 Modified: sofaswitch/trunk/sofa/src/messlist.cxx sofaswitch/trunk/voip/comms.cxx sofaswitch/trunk/voip/comms.h sofaswitch/trunk/voip/jocall.cxx sofaswitch/trunk/voip/mymanager.cxx sofaswitch/trunk/voip/mymanager.h sofaswitch/trunk/voip/udpsound.cxx Log: Multiple patches to logging. Keep compatible with current opal code. Modified: sofaswitch/trunk/sofa/src/messlist.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messlist.cxx (original) +++ sofaswitch/trunk/sofa/src/messlist.cxx Fri Aug 24 01:14:41 2007 @@ -104,7 +104,6 @@ PWaitAndSignal m(mutex); if (PAbstractList::GetSize() == 0) { - PTRACE(3, "No more available comms to use"); return NULL; } Modified: sofaswitch/trunk/voip/comms.cxx ============================================================================== --- sofaswitch/trunk/voip/comms.cxx (original) +++ sofaswitch/trunk/voip/comms.cxx Fri Aug 24 01:14:41 2007 @@ -54,16 +54,18 @@ { PTRACE(3, "Destroy the Comms class instance for " << GetOurId() << " all done"); + DecComms(); +} + +void Comms::OnOpalCallCleared() +{ PWaitAndSignal m(opalCallLock); if (myOpalCall != NULL) { myOpalCall->SafeDereference(); myOpalCall = NULL; } - - DecComms(); } - void Comms::AdviseCallCreation() { PTRACE(3, "Advise of call creation on " << GetOurId() << " and " << remoteController); @@ -82,13 +84,11 @@ { PTRACE(5, "Comms StopAllComms Start " << GetOurId()); Terminate(); - WaitForTermination(); PTRACE(5, "Comms StopAllComms All done " << GetOurId()); } void Comms::OnTermination() { - new CommsConsumer(manager, this); PTRACE(3, "END of comms communications for " << GetOurId()); } @@ -110,8 +110,6 @@ { audioSocket.Close(); Terminate(); - - audioSocket.Close(); } void Comms::ProcessCallNode(PStringArray &cmds, PString & sender) @@ -264,6 +262,16 @@ return mf; } +void CommsProvider::RemoveAllMessageFrames() +{ + PWaitAndSignal m(mutex); + Comms *mf = NULL; + + for(PINDEX i = 0; i < PAbstractList::GetSize(); i++) { + mf = (Comms *)PAbstractList::GetAt(i); + new CommsConsumer(manager, mf); + } +} Comms *CommsProvider::GetNextComms() { @@ -271,7 +279,7 @@ for(;;) { Comms *c = (Comms *)GetTheNextMessageFrame(); if (c->IsTerminated()) { - manager.DestroyOldComms(c); + delete c; } return c; } @@ -284,11 +292,13 @@ manager(_manager), comms(m) { + PTRACE(2, "Create a Clear Comms Consumer to clear a comms instance " << m->GetOurId()); Resume(); } CommsConsumer::~CommsConsumer() { + PTRACE(2, "Finish Clear Comms Consumer to clear a comms instance " << ourId); } void CommsConsumer::Main() @@ -298,29 +308,15 @@ comms->WaitForTermination(); - /*This line means that if, for any reason, the sofa communications - terminates at any time, we will always detect it, and close this - call off dead */ - manager.ClearCall(comms->GetOpalCallToken()); - - PString ourId = comms->GetOurId(); + ourId = comms->GetOurId(); PTRACE(3, "START checking: look for " << ourId << " to appear in a manager list"); - - PINDEX iteration = 0; - for(;;) { - iteration++; - PTRACE(6, "look for comms instance " << ourId << " in the manager" - << " iteration " << iteration); - Comms *c = manager.ClearCommsId(ourId); - if (c != NULL) { - PTRACE(3, "NOW delete comms instance " << ourId); - PTRACE(3, "as we found it and have exclusive access to it"); - PTRACE(3, "and know that this thread has finished."); - delete c; - return; - } - PThread::Sleep(400); + Comms *c = manager.ClearCommsId(ourId); + if (c != NULL) { + PTRACE(3, "NOW delete comms instance " << ourId); + PTRACE(3, "as we found it and have exclusive access to it"); + PTRACE(3, "and know that this thread has finished."); + delete c; } } /* The comment below is magic for those who use emacs to edit this file. */ Modified: sofaswitch/trunk/voip/comms.h ============================================================================== --- sofaswitch/trunk/voip/comms.h (original) +++ sofaswitch/trunk/voip/comms.h Fri Aug 24 01:14:41 2007 @@ -84,6 +84,12 @@ notify the controller accordingly)). */ void AdviseCallCreation(); + + /**A Callback from the opal call class. This indicates that the call has + been completed dead cleared done and dusted. There are no more + communications to come from the current voip call, so this comms instance + can lose its interest in the OpalCall Structure */ + void OnOpalCallCleared(); /**Assign a value to the jocall pointer */ void SetMyOpalCallPtr(MyOpalCall *ptr); @@ -190,6 +196,9 @@ /**Retrieve the next Comms instance */ Comms *GetNextComms(); + /**Cause each entry on this list to be deleted by an instance of the + CommsConsumer class */ + void RemoveAllMessageFrames(); protected: @@ -226,6 +235,9 @@ /**The instance we have to delete */ Comms *comms; + + /**The id associated with the comms instance we ahve to delete */ + PString ourId; }; ///////////////////////////////////////////////////////////////////////////// Modified: sofaswitch/trunk/voip/jocall.cxx ============================================================================== --- sofaswitch/trunk/voip/jocall.cxx (original) +++ sofaswitch/trunk/voip/jocall.cxx Fri Aug 24 01:14:41 2007 @@ -76,10 +76,12 @@ MyOpalCall::~MyOpalCall() { PTRACE(3, "Destructor for Opal Call " << GetToken() << " and " << comms.GetOurId()); - comms.StopAllCommunications(); + comms.StopAllCommunications(); +/* The comms instance must not self delete on completion. We stop the comms + instance, and then we delete it (as we are finished with it) */ + comms.WaitForTermination(); - - manager.DestroyOldComms(commsPtr); + manager.AppendFinishedComms(commsPtr); PTRACE(3, "MyOpalCall\t" << *this << " destroyed dead and gone"); DecMyOpalCall(); @@ -167,6 +169,7 @@ PTRACE(2, "on cleared of this call " << myToken); OpalCall::OnCleared(); CloseThisId(); + comms.OnOpalCallCleared(); } void MyOpalCall::SendThisDtmf(const PString & value) Modified: sofaswitch/trunk/voip/mymanager.cxx ============================================================================== --- sofaswitch/trunk/voip/mymanager.cxx (original) +++ sofaswitch/trunk/voip/mymanager.cxx Fri Aug 24 01:14:41 2007 @@ -83,8 +83,8 @@ MyManager::MyManager(LaunchNewId & _lid, PString & _ourId, PString & _ourPassword) : lid(_lid), - supervisor(*(new Supervisor(lid))) - +supervisor(*(new Supervisor(lid))), +runningComms(*new CommsProvider(lid, *this)) { allocationNumber = 0; IncMyManager(); @@ -106,11 +106,10 @@ supervisor.Resume(); nodesMakingCalls.Initialise(); + nodesFinishedCalls.Initialise(); - runningComms = new CommsProvider(lid, *this); - runningComms->SetPreAllocatedSize(10); - runningComms->Initialise(); - deadComms.Initialise(); + runningComms.SetPreAllocatedSize(10); + runningComms.Initialise(); } @@ -120,8 +119,6 @@ supervisor.WaitForTermination(); delete & supervisor; - delete runningComms; - PTRACE(3, "destroy the manager"); DecMyManager(); } @@ -497,13 +494,11 @@ PStringStream status; status << endl; status << "Pre built calls " - << PString(runningComms->GetSize()) << endl; + << PString(runningComms.GetSize()) << endl; status << "Pending message frames " << PString(nodesMakingCalls.GetSize()) << endl; status << "Current active calls " << PString(activeCalls.GetSize()) << endl; - status << "Terminating calls " - << PString(deadComms.GetSize()) << endl; status << "--------------" << endl; status << " Comms count is " @@ -522,9 +517,8 @@ << GetCountUdpSoundChannel() << endl; status << "--------------" << endl; - PStringArray prebuilts = runningComms->GetCurrentEntries(); + PStringArray prebuilts = runningComms.GetCurrentEntries(); PStringArray pendingNames = nodesMakingCalls.GetCurrentEntries(); - PStringArray deadNames = deadComms.GetCurrentEntries(); if (prebuilts.GetSize() > 0) { status << "PreBuilt frames " << endl; @@ -551,13 +545,6 @@ status << endl; } - if (deadNames.GetSize() > 0) { - status << "Calls that are being cleaned up " << endl; - for (PINDEX i = 0; i < deadNames.GetSize(); i++) - status << " " << deadNames[i] << endl; - status << endl; - } - return status; } @@ -571,25 +558,28 @@ return c; } - c = (Comms *)runningComms->GetMessageFrameOn(memberId); + c = (Comms *)runningComms.GetMessageFrameOn(memberId); if (c != NULL) { PTRACE(3, "Clear comms Id on " << memberId << " for prebuilt, ready to go frames"); return c; } - - c = (Comms *)deadComms.GetMessageFrameOn(memberId); + + c = (Comms *)nodesFinishedCalls.GetMessageFrameOn(memberId); if (c != NULL) { - PTRACE(3, "Clear comms Id on " << memberId - << " for dead comms instances frame"); + PTRACE(3, "Clear comms Id on " << memberId << " for comms instances finished in a call"); return c; } - PTRACE(3, "Clear comms Id on " << memberId << " not found"); return NULL; } - +void MyManager::AppendFinishedComms(Comms *commsPtr) +{ + PTRACE(3, "Manager\tThis comms instance has finished a call, and is about to DIE" << commsPtr->GetOurId()); + nodesFinishedCalls.AddNewMessageFrame(commsPtr); + new CommsConsumer(*this, commsPtr); +} PString MyManager::GetDurationInfo(const PString & token) { @@ -605,7 +595,7 @@ void MyManager::RequestNewId(PString & requester) { - Comms *c = runningComms->GetNextComms(); + Comms *c = runningComms.GetNextComms(); if (c == NULL) return; @@ -660,24 +650,18 @@ return; } -void MyManager::DestroyOldComms(Comms *oldComms) -{ - PTRACE(3, "Place Comms instance " << *oldComms << " onto the deadComms list"); - deadComms.AddNewMessageFrame(oldComms); -} - - void MyManager::RemoveAllCalls() { /* Stop the building of new Comms instances */ PTRACE(3, "Manager\tRemove All Calls Start"); - runningComms->Terminate(); + runningComms.Terminate(); nodesMakingCalls.TerminateAllMessageFrames(); - runningComms->WaitForTermination(); - runningComms->TerminateAllMessageFrames(); - + runningComms.WaitForTermination(); + runningComms.TerminateAllMessageFrames(); + runningComms.RemoveAllMessageFrames(); + PTRACE(3, "Manager\tRemove all calls who are making calls"); /**Now we can remove all calls in the list */ @@ -704,26 +688,26 @@ for(PINDEX i = 0; i < 2; i++) { RemoveAllCalls(); PTRACE(3, "END of all calls "); - - while(runningComms->GetSize() > 0) { - PThread::Sleep(100); - } - PTRACE(3, "Running comms has a size of 0"); - + } + + while(runningComms.GetSize() > 0) { + PTRACE(3, "Manager\tWait for runningComs to reach 0. Curently " + << runningComms.GetSize() << " elements"); + PThread::Sleep(100); + + PTRACE(3, "Running comms has a size of " << runningComms.GetSize()); + while (nodesMakingCalls.GetSize() > 0) { + PTRACE(3, "Manager\tWait for Nodes Makeing Calls to get to zero size"); PThread::Sleep(100); } - PTRACE(3, "nodes making calls has a size of 0"); + PTRACE(3, "nodes making calls has a size of " << nodesMakingCalls.GetSize()); while (activeCalls.GetSize() > 0) { + PTRACE(3, "Manager\tWait for active calls to get to zero size"); PThread::Sleep(100); } - PTRACE(3, "active calls has a size of 0"); - - while (deadComms.GetSize() > 0) { - PThread::Sleep(100); - } - PTRACE(3, "dead comms has a size of 0"); + PTRACE(3, "active calls has a size of " << activeCalls.GetSize()); } PTRACE(3, "Now, we have to leave a wait period"); @@ -836,7 +820,7 @@ { PTRACE(3, "Manager\tCreate a call with any CallID"); Comms *c; - c = runningComms->GetNextComms(); + c = runningComms.GetNextComms(); if (c == NULL) { PTRACE(3, "Failed to make a new node"); @@ -874,7 +858,7 @@ if (c == NULL) { PTRACE(3, "No valid comms structure yet, so create one on the fly "); - c = runningComms->GetNextComms(); + c = runningComms.GetNextComms(); if (c == NULL) { PTRACE(1, "BAD vibes, failed to creaate comms instance "); Modified: sofaswitch/trunk/voip/mymanager.h ============================================================================== --- sofaswitch/trunk/voip/mymanager.h (original) +++ sofaswitch/trunk/voip/mymanager.h Fri Aug 24 01:14:41 2007 @@ -206,10 +206,6 @@ is available */ void RequestNewId(PString & requester); - /**Take this old Comms structure, and delete it, in a separate - thread to the MyOpalCall destructor */ - void DestroyOldComms(Comms *oldComms); - /**Check the different lists of Comms instances in this Manager (runningComms, deadComms, and nodesMakingCalls) and find the matching Comms instance. Return a pointer to the Comms @@ -220,6 +216,11 @@ now" */ void RemoveAllCalls(); + /**This comms instance was used in a call, and the call is finished. Put + this comms instance in a list. This method will then invoke a + CommsConsumer class to remove this instance */ + void AppendFinishedComms(Comms *commsPtr); + protected: /**The interface to the external script which runs python, to provide comms for us */ LaunchNewId &lid; @@ -227,15 +228,21 @@ /** The manager of the comms with remote controller. It allows the calls to be setup */ Supervisor & supervisor; + /**A list of Comms instances, which are already built, connected + to the remote server, and ready to be used */ + CommsProvider &runningComms; + /**A list of the nodes who are initiating calls through us. Frames will be deleted from this list if they have not been claimed. Frames have 10 seconds of life on this list before they are deleted */ MessageFrameListPending nodesMakingCalls; - /**A list of Comms instances, which are already built, connected - to the remote server, and ready to be used */ - CommsProvider *runningComms; + /**A list of the nodes who have completed calls they are in. Frames will + be deleted by the CommsConsumer class, which will fish the node out of + this list and delete it. */ + MessageFrameList nodesFinishedCalls; + /**A list of Comms instances that are known to have died. Comms instances will be removed from this list by the CommsConsumer class.*/ Modified: sofaswitch/trunk/voip/udpsound.cxx ============================================================================== --- sofaswitch/trunk/voip/udpsound.cxx (original) +++ sofaswitch/trunk/voip/udpsound.cxx Fri Aug 24 01:14:41 2007 @@ -101,16 +101,22 @@ BOOL UdpSoundChannel::Write(const void * buffer, PINDEX amount) { - PTRACE(6, "MEDIA\tWrite " << amount << " bytes to the socket"); + { + WORD dPort; + PIPSocket::Address destination; + + audioSocket.GetSendAddress(destination, dPort); + + PTRACE(6, "MEDIA\tWrite " << amount << " bytes to the socket " << destination << ":" << dPort); + } + if (!IsOpen()) { PTRACE(3, "MEDIA\tWrite failed as this sound channel is closed"); return FALSE; } BOOL res = audioSocket.Write(buffer, amount); - if (res) { - PTRACE(5, "MEDIA\tWrite succeeded"); - } else { + if (res == FALSE) { WORD dPort; PIPSocket::Address destination; @@ -123,7 +129,7 @@ lastWriteCount = amount; - PTRACE(5, "MEDIA\tWrite to socket return " << audioSocket.IsOpen()); + PTRACE(7, "MEDIA\tWrite to socket return " << audioSocket.IsOpen()); return audioSocket.IsOpen(); } @@ -136,31 +142,32 @@ } BOOL readOk = TRUE; - PTRACE(5, "MEDIA\tNow do a read of " << amount << " bytes for " << GetSSLabel(isSource)); - PTRACE(5, "MEDIA\tThe read queue has a buffered bytes size of " << readQueue.GetLength()); + PTRACE(7, "MEDIA\tNow do a read of " << amount << " bytes for " << GetSSLabel(isSource)); + PTRACE(7, "MEDIA\tThe read queue has a buffered bytes size of " << readQueue.GetLength()); while (amount > readQueue.GetLength()) { - PTRACE(5, "The internal buffer has insufficient bytes, as " << readQueue.GetLength() << " is less than " << amount); - PTRACE(5, "MEDIA\tGrab some extra bytes from the socket"); readOk = audioSocket.Read(readBuffer.GetPointer(), 480); if (!readOk) { - PTRACE(1, "MEDIA\tThe read of a packet from a socket failed for " << GetSSLabel(isSource)); + PTRACE(3, "MEDIA\tThe read of a packet from a socket failed for " + << GetSSLabel(isSource)); return FALSE; } - PTRACE(5, "The socket provided us with " << audioSocket.GetLastReadCount() << " bytes"); + PTRACE(7, "The socket provided us with " + << audioSocket.GetLastReadCount() << " bytes"); readOk = readQueue.Write(readBuffer.GetPointer(), audioSocket.GetLastReadCount()); - PTRACE(5, "The readqueue now has a size of " << readQueue.GetLength() << " bytes"); + PTRACE(7, "The readqueue now has a size of " + << readQueue.GetLength() << " bytes"); if (!readOk) { - PTRACE(1, "Failed to write incoming packet to the memory queue"); + PTRACE(3, "Failed to write incoming packet to the memory queue"); return FALSE; } } readOk = readQueue.Read(buffer, amount); lastReadCount = readQueue.GetLastReadCount(); - PTRACE(5, "Requested " << amount << " return after getting the next packet, so supply " << lastReadCount); + PTRACE(7, "Requested " << amount << " return after getting the next packet, so supply " << lastReadCount); return readOk; }
participants (1)
-
SofaSWITCH SVN