Author: derek Date: Thu Jun 12 23:11:52 2008 New Revision: 419 Modified: sofaswitch/trunk/sofa/include/sofa/messages.h sofaswitch/trunk/sofa/src/messages.cxx Log: Add handling of the messageframe so that descendants can work out when they have started running. Tidy up the dumpmem command, to have less allocs in it. Modified: sofaswitch/trunk/sofa/include/sofa/messages.h ============================================================================== --- sofaswitch/trunk/sofa/include/sofa/messages.h (original) +++ sofaswitch/trunk/sofa/include/sofa/messages.h Thu Jun 12 23:11:52 2008 @@ -128,6 +128,10 @@ process of closing down */ bool IsTerminating() { return !keepGoing; } + /**report to the descendant class that all initialisation has + finished, and that this class is operational and running */ + virtual void OnRunning() { }; + protected: /**Called when this thread finishes. An application would call @@ -236,9 +240,10 @@ virtual void ProcessSetReadFile(PStringArray &cmds, const PString & sender); #ifdef PMEMORY_CHECK - /**we have received a command asking us to write all current allocations to the specified - file. This command checks the the file is specified in the command line. - If specified, all objects are dumped to that file.*/ + /**we have received a command asking us to write all current + allocations to the specified file. This command checks the the + file is specified in the command line. If specified, all + objects are dumped to that file.*/ virtual void ProcessMemoryDump(PStringArray &cmds, PString & sender); #endif @@ -338,6 +343,12 @@ to. */ PString mediaPartner; +#ifdef PMEMORY_CHECK + /**The state of the memory at which we last did a dump. This + variable is updated each time we do a memory dump */ + static PMemoryHeap::State memoryState; +#endif + private: /**Close the messages socket, and send a terminating message to the remote controller. Only this class can close this @@ -373,12 +384,6 @@ /**Flag to indicate it is time to end this thread. It is only set by the MessageFrame::Terminate() method */ bool keepGoing; - -#ifdef PMEMORY_CHECK - /**The state of the memory at which we last did a dump. This variable is updated - each time we do a memory dump */ - static PMemoryHeap::State memoryState; -#endif }; //////////////////////////////////////////////////////////////////////////////// Modified: sofaswitch/trunk/sofa/src/messages.cxx ============================================================================== --- sofaswitch/trunk/sofa/src/messages.cxx (original) +++ sofaswitch/trunk/sofa/src/messages.cxx Thu Jun 12 23:11:52 2008 @@ -312,6 +312,8 @@ Initialise(); PTRACE(3, "Initialise all done "); + OnRunning(); //Callback to the descendant class that we are running fine. + if (!keepGoing) { PTRACE(3, "END fail warning of message frame thread for " << ourId); } @@ -329,8 +331,6 @@ << messagesSocket.GetErrorText()); PTRACE(3, "End Process Incoming Messages as we had a read error."); keepGoing = false; - SilentlyEndAll(); - CloseMessagesSocket(); } } @@ -800,37 +800,8 @@ #ifdef PMEMORY_CHECK void MessageFrame::ProcessMemoryDump(PStringArray &cmds, PString & sender) { - if (cmds.GetSize() != 2) { - PStringStream error; - error << cmds[0] << " Failed - Output file not specified"; - PTRACE(3, error << sender); - SendThisMessageTo(error, sender); - return; - } - - PTRACE(3, "Dump current memory usage to \"" << cmds[1] << "\""); + PMemoryHeap::DumpObjectsSince(memoryState); - PTextFile outputFile; - if (!outputFile.Open(cmds[1], PFile::WriteOnly, - PFile::Create + PFile::Truncate)) { - PStringStream error; - error << "Failed to open the specified file " - << cmds[1] - << " to dump memory to"; - SendThisMessageTo(error, sender); - PTRACE(3, error); - return; - } - PStringStream status; - status << "Dump memory usage info to the file " << cmds[1]; - cerr << status << endl; - SendThisMessageTo(status, sender); - PMemoryHeap::DumpStatistics(); - - PStringStream result; - PMemoryHeap::DumpObjectsSince(memoryState, result); - outputFile.WriteLine(result); - outputFile.Close(); PMemoryHeap::GetState(memoryState); return; }