Exemplo n.º 1
0
void GLWidget::loadPlugins(const QStringList& list) {
    QStringList::ConstIterator it = list.constBegin();
    while(it != list.constEnd()) 
    {
        QString name = *it;
        QPluginLoader *loader = new QPluginLoader(name);
        if (! loader->load()) {
        	  qDebug() << "Could not load plugin " << name << "\n";
                qDebug() << loader->errorString() << "\n";

	        }
        if (loader->isLoaded()) 
        {
            qDebug() << "Loaded plugin: " << loader->fileName(); // << 	endl;
            QObject *plugin = loader->instance();
            if (plugin) 
            {
                plugins.push_back(loader); 
                BasicPlugin *plugin = qobject_cast<BasicPlugin *>(loader->instance());
                // initialize plugin
                if (plugin)
                {
                    plugin->setWidget(this);
                    plugin->setArgs(mainArgs);
                    plugin->onPluginLoad();
                    if (plugin->drawScene()) // overrides drawScene?
                        drawPlugin = plugin;
                }
            }
        }
        else 
        {
            qDebug() << "Load error: " << name << endl;
	        delete loader;
        }
        
        ++it;
    }

    // make sure all plugins know about the latest plugin that overrides drawScene
    for (unsigned int i=0; i<plugins.size(); ++i)
    {
        BasicPlugin *plugin = qobject_cast<BasicPlugin *>(plugins[i]->instance());
        if (plugin)
            plugin->setDrawPlugin(drawPlugin);
        else
        {
            qDebug() << "Error: the plugin must implement the BasicPlugin interface" << endl <<
            " Example: " << endl << 
            "   Q_INTERFACES(BasicPlugin)" << endl;
        }
    }

    resetCamera();
}
Exemplo n.º 2
0
void tst_QPluginLoader::reloadPlugin()
{
    QPluginLoader loader;
    loader.setFileName( sys_qualifiedLibraryName("theplugin"));     //a plugin
    loader.load(); // not recommended, instance() should do the job.
    PluginInterface *instance = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance);
    QCOMPARE(instance->pluginName(), QLatin1String("Plugin ok"));

    QSignalSpy spy(loader.instance(), SIGNAL(destroyed()));
    QVERIFY(spy.isValid());
    QVERIFY(loader.unload());   // refcount reached 0, did really unload
    QCOMPARE(spy.count(), 1);

    // reload plugin
    QVERIFY(loader.load());
    QVERIFY(loader.isLoaded());

    PluginInterface *instance2 = qobject_cast<PluginInterface*>(loader.instance());
    QVERIFY(instance2);
    QCOMPARE(instance2->pluginName(), QLatin1String("Plugin ok"));

    QVERIFY(loader.unload());
}
Exemplo n.º 3
0
void PluginManager::loadAllPlugins(EnvisionManager& envisionManager)
{
	int lastCountLoaded = -1;

	// Holds the ids of plugins which are not yet loaded.
	QStringList plugins;
	for (auto p_meta : pluginMetaData)
		plugins.append(p_meta.id);

	QTextStream out(stdout);

	while ( lastCountLoaded != loadedPlugins.length() && loadedPlugins.length() < pluginMetaData.length() )
	{
		lastCountLoaded = loadedPlugins.length();

		for (int i = plugins.length() - 1; i >= 0; i--)
		{
			QList<PluginDependency> depList = idToMetaDataMap.value(plugins.at(i))->dependencies;

			bool allDependenciesLoaded = true;
			for (QList<PluginDependency>::iterator dep = depList.begin(); dep != depList.end(); dep++)
			{
				// Check if this dependency is already loaded
				if ( idToPluginLoaderMap.contains(dep->id) == false )
				{
					allDependenciesLoaded = false;
					break;
				}

				// Check if the version of the non-dependent plugin matches the version the current plugin depends on
				if ( !idToMetaDataMap.value(dep->id)->version.startsWith(dep->majorVersion + ".", Qt::CaseSensitive) )
					throw EnvisionException("Plugin " + plugins.at(i) + " depends on version " + dep->majorVersion
							+ " of " + dep->id + " but a different version is installed.");
			}

			if ( allDependenciesLoaded )
			{
				out << "Loading plug-in " << plugins.at(i) << "... " << endl;

				QPluginLoader* plugin = new QPluginLoader(pluginsDir.absoluteFilePath(getLibraryFileName(plugins.at(i))));
				plugin->setLoadHints(QLibrary::ExportExternalSymbolsHint);

				plugin->load();

				if ( plugin->isLoaded() == false )
					throw EnvisionException("Could not load plugin: " + plugin->errorString());

				EnvisionPlugin* p = qobject_cast<EnvisionPlugin*> (plugin->instance());
				p->initialize(envisionManager);

				out << plugins.at(i) << " loaded OK" << endl;

				loadedPlugins.append(plugin);
				idToPluginLoaderMap.insert(plugins.at(i), plugin);
				plugins.removeAt(i);
			}
		}
	}

	// Check if there are any plug-ins with unmet dependencies
	if (plugins.size() > 0)
	{
		out<< "Warning: The following plug-ins have not been loaded because their dependencies are not satisfied" << endl;
		for (int i = 0; i< plugins.size(); ++i) out << "  " << plugins.at(i) << endl;
	}
	else out << "All plug-ins loaded." << endl;
}
Exemplo n.º 4
0
/**
 * @brief Avr_Core_Builder::loadCore Loads the core described by the configuration file at the path mmcu
 * @param mmcu The path for the configuration file
 * @return
 */
