| 303 | } |
| 304 | |
| 305 | void Server::PostXQueueConfig(const httplib::Request &req, httplib::Response &res, const httplib::ContentReader &) |
| 306 | { |
| 307 | size_t pos = 0; |
| 308 | std::string handle_str = req.path_params.at("handle"); |
| 309 | if (handle_str.empty()) { |
| 310 | res.status = httplib::StatusCode::BadRequest_400; |
| 311 | return; |
| 312 | } |
| 313 | XQueueHandle handle = std::stoull(handle_str, &pos, 16); |
| 314 | if (pos != handle_str.length() || handle == 0) { |
| 315 | res.status = httplib::StatusCode::BadRequest_400; |
| 316 | return; |
| 317 | } |
| 318 | |
| 319 | XPreemptLevel level = kPreemptLevelUnknown; |
| 320 | if (req.has_param("level")) { |
| 321 | size_t level_pos = 0; |
| 322 | std::string level_str = req.get_param_value("level"); |
| 323 | level = (XPreemptLevel)std::stoi(level_str, &level_pos, 10); |
| 324 | if (level_pos != level_str.length() || level <= kPreemptLevelUnknown || level >= kPreemptLevelMax) { |
| 325 | res.status = httplib::StatusCode::BadRequest_400; |
| 326 | res.set_content("{\"error\": \"invalid level\"}", "application/json"); |
| 327 | return; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | int64_t threshold = -1; |
| 332 | if (req.has_param("threshold")) { |
| 333 | size_t threshold_pos = 0; |
| 334 | std::string threshold_str = req.get_param_value("threshold"); |
| 335 | threshold = std::stoll(threshold_str, &threshold_pos, 10); |
| 336 | if (threshold_pos != threshold_str.length() || threshold <= 0) { |
| 337 | res.status = httplib::StatusCode::BadRequest_400; |
| 338 | res.set_content("{\"error\": \"invalid command threshold\"}", "application/json"); |
| 339 | return; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | int64_t batch_size = -1; |
| 344 | if (req.has_param("batch_size")) { |
| 345 | size_t sync_pos = 0; |
| 346 | std::string sync_str = req.get_param_value("batch_size"); |
| 347 | batch_size = std::stoll(sync_str, &sync_pos, 10); |
| 348 | if (sync_pos != sync_str.length() || batch_size <= 0) { |
| 349 | res.status = httplib::StatusCode::BadRequest_400; |
| 350 | res.set_content("{\"error\": \"invalid command batch size\"}", "application/json"); |
| 351 | return; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | XQueueStatus status; |
| 356 | if (!GetXQueueStatus(handle, status)) { |
| 357 | res.status = httplib::StatusCode::NotFound_404; |
| 358 | res.set_content("{\"error\": \"XQueue not found\"}", "application/json"); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | if (level != kPreemptLevelUnknown) status.level = level; |
nothing calls this directly
no test coverage detected