Kaydet (Commit) f635e786 authored tarafından siqi's avatar siqi

comManager works now

üst b202d328
...@@ -96,6 +96,11 @@ ...@@ -96,6 +96,11 @@
[self.outputStream setDelegate:self]; [self.outputStream setDelegate:self];
[self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [self.outputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.outputStream open]; [self.outputStream open];
NSArray *temp = [[NSArray alloc]initWithObjects:@"LO_SERVER_CLIENT_PAIR\n", self.name, @"\n", self.pin, @"\n\n", nil];
NSString *command = [temp componentsJoinedByString:@""];
[self sendCommand:command];
} }
} }
...@@ -114,18 +119,15 @@ int count = 0; ...@@ -114,18 +119,15 @@ int count = 0;
switch(eventCode) { switch(eventCode) {
case NSStreamEventOpenCompleted:{ case NSStreamEventOpenCompleted:{
NSLog(@"Connection established"); NSLog(@"Connection established");
self.connected = YES;
if (count == 1) { if (count == 1) {
[[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.connected" object:nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.connected" object:nil];
} else { } else {
count++; count++;
} }
} }
break; break;
case NSStreamEventErrorOccurred:{ case NSStreamEventErrorOccurred:{
NSLog(@"Connection error occured"); NSLog(@"Connection error occured");
[self disconnect];
[[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.disconnected" object:nil]; [[NSNotificationCenter defaultCenter]postNotificationName:@"connection.status.disconnected" object:nil];
} }
break; break;
...@@ -153,7 +155,6 @@ int count = 0; ...@@ -153,7 +155,6 @@ int count = 0;
} }
NSArray *commands = [str componentsSeparatedByString:@"\n"]; NSArray *commands = [str componentsSeparatedByString:@"\n"];
[self.receiver parse:commands]; [self.receiver parse:commands];
data = nil; data = nil;
str = nil; str = nil;
......
...@@ -25,10 +25,6 @@ ...@@ -25,10 +25,6 @@
self = [self init]; self = [self init];
self.client = client; self.client = client;
NSArray *temp = [[NSArray alloc]initWithObjects:@"LO_SERVER_CLIENT_PAIR\n", self.client.name, @"\n", self.client.pin, @"\n\n", nil];
NSString *command = [temp componentsJoinedByString:@""];
[self.client sendCommand:command];
return self; return self;
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
@class Client; @class Client;
@class Server; @class Server;
@class CommandInterpreter; @class CommandInterpreter;
@class SlideShow;
#define MSG_SLIDESHOW_STARTED @"SLIDESHOW_STARTED" #define MSG_SLIDESHOW_STARTED @"SLIDESHOW_STARTED"
#define MSG_SLIDE_CHANGED @"SLIDE_CHANGED" #define MSG_SLIDE_CHANGED @"SLIDE_CHANGED"
...@@ -55,5 +56,6 @@ enum ConnectionState : NSInteger { ...@@ -55,5 +56,6 @@ enum ConnectionState : NSInteger {
@property ConnectionState state; @property ConnectionState state;
@property (nonatomic, strong) id delegate; @property (nonatomic, strong) id delegate;
@property (nonatomic, strong) CommandInterpreter* interpreter;
@end @end
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "CommunicationManager.h" #import "CommunicationManager.h"
#import "Client.h" #import "Client.h"
#import "Server.h" #import "Server.h"
#import "SlideShow.h"
#import "CommandTransmitter.h" #import "CommandTransmitter.h"
#import "CommandInterpreter.h" #import "CommandInterpreter.h"
#import "libreoffice_sdremoteViewController.h" #import "libreoffice_sdremoteViewController.h"
...@@ -18,7 +19,6 @@ ...@@ -18,7 +19,6 @@
@interface CommunicationManager() @interface CommunicationManager()
@property (nonatomic, strong) Client* client; @property (nonatomic, strong) Client* client;
@property (nonatomic, strong) CommandInterpreter* interpreter;
@property (nonatomic, strong) CommandTransmitter* transmitter; @property (nonatomic, strong) CommandTransmitter* transmitter;
@property (atomic, strong) NSMutableSet* servers; @property (atomic, strong) NSMutableSet* servers;
@property (nonatomic, strong) id connectionConnectedObserver; @property (nonatomic, strong) id connectionConnectedObserver;
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
{ {
self = [super init]; self = [super init];
self.state = DISCONNECTED; self.state = DISCONNECTED;
self.interpreter = [[CommandInterpreter alloc] init];
[[NSNotificationCenter defaultCenter]addObserver: self [[NSNotificationCenter defaultCenter]addObserver: self
selector: @selector(connectionStatusHandler:) selector: @selector(connectionStatusHandler:)
...@@ -120,6 +121,7 @@ ...@@ -120,6 +121,7 @@
[self.client disconnect]; [self.client disconnect];
// initialise it with a given server // initialise it with a given server
self.client = [[Client alloc]initWithServer:server managedBy:self interpretedBy:self.interpreter]; self.client = [[Client alloc]initWithServer:server managedBy:self interpretedBy:self.interpreter];
self.transmitter = [[CommandTransmitter alloc] initWithClient:self.client];
[self.client connect]; [self.client connect];
} }
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
@property uint size; @property uint size;
@property uint currentSlide; @property uint currentSlide;
@property (nonatomic, weak) id delegate; @property (nonatomic, strong) id delegate;
- (void) putImage: (NSString *)img AtIndex: (uint) index; - (void) putImage: (NSString *)img AtIndex: (uint) index;
- (void) putNotes: (NSString *)notes AtIndex: (uint) index; - (void) putNotes: (NSString *)notes AtIndex: (uint) index;
......
...@@ -37,14 +37,12 @@ ...@@ -37,14 +37,12 @@
NSData* data = [NSData dataWithBase64String:img]; NSData* data = [NSData dataWithBase64String:img];
UIImage* image = [UIImage imageWithData:data]; UIImage* image = [UIImage imageWithData:data];
[self.imagesArray insertObject:image atIndex:index]; [self.imagesArray insertObject:image atIndex:index];
slideShowViewController* vc = [self delegate]; [[NSNotificationCenter defaultCenter] postNotificationName:@"IMAGE_READY" object:nil];
[[vc image] setImage:image];
} }
- (void) putNotes: (NSString *)notes AtIndex: (uint) index{ - (void) putNotes: (NSString *)notes AtIndex: (uint) index{
[self.notesArray insertObject:notes atIndex:index]; [self.notesArray insertObject:notes atIndex:index];
slideShowViewController* vc = [self delegate]; [[NSNotificationCenter defaultCenter] postNotificationName:@"NOTE_READY" object:nil];
[[vc lecturer_notes] loadHTMLString:notes baseURL:nil];
} }
- (UIImage *) getImageAtIndex: (uint) index - (UIImage *) getImageAtIndex: (uint) index
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<rect key="frame" x="0.0" y="64" width="768" height="960"/> <rect key="frame" x="0.0" y="64" width="768" height="960"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews> <subviews>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="192.168.40.101" borderStyle="roundedRect" minimumFontSize="17" id="9w1-Ym-HcF"> <textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" text="192.168.0.22" borderStyle="roundedRect" minimumFontSize="17" id="9w1-Ym-HcF">
<rect key="frame" x="234" y="402" width="301" height="30"/> <rect key="frame" x="234" y="402" width="301" height="30"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/> <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/> <fontDescription key="fontDescription" type="system" pointSize="14"/>
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "Server.h" #import "Server.h"
#import "slideShowViewController.h" #import "slideShowViewController.h"
#import "CommunicationManager.h" #import "CommunicationManager.h"
#import "CommandInterpreter.h"
@interface libreoffice_sdremoteViewController () @interface libreoffice_sdremoteViewController ()
...@@ -46,6 +47,7 @@ ...@@ -46,6 +47,7 @@
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"slidesPreviewSegue"]) { if ([segue.identifier isEqualToString:@"slidesPreviewSegue"]) {
slideShowViewController *destViewController = segue.destinationViewController; slideShowViewController *destViewController = segue.destinationViewController;
destViewController.slideshow = [self.comManager.interpreter slideShow];
[destViewController.slideshow setDelegate:destViewController]; [destViewController.slideshow setDelegate:destViewController];
} }
} }
......
...@@ -32,20 +32,22 @@ ...@@ -32,20 +32,22 @@
{ {
[super viewDidLoad]; [super viewDidLoad];
// NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
// NSOperationQueue *mainQueue = [NSOperationQueue mainQueue]; NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];
// [self.image setImage:[self.slideshow getImageAtIndex:0]]; // [self.image setImage:[self.slideshow getImageAtIndex:0]];
// [self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil]; // [self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil];
// self.slideShowImageReadyObserver = [center addObserverForName:@"IMAGE_READY" object:nil self.slideShowImageReadyObserver = [center addObserverForName:@"IMAGE_READY" object:nil
// queue:mainQueue usingBlock:^(NSNotification *note) { queue:mainQueue usingBlock:^(NSNotification *note) {
// NSLog(@"Getting image to display: %@", [self.slideshow getImageAtIndex:0]); if ([self.slideshow size] == 0)
// [self.image setImage:[self.slideshow getImageAtIndex:0]]; NSLog(@"Oups");
// }]; NSLog(@"Getting image to display: %@", [self.slideshow getImageAtIndex:0]);
// self.slideShowNoteReadyObserver = [center addObserverForName:@"NOTE_READY" object:nil [self.image setImage:[self.slideshow getImageAtIndex:0]];
// queue:mainQueue usingBlock:^(NSNotification *note) { }];
// NSLog(@"Getting note to display: %@", [self.slideshow getNotesAtIndex:0]); self.slideShowNoteReadyObserver = [center addObserverForName:@"NOTE_READY" object:nil
// [self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil]; queue:mainQueue usingBlock:^(NSNotification *note) {
// }] NSLog(@"Getting note to display: %@", [self.slideshow getNotesAtIndex:0]);
[self.lecturer_notes loadHTMLString: [self.slideshow getNotesAtIndex:0]baseURL:nil];
}];
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment