-
Notifications
You must be signed in to change notification settings - Fork 41
/
AMNetworkServicesChooser.m
68 lines (53 loc) · 1.69 KB
/
AMNetworkServicesChooser.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// AMNEtworkServicesChooser.m
// SSHTunnel
//
// Created by Antoine Mercadal on 23/08/08.
// Copyright 2008 Capgemini. All rights reserved.
//
#import "AMNetworkServicesChooser.h"
@implementation AMNetworkServicesChooser
@synthesize content;
- (id) init
{
if (self = [super init])
{
[self setContent:[NSMutableArray array]];
[self getSystemNetworkServices];
return self;
}
return nil;
}
- (void) getSystemNetworkServices
{
task = [[NSTask alloc] init];
stdOut = [NSPipe pipe];
[task setLaunchPath:@"/usr/sbin/networksetup"];
[task setArguments:[NSArray arrayWithObjects:@"-listallnetworkservices", nil]];
[task setStandardOutput:stdOut];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleEndOfTask:)
name:NSFileHandleReadToEndOfFileCompletionNotification
object:[[task standardOutput] fileHandleForReading]];
[[stdOut fileHandleForReading] readToEndOfFileInBackgroundAndNotify];
[task launch];
}
- (void) handleEndOfTask:(NSNotification *) aNotification
{
NSData *data;
NSString *outputContent;
NSPredicate *checkSuccess;
data = [[aNotification userInfo] objectForKey:NSFileHandleNotificationDataItem];
outputContent = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSMutableArray *a = [NSMutableArray arrayWithArray:[outputContent componentsSeparatedByString:@"\n"]];
[a removeLastObject];
[a removeObjectAtIndex:0];
[self setContent:a];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSFileHandleReadCompletionNotification object:[stdOut fileHandleForReading]];
[task terminate];
data = nil;
outputContent = nil;
checkSuccess = nil;
task = nil;
}
@end