~vanvugt/+junk/mediatomb

« back to all changes in this revision

Viewing changes to src/content_manager.cc

  • Committer: Bazaar Package Importer
  • Author(s): Andres Mejia
  • Date: 2008-03-02 13:09:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080302130916-zlljdze3kt7vuq4b
Tags: 0.11.0-1
* New upstream release.
* Include message about which inotify headers will be used when enabling
  inotify runtime support.
* Fixed error with use of INTERFACE in init script. Also removed use of -m
  option.
* Including new config.xml options.
* Added more build dependencies for new upstream release.
* Removed build dependency of libid3-dev, taglib is now preferred.
* mediatomb.xpm and manpage.xml is now included in orig tarball.
* inotify patch is not needed anymore.
* md5 patch has been committed upstream and is no longer needed. Also removed
  README.Debian.
* TwinHelix PNG fix is now used. Removed from TODO.
* Adding dependency of iceweasel for mediatomb package.
* Updated copyright file.
* Updated watch file.
* Updated rules file for proper configure options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
    Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
8
                       Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
9
9
    
10
 
    Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
 
10
    Copyright (C) 2006-2008 Gena Batyan <bgeradz@mediatomb.cc>,
11
11
                            Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
12
                            Leonhard Wimmer <leo@mediatomb.cc>
13
13
    
24
24
    version 2 along with MediaTomb; if not, write to the Free Software
25
25
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
26
26
    
27
 
    $Id: content_manager.cc 1388 2007-07-11 17:08:40Z jin_eld $
 
27
    $Id: content_manager.cc 1698 2008-02-23 20:48:30Z lww $
28
28
*/
29
29
 
30
30
/// \file content_manager.cc
55
55
    #include "layout/js_layout.h"
56
56
#endif
57
57
 
 
58
#ifdef EXTERNAL_TRANSCODING
 
59
    #include "process.h"
 
60
#endif
 
61
 
 
62
#ifdef YOUTUBE
 
63
    #include "youtube_service.h"
 
64
#endif
 
65
 
 
66
#ifdef SOPCAST
 
67
    #include "sopcast_service.h"
 
68
#endif
 
69
 
58
70
#define DEFAULT_DIR_CACHE_CAPACITY  10
59
71
#define CM_INITIAL_QUEUE_SIZE       20
60
72
 
87
99
 
