MythTV  master
upnptasknotify.h
Go to the documentation of this file.
1 // Program Name: upnptasknotify.h
3 // Created : Oct. 24, 2005
4 //
5 // Purpose : UPnp Task to send Notification messages
6 //
7 // Copyright (c) 2005 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see LICENSE for details
10 //
12 
13 #ifndef UPNPTASKNOTIFY_H
14 #define UPNPTASKNOTIFY_H
15 
16 // POSIX headers
17 #include <sys/types.h>
18 #ifndef _WIN32
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #endif
22 
23 // Qt headers
24 #include <QString>
25 #include <QMutex>
26 
27 // MythTV headers
28 #include "libmythbase/compat.h"
29 
30 #include "taskqueue.h"
31 
32 class MSocketDevice;
33 class UPnpDevice;
34 
36 // Typedefs
38 
40 {
41  NTS_alive = 0,
43 };
44 
47 //
48 // UPnpNotifyTask Class Definition
49 //
52 
53 class UPnpNotifyTask : public Task
54 {
55  protected:
56 
57  QMutex m_mutex;
58 
59  QString m_sMasterIP;
61  std::chrono::seconds m_nMaxAge {1h};
62 
64 
65  protected:
66 
67  // Destructor protected to force use of Release Method
68 
69  ~UPnpNotifyTask() override = default;
70 
71  void ProcessDevice( MSocketDevice *pSocket, UPnpDevice *pDevice );
72  void SendNotifyMsg( MSocketDevice *pSocket, const QString& sNT, const QString& sUDN );
73 
74  public:
75 
76  explicit UPnpNotifyTask( int nServicePort );
77 
78  QString Name() override { return( "Notify" ); } // Task
79  void Execute( TaskQueue *pQueue ) override; // Task
80 
81  // ------------------------------------------------------------------
82 
83  QString GetNTSString()
84  {
85  m_mutex.lock();
86  UPnpNotifyNTS nts = m_eNTS;
87  m_mutex.unlock();
88 
89  switch( nts )
90  {
91  case NTS_alive : return( "ssdp:alive" );
92  case NTS_byebye: return( "ssdp:byebye" );
93  }
94  return( "unknown" );
95  }
96 
97  // ------------------------------------------------------------------
98 
100  {
101  m_mutex.lock();
102  UPnpNotifyNTS nts = m_eNTS;
103  m_mutex.unlock();
104 
105  return( nts );
106  }
107 
108  // ------------------------------------------------------------------
109 
111  {
112  m_mutex.lock();
113  m_eNTS = nts;
114  m_mutex.unlock();
115  }
116 
117 };
118 
119 
120 #endif // UPNPTASKNOTIFY_H
UPnpNotifyTask::Name
QString Name() override
Definition: upnptasknotify.h:78
UPnpNotifyTask
Definition: upnptasknotify.h:53
UPnpNotifyTask::m_mutex
QMutex m_mutex
Definition: upnptasknotify.h:57
NTS_alive
@ NTS_alive
Definition: upnptasknotify.h:41
NTS_byebye
@ NTS_byebye
Definition: upnptasknotify.h:42
TaskQueue
Definition: taskqueue.h:82
UPnpNotifyTask::m_eNTS
UPnpNotifyNTS m_eNTS
Definition: upnptasknotify.h:63
UPnpNotifyTask::~UPnpNotifyTask
~UPnpNotifyTask() override=default
compat.h
Task
Definition: taskqueue.h:54
UPnpDevice
Definition: upnpdevice.h:102
UPnpNotifyTask::m_nMaxAge
std::chrono::seconds m_nMaxAge
Definition: upnptasknotify.h:61
UPnpNotifyTask::SendNotifyMsg
void SendNotifyMsg(MSocketDevice *pSocket, const QString &sNT, const QString &sUDN)
Definition: upnptasknotify.cpp:58
UPnpNotifyTask::UPnpNotifyTask
UPnpNotifyTask(int nServicePort)
Definition: upnptasknotify.cpp:46
taskqueue.h
UPnpNotifyTask::ProcessDevice
void ProcessDevice(MSocketDevice *pSocket, UPnpDevice *pDevice)
Definition: upnptasknotify.cpp:184
UPnpNotifyNTS
UPnpNotifyNTS
Definition: upnptasknotify.h:39
UPnpNotifyTask::SetNTS
void SetNTS(UPnpNotifyNTS nts)
Definition: upnptasknotify.h:110
UPnpNotifyTask::GetNTS
UPnpNotifyNTS GetNTS()
Definition: upnptasknotify.h:99
UPnpNotifyTask::m_nServicePort
int m_nServicePort
Definition: upnptasknotify.h:60
UPnpNotifyTask::m_sMasterIP
QString m_sMasterIP
Definition: upnptasknotify.h:59
UPnpNotifyTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptasknotify.cpp:144
UPnpNotifyTask::GetNTSString
QString GetNTSString()
Definition: upnptasknotify.h:83