~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/loader.cc

Merge Monty.

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
#include "drizzled/plugin/library.h"
42
42
#include "drizzled/strfunc.h"
43
43
#include "drizzled/pthread_globals.h"
 
44
#include "drizzled/util/tokenize.h"
44
45
 
45
46
/* FreeBSD 2.2.2 does not define RTLD_NOW) */
46
47
#ifndef RTLD_NOW
64
65
static vector<sys_var_pluginvar *> plugin_sysvar_vec;
65
66
 
66
67
char *opt_plugin_add= NULL;
 
68
char *opt_plugin_remove= NULL;
67
69
char *opt_plugin_load= NULL;
68
70
char *opt_plugin_dir_ptr;
69
71
char opt_plugin_dir[FN_REFLEN];
148
150
 
149
151
 
150
152
/* prototypes */
 
153
static void plugin_prune_list(vector<string> &plugin_list,
 
154
                              const vector<string> &plugins_to_remove);
151
155
static bool plugin_load_list(plugin::Registry &registry,
152
156
                             memory::Root *tmp_root, int *argc, char **argv,
153
 
                             string plugin_list);
 
157
                             const vector<string> &plugin_list);
154
158
static int test_plugin_options(memory::Root *, plugin::Module *,
155
159
                               int *, char **);
156
160
static void unlock_variables(Session *session, struct system_variables *vars);
432
436
 
433
437
 
434
438
  bool load_failed= false;
 
439
  vector<string> plugin_list;
 
440
  if (opt_plugin_load)
 
441
  {
 
442
    tokenize(opt_plugin_load, plugin_list, ",", true);
 
443
  }
 
444
  else
 
445
  {
 
446
    tokenize(opt_plugin_load_default, plugin_list, ",", true);
 
447
  }
 
448
  if (opt_plugin_add)
 
449
  {
 
450
    tokenize(opt_plugin_add, plugin_list, ",", true);
 
451
  }
 
452
 
 
453
  if (opt_plugin_remove)
 
454
  {
 
455
    vector<string> plugins_to_remove;
 
456
    tokenize(opt_plugin_remove, plugins_to_remove, ",", true);
 
457
    plugin_prune_list(plugin_list, plugins_to_remove);
 
458
  }
 
459
  
435
460
  /* Register all dynamic plugins */
436
 
  if (opt_plugin_load)
437
 
  {
438
 
    load_failed= plugin_load_list(registry, &tmp_root, argc, argv,
439
 
                                  opt_plugin_load);
440
 
  }
441
 
  else
442
 
  {
443
 
    string tmp_plugin_list(opt_plugin_load_default);
444
 
    if (opt_plugin_add)
445
 
    {
446
 
      tmp_plugin_list.push_back(',');
447
 
      tmp_plugin_list.append(opt_plugin_add);
448
 
    }
449
 
    load_failed= plugin_load_list(registry, &tmp_root, argc, argv,
450
 
                                  tmp_plugin_list);
451
 
  }
 
461
  load_failed= plugin_load_list(registry, &tmp_root, argc, argv,
 
462
                                plugin_list);
452
463
  if (load_failed)
453
464
  {
454
465
    free_root(&tmp_root, MYF(0));
486
497
  return false;
487
498
}
488
499
 
489
 
 
 
500
class PrunePlugin :
 
501
  public unary_function<string, bool>
 
502
{
 
503
  const string to_match;
 
504
  PrunePlugin();
 
505
  PrunePlugin& operator=(const PrunePlugin&);
 
506
public:
 
507
  explicit PrunePlugin(const string &match_in) :
 
508
    to_match(match_in)
 
509
  { }
 
510
 
 
511
  result_type operator()(const string &match_against)
 
512
  {
 
513
    return match_against == to_match;
 
514
  }
 
515
};
 
516
 
 
517
static void plugin_prune_list(vector<string> &plugin_list,
 
518
                              const vector<string> &plugins_to_remove)
 
519
{
 
520
  for (vector<string>::const_iterator iter= plugins_to_remove.begin();
 
521
       iter != plugins_to_remove.end();
 
522
       ++iter)
 
523
  {
 
524
    plugin_list.erase(remove_if(plugin_list.begin(),
 
525
                                plugin_list.end(),
 
526
                                PrunePlugin(*iter)),
 
527
                      plugin_list.end());
 
528
  }
 
529
}
490
530
 
491
531
/*
492
532
  called only by plugin_init()
493
533
*/
494
534
static bool plugin_load_list(plugin::Registry &registry,
495
535
                             memory::Root *tmp_root, int *argc, char **argv,
496
 
                             string plugin_list)
 
536
                             const vector<string> &plugin_list)
497
537
{
498
538
  plugin::Library *library= NULL;
499
539
 
500
 
  const string DELIMITER(",");
501
 
  string::size_type last_pos= plugin_list.find_first_not_of(DELIMITER);
502
 
  string::size_type pos= plugin_list.find_first_of(DELIMITER, last_pos);
503
 
  while (string::npos != pos || string::npos != last_pos)
 
540
  for (vector<string>::const_iterator iter= plugin_list.begin();
 
541
       iter != plugin_list.end();
 
542
       ++iter)
504
543
  {
505
 
    const string plugin_name(plugin_list.substr(last_pos, pos - last_pos));
506
 
 
 
544
    const string plugin_name(*iter);
507
545
    library= registry.addLibrary(plugin_name);
508
546
    if (library == NULL)
509
547
    {
523
561
      return true;
524
562
 
525
563
    }
526
 
    last_pos= plugin_list.find_first_not_of(DELIMITER, pos);
527
 
    pos= plugin_list.find_first_of(DELIMITER, last_pos);
528
564
  }
529
565
  return false;
530
566
}