~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/module/loader.cc

update

Show diffs side-by-side

added added

removed removed

Lines of Context:
70
70
  PANDORA_BUILTIN_LOAD_SYMBOLS_LIST, NULL
71
71
};
72
72
 
73
 
namespace drizzled
74
 
{
 
73
namespace drizzled {
75
74
 
76
75
 
77
76
typedef vector<string> PluginOptions;
166
165
    return false;
167
166
  }
168
167
 
169
 
  module::Module *tmp= NULL;
170
168
  /* Find plugin by name */
171
169
  const module::Manifest *manifest= library->getManifest();
172
170
 
180
178
    return true;
181
179
  }
182
180
 
183
 
  tmp= new (std::nothrow) module::Module(manifest, library);
 
181
  module::Module* tmp= new (std::nothrow) module::Module(manifest, library);
184
182
  if (tmp == NULL)
185
183
    return true;
186
184
 
197
195
 
198
196
static void reap_plugins(module::Registry &registry)
199
197
{
200
 
  std::map<std::string, module::Module *>::const_iterator modules=
201
 
    registry.getModulesMap().begin();
202
 
 
203
 
  while (modules != registry.getModulesMap().end())
204
 
  {
205
 
    module::Module *module= (*modules).second;
206
 
    delete module;
207
 
    ++modules;
208
 
  }
 
198
  BOOST_FOREACH(module::Registry::ModuleMap::const_reference module, registry.getModulesMap())
 
199
    delete module.second;
209
200
}
210
201
 
211
202
 
226
217
    }
227
218
  }
228
219
  module->isInited= true;
229
 
 
230
 
 
231
220
  return false;
232
221
}
233
222
 
234
 
 
235
 
inline static void dashes_to_underscores(std::string &name_in,
236
 
                                         char from= '-', char to= '_')
237
 
{
238
 
  for (string::iterator p= name_in.begin();
239
 
       p != name_in.end();
240
 
       ++p)
241
 
  {
242
 
    if (*p == from)
243
 
    {
244
 
      *p= to;
245
 
    }
246
 
  }
247
 
}
248
 
 
249
 
inline static void underscores_to_dashes(std::string &name_in)
250
 
{
251
 
  return dashes_to_underscores(name_in, '_', '-');
252
 
}
253
 
 
254
223
static void compose_plugin_options(vector<string> &target,
255
224
                                   vector<string> options)
256
225
{
257
 
  for (vector<string>::iterator it= options.begin();
258
 
       it != options.end();
259
 
       ++it)
260
 
  {
261
 
    tokenize(*it, target, ",", true);
262
 
  }
263
 
  for (vector<string>::iterator it= target.begin();
264
 
       it != target.end();
265
 
       ++it)
266
 
  {
267
 
    dashes_to_underscores(*it);
268
 
  }
 
226
  BOOST_FOREACH(vector<string>::reference it, options)
 
227
    tokenize(it, target, ",", true);
 
228
  BOOST_FOREACH(vector<string>::reference it, target)
 
229
    std::replace(it.begin(), it.end(), '-', '_');
269
230
}
270
231
 
271
232
void compose_plugin_add(vector<string> options)
293
254
bool plugin_init(module::Registry &registry,
294
255
                 po::options_description &long_options)
295
256
{
296
 
  memory::Root tmp_root(4096);
297
 
 
298
257
  if (initialized)
299
258
    return false;
300
259
 
301
 
  initialized= 1;
 
260
  initialized= true;
302
261
 
303
262
  PluginOptions builtin_load_list;
304
263
  tokenize(builtin_load_plugins, builtin_load_list, ",", true);
332
291
    plugin_prune_list(builtin_load_list, opt_plugin_remove);
333
292
  }
334
293
 
335
 
 
 
294
  memory::Root tmp_root(4096);
336
295
  /*
337
296
    First we register builtin plugins
338
297
  */
369
328
  /*
370
329
    Now we initialize all remaining plugins
371
330
  */
372
 
  module::Registry::ModuleList module_list= registry.getList();
373
 
  module::Registry::ModuleList::iterator modules= module_list.begin();
374
 
    
375
 
  while (modules != module_list.end())
 
331
  BOOST_FOREACH(module::Registry::ModuleList::const_reference module, registry.getList())
376
332
  {
377
 
    module::Module *module= *modules;
378
 
    ++modules;
379
 
    if (module->isInited == false)
 
333
    if (not module->isInited && plugin_initialize(registry, module))
380
334
    {
381
 
      if (plugin_initialize(registry, module))
382
 
      {
383
 
        registry.remove(module);
384
 
        delete module;
385
 
        return true;
386
 
      }
 
335
      registry.remove(module);
 
336
      delete module;
 
337
      return true;
387
338
    }
388
339
  }
389
 
 
390
 
 
391
340
  BOOST_FOREACH(plugin::Plugin::map::value_type value, registry.getPluginsMap())
392
341
  {
393
342
    value.second->prime();
394
343
  }
395
 
 
396
344
  return false;
397
345
}
398
346
 
447
395
                             po::options_description &long_options,
448
396
                             bool builtin)
449
397
{
450
 
  module::Library *library= NULL;
451
 
 
452
 
  for (set<string>::const_iterator iter= plugin_list.begin();
453
 
       iter != plugin_list.end();
454
 
       ++iter)
 
398
  BOOST_FOREACH(const string& plugin_name, plugin_list)
455
399
  {
456
 
    const string plugin_name(*iter);
457
 
 
458
 
    library= registry.addLibrary(plugin_name, builtin);
 
400
    module::Library* library= registry.addLibrary(plugin_name, builtin);
459
401
    if (library == NULL)
460
402
    {
461
403
      errmsg_printf(error::ERROR,
472
414
                    _("Couldn't load plugin named '%s'.\n"),
473
415
                    plugin_name.c_str());
474
416
      return true;
475
 
 
476
417
    }
477
418
  }
478
419
  return false;