00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _QORE_MODULEMANAGER_H
00025
00026 #define _QORE_MODULEMANAGER_H
00027
00028 #include <qore/QoreThreadLock.h>
00029 #include <qore/QoreString.h>
00030
00031 #include <vector>
00032
00037 #define QORE_MODULE_API_MAJOR 0
00038 #define QORE_MODULE_API_MINOR 9
00039
00040 #define QORE_MODULE_COMPAT_API_MAJOR 0
00041 #define QORE_MODULE_COMPAT_API_MINOR 9
00042
00044 struct qore_mod_api_compat_s {
00045 unsigned char major;
00046 unsigned char minor;
00047 };
00048
00050 DLLEXPORT extern const qore_mod_api_compat_s *qore_mod_api_list;
00051
00053 DLLEXPORT extern const unsigned qore_mod_api_list_len;
00054
00055 class QoreNamespace;
00056 class QoreStringNode;
00057 class QoreListNode;
00058 class ExceptionSink;
00059
00061 typedef QoreStringNode *(*qore_module_init_t)();
00062
00064 typedef void (*qore_module_ns_init_t)(QoreNamespace *root_ns, QoreNamespace *qore_ns);
00065
00067 typedef void (*qore_module_delete_t)();
00068
00070 class version_list_t : public std::vector<int> {
00071 private:
00072 QoreString ver;
00073 public:
00074 DLLLOCAL char set(const char *v);
00075 DLLLOCAL const char *getString() const { return ver.getBuffer(); }
00076 };
00077
00078 class ModuleInfo;
00079
00080 enum mod_op_e { MOD_OP_NONE, MOD_OP_EQ, MOD_OP_GT,
00081 MOD_OP_GE, MOD_OP_LT, MOD_OP_LE };
00082
00084
00091 class ModuleManager {
00092 private:
00093 DLLLOCAL static void add(ModuleInfo *m);
00094 DLLLOCAL static void addBuiltin(const char *fn, qore_module_init_t init, qore_module_ns_init_t ns_init, qore_module_delete_t del);
00095 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);
00096 DLLLOCAL static QoreStringNode *loadModuleIntern(const char *name, QoreProgram *pgm, mod_op_e op = MOD_OP_NONE, version_list_t *version = 0);
00097 DLLLOCAL static QoreStringNode *loadModuleFromPath(const char *path, const char *feature = 0, ModuleInfo **mi = 0, QoreProgram *pgm = 0);
00098 DLLLOCAL static ModuleInfo *find(const char *name);
00099 DLLLOCAL static void globDir(const char *dir);
00100 DLLLOCAL static QoreStringNode *parseLoadModuleIntern(const char *name, QoreProgram *pgm = 0);
00101
00103 DLLLOCAL ModuleManager(const ModuleManager&);
00104
00106 DLLLOCAL ModuleManager& operator=(const ModuleManager&);
00107
00108 public:
00110
00113 DLLEXPORT static void addModuleDir(const char *dir);
00114
00116
00119 DLLEXPORT static void addAutoModuleDir(const char *dir);
00120
00122
00125 DLLEXPORT static void addModuleDirList(const char *strlist);
00126
00128
00131 DLLEXPORT static void addAutoModuleDirList(const char *strlist);
00132
00134 DLLEXPORT static QoreListNode *getModuleList();
00135
00137
00143 DLLEXPORT static int runTimeLoadModule(const char *name, ExceptionSink *xsink);
00144
00146
00151 DLLEXPORT static QoreStringNode *parseLoadModule(const char *name, QoreProgram *pgm = 0);
00152
00154
00156 DLLLOCAL ModuleManager();
00157
00159
00161 DLLLOCAL static void init(bool se);
00162
00164
00166 DLLLOCAL static void cleanup();
00167 };
00168
00170 DLLEXPORT extern ModuleManager MM;
00171
00172 static inline bool is_module_api_supported(int major, int minor) {
00173 for (unsigned i = 0; i < qore_mod_api_list_len; ++i)
00174 if (qore_mod_api_list[i].major == major && qore_mod_api_list[i].minor == minor)
00175 return true;
00176 return false;
00177 }
00178
00179 #endif // _QORE_MODULEMANAGER_H