88
100
ContentManager::ContentManager() : TimerSubscriberSingleton<ContentManager>()
89
101
{
 
102
    int i;
90
103
    cond = Ref<Cond>(new Cond(mutex));
91
 
    ignore_unknown_extensions = 0;
 
104
    ignore_unknown_extensions = false;
 
105
    extension_map_case_sensitive = false;
92
106
   
93
107
    taskID = 1;
94
108
    working = false;
107
121
    extension_mimetype_map = 
108
122
        cm->getDictionaryOption(CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_LIST);
109
123
 
110
 
    String optIgnoreUnknown = 
111
 
                  cm->getOption(CFG_IMPORT_MAPPINGS_IGNORE_UNKNOWN_EXTENSIONS);
112
 
    if (optIgnoreUnknown != nil && optIgnoreUnknown == "yes")
113
 
        ignore_unknown_extensions = 1;
 
124
    ignore_unknown_extensions = cm->getBoolOption(CFG_IMPORT_MAPPINGS_IGNORE_UNKNOWN_EXTENSIONS);
114
125
 
115
126
    if (ignore_unknown_extensions && (extension_mimetype_map->size() == 0))
116
127
    {
117
128
        log_warning("Ignore unknown extensions set, but no mappings specified\n");
118
129
        log_warning("Please review your configuration!\n");
119
 
        ignore_unknown_extensions = 0;
 
130
        ignore_unknown_extensions = false;
120
131
    }
121
 
   
 
132
  
 
133
    extension_map_case_sensitive = cm->getBoolOption(CFG_IMPORT_MAPPINGS_EXTENSION_TO_MIMETYPE_CASE_SENSITIVE);
 
134
 
122
135
    mimetype_upnpclass_map = 
123
136
       cm->getDictionaryOption(CFG_IMPORT_MAPPINGS_MIMETYPE_TO_UPNP_CLASS_LIST);
124
137
   
125
138
    Ref<AutoscanList> config_timed_list = 
126
139
        cm->getAutoscanListOption(CFG_IMPORT_AUTOSCAN_TIMED_LIST);
127
140
 
128
 
    for (int i = 0; i < config_timed_list->size(); i++)
 
141
    for (i = 0; i < config_timed_list->size(); i++)
129
142
    {
130
143
        Ref<AutoscanDirectory> dir = config_timed_list->get(i);
131
144
        if (dir != nil)
143
156
    autoscan_timed = storage->getAutoscanList(TimedScanMode);
144
157
 
145
158
#ifdef HAVE_INOTIFY
146
 
    Ref<AutoscanList> config_inotify_list = 
147
 
        cm->getAutoscanListOption(CFG_IMPORT_AUTOSCAN_INOTIFY_LIST);
148
 
 
149
 
    for (int i = 0; i < config_inotify_list->size(); i++)
 
159
    if (cm->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
150
160
    {
151
 
        Ref<AutoscanDirectory> dir = config_inotify_list->get(i);
152
 
        if (dir != nil)
 
161
        Ref<AutoscanList> config_inotify_list = 
 
162
            cm->getAutoscanListOption(CFG_IMPORT_AUTOSCAN_INOTIFY_LIST);
 
163
 
 
164
        for (i = 0; i < config_inotify_list->size(); i++)
153
165
        {
154
 
            String path = dir->getLocation();
155
 
            if (check_path(path, true))
 
166
            Ref<AutoscanDirectory> dir = config_inotify_list->get(i);
 
167
            if (dir != nil)
156
168
            {
157
 
                dir->setObjectID(ensurePathExistence(path));
 
169
                String path = dir->getLocation();
 
170
                if (check_path(path, true))
 
171
                {
 
172
                    dir->setObjectID(ensurePathExistence(path));
 
173
                }
158
174
            }
159
175
        }
 
176
 
 
177
        storage->updateAutoscanPersistentList(InotifyScanMode, 
 
178
                                              config_inotify_list);
 
179
        autoscan_inotify = storage->getAutoscanList(InotifyScanMode);
160
180
    }
161
 
 
162
 
    storage->updateAutoscanPersistentList(InotifyScanMode, config_inotify_list);
163
 
    autoscan_inotify = storage->getAutoscanList(InotifyScanMode);
 
181
    else
 
182
        // make an empty list so we do not have to do extra checks on shutdown 
 
183
        autoscan_inotify = Ref<AutoscanList>(new AutoscanList());
164
184
#endif
165
185
    /* init filemagic */
166
186
#ifdef HAVE_MAGIC
190
210
                       cm->getOption(CFG_IMPORT_SCRIPTING_VIRTUAL_LAYOUT_TYPE);
191
211
    if ((layout_type == "builtin") || (layout_type == "js"))
192
212
        layout_enabled = true;
 
213
 
 
214
#ifdef ONLINE_SERVICES
 
215
    online_services = Ref<OnlineServiceList>(new OnlineServiceList());
 
216
#ifdef YOUTUBE
 
217
    if (cm->getBoolOption(CFG_ONLINE_CONTENT_YOUTUBE_ENABLED))
 
218
    {
 
219
        try 
 
220
        {
 
221
            Ref<OnlineService> yt((OnlineService *)new YouTubeService());
 
222
 
 
223
            i = cm->getIntOption(CFG_ONLINE_CONTENT_YOUTUBE_REFRESH);
 
224
            yt->setRefreshInterval(i);
 
225
 
 
226
            i = cm->getIntOption(CFG_ONLINE_CONTENT_YOUTUBE_PURGE_AFTER);
 
227
            yt->setItemPurgeInterval(i);
 
228
 
 
229
            if (cm->getBoolOption(CFG_ONLINE_CONTENT_YOUTUBE_UPDATE_AT_START))
 
230
                i = CFG_DEFAULT_UPDATE_AT_START;
 
231
 
 
232
            Ref<TimerParameter> yt_param(new TimerParameter(TimerParameter::IDOnlineContent, OS_YouTube));
 
233
            yt->setTimerParameter(RefCast(yt_param, Object));
 
234
            online_services->registerService(yt);
 
235
            
 
236
            if (i > 0)
 
237
            {
 
238
                Timer::getInstance()->addTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), i, yt->getTimerParameter(), true);
 
239
            }
 
240
        }
 
241
        catch (Exception ex)
 
242
        {
 
243
            log_error("Could not setup YouTube: %s\n", 
 
244
                    ex.getMessage().c_str());
 
245
        }
 
246
    }
 
247
#endif //YOUTUBE
 
248
 
 
249
#ifdef SOPCAST
 
250
    if (cm->getBoolOption(CFG_ONLINE_CONTENT_SOPCAST_ENABLED))
 
251
    {
 
252
        try
 
253
        {
 
254
        Ref<OnlineService> sc((OnlineService *)new SopCastService());
 
255
 
 
256
        i = cm->getIntOption(CFG_ONLINE_CONTENT_SOPCAST_REFRESH);
 
257
        sc->setRefreshInterval(i);
 
258
 
 
259
        i = cm->getIntOption(CFG_ONLINE_CONTENT_SOPCAST_PURGE_AFTER);
 
260
        sc->setItemPurgeInterval(i);
 
261
 
 
262
        if (cm->getBoolOption(CFG_ONLINE_CONTENT_SOPCAST_UPDATE_AT_START))
 
263
            i = CFG_DEFAULT_UPDATE_AT_START;
 
264
 
 
265
        Ref<TimerParameter> sc_param(new TimerParameter(TimerParameter::IDOnlineContent, OS_SopCast));
 
266
        sc->setTimerParameter(RefCast(sc_param, Object));
 
267
        online_services->registerService(sc);
 
268
        if (i > 0)
 
269
        {
 
270
            Timer::getInstance()->addTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), i, sc->getTimerParameter(), true);
 
271
        }
 
272
        }
 
