static void tny_fs_stream_cache_set_max_size (TnyStreamCache *self, gint64 max_size) { TnyFsStreamCachePriv *priv; g_return_if_fail (TNY_IS_FS_STREAM_CACHE (self)); priv = TNY_FS_STREAM_CACHE_GET_PRIVATE (self); priv->max_size = max_size; /* if se shrink the cache, then we have to drop old files */ remove_old_files (TNY_FS_STREAM_CACHE (self), 0); }
static TnyStream * tny_fs_stream_cache_get_stream (TnyStreamCache *self, const gchar *id, TnyStreamCacheOpenStreamFetcher fetcher, gpointer userdata) { TnyStream *result = NULL; TnyFsStreamCachePriv *priv; TnyCachedFile *cached_file; g_return_val_if_fail (TNY_IS_FS_STREAM_CACHE (self), NULL); g_return_val_if_fail (id, NULL); priv = TNY_FS_STREAM_CACHE_GET_PRIVATE (self); g_static_mutex_lock (priv->cache_lock); cached_file = g_hash_table_lookup (priv->cached_files, id); g_static_mutex_unlock (priv->cache_lock); if (cached_file) { result = tny_cached_file_get_stream (cached_file); } else { TnyStream *input_stream; gint64 expected_size = 0; input_stream = fetcher (self, &expected_size, userdata); if (input_stream == NULL) return NULL; if (expected_size <= get_available_size (TNY_FS_STREAM_CACHE (self))) { remove_old_files (TNY_FS_STREAM_CACHE (self), expected_size); cached_file = tny_cached_file_new (TNY_FS_STREAM_CACHE (self), id, expected_size, input_stream); g_static_mutex_lock (priv->cache_lock); g_hash_table_insert (priv->cached_files, g_strdup (id), cached_file); g_static_mutex_unlock (priv->cache_lock); result = tny_cached_file_get_stream (cached_file); } else { result = input_stream; } } return result; }
int main(int argc, char *argv[]) { FILE * inpipe; fsid_index_t * fsid_index; dir_index_t * dir_index; int files; int fd; pid_t pid; int policy; char txtbuf[100]; struct sched_param param; if (argc != 1) usage(); pid = getpid(); param.sched_priority = 1; sched_setscheduler(pid,1,¶m); logger_init( log_info, stdout, 0,0 ); daemon(0,0); /* Start indexing */ while (1) { fsid_index = NULL; dir_index = NULL; fsid_index = parse_nowshowing_tivo(); if(!fsid_index) { printf("Warning no FSID index\n"); sleep(90); continue; } fd = open("/var/index/nowshowing", O_WRONLY|O_CREAT|O_TRUNC|OS_FLAGS, READWRITE_PERMISSIONS); if(fd == -1) { LOG_ERROR("Unable to write /var/index/nowshowing"); exit(1); } write_fsid_index_list(fd, fsid_index); close(fd); dir_index = remove_old_files(fsid_index); files = 1; if(!dir_index) { /* Okat there might not be any files */ if( (files = count_files()) != 0) { printf("No dir index\n"); exit(1); } } if((create_index_files(fsid_index, dir_index, files)) == 0) { //free_fsid_index_list(fsid_index); //free_dir_index_list(dir_index); printf("Error indexing one or more recordings\n" "It may be that it got deleted during the indexing\n"); //exit(1); } //write_now_showing(fsid_index); free_fsid_index_list(fsid_index); if(dir_index) { free_dir_index_list(dir_index); } /* Sleep for 15 min */ sleep(900); } logger_free(); return(0); }