mirror of
https://github.com/moonlight-stream/moonlight-qt.git
synced 2026-06-17 14:11:33 +00:00
Stop using CoreData-backed objects in any non-DataManager code
This commit is contained in:
@@ -7,20 +7,20 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "App.h"
|
||||
#import "TemporaryApp.h"
|
||||
#import "HttpManager.h"
|
||||
#import "Host.h"
|
||||
#import "TemporaryHost.h"
|
||||
|
||||
@protocol AppAssetCallback <NSObject>
|
||||
|
||||
- (void) receivedAssetForApp:(App*)app;
|
||||
- (void) receivedAssetForApp:(TemporaryApp*)app;
|
||||
|
||||
@end
|
||||
|
||||
@interface AppAssetManager : NSObject
|
||||
|
||||
- (id) initWithCallback:(id<AppAssetCallback>)callback;
|
||||
- (void) retrieveAssetsFromHost:(Host*)host;
|
||||
- (void) retrieveAssetsFromHost:(TemporaryHost*)host;
|
||||
- (void) stopRetrieving;
|
||||
|
||||
@end
|
||||
|
||||
@@ -28,8 +28,8 @@ static const int MAX_REQUEST_COUNT = 4;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) retrieveAssetsFromHost:(Host*)host {
|
||||
for (App* app in host.appList) {
|
||||
- (void) retrieveAssetsFromHost:(TemporaryHost*)host {
|
||||
for (TemporaryApp* app in host.appList) {
|
||||
if (app.image == nil) {
|
||||
AppAssetRetriever* retriever = [[AppAssetRetriever alloc] init];
|
||||
retriever.app = app;
|
||||
@@ -45,7 +45,7 @@ static const int MAX_REQUEST_COUNT = 4;
|
||||
[_opQueue cancelAllOperations];
|
||||
}
|
||||
|
||||
- (void) sendCallBackForApp:(App*)app {
|
||||
- (void) sendCallBackForApp:(TemporaryApp*)app {
|
||||
[_callback receivedAssetForApp:app];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,14 +7,14 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Host.h"
|
||||
#import "App.h"
|
||||
#import "TemporaryHost.h"
|
||||
#import "TemporaryApp.h"
|
||||
#import "AppAssetManager.h"
|
||||
|
||||
@interface AppAssetRetriever : NSOperation
|
||||
|
||||
@property (nonatomic) Host* host;
|
||||
@property (nonatomic) App* app;
|
||||
@property (nonatomic) TemporaryHost* host;
|
||||
@property (nonatomic) TemporaryApp* app;
|
||||
@property (nonatomic) id<AppAssetCallback> callback;
|
||||
|
||||
@end
|
||||
|
||||
@@ -36,7 +36,7 @@ static const int MAX_ATTEMPTS = 5;
|
||||
[self performSelectorOnMainThread:@selector(sendCallbackForApp:) withObject:self.app waitUntilDone:NO];
|
||||
}
|
||||
|
||||
- (void) sendCallbackForApp:(App*)app {
|
||||
- (void) sendCallbackForApp:(TemporaryApp*)app {
|
||||
[self.callback receivedAssetForApp:app];
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MDNSManager.h"
|
||||
#import "Host.h"
|
||||
#import "TemporaryHost.h"
|
||||
|
||||
@protocol DiscoveryCallback <NSObject>
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
- (void) startDiscovery;
|
||||
- (void) stopDiscovery;
|
||||
- (void) stopDiscoveryBlocking;
|
||||
- (BOOL) addHostToDiscovery:(Host*)host;
|
||||
- (void) removeHostFromDiscovery:(Host*)host;
|
||||
- (void) discoverHost:(NSString*)hostAddress withCallback:(void (^)(Host*, NSString*))callback;
|
||||
- (BOOL) addHostToDiscovery:(TemporaryHost*)host;
|
||||
- (void) removeHostFromDiscovery:(TemporaryHost*)host;
|
||||
- (void) discoverHost:(NSString*)hostAddress withCallback:(void (^)(TemporaryHost*, NSString*))callback;
|
||||
|
||||
@end
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
|
||||
@implementation DiscoveryManager {
|
||||
NSMutableArray* _hostQueue;
|
||||
NSMutableArray* _discoveredHosts;
|
||||
id<DiscoveryCallback> _callback;
|
||||
MDNSManager* _mdnsMan;
|
||||
NSOperationQueue* _opQueue;
|
||||
@@ -35,7 +34,7 @@
|
||||
shouldDiscover = NO;
|
||||
_hostQueue = [NSMutableArray array];
|
||||
DataManager* dataMan = [[DataManager alloc] init];
|
||||
for (Host* host in hosts)
|
||||
for (TemporaryHost* host in hosts)
|
||||
{
|
||||
if (![self addHostToDiscovery:host])
|
||||
{
|
||||
@@ -54,12 +53,12 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(Host *, NSString*))callback {
|
||||
- (void) discoverHost:(NSString *)hostAddress withCallback:(void (^)(TemporaryHost *, NSString*))callback {
|
||||
HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddress uniqueId:_uniqueId deviceName:deviceName cert:_cert];
|
||||
ServerInfoResponse* serverInfoResponse = [[ServerInfoResponse alloc] init];
|
||||
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:serverInfoResponse withUrlRequest:[hMan newServerInfoRequest] fallbackError:401 fallbackRequest:[hMan newHttpServerInfoRequest]]];
|
||||
|
||||
Host* host = nil;
|
||||
TemporaryHost* host = nil;
|
||||
if ([serverInfoResponse isStatusOk]) {
|
||||
DataManager* dataMan = [[DataManager alloc] init];
|
||||
host = [dataMan createHost];
|
||||
@@ -82,7 +81,7 @@
|
||||
Log(LOG_I, @"Starting discovery");
|
||||
shouldDiscover = YES;
|
||||
[_mdnsMan searchForHosts];
|
||||
for (Host* host in _hostQueue) {
|
||||
for (TemporaryHost* host in _hostQueue) {
|
||||
[_opQueue addOperation:[self createWorkerForHost:host]];
|
||||
}
|
||||
}
|
||||
@@ -103,7 +102,7 @@
|
||||
Log(LOG_I, @"All discovery workers stopped");
|
||||
}
|
||||
|
||||
- (BOOL) addHostToDiscovery:(Host *)host {
|
||||
- (BOOL) addHostToDiscovery:(TemporaryHost *)host {
|
||||
if (host.uuid.length > 0 && ![self isHostInDiscovery:host]) {
|
||||
[_hostQueue addObject:host];
|
||||
if (shouldDiscover) {
|
||||
@@ -114,7 +113,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) removeHostFromDiscovery:(Host *)host {
|
||||
- (void) removeHostFromDiscovery:(TemporaryHost *)host {
|
||||
for (DiscoveryWorker* worker in [_opQueue operations]) {
|
||||
if ([worker getHost] == host) {
|
||||
[worker cancel];
|
||||
@@ -128,7 +127,7 @@
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
DataManager* dataMan = [[DataManager alloc] init];
|
||||
// Discover the hosts before adding to eliminate duplicates
|
||||
for (Host* host in hosts) {
|
||||
for (TemporaryHost* host in hosts) {
|
||||
Log(LOG_I, @"Found host through MDNS: %@:", host.name);
|
||||
// Since this is on a background thread, we do not need to use the opQueue
|
||||
DiscoveryWorker* worker = (DiscoveryWorker*)[self createWorkerForHost:host];
|
||||
@@ -145,9 +144,9 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (BOOL) isHostInDiscovery:(Host*)host {
|
||||
- (BOOL) isHostInDiscovery:(TemporaryHost*)host {
|
||||
for (int i = 0; i < _hostQueue.count; i++) {
|
||||
Host* discoveredHost = [_hostQueue objectAtIndex:i];
|
||||
TemporaryHost* discoveredHost = [_hostQueue objectAtIndex:i];
|
||||
if (discoveredHost.uuid.length > 0 && [discoveredHost.uuid isEqualToString:host.uuid]) {
|
||||
return YES;
|
||||
}
|
||||
@@ -155,7 +154,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (NSOperation*) createWorkerForHost:(Host*)host {
|
||||
- (NSOperation*) createWorkerForHost:(TemporaryHost*)host {
|
||||
DiscoveryWorker* worker = [[DiscoveryWorker alloc] initWithHost:host uniqueId:_uniqueId cert:_cert];
|
||||
return worker;
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Host.h"
|
||||
#import "TemporaryHost.h"
|
||||
|
||||
@interface DiscoveryWorker : NSOperation
|
||||
|
||||
- (id) initWithHost:(Host*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert;
|
||||
- (id) initWithHost:(TemporaryHost*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert;
|
||||
- (void) discoverHost;
|
||||
- (Host*) getHost;
|
||||
- (TemporaryHost*) getHost;
|
||||
|
||||
@end
|
||||
|
||||
@@ -13,14 +13,14 @@
|
||||
#import "HttpRequest.h"
|
||||
|
||||
@implementation DiscoveryWorker {
|
||||
Host* _host;
|
||||
TemporaryHost* _host;
|
||||
NSString* _uniqueId;
|
||||
NSData* _cert;
|
||||
}
|
||||
|
||||
static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
||||
|
||||
- (id) initWithHost:(Host*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert {
|
||||
- (id) initWithHost:(TemporaryHost*)host uniqueId:(NSString*)uniqueId cert:(NSData*)cert {
|
||||
self = [super init];
|
||||
_host = host;
|
||||
_uniqueId = uniqueId;
|
||||
@@ -28,7 +28,7 @@ static const float POLL_RATE = 2.0f; // Poll every 2 seconds
|
||||
return self;
|
||||
}
|
||||
|
||||
- (Host*) getHost {
|
||||
- (TemporaryHost*) getHost {
|
||||
return _host;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Host.h"
|
||||
#import "HttpResponse.h"
|
||||
#import "HttpRequest.h"
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#import "HttpManager.h"
|
||||
#import "HttpRequest.h"
|
||||
#import "CryptoManager.h"
|
||||
#import "App.h"
|
||||
#import "TemporaryApp.h"
|
||||
|
||||
#include <libxml2/libxml/xmlreader.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Host.h"
|
||||
|
||||
static NSString* TAG_STATUS_CODE = @"status_code";
|
||||
static NSString* TAG_STATUS_MESSAGE = @"status_message";
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#import "HttpResponse.h"
|
||||
#import "App.h"
|
||||
#import "TemporaryApp.h"
|
||||
#import <libxml2/libxml/xmlreader.h>
|
||||
|
||||
@implementation HttpResponse {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#import "MDNSManager.h"
|
||||
#import "Host.h"
|
||||
#import "TemporaryHost.h"
|
||||
#import "DataManager.h"
|
||||
|
||||
@implementation MDNSManager {
|
||||
@@ -50,7 +50,7 @@ static NSString* NV_SERVICE_TYPE = @"_nvstream._tcp";
|
||||
DataManager* dataMan = [[DataManager alloc] init];
|
||||
for (NSNetService* service in services) {
|
||||
if (service.hostName != nil) {
|
||||
Host* host = [dataMan createHost];
|
||||
TemporaryHost* host = [dataMan createHost];
|
||||
host.activeAddress = host.address = service.hostName;
|
||||
host.name = host.address;
|
||||
[hosts addObject:host];
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "HttpResponse.h"
|
||||
#import "TemporaryHost.h"
|
||||
|
||||
#define TAG_HOSTNAME @"hostname"
|
||||
#define TAG_EXTERNAL_IP @"ExternalIP"
|
||||
@@ -18,7 +19,7 @@
|
||||
@interface ServerInfoResponse : HttpResponse <Response>
|
||||
|
||||
- (void) populateWithData:(NSData *)data;
|
||||
- (void) populateHost:(Host*)host;
|
||||
- (void) populateHost:(TemporaryHost*)host;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
[super parseData];
|
||||
}
|
||||
|
||||
- (void) populateHost:(Host*)host {
|
||||
- (void) populateHost:(TemporaryHost*)host {
|
||||
host.name = [[self getStringTag:TAG_HOSTNAME] trim];
|
||||
host.externalAddress = [[self getStringTag:TAG_EXTERNAL_IP] trim];
|
||||
host.localAddress = [[self getStringTag:TAG_LOCAL_IP] trim];
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "Host.h"
|
||||
#import "TemporaryHost.h"
|
||||
|
||||
@interface WakeOnLanManager : NSObject
|
||||
|
||||
+ (void) wakeHost:(Host*)host;
|
||||
+ (void) wakeHost:(TemporaryHost*)host;
|
||||
|
||||
@end
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
static const int numPorts = 5;
|
||||
static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
|
||||
|
||||
+ (void) wakeHost:(Host*)host {
|
||||
+ (void) wakeHost:(TemporaryHost*)host {
|
||||
NSData* wolPayload = [WakeOnLanManager createPayload:host];
|
||||
CFDataRef dataPayload = CFDataCreate(kCFAllocatorDefault, [wolPayload bytes], [wolPayload length]);
|
||||
CFSocketRef wolSocket = CFSocketCreate(kCFAllocatorDefault, PF_INET, SOCK_DGRAM, IPPROTO_UDP, 0, NULL, NULL);
|
||||
@@ -56,7 +56,7 @@ static const int ports[numPorts] = {7, 9, 47998, 47999, 48000};
|
||||
CFRelease(dataPayload);
|
||||
}
|
||||
|
||||
+ (NSData*) createPayload:(Host*)host {
|
||||
+ (NSData*) createPayload:(TemporaryHost*)host {
|
||||
NSMutableData* payload = [[NSMutableData alloc] initWithCapacity:102];
|
||||
|
||||
// 6 bytes of FF
|
||||
|
||||
Reference in New Issue
Block a user