Example #1
0
static gboolean
cli_context_command_runnable (cli_context_t *ctx, command_action_t *action)
{
	xmmsc_connection_t *conn = cli_context_xmms_async (ctx);
	gint n = 0;

	/* Require connection, abort on failure */
	if (COMMAND_REQ_CHECK(action, COMMAND_REQ_CONNECTION) && !conn) {
		gboolean autostart;
		autostart = !COMMAND_REQ_CHECK(action, COMMAND_REQ_NO_AUTOSTART);
		if (!cli_context_connect (ctx, autostart) && autostart) {
			return FALSE;
		}
	}

	/* Get the cache ready if needed */
	if (COMMAND_REQ_CHECK(action, COMMAND_REQ_CACHE)) {
		/* If executing an alias have to refresh manually */
		if (cli_context_in_status (ctx, CLI_ACTION_STATUS_ALIAS)) {
			cli_context_cache_refresh (ctx);
		}
		while (cli_context_cache_refreshing (ctx)) {
			/* Obviously, there is a problem with updating the cache, abort */
			if (n == MAX_CACHE_REFRESH_LOOP) {
				g_printf (_("Failed to update the cache!"));
				return FALSE;
			}
			cli_context_event_loop_select (ctx);
			n++;
		}
	}

	return TRUE;
}
Example #2
0
gboolean
command_runnable (cli_infos_t *infos, command_action_t *action)
{
	gint n = 0;

	/* Require connection, abort on failure */
	if (COMMAND_REQ_CHECK(action, COMMAND_REQ_CONNECTION) && !infos->conn) {
		gboolean autostart;
		autostart = !COMMAND_REQ_CHECK(action, COMMAND_REQ_NO_AUTOSTART);
		if (!cli_infos_connect (infos, autostart) && autostart) {
			return FALSE;
		}
	}

	/* Get the cache ready if needed */
	if (COMMAND_REQ_CHECK(action, COMMAND_REQ_CACHE)) {
		/* If executing an alias have to refresh manually */
		if (infos->status == CLI_ACTION_STATUS_ALIAS) {
			cli_cache_refresh (infos);
		}
		while (!cli_cache_is_fresh (infos->cache)) {
			/* Obviously, there is a problem with updating the cache, abort */
			if (n == MAX_CACHE_REFRESH_LOOP) {
				g_printf (_("Failed to update the cache!"));
				return FALSE;
			}
			loop_select (infos);
			n++;
		}
	}

	return TRUE;
}