Author: derek
Date: Sun Jul 20 22:42:15 2008
New Revision: 427
Modified:
sofaswitch/trunk/sofa/include/sofa/messages.h
sofaswitch/trunk/sofa/src/messages.cxx
Log:
Tidy up formatting.
Add new methods so descendant class can process additional commands.
Modified: sofaswitch/trunk/sofa/include/sofa/messages.h
==============================================================================
--- sofaswitch/trunk/sofa/include/sofa/messages.h (original)
+++ sofaswitch/trunk/sofa/include/sofa/messages.h Sun Jul 20 22:42:15 2008
@@ -63,6 +63,9 @@
/**Destructor, to close of any threads etc */
virtual ~MessageFrame();
+ /**Report what this comms class things about the status of this instance */
+ PString GetStatusInfo();
+
/**Wait until the messaging subsystem reports it is
initialised. Wait no more than 1 second. If not initialised,
return false. return true immediately on discovering we are
@@ -132,6 +135,20 @@
finished, and that this class is operational and running */
virtual void OnRunning() { };
+ /**Make available the processing of commands to descendant
+ classes. So that (for example) the voip supervisor can process
+ voip related commands
+
+ @return true if the descendant class did manage to decode the
+ commands. The default return is false; */
+ virtual bool ProcessDescendantCommands(const PStringArray & /*cmds*/,
+ const PString & /*sender*/)
+ { return false; }
+
+ /**Find out what commands the descendant class can process. This
+ command is used to process the help command */
+ virtual PStringArray GetDescendantCommands();
+
protected:
/**Called when this thread finishes. An application would call
@@ -150,7 +167,8 @@
/**We have a message come in from the server, and it ends up here.
Now, handle this message, and give it to the relevant method below */
- virtual void ProcessMessage(PString message, PString sender);
+ virtual void ProcessMessage(PString & message,
+ PString & sender);
/**we have received a hangup message, so end the call */
virtual void ProcessHangup(PStringArray &cmds, PString & sender);
Modified: sofaswitch/trunk/sofa/src/messages.cxx
==============================================================================
--- sofaswitch/trunk/sofa/src/messages.cxx (original)
+++ sofaswitch/trunk/sofa/src/messages.cxx Sun Jul 20 22:42:15 2008
@@ -195,6 +195,19 @@
PTRACE(4, "Finish Terminate the message frame for " << GetOurId());
}
+PString MessageFrame::GetStatusInfo()
+{
+ PStringStream answer;
+ answer << "UDP audio socket is " << (audioSocket.IsOpen() ? "Open " : "Closed") << endl
+ << "TCP connection thread is " << (IsTerminated() ? "Stopped " : "Running") << endl
+ << "TCP command socket is " << (messagesSocket.IsOpen() ? "Open " : "Closed") << endl
+ << "Received last command from " << lastSender << endl
+ << "KeepGoing flag is " << (keepGoing ? "true " : "false") << endl
+ << "Media partner is " << mediaPartner << endl
+ << "Remote Controller is " << remoteController << endl;
+ return answer;
+}
+
void MessageFrame::Initialise()
{
SetThreadName(PString("Messages.") + ourId);
@@ -373,7 +386,7 @@
}
PString src = res.Left(l);
PString msg = res.Mid(l + 1);
- ProcessMessage(msg,src);
+ ProcessMessage(msg, src);
}
}
@@ -428,8 +441,10 @@
writeMessageLock.Signal();
}
-void MessageFrame::ProcessMessage(PString message, PString sender)
+void MessageFrame::ProcessMessage(PString & message,
+ PString & sender)
{
+ lastSender = sender;
PStringArray cmds = message.Tokenise(" ", false);
if (cmds[0] *= availableCommands[0]) {
@@ -561,7 +576,8 @@
return;
}
#endif
- PTRACE(3, PString("The command ") + cmds[0] + " was not understood");
+ if (ProcessDescendantCommands(cmds, sender) == false)
+ PTRACE(3, PString("The command ") + cmds[0] + " was not understood");
}
void MessageFrame::ProcessHangup(PStringArray &cmds, PString & sender)
@@ -728,11 +744,23 @@
void MessageFrame::ProcessHelp(PStringArray &cmds, PString & sender)
{
PString reply;
+
for (PINDEX i = 0; i < availableCommands.GetSize(); i++)
reply += availableCommands[i] + PString("\n");
+
+ PStringArray extraCommands = GetDescendantCommands();
+ for (PINDEX i = 0; i < extraCommands.GetSize(); i++)
+ reply += extraCommands[i] + PString("\n");
+
SendThisMessageTo(reply, sender);
}
+PStringArray MessageFrame::GetDescendantCommands()
+{
+ PStringArray emptyAnswer;
+ return emptyAnswer;
+}
+
bool MessageFrame::GetLocalAddress(PIPSocket::Address &address, PINDEX &portNo)
{
PIPSocket::InterfaceTable table;