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;