RetroArch/netlogger.c

100 lines
2.5 KiB
C
Raw Normal View History

2012-04-21 21:13:50 +00:00
/* RetroArch - A frontend for libretro.
2014-01-01 00:50:59 +00:00
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
2016-01-10 03:06:50 +00:00
* Copyright (C) 2011-2016 - Daniel De Matteis
2015-08-30 20:47:50 +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
* 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;
* 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.
* If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(__CELLOS_LV2__) || defined(__PSL1GHT__)
2015-09-16 09:33:53 +00:00
#include "../defines/ps3_defines.h"
2012-03-12 23:44:37 +00:00
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <retro_miscellaneous.h>
2015-03-20 17:18:52 +00:00
#include <net/net_compat.h>
2016-05-01 22:05:33 +00:00
#include <net/net_socket.h>
2012-03-12 23:44:37 +00:00
2015-11-23 11:03:38 +00:00
#include "verbosity.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
static int g_sid;
static struct sockaddr_in target;
2016-05-03 02:26:09 +00:00
void logger_init (void)
2015-08-29 16:57:07 +00:00
{
2016-05-08 05:24:10 +00:00
socket_target_t in_target;
2016-05-03 02:26:09 +00:00
const char *server = PC_DEVELOPMENT_IP_ADDRESS;
unsigned port = PC_DEVELOPMENT_UDP_PORT;
2015-08-30 20:47:50 +00:00
2016-05-03 02:26:09 +00:00
if (!network_init())
2015-08-29 16:57:07 +00:00
{
2016-05-03 02:26:09 +00:00
printf("Could not initialize network logger interface.\n");
return;
2015-08-29 16:57:07 +00:00
}
2016-05-02 17:09:42 +00:00
2016-05-03 02:26:09 +00:00
g_sid = socket_create(
2016-05-02 16:37:08 +00:00
"ra_netlogger",
SOCKET_DOMAIN_INET,
SOCKET_TYPE_DATAGRAM,
2016-05-02 16:42:13 +00:00
SOCKET_PROTOCOL_NONE);
2015-08-29 16:57:07 +00:00
2016-05-08 05:24:10 +00:00
in_target.port = port;
in_target.server = server;
in_target.domain = SOCKET_DOMAIN_INET;
2015-08-29 16:57:07 +00:00
2016-05-08 05:24:10 +00:00
socket_set_target(&target, &in_target);
}
void logger_shutdown (void)
{
2016-05-07 16:35:06 +00:00
if (socket_close(g_sid) < 0)
printf("Could not close socket.\n");
2016-05-01 22:21:13 +00:00
network_deinit();
}
2012-03-12 23:44:37 +00:00
void logger_send(const char *__format,...)
{
va_list args;
va_start(args,__format);
2013-12-22 21:42:03 +00:00
logger_send_v(__format, args);
va_end(args);
2013-12-22 21:42:03 +00:00
}
void logger_send_v(const char *__format, va_list args)
{
2016-05-03 03:00:52 +00:00
static char sendbuf[4096];
2014-06-01 14:06:00 +00:00
int len;
2016-05-03 03:00:52 +00:00
2013-12-22 21:42:03 +00:00
vsnprintf(sendbuf,4000,__format, args);
2014-06-01 14:06:00 +00:00
len = strlen(sendbuf);
2016-05-01 22:21:13 +00:00
sendto(g_sid,
sendbuf,
len,
MSG_DONTWAIT,
(struct sockaddr*)&target,
sizeof(target));
}