MythTV  master
upnptaskcache.h
Go to the documentation of this file.
1 // Program Name: upnptaskcache.h
3 // Created : Jan. 9, 2007
4 //
5 // Purpose : UPnp Task to keep SSDPCache free of stale records
6 //
7 // Copyright (c) 2007 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #ifndef UPNPTASKCACHE_H
14 #define UPNPTASKCACHE_H
15 
16 #include <QString>
17 
18 #include "mythlogging.h"
19 #include "upnp.h"
20 
23 //
24 // SSDPCacheTask Class Definition
25 //
28 
29 class SSDPCacheTask : public Task
30 {
31  protected:
32 
33  std::chrono::milliseconds m_nInterval {30s}; // Number of ms between executing.
34  int m_nExecuteCount {0}; // Used for debugging.
35 
36  // Destructor protected to force use of Release Method
37 
38  ~SSDPCacheTask() override = default;
39 
40  public:
41 
42  SSDPCacheTask() : Task("SSDPCacheTask")
43  {
44  m_nExecuteCount = 0;
45  m_nInterval =
46  UPnp::GetConfiguration()->GetDuration<std::chrono::seconds>("UPnP/SSDP/CacheInterval", 30s);
47  }
48 
49  QString Name() override // Task
50  {
51  return( "SSDPCache" );
52  }
53 
54  void Execute( TaskQueue *pQueue ) override // Task
55  {
57 
58  int nCount = SSDPCache::Instance()->RemoveStale();
59 
60  if (nCount > 0)
61  {
62  LOG(VB_UPNP, LOG_INFO,
63  QString("SSDPCacheTask - Removed %1 stale entries.")
64  .arg(nCount));
65  }
66 
67  if ((m_nExecuteCount % 60) == 0)
69 
70  pQueue->AddTask( m_nInterval, (Task *)this );
71  }
72 
73 };
74 
75 #endif // UPNPTASKCACHE_H
Configuration::GetDuration
std::enable_if< std::chrono::__is_duration< T >::value, T >::type GetDuration(const QString &sSetting, T defaultval=T::zero())
Definition: configuration.h:41
SSDPCacheTask::m_nExecuteCount
int m_nExecuteCount
Definition: upnptaskcache.h:34
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
SSDPCacheTask::SSDPCacheTask
SSDPCacheTask()
Definition: upnptaskcache.h:42
SSDPCache::Instance
static SSDPCache * Instance()
Definition: ssdpcache.cpp:244
TaskQueue
Definition: taskqueue.h:81
SSDPCacheTask::Name
QString Name() override
Definition: upnptaskcache.h:49
upnp.h
mythlogging.h
SSDPCacheTask
Definition: upnptaskcache.h:29
Task
Definition: taskqueue.h:53
SSDPCache::RemoveStale
int RemoveStale()
Definition: ssdpcache.cpp:456
SSDPCache::Dump
void Dump(void)
Prints this device to the console in a human readable form.
Definition: ssdpcache.cpp:582
SSDPCacheTask::m_nInterval
std::chrono::milliseconds m_nInterval
Definition: upnptaskcache.h:33
SSDPCacheTask::~SSDPCacheTask
~SSDPCacheTask() override=default
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
SSDPCacheTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptaskcache.h:54