示例#1
0
int mpdc_init()
{
	static int warned_once = 0;
	if ((mpdz = mpd_init_connection()) == NULL) {
		if (!warned_once) {
			warned_once = 1;
		}
		return -1;
	}
	return 0;
}
示例#2
0
文件: mpdc.c 项目: Keripo/podzilla2
int mpdc_init()
{
	static int warned_once = 0;
	if ((mpdz = mpd_init_connection()) == NULL) {
		if (!warned_once) {
			pz_error(_("Unable to connect to MPD"));
			warned_once = 1;
		}
		return -1;
	}
	return 0;
}
示例#3
0
/* -------------------------------------------------------------------------- */
void *mpd_run(void *cookie)
{
    time_t next_update, current;
    gboolean result;
    int retry_count = RETRY_INTERVAL;
    struct lcd_stuff_mpd mpd;

    /* default values */
    mpd.lcd = (struct lcd_stuff *)cookie;
    mpd.mpd = NULL;
    mpd.error = 0;
    mpd.current_state = 0;
    mpd.song_displayed = false;
    mpd.current_song = NULL;
    mpd.stop_time = UINT_MAX;
    mpd.current_list = NULL;
    mpd.connection = NULL;
    mpd.timeout = 0;

    result = key_file_has_group(MODULE_NAME);
    if (!result) {
        report(RPT_INFO, "mpd disabled");
        conf_dec_count();
        return NULL;
    }

    if (!mpd_init(&mpd))
        goto out;

    if (!mpd_init_connection(&mpd))
        goto out_screen;
    if (!mpd_start_connection(&mpd))
        goto out_screen;

    /* do first update instantly */
    next_update = time(NULL);

    conf_dec_count();

    /* dispatcher */
    while (!g_exit) {

        /* if we are in error state, try to retrieve a connection first */
        if (mpd.error) {
            if (retry_count-- <= 0) { /* each minute */
                if (mpd_start_connection(&mpd)) {
                    mpd.error = false;
                } else {
                    retry_count = RETRY_INTERVAL;
                }
            }

            if (mpd.error) {
                g_usleep(1000000);
                continue;
            }
        }

        current = time(NULL);

        g_usleep(1000000);
        mpd_status_queue_update(mpd.mpd);
        mpd_status_check(mpd.mpd);
        mpd_update_status_time(&mpd);

        /* check playlists ? */
        if (current > next_update) {
            mpd_update_playlist_menu(&mpd);
            next_update = time(NULL) + 60;
        } if (current > mpd.stop_time) {
            mpd_player_stop(mpd.mpd);
            mpd.stop_time = UINT_MAX;
            service_thread_command(mpd.lcd->service_thread,
                                   "menu_set_item \"\" mpd_standby -value 0\n");
        }
    }

out_screen:
    mpd_deinit(&mpd);

out:
    if (mpd.mpd)
        mpd_free(mpd.mpd);
    if (mpd.current_list)
        mpd_free_playlist(mpd.current_list);
    service_thread_unregister_client(mpd.lcd->service_thread, MODULE_NAME);
    mpd_song_delete(mpd.current_song);
    connection_delete(mpd.connection);

    return NULL;
}