ip.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*************************************************************************/
  2. /* ip.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef IP_H
  30. #define IP_H
  31. #include "os/os.h"
  32. #include "io/ip_address.h"
  33. struct _IP_ResolverPrivate;
  34. class IP : public Object {
  35. GDCLASS( IP, Object );
  36. OBJ_CATEGORY("Networking");
  37. public:
  38. enum ResolverStatus {
  39. RESOLVER_STATUS_NONE,
  40. RESOLVER_STATUS_WAITING,
  41. RESOLVER_STATUS_DONE,
  42. RESOLVER_STATUS_ERROR,
  43. };
  44. enum Type {
  45. TYPE_NONE = 0,
  46. TYPE_IPV4 = 1,
  47. TYPE_IPV6 = 2,
  48. TYPE_ANY = 3,
  49. };
  50. enum {
  51. RESOLVER_MAX_QUERIES = 32,
  52. RESOLVER_INVALID_ID=-1
  53. };
  54. typedef int ResolverID;
  55. private:
  56. _IP_ResolverPrivate *resolver;
  57. protected:
  58. static IP*singleton;
  59. static void _bind_methods();
  60. virtual IP_Address _resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY)=0;
  61. Array _get_local_addresses() const;
  62. static IP* (*_create)();
  63. public:
  64. IP_Address resolve_hostname(const String& p_hostname, Type p_type = TYPE_ANY);
  65. // async resolver hostname
  66. ResolverID resolve_hostname_queue_item(const String& p_hostname, Type p_type = TYPE_ANY);
  67. ResolverStatus get_resolve_item_status(ResolverID p_id) const;
  68. IP_Address get_resolve_item_address(ResolverID p_id) const;
  69. virtual void get_local_addresses(List<IP_Address> *r_addresses) const=0;
  70. void erase_resolve_item(ResolverID p_id);
  71. void clear_cache(const String& p_hostname = "");
  72. static IP* get_singleton();
  73. static IP* create();
  74. IP();
  75. ~IP();
  76. };
  77. VARIANT_ENUM_CAST(IP::Type);
  78. #endif // IP_H