mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-15 15:11:28 +00:00
Merge pull request #2286 from cacaodev/CPURLConnection
CPURLConnection +sendAsynchronousRequest:queue:completionHandler:
This commit is contained in:
+139
-26
@@ -25,6 +25,8 @@
|
||||
@import "CPRunLoop.j"
|
||||
@import "CPURLRequest.j"
|
||||
@import "CPURLResponse.j"
|
||||
@import "CPOperationQueue.j"
|
||||
@import "CPOperation.j"
|
||||
|
||||
@protocol CPURLConnectionDelegate <CPObject>
|
||||
|
||||
@@ -93,6 +95,9 @@ var CPURLConnectionDelegate = nil;
|
||||
BOOL _isLocalFileConnection;
|
||||
|
||||
HTTPRequest _HTTPRequest;
|
||||
|
||||
CPOperationQueue _operationQueue;
|
||||
CPOperation _connectionOperation @accessors(readonly, getter=operation);
|
||||
}
|
||||
|
||||
+ (void)setClassDelegate:(id <CPURLConnectionDelegate>)delegate
|
||||
@@ -137,6 +142,18 @@ var CPURLConnectionDelegate = nil;
|
||||
return nil;
|
||||
}
|
||||
|
||||
/*
|
||||
Loads the data for a URL request and executes a function on an operation queue when the request completes or fails.
|
||||
@param aRequest contains the URL to obtain data from.
|
||||
@param aQueue The operation queue to which the function is dispatched when the request completes or failed.
|
||||
@param aHandler The function to execute.
|
||||
@discussion If the request completes successfully, the data parameter of the function contains the resource data, and the error parameter is nil. If the request fails, the data parameter is nil and the error parameter contain information about the failure.
|
||||
*/
|
||||
+ (CPURLConnection)sendAsynchronousRequest:(CPURLRequest)aRequest queue:(CPOperationQueue)aQueue completionHandler:(Function)aHandler
|
||||
{
|
||||
return [[self alloc] _initWithRequest:aRequest queue:aQueue completionHandler:aHandler];
|
||||
}
|
||||
|
||||
/*
|
||||
Creates a url connection with a delegate to monitor the request progress.
|
||||
@param aRequest contains the URL to obtain data from
|
||||
@@ -161,26 +178,51 @@ var CPURLConnectionDelegate = nil;
|
||||
|
||||
if (self)
|
||||
{
|
||||
_request = aRequest;
|
||||
_originalRequest = [aRequest copy];
|
||||
_delegate = aDelegate;
|
||||
_isCanceled = NO;
|
||||
_operationQueue = nil;
|
||||
_connectionOperation = nil;
|
||||
|
||||
var URL = [_request URL],
|
||||
scheme = [URL scheme];
|
||||
[self _initWithRequest:aRequest];
|
||||
}
|
||||
|
||||
// Browsers use "file:", Titanium uses "app:"
|
||||
_isLocalFileConnection = scheme === "file" ||
|
||||
((scheme === "http" || scheme === "https") &&
|
||||
window.location &&
|
||||
(window.location.protocol === "file:" || window.location.protocol === "app:"));
|
||||
if (shouldStartImmediately)
|
||||
[self start];
|
||||
|
||||
_HTTPRequest = new CFHTTPRequest();
|
||||
_HTTPRequest.setTimeout([aRequest timeoutInterval] * 1000);
|
||||
_HTTPRequest.setWithCredentials([aRequest withCredentials]);
|
||||
return self;
|
||||
}
|
||||
|
||||
if (shouldStartImmediately)
|
||||
[self start];
|
||||
- (void)_initWithRequest:(CPURLRequest)aRequest
|
||||
{
|
||||
_request = aRequest;
|
||||
_originalRequest = [aRequest copy];
|
||||
_isCanceled = NO;
|
||||
|
||||
var URL = [_request URL],
|
||||
scheme = [URL scheme];
|
||||
|
||||
// Browsers use "file:", Titanium uses "app:"
|
||||
_isLocalFileConnection = scheme === "file" ||
|
||||
((scheme === "http" || scheme === "https") &&
|
||||
window.location &&
|
||||
(window.location.protocol === "file:" || window.location.protocol === "app:"));
|
||||
|
||||
_HTTPRequest = new CFHTTPRequest();
|
||||
_HTTPRequest.setTimeout([aRequest timeoutInterval] * 1000);
|
||||
_HTTPRequest.setWithCredentials([aRequest withCredentials]);
|
||||
}
|
||||
|
||||
- (id)_initWithRequest:(CPURLRequest)aRequest queue:(CPOperationQueue)aQueue completionHandler:(Function)aHandler
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_delegate = nil;
|
||||
_operationQueue = aQueue;
|
||||
_connectionOperation = [[_AsynchronousConnectionOperation alloc] initWithFunction:aHandler];
|
||||
|
||||
[self _initWithRequest:aRequest];
|
||||
[self start];
|
||||
}
|
||||
|
||||
return self;
|
||||
@@ -232,6 +274,8 @@ var CPURLConnectionDelegate = nil;
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(connection:didFailWithError:)])
|
||||
[_delegate connection:self didFailWithError:anException];
|
||||
else if (_connectionOperation !== nil)
|
||||
[self _connectionOperationDidReceiveResponse:nil data:nil error:anException];
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -244,6 +288,9 @@ var CPURLConnectionDelegate = nil;
|
||||
try
|
||||
{
|
||||
_HTTPRequest.abort();
|
||||
|
||||
if (_connectionOperation)
|
||||
[_connectionOperation cancel];
|
||||
}
|
||||
// We expect an exception in some browsers like FireFox.
|
||||
catch (anException)
|
||||
@@ -267,7 +314,6 @@ var CPURLConnectionDelegate = nil;
|
||||
|
||||
[self _sendDelegateDidFailWithError:exception];
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
- (void)_readyStateDidChange
|
||||
{
|
||||
@@ -280,23 +326,27 @@ var CPURLConnectionDelegate = nil;
|
||||
[CPURLConnectionDelegate connectionDidReceiveAuthenticationChallenge:self];
|
||||
else
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(connection:didReceiveResponse:)])
|
||||
var response;
|
||||
|
||||
if (_isLocalFileConnection)
|
||||
response = [[CPURLResponse alloc] initWithURL:URL];
|
||||
else
|
||||
{
|
||||
if (_isLocalFileConnection)
|
||||
[_delegate connection:self didReceiveResponse:[[CPURLResponse alloc] initWithURL:URL]];
|
||||
else
|
||||
{
|
||||
var response = [[CPHTTPURLResponse alloc] initWithURL:URL];
|
||||
[response _setStatusCode:statusCode];
|
||||
[response _setAllResponseHeaders:_HTTPRequest.getAllResponseHeaders()];
|
||||
[_delegate connection:self didReceiveResponse:response];
|
||||
}
|
||||
response = [[CPHTTPURLResponse alloc] initWithURL:URL];
|
||||
[response _setStatusCode:statusCode];
|
||||
[response _setAllResponseHeaders:_HTTPRequest.getAllResponseHeaders()];
|
||||
}
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(connection:didReceiveResponse:)])
|
||||
[_delegate connection:self didReceiveResponse:response];
|
||||
|
||||
if (!_isCanceled)
|
||||
{
|
||||
if ([_delegate respondsToSelector:@selector(connection:didReceiveData:)])
|
||||
[_delegate connection:self didReceiveData:_HTTPRequest.responseText()];
|
||||
else if (_connectionOperation !== nil)
|
||||
[self _connectionOperationDidReceiveResponse:response data:_HTTPRequest.responseText() error:nil];
|
||||
|
||||
if ([_delegate respondsToSelector:@selector(connectionDidFinishLoading:)])
|
||||
[_delegate connectionDidFinishLoading:self];
|
||||
}
|
||||
@@ -312,6 +362,69 @@ var CPURLConnectionDelegate = nil;
|
||||
return _HTTPRequest;
|
||||
}
|
||||
|
||||
- (void)_connectionOperationDidReceiveResponse:(CPURLResponse)aResponse data:(CPData)aData error:(CPError)anError
|
||||
{
|
||||
[_connectionOperation _setResponse:aResponse data:aData error:anError];
|
||||
|
||||
if (_operationQueue)
|
||||
[_operationQueue addOperation:_connectionOperation];
|
||||
else
|
||||
{
|
||||
// Do we need to send CPOperation KVO notifications ?
|
||||
[_connectionOperation main];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/* @ignore */
|
||||
@implementation _AsynchronousConnectionOperation : CPOperation
|
||||
{
|
||||
BOOL _didReceiveResponse;
|
||||
|
||||
CPURLResponse _response;
|
||||
CPData _data;
|
||||
CPError _error;
|
||||
Function _operationFunction;
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
- (id)initWithFunction:(Function)aFunction
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_didReceiveResponse = NO;
|
||||
_response = nil;
|
||||
_data = nil;
|
||||
_error = nil;
|
||||
_operationFunction = aFunction;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)_setResponse:(CPURLResponse)aResponse data:(CPData)aData error:(CPError)anError
|
||||
{
|
||||
_didReceiveResponse = YES;
|
||||
_response = aResponse;
|
||||
_data = aData;
|
||||
_error = anError;
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
- (void)main
|
||||
{
|
||||
_operationFunction(_response, _data, _error);
|
||||
}
|
||||
|
||||
/* @ignore */
|
||||
- (BOOL)isReady
|
||||
{
|
||||
return (_didReceiveResponse && [super isReady]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPURLConnection (Deprecated)
|
||||
|
||||
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* CPURLConnectionAsyncTest
|
||||
*
|
||||
* Created by You on February 1, 2012.
|
||||
* Copyright 2012, Your Company All rights reserved.
|
||||
|
||||
This test needs to be at the root of your Web Server (http://localhost/CPURLConnectionAsyncTest/) and with php enabled.
|
||||
For each test, we start 3 async connections and we setup the resulting operations to be dependant one from each other. The connection received after the smallest delay is dependant on a connection received with a longer delay.
|
||||
We test that dedendant operations are perfomed before their dependencies.
|
||||
We also test that in the completionHandler(response, data, error), the data and error params are mututally exclusive.*/
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
CPLogRegister(CPLogConsole);
|
||||
|
||||
@implementation AppController : CPObject
|
||||
{
|
||||
@outlet CPTextField testField;
|
||||
CPWindow theWindow; //this "outlet" is connected automatically by the Cib
|
||||
CPOperationQueue queue;
|
||||
CPArray results;
|
||||
}
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
// This is called when the application is done loading.
|
||||
}
|
||||
|
||||
- (CPURLConnection)startAsyncConnection:(CPInteger)idx responseStatus:(CPInteger)aStatus delay:(CPInteger)aDelay isLast:(BOOL)isLast
|
||||
{
|
||||
var resourcePath = [[CPBundle mainBundle] resourcePath],
|
||||
url = [CPURL URLWithString:[CPString stringWithFormat:@"%@delayed.php?sleep=%@&status=%@", resourcePath, aDelay, aStatus]];
|
||||
|
||||
var request = [CPURLRequest requestWithURL:url];
|
||||
|
||||
return [self startAsyncConnection:idx request:request isLast:isLast];
|
||||
}
|
||||
|
||||
- (CPURLConnection)startAsyncConnection:(CPInteger)idx request:(CPURLRequest)request isLast:(BOOL)isLast
|
||||
{
|
||||
var connection = [CPURLConnection sendAsynchronousRequest:request queue:queue completionHandler:function (response, data, error)
|
||||
{
|
||||
var status;
|
||||
|
||||
if (error == nil)
|
||||
error = [CPNull null];
|
||||
|
||||
if (data == nil)
|
||||
data = [CPNull null];
|
||||
|
||||
if (response == nil)
|
||||
status = -1;
|
||||
else
|
||||
status = [response statusCode];
|
||||
|
||||
CPLog.debug([request URL] + "\nRESPONSE:" + response + "\nDATA:" + data + "\nERROR:" + [error description]);
|
||||
|
||||
[results addObject:@{"conn_id":idx, "data":data, "status":status, "error":error}];
|
||||
|
||||
// We received all the responses to the connections we launched (3).
|
||||
if ([results count] == 3)
|
||||
{
|
||||
var test = [self testResults];
|
||||
[testField setStringValue:((test) ? "Test passed" : @"Test failed")];
|
||||
}
|
||||
}];
|
||||
|
||||
return connection;
|
||||
}
|
||||
|
||||
- (BOOL)testResults
|
||||
{
|
||||
if ([results count] !== 3)
|
||||
return NO;
|
||||
|
||||
// In theses tests, we send connections 1,2,3 and we expect the operations to be performed in reverse order: 3,2,1 because of the dependencies we set up.
|
||||
if (![[results valueForKey:@"conn_id"] isEqualToArray:@[3,2,1]])
|
||||
return NO;
|
||||
|
||||
var nul = [CPNull null];
|
||||
|
||||
for (var i = 0; i < [results count]; i++)
|
||||
{
|
||||
var res = [results objectAtIndex:i],
|
||||
noData = [res objectForKey:@"data"] == nul,
|
||||
noError = [res objectForKey:@"error"] == nul;
|
||||
|
||||
if (noData == noError)
|
||||
return NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (IBAction)test1:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 responseStatus:200 delay:2 isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 responseStatus:200 delay:3 isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test2:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 responseStatus:404 delay:2 isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 responseStatus:200 delay:3 isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test3:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 responseStatus:200 delay:2 isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 responseStatus:404 delay:3 isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test4:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 responseStatus:403 delay:2 isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 responseStatus:404 delay:3 isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test5:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:404 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 responseStatus:1000 delay:2 isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 responseStatus:404 delay:3 isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test6:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
var request = [CPURLRequest requestWithURL:"dummy"];
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 request:request isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 request:request isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (IBAction)test7:(id)sender
|
||||
{
|
||||
results = @[];
|
||||
queue = [[CPOperationQueue alloc] init];
|
||||
|
||||
var resourcePath = [[CPBundle mainBundle] resourcePath],
|
||||
url = [CPURL URLWithString:[CPString stringWithFormat:@"%@delayed.php?sleep=%@&status=%@", resourcePath, 10, 200]];
|
||||
var timeoutrequest = [CPURLRequest requestWithURL:url cachePolicy:CPURLRequestUseProtocolCachePolicy timeoutInterval:3];
|
||||
|
||||
var nourl = [CPURLRequest requestWithURL:@"nourl"];
|
||||
|
||||
[testField setStringValue:@"Waiting for response ..."];
|
||||
|
||||
var connection1 = [self startAsyncConnection:1 responseStatus:200 delay:1 isLast:YES];
|
||||
var connection2 = [self startAsyncConnection:2 request:nourl isLast:NO];
|
||||
var connection3 = [self startAsyncConnection:3 request:timeoutrequest isLast:NO];
|
||||
|
||||
[[connection1 operation] addDependency:[connection2 operation]];
|
||||
[[connection2 operation] addDependency:[connection3 operation]];
|
||||
}
|
||||
|
||||
- (void)awakeFromCib
|
||||
{
|
||||
// This is called when the cib is done loading.
|
||||
// You can implement this method on any object instantiated from a Cib.
|
||||
// It's a useful hook for setting up current UI values, and other things.
|
||||
|
||||
// In this case, we want the window from Cib to become our full browser window
|
||||
[theWindow setFullPlatformWindow:YES];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,10 @@
|
||||
<?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>Main cib file base name</key>
|
||||
<string>MainMenu.cib</string>
|
||||
<key>CPBundleName</key>
|
||||
<string>CPURLConnectionAsyncTest</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Jakefile
|
||||
* CPURLConnectionAsyncTest
|
||||
*
|
||||
* Created by You on February 1, 2012.
|
||||
* Copyright 2012, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
var ENV = require("system").env,
|
||||
FILE = require("file"),
|
||||
JAKE = require("jake"),
|
||||
task = JAKE.task,
|
||||
FileList = JAKE.FileList,
|
||||
app = require("cappuccino/jake").app,
|
||||
configuration = ENV["CONFIG"] || ENV["CONFIGURATION"] || ENV["c"] || "Debug",
|
||||
OS = require("os");
|
||||
|
||||
app ("CPURLConnectionAsyncTest", function(task)
|
||||
{
|
||||
task.setBuildIntermediatesPath(FILE.join("Build", "CPURLConnectionAsyncTest.build", configuration));
|
||||
task.setBuildPath(FILE.join("Build", configuration));
|
||||
|
||||
task.setProductName("CPURLConnectionAsyncTest");
|
||||
task.setIdentifier("com.yourcompany.CPURLConnectionAsyncTest");
|
||||
task.setVersion("1.0");
|
||||
task.setAuthor("Your Company");
|
||||
task.setEmail("feedback @nospam@ yourcompany.com");
|
||||
task.setSummary("CPURLConnectionAsyncTest");
|
||||
task.setSources((new FileList("**/*.j")).exclude(FILE.join("Build", "**")));
|
||||
task.setResources(new FileList("Resources/**"));
|
||||
task.setIndexFilePath("index.html");
|
||||
task.setInfoPlistPath("Info.plist");
|
||||
task.setNib2CibFlags("-R Resources/");
|
||||
|
||||
if (configuration === "Debug")
|
||||
task.setCompilerFlags("-DDEBUG -g");
|
||||
else
|
||||
task.setCompilerFlags("-O");
|
||||
});
|
||||
|
||||
task ("default", ["CPURLConnectionAsyncTest"], function()
|
||||
{
|
||||
printResults(configuration);
|
||||
});
|
||||
|
||||
task ("build", ["default"]);
|
||||
|
||||
task ("debug", function()
|
||||
{
|
||||
ENV["CONFIGURATION"] = "Debug";
|
||||
JAKE.subjake(["."], "build", ENV);
|
||||
});
|
||||
|
||||
task ("release", function()
|
||||
{
|
||||
ENV["CONFIGURATION"] = "Release";
|
||||
JAKE.subjake(["."], "build", ENV);
|
||||
});
|
||||
|
||||
task ("run", ["debug"], function()
|
||||
{
|
||||
OS.system(["open", FILE.join("Build", "Debug", "CPURLConnectionAsyncTest", "index.html")]);
|
||||
});
|
||||
|
||||
task ("run-release", ["release"], function()
|
||||
{
|
||||
OS.system(["open", FILE.join("Build", "Release", "CPURLConnectionAsyncTest", "index.html")]);
|
||||
});
|
||||
|
||||
task ("deploy", ["release"], function()
|
||||
{
|
||||
FILE.mkdirs(FILE.join("Build", "Deployment", "CPURLConnectionAsyncTest"));
|
||||
OS.system(["press", "-f", FILE.join("Build", "Release", "CPURLConnectionAsyncTest"), FILE.join("Build", "Deployment", "CPURLConnectionAsyncTest")]);
|
||||
printResults("Deployment")
|
||||
});
|
||||
|
||||
task ("desktop", ["release"], function()
|
||||
{
|
||||
FILE.mkdirs(FILE.join("Build", "Desktop", "CPURLConnectionAsyncTest"));
|
||||
require("cappuccino/nativehost").buildNativeHost(FILE.join("Build", "Release", "CPURLConnectionAsyncTest"), FILE.join("Build", "Desktop", "CPURLConnectionAsyncTest", "CPURLConnectionAsyncTest.app"));
|
||||
printResults("Desktop")
|
||||
});
|
||||
|
||||
task ("run-desktop", ["desktop"], function()
|
||||
{
|
||||
OS.system([FILE.join("Build", "Desktop", "CPURLConnectionAsyncTest", "CPURLConnectionAsyncTest.app", "Contents", "MacOS", "NativeHost"), "-i"]);
|
||||
});
|
||||
|
||||
function printResults(configuration)
|
||||
{
|
||||
print("----------------------------");
|
||||
print(configuration+" app built at path: "+FILE.join("Build", configuration, "CPURLConnectionAsyncTest"));
|
||||
print("----------------------------");
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,121 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="8191" systemVersion="14F27" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
|
||||
<dependencies>
|
||||
<deployment version="1050" identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="8191"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
<connections>
|
||||
<outlet property="delegate" destination="450" id="451"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
|
||||
<customObject id="-3" userLabel="Application"/>
|
||||
<window title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" animationBehavior="default" id="371">
|
||||
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
|
||||
<windowPositionMask key="initialPositionMask" leftStrut="YES" bottomStrut="YES"/>
|
||||
<rect key="contentRect" x="335" y="390" width="934" height="466"/>
|
||||
<rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
|
||||
<view key="contentView" id="372">
|
||||
<rect key="frame" x="0.0" y="0.0" width="934" height="466"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<button verticalHuggingPriority="750" id="463">
|
||||
<rect key="frame" x="17" y="418" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 1" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="464">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test1:" target="450" id="476"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="465">
|
||||
<rect key="frame" x="17" y="385" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 2" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="466">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test2:" target="450" id="477"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="467">
|
||||
<rect key="frame" x="17" y="352" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 3" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="468">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test3:" target="450" id="478"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="469">
|
||||
<rect key="frame" x="17" y="319" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 4" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="470">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test4:" target="450" id="479"/>
|
||||
</connections>
|
||||
</button>
|
||||
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" id="471">
|
||||
<rect key="frame" x="134" y="427" width="312" height="17"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" id="472">
|
||||
<font key="font" size="13" name=".HelveticaNeueDeskInterface-Bold"/>
|
||||
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
|
||||
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
|
||||
</textFieldCell>
|
||||
</textField>
|
||||
<button verticalHuggingPriority="750" id="473">
|
||||
<rect key="frame" x="17" y="286" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 5" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="474">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test5:" target="450" id="480"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="481">
|
||||
<rect key="frame" x="17" y="253" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 6" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="482">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test6:" target="450" id="484"/>
|
||||
</connections>
|
||||
</button>
|
||||
<button verticalHuggingPriority="750" id="KwH-Ah-BVw">
|
||||
<rect key="frame" x="17" y="221" width="77" height="32"/>
|
||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||
<buttonCell key="cell" type="push" title="Test 7" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="I77-Tv-gg9">
|
||||
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
|
||||
<font key="font" metaFont="system"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<action selector="test7:" target="450" id="cAo-pW-veR"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
</view>
|
||||
<point key="canvasLocation" x="502" y="325"/>
|
||||
</window>
|
||||
<customObject id="450" customClass="AppController">
|
||||
<connections>
|
||||
<outlet property="testField" destination="471" id="475"/>
|
||||
<outlet property="theWindow" destination="371" id="459"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
</objects>
|
||||
</document>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
date_default_timezone_set('UTC');
|
||||
// current time
|
||||
$in = date("H:i:s:e", time());
|
||||
|
||||
$code = $_GET["status"];
|
||||
http_response_code($code);
|
||||
|
||||
$sleep = $_GET["sleep"];
|
||||
sleep($sleep);
|
||||
|
||||
$out = date("H:i:s:e", time());
|
||||
|
||||
echo json_encode(array($in,$out));
|
||||
|
||||
?>
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,103 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index-debug.html
|
||||
CPURLConnectionAsyncTest
|
||||
|
||||
Created by You on February 1, 2012.
|
||||
Copyright 2012, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>CPURLConnectionAsyncTest</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
OBJJ_INCLUDE_PATHS = ["Frameworks/Debug", "Frameworks", "SomethingElse"];
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="Frameworks/Debug/Objective-J/Objective-J.js" charset="UTF-8"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
objj_msgSend_reset();
|
||||
|
||||
// DEBUG OPTIONS:
|
||||
|
||||
// Uncomment to enable printing of backtraces on exceptions:
|
||||
//objj_msgSend_decorate(objj_backtrace_decorator);
|
||||
|
||||
// Uncomment to supress exceptions that take place inside a message
|
||||
//objj_msgSend_decorate(objj_supress_exceptions_decorator)
|
||||
|
||||
// Uncomment to enable runtime type checking:
|
||||
//objj_msgSend_decorate(objj_typecheck_decorator);
|
||||
|
||||
// Uncomment (along with both above) to print backtraces on type check errors:
|
||||
//objj_typecheck_prints_backtrace = true;
|
||||
|
||||
// Uncomment to disable the default logger (CPLogConsole if window.console exists, CPLogPopup otherwise):
|
||||
//CPLogUnregister(CPLogDefault);
|
||||
|
||||
// Uncomment to enable a specific logger:
|
||||
//CPLogRegister(CPLogConsole);
|
||||
//CPLogRegister(CPLogPopup);
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading CPURLConnectionAsyncTest...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,77 @@
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<!--
|
||||
index.html
|
||||
CPURLConnectionAsyncTest
|
||||
|
||||
Created by You on February 1, 2012.
|
||||
Copyright 2012, Your Company All rights reserved.
|
||||
-->
|
||||
<head>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7, chrome=1" />
|
||||
|
||||
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
|
||||
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
|
||||
|
||||
<link rel="apple-touch-icon" href="Resources/icon.png" />
|
||||
<link rel="apple-touch-startup-image" href="Resources/default.png" />
|
||||
|
||||
<title>CPURLConnectionAsyncTest</title>
|
||||
|
||||
<script type="text/javascript">
|
||||
OBJJ_MAIN_FILE = "main.j";
|
||||
</script>
|
||||
|
||||
<script type="text/javascript" src="Frameworks/Objective-J/Objective-J.js" charset="UTF-8"></script>
|
||||
|
||||
<style type="text/css">
|
||||
body{margin:0; padding:0;}
|
||||
#container {position: absolute; top:50%; left:50%;}
|
||||
#content {width:800px; text-align:center; margin-left: -400px; height:50px; margin-top:-25px; line-height: 50px;}
|
||||
#content {font-family: "Helvetica", "Arial", sans-serif; font-size: 18px; color: black; text-shadow: 0px 1px 0px white; }
|
||||
#loadgraphic {margin-right: 0.2em; margin-bottom:-2px;}
|
||||
</style>
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<STYLE type="text/css">
|
||||
#container { position: relative; top: 50%; }
|
||||
#content { position: relative;}
|
||||
</STYLE>
|
||||
<![endif]-->
|
||||
|
||||
</head>
|
||||
|
||||
<body style="">
|
||||
<div id="cappuccino-body">
|
||||
<div id="loadingcontainer" style="background-color: #eeeeee; overflow:hidden; width:100%; height:100%; position: absolute; top: 0; left: 0;">
|
||||
<script type="text/javascript">
|
||||
document.write("<div id='container'><p id='content'>" +
|
||||
"<img id='loadgraphic' width='16' height='16' src='Resources/spinner.gif' /> " +
|
||||
"Loading CPURLConnectionAsyncTest...</p></div>");
|
||||
</script>
|
||||
|
||||
<noscript>
|
||||
<div id="container">
|
||||
<div style="width: 440px; padding: 10px 25px 20px 25px; font-family: sans-serif; background-color: #ffffff; position: relative; left: -245px; top: -120px; text-align: center; -moz-border-radius: 20px; -webkit-border-radius: 20px; color: #555555">
|
||||
<p style="line-height: 1.4em;">JavaScript is required for this site to work correctly but is either disabled or not supported by your browser.</p>
|
||||
<p style="font-size:120%; padding:10px;"><a href="http://cappuccino.org/noscript">Show me how to enable JavaScript</a></p>
|
||||
<p style="font-size:80%;">You may want to upgrade to a newer browser while you're at it:</p>
|
||||
<ul style="margin:0;padding:0; text-align: center; font-size:80%;" >
|
||||
<li style="display: inline;"><a href="http://www.apple.com/safari/download/">Safari</a></li>
|
||||
<li style="display: inline;"><a href="http://www.mozilla.com/en-US/firefox/">Firefox</a></li>
|
||||
<li style="display: inline;"><a href="http://www.google.com/chrome/">Chrome</a></li>
|
||||
<li style="display: inline;"><a href="http://www.opera.com/download/">Opera</a></li>
|
||||
<li style="display: inline;"><a href="http://www.microsoft.com/windows/downloads/ie/getitnow.mspx">Internet Explorer</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</noscript>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* AppController.j
|
||||
* CPURLConnectionAsyncTest
|
||||
*
|
||||
* Created by You on February 1, 2012.
|
||||
* Copyright 2012, Your Company All rights reserved.
|
||||
*/
|
||||
|
||||
@import <Foundation/Foundation.j>
|
||||
@import <AppKit/AppKit.j>
|
||||
|
||||
@import "AppController.j"
|
||||
|
||||
|
||||
function main(args, namedArgs)
|
||||
{
|
||||
CPApplicationMain(args, namedArgs);
|
||||
}
|
||||
Reference in New Issue
Block a user