Ejemplo n.º 1
0
/*!
 \brief start_tickler() starts up a GTK+ timeout function based on the
 enum passed to it.
 \param type (TicklerType enum) is an enum passed which is used to know 
 which timeout to fire up.
 \see signal_read_rtvars_thread signal_read_rtvars
 */
G_MODULE_EXPORT void start_tickler(TicklerType type)
{
	gint id = 0;
	GThread *realtime_id = NULL;
	switch (type)
	{
		case RTV_TICKLER:
			if (DATA_GET(global_data,"offline"))
				break;
			if (!DATA_GET(global_data,"rtvars_loaded"))
				break;
			if (DATA_GET(global_data,"restart_realtime"))
			{
				update_logbar("comms_view",NULL,_("TTM is active, Realtime Reader suspended\n"),FALSE,FALSE,FALSE);
				break;
			}
			if (!DATA_GET(global_data,"realtime_id"))
			{
				flush_rt_arrays();

				realtime_id = g_thread_create(signal_read_rtvars_thread,
						NULL, /* Thread args */
						TRUE, /* Joinable */
						NULL); /*GError Pointer */
				DATA_SET(global_data,"realtime_id",realtime_id);
				update_logbar("comms_view",NULL,_("Realtime Reader started\n"),FALSE,FALSE,FALSE);
			}
			else
				update_logbar("comms_view","warning",_("Realtime Reader ALREADY started\n"),FALSE,FALSE,FALSE);
			break;
		case LV_PLAYBACK_TICKLER:
			if (!DATA_GET(global_data,"playback_id"))
			{
				id = gdk_threads_add_timeout((GINT)DATA_GET(global_data,"lv_scroll_delay"),(GSourceFunc)pb_update_logview_traces,GINT_TO_POINTER(FALSE));
				DATA_SET(global_data,"playback_id",GINT_TO_POINTER(id));
			}
			else
				dbg_func(CRITICAL,g_strdup(__FILE__": start_tickler()\n\tPlayback already running \n"));
			break;
		case SCOUNTS_TICKLER:
			if (DATA_GET(global_data,"offline"))
				break;
			if (!((DATA_GET(global_data,"connected")) && 
						(DATA_GET(global_data,"interrogated"))))
				break;
			if (!DATA_GET(global_data,"statuscounts_id"))
			{
				id = g_timeout_add(100,(GSourceFunc)update_errcounts,NULL);
				DATA_SET(global_data,"statuscounts_id",GINT_TO_POINTER(id));
			}
			else
				dbg_func(CRITICAL,g_strdup(__FILE__": start_tickler()\n\tStatuscounts tickler already active \n"));
			break;
		default:
			/* Search for registered handlers from plugins */
			break;

	}
}
Ejemplo n.º 2
0
/*!
  \brief start_datalogging() enables logging and if RT vars aren't running it
  starts them.
  */
G_MODULE_EXPORT void start_datalogging(void)
{
	ENTER();

	if (DATA_GET(global_data,"logging_active"))
	{
		EXIT();
		return;   /* Logging already running ... */
	}
	if (DATA_GET(global_data,"offline"))
	{
		EXIT();
		return;
	}
	if (lookup_widget("dlog_logable_vars_vbox1"))
		gtk_widget_set_sensitive(lookup_widget("dlog_logable_vars_vbox1"),FALSE);
	if (lookup_widget("dlog_format_delimit_hbox1"))
		gtk_widget_set_sensitive(lookup_widget("dlog_format_delimit_hbox1"),FALSE);
	if (lookup_widget("dlog_select_log_button"))
		gtk_widget_set_sensitive(lookup_widget("dlog_select_log_button"),FALSE);

	DATA_SET(global_data,"datalogging_header_needed",GINT_TO_POINTER(TRUE));
	DATA_SET(global_data,"logging_active",GINT_TO_POINTER(TRUE));
	update_logbar("dlog_view",NULL,_("DataLogging Started...\n"),FALSE,FALSE,FALSE);

	if (!DATA_GET(global_data,"offline"))
		start_tickler(RTV_TICKLER);
	DATA_SET(global_data,"forced_update",GINT_TO_POINTER(TRUE));
	EXIT();
	return;
}
Ejemplo n.º 3
0
/*!
 \brief early interrogation() is called from a one shot timeout from main
 in order to start the interrogation process as soon as the gui is up and 
 running.
 */
