| 418 | } |
| 419 | |
| 420 | PyObject* |
| 421 | Connection::ping(PyObject* kwargs) |
| 422 | { |
| 423 | std::optional<std::string> report_id; |
| 424 | extract_field<std::optional<std::string>>(kwargs, "report_id", report_id); |
| 425 | std::optional<std::string> bucket_name; |
| 426 | extract_field<std::optional<std::string>>(kwargs, "bucket_name", bucket_name); |
| 427 | std::optional<std::chrono::milliseconds> timeout_ms; |
| 428 | extract_field<std::optional<std::chrono::milliseconds>>(kwargs, "timeout", timeout_ms); |
| 429 | std::set<couchbase::core::service_type> services; |
| 430 | extract_field<std::set<couchbase::core::service_type>>(kwargs, "services", services); |
| 431 | |
| 432 | PyObject* pyObj_callback = PyDict_GetItemString(kwargs, "callback"); |
| 433 | PyObject* pyObj_errback = PyDict_GetItemString(kwargs, "errback"); |
| 434 | |
| 435 | if (!validate_and_incref_callbacks(pyObj_callback, pyObj_errback)) { |
| 436 | return nullptr; |
| 437 | } |
| 438 | |
| 439 | std::shared_ptr<std::promise<PyObject*>> barrier = nullptr; |
| 440 | std::future<PyObject*> fut; |
| 441 | if (nullptr == pyObj_callback && nullptr == pyObj_errback) { |
| 442 | barrier = std::make_shared<std::promise<PyObject*>>(); |
| 443 | fut = barrier->get_future(); |
| 444 | } |
| 445 | |
| 446 | try { |
| 447 | Py_BEGIN_ALLOW_THREADS |
| 448 | { |
| 449 | cluster_.ping( |
| 450 | report_id, |
| 451 | bucket_name, |
| 452 | services, |
| 453 | timeout_ms, |
| 454 | [pyObj_callback, pyObj_errback, barrier, this](couchbase::core::diag::ping_result resp) { |
| 455 | handle_cluster_operation_callback(resp, pyObj_callback, pyObj_errback, barrier); |
| 456 | }); |
| 457 | } |
| 458 | Py_END_ALLOW_THREADS |
| 459 | |
| 460 | if (barrier) |
| 461 | { |
| 462 | PyObject* result = nullptr; |
| 463 | Py_BEGIN_ALLOW_THREADS result = fut.get(); |
| 464 | Py_END_ALLOW_THREADS return result; |
| 465 | } |
| 466 | Py_RETURN_NONE; |
| 467 | } catch (const std::exception& e) { |
| 468 | if (barrier) { |
| 469 | barrier->set_value(nullptr); |
| 470 | } |
| 471 | PyErr_SetString(PyExc_RuntimeError, e.what()); |
| 472 | Py_XDECREF(pyObj_callback); |
| 473 | Py_XDECREF(pyObj_errback); |
| 474 | return nullptr; |
| 475 | } |
| 476 | } |
| 477 |
no outgoing calls
no test coverage detected