15#ifndef ACTIONENGINE_PYBIND11_ACTIONENGINE_SERVICE_H_ 
   16#define ACTIONENGINE_PYBIND11_ACTIONENGINE_SERVICE_H_ 
   23#include <absl/base/optimization.h> 
   24#include <absl/log/log.h> 
   25#include <absl/status/status.h> 
   26#include <absl/status/statusor.h> 
   27#include <absl/time/time.h> 
   28#include <pybind11/cast.h> 
   29#include <pybind11/gil.h> 
   30#include <pybind11/pybind11.h> 
   31#include <pybind11/pytypes.h> 
   32#include <pybind11_abseil/absl_casters.h> 
   33#include <pybind11_abseil/status_caster.h> 
   34#include <pybind11_abseil/statusor_caster.h> 
   37#include "actionengine/net/stream.h" 
   39#include "actionengine/stores/chunk_store_pybind11.h"   
   40#include "actionengine/util/utils_pybind11.h" 
   42namespace act::pybindings {
 
   44namespace py = ::pybind11;
 
   46void BindStream(py::handle scope, std::string_view name = 
"WireStream");
 
   47void BindSession(py::handle scope, std::string_view name = 
"Session");
 
   48void BindService(py::handle scope, std::string_view name = 
"Service");
 
   49void BindStreamToSessionConnection(
 
   50    py::handle scope, std::string_view name = 
"StreamToSessionConnection");
 
   71  using WireStream::WireStream;
 
   76    py::gil_scoped_acquire gil;
 
   77    const py::function function = py::get_override(
this, 
"send");
 
   80      return absl::UnimplementedError(
 
   81          "send is not implemented in the Python subclass of " 
   84    const py::object py_result = function(message);
 
   86    const absl::StatusOr<py::object> result =
 
   87        pybindings::RunThreadsafeIfCoroutine(py_result);
 
   90      return result.status();
 
   92    return absl::OkStatus();
 
 
   95  absl::StatusOr<std::optional<WireMessage>> 
Receive(
 
   96      absl::Duration timeout)
 override {
 
   97    py::gil_scoped_acquire gil;
 
   98    const py::function function = py::get_override(
this, 
"receive");
 
  101      LOG(FATAL) << 
"receive is not implemented in the Python subclass of " 
  105    const py::object py_result = function(absl::ToDoubleSeconds(timeout));
 
  107    absl::StatusOr<py::object> result =
 
  108        pybindings::RunThreadsafeIfCoroutine(py_result);
 
  111      return result.status();
 
  114    if (result->is_none()) {
 
 
  122    py::gil_scoped_acquire gil;
 
  123    const py::function function = py::get_override(
this, 
"accept");
 
  126      return absl::UnimplementedError(
 
  127          "accept is not implemented in the Python subclass of " 
  131      const py::object py_result = function();
 
  132      const absl::StatusOr<py::object> result =
 
  133          pybindings::RunThreadsafeIfCoroutine(py_result);
 
  136        return result.status();
 
  138    } 
catch (
const py::error_already_set& e) {
 
  139      return absl::InternalError(e.what());
 
  142    return absl::OkStatus();
 
 
  146    py::gil_scoped_acquire gil;
 
  147    const py::function function = py::get_override(
this, 
"start");
 
  150      return absl::UnimplementedError(
 
  151          "start is not implemented in the Python subclass of " 
  155      const py::object py_result = function();
 
  156      const absl::StatusOr<py::object> result =
 
  157          pybindings::RunThreadsafeIfCoroutine(py_result);
 
  160        return result.status();
 
  162    } 
catch (
const py::error_already_set& e) {
 
  163      return absl::InternalError(e.what());
 
  166    return absl::OkStatus();
 
 
  170    py::gil_scoped_acquire gil;
 
  171    const py::function function = py::get_override(
this, 
"half_close");
 
  174      LOG(FATAL) << 
"half_close is not implemented in the Python subclass of " 
  179      const py::object py_result = function();
 
  180      const absl::StatusOr<py::object> result =
 
  181          pybindings::RunThreadsafeIfCoroutine(py_result);
 
  184        LOG(ERROR) << 
"Error in half_close: " << result.status();
 
  186    } 
catch (
const py::error_already_set& e) {
 
  187      LOG(ERROR) << 
"Error in half_close: " << e.what();
 
 
  192    py::gil_scoped_acquire gil;
 
  193    const py::function function = py::get_override(
this, 
"abort");
 
  196      LOG(FATAL) << 
"abort is not implemented in the Python subclass of " 
  201      const py::object py_result = function();
 
  202      const absl::StatusOr<py::object> result =
 
  203          pybindings::RunThreadsafeIfCoroutine(py_result);
 
  206        LOG(ERROR) << 
"Error in abort: " << result.status();
 
  208    } 
catch (
const py::error_already_set& e) {
 
  209      LOG(ERROR) << 
"Error in abort: " << e.what();
 
 
  214    PYBIND11_OVERRIDE_PURE_NAME(absl::Status, PyWireStream, 
"get_status",
 
 
  218  [[nodiscard]] py::object GetLoop()
 const {
 
  219    PYBIND11_OVERRIDE_PURE_NAME(py::object, 
PyWireStream, 
"get_loop",
 
  223  [[nodiscard]] std::string 
GetId()
 const override {
 
  224    PYBIND11_OVERRIDE_PURE_NAME(std::string, PyWireStream, 
"get_id", 
GetId, );
 
 
 
  228py::module_ MakeServiceModule(py::module_ scope,
 
  229                              std::string_view module_name = 
"service");
 
Definition service_pybind11.h:69
void HalfClose() override
Definition service_pybind11.h:169
std::string GetId() const override
Definition service_pybind11.h:223
void Abort() override
Definition service_pybind11.h:191
absl::Status Start() override
Definition service_pybind11.h:145
absl::Status Send(WireMessage message) override
Definition service_pybind11.h:75
absl::Status GetStatus() const override
Definition service_pybind11.h:213
absl::Status Accept() override
Definition service_pybind11.h:121
absl::StatusOr< std::optional< WireMessage > > Receive(absl::Duration timeout) override
Definition service_pybind11.h:95
An abstract interface for raw data storage and retrieval for ActionEngine nodes.
ActionEngine data structures used to implement actions and nodes (data streams).