void printSolution(char* program, char* input, Solution solution, Node **nodeArray)
{
    ofstream resultFile;
    string programName = trimDirectory(program);
    string inputName = trimDirectory(input);
    // stringstream fileName;
    // fileName << "" << programName << "_" << inputName << "_out";
    // DEBUG("Outputting to file %s.", fileName.str());
    // resultFile.open(fileName.str().c_str());
    char fileName[512];
    sprintf(fileName, "%s_%s_out", programName.c_str(), inputName.c_str());
    resultFile.open(fileName);

    pthread_mutex_lock(&done_mutex);
    if (solution == SOLVEABLE)
    {
        cout << "true" << endl;
        resultFile << "true" << endl;
        for (unsigned int cntr = 0; cntr < g_count; cntr++)
        {
            cout << nodeArray[cntr]->getName() << ": " << fixColor(colorSolution[cntr]) << "\n";
            resultFile << nodeArray[cntr]->getName() << ": " << fixColor(colorSolution[cntr]) << "\n";
        }
    }
    else
    {
        cout << "false" << endl;
        resultFile << "false" << endl;
        DEBUG("Solution is set to %d.", solution);
    }
    pthread_mutex_unlock(&done_mutex);
    resultFile.close();
    DEBUG("Done");
}
Ejemplo n.º 2
0
Status FTDCFileManager::rotate(Client* client) {
    auto s = _writer.close();
    if (!s.isOK()) {
        return s;
    }

    auto files = scanDirectory();

    // Rotate as needed
    trimDirectory(files);

    auto swFile = generateArchiveFileName(_path, terseUTCCurrentTime());
    if (!swFile.isOK()) {
        return swFile.getStatus();
    }

    return openArchiveFile(client, swFile.getValue(), {});
}
Ejemplo n.º 3
0
StatusWith<std::unique_ptr<FTDCFileManager>> FTDCFileManager::create(
    const FTDCConfig* config,
    const boost::filesystem::path& path,
    FTDCCollectorCollection* collection,
    Client* client) {
    const boost::filesystem::path dir = boost::filesystem::absolute(path);

    if (!boost::filesystem::exists(dir)) {
        // Create the directory
        boost::system::error_code ec;
        boost::filesystem::create_directories(dir, ec);
        if (ec) {
            return {ErrorCodes::NonExistentPath,
                    str::stream() << "\'" << dir.generic_string()
                                  << "\' could not be created: " << ec.message()};
        }
    }

    auto mgr =
        std::unique_ptr<FTDCFileManager>(new FTDCFileManager(config, dir, std::move(collection)));

    // Enumerate the metrics files
    auto files = mgr->scanDirectory();

    // Recover the interim file
    auto interimDocs = mgr->recoverInterimFile();

    // Open the archive file for writing
    auto swFile = mgr->generateArchiveFileName(path, terseUTCCurrentTime());
    if (!swFile.isOK()) {
        return swFile.getStatus();
    }

    Status s = mgr->openArchiveFile(client, swFile.getValue(), interimDocs);
    if (!s.isOK()) {
        return s;
    }

    // Rotate as needed after we appended interim data to the archive file
    mgr->trimDirectory(files);

    return {std::move(mgr)};
}