reSIProcate/DialogUsageManager  9680
ClientSubscription.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_CLIENTSUBSCRIPTION_HXX)
00002 #define RESIP_CLIENTSUBSCRIPTION_HXX
00003 
00004 #include <deque>
00005 #include "resip/dum/BaseSubscription.hxx"
00006 
00007 namespace resip
00008 {
00009 
00010 class DialogUsageManager;
00011 
00013 
00014 class ClientSubscription: public BaseSubscription
00015 {
00016    public:      
00017       ClientSubscription(DialogUsageManager& dum, Dialog& dialog,
00018                          const SipMessage& request, UInt32 defaultSubExpiration);
00019 
00020       typedef Handle<ClientSubscription> ClientSubscriptionHandle;
00021       ClientSubscriptionHandle getHandle();
00022       
00023       //.dcm. no adornment for ease of use, can add if there is a use case
00024       void acceptUpdate(int statusCode = 200, const char* reason=0);
00025       void rejectUpdate(int statusCode = 400, const Data& reasonPhrase = Data::Empty);
00026       void requestRefresh(UInt32 expires = 0);  // 0 defaults to using original expires value (to remove call end() instead)
00027       virtual void end();
00028       void end(bool immediate); // If immediate is true then usage is destroyed with no further messaging
00029       virtual void reSubscribe();  // forms a new Subscription dialog - reusing the same target and AppDialogSet      
00033       void acceptUpdateCommand(int statusCode = 200, const char* reason=0);
00034       void rejectUpdateCommand(int statusCode = 400, const Data& reasonPhrase = Data::Empty);
00035       void requestRefreshCommand(UInt32 expires = 0);  // 0 defaults to using original expires value (to remove call endCommand() instead)
00036       virtual void endCommand(bool immediate=false); // If immediate is true then usage is destroyed with no further messaging
00037 
00038       virtual EncodeStream& dump(EncodeStream& strm) const;
00039 
00040    protected:
00041       virtual ~ClientSubscription();
00042       virtual void dialogDestroyed(const SipMessage& msg);
00043       virtual void onReadyToSend(SipMessage& msg);
00044       virtual void send(SharedPtr<SipMessage> msg);
00045       virtual void flowTerminated();
00046 
00047    private:
00048       friend class Dialog;
00049       friend class InviteSession;      
00050 
00051       class QueuedNotify
00052       {
00053          public:
00054             QueuedNotify(const SipMessage& notify, bool outOfOrder)
00055                : mNotify(notify), mOutOfOrder(outOfOrder) {}
00056 
00057             SipMessage& notify() { return mNotify; }
00058             bool outOfOrder() { return mOutOfOrder; }
00059 
00060          private:
00061             SipMessage mNotify;
00062             bool mOutOfOrder;
00063       };
00064 
00065       typedef std::deque<QueuedNotify*> NotifyQueue;
00066       NotifyQueue mQueuedNotifies;
00067 
00068       typedef std::vector<QueuedNotify*> Dustbin;
00069       Dustbin mDustbin;
00070 
00071       bool mOnNewSubscriptionCalled;
00072       //SipMessage mLastNotify;      
00073       bool mEnded;
00074       // .bwc. This is when our next reSUB is scheduled to happen.
00075       UInt64 mNextRefreshSecs;
00076       UInt64 mLastSubSecs;
00077 
00078       // this is the expires value from the 2xx coming from the SUB message
00079       UInt32 mDefaultExpires;
00080 
00081       bool mRefreshing;
00082       bool mHaveQueuedRefresh;
00083       int mQueuedRefreshInterval;
00084 
00085       unsigned int mLargestNotifyCSeq;
00086 
00087       virtual void dispatch(const SipMessage& msg);
00088       virtual void dispatch(const DumTimeout& timer);
00089 
00090       void sendQueuedRefreshRequest();
00091       void processNextNotify();
00092       void processResponse(const SipMessage& response);
00093       void clearDustbin();
00094       void scheduleRefresh(unsigned long refreshInterval);
00095       
00096       // disabled
00097       ClientSubscription(const ClientSubscription&);
00098       ClientSubscription& operator=(const ClientSubscription&);
00099 };
00100  
00101 }
00102 
00103 #endif
00104 
00105 /* ====================================================================
00106  * The Vovida Software License, Version 1.0 
00107  * 
00108  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00109  * 
00110  * Redistribution and use in source and binary forms, with or without
00111  * modification, are permitted provided that the following conditions
00112  * are met:
00113  * 
00114  * 1. Redistributions of source code must retain the above copyright
00115  *    notice, this list of conditions and the following disclaimer.
00116  * 
00117  * 2. Redistributions in binary form must reproduce the above copyright
00118  *    notice, this list of conditions and the following disclaimer in
00119  *    the documentation and/or other materials provided with the
00120  *    distribution.
00121  * 
00122  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00123  *    and "Vovida Open Communication Application Library (VOCAL)" must
00124  *    not be used to endorse or promote products derived from this
00125  *    software without prior written permission. For written
00126  *    permission, please contact vocal@vovida.org.
00127  *
00128  * 4. Products derived from this software may not be called "VOCAL", nor
00129  *    may "VOCAL" appear in their name, without prior written
00130  *    permission of Vovida Networks, Inc.
00131  * 
00132  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00133  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00134  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00135  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00136  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00137  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00138  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00139  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00140  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00141  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00142  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00143  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00144  * DAMAGE.
00145  * 
00146  * ====================================================================
00147  * 
00148  * This software consists of voluntary contributions made by Vovida
00149  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00150  * Inc.  For more information on Vovida Networks, Inc., please see
00151  * <http://www.vovida.org/>.
00152  *
00153  */