blob: 8bd5ac9b917876b136869376b58d9fe199818dff [file] [log] [blame]
Alexander Afanasyev14b09482013-10-11 18:24:45 +02001/* -*- Mode: objc; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
Alexander Afanasyev6cacb972013-10-03 23:39:06 -07002/*
3 * @copyright See LICENCE for copyright and license information.
4 *
5 * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
6 * @author Ilya Moiseenko <iliamo@ucla.edu>
7 */
8
9#include "config.h"
10#import "ndnd-status-operation.h"
11
12@implementation NdndStatusOperation
13
14-(id)initWithDelegate:(MenuDelegate*)delegate
15{
16 if (![super init]) return nil;
17 m_delegate = delegate;
18 return self;
19}
20
21-(void)main
22{
23 NSTask *task = [[NSTask alloc] init];
24 [task setLaunchPath: @NDND_STATUS_COMMAND];
25 [task setArguments: [NSArray arrayWithObjects: @"status",@"-x",nil]];
26
27 NSPipe * out = [NSPipe pipe];
28 [task setStandardOutput:out];
29
30 [task launch];
31 [task waitUntilExit];
32
33 NSFileHandle * read = [out fileHandleForReading];
34 NSData * dataRead = [read readDataToEndOfFile];
35 NSString *stringRead = [[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding];
36
37 if ([stringRead isEqualToString:@""]) {
38 [m_delegate performSelectorOnMainThread:@selector(statusUnavailable:)
39 withObject:nil
40 waitUntilDone:YES];
41
42 } else {
43 NSError *error = nil;
44 NSXMLDocument *document = [[NSXMLDocument alloc]
45 initWithXMLString:stringRead
46 options:0
47 error:&error];
48
49 [m_delegate performSelectorOnMainThread:@selector(statusUpdated:)
50 withObject:document
51 waitUntilDone:YES];
52 }
53
54 // [daemonStatusText setStringValue:stringRead];
55}
56
57@end