00001
00002
00003
00004
00005
00006
00007
00008
00009 #import "WIRemoting.h"
00010
00011 @interface RMCall (Private)
00012 - (void)responseDone:(RMResponse*) response;
00013 @end
00014
00015 @implementation RMResponse
00016
00017
00018 + (id)responseWithCall:(RMCall*) call
00019 request:(ASIHTTPRequest*) request
00020 delegate:(NSArray*) aDelegateChain
00021 {
00022 return [[[RMResponse alloc]
00023 initWithCall:call request:request delegate:aDelegateChain] autorelease];
00024 }
00025
00026 - (id)initWithCall:(RMCall*) call
00027 request:(ASIHTTPRequest*) req
00028 delegate:(NSArray*) aDelegateChain
00029 {
00030 self = [super init];
00031
00032 if (nil != self) {
00033 parentCall = call;
00034 request = [req retain];
00035
00036 delegateChain = [aDelegateChain copy];;
00037 }
00038
00039 return self;
00040 }
00041
00042 - (void)dealloc
00043 {
00044 [string release];
00045 [data release];
00046 [delegateChain release];
00047 [super dealloc];
00048 }
00049
00050 - (void)requestFinished:(ASIHTTPRequest*) req
00051 {
00052
00053 string = [[NSString alloc] initWithString:[req responseString]];
00054 data = [[NSData alloc] initWithData:[req responseData]];
00055
00056
00057 for (id<RMResultDelegate> delegate in delegateChain) {
00058 [delegate finished:self];
00059 }
00060
00061
00062 [parentCall responseDone:self];
00063 }
00064
00065 - (void)requestFailed:(ASIHTTPRequest*) req
00066 {
00067
00068 string = [[NSString alloc] initWithString:[req responseString]];
00069 data = [[NSData alloc] initWithData:[req responseData]];
00070 NSError *error = [req error];
00071
00072
00073 for (id<RMResultDelegate> delegate in delegateChain) {
00074 [delegate failed:self
00075 error:error];
00076 }
00077
00078
00079 [parentCall responseDone:self];
00080 }
00081
00082 - (NSString*) responseString
00083 {
00084 return string;
00085 }
00086
00087 - (NSData*) responseData
00088 {
00089 return data;
00090 }
00091
00092 @end