Esempio n. 1
0
/*
 * cmyth_file_request_block()
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Request a file data block of a certain size, and return when the
 * block has been transfered.
 *
 * Return Value:
 *
 * Sucess: number of bytes transfered
 *
 * Failure: an int containing -errno
 */
int32_t
cmyth_file_request_block(cmyth_file_t file, int32_t len)
{
	int err, count;
	int r;
	int32_t c, ret;
	char msg[256];

	if (!file) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n",
			  __FUNCTION__);
		return -EINVAL;
	}

	pthread_mutex_lock(&mutex);

	if(len > file->file_data->conn_tcp_rcvbuf)
		len = file->file_data->conn_tcp_rcvbuf;

	snprintf(msg, sizeof(msg),
		 "QUERY_FILETRANSFER %"PRIu32"[]:[]REQUEST_BLOCK[]:[]%"PRId32,
		 file->file_id, len);

	if ((err = cmyth_send_message(file->file_control, msg)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_send_message() failed (%d)\n",
			  __FUNCTION__, err);
		ret = err;
		goto out;
	}

	if ((count=cmyth_rcv_length(file->file_control)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, count);
		ret = count;
		goto out;
	}
	if ((r=cmyth_rcv_int32(file->file_control, &err, &c, count)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_long() failed (%d)\n",
			  __FUNCTION__, r);
		ret = err;
		goto out;
	}

	file->file_req += c;
	ret = c;

    out:
	pthread_mutex_unlock(&mutex);

	return ret;
}
Esempio n. 2
0
/*
 * cmyth_proglist_get_list()
 *
 * Scope: PRIVATE (static)
 *
 * Description
 *
 * Obtain a program list from the query specified in 'msg' from the
 * function 'func'.  Make the query on 'conn' and put the results in
 * 'proglist'.
 *
 * Return Value:
 *
 * Success: 0
 *
 * Failure: -(ERRNO)
 */
static int
cmyth_proglist_get_list(cmyth_conn_t conn,
                        cmyth_proglist_t proglist,
                        char *msg, const char *func)
{
    int err = 0;
    int count;
    int ret;

    if (!conn) {
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", func);
        return -EINVAL;
    }
    if (!proglist) {
        cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program list\n", func);
        return -EINVAL;
    }

    pthread_mutex_lock(&conn->conn_mutex);

    if ((err = cmyth_send_message(conn, msg)) < 0) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_send_message() failed (%d)\n",
                  func, err);
        ret = err;
        goto out;
    }
    count = cmyth_rcv_length(conn);
    if (count < 0) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_rcv_length() failed (%d)\n",
                  func, count);
        ret = count;
        goto out;
    }
    if (strcmp(msg, "QUERY_GETALLPENDING") == 0) {
        int32_t c;
        int r;
        if ((r = cmyth_rcv_int32(conn, &err, &c, count)) < 0) {
            cmyth_dbg(CMYTH_DBG_ERROR,
                      "%s: cmyth_rcv_length() failed (%d)\n",
                      __FUNCTION__, r);
            ret = err;
            goto out;
        }
        count -= r;
    }
    if (cmyth_rcv_proglist(conn, &err, proglist, count) != count) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_rcv_proglist() < count\n",
                  func);
    }
    if (err) {
        cmyth_dbg(CMYTH_DBG_ERROR,
                  "%s: cmyth_rcv_proglist() failed (%d)\n",
                  func, err);
        ret = -1 * err;
        goto out;
    }

    ret = 0;

out:
    pthread_mutex_unlock(&conn->conn_mutex);

    return ret;
}
Esempio n. 3
0
/*
 * cmyth_proginfo_stop_recording()
 *
 * Scope: PUBLIC
 *
 * Description
 *
 * Make a request on the control connection 'control' to ask the
 * MythTV back end to stop recording the program described in 'prog'.
 *
 * Return Value:
 *
 * Success: 0
 *
 * Failure: -(ERRNO)
 */
int
cmyth_proginfo_stop_recording(cmyth_conn_t control, cmyth_proginfo_t prog)
{
	int32_t c = 0;
	int err = 0;
	int count = 0;
	int r = 0;
	int ret = 0;
	char *buf;
	char *proginfo;

	if (!control) {
		cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n",
			  __FUNCTION__);
		return -EINVAL;
	}
	if (control->conn_version < 12)
	{
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: stop not supported with protocol ver %d\n",
			  __FUNCTION__, control->conn_version);
		return -EINVAL;
	}

	proginfo = cmyth_proginfo_string(control, prog);
	if (proginfo == NULL) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: program_info failed.\n",
			  __FUNCTION__);
		return -EINVAL;
	}

	buf = malloc(strlen(proginfo) + 21 + 1);
	if (!buf) {
		free(proginfo);
		return -ENOMEM;
	}
	sprintf(buf, "STOP_RECORDING 0[]:[]%s", proginfo);
	free(proginfo);

	pthread_mutex_lock(&control->conn_mutex);

	if ((err = cmyth_send_message(control, buf)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_send_message() failed (%d)\n",
			  __FUNCTION__, err);
		ret = err;
		goto out;
	}

	count = cmyth_rcv_length(control);
	if ((r = cmyth_rcv_int32(control, &err, &c, count)) < 0) {
		cmyth_dbg(CMYTH_DBG_ERROR,
			  "%s: cmyth_rcv_length() failed (%d)\n",
			  __FUNCTION__, r);
		ret = err;
		goto out;
	}

	out:
	pthread_mutex_unlock(&control->conn_mutex);
	free(buf);

	return ret;
}