Your SlideShare is downloading. ×
2. writing MySql plugins   general
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

2. writing MySql plugins general

179
views

Published on

Published in: Technology, Art & Photos

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
179
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Roland Bouman http://rpbouman.blogspot.com/ 1 Writing MySQL 5.1 Plugins
  • 2. Roland Bouman http://rpbouman.blogspot.com/ 2 Tasks Before Implementing Plugins ● Include header files: – Standard headers: <stdlib.h>, <ctype.h> – MySQL headers for Clean plugins: <mysql/plugin.h> – MySQL headers for Unclean plugins: <mysql_version.h> ● Create a section for plugin declarations: – mysql_declare_plugin(name) – mysql_declare_plugin_end
  • 3. Roland Bouman http://rpbouman.blogspot.com/ 3 Plug-in Declaration #include <stdlib.h> #include <ctype.h> #include <mysql_version.h> #include <mysql/plugin.h> ... mysql_declare_plugin() // your plugin descriptors go here... { ... plugin descriptor 1... } , ... , { ... plugin descriptor N... } mysql_declare_plugin_end;
  • 4. Roland Bouman http://rpbouman.blogspot.com/ 4 Generic Tasks to Implement an Individual Plug-in ● General plug-in declaration – st_mysql_plugin defined in plugin.h ● Plug-in type-specific descriptor – defined in plugin.h ● init function – Called on INSTALL PLUGIN or server start ● deinit function – Called on UNINSTALL PLUGIN or shutdown
  • 5. Roland Bouman http://rpbouman.blogspot.com/ 5 The Generic Plug-in Descriptor struct st_mysql_plugin { int type; /* type constant */ void *info; /* type-specific descriptor */ const char *name; /* name */ const char *author; /* author */ const char *descr; /* description */ int license; /* license type constant */ int (*init)(void *); /* invoked when loaded */ int (*deinit)(void *); /* invoked when unloaded */ unsigned int version; /* plugin version */ struct st_mysql_show_var status_vars; /* status vars */ void * __reserved1; /* system variables */ void * __reserved2; /* config options */ };
  • 6. Roland Bouman http://rpbouman.blogspot.com/ 6 Plug-in Descriptor Members (1) ● int type: a type constant – MYSQL_STORAGE_ENGINE_PLUGIN – MYSQL_FTPARSER_PLUGIN – MYSQL_DAEMON_PLUGIN – MYSQL_INFORMATION_SCHEMA_PLUGIN ● void *info: plug-in-type specific struct – st_mysql_storage_engine – st_mysql_ft_parser – st_mysql_daemon – st_mysql_information_schema
  • 7. Roland Bouman http://rpbouman.blogspot.com/ 7 Plug-in Descriptor Members (2) ● const char *name: plug-in name – INSTALL PLUGIN <name> ... ● Human readable metadata – const char *author – const char *descr – int license ● All this is user visible in SHOW PLUGINS
  • 8. Roland Bouman http://rpbouman.blogspot.com/ 8 Plug-in Descriptor Members (3) ● int (*init) (void *) – Initialization function – Invoked on INSTALL PLUGIN, server startup ● int (*deinit) (void *) – Deinitalization function (cleanup) – Invoked on UNINSTALL PLUGIN, shutdown ● Argument type is plugin type specific
  • 9. Roland Bouman http://rpbouman.blogspot.com/ 9 Plug-in Descriptor Members (4) ● struct st_mysql_show_var *status_vars; – Status variables – Visible in SHOW STATUS – Plug-in monitoring ● struct st_mysql_sys_var **system_vars; – System variables – Dynamic plug-in configuration
  • 10. Roland Bouman http://rpbouman.blogspot.com/ 10 Minimal Daemon Plug-in: Headers and Plug-in Declaration #include <stdlib.h> #include <ctype.h> #include <stdio.h> #include <mysql_version.h> #include <mysql/plugin.h> //... implementation goes here ... mysql_declare_plugin(hello_world_daemon) { MYSQL_DAEMON_PLUGIN, /* type constant */ &hello_world_daemon_plugin, /* plugin-type specific */ "MYSQL_HELLO_DAEMON", /* Name */ "Roland Bouman (http://rpbouman.blogspot.com/)", /* Author */ "A 'Hello, World!' daemon plugin example.", /* Description */ PLUGIN_LICENSE_GPL, /* License */ hello_world_daemon_plugin_init, /* Init function */ hello_world_daemon_plugin_deinit, /* Deinit function */ 0x0010, /* Version (1.0) */ NULL, /* status variables */ NULL, /* system variables */ NULL /* config options */ } mysql_declare_plugin_end;
  • 11. Roland Bouman http://rpbouman.blogspot.com/ 11 Minimal Daemon Plug-in: Implementation // Log initialization static int hello_world_daemon_plugin_init(void *p) { fprintf(stderr, "hello_world_daemon_plugin_initn"); return 0; } // Log de-initialization static int hello_world_daemon_plugin_deinit(void *p) { fprintf(stderr, "hello_world_daemon_plugin_deinitn"); return 0; } // plug-in type specific structure struct st_mysql_daemon hello_world_daemon_plugin= { MYSQL_DAEMON_INTERFACE_VERSION };