[ Previous | Next | Contents | Glossary | Home | Search ]
Ultimedia Services Version 2 for AIX: Programmer's Guide and Reference

File Type Detection

File type detection is enabled when a program uses the make_by_pathname method of either UMSAudioFileMClass or UMSMovieFileMClass. This method detects the file type and creates the appropriate object. This method can also be used by your programs to determine file types and can be extended to support new file types. The file type detection mechanism is made of the UMS_config configuration file, detection modules, and the UMSFiletypeDetector object.

To learn more about file type detection, see:

For introductory information, see Programming with Formatted File Access Objects.

Configuration File

The configuration file contains various detector alias stanzas that have the form:

Detector.audio:
       detection_module   "/usr/lpp/UMS6000/bin/d_WAVE"
       file_type_alias   "WAVE"
   *NEXT:
       detection_module   "/usr/lpp/UMS6000/bin/d_SND"
       file_type_alias   "SND"
   *NEXT:
       detection_module   "/usr/lpp/UMS6000/bin/d_RAW"
       file_type_alias   "RAW"

Where Detector.audio is an example of a detector alias.

The alias and associated data is referred to as a stanza. The sections of the stanza separated by *Next: fields are referred to as clauses. Clauses are comprised of properties that are assigned string values.

A detector alias has the form:

Detector<.string1><.string2>...<stringn> 

Where each <.string#> further qualifies the alias.

Each clause contained under the alias defines both a detection_module and file_type_alias. The detection_module property defines the path name of a detection module for a given file type. The file_type_alias property defines the string to be used as the file type alias if the detection module in the clause recognizes the file type. The file type alias can be recognized or used directly by an application but is usually used for further interrogation of the configuration file.

Through addition, deletion, or modification of detector alias stanzas, the configuration file provides the capability to:

The default configuration file contains a Detector.audio, a Detector.movie, and a Detector.alias for audio files, movie files, and general file type detection, respectively.

Detection Modules

A detection module is a loadable executable of the form:

typedef int (*detector_function_type)(char *filename)

Where char* filename is the pathname of a file whose type is to be identified.

To qualify a file as being of the type the detector is meant to detect, a detection module examines the file name and contents returning either TRUE or FALSE.

The detection_module properties defined in the configuration file under a detector alias provide an ordered list of detection modules to be used on the file. Detection can be extended to new file types by the creation of new detector modules and modification of the configuration file.

Note: Product extensions adding new UMSAudioFile or UMSMovieFileReader implementations should also add corresponding detectors.

UMSFiletypeDetector

The UMSFiletypeDetector object is the only programming interface necessary to perform file detection. The object has two public methods, one to specify the detector alias and one to initiate the detection.

The following method is used to specify the detector alias:

string category(in string detector_alias)  

Of the form:

Detector<.string1><.string2>...<stringn> 

The detector object uses a UMSConfig object to navigate the configuration file. The detector alias is used as the alias parameter in a seek_alias method call on the UMSConfig object which resolves to the specified alias or its derivatives (successive derivatives are derived by truncating the trailing <.string#> and should resolve to Detector if not a higher derivative). The category method returns the alias or the derivative that was resolved. The clauses within the alias stanza of the configuration file define the set and order of the detection modules.

The other public method causes successive ordered execution of the detection modules specified by the resultant alias until the given file specified by the filename parameter is recognized or the list is exhausted:

string determine_file_type(in string filename)

If the file type is recognized, the corresponding file type alias is returned. A NULL string is returned if the file type is unrecognized.

For introductory information, see Programming with Formatted File Access Objects.


[ Previous | Next | Contents | Glossary | Home | Search ]