controller_patcher/source/network/UDPClient.hpp

67 lines
1.9 KiB
C++
Raw Normal View History

/****************************************************************************
* Copyright (C) 2016,2017 Maschell
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#ifndef _UDPCLIENT_WINDOW_H_
#define _UDPCLIENT_WINDOW_H_
2017-10-29 09:34:47 +01:00
#include "../ControllerPatcherIncludes.hpp"
2021-09-19 21:16:03 +02:00
#include <netinet/in.h>
2023-04-10 11:45:58 +02:00
#include <sys/socket.h>
2023-04-10 11:45:58 +02:00
#define DEFAULT_UDP_CLIENT_PORT 8114
2018-06-19 17:46:37 +02:00
class UDPClient {
friend class ControllerPatcher;
friend class ControllerPatcherHID;
friend class CPTCPServer;
2023-04-10 11:45:58 +02:00
public:
private:
static UDPClient *getInstance() {
2023-04-10 11:45:58 +02:00
if (instance == NULL) {
createInstance();
}
return instance;
}
static UDPClient *createInstance() {
2023-04-10 11:45:58 +02:00
if (instance != NULL) {
destroyInstance();
}
2023-04-10 11:45:58 +02:00
instance = new UDPClient(gUDPClientip, DEFAULT_UDP_CLIENT_PORT);
2023-04-10 11:45:58 +02:00
return getInstance();
}
static void destroyInstance() {
2023-04-10 11:45:58 +02:00
if (instance != NULL) {
delete instance;
instance = NULL;
}
}
2023-04-10 11:45:58 +02:00
UDPClient(uint32_t ip, int32_t port);
~UDPClient();
2023-04-10 11:45:58 +02:00
BOOL sendData(char *data, int32_t length);
2018-06-20 15:07:15 +02:00
volatile int32_t sockfd = -1;
struct sockaddr_in addr;
static UDPClient *instance;
};
#endif //_UDPClient_WINDOW_H_