void load_elements(GtkWidget *dash, xmlNode *a_node) { xmlNode *cur_node = NULL; /* Iterate though all nodes... */ for (cur_node = a_node;cur_node;cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { if (g_strcasecmp((gchar *)cur_node->name,"dash_geometry") == 0) load_geometry(dash,cur_node); if (g_strcasecmp((gchar *)cur_node->name,"gauge") == 0) load_gauge(dash,cur_node); } load_elements(dash,cur_node->children); } }
static void load_elements(MtxGaugeFace *gauge, xmlNode * a_node) { xmlNode *cur_node = NULL; MtxXMLFuncs *xml_funcs = NULL; MtxGaugeFacePrivate *priv = NULL; g_return_if_fail(gauge); priv = MTX_GAUGE_FACE_GET_PRIVATE(gauge); g_return_if_fail(priv); for (cur_node = a_node; cur_node; cur_node = cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE) { /*printf("node type: Element, name: \"%s\"\n", cur_node->name);*/ xml_funcs = NULL; xml_funcs = (MtxXMLFuncs *)g_hash_table_lookup(priv->xmlfunc_hash,cur_node->name); /* If current element name has a set of function * handlers, call the handlers passing the child node. * NOTE in cases where the xml tag has no data the * child is NULL, we STILL need to call the handler * as in this context it means to CLEAR the value * (applies to text vals like "units_str"). We do * this in the handler by detecting that the node * passed is null and handle it appropriately */ if (xml_funcs) { xml_funcs->import_func(gauge,cur_node,xml_funcs->dest_var,xml_funcs->api_compat); } } load_elements(gauge,cur_node->children); } }
int main (int argc, char *argv[]) { char *pCurrentURL = NULL; char *pPlayURL1 = NULL; char *pPlayURL2 = NULL; int loopFlag = 1; int inputCommand = 0; char arr[1024] = ""; /* Check input arguments */ if (argc < 2) { g_printerr ("Usage: %s <url to play>\n", argv[0]); return -1; } pPlayURL1 = argv[1]; pPlayURL2 = argv[2]; /* Initialisation */ gst_init (&argc, &argv); load_elements (pPlayURL1); pCurrentURL = pPlayURL1; mplayer_play(); // g_print("g_timeout_add\n"); // g_timeout_add (500, (GSourceFunc) cb_test_position, pCurrentURL); while (loopFlag) { usuage(); g_print ("Enter your command here#\n"); inputCommand = getchar (); getchar (); fflush(NULL); switch (inputCommand) { case 'l': rewind_speed = 0; forward_speed = 0; play_speed = 0.0; /* When FW is active and wants to play, then we have to update the speed as 1 and just play from at that position */ if (trickPlay == 1) { trickPlay = 0; /* Set to Max value; the update_forward will reset to 0 */ forward_speed = 255; mplayer_ready(); mplayer_trickplay(update_forward(pCurrentURL)); } else if (mediaStop == 1) { mediaStop = 0; mplayer_trickplay(pCurrentURL); } mplayer_play(); break; case 'p': mplayer_pause(); break; case 's': mediaStop = 1; mplayer_ready(); break; case 'q': mplayer_stop(); loopFlag = 0; break; case 'r': mplayer_pause(); mplayer_trickplay(update_rewind (pCurrentURL)); mplayer_play(); break; case 'f': mplayer_pause(); mplayer_trickplay(update_forward(pCurrentURL)); mplayer_play(); default: break; } } return 0; }
void import_dash_xml(gchar * filename) { GtkWidget *dash = NULL; GList *children = NULL; GtkWidget * dialog = NULL; xmlDoc *doc = NULL; xmlNode *root_element = NULL; gint result = 0; g_return_if_fail(filename); dash = GTK_WIDGET(gtk_builder_get_object(toplevel,"dashboard")); children = GTK_FIXED(dash)->children; if (g_list_length(children) > 0) { dialog = gtk_message_dialog_new(NULL,GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Dashboard already containts %i gauges, destroy it?",g_list_length(children)); result = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy(dialog); if (result == GTK_RESPONSE_YES) clear_dashboard(dash); else return; } LIBXML_TEST_VERSION /*parse the file and get the DOM */ doc = xmlReadFile(filename, NULL, 0); if (doc == NULL) { printf("error: could not parse file %s\n",filename); return; } /*Get the root element node */ root_element = xmlDocGetRootElement(doc); load_elements(dash,root_element); OBJ_SET((dash),"dash_xml_filename",g_strdup(filename)); /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); return ; }
void mtx_gauge_face_import_xml(MtxGaugeFace *gauge, const gchar * filename) { xmlDoc *doc = NULL; xmlNode *root_element = NULL; gchar *tmpbuf = NULL; MtxGaugeFacePrivate *priv = NULL; g_return_if_fail(gauge); g_return_if_fail(filename); priv = MTX_GAUGE_FACE_GET_PRIVATE(gauge); g_return_if_fail(priv); /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /*parse the file and get the DOM */ doc = xmlReadFile(filename, NULL, 0); if (doc == NULL) { printf("error: could not parse file %s\n",filename); } else { /*Get the root element node */ root_element = xmlDocGetRootElement(doc); g_object_freeze_notify(G_OBJECT(gauge)); mtx_gauge_face_remove_all_text_blocks(gauge); mtx_gauge_face_remove_all_alert_ranges(gauge); mtx_gauge_face_remove_all_warning_ranges(gauge); mtx_gauge_face_remove_all_tick_groups(gauge); mtx_gauge_face_remove_all_polygons(gauge); load_elements(gauge, root_element); /* Fix for api break, default to CW gauges */ if (priv->rotation == 187) priv->rotation = MTX_ROT_CCW; if (priv->rotation == 188) priv->rotation = MTX_ROT_CW; priv->xc = priv->w / 2; priv->yc = priv->h / 2; priv->radius = MIN (priv->w/2, priv->h/2) - 5; g_object_thaw_notify(G_OBJECT(gauge)); if ((GTK_IS_WINDOW(gtk_widget_get_parent(GTK_WIDGET(gauge)))) && (priv->w > 0) && (priv->h > 0)) gtk_window_resize(GTK_WINDOW(gtk_widget_get_parent(GTK_WIDGET(gauge))),priv->w,priv->h); generate_gauge_background(gauge); mtx_gauge_face_set_value(MTX_GAUGE_FACE(gauge),priv->lbound); mtx_gauge_face_redraw_canvas (gauge); priv->xml_filename = g_strdup(filename); } g_free(tmpbuf); /*free the document */ xmlFreeDoc(doc); /* *Free the global variables that may *have been allocated by the parser. */ xmlCleanupParser(); }
/** Parse a keyfile * * @param _load_mesh : whether the mesh shall loaded * @return success : whether loading the data was successful * * The parameter can be used to prevent the loading of the mesh, * even though we use parse_mesh. We need this for includes. */ bool KeyFile::load(bool _load_mesh) { // read file auto my_filepath = resolve_include_filepath(get_filepath()); std::vector<char> char_buffer = read_binary_file(my_filepath); has_linebreak_at_eof = char_buffer.back() == '\n'; #ifdef QD_DEBUG std::cout << "done." << std::endl; #endif // init parallel worker if master file // if (parent_kf == this) // _wq.init_workers(1); // convert buffer into blocks size_t iLine = 0; std::string last_keyword; std::vector<std::string> line_buffer; std::vector<std::string> line_buffer_tmp; bool found_pgp_section = false; std::string line; auto string_buffer = std::string(char_buffer.begin(), char_buffer.end()); std::stringstream st(string_buffer); // for (; std::getline(st, line); ++iLine) { for (; std::getline(st, line); ++iLine) { if (line.find("-----BEGIN PGP") != std::string::npos) { found_pgp_section = true; #ifdef QD_DEBUG std::cout << "Found PGP Section\n"; #endif } // remove windows file ending ... I hate it ... if (line.size() != 0 && line.back() == '\r') line.pop_back(); // new keyword if (line[0] == '*' || found_pgp_section) { if (!line_buffer.empty() && !last_keyword.empty()) { // transfer possible header for following keyword (see function) transfer_comment_header(line_buffer, line_buffer_tmp); // get type auto kw_type = Keyword::determine_keyword_type(last_keyword); #ifdef QD_DEBUG std::cout << last_keyword << " -> "; switch (kw_type) { case (Keyword::KeywordType::NODE): std::cout << "NODE\n"; break; case (Keyword::KeywordType::ELEMENT): std::cout << "ELEMENT\n"; break; case (Keyword::KeywordType::PART): std::cout << "PART\n"; break; case (Keyword::KeywordType::GENERIC): std::cout << "GENERIC\n"; break; case (Keyword::KeywordType::INCLUDE): std::cout << "INCLUDE\n"; break; case (Keyword::KeywordType::INCLUDE_PATH): std::cout << "INCLUDE_PATH\n"; break; } #endif auto kw = create_keyword(line_buffer, kw_type, iLine - line_buffer.size() - line_buffer_tmp.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); // transfer cropped data line_buffer = line_buffer_tmp; } // we always trim keywords trim_right(line); last_keyword = line; } // IF:line[0] == '*' // Encrypted Sections // // Extracts encrypted section here and places it in a line in the // line buffer. An encrypted section is treated like a keyword. if (found_pgp_section) { found_pgp_section = false; // get stream position const auto stream_position = st.tellg(); const auto end_position = string_buffer.find("-----END PGP", stream_position); if (end_position == std::string::npos) throw( std::runtime_error("Could not find \"-----END PGP MESSAGE-----\" for " "corresponding \"-----BEGIN PGP MESSAGE-----\" ")); // set stream position behind encrypted section st.seekg(end_position); // extract encrypted stuff line += '\n'; line += std::string(char_buffer.begin() + stream_position, char_buffer.begin() + end_position); // print_string_as_hex(line); if (line.back() == '\n') line.pop_back(); if (line.back() == '\r') line.pop_back(); } // we stupidly add every line to the buffer line_buffer.push_back(line); } // for:line // allocate last block if (!line_buffer.empty() && !last_keyword.empty()) { auto kw = create_keyword(line_buffer, Keyword::determine_keyword_type(last_keyword), iLine - line_buffer.size() + 1); if (kw) keywords[kw->get_keyword_name()].push_back(kw); } // only load files above *END! const auto end_kw_position = get_end_keyword_position(); // includes if (load_includes) { // update include dirs get_include_dirs(true); // do the thing for (auto& include_kw : include_keywords) { if (include_kw->get_position() < end_kw_position) // Note: prevent loading the mesh here include_kw->load(false); } } // wait for threads to finish preloading // _wq.wait_for_completion(); // Wait for completion // while (work_queue.size() != 0) { // work_queue.front().wait(); // work_queue.pop(); // } // load mesh if requested if (parse_mesh && _load_mesh) { // load nodes load_nodes(); // load parts load_parts(); // load elements load_elements(); } return true; }