static message_id apply(message_id x) {
   CAF_IGNORE_UNUSED(x);
   auto result = make_message_id(message_id::upstream_message_category
                                 << message_id::category_offset);
   CAF_ASSERT(x.is_async() || x == result);
   return result;
 }
Exemple #2
0
void logger::init(actor_system_config& cfg) {
  CAF_IGNORE_UNUSED(cfg);
#if CAF_LOG_LEVEL >= 0
  namespace lg = defaults::logger;
  component_filter = get_or(cfg, "logger.component-filter",
                            lg::component_filter);
  // Parse the configured log level.
  auto verbosity = get_or(cfg, "logger.verbosity", lg::verbosity);
  switch (static_cast<uint64_t>(verbosity)) {
    case atom_uint("quiet"):
    case atom_uint("QUIET"):
      level_ = CAF_LOG_LEVEL_QUIET;
      break;
    case atom_uint("error"):
    case atom_uint("ERROR"):
      level_ = CAF_LOG_LEVEL_ERROR;
      break;
    case atom_uint("warning"):
    case atom_uint("WARNING"):
      level_ = CAF_LOG_LEVEL_WARNING;
      break;
    case atom_uint("info"):
    case atom_uint("INFO"):
      level_ = CAF_LOG_LEVEL_INFO;
      break;
    case atom_uint("debug"):
    case atom_uint("DEBUG"):
      level_ = CAF_LOG_LEVEL_DEBUG;
      break;
    case atom_uint("trace"):
    case atom_uint("TRACE"):
      level_ = CAF_LOG_LEVEL_TRACE;
      break;
    default: {
      // nop
    }
  }
  // Parse the format string.
  file_format_ = parse_format(get_or(cfg, "logger.file-format",
                                     lg::file_format));
  console_format_ = parse_format(get_or(cfg,"logger.console-format",
                                        lg::console_format));
  // Set flags.
  if (get_or(cfg, "logger.inline-output", false))
    set(inline_output_flag);
  auto con_atm = get_or(cfg, "logger.console", lg::console);
  if (con_atm == atom("UNCOLORED"))
    set(uncolored_console_flag);
  else if (con_atm == atom("COLORED"))
    set(colored_console_flag);
#endif
}
int exec_main(F fun, int argc, char** argv,
              const char* config_file_name = "caf-application.ini") {
  using trait = typename detail::get_callable_trait<F>::type;
  using arg_types = typename trait::arg_types;
  static_assert(detail::tl_size<arg_types>::value == 1
                || detail::tl_size<arg_types>::value == 2,
                "main function must have one or two arguments");
  static_assert(std::is_same<
                  typename detail::tl_head<arg_types>::type,
                  actor_system&
                >::value,
                "main function must take actor_system& as first parameter");
  using arg2 = typename detail::tl_at<arg_types, 1>::type;
  using decayed_arg2 = typename std::decay<arg2>::type;
  static_assert(std::is_same<arg2, unit_t>::value
                || (std::is_base_of<actor_system_config, decayed_arg2>::value
                    && std::is_same<arg2, const decayed_arg2&>::value),
                "second parameter of main function must take a subtype of "
                "actor_system_config as const reference");
  using helper = exec_main_helper<typename trait::arg_types>;
  // pass CLI options to config
  typename helper::config cfg;
  cfg.parse(argc, argv, config_file_name);
  // return immediately if a help text was printed
  if (cfg.cli_helptext_printed)
    return 0;
  // load modules
  std::initializer_list<unit_t> unused{unit_t{cfg.template load<Ts>()}...};
  CAF_IGNORE_UNUSED(unused);
  // pass config to the actor system
  actor_system system{cfg};
  if (cfg.slave_mode) {
    if (! cfg.slave_mode_fun) {
      std::cerr << "cannot run slave mode, I/O module not loaded" << std::endl;
      return 1;
    }
    return cfg.slave_mode_fun(system, cfg);
  }
  helper f;
  f(fun, system, cfg);
  return 0;
}
Exemple #4
0
void manager::io_failure(execution_unit* ctx, operation op) {
  CAF_LOG_TRACE(CAF_ARG(op));
  CAF_IGNORE_UNUSED(op);
  detach(ctx, true);
}