/* Read metadata from hdfName and write temp file. */ void readMetadata(char *hdfName, FILE *metadataFile, char *attr) { intn i; int32 hdfFile; char attrname[100]; hdfFile = SDstart(hdfName, DFACC_READ); if (hdfFile == -1) { fprintf(stdout, "Unable to open HDF file %s \n", hdfName); fflush(stdout); exit(EXIT_FAILURE); } /* First, try attr name alone */ readAttr(hdfFile, metadataFile, attr); /* Now, try concatenating sequence numbers */ for (i = 0; i <= 9; i++) { sprintf(attrname, "%s.%d", attr, i); readAttr(hdfFile, metadataFile, attrname); } SDend(hdfFile); }
/** @details * Parsuje XML element a vytváří z něj konkrétní jeden frame. * @param el XML element <animation_item x,y,(shadow_x, shadow_y)> * obsahující definici jednoho framu. * @param width šířka framu animace * @param height výška framu animace * @param sur_src zdrojový obrázek, ze kterého se vyřízne frame * @param sur_shadow_src zdrojový obrýzek, ze kterého se vyřízne stín. * @see readAttr() */ void Animation::loadItem_(TiXmlElement* el, Uint16 width, Uint16 height, const Surface & sur_src, const Surface & sur_shadow_src){ // atributy pro surface Uint16 x, y; readAttr(el, "x", x); readAttr(el, "y", y); // vytvorit surface Surface sur= create_transparent_surface(width, height, false); SDL_Rect rect={x,y,width,height}; SDL_BlitSurface(sur_src.GetSurface(), &rect, sur.GetSurface(), 0); frames_.push_back(sur); if(!draw_shadow_) return; // atributy pro shadow readAttr(el, "shadow_x", x); readAttr(el, "shadow_y", y); // vytvorit surface sur= create_transparent_surface(width, height, true); rect.x=x; rect.y=y; SDL_BlitSurface(sur_shadow_src.GetSurface(), &rect, sur.GetSurface(), 0); shadow_frames_.push_back(sur); }
/** @details * Nastavuje inicializační hodnoty, parsuje XML element a * vytváří z něj animaci. * @param el XML element obsahující definici animace. * Minimálně musí obsahovat atributy x,y. * Typicky obsahuje podelement animation(rate="") s podelementy animation_item(x,y) * @param width šířka každého framu animace * @param height výška každého framu animace * @param sur_src zdrojový obrázek, ze kterého se vyřeže animace * @param sur_shadow_src zdrojový obrýzek, ze kterého se vyřežou stíny, * defaultně bez stínů. * @see Animation::loadItem_() */ const Animation & Animation::initialize(TiXmlElement* el, Uint16 width, Uint16 height, const Surface & sur_src, const Surface & sur_shadow_src){ // nastaveni defaultnich hodnot frames_.clear(); shadow_frames_.clear(); frame_period_ = 1000; next_frame_ = last_access_ = 0; draw_shadow_ = sur_shadow_src.GetSurface()!=0; if(!el) throw std::string("missing element"); // atributy loadItem_(el, width, height, sur_src, sur_shadow_src); // animace el= el->FirstChildElement("animation"); if(!el) return *this; // nemame animaci // ulozit rate Uint16 frame_rate; readAttr(el, "rate", frame_rate); if(frame_rate==0) throw std::string("attribute rate must be higher than 0"); frame_period_ /= frame_rate; // vsechny slozky animace el= el->FirstChildElement("animation_item"); if(!el) throw std::string("missing element <animation_item>"); while(el){ loadItem_(el, width, height, sur_src, sur_shadow_src); el= el->NextSiblingElement("animation_item"); } return *this; }
void SPTagUse::build(SPDocument *document, Inkscape::XML::Node *repr) { SPObject::build(document, repr); readAttr( "xlink:href" ); // We don't need to create child here: // reading xlink:href will attach ref, and that will cause the changed signal to be emitted, // which will call sp_tag_use_href_changed, and that will take care of the child }
bool Item::unserializeAttr(PropStream& propStream) { unsigned char attr_type; while(propStream.GET_UCHAR(attr_type)){ if(!readAttr((AttrTypes_t)attr_type, propStream)){ return false; break; } } return true; }
bool Item::unserializeAttr(PropStream& propStream) { uint8_t attr_type; while (propStream.GET_UCHAR(attr_type) && attr_type != 0) { Attr_ReadValue ret = readAttr((AttrTypes_t)attr_type, propStream); if (ret == ATTR_READ_ERROR) { return false; } else if (ret == ATTR_READ_END) { return true; } } return true; }
bool Item::unserializeAttr(PropStream& propStream) { uint8_t attrType = ATTR_END; while(propStream.getByte(attrType) && attrType != ATTR_END) { switch(readAttr((AttrTypes_t)attrType, propStream)) { case ATTR_READ_ERROR: return false; case ATTR_READ_END: return true; default: break; } } return true; }
/** * To read the attributes into memory we first have to get the number of * attribute instances of the structure @link perf_file_attr @endlink. To * achieve this, .attrs.size is divided by the size of the containing structure * @link perf_file_attr @endlink. Then we can read the array of instances from * the file offset .attrs.offset. For every instance we have to read the * corresponding IDs. As for the whole structure, there can be several ID's. * .ids.size is used to determine the number of IDs. If only one event source * was used, there is no ID entry since all records belong to the single one * @link perf_file_attr @endlink instance. * * We check that .attr.sample_id_all is set for all instances. This ensures that * all records have an timestamp and an identification entry. All instances are * checked that they have the same value for .attr.sample\_type. */ static bool readAttr() { struct perf_file_attr f_attr; if( (fheader.attrs.size % sizeof( struct perf_file_attr )) != 0 ){ char buf[256]; snprintf( buf, sizeof(buf), "problem with attrs size: %llu %lu", fheader.attrs.size, sizeof( struct perf_file_attr ) ); set_last_error( ERR_SIZE_MISMATCH, strdup(buf) ); return false; } eventAttrCount = fheader.attrs.size / sizeof( struct perf_file_attr ); eventAttr = (struct event_type_entry *)malloc( sizeof( *eventAttr ) * eventAttrCount ); trysys( lseek( i_fd, fheader.attrs.offset, SEEK_SET ) >= 0 ); /* special case if there is only one event * events don't have an ID tag, use default value */ if( eventAttrCount == 1 ){ try( add_link( -1ULL, &eventAttr[0] ) ); } off_t pos = lseek( i_fd, 0, SEEK_CUR ); unsigned int i; for( i = 0; i < eventAttrCount; i++ ){ trysys( lseek( i_fd, pos, SEEK_SET ) >= 0 ); try( readn( i_fd, &f_attr, sizeof(f_attr) ) ); pos = lseek( i_fd, 0, SEEK_CUR ); trysys( pos >= 0 ); trymsg( f_attr.attr.size == sizeof( f_attr.attr ), ERR_SIZE_MISMATCH, "f_attr.config.size" ); eventAttr[i].attr = f_attr.attr; if( !f_attr.attr.sample_id_all ){ set_last_error( ERR_NOT_YET_DEFINED, "need attr.sample_id_all" ); return false; } if( i == 0 ){ samplingType = f_attr.attr.sample_type; } else { if( samplingType != f_attr.attr.sample_type ){ set_last_error( ERR_SAMPLES_DIFFER_IN_TYPE, NULL ); return false; } } u64 f_id; unsigned int idcount = f_attr.ids.size / sizeof(f_id); if( idcount > 0 ){ trysys( lseek( i_fd, f_attr.ids.offset, SEEK_SET ) >= 0 ); unsigned int k; for( k = 0; k < idcount; k++ ){ try( readn( i_fd, &f_id, sizeof( f_id ) ) ); try( add_link( f_id, &eventAttr[i] ) ); } } } return true; } /** * There can also be several instances of the @link perf_trace_event_type * @endlink in the file. As before, the .event_types.size is used to determine * the number of instances. By comparing .config of the @link perf_file_attr * @endlink instances with .event_id of the @link perf_trace_event_type @endlink * instances the corresponding pairs are searched. .name from the latter is * assigned to the @link perf_file_attr @endlink instance. */ static bool readTypes() { unsigned int traceInfoCount = 0; struct perf_trace_event_type *traceInfo = NULL; if( (fheader.event_types.size % sizeof( struct perf_trace_event_type )) != 0 ){ char buf[256]; snprintf( buf, sizeof(buf), "problem with event_types size: %llu %lu\n", fheader.event_types.size, sizeof( struct perf_file_header ) ); set_last_error( ERR_SIZE_MISMATCH, strdup(buf) ); return false; } traceInfoCount = fheader.event_types.size / sizeof( struct perf_trace_event_type ); trysys( lseek( i_fd, fheader.event_types.offset, SEEK_SET ) >= 0 ); traceInfo = (struct perf_trace_event_type *)malloc( fheader.event_types.size ); trysys( traceInfo != NULL ); try( readn( i_fd, traceInfo, fheader.event_types.size ) ); unsigned int i, k; for( i = 0; i < eventAttrCount; i++ ){ for( k = 0; k < traceInfoCount; k++ ){ if( eventAttr[i].attr.config == traceInfo[k].event_id ){ memcpy( &eventAttr[i].name, traceInfo[k].name, sizeof(eventAttr[i].name) ); break; } } if( k == traceInfoCount ){ char buf[256]; snprintf( buf, sizeof(buf), "%llu", eventAttr[i].attr.config ); set_last_error( ERR_TRACE_INFO_NOT_FOUND_FOR_CONFIG, strdup(buf) ); return false; } } return true; } // ---- public ---- u64 get_sampling_type(){ return samplingType; } bool has_more_events(){ off_t off = lseek( i_fd, 0, SEEK_CUR ); trysys( off >= 0 ); //TODO: throw exception return off < (int)(fheader.data.offset+fheader.data.size); } bool next_event_header( struct perf_event_header* header ){ try( readn( i_fd, header, sizeof(*header) ) ); return true; }; bool read_event_data( union perf_event *evt ){ try( evt->header.size <= sizeof(*evt) ); try( readn( i_fd, &(evt->sample.array[0]), evt->header.size-sizeof(evt->header) ) ); return true; }; bool skip_event_data( struct perf_event_header* header ){ try( lseek( i_fd, header->size-sizeof(*header), SEEK_CUR ) >= 0 ); return true; }; /** * Reads the perf file header. * Testing .magic for the content "PERFFILE" to ensure that we are really * reading a perf file. Comparing the .attr_size with the size of the structure * @link perf_file_attr @endlink gives information whether the values * have to be swapped. For readperf, we assume this is not the case. */ bool start_session( int fd ){ i_fd = fd; try( readn( i_fd, &fheader, sizeof(fheader) ) ); const char MAGIC[8] = { 'P', 'E', 'R', 'F', 'F', 'I', 'L', 'E' }; if( fheader.magic != *((u64 *)MAGIC) ){ set_last_error( ERR_NO_PERF_FILE, NULL ); return false; } if( fheader.attr_size != sizeof(struct perf_file_attr) ){ set_last_error( ERR_SIZE_MISMATCH, "maybe needed swap but not implemented" ); return false; }; try( readAttr() ); try( readTypes() ); trysys( lseek( i_fd, fheader.data.offset, SEEK_SET ) >= 0 ); return true; } unsigned int get_entry_count(){ return eventAttrCount; } struct event_type_entry* get_entry_by_index( unsigned int index ){ return &eventAttr[index]; }; struct event_type_entry* get_entry( u64 id ){ unsigned int i; for( i = 0; i < linkcount; i++ ){ if( idlink[i].id == id ){ return idlink[i].entry; } } set_last_error( ERR_ENTRY_NOT_FOUND, "session:get_entry" ); return NULL; };