26#ifndef MYSQLSHDK_SCRIPTING_POLYGLOT_UTILS_POLYGLOT_UTILS_H_
27#define MYSQLSHDK_SCRIPTING_POLYGLOT_UTILS_POLYGLOT_UTILS_H_
35#include <unordered_map>
62 std::vector<poly_value> *argv,
void **data);
71bool get_data(poly_thread thread, poly_callback_info args,
72 std::string_view name,
void **data);
83 std::string_view name,
void **data,
size_t expected_argc,
84 std::vector<poly_value> *argv);
90 void **native_data =
nullptr);
102poly_value
poly_string(poly_thread thread, poly_context context,
103 std::string_view data);
108std::string
to_string(poly_thread thread, poly_value obj);
113int64_t
to_int(poly_thread thread, poly_value obj);
118double to_double(poly_thread thread, poly_value obj);
123double to_boolean(poly_thread thread, poly_value obj);
128poly_value
poly_bool(poly_thread thread, poly_context context,
bool value);
133poly_value
poly_uint(poly_thread thread, poly_context context, uint64_t
value);
138poly_value
poly_int(poly_thread thread, poly_context context, int64_t
value);
143poly_value
poly_double(poly_thread thread, poly_context context,
double value);
148poly_value
poly_null(poly_thread thread, poly_context context);
153poly_value
poly_array(poly_thread thread, poly_context context,
154 const std::vector<poly_value> &values);
159poly_value
get_member(poly_thread thread, poly_value
object,
160 const std::string &name);
185template <
typename Target,
typename Config>
187 poly_callback_info args) {
188 std::vector<poly_value> argv;
189 void *data =
nullptr;
190 poly_value
value =
nullptr;
195 const auto instance =
static_cast<Target *
>(data);
196 const auto language = instance->language();
198 value = (instance->*Config::callback)(argv);
200 language->throw_exception_object(exc);
203 }
catch (
const std::exception &e) {
216template <
typename Target,
typename Config>
218 poly_callback_info args) {
219 std::vector<poly_value> argv;
220 void *data =
nullptr;
221 poly_value
value =
nullptr;
226 const auto instance =
static_cast<Target *
>(data);
227 const auto language = instance->language();
229 value = language->convert(
230 (instance->*Config::callback)(language->convert_args(argv)));
232 language->throw_exception_object(exc);
235 }
catch (
const std::exception &e) {
248template <
typename Target,
typename Config>
250 poly_callback_info args) {
251 void *data =
nullptr;
252 poly_value
value =
nullptr;
256 const auto instance =
static_cast<Target *
>(data);
257 const auto language = instance->language();
259 value = (instance->*Config::callback)();
261 language->throw_exception_object(exc);
262 }
catch (
const std::exception &e) {
277template <
typename Target,
typename Config>
279 poly_callback_info args) {
280 void *data =
nullptr;
281 poly_value
value =
nullptr;
285 const auto instance =
static_cast<Target *
>(data);
286 const auto language = instance->language();
288 value = language->convert((instance->*Config::callback)());
290 language->throw_exception_object(exc);
291 }
catch (
const std::exception &e) {
306template <
typename Target,
typename Config>
308 poly_callback_info args) {
309 std::vector<poly_value> argv;
310 void *data =
nullptr;
311 poly_value
value =
nullptr;
316 const auto instance =
static_cast<Target *
>(data);
317 const auto language = instance->language();
320 value = language->convert(
321 (instance->*Config::callback)(language->convert_args(argv)));
323 language->throw_exception_object(exc);
326 }
catch (
const std::exception &e) {
333bool get_member(poly_thread thread, poly_value
object,
const char *name,
335bool is_object(poly_thread thread, poly_value
object, std::string *class_name);
Represents polyglot errors that will be created from information available in the polyglot library st...
Definition: polyglot_error.h:77
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
const char * k_origin_shell
Definition: polyglot_utils.h:49
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_utils.h:307
poly_value poly_uint(poly_thread thread, poly_context context, uint64_t value)
Converts a bool into a polyglot boolean.
Definition: polyglot_utils.cc:197
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
poly_value poly_bool(poly_thread thread, poly_context context, bool value)
Converts a bool into a polyglot boolean.
Definition: polyglot_utils.cc:182
const char * k_syntax_error
Definition: polyglot_utils.h:51
double to_double(poly_thread thread, poly_value obj)
Converts a polyglot string into a C++ double.
Definition: polyglot_utils.cc:163
bool is_executable(poly_thread thread, poly_value object)
Returns true if the given value is executable.
Definition: polyglot_utils.cc:267
poly_value poly_int(poly_thread thread, poly_context context, int64_t value)
Converts a bool into a polyglot boolean.
Definition: polyglot_utils.cc:189
std::vector< std::string > get_member_keys(poly_thread thread, poly_context context, poly_value object)
Retrieves the names of the members of the given poly_value.
Definition: polyglot_utils.cc:232
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_utils.h:186
bool is_object(poly_thread thread, poly_value object, std::string *class_name)
Definition: polyglot_utils.cc:287
double to_boolean(poly_thread thread, poly_value obj)
Converts a polyglot string into a C++ double.
Definition: polyglot_utils.cc:170
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
int64_t to_int(poly_thread thread, poly_value obj)
Converts a polyglot string into a C++ int64_t.
Definition: polyglot_utils.cc:156
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_utils.h:217
Collectable_type
Definition: polyglot_collectable.h:39
const char * k_interrupted_error
Definition: polyglot_utils.h:52
poly_value poly_double(poly_thread thread, poly_context context, double value)
Converts a double into a polyglot double.
Definition: polyglot_utils.cc:209
poly_value poly_array(poly_thread thread, poly_context context, const std::vector< poly_value > &values)
Converts an array of poly_values into a polyglot array.
Definition: polyglot_utils.cc:223
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
Language
Definition: polyglot_utils.h:47
std::string to_string(poly_thread thread, poly_value obj)
Converts a polyglot string into a C++ string.
Definition: polyglot_utils.cc:145
poly_value poly_null(poly_thread thread, poly_context context)
Returns a polyglot null value.
Definition: polyglot_utils.cc:216
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
poly_value poly_string(poly_thread thread, poly_context context, std::string_view data)
Converts a string into a polyglot string.
Definition: polyglot_utils.cc:177
poly_value get_member(poly_thread thread, poly_value object, const std::string &name)
Retrieves a member identified with name from the given object.
Definition: polyglot_utils.cc:259
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_utils.h:249
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
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_utils.h:278
Definition: file_system_exceptions.h:34
required string type
Definition: replication_group_member_actions.proto:34
case opt name
Definition: sslopt-case.h:29