Qore Programming Language 2.0.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 - 2024 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;
67
71 std::string path;
72};
73
75typedef QoreStringNode* (*qore_module_init_t)();
76
78typedef QoreStringNode* (*qore_module_init_info_t)(qore_module_init_info& info);
79
81typedef void (*qore_module_ns_init_t)(QoreNamespace* root_ns, QoreNamespace* qore_ns);
82
84typedef void (*qore_module_delete_t)();
85
87typedef void (*qore_module_parse_cmd_t)(const QoreString& cmd, ExceptionSink* xsink);
88
89enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
90 MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
91
92typedef std::vector<std::string> strvec_t;
93
95
98 QoreString name;
99 QoreString version;
100 QoreString desc;
101 QoreString author;
102 QoreString url;
103 int api_major = -1;
104 int api_minor = -1;
107 qore_module_ns_init_t ns_init = nullptr;
108 qore_module_delete_t del = nullptr;
109 qore_module_parse_cmd_t parse_cmd = nullptr;
110
111 qore_license_t license;
112 QoreString license_str;
113
115 strvec_t dependencies;
116
118 QoreHashNode* info = nullptr;
119
122};
123
125typedef void (*qore_binary_module_desc_t)(QoreModuleInfo& mod_info);
126
128
136public:
137 ModuleManager(const ModuleManager&) = delete;
138 ModuleManager& operator=(const ModuleManager&) = delete;
139
141
144 DLLEXPORT static void addModuleDir(const char* dir);
145
147
150 DLLEXPORT static void addAutoModuleDir(const char* dir);
151
153
156 DLLEXPORT static void addModuleDirList(const char* strlist);
157
159
162 DLLEXPORT static void addAutoModuleDirList(const char* strlist);
163
165 DLLEXPORT static QoreListNode* getModuleList();
166
168 DLLEXPORT static QoreHashNode* getModuleHash();
169
171
179 DLLEXPORT static int runTimeLoadModule(const char* name, ExceptionSink* xsink);
180
182
191 DLLEXPORT static int runTimeLoadModule(const char* name, QoreProgram* pgm, ExceptionSink* xsink);
192
194
208 DLLEXPORT static int runTimeLoadModule(ExceptionSink* xsink, const char* name, QoreProgram* pgm = nullptr,
209 qore_binary_module_desc_t mod_desc_func = nullptr);
210
212
217 DLLEXPORT static QoreStringNode* parseLoadModule(const char* name, QoreProgram* pgm = nullptr);
218
220 DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram* pgm, ExceptionSink* xsink);
221
223 DLLEXPORT static void addStandardModulePaths();
224
226
237 DLLEXPORT int issueRuntimeCmd(const char* mname, QoreProgram* pgm, const QoreString& cmd, ExceptionSink* xsink);
238
239 // not exported in the public API
240 DLLLOCAL ModuleManager();
241};
242
244DLLEXPORT extern ModuleManager MM;
245
246static inline bool is_module_api_supported(int major, int minor) {
247 for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
248 if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
249 return true;
250 return false;
251}
252
253#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:81
DLLEXPORT ModuleManager MM
the global ModuleManager object
QoreStringNode *(* qore_module_init_t)()
signature of the module constructor/initialization function
Definition ModuleManager.h:75
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:125
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition ModuleManager.h:87
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:84
QoreStringNode *(* qore_module_init_info_t)(qore_module_init_info &info)
signature of the module constructor/initialization function with info
Definition ModuleManager.h:78
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:135
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:97
qore_module_init_t init
either init or init_info can be set
Definition ModuleManager.h:106
qore_module_init_info_t init_info
either init or init_info can be set
Definition ModuleManager.h:121
strvec_t dependencies
list of binary modules that this binary module depends on
Definition ModuleManager.h:115
QoreHashNode * info
extra information to appear in the module info hash
Definition ModuleManager.h:118
element of qore_mod_api_list;
Definition ModuleManager.h:52
Module info for the init_info method.
Definition ModuleManager.h:69
std::string path
path to the module itself
Definition ModuleManager.h:71