G_MODULE_EXPORT gboolean early_interrogation(void)
{
	set_title(g_strdup(_("Initiating background ECU interrogation...")));
	update_logbar("interr_view","warning",_("Initiating background ECU interrogation...\n"),FALSE,FALSE,FALSE);
	io_cmd("interrogation",NULL);
	return FALSE;
}
Ejemplo n.º 4
0
/*! 
  \brief select_datalog_for_import() loads a datalog file for playback
  \param widget is the Calling widget
  \param data is unused
  */
G_MODULE_EXPORT gboolean select_datalog_for_import(GtkWidget *widget, gpointer data)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	GIOChannel *iochannel = NULL;

	ENTER();
	reset_logviewer_state();
	free_log_info((Log_Info *)DATA_GET(global_data,"log_info"));

	fileio = g_new0(MtxFileIO ,1);
	fileio->default_path = g_strdup(DATALOG_DATA_DIR);
	fileio->project = (const gchar *)DATA_GET(global_data,"project_name");
	fileio->parent = lookup_widget("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("Choose a datalog to view");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;

	filename = choose_file(fileio);
	if (filename == NULL)
	{
		update_logbar("dlog_view","warning",_("NO FILE opened for logviewing!\n"),FALSE,FALSE,FALSE);
		EXIT();
		return FALSE;
	}

	iochannel = g_io_channel_new_file(filename, "r+",NULL);
	if (!iochannel)
	{
		update_logbar("dlog_view","warning",_("File open FAILURE! \n"),FALSE,FALSE,FALSE);
		EXIT();
		return FALSE;
	}

	update_logbar("dlog_view",NULL,_("DataLog ViewFile Opened\n"),FALSE,FALSE,FALSE);
	load_logviewer_file(iochannel);
	g_io_channel_shutdown(iochannel,FALSE,NULL);
	g_io_channel_unref(iochannel);

	update_logbar("dlog_view",NULL,_("LogView File Closed\n"),FALSE,FALSE,FALSE);
	gtk_widget_set_sensitive(lookup_widget("logviewer_controls_hbox"),TRUE);
	enable_playback_controls(TRUE);
	free_mtxfileio(fileio);
	EXIT();
	return TRUE;
}
Ejemplo n.º 5
0
/*!
 \brief stop_tickler() kills off the GTK+ timeout for the specified handler 
 passed across in the ENUM
 /param TicklerType an enumeration used to determine which handler to stop.
 \see start_tickler
 */
G_MODULE_EXPORT void stop_tickler(TicklerType type)
{
	GCond *rtv_thread_cond = NULL;
	GMutex *rtv_thread_mutex = NULL;
	rtv_thread_cond = DATA_GET(global_data,"rtv_thread_cond");
	rtv_thread_mutex = DATA_GET(global_data,"rtv_thread_mutex");
	g_return_if_fail(rtv_thread_mutex);

	switch (type)
	{
		case RTV_TICKLER:
			if (DATA_GET(global_data,"realtime_id"))
			{
				DATA_SET(global_data,"realtime_id",NULL);
				g_mutex_lock(rtv_thread_mutex);
				g_cond_signal(rtv_thread_cond);
				g_mutex_unlock(rtv_thread_mutex);
				update_logbar("comms_view",NULL,_("Realtime Reader stopped\n"),FALSE,FALSE,FALSE);
				DATA_SET(global_data,"realtime_id",NULL);
			}
			else
				update_logbar("comms_view",NULL,_("Realtime Reader ALREADY stopped\n"),FALSE,FALSE,FALSE);

			if (!DATA_GET(global_data,"leaving"))
				reset_runtime_status();
			break;

		case LV_PLAYBACK_TICKLER:
			if (DATA_GET(global_data,"playback_id"))
			{
				g_source_remove((GINT)DATA_GET(global_data,"playback_id"));
				DATA_SET(global_data,"playback_id",GINT_TO_POINTER(0));
			}
			break;
		case SCOUNTS_TICKLER:
			if (DATA_GET(global_data,"statuscounts_id"))
			{
				g_source_remove((GINT)DATA_GET(global_data,"statuscounts_id"));
				DATA_SET(global_data,"statuscounts_id",GINT_TO_POINTER(0));
			}
			break;
		default:
			break;
	}
}
Ejemplo n.º 6
0
/*!
  \brief stop_datalogging() stops the datalog process. It DOES not stop realtime
  variable readback though
  */