273
        catch (Exception ex)
 
274
        {
 
275
            log_error("Could not setup SopCast: %s\n",
 
276
                    ex.getMessage().c_str());
 
277
        }
 
278
    }
 
279
#endif //SOPCAST
 
280
 
 
281
 
 
282
#endif //ONLINE_SERVICES
193
283
}
194
284
 
195
285
ContentManager::~ContentManager()
233
323
    autoscan_timed->notifyAll(AS_TIMER_SUBSCRIBER_SINGLETON(this));
234
324
 
235
325
#ifdef HAVE_INOTIFY
236
 
    inotify = Ref<AutoscanInotify>(new AutoscanInotify());
237
 
    /// \todo change this for 0.9.1 (we need a new autoscan architecture)
238
 
    for (int i = 0; i < autoscan_inotify->size(); i++)
239
 
    {
240
 
        Ref<AutoscanDirectory> dir = autoscan_inotify->get(i);
241
 
        if (dir != nil)
242
 
            inotify->monitor(dir);
243
 
    }
244
 
    
245
 
#endif
246
 
}
247
 
 
248
 
void ContentManager::timerNotify(int id)
249
 
{
250
 
    Ref<AutoscanDirectory> dir = autoscan_timed->get(id);
251
 
    if (dir == nil)
252
 
        return;
253
 
    
254
 
    int objectID = dir->getObjectID();
255
 
    rescanDirectory(objectID, dir->getScanID(), dir->getScanMode());
 
326
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
 
327
    {
 
328
        inotify = Ref<AutoscanInotify>(new AutoscanInotify());
 
329
        /// \todo change this (we need a new autoscan architecture)
 
330
        for (int i = 0; i < autoscan_inotify->size(); i++)
 
331
        {
 
332
            Ref<AutoscanDirectory> dir = autoscan_inotify->get(i);
 
333
            if (dir != nil)
 
334
                inotify->monitor(dir);
 
335
        }
 
336
    }
 
337
#endif
 
338
 
 
339
#ifdef EXTERNAL_TRANSCODING
 
340
    process_list = Ref<Array<Executor> >(new Array<Executor>());
 
341
#endif
 
342
}
 
