mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 09:40:06 +00:00
Consolidate PSL1GHT logger into logger/netlogger/logger.c
and expand net/net_compat.c
This commit is contained in:
parent
4f80afe03e
commit
e32b99ac0c
@ -26,17 +26,15 @@
|
||||
#include <compat/posix_string.h>
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_LOGGER) && !defined(ANDROID)
|
||||
#include "../logger/netlogger/logger.c"
|
||||
#endif
|
||||
|
||||
/*============================================================
|
||||
CONSOLE EXTENSIONS
|
||||
============================================================ */
|
||||
#ifdef RARCH_CONSOLE
|
||||
|
||||
#if defined(HAVE_LOGGER) && defined(__PSL1GHT__)
|
||||
#include "../logger/netlogger/psl1ght_logger.c"
|
||||
#elif defined(HAVE_LOGGER) && !defined(ANDROID)
|
||||
#include "../logger/netlogger/logger.c"
|
||||
#endif
|
||||
|
||||
#ifdef HW_DOL
|
||||
#include "../ngc/ssaram.c"
|
||||
#endif
|
||||
|
@ -192,5 +192,10 @@ bool network_init(void);
|
||||
**/
|
||||
void network_deinit(void);
|
||||
|
||||
int network_interface_up(struct sockaddr_in *target, int index,
|
||||
const char *ip_address, unsigned udp_port, int *s);
|
||||
|
||||
int network_interface_down(struct sockaddr_in *target, int *s);
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -201,3 +201,70 @@ void network_deinit(void)
|
||||
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
|
||||
#endif
|
||||
}
|
||||
|
||||
int network_interface_up(struct sockaddr_in *target, int index,
|
||||
const char *ip_address, unsigned udp_port, int *s)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
(void)index;
|
||||
|
||||
#ifdef __CELLOS_LV2__
|
||||
int state, timeout_count = 10;
|
||||
ret = cellNetCtlInit();
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("cellNetCtlInit() failed(%x)\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
ret = cellNetCtlGetState(&state);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("cellNetCtlGetState() failed(%x)\n", ret);
|
||||
return -1;
|
||||
}
|
||||
if (state == CELL_NET_CTL_STATE_IPObtained)
|
||||
break;
|
||||
|
||||
rarch_sleep(500);
|
||||
timeout_count--;
|
||||
if (index && timeout_count < 0)
|
||||
{
|
||||
printf("if_up_with(%d) timeout\n", index);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#elif defined(GEKKO)
|
||||
char t[16];
|
||||
if (if_config(t, NULL, NULL, TRUE) < 0)
|
||||
ret = -1;
|
||||
#endif
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
*s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
target->sin_family = AF_INET;
|
||||
target->sin_port = htons(udp_port);
|
||||
#ifdef GEKKO
|
||||
target->sin_len = 8;
|
||||
#endif
|
||||
|
||||
inet_pton(AF_INET, ip_address, &target->sin_addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int network_interface_down(struct sockaddr_in *target, int *s)
|
||||
{
|
||||
socket_close(*s);
|
||||
#ifdef __CELLOS_LV2__
|
||||
cellNetCtlTerm();
|
||||
#elif defined(GEKKO) && !defined(HW_DOL)
|
||||
net_deinit();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
@ -14,7 +14,7 @@
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#if defined(__CELLOS_LV2__)
|
||||
#if defined(__CELLOS_LV2__) || defined(__PSL1GHT__)
|
||||
#include "../../defines/ps3_defines.h"
|
||||
#endif
|
||||
|
||||
@ -41,78 +41,21 @@ static int sock;
|
||||
static struct sockaddr_in target;
|
||||
static char sendbuf[4096];
|
||||
|
||||
static int if_up_with(int index)
|
||||
{
|
||||
(void)index;
|
||||
#ifdef __CELLOS_LV2__
|
||||
int timeout_count = 10;
|
||||
int state;
|
||||
int ret;
|
||||
|
||||
ret = cellNetCtlInit();
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("cellNetCtlInit() failed(%x)\n", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (;;)
|
||||
{
|
||||
ret = cellNetCtlGetState(&state);
|
||||
if (ret < 0)
|
||||
{
|
||||
printf("cellNetCtlGetState() failed(%x)\n", ret);
|
||||
return -1;
|
||||
}
|
||||
if (state == CELL_NET_CTL_STATE_IPObtained)
|
||||
break;
|
||||
|
||||
rarch_sleep(500);
|
||||
timeout_count--;
|
||||
if (index && timeout_count < 0)
|
||||
{
|
||||
printf("if_up_with(%d) timeout\n", index);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#elif defined(GEKKO)
|
||||
char t[16];
|
||||
if (if_config(t, NULL, NULL, TRUE) < 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
sock=socket(AF_INET, SOCK_DGRAM, 0);
|
||||
|
||||
target.sin_family = AF_INET;
|
||||
target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT);
|
||||
#ifdef GEKKO
|
||||
target.sin_len = 8;
|
||||
#endif
|
||||
|
||||
inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int if_down(int sid)
|
||||
{
|
||||
(void)sid;
|
||||
#ifdef __CELLOS_LV2__
|
||||
cellNetCtlTerm();
|
||||
#elif defined(GEKKO) && !defined(HW_DOL)
|
||||
net_deinit();
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void logger_init (void)
|
||||
{
|
||||
g_sid = if_up_with(1);
|
||||
if (network_interface_up(&target, 1,
|
||||
PC_DEVELOPMENT_IP_ADDRESS,PC_DEVELOPMENT_UDP_PORT, &g_sid) < 0)
|
||||
{
|
||||
printf("Could not initialize network logger interface.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void logger_shutdown (void)
|
||||
{
|
||||
if_down(g_sid);
|
||||
if (network_interface_down(&target, &g_sid) < 0)
|
||||
{
|
||||
printf("Could not deinitialize network logger interface.\n");
|
||||
}
|
||||
}
|
||||
|
||||
void logger_send(const char *__format,...)
|
||||
|
@ -1,79 +0,0 @@
|
||||
/* 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 <net/compat.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "logger.h"
|
||||
|
||||
#if !defined(PC_DEVELOPMENT_IP_ADDRESS)
|
||||
#error "An IP address for the PC logging server was not set in the Makefile, cannot continue."
|
||||
#endif
|
||||
|
||||
#if !defined(PC_DEVELOPMENT_UDP_PORT)
|
||||
#error "An UDP port for the PC logging server was not set in the Makefile, cannot continue."
|
||||
#endif
|
||||
|
||||
int s;
|
||||
struct sockaddr_in server;
|
||||
|
||||
#define INITSTRING "Logging Started\n"
|
||||
#define BYESTRING "Logging Stopped\n"
|
||||
|
||||
void logger_init (void)
|
||||
{
|
||||
s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||
memset(&server, 0, sizeof(server));
|
||||
server.sin_len = sizeof(server);
|
||||
server.sin_family = AF_INET;
|
||||
inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &server.sin_addr);
|
||||
server.sin_port = htons(PC_DEVELOPMENT_UDP_PORT);
|
||||
|
||||
sendto(s, INITSTRING, strlen(INITSTRING), 0, (struct sockaddr*)&server, sizeof(server));
|
||||
}
|
||||
|
||||
void logger_shutdown (void)
|
||||
{
|
||||
sendto(s, BYESTRING, strlen(BYESTRING), 0, (struct sockaddr*)&server, sizeof(server));
|
||||
close(s);
|
||||
}
|
||||
|
||||
void logger_send(const char *format,...)
|
||||
{
|
||||
char log_buf[1024];
|
||||
va_list va;
|
||||
int max;
|
||||
|
||||
if(s == -1)
|
||||
return;
|
||||
|
||||
max = sizeof(logBuffer);
|
||||
va_start(va, format);
|
||||
|
||||
int wrote = vsnprintf(logBuffer, max, format, va);
|
||||
|
||||
if(wrote > max)
|
||||
wrote = max;
|
||||
|
||||
va_end(va);
|
||||
sendto(s, logBuffer, wrote, 0, (struct sockaddr *)&server, sizeof(server));
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user