Bonjour/MYBonjourService.h
author Jens Alfke <jens@mooseyard.com>
Wed Apr 22 16:45:39 2009 -0700 (2009-04-22)
changeset 26 cb9cdf247239
child 28 732576fa8a0d
permissions -rw-r--r--
* Added MYBonjourBrowser and MYBonjourService.
* Added MYPortMapper.
* Added -[TCPEndpoint setPeerToPeerIdentity:].
* Created a static-library target.
     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 <Foundation/Foundation.h>
    10 #import "ConcurrentOperation.h"
    11 @class MYBonjourResolveOperation;
    12 
    13 
    14 /** Represents a Bonjour service discovered by a BonjourBrowser. */
    15 @interface MYBonjourService : NSObject 
    16 {
    17     @private
    18     NSNetService *_netService;
    19     NSDictionary *_txtRecord;
    20     NSSet *_addresses;
    21     CFAbsoluteTime _addressesExpireAt;
    22     MYBonjourResolveOperation *_resolveOp;
    23 }
    24 
    25 /** The service's name. */
    26 @property (readonly) NSString *name;
    27 
    28 /** The service's metadata dictionary, from its DNS TXT record */
    29 @property (readonly,copy) NSDictionary *txtRecord;
    30 
    31 /** A convenience to access a single property from the TXT record. */
    32 - (NSString*) txtStringForKey: (NSString*)key;
    33 
    34 /** Returns a set of IPAddress objects; may be the empty set if address resolution failed,
    35     or nil if addresses have not been resolved yet (or expired).
    36     In the latter case, call -resolve and wait for the returned Operation to finish. */
    37 @property (readonly,copy) NSSet* addresses;
    38 
    39 /** Starts looking up the IP address(es) of this service.
    40     @return  The NSOperation representing the lookup; you can observe this to see when it
    41         completes, or you can observe the service's 'addresses' property. */
    42 - (MYBonjourResolveOperation*) resolve;
    43 
    44 /** The underlying NSNetSerice object. */
    45 @property (readonly) NSNetService *netService;
    46 
    47 
    48 // Protected methods, for subclass use only:
    49 
    50 - (id) initWithNetService: (NSNetService*)netService;
    51 
    52 // (for subclasses to override, but not call):
    53 - (void) added;
    54 - (void) removed;
    55 - (void) txtRecordChanged;
    56 
    57 @end
    58 
    59 
    60 
    61 @interface MYBonjourResolveOperation : ConcurrentOperation
    62 {
    63     MYBonjourService *_service;
    64     NSSet *_addresses;
    65 }
    66 
    67 @property (readonly) MYBonjourService *service;
    68 @property (readonly,retain) NSSet *addresses;
    69 
    70 @end