Ticket #1395: BonjourController.m

File BonjourController.m, 2.2 KB (added by Waldorf, 12 years ago)
Line 
1//
2//  BonjourController.m
3//  Transmission
4//
5//  Created by Maarten Van Coile on 05/12/08.
6//  Copyright 2008 __MyCompanyName__. All rights reserved.
7//
8
9#import "BonjourController.h"
10
11
12@implementation BonjourController
13BonjourController * defaultController = nil;
14
15+ (BonjourController *) defaultController
16{
17    if ( !defaultController )
18        defaultController = [[BonjourController alloc] init];
19    return defaultController;
20}
21
22- (id) init
23{
24    self = [super init];
25    if (self != nil) {
26       
27    }
28    return self;
29}
30
31- (void) dealloc
32{
33    [service release];
34    [super dealloc];
35}
36
37- (void) startWithPort: (NSInteger) port
38{
39    if ( service )
40        [self stop];
41   
42    NSString * serviceName = [NSString stringWithFormat:@"%@: Transmission Web Interface", (NSString *) CSCopyMachineName()];
43    service = [[NSNetService alloc] initWithDomain: @"local."
44                                              type: @"_http._tcp."
45                                              name: serviceName
46                                              port: port];   
47    if ( service )
48    {
49        [service setDelegate:self];
50        [service publish];
51    }
52}
53
54- (void) stop;
55{
56    if ( service )
57    {
58        [service stop];
59        [service release];
60        service = nil;
61    }
62}
63
64- (void)netServiceWillPublish:(NSNetService *)sender
65{
66    NSLog(@"Will publish the Web UI service on port: %d", [sender port]);
67}
68
69- (void)netService:(NSNetService *)sender didNotPublish:(NSDictionary *)errorDict
70{
71    NSLog(@"Failed to publish the Web UI service on port: %d, with error: %@", [sender port], errorDict);
72}
73
74- (void)netServiceDidPublish:(NSNetService *)sender
75{
76    NSLog(@"Did publish the Web UI service on port: %d", [sender port]);
77}
78
79- (void)netServiceWillResolve:(NSNetService *)sender
80{
81    NSLog(@"Will resolve the Web UI service on port: %d", [sender port]);
82}
83
84- (void)netService:(NSNetService *)sender didNotResolve:(NSDictionary *)errorDict
85{
86    NSLog(@"Failed to resolve the Web UI service on port: %d, with error: %@", [sender port], errorDict);
87}
88
89- (void)netServiceDidResolveAddress:(NSNetService *)sender
90{
91    NSLog(@"Did resolve the Web UI service on port: %d", [sender port]);
92}
93
94@end