/[resiprocate]/branches/b-client-outbound-20110213/resip/dum/test/basicClientUserAgent.cxx
ViewVC logotype

Diff of /branches/b-client-outbound-20110213/resip/dum/test/basicClientUserAgent.cxx

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 9016 by sgodin, Wed Feb 16 18:06:10 2011 UTC revision 9018 by sgodin, Wed Feb 16 22:40:07 2011 UTC
# Line 2  Line 2 
2  #include <rutil/Logger.hxx>  #include <rutil/Logger.hxx>
3  #include <rutil/DnsUtil.hxx>  #include <rutil/DnsUtil.hxx>
4  #include <resip/stack/SdpContents.hxx>  #include <resip/stack/SdpContents.hxx>
5    #include <resip/stack/PlainContents.hxx>
6  #include <resip/stack/ConnectionTerminated.hxx>  #include <resip/stack/ConnectionTerminated.hxx>
7  #include <resip/stack/Helper.hxx>  #include <resip/stack/Helper.hxx>
8  #include <resip/dum/AppDialogSetFactory.hxx>  #include <resip/dum/AppDialogSetFactory.hxx>
# Line 34  Line 35 
35  static unsigned int MaxRegistrationRetryTime = 1800;              // RFC5626 section 4.5 default  static unsigned int MaxRegistrationRetryTime = 1800;              // RFC5626 section 4.5 default
36  static unsigned int BaseRegistrationRetryTimeAllFlowsFailed = 30; // RFC5626 section 4.5 default  static unsigned int BaseRegistrationRetryTimeAllFlowsFailed = 30; // RFC5626 section 4.5 default
37  static unsigned int BaseRegistrationRetryTime = 90;               // RFC5626 section 4.5 default  static unsigned int BaseRegistrationRetryTime = 90;               // RFC5626 section 4.5 default
38    static unsigned int NotifySendTime = 30;  // If someone subscribes to our test event package, then send notifies every 30 seconds
39    static unsigned int FailedSubscriptionRetryTime = 60;
40    
41    namespace resip
42    {
43  class ClientAppDialogSetFactory : public AppDialogSetFactory  class ClientAppDialogSetFactory : public AppDialogSetFactory
44  {  {
45  public:  public:
# Line 78  Line 83 
83     virtual MessageDecorator* clone() const { return new SdpMessageDecorator; }     virtual MessageDecorator* clone() const { return new SdpMessageDecorator; }
84  };  };
85    
86    class NotifyTimer : public resip::DumCommand
87    {
88       public:
89          NotifyTimer(BasicClientUserAgent& userAgent, unsigned int timerId) : mUserAgent(userAgent), mTimerId(timerId) {}
90          NotifyTimer(const NotifyTimer& rhs) : mUserAgent(rhs.mUserAgent), mTimerId(rhs.mTimerId) {}
91          ~NotifyTimer() {}
92    
93          void executeCommand() { mUserAgent.onNotifyTimeout(mTimerId); }
94    
95          resip::Message* clone() const { return new NotifyTimer(*this); }
96          EncodeStream& encode(EncodeStream& strm) const { strm << "NotifyTimer: id=" << mTimerId; return strm; }
97          EncodeStream& encodeBrief(EncodeStream& strm) const { return encode(strm); }
98    
99       private:
100          BasicClientUserAgent& mUserAgent;
101          unsigned int mTimerId;
102    };
103    } // end namespace
104    
105  BasicClientUserAgent::BasicClientUserAgent(int argc, char** argv) :  BasicClientUserAgent::BasicClientUserAgent(int argc, char** argv) :
106     BasicClientCmdLineParser(argc, argv),     BasicClientCmdLineParser(argc, argv),
107     mProfile(new MasterProfile),     mProfile(new MasterProfile),
# Line 91  Line 115 
115     mStackThread(mStack, mSelectInterruptor),     mStackThread(mStack, mSelectInterruptor),
116     mDumShutdownRequested(false),     mDumShutdownRequested(false),
117     mDumShutdown(false),     mDumShutdown(false),
118     mRegistrationRetryDelayTime(0)     mRegistrationRetryDelayTime(0),
119       mCurrentNotifyTimerId(0)
120  {  {
121     Log::initialize(mLogType, mLogLevel, argv[0]);     Log::initialize(mLogType, mLogLevel, argv[0]);
122    
# Line 115  Line 140 
140     mProfile->addSupportedMethod(OPTIONS);     mProfile->addSupportedMethod(OPTIONS);
141     mProfile->addSupportedMethod(BYE);     mProfile->addSupportedMethod(BYE);
142     //mProfile->addSupportedMethod(REFER);         //mProfile->addSupportedMethod(REFER);    
143     //mProfile->addSupportedMethod(NOTIFY);         mProfile->addSupportedMethod(NOTIFY);    
144     //mProfile->addSupportedMethod(SUBSCRIBE);     mProfile->addSupportedMethod(SUBSCRIBE);
145     //mProfile->addSupportedMethod(UPDATE);         //mProfile->addSupportedMethod(UPDATE);    
146     mProfile->addSupportedMethod(INFO);         mProfile->addSupportedMethod(INFO);    
147     mProfile->addSupportedMethod(PRACK);         mProfile->addSupportedMethod(PRACK);    
# Line 146  Line 171 
171     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "mixed"));       mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "mixed"));  
172     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "signed"));       mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "signed"));  
173     mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "alternative"));       mProfile->addSupportedMimeType(UPDATE, Mime("multipart", "alternative"));  
174       mProfile->addSupportedMimeType(NOTIFY, Mime("text","plain"));  // subscription testing
175     //mProfile->addSupportedMimeType(NOTIFY, Mime("message", "sipfrag"));       //mProfile->addSupportedMimeType(NOTIFY, Mime("message", "sipfrag"));  
176    
177     // Supported Options Tags     // Supported Options Tags
# Line 243  Line 269 
269     //mDum->addOutOfDialogHandler(REFER, this);     //mDum->addOutOfDialogHandler(REFER, this);
270     mDum->setRedirectHandler(this);     mDum->setRedirectHandler(this);
271     mDum->setClientRegistrationHandler(this);     mDum->setClientRegistrationHandler(this);
272     //mDum->addClientSubscriptionHandler("refer", this);     mDum->addClientSubscriptionHandler("basicClientTest", this);   // fabricated test event package
273     //mDum->addServerSubscriptionHandler("refer", this);     mDum->addServerSubscriptionHandler("basicClientTest", this);
274    
275     // Set AppDialogSetFactory     // Set AppDialogSetFactory
276     auto_ptr<AppDialogSetFactory> dsf(new ClientAppDialogSetFactory(*this));     auto_ptr<AppDialogSetFactory> dsf(new ClientAppDialogSetFactory(*this));
# Line 295  Line 321 
321              mRegHandle->end();              mRegHandle->end();
322           }           }
323    
324             // end any subscriptions
325             if(mServerSubscriptionHandle.isValid())
326             {
327                mServerSubscriptionHandle->end();
328             }
329             if(mClientSubscriptionHandle.isValid())
330             {
331                mClientSubscriptionHandle->end();
332             }
333    
334           // End all calls - !slg! TODO           // End all calls - !slg! TODO
335    
336           mDum->shutdown(this);           mDum->shutdown(this);
# Line 342  Line 378 
378     ConnectionTerminated* terminated = dynamic_cast<ConnectionTerminated*>(msg);     ConnectionTerminated* terminated = dynamic_cast<ConnectionTerminated*>(msg);
379     if (terminated)     if (terminated)
380     {     {
381        InfoLog(<< "BasicClientUserAgent received connection terminated message for: " << terminated->getFlow());        InfoLog(<< "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BasicClientUserAgent received connection terminated message for: " << terminated->getFlow());  // !slg! TODO - remove strange log markers
382        delete msg;        delete msg;
383        return;        return;
384     }     }
# Line 350  Line 386 
386  }  }
387    
388  void  void
389    BasicClientUserAgent::onNotifyTimeout(unsigned int timerId)
390    {
391       if(timerId == mCurrentNotifyTimerId)
392       {
393          sendNotify();
394       }
395    }
396    
397    void
398    BasicClientUserAgent::sendNotify()
399    {
400       if(mServerSubscriptionHandle.isValid())
401       {
402          PlainContents plain("test notify");
403          mServerSubscriptionHandle->send(mServerSubscriptionHandle->update(&plain));
404    
405          // start timer for next one
406          auto_ptr<ApplicationMessage> timer(new NotifyTimer(*this, ++mCurrentNotifyTimerId));
407          mStack.post(timer, NotifySendTime, mDum);
408       }
409    }
410    
411    void
412  BasicClientUserAgent::onDumCanBeDeleted()  BasicClientUserAgent::onDumCanBeDeleted()
413  {  {
414     mDumShutdown = true;     mDumShutdown = true;
# Line 362  Line 421 
421  BasicClientUserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& msg)  BasicClientUserAgent::onSuccess(ClientRegistrationHandle h, const SipMessage& msg)
422  {  {
423     InfoLog(<< "onSuccess(ClientRegistrationHandle): msg=" << msg.brief());     InfoLog(<< "onSuccess(ClientRegistrationHandle): msg=" << msg.brief());
424       if(mRegHandle.getId() == 0)  // Note: reg handle id will only be 0 on first successful registration
425       {
426          // Check if we should try to form a test subscription
427          if(!mSubscribeTarget.host().empty())
428          {
429             SharedPtr<SipMessage> sub = mDum->makeSubscription(NameAddr(mSubscribeTarget), mProfile, "basicClientTest");
430             mDum->send(sub);
431          }
432       }
433     mRegHandle = h;     mRegHandle = h;
434     mRegistrationRetryDelayTime = 0;  // reset     mRegistrationRetryDelayTime = 0;  // reset
435  }  }
# Line 617  Line 685 
685        return;        return;
686     }     }
687     InfoLog(<< "onUpdatePending(ClientSubscriptionHandle): " << msg.brief());     InfoLog(<< "onUpdatePending(ClientSubscriptionHandle): " << msg.brief());
688       h->acceptUpdate();
689  }  }
690    
691  void  void
# Line 629  Line 698 
698        return;        return;
699     }     }
700     InfoLog(<< "onUpdateActive(ClientSubscriptionHandle): " << msg.brief());     InfoLog(<< "onUpdateActive(ClientSubscriptionHandle): " << msg.brief());
701       h->acceptUpdate();
702  }  }
703    
704  void  void
# Line 641  Line 711 
711        return;        return;
712     }     }
713     InfoLog(<< "onUpdateExtension(ClientSubscriptionHandle): " << msg.brief());     InfoLog(<< "onUpdateExtension(ClientSubscriptionHandle): " << msg.brief());
714       h->acceptUpdate();
715  }  }
716    
717  void  void
# Line 684  Line 755 
755        call->onNewSubscription(h, msg);        call->onNewSubscription(h, msg);
756        return;        return;
757     }     }
758       mClientSubscriptionHandle = h;
759     InfoLog(<< "onNewSubscription(ClientSubscriptionHandle): msg=" << msg.brief());     InfoLog(<< "onNewSubscription(ClientSubscriptionHandle): msg=" << msg.brief());
760  }  }
761    
# Line 696  Line 768 
768        return call->onRequestRetry(h, retrySeconds, msg);        return call->onRequestRetry(h, retrySeconds, msg);
769     }     }
770     InfoLog(<< "onRequestRetry(ClientSubscriptionHandle): msg=" << msg.brief());     InfoLog(<< "onRequestRetry(ClientSubscriptionHandle): msg=" << msg.brief());
771     return -1;     return FailedSubscriptionRetryTime;  
772  }  }
773    
774  ////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////
775  // ServerSubscriptionHandler ///////////////////////////////////////////////////  // ServerSubscriptionHandler ///////////////////////////////////////////////////
776  ////////////////////////////////////////////////////////////////////////////////  ////////////////////////////////////////////////////////////////////////////////
777  void  void
778  BasicClientUserAgent::onNewSubscription(ServerSubscriptionHandle, const SipMessage& msg)  BasicClientUserAgent::onNewSubscription(ServerSubscriptionHandle h, const SipMessage& msg)
779  {  {
780     InfoLog(<< "onNewSubscription(ServerSubscriptionHandle): " << msg.brief());     InfoLog(<< "onNewSubscription(ServerSubscriptionHandle): " << msg.brief());
781    
782       mServerSubscriptionHandle = h;
783       mServerSubscriptionHandle->setSubscriptionState(Active);
784       mServerSubscriptionHandle->send(mServerSubscriptionHandle->accept());
785    
786       sendNotify();
787  }  }
788    
789  void  void

Legend:
Removed from v.9016  
changed lines
  Added in v.9018

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27