reSIProcate/stack  9694
TransactionUser.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_TU_HXX)
00002 #define RESIP_TU_HXX 
00003 
00004 #include <iosfwd>
00005 #include <set>
00006 #include "rutil/TimeLimitFifo.hxx"
00007 #include "rutil/Data.hxx"
00008 #include "rutil/CongestionManager.hxx"
00009 #include "resip/stack/Message.hxx"
00010 #include "resip/stack/MessageFilterRule.hxx"
00011 
00012 
00013 namespace resip
00014 {
00015 class SipMessage;
00016 
00048 class TransactionUser
00049 {
00050    public:
00056       void post(Message* msg);
00057 
00066       bool isMyDomain(const Data& domain) const;
00067 
00075       void addDomain(const Data& domain);
00076 
00081       virtual const Data& name() const=0;
00082 
00089       virtual EncodeStream& encode(EncodeStream& strm) const;
00090 
00101       void setMessageFilterRuleList(MessageFilterRuleList &rules);
00102 
00108       bool isRegisteredForTransactionTermination() const;
00109 
00115       bool isRegisteredForConnectionTermination() const;
00116       bool isRegisteredForKeepAlivePongs() const;
00117 
00118       inline CongestionManager::RejectionBehavior getRejectionBehavior() const
00119       {
00120          if(mCongestionManager)
00121          {
00122             return mCongestionManager->getRejectionBehavior(&mFifo);
00123          }
00124          return CongestionManager::NORMAL;
00125       }
00126       
00127       virtual void setCongestionManager(CongestionManager* manager)
00128       {
00129          if(mCongestionManager)
00130          {
00131             mCongestionManager->unregisterFifo(&mFifo);
00132          }
00133          mCongestionManager=manager;
00134          if(mCongestionManager)
00135          {
00136             mCongestionManager->registerFifo(&mFifo);
00137          }
00138       }
00139       
00140       virtual UInt16 getExpectedWait() const
00141       {
00142          return (UInt16)mFifo.expectedWaitTimeMilliSec();
00143       }
00144       
00145       // .bwc. This specifies whether the TU can cope with dropped responses
00146       // (due to congestion). Some TUs may need responses to clean up state,
00147       // while others may rely on TransactionTerminated messages. Those that
00148       // rely on TransactionTerminated messages will be able to return false
00149       // here, meaning that in dire congestion situations, the stack will drop
00150       // responses bound for the TU.
00151       virtual bool responsesMandatory() const {return true;}
00152       
00153    protected:
00154       enum TransactionTermination 
00155       {
00156          RegisterForTransactionTermination,
00157          DoNotRegisterForTransactionTermination
00158       };
00159 
00160       enum ConnectionTermination 
00161       {
00162          RegisterForConnectionTermination,
00163          DoNotRegisterForConnectionTermination
00164       };
00165 
00166       enum KeepAlivePongs 
00167       {
00168          RegisterForKeepAlivePongs,
00169          DoNotRegisterForKeepAlivePongs
00170       };
00171 
00185       TransactionUser(TransactionTermination t=DoNotRegisterForTransactionTermination,
00186                       ConnectionTermination c=DoNotRegisterForConnectionTermination,
00187                       KeepAlivePongs k=DoNotRegisterForKeepAlivePongs);
00188 
00201       TransactionUser(MessageFilterRuleList &rules, 
00202                       TransactionTermination t=DoNotRegisterForTransactionTermination,
00203                       ConnectionTermination c=DoNotRegisterForConnectionTermination,
00204                       KeepAlivePongs k=DoNotRegisterForKeepAlivePongs);
00205 
00206       virtual ~TransactionUser()=0;
00207 
00215       virtual bool isForMe(const SipMessage& msg) const;
00216 
00221       TimeLimitFifo<Message> mFifo;
00222       CongestionManager* mCongestionManager;
00223 
00224    private:      
00225       void postToTransactionUser(Message* msg, TimeLimitFifo<Message>::DepthUsage usage);
00226       unsigned int size() const;
00227       bool wouldAccept(TimeLimitFifo<Message>::DepthUsage usage) const;
00228 
00229    private:
00230       MessageFilterRuleList mRuleList;
00231       typedef std::set<Data> DomainList;
00232       DomainList mDomainList;
00233       bool mRegisteredForTransactionTermination;
00234       bool mRegisteredForConnectionTermination;
00235       bool mRegisteredForKeepAlivePongs;
00236       friend class TuSelector;      
00237 };
00238 
00239 EncodeStream& 
00240 operator<<(EncodeStream& strm, const TransactionUser& tu);
00241 
00242 }
00243 
00244 #endif
00245 
00246 /* ====================================================================
00247  * The Vovida Software License, Version 1.0 
00248  * 
00249  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00250  * 
00251  * Redistribution and use in source and binary forms, with or without
00252  * modification, are permitted provided that the following conditions
00253  * are met:
00254  * 
00255  * 1. Redistributions of source code must retain the above copyright
00256  *    notice, this list of conditions and the following disclaimer.
00257  * 
00258  * 2. Redistributions in binary form must reproduce the above copyright
00259  *    notice, this list of conditions and the following disclaimer in
00260  *    the documentation and/or other materials provided with the
00261  *    distribution.
00262  * 
00263  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00264  *    and "Vovida Open Communication Application Library (VOCAL)" must
00265  *    not be used to endorse or promote products derived from this
00266  *    software without prior written permission. For written
00267  *    permission, please contact vocal@vovida.org.
00268  *
00269  * 4. Products derived from this software may not be called "VOCAL", nor
00270  *    may "VOCAL" appear in their name, without prior written
00271  *    permission of Vovida Networks, Inc.
00272  * 
00273  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00274  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00275  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00276  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00277  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00278  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00279  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00280  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00281  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00282  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00283  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00284  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00285  * DAMAGE.
00286  * 
00287  * ====================================================================
00288  * 
00289  * This software consists of voluntary contributions made by Vovida
00290  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00291  * Inc.  For more information on Vovida Networks, Inc., please see
00292  * <http://www.vovida.org/>.
00293  *
00294  */