VariableSymbol *build_initialized_variable( SuifEnv *env, const LString &name, DataType *type, ValueBlock *vb, bool make_static) { TypeBuilder *tb = (TypeBuilder *) env->get_object_factory(TypeBuilder::get_class_name()); FileSetBlock *fsb = env->get_file_set_block(); suif_assert_message(fsb->get_file_block_count() == 1,("File is ambiguous")); FileBlock *fb = fsb->get_file_block(0); BasicSymbolTable *symtab = to<BasicSymbolTable>(fb->get_symbol_table()); DefinitionBlock *def = fb->get_definition_block (); QualifiedType *q_type = tb->get_qualified_type(type); VariableSymbol *var = create_variable_symbol( env,q_type, name, false ); symtab->append_symbol_table_object(var); VariableDefinition *vardef = create_variable_definition(env,var,type->get_bit_alignment(), vb,make_static); def->append_variable_definition(vardef); return var; }
static ObjectLocation get_object_filename(SuifObject *obj) { ObjectLocation loc; if (!obj) { return(loc); } while (obj && !is_kind_of<FileBlock>(obj)) { obj = obj->get_parent(); } if (!obj) return loc; FileBlock *fb = to<FileBlock>(obj); return(ObjectLocation(fb->get_source_file_name(), 0)); }
/*-------------------------------------------------------------------- * add_std_fse_menu * */ void add_std_fse_menu(vmenu* root_menu, char* parent_menu) { /* file set entry submenu */ FileSetBlock *fsb = suif_env->get_file_set_block(); if (!fsb) return; for (int i = 0; i < fsb->get_file_block_count(); ++i) { FileBlock *file = fsb->get_file_block(i); binding *b = new binding((bfun) &do_show_fse, file); const char* name = file->get_source_file_name().c_str(); root_menu->add_command(b, parent_menu, name ? name : "<no name>" ); } }
int FileVector::need_blocks(off_t offset, size_t size, block_list_t& list) { uint64_t start_block = offset_block(offset); uint64_t end_block = size_block(size, offset); for (uint64_t i = start_block; i < end_block + 1; i++) { FileBlock *fb = get(i, true); if (fb->needs_read()) { list.push_back(fb); } } return (int) list.size(); }
void CycleRead::read_dcmrawdatapath(QString dcmrawpath) { QFileInfo file; QDir dcmrawdir; dcmrawdir.setPath(dcmrawpath); QFileInfoList fList = dcmrawdir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files , QDir::Name); if (!fList.isEmpty()) // QMessageBox::warning(this, tr("Warning"), "No Files in Directory!\n"+file.absoluteFilePath(), // QMessageBox::Ok); { for(int i=0;i < fList.size(); ++i) { file = fList.at(i); if(("dcm" == file.completeSuffix()) && (!_all_filenames.contains(file.filePath()))) { _all_filenames.push_back(file.filePath()); if(_fileblocks.isEmpty()) { //if its the fist file - and no fileblocks exist - create first FileBlock fileblock; fileblock.set_file(file); _fileblocks.push_back(fileblock); } else { if(!_fileblocks.last().set_file(file)) { //if actual file is not for actual block FileBlock fileblock; fileblock.set_file(file); _fileblocks.push_back(fileblock); //create new block at the back } } } } } }
int FileVector::write(const char *buffer, size_t size, off_t offset) { block_list_t list; size_t bytes_written = 0; size_t total_bytes_written = 0; int count = get_blocks(offset, size, list); off_t block_offset = 0; size_t block_size = 0; size_t osize = size; (void) osize; if (count == 0 || size == 0) { return 0; } for (block_list_t::iterator it = list.begin(); it != list.end() && size > 0; it++) { block_offset = offset % m_buffer_size; if (size > m_buffer_size - block_offset) { size -= m_buffer_size - block_offset; block_size = m_buffer_size - block_offset; } else { block_size = size; size = 0; } FileBlock *fb = *it; ASSERT(fb); bytes_written = fb->write(buffer, block_size, block_offset); m_last_touched = fb->m_block; total_bytes_written += bytes_written; offset += block_size; } assert(osize == total_bytes_written); return total_bytes_written; }
int FileVector::read(char *buffer, size_t size, off_t offset) { block_list_t list; size_t bytes_read = 0; size_t total_bytes_read = 0; int count = get_blocks(offset, size, list); off_t block_offset = 0; size_t block_size = 0; if (count == 0) { return 0; } for (block_list_t::iterator it = list.begin(); it != list.end() && size > 0; it++) { block_offset = offset % m_buffer_size; if (size > m_buffer_size - block_offset) { size -= m_buffer_size - block_offset; block_size = m_buffer_size - block_offset; } else { block_size = size; size = 0; } FileBlock *fb = *it; ASSERT(fb); bytes_read = fb->read(buffer, block_size, block_offset); m_last_touched = fb->m_block; fb->m_read = true; total_bytes_read += bytes_read; offset += block_size; } return total_bytes_read; }
int Session::Receive(){ try{ //Use nonblocking IO receive data, throw Exception when occur error int bytes = 0; while((bytes = stream_->Receive(buf_, BUFSIZE)) <= 0) { if(bytes < 0 && (EINTR == errno || EAGAIN == errno)){ continue; } Error("Stream Closed by peer: buf=%p, len=%d, errnum=%d, errmsg=%s", buf_, bytes, errno, strerror(errno)); stream_->Close(); Close(); return 0; } //clear the flag flag_ = true; int n = circle_->add(buf_, bytes); //Note("Receive data: buf=%p, bytes=%d, add_buffer=%d", buf_, bytes, n); for (;;){ if (recv_ && circle_->used() >= HEADLEN) { bytes = circle_->get((char*)head_, HEADLEN); Trace("TRACE Receive Head: total=%d, get=%d, version=%f, type=%d, length=%lu", circle_->used(), bytes, head_->version, head_->type, head_->length); int rev = 0; if((rev = HeadImpl::CheckProtocol(*head_)) < 0){ Error("Protocol Broken"); stream_->Close(); return -1; } else if(HA == rev){ Trace("TRACE Receive a Heartbeat"); recv_ = true; continue; } recv_ = false; } if (!recv_ && circle_->used() >= (unsigned)head_->length) { char *buf = new char[head_->length]; bzero(buf, head_->length); ssize_t len = circle_->get(buf, head_->length); Trace("TRACE Receive body: total=%d, get=%d, type=%d, bodylen=%d", circle_->used(), len, head_->type, head_->length); recv_ = true; FileBlock *res = new FileBlock(); //Memorypool::Instance()->construct(buf, head_->length); assert(NULL != res); res->ParseFromArray(buf, head_->length); Trace("TRACE New FileBlock: buf=%p, len=%d", buf, head_->length); if(NULL == res){ Error("New FileBlock failed: buf_=%p, len=%d", buf_, head_->length); return -1; } //Note("ADD Addr=%p", res); activeq_->Enqueue(res); delete buf; } if ((recv_ && circle_->used() < HEADLEN) || (!recv_ && circle_->used() < (unsigned)head_->length)) { break; } } } catch (const Exception& e){ Error("Exception occur: errmsg=%s", e.what()); return -1; } return 0; }