[Sofaswitch-svn] [commit] r432 - in sofaswitch/trunk: callflow/src sofa/include/sofa sofa/src voip
Author: derek Date: Fri Jul 25 01:00:20 2008 New Revision: 432 Modified: sofaswitch/trunk/callflow/src/callstartstop.cpp sofaswitch/trunk/callflow/src/endcall.cpp sofaswitch/trunk/callflow/src/transfermedia.cpp sofaswitch/trunk/sofa/include/sofa/messages.h sofaswitch/trunk/sofa/src/messages.cxx sofaswitch/trunk/voip/comms.cxx sofaswitch/trunk/voip/comms.h sofaswitch/trunk/voip/counts.cxx sofaswitch/trunk/voip/counts.h sofaswitch/trunk/voip/jocall.cxx sofaswitch/trunk/voip/mymanager.cxx sofaswitch/trunk/voip/mymanager.h sofaswitch/trunk/voip/supervisor.cxx Log: Lots of tidy ups to improve the efficiency of the voip subsystem. Minor cleanups to callflow to make it more robust. Modified: sofaswitch/trunk/callflow/src/callstartstop.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/callstartstop.cpp (original) +++ sofaswitch/trunk/callflow/src/callstartstop.cpp Fri Jul 25 01:00:20 2008 @@ -64,6 +64,18 @@ file.AddLine(wxT(" try: ")); file.AddLine(wxT(" self.rhost = eval(self.data[a][\"worker node\"]) ")); file.AddLine(wxT(" except: ")); + switch (kind) { + case MakeCall: + file.AddLine(wxT(" print \"Attempting to make a call \"")); + break; + case EndCall: + file.AddLine(wxT(" print \"Attempting to end a call \"")); + break; + case AcceptCall: + file.AddLine(wxT(" print \"Attempting to accept a call \" ")); + break; + default:; + } file.AddLine(wxT(" print \"The worker node string \", self.data[a][\"worker node\"], \" could not be evaluated as a Python string\" ")); file.AddLine(wxT(" self.rhost = \"\" ")); if (kind == MakeCall) { Modified: sofaswitch/trunk/callflow/src/endcall.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/endcall.cpp (original) +++ sofaswitch/trunk/callflow/src/endcall.cpp Fri Jul 25 01:00:20 2008 @@ -22,10 +22,6 @@ { } - - - - void DndShapeEndCall::Draw(wxDC & dc) { DndShapeCallStartStop::Draw(dc); Modified: sofaswitch/trunk/callflow/src/transfermedia.cpp ============================================================================== --- sofaswitch/trunk/callflow/src/transfermedia.cpp (original) +++ sofaswitch/trunk/callflow/src/transfermedia.cpp Fri Jul 25 01:00:20 2008 @@ -69,24 +69,26 @@ bool DndShapeTransferMedia::WriteSystemCode(wxTextFile & file) { - file.AddLine(wxT(" def Transfer_Media(self, sTuple): ")); - file.AddLine(wxT(" a,b,c = sTuple ")); - file.AddLine(wxT(" self.tMedia = self.data[a][\"worker node\"] ")); - file.AddLine(wxT(" try: ")); - file.AddLine(wxT(" self.rhost = eval(self.tMedia) ")); - file.AddLine(wxT(" except: ")); - file.AddLine(wxT(" print \"The Worker node Python \", self.tMedia, \" could not be evaluated\" ")); - file.AddLine(wxT(" return self.data[a][\"Output\"] ")); - - file.AddLine(wxT(" self.wNode = self.data[a][\"worker receiver\"] ")); - file.AddLine(wxT(" try: ")); - file.AddLine(wxT(" self.rhost += \":TRANSFERUDP \" + eval(self.wNode) + \"\\0\" ")); - file.AddLine(wxT(" except: ")); - file.AddLine(wxT(" print \"The node to transfer media to \", self.wNode, \" could not be evaluated\" ")); - file.AddLine(wxT(" return self.data[a][\"Output\"] ")); + file.AddLine(wxT(" def Transfer_Media(self, sTuple): ")); + file.AddLine(wxT(" a,b,c = sTuple ")); + file.AddLine(wxT(" self.tMedia = self.data[a][\"worker node\"] ")); + file.AddLine(wxT(" self.wNode = self.data[a][\"worker receiver\"] ")); + file.AddLine(wxT(" try: ")); + file.AddLine(wxT(" self.rhost = eval(self.tMedia) ")); + file.AddLine(wxT(" except: ")); + file.AddLine(wxT(" print \"The transfer media node Python \", self.tMedia, \" could not be evaluated\"")); + file.AddLine(wxT(" print \"Unsure on the validity of the string \", self.wNode, \" as yet\" ")); + file.AddLine(wxT(" return self.data[a][\"Output\"] ")); + + file.AddLine(wxT(" try: ")); + file.AddLine(wxT(" self.rhost += \":TRANSFERUDP \" + eval(self.wNode) + \"\\0\" ")); + file.AddLine(wxT(" except: ")); + file.AddLine(wxT(" print \"The node to transfer media to \", self.wNode, \" could not be evaluated\" ")); + file.AddLine(wxT(" print \"However, python did evaluate \", self.tMedia, \" just fine\" ")); + file.AddLine(wxT(" return self.data[a][\"Output\"] ")); - file.AddLine(wxT(" self.transport.write(self.rhost) ")); - file.AddLine(wxT(" return self.data[a][\"Output\"] ")); + file.AddLine(wxT(" self.transport.write(self.rhost) ")); + file.AddLine(wxT(" return self.data[a][\"Output\"] ")); file.AddLine(wxT("")); return true; Modified: sofaswitch/trunk/sofa/include/sofa/messages.h ============================================================================== --- sofaswitch/trunk/sofa/include/sofa/messages.h (original) +++ sofaswitch/trunk/sofa/include/sofa/messages.h Fri Jul 25 01:00:20 2008 @@ -368,12 +368,6 @@ #endif private: - /**Close the messages socket, and send a terminating message to - the remote controller. Only this class can close this - socket. This helps to ensure it is closed down at the end of - all comms.*/ - void CloseMessagesSocket(); - /**Keep a reference of the class responsible for creating new unique IDs, which are derived from the supplied node Id..*/ LaunchNewId & lid; Modified: sofaswitch/trunk/sofa/src/messages.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messages.cxx (original) +++ sofaswitch/trunk/sofa/src/messages.cxx Fri Jul 25 01:00:20 2008 @@ -145,14 +145,6 @@ SendThisMessageTo(PString("RECEIVEDDTMF ") + receivedDtmf, GetRemoteController()); } -void MessageFrame::CloseMessagesSocket() -{ - PTRACE(3, "Close messages socket for " << GetOurId()); - - PThread::Sleep(100); //Let the message be sent, then close the socket. - messagesSocket.Close(); -} - bool MessageFrame::WaitUntilInitialised() { PTRACE(3, "WaitForInitialised start"); @@ -188,7 +180,7 @@ { keepGoing = false; audioSocket.Close(); - CloseMessagesSocket(); + messagesSocket.Close(); threadRunning.Signal(); goodConnection.Signal(); writeSourceId.Signal(); @@ -350,7 +342,7 @@ } PTRACE(3, "End of Process Incoming Messages - thread has finished"); - CloseMessagesSocket(); + messagesSocket.Close(); OnTermination(); return; @@ -452,7 +444,7 @@ if (OkToHangup()) { keepGoing = false; ProcessHangup(cmds, sender); - CloseMessagesSocket(); + messagesSocket.Close(); } else { SendThisMessageTo("This communications instance cannot hangup", sender); PTRACE(2, "Hangup ignored, as we cannot hangup.."); @@ -519,7 +511,7 @@ if (OkToQuitNow()) { keepGoing = false; ProcessQuitNow(cmds, sender); - CloseMessagesSocket(); + messagesSocket.Close(); } else { SendThisMessageTo("Insufficient Privilidgets to cause a shutdown", sender); PTRACE(2, "Quitnow aborted, as insufficient priviledges"); Modified: sofaswitch/trunk/voip/comms.cxx ============================================================================== --- sofaswitch/trunk/voip/comms.cxx (original) +++ sofaswitch/trunk/voip/comms.cxx Fri Jul 25 01:00:20 2008 @@ -59,6 +59,7 @@ void Comms::OnOpalCallCleared() { PWaitAndSignal m(opalCallLock); + DecEstablished(); if (myOpalCall != NULL) { myOpalCall->SafeDereference(); myOpalCall = NULL; @@ -74,16 +75,10 @@ void Comms::SetMyOpalCallPtr(MyOpalCall *ptr) { - myOpalCall = ptr; - ptr->SafeReference(); - opalCallToken = ptr->GetToken(); -} - -void Comms::StopAllCommunications() -{ - PTRACE(5, "Comms StopAllComms Start " << GetOurId()); - Terminate(); - PTRACE(5, "Comms StopAllComms All done " << GetOurId()); + IncEstablished(); + myOpalCall = ptr; + ptr->SafeReference(); + opalCallToken = ptr->GetToken(); } void Comms::OnTermination() @@ -105,12 +100,6 @@ PTRACE(3, "Silently end all, which is \"ignored\""); } -void Comms::CloseThisId() -{ - audioSocket.Close(); - Terminate(); -} - void Comms::ProcessCallNode(PStringArray &cmds, PString & sender) { { @@ -274,7 +263,7 @@ for(PINDEX i = 0; i < PAbstractList::GetSize(); i++) { mf = (Comms *)PAbstractList::GetAt(i); - new CommsConsumer(manager, mf); + new CommsConsumer(mf); } } @@ -296,38 +285,26 @@ //////////////////////////////////////////////////////////////////////////////// -CommsConsumer::CommsConsumer(MyManager &_manager, Comms *m) - :PThread(10000, AutoDeleteThread, LowPriority, "%X Comms delete"), - manager(_manager), +CommsConsumer::CommsConsumer(Comms *m) + :PThread(10000, AutoDeleteThread, NormalPriority, "%X Comms delete"), 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() { if (comms == NULL) return; - comms->WaitForTermination(); + comms->Terminate(); - ourId = comms->GetOurId(); - PTRACE(3, "START checking: look for " << ourId << " to appear in a manager list"); + comms->WaitForTermination(); - 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; - } + delete comms; } + /* The comment below is magic for those who use emacs to edit this file. */ /* With the comment below, the tab key does auto indent to 2 spaces. */ Modified: sofaswitch/trunk/voip/comms.h ============================================================================== --- sofaswitch/trunk/voip/comms.h (original) +++ sofaswitch/trunk/voip/comms.h Fri Jul 25 01:00:20 2008 @@ -70,10 +70,6 @@ /** Close down the handling of incoming message, and break the link to the MyOpalCall class */ ~Comms(); - - /**Send a message to the remote controller that we are closing down now */ - virtual void StopAllCommunications(); - /**Send a message to the remote controller saying that we are created (and established in the Opal sense of a connection). The id of this node is appended to the message. @@ -101,10 +97,6 @@ by control commands */ PUDPSocket &GetAudioSocket(); - /**Close this id off. Basically, tell the remote end we are closing, - and stop the comms on the tcp socket. */ - void CloseThisId(); - /**Retrieve the opal call token that opal has assigned to the corresponding OpalCall */ PString GetOpalCallToken() { return opalCallToken; } @@ -221,23 +213,15 @@ /**Constructer - create this class, which is given the Comms instance to destroy. This consumer class then does the rest */ - CommsConsumer(MyManager & _manager, Comms *destroyMe); - - /**Destructor */ - ~CommsConsumer(); - + CommsConsumer(Comms *destroyMe); + /**Where this thread runs to do the work */ void Main(); protected: - /**Reference to the class that knows everything about everything */ - MyManager & manager; /**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/counts.cxx ============================================================================== --- sofaswitch/trunk/voip/counts.cxx (original) +++ sofaswitch/trunk/voip/counts.cxx Fri Jul 25 01:00:20 2008 @@ -37,6 +37,7 @@ ///////////////////////////////////////////////////////////////////////////// PAtomicInteger countComms; +PAtomicInteger countEstablished; PAtomicInteger countMyManager; PAtomicInteger countMyOpalCall; PAtomicInteger countOpalUdpSsConnection; @@ -45,6 +46,7 @@ PAtomicInteger countUdpSoundChannel; PAtomicInteger countDelComms; +PAtomicInteger countDelEstablished; PAtomicInteger countDelMyManager; PAtomicInteger countDelMyOpalCall; PAtomicInteger countDelOpalUdpSsConnection; @@ -61,6 +63,15 @@ return msg; } +PString GetCountEstablished() +{ + PStringStream msg; + msg << ::setw(6) << PString(countEstablished) + << ::setw(6) << PString(countDelEstablished) + << ::setw(6) << PString(countEstablished - countDelEstablished) << ::setw(0); + return msg; +} + PString GetCountMyManager() { PStringStream msg; @@ -117,6 +128,7 @@ } void DecComms() { ++countDelComms; } +void DecEstablished() { ++countDelEstablished; } void DecMyManager() { ++countDelMyManager; } void DecMyOpalCall() { ++countDelMyOpalCall; } void DecOpalUdpSsConnection() { ++countDelOpalUdpSsConnection; } @@ -125,6 +137,7 @@ void DecUdpSoundChannel() { ++countDelUdpSoundChannel; } void IncComms() { ++countComms; } +void IncEstablished() { ++countEstablished; } void IncMyManager() { ++countMyManager; } void IncMyOpalCall() { ++countMyOpalCall; } void IncOpalUdpSsConnection() { ++countOpalUdpSsConnection; } Modified: sofaswitch/trunk/voip/counts.h ============================================================================== --- sofaswitch/trunk/voip/counts.h (original) +++ sofaswitch/trunk/voip/counts.h Fri Jul 25 01:00:20 2008 @@ -41,39 +41,96 @@ +/**Decrement the count on the Audio Delay instances established */ void DecAudioDelay(); + +/**Increment the count on the Audio Delay instances established */ void IncAudioDelay(); + +/**Report the count on the Audio Delay instances established */ PString GetCountAudioDelay(); +/**Decrement the count on SofaSwitch Communication instances established */ void DecComms(); + +/**Increment the count on SofaSwitch Communication instances established */ void IncComms(); + +/**Reportt the count on SofaSwitch Communication instances established */ PString GetCountComms(); +/**This is for debugging purposes, and may be used to keep track of + count of any particular variable - look for size of any list for + example. DECREMENT operation */ +void DecEstablished(); + +/**This is for debugging purposes, and may be used to keep track of + count of any particular variable - look for size of any list for + example. INCREMENT operation */ +void IncEstablished(); + +/**This is for debugging purposes, and may be used to keep track of + count of any particular variable - look for size of any list for + example. Report this variable. */ +PString GetCountEstablished(); + +/**Decrement the count on SofaSwitch Manager instances established */ void DecMyManager(); + +/**Increment the count on SofaSwitch Manager instances established */ void IncMyManager(); + +/**Report the count on SofaSwitch Manager instances established */ PString GetCountMyManager(); +/**Decrement the count on SofaSwitch OpalCall instances established */ void DecMyOpalCall(); + +/**Increment the count on SofaSwitch OpalCall instances established */ void IncMyOpalCall(); + +/**Report the count on SofaSwitch OpalCall instances established */ PString GetCountMyOpalCall(); +/**Decrement the count on SofaSwitch Connection instances established */ void DecOpalUdpSsConnection(); + +/**Increment the count on SofaSwitch Connection instances established */ void IncOpalUdpSsConnection(); + +/**Report the count on SofaSwitch Connection instances established */ PString GetCountOpalUdpSsConnection(); +/**Decrement the count on SofaSwitch EndPoints established */ void DecOpalUdpSsEndPoint(); + +/**Increment the count on SofaSwitch EndPoints established */ void IncOpalUdpSsEndPoint(); + +/**Report the count on SofaSwitch EndPoints established */ PString GetCountOpalUdpSsEndPoint(); +/**Decrement the count on Supervisors established */ void DecSupervisor(); + +/**Increment the count on Supervisors established */ void IncSupervisor(); + +/**Report the count on Supervisors established */ PString GetCountSupervisor(); +/**Decrement the count on sound channel established */ void DecUdpSoundChannel(); + +/**Increment the count on sound channel established */ void IncUdpSoundChannel(); + +/**Report the count on sound channel established */ PString GetCountUdpSoundChannel(); + + #endif // _COUNTS_H Modified: sofaswitch/trunk/voip/jocall.cxx ============================================================================== --- sofaswitch/trunk/voip/jocall.cxx (original) +++ sofaswitch/trunk/voip/jocall.cxx Fri Jul 25 01:00:20 2008 @@ -75,13 +75,8 @@ MyOpalCall::~MyOpalCall() { PTRACE(3, "Destructor for Opal Call " << GetToken() << " and " << comms.GetOurId()); - 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.AppendFinishedComms(commsPtr); + new CommsConsumer(commsPtr); PTRACE(3, "MyOpalCall\t" << *this << " destroyed dead and gone"); DecMyOpalCall(); } @@ -89,35 +84,14 @@ bool MyOpalCall::OnSetUp(OpalConnection & connection) { PTRACE(3, "Call\tOnSetUp " << connection); - - bool ok = false; - - if (!LockReadWrite()) { - PTRACE(3, "failed to lock the read write"); - return false; - } - - PTRACE(3, "ConnectionsActive has a size of " - << connectionsActive.GetSize()); - - UnlockReadWrite(); - - PINDEX i = 1; - for (PSafePtr<OpalConnection> conn(connectionsActive, PSafeReadOnly); conn != NULL; ++conn, i++) { - PTRACE(3, "connection " << i << " is " << (*conn)); - } for (PSafePtr<OpalConnection> conn(connectionsActive, PSafeReadOnly); conn != NULL; ++conn) { PTRACE(3, "TRY " << (*conn)); if (conn != &connection) { PTRACE(3, "Now do a setup"); - if (conn->SetUpConnection()) { - PTRACE(3, "set up the connection ok "); - ok = true; - } + conn->SetUpConnection(); } } - PTRACE(2, "finished onsetup of connection/call and it gave " << 1); return true; } @@ -214,7 +188,7 @@ void MyOpalCall::CloseThisId() { - comms.CloseThisId(); + comms.Terminate(); } PUDPSocket & MyOpalCall::GetAudioSocket() Modified: sofaswitch/trunk/voip/mymanager.cxx ============================================================================== --- sofaswitch/trunk/voip/mymanager.cxx (original) +++ sofaswitch/trunk/voip/mymanager.cxx Fri Jul 25 01:00:20 2008 @@ -107,7 +107,6 @@ supervisor.Resume(); nodesMakingCalls.Initialise(); - nodesFinishedCalls.Initialise(); runningComms.SetPreAllocatedSize(10); runningComms.Initialise(); @@ -463,9 +462,9 @@ void MyManager::AcceptThisCall(const PString & uniqueCallId, bool doAccept) { PTRACE(3, "Accept this call if we can find it " << uniqueCallId); - PSafePtr<OpalCall> oCall = FindCallWithLock(uniqueCallId); + PSafePtr<OpalCall> oCall = FindCallWithLock(uniqueCallId, PSafeReadOnly); if (oCall == NULL) { - PTRACE(3, "Failed to accept call with a token of " << uniqueCallId); + PTRACE(3, "Failed to accept call with a token of "); return; } @@ -478,7 +477,7 @@ PString MyManager::GetStatusInfo(const PString & token) { - PSafePtr<OpalCall> call = FindCallWithLock(token); + PSafePtr<OpalCall> call = FindCallWithLock(token, PSafeReadOnly); if (call == NULL) { return "Status unavailable as not in a call"; } @@ -543,6 +542,8 @@ status << "--------------" << endl; status << " Comms count is " << GetCountComms() << endl; + status << " Established count is " + << GetCountEstablished() << endl; status << " MyManager count is " << GetCountMyManager() << endl; status << " MyOpalCall count is " @@ -619,25 +620,12 @@ return c; } - c = (Comms *)nodesFinishedCalls.GetMessageFrameOn(memberId); - if (c != NULL) { - PTRACE(3, "Clear comms Id on " << memberId << " for comms instances finished in a call"); - return c; - } - 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) { - PSafePtr<OpalCall> call = FindCallWithLock(token); + PSafePtr<OpalCall> call = FindCallWithLock(token, PSafeReadOnly); if (call == NULL) { return "Duration unavailable as not in a call"; } @@ -671,7 +659,7 @@ bool MyManager::SendThisDtmf(const PString & token, const PString & thisDtmf) { PTRACE(3, "MyManager\tSend this dtmf " << thisDtmf << " to call " << token); - OpalCall *oCall = FindCallWithLock(token); + OpalCall *oCall = FindCallWithLock(token, PSafeReadOnly); if (oCall == NULL) { PTRACE(3, "MyManager\tSend this dtmf " << thisDtmf << " to call " << token << " FAILED - call not found"); return false; @@ -981,7 +969,7 @@ /* * Local Variables: * mode:c - * c-basic-offset:4 + * c-basic-offset:2 * End: */ Modified: sofaswitch/trunk/voip/mymanager.h ============================================================================== --- sofaswitch/trunk/voip/mymanager.h (original) +++ sofaswitch/trunk/voip/mymanager.h Fri Jul 25 01:00:20 2008 @@ -256,14 +256,9 @@ deleted */ MessageFrameListPending nodesMakingCalls; - /**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.*/ + /**A list of Comms instances that are known to have died. Comms + instances will be removed from this list by the CommsConsumer + class.*/ MessageFrameList deadComms; /**The sound system endpoint that we use to control talk to the Modified: sofaswitch/trunk/voip/supervisor.cxx ============================================================================== --- sofaswitch/trunk/voip/supervisor.cxx (original) +++ sofaswitch/trunk/voip/supervisor.cxx Fri Jul 25 01:00:20 2008 @@ -209,11 +209,10 @@ PString specialAnswer; specialPacketHandler->ReportLists(specialAnswer); - answer << "specialHand " << specialAnswer << "\n"; - { - PWaitAndSignal m(mutexTokenTable); - answer << "token size " << tokenTable.GetSize() << "\n"; - } + answer << "specialHand " << specialAnswer << "\n"; + mutexTokenTable.StartRead(); + answer << "token size " << tokenTable.GetSize() << "\n"; + mutexTokenTable.EndRead(); { PWaitAndSignal m(regProcessorsMutex); answer << "Reg Processors " << regProcessors.GetSize() << "\n";
participants (1)
-
SofaSWITCH SVN