Example #1
0
void
rip_manager_stop (RIP_MANAGER_INFO *rmi)
{
    // Make sure this function isn't getting called twice
    if (!rmi->started) {
	debug_printf ("rip_manager_stop() called while not started\n");
	return;
    }
    
    /* Write to pipe so ripping thread will exit select() */
#if __UNIX__
    debug_printf ("Writing to abort_pipe.\n");
    write (rmi->abort_pipe[1], "0", 1);
#endif

    // Make sure the ripping started before we try to stop
    debug_printf ("Waiting for m_started_sem...\n");
    threadlib_waitfor_sem(&rmi->started_sem);
    rmi->started = 0;

    // Causes the code running in the thread to bail
    debug_printf ("Closing stream_sock...\n");
    socklib_close(&rmi->stream_sock);

    // Kill external process
    if (rmi->ep) {
	debug_printf ("Close external\n");
	close_external (&rmi->ep);
    }

    // blocks until everything is ok and closed
    debug_printf ("Waiting for hthread_ripper to close...\n");
    threadlib_waitforclose(&rmi->hthread_ripper);
    debug_printf ("Destroying subsystems...\n");
    destroy_subsystems (rmi);
    debug_printf ("Destroying m_started_sem\n");
    threadlib_destroy_sem(&rmi->started_sem);
    debug_printf ("Done with rip_manager_stop\n");

    /* Close pipes */
#if __UNIX__
    debug_printf ("Closing abort_pipe.\n");
    close (rmi->abort_pipe[0]);
    close (rmi->abort_pipe[1]);
#endif
}
Example #2
0
int main()
{
	int ret = 0;
	struct e3d_window *wnd;
	struct shaders shaders;
	struct ulog_dev *log;

	ulog_flog(NULL, ULOG_INFO, "Starting\n");

	ret = init_subsystems();
	if (ret)
		goto err;

	wnd = e3d_window_new();
	if (!wnd) {
		ret = -1;
		goto err_subs;
	}

	ret = init_shaders(&shaders);
	if (ret)
		goto err_wnd;

	log = debug_log("Game: ");
	if (!log) {
		ret = -ENOMEM;
		goto err_shader;
	}

	ret = game_run(log, wnd, &shaders);

	ulog_unref(log);
err_shader:
	destroy_shaders(&shaders);
err_wnd:
	e3d_window_free(wnd);
err_subs:
	destroy_subsystems();
err:
	if (ret)
		ulog_flog(NULL, ULOG_ERROR, "Abort\n");
	else
		ulog_flog(NULL, ULOG_INFO, "Exiting\n");
	return -ret;
}
Example #3
0
static void
ripthread (void *thread_arg)
{
    error_code ret;
    RIP_MANAGER_INFO* rmi = (RIP_MANAGER_INFO*) thread_arg;
    debug_ripthread (rmi);
    debug_stream_prefs (rmi->prefs);

    /* Connect to remote server */
    ret = start_ripping (rmi);
    if (ret != SR_SUCCESS) {
	debug_printf ("Ripthread did start_ripping()\n");
	threadlib_signal_sem (&rmi->started_sem);
	post_error (rmi, ret);
	goto DONE;
    }

    rmi->status_callback (rmi, RM_STARTED, (void *)NULL);
    post_status (rmi, RM_STATUS_BUFFERING);
    debug_printf ("Ripthread did initialization\n");
    threadlib_signal_sem(&rmi->started_sem);

    while (TRUE) {
	debug_printf ("Gonna ripstream_rip\n");
        ret = ripstream_rip(rmi);
	debug_printf ("Did ripstream_rip\n");

	if (!rmi->started) {
	    break;
	}
	else if (rmi->megabytes_ripped >= rmi->prefs->maxMB_rip_size 
		 && GET_CHECK_MAX_BYTES (rmi->prefs->flags)) {
	    /* GCS Aug 23, 2003: bytes_ripped can still overflow */
	    socklib_close (&rmi->stream_sock);
	    destroy_subsystems (rmi);
	    //post_error (rmi, SR_ERROR_MAX_BYTES_RIPPED);
	    break;
	}
	else if (ret == SR_SUCCESS_BUFFERING) {
	    post_status (rmi, RM_STATUS_BUFFERING);
	    /* Fall through */
	}
	else if (ret == SR_ERROR_CANT_DECODE_MP3) {
	    post_error (rmi, ret);
	    continue;
	}
	else if ((ret == SR_ERROR_RECV_FAILED || 
		  ret == SR_ERROR_TIMEOUT || 
		  ret == SR_ERROR_NO_TRACK_INFO || 
		  ret == SR_ERROR_SELECT_FAILED) && 
		 GET_AUTO_RECONNECT (rmi->prefs->flags)) {
	    /* Try to reconnect */
	    post_status (rmi, RM_STATUS_RECONNECTING);
	    while (rmi->started) {
		socklib_close(&rmi->stream_sock);
		if (rmi->ep) {
		    debug_printf ("Close external\n");
		    close_external (&rmi->ep);
		}
		destroy_subsystems (rmi);
		ret = start_ripping (rmi);
		if (ret == SR_SUCCESS)
		    break;
		Sleep(1000);
	    }
	    if (!rmi->started) {
		break;
	    }
	    /* Fall through */
	}
	else if (ret == SR_ERROR_ABORT_PIPE_SIGNALLED) {
	    /* Normal exit condition CTRL-C on unix */
	    destroy_subsystems (rmi);
	    break;
	}
	else if (ret != SR_SUCCESS) {
	    destroy_subsystems (rmi);
	    post_error (rmi, ret);
	    break;
	}

	/* All systems go.  Caller should update GUI that it is ripping */
	if (rmi->filesize > 0) {
	    post_status (rmi, RM_STATUS_RIPPING);
	}
    }

    // We get here when there was either a fatal error
    // or we we're not auto-reconnecting and the stream just stopped
    // or when we have been told to stop, via the rmi->started flag
 DONE:
    rmi->status_callback (rmi, RM_DONE, 0);
    rmi->started = 0;
    debug_printf ("ripthread() exiting!\n");
}