r2949 - in trunk/libmsip: include/libmsip source
erik at minisip.org
erik at minisip.org
Thu Nov 23 18:21:52 CET 2006
Author: erik
Date: 2006-11-23 18:21:51 +0100 (Thu, 23 Nov 2006)
New Revision: 2949
Modified:
trunk/libmsip/include/libmsip/SipLayerDialog.h
trunk/libmsip/include/libmsip/SipSMCommand.h
trunk/libmsip/include/libmsip/SipStack.h
trunk/libmsip/include/libmsip/SipStackInternal.h
trunk/libmsip/source/SipLayerDialog.cxx
trunk/libmsip/source/SipStack.cxx
trunk/libmsip/source/SipStackInternal.cxx
Log:
* The "Sip" contained logic for how to make calls. This moves
that code to the DefaultDialogHandler where it belongs. Now
the applications SIP-behavour is implemented in the default
handler, and in the state machines that handler registers to
the SIP stack. This feels much better.
I made the default handler inherit from both "SipSMCommandReceiver" and
"CommandReceiver". This is so that we can move the code in
"Sip::handleCommandResp" to the default handler and in the long run
phase out the "Sip" class.
- Made CommandReceiver and SipSMCommandReceiver inherit virtually
from MOBject so that we have a single MObject in the
SipDefaultHandler classes.
MObject
^ ^
/ \
CommandReceiver SipSMCommandReceiver
^ ^
\ /
SipDefaultHandler
* Both the online configuration and the "Sip-SIM" projects
are a bit held back by the way we handle configuration data.
This is a step towards handling configuration data in a better
way. I think that making a configuration subsystem could be
a good idea. (you could tell the config system to load/mount a
specific config file/sim card/online account, and query it for
settings)
This commit contains small changes that will make this way of
managing the information easier.
Modified: trunk/libmsip/include/libmsip/SipLayerDialog.h
===================================================================
--- trunk/libmsip/include/libmsip/SipLayerDialog.h 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/include/libmsip/SipLayerDialog.h 2006-11-23 17:21:51 UTC (rev 2949)
@@ -43,7 +43,8 @@
SipLayerDialog(MRef<SipCommandDispatcher*> dispatcher);
- void setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb);
+ void setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb);
+ MRef<SipDefaultHandler*> getDefaultDialogCommandHandler();
void addDialog(MRef<SipDialog*> d);
void removeTerminatedDialogs();
@@ -55,7 +56,7 @@
std::list<MRef<SipDialog*> > getDialogs();
private:
- MRef<SipSMCommandReceiver*> defaultHandler;
+ MRef<SipDefaultHandler*> defaultHandler;
minilist<MRef<SipDialog*> > dialogs;
Modified: trunk/libmsip/include/libmsip/SipSMCommand.h
===================================================================
--- trunk/libmsip/include/libmsip/SipSMCommand.h 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/include/libmsip/SipSMCommand.h 2006-11-23 17:21:51 UTC (rev 2949)
@@ -39,7 +39,7 @@
*
* @author Erik Eliasson <eliasson at it.kth.se>
*/
-class LIBMSIP_API SipSMCommand : public MObject{
+class LIBMSIP_API SipSMCommand : public virtual MObject{
public:
static const int COMMAND_PACKET;
static const int COMMAND_STRING;
Modified: trunk/libmsip/include/libmsip/SipStack.h
===================================================================
--- trunk/libmsip/include/libmsip/SipStack.h 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/include/libmsip/SipStack.h 2006-11-23 17:21:51 UTC (rev 2949)
@@ -93,8 +93,62 @@
#define HIGH_PRIO_QUEUE 2
#define LOW_PRIO_QUEUE 4
+/**
+ * \brief The SipDefaultHandler of an application is the class
+ * that decides how the application will behave when
+ * SIP messages are received or the GUI gives the "sip"
+ * subsystem a command. A typical task of the default
+ * handler is to add dialogs to the SIP stack as a
+ * reaction to an incoming message or a command from
+ * the GUI.
+ *
+ * An application needs to "hook into" the SIP stack and decide
+ * how it should handle messages from the network, GUI or commands
+ * generated from within the SIP stack (such as transport error
+ * messages). The application creates a sub-class of SipDefaultHandler
+ * and implements four handler methods.
+ *
+ * An example of what the default handler could do is:
+ * - Create a server voip dialog an INVITE message is receved
+ * - Create a client voip dialog if the GUI sends a command
+ * indicating that the user wants to make a call
+ */
+class LIBMSIP_API SipDefaultHandler : public SipSMCommandReceiver, public CommandReceiver{
+ public:
+ /**
+ * If the SIP stack does not handle a command sent to the
+ * SIP subsystem, then the default handler will receive it.
+ *
+ * This method is required to be a "CommandReceiver" that
+ * receives commands from the MessageRouter.
+ *
+ * @param subsystem This argument will be "sip"
+ * @param cmd
+ */
+ virtual void handleCommand(std::string subsystem, const CommandString &cmd)=0;
+ /**
+ * This method is similar to handleCommand(subsystem, cmd)
+ * with the difference that it returns a response to the
+ * caller.
+ */
+ virtual CommandString handleCommandResp(std::string subsystem, const CommandString &cmd)=0;
+ /**
+ * This method is what the SIP stack uses to communicate
+ * with the default handler. The handler receives
+ * SipSMCommand objects that contain either
+ * - A SIP message received by the transport layer
+ * or
+ * - A CommandString object (a string such as
+ * "transport_error")
+ * plus additional information such as what layer sent
+ * the message (transport, transaction or dialog).
+ */
+ virtual bool handleCommand(const SipSMCommand &cmd)=0;
+};
+
+
class LIBMSIP_API SipStackConfig : public MObject{
public:
SipStackConfig();
@@ -117,8 +171,6 @@
*/
int32_t getLocalSipPort(bool usesStun=false, const std::string &transport="UDP");
-// MRef<SipIdentity*> sipIdentity;
-
bool autoAnswer;
@@ -147,7 +199,6 @@
string instanceId;
};
-
//TODO: Enable conference calling
@@ -184,16 +235,20 @@
* See the main documentation document for how to implement application
* layer support for new header and content types (@see Factories).
*/
-class LIBMSIP_API SipStack : public Runnable{
+class LIBMSIP_API SipStack : public CommandReceiver, public Runnable{
public:
SipStack( MRef<SipStackConfig*> stackConfig );
~SipStack();
void setTransactionHandlesAck(bool transHandleAck);
- void setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb);
+ void setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb);
virtual void run();
virtual void stopRunning();
+ void handleCommand(std::string subsystem, const CommandString &cmd);
+
+ CommandString handleCommandResp(std::string subsystem, const CommandString &cmd);
+
bool handleCommand(const CommandString &cmd);
bool handleCommand(const SipSMCommand &cmd);
void enqueueTimeout(MRef<SipDialog*> receiver, const SipSMCommand &cmd);
Modified: trunk/libmsip/include/libmsip/SipStackInternal.h
===================================================================
--- trunk/libmsip/include/libmsip/SipStackInternal.h 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/include/libmsip/SipStackInternal.h 2006-11-23 17:21:51 UTC (rev 2949)
@@ -46,7 +46,8 @@
void setTransactionHandlesAck(bool transHandleAck);
- void setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb);
+ void setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb);
+ MRef<SipDefaultHandler*> getDefaultDialogCommandHandler();
virtual std::string getMemObjectType() const {return "SipStackInternal";}
Modified: trunk/libmsip/source/SipLayerDialog.cxx
===================================================================
--- trunk/libmsip/source/SipLayerDialog.cxx 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/source/SipLayerDialog.cxx 2006-11-23 17:21:51 UTC (rev 2949)
@@ -67,9 +67,12 @@
dialogListLock.unlock();
}
-void SipLayerDialog::setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb){
+void SipLayerDialog::setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb){
defaultHandler=cb;
}
+MRef<SipDefaultHandler*> SipLayerDialog::getDefaultDialogCommandHandler(){
+ return defaultHandler;
+}
//TODO: Optimize how dialogs are found based on callid parameter.
bool SipLayerDialog::handleCommand(const SipSMCommand &c){
Modified: trunk/libmsip/source/SipStack.cxx
===================================================================
--- trunk/libmsip/source/SipStack.cxx 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/source/SipStack.cxx 2006-11-23 17:21:51 UTC (rev 2949)
@@ -88,7 +88,7 @@
}
-void SipStack::setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb){
+void SipStack::setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb){
STACK->setDefaultDialogCommandHandler(cb);
}
@@ -100,6 +100,17 @@
STACK->stopRunning();
}
+void SipStack::handleCommand(std::string subsystem, const CommandString &cmd){
+ massert(subsystem=="sip");
+ if (!handleCommand(cmd))
+ STACK->getDefaultDialogCommandHandler()->handleCommand(subsystem,cmd);
+}
+
+CommandString SipStack::handleCommandResp(std::string subsystem, const CommandString &cmd){
+ return STACK->getDefaultDialogCommandHandler()->handleCommandResp(subsystem, cmd);
+}
+
+
bool SipStack::handleCommand(const CommandString &cmd){
return STACK->handleCommand(cmd);
}
Modified: trunk/libmsip/source/SipStackInternal.cxx
===================================================================
--- trunk/libmsip/source/SipStackInternal.cxx 2006-11-22 17:35:27 UTC (rev 2948)
+++ trunk/libmsip/source/SipStackInternal.cxx 2006-11-23 17:21:51 UTC (rev 2949)
@@ -153,10 +153,14 @@
return config;
}
-void SipStackInternal::setDefaultDialogCommandHandler(MRef<SipSMCommandReceiver*> cb){
+void SipStackInternal::setDefaultDialogCommandHandler(MRef<SipDefaultHandler*> cb){
dispatcher->getLayerDialog()->setDefaultDialogCommandHandler(cb);
}
+MRef<SipDefaultHandler*> SipStackInternal::getDefaultDialogCommandHandler(){
+ return dispatcher->getLayerDialog()->getDefaultDialogCommandHandler();
+}
+
void SipStackInternal::setTransactionHandlesAck(bool transHandleAck){
dispatcher->getLayerTransaction()->doHandleAck(transHandleAck);
}
More information about the Minisip-devel
mailing list