G_MODULE_EXPORT void stop_datalogging(void)
{
	ENTER();

	GIOChannel *iochannel = NULL;
	if (!DATA_GET(global_data,"logging_active"))
	{
		EXIT();
		return;
	}

	if (DATA_GET(global_data,"offline"))
	{
		EXIT();
		return;
	}
	DATA_SET(global_data,"logging_active",NULL);

	if (lookup_widget("dlog_logable_vars_vbox1"))
		gtk_widget_set_sensitive(lookup_widget("dlog_logable_vars_vbox1"),TRUE);
	if (lookup_widget("dlog_format_delimit_hbox1"))
		gtk_widget_set_sensitive(lookup_widget("dlog_format_delimit_hbox1"),TRUE);
	if (lookup_widget("dlog_select_log_button"))
		gtk_widget_set_sensitive(lookup_widget("dlog_select_log_button"),TRUE);
	if (lookup_widget("dlog_stop_logging_button"))
		gtk_widget_set_sensitive(lookup_widget("dlog_stop_logging_button"),FALSE);
	if (lookup_widget("dlog_start_logging_button"))
		gtk_widget_set_sensitive(lookup_widget("dlog_start_logging_button"),FALSE);
	gtk_label_set_text(GTK_LABEL(lookup_widget("dlog_file_label")),"No Log Selected Yet");


	update_logbar("dlog_view",NULL,_("DataLogging Stopped...\n"),FALSE,FALSE,FALSE);
	iochannel = (GIOChannel *) OBJ_GET(lookup_widget("dlog_select_log_button"),"data");
	if (iochannel)
	{
		g_io_channel_shutdown(iochannel,TRUE,NULL);
		g_io_channel_unref(iochannel);
	}

	g_list_free(object_list);
	object_list = NULL;
	last_len = 0;
	OBJ_SET(lookup_widget("dlog_select_log_button"),"data",NULL);

	EXIT();
	return;
}
Ejemplo n.º 7
0
/*!
  \brief initiates an offline ECU restore from file. Prompts for file, if
  valid, it calles the restore_all function from the ECU plugin
  */
G_MODULE_EXPORT void offline_ecu_restore_pf(void)
{
	MtxFileIO *fileio = NULL;
	gchar *filename = NULL;
	void (*restore_all_f)(const gchar *);
	Firmware_Details *firmware = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	get_symbol("restore_all_ecu_settings",(void **)&restore_all_f);

	g_return_if_fail(firmware);
	g_return_if_fail(restore_all_f);

	if (!DATA_GET(global_data,"interrogated"))
	{
		EXIT();
		return;
	}

	fileio = g_new0(MtxFileIO ,1);
	fileio->default_path = g_strdup(BACKUP_DATA_DIR);
	fileio->project = (const gchar *)DATA_GET(global_data,"project_name");
	fileio->parent = lookup_widget("main_window");
	fileio->on_top = TRUE;
	fileio->title = g_strdup("You should load an ECU backup from a file");
	fileio->action = GTK_FILE_CHOOSER_ACTION_OPEN;
	fileio->shortcut_folders = g_strdup(BACKUP_DATA_DIR);
	if (DATA_GET(global_data,"last_offline_filename"))
	fileio->default_filename = g_strdup((gchar *)DATA_GET(global_data,"last_offline_filename"));

	filename = choose_file(fileio);
	if (filename)
	{
		DATA_SET_FULL(global_data,"last_offline_filename",g_strdup(filename),g_free);
		update_logbar("tools_view",NULL,_("Full Restore of ECU Initiated\n"),FALSE,FALSE,FALSE);
		restore_all_f(filename);
		g_free(filename);
	}
	else
		io_cmd(firmware->get_all_command,NULL);

	free_mtxfileio(fileio);
	EXIT();
	return;
}
Ejemplo n.º 8
0
/*!
  \brief personality_choice() is called from a one shot timeout from main
  in order to open the window to ask the user what ECU family to deal with
  running.
  */
