[Sofaswitch-svn] [commit] r417 - in sofaswitch/trunk: am mcu sofa/include/sofa sofa/src voip
Author: derek Date: Tue May 27 19:09:44 2008 New Revision: 417 Modified: sofaswitch/trunk/am/comms.cxx sofaswitch/trunk/mcu/comms.cxx sofaswitch/trunk/sofa/include/sofa/messlist.h sofaswitch/trunk/sofa/src/messages.cxx sofaswitch/trunk/sofa/src/messlist.cxx sofaswitch/trunk/voip/comms.cxx sofaswitch/trunk/voip/jocall.cxx sofaswitch/trunk/voip/mymanager.cxx Log: Fix the comms constructor, so we avoid the call of pure virtual functions. the commsProvider internal thread must start work after the creation of everything has completed. Correctly send a message back to the remote controller that the call has been established. This is useful in those scripts that want to know when the call is operational. Modified: sofaswitch/trunk/am/comms.cxx ============================================================================== --- sofaswitch/trunk/am/comms.cxx (original) +++ sofaswitch/trunk/am/comms.cxx Tue May 27 19:09:44 2008 @@ -262,6 +262,7 @@ : MessageFrameListProvider(_lid), manager(_manager) { + StartWorkNow(); } MessageFrame *CommsProvider::BuildMessageFrame() Modified: sofaswitch/trunk/mcu/comms.cxx ============================================================================== --- sofaswitch/trunk/mcu/comms.cxx (original) +++ sofaswitch/trunk/mcu/comms.cxx Tue May 27 19:09:44 2008 @@ -222,6 +222,7 @@ : MessageFrameListProvider(_lid), manager(_manager) { + StartWorkNow(); } MessageFrame *CommsProvider::BuildMessageFrame() Modified: sofaswitch/trunk/sofa/include/sofa/messlist.h ============================================================================== --- sofaswitch/trunk/sofa/include/sofa/messlist.h (original) +++ sofaswitch/trunk/sofa/include/sofa/messlist.h Tue May 27 19:09:44 2008 @@ -174,10 +174,17 @@ will be overridden, to create descendants of MessageFrames, and store them in this list. - This method is pure virtual. We DEMAND that the user provides their own - interpretation of this method.*/ + We DEMAND that the user provides their own interpretation of this + method. */ virtual MessageFrame *BuildMessageFrame() = 0; + /**the work of building a new message frame is started by the + descendant class calling this method. Thus, the constructor of + the descendant class should call this method. The constructor of + this MessageFrameListProvider MUST not call this method. You will + get pure virtual errors, as BuildMessageFrame is not defined. */ + void StartWorkNow(); + #ifdef DOC_PLUS_PLUS /**The thread, which runs to create new and ready to go instances, runs in here */ void MakeNewMessageFrames(PThread &, INT param); Modified: sofaswitch/trunk/sofa/src/messages.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messages.cxx (original) +++ sofaswitch/trunk/sofa/src/messages.cxx Tue May 27 19:09:44 2008 @@ -320,45 +320,21 @@ PINDEX maxm = 2000; PBYTEArray data(maxm); -#define consecutiveReadNulls 10 - PINDEX readSize[consecutiveReadNulls]; - PINDEX readIndex = 0; - PINDEX ir; - for(ir = 0; ir < consecutiveReadNulls; ir++) - readSize[ir] = 1; - while(keepGoing){ - messagesSocket.Read(data.GetPointer(), maxm); - PINDEX size = messagesSocket.GetLastReadCount(); - PINDEX lastError = messagesSocket.GetErrorCode(); - - readSize[readIndex] = size; - readIndex = (readIndex + 1) % consecutiveReadNulls; - PINDEX readSum = 0; - for(ir = 0; ir < consecutiveReadNulls; ir++) - readSum += readSize[ir]; - if (readSum == 0) { - PTRACE(3, "There is an error on this socket. END NOW " - << messagesSocket.GetErrorText()); - - SilentlyEndAll(); - CloseMessagesSocket(); - keepGoing = false; - continue; - } - - if (lastError != PChannel::NoError) { + if (messagesSocket.Read(data.GetPointer(), maxm)) { + PINDEX size = messagesSocket.GetLastReadCount(); + ProcessIncomingMessages(data, size); + } else { PTRACE(3, "Failed in read from comms socket, code is " << messagesSocket.GetErrorText()); PTRACE(3, "End Process Incoming Messages as we had a read error."); keepGoing = false; - continue; - } else { - ProcessIncomingMessages(data, size); - } + SilentlyEndAll(); + CloseMessagesSocket(); + } } - PTRACE(5, "End of Process Incoming Messages - thread has finished"); + PTRACE(3, "End of Process Incoming Messages - thread has finished"); CloseMessagesSocket(); OnTermination(); Modified: sofaswitch/trunk/sofa/src/messlist.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messlist.cxx (original) +++ sofaswitch/trunk/sofa/src/messlist.cxx Tue May 27 19:09:44 2008 @@ -161,14 +161,18 @@ keepGoing = true; MessageFrameList::Initialise(); - makeNewMessageFrame = PThread::Create(PCREATE_NOTIFIER(MakeNewMessageFrames), 0, - PThread::NoAutoDeleteThread, - PThread::NormalPriority, - "%X make Frames"); - PTRACE(3, "Create new MessageFrame provider."); } +void MessageFrameListProvider::StartWorkNow() +{ + makeNewMessageFrame = PThread::Create(PCREATE_NOTIFIER(MakeNewMessageFrames), + 0, + PThread::NoAutoDeleteThread, + PThread::NormalPriority, + "%X make Frames"); +} + void MessageFrameListProvider::RemoveDeadEntries() { MessageFrameList deads; @@ -210,6 +214,7 @@ makeAnother.Signal(); } + void MessageFrameListProvider::MakeNewMessageFrames(PThread &, INT ) { for( ;keepGoing; ) { @@ -224,8 +229,8 @@ PTRACE(3, "We had an error in buildmessageframe - null returned"); } } - if (keepGoing) - makeAnother.Wait(1000); + for(PINDEX i = 0; (i < 10) && keepGoing; i++) + makeAnother.Wait(100); } PTRACE(3, "End of message frame list provider thread "); } Modified: sofaswitch/trunk/voip/comms.cxx ============================================================================== --- sofaswitch/trunk/voip/comms.cxx (original) +++ sofaswitch/trunk/voip/comms.cxx Tue May 27 19:09:44 2008 @@ -251,6 +251,7 @@ : MessageFrameListProvider(_lid), manager(_manager) { + StartWorkNow(); } MessageFrame *CommsProvider::BuildMessageFrame() Modified: sofaswitch/trunk/voip/jocall.cxx ============================================================================== --- sofaswitch/trunk/voip/jocall.cxx (original) +++ sofaswitch/trunk/voip/jocall.cxx Tue May 27 19:09:44 2008 @@ -136,18 +136,15 @@ bool MyOpalCall::OnEstablished(OpalConnection & connection) { - PTRACE(2, "On Established of connection. " << connection.GetToken()); + PTRACE(2, "OnEstablished of connection. " + << GetPartyA() << " and " << GetPartyB()); - if (sentEstablishedMessage) - return OpalCall::OnEstablished(connection); - - if (PIsDescendant(&connection, OpalUdpSsConnection)) { + if (!sentEstablishedMessage) { comms.AdviseCallCreation(); - sentEstablishedMessage = true; - + sentEstablishedMessage = true; PTRACE(3, "We have just advised that the call was created "); } - + return OpalCall::OnEstablished(connection); } Modified: sofaswitch/trunk/voip/mymanager.cxx ============================================================================== --- sofaswitch/trunk/voip/mymanager.cxx (original) +++ sofaswitch/trunk/voip/mymanager.cxx Tue May 27 19:09:44 2008 @@ -732,8 +732,10 @@ void MyManager::OnEstablishedCall(OpalCall & call) { - // cout << "In call with " << call.GetPartyB() << endl; - OpalManager::OnEstablishedCall(call); + PTRACE(3, "Established call with " << call.GetPartyA() + << " and " << call.GetPartyB()); + // cout << "In call with " << call.GetPartyB() << endl; + OpalManager::OnEstablishedCall(call); }
participants (1)
-
SofaSWITCH SVN