mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
Split up OSK driver code into separate file osk_driver.c
This commit is contained in:
parent
f1196733b1
commit
2029e13e23
@ -100,6 +100,7 @@ OBJ += frontend/frontend.o \
|
||||
audio/audio_driver.o \
|
||||
input/input_driver.o \
|
||||
gfx/video_driver.o \
|
||||
osk_driver.o \
|
||||
driver.o \
|
||||
settings.o \
|
||||
settings_list.o \
|
||||
|
129
driver.c
129
driver.c
@ -40,80 +40,6 @@
|
||||
|
||||
driver_t driver;
|
||||
|
||||
static const input_osk_driver_t *osk_drivers[] = {
|
||||
#ifdef __CELLOS_LV2__
|
||||
&input_ps3_osk,
|
||||
#endif
|
||||
&input_null_osk,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* osk_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
static const void *osk_driver_find_handle(int index)
|
||||
{
|
||||
const void *drv = osk_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv;
|
||||
}
|
||||
|
||||
/**
|
||||
* osk_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
static const char *osk_driver_find_ident(int index)
|
||||
{
|
||||
const input_osk_driver_t *drv = osk_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->ident;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_get_osk_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
**/
|
||||
const char* config_get_osk_driver_options(void)
|
||||
{
|
||||
union string_list_elem_attr attr;
|
||||
unsigned i;
|
||||
char *options = NULL;
|
||||
int options_len = 0;
|
||||
struct string_list *options_l = string_list_new();
|
||||
|
||||
attr.i = 0;
|
||||
|
||||
for (i = 0; osk_driver_find_handle(i); i++)
|
||||
{
|
||||
const char *opt = osk_driver_find_ident(i);
|
||||
options_len += strlen(opt) + 1;
|
||||
string_list_append(options_l, opt, attr);
|
||||
}
|
||||
|
||||
options = (char*)calloc(options_len, sizeof(char));
|
||||
|
||||
string_list_join_concat(options, options_len, options_l, "|");
|
||||
|
||||
string_list_free(options_l);
|
||||
options_l = NULL;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
static const camera_driver_t *camera_drivers[] = {
|
||||
#ifdef HAVE_V4L2
|
||||
&camera_v4l2,
|
||||
@ -537,61 +463,6 @@ void find_next_driver(const char *label, char *str, size_t sizeof_str)
|
||||
RARCH_WARN("Couldn't find any next driver (current one: \"%s\").\n", str);
|
||||
}
|
||||
|
||||
/**
|
||||
* find_osk_driver:
|
||||
*
|
||||
* Find OSK (onscreen keyboard) driver.
|
||||
**/
|
||||
static void find_osk_driver(void)
|
||||
{
|
||||
int i = find_driver_index("osk_driver", g_settings.osk.driver);
|
||||
if (i >= 0)
|
||||
driver.osk = osk_driver_find_handle(i);
|
||||
else
|
||||
{
|
||||
unsigned d;
|
||||
RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n",
|
||||
g_settings.osk.driver);
|
||||
RARCH_LOG_OUTPUT("Available OSK drivers are:\n");
|
||||
for (d = 0; osk_driver_find_handle(d); d++)
|
||||
RARCH_LOG_OUTPUT("\t%s\n", osk_driver_find_ident(d));
|
||||
|
||||
RARCH_WARN("Going to default to first OSK driver...\n");
|
||||
|
||||
driver.osk = osk_driver_find_handle(0);
|
||||
|
||||
if (!driver.osk)
|
||||
rarch_fail(1, "find_osk_driver()");
|
||||
}
|
||||
}
|
||||
|
||||
static void init_osk(void)
|
||||
{
|
||||
/* Resource leaks will follow if osk is initialized twice. */
|
||||
if (driver.osk_data)
|
||||
return;
|
||||
|
||||
find_osk_driver();
|
||||
|
||||
/* FIXME - refactor params later based on semantics */
|
||||
driver.osk_data = driver.osk->init(0);
|
||||
|
||||
if (!driver.osk_data)
|
||||
{
|
||||
RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n");
|
||||
driver.osk_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
static void uninit_osk(void)
|
||||
{
|
||||
if (driver.osk_data && driver.osk && driver.osk->free)
|
||||
driver.osk->free(driver.osk_data);
|
||||
driver.osk_data = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void find_camera_driver(void)
|
||||
{
|
||||
int i = find_driver_index("camera_driver", g_settings.camera.driver);
|
||||
|
29
driver.h
29
driver.h
@ -31,6 +31,7 @@
|
||||
#include "audio/audio_driver.h"
|
||||
|
||||
#include "menu/menu_driver.h"
|
||||
#include "osk_driver.h"
|
||||
#include "audio/resamplers/resampler.h"
|
||||
#include "record/ffemu.h"
|
||||
|
||||
@ -160,20 +161,6 @@ enum analog_dpad_mode
|
||||
ANALOG_DPAD_LAST
|
||||
};
|
||||
|
||||
typedef struct input_osk_driver
|
||||
{
|
||||
void *(*init)(size_t size);
|
||||
void (*free)(void *data);
|
||||
bool (*enable_key_layout)(void *data);
|
||||
void (*oskutil_create_activation_parameters)(void *data);
|
||||
void (*write_msg)(void *data, const void *msg);
|
||||
void (*write_initial_msg)(void *data, const void *msg);
|
||||
bool (*start)(void *data);
|
||||
void (*lifecycle)(void *data, uint64_t status);
|
||||
void *(*get_text_buf)(void *data);
|
||||
const char *ident;
|
||||
} input_osk_driver_t;
|
||||
|
||||
typedef struct camera_driver
|
||||
{
|
||||
/* FIXME: params for initialization - queries for resolution,
|
||||
@ -615,17 +602,6 @@ const char* config_get_camera_driver_options(void);
|
||||
**/
|
||||
const char* config_get_video_driver_options(void);
|
||||
|
||||
/**
|
||||
* config_get_osk_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
**/
|
||||
const char* config_get_osk_driver_options(void);
|
||||
|
||||
/**
|
||||
* config_get_location_driver_options:
|
||||
*
|
||||
@ -672,9 +648,6 @@ extern location_driver_t location_apple;
|
||||
extern location_driver_t location_android;
|
||||
extern location_driver_t location_null;
|
||||
|
||||
extern input_osk_driver_t input_ps3_osk;
|
||||
extern input_osk_driver_t input_null_osk;
|
||||
|
||||
extern rarch_joypad_driver_t *joypad_drivers[];
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -499,6 +499,7 @@ DRIVERS
|
||||
#include "../gfx/video_driver.c"
|
||||
#include "../input/input_driver.c"
|
||||
#include "../audio/audio_driver.c"
|
||||
#include "../osk_driver.c"
|
||||
#include "../driver.c"
|
||||
|
||||
/*============================================================
|
||||
|
148
osk_driver.c
Normal file
148
osk_driver.c
Normal file
@ -0,0 +1,148 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <string/string_list.h>
|
||||
#include "osk_driver.h"
|
||||
#include "driver.h"
|
||||
#include "general.h"
|
||||
|
||||
static const input_osk_driver_t *osk_drivers[] = {
|
||||
#ifdef __CELLOS_LV2__
|
||||
&input_ps3_osk,
|
||||
#endif
|
||||
&input_null_osk,
|
||||
NULL,
|
||||
};
|
||||
|
||||
/**
|
||||
* osk_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const void *osk_driver_find_handle(int index)
|
||||
{
|
||||
const void *drv = osk_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv;
|
||||
}
|
||||
|
||||
/**
|
||||
* osk_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const char *osk_driver_find_ident(int index)
|
||||
{
|
||||
const input_osk_driver_t *drv = osk_drivers[index];
|
||||
if (!drv)
|
||||
return NULL;
|
||||
return drv->ident;
|
||||
}
|
||||
|
||||
/**
|
||||
* config_get_osk_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
**/
|
||||
const char* config_get_osk_driver_options(void)
|
||||
{
|
||||
union string_list_elem_attr attr;
|
||||
unsigned i;
|
||||
char *options = NULL;
|
||||
int options_len = 0;
|
||||
struct string_list *options_l = string_list_new();
|
||||
|
||||
attr.i = 0;
|
||||
|
||||
for (i = 0; osk_driver_find_handle(i); i++)
|
||||
{
|
||||
const char *opt = osk_driver_find_ident(i);
|
||||
options_len += strlen(opt) + 1;
|
||||
string_list_append(options_l, opt, attr);
|
||||
}
|
||||
|
||||
options = (char*)calloc(options_len, sizeof(char));
|
||||
|
||||
string_list_join_concat(options, options_len, options_l, "|");
|
||||
|
||||
string_list_free(options_l);
|
||||
options_l = NULL;
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
/**
|
||||
* find_osk_driver:
|
||||
*
|
||||
* Find OSK (onscreen keyboard) driver.
|
||||
**/
|
||||
void find_osk_driver(void)
|
||||
{
|
||||
int i = find_driver_index("osk_driver", g_settings.osk.driver);
|
||||
if (i >= 0)
|
||||
driver.osk = osk_driver_find_handle(i);
|
||||
else
|
||||
{
|
||||
unsigned d;
|
||||
RARCH_ERR("Couldn't find any OSK driver named \"%s\"\n",
|
||||
g_settings.osk.driver);
|
||||
RARCH_LOG_OUTPUT("Available OSK drivers are:\n");
|
||||
for (d = 0; osk_driver_find_handle(d); d++)
|
||||
RARCH_LOG_OUTPUT("\t%s\n", osk_driver_find_ident(d));
|
||||
|
||||
RARCH_WARN("Going to default to first OSK driver...\n");
|
||||
|
||||
driver.osk = osk_driver_find_handle(0);
|
||||
|
||||
if (!driver.osk)
|
||||
rarch_fail(1, "find_osk_driver()");
|
||||
}
|
||||
}
|
||||
|
||||
void init_osk(void)
|
||||
{
|
||||
/* Resource leaks will follow if osk is initialized twice. */
|
||||
if (driver.osk_data)
|
||||
return;
|
||||
|
||||
find_osk_driver();
|
||||
|
||||
/* FIXME - refactor params later based on semantics */
|
||||
driver.osk_data = driver.osk->init(0);
|
||||
|
||||
if (!driver.osk_data)
|
||||
{
|
||||
RARCH_ERR("Failed to initialize OSK driver. Will continue without OSK.\n");
|
||||
driver.osk_active = false;
|
||||
}
|
||||
}
|
||||
|
||||
void uninit_osk(void)
|
||||
{
|
||||
if (driver.osk_data && driver.osk && driver.osk->free)
|
||||
driver.osk->free(driver.osk_data);
|
||||
driver.osk_data = NULL;
|
||||
}
|
89
osk_driver.h
Normal file
89
osk_driver.h
Normal file
@ -0,0 +1,89 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||
*
|
||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||
* of the GNU General Public License as published by the Free Software Found-
|
||||
* ation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||
* PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __OSK_DRIVER__H
|
||||
#define __OSK_DRIVER__H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <boolean.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct input_osk_driver
|
||||
{
|
||||
void *(*init)(size_t size);
|
||||
void (*free)(void *data);
|
||||
bool (*enable_key_layout)(void *data);
|
||||
void (*oskutil_create_activation_parameters)(void *data);
|
||||
void (*write_msg)(void *data, const void *msg);
|
||||
void (*write_initial_msg)(void *data, const void *msg);
|
||||
bool (*start)(void *data);
|
||||
void (*lifecycle)(void *data, uint64_t status);
|
||||
void *(*get_text_buf)(void *data);
|
||||
const char *ident;
|
||||
} input_osk_driver_t;
|
||||
|
||||
/**
|
||||
* osk_driver_find_handle:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: handle to OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const void *osk_driver_find_handle(int index);
|
||||
|
||||
/**
|
||||
* osk_driver_find_ident:
|
||||
* @index : index of driver to get handle to.
|
||||
*
|
||||
* Returns: Human-readable identifier of OSK driver at index. Can be NULL
|
||||
* if nothing found.
|
||||
**/
|
||||
const char *osk_driver_find_ident(int index);
|
||||
|
||||
/**
|
||||
* config_get_osk_driver_options:
|
||||
*
|
||||
* Get an enumerated list of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
*
|
||||
* Returns: string listing of all OSK (onscreen keyboard) driver names,
|
||||
* separated by '|'.
|
||||
**/
|
||||
const char* config_get_osk_driver_options(void);
|
||||
|
||||
/**
|
||||
* find_osk_driver:
|
||||
*
|
||||
* Find OSK (onscreen keyboard) driver.
|
||||
**/
|
||||
void find_osk_driver(void);
|
||||
|
||||
void init_osk(void);
|
||||
|
||||
void uninit_osk(void);
|
||||
|
||||
extern input_osk_driver_t input_ps3_osk;
|
||||
extern input_osk_driver_t input_null_osk;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user