Imported Upstream version 878.70.2
[platform/upstream/mdnsresponder.git] / mDNSMacOSX / PreferencePane / BonjourPrefTool / main.m
1 /*
2  *
3  * Copyright (c) 2016 Apple Inc. All rights reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17
18 #import <Foundation/Foundation.h>
19 #import "BonjourPrefTool.h"
20
21 @interface ServiceDelegate : NSObject <NSXPCListenerDelegate>
22 @end
23
24 @implementation ServiceDelegate
25
26 - (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
27     // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
28     (void)listener; // Unused
29     
30     // Configure the connection.
31     // First, set the interface that the exported object implements.
32     newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(BonjourPrefToolProtocol)];
33     
34     // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
35     BonjourPrefTool *exportedObject = [BonjourPrefTool new];
36     newConnection.exportedObject = exportedObject;
37     
38     // Resuming the connection allows the system to deliver more incoming messages.
39     [newConnection resume];
40     
41     // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
42     return YES;
43 }
44
45 @end
46
47 int main(int argc, const char *argv[])
48 {
49     (void)argc; // Unused
50     (void)argv; // Unused
51
52     // Create the delegate for the service.
53     ServiceDelegate *delegate = [ServiceDelegate new];
54     
55     // Set up the one NSXPCListener for this service. It will handle all incoming connections.
56     NSXPCListener *listener = [NSXPCListener serviceListener];
57     listener.delegate = delegate;
58     
59     // Resuming the serviceListener starts this service. This method does not return.
60     [listener resume];
61     return 0;
62 }