00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _QORE_MODULEMANAGER_H
00024
00025 #define _QORE_MODULEMANAGER_H
00026
00027 #include <qore/QoreThreadLock.h>
00028 #include <qore/QoreString.h>
00029
00030 #include <vector>
00031
00036 #define QORE_MODULE_API_MAJOR 0
00037 #define QORE_MODULE_API_MINOR 8
00038
00040 struct qore_mod_api_compat_s {
00041 unsigned char major;
00042 unsigned char minor;
00043 };
00044
00046 DLLEXPORT extern const qore_mod_api_compat_s *qore_mod_api_list;
00047
00049 DLLEXPORT extern const unsigned qore_mod_api_list_len;
00050
00051 class QoreNamespace;
00052 class QoreStringNode;
00053 class QoreListNode;
00054 class ExceptionSink;
00055
00057 typedef QoreStringNode *(*qore_module_init_t)();
00058
00060 typedef void (*qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns);
00061
00063 typedef void (*qore_module_delete_t)();
00064
00066 class version_list_t : public std::vector<int> {
00067 private:
00068 QoreString ver;
00069 public:
00070 DLLLOCAL char set(const char *v);
00071 DLLLOCAL const char *getString() const { return ver.getBuffer(); }
00072 };
00073
00074 class ModuleInfo;
00075
00076 enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
00077 MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
00078
00080
00087 class ModuleManager {
00088 private:
00089 DLLLOCAL static void add(ModuleInfo *m);
00090 DLLLOCAL static void addBuiltin(const char *fn, qore_module_init_t init, qore_module_ns_init_t ns_init, qore_module_delete_t del);
00091 DLLLOCAL static ModuleInfo *add(const char *fn, char *n, int major, int minor, qore_module_init_t init, qore_module_ns_init_t ns_init, qore_module_delete_t del, char *d, char *v, char *a, char *u, void *p);
00092 DLLLOCAL static QoreStringNode *loadModuleIntern(const char *name, QoreProgram *pgm, mod_op_e op = MOD_OP_NONE, version_list_t *version = 0);
00093 DLLLOCAL static QoreStringNode *loadModuleFromPath(const char *path, const char *feature = 0, ModuleInfo **mi = 0, QoreProgram *pgm = 0);
00094 DLLLOCAL static ModuleInfo *find(const char *name);
00095 DLLLOCAL static void globDir(const char *dir);
00096 DLLLOCAL static QoreStringNode *parseLoadModuleIntern(const char *name, QoreProgram *pgm = 0);
00097
00099 DLLLOCAL ModuleManager(const ModuleManager&);
00100
00102 DLLLOCAL ModuleManager& operator=(const ModuleManager&);
00103
00104 public:
00106
00109 DLLEXPORT static void addModuleDir(const char *dir);
00110
00112
00115 DLLEXPORT static void addAutoModuleDir(const char *dir);
00116
00118
00121 DLLEXPORT static void addModuleDirList(const char *strlist);
00122
00124
00127 DLLEXPORT static void addAutoModuleDirList(const char *strlist);
00128
00130 DLLEXPORT static QoreListNode *getModuleList();
00131
00133
00139 DLLEXPORT static int runTimeLoadModule(const char *name, ExceptionSink *xsink);
00140
00142
00147 DLLLOCAL static QoreStringNode *parseLoadModule(const char *name, QoreProgram *pgm = 0);
00148
00150
00152 DLLLOCAL ModuleManager();
00153
00155
00157 DLLLOCAL static void init(bool se);
00158
00160
00162 DLLLOCAL static void cleanup();
00163 };
00164
00166 DLLEXPORT extern ModuleManager MM;
00167
00168 DLLLOCAL static inline bool is_module_api_supported(int major, int minor) {
00169 for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
00170 if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
00171 return true;
00172 return false;
00173 }
00174
00175 #endif // _QORE_MODULEMANAGER_H