Qore Programming Language 2.3.0
Loading...
Searching...
No Matches
ModuleManager.h
Go to the documentation of this file.
1/* -*- mode: c++; indent-tabs-mode: nil -*- */
2/*
3 ModuleManager.h
4
5 Qore Programming Language
6
7 Copyright (C) 2003 - 2025 Qore Technologies, s.r.o.
8
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the "Software"),
11 to deal in the Software without restriction, including without limitation
12 the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26
27 Note that the Qore library is released under a choice of three open-source
28 licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29 information.
30*/
31
32#ifndef _QORE_MODULEMANAGER_H
33
34#define _QORE_MODULEMANAGER_H
35
36#include <qore/QoreThreadLock.h>
37#include <qore/QoreString.h>
38
39#include <vector>
40
45#define QORE_MODULE_API_MAJOR 1
46#define QORE_MODULE_API_MINOR 4
47
48#define QORE_MODULE_COMPAT_API_MAJOR QORE_MODULE_API_MAJOR
49#define QORE_MODULE_COMPAT_API_MINOR QORE_MODULE_API_MINOR
50
53 unsigned char major;
54 unsigned char minor;
55};
56
58DLLEXPORT extern const qore_mod_api_compat_s* qore_mod_api_list;
59
61DLLEXPORT extern const unsigned qore_mod_api_list_len;
62
63class QoreNamespace;
64class QoreStringNode;
65class QoreListNode;
66class ExceptionSink;
67class QoreProgram;
68
72 std::string path;
73};
74
76typedef QoreStringNode* (*qore_module_init_t)();
77
79typedef QoreStringNode* (*qore_module_init_info_t)(qore_module_init_info& info);
80
82typedef void (*qore_module_ns_init_t)(QoreNamespace* root_ns, QoreNamespace* qore_ns);
83
85typedef void (*qore_module_delete_t)();
86
88typedef void (*qore_module_parse_cmd_t)(const QoreString& cmd, ExceptionSink* xsink);
89
90enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
91 MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
92
93typedef std::vector<std::string> strvec_t;
94
96
99 QoreString name;
100 QoreString version;
101 QoreString desc;
102 QoreString author;
103 QoreString url;
104 int api_major = -1;
105 int api_minor = -1;
108 qore_module_ns_init_t ns_init = nullptr;
109 qore_module_delete_t del = nullptr;
110 qore_module_parse_cmd_t parse_cmd = nullptr;
111
112 qore_license_t license;
113 QoreString license_str;
114
116 strvec_t dependencies;
117
119 QoreHashNode* info = nullptr;
120
123};
124
126typedef void (*qore_binary_module_desc_t)(QoreModuleInfo& mod_info);
127
129
137public:
138 ModuleManager(const ModuleManager&) = delete;
139 ModuleManager& operator=(const ModuleManager&) = delete;
140
142
145 DLLEXPORT static void addModuleDir(const char* dir);
146
148
151 DLLEXPORT static void addAutoModuleDir(const char* dir);
152
154
157 DLLEXPORT static void addModuleDirList(const char* strlist);
158
160
163 DLLEXPORT static void addAutoModuleDirList(const char* strlist);
164
166 DLLEXPORT static QoreListNode* getModuleList();
167
169 DLLEXPORT static QoreHashNode* getModuleHash();
170
172
180 DLLEXPORT static int runTimeLoadModule(const char* name, ExceptionSink* xsink);
181
183
192 DLLEXPORT static int runTimeLoadModule(const char* name, QoreProgram* pgm, ExceptionSink* xsink);
193
195
209 DLLEXPORT static int runTimeLoadModule(ExceptionSink* xsink, const char* name, QoreProgram* pgm = nullptr,
210 qore_binary_module_desc_t mod_desc_func = nullptr);
211
213
218 DLLEXPORT static QoreStringNode* parseLoadModule(const char* name, QoreProgram* pgm = nullptr);
219
221 DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram* pgm, ExceptionSink* xsink);
222
224 DLLEXPORT static void addStandardModulePaths();
225
227
238 DLLEXPORT int issueRuntimeCmd(const char* mname, QoreProgram* pgm, const QoreString& cmd, ExceptionSink* xsink);
239
240 // not exported in the public API
241 DLLLOCAL ModuleManager();
242};
243
245DLLEXPORT extern ModuleManager MM;
246
247static inline bool is_module_api_supported(int major, int minor) {
248 for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
249 if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
250 return true;
251 return false;
252}
253
254#endif // _QORE_MODULEMANAGER_H
void(* qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns)
signature of the module namespace change/delta function
Definition ModuleManager.h:82
DLLEXPORT ModuleManager MM
the global ModuleManager object
QoreStringNode *(* qore_module_init_t)()
signature of the module constructor/initialization function
Definition ModuleManager.h:76
DLLEXPORT const unsigned qore_mod_api_list_len
number of elements in qore_mod_api_list;
void(* qore_binary_module_desc_t)(QoreModuleInfo &mod_info)
Module description function.
Definition ModuleManager.h:126
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition ModuleManager.h:88
DLLEXPORT const qore_mod_api_compat_s * qore_mod_api_list
list of module APIs this library supports
void(* qore_module_delete_t)()
signature of the module destructor function
Definition ModuleManager.h:85
QoreStringNode *(* qore_module_init_info_t)(qore_module_init_info &info)
signature of the module constructor/initialization function with info
Definition ModuleManager.h:79
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition ExceptionSink.h:50
manages the loading of Qore modules from feature or path names. Also manages adding module changes in...
Definition ModuleManager.h:136
static DLLEXPORT int runTimeLoadModule(const char *name, QoreProgram *pgm, ExceptionSink *xsink)
loads the named module at run time, returns -1 if an exception was raised, 0 for OK
static DLLEXPORT void addStandardModulePaths()
adds the standard module directories to the module path (only necessary if the module paths are set u...
static DLLEXPORT int runTimeLoadModule(const char *name, ExceptionSink *xsink)
loads the named module at run time, returns -1 if an exception was raised, 0 for OK
static DLLEXPORT void addAutoModuleDir(const char *dir)
no longer supported - removed for security reasons
static DLLEXPORT void addModuleDir(const char *dir)
to add a single directory to the QORE_MODULE_DIR list, can only be called before the library initiali...
DLLEXPORT void registerUserModuleFromSource(const char *name, const char *src, QoreProgram *pgm, ExceptionSink *xsink)
registers the given user module from the module source given as an argument
static DLLEXPORT int runTimeLoadModule(ExceptionSink *xsink, const char *name, QoreProgram *pgm=nullptr, qore_binary_module_desc_t mod_desc_func=nullptr)
Loads the module at runtime, returns -1 if an exception was raised, 0 for OK.
static DLLEXPORT void addAutoModuleDirList(const char *strlist)
no longer supported - removed for security reasons
static DLLEXPORT QoreStringNode * parseLoadModule(const char *name, QoreProgram *pgm=nullptr)
loads the named module at parse time (or before run time, even if parsing is not active),...
static DLLEXPORT QoreHashNode * getModuleHash()
retuns a hash of module information hashes, caller owns the list reference returned
static DLLEXPORT void addModuleDirList(const char *strlist)
to add a list of directories separated by ':' characters to the QORE_MODULE_DIR list,...
DLLEXPORT int issueRuntimeCmd(const char *mname, QoreProgram *pgm, const QoreString &cmd, ExceptionSink *xsink)
Issues a module command for the given module.
static DLLEXPORT QoreListNode * getModuleList()
retuns a list of module information hashes, caller owns the list reference returned
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition QoreHashNode.h:51
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition QoreListNode.h:52
contains constants, classes, and subnamespaces in QoreProgram objects
Definition QoreNamespace.h:65
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition QoreProgram.h:128
Qore's string type supported by the QoreEncoding class.
Definition QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition QoreStringNode.h:50
qore_license_t
qore library and module license type identifiers
Definition common.h:91
Qore module info.
Definition ModuleManager.h:98
qore_module_init_t init
either init or init_info can be set
Definition ModuleManager.h:107
qore_module_init_info_t init_info
either init or init_info can be set
Definition ModuleManager.h:122
strvec_t dependencies
list of binary modules that this binary module depends on
Definition ModuleManager.h:116
QoreHashNode * info
extra information to appear in the module info hash
Definition ModuleManager.h:119
element of qore_mod_api_list;
Definition ModuleManager.h:52
Module info for the init_info method.
Definition ModuleManager.h:70
std::string path
path to the module itself
Definition ModuleManager.h:72