TDE core libraries
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

servicebase.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* This file is part of the KDE project
  2. *
  3. * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Library General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. */
  20. #ifndef DNSSDSERVICEBASE_H
  21. #define DNSSDSERVICEBASE_H
  22. #include <tqmap.h>
  23. #include <ksharedptr.h>
  24. class TQString;
  25. class TQDataStream;
  26. namespace DNSSD
  27. {
  28. class ServiceBasePrivate;
  29. /**
  30. This class is used to carry information about service. It can be remote, local,
  31. metaservice or domain. Metaservice has only type and domain - it means that
  32. services of given type are present in given domain.
  33. @short Describes any type of service.
  34. @author Jakub Stachowski
  35. */
  36. class TDEDNSSD_EXPORT ServiceBase : public TDEShared
  37. {
  38. public:
  39. typedef TDESharedPtr<ServiceBase> Ptr;
  40. /**
  41. @param name Service name - empty for metaservices
  42. @param type Service type - empty for domains
  43. @param domain Domain name
  44. @param host Host name
  45. @param port Port number
  46. */
  47. ServiceBase(const TQString& name=TQString::null,const TQString& type=TQString::null,
  48. const TQString& domain=TQString::null, const TQString& host=TQString::null,
  49. unsigned short port=0);
  50. virtual ~ServiceBase();
  51. /**
  52. Returns name of service. This is empty for metaservices
  53. */
  54. const TQString& serviceName() const;
  55. /**
  56. Returns type of service. It always in format _sometype._udp or _sometype._tcp and
  57. it is empty for domains.
  58. */
  59. const TQString& type() const;
  60. /**
  61. Returns domain that given service belongs to. It is "local." for link-local services.
  62. */
  63. const TQString& domain() const;
  64. /**
  65. Returns hostname. It is only valid for local and resolved remote services.
  66. */
  67. const TQString& hostName() const;
  68. /**
  69. Returns port number. It is only valid for local and resolved remote services.
  70. */
  71. unsigned short port() const;
  72. /**
  73. Returns read only map of text properties. It is only valid for local and resolved remote services.
  74. */
  75. const TQMap<TQString,TQString>& textData() const;
  76. protected:
  77. TQString m_serviceName;
  78. TQString m_type;
  79. TQString m_domain;
  80. TQString m_hostName;
  81. unsigned short m_port;
  82. /**
  83. Map of TXT properties
  84. */
  85. TQMap<TQString,TQString> m_textData;
  86. /**
  87. Encode service name, type and domain into string that can be used as DNS-SD PTR label
  88. */
  89. TQString encode();
  90. /**
  91. Decode PTR label returned by DNS resolver into service name, type and domain. It also
  92. handles special cases - metaservices and domains.
  93. */
  94. void decode(const TQString& name);
  95. friend TDEDNSSD_EXPORT TQDataStream & operator<< (TQDataStream & s, const ServiceBase & a);
  96. friend TDEDNSSD_EXPORT TQDataStream & operator>> (TQDataStream & s, ServiceBase & a);
  97. virtual void virtual_hook(int, void*);
  98. private:
  99. ServiceBasePrivate* d;
  100. };
  101. }
  102. #endif