00001 #ifndef MYTHAIRPLAYSERVER_H
00002 #define MYTHAIRPLAYSERVER_H
00003
00004 #include <QObject>
00005 #include <QUrl>
00006
00007 #include "serverpool.h"
00008 #include "mythtvexp.h"
00009
00010 class QMutex;
00011 class MThread;
00012 class BonjourRegister;
00013
00014 #define AIRPLAY_PORT_RANGE 100
00015
00016 enum AirplayEvent
00017 {
00018 AP_EVENT_NONE = -1,
00019 AP_EVENT_PLAYING = 0,
00020 AP_EVENT_PAUSED = 1,
00021 AP_EVENT_LOADING = 2,
00022 AP_EVENT_STOPPED = 3,
00023 };
00024
00025 class AirplayConnection
00026 {
00027 public:
00028 AirplayConnection()
00029 : controlSocket(NULL), reverseSocket(NULL), speed(1.0f),
00030 position(0.0f), initial_position(-1.0f), url(QUrl()),
00031 lastEvent(AP_EVENT_NONE), stopped(false), was_playing(false)
00032 { }
00033 QTcpSocket *controlSocket;
00034 QTcpSocket *reverseSocket;
00035 float speed;
00036 double position;
00037 double initial_position;
00038 QUrl url;
00039 AirplayEvent lastEvent;
00040 bool stopped;
00041 bool was_playing;
00042 };
00043
00044 class APHTTPRequest;
00045
00046 class MTV_PUBLIC MythAirplayServer : public ServerPool
00047 {
00048 Q_OBJECT
00049
00050 public:
00051 static bool Create(void);
00052 static void Cleanup(void);
00053
00054 MythAirplayServer();
00055
00056 private slots:
00057 void Start();
00058 void newConnection(QTcpSocket *client);
00059 void deleteConnection();
00060 void read();
00061
00062 private:
00063 virtual ~MythAirplayServer(void);
00064 void Teardown(void);
00065 void HandleResponse(APHTTPRequest *req, QTcpSocket *socket);
00066 QByteArray StatusToString(int status);
00067 QString eventToString(AirplayEvent event);
00068 void GetPlayerStatus(bool &playing, float &speed, double &position,
00069 double &duration);
00070 QString GetMacAddress();
00071 bool SendReverseEvent(QByteArray &session, AirplayEvent event);
00072 void SendResponse(QTcpSocket *socket,
00073 int status, QByteArray header,
00074 QByteArray content_type, QString body);
00075
00076
00077 static MythAirplayServer *gMythAirplayServer;
00078 static QMutex *gMythAirplayServerMutex;
00079 static MThread *gMythAirplayServerThread;
00080
00081
00082 QString m_name;
00083 BonjourRegister *m_bonjour;
00084 bool m_valid;
00085 QMutex *m_lock;
00086 int m_setupPort;
00087 QList<QTcpSocket*> m_sockets;
00088 QHash<QByteArray,AirplayConnection> m_connections;
00089 };
00090
00091 #endif // MYTHAIRPLAYSERVER_H