LoadBroker


Inherits From:
NSObject
Declared In:
LoadBroker.h


Class Description

This is a useful superclass of a number of classes to be called by the client program. It is a "broker" in that it works in the middle of a transaction, passing a request to its "supplier" and then passing the result back to its "consumer." It contains default methods for passing the completion method after loading back to its consumer.

The methods loadSuccess:handle:parameter:, loadCancelledParameter:, and loadError:parameter: are for responding to load completion, cancellation, and error termination, respectively. These should be overridden by the concrete subclasses if they care about the result. If not overridden, they will be passed on to the client, which allows the next guy up to respond to it. So this means that the overrides of these methods must invoke super methods in order to have the clients also get a crack at them, and perhaps change the data or parameter to what is more appropriate for the client. Subclasses must implement all three if they are to do anything with results that requires cleaning up.

Consumers that are LoadBrokers are designed to use these three selectors, but consumers that are the "final" consumer (not another broker) can set up any selector desired. This allows a single controller class to use more than one load broker, and have a different set of methods to deal with the results from different load brokers.

BE SURE to invoke detachConsumer on this object before deallocating this in your class's release method.


Global Variables

Synopsis:

NSString *LOAD_OPTION_COOKIEDICT;

Description:

A dictionary of cookie key/values to send to the server. See CURLHandle for details on format of the dictionary.

Synopsis:

NSString *LOAD_OPTION_CACHE;

Description:

Set this to YES if we want the results of the request to be cached.

Synopsis:

NSString *LOAD_OPTION_HEADERS;

Description:

Specify a dictionary of additional headers to add to a request. User agent, for instance, could be specified from this dictionary.

Synopsis:

NSString *LOAD_OPTION_REQUESTENCODING;

Description:

And NSNumber of the string encoding for the request. If not specified, it will be NSASCIIStringEncoding.

Synopsis:

NSString *LOAD_OPTION_POSTDICT;

Description:

NSDictionary form of what is POSTed via HTTP.

Synopsis:

NSString *LOAD_OPTION_POSTSTRING;

Description:

For HTTP POST that wants raw data rather than a key=value&key2=value2 style dictionary. Setting this automatically causes a post to happen.

Synopsis:

NSString *LOAD_OPTION_DOPOST;

Description:

Set this to YES to force the request to be an HTTP POST. Not needed if you specify method = POST in your parsing dictionary or if you specify LOAD_OPTION_POSTSTRING or LOAD_OPTION_POSTDICT


Instance Variables

NSString *mDescriptor;
id mConsumer;
SEL mSuccess;
SEL mCancelled;
SEL mError;

mDescriptorNo description.
mConsumerThe Consumer: a LoadBroker, or any class that handles results
mSuccessSelector to invoke on success
mCancelledSelector to invoke on cancel
mErrorSelector to invoke on error


Method Types

- initWithDescriptor:consumer:
- initWithDescriptor:consumer:success:cancelled:error:
- detachConsumer
- loadSuccess:handle:parameter:
- loadCancelledParameter:
- loadError:parameter:
- setDescriptor:

Instance Methods

detachConsumer

- (void)detachConsumer

Sever the connection with the consumer. This must be called before a consumer is released, so that the LoadBroker, in a different thread, won't try to talk to a deallocated consumer.


initWithDescriptor:consumer:

- (id)initWithDescriptor:(NSString *)inDescriptor consumer:(id)inConsumer

Initialize a loadBroker to invoke the default methods upon completion: loadSuccess:handle:parameter:, loadCancelledParameter:, and loadError:parameter:. See initWithDescriptor:consumer:success:cancelled:error:.


initWithDescriptor:consumer:success:cancelled:error:

- (id)initWithDescriptor:(NSString *)inDescriptor consumer:(id)inConsumer success:(SEL)inSuccess cancelled:(SEL)inCancelled error:(SEL)inError

Initialize a new LoadBroker. inDescriptor is a string to describe the purpose of the broker (for debugging uses). inConsumer is the object (another LoadBroker subclass, or any object that will respond to the completion methods) to be passed the completion methods. inSuccess, inCancelled, and inError are the selectors to invoke upon completion; these should be methods with the same signature as loadSuccess:handle:parameter:, loadCancelledParameter:, and loadError:parameter:.

The consumer is not retained; it is treated much like a delegate. This is to prevent retain cycles.


loadCancelledParameter:

- (void)loadCancelledParameter:(id)inParam

Cancelled load. Pass on the cancelled selector that is stored for this class, along with the same parameters, to the consumer if it responds to that selector.


loadError:parameter:

- (void)loadError:(id)inError parameter:(id)inParam

Error in loading. Pass on the error selector that is stored for this class, along with the same parameters, to the consumer if it responds to that selector.


loadSuccess:handle:parameter:

- (void)loadSuccess:(id)inData handle:(id)inURLHandle parameter:(id)inParam

Successful load. Pass on the success selector that is stored for this class, along with the same parameters, to the consumer if it responds to that selector.


setDescriptor:

- (void)setDescriptor:(NSString *)inDescriptor

Set the string descriptor for this LoadBroker. This is useful for debugging; it shows up in the description of the object.


Version 1.1 Copyright ©2003 by Karelia Software, LLC. All Rights Reserved.