replaced printf and fprintf(\stderr with log_dbg and log_err

This commit is contained in:
matthias.ringwald 2011-05-05 18:45:28 +00:00
parent 933d8a8084
commit 9cfcc54d6f
8 changed files with 75 additions and 75 deletions

View File

@ -44,6 +44,7 @@
#include "bt_control_iphone.h"
#include "hci_transport.h"
#include "hci.h"
#include "debug.h"
#include <sys/utsname.h> // uname
#include <stdlib.h> // system, random, srandom
@ -189,9 +190,9 @@ static void ioregistry_get_info() {
IOObjectRelease(bt_service);
// dump info
printf("local-mac-address: ");
log_dbg("local-mac-address: ");
print_bd_addr(local_mac_address);
printf("\ntransport-speed: %u\n", transport_speed);
log_dbg("\ntransport-speed: %u\n", transport_speed);
#else
// use dummy addr if not on iphone/ipod touch
int i = 0;
@ -462,7 +463,7 @@ static int iphone_on (void *transport_config){
close(fd);
} else {
// no way!
fprintf(stderr, "bt_control.c:iphone_on(): Failed to open '%s', trying killall %s\n", hci_uart_config->device_name, bluetool);
log_err( "bt_control.c:iphone_on(): Failed to open '%s', trying killall %s\n", hci_uart_config->device_name, bluetool);
system("killall -9 BlueToolH4");
system("killall -9 BlueTool");
sleep(3);
@ -472,7 +473,7 @@ static int iphone_on (void *transport_config){
if (fd > 0){
close(fd);
} else {
fprintf(stderr, "bt_control.c:iphone_on(): Failed to open '%s' again, trying killall BTServer and killall %s\n", hci_uart_config->device_name, bluetool);
log_err( "bt_control.c:iphone_on(): Failed to open '%s' again, trying killall BTServer and killall %s\n", hci_uart_config->device_name, bluetool);
system("killall -9 BTServer");
system("killall -9 BlueToolH4");
system("killall -9 BlueTool");
@ -508,7 +509,7 @@ static int iphone_on (void *transport_config){
while (1) {
singlechar = fgetc(outputFile);
if (singlechar == EOF) break;
printf("%c", singlechar);
log_dbg("%c", singlechar);
};
err = pclose(outputFile);
}
@ -572,7 +573,7 @@ static int iphone_wake(void *config){
static void MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, void * messageArgument ) {
char data;
printf( "messageType %08lx, arg %08lx\n", (long unsigned int)messageType, (long unsigned int)messageArgument);
log_dbg( "messageType %08lx, arg %08lx\n", (long unsigned int)messageType, (long unsigned int)messageArgument);
switch ( messageType ) {
case kIOMessageCanSystemSleep:
/* Idle sleep is about to kick in. This message will not be sent for forced sleep.
@ -633,7 +634,7 @@ static int power_notification_process(struct data_source *ds) {
int bytes_read = read(power_notification_pipe_fds[0], &token, 1);
if (bytes_read != 1) return;
printf("power_notification_process: %u\n", token);
log_dbg("power_notification_process: %u\n", token);
power_notification_callback( (POWER_NOTIFICATION_t) token );
}
@ -646,7 +647,7 @@ static void power_notification_run(void *context){
// register to receive system sleep notifications
root_port = IORegisterForSystemPower(NULL, &notifyPortRef, MySleepCallBack, &notifierObject);
if (!root_port) {
printf("IORegisterForSystemPower failed\n");
log_dbg("IORegisterForSystemPower failed\n");
return;
}

View File

@ -52,6 +52,7 @@
#include <btstack/linked_list.h>
#include <btstack/run_loop.h>
#include "debug.h"
#include "hci.h"
#include "hci_dump.h"
#include "hci_transport.h"
@ -115,12 +116,12 @@ static remote_device_db_t * remote_device_db = NULL;
static rfcomm_channel_generator = 1;
static void dummy_bluetooth_status_handler(BLUETOOTH_STATE state){
printf("Bluetooth status: %u\n", state);
log_dbg("Bluetooth status: %u\n", state);
};
static void daemon_no_connections_timeout(){
if (clients_require_power_on()) return; // false alarm :)
printf("No active client connection for %u seconds -> POWER OFF\n", DAEMON_NO_ACTIVE_CLIENT_TIMEOUT/1000);
log_dbg("No active client connection for %u seconds -> POWER OFF\n", DAEMON_NO_ACTIVE_CLIENT_TIMEOUT/1000);
hci_power_control(HCI_POWER_OFF);
}
@ -184,7 +185,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
hci_discoverable_control(clients_require_discoverable());
break;
case BTSTACK_SET_BLUETOOTH_ENABLED:
printf("BTSTACK_SET_BLUETOOTH_ENABLED: %u\n", packet[3]);
log_dbg("BTSTACK_SET_BLUETOOTH_ENABLED: %u\n", packet[3]);
if (packet[3]) {
// global enable
@ -279,7 +280,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
}
case SDP_REGISTER_SERVICE_RECORD:
printf("SDP_REGISTER_SERVICE_RECORD size %u\n", size);
log_dbg("SDP_REGISTER_SERVICE_RECORD size %u\n", size);
sdp_register_service_internal(connection, &packet[3]);
break;
case SDP_UNREGISTER_SERVICE_RECORD:
@ -288,7 +289,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
break;
default:
//@TODO: log into hci dump as vendor specific "event"
fprintf(stderr, "Error: command %u not implemented\n:", READ_CMD_OCF(packet));
log_err("Error: command %u not implemented\n:", READ_CMD_OCF(packet));
break;
}
return 0;
@ -345,7 +346,7 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
}
break;
case DAEMON_NR_CONNECTIONS_CHANGED:
printf("Nr Connections changed, new %u\n",data[1]);
log_dbg("Nr Connections changed, new %u\n",data[1]);
break;
default:
break;
@ -353,7 +354,7 @@ static int daemon_client_handler(connection_t *connection, uint16_t packet_type,
break;
}
if (err) {
printf("Daemon Handler: err %d\n", err);
log_dbg("Daemon Handler: err %d\n", err);
}
return err;
}
@ -381,12 +382,12 @@ static void deamon_status_event_handler(uint8_t *packet, uint16_t size){
switch (packet[0]) {
case BTSTACK_EVENT_STATE:
hci_state = packet[2];
printf("New state: %u\n", hci_state);
log_dbg("New state: %u\n", hci_state);
update_status = 1;
break;
case BTSTACK_EVENT_NR_CONNECTIONS_CHANGED:
num_connections = packet[2];
printf("New nr connections: %u\n", num_connections);
log_dbg("New nr connections: %u\n", num_connections);
update_status = 1;
break;
default:
@ -440,22 +441,22 @@ static void daemon_sigint_handler(int param){
notify_post("ch.ringwald.btstack.stopped");
#endif
printf(" <= SIGINT received, shutting down..\n");
log_dbg(" <= SIGINT received, shutting down..\n");
hci_power_control( HCI_POWER_OFF);
hci_close();
printf("Good bye, see you.\n");
log_dbg("Good bye, see you.\n");
exit(0);
}
static void daemon_sigpipe_handler(int param){
printf(" <= SIGPIPE received.. trying to ignore..\n");
log_dbg(" <= SIGPIPE received.. trying to ignore..\n");
}
static void usage(const char * name) {
printf("%s, BTstack background daemon\n", name);
printf("usage: %s [-h|--help] [--tcp]\n", name);
printf(" -h|--help display this usage\n");
printf(" --tcp use TCP server socket instead of local unix socket\n");
log_dbg("%s, BTstack background daemon\n", name);
log_dbg("usage: %s [-h|--help] [--tcp]\n", name);
log_dbg(" -h|--help display this usage\n");
log_dbg(" --tcp use TCP server socket instead of local unix socket\n");
}
int main (int argc, char * const * argv){
@ -498,8 +499,8 @@ int main (int argc, char * const * argv){
// make stderr/stdout unbuffered
setbuf(stderr, NULL);
setbuf(stdout, NULL);
printf("BTdaemon started - stdout\n");
fprintf(stderr,"BTdaemon started - stderr\n");
log_dbg("BTdaemon started - stdout\n");
log_err("BTdaemon started - stderr\n");
// handle CTRL-c
signal(SIGINT, daemon_sigint_handler);
@ -560,7 +561,7 @@ int main (int argc, char * const * argv){
timeout.process = daemon_no_connections_timeout;
#ifdef HAVE_RFCOMM
printf("config.h: HAVE_RFCOMM\n");
log_dbg("config.h: HAVE_RFCOMM\n");
rfcomm_init();
rfcomm_register_packet_handler(daemon_packet_handler);
#endif

View File

@ -43,6 +43,7 @@
#include <string.h>
#include <pthread.h>
#include "debug.h"
#include "hci.h"
#include "hci_transport.h"
#include "hci_dump.h"
@ -247,7 +248,7 @@ static void h4_statemachine(){
bytes_to_read = HCI_ACL_DATA_PKT_HDR;
h4_state = H4_W4_ACL_HEADER;
} else {
fprintf(stderr, "h4_process: invalid packet type 0x%02x\n", hci_packet[0]);
log_err("h4_process: invalid packet type 0x%02x\n", hci_packet[0]);
read_pos = 0;
bytes_to_read = 1;
}

View File

@ -1122,7 +1122,7 @@ void rfcomm_packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packe
// TODO: don't send 2 packets without getting a "done" from stack
// also start our negotiation
fprintf(stderr,"-> Sending MSC CMD for #%u (but should wait for l2cap credits)\n", message_dlci);
log_err("-> Sending MSC CMD for #%u (but should wait for l2cap credits)\n", message_dlci);
rfcomm_send_uih_msc_cmd(multiplexer, message_dlci, 0x8d); // ea=1,fc=0,rtc=1,rtr=1,ic=0,dv=1
rfChannel->state = RFCOMM_CHANNEL_W4_MSC_RSP;

View File

@ -42,6 +42,7 @@
#include "run_loop_private.h"
#include "debug.h"
#include "../config.h"
static run_loop_t * the_run_loop = NULL;
@ -60,7 +61,7 @@ extern run_loop_t run_loop_cocoa;
void run_loop_assert(){
#ifndef EMBEDDED
if (!the_run_loop){
fprintf(stderr, "ERROR: run_loop function called before run_loop_init!\n");
log_err("ERROR: run_loop function called before run_loop_init!\n");
exit(10);
}
#endif
@ -115,7 +116,7 @@ void run_loop_execute() {
void run_loop_init(RUN_LOOP_TYPE type){
#ifndef EMBEDDED
if (the_run_loop){
fprintf(stderr, "ERROR: run loop initialized twice!\n");
log_err("ERROR: run loop initialized twice!\n");
exit(10);
}
#endif
@ -135,7 +136,7 @@ void run_loop_init(RUN_LOOP_TYPE type){
#endif
default:
#ifndef EMBEDDED
fprintf(stderr, "ERROR: invalid run loop type %u selected!\n", type);
log_err("ERROR: invalid run loop type %u selected!\n", type);
exit(10);
#endif
break;

View File

@ -38,6 +38,7 @@
#include <btstack/run_loop.h>
#include <btstack/linked_list.h>
#include "debug.h"
#include "run_loop_private.h"
#include <sys/select.h>
@ -56,7 +57,7 @@ static linked_list_t timers;
*/
void posix_add_data_source(data_source_t *ds){
data_sources_modified = 1;
// printf("posix_add_data_source %x with fd %u\n", (int) ds, ds->fd);
// log_dbg("posix_add_data_source %x with fd %u\n", (int) ds, ds->fd);
linked_list_add(&data_sources, (linked_item_t *) ds);
}
@ -65,7 +66,7 @@ void posix_add_data_source(data_source_t *ds){
*/
int posix_remove_data_source(data_source_t *ds){
data_sources_modified = 1;
// printf("posix_remove_data_source %x\n", (int) ds);
// log_dbg("posix_remove_data_source %x\n", (int) ds);
return linked_list_remove(&data_sources, (linked_item_t *) ds);
}
@ -76,7 +77,7 @@ void posix_add_timer(timer_source_t *ts){
linked_item_t *it;
for (it = (linked_item_t *) &timers; it->next ; it = it->next){
if ((timer_source_t *) it->next == ts){
fprintf(stderr, "run_loop_timer_add error: timer to add already in list!\n");
log_err( "run_loop_timer_add error: timer to add already in list!\n");
return;
}
if (run_loop_timer_compare( (timer_source_t *) it->next, ts) > 0) {
@ -85,7 +86,7 @@ void posix_add_timer(timer_source_t *ts){
}
ts->item.next = it->next;
it->next = (linked_item_t *) ts;
// printf("Added timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// log_dbg("Added timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// posix_dump_timer();
}
@ -93,7 +94,7 @@ void posix_add_timer(timer_source_t *ts){
* Remove timer from run loop
*/
int posix_remove_timer(timer_source_t *ts){
// printf("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// log_dbg("Removed timer %x at %u\n", (int) ts, (unsigned int) ts->timeout.tv_sec);
// posix_dump_timer();
return linked_list_remove(&timers, (linked_item_t *) ts);
}
@ -103,7 +104,7 @@ void posix_dump_timer(){
int i = 0;
for (it = (linked_item_t *) timers; it ; it = it->next){
timer_source_t *ts = (timer_source_t*) it;
printf("timer %u, timeout %u\n", i, (unsigned int) ts->timeout.tv_sec);
log_dbg("timer %u, timeout %u\n", i, (unsigned int) ts->timeout.tv_sec);
}
}
@ -156,16 +157,16 @@ void posix_execute() {
// process data sources very carefully
// bt_control.close() triggered from a client can remove a different data source
// printf("posix_execute: before ds check\n");
// log_dbg("posix_execute: before ds check\n");
data_sources_modified = 0;
for (ds = (data_source_t *) data_sources; !data_sources_modified && ds != NULL; ds = (data_source_t *) ds->item.next){
// printf("posix_execute: check %x with fd %u\n", (int) ds, ds->fd);
// log_dbg("posix_execute: check %x with fd %u\n", (int) ds, ds->fd);
if (FD_ISSET(ds->fd, &descriptors)) {
// printf("posix_execute: process %x with fd %u\n", (int) ds, ds->fd);
// log_dbg("posix_execute: process %x with fd %u\n", (int) ds, ds->fd);
ds->process(ds);
}
}
// printf("posix_execute: after ds check\n");
// log_dbg("posix_execute: after ds check\n");
// process timers
// pre: 0 <= tv_usec < 1000000
@ -174,7 +175,7 @@ void posix_execute() {
ts = (timer_source_t *) timers;
if (ts->timeout.tv_sec > current_tv.tv_sec) break;
if (ts->timeout.tv_sec == current_tv.tv_sec && ts->timeout.tv_usec > current_tv.tv_usec) break;
// printf("posix_execute: process times %x\n", (int) ts);
// log_dbg("posix_execute: process times %x\n", (int) ts);
// remove timer before processing it to allow handler to re-register with run loop
run_loop_remove_timer(ts);

View File

@ -179,7 +179,7 @@ void static socket_connection_emit_nr_connections(){
event[0] = DAEMON_NR_CONNECTIONS_CHANGED;
event[1] = nr_connections;
(*socket_connection_packet_callback)(NULL, DAEMON_EVENT_PACKET, 0, (uint8_t *) &event, 2);
// printf("Nr connections changed,.. new %u\n", nr_connections);
// log_dbg("Nr connections changed,.. new %u\n", nr_connections);
}
int socket_connection_hci_process(struct data_source *ds) {
@ -280,7 +280,7 @@ static int socket_connection_accept(struct data_source *socket_ds) {
// no sigpipe
socket_connection_set_no_sigpipe(fd);
printf("socket_connection_accept new connection %u\n", fd);
log_dbg("socket_connection_accept new connection %u\n", fd);
connection_t * connection = socket_connection_register_new_connection(fd);
socket_connection_emit_connection_opened(connection);
@ -304,12 +304,12 @@ int socket_connection_create_tcp(int port){
// create tcp socket
if ((ds->fd = socket (PF_INET, SOCK_STREAM, 0)) < 0) {
fprintf (stderr, "Error creating socket ...(%s)\n", strerror(errno));
log_err("Error creating socket ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
printf ("Socket created for port %u\n", port);
log_dbg ("Socket created for port %u\n", port);
struct sockaddr_in addr;
addr.sin_family = AF_INET;
@ -320,20 +320,20 @@ int socket_connection_create_tcp(int port){
setsockopt(ds->fd, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(int));
if (bind ( ds->fd, (struct sockaddr *) &addr, sizeof (addr) ) ) {
fprintf(stderr, "Error on bind() ...(%s)\n", strerror(errno));
log_err("Error on bind() ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
if (listen (ds->fd, MAX_PENDING_CONNECTIONS)) {
fprintf (stderr, "Error on listen() ...(%s)\n", strerror(errno));
log_err("Error on listen() ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
run_loop_add_data_source(ds);
printf ("Server up and running ...\n");
log_dbg ("Server up and running ...\n");
return 0;
}
@ -349,7 +349,7 @@ void socket_connection_launchd_register_fd_array(launch_data_t listening_fd_arra
launch_data_t tempi = launch_data_array_get_index (listening_fd_array, i);
int listening_fd = launch_data_get_fd(tempi);
launch_data_free (tempi);
printf("file descriptor = %u\n",(unsigned int) i+1, listening_fd);
log_dbg("file descriptor = %u\n",(unsigned int) i+1, listening_fd);
// create data_source_t for fd
data_source_t *ds = malloc( sizeof(data_source_t));
@ -374,24 +374,24 @@ int socket_connection_create_launchd(){
*
*/
if ((checkin_request = launch_data_new_string(LAUNCH_KEY_CHECKIN)) == NULL) {
fprintf(stderr, "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.");
log_err( "launch_data_new_string(\"" LAUNCH_KEY_CHECKIN "\") Unable to create string.");
return -1;
}
if ((checkin_response = launch_msg(checkin_request)) == NULL) {
fprintf(stderr, "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %u", errno);
log_err( "launch_msg(\"" LAUNCH_KEY_CHECKIN "\") IPC failure: %u", errno);
return -1;
}
if (LAUNCH_DATA_ERRNO == launch_data_get_type(checkin_response)) {
errno = launch_data_get_errno(checkin_response);
fprintf(stderr, "Check-in failed: %u", errno);
log_err( "Check-in failed: %u", errno);
return -1;
}
launch_data_t the_label = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_LABEL);
if (NULL == the_label) {
fprintf(stderr, "No label found");
log_err( "No label found");
return -1;
}
@ -400,12 +400,12 @@ int socket_connection_create_launchd(){
*/
sockets_dict = launch_data_dict_lookup(checkin_response, LAUNCH_JOBKEY_SOCKETS);
if (NULL == sockets_dict) {
fprintf(stderr,"No sockets found to answer requests on!");
log_err("No sockets found to answer requests on!");
return -1;
}
// if (launch_data_dict_get_count(sockets_dict) > 1) {
// fprintf(stderr,"Some sockets will be ignored!");
// log_err("Some sockets will be ignored!");
// }
/*
@ -413,7 +413,7 @@ int socket_connection_create_launchd(){
*/
listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners");
if (listening_fd_array) {
// fprintf(stderr,"Listeners...\n");
// log_err("Listeners...\n");
socket_connection_launchd_register_fd_array( listening_fd_array );
}
@ -422,7 +422,7 @@ int socket_connection_create_launchd(){
*/
listening_fd_array = launch_data_dict_lookup(sockets_dict, "Listeners2");
if (listening_fd_array) {
// fprintf(stderr,"Listeners2...\n");
// log_err("Listeners2...\n");
socket_connection_launchd_register_fd_array( listening_fd_array );
}
@ -445,12 +445,12 @@ int socket_connection_create_unix(char *path){
// create unix socket
if ((ds->fd = socket (AF_UNIX, SOCK_STREAM, 0)) < 0) {
fprintf(stderr, "Error creating socket ...(%s)\n", strerror(errno));
log_err( "Error creating socket ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
printf ("Socket created at %s\n", path);
log_dbg ("Socket created at %s\n", path);
struct sockaddr_un addr;
bzero(&addr, sizeof(addr));
@ -462,20 +462,20 @@ int socket_connection_create_unix(char *path){
setsockopt(ds->fd, SOL_SOCKET, SO_REUSEADDR, &y, sizeof(int));
if (bind ( ds->fd, (struct sockaddr *) &addr, sizeof (addr) ) ) {
fprintf(stderr, "Error on bind() ...(%s)\n", strerror(errno));
log_err( "Error on bind() ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
if (listen (ds->fd, MAX_PENDING_CONNECTIONS)) {
fprintf(stderr, "Error on listen() ...(%s)\n", strerror(errno));
log_err( "Error on listen() ...(%s)\n", strerror(errno));
free(ds);
return -1;
}
run_loop_add_data_source(ds);
printf ("Server up and running ...\n");
log_dbg ("Server up and running ...\n");
return 0;
}

View File

@ -39,6 +39,7 @@
#include <btstack/utils.h>
#include <stdio.h>
#include "debug.h"
void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value){
buffer[pos++] = value;
@ -74,31 +75,25 @@ void bt_flip_addr(bd_addr_t dest, bd_addr_t src){
}
void hexdump(void *data, int size){
#ifndef EMBEDDED
int i;
for (i=0; i<size;i++){
printf("%02X ", ((uint8_t *)data)[i]);
log_dbg("%02X ", ((uint8_t *)data)[i]);
}
printf("\n");
#endif
log_dbg("\n");
}
void printUUID(uint8_t *uuid) {
#ifndef EMBEDDED
printf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
log_dbg("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid[0], uuid[1], uuid[2], uuid[3], uuid[4], uuid[5], uuid[6], uuid[7],
uuid[8], uuid[9], uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
#endif
}
void print_bd_addr( bd_addr_t addr){
#ifndef EMBEDDED
int i;
for (i=0; i<BD_ADDR_LEN-1;i++){
printf("%02X:", ((uint8_t *)addr)[i]);
log_dbg("%02X:", ((uint8_t *)addr)[i]);
}
printf("%02X", ((uint8_t *)addr)[i]);
#endif
log_dbg("%02X", ((uint8_t *)addr)[i]);
}
int sscan_bd_addr(uint8_t * addr_string, bd_addr_t addr){