Пример #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);
                }
            }   
        }
    }
}
/*!
  Creates and returns a TSessionStore object that matches the given key,
  or returns 0 if no matching session store is found.
*/
TSessionStore *TSessionStoreFactory::create(const QString &key)
{
    T_TRACEFUNC("key: %s", qPrintable(key));

    static const QString COOKIE_KEY = TSessionCookieStore().key().toLower();
    static const QString SQLOBJECT_KEY = TSessionSqlObjectStore().key().toLower();
    static const QString FILE_KEY = TSessionFileStore().key().toLower();
    static const QString REDIS_KEY = TSessionRedisStore().key().toLower();

    QMutexLocker locker(&mutex);

    loadPlugins();
    TSessionStore *ret = 0;

    QString k = key.toLower();
    if (k == COOKIE_KEY) {
        ret = new TSessionCookieStore;
    } else if (k == SQLOBJECT_KEY) {
        ret = new TSessionSqlObjectStore;
    } else if (k == FILE_KEY) {
        ret = new TSessionFileStore;
    } else if (k == REDIS_KEY) {
        ret = new TSessionRedisStore;
    } else {
        TSessionStoreInterface *ssif = sessIfMap->value(k);
        if (ssif) {
            ret = ssif->create(key);
        }
    }

    return ret;
}
/*!
  Returns the list of valid keys, i.e.\ the available session stores.
*/
QStringList TSessionStoreFactory::keys()
{
    QMutexLocker locker(&mutex);
    QStringList ret;

    loadPlugins();
    ret << TSessionSqlObjectStore().key().toLower()
        << TSessionCookieStore().key().toLower()
        << TSessionFileStore().key().toLower()
        << TSessionRedisStore().key().toLower()
        << sessIfMap->keys();

    return ret;
}
Пример #4
0
QStringList TSessionStoreFactory::keys()
{
    QMutexLocker locker(&mutex);

    loadPlugins();
    QStringList ret;
    ret << TSessionSqlObjectStore().key()
        << TSessionCookieStore().key()
        << TSessionFileStore().key();

    for (QListIterator<TSessionStoreInterface *> i(*ssifs); i.hasNext(); ) {
        ret << i.next()->keys();
    }
    return ret;
}