MCPcopy Create free account
hub / github.com/AimRT/AimRT / PbRpcServiceBaseRegisterServiceFunc

Function PbRpcServiceBaseRegisterServiceFunc

src/runtime/python_runtime/export_rpc.h:112–156  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110using ServiceFuncType = std::function<ServiceFuncReturnType(aimrt::rpc::ContextRef, const pybind11::bytes&)>;
111
112inline void PbRpcServiceBaseRegisterServiceFunc(
113 aimrt::rpc::ServiceBase& service,
114 std::string_view func_name,
115 const std::shared_ptr<const PyPbTypeSupport>& req_type_support,
116 const std::shared_ptr<const PyPbTypeSupport>& rsp_type_support,
117 ServiceFuncType&& service_func) {
118 static std::vector<std::shared_ptr<const PyPbTypeSupport>> py_ts_vec;
119 py_ts_vec.emplace_back(req_type_support);
120 py_ts_vec.emplace_back(rsp_type_support);
121
122 aimrt::rpc::ServiceFunc aimrt_service_func(
123 [service_func{std::move(service_func)}](
124 const aimrt_rpc_context_base_t* ctx, const void* req_ptr, void* rsp_ptr, aimrt_function_base_t* callback) {
125 aimrt::rpc::ServiceCallback callback_f(callback);
126
127 aimrt::rpc::ContextRef ctx_ref(ctx);
128
129 try {
130 const std::string& req_buf = *static_cast<const std::string*>(req_ptr);
131 std::string& rsp_buf = *static_cast<std::string*>(rsp_ptr);
132
133 pybind11::gil_scoped_acquire acquire;
134
135 auto req_buf_bytes = pybind11::bytes(req_buf);
136 auto [status, rsp_buf_tmp] = service_func(ctx_ref, req_buf_bytes);
137 req_buf_bytes.release();
138
139 pybind11::gil_scoped_release release;
140
141 rsp_buf = std::move(rsp_buf_tmp);
142 callback_f(status.Code());
143 return;
144 } catch (...) {
145 callback_f(AIMRT_RPC_STATUS_SVR_HANDLE_FAILED);
146 return;
147 }
148 });
149
150 service.RegisterServiceFunc(
151 func_name,
152 nullptr,
153 req_type_support->NativeHandle(),
154 rsp_type_support->NativeHandle(),
155 std::move(aimrt_service_func));
156}
157
158inline bool PbRpcHandleRefRegisterClientFunc(
159 aimrt::rpc::RpcHandleRef& rpc_handle_ref,

Callers

nothing calls this directly

Calls 2

RegisterServiceFuncMethod · 0.45
NativeHandleMethod · 0.45

Tested by

no test coverage detected