Sayonara Player
StreamServer.h
1 /* StreamServer.h */
2 
3 /* Copyright (C) 2011-2016 Lucio Carreras
4  *
5  * This file is part of sayonara player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16 
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef STREAM_SERVER_H
22 #define STREAM_SERVER_H
23 
24 #include "StreamWriter.h"
25 
26 #include "Components/PlayManager/PlayManager.h"
27 #include "Helper/Settings/SayonaraClass.h"
28 
29 #include <QThread>
30 #include <QList>
31 #include <QPair>
32 #include <QTcpSocket>
33 #include <QTcpServer>
34 
35 
36 class EngineHandler;
41 class StreamServer :
42  public QThread,
43  protected SayonaraClass
44 {
45 
46  Q_OBJECT
47 
48  signals:
49  void sig_new_connection(const QString& ip);
50  void sig_connection_closed(const QString& ip);
51  void sig_can_listen(bool);
52 
53  public:
54  StreamServer(QObject* parent=nullptr);
55  ~StreamServer();
56 
57  private:
58  QTcpServer* _server=nullptr; // the server
59 
60  MetaData _cur_track; // cur played track
61  bool _mp3_enc_available; // is encoder available
62 
63  QList<QPair<QTcpSocket*, QString>> _pending; // pending requests queue
64  bool _asking; // set if currently any requests are being processed
65 
66  QList<StreamWriterPtr> _lst_sw; // all open streams
67  QStringList _allowed_ips; // IPs without prompt
68  QStringList _discmissed_ips; // dismissed IPs
69 
70  // create new server and listen
71  void create_server();
72 
73  // listen for connection
74  bool listen_for_connection();
75 
76 
77  protected:
78  void run();
79 
80 
81  public slots:
82 
83  void accept_client(QTcpSocket* socket, const QString& ip);
84  void reject_client(QTcpSocket* socket, const QString& ip);
85  void dismiss(int idx);
86 
87  void disconnect(StreamWriterPtr sw);
88  void disconnect_all();
89 
90  void server_close();
91  void stop();
92  void retry();
93 
94 
95  private slots:
96  void track_changed(const MetaData&);
97  void server_destroyed();
98 
99  void new_client_request();
100  void disconnected(StreamWriter* sw);
101  void new_connection(const QString& ip);
102 
103  void _sl_active_changed();
104  void _sl_port_changed();
105  void _sl_mp3_enc_found();
106 };
107 
108 #endif
The StreamWriter class. This class is the interface between StreamDataSender and StreamServer. It watches the client socket and spreads data to its client.
Definition: StreamWriter.h:44
The StreamServer class. This class is listening for new connections and holds and administrates curre...
Definition: StreamServer.h:41
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: MetaData.h:49
Definition: EngineHandler.h:36
Definition: org_mpris_media_player2_adaptor.h:20