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 #include "XrdSys/XrdSysPthread.hh" 00027 00028 namespace XrdCl 00029 { 00030 class Message; 00031 class OutgoingMsgHandler; 00032 00033 //---------------------------------------------------------------------------- 00035 //---------------------------------------------------------------------------- 00036 class OutQueue 00037 { 00038 public: 00039 //------------------------------------------------------------------------ 00049 //------------------------------------------------------------------------ 00050 void PushBack( Message *msg, 00051 OutgoingMsgHandler *handler, 00052 time_t expires, 00053 bool stateful ); 00054 00055 //------------------------------------------------------------------------ 00065 //------------------------------------------------------------------------ 00066 void PushFront( Message *msg, 00067 OutgoingMsgHandler *handler, 00068 time_t expires, 00069 bool stateful ); 00070 00071 //------------------------------------------------------------------------ 00075 //------------------------------------------------------------------------ 00076 Message *PopMessage( OutgoingMsgHandler *&handler, 00077 time_t &expires, 00078 bool &stateful ); 00079 00080 //------------------------------------------------------------------------ 00082 //------------------------------------------------------------------------ 00083 void PopFront(); 00084 00085 //------------------------------------------------------------------------ 00087 //------------------------------------------------------------------------ 00088 void Report( Status status ); 00089 00090 //------------------------------------------------------------------------ 00092 //------------------------------------------------------------------------ 00093 bool IsEmpty() const 00094 { 00095 return pMessages.empty(); 00096 } 00097 00098 //------------------------------------------------------------------------ 00099 // Return the size of the queue 00100 //------------------------------------------------------------------------ 00101 uint64_t GetSize() const 00102 { 00103 return pMessages.size(); 00104 } 00105 00106 //------------------------------------------------------------------------ 00108 //------------------------------------------------------------------------ 00109 uint64_t GetSizeStateless() const; 00110 00111 //------------------------------------------------------------------------ 00117 //------------------------------------------------------------------------ 00118 void GrabExpired( OutQueue &queue, time_t exp = 0 ); 00119 00120 //------------------------------------------------------------------------ 00125 //------------------------------------------------------------------------ 00126 void GrabStateful( OutQueue &queue ); 00127 00128 //------------------------------------------------------------------------ 00132 //------------------------------------------------------------------------ 00133 void GrabItems( OutQueue &queue ); 00134 00135 private: 00136 //------------------------------------------------------------------------ 00137 // Helper struct holding all the message data 00138 //------------------------------------------------------------------------ 00139 struct MsgHelper 00140 { 00141 MsgHelper( Message *m, OutgoingMsgHandler *h, time_t r, bool s ): 00142 msg( m ), handler( h ), expires( r ), stateful( s ) {} 00143 00144 Message *msg; 00145 OutgoingMsgHandler *handler; 00146 time_t expires; 00147 bool stateful; 00148 }; 00149 00150 typedef std::list<MsgHelper> MessageList; 00151 MessageList pMessages; 00152 mutable XrdSysMutex pMutex; 00153 00154 }; 00155 } 00156 00157 #endif // __XRD_CL_OUT_QUEUE_HH__