reSIProcate/DialogUsageManager  9680
Classes | Defines | Functions
BasicCall.cxx File Reference
#include "resip/stack/SdpContents.hxx"
#include "resip/stack/PlainContents.hxx"
#include "resip/stack/SipMessage.hxx"
#include "resip/stack/ShutdownMessage.hxx"
#include "resip/stack/SipStack.hxx"
#include "resip/dum/ClientAuthManager.hxx"
#include "resip/dum/ClientInviteSession.hxx"
#include "resip/dum/ClientRegistration.hxx"
#include "resip/dum/DialogUsageManager.hxx"
#include "resip/dum/DumShutdownHandler.hxx"
#include "resip/dum/InviteSessionHandler.hxx"
#include "resip/dum/MasterProfile.hxx"
#include "resip/dum/RegistrationHandler.hxx"
#include "resip/dum/ServerInviteSession.hxx"
#include "resip/dum/ServerOutOfDialogReq.hxx"
#include "resip/dum/OutOfDialogHandler.hxx"
#include "resip/dum/AppDialog.hxx"
#include "resip/dum/AppDialogSet.hxx"
#include "resip/dum/AppDialogSetFactory.hxx"
#include "rutil/Log.hxx"
#include "rutil/Logger.hxx"
#include "rutil/Random.hxx"
#include "rutil/WinLeakCheck.hxx"
#include <sstream>
#include <time.h>
Include dependency graph for BasicCall.cxx:

Go to the source code of this file.

Classes

class  testAppDialog
class  testAppDialogSet
class  testAppDialogSetFactory
class  TestInviteSessionHandler
class  TestUac
class  TestUas
class  TestShutdownHandler

Defines

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Functions

int main (int argc, char **argv)

Define Documentation

#define RESIPROCATE_SUBSYSTEM   Subsystem::TEST

Definition at line 28 of file BasicCall.cxx.


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 553 of file BasicCall.cxx.

References resip::DialogUsageManager::addOutOfDialogHandler(), resip::DialogUsageManager::addTransport(), resip::Log::Cout, TestUac::done, TestUas::done, TestShutdownHandler::dumShutDown, resip::DialogUsageManager::getMasterProfile(), resip::PlainContents::getStaticType(), TestUas::hangup(), resip::Uri::host(), resip::Log::Info, resip::Log::initialize(), resip::DialogUsageManager::makeInviteSession(), resip::DialogUsageManager::makeOutOfDialogRequest(), resip::DialogUsageManager::makeRegistration(), TestUac::mSdp, resip::Symbols::Outbound, resip::SipStack::process(), resip::DialogUsageManager::process(), resip::DialogUsageManager::send(), resip::DialogUsageManager::setAppDialogSetFactory(), resip::DialogUsageManager::setClientAuthManager(), resip::DialogUsageManager::setClientRegistrationHandler(), resip::DialogUsageManager::setInviteSessionHandler(), resip::DialogUsageManager::setMasterProfile(), resip::DialogUsageManager::shutdown(), resip::TCP, resip::UDP, resip::NameAddr::uri(), and resip::Uri::user().