343
 
 
344
#if defined(EXTERNAL_TRANSCODING) || defined(SOPCAST)
 
345
void ContentManager::registerExecutor(Ref<Executor> exec)
 
346
{
 
347
    AUTOLOCK(mutex);
 
348
    process_list->append(exec);
 
349
}
 
350
 
 
351
void ContentManager::unregisterExecutor(Ref<Executor> exec)
 
352
{
 
353
    // when shutting down we will kill the transcoding processes,
 
354
    // which if given enough time will get a close in the io handler and
 
355
    // will try to unregister themselves - this would mess up the
 
356
    // transcoding_processes list
 
357
    // since we are anyway shutting down we can ignore the unregister call
 
358
    // and go through the list, ensuring that no zombie stays alive :>
 
359
    if (shutdownFlag)
 
360
        return;
 
361
 
 
362
    AUTOLOCK(mutex);
 
363
    for (int i = 0; i < process_list->size(); i++)
 
364
    {
 
365
        if (process_list->get(i) == exec)
 
366
            process_list->remove(i);
 
367
    }
 
368
}
 
369
#endif
 
370
 
 
371
void ContentManager::timerNotify(Ref<Object> parameter)
 
372
{
 
373
    if (parameter == nil)
 
374
        return;
 
375
    
 
376
    Ref<TimerParameter> tp = RefCast(parameter, TimerParameter);
 
377
    if (tp->whoami() == TimerParameter::IDAutoscan)
 
378
    {
 
379
        Ref<AutoscanDirectory> dir = autoscan_timed->get(tp->getID());
 
380
        if (dir == nil)
 
381
            return;
 
382
 
 
383
        int objectID = dir->getObjectID();
 
384
        rescanDirectory(objectID, dir->getScanID(), dir->getScanMode());
 
385
    }
 
386
#ifdef ONLINE_SERVICES
 
387
    else if (tp->whoami() == TimerParameter::IDOnlineContent)
 
388
    {
 
389
        fetchOnlineContent((service_type_t)(tp->getID()));
 
390
    }
 
391
#endif
256
392
}
257
393
 
258
394
void ContentManager::shutdown()
288
424
#endif
289
425
 
290
426
    shutdownFlag = true;
 
427
 
 
428
#ifdef EXTERNAL_TRANSCODING 
 
429
    for (int i = 0; i < process_list->size(); i++)
 
430
    {
 
431
        Ref<Executor> exec = process_list->get(i);
 
432
        if (exec != nil)
 
433
            exec->kill();
 
434
    }
 
435
#endif
 
436
 
291
437
    log_debug("signalling...\n");
292
438
    signal();
293
439
    AUTOUNLOCK();
294
440
    log_debug("waiting for thread...\n");
 
441
 
295
442
    if (taskThread)
296
443
        pthread_join(taskThread, NULL);
297
444
    taskThread = 0;
 
445
 
298
446
#ifdef HAVE_MAGIC
299
447
    if (ms)
300
448
    {
360
508
    acct->totalFiles = storage->getTotalFiles();
361
509
}
362
510
 
363
 
void ContentManager::addVirtualItem(Ref<CdsObject> obj)
 
