Author: derek Date: Sun Jul 20 22:45:12 2008 New Revision: 430 Modified: sofaswitch/trunk/voip/mymanager.cxx sofaswitch/trunk/voip/mymanager.h sofaswitch/trunk/voip/supervisor.cxx sofaswitch/trunk/voip/supervisor.h Log: Add additional command of (iaxstatus and iaxstatus full) This command reports on the usage in OPAL's iax lists. Modified: sofaswitch/trunk/voip/mymanager.cxx ============================================================================== --- sofaswitch/trunk/voip/mymanager.cxx (original) +++ sofaswitch/trunk/voip/mymanager.cxx Sun Jul 20 22:45:12 2008 @@ -330,7 +330,7 @@ // Create IAX2 protocol handler if (!args.HasOption("no-iax2")) { - iax2EP = new IAX2EndPoint(*this); + iax2EP = new ReportingIAX2EndPoint(*this); if (args.HasOption('p')) iax2EP->SetPassword(args.GetOptionString('p')); Modified: sofaswitch/trunk/voip/mymanager.h ============================================================================== --- sofaswitch/trunk/voip/mymanager.h (original) +++ sofaswitch/trunk/voip/mymanager.h Sun Jul 20 22:45:12 2008 @@ -229,6 +229,16 @@ comms instances in a call */ PSortedStringList GetCurrentNames(); + + /**Return the pointer to the iax2 endpoint. This is used for + retrieving stats, and is dangerous to be used for other + things. */ +#if OPAL_IAX2 + void *GetIax2Ep() { return (void *)iax2EP; } +#else + void *GetIax2Ep() { return NULL; } +#endif + protected: /**The interface to the external script which runs python, to provide comms for us */ LaunchNewId &lid; Modified: sofaswitch/trunk/voip/supervisor.cxx ============================================================================== --- sofaswitch/trunk/voip/supervisor.cxx (original) +++ sofaswitch/trunk/voip/supervisor.cxx Sun Jul 20 22:45:12 2008 @@ -29,6 +29,7 @@ */ #include <ptlib.h> +#include <iax2/receiver.h> #ifdef __GNUC__ #pragma implementation "supervisor.h" @@ -42,6 +43,7 @@ #include "supervisor.h" + #define new PNEW //////////////////////////////////////////////////////////////////////////////// @@ -52,6 +54,8 @@ { IncSupervisor(); PTRACE(3, "Create a supervisor "); + + extraAvailableCommands += PString(/* 0 */ "IAXSTATUS"); } Supervisor::~Supervisor() @@ -150,6 +154,74 @@ VoipProcess::Current().GetManager()->RequestNewId(sender); } +bool Supervisor::ProcessDescendantCommands(const PStringArray & cmds, + const PString & sender) +{ + if (extraAvailableCommands[0] *= cmds[0]) { + PTRACE(4, "Process iax status"); + ProcessIaxStatus(cmds, sender); + return true; + } + + return false; +} + +void Supervisor::ProcessIaxStatus(const PStringArray & cmds, + const PString & sender) +{ + MyManager *opal = VoipProcess::Current().GetManager(); + PStringStream answer; + + void *iax2Ep = opal->GetIax2Ep(); + if (iax2Ep == NULL) { + answer << PString("FAILED as this SofaSwitch node does "); + answer << PString("not support iax. Sorry"); + } + +#if OPAL_IAX2 + ReportingIAX2EndPoint *r = (ReportingIAX2EndPoint *)iax2Ep; + bool fullReport = false; + if (cmds.GetSize() >= 2) { + fullReport = cmds[1] *= PString("full"); + } + answer << PString("\n") << r->GetListSizes(fullReport); +#endif + + SendThisMessageTo(answer, sender); + return; +} +///////////////////////////////////////////////////////////////////////////// + +ReportingIAX2EndPoint::ReportingIAX2EndPoint(OpalManager & manager) + : IAX2EndPoint(manager) +{ + +} + +PString ReportingIAX2EndPoint::GetListSizes(bool getFullReport) +{ + PStringStream answer; + PString transmitterAnswer; + ReportTransmitterLists(transmitterAnswer, getFullReport); + answer << "Transmitter " << transmitterAnswer; + answer << "Receiver " << receiver->GetSize() << "\n"; + answer << "RegProcessor" << regProcessors.GetSize() << "\n"; + + PString specialAnswer; + specialPacketHandler->ReportLists(specialAnswer); + answer << "specialHand " << specialAnswer << "\n"; + { + PWaitAndSignal m(mutexTokenTable); + answer << "token size " << tokenTable.GetSize() << "\n"; + } + { + PWaitAndSignal m(regProcessorsMutex); + answer << "Reg Processors " << regProcessors.GetSize() << "\n"; + } + + return answer; +} + /* 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/supervisor.h ============================================================================== --- sofaswitch/trunk/voip/supervisor.h (original) +++ sofaswitch/trunk/voip/supervisor.h Sun Jul 20 22:45:12 2008 @@ -36,6 +36,7 @@ #include <ptlib.h> #endif +#include <iax2/iax2ep.h> #include <sofa/messages.h> #ifdef P_USE_PRAGMA @@ -62,6 +63,17 @@ things like memory leak checkpoints */ virtual void OnRunning(); + /**The voip supervisor can do extra commands that the generic message handler + cannot process. This method catches these extra command handling. + + @return true if the voip supervisor did manage to decode the + commands. The default return is false; */ + virtual bool ProcessDescendantCommands(const PStringArray & /*cmds*/, + const PString & /*sender*/); + + /**Report here the extra commands the voip supervisor can process */ + virtual PStringArray GetDescendantCommands() { return extraAvailableCommands; } + protected: /**The supervisor has completed. This method is called when this supervisor instance terminates. Since there is only one @@ -100,6 +112,9 @@ /**Placed here - the child class has this method as pure virtual... */ virtual void ProcessAnswer(PStringArray &cmds, PString & sender); + /**Report to the sender the status of the lists in the iax portion of opal. */ + virtual void ProcessIaxStatus(const PStringArray &cmds, const PString & sender); + /**Some MessageFrame instances do not have the permission to quit now. This virtual method determines if this instance is permitted to exit the program. This is the supervisor, so we can cause a shutdown. */ @@ -109,6 +124,8 @@ no message to the remote node - just end end end. */ virtual void SilentlyEndAll(); + /**The list of extra commands we can handle in the voip supervisor */ + PStringArray extraAvailableCommands; ////////////////////////////////////////////// private: @@ -120,6 +137,25 @@ // CommsProvider availableComms; }; +///////////////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////// + +/**the purpose of this class is to access the members of the iax2ep for reporting on size */ + +class ReportingIAX2EndPoint : public IAX2EndPoint +{ + PCLASSINFO(ReportingIAX2EndPoint, IAX2EndPoint); + + public: + /**constructor, which just calls the descendant */ + ReportingIAX2EndPoint(OpalManager & manager); + + /**Get a string which details the size of the internal lists */ + PString GetListSizes(bool getFullReport = false); +}; + + + #endif // _SUPERVISOR_H