PortMapper/MYDNSService.h
author Jens Alfke <jens@mooseyard.com>
Mon Apr 27 09:03:56 2009 -0700 (2009-04-27)
changeset 28 732576fa8a0d
parent 27 92581f26073e
child 31 1d6924779df7
permissions -rw-r--r--
Rewrote the Bonjour classes, using the low-level <dns_sd.h> API. They're now subclasses of MYDNSService.
     1 //
     2 //  MYDNSService.h
     3 //  MYNetwork
     4 //
     5 //  Created by Jens Alfke on 4/23/09.
     6 //  Copyright 2009 Jens Alfke. All rights reserved.
     7 //
     8 
     9 #import <Foundation/Foundation.h>
    10 #import <CoreFoundation/CFSocket.h>
    11 
    12 
    13 /** Abstract superclass for services based on DNSServiceRefs, such as MYPortMapper. */
    14 @interface MYDNSService : NSObject
    15 {
    16     @private
    17     struct _DNSServiceRef_t *_serviceRef;
    18     CFSocketRef _socket;
    19     CFRunLoopSourceRef _socketSource;
    20     SInt32 _error;
    21     BOOL _continuous;
    22 }
    23 
    24 /** If NO (the default), the service will stop after it gets a result.
    25     If YES, it will continue to run until stopped. */
    26 @property BOOL continuous;
    27 
    28 /** Starts the service.
    29     Returns immediately; you can find out when the service actually starts (or fails to)
    30     by observing the isOpen and error properties.
    31     It's very unlikely that this call itself will fail (return NO). If it does, it
    32     probably means that the mDNSResponder process isn't working. */
    33 - (BOOL) start;
    34 
    35 /** Stops the service. */
    36 - (void) stop;
    37 
    38 
    39 /** The error status, a DNSServiceErrorType enum; nonzero if something went wrong. 
    40     This property is KV observable. */
    41 @property int32_t error;
    42 
    43 // PROTECTED:
    44 
    45 /** Subclass must implement this abstract method to create a new DNSServiceRef.
    46     This method is called by -open.
    47     If an error occurs, the method should set self.error and return NULL.*/
    48 - (struct _DNSServiceRef_t*) createServiceRef;
    49 
    50 @property (readonly) struct _DNSServiceRef_t* serviceRef;
    51 
    52 /** Same as -stop, but does not clear the error property.
    53     (The stop method actually calls this first.) */
    54 - (void) cancel;
    55 
    56 /** Block until a message is received from the daemon.
    57     This will cause the service's callback (defined by the subclass) to be invoked.
    58     @return  YES if a message is received, NO on error (or if the service isn't started) */
    59 - (BOOL) waitForReply;
    60 
    61 @end