Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (53 sloc) 2.298 kb
fdbe89f @stevestreza Added support for running a listener on the Service
authored
1 //
2 // main.c
3 // TestService
4 //
e13de2a @stevestreza Updated copyright AGAIN
authored
5 // Created by Steve Streza on 7/24/11. Copyright 2011 XPCKit.
e7dc24b @stevestreza Updated code license
authored
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 // http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
fdbe89f @stevestreza Added support for running a listener on the Service
authored
18 //
19
20 #import <Foundation/Foundation.h>
624eb4b @stevestreza Added a working client/server test app
authored
21 #import <xpc/xpc.h>
fdbe89f @stevestreza Added support for running a listener on the Service
authored
22 #import "XPCKit.h"
23
24 int main(int argc, const char *argv[])
25 {
dd2f2f2 @stevestreza Minor service API change
authored
26 [XPCService runServiceWithConnectionHandler:^(XPCConnection *connection){
1ce594d @stevestreza Added NSFileHandle support for XPCKit, with example code in the app/serv...
authored
27 [connection _sendLog:@"Multiply received a connection"];
3d4516b @stevestreza Replaced the XPCListener singleton with an XPCService optional singleton...
authored
28 [connection setEventHandler:^(NSDictionary *message, XPCConnection *connection){
1ce594d @stevestreza Added NSFileHandle support for XPCKit, with example code in the app/serv...
authored
29 [connection _sendLog:[NSString stringWithFormat:@"Multiply received a message! %@", message]];
3d4516b @stevestreza Replaced the XPCListener singleton with an XPCService optional singleton...
authored
30 if([[message objectForKey:@"operation"] isEqual:@"multiply"]){
31 NSArray *values = [message objectForKey:@"values"];
624eb4b @stevestreza Added a working client/server test app
authored
32
3d4516b @stevestreza Replaced the XPCListener singleton with an XPCService optional singleton...
authored
33 // calculate the product
34 double product = 1.0;
35 for(NSUInteger index=0; index < values.count; index++){
36 product = product * [(NSNumber *)[values objectAtIndex:index] doubleValue];
37 }
624eb4b @stevestreza Added a working client/server test app
authored
38
3d4516b @stevestreza Replaced the XPCListener singleton with an XPCService optional singleton...
authored
39 [connection sendMessage:[NSDictionary dictionaryWithObject:[NSNumber numberWithDouble:product] forKey:@"result"]];
40 }
1ce594d @stevestreza Added NSFileHandle support for XPCKit, with example code in the app/serv...
authored
41
42 if([[message objectForKey:@"operation"] isEqual:@"read"]){
43 NSString *path = [message objectForKey:@"path"];
1f61651 @stevestreza Re-enabled data passing for shmem
authored
44 NSData *data = [[NSFileManager defaultManager] contentsAtPath:path];
1ce594d @stevestreza Added NSFileHandle support for XPCKit, with example code in the app/serv...
authored
45 NSFileHandle *fileHandle = [NSFileHandle fileHandleForReadingAtPath:path];
46
47 // [connection _sendLog:[NSString stringWithFormat:@"data %i bytes handle %@",data.length, fileHandle]];
48
49 [connection sendMessage:[NSDictionary dictionaryWithObjectsAndKeys:
1f61651 @stevestreza Re-enabled data passing for shmem
authored
50 data, @"data",
1ce594d @stevestreza Added NSFileHandle support for XPCKit, with example code in the app/serv...
authored
51 fileHandle, @"fileHandle",
52 nil]];
53 }
0613148 @stevestreza Added NSDate parsing
authored
54
55 if([[message objectForKey:@"operation"] isEqual:@"whatTimeIsIt"]){
56 [connection sendMessage:[NSDictionary dictionaryWithObject:[NSDate date] forKey:@"date"]];
57 }
3d4516b @stevestreza Replaced the XPCListener singleton with an XPCService optional singleton...
authored
58 }];
624eb4b @stevestreza Added a working client/server test app
authored
59 }];
dd2f2f2 @stevestreza Minor service API change
authored
60
61
62
fdbe89f @stevestreza Added support for running a listener on the Service
authored
63 return 0;
64 }
Something went wrong with that request. Please try again.