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

Function PbSubscribeWithCtx

src/runtime/python_runtime/export_channel.h:72–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

70}
71
72inline bool PbSubscribeWithCtx(
73 aimrt::channel::SubscriberRef& subscriber_ref,
74 const std::shared_ptr<const PyPbTypeSupport>& msg_type_support,
75 std::function<void(aimrt::channel::ContextRef, const pybind11::bytes&)>&& callback) {
76 static std::vector<std::shared_ptr<const PyPbTypeSupport>> py_ts_vec;
77 py_ts_vec.emplace_back(msg_type_support);
78
79 return subscriber_ref.Subscribe(
80 msg_type_support->NativeHandle(),
81 [callback{std::move(callback)}](
82 const aimrt_channel_context_base_t* ctx_ptr,
83 const void* msg_ptr,
84 aimrt_function_base_t* release_callback_base) {
85 aimrt::channel::SubscriberReleaseCallback release_callback(release_callback_base);
86
87 const std::string& msg_buf = *static_cast<const std::string*>(msg_ptr);
88 auto ctx_ref = aimrt::channel::ContextRef(ctx_ptr);
89
90 pybind11::gil_scoped_acquire acquire;
91
92 auto msg_buf_bytes = pybind11::bytes(msg_buf);
93 callback(ctx_ref, msg_buf_bytes);
94 msg_buf_bytes.release();
95
96 pybind11::gil_scoped_release release;
97
98 release_callback();
99 });
100}
101
102inline void ExportPublisherRef(pybind11::object m) {
103 using aimrt::channel::PublisherRef;

Callers

nothing calls this directly

Calls 3

ContextRefClass · 0.50
SubscribeMethod · 0.45
NativeHandleMethod · 0.45

Tested by

no test coverage detected