Exemple #1
0
cmyth_event_t
cmyth_event_get(cmyth_conn_t conn, char * data, int len)
{
	int count, err, consumed, i;
	char tmp[1024];
	cmyth_event_t event;
	cmyth_proginfo_t proginfo = NULL;

	if (conn == NULL)
		goto fail;

	if ((count=cmyth_rcv_length(conn)) <= 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, count);
		return CMYTH_EVENT_CLOSE;
	}

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;
	if (strcmp(tmp, "BACKEND_MESSAGE") != 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_string() failed (%d)\n",
			  __FUNCTION__, count);
		goto fail;
	}

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;
	if (strcmp(tmp, "RECORDING_LIST_CHANGE") == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE;
	} else if (strncmp(tmp, "RECORDING_LIST_CHANGE ADD", 25) == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_ADD;
		strncpy(data, tmp + 26, len);
	} else if (strcmp(tmp, "RECORDING_LIST_CHANGE UPDATE") == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_UPDATE;
		/* receive a proginfo structure - do nothing with it (yet?)*/
		proginfo = cmyth_proginfo_create();
		if (!proginfo) {
			cmyth_dbg(CMYTH_DBG_ERROR,
				"%s: cmyth_proginfo_create() failed\n",
				__FUNCTION__);
			goto fail;
		}
		consumed = cmyth_rcv_proginfo(conn, &err, proginfo, count);
		ref_release(proginfo);
		proginfo = NULL;
		count -= consumed;
	} else if (strncmp(tmp, "RECORDING_LIST_CHANGE DELETE", 28) == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_DELETE;
		strncpy(data, tmp + 29, len);
	} else if (strcmp(tmp, "SCHEDULE_CHANGE") == 0) {
		event = CMYTH_EVENT_SCHEDULE_CHANGE;
	} else if (strncmp(tmp, "DONE_RECORDING", 14) == 0) {
		event = CMYTH_EVENT_DONE_RECORDING;
	} else if (strncmp(tmp, "QUIT_LIVETV", 11) == 0) {
		event = CMYTH_EVENT_QUIT_LIVETV;
	} else if (strncmp(tmp, "LIVETV_WATCH", 12) == 0) {
		event = CMYTH_EVENT_WATCH_LIVETV;
		strncpy(data, tmp + 13, len);
	/* Sergio: Added to support the new live tv protocol */
	} else if (strncmp(tmp, "LIVETV_CHAIN UPDATE", 19) == 0) {
		event = CMYTH_EVENT_LIVETV_CHAIN_UPDATE;
		strncpy(data, tmp + 20, len);
	} else if (strncmp(tmp, "SIGNAL", 6) == 0) { 
		event = CMYTH_EVENT_SIGNAL; 
		/* get slock, signal, seen_pat, matching_pat */ 
		while (count > 0) { 
			/* get signalmonitorvalue name */ 
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count); 
			count -= consumed; 

			/* get signalmonitorvalue status */ 
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count); 
			count -= consumed; 
		}
	} else if (strncmp(tmp, "ASK_RECORDING", 13) == 0) {
		event = CMYTH_EVENT_ASK_RECORDING;
		if (cmyth_conn_get_protocol_version(conn) < 37) {
			/* receive 4 string - do nothing with them */
			for (i = 0; i < 4; i++) {
				consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) -1, count);
				count -= consumed;
			}
		} else {
			/* receive a proginfo structure - do nothing with it (yet?)*/
			proginfo = cmyth_proginfo_create();
			if (!proginfo) {
				cmyth_dbg(CMYTH_DBG_ERROR,
					"%s: cmyth_proginfo_create() failed\n",
					__FUNCTION__);
				goto fail;
			}
			consumed = cmyth_rcv_proginfo(conn, &err, proginfo, count);
			ref_release(proginfo);
			proginfo = NULL;
			count -= consumed;
		}
	} else if (strncmp(tmp, "CLEAR_SETTINGS_CACHE", 20) == 0) {
		event = CMYTH_EVENT_CLEAR_SETTINGS_CACHE;
	} else if (strncmp(tmp, "GENERATED_PIXMAP", 16) == 0) {
		/* capture the file which a pixmap has been generated for */
		event = CMYTH_EVENT_GENERATED_PIXMAP;
		consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
		count -= consumed;
		if (strncmp(tmp, "OK", 2) == 0) {
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
			count -= consumed;
			strncpy(data, tmp, len);
		} else {
			data[0] = 0;
		}
	} else if (strncmp(tmp, "SYSTEM_EVENT", 12) == 0) {
		event = CMYTH_EVENT_SYSTEM_EVENT;
		strncpy(data, tmp + 13, len);
	} else if (strncmp(tmp, "UPDATE_FILE_SIZE", 16) == 0) {
		event = CMYTH_EVENT_UPDATE_FILE_SIZE;
		strncpy(data, tmp + 17, len);
	} else if (strncmp(tmp, "COMMFLAG_START", 14) == 0) {
		event = CMYTH_EVENT_COMMFLAG_START;
		strncpy(data, tmp + 15, len);
	} else {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: unknown mythtv BACKEND_MESSAGE '%s'\n", __FUNCTION__, tmp);
		event = CMYTH_EVENT_UNKNOWN;
		strncpy(data, tmp, len);
	}

	while(count > 0) {
		consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
		count -= consumed;
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: leftover data %s\n", __FUNCTION__, tmp);
	}

	return event;

 fail:
	return CMYTH_EVENT_ERROR;
}
Exemple #2
0
cmyth_event_t
cmyth_event_get_message(cmyth_conn_t conn, char * data, int32_t len, cmyth_proginfo_t * prog)
{
	int count, err, consumed;
	char tmp[1024];
	cmyth_event_t event;
	cmyth_proginfo_t proginfo = NULL;

	if (conn == NULL)
		return CMYTH_EVENT_UNKNOWN;

	if ((count = cmyth_rcv_length(conn)) <= 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, count);
		return CMYTH_EVENT_CLOSE;
	}

	data[0] = 0;

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;
	if (strcmp(tmp, "BACKEND_MESSAGE") != 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_string() failed (%d)\n",
			  __FUNCTION__, count);
		event = CMYTH_EVENT_UNKNOWN;
		goto out;
	}

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;

	/*
	 * RECORDING_LIST_CHANGE
	 */
	if (strcmp(tmp, "RECORDING_LIST_CHANGE") == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE;
	}

	/*
	 * RECORDING_LIST_CHANGE ADD
	 */
	else if (strncmp(tmp, "RECORDING_LIST_CHANGE ADD", 25) == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_ADD;
		strncpy(data, tmp + 26, len);
	}

	/*
	 * RECORDING_LIST_CHANGE UPDATE
	 */
	else if (strcmp(tmp, "RECORDING_LIST_CHANGE UPDATE") == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_UPDATE;
		proginfo = cmyth_proginfo_create();
		if (!proginfo) {
			cmyth_dbg(CMYTH_DBG_ERROR,
				"%s: cmyth_proginfo_create() failed\n",
				__FUNCTION__);
			event = CMYTH_EVENT_UNKNOWN;
			goto out;
		}
		consumed = cmyth_rcv_proginfo(conn, &err, proginfo, count);
		count -= consumed;
		*prog = proginfo;
	}

	/*
	 * RECORDING_LIST_CHANGE DELETE
	 */
	else if (strncmp(tmp, "RECORDING_LIST_CHANGE DELETE", 28) == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE_DELETE;
		strncpy(data, tmp + 29, len);
	}

	/*
	 * SCHEDULE_CHANGE
	 */
	else if (strcmp(tmp, "SCHEDULE_CHANGE") == 0) {
		event = CMYTH_EVENT_SCHEDULE_CHANGE;
	}

	/*
	 * DONE_RECORDING
	 */
	else if (strncmp(tmp, "DONE_RECORDING", 14) == 0) {
		event = CMYTH_EVENT_DONE_RECORDING;
		strncpy(data, tmp + 15, len);
	}

	/*
	 * QUIT_LIVETV
	 */
	else if (strncmp(tmp, "QUIT_LIVETV", 11) == 0) {
		event = CMYTH_EVENT_QUIT_LIVETV;
	}

	/*
	 * LIVETV_WATCH
	 */
	else if (strncmp(tmp, "LIVETV_WATCH", 12) == 0) {
		event = CMYTH_EVENT_LIVETV_WATCH;
		strncpy(data, tmp + 13, len);
	}

	/*
	 * LIVETV_CHAIN UPDATE
	 */
	else if (strncmp(tmp, "LIVETV_CHAIN UPDATE", 19) == 0) {
		event = CMYTH_EVENT_LIVETV_CHAIN_UPDATE;
		strncpy(data, tmp + 20, len);
	}

	/*
	 * SIGNAL
	 */
	else if (strncmp(tmp, "SIGNAL", 6) == 0) {
		int32_t dstlen = len;
		event = CMYTH_EVENT_SIGNAL;
		/*Get Recorder ID */
		strncat(data, "cardid ", 7);
		strncat(data, tmp + 7, consumed - 12);
		strncat(data, ";", 2);
		/* get slock, signal, seen_pat, matching_pat */
		while (count > 0) {
			/* get signalmonitorvalue name */
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
			count -= consumed;
			/*strncat(data,tmp,dstlen-2);
			strncat(data,"=",2);
			dstlen -= consumed;*/
			/* get signalmonitorvalue status */
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
			count -= consumed;
			strncat(data,tmp,dstlen-2);
			strncat(data,";",2);
			dstlen -= consumed;
		}
	}

	/*
	 * ASK_RECORDING
	 */
	else if (strncmp(tmp, "ASK_RECORDING", 13) == 0) {
		event = CMYTH_EVENT_ASK_RECORDING;
		strncpy(data, tmp + 14, len);
		if (cmyth_conn_get_protocol_version(conn) >= 37) {
			proginfo = cmyth_proginfo_create();
			if (!proginfo) {
				cmyth_dbg(CMYTH_DBG_ERROR,
					"%s: cmyth_proginfo_create() failed\n",
					__FUNCTION__);
				event = CMYTH_EVENT_UNKNOWN;
				goto out;
			}
			consumed = cmyth_rcv_proginfo(conn, &err, proginfo, count);
			count -= consumed;
			*prog = proginfo;
		}
	}

	/*
	 * CLEAR_SETTINGS_CACHE
	 */
	else if (strncmp(tmp, "CLEAR_SETTINGS_CACHE", 20) == 0) {
		event = CMYTH_EVENT_CLEAR_SETTINGS_CACHE;
	}

	/*
	 * GENERATED_PIXMAP
	 */
	else if (strncmp(tmp, "GENERATED_PIXMAP", 16) == 0) {
		/* capture the file which a pixmap has been generated for */
		event = CMYTH_EVENT_GENERATED_PIXMAP;
		consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
		count -= consumed;
		if (strncmp(tmp, "OK", 2) == 0) {
			/* receive <chanid_timestamp (isoformat)> */
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
			count -= consumed;
			strncpy(data, tmp, len);
		}
	}

	/*
	 * SYSTEM_EVENT
	 */
	else if (strncmp(tmp, "SYSTEM_EVENT", 12) == 0) {
		event = CMYTH_EVENT_SYSTEM_EVENT;
		strncpy(data, tmp + 13, len);
	}

	/*
	 * UPDATE_FILE_SIZE
	 */
	else if (strncmp(tmp, "UPDATE_FILE_SIZE", 16) == 0) {
		event = CMYTH_EVENT_UPDATE_FILE_SIZE;
		strncpy(data, tmp + 17, len);
	}

	/*
	 * Unknown message
	 */
	else {
		cmyth_dbg(CMYTH_DBG_INFO,
			  "%s: unknown BACKEND_MESSAGE '%s'\n", __FUNCTION__, tmp);
		event = CMYTH_EVENT_UNKNOWN;
	}

	out:
	while(count > 0 && err == 0) {
		consumed = cmyth_rcv_data(conn, &err, tmp, sizeof(tmp) - 1, count);
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: leftover data: count %i, read %i, errno %i\n", __FUNCTION__, count, consumed, err);
		count -= consumed;
	}

	return event;
}
Exemple #3
0
cmyth_event_t
cmyth_event_get(cmyth_conn_t conn, char * data, int len)
{
	int count, err, consumed, i;
	char tmp[1024];
	cmyth_event_t event;
	cmyth_proginfo_t proginfo = NULL;

	if (conn == NULL)
		goto fail;

	if ((count=cmyth_rcv_length(conn)) <= 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, count);
		return CMYTH_EVENT_CLOSE;
	}

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;
	if (strcmp(tmp, "BACKEND_MESSAGE") != 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_string() failed (%d)\n",
			  __FUNCTION__, count);
		goto fail;
	}

	consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	count -= consumed;
	if (strcmp(tmp, "RECORDING_LIST_CHANGE") == 0) {
		event = CMYTH_EVENT_RECORDING_LIST_CHANGE;
	} else if (strcmp(tmp, "SCHEDULE_CHANGE") == 0) {
		event = CMYTH_EVENT_SCHEDULE_CHANGE;
	} else if (strncmp(tmp, "DONE_RECORDING", 14) == 0) {
		event = CMYTH_EVENT_DONE_RECORDING;
	} else if (strncmp(tmp, "QUIT_LIVETV", 11) == 0) {
		event = CMYTH_EVENT_QUIT_LIVETV;
   /* Sergio: Added to support the new live tv protocol */
  } else if (strncmp(tmp, "LIVETV_CHAIN UPDATE", 19) == 0) {
		event = CMYTH_EVENT_LIVETV_CHAIN_UPDATE;
		strncpy(data,tmp,len);
	} else if (strncmp(tmp, "SIGNAL", 6) == 0) { 
		event = CMYTH_EVENT_SIGNAL; 
		/* get slock, signal, seen_pat, matching_pat */ 
		while (count > 0) { 
			/* get signalmonitorvalue name */ 
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count); 
			count -= consumed; 

			/* get signalmonitorvalue status */ 
			consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count); 
			count -= consumed; 
		}
	} else if (strncmp(tmp, "ASK_RECORDING", 13) == 0) {
		event = CMYTH_EVENT_ASK_RECORDING;
		if (cmyth_conn_get_protocol_version(conn) < 37) {
			/* receive 4 string - do nothing with them */
			for (i=0; i<4; i++) {
				consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) -1, count);
				count -= consumed;
			}
		}
		else
		{
			/* receive a proginfo structure - do nothing with it (yet?)*/
			proginfo = cmyth_proginfo_create();
			if (!proginfo) {
				cmyth_dbg(CMYTH_DBG_ERROR,
					"%s: cmyth_proginfo_create() failed\n",
					__FUNCTION__);
				goto fail;
			}
			consumed = cmyth_rcv_proginfo(conn, &err, proginfo, count);
			ref_release(proginfo);
			proginfo=NULL;
			count -= consumed;
		}
	} else {
		cmyth_dbg(CMYTH_DBG_DETAIL,
			  "%s: unknown mythtv BACKEND_MESSAGE '%s'\n", __FUNCTION__, tmp);
		event = CMYTH_EVENT_UNKNOWN;
	}

  while(count > 0)
  {
	  consumed = cmyth_rcv_string(conn, &err, tmp, sizeof(tmp) - 1, count);
	  count -= consumed;
		cmyth_dbg(CMYTH_DBG_DEBUG, "%s: leftover data %s\n", __FUNCTION__, tmp);
  }

	return event;

 fail:
	return CMYTH_EVENT_UNKNOWN;
}
Exemple #4
0
int
main(int argc, char **argv)
{
	int c, opt_index;
	int verbose = 0;
	int opt_e = 0, opt_r = 0, opt_s = 0, opt_u = 0;
	char *server;

	while ((c=getopt_long(argc, argv, "hersuv", opts, &opt_index)) != -1) {
		switch (c) {
		case 'h':
			print_help(argv[0]);
			exit(0);
			break;
		case 'e':
			opt_e = 1;
			break;
		case 'r':
			opt_r = 1;
			break;
		case 's':
			opt_s = 1;
			break;
		case 'u':
			opt_u = 1;
			break;
		case 'v':
			verbose++;
			break;
		default:
			print_help(argv[0]);
			exit(1);
			break;
		}
	}

	if (optind == argc) {
		fprintf(stderr, "no server given!\n");
		return -1;
	}

	server = argv[optind];

	if (!is_alive(server)) {
		printf("%s is not responding.\n", server);
		return 1;
	}

	printf("%s is alive.\n", server);

	if (cmyth_conn_block_shutdown(control) < 0) {
		printf("Failed to block backend shutdown!\n");
	}

	if (verbose) {
		int version, count;
		cmyth_proglist_t list;
		long long total, used;

		printf("libcmyth version %s\n", cmyth_version());
		printf("librefmem version %s\n", ref_version());

		version = cmyth_conn_get_protocol_version(control);

		printf("\tprotocol version: %d\n", version);

		list = cmyth_proglist_get_all_recorded(control);
		count = cmyth_proglist_get_count(list);

		printf("\trecordings: %d\n", count);

		if (cmyth_conn_get_freespace(control, &total, &used) == 0) {
			printf("\ttotal space: %lld bytes\n", total);
			printf("\tused space:  %lld bytes\n", used);
		}

		get_event(server);

		ref_release(list);
	}

	if (opt_e) {
		get_recordings(verbose);
	}

	if (opt_r) {
		get_recorders(verbose);
	}

	if (opt_s) {
		get_scheduled(verbose);
	}

	if (opt_u) {
		get_upcoming(verbose);
	}

	if (cmyth_conn_allow_shutdown(control) < 0) {
		printf("Failed to allow backend shutdown!\n");
	}

	ref_release(control);

	if (verbose > 1) {
		unsigned int refs, bytes;

		ref_get_usage(&refs, &bytes);

		printf("Refmem: refs  %d\n", refs);
		printf("Refmem: bytes %d\n", bytes);

		if (refs > 0) {
			ref_alloc_show();
		}
	}

	return 0;
}