511
void ContentManager::addVirtualItem(Ref<CdsObject> obj, bool allow_fifo)
364
512
{
365
513
    obj->validate();
366
514
    String path = obj->getLocation();
369
517
    Ref<CdsObject> pcdir = storage->findObjectByPath(path);
370
518
    if (pcdir == nil)
371
519
    {
372
 
        pcdir = createObjectFromFile(path);
 
520
        pcdir = createObjectFromFile(path, true, allow_fifo);
373
521
        if (pcdir == nil)
374
522
        {
375
523
            throw _Exception(_("Could not add ") + path);
1089
1237
}
1090
1238
 
1091
1239
// returns nil if file ignored due to configuration
1092
 
Ref<CdsObject> ContentManager::createObjectFromFile(String path, bool magic)
 
1240
Ref<CdsObject> ContentManager::createObjectFromFile(String path, bool magic, bool allow_fifo)
1093
1241
{
1094
1242
    String filename = get_filename(path);
1095
1243
 
1103
1251
    }
1104
1252
 
1105
1253
    Ref<CdsObject> obj;
1106
 
    if (S_ISREG(statbuf.st_mode)) // item
 
1254
    if (S_ISREG(statbuf.st_mode) || (allow_fifo && S_ISFIFO(statbuf.st_mode))) // item
1107
1255
    {
1108
1256
        /* retrieve information about item and decide
1109
1257
           if it should be included */
1172
1320
{
1173
1321
    if (extension_mimetype_map == nil)
1174
1322
        return nil;
 
1323
 
 
1324
    if (!extension_map_case_sensitive)
 
1325
        extension = extension.toLower();
 
1326
 
1175
1327
    return extension_mimetype_map->get(extension);
1176
1328
}
1177
1329
String ContentManager::mimetype2upnpclass(String mimeType)
1326
1478
        _loadAccounting();
1327
1479
    }
1328
1480
}
1329
 
int ContentManager::addFile(zmm::String path, bool recursive, bool async, bool hidden, bool lowPriority, bool cancellable)
 
1481
 
 
1482
int ContentManager::addFile(zmm::String path, bool recursive, bool async, 
 
1483
                            bool hidden, bool lowPriority, bool cancellable)
1330
1484
{
1331
1485
    return addFileInternal(path, recursive, async, hidden, lowPriority, 0, cancellable);
1332
1486
}
1333
1487
 
1334
 
int ContentManager::addFileInternal(zmm::String path, bool recursive, bool async, 
1335
 
                                     bool hidden, bool lowPriority, unsigned int parentTaskID, bool cancellable)
 
1488
int ContentManager::addFileInternal(zmm::String path, bool recursive, 
 
1489
                                    bool async, bool hidden, bool lowPriority, 
 
1490
                                    unsigned int parentTaskID, 
 
1491
                                    bool cancellable)
1336
1492
{
1337
1493
    if (async)
1338
1494
    {
1348
1504
    }
1349
1505
}
1350
1506
 
 
1507
#ifdef ONLINE_SERVICES
 
1508
void ContentManager::fetchOnlineContent(service_type_t service,
 
1509
                                        bool lowPriority, bool cancellable)
 
1510
{
 
1511
    Ref<OnlineService> os = online_services->getService(service);
 
1512
    if (os == nil)
 
1513
    {
 
1514
        log_debug("No surch service! %d\n", service);
 
1515
        throw _Exception(_("Service not found!"));
 
1516
    }
 
1517
    fetchOnlineContentInternal(os, lowPriority, cancellable);
 
1518
}
 
1519
 
 
1520
void ContentManager::fetchOnlineContentInternal(Ref<OnlineService> service, 
 
1521
                                        bool lowPriority, bool cancellable,
 
1522
                                        unsigned int parentTaskID)
 
1523
{
 
1524
    Ref<CMTask> task(new CMFetchOnlineContentTask(service, cancellable));
 
1525
    task->setDescription(_("Updating content from ") + 
 
1526
                         service->getServiceName());
 
1527
    task->setParentID(parentTaskID);
 
1528
    service->incTaskCount();
 
1529
    addTask(task, lowPriority);    
 
1530
}
 
1531
 
 
1532
void ContentManager::_fetchOnlineContent(Ref<OnlineService> service, 
 
1533
                                         unsigned int parentTaskID)
 
1534
{
 
1535
    log_debug("Fetching online content!\n");
 
1536
    if (layout_enabled)
 
1537
        initLayout();
 
1538
 
 
1539
    if (service->refreshServiceData(layout) && (!shutdownFlag))
 
1540
    {
 
1541
        log_debug("Scheduling another task for online service: %s\n",
 
1542
                  service->getServiceName().c_str());
 
1543
 
 
1544
        if (service->getRefreshInterval() > 0)
 
1545
            fetchOnlineContentInternal(service, true, true, parentTaskID);
 
1546
    }
 
1547
    else
 
1548
    {
 
1549
        log_debug("Finished fetch cycle for service: %s\n",
 
1550
                  service->getServiceName().c_str());
 
1551
 
 
1552
        if (service->getItemPurgeInterval() > 0)
 
1553
        {
 
1554
            Ref<Storage> storage = Storage::getInstance();
 
1555
            Ref<IntArray> ids = storage->getServiceObjectIDs(service->getStoragePrefix());
 
1556
 
 
1557
            struct timespec current, last;
 
1558
            getTimespecNow(&current);
 
1559
            last.tv_nsec = 0;
 
1560
            String temp;
 
1561
 
 
1562
            for (int i = 0; i < ids->size(); i++)
 
1563
            {
 
1564
                int object_id = ids->get(i);
 
1565
                Ref<CdsObject> obj = storage->loadObject(object_id);
 
1566
                if (obj == nil)
 
1567
                    continue;
 
1568
 
 
1569
                temp = obj->getAuxData(_(ONLINE_SERVICE_LAST_UPDATE));
 
1570
                if (!string_ok(temp))
 
1571
                    continue;
 
1572
 
 
1573
                last.tv_sec = temp.toLong();
 
1574
 
 
1575
                if ((service->getItemPurgeInterval() > 0) && 
 
1576
                    ((current.tv_sec - last.tv_sec) > service->getItemPurgeInterval()))
 
1577
                {
 
1578
                    log_debug("Purging old online service object %s\n", 
 
1579
                            obj->getTitle().c_str());
 
1580
                    removeObject(object_id, false);
 
1581
                }
 
1582
            } 
 
1583
        }
 
1584
    }
 
1585
}
 
1586
#endif
 
1587
 
1351
1588
void ContentManager::invalidateAddTask(Ref<CMTask> t, String path)
1352
1589
{
1353
1590
    if (t->getType() == AddFile)
1439
1676
            Ref<AutoscanList> rm_list = autoscan_timed->removeIfSubdir(path);
1440
1677
            for (i = 0; i < rm_list->size(); i++)
1441
1678
            {
1442
 
                Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), rm_list->get(i)->getScanID(), true);
 
1679
                Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), rm_list->get(i)->getTimerParameter(), true);
