-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathMasterViewController.m
More file actions
319 lines (260 loc) · 9.64 KB
/
MasterViewController.m
File metadata and controls
319 lines (260 loc) · 9.64 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
//
// MasterViewController.m
// DLNASample
//
// Created by 健司 古山 on 12/05/06.
// Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//
#import "MasterViewController.h"
#import "ServerContentViewController.h"
#import "DetailViewController.h"
#import "AppDelegate.h"
#import "UPnPDeviceTableViewCell.h"
#import "RendererTableViewController.h"
//#include <cybergarage/upnp/cupnp.h>
//#include <cybergarage/xml/cxml.h>
@implementation MasterViewController
@synthesize detailViewController = _detailViewController;
@synthesize dataSource = dataSource_;
@synthesize avController = _avController;
@synthesize renderers = _renderers;
#if 0
void PrintContentDirectory(CGUpnpAction *browseAction, int indent, NSString *objectId)
{
int n;
[browseAction setArgumentValue:objectId forName:@"ObjectID"];
[browseAction setArgumentValue:@"BrowseDirectChildren" forName:@"BrowseFlag"];
[browseAction setArgumentValue:@"*" forName:@"Filter"];
[browseAction setArgumentValue:@"0" forName:@"StartingIndex"];
[browseAction setArgumentValue:@"0" forName:@"RequestedCount"];
[browseAction setArgumentValue:@"" forName:@"SortCriteria"];
if (![browseAction post])
return;
NSMutableString *indentStr = [NSMutableString string];
for (n=0; n<indent; n++)
[indentStr appendString:@" "];
NSString *resultStr = [browseAction argumentValueForName:@"Result"];
NSLog(@"%@", resultStr);
NSArray* array = [CGUpnpAvObject arrayWithXMLString:resultStr];
for (CGUpnpAvObject* avObj in array) {
NSLog(@"####%@", avObj.title);
}
}
#endif
void PrintDmsInfo(CGUpnpDevice *dev, int dmsNum)
{
NSLog(@"[%d] %@", dmsNum, [dev friendlyName]);
CGUpnpService *conDirService = [dev getServiceForType:@"urn:schemas-upnp-org:service:ContentDirectory:1"];
if (!conDirService)
return;
CGUpnpStateVariable *searchCap = [conDirService getStateVariableForName:@"SearchCapabilities"];
if (searchCap) {
if ([searchCap query])
NSLog(@" SearchCapabilities = %@\n", [searchCap value]);
}
CGUpnpStateVariable *sorpCap = [conDirService getStateVariableForName:@"SortCapabilities"];
if (sorpCap) {
if ([sorpCap query])
NSLog(@" SortCapabilities = %@\n", [sorpCap value]);
}
CGUpnpAction *browseAction = [conDirService getActionForName:@"Browse"];
if (!browseAction)
return;
//PrintContentDirectory(browseAction, 0, @"0");
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = NSLocalizedString(@"DLNA Server", @"Master");
}
return self;
}
- (void)dealloc
{
[self.avController stop];
[_avController release];
[_detailViewController release];
self.avController = nil;
[super dealloc];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
CGUpnpAvController* avCtrl = [[CGUpnpAvController alloc] init];
avCtrl.delegate = self;
[avCtrl search];
self.avController = avCtrl;
[avCtrl release];
UIBarButtonItem* leftButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(leftButtonDidPush)];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
#pragma mark -
- (void)leftButtonDidPush
{
RendererTableViewController* viewController = [[RendererTableViewController alloc] initWithAvController:self.avController];
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];
}
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataSource count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
#if 0
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure the cell.
//cell.textLabel.text = NSLocalizedString(@"Detail", @"Detail");
CGUpnpDevice *dev = [self.dataSource objectAtIndex:indexPath.row];
cell.textLabel.text = [dev friendlyName];
cell.detailTextLabel.text = [dev ipaddress];
return cell;
#else
//NSLog(@"numberOfRowsInSection = %@", indexPath);
static NSString *CELLID = @"upnprootobj";
UPnPDeviceTableViewCell *cell = (UPnPDeviceTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CELLID];
if (cell == nil) {
cell = [[[UPnPDeviceTableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CELLID] autorelease];
}
int row = [indexPath indexAtPosition:1];
if (row < [self.dataSource count]) {
CGUpnpDevice *device = [self.dataSource objectAtIndex:row];
/*
UIImage *icon = [UIImage imageWithContentsOfFile:imagePath];
cell.image = icon;
*/
[cell setDevice:device];
//[cell setText:[server friendlyName]];
//[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
}
return cell;
#endif
}
/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the specified item to be editable.
return YES;
}
*/
/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source.
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
}
}
*/
/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/
/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
// Return NO if you do not want the item to be re-orderable.
return YES;
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//if (!self.detailViewController) {
self.detailViewController = [[[ServerContentViewController alloc] initWithAvServer:[self.dataSource objectAtIndex:indexPath.row] atIndexPath:indexPath objectId:@"0"] autorelease];
//}
//[self.detailViewController setDetailItem:[self.dataSource objectAtIndex:indexPath.row]];
[self.navigationController pushViewController:self.detailViewController animated:YES];
}
#pragma mark -
#pragma mark CGUpnpControlPointDelegate
- (void)controlPoint:(CGUpnpControlPoint *)controlPoint deviceUpdated:(NSString *)deviceUdn {
NSLog(@"%@", deviceUdn);
self.avController = (CGUpnpAvController*)controlPoint;
//self.dataSource = [controlPoint devices];
self.renderers = [((CGUpnpAvController*)controlPoint) renderers];
// NSArray* renderers = [((CGUpnpAvController*)controlPoint) renderers];
// if ([renderers count] > 0) {
// for (CGUpnpAvRenderer* renderer in renderers) {
// NSLog(@"avRendererUDN:%@", [renderer udn]);
// }
// }
self.dataSource = [((CGUpnpAvController*)controlPoint) servers];
int dmsNum = 0;
// for (CGUpnpDevice *dev in [controlPoint devices]) {
// //NSLog(@"%@:%@", [dev friendlyName], [dev ipaddress]);
// if ([dev isDeviceType:@"urn:schemas-upnp-org:device:MediaServer:1"]) {
//// PrintDmsInfo(dev, ++dmsNum);
// //NSLog(@"#Server:%@", [dev deviceType]);
//
// }
// else if([dev isDeviceType:@"urn:schemas-upnp-org:device:MediaRenderer:1"]) {
// NSLog(@"#Renderer%@", [dev deviceType]);
// }
// }
[self.tableView reloadData];
}
- (void)controlPoint:(CGUpnpControlPoint *)controlPoint deviceAdded:(NSString *)deviceUdn
{
NSLog(@"device added udn %@", deviceUdn);
}
- (void)controlPoint:(CGUpnpControlPoint *)controlPoint deviceRemoved:(NSString *)deviceUdn
{
NSLog(@"device removed udn %@", deviceUdn);
self.dataSource = [controlPoint devices];
[self.tableView reloadData];
}
@end