00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "mmsbase/mmsimportpluginhandler.h"
00034
00035 MMSImportPluginHandler::MMSImportPluginHandler(MMSPluginData plugindata, bool autoload, IMMSImportPlugin *_plugin) :
00036 loaded(false),
00037 initialized(false),
00038 plugindata(plugindata),
00039 plugin(_plugin),
00040 handler(NULL) {
00041 if(plugin)
00042 this->loaded = true;
00043 else if(autoload)
00044 this->load();
00045 }
00046
00047 MMSImportPluginHandler::~MMSImportPluginHandler() {
00048 if (this->loaded) {
00049 delete this->plugin;
00050 if(this->handler) delete this->handler;
00051 }
00052 }
00053
00054 void MMSImportPluginHandler::invokeInitialize(void *data) {
00055 if (!this->loaded)
00056 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not loaded");
00057 if (this->initialized)
00058 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is already initialized");
00059
00060 this->calllock.lock();
00061 this->initialized = this->plugin->initialize(this->plugindata);
00062 this->calllock.unlock();
00063 }
00064
00065 void MMSImportPluginHandler::invokeExecute(void *data) {
00066 if (!this->loaded)
00067 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not loaded");
00068 if (!this->initialized)
00069 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not initialized");
00070
00071 this->calllock.lock();
00072 this->plugin->execute();
00073 this->calllock.unlock();
00074 }
00075
00076 void MMSImportPluginHandler::invokeShutdown(void *data) {
00077 if (!this->loaded)
00078 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not loaded");
00079 if (!this->initialized)
00080 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not initialized");
00081
00082 this->calllock.lock();
00083 this->plugin->shutdown();
00084 this->calllock.unlock();
00085 }
00086
00087 void MMSImportPluginHandler::invokeCleanUp(void *data) {
00088 if (!this->loaded)
00089 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not loaded");
00090 if (!this->initialized)
00091 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not initialized");
00092
00093 this->calllock.lock();
00094 this->plugin->cleanUp();
00095 this->calllock.unlock();
00096 }
00097
00098 bool MMSImportPluginHandler::isLoaded() {
00099 return this->loaded;
00100 }
00101
00102 bool MMSImportPluginHandler::isInitialized() {
00103 return this->initialized;
00104 }
00105
00106 void MMSImportPluginHandler::load() {
00107 if (this->loaded)
00108 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is already loaded");
00109
00110 this->handler = new MMSShlHandler(this->plugindata.getFilename());
00111 this->handler->open();
00112 NEWIMPORTPLUGIN_PROC newproc = (NEWIMPORTPLUGIN_PROC)this->handler->getFunction("newImportPlugin");
00113 this->plugin = newproc();
00114
00115 if (this->plugin)
00116 this->loaded = true;
00117 }
00118
00119 void MMSImportPluginHandler::unload() {
00120 if (!this->loaded)
00121 throw MMSImportPluginError(0,"Import Plugin " + this->plugindata.getName() + " is not loaded");
00122
00123 if(this->plugin) {
00124 delete this->plugin;
00125 this->plugin = NULL;
00126 }
00127
00128 if(this->handler) {
00129 delete this->handler;
00130 this->handler = NULL;
00131 }
00132
00133 this->loaded = false;
00134 this->initialized = false;
00135 }
00136
00137 void MMSImportPluginHandler::setPluginData(MMSPluginData plugindata) {
00138 this->plugindata = plugindata;
00139 }
00140
00141 MMSPluginData MMSImportPluginHandler::getPluginData() {
00142 return this->plugindata;
00143 }