Esempio n. 1
0
void TSessionStoreFactory::loadPlugins()
{
    if (!ssifs) {
        ssifs = new QList<TSessionStoreInterface *>();
        qAddPostRoutine(cleanup);
        
        // Init hash
        hash.insert(TSessionSqlObjectStore().key().toLower(), SqlObject);
        hash.insert(TSessionCookieStore().key().toLower(), Cookie);
        hash.insert(TSessionFileStore().key().toLower(), File);

        QDir dir(Tf::app()->pluginPath());
        QStringList list = dir.entryList(QDir::Files);
        for (QStringListIterator i(list); i.hasNext(); ) {
            QPluginLoader loader(dir.absoluteFilePath(i.next()));
            TSessionStoreInterface *iface = qobject_cast<TSessionStoreInterface *>(loader.instance());
            if ( iface ) {
                ssifs->append(iface);
                QStringList keys = iface->keys();
                for (QStringListIterator j(keys); j.hasNext(); ) {
                    hash.insert(j.next(), Plugin);
                }
            }   
        }
    }
}
Esempio n. 2
0
TSessionStore *TSessionStoreFactory::create(const QString &key)
{
    T_TRACEFUNC("key: %s", qPrintable(key));

    QMutexLocker locker(&mutex);
 
    loadPlugins();
    TSessionStore *ret = 0;
    QString k = key.toLower();
    int type = hash.value(k, Invalid);
    switch (type) {
    case SqlObject:
        ret = new TSessionSqlObjectStore;
        break;

    case Cookie:
        ret = new TSessionCookieStore;
        break;

    case File:
        ret = new TSessionFileStore;
        break;

    case Plugin: {
        for (QListIterator<TSessionStoreInterface *> i(*ssifs); i.hasNext(); ) {
             TSessionStoreInterface *p = i.next();
             if (p->keys().contains(k)) {
                 ret = p->create(k);
                 break;
             }
         }
         break; }

    default:
        // do nothing
        break;
    }

    return ret;
}
/*!
  Loads session store plugins in the plugin directory.
*/
void TSessionStoreFactory::loadPlugins()
{
    if (!sessIfMap) {
        sessIfMap = new QMap<QString, TSessionStoreInterface*>();
        qAddPostRoutine(cleanup);

        QDir dir(Tf::app()->pluginPath());
        QStringList list = dir.entryList(QDir::Files);
        for (QStringListIterator i(list); i.hasNext(); ) {
            QPluginLoader loader(dir.absoluteFilePath(i.next()));

            tSystemDebug("plugin library for session store: %s", qPrintable(loader.fileName()));
            if (!loader.load()) {
                tSystemError("plugin load error: %s", qPrintable(loader.errorString()));
                continue;
            }

            TSessionStoreInterface *iface = qobject_cast<TSessionStoreInterface *>(loader.instance());
            if ( iface ) {
#if QT_VERSION >= 0x050000
                QVariantList array = loader.metaData().value("MetaData").toObject().value("Keys").toArray().toVariantList();
                for (QListIterator<QVariant> it(array); it.hasNext(); ) {
                    QString key = it.next().toString().toLower();
                    tSystemInfo("Loaded session store plugin: %s", qPrintable(key));
                    sessIfMap->insert(key, iface);
                }
#else
                QStringList keys = iface->keys();
                for (QStringListIterator j(keys); j.hasNext(); ) {
                    QString key = j.next().toLower();
                    tSystemInfo("Loaded session store plugin: %s", qPrintable(key));
                    sessIfMap->insert(key, iface);
                }
#endif
            }
        }
    }
}