MCPcopy Create free account
hub / github.com/PlotJuggler/PlotJuggler / onCreate

Method onCreate

pj_runtime/src/DataProcessorsRuntimeHost.cpp:50–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

48}
49
50bool DataProcessorsRuntimeHost::onCreate(
51 void* ctx, PJ_string_view_t id, PJ_string_view_t kind, PJ_string_view_t /*language*/,
52 const PJ_string_view_t* inputs, uint64_t input_count, const PJ_string_view_t* outputs, uint64_t output_count,
53 PJ_string_view_t script, PJ_string_view_t params_json, uint32_t flags, PJ_string_view_t* out_topics,
54 uint64_t out_topics_capacity, uint64_t* out_topics_count, PJ_error_t* out_error) noexcept {
55 auto* self = static_cast<DataProcessorsRuntimeHost*>(ctx);
56 if (self == nullptr) {
57 return false;
58 }
59 try {
60 if (!parseKind(sdk::toStringView(kind))) {
61 sdk::fillError(
62 out_error, kErrorRejected, kDomain,
63 "unknown data processor kind '" + std::string(sdk::toStringView(kind)) + "'");
64 return false;
65 }
66 std::vector<std::string> input_names;
67 input_names.reserve(input_count);
68 for (uint64_t i = 0; i < input_count; ++i) {
69 input_names.emplace_back(sdk::toStringView(inputs[i]));
70 }
71 std::vector<std::string> output_names;
72 output_names.reserve(output_count);
73 for (uint64_t i = 0; i < output_count; ++i) {
74 output_names.emplace_back(sdk::toStringView(outputs[i]));
75 }
76 const bool ephemeral = (flags & PJ_DATA_PROCESSOR_FLAG_EPHEMERAL) != 0;
77 auto result = self->service_.upsertTransform(
78 self->plugin_id_, sdk::toStringView(id), std::move(input_names), std::move(output_names),
79 sdk::toStringView(script), sdk::toStringView(params_json), ephemeral);
80 if (!result.has_value()) {
81 sdk::fillError(out_error, kErrorRejected, kDomain, result.error());
82 return false;
83 }
84 // Resolved output topic names back to the plugin via the count-then-fill
85 // convention. Owned snapshot in member storage; the returned views point into it
86 // and stay valid until the next call on this vtable (the ABI contract).
87 self->create_topics_storage_ = std::move(result->outputs);
88 if (out_topics_count != nullptr) {
89 *out_topics_count = self->create_topics_storage_.size();
90 }
91 if (out_topics != nullptr) {
92 const uint64_t n = std::min<uint64_t>(out_topics_capacity, self->create_topics_storage_.size());
93 for (uint64_t i = 0; i < n; ++i) {
94 out_topics[i] = sdk::toAbiString(self->create_topics_storage_[i]);
95 }
96 }
97 return true;
98 } catch (const std::exception& e) {
99 sdk::fillError(out_error, kErrorInternal, kDomain, e.what());
100 return false;
101 } catch (...) {
102 sdk::fillError(out_error, kErrorInternal, kDomain, "unknown error creating data processor");
103 return false;
104 }
105}
106
107bool DataProcessorsRuntimeHost::onRemove(void* ctx, PJ_string_view_t id, PJ_error_t* out_error) noexcept {

Callers

nothing calls this directly

Calls 5

parseKindFunction · 0.85
reserveMethod · 0.80
upsertTransformMethod · 0.80
toStringViewFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected