MythTV  master
mythairplayserver.h
Go to the documentation of this file.
1 #ifndef MYTHAIRPLAYSERVER_H
2 #define MYTHAIRPLAYSERVER_H
3 
4 #include <QObject>
5 #include <QUrl>
6 #include <cstdint> // for uintxx_t
7 
8 #include "serverpool.h"
9 #include "mythtvexp.h"
10 #include "mythmainwindow.h"
11 
12 class QMutex;
13 class QTimer;
14 class MThread;
15 class BonjourRegister;
16 
17 #define AIRPLAY_PORT_RANGE 100
18 #define AIRPLAY_HARDWARE_ID_SIZE 6
19 QString AirPlayHardwareId(void);
20 QString GenerateNonce(void);
21 QByteArray DigestMd5Response(const QString& response, const QString& option,
22  const QString& nonce, const QString& password,
23  QByteArray &auth);
24 
26 {
32 };
33 
35 {
36  public:
37  AirplayConnection() = default;
39  {
40  UnRegister();
41  }
42  void UnRegister(void)
43  {
44  if (m_notificationid > 0)
45  {
47  m_notificationid = -1;
48  }
49  }
50  QTcpSocket *m_controlSocket {nullptr};
51  QTcpSocket *m_reverseSocket {nullptr};
52  float m_speed {1.0F};
53  double m_position {0.0};
54 // double m_initial_position {-1.0};
55  QUrl m_url;
57  bool m_stopped {false};
58  bool m_was_playing {false};
59  bool m_initialized {false};
60  bool m_photos {false};
61  // Notification
62  int m_notificationid {-1};
63 };
64 
65 class APHTTPRequest;
66 
68 {
69  Q_OBJECT
70 
71  public:
72  static bool Create(void);
73  static void Cleanup(void);
75  { return gMythAirplayServer; }
76 
78  : m_lock(new QMutex(QMutex::Recursive)) {}
79 
80  private slots:
81  void Start();
82  void Stop();
83  void newConnection(QTcpSocket *client);
84  void deleteConnection();
85  void read(void);
86  void timeout(void);
87 
88  private:
89  ~MythAirplayServer(void) override;
90  void Teardown(void);
91  void HandleResponse(APHTTPRequest *req, QTcpSocket *socket);
92  QByteArray StatusToString(int status);
93  QString eventToString(AirplayEvent event);
94  void GetPlayerStatus(bool &playing, float &speed,
95  double &position, double &duration,
96  QString &pathname);
97  QString GetMacAddress();
98  bool SendReverseEvent(QByteArray &session, AirplayEvent event);
99  void SendResponse(QTcpSocket *socket,
100  int status, const QByteArray& header,
101  const QByteArray& content_type, const QString& body);
102 
103  void deleteConnection(QTcpSocket *socket);
104  void DisconnectAllClients(const QByteArray &session);
105  void StopSession(const QByteArray &session);
106  void StartPlayback(const QString &pathname);
107  void StopPlayback(void);
108  void SeekPosition(uint64_t position);
109  void PausePlayback(void);
110  void UnpausePlayback(void);
111  void HideAllPhotos(void);
112 
113  // Globals
115  static QMutex *gMythAirplayServerMutex;
117 
118  // Members
119  QString m_name {"MythTV"};
120  BonjourRegister *m_bonjour {nullptr};
121  bool m_valid {false};
122  QMutex *m_lock {nullptr};
123  int m_setupPort {5100};
124  QList<QTcpSocket*> m_sockets;
125  QHash<QByteArray,AirplayConnection> m_connections;
126  QString m_pathname;
127 
128  //Authentication
129  QString m_nonce;
130 
131  //Incoming data
132  QHash<QTcpSocket*, APHTTPRequest*> m_incoming;
133 
134  // Bonjour Service re-advertising
135  QTimer *m_serviceRefresh {nullptr};
136 };
137 
138 #endif // MYTHAIRPLAYSERVER_H
AirplayEvent
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
unsigned int slots[4]
Definition: element.c:38
QTcpSocket * m_reverseSocket
static QMutex * gMythAirplayServerMutex
QString AirPlayHardwareId(void)
void UnRegister(void *from, int id, bool closeimemdiately=false)
Unregister the client.
def read(device=None, features=[])
Definition: disc.py:35
QTcpSocket * m_controlSocket
#define MTV_PUBLIC
Definition: mythtvexp.h:15
QByteArray DigestMd5Response(const QString &response, const QString &option, const QString &nonce, const QString &password, QByteArray &auth)
static MThread * gMythAirplayServerThread
AirplayConnection()=default
static MythAirplayServer * AirplaySharedInstance(void)
QHash< QByteArray, AirplayConnection > m_connections
Manages a collection of sockets listening on different ports.
Definition: serverpool.h:59
static MythAirplayServer * gMythAirplayServer
AirplayEvent m_lastEvent
QString GenerateNonce(void)
QList< QTcpSocket * > m_sockets
QHash< QTcpSocket *, APHTTPRequest * > m_incoming
void newConnection(QTcpSocket *)
MythNotificationCenter * GetNotificationCenter(void)