G_MODULE_EXPORT gboolean personality_choice(void)
{
	GtkWidget *dialog = NULL;
	GtkWidget *vbox = NULL;
	GtkWidget *hbox = NULL;
	GtkWidget *ebox = NULL;
	GtkWidget *sep = NULL;
	GtkWidget *button = NULL;
	GtkWidget *label = NULL;
	gchar ** dirs = NULL;
	gchar * filename = NULL;
	PersonaElement *element = NULL;
	gchar *tmpbuf = NULL;
	gboolean shouldjump = FALSE;
	gchar *name = NULL;
	GArray *classes = NULL;
	GSList *group = NULL;
	GList *p_list = NULL;
	GList *s_list = NULL;
	ConfigFile *cfgfile = NULL;
	guint i = 0;
	gint result = 0;
	gchar * pathstub = NULL;
	extern gconstpointer *global_data;

	pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",NULL);
	dirs = get_dirs((const gchar *)DATA_GET(global_data,"project_name"),pathstub,&classes);
	if (!dirs)
	{
		MTXDBG(CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n"));
		return FALSE;
	}
	i = 0;
	while (dirs[i])
	{
		tmpbuf = g_build_filename(dirs[i],"details.cfg",NULL);
		cfgfile = cfg_open_file(tmpbuf);
		if (!cfgfile)
		{
			/*MTXDBG(CRITICAL,_("\"%s\" file missing!, was MegaTunix installed properly?\n"),tmpbuf);*/
			i++;
			g_free(tmpbuf);
			continue;

		}
		g_free(tmpbuf);
		element = g_new0(PersonaElement, 1);
		cfg_read_string(cfgfile,"Family","sequence",&element->sequence);
		cfg_read_string(cfgfile,"Family","friendly_name",&element->name);
		cfg_read_string(cfgfile,"Family","persona",&element->persona);
		cfg_read_string(cfgfile,"Family","ecu_lib",&element->ecu_lib);
		cfg_read_string(cfgfile,"Family","common_lib",&element->common_lib);
		if (!cfg_read_string(cfgfile,"Family","baud",&element->baud_str))
			MTXDBG(CRITICAL,_("\"details.cfg\" baud string undefined!, was MegaTunix installed properly?\n"));
		element->dirname = g_strdup(dirs[i]);
		element->filename = g_path_get_basename(dirs[i]);
		if (g_strcasecmp(element->filename,(gchar *)DATA_GET(global_data,"last_ecu_family")) == 0)
			element->def = TRUE;
		if ((DATA_GET(global_data,"cli_persona")) && (element->persona))
		{
			if (g_strcasecmp(element->persona, (gchar *)DATA_GET(global_data,"cli_persona")) == 0)
			{
				button = gtk_toggle_button_new();
				gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE);
				persona_selection(button,(gpointer)element);
				g_object_ref_sink(button);
				g_object_unref(button);
				shouldjump = TRUE;
			}
		}

		if (g_array_index(classes,FileClass,i) == PERSONAL)
			p_list = g_list_prepend(p_list,(gpointer)element);
		if (g_array_index(classes,FileClass,i) == SYSTEM)
			s_list = g_list_prepend(s_list,(gpointer)element);
		g_free(name);
		i++;
		cfg_free(cfgfile);	
	}
	p_list = g_list_sort(p_list,persona_seq_sort);
	s_list = g_list_sort(s_list,persona_seq_sort);
	g_strfreev(dirs);
	g_array_free(classes,TRUE);
	if (shouldjump)
	{
		g_list_foreach(p_list,free_persona_element,NULL);
		g_list_foreach(s_list,free_persona_element,NULL);
		g_list_free(p_list);
		g_list_free(s_list);
		DATA_SET(global_data,"cli_persona",NULL);
		if (DATA_GET(global_data,"offline"))
			goto jumpahead_offline;
		else
			goto jumpahead;
	}

	set_title(g_strdup(_("Choose an ECU family?")));
	update_logbar("interr_view","warning",_("Prompting user for ECU family to interrogate...\n"),FALSE,FALSE,FALSE);

	dialog = gtk_dialog_new_with_buttons("Select ECU Personality",
			GTK_WINDOW(lookup_widget("main_window")),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			"Exit MegaTunix",
			GTK_RESPONSE_CLOSE,
			"Go Offline",
			GTK_RESPONSE_CANCEL,
			"Find my ECU",
			GTK_RESPONSE_OK,
			NULL);
	vbox = gtk_vbox_new(TRUE,2);
	gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
	//gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox),vbox,TRUE,TRUE,0);
	gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),vbox,TRUE,TRUE,0);
	if (g_list_length(p_list) > 0)
	{
		label = gtk_label_new("Custom (personal) Profiles");
		gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);

		group = NULL;
		/* Cycle list for PERSONAL profile files */
		for (i=0;i<g_list_length(p_list);i++)
		{
			element = (PersonaElement *)g_list_nth_data(p_list,i);

			ebox = gtk_event_box_new();
			gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
			hbox = gtk_hbox_new(FALSE,10);
			gtk_container_add(GTK_CONTAINER(ebox),hbox);
			label = gtk_label_new(element->name);
			gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
			if (!check_for_files (element->dirname,"prof"))
			{
				gtk_widget_set_sensitive(ebox,FALSE);
				button = gtk_radio_button_new(NULL);
			}
			else
			{
				button = gtk_radio_button_new(group);
				group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
			}
			g_signal_connect(button,
					"toggled",
					G_CALLBACK(persona_selection),
					element);
			gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
			if (element->def)
			{
				gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE);
				gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button));
			}
		}

		sep = gtk_hseparator_new();
		gtk_box_pack_start(GTK_BOX(vbox),sep,TRUE,TRUE,0);
	}
	label = gtk_label_new("System Wide ECU Profiles");
	gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
	/* Cycle list for System interogation files */
	for (i=0;i<g_list_length(s_list);i++)
	{
		element = (PersonaElement *)g_list_nth_data(s_list,i);
		ebox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
		hbox = gtk_hbox_new(FALSE,10);
		gtk_container_add(GTK_CONTAINER(ebox),hbox);
		label = gtk_label_new(element->name);
		gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
		if (!check_for_files (element->dirname,"prof"))
		{
			gtk_widget_set_sensitive(ebox,FALSE);
			button = gtk_radio_button_new(NULL);
		}
		else
		{
			button = gtk_radio_button_new(group);
			group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
		}
		g_signal_connect(button,
				"toggled",
				G_CALLBACK(persona_selection),
				element);
		gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
		if (element->def)
		{
			gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE);
			gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button));
		}
	}

	gtk_widget_show_all(dialog);
	result = gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	g_list_foreach(p_list,free_persona_element,NULL);
	g_list_foreach(s_list,free_persona_element,NULL);
	g_list_free(p_list);
	g_list_free(s_list);
	switch (result)
	{
		case GTK_RESPONSE_CLOSE:
			leave(NULL,NULL);
			break;
		case GTK_RESPONSE_ACCEPT:
		case GTK_RESPONSE_OK: /* Normal mode */
jumpahead:
			plugins_init();
			pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"comm.xml",NULL);
			filename = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,NULL);
			g_free(pathstub);
			load_comm_xml(filename);
			g_free(filename);
			io_cmd("interrogation",NULL);
			break;
		default: /* Offline */
