You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.3 KiB

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