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

initial commit

üst c40c00c1
//
// 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
//
// 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
//
// 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
//
// CommunicationManager.m
// sdremote
//
// Created by Liu Siqi on 6/3/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import "CommunicationManager.h"
@implementation CommunicationManager
@end
//
// 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
//
// Receiver.m
// sdremote
//
// Created by Liu Siqi on 6/3/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import "Receiver.h"
@implementation Receiver
@end
//
// 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
//
// 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
This diff is collapsed.
/* Localized versions of Info.plist keys */
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2519" systemVersion="12A206j" targetRuntime="iOS.CocoaTouch.iPad" propertyAccessControl="none" useAutolayout="YES" initialViewController="2">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1856"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<scene sceneID="4">
<objects>
<viewController id="2" customClass="libreoffice_sdremoteViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5">
<rect key="frame" x="0.0" y="20" width="768" height="1004"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="3" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar" statusBarStyle="blackTranslucent"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination"/>
</simulatedMetricsContainer>
</document>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="2.0" toolsVersion="2519" systemVersion="12A206j" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" initialViewController="2">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="1856"/>
</dependencies>
<scenes>
<!--class Prefix:identifier View Controller-->
<scene sceneID="5">
<objects>
<viewController id="2" customClass="libreoffice_sdremoteViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="3">
<rect key="frame" x="0.0" y="20" width="320" height="460"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="4" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
<simulatedMetricsContainer key="defaultSimulatedMetrics">
<simulatedStatusBarMetrics key="statusBar"/>
<simulatedOrientationMetrics key="orientation"/>
<simulatedScreenMetrics key="destination" type="retina4"/>
</simulatedMetricsContainer>
</document>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>org.libreoffice.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>MainStoryboard_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>MainStoryboard_iPad</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>
//
// Prefix header for all source files of the 'iosremote' target in the 'iosremote' project
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
//
// libreoffice_sdremoteAppDelegate.h
// iosremote
//
// Created by Liu Siqi on 6/4/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface libreoffice_sdremoteAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
//
// libreoffice_sdremoteAppDelegate.m
// iosremote
//
// Created by Liu Siqi on 6/4/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import "libreoffice_sdremoteAppDelegate.h"
@implementation libreoffice_sdremoteAppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
return YES;
}
- (void)applicationWillResignActive:(UIApplication *)application
{
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
@end
//
// libreoffice_sdremoteViewController.h
// iosremote
//
// Created by Liu Siqi on 6/4/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface libreoffice_sdremoteViewController : UIViewController
@end
//
// libreoffice_sdremoteViewController.m
// iosremote
//
// Created by Liu Siqi on 6/4/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import "libreoffice_sdremoteViewController.h"
@interface libreoffice_sdremoteViewController ()
@end
@implementation libreoffice_sdremoteViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
//
// main.m
// iosremote
//
// Created by Liu Siqi on 6/4/13.
// Copyright (c) 2013 libreoffice. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "libreoffice_sdremoteAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([libreoffice_sdremoteAppDelegate class]));
}
}
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