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

mmseventdispatcher.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 "mmscore/mmseventdispatcher.h"
00034 #include "mmscore/mmseventthread.h"
00035 
00036 
00037 MMSEventDispatcher::MMSEventDispatcher(MMSPluginManager *manager,MMSEventSignupManager *signupmanager) {
00038     this->manager = manager;
00039     this->signupmanager = signupmanager;
00040 }
00041 
00042 MMSEventDispatcher::~MMSEventDispatcher() {
00043 }
00044 
00045 void MMSEventDispatcher::raise(_IMMSEvent *event, int id) {
00046     MMSEventThread *thread;
00047     vector <MMSOSDPluginHandler *> osdHandlers;
00048     vector <MMSCentralPluginHandler *> centralHandlers;
00049     vector <MMSBackendPluginHandler *> backendHandlers;
00050     vector <MMSPluginData *> plugins;
00051     vector <sigc::signal<void, _IMMSEvent*> *> mysignals;
00052     IMMSEvent e(event);
00053 
00054     if (id > 0) {
00055         DEBUGMSG("MMSEventdispatcher", "have a direct receiver");
00056         try {
00057             thread = new MMSEventThread(this->getManager()->getOSDPluginHandler(id), e);
00058         } catch(MMSError &error) {
00059             thread = new MMSEventThread(this->getManager()->getCentralPluginHandler(id), e);
00060         }
00061         thread->start();
00062     } else {
00063         DEBUGMSG("MMSEventdispatcher", "get receiver plugins");
00064         /* get all receiver plugins */
00065         try {
00066             plugins = this->getSignupManager()->getReceiverPlugins(event);
00067 
00068             DEBUGMSG("MMSEventdispatcher", "filter the osd handler");
00069             /* get all osd handlers */
00070             osdHandlers = getManager()->getOSDPluginHandlers(plugins);
00071             for(unsigned int i=0; i<osdHandlers.size();i++) {
00072                 DEBUGMSG("MMSEventdispatcher", "%s --> create new event thread for %s.", (osdHandlers.at(i))->getPluginData().getName().c_str(), event->getHeading().c_str());
00073                 /* start the threads */
00074                 thread = new MMSEventThread(osdHandlers.at(i), e);
00075                 thread->start();
00076             }
00077 
00078             DEBUGMSG("MMSEventdispatcher", "filter the central handler");
00079             /* get all central handlers */
00080             centralHandlers = getManager()->getCentralPluginHandlers(plugins);
00081             for(unsigned int i=0; i<centralHandlers.size();i++) {
00082                 DEBUGMSG("MMSEventdispatcher", "%s --> create new event thread for %s", (centralHandlers.at(i))->getPluginData().getName().c_str(), event->getHeading().c_str());
00083                 /* start the threads */
00084                 thread = new MMSEventThread(centralHandlers.at(i), e);
00085                 thread->start();
00086             }
00087 
00088             DEBUGMSG("MMSEventdispatcher", "filter the backend handler");
00089             /* get all central handlers */
00090             backendHandlers = getManager()->getBackendPluginHandlers(plugins);
00091             for(unsigned int i=0; i<backendHandlers.size();i++) {
00092                 /* start the threads */
00093                 DEBUGMSG("MMSEventdispatcher", "%s --> create new event thread for %s.", (backendHandlers.at(i))->getPluginData().getName().c_str(), event->getHeading().c_str());
00094                 thread = new MMSEventThread(backendHandlers.at(i), e);
00095                 thread->start();
00096             }
00097 
00098         } catch (MMSEventSignupManagerError &err) {
00099             DEBUGMSG("MMSEventdispatcher", "Error: %s", err.getMessage().c_str());
00100             DEBUGMSG("MMSEventdispatcher", "try signal receivers");
00101         }
00102 
00103         // go for receiver signals
00104         try {
00105             mysignals = this->getSignupManager()->getReceiverSignals(event);
00106             for(vector <sigc::signal<void, _IMMSEvent*> *>::iterator it = mysignals.begin(); it != mysignals.end();it++) {
00107                 (*it)->emit(event);
00108             }
00109         } catch (MMSEventSignupManagerError &err) {
00110             DEBUGMSG("MMSEventdispatcher", "Error: %s", err.getMessage().c_str());
00111             return;
00112         }
00113 
00114         //get rid of the allocated plugindata
00115         for(vector<MMSPluginData *>::iterator it = plugins.begin(); it != plugins.end(); ++it)
00116             delete *it;
00117 
00118         plugins.clear();
00119     }
00120 }
00121 
00122 MMSPluginManager *MMSEventDispatcher::getManager() {
00123     return this->manager;
00124 }
00125 MMSEventSignupManager *MMSEventDispatcher::getSignupManager() {
00126     return this->signupmanager;
00127 }

Generated by doxygen