Qore Programming Language  0.8.9
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 2003 - 2014 David Nichols
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 
24 #ifndef _QORE_MODULEMANAGER_H
25 
26 #define _QORE_MODULEMANAGER_H
27 
28 #include <qore/QoreThreadLock.h>
29 #include <qore/QoreString.h>
30 
31 #include <vector>
32 
37 #define QORE_MODULE_API_MAJOR 0
38 #define QORE_MODULE_API_MINOR 18
39 
40 #define QORE_MODULE_COMPAT_API_MAJOR 0
41 #define QORE_MODULE_COMPAT_API_MINOR 18
42 
43 struct qore_mod_api_compat_s {
45  unsigned char major;
46  unsigned char minor;
47 };
48 
50 DLLEXPORT extern const qore_mod_api_compat_s *qore_mod_api_list;
51 
53 DLLEXPORT extern const unsigned qore_mod_api_list_len;
54 
55 class QoreNamespace;
56 class QoreStringNode;
57 class QoreListNode;
58 class ExceptionSink;
59 
61 typedef QoreStringNode *(*qore_module_init_t)();
62 
64 typedef void (*qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns);
65 
67 typedef void (*qore_module_delete_t)();
68 
70 typedef void (*qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink);
71 
72 enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
73  MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
74 
76 
84 private:
86  DLLLOCAL ModuleManager(const ModuleManager&);
87 
89  DLLLOCAL ModuleManager& operator=(const ModuleManager&);
90 
91 public:
93 
96  DLLEXPORT static void addModuleDir(const char *dir);
97 
99 
102  DLLEXPORT static void addAutoModuleDir(const char *dir);
103 
105 
108  DLLEXPORT static void addModuleDirList(const char *strlist);
109 
111 
114  DLLEXPORT static void addAutoModuleDirList(const char *strlist);
115 
117  DLLEXPORT static QoreListNode *getModuleList();
118 
120  DLLEXPORT static QoreHashNode *getModuleHash();
121 
123 
131  DLLEXPORT static int runTimeLoadModule(const char *name, ExceptionSink *xsink);
132 
134 
143  DLLEXPORT static int runTimeLoadModule(const char *name, QoreProgram* pgm, ExceptionSink *xsink);
144 
146 
151  DLLEXPORT static QoreStringNode *parseLoadModule(const char *name, QoreProgram *pgm = 0);
152 
154  DLLEXPORT void registerUserModuleFromSource(const char* name, const char* src, QoreProgram *pgm, ExceptionSink* xsink);
155 
157  DLLEXPORT static void addStandardModulePaths();
158 
159  // not exported in the public API
160  DLLLOCAL ModuleManager();
161 };
162 
164 DLLEXPORT extern ModuleManager MM;
165 
166 static inline bool is_module_api_supported(int major, int minor) {
167  for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
168  if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
169  return true;
170  return false;
171 }
172 
173 #endif // _QORE_MODULEMANAGER_H
static DLLEXPORT QoreListNode * getModuleList()
retuns a list of module information hashes, caller owns the list reference returned ...
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:41
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:50
void(* qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns)
signature of the module namespace change/delta function
Definition: ModuleManager.h:64
Qore&#39;s string type supported by the QoreEncoding class.
Definition: QoreString.h:42
Qore&#39;s string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:40
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:83
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:44
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:95
container for holding Qore-language exception information and also for registering a &quot;thread_exit&quot; ca...
Definition: ExceptionSink.h:35
element of qore_mod_api_list;
Definition: ModuleManager.h:44
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
void(* qore_module_delete_t)()
signature of the module destructor function
Definition: ModuleManager.h:67
DLLEXPORT const unsigned qore_mod_api_list_len
number of elements in qore_mod_api_list;
void(* qore_module_parse_cmd_t)(const QoreString &cmd, ExceptionSink *xsink)
signature of the module parse command function
Definition: ModuleManager.h:70