00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031 #ifndef __CONTENT_MANAGER_H__
00032 #define __CONTENT_MANAGER_H__
00033
00034 #include "common.h"
00035 #include "cds_objects.h"
00036 #include "storage.h"
00037 #include "dictionary.h"
00038 #include "sync.h"
00039 #include "autoscan.h"
00040 #include "timer.h"
00041 #include "generic_task.h"
00042 #ifdef HAVE_JS
00043
00044
00045 class PlaylistParserScript;
00046 #include "scripting/playlist_parser_script.h"
00047 #ifdef HAVE_LIBDVDNAV
00048 class DVDImportScript;
00049 #include "scripting/dvd_image_import_script.h"
00050 #endif
00051
00052 #endif
00053 #include "layout/layout.h"
00054 #ifdef HAVE_INOTIFY
00055 #include "autoscan_inotify.h"
00056 #endif
00057
00058 #ifdef EXTERNAL_TRANSCODING
00059 #include "transcoding/transcoding.h"
00060 #endif
00061
00062 #ifdef ONLINE_SERVICES
00063 #include "online_service.h"
00064 #ifdef YOUTUBE
00065 #include "cached_url.h"
00066 #include "reentrant_array.h"
00067 #define MAX_CACHED_URLS 20
00068 #define URL_CACHE_CHECK_INTERVAL 300
00069
00070
00071 #define URL_CACHE_LIFETIME 600
00072 #endif
00073 #endif//ONLINE_SERVICES
00074
00075 #if defined (EXTERNAL_TRANSCODING) || defined(SOPCAST)
00076 #include "executor.h"
00077 #endif
00078
00079 class CMAddFileTask : public GenericTask
00080 {
00081 protected:
00082 zmm::String path;
00083 zmm::String rootpath;
00084 bool recursive;
00085 bool hidden;
00086 public:
00087 CMAddFileTask(zmm::String path, zmm::String rootpath, bool recursive=false,
00088 bool hidden=false, bool cancellable = true);
00089 zmm::String getPath();
00090 zmm::String getRootPath();
00091 virtual void run();
00092 };
00093
00094 class CMRemoveObjectTask : public GenericTask
00095 {
00096 protected:
00097 int objectID;
00098 bool all;
00099 public:
00100 CMRemoveObjectTask(int objectID, bool all);
00101 virtual void run();
00102 };
00103
00104 class CMLoadAccountingTask : public GenericTask
00105 {
00106 public:
00107 CMLoadAccountingTask();
00108 virtual void run();
00109 };
00110
00111 class CMRescanDirectoryTask : public GenericTask
00112 {
00113 protected:
00114 int objectID;
00115 int scanID;
00116 scan_mode_t scanMode;
00117 public:
00118 CMRescanDirectoryTask(int objectID, int scanID, scan_mode_t scanMode,
00119 bool cancellable);
00120 virtual void run();
00121 };
00122
00123 class CMAccounting : public zmm::Object
00124 {
00125 public:
00126 CMAccounting();
00127 public:
00128 int totalFiles;
00129 };
00130
00131 #ifdef ONLINE_SERVICES
00132 class CMFetchOnlineContentTask : public GenericTask
00133 {
00134 protected:
00135 zmm::Ref<OnlineService> service;
00136 zmm::Ref<Layout> layout;
00137 bool unscheduled_refresh;
00138
00139 public:
00140 CMFetchOnlineContentTask(zmm::Ref<OnlineService> service,
00141 zmm::Ref<Layout> layout,
00142 bool cancellable, bool unscheduled_refresh);
00143 virtual void run();
00144 };
00145 #endif
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175 class ContentManager : public TimerSubscriberSingleton<ContentManager>
00176 {
00177 public:
00179 class TimerParameter : public zmm::Object
00180 {
00181 public:
00182 enum timer_param_t
00183 {
00184 IDAutoscan,
00185 #ifdef ONLINE_SERVICES
00186 IDOnlineContent,
00187 #ifdef YOUTUBE
00188 IDURLCache
00189 #endif
00190
00191 #endif
00192 };
00193
00194 TimerParameter(timer_param_t param, int id)
00195 {
00196 this->param = param;
00197 this->id = id;
00198 }
00199
00200 timer_param_t whoami() { return param; }
00201 void setID(int id) { this->id = id; }
00202 int getID() { return id; }
00203
00204 protected:
00205 timer_param_t param;
00206 int id;
00207 };
00208
00209
00210 ContentManager();
00211 virtual void init();
00212 virtual ~ContentManager();
00213 void shutdown();
00214
00215 virtual void timerNotify(zmm::Ref<zmm::Object> parameter);
00216
00217 bool isBusy() { return working; }
00218
00219 zmm::Ref<CMAccounting> getAccounting();
00220
00222 zmm::Ref<GenericTask> getCurrentTask();
00223
00225 zmm::Ref<zmm::Array<GenericTask> > getTasklist();
00226
00228 void invalidateTask(unsigned int taskID, task_owner_t taskOwner = ContentManagerTask);
00229
00230
00231
00232
00233
00234 void loadAccounting(bool async=true);
00235
00243 int addFile(zmm::String path, bool recursive=true, bool async=true,
00244 bool hidden=false, bool lowPriority=false,
00245 bool cancellable=true);
00246
00247 int ensurePathExistence(zmm::String path);
00248 void removeObject(int objectID, bool async=true, bool all=false);
00249 void rescanDirectory(int objectID, int scanID, scan_mode_t scanMode,
00250 zmm::String descPath = nil, bool cancellable = true);
00251
00255 void updateObject(int objectID, zmm::Ref<Dictionary> parameters);
00256
00257 zmm::Ref<CdsObject> createObjectFromFile(zmm::String path,
00258 bool magic=true,
00259 bool allow_fifo=false);
00260
00261 #ifdef ONLINE_SERVICES
00264 void fetchOnlineContent(service_type_t service, bool lowPriority=true,
00265 bool cancellable=true,
00266 bool unscheduled_refresh = false);
00267
00268 void cleanupOnlineServiceObjects(zmm::Ref<OnlineService> service);
00269
00270 #ifdef YOUTUBE
00272 void cacheURL(zmm::Ref<CachedURL> url);
00274 zmm::String getCachedURL(int objectID);
00275 #endif
00276 #endif//ONLINE_SERVICES
00277
00286 void addVirtualItem(zmm::Ref<CdsObject> obj, bool allow_fifo=false);
00287
00293 void addObject(zmm::Ref<CdsObject> obj);
00294
00303 int addContainerChain(zmm::String chain, zmm::String lastClass = nil,
00304 int lastRefID = INVALID_OBJECT_ID);
00305
00310 void addContainer(int parentID, zmm::String title, zmm::String upnpClass);
00311
00314 void updateObject(zmm::Ref<CdsObject> obj, bool send_updates = true);
00315
00322 zmm::Ref<CdsObject> convertObject(zmm::Ref<CdsObject> obj, int objectType);
00323
00325 zmm::Ref<AutoscanDirectory> getAutoscanDirectory(int scanID, scan_mode_t scanMode);
00326
00328 zmm::Ref<AutoscanDirectory> getAutoscanDirectory(zmm::String location);
00330 void removeAutoscanDirectory(int scanID, scan_mode_t scanMode);
00331
00333 void removeAutoscanDirectory(zmm::String location);
00334
00336 void removeAutoscanDirectory(int objectID);
00337
00340 void setAutoscanDirectory(zmm::Ref<AutoscanDirectory> dir);
00341
00343 void handlePeristentAutoscanRemove(int scanID, scan_mode_t scanMode);
00344
00346 void handlePersistentAutoscanRecreate(int scanID, scan_mode_t scanMode);
00347
00349 zmm::Ref<zmm::Array<AutoscanDirectory> > getAutoscanDirectories(scan_mode_t scanMode);
00350
00352 zmm::Ref<zmm::Array<AutoscanDirectory> > getAutoscanDirectories();
00353
00354
00356 void reloadLayout();
00357
00358 #if defined(EXTERNAL_TRANSCODING) || defined(SOPCAST)
00366 void registerExecutor(zmm::Ref<Executor> exec);
00367
00373 void unregisterExecutor(zmm::Ref<Executor> exec);
00374 #endif
00375
00376 #ifdef HAVE_MAGIC
00377 zmm::String getMimeTypeFromBuffer(void *buffer, size_t length);
00378 #endif
00379 protected:
00380 void initLayout();
00381 void destroyLayout();
00382
00383 #ifdef HAVE_JS
00384 void initJS();
00385 void destroyJS();
00386 #endif
00387
00388 zmm::Ref<RExp> reMimetype;
00389
00390 bool ignore_unknown_extensions;
00391 bool extension_map_case_sensitive;
00392
00393 zmm::Ref<Dictionary> extension_mimetype_map;
00394 zmm::Ref<Dictionary> mimetype_upnpclass_map;
00395 zmm::Ref<Dictionary> mimetype_contenttype_map;
00396
00397 zmm::Ref<AutoscanList> autoscan_timed;
00398 #ifdef HAVE_INOTIFY
00399 zmm::Ref<AutoscanList> autoscan_inotify;
00400 zmm::Ref<AutoscanInotify> inotify;
00401 #endif
00402
00403 #if defined(EXTERNAL_TRANSCODING) || defined(SOPCAST)
00404 zmm::Ref<Mutex> pr_mutex;
00405 zmm::Ref<zmm::Array<Executor> > process_list;
00406 #endif
00407
00408 void _loadAccounting();
00409
00410 int addFileInternal(zmm::String path, zmm::String rootpath,
00411 bool recursive=true,
00412 bool async=true, bool hidden=false,
00413 bool lowPriority=false,
00414 unsigned int parentTaskID = 0,
00415 bool cancellable = true);
00416 int _addFile(zmm::String path, zmm::String rootpath, bool recursive=false, bool hidden=false, zmm::Ref<GenericTask> task=nil);
00417
00418 void _removeObject(int objectID, bool all);
00419
00420 void _rescanDirectory(int containerID, int scanID, scan_mode_t scanMode, scan_level_t scanLevel, zmm::Ref<GenericTask> task=nil);
00421
00422 void addRecursive(zmm::String path, bool hidden, zmm::Ref<GenericTask> task);
00423
00424
00425 zmm::String extension2mimetype(zmm::String extension);
00426 zmm::String mimetype2upnpclass(zmm::String mimeType);
00427
00428 void invalidateAddTask(zmm::Ref<GenericTask> t, zmm::String path);
00429
00430 zmm::Ref<Layout> layout;
00431
00432 #ifdef ONLINE_SERVICES
00433 zmm::Ref<OnlineServiceList> online_services;
00434
00435 void fetchOnlineContentInternal(zmm::Ref<OnlineService> service,
00436 bool lowPriority=true,
00437 bool cancellable=true,
00438 unsigned int parentTaskID = 0,
00439 bool unscheduled_refresh = false);
00440
00441 void _fetchOnlineContent(zmm::Ref<OnlineService>,
00442 unsigned int parentTaskID,
00443 bool unscheduled_refresh);
00444
00445 #ifdef YOUTUBE
00446 zmm::Ref<Mutex> urlcache_mutex;
00447 zmm::Ref<ReentrantArray<CachedURL> > cached_urls;
00449 void checkCachedURLs();
00450 #endif
00451
00452 #endif //ONLINE_SERVICES
00453
00454 #ifdef HAVE_JS
00455 zmm::Ref<PlaylistParserScript> playlist_parser_script;
00456 #ifdef HAVE_LIBDVDNAV
00457 zmm::Ref<DVDImportScript> dvd_import_script;
00458 #endif
00459 #endif
00460
00461 bool layout_enabled;
00462
00463 void setLastModifiedTime(time_t lm);
00464
00465 inline void signal() { cond->signal(); }
00466 static void *staticThreadProc(void *arg);
00467 void threadProc();
00468
00469 void addTask(zmm::Ref<GenericTask> task, bool lowPriority = false);
00470
00471 zmm::Ref<CMAccounting> acct;
00472
00473 pthread_t taskThread;
00474 zmm::Ref<Cond> cond;
00475
00476 bool working;
00477
00478 bool shutdownFlag;
00479
00480 zmm::Ref<zmm::ObjectQueue<GenericTask> > taskQueue1;
00481 zmm::Ref<zmm::ObjectQueue<GenericTask> > taskQueue2;
00482 zmm::Ref<GenericTask> currentTask;
00483
00484 unsigned int taskID;
00485
00486 friend void CMAddFileTask::run();
00487 friend void CMRemoveObjectTask::run();
00488 friend void CMRescanDirectoryTask::run();
00489 #ifdef ONLINE_SERVICES
00490 friend void CMFetchOnlineContentTask::run();
00491 #endif
00492 friend void CMLoadAccountingTask::run();
00493 };
00494
00495 #endif // __CONTENT_MANAGER_H__