Exemple #1
0
void Module::Start()
{

  if (d->moduleContext)
  {
    US_WARN << "Module " << d->info.name << " already started.";
    return;
  }

  d->moduleContext = new ModuleContext(this->d);

//  try
//  {
    d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::LOADING, this));
    // try to get a ModuleActivator instance
    if (d->info.activatorHook)
    {
      try
      {
        d->moduleActivator = d->info.activatorHook();
      }
      catch (...)
      {
        US_ERROR << "Creating the module activator of " << d->info.name << " failed";
        throw;
      }

      d->moduleActivator->Load(d->moduleContext);
    }

    d->StartStaticModules();

#ifdef US_ENABLE_AUTOLOADING_SUPPORT
    if (ModuleSettings::IsAutoLoadingEnabled())
    {
      AutoLoadModules(d->info);
    }
#endif

    d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::LOADED, this));
//  }
//  catch (...)
//  {
//    d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::UNLOADING, this));
//    d->RemoveModuleResources();

//    delete d->moduleContext;
//    d->moduleContext = 0;

//    d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::UNLOADED, this));
//    US_ERROR << "Calling the module activator Load() method of " << d->info.name << " failed!";
//    throw;
//  }
}
Exemple #2
0
void Module::Start()
{

  if (d->moduleContext)
  {
    US_WARN << "Module " << d->info.name << " already started.";
    return;
  }

  d->moduleContext = new ModuleContext(this->d);

  typedef ModuleActivator*(*ModuleActivatorHook)(void);
  ModuleActivatorHook activatorHook = nullptr;

  std::string activator_func = "_us_module_activator_instance_" + d->info.name;
  void* activatorHookSym = ModuleUtils::GetSymbol(d->info, activator_func.c_str());
  std::memcpy(&activatorHook, &activatorHookSym, sizeof(void*));

  d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::LOADING, this));
  // try to get a ModuleActivator instance

  if (activatorHook)
  {
    try
    {
      d->moduleActivator = activatorHook();
    }
    catch (...)
    {
      US_ERROR << "Creating the module activator of " << d->info.name << " failed";
      throw;
    }

    // This method should be "noexcept" and by not catching exceptions
    // here we semantically treat it that way since any exception during
    // static initialization will either terminate the program or cause
    // the dynamic loader to report an error.
    d->moduleActivator->Load(d->moduleContext);
  }

#ifdef US_ENABLE_AUTOLOADING_SUPPORT
  if (ModuleSettings::IsAutoLoadingEnabled())
  {
    const std::vector<std::string> loadedPaths = AutoLoadModules(d->info);
    if (!loadedPaths.empty())
    {
      d->moduleManifest.SetValue(PROP_AUTOLOADED_MODULES(), Any(loadedPaths));
    }
  }
#endif

  d->coreCtx->listeners.ModuleChanged(ModuleEvent(ModuleEvent::LOADED, this));
}