plugins.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QString>
00022 #include <QLibrary>
00023 #include <QStringList>
00024 
00025 #include "funcaux.h"
00026 #include "plugins.h"
00027 
00028 
00029 typedef int (*MyPrototype)(void *);
00030 MyPrototype myFunction;
00031 
00032 typedef int (*MyPrototype1)(void *, void **);
00033 MyPrototype1 myFunction1;
00034 
00035 Plugins *g_plugins;
00036 
00037 
00039 
00041 Plugins::Plugins() {
00042     _depura("Plugins::Plugins", 0);
00043     _depura("END Plugins::Plugins", 0);
00044 }
00045 
00046 
00048 
00050 Plugins::~Plugins() {
00051     _depura("Plugins::~Plugins", 0);
00052     _depura("END Plugins::~Plugins", 0);
00053 }
00054 
00055 
00057 
00060 void Plugins::cargaLibs(const QString libs) {
00062     QString cad = libs;
00063     _depura("Plugins::cargaLibs", 0, cad);
00064     if (cad == "") {
00065         _depura("END Plugins::cargaLibs", 0, cad);
00066         return;
00067     } // end if
00068     QStringList plugins = cad.split(";");
00069     for (QStringList::Iterator it = plugins.begin(); it != plugins.end(); ++it) {
00070         QLibrary *lib = new QLibrary(*it);
00071         lib->load();
00072         if (!lib->isLoaded()) {
00073             mensajeInfo("No se ha podido cargar la libreria: " + *it + "\nERROR: " + lib->errorString());
00074         } else {
00075             m_lista.append(lib);
00076         } // end if
00077     } // end for
00078     _depura("END Plugins::cargaLibs", 0);
00079 }
00080 
00082 
00087 int Plugins::lanza(const char *func, void *clase) {
00088     _depura("Plugins::lanza", 0, func);
00089     int a = 0;
00090     for (int i = 0; i < m_lista.size(); ++i) {
00091         myFunction = (MyPrototype) m_lista.at(i)->resolve(func);
00092         if (myFunction) {
00093             _depura("Plugins_lanza", 0, "Encontrada una funcion correspondiente con el prototipo");
00094             a = myFunction(clase);
00095         } else {
00096             _depura("Plugins_lanza", 0, "No ha entrado la libreria");
00097         } // end if
00098     } // end for
00099     _depura("END Plugins::lanza", 0);
00100     return a;
00101 }
00102 
00103 
00105 
00108 int Plugins::lanza(const char *func, void *clase, void **ret) {
00109     _depura("Plugins::lanza", 0, func);
00110     int a = 0;
00111     for (int i = 0; i < m_lista.size(); ++i) {
00112         myFunction1 = (MyPrototype1) m_lista.at(i)->resolve(func);
00113         if (myFunction1) {
00114             _depura("Plugins_lanza", 0, "Encontrada una funcion correspondiente con el prototipo");
00115             a = myFunction1(clase, ret);
00116         } else {
00117             _depura("Plugins_lanza", 0, "No ha entrado la libreria");
00118         } // end if
00119     } // end for
00120     _depura("END Plugins::lanza", 0);
00121     return a;
00122 }
00123 

Generated on Sat Dec 15 00:01:22 2007 for BulmaGes by  doxygen 1.5.1