improve pipes

This commit is contained in:
itsmattkc 2024-05-24 10:04:08 -07:00
parent 91863a3068
commit 3b3b11dfef
8 changed files with 16 additions and 103 deletions

View file

@ -81,8 +81,6 @@ void Backend::interrupt()
uint8_t cc = VANILLA_PIPE_IN_INTERRUPT;
write(m_pipeOut, &cc, sizeof(cc));
m_pipeMutex.unlock();
ignoreByte(m_pipeIn);
} else {
vanilla_stop();
}

View file

@ -156,7 +156,7 @@ MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
QMetaObject::invokeMethod(m_audioHandler, &AudioHandler::run, Qt::QueuedConnection);
connect(m_backend, &Backend::videoAvailable, m_videoDecoder, &VideoDecoder::sendPacket);
connect(m_backend, &Backend::syncCompleted, m_connectBtn, &QPushButton::setEnabled);
connect(m_backend, &Backend::syncCompleted, this, [this](bool e){if (e) m_connectBtn->setEnabled(true);});
connect(m_videoDecoder, &VideoDecoder::frameReady, m_viewer, &Viewer::setImage);
connect(m_backend, &Backend::audioAvailable, m_audioHandler, &AudioHandler::write);
connect(m_backend, &Backend::vibrate, m_gamepadHandler, &GamepadHandler::vibrate, Qt::DirectConnection);
@ -196,8 +196,6 @@ MainWindow::~MainWindow()
SDL_Quit();
setConnectedState(false);
delete m_viewer;
}
@ -286,6 +284,10 @@ void MainWindow::setConnectedState(bool on)
QMetaObject::invokeMethod(m_backend, &Backend::connectToConsole, Qt::QueuedConnection, m_wirelessInterfaceComboBox->currentText());
} else {
if (m_backend) {
m_backend->interrupt();
}
m_connectBtn->setText(tr("Connect"));
m_viewer->setImage(QImage());

View file

@ -1,89 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "status.h"
#include "vanilla.h"
void console_event_handler(void *context, int type, const char *data, size_t data_size)
{
switch (type) {
case VANILLA_EVENT_VIDEO:
print_info("RECEIVED VIDEO PACKET OF SIZE %llu", data_size);
break;
case VANILLA_EVENT_AUDIO:
print_info("RECEIVED AUDIO PACKET OF SIZE %llu", data_size);
break;
}
}
int main(int argc, char **argv)
{
print_status(VANILLA_READY);
char *line = NULL;
size_t size;
while (1) {
ssize_t sz = getline(&line, &size, stdin);
if (sz == -1) {
break;
}
static const int cmd_max_args = 10;
static const int cmd_max_arg_length = 20;
int cmd_nb_arg = 0;
char cmd_args[cmd_max_args][cmd_max_arg_length];
static const char *delim = " \n";
char *token = strtok(line, delim);
while (token && cmd_nb_arg < cmd_max_args) {
strncpy(cmd_args[cmd_nb_arg], token, cmd_max_arg_length);
token = strtok(NULL, delim);
cmd_nb_arg++;
}
if (cmd_nb_arg == 0) {
print_status(VANILLA_UNKNOWN_COMMAND);
continue;
}
if (!strcmp("SYNC", cmd_args[0])) {
if (cmd_nb_arg != 3) {
print_status(VANILLA_INVALID_ARGUMENT);
continue;
}
const char *wireless_interface = cmd_args[1];
const char *code = cmd_args[2];
int sync_status = vanilla_sync_with_console(wireless_interface, atoi(code));
if (sync_status == VANILLA_SUCCESS) {
print_status(VANILLA_SUCCESS);
} else {
print_status(VANILLA_ERROR);
}
} else if (!strcmp("CONNECT", cmd_args[0])) {
if (cmd_nb_arg != 2) {
print_status(VANILLA_INVALID_ARGUMENT);
continue;
}
const char *wireless_interface = cmd_args[1];
int status = vanilla_connect_to_console(wireless_interface, console_event_handler, NULL);
if (status == VANILLA_SUCCESS) {
print_status(VANILLA_SUCCESS);
} else {
print_status(VANILLA_ERROR);
}
} else if (!strcmp("EXIT", cmd_args[0])) {
break;
} else {
print_status(VANILLA_UNKNOWN_COMMAND);
}
}
return 0;
}

View file

@ -26,7 +26,7 @@ void print_info(const char *errstr, ...)
vanilla_log_no_newline(VANILLA_STATUS_STRINGS[-VANILLA_INFO]);
vanilla_log_no_newline(" ");
vanilla_log_no_newline(errstr, args);
vanilla_log_no_newline_va(errstr, args);
vanilla_log_no_newline("\n");
va_end(args);

View file

@ -74,7 +74,7 @@ size_t get_home_directory_file(const char *filename, char *buf, size_t buf_size)
size_t get_max_path_length()
{
return pathconf(".", _PC_PATH_MAX);;
return pathconf(".", _PC_PATH_MAX);
}
void interrupt_handler(int signum)

View file

@ -111,13 +111,18 @@ void vanilla_log_no_newline(const char *format, ...)
va_list va;
va_start(va, format);
if (custom_logger) {
custom_logger(format, va);
}
vanilla_log_no_newline_va(format, va);
va_end(va);
}
void vanilla_log_no_newline_va(const char *format, va_list args)
{
if (custom_logger) {
custom_logger(format, args);
}
}
void vanilla_install_logger(void (*logger)(const char *, va_list))
{
custom_logger = logger;

View file

@ -112,6 +112,7 @@ void vanilla_set_touch(int x, int y);
*/
void vanilla_log(const char *format, ...);
void vanilla_log_no_newline(const char *format, ...);
void vanilla_log_no_newline_va(const char *format, va_list args);
/**
* Install custom logger

View file

@ -246,10 +246,6 @@ int main()
if (current_action != 0) {
void *ret;
vanilla_stop();
write_control_code(VANILLA_PIPE_ERR_SUCCESS);
pthread_join(current_action, &ret);
} else {
write_control_code(VANILLA_PIPE_ERR_INVALID);
}
break;
}