ModuleManager.h
Go to the documentation of this file.
/* -*- mode: c++; indent-tabs-mode: nil -*- */
/*
ModuleManager.h
Qore Programming Language
Copyright (C) 2003 - 2020 Qore Technologies, s.r.o.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Note that the Qore library is released under a choice of three open-source
licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
information.
*/
#ifndef _QORE_MODULEMANAGER_H
#define _QORE_MODULEMANAGER_H
#include <qore/QoreThreadLock.h>
#include <qore/QoreString.h>
#include <vector>
#define QORE_MODULE_API_MAJOR 0
#define QORE_MODULE_API_MINOR 23
#define QORE_MODULE_COMPAT_API_MAJOR 0
#define QORE_MODULE_COMPAT_API_MINOR 23
struct qore_mod_api_compat_s {
unsigned char major;
unsigned char minor;
};
DLLEXPORT extern const qore_mod_api_compat_s *qore_mod_api_list;
DLLEXPORT extern const unsigned qore_mod_api_list_len;
class QoreNamespace;
class QoreStringNode;
class QoreListNode;
class ExceptionSink;
typedef QoreStringNode *(*qore_module_init_t)();
typedef void (*qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns);
typedef void (*qore_module_delete_t)();
typedef void (*qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink);
enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
class ModuleManager {
public:
ModuleManager(const ModuleManager&) = delete;
ModuleManager& operator=(const ModuleManager&) = delete;
DLLEXPORT static void addModuleDir(const char *dir);
DLLEXPORT static void addAutoModuleDir(const char *dir);
DLLEXPORT static void addModuleDirList(const char *strlist);
DLLEXPORT static void addAutoModuleDirList(const char *strlist);
DLLEXPORT static QoreListNode *getModuleList();
DLLEXPORT static QoreHashNode *getModuleHash();
DLLEXPORT static int runTimeLoadModule(const char *name, ExceptionSink *xsink);
DLLEXPORT static int runTimeLoadModule(const char *name, QoreProgram* pgm, ExceptionSink *xsink);
DLLEXPORT static QoreStringNode *parseLoadModule(const char *name, QoreProgram *pgm = 0);
DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram *pgm, ExceptionSink* xsink);
DLLEXPORT static void addStandardModulePaths();
// not exported in the public API
DLLLOCAL ModuleManager();
};
DLLEXPORT extern ModuleManager MM;
static inline bool is_module_api_supported(int major, int minor) {
for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
return true;
return false;
}
#endif // _QORE_MODULEMANAGER_H
qore_module_parse_cmd_t
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition: ModuleManager.h:78
qore_module_ns_init_t
void(* qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns)
signature of the module namespace change/delta function
Definition: ModuleManager.h:72
ModuleManager::addStandardModulePaths
static DLLEXPORT void addStandardModulePaths()
adds the standard module directories to the module path (only necessary if the module paths are set u...
qore_mod_api_compat_s
element of qore_mod_api_list;
Definition: ModuleManager.h:52
QoreProgram
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only
Definition: QoreProgram.h:126
QoreHashNode
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
ModuleManager::getModuleList
static DLLEXPORT QoreListNode * getModuleList()
retuns a list of module information hashes, caller owns the list reference returned
ModuleManager::parseLoadModule
static DLLEXPORT QoreStringNode * parseLoadModule(const char *name, QoreProgram *pgm=0)
loads the named module at parse time (or before run time, even if parsing is not active),...
ModuleManager::registerUserModuleFromSource
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
QoreListNode
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
QoreNamespace
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:64
qore_mod_api_list_len
DLLEXPORT const unsigned qore_mod_api_list_len
number of elements in qore_mod_api_list;
ModuleManager
manages the loading of Qore modules from feature or path names. Also manages adding module changes in...
Definition: ModuleManager.h:91
QoreString
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
ModuleManager::addModuleDirList
static DLLEXPORT void addModuleDirList(const char *strlist)
to add a list of directories separated by ':' characters to the QORE_MODULE_DIR list,...
ModuleManager::addAutoModuleDir
static DLLEXPORT void addAutoModuleDir(const char *dir)
no longer supported - removed for security reasons
ExceptionSink
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
ModuleManager::addAutoModuleDirList
static DLLEXPORT void addAutoModuleDirList(const char *strlist)
no longer supported - removed for security reasons
qore_module_delete_t
void(* qore_module_delete_t)()
signature of the module destructor function
Definition: ModuleManager.h:75
ModuleManager::getModuleHash
static DLLEXPORT QoreHashNode * getModuleHash()
retuns a hash of module information hashes, caller owns the list reference returned
ModuleManager::addModuleDir
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...
qore_mod_api_list
DLLEXPORT const qore_mod_api_compat_s * qore_mod_api_list
list of module APIs this library supports
QoreStringNode
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
MM
DLLEXPORT ModuleManager MM
the global ModuleManager object
ModuleManager::runTimeLoadModule
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