예제 #1
0
OcsShareeJob::OcsShareeJob(AccountPtr account)
: OcsJob(account)
{
    setPath("ocs/v1.php/apps/files_sharing/api/v1/sharees");
    connect(this, SIGNAL(jobFinished(QVariantMap)), SLOT(jobDone(QVariantMap)));

}
예제 #2
0
void MultiMailMessenger::onSendResult(WP::err error)
{
    if (error != WP::kOk) {
        // todo
    }

    lastParticipantIndex++;
    if (lastParticipantIndex == messageChannelInfo->getParticipants().size()) {
        emit messagesSent();
        return;
    }
    const MessageChannelInfo::Participant *participant = &messageChannelInfo->getParticipants().at(lastParticipantIndex);
    Contact *myself = mailbox->getOwner()->getMyself();
    if (participant->uid == myself->getUid()) {
        onSendResult(WP::kOk);
        return;
    }

    MailMessengerRef mailMessenger(new MailMessenger(mailbox, participant, profile, message));
    QString targetServer = mailMessenger->getTargetServer();
    if (targetServer == "") {
        onSendResult(WP::kBadValue);
        return;
    }
    QUrl url(targetServer);
    RemoteConnectionJobQueue *queue = ConnectionManager::get()->getConnectionJobQueue(
                ConnectionManager::getDefaultConnectionFor(url));
    queue->queue(mailMessenger);


    connect(mailMessenger.data(), SIGNAL(jobDone(WP::err)), this, SLOT(onSendResult(WP::err)));
}
예제 #3
0
파일: Threads.cpp 프로젝트: GLolol/znc
void CThreadPool::threadFunc() {
    CMutexLocker guard(m_mutex);
    // m_num_threads was already increased
    m_num_idle++;

    while (true) {
        while (m_jobs.empty()) {
            if (!threadNeeded()) break;
            m_cond.wait(m_mutex);
        }
        if (!threadNeeded()) break;

        // Figure out a job to do
        CJob* job = m_jobs.front();
        m_jobs.pop_front();

        // Now do the actual job
        m_num_idle--;
        job->m_eState = CJob::RUNNING;
        guard.unlock();

        job->runThread();

        guard.lock();
        jobDone(job);
        m_num_idle++;
    }
    assert(m_num_threads > 0 && m_num_idle > 0);
    m_num_threads--;
    m_num_idle--;

    if (m_num_threads == 0 && m_done) m_exit_cond.notify_one();
}
예제 #4
0
void RemoteSync::syncPushReply(WP::err code)
{
    if (code != WP::kOk)
        return;

    QByteArray data = serverReply->readAll();

    database->updateLastSyncCommit(remoteStorage->getUid(), database->branch(), syncUid);
    emit jobDone(WP::kOk);
}
예제 #5
0
파일: job.c 프로젝트: Shanepruett/CS453Lab5
void printJobStatus(const void *jobObj)
{

    JobPtr object = (JobPtr) jobObj;
    if (jobDone(jobObj)) {

	printf("[%d] Done %s \n", object->jobNumber, object->command);
    } else {

	printf("[%d] Running %s \n", object->jobNumber, object->command);
    }

}
예제 #6
0
void Client::updated() {
	stillAlive();
	// get the information in statusBuffer
	statusBuffer = client->status();
	// and deal with what it says
	if(statusBuffer.section("?", 0, 0) == "ERROR") {
		if (statusBuffer.section("?", 1, 1) == "FATAL") {
			emit disconnect(statusBuffer.section("?", 2, 2), thread);
		}
		else if (statusBuffer.section("?", 1, 1) == "RECOVERABLE") {
			emit couldntConnect(statusBuffer.section("?", 2, 2), thread);
		}
		else
			emit jobFailed("Bad plugin error string.", thread);
	}
	else if (statusBuffer.section("?", 0, 0) == "PROGRESS") {
		// here is the status update code
		emit changed(statusBuffer.section("?", 1, 1), thread, statusBuffer.section("?", 2, 2).toInt());
	}
	else if (statusBuffer.section("?", 0, 0) == "CONNECTED") {
		// yay!  It connected... now get to it, slacker
		emit connected(statusBuffer.section("?", 1, 1), thread);
	}
	else if (statusBuffer.section("?", 0, 0) == "RESULT") {
		if (statusBuffer.section("?", 1, 1) == "TRUE") {
			if (!Loaded) {
				Loaded = true;
				emit continueRender("Loaded file successfully", thread);
			}
		}
		else
			// emit to say that the result was bad
			emit jobFailed("Job Failed", thread);
	}
	else if (statusBuffer.section("?", 0, 0) == "ECHO") {
		emit echo(statusBuffer.section("?",1,-1), thread);
	}
	else if (statusBuffer.section("?", 0, 0) == "OUTPUT") {
		// can change later to check for successful creation of filename
		emit echo(statusBuffer.section("?", 1, 1), thread);
		emit jobDone("Job finished", thread);
	}
	else
		emit echo(statusBuffer, thread);
}
예제 #7
0
void KoProgressUpdaterTest::testFromWeaver()
{
    jobsdone = 0;

    TestProgressBar bar;
    KoProgressUpdater pu(&bar);
    pu.start(10);
    ThreadWeaver::Queue::instance()->setMaximumNumberOfThreads(4);
    for (int i = 0; i < 10; ++i) {
        QPointer<KoUpdater> up = pu.startSubtask();
        ThreadWeaver::QObjectDecorator * job = new ThreadWeaver::QObjectDecorator(new TestWeaverJob(up, 10));
        connect( job, SIGNAL(done(ThreadWeaver::JobPointer)), SLOT(jobDone(ThreadWeaver::JobPointer)) );
        ThreadWeaver::Queue::instance()->enqueue(ThreadWeaver::make_job_raw(job));
    }
    while (!ThreadWeaver::Queue::instance()->isIdle()) {
         QTest::qSleep(WAIT_FOR_PROGRESSUPDATER_UI_UPDATES);
         QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
    }
    ThreadWeaver::Queue::instance()->finish();
    QCOMPARE(jobsdone, 10);
}
예제 #8
0
void MailMessenger::onContactFound(WP::err error)
{
    delete contactRequest;
    contactRequest = NULL;

    if (error != WP::kOk) {
        emit jobDone(error);
        return;
    }

    targetContact = userIdentity->findContact(receiver->address);
    if (targetContact == NULL)
        return;

    if (authentication->isVerified())
        authConnected(WP::kOk);
    else {
        authentication->disconnect(this);
        connect(authentication.data(), SIGNAL(authenticationAttemptFinished(WP::err)),
                this, SLOT(authConnected(WP::err)));
        authentication->login();
    }
}
예제 #9
0
void RemoteSync::syncReply(WP::err code)
{
    if (code != WP::kOk)
        return;

    QByteArray data = serverReply->readAll();
    serverReply = NULL;

    IqInStanzaHandler iqHandler(kResult);
    SyncPullData syncPullData;
    SyncPullHandler *syncPullHandler = new SyncPullHandler(&syncPullData);
    iqHandler.addChildHandler(syncPullHandler);

    ProtocolInStream inStream(data);
    inStream.addHandler(&iqHandler);

    inStream.parse();

    QString localBranch = database->branch();
    QString localTipCommit = database->getTip();
    QString lastSyncCommit = database->getLastSyncCommit(remoteStorage->getUid(), localBranch);

    if (!syncPullHandler->hasBeenHandled() || syncPullData.branch != localBranch) {
        // error occured, the server should at least send back the branch name
        // TODO better error message
        emit jobDone(WP::kBadValue);
        return;
    }
    if (syncPullData.tip == localTipCommit) {
        // done
        emit jobDone(WP::kOk);
        return;
    }
    // see if the server is ahead by checking if we got packages
    if (syncPullData.pack.size() != 0) {
        syncUid = syncPullData.tip;
        WP::err error = database->importPack(syncPullData.pack, lastSyncCommit,
                                              syncPullData.tip);
        if (error != WP::kOk) {
            emit jobDone(error);
            return;
        }

        localTipCommit = database->getTip();
        // done? otherwise it was a merge and we have to push our merge
        if (localTipCommit == lastSyncCommit) {
            emit jobDone(WP::kOk);
            return;
        }
    }

    // we are ahead of the server: push changes to the server
    QByteArray pack;
    WP::err error = database->exportPack(pack, lastSyncCommit, localTipCommit, syncUid);
    if (error != WP::kOk) {
        emit jobDone(error);
        return;
    }
    syncUid = localTipCommit;

    QByteArray outData;
    ProtocolOutStream outStream(&outData);

    IqOutStanza *iqStanza = new IqOutStanza(kSet);
    outStream.pushStanza(iqStanza);
    OutStanza *pushStanza = new OutStanza("sync_push");
    pushStanza->addAttribute("branch", localBranch);
    pushStanza->addAttribute("start_commit", syncPullData.tip);
    pushStanza->addAttribute("last_commit", localTipCommit);
    outStream.pushChildStanza(pushStanza);
    OutStanza *pushPackStanza = new OutStanza("pack");
    pushPackStanza->setText(pack.toBase64());
    outStream.pushChildStanza(pushPackStanza);

    outStream.flush();

    serverReply = remoteConnection->send(outData);
    connect(serverReply, SIGNAL(finished(WP::err)), this, SLOT(syncPushReply(WP::err)));
}
예제 #10
0
void MailMessenger::authConnected(WP::err error)
{
    if (error == WP::kContactNeeded) {
        startContactRequest();
        return;
    } else if (error != WP::kOk) {
        emit jobDone(error);
        return;
    }

    MessageChannelRef targetMessageChannel = MessageChannelRef();
    if (message->getChannel().staticCast<MessageChannel>()->isNewLocale()) {
        targetMessageChannel = MessageChannelRef(
            new MessageChannel(message->getChannel().staticCast<MessageChannel>(), targetContact,
                                              targetContact->getKeys()->getMainKeyId()));
    }

    QByteArray data;
    ProtocolOutStream outStream(&data);
    IqOutStanza *iqStanza = new IqOutStanza(kSet);
    outStream.pushStanza(iqStanza);

    Contact *myself = userIdentity->getMyself();
    OutStanza *messageStanza =  new OutStanza("put_message");
    messageStanza->addAttribute("server_user", targetUser);
    messageStanza->addAttribute("channel", message->getChannel()->getUid());
    outStream.pushChildStanza(messageStanza);

    QString signatureKeyId = myself->getKeys()->getMainKeyId();

    // write new channel
    if (targetMessageChannel != NULL) {
        error = XMLSecureParcel::write(&outStream, myself, signatureKeyId,
                                       targetMessageChannel.data(), "channel");
        if (error != WP::kOk) {
            emit jobDone(error);
            return;
        }
    }

    // write new channel info
    MessageChannelInfoRef info = message->getChannelInfo();
    if (info->isNewLocale()) {
        error = XMLSecureParcel::write(&outStream, myself, signatureKeyId, info.data(),
                                       "channel_info");
        if (error != WP::kOk) {
            emit jobDone(error);
            return;
        }
    }

    // write message
    error = XMLSecureParcel::write(&outStream, myself, signatureKeyId, message.data(), "message");
    if (error != WP::kOk) {
        emit jobDone(error);
        return;
    }

    outStream.flush();

    message = MessageRef();

    serverReply = remoteConnection->send(data);
    connect(serverReply, SIGNAL(finished(WP::err)), this, SLOT(handleReply(WP::err)));
}
예제 #11
0
void MailMessenger::handleReply(WP::err error)
{
    QByteArray data = serverReply->readAll();
    emit jobDone(error);
}
void paraNode()
/* paraNode - a net server. */
{
char *line;
char *command;
struct sockaddr_in sai;

/* We have to know who we are... */
hostName = getMachine();
initRandom();
getTicksToHundreths();

/* log init */
if (optionExists("log"))
    logOpenFile("paraNode", optionVal("log", NULL));
else    
    logOpenSyslog("paraNode", optionVal("logFacility", NULL));
logSetMinPriority(optionVal("logMinPriority", "info"));
logInfo("starting paraNode on %s", hostName);

/* Make job lists. */
jobsRunning = newDlList();
jobsFinished = newDlList();

/* Set up socket and self to listen to it. */
ZeroVar(&sai);
sai.sin_family = AF_INET;
sai.sin_port = htons(paraNodePort);
sai.sin_addr.s_addr = INADDR_ANY;
mainRudp = rudpMustOpenBound(&sai);
mainRudp->maxRetries = 12;

/* Event loop. */
findNow();
for (;;)
    {
    /* Get next incoming message and optionally check to make
     * sure that it's from a host we trust, and check signature
     * on first bit of incoming data. */
    if (pmReceive(&pmIn, mainRudp))
	{
	findNow();
	if (hubName == NULL || ntohl(pmIn.ipAddress.sin_addr.s_addr) == hubIp 
		|| ntohl(pmIn.ipAddress.sin_addr.s_addr) == localIp)
	    {
	    /* Host and signature look ok,  read a string and
	     * parse out first word as command. */
	    line = pmIn.data;
	    logDebug("message from %s: \"%s\"",
                     paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr)),
                     line);
	    command = nextWord(&line);
	    if (command != NULL)
		{
		if (sameString("quit", command))
		    break;
		else if (sameString("run", command))
		    doRun(line, &pmIn.ipAddress);
		else if (sameString("jobDone", command))
		    jobDone(line);
		else if (sameString("status", command))
		    doStatus();
		else if (sameString("kill", command))
		    doKill(line);
		else if (sameString("check", command))
		    doCheck(line, &pmIn.ipAddress);
		else if (sameString("resurrect", command))
		    doResurrect(line, &pmIn.ipAddress);
		else if (sameString("listJobs", command))
		    listJobs();
		else if (sameString("fetch", command))
		    doFetch(line);
                else
                    logWarn("invalid command: \"%s\"", command);
		}
	    logDebug("done command");
	    }
	else
	    {
	    logWarn("command from unauthorized host %s",
                    paraFormatIp(ntohl(pmIn.ipAddress.sin_addr.s_addr)));
	    }
	}
    }
rudpClose(&mainRudp);
}