Associating Application Data with Dialogs/DialogSets

From reSIProcate
Jump to navigation Jump to search

An application can associate user data with Dialog/DialogSet by overriding the AppDialog, AppDialogSet and AppDialogSetFactory classes.

1. The application should create classes inherited from AppDialog, AppDialogSet and AppDialogSetFactory. These classes can then contain any application specific data.

2. For the UAC side - when a new dialogset/dialog is to be created. Create one of the AppDialogSet inherited objects and pass it into the DUM makeXXXX functions.

3. For the UAS side - override createAppDialogSet function from AppDialogSetFactory so that the object (inherited from AppDialogSet) is created instead of the base AppDialogSet object.

4. The handlers can get at data in the AppDialog or AppDialogSet by calling getAppDialog() or getAppDialogSet on the usage handle and casting the result to the inherited class.


For example - In this case the user data is just an int...

  class TestAppDialog : public AppDialog
  {
  public:
     TestAppDialog(HandleManager& ham, int portID) : AppDialog(ham), m_portID(portID)
     {
        InfoLog(  << "TestAppDialogSet::TestAppDialog: " << m_portID);
     }
     virtual ~TestAppDialog()
     {
        InfoLog(  << "TestAppDialog::~TestAppDialog: " << m_portID);
     }
     int m_portID;
  };
  class TestAppDialogSet : public AppDialogSet 
  {
  public:
     TestAppDialogSet(DialogUsageManager& dum, int portID) : AppDialogSet(dum), m_portID(portID)
     {
        InfoLog(  << "TestAppDialogSet::TestAppDialogSet: " << m_portID);
     }
     virtual ~TestAppDialogSet()
     {
        InfoLog(  << "TestAppDialogSet::~TestAppDialogSet: " << m_portID);
     }
     virtual AppDialog* createAppDialog(const SipMessage& msg)
     {
        InfoLog(  << "TestAppDialogSet::createAppDialog: " << m_portID << ", " << msg.brief());
        return new TestAppDialog(mDum, m_portID);
     }
     int m_portID;
  };
  class TestAppDialogSetFactory : public AppDialogSetFactory 
  {
  public:
     virtual AppDialogSet* createAppDialogSet(DialogUsageManager& dum, const SipMessage& msg)
     {
        InfoLog(  << "TestAppDialogSetFactory::createAppDialogSet: " << msg.brief());
        return new TestAppDialogSet(dum, application.getPortID());
        // For a UAS the testAppDialogSet will be created by DUM using this function.  If you want to set 
        // Application Data, another approach is to wait for onNewSession(ServerInviteSessionHandle ...) 
        // to be called, then use the ServerInviteSessionHandle to get at the AppDialogSet or AppDialog,
        // then cast to your derived class and set the desired application data.
     }
  };


Client side sample code:

  dumUac->send(dumUac->makeInviteSession(uasAor, uac.sdp, new TestAppDialogSet(*dumUac, 1110000)));

Handler Sample code for accessing user data:

  ....
  virtual void onNewSession(ServerInviteSessionHandle sis, InviteSession::OfferAnswerType oat, const SipMessage& msg)  
  {
     int portID = ((TestAppDialog*)sis->getAppDialog().get())->m_portID;
     InfoLog( << "[" << portID << "] TestUAS::onNewSession(ServerInviteSessionHandle): " << name << " "  << endl << msg);
     mSis = sis;  
     sis->send(sis->provisional(180));
  }