Esempio n. 1
0
int
main(int argc, char** argv)
{
	rofl::cunixenv env_parser(argc, argv);

	/* update defaults */
	env_parser.add_option(rofl::coption(true,REQUIRED_ARGUMENT,'l',"logfile","Log file used when daemonization", ETHSWCTLD_LOG_FILE));
	env_parser.add_option(rofl::coption(true, REQUIRED_ARGUMENT, 'p', "pidfile", "set pid-file", std::string(ETHSWCTLD_PID_FILE)));

	//Parse
	env_parser.parse_args();

	if (not env_parser.is_arg_set("daemonize")) {
		// only do this in non
		std::string ident(env_parser.get_arg("logfile"));

		rofl::logging::init();
		rofl::logging::set_debug_level(atoi(env_parser.get_arg("debug").c_str()));
	} else {

		rofl::cdaemon::daemonize(env_parser.get_arg("pidfile"), env_parser.get_arg("logfile"));
		rofl::logging::set_debug_level(atoi(env_parser.get_arg("debug").c_str()));
		rofl::logging::notice << "[proxyd][main] daemonizing successful" << std::endl;
	}

	rofl::examples::proxy::ccontrol ctl;

	rofl::cioloop::get_loop().run();

	rofl::cioloop::get_loop().shutdown();

	return 0;
}
//
// generate_shell_script
//
void Set_Classpath_Script_Generator::
generate_sh_script (const std::string & bindir)
{
  std::string sh_filename = bindir + "/set_classpath.sh";

  std::ofstream sh_file;
  sh_file.open (sh_filename.c_str ());

  if (sh_file.is_open ())
  {
    sh_file
      << "#!/bin/bash" << std::endl
      << std::endl
      << sh_header << std::endl
      << "BIN_DIR=`dirname $0`" << std::endl
      << "LIB_DIR=${BIN_DIR}/../lib" << std::endl
      << std::endl
      << "export CLASSPATH=";

    std::set <std::string>::const_iterator
      iter = this->impls_.begin (), iter_end = this->impls_.end ();

    for ( ; iter != iter_end; ++ iter)
    {
      sh_file
        << "${LIB_DIR}/" << *iter << ".jar:";
    }

    // We need to prepend te jarfiles that were used to build the application
    // level components. This usually includes the worker libraries.
    std::string output;
    CUTS_BE_Env_Variable_Parser_T <Sh_Env_Variable> env_parser (output);

    iter = this->lit_jars_.begin ();
    iter_end = this->lit_jars_.end ();

    for ( ; iter != iter_end; ++ iter)
    {
      // Convert any environment variables defined in the JAR file.
      if (boost::spirit::parse (iter->c_str (), env_parser).full)
        sh_file << output << ":";
      else
        sh_file << *iter << ":";
    }

    // Prepend the current classpath to the variable.
    sh_file
      << "${LIB_DIR}/jbi.eventtypes.jar:${CLASSPATH}" << std::endl;

    // Close the file
    sh_file.close ();
  }
  else
  {
    // print an error
  }
}
//
// generate_batch_file
//
void Set_Classpath_Script_Generator::
generate_bat_script (const std::string & bindir)
{
  std::string bat_filename = bindir + "\\set_classpath.bat";

  std::ofstream bat_file;
  bat_file.open (bat_filename.c_str ());

  if (bat_file.is_open ())
  {
    bat_file
      << bat_header << std::endl
      << "@set CLASSPATH=";

    std::set <std::string>::const_iterator
      iter = this->impls_.begin (), iter_end = this->impls_.end ();

    for ( ; iter != iter_end; ++ iter)
    {
      bat_file
        << "%~dp0..\\lib\\" << *iter << ".jar;";
    }

    // We need to prepend te jarfiles that were used to build the application
    // level components. This usually includes the worker libraries.
    std::string output;
    CUTS_BE_Env_Variable_Parser_T <Bat_Env_Variable> env_parser (output);

    iter = this->lit_jars_.begin ();
    iter_end = this->lit_jars_.end ();

    for ( ; iter != iter_end; ++ iter)
    {
      // Convert any environment variables defined in the JAR file.
      if (boost::spirit::parse (iter->c_str (), env_parser).full)
        bat_file << output << ";";
      else
        bat_file << *iter << ";";
    }

    // Prepend the current classpath to the variable.
    bat_file
      << "%~dp0..\\lib\\jbi.eventtypes.jar;%CLASSPATH%" << std::endl;

    // Close the file
    bat_file.close ();
  }
  else
  {
    // print an error
  }
}