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 
38 typedef enum
39 {
40  NTS_alive = 0,
42 
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  int m_nMaxAge {3600};
62 
64 
65  protected:
66 
67  // Destructor protected to force use of Release Method
68 
69  virtual ~UPnpNotifyTask() = 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 * ) 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
QString GetNTSString()
void Execute(TaskQueue *) override
UPnpNotifyNTS GetNTS()
QString m_sMasterIP
void SendNotifyMsg(MSocketDevice *pSocket, const QString &sNT, const QString &sUDN)
UPnpNotifyTask(int nServicePort)
virtual ~UPnpNotifyTask()=default
void SetNTS(UPnpNotifyNTS nts)
UPnpNotifyNTS m_eNTS
void ProcessDevice(MSocketDevice *pSocket, UPnpDevice *pDevice)
UPnpNotifyNTS
QString Name() override
Definition: taskqueue.h:53