26#ifndef MYSQLSHDK_SCRIPTING_POLYGLOT_NATIVE_WRAPPERS_POLYGLOT_NATIVE_WRAPPER_
27#define MYSQLSHDK_SCRIPTING_POLYGLOT_NATIVE_WRAPPERS_POLYGLOT_NATIVE_WRAPPER_
44class Polyglot_language;
70template <
typename T, Collectable_type t>
91 std::make_unique<Collectable_t>(native_value,
m_language);
92 auto language = collectable->language();
97 collectable->registry()->add(collectable.release());
106 void *data =
nullptr;
116 if (
const auto &target_native = collectable->data()) {
117 *ret_object = target_native;
125 poly_callback_info args) {
126 void *data =
nullptr;
128 if (
get_data(thread, args,
"destroy", &data)) {
130 const auto collectable =
static_cast<ICollectable *
>(data);
134 auto registry = collectable->
registry();
136 registry->
remove(collectable);
153 template <
typename Config>
155 poly_callback_info args) {
156 void *data =
nullptr;
157 poly_value
value =
nullptr;
161 const auto language = collectable->
language();
163 value = language->convert(Config::callback(collectable->data()));
165 language->throw_exception_object(exc);
167 language->throw_jit_executor_exception(exc);
168 }
catch (
const std::exception &e) {
182 template <
typename Config>
184 poly_callback_info args) {
185 void *data =
nullptr;
186 poly_value
value =
nullptr;
190 const auto language = collectable->
language();
192 value = Config::callback(language, collectable->data());
194 language->throw_exception_object(exc);
196 language->throw_jit_executor_exception(exc);
197 }
catch (
const std::exception &e) {
211 template <
typename Config>
213 poly_callback_info args) {
214 std::vector<poly_value> argv;
215 void *data =
nullptr;
216 poly_value
value =
nullptr;
222 const auto language = collectable->
language();
224 value = language->convert(Config::callback(
225 collectable->data(), language->convert_args(argv)));
227 language->throw_exception_object(exc);
229 language->throw_jit_executor_exception(exc);
232 }
catch (
const std::exception &e) {
246 template <
typename Config>
248 poly_callback_info args) {
249 std::vector<poly_value> argv;
250 void *data =
nullptr;
251 poly_value
value =
nullptr;
257 const auto language = collectable->
language();
259 value = Config::callback(language, collectable->data(), argv);
261 language->throw_exception_object(exc);
263 language->throw_jit_executor_exception(exc);
266 }
catch (
const std::exception &e) {
279 template <
typename Config>
281 poly_callback_info args) {
282 std::vector<poly_value> argv;
283 void *data =
nullptr;
284 poly_value
value =
nullptr;
285 std::shared_ptr<Polyglot_language> language = {};
302 Config::callback(collectable->data(), language->convert_args(argv));
308 value = language->convert(v);
310 language->throw_exception_object(exc);
312 language->throw_jit_executor_exception(exc);
313 }
catch (
const std::exception &e) {
void remove(ICollectable *target)
Definition: polyglot_collectable.cc:73
Represents a data object to be associated to a Polyglot wrapper for C++ elements.
Definition: polyglot_collectable.h:79
Base collectable interface to be able to determine the type of a collectable object without with no n...
Definition: polyglot_collectable.h:55
std::shared_ptr< Polyglot_language > language() const
Definition: polyglot_collectable.cc:54
Collectable_registry * registry() const
Definition: polyglot_collectable.cc:58
Definition: jit_executor_exceptions.h:34
Represents polyglot errors that will be created from information available in the polyglot library st...
Definition: polyglot_error.h:77
Exposure of C++ objects to the polyglot library is done through the usage of Proxy objects provided b...
Definition: polyglot_native_wrapper.h:71
static poly_value native_handler_no_args(poly_thread thread, poly_callback_info args)
Generic handler to be used with pure native functions, no interaction with the polyglot library is do...
Definition: polyglot_native_wrapper.h:154
virtual ~Polyglot_native_wrapper()=default
Polyglot_native_wrapper(std::weak_ptr< Polyglot_language > language)
Definition: polyglot_native_wrapper.h:78
static poly_value polyglot_handler_no_args(poly_thread thread, poly_callback_info args)
Generic handler to be used with functions that interact with the polyglot library:
Definition: polyglot_native_wrapper.h:183
static poly_value native_handler_fixed_args(poly_thread thread, poly_callback_info args)
Generic handler to be used with pure native functions, no interaction with the polyglot library is do...
Definition: polyglot_native_wrapper.h:212
std::weak_ptr< Polyglot_language > m_language
Definition: polyglot_native_wrapper.h:320
Polyglot_native_wrapper & operator=(Polyglot_native_wrapper &&)=delete
Polyglot_native_wrapper(Polyglot_native_wrapper &&)=delete
static bool unwrap(poly_thread thread, poly_value value, Native_ptr *ret_object)
Definition: polyglot_native_wrapper.h:102
static poly_value handler_release_collectable(poly_thread thread, poly_callback_info args)
Definition: polyglot_native_wrapper.h:124
Polyglot_native_wrapper & operator=(const Polyglot_native_wrapper &)=delete
static poly_value polyglot_handler_fixed_args(poly_thread thread, poly_callback_info args)
Generic handler to be used with functions that interact with the polyglot library,...
Definition: polyglot_native_wrapper.h:247
Polyglot_native_wrapper(const Polyglot_native_wrapper &)=delete
std::shared_ptr< T > Native_ptr
Definition: polyglot_native_wrapper.h:74
poly_value wrap(const Native_ptr &native_value) const
Definition: polyglot_native_wrapper.h:89
Polyglot_native_wrapper()=delete
virtual poly_value create_wrapper(poly_thread thread, poly_context context, ICollectable *collectable) const =0
static poly_value native_handler_variable_args(poly_thread thread, poly_callback_info args)
Generic handler to be used with pure native functions, no interaction with the polyglot library is do...
Definition: polyglot_native_wrapper.h:280
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
void throw_callback_exception(poly_thread thread, const char *error)
The integration of the PolyglotAPI is mostly centered in the registration of C++ callbacks to impleme...
Definition: polyglot_utils.cc:251
bool get_args_and_data(poly_thread thread, poly_callback_info args, std::string_view name, void **data, size_t expected_argc, std::vector< poly_value > *argv)
Returns the collectable and arguments sent by Polyglot on a call to a C++ function.
Definition: polyglot_utils.cc:109
bool is_native_type(poly_thread thread, poly_value value, Collectable_type type, void **native_data)
Identifies if a given poly_value corresponds to a wrapped C++ element.
Definition: polyglot_utils.cc:126
size_t parse_callback_args(poly_thread thread, poly_callback_info args, std::vector< poly_value > *argv, void **data)
Parses the callback information sent by polyglot, returning if requested a vector with the arguments ...
Definition: polyglot_utils.cc:63
bool get_data(poly_thread thread, poly_callback_info args, std::string_view name, void **data)
Returns the collectable sent by Polyglot on a call to a C++ function.
Definition: polyglot_utils.cc:92
Definition: file_system_exceptions.h:34
Definition: gcs_xcom_synode.h:64
case opt name
Definition: sslopt-case.h:29