Exemplo n.º 1
0
rarch_remote_t *rarch_remote_new(uint16_t port)
{
   unsigned user;
#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
   settings_t   *settings = config_get_ptr();
#endif
   rarch_remote_t *handle = (rarch_remote_t*)
      calloc(1, sizeof(*handle));

   if (!handle)
      return NULL;

   (void)port;

#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
   for(user = 0; user < settings->input.max_users; user ++)
   {
      handle->net_fd[user] = -1;
      if(settings->network_remote_enable_user[user])
         if (!remote_init_network(handle, port, user))
            goto error;
   }
#endif

   return handle;

#if defined(HAVE_NETWORK_GAMEPAD) && defined(HAVE_NETPLAY)
error:
   rarch_remote_free(handle);
   return NULL;
#endif
}
Exemplo n.º 2
0
bool input_driver_ctl(enum rarch_input_ctl_state state, void *data)
{
   static bool input_driver_block_hotkey             = false;
   static bool input_driver_block_libretro_input     = false;
   static bool input_driver_osk_enabled              = false;
   static bool input_driver_keyboard_linefeed_enable = false;
   static bool input_driver_nonblock_state           = false;
   static bool input_driver_flushing_input           = false;
   static bool input_driver_data_own                 = false;

   switch (state)
   {
      case RARCH_INPUT_CTL_KEY_PRESSED:
         {
            unsigned *key = (unsigned*)data;
            if (key && current_input->key_pressed)
               return current_input->key_pressed(current_input_data, *key);
         }
         return false;
      case RARCH_INPUT_CTL_HAS_CAPABILITIES:
         if (!current_input->get_capabilities || !current_input_data)
            return false;
         break;
      case RARCH_INPUT_CTL_POLL:
         current_input->poll(current_input_data);
         break;
      case RARCH_INPUT_CTL_INIT:
         if (current_input)
            current_input_data = current_input->init();

         if (!current_input_data)
            return false;
         break;
      case RARCH_INPUT_CTL_DEINIT:
         if (current_input && current_input->free)
            current_input->free(current_input_data);
         current_input_data = NULL;
         break;
      case RARCH_INPUT_CTL_DESTROY_DATA:
         current_input_data = NULL;
         break;
      case RARCH_INPUT_CTL_DESTROY:
         input_driver_block_hotkey             = false;
         input_driver_block_libretro_input     = false;
         input_driver_keyboard_linefeed_enable = false;
         input_driver_nonblock_state           = false;
         input_driver_flushing_input           = false;
         input_driver_data_own                 = false;
         memset(&input_driver_turbo_btns, 0, sizeof(turbo_buttons_t));
         current_input                         = NULL;
         break;
      case RARCH_INPUT_CTL_GRAB_STDIN:
         if (!current_input->grab_stdin)
            return false;
         return current_input->grab_stdin(current_input_data);
      case RARCH_INPUT_CTL_KB_MAPPING_IS_BLOCKED:
         if (!current_input->keyboard_mapping_is_blocked)
            return false;
         return current_input->keyboard_mapping_is_blocked(
               current_input_data);
      case RARCH_INPUT_CTL_FIND_DRIVER:
         {
            int i;
            driver_ctx_info_t drv;
            settings_t *settings = config_get_ptr();

            drv.label = "input_driver";
            drv.s     = settings->input.driver;

            driver_ctl(RARCH_DRIVER_CTL_FIND_INDEX, &drv);

            i = drv.len;

            if (i >= 0)
               current_input = (const input_driver_t*)
                  input_driver_find_handle(i);
            else
            {
               unsigned d;
               RARCH_ERR("Couldn't find any input driver named \"%s\"\n",
                     settings->input.driver);
               RARCH_LOG_OUTPUT("Available input drivers are:\n");
               for (d = 0; input_driver_find_handle(d); d++)
                  RARCH_LOG_OUTPUT("\t%s\n", input_driver_find_ident(d));
               RARCH_WARN("Going to default to first input driver...\n");

               current_input = (const input_driver_t*)
                  input_driver_find_handle(0);

               if (current_input)
                  return true;
               retro_fail(1, "find_input_driver()");
               return false;
            }
         }
         break;
      case RARCH_INPUT_CTL_SET_FLUSHING_INPUT:
         input_driver_flushing_input = true;
         break;
      case RARCH_INPUT_CTL_UNSET_FLUSHING_INPUT:
         input_driver_flushing_input = false;
         break;
      case RARCH_INPUT_CTL_IS_FLUSHING_INPUT:
         return input_driver_flushing_input;
      case RARCH_INPUT_CTL_SET_HOTKEY_BLOCK:
         input_driver_block_hotkey = true;
         break;
      case RARCH_INPUT_CTL_UNSET_HOTKEY_BLOCK:
         input_driver_block_hotkey = false;
         break;
      case RARCH_INPUT_CTL_IS_HOTKEY_BLOCKED:
         return input_driver_block_hotkey;
      case RARCH_INPUT_CTL_SET_LIBRETRO_INPUT_BLOCKED:
         input_driver_block_libretro_input = true;
         break;
      case RARCH_INPUT_CTL_UNSET_LIBRETRO_INPUT_BLOCKED:
         input_driver_block_libretro_input = false;
         break;
      case RARCH_INPUT_CTL_IS_LIBRETRO_INPUT_BLOCKED:
         return input_driver_block_libretro_input;
      case RARCH_INPUT_CTL_SET_NONBLOCK_STATE:
         input_driver_nonblock_state = true;
         break;
      case RARCH_INPUT_CTL_UNSET_NONBLOCK_STATE:
         input_driver_nonblock_state = false;
         break;
      case RARCH_INPUT_CTL_IS_NONBLOCK_STATE:
         return input_driver_nonblock_state;
      case RARCH_INPUT_CTL_SET_OWN_DRIVER:
         input_driver_data_own = true;
         break;
      case RARCH_INPUT_CTL_UNSET_OWN_DRIVER:
         input_driver_data_own = false;
         break;
      case RARCH_INPUT_CTL_OWNS_DRIVER:
         return input_driver_data_own;
      case RARCH_INPUT_CTL_SET_OSK_ENABLED:
         input_driver_osk_enabled = true;
         break;
      case RARCH_INPUT_CTL_UNSET_OSK_ENABLED:
         input_driver_osk_enabled = false;
         break;
      case RARCH_INPUT_CTL_IS_OSK_ENABLED:
         return input_driver_osk_enabled;
      case RARCH_INPUT_CTL_SET_KEYBOARD_LINEFEED_ENABLED:
         input_driver_keyboard_linefeed_enable = true;
         break;
      case RARCH_INPUT_CTL_UNSET_KEYBOARD_LINEFEED_ENABLED:
         input_driver_keyboard_linefeed_enable = false;
         break;
      case RARCH_INPUT_CTL_IS_KEYBOARD_LINEFEED_ENABLED:
         return input_driver_keyboard_linefeed_enable;
      case RARCH_INPUT_CTL_COMMAND_INIT:
#ifdef HAVE_COMMAND
         input_driver_command_init();
#endif
         break;
      case RARCH_INPUT_CTL_COMMAND_DEINIT:
#ifdef HAVE_COMMAND
         if (input_driver_command)
            rarch_cmd_free(input_driver_command);
         input_driver_command = NULL;
#endif
         break;
      case RARCH_INPUT_CTL_REMOTE_DEINIT:
#ifdef HAVE_NETWORK_GAMEPAD
         if (input_driver_remote)
            rarch_remote_free(input_driver_remote);
         input_driver_remote = NULL;
#endif
         break;
      case RARCH_INPUT_CTL_REMOTE_INIT:
#ifdef HAVE_NETWORK_GAMEPAD
         input_driver_remote_init();
#endif
         break;
      case RARCH_INPUT_CTL_NONE:
      default:
         break;
   }

   return true;
}