{
   //Log::initialize(Log::Cout, resip::Log::Warning, argv[0]);
   //Log::initialize(Log::Cout, resip::Log::Debug, argv[0]);
   Log::initialize(Log::Cout, resip::Log::Info, argv[0]);
   //Log::initialize(Log::Cout, resip::Log::Debug, argv[0]);

#if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 
   FindMemoryLeaks fml;
   {
#endif
   bool doReg = false;
   NameAddr uacAor;
   NameAddr uasAor;
   Data uacPasswd;
   Data uasPasswd;
   bool useOutbound = false;
   Uri outboundUri;

   if ( argc == 1 ) 
   {
      uacAor = NameAddr("sip:UAC@127.0.0.1:12005");
      uasAor = NameAddr("sip:UAS@127.0.0.1:12010");
      cout << "Skipping registration (no arguments)." << endl;
   } 
   else 
   {
      if ( argc < 5 ) 
      {
         cout << "usage: " << argv[0] <<
                 " sip:user1 passwd1 sip:user2 passwd2 [outbound]" << endl;
         return 1;
      }
      doReg = true;
      uacAor = NameAddr(argv[1]);
      uacPasswd = Data(argv[2]);
      uasAor = NameAddr(argv[3]);
      uasPasswd = Data(argv[4]);
      if ( argc >= 6 ) 
      {
         useOutbound = true;
         outboundUri = Uri(Data(argv[5]));
      }
   }

   //set up UAC
   SipStack stackUac;
   DialogUsageManager* dumUac = new DialogUsageManager(stackUac);
   dumUac->addTransport(UDP, 12005);
   dumUac->addTransport(TCP, 12005);

   SharedPtr<MasterProfile> uacMasterProfile(new MasterProfile);
   auto_ptr<ClientAuthManager> uacAuth(new ClientAuthManager);
   dumUac->setMasterProfile(uacMasterProfile);
   dumUac->setClientAuthManager(uacAuth);

   TestUac uac;
   dumUac->setInviteSessionHandler(&uac);
   dumUac->setClientRegistrationHandler(&uac);
   dumUac->addOutOfDialogHandler(OPTIONS, &uac);

   auto_ptr<AppDialogSetFactory> uac_dsf(new testAppDialogSetFactory);
   dumUac->setAppDialogSetFactory(uac_dsf);

   if ( doReg ) 
   {
      dumUac->getMasterProfile()->setDigestCredential(uacAor.uri().host(), uacAor.uri().user(), uacPasswd);
   }
   if (useOutbound) 
   {
       dumUac->getMasterProfile()->setOutboundProxy(outboundUri);
       dumUac->getMasterProfile()->addSupportedOptionTag(Token(Symbols::Outbound));
   }

   dumUac->getMasterProfile()->setDefaultFrom(uacAor);
   dumUac->getMasterProfile()->addSupportedMethod(INFO);
   dumUac->getMasterProfile()->addSupportedMethod(MESSAGE);
   dumUac->getMasterProfile()->addSupportedMimeType(INFO, PlainContents::getStaticType());
   dumUac->getMasterProfile()->addSupportedMimeType(MESSAGE, PlainContents::getStaticType());
   dumUac->getMasterProfile()->setDefaultRegistrationTime(70);

   //set up UAS
   SipStack stackUas;
   DialogUsageManager* dumUas = new DialogUsageManager(stackUas);
   dumUas->addTransport(UDP, 12010);
   dumUas->addTransport(TCP, 12010);
   
   SharedPtr<MasterProfile> uasMasterProfile(new MasterProfile);
   std::auto_ptr<ClientAuthManager> uasAuth(new ClientAuthManager);
   dumUas->setMasterProfile(uasMasterProfile);
   dumUas->setClientAuthManager(uasAuth);

   if(doReg) 
   {
      dumUas->getMasterProfile()->setDigestCredential(uasAor.uri().host(), uasAor.uri().user(), uasPasswd);
   }
   if(useOutbound) 
   {
      dumUas->getMasterProfile()->setOutboundProxy(outboundUri);
      dumUas->getMasterProfile()->addSupportedOptionTag(Token(Symbols::Outbound));
   }

   dumUas->getMasterProfile()->setDefaultFrom(uasAor);
   dumUas->getMasterProfile()->addSupportedMethod(INFO);
   dumUas->getMasterProfile()->addSupportedMethod(MESSAGE);
   dumUas->getMasterProfile()->addSupportedMimeType(INFO, PlainContents::getStaticType());
   dumUas->getMasterProfile()->addSupportedMimeType(MESSAGE, PlainContents::getStaticType());
   dumUas->getMasterProfile()->setDefaultRegistrationTime(70);

   time_t bHangupAt = 0;
   TestUas uas(&bHangupAt);
   dumUas->setClientRegistrationHandler(&uas);
   dumUas->setInviteSessionHandler(&uas);
   dumUas->addOutOfDialogHandler(OPTIONS, &uas);

   auto_ptr<AppDialogSetFactory> uas_dsf(new testAppDialogSetFactory);
   dumUas->setAppDialogSetFactory(uas_dsf);

   if (doReg) 
   {
      SharedPtr<SipMessage> regMessage = dumUas->makeRegistration(uasAor, new testAppDialogSet(*dumUac, "UAS(Registration)"));
      cout << "Sending register for Uas: " << endl << regMessage << endl;
      dumUas->send(regMessage);
   } 
   else 
   {
      uas.registered = true;
   }
   if (doReg) 
   {
      SharedPtr<SipMessage> regMessage = dumUac->makeRegistration(uacAor, new testAppDialogSet(*dumUac, "UAC(Registration)"));
      cout << "Sending register for Uac: " << endl << regMessage << endl;
      dumUac->send(regMessage);
   } 
   else 
   {
      uac.registered = true;
   }

   bool finishedTest = false;
   bool stoppedRegistering = false;
   bool startedCallFlow = false;
   bool hungup = false;   
   TestShutdownHandler uasShutdownHandler("UAS");   
   TestShutdownHandler uacShutdownHandler("UAC");   

   while (!(uasShutdownHandler.dumShutDown && uacShutdownHandler.dumShutDown))
   {
     if (!uacShutdownHandler.dumShutDown)
     {
        stackUac.process(50);
        while(dumUac->process());
     }
     if (!uasShutdownHandler.dumShutDown)
     {
        stackUas.process(50);
        while(dumUas->process());
     }

     if (!(uas.done && uac.done))
     {
        if (uas.registered && uac.registered && !startedCallFlow)
        {
           if (!startedCallFlow)
           {
              startedCallFlow = true;
              if ( doReg ) {
                 cout << "!!!!!!!!!!!!!!!! Registered !!!!!!!!!!!!!!!! " << endl;
              }

              // Kick off call flow by sending an OPTIONS request then an INVITE request from the UAC to the UAS
              cout << "UAC: Sending Options Request to UAS." << endl;
              dumUac->send(dumUac->makeOutOfDialogRequest(uasAor, OPTIONS, new testAppDialogSet(*dumUac, "UAC(OPTIONS)")));  // Should probably add Allow, Accept, Accept-Encoding, Accept-Language and Supported headers - but this is fine for testing/demonstration

              cout << "UAC: Sending Invite Request to UAS." << endl;
              dumUac->send(dumUac->makeInviteSession(uasAor, uac.mSdp, new testAppDialogSet(*dumUac, "UAC(INVITE)")));
           }
        }

        // Check if we should hangup yet
        if (bHangupAt!=0)
        {
           if (time(NULL)>bHangupAt && !hungup)
           {
              hungup = true;
              uas.hangup();
           }
        }
     }
     else
     {
        if (!stoppedRegistering)
        {
           finishedTest = true;
           stoppedRegistering = true;
           dumUas->shutdown(&uasShutdownHandler);
           dumUac->shutdown(&uacShutdownHandler);
            if ( doReg ) 
            {
              uas.registerHandle->stopRegistering();
              uac.registerHandle->stopRegistering();
            }
        }
     }
   }

   // OK to delete DUM objects now
   delete dumUac; 
   delete dumUas;

   cout << "!!!!!!!!!!!!!!!!!! Successful !!!!!!!!!! " << endl;
#if defined(WIN32) && defined(_DEBUG) && defined(LEAK_CHECK) 
   }
#endif

}

Here is the call graph for this function: