Skip to content

Commit

Permalink
[XrdCl] Support HostList in lambda completion handlers.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichal committed Apr 26, 2022
1 parent 909a0ed commit 0395fbb
Showing 1 changed file with 71 additions and 12 deletions.
83 changes: 71 additions & 12 deletions src/XrdCl/XrdClOperationHandlers.hh
Expand Up @@ -160,30 +160,42 @@ namespace XrdCl
//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda
//! @param func : function, functor or lambda (2 arguments)
//------------------------------------------------------------------------
FunctionWrapper(
std::function<void( XRootDStatus&, Response& )> handleFunction ) :
fun( [handleFunction]( XRootDStatus &s, Response &r, HostList& ){ handleFunction( s, r ); } )
{
}

//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda (3 arguments)
//------------------------------------------------------------------------
FunctionWrapper(
std::function<void( XRootDStatus&, Response&, HostList& )> handleFunction ) :
fun( handleFunction )
{
}

//------------------------------------------------------------------------
//! Callback method.
//------------------------------------------------------------------------
void HandleResponse( XRootDStatus *status, AnyObject *response )
void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList )
{
std::unique_ptr<XRootDStatus> delst( status );
std::unique_ptr<AnyObject> delrsp( response );
std::unique_ptr<HostList> delhl( hostList );
Response *res = GetResponse<Response>( status, response );
fun( *status, *res );
fun( *status, *res, *hostList );
}

private:
//------------------------------------------------------------------------
//! user defined function, functor or lambda
//------------------------------------------------------------------------
std::function<void( XRootDStatus&, Response& )> fun;
std::function<void( XRootDStatus&, Response&, HostList& )> fun;
};

//----------------------------------------------------------------------------
Expand All @@ -199,29 +211,41 @@ namespace XrdCl
//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda
//! @param func : function, functor or lambda (1 argument)
//------------------------------------------------------------------------
FunctionWrapper(
std::function<void( XRootDStatus& )> handleFunction ) :
fun( [handleFunction]( XRootDStatus& s, HostList& ){ handleFunction( s ); } )
{
}

//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda (2 arguments)
//------------------------------------------------------------------------
FunctionWrapper(
std::function<void( XRootDStatus&, HostList& )> handleFunction ) :
fun( handleFunction )
{
}

//------------------------------------------------------------------------
//! Callback method.
//------------------------------------------------------------------------
void HandleResponse( XRootDStatus *status, AnyObject *response )
void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList )
{
std::unique_ptr<XRootDStatus> delst( status );
std::unique_ptr<AnyObject> delrsp( response );
fun( *status );
std::unique_ptr<HostList> delhl( hostList );
fun( *status, *hostList );
}

private:
//------------------------------------------------------------------------
//! user defined function, functor or lambda
//------------------------------------------------------------------------
std::function<void( XRootDStatus& )> fun;
std::function<void( XRootDStatus&, HostList& )> fun;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -315,22 +339,34 @@ namespace XrdCl
//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda
//! @param func : function, functor or lambda (2 arguments)
//------------------------------------------------------------------------
ExOpenFuncWrapper( const Ctx<File> &f,
std::function<void( XRootDStatus&, StatInfo& )> handleFunction ) :
f( f ), fun( [handleFunction]( XRootDStatus &s, StatInfo &i, HostList& ){ handleFunction( s, i ); } )
{
}

//------------------------------------------------------------------------
//! Constructor.
//
//! @param func : function, functor or lambda (3 arguments)
//------------------------------------------------------------------------
ExOpenFuncWrapper( const Ctx<File> &f,
std::function<void( XRootDStatus&, StatInfo&, HostList& )> handleFunction ) :
f( f ), fun( handleFunction )
{
}

//------------------------------------------------------------------------
//! Callback method.
//------------------------------------------------------------------------
void HandleResponse( XRootDStatus *status, AnyObject *response )
void HandleResponseWithHosts( XRootDStatus *status, AnyObject *response, HostList *hostList )
{
delete response;
std::unique_ptr<XRootDStatus> delst( status );
std::unique_ptr<StatInfo> delrsp;
std::unique_ptr<HostList> delhl;
StatInfo *info = nullptr;
if( status->IsOK() )
{
Expand All @@ -339,15 +375,15 @@ namespace XrdCl
}
else
info = &NullRef<StatInfo>::value;
fun( *status, *info );
fun( *status, *info, *hostList );
}

private:
Ctx<File> f;
//------------------------------------------------------------------------
//! user defined function, functor or lambda
//------------------------------------------------------------------------
std::function<void( XRootDStatus&, StatInfo& )> fun;
std::function<void( XRootDStatus&, StatInfo&, HostList& )> fun;
};

//----------------------------------------------------------------------------
Expand Down Expand Up @@ -636,6 +672,18 @@ namespace XrdCl
return new FunctionWrapper<Response>( func );
}

//------------------------------------------------------------------------
//! A factory method
//!
//! @param func : the function/functor/lambda that should be wrapped
//! @return : FunctionWrapper instance
//------------------------------------------------------------------------
inline static ResponseHandler* Create( std::function<void( XRootDStatus&,
Response&, HostList& )> func )
{
return new FunctionWrapper<Response>( func );
}

//------------------------------------------------------------------------
//! A factory method
//!
Expand Down Expand Up @@ -674,6 +722,17 @@ namespace XrdCl
return new FunctionWrapper<void>( func );
}

//------------------------------------------------------------------------
//! A factory method
//!
//! @param func : the function/functor/lambda that should be wrapped
//! @return : SimpleFunctionWrapper instance
//------------------------------------------------------------------------
inline static ResponseHandler* Create( std::function<void( XRootDStatus&, HostList& )> func )
{
return new FunctionWrapper<void>( func );
}

//------------------------------------------------------------------------
//! A factory method
//!
Expand Down

0 comments on commit 0395fbb

Please sign in to comment.