//----------------------------------------------------------------------------
void ctkPluginFrameworkContext::init()
{
  log() << "initializing";

  if (firstInit && ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT
      == props[ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN])
  {
    deleteFWDir();
    firstInit = false;
  }

  // Pre-load libraries
  // This may speed up installing new plug-ins if they have dependencies on
  // one of these libraries. It prevents repeated loading and unloading of the
  // pre-loaded libraries during caching of the plug-in meta-data.
  if (props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].isValid())
  {
    QStringList preloadLibs = props[ctkPluginConstants::FRAMEWORK_PRELOAD_LIBRARIES].toStringList();
    QLibrary::LoadHints loadHints;
    QVariant loadHintsVariant = props[ctkPluginConstants::FRAMEWORK_PLUGIN_LOAD_HINTS];
    if (loadHintsVariant.isValid())
    {
      loadHints = loadHintsVariant.value<QLibrary::LoadHints>();
    }

    foreach(QString preloadLib, preloadLibs)
    {
      QLibrary lib;
      QStringList nameAndVersion = preloadLib.split(":");

      QString libraryName;
      if (nameAndVersion.count() == 1)
      {
        libraryName = nameAndVersion.front();
        lib.setFileName(nameAndVersion.front());
      }
      else if (nameAndVersion.count() == 2)
      {
        libraryName = nameAndVersion.front() + "." + nameAndVersion.back();
        lib.setFileNameAndVersion(nameAndVersion.front(), nameAndVersion.back());
      }
      else
      {
        qWarning() << "Wrong syntax in" << preloadLib << ". Use <lib-name>[:version]. Skipping.";
        continue;
      }

      lib.setLoadHints(loadHints);
      log() << "Pre-loading library" << lib.fileName() << "with hints [" << static_cast<int>(loadHints) << "]";
      if (!lib.load())
      {
        qWarning() << "Pre-loading library" << lib.fileName() << "failed:" << lib.errorString() << "\nCheck your library search paths.";
      }
    }
Esempio n. 2
0
    bool load()
    {
        m_libUdev.setLoadHints(QLibrary::ResolveAllSymbolsHint);
        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 1);
        m_loaded = m_libUdev.load();
        if (resolveMethods())
            return true;

        m_libUdev.setFileNameAndVersion(QStringLiteral("udev"), 0);
        m_loaded = m_libUdev.load();
        return resolveMethods();
    }
Esempio n. 3
0
void tst_QLibrary::loadHints()
{
    QFETCH( QString, lib );
    QFETCH( int, loadHints);
    QFETCH( bool, result );
    //QLibrary library( lib );
    QLibrary library;
    QLibrary::LoadHints lh(loadHints);
    if (int(loadHints) != 0) {
        lh |= library.loadHints();
        library.setLoadHints(lh);
    }
    library.setFileName(lib);
    QCOMPARE(library.loadHints(), lh);
    bool ok = library.load();
    if ( result ) {
        QVERIFY( ok );
        QVERIFY(library.unload());
    } else {
        QVERIFY( !ok );
    }
}
Esempio n. 4
0
void LocalApp::readSuffixFilter(){
    QFile *suffixFilterFile = 0;
    if ( appName == "home")
        suffixFilterFile = new QFile (home+"/"+QString("home.suffixfilter"));
    else
        suffixFilterFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".suffixfilter"));
    ERR<<"INFO: LocalApp::readSuffixFilter(): "<<suffixFilterFile->fileName()<<endl;
#ifndef USE_QT5
    if ( ! suffixFilterFile->open(QIODevice::ReadOnly) ){
#else
    if ( ! suffixFilterFile->open(QFile::ReadOnly) ){
#endif
        ERR<<"WARN: LocalApp::readSuffixFilter(): Unable to read : "<<suffixFilterFile->fileName()<<endl;
        suffixFilterFile->close();

    }else {
        suffixFilter += suffixFilterFile->readAll();
        suffixFilterFile->close();
    }

    //TODO: convert suffix filter to map of string
    ERR<<"DBUG: LocalApp::readSuffixFilter(): "<<suffixFilter<<endl;
    delete suffixFilterFile;
}

