reSIProcate/stack  9694
TransactionController.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_TRANSACTION_CONTROLLER_HXX)
00002 #define RESIP_TRANSACTION_CONTROLLER_HXX
00003 
00004 #include "resip/stack/TuSelector.hxx"
00005 #include "resip/stack/TransactionMap.hxx"
00006 #include "resip/stack/TransportSelector.hxx"
00007 #include "resip/stack/TimerQueue.hxx"
00008 #include "rutil/CongestionManager.hxx"
00009 
00010 #include "rutil/ConsumerFifoBuffer.hxx"
00011 
00012 namespace resip
00013 {
00014 
00015 class TransactionMessage;
00016 class TimerMessage;
00017 class ApplicationMessage;
00018 class StatisticsManager;
00019 class SipStack;
00020 class Compression;
00021 class FdPollGrp;
00022 
00023 class TransactionController
00024 {
00025    public:
00026       // set after starting at your peril
00027       static unsigned int MaxTUFifoSize;
00028       static unsigned int MaxTUFifoTimeDepthSecs;
00029 
00030       TransactionController(SipStack& stack, 
00031                               AsyncProcessHandler* handler);
00032       ~TransactionController();
00033 
00034       void process(int timeout=0);
00035       unsigned int getTimeTillNextProcessMS();
00036 
00037       // graceful shutdown (eventually)
00038       void shutdown();
00039 
00040       TransportSelector& transportSelector() { return mTransportSelector; }
00041       const TransportSelector& transportSelector() const { return mTransportSelector; }
00042 
00043       bool isTUOverloaded() const;
00044       
00045       void send(SipMessage* msg);
00046 
00047       unsigned int getTuFifoSize() const;
00048       unsigned int sumTransportFifoSizes() const;
00049       unsigned int getTransactionFifoSize() const;
00050       unsigned int getNumClientTransactions() const;
00051       unsigned int getNumServerTransactions() const;
00052       unsigned int getTimerQueueSize() const;
00053       void zeroOutStatistics();
00054       void pollStatistics();
00055       
00056       void setCongestionManager( CongestionManager *manager ) 
00057       { 
00058          mTransportSelector.setCongestionManager(manager);
00059          if(mCongestionManager)
00060          {
00061             mCongestionManager->unregisterFifo(&mStateMacFifo);
00062          }
00063          mCongestionManager=manager;
00064          if(mCongestionManager)
00065          {
00066             mCongestionManager->registerFifo(&mStateMacFifo);
00067          }
00068       }
00069 
00070       CongestionManager::RejectionBehavior getRejectionBehavior() const
00071       {
00072          if(mCongestionManager)
00073          {
00074             return mCongestionManager->getRejectionBehavior(&mStateMacFifo);
00075          }
00076          return CongestionManager::NORMAL;
00077       }
00078 
00079       void registerMarkListener(MarkListener* listener);
00080       void unregisterMarkListener(MarkListener* listener);
00081 
00082       inline bool getFixBadDialogIdentifiers() const 
00083       {
00084          return mFixBadDialogIdentifiers;
00085       }
00086 
00087       inline void setFixBadDialogIdentifiers(bool pFixBadDialogIdentifiers) 
00088       {
00089          mFixBadDialogIdentifiers = pFixBadDialogIdentifiers;
00090       }
00091 
00092       inline bool getFixBadCSeqNumbers() const { return mFixBadCSeqNumbers;} 
00093       inline void setFixBadCSeqNumbers(bool pFixBadCSeqNumbers)
00094       {
00095          mFixBadCSeqNumbers = pFixBadCSeqNumbers;
00096       }
00097 
00098       void abandonServerTransaction(const Data& tid);
00099       void cancelClientInviteTransaction(const Data& tid);
00100       void terminateFlow(const resip::Tuple& flow);
00101       void enableFlowTimer(const resip::Tuple& flow);
00102 
00103       void setInterruptor(AsyncProcessHandler* handler);
00104    private:
00105       TransactionController(const TransactionController& rhs);
00106       TransactionController& operator=(const TransactionController& rhs);
00107       SipStack& mStack;
00108       
00109       // If true, indicate to the Transaction to ignore responses for which
00110       // there is no transaction. 
00111       // !jf! Probably should transmit stray responses statelessly. see RFC3261
00112       bool mDiscardStrayResponses;
00113 
00114       bool mFixBadDialogIdentifiers;
00115 
00116       bool mFixBadCSeqNumbers;
00117       // fifo used to communicate to the transaction state machine within the
00118       // stack. Not for external use by the application. May contain, sip
00119       // messages (requests and responses), timers (used by state machines),
00120       // asynchronous dns responses, transport errors from the underlying
00121       // transports, etc. 
00122       Fifo<TransactionMessage> mStateMacFifo;
00123       ConsumerFifoBuffer<TransactionMessage> mStateMacFifoOutBuffer;
00124       CongestionManager* mCongestionManager;
00125 
00126       //This needs to be separate from mStateMacFifo, because timer messages
00127       //need to be processed before other work. (If timers start getting behind
00128       //all kinds of nastiness occurs. We can tolerate some SipMessage traffic
00129       //getting behind, but processing timers late can cripple the entire
00130       //system with state-bloat.)
00131       // !bwc! This thing does not need to be threadsafe; it is both populated 
00132       // and consumed from the same thread.
00133       Fifo<TimerMessage> mTimerFifo;
00134 
00135       // from the sipstack (for convenience)
00136       TuSelector& mTuSelector;
00137 
00138       // Used to decide which transport to send a sip message on. 
00139       TransportSelector mTransportSelector;
00140 
00141       // stores all of the transactions that are currently active in this stack 
00142       TransactionMap mClientTransactionMap;
00143       TransactionMap mServerTransactionMap;
00144 
00145       // timers associated with the transactions. When a timer fires, it is
00146       // placed in the mStateMacFifo
00147       TransactionTimerQueue  mTimers;
00148 
00149       bool mShuttingDown;
00150       
00151       StatisticsManager& mStatsManager;
00152       
00153       Data mHostname;
00154       
00155       friend class SipStack; // for debug only
00156       friend class StatelessHandler;
00157       friend class TransactionState;
00158       friend class TransportSelector;
00159 
00160       friend class TestDnsResolver;
00161       friend class TestFSM;
00162 };
00163 
00164 
00165 }
00166 
00167 
00168 #endif
00169 /* ====================================================================
00170  * The Vovida Software License, Version 1.0 
00171  * 
00172  * Copyright (c) 2004 Vovida Networks, Inc.  All rights reserved.
00173  * 
00174  * Redistribution and use in source and binary forms, with or without
00175  * modification, are permitted provided that the following conditions
00176  * are met:
00177  * 
00178  * 1. Redistributions of source code must retain the above copyright
00179  *    notice, this list of conditions and the following disclaimer.
00180  * 
00181  * 2. Redistributions in binary form must reproduce the above copyright
00182  *    notice, this list of conditions and the following disclaimer in
00183  *    the documentation and/or other materials provided with the
00184  *    distribution.
00185  * 
00186  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00187  *    and "Vovida Open Communication Application Library (VOCAL)" must
00188  *    not be used to endorse or promote products derived from this
00189  *    software without prior written permission. For written
00190  *    permission, please contact vocal@vovida.org.
00191  *
00192  * 4. Products derived from this software may not be called "VOCAL", nor
00193  *    may "VOCAL" appear in their name, without prior written
00194  *    permission of Vovida Networks, Inc.
00195  * 
00196  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00197  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00198  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00199  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00200  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00201  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00202  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00203  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00204  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00205  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00206  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00207  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00208  * DAMAGE.
00209  * 
00210  * ====================================================================
00211  * 
00212  * This software consists of voluntary contributions made by Vovida
00213  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00214  * Inc.  For more information on Vovida Networks, Inc., please see
00215  * <http://www.vovida.org/>.
00216  *
00217  * vi: set shiftwidth=3 expandtab:
00218  */