HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NET_MDNS.h
Go to the documentation of this file.
1 /*MIT License
2  *
3  * Copyright (c) 2020 Carlos Gomes Martinho
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included in
13  * all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #ifndef __NET_MDNS_H__
25 #define __NET_MDNS_H__
26 
27 #include "NET_API.h"
28 
29 #include <UT/UT_Array.h>
30 #include <UT/UT_NonCopyable.h>
31 #include <UT/UT_StringHolder.h>
32 
33 #include <thread>
34 #include <chrono>
35 
37 {
39  // Address
41  // Domain Name pointer
43  // Arbitrary text string
45  // IP6 Address [Thomson]
47  // Server Selection [RFC2782]
49 };
50 
52 {
57 };
58 
60 {
64 };
65 
67 {
68 public:
70  uint16_t myPort;
71  uint16_t myPriority;
72  uint16_t myWeight;
73 };
74 
76 {
77 public:
78  bool operator==(const NET_mDNSQueryResult &other) const
79  {
80  return myEntry == other.myEntry;
81  }
82  bool operator!=(const NET_mDNSQueryResult &other) const
83  {
84  return !(*this == other);
85  }
86 
91 };
92 
94 {
95 public:
97  myHostname("nobody"),
98  myName("_http._tcp.local."),
99  myTxtRecord(),
100  myHasIpv4(false),
101  myHasIpv6(false),
102  myServiceAddressIpv4(0)
103  {
104  memset(myServiceAddressIpv6, 0, sizeof(myServiceAddressIpv6));
105  }
106  ~NET_mDNS();
107 
109 
110 #if 0
111  bool isServiceRunning() { return myIsRunning; }
112  void setServiceHostname(const UT_StringHolder &hostname)
113  {
114  myHostname = hostname;
115  }
116  void setServicePort(std::uint16_t port) { myPort = port; }
117  void setServiceName(const UT_StringHolder &name) { myName = name; }
118  void setServiceTxtRecord(const UT_StringHolder &txt_record)
119  {
120  myTxtRecord = txt_record;
121  }
122  void startService();
123  void stopService();
124 #endif
125  void executeQuery(
126  const UT_StringHolder &service,
128  const std::chrono::milliseconds &max_query_time,
130 #if 0
131  void executeDiscovery();
132 #endif
133 private:
134 #if 0
135  void runMainLoop();
136  int openServiceSockets(int *sockets, int max_sockets);
137 
138  std::thread worker_thread_;
139  std::uint16_t myPort;
140  bool myIsRunning;
141 #endif
142  int openClientSockets(
143  int *sockets,
144  int max_sockets,
145  int port,
146  NET_mDNSIpFilter ip_filter);
147 
148  UT_StringHolder myHostname;
149  UT_StringHolder myName;
150  UT_StringHolder myTxtRecord;
151 
152  bool myHasIpv4;
153  bool myHasIpv6;
154 
155  uint32_t myServiceAddressIpv4;
156  uint8_t myServiceAddressIpv6[16];
157 };
158 
159 #endif // __NET_MDNS_H__
160 
UT_StringHolder myFromAddr
Definition: NET_MDNS.h:89
uint16_t myPort
Definition: NET_MDNS.h:70
UT_StringHolder myName
Definition: NET_MDNS.h:69
uint16_t myPriority
Definition: NET_MDNS.h:71
NET_mDNSEntryType myEntryType
Definition: NET_MDNS.h:87
bool operator==(const NET_mDNSQueryResult &other) const
Definition: NET_MDNS.h:78
#define NET_API
Definition: NET_API.h:9
bool operator!=(const NET_mDNSQueryResult &other) const
Definition: NET_MDNS.h:82
NET_mDNSEntryType
Definition: NET_MDNS.h:51
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
GLuint const GLchar * name
Definition: glcorearb.h:786
NET_mDNSIpFilter
Definition: NET_MDNS.h:59
**Note that the tasks the is the thread number *for the or if it s being executed by a non pool thread(this *can happen in cases where the whole pool is occupied and the calling *thread contributes to running the work load).**Thread pool.Have fun
NET_mDNS()
Definition: NET_MDNS.h:96
UT_StringHolder myEntry
Definition: NET_MDNS.h:88
uint16_t myWeight
Definition: NET_MDNS.h:72
NET_mDNSRecordSRV mySRV
Definition: NET_MDNS.h:90
NET_mDNSRecordType
Definition: NET_MDNS.h:36