Exemplo n.º 1
0
int main(int argc, char **argv)
{
    if(argc <= 1)
        usage();

    struct sb1_file_t *sb = create_sb1_file();

    struct cmd_line_next_arg_user_t u;
    u.argc = argc - 1;
    u.argv = argv + 1;
    int ret = apply_args(sb, &cmd_line_next_arg, &u);
    if(ret < 0)
    {
        sb1_free(sb);
        return ret;
    }

    if(!g_output_file)
        bug("You must specify an output file\n");
    if(!g_final)
    {
        if(g_strict)
            bug("There is no final command in this command stream!\n");
        else
            printf("Warning: there is no final command in this command stream!\n");
    }

    enum sb1_error_t err = sb1_write_file(sb, g_output_file);
    if(err != SB1_SUCCESS)
        printf("Error: %d\n", err);

    return ret;
}
Exemplo n.º 2
0
 void handle_results() {
   auto& map_fun = actor_facade_->map_results_;
   auto msg = map_fun ? apply_args(map_fun,
                                   detail::get_indices(result_buffers_),
                                   result_buffers_)
                      : message_from_results{}(result_buffers_);
   handle_.deliver(std::move(msg));
 }
Exemplo n.º 3
0
 match_case::result invoke(detail::invoke_result_visitor& f,
                           type_erased_tuple& xs) override {
   detail::meta_elements<pattern> ms;
   // check if try_match() reports success
   if (!detail::try_match(xs, ms.arr.data(), ms.arr.size()))
     return match_case::no_match;
   typename detail::il_indices<decayed_arg_types>::type indices;
   lfinvoker<std::is_same<result_type, void>::value, F> fun{fun_};
   message tmp;
   auto needs_detaching = is_manipulator && xs.shared();
   if (needs_detaching)
     tmp = message::copy(xs);
   intermediate_pseudo_tuple tup{needs_detaching ? tmp.content() : xs};
   auto fun_res = apply_args(fun, indices, tup);
   return f.visit(fun_res) ? match_case::match : match_case::skip;
 }
Exemplo n.º 4
0
 match_case::result invoke(optional<message>& res, message& msg) override {
   intermediate_tuple it;
   detail::meta_elements<pattern> ms;
   // check if try_match() reports success
   if (!detail::try_match(msg, ms.arr.data(), ms.arr.size(), it.data)) {
     return match_case::no_match;
   }
   // detach msg before invoking m_fun if needed
   if (is_manipulator) {
     msg.force_detach();
     // update pointers in our intermediate tuple
     for (size_t i = 0; i < msg.size(); ++i) {
       // msg is guaranteed to be detached, hence we don't need to
       // check this condition over and over again via mutable_at
       it[i] = const_cast<void*>(msg.at(i));
     }
   }
   lfinvoker<std::is_same<result_type, void>::value, F> fun{m_fun};
   detail::optional_message_visitor omv;
   auto funres = apply_args(fun, detail::get_indices(it), it);
   res = omv(funres);
   return match_case::match;
 }
Exemplo n.º 5
0
 // this function could as well be implemented in `match_case_impl`;
 // however, dealing with all the template parameters in a debugger
 // is just dreadful; this "hack" essentially hides all the ugly
 // template boilterplate types when debugging CAF applications
 match_case::result invoke(optional<message>& res, message& msg) override {
   struct storage {
     storage() : valid(false) {
       // nop
     }
     ~storage() {
       if (valid) {
         data.~tuple_type();
       }
     }
     union { tuple_type data; };
     bool valid;
   };
   storage st;
   if (prepare_invoke(msg, &st.data)) {
     st.valid = true;
     lfinvoker<std::is_same<result_type, void>::value, F> fun{m_fun};
     detail::optional_message_visitor omv;
     auto funres = apply_args(fun, detail::get_indices(st.data), st.data);
     res = omv(funres);
     return match_case::match;
   }
   return match_case::no_match;
 }
 void consume(std::tuple<Ts...>& x) {
   result_ += '(';
   apply_args(*this, get_indices(x), x);
   result_ += ')';
 }
 void operator()(std::tuple<Ts...>& xs) {
   apply_args(*this, get_indices(xs), xs);
 }
