[Mvpmc-cvs] mvplib/libcmyth cmyth_local.h,1.9,1.10 connection.c,1.8,1.9 file.c,1.8,1.9 proginfo.c,1.
Status: Alpha
Brought to you by:
gettler
From: Jon G. <ge...@us...> - 2004-12-10 03:13:03
|
Update of /cvsroot/mvpmc/mvplib/libcmyth In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19961/libcmyth Modified Files: cmyth_local.h connection.c file.c proginfo.c proglist.c Log Message: Start adding locks around the myth protocol commands to prevent multiple commands being outstanding at the same time, since the protocol only supports serialized commands. Index: connection.c =================================================================== RCS file: /cvsroot/mvpmc/mvplib/libcmyth/connection.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** connection.c 5 Dec 2004 18:45:14 -0000 1.8 --- connection.c 10 Dec 2004 03:12:49 -0000 1.9 *************** *** 35,38 **** --- 35,40 ---- #include <cmyth_local.h> + pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + /* * cmyth_conn_create(void) Index: proginfo.c =================================================================== RCS file: /cvsroot/mvpmc/mvplib/libcmyth/proginfo.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** proginfo.c 5 Dec 2004 18:45:14 -0000 1.10 --- proginfo.c 10 Dec 2004 03:12:49 -0000 1.11 *************** *** 359,363 **** { long c = 0; ! char *ret; unsigned int len = ((2 * CMYTH_LONGLONG_LEN) + (4 * CMYTH_TIMESTAMP_LEN) + --- 359,363 ---- { long c = 0; ! char *buf; unsigned int len = ((2 * CMYTH_LONGLONG_LEN) + (4 * CMYTH_TIMESTAMP_LEN) + *************** *** 378,381 **** --- 378,382 ---- int count; long r; + int ret; if (!prog) { *************** *** 395,400 **** len += strlen(prog->proginfo_hostname); ! ret = alloca(len + 1+2048); ! if (!ret) { return -ENOMEM; } --- 396,401 ---- len += strlen(prog->proginfo_hostname); ! buf = alloca(len + 1+2048); ! if (!buf) { return -ENOMEM; } *************** *** 414,418 **** if (control->conn_version >= 14) { ! sprintf(ret, "%s 0[]:[]" "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" --- 415,419 ---- if (control->conn_version >= 14) { ! sprintf(buf, "%s 0[]:[]" "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" *************** *** 464,468 **** originalairdate_dt); } else if (control->conn_version >= 12) { ! sprintf(ret, "%s 0[]:[]" "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" --- 465,469 ---- originalairdate_dt); } else if (control->conn_version >= 12) { ! sprintf(buf, "%s 0[]:[]" "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" *************** *** 520,528 **** } ! if ((err = cmyth_send_message(control, ret)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ! return err; } --- 521,532 ---- } ! pthread_mutex_lock(&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; } *************** *** 532,536 **** "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! return err; } --- 536,541 ---- "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! ret = err; ! goto out; } *************** *** 540,544 **** */ ! return 0; } --- 545,554 ---- */ ! ret = 0; ! ! out: ! pthread_mutex_unlock(&mutex); ! ! return ret; } *************** *** 1175,1178 **** --- 1185,1214 ---- /* + * cmyth_proginfo_length(cmyth_proginfo_t prog) + * + * + * Scope: PUBLIC + * + * Description + * + * Retrieves the 'proginfo_Length' field of a program info + * structure. + * + * Return Value: + * + * Success: long long file length + * + * Failure: NULL + */ + long long + cmyth_proginfo_length(cmyth_proginfo_t prog) + { + if (!prog) { + return -1; + } + return prog->proginfo_Length; + } + + /* * cmyth_proginfo_rec_start(cmyth_proginfo_t prog) * *************** *** 1240,1241 **** --- 1276,1507 ---- return prog->proginfo_rec_status; } + + static int + fill_command(cmyth_conn_t control, cmyth_proginfo_t prog, char *cmd) + { + long c = 0; + char *buf; + unsigned int len = ((2 * CMYTH_LONGLONG_LEN) + + (4 * CMYTH_TIMESTAMP_LEN) + + (13 * CMYTH_LONG_LEN)); + char start_ts[CMYTH_TIMESTAMP_LEN + 1]; + char end_ts[CMYTH_TIMESTAMP_LEN + 1]; + char rec_start_ts[CMYTH_TIMESTAMP_LEN + 1]; + char rec_end_ts[CMYTH_TIMESTAMP_LEN + 1]; + char originalairdate[CMYTH_TIMESTAMP_LEN + 1]; + char lastmodified[CMYTH_TIMESTAMP_LEN + 1]; + char start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; + char end_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; + char rec_start_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; + char rec_end_ts_dt[CMYTH_TIMESTAMP_LEN + 1]; + char originalairdate_dt[CMYTH_TIMESTAMP_LEN + 1]; + char lastmodified_dt[CMYTH_TIMESTAMP_LEN + 1]; + int err; + int count; + long r; + int ret; + char *host = "mediamvp"; + + if (!prog) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", + __FUNCTION__); + return -EINVAL; + } + + len += strlen(prog->proginfo_title); + len += strlen(prog->proginfo_subtitle); + len += strlen(prog->proginfo_description); + len += strlen(prog->proginfo_category); + len += strlen(prog->proginfo_chanstr); + len += strlen(prog->proginfo_chansign); + len += strlen(prog->proginfo_channame); + len += strlen(prog->proginfo_url); + len += strlen(prog->proginfo_hostname); + + buf = alloca(len + 1+2048); + if (!buf) { + return -ENOMEM; + } + + cmyth_timestamp_to_string(start_ts, prog->proginfo_start_ts); + cmyth_timestamp_to_string(end_ts, prog->proginfo_end_ts); + cmyth_timestamp_to_string(rec_start_ts, prog->proginfo_rec_start_ts); + cmyth_timestamp_to_string(rec_end_ts, prog->proginfo_rec_end_ts); + cmyth_timestamp_to_string(originalairdate, prog->proginfo_originalairdate); + cmyth_timestamp_to_string(lastmodified, prog->proginfo_lastmodified); + cmyth_datetime_to_string(start_ts_dt, prog->proginfo_start_ts); + cmyth_datetime_to_string(end_ts_dt, prog->proginfo_end_ts); + cmyth_datetime_to_string(rec_start_ts_dt, prog->proginfo_rec_start_ts); + cmyth_datetime_to_string(rec_end_ts_dt, prog->proginfo_rec_end_ts); + cmyth_datetime_to_string(originalairdate_dt, prog->proginfo_originalairdate); + cmyth_datetime_to_string(lastmodified_dt, prog->proginfo_lastmodified); + + if (control->conn_version >= 14) { + sprintf(buf, + "%s %s[]:[]0[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%lld[]:[]" + "%lld[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" + "%ld[]:[]%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]" + "%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]%ld[]:[]" + "%ld[]:[]%s[]:[]%s[]:[]%ld[]:[]%ld[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]", + cmd, host, + prog->proginfo_title, + prog->proginfo_subtitle, + prog->proginfo_description, + prog->proginfo_category, + prog->proginfo_chanId, + prog->proginfo_chanstr, + prog->proginfo_chansign, + prog->proginfo_chanicon, + prog->proginfo_url, + prog->proginfo_Length >> 32, + (prog->proginfo_Length & 0xffffffff), + start_ts_dt, + end_ts_dt, + prog->proginfo_unknown_0, + prog->proginfo_recording, + prog->proginfo_override, + prog->proginfo_hostname, + prog->proginfo_source_id, + prog->proginfo_card_id, + prog->proginfo_input_id, + prog->proginfo_rec_priority, + prog->proginfo_rec_status, + prog->proginfo_record_id, + prog->proginfo_rec_type, + prog->proginfo_rec_dups, + prog->proginfo_unknown_1, + rec_start_ts_dt, + rec_end_ts_dt, + prog->proginfo_repeat, + prog->proginfo_program_flags, + prog->proginfo_recgroup, + prog->proginfo_chancommfree, + prog->proginfo_chan_output_filters, + prog->proginfo_seriesid, + prog->proginfo_programid, + lastmodified_dt, + prog->proginfo_stars, + originalairdate_dt); + } else if (control->conn_version >= 12) { + sprintf(buf, + "%s %s[]:[]0[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]%lld[]:[]" + "%lld[]:[]%s[]:[]%s[]:[]%s[]:[]%ld[]:[]" + "%ld[]:[]%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]" + "%s[]:[]%ld[]:[]%ld[]:[]%ld[]:[]%ld[]:[]" + "%ld[]:[]%s[]:[]%s[]:[]%ld[]:[]%ld[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]" + "%s[]:[]%s[]:[]%s[]:[]%s[]:[]", + cmd, host, + prog->proginfo_title, + prog->proginfo_subtitle, + prog->proginfo_description, + prog->proginfo_category, + prog->proginfo_chanId, + prog->proginfo_chanstr, + prog->proginfo_chansign, + prog->proginfo_chanicon, + prog->proginfo_url, + prog->proginfo_Length >> 32, + (prog->proginfo_Length & 0xffffffff), + start_ts, + end_ts, + prog->proginfo_unknown_0, + prog->proginfo_recording, + prog->proginfo_override, + prog->proginfo_hostname, + prog->proginfo_source_id, + prog->proginfo_card_id, + prog->proginfo_input_id, + prog->proginfo_rec_priority, + prog->proginfo_rec_status, + prog->proginfo_record_id, + prog->proginfo_rec_type, + prog->proginfo_rec_dups, + prog->proginfo_unknown_1, + rec_start_ts, + rec_end_ts, + prog->proginfo_repeat, + prog->proginfo_program_flags, + prog->proginfo_recgroup, + prog->proginfo_chancommfree, + prog->proginfo_chan_output_filters, + prog->proginfo_seriesid, + prog->proginfo_programid, + lastmodified, + prog->proginfo_stars, + originalairdate); + } else { + cmyth_dbg(CMYTH_DBG_ERROR, + "%s: fill not supported with protocol ver %d\n", + __FUNCTION__, control->conn_version); + return -EINVAL; + } + + 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; + } + + /* + * XXX: for some reason, this seems to return an error, even though + * it succeeds... + */ + + ret = 0; + + out: + return ret; + } + + int + cmyth_proginfo_fill(cmyth_conn_t control, cmyth_proginfo_t prog) + { + int err = 0; + int count; + int ret; + + if (!control) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); + return -EINVAL; + } + if (!prog) { + cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); + return -EINVAL; + } + + pthread_mutex_lock(&mutex); + + if ((ret=fill_command(control, prog, "FILL_PROGRAM_INFO") != 0)) + goto out; + + count = cmyth_rcv_length(control); + if (count < 0) { + cmyth_dbg(CMYTH_DBG_ERROR, + "%s: cmyth_rcv_length() failed (%d)\n", + __FUNCTION__, count); + ret = count; + goto out; + } + if (cmyth_rcv_proginfo(control, &err, prog, count) != count) { + cmyth_dbg(CMYTH_DBG_ERROR, + "%s: cmyth_rcv_proginfo() < count\n", __FUNCTION__); + ret = err; + goto out; + } + + ret = 0; + + out: + pthread_mutex_unlock(&mutex); + + return ret; + } Index: file.c =================================================================== RCS file: /cvsroot/mvpmc/mvplib/libcmyth/file.c,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** file.c 5 Dec 2004 18:45:14 -0000 1.8 --- file.c 10 Dec 2004 03:12:49 -0000 1.9 *************** *** 158,161 **** --- 158,163 ---- return 0; + pthread_mutex_lock(&mutex); + snprintf(msg, sizeof(msg), "QUERY_FILETRANSFER %ld[]:[]DONE", file->file_id); *************** *** 181,184 **** --- 183,188 ---- cmyth_file_destroy(file); + pthread_mutex_unlock(&mutex); + return 0; *************** *** 186,189 **** --- 190,195 ---- cmyth_atomic_inc(&file->refcount); + pthread_mutex_unlock(&mutex); + return err; } *************** *** 331,335 **** int err, count; int r; ! long c; char msg[256]; --- 337,341 ---- int err, count; int r; ! long c, ret; char msg[256]; *************** *** 340,343 **** --- 346,351 ---- } + pthread_mutex_lock(&mutex); + snprintf(msg, sizeof(msg), "QUERY_FILETRANSFER %ld[]:[]REQUEST_BLOCK[]:[]%ld", *************** *** 348,352 **** "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ! return err; } --- 356,361 ---- "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ! ret = err; ! goto out; } *************** *** 356,365 **** "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! return err; } file->file_pos += c; ! return c; } --- 365,379 ---- "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! ret = err; ! goto out; } file->file_pos += c; + ret = c; ! out: ! pthread_mutex_unlock(&mutex); ! ! return ret; } *************** *** 396,399 **** --- 410,414 ---- long r; long hi, lo; + long long ret; if ((control == NULL) || (file == NULL)) *************** *** 403,406 **** --- 418,423 ---- return file->file_pos; + pthread_mutex_lock(&mutex); + snprintf(msg, sizeof(msg), "QUERY_FILETRANSFER %ld[]:[]SEEK[]:[]%ld[]:[]%ld[]:[]%d[]:[]%ld[]:[]%ld", *************** *** 416,420 **** "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ! return err; } --- 433,438 ---- "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ! ret = err; ! goto out; } *************** *** 424,428 **** "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! return err; } --- 442,447 ---- "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! ret = err; ! goto out; } *************** *** 438,442 **** break; } ! return file->file_pos; } --- 457,466 ---- break; } + + ret = file->file_pos; + + out: + pthread_mutex_unlock(&mutex); ! return ret; } Index: cmyth_local.h =================================================================== RCS file: /cvsroot/mvpmc/mvplib/libcmyth/cmyth_local.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** cmyth_local.h 5 Dec 2004 18:45:14 -0000 1.9 --- cmyth_local.h 10 Dec 2004 03:12:49 -0000 1.10 *************** *** 26,29 **** --- 26,33 ---- #include <cmyth.h> #include <time.h> + #include <pthread.h> + + #define mutex __cmyth_mutex + extern pthread_mutex_t mutex; /* Index: proglist.c =================================================================== RCS file: /cvsroot/mvpmc/mvplib/libcmyth/proglist.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** proglist.c 11 Oct 2004 01:26:29 -0000 1.3 --- proglist.c 10 Dec 2004 03:12:49 -0000 1.4 *************** *** 252,255 **** --- 252,256 ---- int err = 0; int count; + int ret; if (!conn) { *************** *** 261,268 **** return -EINVAL; } if ((err = cmyth_send_message(conn, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", func, err); ! return err; } count = cmyth_rcv_length(conn); --- 262,273 ---- return -EINVAL; } + + pthread_mutex_lock(&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); *************** *** 270,274 **** cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", func, count); ! return count; } if (strcmp(msg, "QUERY_GETALLPENDING") == 0) { --- 275,280 ---- cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", func, count); ! ret = count; ! goto out; } if (strcmp(msg, "QUERY_GETALLPENDING") == 0) { *************** *** 279,283 **** "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! return err; } count -= r; --- 285,290 ---- "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ! ret = err; ! goto out; } count -= r; *************** *** 290,297 **** cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_proglist() failed (%d)\n", func, err); ! err = -1 * err; ! return err; } ! return 0; } --- 297,310 ---- 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(&mutex); ! ! return ret; } |