11573Srgrimes/* 21573Srgrimes * Auvia BeOS Driver for Via VT82xx Southbridge audio 31573Srgrimes * 41573Srgrimes * Copyright (c) 2003, Jerome Duval (jerome.duval@free.fr) 51573Srgrimes * 61573Srgrimes * Original code : BeOS Driver for Intel ICH AC'97 Link interface 71573Srgrimes * Copyright (c) 2002, Marcus Overhagen <marcus@overhagen.de> 81573Srgrimes * 91573Srgrimes * All rights reserved. 101573Srgrimes * Redistribution and use in source and binary forms, with or without modification, 111573Srgrimes * are permitted provided that the following conditions are met: 121573Srgrimes * 131573Srgrimes * - Redistributions of source code must retain the above copyright notice, 141573Srgrimes * this list of conditions and the following disclaimer. 151573Srgrimes * - Redistributions in binary form must reproduce the above copyright notice, 161573Srgrimes * this list of conditions and the following disclaimer in the documentation 171573Srgrimes * and/or other materials provided with the distribution. 181573Srgrimes * 191573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 201573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 211573Srgrimes * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 221573Srgrimes * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 231573Srgrimes * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 241573Srgrimes * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 251573Srgrimes * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 261573Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 271573Srgrimes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 281573Srgrimes * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2950476Speter * 301573Srgrimes */ 311573Srgrimes 321573Srgrimes 3379531Sru#include <KernelExport.h> 341573Srgrimes 351573Srgrimes#include <fcntl.h> 361573Srgrimes#include <stdio.h> 3759460Sphantom#include <string.h> 3859460Sphantom#include <unistd.h> 391573Srgrimes 4084306Sru#include <directories.h> 411573Srgrimes#include <OS.h> 421573Srgrimes 431573Srgrimes#include "debug.h" 441573Srgrimes#include "auvia.h" 451573Srgrimes 461573Srgrimes 471573Srgrimes#if DEBUG > 0 48131504Srustatic const char *logfile = kSystemLogDirectory "/auvia.log"; 49131504Srustatic sem_id loglock; 501573Srgrimes#endif 511573Srgrimes 521573Srgrimes 531573Srgrimesvoid debug_printf(const char *text,...); 541573Srgrimesvoid log_printf(const char *text,...); 551573Srgrimesvoid log_create(void); 561573Srgrimes 571573Srgrimes 581573Srgrimesvoid debug_printf(const char *text,...) 591573Srgrimes{ 601573Srgrimes char buf[1024]; 611573Srgrimes va_list ap; 621573Srgrimes 631573Srgrimes va_start(ap,text); 641573Srgrimes vsprintf(buf,text,ap); 651573Srgrimes va_end(ap); 661573Srgrimes 671573Srgrimes dprintf(DRIVER_NAME ": %s",buf); 681573Srgrimes} 691573Srgrimes 701573Srgrimes 711573Srgrimesvoid log_create() 721573Srgrimes{ 73108028Sru#if DEBUG > 0 741573Srgrimes int fd = open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0666); 751573Srgrimes const char *text = DRIVER_NAME ", " VERSION "\n"; 76149956Srwatson loglock = create_sem(1,"logfile sem"); 771573Srgrimes write(fd,text,strlen(text)); 781573Srgrimes close(fd); 791573Srgrimes#endif 801573Srgrimes} 811573Srgrimes 82108028Sru 8320097Swoschvoid log_printf(const char *text,...) 8417906Swosch{ 85108028Sru#if DEBUG > 0 8617906Swosch int fd; 87108028Sru char buf[1024]; 8817906Swosch va_list ap; 89 90 va_start(ap,text); 91 vsprintf(buf,text,ap); 92 va_end(ap); 93 94 dprintf(DRIVER_NAME ": %s",buf); 95 96 acquire_sem(loglock); 97 fd = open(logfile, O_WRONLY | O_APPEND); 98 write(fd,buf,strlen(buf)); 99 close(fd); 100 release_sem(loglock); 101 102 #if DEBUG > 1 103 snooze(150000); 104 #endif 105#endif 106} 107