Exemplo n.º 8
0
void gmpv_mpv_initialize(GmpvMpv *mpv)
{
	GSettings *main_settings = g_settings_new(CONFIG_ROOT);
	gchar *config_dir = get_config_dir_path();
	gchar *mpvopt = NULL;
	gchar *current_vo = NULL;
	gchar *mpv_version = NULL;

	const struct
	{
		const gchar *name;
		const gchar *value;
	}
	options[] = {	{"osd-level", "1"},
			{"softvol", "yes"},
			{"force-window", "yes"},
			{"input-default-bindings", "yes"},
			{"audio-client-name", ICON_NAME},
			{"title", "${media-title}"},
			{"autofit-larger", "75%"},
			{"window-scale", "1"},
			{"pause", "no"},
			{"ytdl", "yes"},
			{"osd-bar", "no"},
			{"input-cursor", "no"},
			{"cursor-autohide", "no"},
			{"softvol-max", "100"},
			{"config", "yes"},
			{"screenshot-template", "gnome-mpv-shot%n"},
			{"config-dir", config_dir},
			{NULL, NULL} };

	g_assert(mpv->mpv_ctx);

	for(gint i = 0; options[i].name; i++)
	{
		g_debug(	"Applying default option --%s=%s",
				options[i].name,
				options[i].value );

		mpv_set_option_string(	mpv->mpv_ctx,
					options[i].name,
					options[i].value );
	}

	if(g_settings_get_boolean(main_settings, "mpv-config-enable"))
	{
		gchar *mpv_conf
			= g_settings_get_string
				(main_settings, "mpv-config-file");

		g_info("Loading config file: %s", mpv_conf);
		mpv_load_config_file(mpv->mpv_ctx, mpv_conf);

		g_free(mpv_conf);
	}

	if(g_settings_get_boolean(main_settings, "mpv-input-config-enable"))
	{
		gchar *input_conf
			= g_settings_get_string
				(main_settings, "mpv-input-config-file");

		g_info("Loading input config file: %s", input_conf);
		load_input_conf(mpv, input_conf);

		g_free(input_conf);
	}
	else
	{
		load_input_conf(mpv, NULL);
	}

	mpvopt = g_settings_get_string(main_settings, "mpv-options");

	g_debug("Applying extra mpv options: %s", mpvopt);

	/* Apply extra options */
	if(apply_args(mpv->mpv_ctx, mpvopt) < 0)
	{
		const gchar *msg
			= _("Failed to apply one or more MPV options.");

		g_signal_emit_by_name(mpv, "mpv-error", msg);
	}

	if(mpv->force_opengl || mpv->wid <= 0)
	{
		g_info("Forcing --vo=opengl-cb");
		mpv_set_option_string(mpv->mpv_ctx, "vo", "opengl-cb");

	}
	else
	{
		g_debug(	"Attaching mpv window to wid %#x",
				(guint)mpv->wid );

		mpv_set_option(mpv->mpv_ctx, "wid", MPV_FORMAT_INT64, &mpv->wid);
	}

	mpv_observe_property(mpv->mpv_ctx, 0, "aid", MPV_FORMAT_INT64);
	mpv_observe_property(mpv->mpv_ctx, 0, "chapters", MPV_FORMAT_INT64);
	mpv_observe_property(mpv->mpv_ctx, 0, "core-idle", MPV_FORMAT_FLAG);
	mpv_observe_property(mpv->mpv_ctx, 0, "fullscreen", MPV_FORMAT_FLAG);
	mpv_observe_property(mpv->mpv_ctx, 0, "pause", MPV_FORMAT_FLAG);
	mpv_observe_property(mpv->mpv_ctx, 0, "length", MPV_FORMAT_DOUBLE);
	mpv_observe_property(mpv->mpv_ctx, 0, "media-title", MPV_FORMAT_STRING);
	mpv_observe_property(mpv->mpv_ctx, 0, "playlist-pos", MPV_FORMAT_INT64);
	mpv_observe_property(mpv->mpv_ctx, 0, "track-list", MPV_FORMAT_NODE);
	mpv_observe_property(mpv->mpv_ctx, 0, "volume", MPV_FORMAT_DOUBLE);
	mpv_set_wakeup_callback(mpv->mpv_ctx, wakeup_callback, mpv);
	mpv_check_error(mpv_initialize(mpv->mpv_ctx));


	mpv_version = gmpv_mpv_get_property_string(mpv, "mpv-version");
	current_vo = gmpv_mpv_get_property_string(mpv, "current-vo");

	g_info("Using %s", mpv_version);

	if(current_vo && !GDK_IS_X11_DISPLAY(gdk_display_get_default()))
	{
		g_info(	"The chosen vo is %s but the display is not X11; "
			"forcing --vo=opengl-cb and resetting",
			current_vo );

		mpv->force_opengl = TRUE;
		mpv->state.paused = FALSE;

		gmpv_mpv_reset(mpv);
	}
	else
	{
		GSettings *win_settings;
		gdouble volume;

		win_settings = g_settings_new(CONFIG_WIN_STATE);
		volume = g_settings_get_double(win_settings, "volume")*100;

		g_debug("Setting volume to %f", volume);
		mpv_set_property(	mpv->mpv_ctx,
					"volume",
					MPV_FORMAT_DOUBLE,
					&volume );

		/* The vo should be opengl-cb if current_vo is NULL*/
		if(!current_vo)
		{
			mpv->opengl_ctx =	mpv_get_sub_api
						(	mpv->mpv_ctx,
							MPV_SUB_API_OPENGL_CB );
		}

		gmpv_mpv_opt_handle_msg_level(mpv);
		gmpv_mpv_opt_handle_fs(mpv);
		gmpv_mpv_opt_handle_geometry(mpv);

		mpv->force_opengl = FALSE;
		mpv->state.ready = TRUE;
		g_signal_emit_by_name(mpv, "mpv-init");

		g_clear_object(&win_settings);
	}

	g_clear_object(&main_settings);
	g_free(config_dir);
	g_free(mpvopt);
	mpv_free(current_vo);
	mpv_free(mpv_version);
}
Exemplo n.º 9
0
int
PingusMain::run(int argc, char** argv)
{
  g_logger.set_log_level(Logger::kWarning);

  tinygettext::Log::set_log_info_callback(0);

  try
  {
    // FIXME force set language using System::get_language() to get it from env
    dictionary_manager.set_language(tinygettext::Language::from_env(System::get_language()));
    
    parse_args(argc, argv); // here language and po dir isn't set, no traslation in command line
    init_path_finder(); // here init language path
    read_rc_file(); // here set language if ~/.pingus/config exist and language value is set
    apply_args(); // here set language if arg -l is specified
    
    print_greeting_message();
    
    // init the display
    FramebufferType fbtype = SDL_FRAMEBUFFER; 
    if (cmd_options.framebuffer_type.is_set())
    {
      fbtype = cmd_options.framebuffer_type.get();
    }

    bool fullscreen = cmd_options.fullscreen.is_set() ? cmd_options.fullscreen.get() : false;
    bool resizable  = cmd_options.resizable.is_set()  ? cmd_options.resizable.get()  : true;

    Size screen_size(800, 600);
    if (fullscreen)
    {
      if (cmd_options.fullscreen_resolution.is_set())
      {
        screen_size = cmd_options.fullscreen_resolution.get();
      }
    }
    else
    {
      if (cmd_options.geometry.is_set())
      {
        screen_size = cmd_options.geometry.get();
      }
    }

    SDLSystem system;
    try
    {
      system.create_window(fbtype, screen_size, fullscreen, resizable);
    }
    catch(const std::exception& err)
    {
      if (fbtype == SDL_FRAMEBUFFER)
      {
        throw;
      }
      else
      {
        log_error("couldn't create window, falling back to SDL: " << err.what());
        system.create_window(SDL_FRAMEBUFFER, screen_size, fullscreen, resizable);
        config_manager.set_renderer(SDL_FRAMEBUFFER);
      }
    }

    // init other components
    SavegameManager savegame_manager("savegames/savegames.scm");
    StatManager stat_manager("savegames/variables.scm");

    // FIXME: turn these into RAII 
    Resource::init();
    Fonts::init();
    Sound::PingusSound::init();
    
    config_manager.apply(cmd_options);

    // start and run the actual game
    start_game();
  }
  catch (const std::bad_alloc&) 
  {
    std::cout << _("Pingus: Out of memory!") << std::endl;
  }
  catch (const std::exception& a) 
  {
    std::cout << _("Pingus: Standard exception caught!:\n") << a.what() << std::endl;
  }
  catch (...) 
  {
    std::cout << _("Pingus: Unknown throw caught!") << std::endl;
  }

  Sound::PingusSound::deinit();
  Fonts::deinit();
  WorldObjFactory::deinit();
  Resource::deinit();

  return 0;
}