1 /**
2 UPNP device.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.upnpdevice;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.reference;
25 /**
26 UPNP device.
27 
28 See $(D UPNP) for UPNP discovery and utility functions. Provides low-level access to UPNP control commands. Allows to manage port mappings (port forwarding) and to query network information of the device (like local and external IP address and status). Note that methods on this class are synchronous and block the calling thread.
29 */
30 @GodotBaseClass struct UPNPDevice
31 {
32 	package(godot) enum string _GODOT_internal_name = "UPNPDevice";
33 public:
34 @nogc nothrow:
35 	union { /** */ godot_object _godot_object; /** */ Reference _GODOT_base; }
36 	alias _GODOT_base this;
37 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
38 	package(godot) __gshared bool _classBindingInitialized = false;
39 	package(godot) static struct GDNativeClassBinding
40 	{
41 		__gshared:
42 		@GodotName("add_port_mapping") GodotMethod!(long, long, long, String, String, long) addPortMapping;
43 		@GodotName("delete_port_mapping") GodotMethod!(long, long, String) deletePortMapping;
44 		@GodotName("get_description_url") GodotMethod!(String) getDescriptionUrl;
45 		@GodotName("get_igd_control_url") GodotMethod!(String) getIgdControlUrl;
46 		@GodotName("get_igd_our_addr") GodotMethod!(String) getIgdOurAddr;
47 		@GodotName("get_igd_service_type") GodotMethod!(String) getIgdServiceType;
48 		@GodotName("get_igd_status") GodotMethod!(UPNPDevice.IGDStatus) getIgdStatus;
49 		@GodotName("get_service_type") GodotMethod!(String) getServiceType;
50 		@GodotName("is_valid_gateway") GodotMethod!(bool) isValidGateway;
51 		@GodotName("query_external_address") GodotMethod!(String) queryExternalAddress;
52 		@GodotName("set_description_url") GodotMethod!(void, String) setDescriptionUrl;
53 		@GodotName("set_igd_control_url") GodotMethod!(void, String) setIgdControlUrl;
54 		@GodotName("set_igd_our_addr") GodotMethod!(void, String) setIgdOurAddr;
55 		@GodotName("set_igd_service_type") GodotMethod!(void, String) setIgdServiceType;
56 		@GodotName("set_igd_status") GodotMethod!(void, long) setIgdStatus;
57 		@GodotName("set_service_type") GodotMethod!(void, String) setServiceType;
58 	}
59 	/// 
60 	pragma(inline, true) bool opEquals(in UPNPDevice other) const
61 	{ return _godot_object.ptr is other._godot_object.ptr; }
62 	/// 
63 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
64 	{ _godot_object.ptr = n; return null; }
65 	/// 
66 	pragma(inline, true) bool opEquals(typeof(null) n) const
67 	{ return _godot_object.ptr is n; }
68 	/// 
69 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
70 	mixin baseCasts;
71 	/// Construct a new instance of UPNPDevice.
72 	/// Note: use `memnew!UPNPDevice` instead.
73 	static UPNPDevice _new()
74 	{
75 		static godot_class_constructor constructor;
76 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("UPNPDevice");
77 		if(constructor is null) return typeof(this).init;
78 		return cast(UPNPDevice)(constructor());
79 	}
80 	@disable new(size_t s);
81 	/// 
82 	enum IGDStatus : int
83 	{
84 		/**
85 		OK.
86 		*/
87 		igdStatusOk = 0,
88 		/**
89 		HTTP error.
90 		*/
91 		igdStatusHttpError = 1,
92 		/**
93 		Empty HTTP response.
94 		*/
95 		igdStatusHttpEmpty = 2,
96 		/**
97 		Returned response contained no URLs.
98 		*/
99 		igdStatusNoUrls = 3,
100 		/**
101 		Not a valid IGD.
102 		*/
103 		igdStatusNoIgd = 4,
104 		/**
105 		Disconnected.
106 		*/
107 		igdStatusDisconnected = 5,
108 		/**
109 		Unknown device.
110 		*/
111 		igdStatusUnknownDevice = 6,
112 		/**
113 		Invalid control.
114 		*/
115 		igdStatusInvalidControl = 7,
116 		/**
117 		Memory allocation error.
118 		*/
119 		igdStatusMallocError = 8,
120 		/**
121 		Unknown error.
122 		*/
123 		igdStatusUnknownError = 9,
124 	}
125 	/// 
126 	enum Constants : int
127 	{
128 		igdStatusOk = 0,
129 		igdStatusHttpError = 1,
130 		igdStatusHttpEmpty = 2,
131 		igdStatusNoUrls = 3,
132 		igdStatusNoIgd = 4,
133 		igdStatusDisconnected = 5,
134 		igdStatusUnknownDevice = 6,
135 		igdStatusInvalidControl = 7,
136 		igdStatusMallocError = 8,
137 		igdStatusUnknownError = 9,
138 	}
139 	/**
140 	Adds a port mapping to forward the given external port on this $(D UPNPDevice) for the given protocol to the local machine. See $(D UPNP.addPortMapping).
141 	*/
142 	long addPortMapping(in long port, in long port_internal = 0, in String desc = gs!"", in String proto = gs!"UDP", in long duration = 0) const
143 	{
144 		checkClassBinding!(typeof(this))();
145 		return ptrcall!(long)(GDNativeClassBinding.addPortMapping, _godot_object, port, port_internal, desc, proto, duration);
146 	}
147 	/**
148 	Deletes the port mapping identified by the given port and protocol combination on this device. See $(D UPNP.deletePortMapping).
149 	*/
150 	long deletePortMapping(in long port, in String proto = gs!"UDP") const
151 	{
152 		checkClassBinding!(typeof(this))();
153 		return ptrcall!(long)(GDNativeClassBinding.deletePortMapping, _godot_object, port, proto);
154 	}
155 	/**
156 	
157 	*/
158 	String getDescriptionUrl() const
159 	{
160 		checkClassBinding!(typeof(this))();
161 		return ptrcall!(String)(GDNativeClassBinding.getDescriptionUrl, _godot_object);
162 	}
163 	/**
164 	
165 	*/
166 	String getIgdControlUrl() const
167 	{
168 		checkClassBinding!(typeof(this))();
169 		return ptrcall!(String)(GDNativeClassBinding.getIgdControlUrl, _godot_object);
170 	}
171 	/**
172 	
173 	*/
174 	String getIgdOurAddr() const
175 	{
176 		checkClassBinding!(typeof(this))();
177 		return ptrcall!(String)(GDNativeClassBinding.getIgdOurAddr, _godot_object);
178 	}
179 	/**
180 	
181 	*/
182 	String getIgdServiceType() const
183 	{
184 		checkClassBinding!(typeof(this))();
185 		return ptrcall!(String)(GDNativeClassBinding.getIgdServiceType, _godot_object);
186 	}
187 	/**
188 	
189 	*/
190 	UPNPDevice.IGDStatus getIgdStatus() const
191 	{
192 		checkClassBinding!(typeof(this))();
193 		return ptrcall!(UPNPDevice.IGDStatus)(GDNativeClassBinding.getIgdStatus, _godot_object);
194 	}
195 	/**
196 	
197 	*/
198 	String getServiceType() const
199 	{
200 		checkClassBinding!(typeof(this))();
201 		return ptrcall!(String)(GDNativeClassBinding.getServiceType, _godot_object);
202 	}
203 	/**
204 	Returns `true` if this is a valid IGD (InternetGatewayDevice) which potentially supports port forwarding.
205 	*/
206 	bool isValidGateway() const
207 	{
208 		checkClassBinding!(typeof(this))();
209 		return ptrcall!(bool)(GDNativeClassBinding.isValidGateway, _godot_object);
210 	}
211 	/**
212 	Returns the external IP address of this $(D UPNPDevice) or an empty string.
213 	*/
214 	String queryExternalAddress() const
215 	{
216 		checkClassBinding!(typeof(this))();
217 		return ptrcall!(String)(GDNativeClassBinding.queryExternalAddress, _godot_object);
218 	}
219 	/**
220 	
221 	*/
222 	void setDescriptionUrl(in String url)
223 	{
224 		checkClassBinding!(typeof(this))();
225 		ptrcall!(void)(GDNativeClassBinding.setDescriptionUrl, _godot_object, url);
226 	}
227 	/**
228 	
229 	*/
230 	void setIgdControlUrl(in String url)
231 	{
232 		checkClassBinding!(typeof(this))();
233 		ptrcall!(void)(GDNativeClassBinding.setIgdControlUrl, _godot_object, url);
234 	}
235 	/**
236 	
237 	*/
238 	void setIgdOurAddr(in String addr)
239 	{
240 		checkClassBinding!(typeof(this))();
241 		ptrcall!(void)(GDNativeClassBinding.setIgdOurAddr, _godot_object, addr);
242 	}
243 	/**
244 	
245 	*/
246 	void setIgdServiceType(in String type)
247 	{
248 		checkClassBinding!(typeof(this))();
249 		ptrcall!(void)(GDNativeClassBinding.setIgdServiceType, _godot_object, type);
250 	}
251 	/**
252 	
253 	*/
254 	void setIgdStatus(in long status)
255 	{
256 		checkClassBinding!(typeof(this))();
257 		ptrcall!(void)(GDNativeClassBinding.setIgdStatus, _godot_object, status);
258 	}
259 	/**
260 	
261 	*/
262 	void setServiceType(in String type)
263 	{
264 		checkClassBinding!(typeof(this))();
265 		ptrcall!(void)(GDNativeClassBinding.setServiceType, _godot_object, type);
266 	}
267 	/**
268 	URL to the device description.
269 	*/
270 	@property String descriptionUrl()
271 	{
272 		return getDescriptionUrl();
273 	}
274 	/// ditto
275 	@property void descriptionUrl(String v)
276 	{
277 		setDescriptionUrl(v);
278 	}
279 	/**
280 	IDG control URL.
281 	*/
282 	@property String igdControlUrl()
283 	{
284 		return getIgdControlUrl();
285 	}
286 	/// ditto
287 	@property void igdControlUrl(String v)
288 	{
289 		setIgdControlUrl(v);
290 	}
291 	/**
292 	Address of the local machine in the network connecting it to this $(D UPNPDevice).
293 	*/
294 	@property String igdOurAddr()
295 	{
296 		return getIgdOurAddr();
297 	}
298 	/// ditto
299 	@property void igdOurAddr(String v)
300 	{
301 		setIgdOurAddr(v);
302 	}
303 	/**
304 	IGD service type.
305 	*/
306 	@property String igdServiceType()
307 	{
308 		return getIgdServiceType();
309 	}
310 	/// ditto
311 	@property void igdServiceType(String v)
312 	{
313 		setIgdServiceType(v);
314 	}
315 	/**
316 	IGD status. See $(D igdstatus).
317 	*/
318 	@property UPNPDevice.IGDStatus igdStatus()
319 	{
320 		return getIgdStatus();
321 	}
322 	/// ditto
323 	@property void igdStatus(long v)
324 	{
325 		setIgdStatus(v);
326 	}
327 	/**
328 	Service type.
329 	*/
330 	@property String serviceType()
331 	{
332 		return getServiceType();
333 	}
334 	/// ditto
335 	@property void serviceType(String v)
336 	{
337 		setServiceType(v);
338 	}
339 }