~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_plugin.cc

  • Committer: Monty Taylor
  • Date: 2009-08-05 08:52:52 UTC
  • mto: (1093.1.57 captain)
  • mto: This revision was merged to the branch mainline in revision 1115.
  • Revision ID: mordred@inaugust.com-20090805085252-27rso8llvaknwy5q
Added ListenHandler as a member of PluginRegistry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
150
150
 
151
151
 
152
152
/* prototypes */
153
 
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
 
153
static bool plugin_load_list(PluginRegistry &registry,
 
154
                             MEM_ROOT *tmp_root, int *argc, char **argv,
154
155
                             const char *list);
155
156
static int test_plugin_options(MEM_ROOT *, plugin::Handle *,
156
157
                               int *, char **);
157
 
static bool register_builtin(plugin::Handle *,
 
158
static bool register_builtin(PluginRegistry &registry,
 
159
                             plugin::Handle *,
158
160
                             plugin::Handle **);
159
161
static void unlock_variables(Session *session, struct system_variables *vars);
160
162
static void cleanup_variables(Session *session, struct system_variables *vars);
161
163
static void plugin_vars_free_values(sys_var *vars);
162
164
static void plugin_opt_set_limits(struct my_option *options,
163
165
                                  const struct st_mysql_sys_var *opt);
164
 
static void reap_plugins(void);
 
166
static void reap_plugins(PluginRegistry &plugins);
165
167
 
166
168
 
167
169
/* declared in set_var.cc */
412
414
  NOTE
413
415
    Requires that a write-lock is held on LOCK_system_variables_hash
414
416
*/
415
 
static bool plugin_add(MEM_ROOT *tmp_root,
 
417
static bool plugin_add(PluginRegistry &registry, MEM_ROOT *tmp_root,
416
418
                       const LEX_STRING *name, const LEX_STRING *dl,
417
419
                       int *argc, char **argv, int report)
418
420
{
419
 
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
420
 
 
421
421
  plugin::Manifest *manifest;
422
422
  if (! initialized)
423
423
    return(0);
473
473
}
474
474
 
475
475
 
476
 
static void plugin_del(plugin::Handle *plugin)
 
476
static void plugin_del(PluginRegistry &registry, plugin::Handle *plugin)
477
477
{
478
 
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
479
478
  if (plugin->isInited)
480
479
  {
481
480
    if (plugin->getManifest().status_vars)
498
497
  delete plugin;
499
498
}
500
499
 
501
 
static void reap_plugins(void)
 
500
static void reap_plugins(PluginRegistry &plugins)
502
501
{
503
502
  size_t count;
504
503
  uint32_t idx;
509
508
  for (idx= 0; idx < count; idx++)
510
509
  {
511
510
    plugin= *dynamic_element(&plugin_array, idx, drizzled::plugin::Handle **);
512
 
    plugin_del(plugin);
 
511
    plugin_del(plugins, plugin);
513
512
  }
514
513
  drizzle_del_plugin_sysvar();
515
514
}
516
515
 
517
 
static bool plugin_initialize(drizzled::plugin::Handle *plugin)
 
516
static bool plugin_initialize(PluginRegistry &registry,
 
517
                              drizzled::plugin::Handle *plugin)
518
518
{
519
519
  assert(plugin->isInited == false);
520
520
 
521
 
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
522
521
  if (plugin->getManifest().init)
523
522
  {
524
523
    if (plugin->getManifest().init(registry))
576
575
 
577
576
  Finally we initialize everything, aka the dynamic that have yet to initialize.
578
577
*/
579
 
int plugin_init(int *argc, char **argv, int flags)
 
578
int plugin_init(PluginRegistry &registry, int *argc, char **argv, int flags)
580
579
{
581
580
  uint32_t idx;
582
581
  plugin::Manifest **builtins;
618
617
      if (test_plugin_options(&tmp_root, handle, argc, argv))
619
618
        continue;
620
619
 
621
 
      if (register_builtin(handle, &handle))
 
620
      if (register_builtin(registry, handle, &handle))
622
621
        goto err_unlock;
623
622
 
624
 
      if (plugin_initialize(handle))
 
623
      if (plugin_initialize(registry, handle))
625
624
        goto err_unlock;
626
625
 
627
626
    }
632
631
  if (!(flags & PLUGIN_INIT_SKIP_DYNAMIC_LOADING))
633
632
  {
634
633
    if (opt_plugin_load)
635
 
      plugin_load_list(&tmp_root, argc, argv, opt_plugin_load);
 
634
      plugin_load_list(registry, &tmp_root, argc, argv, opt_plugin_load);
636
635
  }
637
636
 
638
637
  if (flags & PLUGIN_INIT_SKIP_INITIALIZATION)
646
645
    handle= *dynamic_element(&plugin_array, idx, plugin::Handle **);
647
646
    if (handle->isInited == false)
648
647
    {
649
 
      if (plugin_initialize(handle))
650
 
        plugin_del(handle);
 
648
      if (plugin_initialize(registry, handle))
 
649
        plugin_del(registry, handle);
651
650
    }
652
651
  }
653
652
 
664
663
}
665
664
 
666
665
 
667
 
static bool register_builtin(plugin::Handle *tmp,
 
666
static bool register_builtin(PluginRegistry &registry,
 
667
                             plugin::Handle *tmp,
668
668
                             plugin::Handle **ptr)
669
669
{
670
670
 
671
 
  PluginRegistry &registry= PluginRegistry::getPluginRegistry();
672
 
 
673
671
  tmp->isInited= false;
674
672
  tmp->plugin_dl= 0;
675
673
 
688
686
/*
689
687
  called only by plugin_init()
690
688
*/
691
 
static bool plugin_load_list(MEM_ROOT *tmp_root, int *argc, char **argv,
 
689
static bool plugin_load_list(PluginRegistry &plugins,
 
690
                             MEM_ROOT *tmp_root, int *argc, char **argv,
692
691
                             const char *list)
693
692
{
694
693
  char buffer[FN_REFLEN];
728
727
            name.length= strlen(name.str);
729
728
 
730
729
            free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
731
 
            if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
 
730
            if (plugin_add(plugins, tmp_root, &name, &dl,
 
731
                           argc, argv, REPORT_TO_LOG))
732
732
              goto error;
733
733
          }
734
734
          plugin_dl_del(&dl); // reduce ref count
737
737
      else
738
738
      {
739
739
        free_root(tmp_root, MYF(MY_MARK_BLOCKS_FREE));
740
 
        if (plugin_add(tmp_root, &name, &dl, argc, argv, REPORT_TO_LOG))
 
740
        if (plugin_add(plugins, tmp_root, &name, &dl,
 
741
                       argc, argv, REPORT_TO_LOG))
741
742
          goto error;
742
743
      }
743
744
      name.length= dl.length= 0;
766
767
}
767
768
 
768
769
 
769
 
void plugin_shutdown(void)
 
770
void plugin_shutdown(PluginRegistry &registry)
770
771
{
771
772
  uint32_t idx;
772
773
  size_t count= plugin_array.elements;
777
778
  {
778
779
    reap_needed= true;
779
780
 
780
 
    reap_plugins();
 
781
    reap_plugins(registry);
781
782
    unlock_variables(NULL, &global_system_variables);
782
783
    unlock_variables(NULL, &max_system_variables);
783
784