00001 //------------------------------------------------------------------------------ 00002 // Copyright (c) 2011-2014 by European Organization for Nuclear Research (CERN) 00003 // Author: Lukasz Janyst <ljanyst@cern.ch> 00004 //------------------------------------------------------------------------------ 00005 // This file is part of the XRootD software suite. 00006 // 00007 // XRootD is free software: you can redistribute it and/or modify 00008 // it under the terms of the GNU Lesser General Public License as published by 00009 // the Free Software Foundation, either version 3 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // XRootD is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU Lesser General Public License 00018 // along with XRootD. If not, see <http://www.gnu.org/licenses/>. 00019 // 00020 // In applying this licence, CERN does not waive the privileges and immunities 00021 // granted to it by virtue of its status as an Intergovernmental Organization 00022 // or submit itself to any jurisdiction. 00023 //------------------------------------------------------------------------------ 00024 00025 #ifndef __XRD_CL_POST_MASTER_INTERFACES_HH__ 00026 #define __XRD_CL_POST_MASTER_INTERFACES_HH__ 00027 00028 #include <stdint.h> 00029 #include <ctime> 00030 00031 #include "XrdCl/XrdClStatus.hh" 00032 #include "XrdCl/XrdClAnyObject.hh" 00033 #include "XrdCl/XrdClURL.hh" 00034 00035 class XrdNetAddr; 00036 00037 namespace XrdCl 00038 { 00039 class Channel; 00040 class Message; 00041 class URL; 00042 00043 //---------------------------------------------------------------------------- 00045 //---------------------------------------------------------------------------- 00046 class MessageFilter 00047 { 00048 public: 00049 virtual ~MessageFilter() {} 00050 00051 //------------------------------------------------------------------------ 00054 //------------------------------------------------------------------------ 00055 virtual bool Filter( const Message *msg ) = 0; 00056 }; 00057 00058 //---------------------------------------------------------------------------- 00060 //---------------------------------------------------------------------------- 00061 class IncomingMsgHandler 00062 { 00063 public: 00064 //------------------------------------------------------------------------ 00066 //------------------------------------------------------------------------ 00067 enum Action 00068 { 00069 Take = 0x0001, 00070 Ignore = 0x0002, 00071 RemoveHandler = 0x0004, 00072 00073 Raw = 0x0008, 00074 00075 00076 NoProcess = 0x0010 00077 00078 00079 }; 00080 00081 //------------------------------------------------------------------------ 00083 //------------------------------------------------------------------------ 00084 enum StreamEvent 00085 { 00086 Ready = 1, 00087 Broken = 2, 00088 Timeout = 3, 00089 FatalError = 4 00090 }; 00091 00092 //------------------------------------------------------------------------ 00094 //------------------------------------------------------------------------ 00095 00096 virtual ~IncomingMsgHandler() {} 00097 00098 //------------------------------------------------------------------------ 00104 //------------------------------------------------------------------------ 00105 virtual uint16_t Examine( Message *msg ) = 0; 00106 00107 //------------------------------------------------------------------------ 00111 //------------------------------------------------------------------------ 00112 virtual void Process( Message *msg ) { (void)msg; }; 00113 00114 //------------------------------------------------------------------------ 00124 //------------------------------------------------------------------------ 00125 virtual Status ReadMessageBody( Message *msg, 00126 int socket, 00127 uint32_t &bytesRead ) 00128 { 00129 (void)msg; (void)socket; (void)bytesRead; 00130 return Status( stOK, suDone ); 00131 }; 00132 00133 //------------------------------------------------------------------------ 00140 //------------------------------------------------------------------------ 00141 virtual uint8_t OnStreamEvent( StreamEvent event, 00142 uint16_t streamNum, 00143 Status status ) 00144 { 00145 (void)event; (void)streamNum; (void)status; 00146 return 0; 00147 }; 00148 }; 00149 00150 //---------------------------------------------------------------------------- 00152 //---------------------------------------------------------------------------- 00153 class OutgoingMsgHandler 00154 { 00155 public: 00156 virtual ~OutgoingMsgHandler() {} 00157 00158 //------------------------------------------------------------------------ 00160 //------------------------------------------------------------------------ 00161 virtual void OnStatusReady( const Message *message, 00162 Status status ) = 0; 00163 00164 //------------------------------------------------------------------------ 00172 //------------------------------------------------------------------------ 00173 virtual void OnReadyToSend( Message *msg, uint16_t streamNum ) 00174 { 00175 (void)msg; (void)streamNum; 00176 }; 00177 00178 //------------------------------------------------------------------------ 00182 //------------------------------------------------------------------------ 00183 virtual bool IsRaw() const { return false; } 00184 00185 //------------------------------------------------------------------------ 00194 //------------------------------------------------------------------------ 00195 virtual Status WriteMessageBody( int socket, 00196 uint32_t &bytesRead ) 00197 { 00198 (void)socket; (void)bytesRead; 00199 return Status(); 00200 } 00201 }; 00202 00203 //---------------------------------------------------------------------------- 00205 //---------------------------------------------------------------------------- 00206 class ChannelEventHandler 00207 { 00208 public: 00209 //------------------------------------------------------------------------ 00211 //------------------------------------------------------------------------ 00212 enum ChannelEvent 00213 { 00214 StreamReady = 1, 00215 StreamBroken = 2, 00216 FatalError = 4 00217 }; 00218 00219 //------------------------------------------------------------------------ 00221 //------------------------------------------------------------------------ 00222 virtual ~ChannelEventHandler() {}; 00223 00224 //------------------------------------------------------------------------ 00232 //------------------------------------------------------------------------ 00233 virtual bool OnChannelEvent( ChannelEvent event, 00234 Status status, 00235 uint16_t stream ) = 0; 00236 }; 00237 00238 //---------------------------------------------------------------------------- 00240 //---------------------------------------------------------------------------- 00241 00242 struct HandShakeData 00243 { 00244 //-------------------------------------------------------------------------- 00246 //-------------------------------------------------------------------------- 00247 HandShakeData( const URL *addr, uint16_t stream, uint16_t subStream ): 00248 step(0), out(0), in(0), url(addr), streamId(stream), 00249 subStreamId( subStream ), startTime( time(0) ), serverAddr(0) 00250 {} 00251 uint16_t step; 00252 Message *out; 00253 Message *in; 00254 const URL *url; 00255 uint16_t streamId; 00256 uint16_t subStreamId; 00257 time_t startTime; 00258 const 00259 XrdNetAddr *serverAddr; 00260 std::string clientName; 00261 std::string streamName; 00262 }; 00263 00264 //---------------------------------------------------------------------------- 00267 //---------------------------------------------------------------------------- 00268 struct PathID 00269 { 00270 PathID( uint16_t u = 0, uint16_t d = 0 ): up(u), down(d) {} 00271 uint16_t up; 00272 uint16_t down; 00273 }; 00274 00275 //---------------------------------------------------------------------------- 00278 //---------------------------------------------------------------------------- 00279 struct TransportQuery 00280 { 00281 static const uint16_t Name = 1; 00282 static const uint16_t Auth = 2; 00283 }; 00284 00285 //---------------------------------------------------------------------------- 00287 //---------------------------------------------------------------------------- 00288 class TransportHandler 00289 { 00290 public: 00291 00292 //------------------------------------------------------------------------ 00294 //------------------------------------------------------------------------ 00295 enum StreamAction 00296 { 00297 NoAction = 0x0000, 00298 DigestMsg = 0x0001, 00299 00300 AbortStream = 0x0002, 00301 00302 00303 CloseStream = 0x0004, 00304 00305 ResumeStream = 0x0008, 00306 00307 HoldStream = 0x0010 00308 }; 00309 00310 00311 virtual ~TransportHandler() {} 00312 00313 //------------------------------------------------------------------------ 00324 //------------------------------------------------------------------------ 00325 virtual Status GetHeader( Message *message, int socket ) = 0; 00326 00327 //------------------------------------------------------------------------ 00336 //------------------------------------------------------------------------ 00337 virtual Status GetBody( Message *message, int socket ) = 0; 00338 00339 //------------------------------------------------------------------------ 00341 //------------------------------------------------------------------------ 00342 virtual void InitializeChannel( AnyObject &channelData ) = 0; 00343 00344 //------------------------------------------------------------------------ 00346 //------------------------------------------------------------------------ 00347 virtual void FinalizeChannel( AnyObject &channelData ) = 0; 00348 00349 //------------------------------------------------------------------------ 00351 //------------------------------------------------------------------------ 00352 virtual Status HandShake( HandShakeData *handShakeData, 00353 AnyObject &channelData ) = 0; 00354 00355 //------------------------------------------------------------------------ 00357 //------------------------------------------------------------------------ 00358 virtual bool IsStreamTTLElapsed( time_t inactiveTime, 00359 uint16_t streamId, 00360 AnyObject &channelData ) = 0; 00361 00362 //------------------------------------------------------------------------ 00365 //------------------------------------------------------------------------ 00366 virtual Status IsStreamBroken( time_t inactiveTime, 00367 uint16_t streamId, 00368 AnyObject &channelData ) = 0; 00369 00370 //------------------------------------------------------------------------ 00376 //------------------------------------------------------------------------ 00377 virtual PathID Multiplex( Message *msg, 00378 AnyObject &channelData, 00379 PathID *hint = 0 ) = 0; 00380 00381 //------------------------------------------------------------------------ 00387 //------------------------------------------------------------------------ 00388 virtual PathID MultiplexSubStream( Message *msg, 00389 uint16_t streamId, 00390 AnyObject &channelData, 00391 PathID *hint = 0 ) = 0; 00392 00393 //------------------------------------------------------------------------ 00395 //------------------------------------------------------------------------ 00396 virtual uint16_t StreamNumber( AnyObject &channelData ) = 0; 00397 00398 //------------------------------------------------------------------------ 00400 //------------------------------------------------------------------------ 00401 virtual uint16_t SubStreamNumber( AnyObject &channelData ) = 0; 00402 00403 //------------------------------------------------------------------------ 00405 //------------------------------------------------------------------------ 00406 virtual void Disconnect( AnyObject &channelData, 00407 uint16_t streamId, 00408 uint16_t subStreamId ) = 0; 00409 00410 //------------------------------------------------------------------------ 00412 //------------------------------------------------------------------------ 00413 virtual Status Query( uint16_t query, 00414 AnyObject &result, 00415 AnyObject &channelData ) = 0; 00416 00417 //------------------------------------------------------------------------ 00419 //------------------------------------------------------------------------ 00420 virtual uint32_t MessageReceived( Message *msg, 00421 uint16_t streamId, 00422 uint16_t subStream, 00423 AnyObject &channelData ) = 0; 00424 00425 //------------------------------------------------------------------------ 00427 //------------------------------------------------------------------------ 00428 virtual void MessageSent( Message *msg, 00429 uint16_t streamId, 00430 uint16_t subStream, 00431 uint32_t bytesSent, 00432 AnyObject &channelData ) = 0; 00433 }; 00434 } 00435 00436 #endif // __XRD_CL_POST_MASTER_INTERFACES_HH__