-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDevice_Controller.m
126 lines (92 loc) · 2.96 KB
/
Device_Controller.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// Device_Controller.m
// data_m
//
// Created by Mike Fluff on 3/17/11.
// Copyright 2011 __MyCompanyName__. All rights reserved.
//
#import "Device_Controller.h"
#import "DeviceConfigurator.h"
#import "Test_Activity_Controller.h"
@implementation Device_Controller
@synthesize isConfigured;
@synthesize lock;
@synthesize delegate;
@synthesize TAC;
- (id)init
{
self = [super init];
if (self) {
// Initialization code here.
NSLock *lock = [[NSLock alloc] init];
}
return self;
}
-(id)initWithIp:(NSString *)ipaddr login:(NSString *)log password:(NSString *)pass
{
self = [super init];
if (self) {
iface = [[basher alloc] init];
ip = ipaddr;
login = log;
password = pass;
isAvailable = NO;
png = [[pinger alloc] initWithController:self host:ip];
tc = [[TestConfigurator alloc] init];
config_hash = [[NSString alloc] initWithString:[NSString MyStringWithRandomUppercaseLetter:8]];
}
return self;
}
//this method uses to load pre-copied config on device
-(void)loadconfig
{
NSArray *arguments = [[NSArray alloc] initWithObjects:config_hash,nil];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSObject *action = [defaults objectForKey:@"loadconfig"];
[iface setAction:action];
[iface initWithController:self addr:ip login:login password:password type:@"expect"];
[iface startArgProcess:arguments];
isConfigured = YES;
}
//this method moves config to device
-(BOOL)moveConfigToDevice
{
NSString *file = [[NSString alloc] init];
[iface initWithController:self addr:ip login:login password:password type:@"ssh"];
[iface copyFile:[self saveStringConfigToFile:[tc returnConfig] withName:config_hash] toDestinition:[NSString stringWithFormat:@"/opt/vyatta/etc/config/%@", config_hash]];
return YES;
}
//this method gets string config, save it in temporary file and return path to it
-(NSString *)saveStringConfigToFile:(NSString *)config withName:(NSString *)name
{
NSURL *storeUrl = [NSURL fileURLWithPath:[@"/tmp/neo/" stringByAppendingPathComponent:name]];
[config writeToURL:storeUrl atomically:YES encoding:NSASCIIStringEncoding error:NULL];
return [storeUrl relativePath];
}
//this method is moving config to device and loading it
-(void)processConfig
{
NSAutoreleasePool * pool;
pool = [[NSAutoreleasePool alloc] init];
while(true)
{
if([lock tryLock])
{
[self moveConfigToDevice];
[lock unlock];
break;
}
}
[self loadconfig];
[pool drain];
[delegate threadFinished];
}
-(void)configureDeviceForTest:(NSString *)testType withIntNum:(NSInteger)links withPairsNum:(NSInteger)pairs side:(NSString *)side okt:(NSInteger)okt type:(NSString *)type
{
[tc initWithTest:testType links:links pairs:pairs side:side oktet:okt type:type];
}
- (void)dealloc
{
[super dealloc];
}
@end