List:Internals« Previous MessageNext Message »
From:Sergei Golubchik Date:June 29 2008 1:16pm
Subject:Re: Plugin declaration
View as plain text  
Hi!

On Jun 29, Muslimas Chochlovas wrote:
> Hello,
> 
> Usually when we want to declare one or more plugins we use two macros
> defined in plugin.h: mysql_declare_plugin and mysql_declare_plugin_end
> (http://dev.mysql.com/doc/refman/6.0/en/plugin-creating.html). It works just
> fine if the implementation is within a single file. If you try to declare
> plugins in separate files using the macros above, the compiler will complain
> about multiple definitions of _mysql_plugin_interface_version_ and
> _mysql_plugin_declarations_. Now what I did - suppose we have two files
> plugin_1.cc and plugin_2.cc. plugin_1.cc contains only functions and data
> structures needed by plugin_1 and the same for plugin_2.cc
> Simplified plugin_1.cc:
> //plugin_1.cc
> .....
> struct st_mysql_plugin plugin_1= {....}; 
> .....
> //plugin_2.cc
> .....
> struct st_mysql_plugin plugin_2= {....}; 
> .....
> 
> Then I add one file to declare plugins manually without using macros.
> //init.cc
> extern st_mysql_plugin plugin_1;
> extern st_mysql_plugin plugin_2;
> 
> struct st_mysql_plugin dummy=
> {0,0,0,0,0,0,0,0,0,0,0,0};
> 
> int _mysql_plugin_interface_version_= MYSQL_PLUGIN_INTERFACE_VERSION;
> struct st_mysql_plugin _mysql_plugin_declarations_=
> {
>   plugin_1,
>   plugin_2,
>   dummy
> };
> 
> It compiles and runs without errors. But my question - is it correct to
> declare plugins this way or maybe there should be another approach. I just
> couldn't find any documentation or examples which would match my case.

It should be ok. Although you could just as well use macros and write

mysql_declare_plugin(yours)
  plugin_1,
  plugin_2
mysql_declare_plugin_end

Or even 

mysql_declare_plugin(yours)
 { .... }, // declarations for plugin 1
 { .... }, // declarations for plugin 2
mysql_declare_plugin_end

because there's no rule that plugin declaration cannot refer to a
function in a different file. That is, you put your functions in
whatever file you want, and a plugin declaration in a different file -
no problem whatsoever.

Regards / Mit vielen Grüssen,
Sergei

-- 
   __  ___     ___ ____  __
  /  |/  /_ __/ __/ __ \/ /   Sergei Golubchik <serg@stripped>
 / /|_/ / // /\ \/ /_/ / /__  Principal Software Engineer/Server Architect
/_/  /_/\_, /___/\___\_\___/  Sun Microsystems GmbH, HRB München 161028
       <___/                  Sonnenallee 1, 85551 Kirchheim-Heimstetten
Geschäftsführer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
Vorsitzender des Aufsichtsrates: Martin Häring
Thread
Plugin declarationMuslimas Chochlovas29 Jun
  • Re: Plugin declarationSergei Golubchik29 Jun
    • RE: Plugin declarationMuslimas Chochlovas29 Jun