CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
QueryAttrHandler Class Reference
Inheritance diagram for QueryAttrHandler:

Classes

struct  QueryAttrState
 

Public Member Functions

QueryAttrHandleroperator= (const QueryAttrHandler &)=delete
 
 QueryAttrHandler (const QueryAttrHandler &)=delete
 
 ~QueryAttrHandler () override=default
 

Static Public Member Functions

static XrdCl::XRootDStatus query (XrdCl::FileSystem &fs, const std::string &attr, std::chrono::milliseconds timeout, std::string &result)
 

Private Member Functions

void HandleResponse (XrdCl::XRootDStatus *status, XrdCl::AnyObject *response) override
 
 QueryAttrHandler ()
 

Private Attributes

std::weak_ptr< QueryAttrStatem_state
 

Friends

std::unique_ptr< QueryAttrHandlerstd::make_unique ()
 

Detailed Description

A handler for querying a XrdCl::FileSystem object which is safe to be invoked from an XrdCl callback (that is, we don't need an available callback thread to timeout).

Definition at line 82 of file XrdSource.cc.

Constructor & Destructor Documentation

◆ ~QueryAttrHandler()

QueryAttrHandler::~QueryAttrHandler ( )
overridedefault

◆ QueryAttrHandler() [1/2]

QueryAttrHandler::QueryAttrHandler ( const QueryAttrHandler )
delete

◆ QueryAttrHandler() [2/2]

QueryAttrHandler::QueryAttrHandler ( )
inlineprivate

Definition at line 124 of file XrdSource.cc.

124 {}

Member Function Documentation

◆ HandleResponse()

void QueryAttrHandler::HandleResponse ( XrdCl::XRootDStatus *  status,
XrdCl::AnyObject *  response 
)
inlineoverrideprivate

Definition at line 126 of file XrdSource.cc.

126  {
127  // NOTE: we own the status and response pointers.
128  std::unique_ptr<XrdCl::AnyObject> response_mgr;
129  response_mgr.reset(response);
130 
131  // Lock our state information then dispose of our object.
132  auto l_state = m_state.lock();
133  delete this;
134  if (!l_state) {
135  return;
136  }
137 
138  // On function exit, notify any waiting threads.
139  std::unique_ptr<char, std::function<void(char *)>> notify_guard(nullptr,
140  [&](char *) { l_state->m_condvar.notify_all(); });
141 
142  {
143  // On exit from the block, make sure m_status is set; it needs to be set before we notify threads.
144  std::unique_ptr<char, std::function<void(char *)>> exit_guard(nullptr, [&](char *) {
145  if (!l_state->m_status)
146  l_state->m_status = std::make_unique<XrdCl::XRootDStatus>(XrdCl::stError, XrdCl::errInternal);
147  });
148  if (!status) {
149  return;
150  }
151  if (status->IsOK()) {
152  if (!response) {
153  return;
154  }
155  XrdCl::Buffer *buf_ptr;
156  response->Get(buf_ptr);
157  // AnyObject::Set lacks specialization for nullptr
158  response->Set(static_cast<int *>(nullptr));
159  l_state->m_response.reset(buf_ptr);
160  }
161  l_state->m_status.reset(status);
162  }
163  }

References HiBiasedCentrality_cfi::function, mps_update::status, and funct::void.

◆ operator=()

QueryAttrHandler& QueryAttrHandler::operator= ( const QueryAttrHandler )
delete

◆ query()

static XrdCl::XRootDStatus QueryAttrHandler::query ( XrdCl::FileSystem &  fs,
const std::string &  attr,
std::chrono::milliseconds  timeout,
std::string &  result 
)
inlinestatic

Definition at line 90 of file XrdSource.cc.

93  {
94  auto handler = std::make_unique<QueryAttrHandler>();
95  auto l_state = std::make_shared<QueryAttrState>();
96  handler->m_state = l_state;
97  XrdCl::Buffer arg(attr.size());
98  arg.FromString(attr);
99 
100  XrdCl::XRootDStatus st = fs.Query(XrdCl::QueryCode::Config, arg, handler.get());
101  if (!st.IsOK()) {
102  return st;
103  }
104 
105  // Successfully registered the callback; it will always delete itself, so we shouldn't.
106  handler.release();
107 
108  std::unique_lock<std::mutex> guard(l_state->m_mutex);
109  // Wait until some status is available or a timeout.
110  l_state->m_condvar.wait_for(guard, timeout, [&] { return l_state->m_status.get(); });
111 
112  if (l_state->m_status) {
113  if (l_state->m_status->IsOK()) {
114  result = l_state->m_response->ToString();
115  }
116  return *(l_state->m_status);
117  } else { // We had a timeout; construct a reasonable message.
118  return XrdCl::XRootDStatus(
119  XrdCl::stError, XrdCl::errSocketTimeout, 1, "Timeout when waiting for query callback.");
120  }
121  }

References helper::Config, and mps_fire::result.

Referenced by XrdAdaptor::Source::getXrootdSiteFromURL().

Friends And Related Function Documentation

◆ std::make_unique

std::unique_ptr<QueryAttrHandler> std::make_unique ( )
friend

Member Data Documentation

◆ m_state

std::weak_ptr<QueryAttrState> QueryAttrHandler::m_state
private

Definition at line 178 of file XrdSource.cc.

mps_update.status
status
Definition: mps_update.py:68
timeout
Definition: timeout.py:1
cms::cuda::device::unique_ptr
std::unique_ptr< T, impl::DeviceDeleter > unique_ptr
Definition: device_unique_ptr.h:33
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
funct::void
TEMPL(T2) struct Divides void
Definition: Factorize.h:24
funct::arg
A arg
Definition: Factorize.h:31
mps_fire.result
result
Definition: mps_fire.py:311
QueryAttrHandler::m_state
std::weak_ptr< QueryAttrState > m_state
Definition: XrdSource.cc:178
helper.Config
Config
Definition: helper.py:10