jumpahead_offline:
			plugins_init();
			pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),"comm.xml",NULL);
			filename = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,NULL);
			g_free(pathstub);
			load_comm_xml(filename);
			g_free(filename);
			g_timeout_add(100,(GSourceFunc)set_offline_mode,NULL);
			return FALSE;
	}
	return FALSE;
}
Ejemplo n.º 9
0
/*!
  \brief load_gui_tabs_pf() is called after interrogation completes 
  successfully. It's purpose is to load all the glade files and 
  datamaps as specified in the interrogation profile of the detected firmware. 
  */
G_MODULE_EXPORT gboolean load_gui_tabs_pf(void)
{
	gint i = 0;
	gint cur = 0;
	ConfigFile *cfgfile = NULL;
	gchar * map_file = NULL;
	gchar * glade_file = NULL;
	gchar * tmpbuf = NULL;
	gchar * tab_name = NULL;
	gchar * tab_ident = NULL;
	gboolean tmpi = FALSE;
	GtkWidget *label = NULL;
	GtkWidget *container = NULL;
	GtkWidget *child = NULL;
	GtkWidget *notebook = NULL;
	GtkWidget *item = NULL;
	TabInfo *tabinfo = NULL;
	GPtrArray *tabinfos = NULL;
	extern GdkColor red;
	gboolean * hidden_list = NULL;
	Firmware_Details *firmware = NULL;
	CmdLineArgs *args = NULL;
	gchar * pathstub = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	args = (CmdLineArgs *)DATA_GET(global_data,"args");

	if (DATA_GET(global_data,"tabs_loaded"))
	{
		EXIT();
		return FALSE;
	}
	if (!firmware)
	{
		EXIT();
		return FALSE;
	}
	if (!firmware->tab_list)
	{
		EXIT();
		return FALSE;
	}
	if (!firmware->tab_confs)
	{
		EXIT();
		return FALSE;
	}
	if (args->inhibit_tabs)
	{
		EXIT();
		return FALSE;
	}

	set_title(g_strdup(_("Loading Gui Tabs...")));
	notebook = lookup_widget("toplevel_notebook");
	hidden_list = (gboolean *)DATA_GET(global_data,"hidden_list");
	tabinfos = g_ptr_array_new();

	while (firmware->tab_list[i])
	{

		pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_list[i],NULL);
		glade_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"glade");
		g_free(pathstub);
		pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_confs[i],NULL);
		map_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"datamap");
		g_free(pathstub);
		if (!g_file_test(glade_file,G_FILE_TEST_EXISTS))
		{
			MTXDBG(TABLOADER|CRITICAL,_("GLADE FILE: \"%s.glade\" NOT FOUND\n"),firmware->tab_list[i]);
			update_logbar("interr_view","warning",g_strdup(_("Glade File: ")),FALSE,FALSE,TRUE);
			update_logbar("interr_view","info",g_strdup_printf("\"%s.glade\"",firmware->tab_list[i]),FALSE,FALSE,TRUE);
			update_logbar("interr_view","warning",g_strdup(_("  is MISSING!\n")),FALSE,FALSE,TRUE);
			i++;
			continue;
		}
		if (!g_file_test(map_file,G_FILE_TEST_EXISTS))
		{
			MTXDBG(TABLOADER|CRITICAL,_("DATAMAP: \"%s.datamap\" NOT FOUND\n"),firmware->tab_confs[i]);
			update_logbar("interr_view","warning",g_strdup(_("Datamap File: ")),FALSE,FALSE,TRUE);
			update_logbar("interr_view","info",g_strdup_printf("\"%s.datamap\"",firmware->tab_confs[i]),FALSE,FALSE,TRUE);
			update_logbar("interr_view","warning",g_strdup(_("  is MISSING!\n")),FALSE,FALSE,TRUE);
			i++;
			continue;
		}
		cfgfile = cfg_open_file(map_file);
		if (cfgfile)
		{
			tabinfo = g_new0(TabInfo, 1);
			tabinfo->glade_file = g_strdup(glade_file);
			tabinfo->datamap_file = g_strdup(map_file);

			cfg_read_string(cfgfile,"global","tab_name",&tab_name);

			label = gtk_label_new(NULL);
			tabinfo->tab_label = label;
			gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),tab_name);
			if (cfg_read_boolean(cfgfile,"global","ellipsize",&tmpi))
			{
				if (tmpi)
				{
					OBJ_SET(label,"ellipsize_preferred",GINT_TO_POINTER(TRUE));
					if (DATA_GET(global_data,"ellipsize_tabs"))
						gtk_label_set_ellipsize(GTK_LABEL(label),PANGO_ELLIPSIZE_END);
				}
			}
			if (cfg_read_string(cfgfile,"global","bind_to_list",&tmpbuf))
			{
				OBJ_SET_FULL(label,"bind_to_list",g_strdup(tmpbuf),g_free);
				bind_to_lists(label,tmpbuf);
				g_free(tmpbuf);
				if (cfg_read_string(cfgfile,"global","match_type",&tmpbuf))
				{
					tmpi = translate_string(tmpbuf);
					g_free(tmpbuf);
					OBJ_SET(label,"match_type",GINT_TO_POINTER(tmpi));
				}
			}
			gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
			container = gtk_vbox_new(1,0);
			if (cfg_read_string(cfgfile,"topframe","tab_ident",&tab_ident))
			{
				tmpi = translate_string(tab_ident);
				g_free(tab_ident);
				OBJ_SET(container,"tab_ident",GINT_TO_POINTER(tmpi));
			}
			g_free(tab_name);
			OBJ_SET_FULL(label,"glade_file",g_strdup(glade_file),cleanup);
			OBJ_SET_FULL(label,"datamap_file",g_strdup(map_file),cleanup);
			OBJ_SET(label,"not_rendered",GINT_TO_POINTER(TRUE));
			gtk_notebook_append_page(GTK_NOTEBOOK(notebook),container,label);
			gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook),container,TRUE);
			gtk_widget_show(container);
			cur = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook))-1;
			tabinfo->page_num = cur;
			tabinfo->notebook = GTK_NOTEBOOK(notebook);
			if (hidden_list[cur] == TRUE)
			{
				child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),cur);
				label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),child);
				gtk_widget_hide(child);
				gtk_widget_hide(label);
				item = lookup_widget("show_tab_visibility_menuitem");
				gtk_widget_modify_text(gtk_bin_get_child(GTK_BIN(item)),GTK_STATE_NORMAL,&red);
			}
			g_ptr_array_add(tabinfos,(gpointer)tabinfo);
		}
		cfg_free(cfgfile);
		g_free(map_file);
		g_free(glade_file);
		i++;

		if (!firmware)
			break;
	}
	preload_deps(tabinfos);
	DATA_SET_FULL(global_data,"tabinfos",tabinfos,dealloc_tabinfos);
	DATA_SET(global_data,"tabs_loaded",GINT_TO_POINTER(TRUE));
	MTXDBG(TABLOADER,_("All is well, leaving...\n\n"));
	set_title(g_strdup(_("Gui Tabs Loaded...")));
	gdk_flush();
	EXIT();
	return TRUE;
}
Ejemplo n.º 10
0
/*!
 \brief gui_dispatcher() is a GTK+ timeout that runs 30 tiems per second checking
 for message on the dispatch queue which handles gui operations after a thread
 function runs, This will attempt to handle multiple messages at a time if the
 queue has multiple message queued up.
 \param data (gpointer) unused
 \returns TRUE 
 */
