Technote 1169The Download ManagerBy David GelphmanRevised by David Gelphman & Dave Polaschek Apple Worldwide Developer Technical Support |
CONTENTS
Introduction
Section 2 : |
This Technote is divided into two sections. Section 1 discusses the Download Manager API that Download Manager clients would use to call the Download Manager to cause a file, or other data, to be downloaded to a PostScript printer. (The Desktop Printing software is an example of a Download Manager client that uses this API.) Writers of low-level converters should read Section 1 to get an overview of the environment in which their converter will operate. Section 2 discusses the APIs that the Download Manager uses to call the low-level converters. This material is intended for the writers of the low-level converters which are called by the Download Manager. In addition to downloading files to a PostScript output device, it is possible for a client to provide the data from a source other than a file or to obtain the PostScript output data itself rather have it transmitted it to a device. Programmers who wish to create a Download Manager client that supplies the data to convert and/or a client that receives the Download Manager generated PostScript output should read the discussion of streams in Section 2. Moreoever, programmers who wish to create a Download Manager client that only downloads files to a PostScript output device need not read Section 2. |
Section 1This section discusses the calls that a Download Manager client uses to download data through the Download Manager. Most Download Manager clients can ignore Section 2, which discusses the APIs that the Download Manager itself uses to call the low-level converters. The section File Download Example is an example of using the Download Manager to download a file. This is the approach that the Desktop Printing software uses. |
Download Manager APIsThe Download Manager APIs allow a client to determine whether the Download Manager, together with the current set of low-level converter modules available, can convert and download a given piece of data. This data may be the data fork of a file, or it may be supplied by the client via a stream mechanism which is defined below. Once the client has determined if the Download Manager can handle the data, it calls the Download Manager routine to invoke the processes of conversion and downloading. Downloading FilesThis section of the document describes the high-level APIs that a client of the Download Manager, such as the Desktop Printing software, would call to downloadfiles . First, the client calls the psCanDownloadFile routine:
The Download Manager routine
The
Note that whether the Download Manager can handle a given file may be dependent on the
Once a client determines that the document can be downloaded by the Download Manager, it can call the routine
Note that the
DownloadDocumentInfo structure
The
The
The
The
The
The |
The
The psDownloadFile
Once the Download Manager client has determined that the file can be handled by the Download Manager, it calls the
The
The error value |
The Status-Idle Procedure
The
|
The
The
The
The section field indicates which phase of the download is currently in progress. Currently the possible section values are The subsection field contains Document Structuring Conventions information or other section information about the PostScript data being downloaded (see the heading DownloadIdleInfo Section, Subsection and StatusInfo below).
The
The client’s |
DownloadIdleInfo Section, Subsection, and StatusInfo
The
The
The subsection field is of type The Download Manager generates status and error subsection values. Beyond that, each low-level converter module is responsible for generating subsection values during the download. While any subsection value from the list in “PSSectionInfo.h” is possible, Table 1 lists those most likely to be generated by existing low-level converters. No one converter necessarily generates all of these subsection values for each job.
The
For example, the low-level PostScript converter module (which downloads PostScript and EPS input data) generates the Table 1
A few of the subsections do not correspond to DSC comments but instead are used to convey information to the client such as status data, printer error conditions, and error or warning messages from a converter.
The
The
The
The
The
The
The
The
For example, when the PostScript converter supplies a warning that the document being downloaded requires a PostScript language level greater than the target output device supports, it supplies a Utility Functions For A Client’s Use of the Download ManagerpsCreateDMJobCollection
The Download Manager makes available a routine called
Depending on how a client operates, it may be appropriate to call
If there is no error, File Download ExampleFor a Download Manager client such as the Desktop Printing software, downloading a file is fairly straightforward. The following example illustrates the basics:
The code example assumes that we’ve defined a routine
The code example uses stack allocation for the Downloading StreamsSome Download Manager clients may have data which is not in a file, but is instead supplied in another fashion. Other clients may want to direct the output to something other than a Desktop Printer and receive the converted PostScript output data directly. In these cases, the client provides an input stream for reading the data to convert and an output stream to which the Download Manager and the low-level converters write. psCanDownloadStream
Note that the details of the
This function is similar to the
psCanDownloadData
If the client has data that allows it to be read only once, the
This function is similar to the
psDownloadStream
This function is similar to
A careful reader will notice that the
Additional Utility FunctionspsGetDownloadMgrLibVersionThe Download Manager provides an additional call for use by its clients:
The
Readers familiar with the Code Fragment Manager will notice that this information mirrors the version information built into a CFM library. Unfortunately, in some versions of the system software, the The Download Manager API does not contain any information about how to determine the location of the plug-ins folder that it uses for its plug-in converters. See Technote 1170: The Printing Plug-ins Manager for more information about calls relating to the “Printing Plug-ins” folder. |
This section describes the public interface to the low-level converters that the Download Manager calls to perform the data conversion portion of the download. Developers writing programs which only invoke the Download Manager to download files to a desktop printer do not need to read this section to understand how to call the Download Manager. |
Low-level Converter APIsThis section describes the APIs that the Download Manager uses to call the low-level converters that it knows about. The Download Manager knows about the built-in converters (a set of shared libraries built into PrintingLib) as well as converter modules in the “Printing Plug-ins” folder in the Extensions folder. Files containing converter module plug-ins must contain a resource of type ‘PLGN’, ID -8192 with the plug-in type ‘down’ and subtype ‘????’. Details of the PLGN resource are described in Technote 1170: The Printing Plug-ins Manager. Streams InformationLow-level converters don’t know where the data they are converting comes from, nor do they know the ultimate destination of their PostScript output data. Instead, they read the data from input procedures and write data to output procedures. These procedures are packed into structures called streams. PSStream structure
The low-level converters read and write data from stream structures of type
The
The read and write procedures of the
The read field of the
The
The
When actually converting data, a low-level converter is passed an output stream of type
Note that some output streams have no Additional functions for random-access streams
Streams of type
The
The
The position value is zero-based; that is, the value of
The
For the
The
The
One additional comment about the streams used by the Download Manager and the low-level converters is that they each call stream routines as native code, without using Low-level Converting Routines
When a client such as the Desktop Printing software calls the Download Manager routine
The
The version field of the
Once the Download Manager establishes the best converter for the job (i.e., the one returning the highest priority), the
Getting Information For A Client
When a Download Manager client calls the Download Manager routine
The updated hints collection returned from
Peeking at the Data
When a Download Manager client calls the Download Manager routines
This routine is called by the Download Manager to allow the low-level converter an opportunity to look at the data to be downloaded and thereby collect useful information. Such information might be collected to provide information back to the Download Manager for reporting to the Download Manager client (such as fonts used in a document, etc). Other information might be collected by the low-level converter for passing back to itself when it is later asked to “convert” and download the document with the
The updated hints collection returned from Examples of data put into the hints during the peek phase by a low-level converter might be:
While a low-level converter should always be prepared to handle the fact that a peek pass may not be made, it may still find it useful to peek at the data when it is given the chance to do so. This means that a low-level converter should be prepared to operate without data it would normally collect during a possible
Queries
When a client makes a call to
This routine is passed the hints collection for the current job. If the low-level converter routine Basic QueriesMost queries fall into the category of basic queries. Examples of these queries are the PostScript language level, PostScript version information, color or black and white device knowledge, and so forth. Such queries are generated by adding the appropriate hints to the query collection, with default values chosen by the converter for its own conservative handling approach. For example, to cause the Download Manager to query for the PostScript language level, the following code is used:
Note here that the default value used is Font Queries
The Download Manager can query for a specific list of fonts or obtain the entire list of fonts available in the target output device. Both of these font queries are specified with the hint
and the following constants are defined:
If the tag field of the
If the tag field of the
Communication Channel QueriesA second category of special queries is that for the communication channel characteristics. Most low-level converters will generate different output data if the communication pathway to the target output device supports binary data. There are two hints used to query for whether the output device supports binary data and both should be consulted.
The first is the hint with tag value
The second is the hint with the tag value |
Normally a low-level converter will add both of these hints to the query collection with default values of false to specify that the Download Manager supply the appropriate query for the channel characteristics. The value for these hints after the query determines the channel characteristics. |
A low-level converter receives its query results in the hints collection supplied to the call
A low-level converter should be prepared to operate without results from a query. Query results can be unavailable in at least two ways. If the Download Manager is invoked using the routine Another case where queries may not be completed is when the download is to a file without a printer involved or with any communication channel that does not support a backchannel, such as LPR. In that case, some of the queries may be satisfied by PPD data, but others return a default value. Doing the Conversion
After the query phase, the Download Manager calls the
|
It is the responsibility of the low-level converter to read the data supplied in the stream pointed to by
The
|
While processing the data to be converted during
The hints collection passed to |
Since calls to
The following figure attempts to illustrate the way the input and output streams are used by a low-level converter during the call to |
Converter Capabilities
At various times, the Download Manager determines what low-level converters are available and then determines what file types each low-level converter can potentially handle. It does this by calling the
The |
typedef struct ConverterDescription { OSType converterDescSignature; ConverterDescVersion converterDescVersion; ConverterType converterType; ConverterService converterService; }ConverterDescription; |
The first field in the |
enum { kTheConverterDescriptionSignature = 'dhwu' /*first long word of ConverterDescription*/ }; |
The second long word of the
The next field of the |
typedef struct ConverterType{ Str31 name; Str255 info; NumVersion version; }ConverterType; typedef struct NumVersion{ UInt8 majorRev; /*1st part of version number in BCD*/ UInt8 minorAndBugRev; /*2nd and 3rd part of version number share a byte*/ UInt8 stage; /*stage code: dev, alpha, beta, final*/ UInt8 nonRelRev; /*rev level of nonreleased version*/ }NumVersion; |
The final field in the |
typedef struct ConverterService{ UInt32 nTypes; ConverterTypeInfo typeInfo[1]; }ConverterService; typedef struct ConverterTypeInfo{ OSType type; Fixed priority; Str15 matchString; }ConverterTypeInfo; |
A given converter may be able to handle a number of different
The type field of the
The
The Download Manager uses the
In some cases the
The
As an example, here is a sample
Note that by reporting a non-zero priority hint for each type, this hypothetical converter says that it can operate on a stream that cannot be randomly accessed.
When the Download Manager calls The converter module is responsible for disposing of any memory it allocates as part of generating the Utility Functions
The
Readers familiar with the Code Fragment Manager will notice that this information mirrors the version information built into a CFM library. Unfortunately, in some versions of the system software, the Errors
Logging
The Download Manager can log errors and warnings that might be generated by a low-level converter. The The amount of information logged is controlled by the LOGD resource. It is defined by default as:
When logging is turned on, the log file (default name “Download Manager Log”) is created in the user’s Printing Prefs folder. |
SummaryThe Download Manager allows Desktop Printing and other clients to quickly send documents to a PostScript printer. Applications which wish to bypass QuickDraw can call the Download Manager to send data directly to the printer. Also, the types of documents handled by the Download Manager can be extended by third parties creating new “low-level converters.” More information on writing low-level converters will be provided in a separate Technote. |
Change History
|
Thanks to Rich Blanchard, John Blanchard, Andreas Wickberg, Ingrid Kelly, Paul Danbold, and Howard Miller.