xrootd
XrdOucCallBack.hh
Go to the documentation of this file.
1 #ifndef __XRDOUCCALLBACK__HH_
2 #define __XRDOUCCALLBACK__HH_
3 /******************************************************************************/
4 /* */
5 /* X r d O u c C a l l B a c k . h h */
6 /* */
7 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
8 /* All Rights Reserved */
9 /* Produced by Andrew Hanushevsky for Stanford University under contract */
10 /* DE-AC02-76-SFO0515 with the Department of Energy */
11 /* */
12 /* This file is part of the XRootD software suite. */
13 /* */
14 /* XRootD is free software: you can redistribute it and/or modify it under */
15 /* the terms of the GNU Lesser General Public License as published by the */
16 /* Free Software Foundation, either version 3 of the License, or (at your */
17 /* option) any later version. */
18 /* */
19 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
20 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
21 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
22 /* License for more details. */
23 /* */
24 /* You should have received a copy of the GNU Lesser General Public License */
25 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
26 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
27 /* */
28 /* The copyright holder's institutional names and contributor's names may not */
29 /* be used to endorse or promote products derived from this software without */
30 /* specific prior written permission of the institution or contributor. */
31 /******************************************************************************/
32 
33 #include "XrdOuc/XrdOucErrInfo.hh"
34 #include "XrdSys/XrdSysPthread.hh"
35 
36 /* The XrdOucCallBack object encapsulates the vagaries of handling callbacks
37  in the xrootd framework; where callbacks are allowed. Once a callback is
38  successfully established using Init() this object should not be deleted
39  until Reply() of Cancel() is called. The destructor automatically calls
40  Cancel() is a callback is outstanding. The object may be reused after
41  Cancel() or Reply is called. See warnings on Init() and Cancel().
42 
43  This object is not MT-safe and must be used in a serial fashion.
44 */
45 
46 class XrdOucCallBack : public XrdOucEICB
47 {
48 public:
49 
50 /* Allowed() tell you whether or not am XrdOucErrInfo object has been setup to
51  allow callbacks. You should test this before assuming you can use
52  the object to effect a callback.
53 
54  Returns: True - if a callback is allowed.
55  False - otherwise.
56 */
57 static int Allowed(XrdOucErrInfo *eInfo) {return eInfo->getErrCB() != 0;}
58 
59 /* Cancel() cancels the callback. If no callback is oustanding, it does
60  nothing. Otherwise, the associated endpoint is told to retry
61  whatever operation caused the callback to be setup. Warning,
62  calling Cancel() or deleting this object after calling Init()
63  but not effecting a callback response will cause the calling
64  thread to hang!
65 */
66  void Cancel();
67 
68 /* Init() sets up a call back using the provided XrdOucErrInfo object.
69  You must successfully call Init() before calling Reply()!
70  Warning, once you cann Init() you *must* effect a callback
71  response; otherwise, it is likely a subsequent thread using
72  this object will hang!
73 
74  Returns: True - if a callback was set up.
75  False - otherwise (i.e., object does not allow callbacks).
76 */
77  int Init(XrdOucErrInfo *eInfo);
78 
79 /* Reply() sends the specified results to the endpoint associated with the
80  callback esablished by Init(). The parameters are:
81  retVal - The value you would have synchrnously returned.
82  eValue - The numeric value that would have been returned in the
83  original XrdOucErrInfo object.
84  eText - The character string that would have been returned in the
85  original XrdOucErrInfo object.
86  Path - Optional path related to the reply. It is passed to the
87  callback effector and is used for tracing & monitoring.
88 
89  Returns: True - if a callback was initiated.
90  False - callback failed; likely Init() was not successfully called.
91 */
92  int Reply(int retVal, int eValue, const char *eText,
93  const char *Path=0);
94 
95  XrdOucCallBack() : Next(0), cbSync(0), cbArg(0), cbObj(0) {}
97 
98 // The following is a handy pointer to allow for linking these objects together
99 //
101 
102 private:
103 void Done(int &Result,XrdOucErrInfo *eInfo,const char *Path=0)
104 { (void)Result; (void)eInfo; (void)Path; cbSync.Post();}
105 int Same(unsigned long long arg1, unsigned long long arg2)
106 { (void)arg1; (void)arg2; return 0;}
107 
109 unsigned long long cbArg;
111 char UserID[64];
112 };
113 #endif
XrdSysSemaphore cbSync
Definition: XrdOucCallBack.hh:108
XrdOucCallBack()
Definition: XrdOucCallBack.hh:95
char UserID[64]
Definition: XrdOucCallBack.hh:111
void Post()
Definition: XrdSysPthread.hh:344
Definition: XrdOucErrInfo.hh:97
Definition: XrdSysPthread.hh:332
int Same(unsigned long long arg1, unsigned long long arg2)
Definition: XrdOucCallBack.hh:105
XrdOucCallBack * Next
Definition: XrdOucCallBack.hh:100
Definition: XrdOucCallBack.hh:46
static int Allowed(XrdOucErrInfo *eInfo)
Definition: XrdOucCallBack.hh:57
void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)
Definition: XrdOucCallBack.hh:103
XrdOucEICB * cbObj
Definition: XrdOucCallBack.hh:110
~XrdOucCallBack()
Definition: XrdOucCallBack.hh:96
int Reply(int retVal, int eValue, const char *eText, const char *Path=0)
Definition: XrdOucErrInfo.hh:481
int Init(XrdOucErrInfo *eInfo)
XrdOucEICB * getErrCB()
Definition: XrdOucErrInfo.hh:221
unsigned long long cbArg
Definition: XrdOucCallBack.hh:109