Bonjour/MYBonjourService.h
author Jens Alfke <jens@mooseyard.com>
Mon Jul 20 13:26:29 2009 -0700 (2009-07-20)
changeset 59 46c7844cb592
parent 50 63baa74c903f
permissions -rw-r--r--
* MYBonjourBrowser: Added delegate (no methods for it yet, just for client use.)
* MYBonjourRegistration: Added +canonicalFormOfTXTRecordDictionary:.
* MYBonjourService: Added back-reference to browser.
* IPAddress: Added conversions to/from struct sockaddr.
     1 //
     2 //  MYBonjourService.h
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 1/22/08.
     6 //  Copyright 2008 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import "MYDNSService.h"
    10 @class MYBonjourBrowser, MYBonjourQuery, MYAddressLookup;
    11 
    12 
    13 /** Represents a Bonjour service discovered by a MYBonjourBrowser. */
    14 @interface MYBonjourService : MYDNSService 
    15 {
    16     @private
    17     MYBonjourBrowser *_bonjourBrowser;
    18     NSString *_name, *_fullName, *_type, *_domain, *_hostname;
    19     uint32_t _interfaceIndex;
    20     BOOL _startedResolve;
    21     UInt16 _port;
    22     NSDictionary *_txtRecord;
    23     MYBonjourQuery *_txtQuery;
    24     MYAddressLookup *_addressLookup;
    25 }
    26 
    27 /** The browser I belong to. */
    28 @property (readonly) MYBonjourBrowser *bonjourBrowser;
    29 
    30 /** The service's name. */
    31 @property (readonly) NSString *name;
    32 
    33 /** The service's type. */
    34 @property (readonly) NSString *type;
    35 
    36 /** The service's domain. */
    37 @property (readonly) NSString *domain;
    38 
    39 /** The service's full name -- the name, type and domain concatenated together. */
    40 @property (readonly,copy) NSString* fullName;
    41 
    42 /** The index of the network interface on which this service was found. */
    43 @property (readonly) uint32_t interfaceIndex;
    44 
    45 
    46 /** @name Addressing
    47  *  Getting the IP address of the service
    48  */
    49 //@{
    50 
    51 /** The hostname of the machine providing this service. */
    52 @property (readonly, copy) NSString *hostname;
    53 
    54 /** The IP port number of this service on its host. */
    55 @property (readonly) UInt16 port;
    56 
    57 /** Returns a MYDNSLookup object that resolves the raw IP address(es) of this service.
    58     Subsequent calls to this method will always return the same object. */
    59 - (MYAddressLookup*) addressLookup;
    60 
    61 //@}
    62 
    63 
    64 /** @name TXT and other DNS records
    65  */
    66 //@{
    67 
    68 /** The service's metadata dictionary, from its DNS TXT record */
    69 @property (readonly,copy) NSDictionary *txtRecord;
    70 
    71 /** A convenience to access a single property from the TXT record. */
    72 - (NSString*) txtStringForKey: (NSString*)key;
    73 
    74 /** Starts a new MYBonjourQuery for the specified DNS record type of this service.
    75     @param recordType  The DNS record type, e.g. kDNSServiceType_TXT; see the enum in <dns_sd.h>. */
    76 - (MYBonjourQuery*) queryForRecord: (UInt16)recordType;
    77 
    78 //@}
    79 
    80 
    81 /** @name Protected
    82  *  Advanced methods that may be overridden by subclasses, but should not be called directly.
    83  */
    84 //@{
    85 
    86 /** Designated initializer. You probably don't want to create MYBonjourService instances yourself,
    87     but if you subclass you might need to override this initializer. */
    88 - (id) initWithBrowser: (MYBonjourBrowser*)browser
    89                   name: (NSString*)serviceName
    90                   type: (NSString*)type
    91                 domain: (NSString*)domain
    92              interface: (UInt32)interfaceIndex;
    93 
    94 /** Called when this service is officially added to its browser's service set.
    95     You can override this, but be sure to call the superclass method. */
    96 - (void) added;
    97 
    98 /** Called when this service is officially removed to its browser's service set.
    99     You can override this, but be sure to call the superclass method. */
   100 - (void) removed;
   101 
   102 /** Called when this service's TXT record changes.
   103     You can override this, but be sure to call the superclass method. */
   104 - (void) txtRecordChanged;
   105 
   106 /** Called when a query started by this service updates.
   107     You can override this, but be sure to call the superclass method. */
   108 - (void) queryDidUpdate: (MYBonjourQuery*)query;
   109 
   110 //@}
   111 
   112 @end