1
0
mirror of https://github.com/libretro/RetroArch synced 2025-03-06 22:13:25 +00:00

(iOS) Pass BTstack messages through RARCH_LOG; patch the logger to print to stdout when building for the simulator.

This commit is contained in:
meancoot 2013-12-24 15:27:44 -05:00
parent 0b17dc0d47
commit 2ae0356081
5 changed files with 34 additions and 26 deletions

@ -38,6 +38,4 @@ gfx_ctx_proc_t apple_gfx_ctx_get_proc_address(const char *symbol_name);
void apple_bind_game_view_fbo(void); void apple_bind_game_view_fbo(void);
#endif #endif
#define ios_add_log_message(...) printf(__VA_ARGS__)
#endif #endif

@ -71,7 +71,7 @@ bool btstack_try_load()
if (btstack_tested) if (btstack_tested)
return btstack_loaded; return btstack_loaded;
ios_add_log_message("BTstack: Attempting to load"); RARCH_LOG("BTstack: Attempting to load\n");
btstack_tested = true; btstack_tested = true;
btstack_loaded = false; btstack_loaded = false;
@ -80,8 +80,8 @@ bool btstack_try_load()
if (!btstack) if (!btstack)
{ {
ios_add_log_message("BTstack: /usr/lib/libBTstack.dylib not loadable"); RARCH_LOG("BTstack: /usr/lib/libBTstack.dylib not loadable\n");
ios_add_log_message("BTstack: Not loaded"); RARCH_LOG("BTstack: Not loaded\n");
return false; return false;
} }
@ -91,8 +91,8 @@ bool btstack_try_load()
if (!*grabbers[i].target) if (!*grabbers[i].target)
{ {
ios_add_log_message("BTstack: Symbol %s not found in /usr/lib/libBTstack.dylib", grabbers[i].name); RARCH_LOG("BTstack: Symbol %s not found in /usr/lib/libBTstack.dylib\n", grabbers[i].name);
ios_add_log_message("BTstack: Not loaded"); RARCH_LOG("BTstack: Not loaded\n");
dlclose(btstack); dlclose(btstack);
return false; return false;
@ -102,7 +102,7 @@ bool btstack_try_load()
run_loop_init_ptr(RUN_LOOP_COCOA); run_loop_init_ptr(RUN_LOOP_COCOA);
bt_register_packet_handler_ptr(btpad_packet_handler); bt_register_packet_handler_ptr(btpad_packet_handler);
ios_add_log_message("BTstack: Loaded"); RARCH_LOG("BTstack: Loaded\n");
btstack_loaded = true; btstack_loaded = true;
return true; return true;
@ -115,7 +115,7 @@ void btstack_set_poweron(bool on)
if (!btstack_open && bt_open_ptr()) if (!btstack_open && bt_open_ptr())
{ {
ios_add_log_message("BTstack: bt_open failed"); RARCH_LOG("BTstack: bt_open failed\n");
btstack_loaded = false; btstack_loaded = false;
return; return;
} }
@ -124,7 +124,7 @@ void btstack_set_poweron(bool on)
if (on != btstack_poweron) if (on != btstack_poweron)
{ {
btstack_poweron = on; btstack_poweron = on;
ios_add_log_message("BTstack: Turning %s", on ? "on" : "off"); RARCH_LOG("BTstack: Turning %s\n", on ? "on" : "off");
bt_send_cmd_ptr(btstack_set_power_mode_ptr, on ? HCI_POWER_ON : HCI_POWER_OFF); bt_send_cmd_ptr(btstack_set_power_mode_ptr, on ? HCI_POWER_ON : HCI_POWER_OFF);
} }
} }

