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

mmsbackendpluginhandler.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/mmsbackendpluginhandler.h"
00034 
00035 MMSBackendPluginHandler::MMSBackendPluginHandler(MMSPluginData plugindata, bool autoload, IMMSBackendPlugin *_plugin) :
00036     loaded(false),
00037     initialized(false),
00038     plugindata(plugindata),
00039     plugin(_plugin),
00040     handler(NULL),
00041     switcher(NULL) {
00042     if(plugin)
00043         this->loaded = true;
00044     else if(autoload)
00045         this->load();
00046 }
00047 
00048 MMSBackendPluginHandler::~MMSBackendPluginHandler() {
00049     if (this->loaded) {
00050         delete this->plugin;
00051         if(this->handler) delete this->handler;
00052     }
00053 }
00054 
00055 void MMSBackendPluginHandler::invokeInitialize(void *data) {
00056     if (!this->loaded)
00057         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not loaded");
00058     if (this->initialized)
00059         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is already initialized");
00060 
00061     this->calllock.lock();
00062     this->initialized = this->plugin->initialize(this->plugindata, this->switcher);
00063     this->calllock.unlock();
00064 }
00065 
00066 void MMSBackendPluginHandler::invokeOnEvent(IMMSEvent event) {
00067     if (!this->loaded)
00068         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not loaded");
00069     if (!this->initialized)
00070         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not initialized");
00071 
00072     this->calllock.lock();
00073     this->plugin->onEvent(event);
00074     this->calllock.unlock();
00075 }
00076 
00077 void MMSBackendPluginHandler::invokeShutdown(void *data) {
00078     if (!this->loaded)
00079         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not loaded");
00080     if (!this->initialized)
00081         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not initialized");
00082 
00083     this->calllock.lock();
00084     this->plugin->shutdown();
00085     this->calllock.unlock();
00086 }
00087 
00088 bool MMSBackendPluginHandler::isLoaded() {
00089     return this->loaded;
00090 }
00091 
00092 bool MMSBackendPluginHandler::isInitialized() {
00093     return this->initialized;
00094 }
00095 
00096 void MMSBackendPluginHandler::load() {
00097     if (this->loaded)
00098         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is already loaded");
00099 
00100     this->handler = new MMSShlHandler(this->plugindata.getFilename());
00101     this->handler->open();
00102     NEWBACKENDPLUGIN_PROC newproc = (NEWBACKENDPLUGIN_PROC)this->handler->getFunction("newBackendPlugin");
00103     this->plugin = newproc();
00104 
00105     if(this->plugin)
00106         this->loaded = true;
00107 }
00108 
00109 void MMSBackendPluginHandler::unload() {
00110     if (!this->loaded)
00111         throw MMSBackendPluginError(0,"Backend Plugin " + this->plugindata.getName() + " is not loaded");
00112 
00113     if(this->plugin) {
00114         delete this->plugin;
00115         this->plugin = NULL;
00116     }
00117 
00118     if(this->handler) {
00119         delete this->handler;
00120         this->handler = NULL;
00121     }
00122 
00123     this->loaded = false;
00124     this->initialized = false;
00125 }
00126 
00127 void MMSBackendPluginHandler::setPluginData(MMSPluginData plugindata) {
00128     this->plugindata = plugindata;
00129 }
00130 
00131 MMSPluginData MMSBackendPluginHandler::getPluginData() {
00132     return this->plugindata;
00133 }
00134 
00135 void MMSBackendPluginHandler::setSwitcherInterface(IMMSSwitcher *switcher) {
00136     this->switcher = switcher;
00137 }
00138 

Generated by doxygen