void CodaClientApplication::handleCreateProcess(const Coda::CodaCommandResult &result)
{
    const bool ok = result.type == Coda::CodaCommandResult::SuccessReply;
    if (ok) {
        printTimeStamp();
        std::printf("Launch succeeded: %s\n", qPrintable(result.toString()));
        if (!m_launchDebug)
            doExit(0);
    } else {
        std::fprintf(stderr, "Launch failed: %s\n", qPrintable(result.toString()));
        doExit(-1);
    }
}
void CodaClientApplication::handleFileSystemOpen(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        std::fprintf(stderr, "Open remote file failed: %s\n", qPrintable(result.toString()));
        doExit(-1);
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).data().isEmpty()) {
        std::fprintf(stderr, "Internal error: No filehandle obtained\n");
        doExit(-1);
        return;
    }

    m_remoteFileHandle = result.values.at(0).data();

    if (m_mode == Stat) {
        m_trkDevice->sendFileSystemFstatCommand(Coda::CodaCallback(this, &CodaClientApplication::handleFileSystemFStat),
                                               m_remoteFileHandle);
        return;
    }
    // Put.
    m_putFile.reset(new QFile(m_putLocalFile));
    if (!m_putFile->open(QIODevice::ReadOnly)) { // Should not fail, was checked before
        std::fprintf(stderr, "Open local file failed: %s\n", qPrintable(m_putFile->errorString()));
        doExit(-1);
        return;
    }
    putSendNextChunk();
}
Example #3
0
void CodaSignalHandler::handleFileSystemRead(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply || result.values.size() != 2) {
        reportError(tr("Could not read remote file: %1").arg(result.errorString()));
        return;
    }

    QByteArray data = QByteArray::fromBase64(result.values.at(0).data());
    bool eof = result.values.at(1).toVariant().toBool();
    qint64 written = d->localFile->write(data);
    if (written < 0) {
        reportError(tr("Could not write data to host file: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
        return;
    }

    d->remoteBytesLeft -= written;
    if (!eof && d->remoteBytesLeft > 0) {
        readNextChunk();
    }
    else {
        d->localFile->flush();
        d->localFile->close();
        closeFile();
    }
}
Example #4
0
void CodaSignalHandler::handleSymbianInstall(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        reportMessage(tr("Installation has finished."));
        d->action = static_cast<CodaAction>(d->action & ~ActionInstall);
        handleActions();
    } else {
        reportError(tr("Installation failed: %1").arg(result.errorString()));
    }
}
void CodaClientApplication::handleUninstall(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        printTimeStamp();
        std::printf("Uninstallation succeeded\n.");
        doExit(0);
    } else {
        std::fprintf(stderr, "Uninstallation failed: %s\n", qPrintable(result.toString()));
        doExit(-1);
    }
}
Example #6
0
void CodaSignalHandler::handleAppRunning(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        reportMessage(tr("Running..."));

        Coda::JsonValue value = result.values.at(0);
        readAppId(value);
    } else {
        reportError(tr("Launch failed: %1").arg(result.toString()));
    }
}
void CodaClientApplication::handleFileSystemClose(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        printTimeStamp();
        std::printf("File closed.\n");
        const bool ok = m_mode == Put ? m_putWriteOk : m_statFstatOk;
        doExit(ok ? 0 : -1);
    } else {
        std::fprintf(stderr, "File close failed: %s\n", qPrintable(result.toString()));
        doExit(-1);
    }
}
void CodaClientApplication::handleFileSystemWrite(const Coda::CodaCommandResult &result)
{
    // Close remote file even if copy fails
    m_putWriteOk = result;
    if (!m_putWriteOk)
        std::fprintf(stderr, "Writing data failed: %s\n", qPrintable(result.toString()));
    if (!m_putWriteOk || m_putLastChunkSize < m_putChunkSize) {
        closeRemoteFile();
    } else {
        putSendNextChunk();
    }
}
Example #9
0
void CodaSignalHandler::handleFileSystemClose(const Coda::CodaCommandResult &result)
{
    if (result.type == Coda::CodaCommandResult::SuccessReply) {
        reportMessage(tr("File closed."));
        if (d->action & ActionCopy) {
            d->action = static_cast<CodaAction>(d->action & ~ActionCopy);
        } else if (d->action & ActionDownload) {
            d->action = static_cast<CodaAction>(d->action & ~ActionDownload);
        }
        handleActions();
    } else {
        reportError(tr("Failed to close the remote file: %1").arg(result.toString()));
    }
}
Example #10
0
void CodaSignalHandler::handleFileSystemWrite(const Coda::CodaCommandResult &result)
{
    // Close remote file even if copy fails
    d->putWriteOk = result;
    if (!d->putWriteOk) {
        QString fileName = QFileInfo(d->copyDstFileName).fileName();
        reportError(tr("Could not write to file %1 on device: %2").arg(fileName).arg(result.errorString()));
    }

    if (!d->putWriteOk || d->putLastChunkSize < d->putChunkSize) {
        closeFile();
    } else {
        putSendNextChunk();
    }
}
void CodaClientApplication::handleFileSystemFStat(const Coda::CodaCommandResult &result)
{
    m_statFstatOk = result.type == Coda::CodaCommandResult::SuccessReply;
    // Close remote file even if copy fails
    if (m_statFstatOk) {
        const Coda::CodaStatResponse statr = Coda::CodaDevice::parseStat(result);
        printTimeStamp();
        std::printf("File: %s\nSize: %llu bytes\nAccessed: %s\nModified: %s\n",
                    qPrintable(m_statRemoteFile), statr.size,
                    qPrintable(statr.accessTime.toString(Qt::LocalDate)),
                    qPrintable(statr.modTime.toString(Qt::LocalDate)));
    } else {
        std::fprintf(stderr, "FStat failed: %s\n", qPrintable(result.toString()));
    }
    closeRemoteFile();
}
Example #12
0
void CodaSignalHandler::handleFileSystemStart(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        reportError(tr("Could not open remote file: %1").arg(result.errorString()));
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).children().isEmpty()) {
        reportError(tr("Could not get file attributes"));
        return;
    }

    Coda::JsonValue val = result.values.at(0).findChild("Size");
    d->remoteFileSize = val.isValid() ? val.data().toLong() : -1L;
    if (d->remoteFileSize < 0) {
        reportError(tr("Could not get file size"));
        return;
    }

    d->remoteBytesLeft = d->remoteFileSize;
    readNextChunk();
}
Example #13
0
void CodaSignalHandler::handleFileSystemOpen(const Coda::CodaCommandResult &result)
{
    if (result.type != Coda::CodaCommandResult::SuccessReply) {
        reportError(tr("Could not open remote file: %1").arg(result.errorString()));
        return;
    }

    if (result.values.size() < 1 || result.values.at(0).data().isEmpty()) {
        reportError(tr("Internal error: No filehandle obtained"));
        return;
    }

    if (d->action & ActionCopy) {
        d->remoteFileHandle = result.values.at(0).data();
        d->remoteFile.reset(new QFile(d->copySrcFileName));
        if (!d->remoteFile->open(QIODevice::ReadOnly)) { // Should not fail, was checked before
            reportError(tr("Could not open local file %1").arg(d->copySrcFileName));
            return;
        }
        putSendNextChunk();
    } else if (d->action & ActionDownload) {
        d->remoteFileHandle = result.values.at(0).data();
        d->localFile.reset(new QFile(d->dlDstFileName));
        // remove any existing file with the same name
        if (d->localFile->exists() && !d->localFile->remove()) {
            reportError(tr("Could not create host file: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
            return;
        }
        // open local file in write-only mode
        if (!d->localFile->open(QFile::WriteOnly)) {
            reportError(tr("Could not open host file for writing: %1 due to error: %2").arg(d->localFile->fileName(), d->localFile->errorString()));
            return;
        }
        d->codaDevice->sendFileSystemFstatCommand(Coda::CodaCallback(this, &CodaSignalHandler::handleFileSystemStart),
                                                  d->remoteFileHandle);
    }
}