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,
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
~UPnpNotifyTask() override=default
QString GetNTSString()
UPnpNotifyNTS GetNTS()
QString m_sMasterIP
void Execute(TaskQueue *pQueue) override
void SendNotifyMsg(MSocketDevice *pSocket, const QString &sNT, const QString &sUDN)
UPnpNotifyTask(int nServicePort)
void SetNTS(UPnpNotifyNTS nts)
UPnpNotifyNTS m_eNTS
void ProcessDevice(MSocketDevice *pSocket, UPnpDevice *pDevice)
UPnpNotifyNTS
QString Name() override
Definition: taskqueue.h:53