user since
Wed Mar 10 2004 at 03:20:43 (13.7 years ago )
last seen
Fri Aug 13 2004 at 01:29:23 (13.3 years ago )
level / experience
1 (Initiate)
specialties
software engineering
most recent writeup
Still empty (idea)
Send private message to segfault_0

I enjoy reading classical literature because I feel like im always on the edge of unconvering some long lost or forgotten bit of information that will change my life. When I do find something I dont feel like I learned it but rather that someone else has managed to articulate something that originated in my head, regardless of how simple minded this is. And yes I intentionally ended that last sentence with a preposition.

Things themselves touch not the soul, not in the least degree; nor have they admission to the soul, nor can they turn or move the soul: but the soul turns and moves itself alone, and whatever judgements it may think proper to make, such it makes for itself the things which present themselves to it. - Marcus Aurelius

Rather important statement - its more and more rare to find individuals who can take an idea under consideration without taking it into their heart.

Programming a Plug-in API in C

Extensibility is an often overlooked goal of software engineers everywhere. It's easy to write a program and never concieve that anyone will want to modify or otherwise extend that code at a later date; its much more difficult to actually write the application so it can be extended easily. One approach to this problem is known as a plug-in architecture or API. This technique denotes allowing other software developers to create their own code modules to a certain specification which, if done properly, will be useable by the original application.

This write-up will concentrate on the C programming language since it is very possibly the closest thing to a defacto standard that the varied history of programming has provided.

The first step in developing an application that can use plug-ins is to develop an API. An API is a subset of functionality that a program which implements the API promises to provide. What will be included in your API will depend on what the goal of your application is and how much control you want to give to other developers. My example will be very simple, a CRC function. A CRC, or Cyclic Redundancy Codes, function takes in a stream of data and does a mathmatical calculation on the contents which will provide a predicatably different result for different data sets. This in turn allows you check data for damage or tampering after transporting the data from one location to another over an insecure or unreliable method of transmission. Most applications that send data over the internet uses either a CRC or a more complicated process to ensure data integrity.

There are a number of CRC functions out there, usually differentiated by the polynomial used to calculate the result or the application of other techniques that add to the quality or accuracy of the CRC. Perhaps your program provides a CRC function but future users may want to supply a more complex one for better resolution or a smaller faster one for more speed. If you implemented your CRC as a plug-in, this will be possible.

Plug-ins are implemented as dynamic link libraries (.dll) or on a *NIX platform as a shared object file (.so). You will have to be familiar with their creation to follow along. The application that uses the plug-ins will be a normal application for the target platform. The API is created by making a definition of the functions the API will contain that will be shared by both the library and the application.


#ifndef _SEGFT0_PLUGIN_API
#define _SEGFT0_PLUGIN_API

typedef struct PLUGIN {
   void* (*crc) (unsigned char*, int);  // function pointer to hold CRC
   // other functions could be defined here...
} plugin;

#endif