summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorsiqi <me@siqi.fr>2013-06-04 13:47:12 +0200
committersiqi <me@siqi.fr>2013-06-04 13:49:13 +0200
commit88f13ea2173bd203cfa0f97f0bef890dcc3f6262 (patch)
tree6f63da3007e90c798eaf8485c70c0c0319e7e1a9 /ios
parent85be4cc4cd33bbc0e9a0d9fe1c362000c972dbdd (diff)
communication files
Diffstat (limited to 'ios')
-rw-r--r--ios/iosremote/iosremote/Communication/.DS_Storebin0 -> 6148 bytes
-rw-r--r--ios/iosremote/iosremote/Communication/Client.h24
-rw-r--r--ios/iosremote/iosremote/Communication/Client.m139
-rw-r--r--ios/iosremote/iosremote/Communication/CommunicationManager.h13
-rw-r--r--ios/iosremote/iosremote/Communication/CommunicationManager.m13
-rw-r--r--ios/iosremote/iosremote/Communication/Receiver.h13
-rw-r--r--ios/iosremote/iosremote/Communication/Receiver.m13
-rw-r--r--ios/iosremote/iosremote/Communication/Server.h23
-rw-r--r--ios/iosremote/iosremote/Communication/Server.m36
9 files changed, 274 insertions, 0 deletions
diff --git a/ios/iosremote/iosremote/Communication/.DS_Store b/ios/iosremote/iosremote/Communication/.DS_Store
new file mode 100644
index 000000000000..bbb5276d7d0d
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/.DS_Store
Binary files differ
diff --git a/ios/iosremote/iosremote/Communication/Client.h b/ios/iosremote/iosremote/Communication/Client.h
new file mode 100644
index 000000000000..3827b2f33a8a
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Client.h
@@ -0,0 +1,24 @@
+//
+// Client.h
+//
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "Server.h"
+#import "CommunicationManager.h"
+#import "Receiver.h"
+
+@interface Client : NSObject
+
+-(void) connect;
+
+- (id) initWithServer:(Server*)server
+ managedBy:(CommunicationManager*)manager
+ interpretedBy:(Receiver*)receiver;
+
+-(void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode;
+
+@end \ No newline at end of file
diff --git a/ios/iosremote/iosremote/Communication/Client.m b/ios/iosremote/iosremote/Communication/Client.m
new file mode 100644
index 000000000000..b90c9d983a47
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Client.m
@@ -0,0 +1,139 @@
+//
+// Client.m
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import "Client.h"
+#import "Server.h"
+#import "Receiver.h"
+#import "CommunicationManager.h"
+
+@interface Client() <NSStreamDelegate>
+
+@property (nonatomic, strong) NSInputStream* mInputStream;
+@property (nonatomic, strong) NSOutputStream* mOutputStream;
+
+@property (nonatomic, strong) NSString* mPin;
+@property (nonatomic, strong) NSString* mName;
+@property uint mPort;
+
+@property (nonatomic, weak) Server* mServer;
+@property (nonatomic, weak) Receiver* mReceiver;
+@property (nonatomic, weak) CommunicationManager* mComManager;
+
+@property (nonatomic, retain) NSMutableData* mData;
+
+@property BOOL mReady;
+
+@end
+
+
+
+@implementation Client
+
+@synthesize mInputStream = _mInputStream;
+@synthesize mOutputStream = _mOutputStream;
+@synthesize mPin = _mPin;
+@synthesize mName = _mName;
+@synthesize mServer = _mServer;
+@synthesize mComManager = _mComManager;
+@synthesize mData = _mData;
+@synthesize mReady = _mReady;
+
+NSString * const CHARSET = @"UTF-8";
+
+- (id) initWithServer:(Server*)server
+ managedBy:(CommunicationManager*)manager
+ interpretedBy:(Receiver*)receiver
+{
+ self.mPin = @"";
+ self.mName = server.serverName;
+ self.mComManager = manager;
+ self.mReceiver = receiver;
+ // hardcoded here to test the communication TODO
+ self.mPort = 1599;
+
+ return self;
+}
+
+- (void)streamOpenWithIp:(NSString *)ip withPortNumber:(uint)portNumber
+{
+ NSLog(@"Connecting to %@:%u", ip, portNumber);
+ CFReadStreamRef readStream;
+ CFWriteStreamRef writeStream;
+ CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, (__bridge CFStringRef)ip, portNumber, &readStream, &writeStream);
+
+ if(readStream && writeStream)
+ {
+ CFReadStreamSetProperty(readStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+ CFWriteStreamSetProperty(writeStream, kCFStreamPropertyShouldCloseNativeSocket, kCFBooleanTrue);
+
+ //Setup mInputStream
+ self.mInputStream = (__bridge NSInputStream *)readStream;
+ [self.mInputStream setDelegate:self];
+ [self.mInputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ [self.mInputStream open];
+
+ //Setup outputstream
+ self.mOutputStream = (__bridge NSOutputStream *)writeStream;
+ [self.mOutputStream setDelegate:self];
+ [self.mOutputStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
+ [self.mOutputStream open];
+ }
+ NSLog(@"Connected");
+}
+
+- (void) sendCommand:(NSString *)aCommand
+{
+ // UTF-8 as speficied in specification
+ NSData * data = [aCommand dataUsingEncoding:NSUTF8StringEncoding];
+
+ [self.mOutputStream write:(uint8_t *)[data bytes] maxLength:[data length]];
+}
+
+- (void)stream:(NSStream *)stream handleEvent:(NSStreamEvent)eventCode {
+
+ switch(eventCode) {
+ case NSStreamEventHasBytesAvailable:
+ {
+ if(!self.mData) {
+ self.mData = [NSMutableData data];
+ }
+ uint8_t buf[1024];
+ unsigned int len = 0;
+ len = [(NSInputStream *)stream read:buf maxLength:1024];
+ if(len) {
+ [self.mData appendBytes:(const void *)buf length:len];
+ int bytesRead = 0;
+ // bytesRead is an instance variable of type NSNumber.
+ bytesRead += len;
+ } else {
+ NSLog(@"No data but received event for whatever reasons!");
+ }
+
+ NSString *str = [[NSString alloc] initWithData:self.mData
+ encoding:NSUTF8StringEncoding];
+ NSLog(@"Data Received: %@", str);
+
+ self.mData = nil;
+ } break;
+ default:
+ {
+
+ }
+
+ }
+}
+
+
+- (void) connect
+{
+ [self streamOpenWithIp:self.mServer.serverAddress withPortNumber:self.mPort];
+}
+
+
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.h b/ios/iosremote/iosremote/Communication/CommunicationManager.h
new file mode 100644
index 000000000000..d649e3c55beb
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.h
@@ -0,0 +1,13 @@
+//
+// CommunicationManager.h
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface CommunicationManager : NSObject
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/CommunicationManager.m b/ios/iosremote/iosremote/Communication/CommunicationManager.m
new file mode 100644
index 000000000000..c91b2f5e2ae6
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/CommunicationManager.m
@@ -0,0 +1,13 @@
+//
+// CommunicationManager.m
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import "CommunicationManager.h"
+
+@implementation CommunicationManager
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/Receiver.h b/ios/iosremote/iosremote/Communication/Receiver.h
new file mode 100644
index 000000000000..9889ec749577
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Receiver.h
@@ -0,0 +1,13 @@
+//
+// Receiver.h
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface Receiver : NSObject
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/Receiver.m b/ios/iosremote/iosremote/Communication/Receiver.m
new file mode 100644
index 000000000000..30a48c675d68
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Receiver.m
@@ -0,0 +1,13 @@
+//
+// Receiver.m
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import "Receiver.h"
+
+@implementation Receiver
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/Server.h b/ios/iosremote/iosremote/Communication/Server.h
new file mode 100644
index 000000000000..1cf483dd64b0
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Server.h
@@ -0,0 +1,23 @@
+//
+// Server.h
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+typedef enum protocol {NETWORK} Protocol_t;
+
+@interface Server : NSObject
+
+@property (nonatomic) Protocol_t protocol;
+@property (nonatomic, strong) NSString* serverName;
+@property (nonatomic, strong) NSString* serverAddress;
+
+- (id)initWithProtocol:(Protocol_t)protocal
+ atAddress:(NSString*) address
+ ofName:(NSString*) name;
+
+@end
diff --git a/ios/iosremote/iosremote/Communication/Server.m b/ios/iosremote/iosremote/Communication/Server.m
new file mode 100644
index 000000000000..d7bf1adcf00c
--- /dev/null
+++ b/ios/iosremote/iosremote/Communication/Server.m
@@ -0,0 +1,36 @@
+//
+// Server.m
+// sdremote
+//
+// Created by Liu Siqi on 6/3/13.
+// Copyright (c) 2013 libreoffice. All rights reserved.
+//
+
+#import "Server.h"
+
+@interface Server()
+
+@end
+
+@implementation Server
+
+@synthesize protocol = _protocol;
+@synthesize serverName = _serverName;
+@synthesize serverAddress = _serverAddress;
+
+- (id)initWithProtocol:(Protocol_t)protocal
+ atAddress:(NSString*) address
+ ofName:(NSString*) name
+{
+ self = [self init];
+ self.protocol = protocal;
+ self.serverAddress = address;
+ self.serverName = name;
+ return self;
+}
+
+- (NSString *)description{
+ return [NSString stringWithFormat:@"Server: Name:%@ Addr:%@", self.serverName, self.serverAddress];
+}
+
+@end