Copyright (c) Hyperion Entertainment and contributors.
Application Library
This page is currently being updated to AmigaOS 4.x. Some of the information contained here may not yet be applicable in part or totally. |
Introduction
The Application Library is a multipurpose auxiliary library that provides various functions related to the development and use of applications. The very concept of application is a relatively recent addition to AmigaOS. Before, the system only distinguished between different types of program on a very low level, seeing them as either tasks or processes. This distinction might have been useful in the past when tasks (which require fewer resources in return for not being able to access DOS functions) could improve system performance. But it can hardly make a difference on today’s hardware so the trade-offs are no longer worth it. Nowadays it makes more sense to discriminate between programs that operate without the user even noticing (e.g. drivers, handlers, filesystems and other background services), and genuine full-blown applications with GUI and all.
AmigaOS alone cannot make such a distinction: it uses the Application Library as a mediator through which applications introduce themselves to the system. This process is called application registration, during which the application receives a unique identifier and is added to a public list among other applications. Once registered, the application can make use of the library’s many features:
- It can send/receive messages to/from other registered applications. The library supports a set of common control messages (commands) such as those telling an application to quit, iconify or bring its window to front. But it also allows custom messages designed for an application’s particular needs; in this respect the Application Library provides an alternative to ARexx control.
- It can use PrefsObjects, an XML-based, object-oriented system for handling program preferences. Before AmigaOS 4.x no real standard existed for storing preferences: some developers used icon tooltypes, some used proprietary formats, text or binary. The Application Library provides a format that is human-readable and easily editable in a simple text editor; that is comprehensive enough to cover even very complex settings structures; and that is fully controllable via the library, without the need to laboriously implement data parsing and verification.
- It can notify the user about, for example, completed tasks via automatic pop-up messages. These represent a practical, less obtrusive alternative to traditional requesters.
- It can easily create and manage lists of recently-used documents.
- It can register as a unique application, preventing other instances of itself from running.
- It can show its icon or display the current program state in taskbar-like applications, such as AmiDock.
- It can control the behaviour of screen-blankers. Applications that don’t want to be disturbed may prevent the blanker from kicking in, or tell other applications to “keep quiet”.
Library opening chores
Just like other AmigaOS libraries, the Application Library must be opened before it is used. Further, at least one of its interfaces must be obtained, depending on the functionality you require. The Application Library has two interfaces, called “application” and “prefsobjects”. You always need to obtain the “application” interface because it provides access to most library functions including application registration. You’ll only need to open the “prefsobjects” interface if you intend to make use of the PrefsObjects preferences system.
struct Library *ApplicationBase = NULL; struct ApplicationIFace *IApplication = NULL; struct PrefsObjectsIFace *IPrefsObjects = NULL; if ( (ApplicationBase = IExec->OpenLibrary("application.library", 52)) ) { IApplication = (APTR)IExec->GetInterface(ApplicationBase, "application", 1, NULL); IPrefsObjects = (APTR)IExec->GetInterface(ApplicationBase, "prefsobjects", 1, NULL); } if ( !ApplicationBase || !IApplication || !IPrefsObjects ) { /* handle library opening error */ }
Note that there is no interface called “main” like older, single-interface libraries have.
When your application has run its course, don’t forget to clean up and close both the library and its interface(s):
IExec->DropInterface((struct Interface *)IPrefsObjects); IExec->DropInterface((struct Interface *)IApplication); IExec->CloseLibrary(ApplicationBase);