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