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

2. writing MySql plugins general

on

  • 307 views

 

Statistics

Views

Total Views
307
Views on SlideShare
307
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as OpenOffice

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

2. writing MySql plugins   general 2. writing MySql plugins general Presentation Transcript

  • Roland Bouman http://rpbouman.blogspot.com/ 1 Writing MySQL 5.1 Plugins
  • 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
  • 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;
  • 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
  • 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 */ };
  • 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
  • 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
  • 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
  • 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
  • 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;
  • 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 };