| 226 | } |
| 227 | |
| 228 | void Server::GetXQueue(const httplib::Request &req, httplib::Response &res) |
| 229 | { |
| 230 | size_t pos = 0; |
| 231 | std::string handle_str = req.path_params.at("handle"); |
| 232 | if (handle_str.empty()) { |
| 233 | res.status = httplib::StatusCode::BadRequest_400; |
| 234 | return; |
| 235 | } |
| 236 | XQueueHandle handle = std::stoull(handle_str, &pos, 16); |
| 237 | if (pos != handle_str.length() || handle == 0) { |
| 238 | res.status = httplib::StatusCode::BadRequest_400; |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | static std::mutex query_mtx; |
| 243 | std::lock_guard<std::mutex> lock(query_mtx); |
| 244 | |
| 245 | static StatusQuery query(true); // also query process info |
| 246 | query.Reset(); |
| 247 | query.status_.reserve(128); |
| 248 | query.processes_.reserve(128); |
| 249 | |
| 250 | auto e = std::make_unique<XQueueQueryEvent>(handle, &query); |
| 251 | XASSERT(self_chan_->Send(e->Data(), e->Size()), "cannot send XQueue query event"); |
| 252 | query.Wait(); |
| 253 | |
| 254 | if (query.status_.empty() || query.processes_.empty()) { |
| 255 | res.status = httplib::StatusCode::NotFound_404; |
| 256 | return; |
| 257 | } |
| 258 | Json::Value xqueue(Json::objectValue); |
| 259 | XQueueStatusToJson(xqueue, *query.status_[0]); |
| 260 | Json::Value process(Json::objectValue); |
| 261 | process["pid"] = (Json::Int)query.processes_[0]->pid; |
| 262 | process["cmdline"] = query.processes_[0]->cmdline; |
| 263 | |
| 264 | Json::Value response(Json::objectValue); |
| 265 | response["xqueue"] = xqueue; |
| 266 | response["process"] = process; |
| 267 | res.set_content(Json::writeString(json_writer_, response).c_str(), "application/json"); |
| 268 | } |
| 269 | |
| 270 | void Server::GetXQueues(const httplib::Request &, httplib::Response &res) |
| 271 | { |