1443
1680
            }
1444
1681
#ifdef HAVE_INOTIFY
1445
 
            rm_list = autoscan_inotify->removeIfSubdir(path);
1446
 
            for (i = 0; i < rm_list->size(); i++)
 
1682
            if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1447
1683
            {
1448
 
                Ref<AutoscanDirectory> dir = rm_list->get(i);
1449
 
                inotify->unmonitor(dir);
 
1684
                rm_list = autoscan_inotify->removeIfSubdir(path);
 
1685
                for (i = 0; i < rm_list->size(); i++)
 
1686
                {
 
1687
                    Ref<AutoscanDirectory> dir = rm_list->get(i);
 
1688
                    inotify->unmonitor(dir);
 
1689
                }
1450
1690
            }
1451
1691
#endif
1452
1692
 
1576
1816
        SessionManager::getInstance()->containerChangedUI(adir->getObjectID());
1577
1817
        
1578
1818
        // if 3rd parameter is true: won't fail if scanID doesn't exist
1579
 
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), scanID, true);
 
1819
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), adir->getTimerParameter(), true);
1580
1820
 
1581
1821
    }
1582
1822
#ifdef HAVE_INOTIFY
1583
 
    else if (scanMode == InotifyScanMode)
 
1823
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1584
1824
    {
1585
 
        Ref<Storage> storage = Storage::getInstance();
1586
 
        Ref<AutoscanDirectory> adir = autoscan_inotify->get(scanID);
1587
 
        if (adir == nil)
1588
 
            throw _Exception(_("can not remove autoscan directory - was not an autoscan"));
1589
 
        autoscan_inotify->remove(scanID);
1590
 
        storage->removeAutoscanDirectory(adir->getStorageID());
1591
 
        SessionManager::getInstance()->containerChangedUI(adir->getObjectID());
1592
 
        inotify->unmonitor(adir);
 
1825
        if (scanMode == InotifyScanMode)
 
1826
        {
 
1827
            Ref<Storage> storage = Storage::getInstance();
 
1828
            Ref<AutoscanDirectory> adir = autoscan_inotify->get(scanID);
 
1829
            if (adir == nil)
 
1830
                throw _Exception(_("can not remove autoscan directory - was not an autoscan"));
 
1831
            autoscan_inotify->remove(scanID);
 
1832
            storage->removeAutoscanDirectory(adir->getStorageID());
 
1833
            SessionManager::getInstance()->containerChangedUI(adir->getObjectID());
 
1834
            inotify->unmonitor(adir);
 
1835
        }
1593
1836
    }
