As of MySQL 5.5, plugins have access to server “services.” The services interface exposes server functionality that plugins can call. It complements the plugin API and has these characteristics:
Services enable plugins to access code inside the server using ordinary function calls.
Services are portable and work on multiple platforms.
The interface includes a versioning mechanism so that plugin versions can be checked at load time against service versions supported by the server. Versioning protects against incompatibilities between the version of a service that the server provides and the version of the service expected or required by a plugin.
On the plugin side of the services interface, the relevant
information is provided in a set of header files. A plugin
accesses this information by including the
plugin.h file (which plugins must include
anyway):
#include <mysql/plugin.h>
plugin.h includes the
services.h file, which acts as an
“umbrella” file that includes the service-specific headers
with names of the form service_xxx.h. Within
a MySQL source distribution, the header files are located in the
include/mysql directory and have an inclusion
hierarchy like this:
plugin.h includes
services.h.
services.h is the “umbrella” header
that includes all available service-specific header files.
Service-specific headers have names like
service_my_snprintf.h or
service_thd_alloc.h.
The server side of the services interface uses the header files
just listed, but also involves other files. Within a MySQL
source distribution, these files are located in the
libservices and sql
directories:
The libservices directory contains the source
files from which the libmysqlservices library
is built. Files in this directory include:
HOWTO : Instructions for writing plugin
services.
xxx_services.h : Service-specific
interface files.
Current service files are
my_snprintf_service.c and
thd_alloc_service.h.
During the MySQL build and install process, the
libmysqlservices library is compiled and
installed in a directory where plugins can access it. All
plugins should link in this library using the
-lmysqlservices flag when they are built.
The sql directory contains
sql_plugin.cc, which implements plugin
functionality. This file includes
sql_plugin_services.h, where each available
service is registered.
Services are implemented by modifying server code in the
sql directory to register the service in the
plugin code, and by providing interface files in the
libservices directory and under the
include directory.
For complete instructions on writing a service, see the
HOWTO file in the
libservices directory within a MySQL source
distribution. As you read the HOWTO file, you
might find it useful to examine the files that implement
existing services.
When you write a service, be sure to provide complete
instructions on how to use it. A service named
xxx will have a file named
service_xxx.h in the
include/mysql directory. For the benefit of
plugin developers who use your service, this file should include
comments that fully document the service interface:
Its purpose
Any applicable guidelines, including limitations or restrictions
For each function, a description of what it does, its calling sequence, and return value
The goal for documentation in this file is that plugin developers should be able to look at the file and completely understand how to use the service.
