Created RPCServerConfig class with NSCoding implementation

This commit is contained in:
Alexey Chechetkin
2015-06-23 18:55:49 +03:00
parent 21bd201242
commit 61aef7446e
6 changed files with 123 additions and 32 deletions

View File

@@ -12,6 +12,7 @@
2C5810E11B39A5E50069020D /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 2C5810E01B39A5E50069020D /* Images.xcassets */; };
2C5810E41B39A5E50069020D /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2C5810E21B39A5E50069020D /* LaunchScreen.xib */; };
2C5810F01B39A5E50069020D /* TransmissionRPCClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C5810EF1B39A5E50069020D /* TransmissionRPCClientTests.m */; };
2C5810FB1B39A7B20069020D /* RPCServerConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 2C5810FA1B39A7B20069020D /* RPCServerConfig.m */; };
/* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */
@@ -35,6 +36,8 @@
2C5810E91B39A5E50069020D /* TransmissionRPCClientTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = TransmissionRPCClientTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
2C5810EE1B39A5E50069020D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
2C5810EF1B39A5E50069020D /* TransmissionRPCClientTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TransmissionRPCClientTests.m; sourceTree = "<group>"; };
2C5810F91B39A7B20069020D /* RPCServerConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RPCServerConfig.h; sourceTree = "<group>"; };
2C5810FA1B39A7B20069020D /* RPCServerConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RPCServerConfig.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -78,8 +81,6 @@
children = (
2C5810DD1B39A5E50069020D /* AppDelegate.h */,
2C5810DE1B39A5E50069020D /* AppDelegate.m */,
2C5810E01B39A5E50069020D /* Images.xcassets */,
2C5810E21B39A5E50069020D /* LaunchScreen.xib */,
2C5810D91B39A5E50069020D /* Supporting Files */,
);
path = TransmissionRPCClient;
@@ -88,8 +89,12 @@
2C5810D91B39A5E50069020D /* Supporting Files */ = {
isa = PBXGroup;
children = (
2C5810E21B39A5E50069020D /* LaunchScreen.xib */,
2C5810E01B39A5E50069020D /* Images.xcassets */,
2C5810DA1B39A5E50069020D /* Info.plist */,
2C5810DB1B39A5E50069020D /* main.m */,
2C5810F91B39A7B20069020D /* RPCServerConfig.h */,
2C5810FA1B39A7B20069020D /* RPCServerConfig.m */,
);
name = "Supporting Files";
sourceTree = "<group>";
@@ -160,6 +165,7 @@
TargetAttributes = {
2C5810D51B39A5E50069020D = {
CreatedOnToolsVersion = 6.3.2;
DevelopmentTeam = 72C28QMYS6;
};
2C5810E81B39A5E50069020D = {
CreatedOnToolsVersion = 6.3.2;
@@ -212,6 +218,7 @@
files = (
2C5810DF1B39A5E50069020D /* AppDelegate.m in Sources */,
2C5810DC1B39A5E50069020D /* main.m in Sources */,
2C5810FB1B39A7B20069020D /* RPCServerConfig.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -331,7 +338,9 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = TransmissionRPCClient/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};
@@ -341,7 +350,9 @@
isa = XCBuildConfiguration;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
INFOPLIST_FILE = TransmissionRPCClient/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_NAME = "$(TARGET_NAME)";
};

View File

@@ -23,26 +23,5 @@
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

View File

@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="6214" systemVersion="14A314h" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7706" systemVersion="14C1514" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="6207"/>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7703"/>
<capability name="Constraints with non-1.0 multipliers" minToolsVersion="5.1"/>
</dependencies>
<objects>
@@ -12,15 +13,15 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text=" Copyright (c) 2015 Alexey Chechetkin. All rights reserved." textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumFontSize="9" translatesAutoresizingMaskIntoConstraints="NO" id="8ie-xW-0ye">
<rect key="frame" x="20" y="439" width="441" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<rect key="frame" x="20" y="448" width="441" height="12"/>
<fontDescription key="fontDescription" type="system" pointSize="10"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="TransmissionRPCClient" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="140" width="441" height="43"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="36"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<label opaque="NO" clipsSubviews="YES" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Transmission RPC Client" textAlignment="center" lineBreakMode="middleTruncation" baselineAdjustment="alignBaselines" minimumFontSize="18" translatesAutoresizingMaskIntoConstraints="NO" id="kId-c2-rCX">
<rect key="frame" x="20" y="147" width="441" height="29"/>
<fontDescription key="fontDescription" type="boldSystem" pointSize="24"/>
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
<nil key="highlightedColor"/>
</label>
</subviews>

View File

@@ -33,6 +33,7 @@
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>

View File

@@ -0,0 +1,28 @@
//
// RPCServerConfig.h
// Holds transmission remote rpc settings
//
#import <Foundation/Foundation.h>
#define RPC_DEFAULT_PORT 8090
#define RPC_DEFAULT_PATH @"/transmission/rpc"
#define RPC_DEFAULT_REFRESH_TIME 5
#define RPC_DEFAULT_REQUEST_TIMEOUT 10
#define RPC_DEFAULT_USE_SSL NO
#define RPC_DEFAULT_NAME @"?"
#define RPC_DEFAULT_HOST @"?"
@interface RPCServerConfig : NSObject <NSCoding>
@property(nonatomic) NSString *name; // common server name
@property(nonatomic) NSString *host; // ip address of domain name of server
@property(nonatomic) int port; // RPC port to connect to (default 8090)
@property(nonatomic) NSString *rpcPath; // rpc path (default /transmission/remote/rpc
@property(nonatomic) NSString *userName; // http basic auth user name
@property(nonatomic) NSString *userPassword; // http basic auth password
@property(nonatomic) BOOL useSSL; // use https
@property(nonatomic) int refreshTime; // refresh time in seconds
@property(nonatomic) int requestTimeout; // request timeout to server in seconds
@end

View File

@@ -0,0 +1,71 @@
//
// RPCServerConfig.m
// Holds transmission remote rpc settings
#import "RPCServerConfig.h"
static NSString *CODER_NAME = @"name";
static NSString *CODER_RPC_PATH = @"path";
static NSString *CODER_USER_NAME = @"username";
static NSString *CODER_USER_PASSWORD = @"pass";
static NSString *CODER_PORT = @"port";
static NSString *CODER_HOST = @"host";
static NSString *CODER_USE_SSL = @"ssl";
static NSString *CODER_REFRESH_TIME = @"time";
static NSString *CODER_REQUEST_TIMEOUT = @"reqtimeout";
@implementation RPCServerConfig
// init with default params
- (instancetype)init
{
self = [super init];
if( self )
{
_name = RPC_DEFAULT_NAME;
_host = RPC_DEFAULT_HOST;
_port = RPC_DEFAULT_PORT;
_useSSL = RPC_DEFAULT_USE_SSL;
_rpcPath = RPC_DEFAULT_PATH;
_refreshTime = RPC_DEFAULT_REFRESH_TIME;
_requestTimeout = RPC_DEFAULT_REQUEST_TIMEOUT;
}
return self;
}
#pragma mark - NSCoding protocol imp
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super init];
if( self )
{
_name = [aDecoder decodeObjectForKey:CODER_NAME];
_rpcPath = [aDecoder decodeObjectForKey:CODER_RPC_PATH];
_userName = [aDecoder decodeObjectForKey:CODER_USER_NAME];
_userPassword = [aDecoder decodeObjectForKey:CODER_USER_PASSWORD];
_port = [aDecoder decodeIntForKey:CODER_PORT];
_host = [aDecoder decodeObjectForKey:CODER_HOST];
_useSSL = [aDecoder decodeBoolForKey:CODER_USE_SSL];
_refreshTime = [aDecoder decodeIntForKey:CODER_REFRESH_TIME];
_requestTimeout = [aDecoder decodeIntForKey:CODER_REQUEST_TIMEOUT];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.name forKey:CODER_NAME];
[coder encodeObject:self.rpcPath forKey:CODER_RPC_PATH];
[coder encodeObject:self.host forKey:CODER_HOST];
[coder encodeObject:self.userName forKey:CODER_USER_NAME];
[coder encodeObject:self.userPassword forKey: CODER_USER_PASSWORD];
[coder encodeInt:self.port forKey:CODER_PORT];
[coder encodeInt:self.refreshTime forKey: CODER_REFRESH_TIME];
[coder encodeInt:self.requestTimeout forKey:CODER_REQUEST_TIMEOUT];
[coder encodeBool:self.useSSL forKey:CODER_USE_SSL];
}
@end