@ -145,8 +145,8 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
if (COMMAND_COMPLETE_EVENT(packet, (*hci_read_bd_addr_ptr))) if (COMMAND_COMPLETE_EVENT(packet, (*hci_read_bd_addr_ptr)))
{ {
bt_flip_addr_ptr(event_addr, &packet[6]); bt_flip_addr_ptr(event_addr, &packet[6]);
if (!packet[5]) ios_add_log_message("BTpad: Local address is %s", bd_addr_to_str_ptr(event_addr)); if (!packet[5]) RARCH_LOG("BTpad: Local address is %s\n", bd_addr_to_str_ptr(event_addr));
else ios_add_log_message("BTpad: Failed to get local address (Status: %02X)", packet[5]); else RARCH_LOG("BTpad: Failed to get local address (Status: %02X)\n", packet[5]);
} }
} }
break; break;
@ -160,7 +160,7 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
struct apple_pad_connection* connection = btpad_find_empty_connection(); struct apple_pad_connection* connection = btpad_find_empty_connection();
if (connection) if (connection)
{ {
ios_add_log_message("BTpad: Inquiry found device"); RARCH_LOG("BTpad: Inquiry found device\n");
memset(connection, 0, sizeof(struct apple_pad_connection)); memset(connection, 0, sizeof(struct apple_pad_connection));
memcpy(connection->address, event_addr, sizeof(bd_addr_t)); memcpy(connection->address, event_addr, sizeof(bd_addr_t));
@ -197,11 +197,11 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
{ {
if (!connection) if (!connection)
{ {
ios_add_log_message("BTpad: Got L2CAP 'Channel Opened' event for unrecognized device"); RARCH_LOG("BTpad: Got L2CAP 'Channel Opened' event for unrecognized device\n");
break; break;
} }
ios_add_log_message("BTpad: L2CAP channel opened: (PSM: %02X)", psm); RARCH_LOG("BTpad: L2CAP channel opened: (PSM: %02X)\n", psm);
connection->handle = handle; connection->handle = handle;
if (psm == PSM_HID_CONTROL) if (psm == PSM_HID_CONTROL)
@ -209,16 +209,16 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
else if (psm == PSM_HID_INTERRUPT) else if (psm == PSM_HID_INTERRUPT)
connection->channels[1] = channel_id; connection->channels[1] = channel_id;
else else
ios_add_log_message("BTpad: Got unknown L2CAP PSM, ignoring (PSM: %02X)", psm); RARCH_LOG("BTpad: Got unknown L2CAP PSM, ignoring (PSM: %02X)\n", psm);
if (connection->channels[0] && connection->channels[1]) if (connection->channels[0] && connection->channels[1])
{ {
ios_add_log_message("BTpad: Got both L2CAP channels, requesting name"); RARCH_LOG("BTpad: Got both L2CAP channels, requesting name\n");
btpad_queue_hci_remote_name_request(connection->address, 0, 0, 0); btpad_queue_hci_remote_name_request(connection->address, 0, 0, 0);
} }
} }
else else
ios_add_log_message("BTpad: Got failed L2CAP 'Channel Opened' event (PSM: %02X, Status: %02X)", psm, packet[2]); RARCH_LOG("BTpad: Got failed L2CAP 'Channel Opened' event (PSM: %02X, Status: %02X)\n", psm, packet[2]);
} }
break; break;
@ -236,7 +236,7 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
connection = btpad_find_empty_connection(); connection = btpad_find_empty_connection();
if (connection) if (connection)
{ {
ios_add_log_message("BTpad: Got new incoming connection"); RARCH_LOG("BTpad: Got new incoming connection\n");
memset(connection, 0, sizeof(struct apple_pad_connection)); memset(connection, 0, sizeof(struct apple_pad_connection));
@ -248,7 +248,7 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
else break; else break;
} }
ios_add_log_message("BTpad: Incoming L2CAP connection (PSM: %02X)", psm); RARCH_LOG("BTpad: Incoming L2CAP connection (PSM: %02X)\n", psm);
bt_send_cmd_ptr(l2cap_accept_connection_ptr, channel_id); bt_send_cmd_ptr(l2cap_accept_connection_ptr, channel_id);
} }
break; break;
@ -261,11 +261,11 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
if (!connection) if (!connection)
{ {
ios_add_log_message("BTpad: Got unexpected remote name, ignoring"); RARCH_LOG("BTpad: Got unexpected remote name, ignoring\n");
break; break;
} }
ios_add_log_message("BTpad: Got %.200s", (char*)&packet[9]); RARCH_LOG("BTpad: Got %.200s\n", (char*)&packet[9]);
connection->slot = apple_joypad_connect((char*)packet + 9, connection); connection->slot = apple_joypad_connect((char*)packet + 9, connection);
connection->state = BTPAD_CONNECTED; connection->state = BTPAD_CONNECTED;
@ -274,7 +274,7 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
case HCI_EVENT_PIN_CODE_REQUEST: case HCI_EVENT_PIN_CODE_REQUEST:
{ {
ios_add_log_message("BTpad: Sending WiiMote PIN"); RARCH_LOG("BTpad: Sending WiiMote PIN\n");
bt_flip_addr_ptr(event_addr, &packet[2]); bt_flip_addr_ptr(event_addr, &packet[2]);
btpad_queue_hci_pin_code_request_reply(event_addr, &packet[2]); btpad_queue_hci_pin_code_request_reply(event_addr, &packet[2]);
@ -297,14 +297,14 @@ void btpad_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet
} }
} }
else else
ios_add_log_message("BTpad: Got failed 'Disconnection Complete' event (Status: %02X)", packet[2]); RARCH_LOG("BTpad: Got failed 'Disconnection Complete' event (Status: %02X)\n", packet[2]);
} }
break; break;
case L2CAP_EVENT_SERVICE_REGISTERED: case L2CAP_EVENT_SERVICE_REGISTERED:
{ {
if (!packet[2]) if (!packet[2])
ios_add_log_message("BTpad: Got failed 'Service Registered' event (PSM: %02X, Status: %02X)", READ_BT_16(packet, 3), packet[2]); RARCH_LOG("BTpad: Got failed 'Service Registered' event (PSM: %02X, Status: %02X)\n", READ_BT_16(packet, 3), packet[2]);
} }
break; break;
} }

