|
||||
File indexing completed on 2025-01-18 10:15:41
0001 #ifndef __XRDOUCCALLBACK__HH_ 0002 #define __XRDOUCCALLBACK__HH_ 0003 /******************************************************************************/ 0004 /* */ 0005 /* X r d O u c C a l l B a c k . h h */ 0006 /* */ 0007 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */ 0008 /* All Rights Reserved */ 0009 /* Produced by Andrew Hanushevsky for Stanford University under contract */ 0010 /* DE-AC02-76-SFO0515 with the Department of Energy */ 0011 /* */ 0012 /* This file is part of the XRootD software suite. */ 0013 /* */ 0014 /* XRootD is free software: you can redistribute it and/or modify it under */ 0015 /* the terms of the GNU Lesser General Public License as published by the */ 0016 /* Free Software Foundation, either version 3 of the License, or (at your */ 0017 /* option) any later version. */ 0018 /* */ 0019 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */ 0020 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */ 0021 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */ 0022 /* License for more details. */ 0023 /* */ 0024 /* You should have received a copy of the GNU Lesser General Public License */ 0025 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */ 0026 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */ 0027 /* */ 0028 /* The copyright holder's institutional names and contributor's names may not */ 0029 /* be used to endorse or promote products derived from this software without */ 0030 /* specific prior written permission of the institution or contributor. */ 0031 /******************************************************************************/ 0032 0033 #include "XrdOuc/XrdOucErrInfo.hh" 0034 #include "XrdSys/XrdSysPthread.hh" 0035 0036 /* The XrdOucCallBack object encapsulates the vagaries of handling callbacks 0037 in the xrootd framework; where callbacks are allowed. Once a callback is 0038 successfully established using Init() this object should not be deleted 0039 until Reply() of Cancel() is called. The destructor automatically calls 0040 Cancel() is a callback is outstanding. The object may be reused after 0041 Cancel() or Reply is called. See warnings on Init() and Cancel(). 0042 0043 This object is not MT-safe and must be used in a serial fashion. 0044 */ 0045 0046 class XrdOucCallBack : public XrdOucEICB 0047 { 0048 public: 0049 0050 /* Allowed() tell you whether or not am XrdOucErrInfo object has been setup to 0051 allow callbacks. You should test this before assuming you can use 0052 the object to effect a callback. 0053 0054 Returns: True - if a callback is allowed. 0055 False - otherwise. 0056 */ 0057 static int Allowed(XrdOucErrInfo *eInfo) {return eInfo->getErrCB() != 0;} 0058 0059 /* Cancel() cancels the callback. If no callback is oustanding, it does 0060 nothing. Otherwise, the associated endpoint is told to retry 0061 whatever operation caused the callback to be setup. Warning, 0062 calling Cancel() or deleting this object after calling Init() 0063 but not effecting a callback response will cause the calling 0064 thread to hang! 0065 */ 0066 void Cancel(); 0067 0068 /* Init() sets up a call back using the provided XrdOucErrInfo object. 0069 You must successfully call Init() before calling Reply()! 0070 Warning, once you cann Init() you *must* effect a callback 0071 response; otherwise, it is likely a subsequent thread using 0072 this object will hang! 0073 0074 Returns: True - if a callback was set up. 0075 False - otherwise (i.e., object does not allow callbacks). 0076 */ 0077 int Init(XrdOucErrInfo *eInfo); 0078 0079 /* Reply() sends the specified results to the endpoint associated with the 0080 callback esablished by Init(). The parameters are: 0081 retVal - The value you would have synchrnously returned. 0082 eValue - The numeric value that would have been returned in the 0083 original XrdOucErrInfo object. 0084 eText - The character string that would have been returned in the 0085 original XrdOucErrInfo object. 0086 Path - Optional path related to the reply. It is passed to the 0087 callback effector and is used for tracing & monitoring. 0088 0089 Returns: True - if a callback was initiated. 0090 False - callback failed; likely Init() was not successfully called. 0091 */ 0092 int Reply(int retVal, int eValue, const char *eText, 0093 const char *Path=0); 0094 0095 XrdOucCallBack() : Next(0), cbSync(0), cbArg(0), cbObj(0) {} 0096 ~XrdOucCallBack() {if (cbObj) Cancel();} 0097 0098 // The following is a handy pointer to allow for linking these objects together 0099 // 0100 XrdOucCallBack *Next; 0101 0102 private: 0103 void Done(int &Result,XrdOucErrInfo *eInfo,const char *Path=0) 0104 { (void)Result; (void)eInfo; (void)Path; cbSync.Post();} 0105 int Same(unsigned long long arg1, unsigned long long arg2) 0106 { (void)arg1; (void)arg2; return 0;} 0107 0108 XrdSysSemaphore cbSync; 0109 unsigned long long cbArg; 0110 XrdOucEICB *cbObj; 0111 char UserID[64]; 0112 }; 0113 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |