Qore Programming Language 1.14.2
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 - 2023 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
69typedef QoreStringNode* (*qore_module_init_t)();
70
72typedef void (*qore_module_ns_init_t)(QoreNamespace* root_ns, QoreNamespace* qore_ns);
73
75typedef void (*qore_module_delete_t)();
76
78typedef void (*qore_module_parse_cmd_t)(const QoreString& cmd, ExceptionSink* xsink);
79
80enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
81 MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
82
83typedef std::vector<std::string> strvec_t;
84
86
89 QoreString name;
90 QoreString version;
91 QoreString desc;
92 QoreString author;
93 QoreString url;
94 int api_major = -1;
95 int api_minor = -1;
96 qore_module_init_t init = nullptr;
97 qore_module_ns_init_t ns_init = nullptr;
98 qore_module_delete_t del = nullptr;
99 qore_module_parse_cmd_t parse_cmd = nullptr;
100
101 qore_license_t license;
102 QoreString license_str;
103
105 strvec_t dependencies;
106
108 QoreHashNode* info = nullptr;
109};
110
112typedef void (*qore_binary_module_desc_t)(QoreModuleInfo& mod_info);
113
115
123public:
124 ModuleManager(const ModuleManager&) = delete;
125 ModuleManager& operator=(const ModuleManager&) = delete;
126
128
131 DLLEXPORT static void addModuleDir(const char* dir);
132
134
137 DLLEXPORT static void addAutoModuleDir(const char* dir);
138
140
143 DLLEXPORT static void addModuleDirList(const char* strlist);
144
146
149 DLLEXPORT static void addAutoModuleDirList(const char* strlist);
150
152 DLLEXPORT static QoreListNode* getModuleList();
153
155 DLLEXPORT static QoreHashNode* getModuleHash();
156
158
166 DLLEXPORT static int runTimeLoadModule(const char* name, ExceptionSink* xsink);
167
169
178 DLLEXPORT static int runTimeLoadModule(const char* name, QoreProgram* pgm, ExceptionSink* xsink);
179
181
195 DLLEXPORT static int runTimeLoadModule(ExceptionSink* xsink, const char* name, QoreProgram* pgm = nullptr,
196 qore_binary_module_desc_t mod_desc_func = nullptr);
197
199
204 DLLEXPORT static QoreStringNode* parseLoadModule(const char* name, QoreProgram* pgm = nullptr);
205
207 DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram* pgm, ExceptionSink* xsink);
208
210 DLLEXPORT static void addStandardModulePaths();
211
212 // not exported in the public API
213 DLLLOCAL ModuleManager();
214};
215
217DLLEXPORT extern ModuleManager MM;
218
219static inline bool is_module_api_supported(int major, int minor) {
220 for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
221 if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
222 return true;
223 return false;
224}
225
226#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:72
DLLEXPORT ModuleManager MM
the global ModuleManager object
QoreStringNode *(* qore_module_init_t)()
signature of the module constructor/initialization function
Definition: ModuleManager.h:69
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:112
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition: ModuleManager.h:78
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:75
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:122
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,...
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:50
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:85
Qore module info.
Definition: ModuleManager.h:88
strvec_t dependencies
list of binary modules that this binary module depends on
Definition: ModuleManager.h:105
QoreHashNode * info
extra information to appear in the module info hash
Definition: ModuleManager.h:108
element of qore_mod_api_list;
Definition: ModuleManager.h:52