xbmc
UdpClient.h
1 /*
2  * Copyright (c) 2002 Frodo
3  * Portions Copyright (c) by the authors of ffmpeg and xvid
4  *
5  * Copyright (C) 2002-2018 Team Kodi
6  * This file is part of Kodi - https://kodi.tv
7  *
8  * SPDX-License-Identifier: GPL-2.0-or-later
9  * See LICENSES/README.md for more information.
10  */
11 
12 #pragma once
13 
14 #include "threads/CriticalSection.h"
15 #include "threads/Thread.h"
16 
17 #include <string>
18 #include <vector>
19 
20 #include <netinet/in.h>
21 #include <sys/socket.h>
22 
23 #include "PlatformDefs.h"
24 
26 {
27 public:
28  CUdpClient();
29  ~CUdpClient(void) override;
30 
31 protected:
32 
33  bool Create();
34  void Destroy();
35 
36  void OnStartup() override;
37  void Process() override;
38 
39  bool Broadcast(int aPort, const std::string& aMessage);
40  bool Send(const std::string& aIpAddress, int aPort, const std::string& aMessage);
41  bool Send(struct sockaddr_in aAddress, const std::string& aMessage);
42  bool Send(struct sockaddr_in aAddress, unsigned char* pMessage, DWORD dwSize);
43 
44  virtual void OnMessage(struct sockaddr_in& aRemoteAddress,
45  const std::string& aMessage,
46  unsigned char* pMessage,
47  DWORD dwMessageLength)
48  {
49  }
50 
51 protected:
52 
53  struct UdpCommand
54  {
55  struct sockaddr_in address;
56  std::string message;
57  unsigned char* binary;
58  DWORD binarySize;
59  };
60 
61  bool DispatchNextCommand();
62 
63  SOCKET client_socket;
64 
65  std::vector<UdpCommand> commands;
66  typedef std::vector<UdpCommand> ::iterator COMMANDITERATOR;
67 
68  CCriticalSection critical_section;
69 };
Definition: Thread.h:44
Definition: UdpClient.h:25
Definition: UdpClient.h:53