Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsimportpluginhandler.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
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 }

Generated by doxygen