예제 #1
0
void IMAPAsyncSession::cancelAllOperations()
{
    for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        currentSession->cancelAllOperations();
    }
}
예제 #2
0
void IMAPAsyncSession::setConnectionLogger(ConnectionLogger * logger)
{
    mConnectionLogger = logger;
    for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        currentSession->setConnectionLogger(logger);
    }
}
예제 #3
0
IMAPOperation * IMAPAsyncSession::disconnectOperation()
{
    IMAPMultiDisconnectOperation * op = new IMAPMultiDisconnectOperation();
    op->autorelease();
    for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        op->addOperation(currentSession->disconnectOperation());
    }
    return op;
}
예제 #4
0
IMAPAsyncConnection * IMAPAsyncSession::matchingSessionForFolder(String * folder)
{
    for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        if (currentSession->lastFolder() != NULL) {
            if (currentSession->lastFolder()->isEqual(folder)) {
                return currentSession;
            }
        }
        else {
            return currentSession;
        }
    }
    return availableSession();
}
예제 #5
0
IMAPAsyncConnection * IMAPAsyncSession::availableSession()
{
    // try find existant session with empty queue for reusing.
    IMAPAsyncConnection * chosenSession = sessionWithMinQueue(false, NULL);
    if ((chosenSession != NULL) && (chosenSession->operationsCount() == 0)) {
        return chosenSession;
    }

    // create new session, if maximum connections limit does not reached yet.
    if ((mMaximumConnections == 0) || (mSessions->count() < mMaximumConnections)) {
        chosenSession = session();
        mSessions->addObject(chosenSession);
        return chosenSession;
    }

    // otherwise returns existant session with minimum size of queue.
    return chosenSession;
}
예제 #6
0
IMAPAsyncConnection * IMAPAsyncSession::sessionForFolder(String * folder, bool urgent)
{
    if (folder == NULL) {
        return availableSession();
    }
    else {
        IMAPAsyncConnection * s = NULL;
        if (urgent && mAllowsFolderConcurrentAccessEnabled) {
            s = availableSession();
            if (s->operationsCount() == 0) {
                s->setLastFolder(folder);
                return s;
            }
        }

        s = matchingSessionForFolder(folder);
        s->setLastFolder(folder);
        return s;
    }
}
예제 #7
0
IMAPAsyncConnection * IMAPAsyncSession::sessionForFolder(String * folder, bool urgent)
{
    if (folder == NULL) {
        return matchingSessionForFolder(NULL);
    }
    else {
        IMAPAsyncConnection * s = NULL;

        // try find session with empty queue, selected to the folder
        s = sessionWithMinQueue(true, folder);
        if (s != NULL && s->operationsCount() == 0) {
            s->setLastFolder(folder);
            return s;
        }

        if (urgent && mAllowsFolderConcurrentAccessEnabled) {
            // in urgent mode try reuse any available session with
            // empty queue or create new one, if maximum connections limit does not reached.
            s = availableSession();
            if (s->operationsCount() == 0) {
                s->setLastFolder(folder);
                return s;
            }
        }

        // otherwise returns session with minimum size of queue among selected to the folder.
        s = matchingSessionForFolder(folder);
        s->setLastFolder(folder);
        return s;
    }
}
예제 #8
0
void IMAPAsyncSession::operationRunningStateChanged()
{
    bool isRunning = false;
    for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * currentSession = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        if (currentSession->isQueueRunning()){
            isRunning = true;
            break;
        }
    }
    if (mQueueRunning == isRunning) {
        return;
    }
    mQueueRunning = isRunning;
    if (mOperationQueueCallback != NULL) {
        if (isRunning) {
            mOperationQueueCallback->queueStartRunning();
        }
        else {
            mOperationQueueCallback->queueStoppedRunning();
        }
    }
}
예제 #9
0
IMAPAsyncConnection * IMAPAsyncSession::availableSession()
{
    if (mMaximumConnections == 0) {
        for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
            IMAPAsyncConnection * s = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
            if (s->operationsCount() == 0)
                return s;
        }
        IMAPAsyncConnection * chosenSession = session();
        mSessions->addObject(chosenSession);
        return chosenSession;
    }
    else {
        IMAPAsyncConnection * chosenSession = NULL;
        unsigned int minOperationsCount = 0;
        for(unsigned int i = 0 ; i < mSessions->count() ; i ++) {
            IMAPAsyncConnection * s = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
            if (chosenSession == NULL) {
                chosenSession = s;
                minOperationsCount = s->operationsCount();
            }
            else if (s->operationsCount() < minOperationsCount) {
                chosenSession = s;
                minOperationsCount = s->operationsCount();
            }
        }
        if (mSessions->count() < mMaximumConnections) {
            if ((chosenSession != NULL) && (minOperationsCount == 0)) {
                return chosenSession;
            }
            chosenSession = session();
            mSessions->addObject(chosenSession);
            return chosenSession;
        }
        else {
            return chosenSession;
        }
    }
}
예제 #10
0
IMAPAsyncConnection * IMAPAsyncSession::sessionWithMinQueue(bool filterByFolder, String * folder)
{
    IMAPAsyncConnection * chosenSession = NULL;
    unsigned int minOperationsCount = 0;

    for (unsigned int i = 0 ; i < mSessions->count() ; i ++) {
        IMAPAsyncConnection * s = (IMAPAsyncConnection *) mSessions->objectAtIndex(i);
        if ((chosenSession == NULL) || (s->operationsCount() < minOperationsCount)) {
            bool matched = true;
            if (filterByFolder) {
                // filter by last selested folder
                matched = ((folder != NULL && s->lastFolder() != NULL && s->lastFolder()->isEqual(folder))
                           || (folder == NULL && s->lastFolder() == NULL));
            }
            if (matched) {
                chosenSession = s;
                minOperationsCount = s->operationsCount();
            }
        }
    }

    return chosenSession;
}
예제 #11
0
IMAPAsyncConnection * IMAPAsyncSession::session()
{
    IMAPAsyncConnection * session = new IMAPAsyncConnection();
    session->setConnectionLogger(mConnectionLogger);
    session->setOwner(this);
    session->autorelease();

    session->setHostname(mHostname);
    session->setPort(mPort);
    session->setUsername(mUsername);
    session->setPassword(mPassword);
    session->setOAuth2Token(mOAuth2Token);
    session->setAuthType(mAuthType);
    session->setConnectionType(mConnectionType);
    session->setTimeout(mTimeout);
    session->setCheckCertificateEnabled(mCheckCertificateEnabled);
    session->setVoIPEnabled(mVoIPEnabled);
    session->setDefaultNamespace(mDefaultNamespace);
    session->setClientIdentity(mClientIdentity);
#if __APPLE__
    session->setDispatchQueue(mDispatchQueue);
#endif
#if 0 // should be implemented properly
    if (mAutomaticConfigurationDone) {
        session->setAutomaticConfigurationEnabled(false);
    }
#endif

    return session;
}