1594
1837
#endif
1595
1838
    
1604
1847
 
1605
1848
    if (adir->getScanMode() == TimedScanMode)
1606
1849
    {
1607
 
        int scanID = autoscan_timed->remove(adir->getLocation());
 
1850
        autoscan_timed->remove(adir->getLocation());
1608
1851
        storage->removeAutoscanDirectoryByObjectID(objectID);
1609
1852
        SessionManager::getInstance()->containerChangedUI(objectID);
1610
 
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), scanID, true);
 
1853
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), adir->getTimerParameter(), true);
1611
1854
    }
1612
1855
#ifdef HAVE_INOTIFY
1613
 
    else if (adir->getScanMode() == InotifyScanMode)
 
1856
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1614
1857
    {
1615
 
        autoscan_inotify->remove(adir->getLocation());
1616
 
        storage->removeAutoscanDirectoryByObjectID(objectID);
1617
 
        SessionManager::getInstance()->containerChangedUI(objectID);
1618
 
        inotify->unmonitor(adir);
 
1858
        if (adir->getScanMode() == InotifyScanMode)
 
1859
        {
 
1860
            autoscan_inotify->remove(adir->getLocation());
 
1861
            storage->removeAutoscanDirectoryByObjectID(objectID);
 
1862
            SessionManager::getInstance()->containerChangedUI(objectID);
 
1863
            inotify->unmonitor(adir);
 
1864
        }
1619
1865
    }
1620
1866
#endif
1621
1867
}
1625
1871
    /// \todo change this when more scanmodes become avaiable
1626
1872
    Ref<AutoscanDirectory> adir = autoscan_timed->get(location);
1627
1873
#ifdef HAVE_INOTIFY
1628
 
    if (adir == nil)
1629
 
        adir = autoscan_inotify->get(location);
 
1874
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
 
1875
    {
 
1876
        if (adir == nil)
 
1877
            adir = autoscan_inotify->get(location);
 
1878
    }
1630
1879
#endif
1631
1880
    if (adir == nil)
1632
1881
        throw _Exception(_("can not remove autoscan directory - was not an autoscan"));
1667
1916
    // We will have to change this for other scan modes
1668
1917
    original = autoscan_timed->getByObjectID(dir->getObjectID());
1669
1918
#ifdef HAVE_INOTIFY
1670
 
    if (original == nil)
1671
 
        original = autoscan_inotify->getByObjectID(dir->getObjectID());
 
1919
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
 
1920
    {
 
1921
        if (original == nil)
 
1922
            original = autoscan_inotify->getByObjectID(dir->getObjectID());
 
1923
    }
1672
1924
#endif
1673
1925
 
1674
1926
    if (original != nil)
1695
1947
        if (dir->getScanMode() == TimedScanMode)
1696
1948
        {
1697
1949
            scanID = autoscan_timed->add(dir);
1698
 
            timerNotify(scanID);
 
1950
            timerNotify(dir->getTimerParameter());
1699
1951
        }
1700
1952
#ifdef HAVE_INOTIFY
1701
 
        else if (dir->getScanMode() == InotifyScanMode)
 
1953
        if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1702
1954
        {
1703
 
            autoscan_inotify->add(dir);
1704
 
            inotify->monitor(dir);
 
1955
            if (dir->getScanMode() == InotifyScanMode)
 
1956
            {
 
1957
                autoscan_inotify->add(dir);
 
1958
                inotify->monitor(dir);
 
1959
            }
1705
1960
        }
