2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-02-27 12:43:44 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-02-27 12:43:44 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-02-27 12:43:44 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-02-27 12:43:44 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-11-11 10:14:55 +00:00
|
|
|
#if defined(__CELLOS_LV2__)
|
2012-09-16 02:04:25 +00:00
|
|
|
#include "../../ps3/sdk_defines.h"
|
|
|
|
#ifndef __PSL1GHT__
|
2012-02-27 12:43:44 +00:00
|
|
|
#include <netex/net.h>
|
|
|
|
#include <cell/sysmodule.h>
|
|
|
|
#include <netex/libnetctl.h>
|
|
|
|
#include <sys/timer.h>
|
2012-09-16 02:04:25 +00:00
|
|
|
#endif
|
2012-02-27 12:43:44 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2013-11-11 10:14:55 +00:00
|
|
|
#elif defined(GEKKO)
|
2012-03-12 23:44:37 +00:00
|
|
|
#include <network.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
2012-02-27 12:43:44 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2012-07-27 19:33:18 +00:00
|
|
|
#ifndef GEKKO
|
2012-03-12 23:44:37 +00:00
|
|
|
#include "../../netplay_compat.h"
|
2012-07-27 19:33:18 +00:00
|
|
|
#endif
|
2012-03-12 23:44:37 +00:00
|
|
|
|
2012-02-27 12:43:44 +00:00
|
|
|
#include "logger.h"
|
|
|
|
|
2012-02-28 15:32:52 +00:00
|
|
|
#if !defined(PC_DEVELOPMENT_IP_ADDRESS)
|
2012-07-28 15:43:45 +00:00
|
|
|
#error "An IP address for the PC logging server was not set in the Makefile, cannot continue."
|
2012-02-28 15:32:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(PC_DEVELOPMENT_UDP_PORT)
|
2012-07-28 15:43:45 +00:00
|
|
|
#error "An UDP port for the PC logging server was not set in the Makefile, cannot continue."
|
2012-02-28 15:32:52 +00:00
|
|
|
#endif
|
2012-02-27 12:43:44 +00:00
|
|
|
|
|
|
|
static int g_sid;
|
|
|
|
static int sock;
|
|
|
|
static struct sockaddr_in target;
|
|
|
|
static char sendbuf[4096];
|
|
|
|
|
2012-07-27 21:51:36 +00:00
|
|
|
#ifdef GEKKO
|
|
|
|
#define sendto(s, msg, len, flags, addr, tolen) net_sendto(s, msg, len, 0, addr, 8)
|
2012-03-12 23:44:37 +00:00
|
|
|
#define socket(domain, type, protocol) net_socket(domain, type, protocol)
|
|
|
|
|
|
|
|
static int inet_pton(int af, const char *src, void *dst)
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
if (af != AF_INET)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return inet_aton (src, dst);
|
2012-03-12 23:44:37 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-02-27 12:43:44 +00:00
|
|
|
static int if_up_with(int index)
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
(void)index;
|
2012-03-12 23:44:37 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
2012-04-10 19:23:42 +00:00
|
|
|
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);
|
2012-11-25 04:41:12 +00:00
|
|
|
return (-1);
|
2012-04-10 19:23:42 +00:00
|
|
|
}
|
|
|
|
if (state == CELL_NET_CTL_STATE_IPObtained)
|
|
|
|
break;
|
|
|
|
|
|
|
|
sys_timer_usleep(500 * 1000);
|
|
|
|
timeout_count--;
|
|
|
|
if (index && timeout_count < 0)
|
|
|
|
{
|
|
|
|
printf("if_up_with(%d) timeout\n", index);
|
2012-11-25 04:41:12 +00:00
|
|
|
return (0);
|
2012-04-10 19:23:42 +00:00
|
|
|
}
|
|
|
|
}
|
2012-07-27 20:22:49 +00:00
|
|
|
#elif defined(GEKKO)
|
2012-07-27 21:51:36 +00:00
|
|
|
char t[16];
|
|
|
|
if (if_config(t, NULL, NULL, TRUE) < 0)
|
2012-07-27 20:22:49 +00:00
|
|
|
{
|
|
|
|
return (-1);
|
|
|
|
}
|
2012-03-12 23:44:37 +00:00
|
|
|
#endif
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-07-27 21:51:36 +00:00
|
|
|
sock=socket(AF_INET, SOCK_DGRAM, 0);
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
target.sin_family = AF_INET;
|
|
|
|
target.sin_port = htons(PC_DEVELOPMENT_UDP_PORT);
|
2012-07-27 21:51:36 +00:00
|
|
|
#ifdef GEKKO
|
|
|
|
target.sin_len = 8;
|
|
|
|
#endif
|
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
inet_pton(AF_INET, PC_DEVELOPMENT_IP_ADDRESS, &target.sin_addr);
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
return (0);
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int if_down(int sid)
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
(void)sid;
|
2012-03-12 23:44:37 +00:00
|
|
|
#ifdef __CELLOS_LV2__
|
2012-04-10 19:23:42 +00:00
|
|
|
cellNetCtlTerm();
|
2012-09-01 00:47:54 +00:00
|
|
|
#elif defined(GEKKO) && !defined(HW_DOL)
|
2012-07-27 21:51:36 +00:00
|
|
|
net_deinit();
|
2012-03-12 23:44:37 +00:00
|
|
|
#endif
|
2012-04-10 19:23:42 +00:00
|
|
|
return (0);
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void logger_init (void)
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
g_sid = if_up_with(1);
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void logger_shutdown (void)
|
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
if_down(g_sid);
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|
|
|
|
|
2012-03-12 23:44:37 +00:00
|
|
|
void logger_send(const char *__format,...)
|
2012-02-27 12:43:44 +00:00
|
|
|
{
|
2012-04-10 19:23:42 +00:00
|
|
|
va_list args;
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
va_start(args,__format);
|
|
|
|
vsnprintf(sendbuf,4000,__format, args);
|
|
|
|
va_end(args);
|
2012-02-27 12:43:44 +00:00
|
|
|
|
2012-04-10 19:23:42 +00:00
|
|
|
int len=strlen(sendbuf);
|
|
|
|
sendto(sock,sendbuf,len,MSG_DONTWAIT,(struct sockaddr*)&target,sizeof(target));
|
2012-02-27 12:43:44 +00:00
|
|
|
}
|