2015-01-31 20:10:14 -05:00
|
|
|
//
|
|
|
|
|
// AppManager.m
|
2015-05-12 21:48:30 -04:00
|
|
|
// Moonlight
|
2015-01-31 20:10:14 -05:00
|
|
|
//
|
|
|
|
|
// Created by Diego Waxemberg on 10/25/14.
|
2015-05-12 21:48:30 -04:00
|
|
|
// Copyright (c) 2014 Moonlight Stream. All rights reserved.
|
2015-01-31 20:10:14 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "AppAssetManager.h"
|
|
|
|
|
#import "CryptoManager.h"
|
|
|
|
|
#import "Utils.h"
|
|
|
|
|
#import "HttpResponse.h"
|
|
|
|
|
#import "AppAssetRetriever.h"
|
|
|
|
|
|
|
|
|
|
@implementation AppAssetManager {
|
|
|
|
|
NSOperationQueue* _opQueue;
|
|
|
|
|
id<AppAssetCallback> _callback;
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-28 23:37:55 -07:00
|
|
|
static const int MAX_REQUEST_COUNT = 4;
|
|
|
|
|
|
2015-01-31 20:10:14 -05:00
|
|
|
- (id) initWithCallback:(id<AppAssetCallback>)callback {
|
|
|
|
|
self = [super init];
|
|
|
|
|
_callback = callback;
|
2015-05-28 23:37:55 -07:00
|
|
|
_opQueue = [[NSOperationQueue alloc] init];
|
|
|
|
|
[_opQueue setMaxConcurrentOperationCount:MAX_REQUEST_COUNT];
|
2015-07-10 21:22:57 -07:00
|
|
|
|
2015-01-31 20:10:14 -05:00
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-01 20:31:24 -08:00
|
|
|
- (void) retrieveAssetsFromHost:(TemporaryHost*)host {
|
|
|
|
|
for (TemporaryApp* app in host.appList) {
|
2015-07-10 21:22:57 -07:00
|
|
|
if (app.image == nil) {
|
|
|
|
|
AppAssetRetriever* retriever = [[AppAssetRetriever alloc] init];
|
|
|
|
|
retriever.app = app;
|
|
|
|
|
retriever.host = host;
|
|
|
|
|
retriever.callback = _callback;
|
|
|
|
|
|
|
|
|
|
[_opQueue addOperation:retriever];
|
|
|
|
|
}
|
2015-01-31 20:10:14 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (void) stopRetrieving {
|
|
|
|
|
[_opQueue cancelAllOperations];
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-01 20:31:24 -08:00
|
|
|
- (void) sendCallBackForApp:(TemporaryApp*)app {
|
2015-01-31 20:10:14 -05:00
|
|
|
[_callback receivedAssetForApp:app];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|