MythTV master
ssdp.h
Go to the documentation of this file.
1
2// Program Name: ssdp.h
3// Created : Oct. 1, 2005
4//
5// Purpose : SSDP Discovery Service Implmenetation
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 SSDP_H
14#define SSDP_H
15
16#include <chrono>
17using namespace std::chrono_literals;
18#include <cstdint>
19
20#include <QHostAddress>
21#include <QString>
22#include <QUdpSocket>
23
24#include "libmythbase/mthread.h"
25
26#include "upnpexp.h"
27
28static constexpr const char* SSDP_GROUP { "239.255.255.250" };
29static constexpr uint16_t SSDP_PORT { 1900 };
30
31enum SSDPRequestType : std::uint8_t
32{
36 SSDP_Notify = 3
37};
38
39class SSDPReceiver : public QObject
40{
41 Q_OBJECT
42
43 public:
45
46 void performSearch(const QString &sST, std::chrono::seconds timeout = 2s);
48
49 private slots:
51
52 private:
53 QUdpSocket m_socket {this};
55 const QHostAddress m_groupAddress {SSDP_GROUP};
56 bool m_isRunning {true};
57};
58
60{
61 private:
62 // Singleton instance used by all.
63 static SSDP* g_pSSDP;
64
65 int m_nServicePort {0};
66
67 class UPnpNotifyTask* m_pNotifyTask {nullptr};
68
70 MThread m_thread {"SSDP"};
71
72 private:
73
74 // ------------------------------------------------------------------
75 // Private so the singleton pattern can be enforced.
76 // ------------------------------------------------------------------
77
78 SSDP ();
79
80 public:
81
82 static inline const QString kBackendURI = "urn:schemas-mythtv-org:device:MasterMediaServer:1";
83
84 static SSDP* Instance();
85 static void Shutdown();
86
87 ~SSDP();
88
91 void PerformSearch(const QString &sST, std::chrono::seconds timeout = 2s);
92
93 void EnableNotifications ( int nServicePort );
94 void DisableNotifications();
96 {
97 if (m_pNotifyTask != nullptr)
98 {
99 return m_nServicePort;
100 }
101 return 0;
102 }
103};
104
105#endif // SSDP_H
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:49
QUdpSocket m_socket
Definition: ssdp.h:53
void processPendingDatagrams()
Definition: ssdp.cpp:405
void setIsRunning(bool isRunning)
Definition: ssdp.h:47
const QHostAddress m_groupAddress
Definition: ssdp.h:55
const uint16_t m_port
Definition: ssdp.h:54
bool m_isRunning
Definition: ssdp.h:56
void performSearch(const QString &sST, std::chrono::seconds timeout=2s)
Definition: ssdp.cpp:164
SSDPReceiver()
Definition: ssdp.cpp:396
Definition: ssdp.h:60
int getNotificationPort() const
Definition: ssdp.h:95
SSDPReceiver m_receiver
Definition: ssdp.h:69
static SSDP * g_pSSDP
Definition: ssdp.h:63
unsigned short uint16_t
Definition: iso6937tables.h:3
static bool isRunning(const char *program)
Returns true if a program containing the specified string is running on this machine.
static constexpr uint16_t SSDP_PORT
Definition: ssdp.h:29
static constexpr const char * SSDP_GROUP
Definition: ssdp.h:28
SSDPRequestType
Definition: ssdp.h:32
@ SSDP_Notify
Definition: ssdp.h:36
@ SSDP_MSearchResp
Definition: ssdp.h:35
@ SSDP_Unknown
Definition: ssdp.h:33
@ SSDP_MSearch
Definition: ssdp.h:34
#define UPNP_PUBLIC
Definition: upnpexp.h:9