Sayonara Player
RemoteControl.h
1 /* RemoteControl.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 
22 
23 #ifndef REMOTECONTROL_H
24 #define REMOTECONTROL_H
25 
26 #include "Helper/Settings/SayonaraClass.h"
27 #include "Components/PlayManager/PlayManager.h"
28 #include "Components/Playlist/Playlist.h"
29 
30 #include <QObject>
31 #include <QTcpServer>
32 #include <QTcpSocket>
33 #include <QMap>
34 #include <QByteArray>
35 
36 #include <functional>
37 
38 class PlaylistHandler;
39 
40 typedef std::function<void()> RemoteFunction ;
41 typedef std::function<void(int)> RemoteFunctionInt ;
42 
84 class RemoteControl : public QObject, protected SayonaraClass
85 {
86  Q_OBJECT
87 
88 public:
89  RemoteControl(QObject *parent = 0);
90  virtual ~RemoteControl();
91 
92 
93  bool is_connected() const;
94 
95 private slots:
96  void new_connection();
97  void socket_disconnected();
98  void new_request();
99 
100  void pos_changed_ms(const quint64 pos);
101  void track_changed(const MetaData& md);
102  void volume_changed(int vol);
103  void playstate_changed(PlayManager::PlayState playstate);
104  void playlist_changed(PlaylistConstPtr pl);
105 
106  void _sl_active_changed();
107  void _sl_port_changed();
108  void _sl_broadcast_changed();
109 
110 
111 private:
112 
113  bool _initialized;
114 
116  QMap<QByteArray, RemoteFunctionInt> _fn_int_call_map;
117 
118  QTcpServer* _server=nullptr;
119  QTcpSocket* _socket=nullptr;
120  PlayManager* _play_manager=nullptr;
121  PlaylistHandler* _plh=nullptr;
122 
123 private:
124 
125  void init();
126 
127  void set_volume(int vol);
128  void seek_rel(int pos_percent);
129  void seek_rel_ms(int pos_ms);
130  void change_track(int idx);
131 
132  void show_api();
133  void request_state();
134 
135  int extract_parameter_int(const QByteArray& arr, int cmd_len);
136 
137  void write_playstate();
138  void write_broadcast_info();
139  void write_cur_track();
140  void write_volume();
141  void write_cur_pos();
142  void write_playlist();
143 
144  void write_cover();
145  void write_cover(const MetaData& md);
146 
147  void write(const QByteArray& arr);
148 
149 
150 
151 };
152 
153 #endif // REMOTECONTROL_H
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: MetaData.h:49
PlayState
Current Playing state.
Definition: PlayManager.h:79
Remote control allows to control Sayonara from an external application via network. Various commands are implemented. Sayonara also delivers information about state changes,The current implemented commands are: .
Definition: RemoteControl.h:84
Global handler for current playback state (Singleton)
Definition: PlayManager.h:67
Global handler for playlists.
Definition: PlaylistHandler.h:48