|
17 | 17 |
|
18 | 18 | #include "pj_base/expected.hpp" |
19 | 19 | #include "pj_base/plugin_abi_export.hpp" |
| 20 | +#include "pj_base/sdk/data_source_host_views.hpp" // ParserIngestHostView, errorToString |
20 | 21 | #include "pj_base/sdk/plugin_data_api.hpp" |
21 | 22 | #include "pj_base/sdk/service_registry.hpp" |
22 | 23 | #include "pj_base/sdk/service_traits.hpp" |
@@ -56,6 +57,43 @@ class ToolboxRuntimeHostView { |
56 | 57 | } |
57 | 58 | } |
58 | 59 |
|
| 60 | + /// Create (or fetch) the parser-ingest context for a toolbox-created data |
| 61 | + /// source (pass ToolboxHostView::createDataSource's handle `.id`). Returns |
| 62 | + /// the shared delegated-ingest view: ensureParserBinding() once per topic, |
| 63 | + /// pushMessage() per record. Drive the returned view from a single worker |
| 64 | + /// thread; unlike reportMessage/notifyDataChanged, parser ingest is not |
| 65 | + /// GUI-marshalled. |
| 66 | + [[nodiscard]] Expected<ParserIngestHostView> createParserIngest(uint32_t data_source_id) const { |
| 67 | + if (!valid()) { |
| 68 | + return unexpected("toolbox runtime host is not bound"); |
| 69 | + } |
| 70 | + if (!PJ_HAS_TAIL_SLOT(PJ_toolbox_runtime_host_vtable_t, host_.vtable, create_parser_ingest)) { |
| 71 | + return unexpected("toolbox runtime host does not support create_parser_ingest (older host)"); |
| 72 | + } |
| 73 | + PJ_data_source_runtime_host_t raw{}; |
| 74 | + PJ_error_t err{}; |
| 75 | + if (!host_.vtable->create_parser_ingest(host_.ctx, data_source_id, &raw, &err)) { |
| 76 | + return unexpected(errorToString(err)); |
| 77 | + } |
| 78 | + return ParserIngestHostView{raw}; |
| 79 | + } |
| 80 | + |
| 81 | + /// Flush + destroy the context. Idempotent. The view returned by |
| 82 | + /// createParserIngest must not be used afterwards. |
| 83 | + [[nodiscard]] Status releaseParserIngest(uint32_t data_source_id) const { |
| 84 | + if (!valid()) { |
| 85 | + return unexpected("toolbox runtime host is not bound"); |
| 86 | + } |
| 87 | + if (!PJ_HAS_TAIL_SLOT(PJ_toolbox_runtime_host_vtable_t, host_.vtable, release_parser_ingest)) { |
| 88 | + return unexpected("toolbox runtime host does not support release_parser_ingest (older host)"); |
| 89 | + } |
| 90 | + PJ_error_t err{}; |
| 91 | + if (!host_.vtable->release_parser_ingest(host_.ctx, data_source_id, &err)) { |
| 92 | + return unexpected(errorToString(err)); |
| 93 | + } |
| 94 | + return okStatus(); |
| 95 | + } |
| 96 | + |
59 | 97 | [[nodiscard]] const PJ_toolbox_runtime_host_t& raw() const { |
60 | 98 | return host_; |
61 | 99 | } |
|
0 commit comments