diff --git a/devicemodel/hw/platform/ioc.c b/devicemodel/hw/platform/ioc.c index 634d609b2..31ff5bf83 100644 --- a/devicemodel/hw/platform/ioc.c +++ b/devicemodel/hw/platform/ioc.c @@ -90,14 +90,21 @@ #include "ioc.h" -/* - * Debug printf - */ +/* For debugging log to a file */ static int ioc_debug; -#define DPRINTF(fmt, args...) \ - do { if (ioc_debug) printf(fmt, ##args); } while (0) -#define WPRINTF(fmt, args...) printf(fmt, ##args) - +static FILE *dbg_file; +#define IOC_LOG_INIT do { if (ioc_debug) {\ + dbg_file = fopen("/tmp/ioc_log", "w+");\ +if (!dbg_file)\ + printf("ioc log open failed\r\n"); else cbc_set_log_file(dbg_file);\ +} } while (0) +#define IOC_LOG_DEINIT do { if (dbg_file) fclose(dbg_file); dbg_file = NULL;\ +cbc_set_log_file(dbg_file);\ +} while (0) +#define DPRINTF(format, arg...) \ +do { if (ioc_debug && dbg_file) { fprintf(dbg_file, format, arg);\ + fflush(dbg_file); } } while (0) +#define WPRINTF(format, arg...) printf(format, ##arg) /* * Type definition for thread function. @@ -1096,7 +1103,7 @@ ioc_create_thread(const char *name, pthread_t *tid, ioc_work func, void *arg) { if (pthread_create(tid, NULL, func, arg) != 0) { - DPRINTF("ioc can not create thread\r\n"); + DPRINTF("%s", "ioc can not create thread\r\n"); return -1; } pthread_setname_np(*tid, name); @@ -1146,6 +1153,8 @@ ioc_init(void) int i; struct ioc_dev *ioc; + IOC_LOG_INIT; + if (ioc_is_platform_supported() != 0) goto ioc_err; @@ -1261,6 +1270,7 @@ alloc_err: free(ioc->pool); free(ioc); ioc_err: + IOC_LOG_DEINIT; DPRINTF("%s", "ioc mediator startup failed!!\r\n"); return NULL; } @@ -1281,4 +1291,5 @@ ioc_deinit(struct ioc_dev *ioc) free(ioc->evts); free(ioc->pool); free(ioc); + IOC_LOG_DEINIT; } diff --git a/devicemodel/hw/platform/ioc_cbc.c b/devicemodel/hw/platform/ioc_cbc.c index 07851c6be..384d8e10f 100644 --- a/devicemodel/hw/platform/ioc_cbc.c +++ b/devicemodel/hw/platform/ioc_cbc.c @@ -41,9 +41,11 @@ * Debug printf */ static int ioc_cbc_debug; -#define DPRINTF(fmt, args...) \ - do { if (ioc_cbc_debug) printf(fmt, ##args); } while (0) -#define WPRINTF(fmt, args...) printf(fmt, ##args) +static FILE *dbg_file; +#define DPRINTF(format, arg...) \ +do { if (ioc_cbc_debug && dbg_file) { fprintf(dbg_file, format, arg);\ + fflush(dbg_file); } } while (0) +#define WPRINTF(format, arg...) printf(format, ##arg) static void cbc_send_pkt(struct cbc_pkt *pkt); @@ -895,3 +897,12 @@ wlist_init_signal(struct cbc_signal *cbc_tbl, size_t cbc_size, } } } + +/* + * Share log file with IOC. + */ +void +cbc_set_log_file(FILE *f) +{ + dbg_file = f; +} diff --git a/devicemodel/include/ioc.h b/devicemodel/include/ioc.h index 49b0ed5c4..c9b79cab7 100644 --- a/devicemodel/include/ioc.h +++ b/devicemodel/include/ioc.h @@ -735,4 +735,7 @@ void wlist_init_signal(struct cbc_signal *cbc_tbl, size_t cbc_size, struct wlist_signal *wlist_tbl, size_t wlist_size); void wlist_init_group(struct cbc_group *cbc_tbl, size_t cbc_size, struct wlist_group *wlist_tbl, size_t wlist_size); + +/* Set CBC log file */ +void cbc_set_log_file(FILE *f); #endif