void LocalApp::readLibraryLoadConfig(){
    QFile *llConfigFile = 0;
    if ( appName == "home")
        llConfigFile = new QFile (home+"/"+QString("home.cfg"));
    else
        llConfigFile = new QFile (home+"/"+ appName + "/"+ appName + QString(".cfg"));
#ifndef USE_QT5
    if ( ! llConfigFile->open(QIODevice::ReadOnly) ){
#else
    if ( ! llConfigFile->open(QFile::ReadOnly) ){
#endif
        ERR<<"DBUG: LocalApp::readLibraryLoadConfig(): Unable to open file :"<<llConfigFile->fileName()<<endl;
    } else {
        QByteArray libConfig;
        while ( (libConfig = llConfigFile->readLine() ).length() > 0 ){
            /*
             * Read the config file
             * <scriptname>:<libraryname>
             */
            QString line(libConfig);
            if( line.split(":").length() > 1) {
                QString script = line.split(":")[0];
                QString soFile = line.split(":")[1];
#ifndef WINDOWS
                soFile.replace(QString("\n"), QString(""));
                soFile += QString(".so");
                //soFile.remove(soFile.length()-1,1);
#else
                soFile.replace(QString("\r\n"), QString(""));
                soFile += QString(".dll");
                //soFile.remove(soFile.length()-2,2);
#endif
                if( appName == "home"){
                    QLibrary *lib = new QLibrary( home + "/" + soFile );
                    lib->setLoadHints(QLibrary::ResolveAllSymbolsHint);
                    lib->load();
                    ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<< script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl;
                    mapScriptToSo[script] = lib;

                } else {
                    QLibrary *lib = new QLibrary( home + "/" + appName + "/" + soFile, this );
                    lib->setLoadHints(QLibrary::ResolveAllSymbolsHint);
                    lib->load();
                    ERR<<"ERRR: LocalApp::readLibraryLoadConfig(): "<<script<<" -> "<<lib->fileName()<<": Loaded ? "<<lib->isLoaded()<<endl;
                    mapScriptToSo[script] = lib;
                }
            }
        }
    }

    delete llConfigFile;
}


QString LocalApp::readAppName( QUrl url ){
    QString app("");
#ifndef USE_QT5
    ERR<<"INFO: LocalApp::readAppName(): Encoded Path: "<<url.encodedPath()<<endl;
    //QStringList
    app = url.encodedPath().split('/')[0];
    //app = list[0];
    if ( app.contains(".py")){
       app = "home";
    }
    ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl;
#else
    ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl;
    app = url.path().split('/')[0];
    if ( app.contains(".py") || app.contains(".")){
        app = "home";
    }
    ERR<<"INFO: LocalApp::readAppName(): App: "<<app<<endl;
    ERR<<"INFO: LocalApp::readAppName(): Path: "<<url.path()<<endl;
#endif
    return app;
}
bool KviModuleManager::loadModule(const QString &modName)
{
	if(findModule(modName))
	{
		//qDebug("MODULE %s ALREADY IN CORE MEMORY",modName);
		return true;
	}
	QString tmp;
	QString szName;
#if defined(COMPILE_ON_WINDOWS)
	KviQString::appendFormatted(szName,"kvi%Q.dll",&modName);
#elif defined(COMPILE_ON_MINGW)
	KviQString::appendFormatted(szName,"libkvi%Q.dll",&modName);
#else
	KviQString::appendFormatted(szName,"libkvi%Q.so",&modName);
#endif
	szName=szName.toLower();

	g_pApp->getLocalKvircDirectory(tmp,KviApplication::Modules,szName);
	if(!KviFileUtils::fileExists(tmp))
	{
		g_pApp->getGlobalKvircDirectory(tmp,KviApplication::Modules,szName);
	}

	QLibrary* pLibrary = new QLibrary(tmp);
	pLibrary->setLoadHints(QLibrary::ExportExternalSymbolsHint);

	if(!pLibrary->load())
	{
		m_szLastError = pLibrary->errorString();
		delete pLibrary;
		return false;
	}
	KviModuleInfo * info = (KviModuleInfo *)pLibrary->resolve(KVIRC_MODULE_STRUCTURE_SYMBOL);
	if(!info)
	{
		m_szLastError = __tr2qs("No " KVIRC_MODULE_STRUCTURE_SYMBOL " symbol exported: not a kvirc module ?");
		pLibrary->unload();
		delete pLibrary;
		return false;
	}
	if(!info->szKVIrcVersion)
	{
		m_szLastError = __tr2qs("This module has no version information: refusing to load it");
		pLibrary->unload();
		delete pLibrary;
		return false;
	}
	if(!KVI_OPTION_BOOL(KviOption_boolIgnoreModuleVersions))
	{
		if(!kvi_strEqualCS(info->szKVIrcVersion,KVI_VERSION))
		{
			m_szLastError = __tr2qs("This module was compiled for a different KVIrc version and can't be loaded");
			m_szLastError += " (";
			m_szLastError += info->szKVIrcVersion;
			m_szLastError += ")";
			pLibrary->unload();
			delete pLibrary;
			return false;
		}
	}
	KviModule * module = new KviModule(pLibrary,info,modName,szName.toUtf8().data());

	// the module is probably up.. the only thing can fail is the init_routine now
	
	// load the message catalogue if any
	if(info->szModuleContext)
	{
		QString szDir;
		// it's more probable to have the translations in the global directory
		// try it as first... (yes, catalogue overriding is impossible this way.. but, anybody cares ?)
		g_pApp->getGlobalKvircDirectory(szDir,KviApplication::Locale);

		if(!KviLocale::instance()->loadCatalogue(info->szModuleContext,szDir))
		{
			// try the local directory then
			g_pApp->getLocalKvircDirectory(szDir,KviApplication::Locale);
			KviLocale::instance()->loadCatalogue(info->szModuleContext,szDir);
		}
	}
	
	if(info->init_routine)
	{
		if(!((info->init_routine)(module)))
		{
			m_szLastError = __tr2qs("Failed to execute the init routine");
			//qDebug("ERROR IN LOADING MODULE %s (%s): failed to execute the init routine",modName,szName.ptr());
			delete module;
			// kill the message catalogue too then
			KviLocale::instance()->unloadCatalogue(modName);
			return false;
		}
	}
	m_pModuleDict->insert(modName,module);

	/*
	registerDefaultCommands(module);
	*/
	module->registerDefaultCommands();

	if(KVI_OPTION_BOOL(KviOption_boolCleanupUnusedModules))
	{
		if(!m_pCleanupTimer->isActive())
		{
			if(KVI_OPTION_UINT(KviOption_uintModuleCleanupTimerInterval) < 30)
				KVI_OPTION_UINT(KviOption_uintModuleCleanupTimerInterval) = 30;
			m_pCleanupTimer->start(KVI_OPTION_UINT(KviOption_uintModuleCleanupTimerInterval) * 1000);
		}
	}
	// be verbose if needed....just make sure that we're not shutting down...
	if(_OUTPUT_VERBOSE && !g_pApp->kviClosingDown())
	{
		if(g_pMainWindow)
		{
			KviConsoleWindow * pWnd = g_pMainWindow->firstConsole();
			if(pWnd) // this may be NULL when the app is starting up
				pWnd->output(
						KVI_OUT_VERBOSE,
						__tr2qs("Loaded module '%s' (%s)"),
						modName.toUtf8().data(),
						szName.toUtf8().data()
					);
		}
	}
	return true;
}