@ -42,7 +42,6 @@ int get_ios_version_major()
return version; return version;
} }
void ios_set_bluetooth_mode(NSString* mode) void ios_set_bluetooth_mode(NSString* mode)
{ {
apple_input_enable_icade([mode isEqualToString:@"icade"]); apple_input_enable_icade([mode isEqualToString:@"icade"]);

@ -17,17 +17,28 @@
#ifndef __APPLE_IOS_LOGGER_H #ifndef __APPLE_IOS_LOGGER_H
#define __APPLE_IOS_LOGGER_H #define __APPLE_IOS_LOGGER_H
#include <TargetConditionals.h>
#if TARGET_IPHONE_SIMULATOR
#include <stdio.h>
#else
#include <asl.h> #include <asl.h>
#endif
#include <stdarg.h> #include <stdarg.h>
static inline void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap) static inline void RARCH_LOG_V(const char *tag, const char *fmt, va_list ap)
{ {
#if TARGET_IPHONE_SIMULATOR
vprintf(fmt, ap);
#else
aslmsg msg = asl_new(ASL_TYPE_MSG); aslmsg msg = asl_new(ASL_TYPE_MSG);
asl_set(msg, ASL_KEY_READ_UID, "-1"); asl_set(msg, ASL_KEY_READ_UID, "-1");
if (tag) if (tag)
asl_log(NULL, msg, ASL_LEVEL_NOTICE, "%s", tag); asl_log(NULL, msg, ASL_LEVEL_NOTICE, "%s", tag);
asl_vlog(NULL, msg, ASL_LEVEL_NOTICE, fmt, ap); asl_vlog(NULL, msg, ASL_LEVEL_NOTICE, fmt, ap);
asl_free(msg); asl_free(msg);
#endif
} }
static inline void RARCH_LOG(const char *fmt, ...) static inline void RARCH_LOG(const char *fmt, ...)