Debian Codegraph @

libservices/HOWTO

raw
1 Copyright (c) 2009, 2026, Oracle and/or its affiliates.
2
3 !!!!!!!!!!!!!!!!!!!!!!!!!!!!
4 NOTE: Document is deprecated
5 Use Component Services instead
6 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7
8 How to create a new service
9 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
10
11 A "service" is a set of C functions in a structure that a
12 service dynamic linker uses when a dynamic plugin is loaded.
13
14 If you want to export C++ class you need to provide an
15 extern "C" function that will create a new instance of your class,
16 and put it in a service.
17
18 Data structures are not part of the service structure, but they are part
19 of the API you create and usually need to be declared in the same
20 service_*.h file.
21
22 To turn a set of functions (foo_func1, foo_func2)
23 into a service "foo" you need to
24
25 1. create a new file include/mysql/service_foo.h
26
27 2. the template is
28 ==================================================================
29 #ifndef MYSQL_SERVICE_FOO_INCLUDED
30 /* standard GPL header */
31
32 /**
33 @file
34 *exhaustive* description of the interface you provide.
35 This file is the main user documentation of the new service
36 */
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 extern struct foo_service_st {
42 int (*foo_func1_type)(...); /* fix the prototype as appropriate */
43 void (*foo_func2_type)(...); /* fix the prototype as appropriate */
44 } *foo_service;
45
46 #ifdef MYSQL_DYNAMIC_PLUGIN
47
48 #define foo_func1(...) foo_service->foo_func1_type(...)
49 #define foo_func2(...) foo_service->foo_func2_type(...)
50
51 #else
52
53 int foo_func1_type(...); /* fix the prototype as appropriate */
54 void foo_func2_type(...); /* fix the prototype as appropriate */
55
56 #endif
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #define MYSQL_SERVICE_FOO_INCLUDED
63 #endif
64 ==================================================================
65
66 the service_foo.h file should be self-contained, if it needs system headers -
67 include them in it, e.g. if you use size_t - #include <stdlib.h>
68
69 it should also declare all the accompanying data structures, as necessary
70 (e.g. thd_alloc_service declares MYSQL_LEX_STRING).
71
72 3. add the new file to include/Makefile.am (pkginclude_HEADERS)
73 4. add the new file to include/mysql/services.h
74 5. increase the minor plugin ABI version in include/mysql/plugin.h
75 (MYSQL_PLUGIN_INTERFACE_VERSION = MYSQL_PLUGIN_INTERFACE_VERSION+1)
76 6. add the version of your service to include/service_versions.h:
77 ==================================================================
78 #define VERSION_foo 0x0100
79 ==================================================================
80
81 7. create a new file libservices/foo_service.c using the following template:
82 ==================================================================
83 /* GPL header */
84 #include <service_versions.h>
85 SERVICE_VERSION *foo_service= (void*)VERSION_foo;
86 ==================================================================
87
88 8. add the new file to libservices/CMakeLists.txt (MYSQLSERVICES_SOURCES)
89 9. add the new file to libservices/Makefile.am (libmysqlservices_a_SOURCES)
90 10. and finally, register your service for dynamic linking in
91 sql/sql_plugin_services.h
92 10.1 fill in the service structure:
93 ==================================================================
94 static struct foo_service_st foo_handler = {
95 foo_func1,
96 foo_func2
97 }
98 ==================================================================
99
100 10.2 and add it to the list of services
101
102 ==================================================================
103 { "foo_service", VERSION_foo, &foo_handler }
104 ==================================================================
105
106 that's all.
107