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 LICENSE for details
10 //
12 
13 #ifndef UPNPTASKCACHE_H
14 #define UPNPTASKCACHE_H
15 
16 #include <QString>
17 
19 
20 #include "libmythupnp/upnp.h"
21 
24 //
25 // SSDPCacheTask Class Definition
26 //
29 
30 class SSDPCacheTask : public Task
31 {
32  protected:
33 
34  std::chrono::milliseconds m_nInterval {30s}; // Number of ms between executing.
35  int m_nExecuteCount {0}; // Used for debugging.
36 
37  // Destructor protected to force use of Release Method
38 
39  ~SSDPCacheTask() override = default;
40 
41  public:
42 
43  SSDPCacheTask() : Task("SSDPCacheTask")
44  {
45  m_nExecuteCount = 0;
46  m_nInterval = 30s;
47 // TODO: Rework when separating upnp/ssdp stack
48 // XmlConfiguration().GetDuration<std::chrono::seconds>("UPnP/SSDP/CacheInterval", 30s);
49  }
50 
51  QString Name() override // Task
52  {
53  return( "SSDPCache" );
54  }
55 
56  void Execute( TaskQueue *pQueue ) override // Task
57  {
59 
60  int nCount = SSDPCache::Instance()->RemoveStale();
61 
62  if (nCount > 0)
63  {
64  LOG(VB_UPNP, LOG_INFO,
65  QString("SSDPCacheTask - Removed %1 stale entries.")
66  .arg(nCount));
67  }
68 
69  if ((m_nExecuteCount % 60) == 0)
71 
72  pQueue->AddTask( m_nInterval, (Task *)this );
73  }
74 
75 };
76 
77 #endif // UPNPTASKCACHE_H
SSDPCacheTask::m_nExecuteCount
int m_nExecuteCount
Definition: upnptaskcache.h:35
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
SSDPCacheTask::SSDPCacheTask
SSDPCacheTask()
Definition: upnptaskcache.h:43
SSDPCache::Instance
static SSDPCache * Instance()
Definition: ssdpcache.cpp:237
TaskQueue
Definition: taskqueue.h:82
SSDPCacheTask::Name
QString Name() override
Definition: upnptaskcache.h:51
upnp.h
mythlogging.h
SSDPCacheTask
Definition: upnptaskcache.h:30
Task
Definition: taskqueue.h:54
SSDPCache::RemoveStale
int RemoveStale()
Definition: ssdpcache.cpp:449
SSDPCache::Dump
void Dump(void)
Prints this device to the console in a human readable form.
Definition: ssdpcache.cpp:575
SSDPCacheTask::m_nInterval
std::chrono::milliseconds m_nInterval
Definition: upnptaskcache.h:34
SSDPCacheTask::~SSDPCacheTask
~SSDPCacheTask() override=default
SSDPCacheTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptaskcache.h:56