Beispiel #1
0
/* proginfo.c */
int
cmyth_get_delete_list_deprecated(cmyth_conn_t conn, char * msg, cmyth_proglist_t prog)
{
 int err=0;
 int count;
 int prog_count=0;

 if (!conn) {
 cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__);
 return -1;
 }
 pthread_mutex_lock(&conn->conn_mutex);
 if ((err = cmyth_send_message(conn, msg)) < 0) {
 fprintf (stderr, "ERROR %d \n",err);
 cmyth_dbg(CMYTH_DBG_ERROR,
 "%s: cmyth_send_message() failed (%d)\n",__FUNCTION__,err);
 return err;
 }
 count = cmyth_rcv_length(conn);
 cmyth_rcv_proglist(conn, &err, prog, count);
 prog_count=cmyth_proglist_get_count(prog);
 pthread_mutex_unlock(&conn->conn_mutex);
 return prog_count;
}
Beispiel #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;
}