]> git.vomp.tv Git - vompclient.git/blob - inputudp.h
Convert PlayerRadioRec to std::thread
[vompclient.git] / inputudp.h
1 /*
2     Copyright 2006 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef INPUTUDP_H
21 #define INPUTUDP_H
22
23 #include <string>
24 #include <thread>
25 #include <mutex>
26
27 #ifdef WIN32
28 #include <winsock2.h>
29 #endif
30
31 #include "defines.h"
32 #include "input.h"
33
34 class DatagramSocket;
35 class Log;
36
37 class InputUDP : public Input
38 {
39   public:
40     bool init();
41     void shutdown();
42
43     bool start();
44     void stop();
45
46     // InputUDP doesn't do any translation stuff so just keep everything happy here
47     void InitHWCListwithDefaults() {};
48     UCHAR TranslateHWCFixed(HWC_TYPE code) { return static_cast<UCHAR>(code); };
49     const char* getHardCodedHardwareKeyNamesForVompKey(UCHAR vompKey);
50     std::string getHardwareKeyName(HWC_TYPE hardwareKey);
51
52   private:
53     static const char* myModName;
54     const char* modName() { return myModName; }
55
56     bool initted{};
57     DatagramSocket* ds{};
58     Log* log{};
59
60     std::thread listenThread;
61     std::mutex threadStartProtect;
62     void listenLoop();
63     bool listenLoopStop{};
64
65 #ifdef WIN32
66     SOCKET quitPipe;
67 #else
68     int pfds[2];
69 #endif
70
71     void processRequest(const void* data, UINT length);
72 };
73
74 #endif