XRootD
XrdOucCallBack.cc
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d O u c C a l l B a c k . c c */
4 /* */
5 /* (c) 2011 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Andrew Hanushevsky for Stanford University under contract */
8 /* DE-AC02-76-SFO0515 with the Department of Energy */
9 /* */
10 /* This file is part of the XRootD software suite. */
11 /* */
12 /* XRootD is free software: you can redistribute it and/or modify it under */
13 /* the terms of the GNU Lesser General Public License as published by the */
14 /* Free Software Foundation, either version 3 of the License, or (at your */
15 /* option) any later version. */
16 /* */
17 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
18 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
20 /* License for more details. */
21 /* */
22 /* You should have received a copy of the GNU Lesser General Public License */
23 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
24 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
25 /* */
26 /* The copyright holder's institutional names and contributor's names may not */
27 /* be used to endorse or promote products derived from this software without */
28 /* specific prior written permission of the institution or contributor. */
29 /******************************************************************************/
30 
31 #include "XrdOuc/XrdOucCallBack.hh"
32 #include "XrdSys/XrdSysPlatform.hh"
33 
34 /******************************************************************************/
35 /* C a n c e l */
36 /******************************************************************************/
37 
39 {
40 
41 // If a callback is outstanding, send a reply indicating that the operation
42 // should be retried.
43 //
44  if (cbObj) Reply(1, 0, "");
45 }
46 
47 /******************************************************************************/
48 /* I n i t */
49 /******************************************************************************/
50 
52 {
53  const char *theUser;
54 
55 
56 // Make sure we can do a callback here
57 //
58  if (cbObj || eInfo->getErrCB() == 0) return 0;
59 
60 // Copy relevant data
61 //
62  if ((theUser = eInfo->getErrUser())) strlcpy(UserID,theUser,sizeof(UserID));
63  else strcpy(UserID, "???");
64  cbObj = eInfo->getErrCB(cbArg);
65 
66 // Now set the callback object in the input ErrInfo object to be ours so
67 // that we can make sure that the wait for callback response was sent
68 // before we actually effect a reply.
69 //
70  eInfo->setErrCB(this, cbArg);
71 
72 // All done
73 //
74  return 1;
75 }
76 
77 /******************************************************************************/
78 /* R e p l y */
79 /******************************************************************************/
80 
81 int XrdOucCallBack::Reply(int retVal, int eValue, const char *eText,
82  const char *Path)
83 {
84  XrdOucErrInfo cbInfo(UserID, this, cbArg);
85  XrdOucEICB *objCB;
86 
87 // Verify that we can actually do a callback
88 //
89  if (!(objCB = cbObj)) return 0;
90  cbObj = 0;
91 
92 // Wait for the semaphore to make sure the "wait for callback" response was
93 // actually sent to preserve time causality.
94 //
95  cbSync.Wait();
96 
97 // Send the reply using the constructed ErrInfo object and then wait until we
98 // know that the response was actually sent to allow this object to be deleted.
99 //
100  cbInfo.setErrInfo(eValue, (eText ? eText : ""));
101  objCB->Done(retVal, &cbInfo, Path);
102  cbSync.Wait();
103 
104 // All done
105 //
106  return 1;
107 }
XrdOucString Path
size_t strlcpy(char *dst, const char *src, size_t sz)
int Reply(int retVal, int eValue, const char *eText, const char *Path=0)
int Init(XrdOucErrInfo *eInfo)
virtual void Done(int &Result, XrdOucErrInfo *eInfo, const char *Path=0)=0
XrdOucEICB * getErrCB()
void setErrCB(XrdOucEICB *cb, unsigned long long cbarg=0)
int setErrInfo(int code, const char *emsg)
const char * getErrUser()