Qore Programming Language  0.9.0
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 - 2018 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 0
46 #define QORE_MODULE_API_MINOR 22
47 
48 #define QORE_MODULE_COMPAT_API_MAJOR 0
49 #define QORE_MODULE_COMPAT_API_MINOR 22
50 
51 hashdecl qore_mod_api_compat_s {
53  unsigned char major;
54  unsigned char minor;
55 };
56 
58 DLLEXPORT extern const qore_mod_api_compat_s *qore_mod_api_list;
59 
61 DLLEXPORT extern const unsigned qore_mod_api_list_len;
62 
63 class QoreNamespace;
64 class QoreStringNode;
65 class QoreListNode;
66 class ExceptionSink;
67 
69 typedef QoreStringNode *(*qore_module_init_t)();
70 
72 typedef void (*qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns);
73 
75 typedef void (*qore_module_delete_t)();
76 
78 typedef void (*qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink);
79 
80 enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
81  MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
82 
84 
92 private:
94  DLLLOCAL ModuleManager(const ModuleManager&);
95 
97  DLLLOCAL ModuleManager& operator=(const ModuleManager&);
98 
99 public:
101 
104  DLLEXPORT static void addModuleDir(const char *dir);
105 
107 
110  DLLEXPORT static void addAutoModuleDir(const char *dir);
111 
113 
116  DLLEXPORT static void addModuleDirList(const char *strlist);
117 
119 
122  DLLEXPORT static void addAutoModuleDirList(const char *strlist);
123 
125  DLLEXPORT static QoreListNode *getModuleList();
126 
128  DLLEXPORT static QoreHashNode *getModuleHash();
129 
131 
139  DLLEXPORT static int runTimeLoadModule(const char *name, ExceptionSink *xsink);
140 
142 
151  DLLEXPORT static int runTimeLoadModule(const char *name, QoreProgram* pgm, ExceptionSink *xsink);
152 
154 
159  DLLEXPORT static QoreStringNode *parseLoadModule(const char *name, QoreProgram *pgm = 0);
160 
162  DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram *pgm, ExceptionSink* xsink);
163 
165  DLLEXPORT static void addStandardModulePaths();
166 
167  // not exported in the public API
168  DLLLOCAL ModuleManager();
169 };
170 
172 DLLEXPORT extern ModuleManager MM;
173 
174 static inline bool is_module_api_supported(int major, int minor) {
175  for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
176  if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
177  return true;
178  return false;
179 }
180 
181 #endif // _QORE_MODULEMANAGER_H
static DLLEXPORT QoreListNode * getModuleList()
retuns a list of module information hashes, caller owns the list reference returned ...
void(* qore_module_delete_t)()
signature of the module destructor function
Definition: ModuleManager.h:75
DLLEXPORT const qore_mod_api_compat_s * qore_mod_api_list
list of module APIs this library supports
static DLLEXPORT QoreHashNode * getModuleHash()
retuns a hash 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
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 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
contains constants, classes, and subnamespaces in QoreProgram objects
Definition: QoreNamespace.h:65
void(* qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns)
signature of the module namespace change/delta function
Definition: ModuleManager.h:72
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition: ModuleManager.h:78
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
static DLLEXPORT void addModuleDirList(const char *strlist)
to add a list of directories separated by &#39;:&#39; characters to the QORE_MODULE_DIR list, can only be called before the library initialization function qore_init()
manages the loading of Qore modules from feature or path names. Also manages adding module changes in...
Definition: ModuleManager.h:91
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
static DLLEXPORT void addAutoModuleDir(const char *dir)
no longer supported - removed for security reasons
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), returns a non-0 QoreStringNode pointer if an error occured, caller owns the QoreStringNode pointer&#39;s reference count returned if non-0
supports parsing and executing Qore-language code, reference counted, dynamically-allocated only ...
Definition: QoreProgram.h:126
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
element of qore_mod_api_list;
Definition: ModuleManager.h:52
DLLEXPORT ModuleManager MM
the global ModuleManager object
static DLLEXPORT void addStandardModulePaths()
adds the standard module directories to the module path (only necessary if the module paths are set u...
static DLLEXPORT void addAutoModuleDirList(const char *strlist)
no longer supported - removed for security reasons
DLLEXPORT const unsigned qore_mod_api_list_len
number of elements in qore_mod_api_list;