char * cmyth_proginfo_playgroup(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL playgroup\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_playgroup); }
cmyth_timestamp_t cmyth_proginfo_originalairdate(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL original air date\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_originalairdate); }
/* * cmyth_recorder_is_recording(cmyth_recorder_t rec) * * Scope: PUBLIC * * Description * * Determine whether recorder 'rec' is currently recording. Return * the true / false answer. * * Return Value: * * Success: 0 if the recorder is idle, 1 if the recorder is recording. * * Failure: -(ERRNO) */ int cmyth_recorder_is_recording(cmyth_recorder_t rec) { int err, count; int r; long c, ret; char msg[256]; if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return -EINVAL; } pthread_mutex_lock(&mutex); snprintf(msg, sizeof(msg), "QUERY_RECORDER %u[]:[]IS_RECORDING", rec->rec_id); if ((err=cmyth_send_message(rec->rec_conn, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); ret = err; goto out; } count = cmyth_rcv_length(rec->rec_conn); if ((r=cmyth_rcv_long(rec->rec_conn, &err, &c, count)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_length() failed (%d)\n", __FUNCTION__, r); ret = err; goto out; } ret = c; out: pthread_mutex_unlock(&mutex); return ret; }
/* * cmyth_chanlist_get_count() * * Scope: PUBLIC * * Description: * * Retrieve the number of elements in the channels list * structure in 'cl'. * * Return Value: * * Success: A number >= 0 indicating the number of items in 'cl' * * Failure: -(errno) */ int cmyth_chanlist_get_count(cmyth_chanlist_t cl) { if (!cl) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", __FUNCTION__); return -EINVAL; } return cl->chanlist_count; }
char * cmyth_proginfo_seriesid(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL series ID\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_seriesid); }
/* * cmyth_proginfo_category(cmyth_proginfo_t prog) * * * Scope: PUBLIC * * Description * * Retrieves the 'proginfo_category' field of a program info structure. * * The returned string is a pointer to the string within the program * info structure, so it should not be modified by the caller. The * return value is a 'char *' for this reason. * * Return Value: * * Success: A pointer to a 'char *' pointing to the field. * * Failure: NULL */ char * cmyth_proginfo_category(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program information\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_category); }
/* * cmyth_recordingrulelist_get_count() * * Scope: PUBLIC * * Description: * * Retrieve the number of elements in the recording schedule list * structure in 'rrl'. * * Return Value: * * Success: A number >= 0 indicating the number of items in 'rrl' * * Failure: -(errno) */ int cmyth_recordingrulelist_get_count(cmyth_recordingrulelist_t rrl) { if (!rrl) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL recordingrule list\n", __FUNCTION__); return -EINVAL; } return rrl->recordingrulelist_count; }
char * cmyth_proginfo_stars(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL stars\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_stars); }
char * cmyth_proginfo_inetref(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL inetref\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_inetref); }
int cmyth_recorder_done_ringbuf(cmyth_recorder_t rec) { int err; int ret = -1; char msg[256]; if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return -ENOSYS; } if(rec->rec_conn->conn_version >= 26) return 0; pthread_mutex_lock(&mutex); snprintf(msg, sizeof(msg), "QUERY_RECORDER %"PRIu32"[]:[]DONE_RINGBUF", rec->rec_id); if ((err=cmyth_send_message(rec->rec_conn, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); goto fail; } if ((err=cmyth_rcv_okay(rec->rec_conn)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_okay() failed (%d)\n", __FUNCTION__, err); goto fail; } ret = 0; fail: pthread_mutex_unlock(&mutex); return ret; }
/* * cmyth_recorder_check_channel(cmyth_recorder_t rec, char *channame) * * Scope: PUBLIC * * Description * * Request that the recorder 'rec' check the validity of the channel * specified by 'channame'. * * Return Value: * * Check the validity of a channel name. * Success: 1 - valid channel, 0 - invalid channel * * Failure: -(ERRNO) */ int cmyth_recorder_check_channel(cmyth_recorder_t rec, char *channame) { int err; int ret = -1; char msg[256]; if (!rec || !channame) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: invalid args " "rec = %p, channame = %p\n", __FUNCTION__, rec, channame); return -EINVAL; } pthread_mutex_lock(&rec->rec_conn->conn_mutex); snprintf(msg, sizeof(msg), "QUERY_RECORDER %d[]:[]CHECK_CHANNEL[]:[]%s", rec->rec_id, channame); if ((err=cmyth_send_message(rec->rec_conn, msg)) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_send_message() failed (%d)\n", __FUNCTION__, err); goto fail; } if ((err=cmyth_rcv_match(rec->rec_conn, "1")) < 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_rcv_match() failed (%d)\n", __FUNCTION__, err); goto fail; } ret = 0; fail: pthread_mutex_unlock(&rec->rec_conn->conn_mutex); return ret; }
/* * cmyth_timestamp_to_isostring(char *str, cmyth_timestamp_t ts) * * Scope: PUBLIC * * Description * * Create a string from the timestamp structure 'ts' and put it in the * user supplied buffer 'str'. The size of 'str' must be * CMYTH_TIMESTAMP_LEN + 1 or this will overwrite beyond 'str'. * * * Return Value: * * Success: 0 * * Failure: -(ERRNO) */ int cmyth_timestamp_to_isostring(char *str, cmyth_timestamp_t ts) { if (!str) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL output string provided\n", __FUNCTION__); return -EINVAL; } if (!ts) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL timestamp provided\n", __FUNCTION__); return -EINVAL; } sprintf(str, "%4.4ld-%2.2ld-%2.2ld", ts->timestamp_year, ts->timestamp_month, ts->timestamp_day); return 0; }
MYSQL * cmyth_db_get_connection(cmyth_database_t db) { if(cmyth_db_check_connection(db) != 0) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_db_check_connection failed\n", __FUNCTION__); return NULL; } return db->mysql; }
long cmyth_proginfo_card_id(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); return -1; } return prog->proginfo_card_id; }
int cmyth_proginfo_port(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); return -1; } return prog->proginfo_port; }
/* * cmyth_proginfo_host(cmyth_proginfo_t prog) * * Scope: PUBLIC * * Description * * Get the host name of the recorder serving the program 'prog'. * * Return Value: * * Success: A held, non-NULL string pointer * * Failure: NULL */ char* cmyth_proginfo_host(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); return NULL; } return ref_hold(prog->proginfo_host); }
/* * cmyth_proginfo_get_detail(cmyth_conn_t control, cmyth_proginfo_t prog) * * Scope: PUBLIC * * Description * * Completely fill out a program info based on a supplied (possibly * incomplete) program info. The supplied program info will be duplicated and * a pointer to the duplicate will be returned. * * NOTE: The original program info is released before the return. If the * caller wishes to retain access to the original it must already be * held before the call. This permits the called to replace a * program info directly with the return from this function. * * Return Value: * * Success: A held, Non-NULL program_info * * Failure: NULL */ cmyth_proginfo_t cmyth_proginfo_get_detail(cmyth_conn_t control, cmyth_proginfo_t p) { cmyth_proginfo_t ret = cmyth_proginfo_dup(p); if (ret == NULL) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_proginfo_dup() failed\n", __FUNCTION__); return NULL; } if (cmyth_proginfo_fill(control, ret) < 0) { ref_release(ret); cmyth_dbg(CMYTH_DBG_ERROR, "%s: cmyth_proginfo_fill() failed\n", __FUNCTION__); return NULL; } return ret; }
int8_t cmyth_proginfo_priority(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); return 0; } return prog->proginfo_rec_priority; }
uint32_t cmyth_proginfo_recordid(cmyth_proginfo_t prog) { if (!prog) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no program info\n", __FUNCTION__); return 0; } return prog->proginfo_record_id; }
/* * cmyth_rec_num_destroy(cmyth_rec_num_t rn) * * Scope: PRIVATE (static) * * Description * * Destroy and release all storage associated with the recorder number * structure 'rn'. This function should only ever be called by * cmyth_rec_num_release(). All others should call * cmyth_rec_num_release() to free rec_num structures. * * Return Value: * * None. */ static void cmyth_rec_num_destroy(cmyth_rec_num_t rn) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s\n", __FUNCTION__); if (!rn) { return; } if (rn->recnum_host) { ref_release(rn->recnum_host); } }
static int cmyth_livetv_chain_select(cmyth_recorder_t rec, struct timeval *timeout) { if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); return -EINVAL; } return cmyth_file_select(rec->rec_livetv_file, timeout); }
uint32_t cmyth_recorder_get_recorder_id(cmyth_recorder_t rec) { if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no recorder connection\n", __FUNCTION__); return 0; } return rec->rec_id; }
cmyth_commbreak_t cmyth_commbreak_create(void) { cmyth_commbreak_t ret = ref_alloc(sizeof(*ret)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); if (!ret) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); return NULL; } ref_set_destroy(ret, (ref_destroy_t)cmyth_commbreak_destroy); ret->start_mark = 0; ret->start_offset = 0; ret->end_mark = 0; ret->end_offset = 0; cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__); return ret; }
/* * cmyth_conn_destroy(cmyth_conn_t conn) * * Scope: PRIVATE (static) * * Description * * Tear down and release storage associated with a connection. This * should only be called by cmyth_conn_release(). All others should * call ref_release() to release a connection. * * Return Value: * * None. */ static void cmyth_conn_destroy(cmyth_conn_t conn) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); if (!conn) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s } !\n", __FUNCTION__); return; } if (conn->conn_buf) { free(conn->conn_buf); } if (conn->conn_fd >= 0) { cmyth_dbg(CMYTH_DBG_PROTO, "%s: shutdown and close connection fd = %d\n", __FUNCTION__, conn->conn_fd); shutdown(conn->conn_fd, SHUT_RDWR); closesocket(conn->conn_fd); } cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__); }
int cmyth_conn_get_protocol_version(cmyth_conn_t conn) { if (!conn) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); return -1; } return conn->conn_version; }
/* mythtv_mysql.c */ int cmyth_tuner_type_check_deprecated(cmyth_database_t db, cmyth_recorder_t rec, int check_tuner_type) { MYSQL_RES *res=NULL; MYSQL_ROW row; const char * query_str = "SELECT cardtype from capturecard WHERE cardid=?"; cmyth_mysql_query_t * query; if ( check_tuner_type == 0 ) { cmyth_dbg(CMYTH_DBG_ERROR,"MythTV Tuner check not enabled in Mythtv Options\n"); return (1); } query = cmyth_mysql_query_create(db,query_str); if (cmyth_mysql_query_param_uint(query,rec->rec_id) < 0) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, binding of query failed\n",__FUNCTION__); ref_release(query); return -1; } res = cmyth_mysql_query_result(query); if(res == NULL) { cmyth_dbg(CMYTH_DBG_ERROR,"%s, finalisation/execution\n",__FUNCTION__); return -1; } row = mysql_fetch_row(res); ref_release(query); mysql_free_result(res); if (strcmp(row[0],"MPEG") == 0) { return (1); //return the first available MPEG tuner } else if (strcmp(row[0],"HDHOMERUN") == 0) { return (1); //return the first available MPEG2TS tuner } else if (strcmp(row[0],"DVB") == 0) { return (1); //return the first available DVB tuner } else { return (0); } }
/* * cmyth_proglist_get_item() * * Scope: PUBLIC * * Description: * * Retrieve the program information structure found at index 'index' * in the list in 'pl'. Return the program information structure * held. Before forgetting the reference to this program info structure * the caller must call ref_release(). * * Return Value: * * Success: A non-null cmyth_proginfo_t (this is a pointer type) * * Failure: A NULL cmyth_proginfo_t */ cmyth_proginfo_t cmyth_proglist_get_item(cmyth_proglist_t pl, int index) { if (!pl) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL program list\n", __FUNCTION__); return NULL; } if (!pl->proglist_list) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: NULL list\n", __FUNCTION__); return NULL; } if ((index < 0) || (index >= pl->proglist_count)) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: index %d out of range\n", __FUNCTION__, index); return NULL; } ref_hold(pl->proglist_list[index]); return pl->proglist_list[index]; }
/* * cmyth_livetv_chain_get_block(cmyth_recorder_t rec, char *buf, * unsigned long len) * Scope: PUBLIC * Description * Read incoming file data off the network into a buffer of length len. * * Return Value: * Sucess: number of bytes read into buf * Failure: -1 */ int cmyth_livetv_chain_get_block(cmyth_recorder_t rec, char *buf, unsigned long len) { if (!rec) { cmyth_dbg(CMYTH_DBG_ERROR, "%s: no connection\n", __FUNCTION__); return -EINVAL; } return cmyth_file_get_block(rec->rec_livetv_file, buf, len); }
cmyth_input_t cmyth_input_create(void) { cmyth_input_t ret = ref_alloc(sizeof(*ret)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); if (!ret) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); return NULL; } ref_set_destroy(ret, (ref_destroy_t)cmyth_input_destroy); ret->inputname = NULL; ret->sourceid = 0; ret->inputid = 0; ret->cardid = 0; ret->multiplexid = 0; cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__); return ret; }
/* * cmyth_conn_create(void) * * Scope: PRIVATE (static) * * Description * * Allocate and initialize a cmyth_conn_t structure. This should only * be called by cmyth_connect(), which establishes a connection. * * Return Value: * * Success: A non-NULL cmyth_conn_t (this type is a pointer) * * Failure: A NULL cmyth_conn_t */ static cmyth_conn_t cmyth_conn_create(void) { cmyth_conn_t ret = ref_alloc(sizeof(*ret)); cmyth_dbg(CMYTH_DBG_DEBUG, "%s {\n", __FUNCTION__); if (!ret) { cmyth_dbg(CMYTH_DBG_DEBUG, "%s }!\n", __FUNCTION__); return NULL; } ref_set_destroy(ret, (ref_destroy_t)cmyth_conn_destroy); ret->conn_fd = -1; ret->conn_buf = NULL; ret->conn_len = 0; ret->conn_buflen = 0; ret->conn_pos = 0; ret->conn_hang = 0; cmyth_dbg(CMYTH_DBG_DEBUG, "%s }\n", __FUNCTION__); return ret; }