reSIProcate/DialogUsageManager  9694
basicClientUserAgent.hxx
Go to the documentation of this file.
00001 #if !defined(basicClientUserAgent_hxx)
00002 #define basicClientUserAgent_hxx
00003 
00004 #include <set>
00005 #include "basicClientCmdLineParser.hxx"
00006 
00007 #include "resip/stack/InterruptableStackThread.hxx"
00008 #include "rutil/SelectInterruptor.hxx"
00009 #include "resip/dum/MasterProfile.hxx"
00010 #include "resip/dum/RegistrationHandler.hxx"
00011 #include "resip/dum/SubscriptionHandler.hxx"
00012 #include "resip/dum/RedirectHandler.hxx"
00013 #include "resip/dum/DialogSetHandler.hxx"
00014 #include "resip/dum/DumShutdownHandler.hxx"
00015 #include "resip/dum/OutOfDialogHandler.hxx"
00016 #include "resip/dum/InviteSessionHandler.hxx"
00017 #include "resip/dum/DialogUsageManager.hxx"
00018 #include "resip/dum/Postable.hxx"
00019 
00020 namespace resip
00021 {
00022 class BasicClientCall;
00023 
00024 class BasicClientUserAgent : public BasicClientCmdLineParser, 
00025                              public Postable,
00026                              public DialogSetHandler,
00027                              public ClientRegistrationHandler, 
00028                              public ClientSubscriptionHandler, 
00029                              public ServerSubscriptionHandler,
00030                              public OutOfDialogHandler, 
00031                              public InviteSessionHandler,
00032                              public DumShutdownHandler,
00033                              public RedirectHandler
00034 {
00035 public:
00036    BasicClientUserAgent(int argc, char** argv);
00037    virtual ~BasicClientUserAgent();
00038 
00039    virtual void startup();
00040    virtual void shutdown();
00041    bool process(int timeoutMs);  // returns false when shutdown is complete and process should no longer be called
00042 
00043    DialogUsageManager& getDialogUsageManager() { return *mDum; }
00044    SharedPtr<UserProfile> getIncomingUserProfile(const SipMessage& msg) { return mProfile; } // This test program only uses the one global Master Profile - just return it
00045       
00046 protected:
00047    // Postable Handler ////////////////////////////////////////////////////////////
00048    virtual void post(Message*);  // Used to receive Connection Terminated messages
00049 
00050    // Shutdown Handler ////////////////////////////////////////////////////////////
00051    void onDumCanBeDeleted();
00052 
00053    // Registration Handler ////////////////////////////////////////////////////////
00054    virtual void onSuccess(resip::ClientRegistrationHandle h, const resip::SipMessage& response);
00055    virtual void onFailure(resip::ClientRegistrationHandle h, const resip::SipMessage& response);
00056    virtual void onRemoved(resip::ClientRegistrationHandle h, const resip::SipMessage& response);
00057    virtual int onRequestRetry(resip::ClientRegistrationHandle h, int retryMinimum, const resip::SipMessage& msg);
00058 
00059    // ClientSubscriptionHandler ///////////////////////////////////////////////////
00060    virtual void onUpdatePending(resip::ClientSubscriptionHandle h, const resip::SipMessage& notify, bool outOfOrder);
00061    virtual void onUpdateActive(resip::ClientSubscriptionHandle h, const resip::SipMessage& notify, bool outOfOrder);
00062    virtual void onUpdateExtension(resip::ClientSubscriptionHandle, const resip::SipMessage& notify, bool outOfOrder);
00063    virtual void onNotifyNotReceived(ClientSubscriptionHandle h);
00064    virtual void onTerminated(resip::ClientSubscriptionHandle h, const resip::SipMessage* notify);
00065    virtual void onNewSubscription(resip::ClientSubscriptionHandle h, const resip::SipMessage& notify);
00066    virtual int  onRequestRetry(resip::ClientSubscriptionHandle h, int retrySeconds, const resip::SipMessage& notify);
00067 
00068    // Invite Session Handler /////////////////////////////////////////////////////
00069    virtual void onNewSession(resip::ClientInviteSessionHandle h, resip::InviteSession::OfferAnswerType oat, const resip::SipMessage& msg);
00070    virtual void onNewSession(resip::ServerInviteSessionHandle h, resip::InviteSession::OfferAnswerType oat, const resip::SipMessage& msg);
00071    virtual void onFailure(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg);
00072    virtual void onEarlyMedia(resip::ClientInviteSessionHandle, const resip::SipMessage&, const resip::SdpContents&);
00073    virtual void onProvisional(resip::ClientInviteSessionHandle, const resip::SipMessage& msg);
00074    virtual void onConnected(resip::ClientInviteSessionHandle h, const resip::SipMessage& msg);
00075    virtual void onConnected(resip::InviteSessionHandle, const resip::SipMessage& msg);
00076    virtual void onStaleCallTimeout(resip::ClientInviteSessionHandle);
00077    virtual void onTerminated(resip::InviteSessionHandle h, resip::InviteSessionHandler::TerminatedReason reason, const resip::SipMessage* msg);
00078    virtual void onRedirected(resip::ClientInviteSessionHandle, const resip::SipMessage& msg);
00079    virtual void onAnswer(resip::InviteSessionHandle, const resip::SipMessage& msg, const resip::SdpContents&);
00080    virtual void onOffer(resip::InviteSessionHandle handle, const resip::SipMessage& msg, const resip::SdpContents& offer);
00081    virtual void onOfferRequired(resip::InviteSessionHandle, const resip::SipMessage& msg);
00082    virtual void onOfferRejected(resip::InviteSessionHandle, const resip::SipMessage* msg);
00083    virtual void onOfferRequestRejected(resip::InviteSessionHandle, const resip::SipMessage& msg);
00084    virtual void onRemoteSdpChanged(resip::InviteSessionHandle, const resip::SipMessage& msg, const resip::SdpContents& sdp);
00085    virtual void onInfo(resip::InviteSessionHandle, const resip::SipMessage& msg);
00086    virtual void onInfoSuccess(resip::InviteSessionHandle, const resip::SipMessage& msg);
00087    virtual void onInfoFailure(resip::InviteSessionHandle, const resip::SipMessage& msg);
00088    virtual void onRefer(resip::InviteSessionHandle, resip::ServerSubscriptionHandle, const resip::SipMessage& msg);
00089    virtual void onReferAccepted(resip::InviteSessionHandle, resip::ClientSubscriptionHandle, const resip::SipMessage& msg);
00090    virtual void onReferRejected(resip::InviteSessionHandle, const resip::SipMessage& msg);
00091    virtual void onReferNoSub(resip::InviteSessionHandle, const resip::SipMessage& msg);
00092    virtual void onMessage(resip::InviteSessionHandle, const resip::SipMessage& msg);
00093    virtual void onMessageSuccess(resip::InviteSessionHandle, const resip::SipMessage& msg);
00094    virtual void onMessageFailure(resip::InviteSessionHandle, const resip::SipMessage& msg);
00095    virtual void onForkDestroyed(resip::ClientInviteSessionHandle);
00096    virtual void onReadyToSend(InviteSessionHandle, SipMessage& msg);
00097    virtual void onFlowTerminated(InviteSessionHandle);
00098 
00099    // DialogSetHandler  //////////////////////////////////////////////
00100    virtual void onTrying(resip::AppDialogSetHandle, const resip::SipMessage& msg);
00101    virtual void onNonDialogCreatingProvisional(resip::AppDialogSetHandle, const resip::SipMessage& msg);
00102 
00103    // ServerSubscriptionHandler ///////////////////////////////////////////////////
00104    virtual void onNewSubscription(resip::ServerSubscriptionHandle, const resip::SipMessage& sub);
00105    virtual void onNewSubscriptionFromRefer(resip::ServerSubscriptionHandle, const resip::SipMessage& sub);
00106    virtual void onRefresh(resip::ServerSubscriptionHandle, const resip::SipMessage& sub);
00107    virtual void onTerminated(resip::ServerSubscriptionHandle);
00108    virtual void onReadyToSend(resip::ServerSubscriptionHandle, resip::SipMessage&);
00109    virtual void onNotifyRejected(resip::ServerSubscriptionHandle, const resip::SipMessage& msg);      
00110    virtual void onError(resip::ServerSubscriptionHandle, const resip::SipMessage& msg);      
00111    virtual void onExpiredByClient(resip::ServerSubscriptionHandle, const resip::SipMessage& sub, resip::SipMessage& notify);
00112    virtual void onExpired(resip::ServerSubscriptionHandle, resip::SipMessage& notify);
00113    virtual bool hasDefaultExpires() const;
00114    virtual UInt32 getDefaultExpires() const;
00115 
00116    // OutOfDialogHandler //////////////////////////////////////////////////////////
00117    virtual void onSuccess(resip::ClientOutOfDialogReqHandle, const resip::SipMessage& response);
00118    virtual void onFailure(resip::ClientOutOfDialogReqHandle, const resip::SipMessage& response);
00119    virtual void onReceivedRequest(resip::ServerOutOfDialogReqHandle, const resip::SipMessage& request);
00120 
00121    // RedirectHandler /////////////////////////////////////////////////////////////
00122    virtual void onRedirectReceived(resip::AppDialogSetHandle, const resip::SipMessage& response);
00123    virtual bool onTryingNextTarget(resip::AppDialogSetHandle, const resip::SipMessage& request);
00124 
00125 protected:
00126    void addTransport(TransportType type, int port);
00127    friend class NotifyTimer;
00128    void onNotifyTimeout(unsigned int timerId);
00129    void sendNotify();
00130    friend class CallTimer;
00131    void onCallTimeout(BasicClientCall* call);
00132 
00133    SharedPtr<MasterProfile> mProfile;
00134    Security* mSecurity;
00135    SipStack mStack;
00136    DialogUsageManager* mDum; // DUM holds pointers to alot of objects that access this UserAgent class - using a pointer to DUM so that we can have more control over it's lifetime
00137    SelectInterruptor mSelectInterruptor;
00138    InterruptableStackThread mStackThread;
00139    volatile bool mDumShutdownRequested;
00140    bool mDumShutdown;
00141    ClientRegistrationHandle mRegHandle;
00142    ClientSubscriptionHandle mClientSubscriptionHandle;
00143    ServerSubscriptionHandle mServerSubscriptionHandle;
00144    unsigned int mRegistrationRetryDelayTime;
00145    unsigned int mCurrentNotifyTimerId;
00146 
00147    friend class BasicClientCall;
00148    std::set<BasicClientCall*> mCallList;
00149    void registerCall(BasicClientCall* call);
00150    void unregisterCall(BasicClientCall* call);
00151    bool isValidCall(BasicClientCall* call);
00152 };
00153  
00154 }
00155 
00156 #endif
00157 
00158 /* ====================================================================
00159 
00160  Copyright (c) 2011, SIP Spectrum, Inc.
00161  All rights reserved.
00162 
00163  Redistribution and use in source and binary forms, with or without
00164  modification, are permitted provided that the following conditions are 
00165  met:
00166 
00167  1. Redistributions of source code must retain the above copyright 
00168     notice, this list of conditions and the following disclaimer. 
00169 
00170  2. Redistributions in binary form must reproduce the above copyright
00171     notice, this list of conditions and the following disclaimer in the
00172     documentation and/or other materials provided with the distribution. 
00173 
00174  3. Neither the name of SIP Spectrum nor the names of its contributors 
00175     may be used to endorse or promote products derived from this 
00176     software without specific prior written permission. 
00177 
00178  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
00179  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
00180  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
00181  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
00182  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
00183  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
00184  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
00185  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
00186  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
00187  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
00188  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00189 
00190  ==================================================================== */
00191