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 COPYING 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 "compat.h"
29 #include "taskqueue.h"
30 
31 class MSocketDevice;
32 class UPnpDevice;
33 
35 // Typedefs
37 
39 {
40  NTS_alive = 0,
41  NTS_byebye = 1
42 };
43 
46 //
47 // UPnpNotifyTask Class Definition
48 //
51 
52 class UPnpNotifyTask : public Task
53 {
54  protected:
55 
56  QMutex m_mutex;
57 
58  QString m_sMasterIP;
60  int m_nMaxAge {3600};
61 
63 
64  protected:
65 
66  // Destructor protected to force use of Release Method
67 
68  ~UPnpNotifyTask() override = default;
69 
70  void ProcessDevice( MSocketDevice *pSocket, UPnpDevice *pDevice );
71  void SendNotifyMsg( MSocketDevice *pSocket, const QString& sNT, const QString& sUDN );
72 
73  public:
74 
75  explicit UPnpNotifyTask( int nServicePort );
76 
77  QString Name() override { return( "Notify" ); } // Task
78  void Execute( TaskQueue *pQueue ) override; // Task
79 
80  // ------------------------------------------------------------------
81 
82  QString GetNTSString()
83  {
84  m_mutex.lock();
85  UPnpNotifyNTS nts = m_eNTS;
86  m_mutex.unlock();
87 
88  switch( nts )
89  {
90  case NTS_alive : return( "ssdp:alive" );
91  case NTS_byebye: return( "ssdp:byebye" );
92  }
93  return( "unknown" );
94  }
95 
96  // ------------------------------------------------------------------
97 
99  {
100  m_mutex.lock();
101  UPnpNotifyNTS nts = m_eNTS;
102  m_mutex.unlock();
103 
104  return( nts );
105  }
106 
107  // ------------------------------------------------------------------
108 
110  {
111  m_mutex.lock();
112  m_eNTS = nts;
113  m_mutex.unlock();
114  }
115 
116 };
117 
118 
119 #endif // UPNPTASKNOTIFY_H
UPnpNotifyTask::Name
QString Name() override
Definition: upnptasknotify.h:77
UPnpNotifyTask
Definition: upnptasknotify.h:53
UPnpNotifyTask::m_mutex
QMutex m_mutex
Definition: upnptasknotify.h:56
NTS_alive
@ NTS_alive
Definition: upnptasknotify.h:40
NTS_byebye
@ NTS_byebye
Definition: upnptasknotify.h:41
UPnpNotifyTask::m_nMaxAge
int m_nMaxAge
Definition: upnptasknotify.h:60
TaskQueue
Definition: taskqueue.h:82
UPnpNotifyTask::m_eNTS
UPnpNotifyNTS m_eNTS
Definition: upnptasknotify.h:62
UPnpNotifyTask::~UPnpNotifyTask
~UPnpNotifyTask() override=default
compat.h
Task
Definition: taskqueue.h:54
UPnpDevice
Definition: upnpdevice.h:100
UPnpNotifyTask::SendNotifyMsg
void SendNotifyMsg(MSocketDevice *pSocket, const QString &sNT, const QString &sUDN)
Definition: upnptasknotify.cpp:55
UPnpNotifyTask::UPnpNotifyTask
UPnpNotifyTask(int nServicePort)
Definition: upnptasknotify.cpp:43
taskqueue.h
UPnpNotifyTask::ProcessDevice
void ProcessDevice(MSocketDevice *pSocket, UPnpDevice *pDevice)
Definition: upnptasknotify.cpp:177
UPnpNotifyNTS
UPnpNotifyNTS
Definition: upnptasknotify.h:39
UPnpNotifyTask::SetNTS
void SetNTS(UPnpNotifyNTS nts)
Definition: upnptasknotify.h:109
UPnpNotifyTask::GetNTS
UPnpNotifyNTS GetNTS()
Definition: upnptasknotify.h:98
UPnpNotifyTask::m_nServicePort
int m_nServicePort
Definition: upnptasknotify.h:59
UPnpNotifyTask::m_sMasterIP
QString m_sMasterIP
Definition: upnptasknotify.h:58
UPnpNotifyTask::Execute
void Execute(TaskQueue *pQueue) override
Definition: upnptasknotify.cpp:137
UPnpNotifyTask::GetNTSString
QString GetNTSString()
Definition: upnptasknotify.h:82