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

mmsosdpluginhandler.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/mmsosdpluginhandler.h"
00034 
00035 MMSOSDPluginHandler::MMSOSDPluginHandler(MMSPluginData plugindata, bool autoload, IMMSOSDPlugin *_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 MMSOSDPluginHandler::~MMSOSDPluginHandler() {
00049     if (this->loaded) {
00050         delete this->plugin;
00051         if(this->handler) delete this->handler;
00052     }
00053 }
00054 
00055 void MMSOSDPluginHandler::invokeInitialize(void *data) {
00056     if (!this->loaded)
00057         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00058     if (this->initialized)
00059         throw MMSOSDPluginError(0,"OSD 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 MMSOSDPluginHandler::invokeOnEvent(IMMSEvent event) {
00067     if (!this->loaded)
00068         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00069     if (!this->initialized)
00070         throw MMSOSDPluginError(0,"OSD 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 MMSOSDPluginHandler::invokeShutdown(void *data) {
00078     if (!this->loaded)
00079         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00080     if (!this->initialized)
00081         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00082 
00083     this->calllock.lock();
00084     this->plugin->shutdown();
00085     this->calllock.unlock();
00086 }
00087 
00088 void MMSOSDPluginHandler::invokeShowPreview(void *data) {
00089     if (!this->loaded)
00090         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00091     if (!this->initialized)
00092         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00093 
00094     this->calllock.lock();
00095     if (!this->plugin->showPreview(data)) {
00096         this->calllock.unlock();
00097         throw MMSOSDPluginError(1,"OSD Plugin " + this->plugindata.getName() + " has nothing to display (showPreview())");
00098     }
00099     this->calllock.unlock();
00100 }
00101 
00102 void MMSOSDPluginHandler::invokeShow(void *data) {
00103     if (!this->loaded)
00104         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00105     if (!this->initialized)
00106         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not initialized");
00107 
00108     this->calllock.lock();
00109     if (!this->plugin->show(data)) {
00110         this->calllock.unlock();
00111         throw MMSOSDPluginError(1,"OSD Plugin " + this->plugindata.getName() + " has nothing to display (show())");
00112     }
00113     this->calllock.unlock();
00114 }
00115 
00116 bool MMSOSDPluginHandler::isLoaded() {
00117     return this->loaded;
00118 }
00119 
00120 bool MMSOSDPluginHandler::isInitialized() {
00121     return this->initialized;
00122 }
00123 
00124 void MMSOSDPluginHandler::load() {
00125     if (this->loaded)
00126         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is already loaded");
00127 
00128     this->handler = new MMSShlHandler(this->plugindata.getFilename());
00129     this->handler->open();
00130     NEWOSDPLUGIN_PROC newproc = (NEWOSDPLUGIN_PROC)this->handler->getFunction("newOSDPlugin");
00131     this->plugin = newproc();
00132 
00133     if (this->plugin)
00134         this->loaded = true;
00135 }
00136 
00137 void MMSOSDPluginHandler::unload() {
00138     if (!this->loaded)
00139         throw MMSOSDPluginError(0,"OSD Plugin " + this->plugindata.getName() + " is not loaded");
00140 
00141     if(this->plugin) {
00142         delete this->plugin;
00143         this->plugin = NULL;
00144     }
00145 
00146     if(this->handler) {
00147         delete this->handler;
00148         this->handler = NULL;
00149     }
00150 
00151     this->loaded = false;
00152     this->initialized = false;
00153 }
00154 
00155 void MMSOSDPluginHandler::setPluginData(MMSPluginData plugindata) {
00156     this->plugindata = plugindata;
00157 }
00158 
00159 MMSPluginData MMSOSDPluginHandler::getPluginData() {
00160     return this->plugindata;
00161 }
00162 
00163 void MMSOSDPluginHandler::setSwitcherInterface(IMMSSwitcher *switcher) {
00164     this->switcher = switcher;
00165 }

Generated by doxygen