reSIProcate/stack  9694
TuSelector.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_TuSelector_HXX)
00002 #define RESIP_TuSelector_HXX 
00003 
00004 #include "resip/stack/SipMessage.hxx"
00005 #include "resip/stack/StatisticsMessage.hxx"
00006 #include "resip/stack/TransactionUserMessage.hxx"
00007 #include "rutil/TimeLimitFifo.hxx"
00008 #include "rutil/Fifo.hxx"
00009 
00010 namespace resip
00011 {
00012 
00013 class ConnectionTerminated;
00014 class KeepAlivePong;
00015 class Message;
00016 class TransactionUser;
00017 class AsyncProcessHandler;
00018 
00019 class TuSelector
00020 {
00021    public:
00022       TuSelector(TimeLimitFifo<Message>& fallBackFifo);
00023       ~TuSelector();
00024       
00025       void add(Message* msg, TimeLimitFifo<Message>::DepthUsage usage);
00026       void add(ConnectionTerminated* term);
00027       void add(KeepAlivePong* pong);
00028       
00029       unsigned int size() const;      
00030       bool wouldAccept(TimeLimitFifo<Message>::DepthUsage usage) const;
00031   
00032       TransactionUser* selectTransactionUser(const SipMessage& msg);
00033       bool haveTransactionUsers() const { return mTuSelectorMode; }
00034       void registerTransactionUser(TransactionUser&);
00035       void requestTransactionUserShutdown(TransactionUser&);
00036       void unregisterTransactionUser(TransactionUser&);
00037       void process();
00038       unsigned int getTimeTillNextProcessMS();
00039       bool isTransactionUserStillRegistered(const TransactionUser* ) const;
00040 
00041       // Handler is notified when a message is posted
00042       // to the default application receive queue.
00043       void setFallbackPostNotify(AsyncProcessHandler *handler);
00044       
00045       void setCongestionManager(CongestionManager* manager);
00046       CongestionManager::RejectionBehavior getRejectionBehavior(TransactionUser* tu) const;
00047       unsigned int getExpectedWait(TransactionUser* tu) const;
00048 
00049    private:
00050       void remove(TransactionUser* tu);
00051       void markShuttingDown(TransactionUser* tu);
00052       bool exists(TransactionUser* tu);
00053 
00054    private:
00055       struct Item
00056       {
00057             Item(TransactionUser* ptu) : tu(ptu), shuttingDown(false) {}
00058             TransactionUser* tu;
00059             bool shuttingDown;
00060             bool operator==(const Item& rhs) { return tu == rhs.tu; }
00061       };
00062       
00063       typedef std::vector<Item> TuList;
00064       TuList mTuList;
00065       TimeLimitFifo<Message>& mFallBackFifo;
00066       CongestionManager* mCongestionManager;
00067       AsyncProcessHandler *mFallbackPostNotify;
00068       Fifo<TransactionUserMessage> mShutdownFifo;
00069       bool mTuSelectorMode;
00070       StatisticsMessage::Payload mStatsPayload;
00071 };
00072 }
00073 
00074 #endif
00075 
00076 /* ====================================================================
00077  * The Vovida Software License, Version 1.0 
00078  * 
00079  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00080  * 
00081  * Redistribution and use in source and binary forms, with or without
00082  * modification, are permitted provided that the following conditions
00083  * are met:
00084  * 
00085  * 1. Redistributions of source code must retain the above copyright
00086  *    notice, this list of conditions and the following disclaimer.
00087  * 
00088  * 2. Redistributions in binary form must reproduce the above copyright
00089  *    notice, this list of conditions and the following disclaimer in
00090  *    the documentation and/or other materials provided with the
00091  *    distribution.
00092  * 
00093  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00094  *    and "Vovida Open Communication Application Library (VOCAL)" must
00095  *    not be used to endorse or promote products derived from this
00096  *    software without prior written permission. For written
00097  *    permission, please contact vocal@vovida.org.
00098  *
00099  * 4. Products derived from this software may not be called "VOCAL", nor
00100  *    may "VOCAL" appear in their name, without prior written
00101  *    permission of Vovida Networks, Inc.
00102  * 
00103  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00104  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00105  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00106  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00107  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00108  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00109  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00110  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00111  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00112  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00113  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00114  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00115  * DAMAGE.
00116  * 
00117  * ====================================================================
00118  * 
00119  * This software consists of voluntary contributions made by Vovida
00120  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00121  * Inc.  For more information on Vovida Networks, Inc., please see
00122  * <http://www.vovida.org/>.
00123  *
00124  */