1706
1961
#endif
1707
1962
        SessionManager::getInstance()->containerChangedUI(dir->getObjectID());
1709
1964
    }
1710
1965
 
1711
1966
    if (original->getScanMode() == TimedScanMode)
1712
 
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), original->getScanID(), true);
 
1967
        Timer::getInstance()->removeTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON(this), original->getTimerParameter(), true);
1713
1968
#ifdef HAVE_INOTIFY
1714
 
    else if (original->getScanMode() == InotifyScanMode)
 
1969
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1715
1970
    {
1716
 
        inotify->unmonitor(original);
 
1971
        if (original->getScanMode() == InotifyScanMode)
 
1972
        {
 
1973
            inotify->unmonitor(original);
 
1974
        }
1717
1975
    }
1718
1976
#endif
1719
1977
 
1743
2001
        autoscan_timed->remove(copy->getScanID());
1744
2002
    }
1745
2003
#ifdef HAVE_INOTIFY
1746
 
    else if (copy->getScanMode() == InotifyScanMode)
 
2004
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1747
2005
    {
1748
 
        autoscan_inotify->remove(copy->getScanID());
 
2006
        if (copy->getScanMode() == InotifyScanMode)
 
2007
        {
 
2008
            autoscan_inotify->remove(copy->getScanID());
 
2009
        }
1749
2010
    }
1750
2011
#endif
1751
2012
 
1754
2015
    if (dir->getScanMode() == TimedScanMode)
1755
2016
    {
1756
2017
        scanID = autoscan_timed->add(copy);
1757
 
        timerNotify(scanID);
 
2018
        timerNotify(copy->getTimerParameter());
1758
2019
    }
1759
2020
#ifdef HAVE_INOTIFY
1760
 
    else if (dir->getScanMode() == InotifyScanMode)
 
2021
    if (ConfigManager::getInstance()->getBoolOption(CFG_IMPORT_AUTOSCAN_USE_INOTIFY))
1761
2022
    {
1762
 
        autoscan_inotify->add(copy);
1763
 
        inotify->monitor(copy);
 
2023
        if (dir->getScanMode() == InotifyScanMode)
 
2024
        {
 
2025
            autoscan_inotify->add(copy);
 
2026
            inotify->monitor(copy);
 
2027
        }
1764
2028
    }
1765
2029
#endif
1766
2030
 
1841
2105
    {
1842
2106
        dir->updateLMT();
1843
2107
        if (dir->getScanMode() == TimedScanMode)
1844
 
            Timer::getInstance()->addTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON_FROM_REF(cm), dir->getInterval(), dir->getScanID(), true);
1845
 
    }
1846
 
}
 
2108
            Timer::getInstance()->addTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON_FROM_REF(cm), dir->getInterval(), dir->getTimerParameter(), true);
 
2109
    }
 
2110
}
 
2111
 
 
2112
#ifdef ONLINE_SERVICES
 
2113
CMFetchOnlineContentTask::CMFetchOnlineContentTask(Ref<OnlineService> service,
 
2114
                                                   bool cancellable)
 
2115
{
 
2116
    this->service = service;
 
2117
    this->taskType = FetchOnlineContent;
 
2118
    this->cancellable = cancellable;
 
2119
}
 
2120
 
 
2121
void CMFetchOnlineContentTask::run(Ref<ContentManager> cm)
 
2122
{
 
2123
    if (this->service == nil)
 
2124
    {
 
2125
        log_debug("Received invalid service!\n");
 
2126
        return;
 
2127
    }
 
2128
    cm->_fetchOnlineContent(service, getParentID());
 
2129
    service->decTaskCount();
 
2130
    if (service->getTaskCount() == 0)
 
2131
    {
 
2132
        Timer::getInstance()->addTimerSubscriber(AS_TIMER_SUBSCRIBER_SINGLETON_FROM_REF(cm), 
 
2133
                service->getRefreshInterval(), 
 
2134
                service->getTimerParameter(), true);
 
2135
    }
 
2136
}
 
2137
#endif
1847
2138
 
1848
2139
CMLoadAccountingTask::CMLoadAccountingTask() : CMTask()
1849
2140
{