Avr_Core* Avr_Core_Builder::loadCore(QString mmcu){
    //Loader to open plugins
    QPluginLoader loader;
    core = new Avr_Core();
    //Setup the Basics
    core->setMemory(new Avr_Memory);
    core->setRegisters(new Avr_Registers);

    //Load Configuration File
    string line;string id;string setting;

    QString path = PLUGIN_PATH + mmcu;
    ifstream configFile;
    configFile.open(path.toStdString().c_str());

    if (configFile.is_open()){
        //Process config file, there might be a problem
        //with the loop termination here
        while (!configFile.eof()){
            configFile >> line;
            if (line == "END"){
                break;
            }

            if (line[0]==';'){
                //Line is a comment skip
                continue;
            }
            int i = line.find(':');
            id = line.substr(0,i);
            setting = line.substr(i + 1, line.size() - i - 1);
            if (id == "RAMSIZE"){
                qDebug() << "Load Ram\n";
                core->mem->initRam(sizeToInt(setting) + 0xff);
                core->reg->setRam(core->mem->getRam());
				core->reg->setRamEnd(core->mem->getRamEnd());
            }else if (id == "FLASHSIZE"){
                qDebug() << "Load Flash\n";
                core->setFlash(new Avr_Flash(sizeToInt(setting)));

            }else if (id == "EPROMSIZE"){
                qDebug() << "Load Eprom\n";
                core->mem->initEprom(sizeToInt(setting));

            }else if (id == "SPL"){
                qDebug() << "Set SPL\n";
                core->reg->setStackPL(getRegPtr(setting));

            }else if (id == "SPH"){
                qDebug() << "Set SPH\n";
                core->reg->setStackPH(getRegPtr(setting));

            }else if (id == "SREG"){
                core->reg->setSREGP(getRegPtr(setting));

            }else if (id == "PLUGINLIB"){

                qDebug() << "Load Plugin " << QString(setting.c_str()) << "\n";
                loader.setFileName(PLUGIN_PATH + QString(setting.c_str()));
                loader.load();

                QObject *plugin = loader.instance();

                Avr_Hardware_Interface *h = qobject_cast<Avr_Hardware_Interface*>(plugin);

                //Attach all registers
                h->attachRegister(core->reg);

                //Load Registers for the plugin
                //this loads specific registers for specific roles
                for (int j = 0; j < h->getRegisterCount();j++){
                    configFile >> line;
                    if (line[0]==';'){
                        j -= 1;
                        continue;
                    }
                    i = line.find(':');
                    id = line.substr(0,i);
                    setting = line.substr(i + 1, line.size() - i - 1);
                    qDebug() << "Setting " << QString(setting.c_str()) << "\n";
                    h->bindRegister(QString(id.c_str()),getRegPtr(setting));
                   //h->bindRegister(QString(id.c_str()),getRegLoc(setting));
                }
                //Load Interrupts

                core->hardware.push_back(h);
            }else if (id == "INTERFACE"){
                loader.setFileName(QString(setting.c_str()));
                loader.load();
                QList <QObject*> objects = loader.staticInstances();
                if (loader.isLoaded()){
                    std::cout << "Loaded\n";
                }else{
                    std::cout << "Object Count " << objects.size() <<"\n";
                }
                QObject *plugin = loader.instance();
                //Set the Interface;
                this->interface = qobject_cast<Avr_Hardware_Interface*>(plugin);
            }
        }