예제 #1
0
bool FB::SimpleStreamHelper::onStreamCompleted( FB::StreamCompletedEvent *evt, FB::BrowserStream * )
{
    if (!evt->success) {
        if (callback)
            callback(false, FB::HeaderMap(), boost::shared_array<uint8_t>(), received);
        callback.clear();
        return false;
    }
    if (!data) {
        data = boost::shared_array<uint8_t>(new uint8_t[received]);
        int i = 0;
        for (BlockList::const_iterator it = blocks.begin();
            it != blocks.end(); ++it) {
            size_t offset(i * blockSize);
            size_t len(received - offset);
            if (len > blockSize)
                len = blockSize;

            std::copy(it->get(), it->get()+len, data.get()+offset);
            ++i;
        }
        // Free all the old blocks
        blocks.clear();
    }
    if (callback)
        callback(true, parse_http_headers(stream->getHeaders()), data, received);
    callback.clear();
    return true;
}
예제 #2
0
bool FB::SimpleStreamHelper::onStreamCompleted( FB::StreamCompletedEvent *evt, FB::BrowserStream *stream )
{
    if (!evt->success) {
        if (callback)
            callback(false, FB::HeaderMap(), boost::shared_array<uint8_t>(), received);
        callback.clear();
        self.reset();
        return false;
    }
    if (!data) {
        data = boost::shared_array<uint8_t>(new uint8_t[received]);
        int i = 0;
        for (BlockList::const_iterator it = blocks.begin();
            it != blocks.end(); ++it) {
            size_t offset(i * blockSize);
            size_t len(received - offset);
            if (len > blockSize)
                len = blockSize;

            std::copy(it->get(), it->get()+len, data.get()+offset);
            ++i;
        }
        // Free all the old blocks
        blocks.clear();
    }
    if (callback && stream) {
        std::multimap<std::string, std::string> headers;
        headers = parse_http_headers(stream->getHeaders());
        callback(true, headers, data, received);
    }
    callback.clear();
    self.reset();
    return false; // Always return false to make sure the browserhost knows to let go of the object
}
예제 #3
0
/*!
 Set up the event recorder by defining the fault boundaries (in terms of block IDs).
 */
void EventRecorder::init(SimFramework *_sim) {
	VCSimulation				*sim = static_cast<VCSimulation*>(_sim);
	std::string					file_name = sim->getEventsFile().c_str();
	BlockList::const_iterator	it;
	
	if (!sim->isRootNode()) return;
	
    eFile.open(file_name.c_str());
    assertThrow(eFile, "Failed to open events file: " + file_name);
    eFile << std::fixed << std::setprecision(2);
	
    // SETTING FID BOUNDS, ID OF THE FIRST AND THE LAST BLOCK
    FaultID prev_fid = UNDEFINED_FAULT_ID;
	BlockID start_block_id = UNDEFINED_BLOCK_ID;
    for(it=sim->begin();it!=sim->end();++it) {
        if(it->getFaultID() != prev_fid) {
			if (start_block_id != UNDEFINED_BLOCK_ID) {
				faultBlockIDs.push_back(std::make_pair(start_block_id, it->getBlockID()-1));
			}
			start_block_id = it->getBlockID();
            prev_fid = it->getFaultID();
        }
    }
	faultBlockIDs.push_back(std::make_pair(start_block_id, sim->numGlobalBlocks()-1));
	assertThrow(start_block_id!=UNDEFINED_BLOCK_ID, "Could not find any blocks in simulation.");
}
예제 #4
0
BasicBlock::EdgeList::const_iterator 
	BasicBlock::get_edge(BlockList::const_iterator b) const {
	for (EdgePointerVector::const_iterator edge = out_edges.begin(); 
		edge != out_edges.end(); ++edge) {
		if ((*edge)->tail == b) return *edge;
	}
	assertM(false, "No edge from " << label() << " to " << b->label());
	return EdgeList::const_iterator();
}
예제 #5
0
void GreensFuncCalcStandard::InnerCalcStandard(Simulation *sim,
                                               const BlockID &bnum,
                                               GreensValsSparseMatrix &ssh,
                                               GreensValsSparseMatrix &snorm) {
    Block source_block = sim->getBlock(bnum);
    BlockIDList                         target_blocks;
    BlockIDList::const_iterator         bit;
    BlockList::const_iterator           it;
    double                              stress_values[2];

    // Get a list of block IDs we want to calculate the Greens function for
    for (it=sim->begin(); it!=sim->end(); ++it) target_blocks.push_back(it->getBlockID());

    // Convert the strains to Greens values and record them
    for (bit=target_blocks.begin(); bit!=target_blocks.end(); ++bit) {
        Block target_block = sim->getBlock(*bit);

        target_block.get_rake_and_normal_stress_due_to_block(stress_values, sim->getGreensSampleDistance(), source_block);

        ssh[bnum][*bit] = stress_values[0];
        snorm[bnum][*bit] = stress_values[1];
    }
}