gboolean gui_dispatcher(gpointer data)
{
	gint len=0;
	gint i=0;
	UpdateFunction val = 0;
	gint count = 0;
	GtkWidget *widget = NULL;
	Io_Message *message = NULL;
	Text_Message *t_message = NULL;
	Widget_Update *w_update = NULL;
	QFunction *qfunc = NULL;
	extern volatile gboolean leaving;
	/*extern gint mem_view_style[];*/

	if (!gui_dispatch_queue) /*queue not built yet... */
	{
		g_cond_signal(gui_dispatch_cond);
		return TRUE;
	}
	/* Endless Loop, wait for message, processs and repeat... */
trypop:
	/*printf("gui_dispatch queue length is %i\n",g_async_queue_length(gui_dispatch_queue));*/
	if (leaving)
	{
		g_cond_signal(gui_dispatch_cond);
		return TRUE;
	}
	message = g_async_queue_try_pop(gui_dispatch_queue);
	if (!message)
	{
		/*	printf("no messages waiting, returning\n");*/
		g_cond_signal(gui_dispatch_cond);
		return TRUE;
	}

	if (message->functions != NULL)
	{
		len = message->functions->len;
		for (i=0;i<len;i++)
		{
			if (leaving)
			{
				dealloc_message(message);
				g_cond_signal(gui_dispatch_cond);
				return TRUE;
			}

			val = g_array_index(message->functions,UpdateFunction, i);
			/*printf("gui_dispatcher\n");*/
			switch ((UpdateFunction)val)
			{
				case UPD_LOGBAR:
					/*printf("logbar update\n");*/
					t_message = (Text_Message *)message->payload;
					gdk_threads_enter();
					update_logbar(t_message->view_name,t_message->tagname,t_message->msg,t_message->count,t_message->clear);
					gdk_threads_leave();
					dealloc_textmessage(t_message);
					message->payload = NULL;
					break;
				case UPD_RUN_FUNCTION:
					/*printf("run function\n");*/
					qfunc = (QFunction *)message->payload;
					gdk_threads_enter();
					run_post_functions(qfunc->func_name);
					gdk_threads_leave();
					dealloc_qfunction(qfunc);
					message->payload = NULL;
					break;

				case UPD_WIDGET:
					/*printf("widget update\n");*/
					widget = NULL;
					w_update = (Widget_Update *)message->payload;
					switch (w_update->type)
					{
						case MTX_ENTRY:
							/*printf("entry\n");*/
							if (NULL == (widget = lookup_widget(w_update->widget_name)))
								break;
							gdk_threads_enter();
							gtk_entry_set_text(GTK_ENTRY(widget),w_update->msg);
							gdk_threads_leave();
							break;
						case MTX_LABEL:
							/*printf("label\n");*/
							if (NULL == (widget = lookup_widget(w_update->widget_name)))
								break;
							gdk_threads_enter();
							gtk_label_set_text(GTK_LABEL(widget),w_update->msg);
							gdk_threads_leave();
							break;
						case MTX_TITLE:
							/*printf("title\n");*/
							gdk_threads_enter();
							set_title(g_strdup(w_update->msg));
							gdk_threads_leave();
							break;
						case MTX_SENSITIVE:
							/*printf("sensitivity change\n");*/
							if (NULL == (widget = lookup_widget(w_update->widget_name)))
								break;
							gdk_threads_enter();
							gtk_widget_set_sensitive(GTK_WIDGET(widget),w_update->state);
							gdk_threads_leave();
							break;
						default:
							break;
					}
					dealloc_w_update(w_update);
					message->payload = NULL;
					break;
					gdk_threads_enter();
					reset_temps(OBJ_GET(global_data,"temp_units"));
					gdk_threads_leave();
					/*
					   case UPD_RAW_MEMORY:
					   update_raw_memory_view(mem_view_style[message->offset],message->offset);
					   break;
					 */
			}

			gdk_threads_enter();
			while (gtk_events_pending())
			{
				if (leaving)
					goto dealloc;
				gtk_main_iteration();
			}
			gdk_threads_leave();
		}
	}
dealloc:
	dealloc_message(message);
	/*printf ("deallocation of dispatch message complete\n");*/
	count++;
	/* try to handle up to 4 messages at a time.  If this is 
	 * set too high, we can cause the timeout to hog the gui if it's
	 * too low, things can fall behind. (GL redraw ;( )
	 * */
	if ((count < 3) && (!leaving))
	{
		/*printf("trying to handle another message\n");*/
		goto trypop;
	}
	/*printf("returning\n");*/
	g_cond_signal(gui_dispatch_cond);
	return TRUE;
}