コード例 #1
0
  /** Constructor.
   * Initializes and starts the embedded Fawkes, and loads the nao plugin
   * without precondition.
   * @param broker NaoQi broker to use, will be forwarded to the nao plugin
   * @param name name of the module (no idea why NaoQi wants to pass it
   * as a parameter)
   */
  NaoFawkesModule(AL::ALPtr<AL::ALBroker> broker, const std::string &name)
    : AL::ALModule(broker, name), broker(broker)
  {
    setModuleDescription("Fawkes integration module");

    AL::ALPtr<AL::ALLoggerProxy> logger = broker->getLoggerProxy();

    try {
      logger->info("NaoQiFawkes", "*** Initializing embedded Fawkes");

      // The module flags hack is required because otherwise NaoQi segfaults
      // due to problems with boost static initialization after a module
      // has been closed once, unfortunately that prevents loading a
      // new version of a plugin without a restart.

      fawkes::runtime::InitOptions init_options = 
	fawkes::runtime::InitOptions("naofawkes")
	.plugin_module_flags(fawkes::Module::MODULE_FLAGS_DEFAULT |
			     fawkes::Module::MODULE_NODELETE)
	.net_service_name("NaoQi Fawkes on %h")
        .loggers("console;syslog:NaoQiFawkes")
	.load_plugins("naoqi,webview")
        .default_plugin("nao_default");

      if (fawkes::runtime::init(init_options) != 0) {
	//throw AL::ALError(name, "ctor", "Initializing Fawkes failed");
	logger->info("NaoQiFawkes", "--- Fawkes initialization failed");
        play_sound(RESDIR"/sounds/naoshutdown.wav");
      } else {

	logger->info("NaoQiFawkes", "*** Starting embedded Fawkes");
	fawkes::runtime::main_thread->full_start();
        logger->info("NaoQiFawkes", "*** Embedded Fawkes initialization done");
        play_sound(RESDIR"/sounds/naostartup.wav");
      }
    } catch (fawkes::Exception &e) {
      std::string message;
      for (fawkes::Exception::iterator i = e.begin(); i != e.end(); ++i) {
        if (i != e.begin())  message += "\n";
        message += *i;
      }
      logger->info("NaoQiFawkes",
                   "--- Fawkes initialization failed, exception follows.");
      logger->info("NaoQiFawkes", message);
      play_sound(RESDIR"/sounds/naoshutdown.wav");
      //throw AL::ALError(name, "ctor", e.what());
    }

  }
コード例 #2
0
int
_createModule(AL::ALPtr<AL::ALBroker> broker)
{      
  // init broker with the main broker inctance 
  // from the parent executable

  AL::ALPtr<AL::ALLoggerProxy> logger = broker->getLoggerProxy();

  logger->info("NaoQiFawkes", "*** Setting broker stuff");
  AL::ALBrokerManager::setInstance(broker->fBrokerManager.lock());
  AL::ALBrokerManager::getInstance()->addBroker(broker);

  fawkes::naoqi::broker = broker;
    
  // create modules instance
  logger->info("NaoQiFawkes", "*** Instantiating Module");
  AL::ALModule::createModule<NaoFawkesModule>(broker, "NaoFawkesModule");

  return 0;
}