示例#1
0
文件: state_file.c 项目: ion1/mpd
static void
state_file_write(void)
{
	FILE *fp;

	assert(state_file_path != NULL);

	g_debug("Saving state file %s", state_file_path);

	fp = fopen(state_file_path, "w");
	if (G_UNLIKELY(!fp)) {
		g_warning("failed to create %s: %s",
			  state_file_path, strerror(errno));
		return;
	}

	save_sw_volume_state(fp);
	audio_output_state_save(fp);
	playlist_state_save(fp, &g_playlist);

	fclose(fp);

	prev_volume_version = sw_volume_state_get_hash();
	prev_output_version = audio_output_state_get_version();
	prev_playlist_version = playlist_state_get_hash(&g_playlist);
}
示例#2
0
文件: state_file.c 项目: ion1/mpd
/**
 * This function is called every 5 minutes by the GLib main loop, and
 * saves the state file.
 */
static gboolean
timer_save_state_file(G_GNUC_UNUSED gpointer data)
{
	if (prev_volume_version == sw_volume_state_get_hash() &&
	    prev_output_version == audio_output_state_get_version() &&
	    prev_playlist_version == playlist_state_get_hash(&g_playlist))
		/* nothing has changed - don't save the state file,
		   don't spin up the hard disk */
		return true;

	state_file_write();
	return true;
}
示例#3
0
/**
 * This function is called every 5 minutes by the GLib main loop, and
 * saves the state file.
 */
static gboolean
timer_save_state_file(gpointer data)
{
	struct player_control *pc = data;

	if (prev_volume_version == sw_volume_state_get_hash() &&
	    prev_output_version == audio_output_state_get_version() &&
	    prev_playlist_version == playlist_state_get_hash(&g_playlist, pc))
		/* nothing has changed - don't save the state file,
		   don't spin up the hard disk */
		return true;

	state_file_write(pc);
	return true;
}
示例#4
0
static void
state_file_read(struct player_control *pc)
{
	FILE *fp;
	bool success;

	assert(state_file_path != NULL);

	g_debug("Loading state file %s", state_file_path);

	fp = fopen(state_file_path, "r");
	if (G_UNLIKELY(!fp)) {
		g_warning("failed to open %s: %s",
			  state_file_path, strerror(errno));
		return;
	}

	GString *buffer = g_string_sized_new(1024);
	const char *line;
	while ((line = read_text_line(fp, buffer)) != NULL) {
		success = read_sw_volume_state(line) ||
			audio_output_state_read(line) ||
			playlist_state_restore(line, fp, buffer,
					       &g_playlist, pc);
		if (!success)
			g_warning("Unrecognized line in state file: %s", line);
	}

	fclose(fp);

	prev_volume_version = sw_volume_state_get_hash();
	prev_output_version = audio_output_state_get_version();
	prev_playlist_version = playlist_state_get_hash(&g_playlist, pc);


	g_string_free(buffer, true);
}