MySQL 9.3.0
Source Code Documentation
polyglot_common_context.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, 2025, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
19 * the GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26#ifndef MYSQLSHDK_SCRIPTING_POLYGLOT_LANGUAGES_POLYGLOT_COMMON_CONTEXT_H_
27#define MYSQLSHDK_SCRIPTING_POLYGLOT_LANGUAGES_POLYGLOT_COMMON_CONTEXT_H_
28
30
31#include <memory>
32
37
38namespace shcore {
39namespace polyglot {
40
41/**
42 * Common context for GraalVM Languages
43 *
44 * Encloses the following global routines/components:
45 *
46 * - Initialization/TearDown of the GraalVM Isolate.
47 * - Registration of global logging callbacks.
48 * - Setup of the global engine.
49 * - Provides access to the garbage collector for event registration.
50 *
51 * This class can be specialized to:
52 *
53 * - Provide custom callbacks for the global logging functions.
54 * - Create a custom Engine to be used in the contexts created from this class.
55 * - Provide custom configuration for the garbage collector.
56 */
58 public:
60 virtual ~Polyglot_common_context() = default;
61
62 virtual void initialize(const std::vector<std::string> &isolate_args);
63 virtual void finalize();
64
65 poly_reference engine() const { return m_engine.get(); }
66 poly_isolate isolate() const { return m_isolate; }
67 poly_thread thread() const { return m_thread; }
68
69 void clean_collectables();
70
72
73 protected:
74 poly_isolate m_isolate = nullptr;
75 poly_thread m_thread = nullptr;
76
77 private:
78 void init_engine();
79 static void fatal_error_callback(void *data);
80 static void flush_callback(void *data);
81 static void log_callback(const char *bytes, size_t length, void *data);
82 virtual void fatal_error() = 0;
83 virtual void flush() = 0;
84 virtual void log(const char *bytes, size_t length) = 0;
85 virtual poly_engine create_engine() { return nullptr; }
86 virtual Garbage_collector::Config gc_config() { return {}; }
87
89 std::unique_ptr<Polyglot_scope> m_scope;
91};
92
93} // namespace polyglot
94} // namespace shcore
95
96#endif // MYSQLSHDK_SCRIPTING_POLYGLOT_LANGUAGES_POLYGLOT_COMMON_CONTEXT_H_
When a Polyglot wrapper for a C++ object is created, a collectable instance is created to be passed t...
Definition: polyglot_collectable.h:113
Common context for GraalVM Languages.
Definition: polyglot_common_context.h:57
poly_thread thread() const
Definition: polyglot_common_context.h:67
virtual void initialize(const std::vector< std::string > &isolate_args)
Definition: polyglot_common_context.cc:59
static void fatal_error_callback(void *data)
Definition: polyglot_common_context.cc:113
Collectable_registry m_registry
Definition: polyglot_common_context.h:90
virtual void finalize()
Definition: polyglot_common_context.cc:97
poly_isolate m_isolate
Definition: polyglot_common_context.h:74
void init_engine()
Definition: polyglot_common_context.cc:129
virtual Garbage_collector::Config gc_config()
Definition: polyglot_common_context.h:86
std::unique_ptr< Polyglot_scope > m_scope
Definition: polyglot_common_context.h:89
virtual poly_engine create_engine()
Definition: polyglot_common_context.h:85
poly_reference engine() const
Definition: polyglot_common_context.h:65
Store m_engine
Definition: polyglot_common_context.h:88
virtual void log(const char *bytes, size_t length)=0
poly_isolate isolate() const
Definition: polyglot_common_context.h:66
static void log_callback(const char *bytes, size_t length, void *data)
Definition: polyglot_common_context.cc:123
Collectable_registry * collectable_registry()
Definition: polyglot_common_context.h:71
poly_thread m_thread
Definition: polyglot_common_context.h:75
void clean_collectables()
Definition: polyglot_common_context.cc:136
static void flush_callback(void *data)
Definition: polyglot_common_context.cc:118
Helper class to handle polyglot values made permanent.
Definition: polyglot_store.h:47
poly_reference get() const noexcept
Definition: polyglot_store.h:70
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
Definition: file_system_exceptions.h:34
Definition: polyglot_garbage_collector.h:81