Skip to content

Commit cfb123f

Browse files
committed
Initial MCP server implementation
2 parents c4bb1bf + f724cc3 commit cfb123f

14 files changed

Lines changed: 117 additions & 87 deletions

Makefile.common

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,7 @@ endif
815815
ifeq ($(HAVE_LAKKA), 1)
816816
OBJ += network/drivers_wifi/connmanctl.o
817817
OBJ += misc/cpufreq/cpufreq.o
818+
LIBS += -lsystemd
818819
endif
819820

820821
ifeq ($(HAVE_WIFI), 1)

Makefile.ctr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ ASFLAGS := -g $(ARCH) -O3
200200
LDFLAGS += -specs=ctr/3dsx_custom.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)
201201
CFLAGS += -std=gnu99
202202

203+
CFLAGS += -ffunction-sections -fdata-sections
204+
LDFLAGS += -Wl,--gc-sections
205+
203206
LIB_CORE :=
204207
LIB_CORE_FULL :=
205208

command.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,8 +1351,12 @@ static size_t command_event_save_config(const char *config_path,
13511351
static size_t command_event_undo_save_state(char *s, size_t len)
13521352
{
13531353
if (content_undo_save_buf_is_empty())
1354-
return strlcpy(s,
1355-
msg_hash_to_str(MSG_NO_SAVE_STATE_HAS_BEEN_OVERWRITTEN_YET), len);
1354+
{
1355+
enum msg_hash_enums msg = content_undo_save_disabled()
1356+
? MSG_CORE_DOES_NOT_SUPPORT_SAVESTATE_UNDO
1357+
: MSG_NO_SAVE_STATE_HAS_BEEN_OVERWRITTEN_YET;
1358+
return strlcpy(s, msg_hash_to_str(msg), len);
1359+
}
13561360
if (!content_undo_save_state())
13571361
return strlcpy(s,
13581362
msg_hash_to_str(MSG_FAILED_TO_UNDO_SAVE_STATE), len);
@@ -1363,9 +1367,12 @@ static size_t command_event_undo_save_state(char *s, size_t len)
13631367
static size_t command_event_undo_load_state(char *s, size_t len)
13641368
{
13651369
if (content_undo_load_buf_is_empty())
1366-
return strlcpy(s,
1367-
msg_hash_to_str(MSG_NO_STATE_HAS_BEEN_LOADED_YET),
1368-
len);
1370+
{
1371+
enum msg_hash_enums msg = content_undo_save_disabled()
1372+
? MSG_CORE_DOES_NOT_SUPPORT_SAVESTATE_UNDO
1373+
: MSG_NO_STATE_HAS_BEEN_LOADED_YET;
1374+
return strlcpy(s, msg_hash_to_str(msg), len);
1375+
}
13691376
if (!content_undo_load_state())
13701377
return snprintf(s, len, "%s \"%s\".",
13711378
msg_hash_to_str(MSG_FAILED_TO_UNDO_LOAD_STATE),

configuration.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3080,7 +3080,7 @@ void config_set_defaults(void *data)
30803080
configuration_set_bool(settings,
30813081
settings->bools.ssh_enable, filestream_exists(LAKKA_SSH_PATH));
30823082
configuration_set_bool(settings,
3083-
settings->bools.samba_enable, filestream_exists(LAKKA_SAMBA_PATH));
3083+
settings->bools.samba_enable, !filestream_exists(LAKKA_SAMBA_DISABLED_FILE_PATH));
30843084
configuration_set_bool(settings,
30853085
settings->bools.bluetooth_enable, filestream_exists(LAKKA_BLUETOOTH_PATH));
30863086
configuration_set_bool(settings, settings->bools.localap_enable, false);
@@ -4450,7 +4450,7 @@ static bool config_load_file(global_t *global,
44504450
configuration_set_bool(settings,
44514451
settings->bools.ssh_enable, filestream_exists(LAKKA_SSH_PATH));
44524452
configuration_set_bool(settings,
4453-
settings->bools.samba_enable, filestream_exists(LAKKA_SAMBA_PATH));
4453+
settings->bools.samba_enable, !filestream_exists(LAKKA_SAMBA_DISABLED_FILE_PATH));
44544454
configuration_set_bool(settings,
44554455
settings->bools.bluetooth_enable, filestream_exists(LAKKA_BLUETOOTH_PATH));
44564456
#ifdef HAVE_RETROFLAG
@@ -5792,11 +5792,11 @@ bool config_save_file(const char *path)
57925792
else
57935793
filestream_delete(LAKKA_SSH_PATH);
57945794
if (settings->bools.samba_enable)
5795-
filestream_close(filestream_open(LAKKA_SAMBA_PATH,
5795+
filestream_delete(LAKKA_SAMBA_DISABLED_FILE_PATH);
5796+
else
5797+
filestream_close(filestream_open(LAKKA_SAMBA_DISABLED_FILE_PATH,
57965798
RETRO_VFS_FILE_ACCESS_WRITE,
57975799
RETRO_VFS_FILE_ACCESS_HINT_NONE));
5798-
else
5799-
filestream_delete(LAKKA_SAMBA_PATH);
58005800
if (settings->bools.bluetooth_enable)
58015801
filestream_close(filestream_open(LAKKA_BLUETOOTH_PATH,
58025802
RETRO_VFS_FILE_ACCESS_WRITE,

content.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,10 @@ bool content_init(void);
103103
/* Resets the state and savefile backup buffers */
104104
void content_reset_savestate_backups(void);
105105

106-
/* Checks if the buffers are empty */
106+
/* Checks if the buffers are empty, or undo feature is disabled */
107107
bool content_undo_load_buf_is_empty(void);
108108
bool content_undo_save_buf_is_empty(void);
109+
bool content_undo_save_disabled(void);
109110

110111
/* Clears the pending subsystem rom buffer */
111112
bool content_is_subsystem_pending_load(void);

intl/msg_hash_us.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14227,6 +14227,10 @@ MSG_HASH(
1422714227
MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES,
1422814228
"Core does not support save states."
1422914229
)
14230+
MSG_HASH(
14231+
MSG_CORE_DOES_NOT_SUPPORT_SAVESTATE_UNDO,
14232+
"Core does not support save state undo."
14233+
)
1423014234
MSG_HASH(
1423114235
MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS,
1423214236
"Core does not support Disc Control."

lakka.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
#ifndef __RARCH_LAKKA_H
1919
#define __RARCH_LAKKA_H
2020

21-
#define LAKKA_SSH_PATH "/storage/.cache/services/sshd.conf"
22-
#define LAKKA_SAMBA_PATH "/storage/.cache/services/samba.conf"
23-
#define LAKKA_BLUETOOTH_PATH "/storage/.cache/services/bluez.conf"
21+
#define LAKKA_SSH_PATH "/storage/.cache/services/sshd.conf"
22+
#define LAKKA_SAMBA_PATH "/storage/.cache/services/samba.conf"
23+
#define LAKKA_SAMBA_DISABLED_FILE_PATH "/storage/.cache/services/samba.disabled"
24+
#define LAKKA_BLUETOOTH_PATH "/storage/.cache/services/bluez.conf"
2425
#ifdef HAVE_RETROFLAG
25-
#define LAKKA_SAFESHUTDOWN_PATH "/storage/.cache/services/safeshutdown.conf"
26+
#define LAKKA_SAFESHUTDOWN_PATH "/storage/.cache/services/safeshutdown.conf"
2627
#endif
27-
#define LAKKA_UPDATE_DIR "/storage/.update/"
28-
#define LAKKA_CONNMAN_DIR "/storage/.cache/connman/"
29-
#define LAKKA_LOCALAP_PATH "/storage/.cache/services/localap.conf"
30-
#define LAKKA_TIMEZONE_PATH "/storage/.cache/timezone"
28+
#define LAKKA_UPDATE_DIR "/storage/.update/"
29+
#define LAKKA_CONNMAN_DIR "/storage/.cache/connman/"
30+
#define LAKKA_LOCALAP_PATH "/storage/.cache/services/localap.conf"
31+
#define LAKKA_TIMEZONE_PATH "/storage/.cache/timezone"
3132

3233
#define DEFAULT_TIMEZONE "UTC"
3334
#define TIMEZONE_LENGTH 255

menu/menu_setting.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9499,6 +9499,33 @@ static void systemd_service_toggle(const char *path, char *unit, bool enable)
94999499
}
95009500
}
95019501

9502+
static void systemd_samba_service_toggle(const char *path, char *unit, bool enable)
9503+
{
9504+
/* There is difference between samba and ssh/bluetooth.
9505+
* - samba.service is disabled if "/storage/.cache/services/samba.disabled" file is exist.
9506+
* - ssh.service is enabled if "/storage/.cache/services/sshd.conf" file is exist.
9507+
* - bluetooth.service is enabled if "/storage/.cache/services/bluez.conf" file is exist.
9508+
* So it separates the systemd_service_toggle for samba.service. */
9509+
9510+
pid_t pid = fork();
9511+
char* args[] = {(char*)"systemctl",
9512+
enable ? (char*)"start" : (char*)"stop",
9513+
unit,
9514+
NULL};
9515+
9516+
if (pid == 0)
9517+
{
9518+
if (enable)
9519+
filestream_delete(path);
9520+
else
9521+
filestream_close(filestream_open(path,
9522+
RETRO_VFS_FILE_ACCESS_WRITE,
9523+
RETRO_VFS_FILE_ACCESS_HINT_NONE));
9524+
9525+
execvp(args[0], args);
9526+
}
9527+
}
9528+
95029529
#ifdef HAVE_LAKKA_SWITCH
95039530
static void switch_oc_enable_toggle_change_handler(rarch_setting_t *setting)
95049531
{
@@ -9547,7 +9574,7 @@ static void ssh_enable_toggle_change_handler(rarch_setting_t *setting)
95479574

95489575
static void samba_enable_toggle_change_handler(rarch_setting_t *setting)
95499576
{
9550-
systemd_service_toggle(LAKKA_SAMBA_PATH, (char*)"smbd.service",
9577+
systemd_samba_service_toggle(LAKKA_SAMBA_DISABLED_FILE_PATH, (char*)"smbd.service",
95519578
*setting->value.target.boolean);
95529579
}
95539580

msg_hash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ enum msg_hash_enums
513513
MSG_SAVED_STATE_TO_SLOT,
514514
MSG_SAVED_STATE_TO_SLOT_AUTO,
515515
MSG_CORE_DOES_NOT_SUPPORT_SAVESTATES,
516+
MSG_CORE_DOES_NOT_SUPPORT_SAVESTATE_UNDO,
516517
MSG_FAILED_TO_LOAD_STATE,
517518
MSG_FAILED_TO_UNDO_LOAD_STATE,
518519
MSG_FAILED_TO_UNDO_SAVE_STATE,

retroarch.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@
229229

230230
#ifdef HAVE_LAKKA
231231
#include "lakka.h"
232+
#include <systemd/sd-daemon.h>
232233
#endif
233234

234235
#define _PSUPP(var, name, desc) printf(" %s:\n\t\t%s: %s\n", name, desc, var ? "yes" : "no")
@@ -6152,7 +6153,9 @@ int rarch_main(int argc, char *argv[], void *data)
61526153
if (settings->uints.cloud_sync_sync_mode == CLOUD_SYNC_MODE_AUTOMATIC)
61536154
task_push_cloud_sync();
61546155
#endif
6155-
6156+
#ifdef HAVE_LAKKA
6157+
sd_notify(0, "READY=1");
6158+
#endif
61566159
#if !defined(HAVE_MAIN) || defined(HAVE_QT)
61576160
for (;;)
61586161
{

0 commit comments

Comments
 (0)