xrootd
XrdClOutQueue.hh
Go to the documentation of this file.
00001 //------------------------------------------------------------------------------
00002 // Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
00003 // Author: Lukasz Janyst <ljanyst@cern.ch>
00004 //------------------------------------------------------------------------------
00005 // XRootD is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU Lesser General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // XRootD is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
00017 //------------------------------------------------------------------------------
00018 
00019 #ifndef __XRD_CL_OUT_QUEUE_HH__
00020 #define __XRD_CL_OUT_QUEUE_HH__
00021 
00022 #include <list>
00023 #include <utility>
00024 #include "XrdCl/XrdClStatus.hh"
00025 
00026 namespace XrdCl
00027 {
00028   class Message;
00029   class OutgoingMsgHandler;
00030 
00031   //----------------------------------------------------------------------------
00033   //----------------------------------------------------------------------------
00034   class OutQueue
00035   {
00036     public:
00037       //------------------------------------------------------------------------
00047       //------------------------------------------------------------------------
00048       void PushBack( Message              *msg,
00049                      OutgoingMsgHandler   *handler,
00050                      time_t                expires,
00051                      bool                  stateful );
00052 
00053       //------------------------------------------------------------------------
00063       //------------------------------------------------------------------------
00064       void PushFront( Message              *msg,
00065                       OutgoingMsgHandler   *handler,
00066                       time_t                expires,
00067                       bool                  stateful );
00068 
00069       //------------------------------------------------------------------------
00073       //------------------------------------------------------------------------
00074       Message *PopMessage( OutgoingMsgHandler   *&handler,
00075                            time_t                &expires,
00076                            bool                  &stateful );
00077 
00078       //------------------------------------------------------------------------
00080       //------------------------------------------------------------------------
00081       void PopFront();
00082 
00083       //------------------------------------------------------------------------
00085       //------------------------------------------------------------------------
00086       void Report( Status status );
00087 
00088       //------------------------------------------------------------------------
00090       //------------------------------------------------------------------------
00091       bool IsEmpty() const
00092       {
00093         return pMessages.empty();
00094       }
00095 
00096       //------------------------------------------------------------------------
00097       // Return the size of the queue
00098       //------------------------------------------------------------------------
00099       uint64_t GetSize() const
00100       {
00101         return pMessages.size();
00102       }
00103 
00104       //------------------------------------------------------------------------
00106       //------------------------------------------------------------------------
00107       uint64_t GetSizeStateless() const;
00108 
00109       //------------------------------------------------------------------------
00115       //------------------------------------------------------------------------
00116       void GrabExpired( OutQueue &queue, time_t exp = 0 );
00117 
00118       //------------------------------------------------------------------------
00123       //------------------------------------------------------------------------
00124       void GrabStateful( OutQueue &queue );
00125 
00126       //------------------------------------------------------------------------
00130       //------------------------------------------------------------------------
00131       void GrabItems( OutQueue &queue );
00132 
00133     private:
00134       //------------------------------------------------------------------------
00135       // Helper struct holding all the message data
00136       //------------------------------------------------------------------------
00137       struct MsgHelper
00138       {
00139         MsgHelper( Message *m, OutgoingMsgHandler *h, time_t r, bool s ):
00140           msg( m ), handler( h ), expires( r ), stateful( s ) {}
00141 
00142         Message              *msg;
00143         OutgoingMsgHandler   *handler;
00144         time_t                expires;
00145         bool                  stateful;
00146       };
00147 
00148       typedef std::list<MsgHelper> MessageList;
00149       MessageList pMessages;
00150   };
00151 }
00152 
00153 #endif // __XRD_CL_OUT_QUEUE_HH__