Overview

The Addon Interfaces Library, libaoi.so, contains functions for accessing addon interfaces. An addon is an implementation of a set of interfaces that provide some new functionality, and that can be dynamically loaded and unloaded by an application at runtime. An interface is a group of related functions and data. By using a known set of interfaces, you can add functionality to deployed applications without having to recompile and redeploy the application. Addons are typically contained in DLLs, and are sometimes also called plugins.

This approach to dynamically adding functionality is different from simply loading a DLL at runtime using a function such as dlopen(), as the application does not have to know the specific functionality contained by the DLL ahead of time. Rather, the application can search the DLL for a known interface, and if available, that functionality can be accessed.

An Example

For example, say that you want to write a screensaver application. You could define a screensaver interface that would allow you to write addons that contain screensaver functionality. Each screensaver addon would have a known interface that the application would use to start, stop, and set options for that particular screensaver. To write such an application, you would perform the following general steps to use the Addon Interfaces Library:

First, determine the mandatory functionality for the application. For each screensaver addon, you need a function that creates and populates an options pane. You may also want a function that initializes the screensaver addon, and another to uninitialize it to restore any resources acquired during the initialization of the addon.

You'll also need a function to start and stop the screensaver display. You may end up with an interface similar to:

typedef struct
{
 int32_t Initialize(void);
 int32_t Uninitialize(void);
 PtWidget_t *OptionsWidget(void);
 int32_t Start(void);
 int32_t Stop(void);
} ScreenSaver;

Within your addon a declaration of the interfaces available is provided that allows the AOI library to discover and make use of the interfaces.

AOInterface_t interfaces[]=
{
  { "Name", 0, "my_screensaver" },
  { "ScreenSaver", SS_VERSION, &SS2 },
  { "ScreenSaverPrefs", SS_PREFSVERSION, &SSP2 }
  { 0,0,0 }
};

Your screensaver would use the addon library to find all the available addons (loaded DLLs, which contain the screensavers) that have this set of interfaces, and allow the user to select which screensaver (and options for that screensaver) to use.

A screensaver addon might have user-set preferences. In this case, a “preferences” interface would exist for that addon. The application would only display preferences for those screensavers with a “ScreenSaverPrefs” interface. It might look like:

typedef struct
{
  int32_t LoadPrefs(void);
  int32_t SavePrefs(void);
} ScreenSaverPrefs;

Library components

The Addon Interfaces Library consists of: