Exemplo n.º 1
0
static int
get_event(char *host)
{
	struct timeval tv;
	cmyth_conn_t event;

	if ((event=cmyth_conn_connect_event(host, 6543,
					    16*1024, 4096)) == NULL) {
		return -1;
	}

	tv.tv_sec = 1;
	tv.tv_usec = 0;

	if (cmyth_event_select(event, &tv) > 0) {
		cmyth_event_t e;
		char data[128];

		memset(data, 0, sizeof(data));

		e = cmyth_event_get(event, data, sizeof(data));

		printf("Event: %d '%s'\n", e, data);
	}

	ref_release(event);

	return 0;
}
Exemplo n.º 2
0
static void*
cmyth_chain_event_loop(void *data)
{
	int oldstate;
	struct event_loop_args *args = (struct event_loop_args*)data;
	cmyth_chain_t chain = args->chain;
	cmyth_recorder_t rec = args->rec;
	cmyth_recorder_t new_rec;

	cmyth_dbg(CMYTH_DBG_DEBUG, "%s(): thread started!\n", __FUNCTION__);

	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);

	chain->chain_event = cmyth_conn_connect_event(rec->rec_server,
						      rec->rec_port,
						      16*1024, 4096);

	if (chain->chain_event == NULL) {
		return NULL;
	}

	new_rec = cmyth_conn_get_recorder(rec->rec_conn, rec->rec_id);

	chain->chain_thread_rec = new_rec;

	ref_release(chain);
	ref_release(rec);

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);

	while (1) {
		cmyth_event_t next;
		char buf[256];

		next = cmyth_event_get(chain->chain_event, buf, sizeof(buf));

		pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);

		switch (next) {
		case CMYTH_EVENT_LIVETV_CHAIN_UPDATE:
			cmyth_dbg(CMYTH_DBG_DEBUG,
				  "%s(): chain update %s\n", __FUNCTION__, buf);
			cmyth_chain_update(chain, new_rec, buf);
			break;
		default:
			break;
		}

		pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &oldstate);
	}

	return NULL;
}
Exemplo n.º 3
0
Arquivo: mythfuse.c Projeto: tsp/cmyth
static int
lookup_server(char *host)
{
	intptr_t i, j = -1;
	cmyth_conn_t control, event;

	debug("%s(): host '%s'\n", __FUNCTION__, host);

	for (i=0; i<MAX_CONN; i++) {
		if (conn[i].host && (strcmp(conn[i].host, host) == 0)) {
			break;
		}
		if ((j < 0) && (!conn[i].used)) {
			j = i;
		}
	}

	if (i == MAX_CONN) {
		if (j < 0) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			return -1;
		}
		conn[j].used = 1;
	}

	if (i == MAX_CONN) {
		if ((control=cmyth_conn_connect_ctrl(host, port, 16*1024,
						     tcp_control)) == NULL) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			conn[j].used = 0;
			return -1;
		}
		if ((event=cmyth_conn_connect_event(host, port, 16*1024,
						    tcp_control)) == NULL) {
			debug("%s(): error at %d\n", __FUNCTION__, __LINE__);
			conn[j].used = 0;
			return -1;
		}

		conn[j].host = strdup(host);
		conn[j].control = control;
		conn[j].event = event;
		conn[j].list = NULL;

		pthread_create(&conn[j].thread, NULL, event_loop, (void*)j);

		i = j;
	}

	return i;
}