//разбор библиотеки void ParseLibrary (Parser::Iterator library_iter) { for_each_child (*library_iter, "vertex_streams.vertex_stream", xtl::bind (&XmlMeshLibraryLoader::ParseVertexStream, this, _1)); for_each_child (*library_iter, "vertex_streams.vertex_weight_stream", xtl::bind (&XmlMeshLibraryLoader::ParseVertexWeightStream, this, _1)); for_each_child (*library_iter, "vertex_buffers.vertex_buffer", xtl::bind (&XmlMeshLibraryLoader::ParseVertexBuffer, this, _1)); for_each_child (*library_iter, "index_buffers.index_buffer", xtl::bind (&XmlMeshLibraryLoader::ParseIndexBuffer, this, _1)); for_each_child (*library_iter, "meshes.mesh", xtl::bind (&XmlMeshLibraryLoader::ParseMesh, this, _1)); }
void DaeParser::ParseLibraryGeometries (Parser::Iterator iter) { if (!iter->First ("geometry")) { iter->Log ().Warning (*iter, "Empty 'library_geometries' node. Must be at least one 'geometry' sub-tag"); return; } for_each_child (*iter, "geometry", bind (&DaeParser::ParseGeometry, this, _1)); }
void check_all_locks(void) { unsigned int i; check_lock(&shm->reaper_lock); check_lock(&shm->syscalltable_lock); for_each_child(i) check_lock(&shm->children[i]->syscall.lock); }
void DaeParser::ParseLibraryMaterials (Parser::Iterator iter) { if (!iter->First ("material")) { iter->Log ().Warning (*iter, "Empty 'library_materials' node. Must be at least one 'material' sub-tag"); return; } for_each_child (*iter, "material", bind (&DaeParser::ParseMaterial, this, _1)); }
//разбор меша void ParseMesh (Parser::Iterator mesh_iter) { static const char* METHOD_NAME = "media::geometry::XmlMeshLibraryLoader::ParseMesh"; //чтение имён: меша, индексного буфера (если есть) const char *id = get<const char*> (*mesh_iter, "id"), *name = get<const char*> (*mesh_iter, "name", id), *ib_id = ""; try_read (*mesh_iter, "index_buffer", ib_id); //создание меша Mesh mesh; mesh.Rename (name); //поиск вершинных буферов for (Parser::AttributeIterator vb_iter=make_attribute_iterator (*mesh_iter, "vertex_buffers.#text"); vb_iter; ++vb_iter) { VertexBufferMap::iterator iter = vertex_buffers.find (*vb_iter); if (iter == vertex_buffers.end ()) throw xtl::make_argument_exception (METHOD_NAME, "vertex_buffers[i]", *vb_iter, "Vertex buffer not found"); mesh.Attach (iter->second); } //поиск индексного буфера IndexBuffer* ib = 0; if (*ib_id) { IndexBufferMap::iterator ib_iter = index_buffers.find (ib_id); if (ib_iter == index_buffers.end ()) throw xtl::make_argument_exception (METHOD_NAME, "index_buffer", ib_id, "Index buffer not found"); ib = &ib_iter->second; } if (ib) mesh.Attach (*ib); //чтение примитивов for_each_child (*mesh_iter, "primitives.primitive", xtl::bind (&XmlMeshLibraryLoader::ParsePrimitive, this, _1, xtl::ref (mesh))); //присоединение меша к модели library.Attach (id, mesh); }
/* returns TRUE if something is awry */ bool check_all_locks(void) { unsigned int i; bool ret = FALSE; check_lock(&shm->syscalltable_lock); for_each_child(i) ret |= check_lock(&shm->children[i]->syscall.lock); return ret; }
static void lstopo__prepare_custom_styles(struct lstopo_output *loutput, hwloc_obj_t obj) { struct lstopo_obj_userdata *lud = obj->userdata; struct lstopo_style *s = &lud->style; hwloc_obj_t child; unsigned forcer, forceg, forceb; const char *stylestr; lud->style_set = 0; stylestr = hwloc_obj_get_info_by_name(obj, "lstopoStyle"); if (stylestr) { while (*stylestr != '\0') { if (sscanf(stylestr, "%02x%02x%02x", &forcer, &forceg, &forceb) == 3 || sscanf(stylestr, "Background=#%02x%02x%02x", &forcer, &forceg, &forceb) == 3) { s->bg.r = forcer & 255; s->bg.g = forceg & 255; s->bg.b = forceb & 255; lud->style_set |= LSTOPO_STYLE_BG; loutput->methods->declare_color(loutput, &s->bg); s->t.r = s->t.g = s->t.b = (s->bg.r + s->bg.g + s->bg.b < 0xff) ? 0xff : 0; } else if (sscanf(stylestr, "Text=#%02x%02x%02x", &forcer, &forceg, &forceb) == 3) { s->t.r = forcer & 255; s->t.g = forceg & 255; s->t.b = forceb & 255; lud->style_set |= LSTOPO_STYLE_T; loutput->methods->declare_color(loutput, &s->t); } else if (sscanf(stylestr, "Text2=#%02x%02x%02x", &forcer, &forceg, &forceb) == 3) { s->t2.r = forcer & 255; s->t2.g = forceg & 255; s->t2.b = forceb & 255; lud->style_set |= LSTOPO_STYLE_T2; loutput->methods->declare_color(loutput, &s->t2); } stylestr = strchr(stylestr, ';'); if (!stylestr) break; stylestr++; } } for_each_child(child, obj) lstopo__prepare_custom_styles(loutput, child); for_each_memory_child(child, obj) lstopo__prepare_custom_styles(loutput, child); for_each_io_child(child, obj) lstopo__prepare_custom_styles(loutput, child); for_each_misc_child(child, obj) lstopo__prepare_custom_styles(loutput, child); }
static void kill_all_kids(void) { unsigned int i; shm->spawn_no_more = TRUE; reap_dead_kids(); /* Wait for all the children to exit. */ while (shm->running_childs > 0) { int children_seen = 0; /* Ok, some kids are still alive. 'help' them along with a SIGKILL */ for_each_child(i) { pid_t pid; int ret; pid = shm->children[i]->pid; if (pid == EMPTY_PIDSLOT) continue; /* if we find corruption, just skip over it. */ if (pid_is_valid(pid) == FALSE) continue; children_seen++; ret = kill(pid, SIGKILL); /* check we don't have anything stale in the pidlist */ if (ret == -1) { if (errno == ESRCH) reap_child(pid); } } if (children_seen == 0) shm->running_childs = 0; /* Check that no dead children hold locks. */ check_all_locks(); /* wait a second to give kids a chance to exit. */ sleep(1); } /* Just to be sure, clear out the pid slots. */ for_each_child(i) shm->children[i]->pid = EMPTY_PIDSLOT; }
void InstallInfo::loadXmlData(const XML::gcXMLElement &xmlNode, WildcardManager* pWildCard) { WildcardManager lwc(pWildCard); auto wcNode = xmlNode.FirstChildElement("wcards"); if (wcNode.IsValid()) { lwc.parseXML(wcNode); } xmlNode.GetChild("name", m_szName); auto icsNode = xmlNode.FirstChildElement("settings").FirstChildElement("installlocations"); if (!icsNode.IsValid()) return; icsNode.for_each_child("installlocation", [&](const XML::gcXMLElement &xmlChild) { if (m_bInstalled) return; const std::string path = xmlChild.GetChild("path"); const std::string check = xmlChild.GetChild("check"); if (path.empty() || check.empty()) return; char* CheckRes = nullptr; char* PathRes = nullptr; try { lwc.constructPath(check.c_str(), &CheckRes); lwc.constructPath(path.c_str(), &PathRes); if (CheckRes && PathRes && UTIL::FS::isValidFile(UTIL::FS::PathWithFile(CheckRes))) { m_szPath = PathRes; m_bInstalled = true; } } catch (gcException &e) { Debug(gcString("InstallInfo: Error parsing wildcards for installInfo: {0}\n", e)); } safe_delete(CheckRes); safe_delete(PathRes); }); }
static void fill_fullpaths(struct node *tree, const char *prefix) { struct node *child; const char *unit; tree->fullpath = join_path(prefix, tree->name); unit = strchr(tree->name, '@'); if (unit) tree->basenamelen = unit - tree->name; else tree->basenamelen = strlen(tree->name); for_each_child(tree, child) fill_fullpaths(child, tree->fullpath); }
static FILE * find_child_logfile_handle(pid_t pid) { int i; unsigned int j; FILE *log = NULL; i = find_childno(pid); if (i != CHILD_NOT_FOUND) { log = shm->children[i]->logfile; } else { /* This is pretty ugly, and should never happen, * but try again a second later, in case we're racing setup/teardown. * FIXME: We may not even need this now that we have proper locking; test it. */ sleep(1); i = find_childno(pid); if (i == CHILD_NOT_FOUND) { outputerr("Couldn't find child for pid %d\n", pid); return mainlogfile; } log = shm->children[i]->logfile; } if (log != NULL) return log; /* if the logfile hadn't been set, log to main. */ shm->children[i]->logfile = mainlogfile; outputerr("## child %d logfile handle was null logging to main!\n", i); outputerr("## Couldn't find logfile for pid %d\n", pid); dump_childnos(); outputerr("## Logfiles for pids: "); for_each_child(j) outputerr("%p ", shm->children[j]->logfile); outputerr("\n"); (void)fflush(stdout); sleep(5); return mainlogfile; }
void pids_init(void) { unsigned int i; if (read_pid_max()) { #ifdef __x86_64__ pidmax = 4194304; #else pidmax = 32768; #endif outputerr("Couldn't read pid_max from proc\n"); } output(0, "Using pid_max = %d\n", pidmax); pids = alloc_shared(max_children * sizeof(int)); for_each_child(i) pids[i] = EMPTY_PIDSLOT; }
FILE *robust_find_logfile_handle(void) { FILE *handle = NULL; if ((logging == TRUE) && (logfiles_opened)) { handle = find_logfile_handle(); if (!handle) { unsigned int j; outputerr("## child logfile handle was null logging to main!\n"); (void)fflush(stdout); for_each_child(j) shm->children[j]->logfile = mainlogfile; sleep(5); handle = find_logfile_handle(); } } return handle; }
static void lstopo_destroy_userdata(hwloc_obj_t parent) { hwloc_obj_t child; struct lstopo_obj_userdata *save = parent->userdata; if (save) { parent->userdata = save->common.next; free(save); } for_each_child(child, parent) lstopo_destroy_userdata(child); for_each_memory_child(child, parent) lstopo_destroy_userdata(child); for_each_io_child(child, parent) lstopo_destroy_userdata(child); for_each_misc_child(child, parent) lstopo_destroy_userdata(child); }
static void lstopo_populate_userdata(hwloc_obj_t parent) { hwloc_obj_t child; struct lstopo_obj_userdata *save = malloc(sizeof(*save)); save->common.buffer = NULL; /* so that it is ignored on XML export */ save->common.next = parent->userdata; save->pci_collapsed = 0; parent->userdata = save; for_each_child(child, parent) lstopo_populate_userdata(child); for_each_memory_child(child, parent) lstopo_populate_userdata(child); for_each_io_child(child, parent) lstopo_populate_userdata(child); for_each_misc_child(child, parent) lstopo_populate_userdata(child); }
int main () { printf ("Results of parse_for_each_child_test:\n"); ParseLog log; ParseTreeBuilder builder; builder.SetSource ("source1"); builder.BeginNode ("A", 1); builder.EndNode (); builder.BeginNode ("A", 2); builder.EndNode (); builder.BeginNode ("A", 3); builder.EndNode (); ParseNode root = builder.Build (log); for_each_child (root, "A", &f); log.Print (&print_log); return 0; }
static FILE * find_logfile_handle(void) { pid_t pid; int i; pid = getpid(); if (pid == initpid) return mainlogfile; if (pid == shm->mainpid) return mainlogfile; if (pid == watchdog_pid) return mainlogfile; i = find_childno(pid); if (i != CHILD_NOT_FOUND) return shm->children[i]->logfile; else { /* try one more time. FIXME: This is awful. */ unsigned int j; sleep(1); i = find_childno(pid); if (i != CHILD_NOT_FOUND) return shm->children[i]->logfile; outputerr("## Couldn't find logfile for pid %d\n", pid); dump_childnos(); outputerr("## Logfiles for pids: "); for_each_child(j) outputerr("%p ", shm->children[j]->logfile); outputerr("\n"); } return NULL; }
int main () { printf ("Results of parse_utils_test:\n"); ParseLog log; try { ParseTreeBuilder builder; builder.SetSource ("source1"); builder.BeginNode ("A", 1); builder.AddAttribute ("1"); builder.EndNode (); builder.BeginNode ("B", 2); builder.AddAttribute ("2.2"); builder.EndNode (); builder.BeginNode ("C", 3); builder.AddAttribute ("3a"); builder.EndNode (); builder.BeginNode ("D", 4); builder.AddAttribute ("1"); builder.AddAttribute ("2"); builder.AddAttribute ("3"); builder.EndNode (); builder.BeginNode ("E"); builder.AddAttribute ("a"); builder.EndNode (); builder.BeginNode ("E"); builder.AddAttribute ("b"); builder.AddAttribute ("c"); builder.EndNode (); ParseNode root = builder.Build (log); printf ("A=%d\n", get<int> (root, "A")); printf ("B=%.1f\n", get<float> (root, "B")); printf ("C=%.1f\n", get<float> (root, "C", 3.1f)); int array [3]; read (root, "D", array, 3); printf ("D="); for (int i=0; i<3; i++) printf ("%d ", array [i]); printf ("\n"); for_each_child (root, "E", &dump); printf ("ExceptionCheck=%.1f\n", get<float> (root, "C")); } catch (std::exception& exception) { printf ("exception: %s\n", exception.what ()); } log.Print (&print_log); return 0; }
//разбор вершинного потока void ParseVertexStream (Parser::Iterator vs_iter) { //чтение идентификатора потока const char* id = get<const char*> (*vs_iter, "id"); //определение числа вершин и размера вершины unsigned int vertices_count = get<unsigned int> (*vs_iter, "vertices_count"), vertex_size = get<unsigned int> (*vs_iter, "vertex_size"); VertexFormat vertex_format; //разбор вершинного формата for_each_child (*vs_iter, "channel", xtl::bind (&XmlMeshLibraryLoader::ParseVertexFormatChannel, this, _1, xtl::ref (vertex_format))); //создание вершинного потока VertexStream vs (vertices_count, VertexDeclaration (vertex_format, vertex_size)); //чтение данных Parser::NamesakeIterator channel_iter = vs_iter->First ("channel"); for (uint32_t i=0, channel_count=vertex_format.AttributesCount (); i<channel_count; i++, ++channel_iter) { const VertexAttribute& attribute = vertex_format.Attribute (i); for (;channel_iter && get<size_t> (*channel_iter, "offset", (size_t)-1) != attribute.offset; ++channel_iter); if (!channel_iter) return; switch (attribute.type) { case VertexAttributeType_Float2: read (*channel_iter, "#text", MakeVertexAttributeIterator<math::vec2f> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Float3: read (*channel_iter, "#text", MakeVertexAttributeIterator<math::vec3f> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Float4: read (*channel_iter,"#text", MakeVertexAttributeIterator<math::vec4f> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Short2: read (*channel_iter, "#text", MakeVertexAttributeIterator<math::vec2s> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Short3: read (*channel_iter, "#text", MakeVertexAttributeIterator<math::vec3s> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Short4: read (*channel_iter,"#text", MakeVertexAttributeIterator<math::vec4s> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_UByte4: read (*channel_iter, "#text", MakeVertexAttributeIterator<math::vec4ub> (vs, attribute.offset), vertices_count); break; case VertexAttributeType_Influence: read (*channel_iter, "#text", MakeVertexAttributeIterator<VertexInfluence> (vs, attribute.offset), vertices_count); break; default: return; } } //регистрация потока vertex_streams.insert_pair (id, vs); }