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 77 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 119 of file XrdSource.cc.

119 {}

Member Function Documentation

◆ HandleResponse()

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

Definition at line 121 of file XrdSource.cc.

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

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 85 of file XrdSource.cc.

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

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 173 of file XrdSource.cc.

mps_update.status
status
Definition: mps_update.py:69
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:29
funct::arg
A arg
Definition: Factorize.h:36
mps_fire.result
result
Definition: mps_fire.py:303
QueryAttrHandler::m_state
std::weak_ptr< QueryAttrState > m_state
Definition: XrdSource.cc:173
helper.Config
Config
Definition: helper.py:10