/***************************************************************************** * vTaskCodeBackground: Demo Background Periodic Task * * RETURNS: None */ void vTaskCodeBackground( void * pvParameters ) { UINT32 count = 0; portSHORT cpuNo; UINT32 taskNum; char *pName; #ifdef INCLUDE_DEBUG_VGA int currentLine; char achBuffer[80]; #endif pName = ((TASKPARAM*)(pvParameters))->taskName; #ifdef INCLUDE_DEBUG_VGA currentLine = atomic32Inc( (UINT32 *) &startLine ); vgaClearLine( currentLine ); #endif cpuNo = sPortGetCurrentCPU(); taskNum = uxTaskNumGet( cpuNo, NULL ); #ifdef INCLUDE_MAIN_DEBUG DBLOG( "CPU:%d Starting T%02u: %s\n", cpuNo, taskNum, pName ); #endif for(;;) { atomic32Inc( (UINT32 *) &count ); #ifdef INCLUDE_DEBUG_VGA sprintf( achBuffer, "CPU:%d T%02u: %s Count: %u Idle count: %u", cpuNo, taskNum, pName, count, idleCount[cpuNo] ); vgaPutsXY( 1, currentLine, achBuffer ); #endif vTaskDelay( 1000 ); #ifdef FREERTOS_SEMA_TEST if ( count == 10 ) { /* Grab the debug message mutex to block other tasks */ /* User - check serial console output has stoppped */ xSemaphoreTake(globalMutexPool[MUTEX_DEBUG_STR_WRITE],portMAX_DELAY); } if ( count == 20 ) { /* Release the debug message */ /* User - check serial console output has resumed */ xSemaphoreGive(globalMutexPool[MUTEX_DEBUG_STR_WRITE]); count = 0; } #endif } }
void vGetUSMIPAddrs(char *pBuff) { #ifndef INCLUDE_USM_IP_ADDRESS struct netif *pNetif; static char buff[20]; static char zero_ip[] = "0.0.0.0"; #endif vTaskDelay(1000); #ifdef INCLUDE_USM_IP_ADDRESS #warning "***** SM Static IP address *****" strcpy(pBuff, USM_IP_ADDRESS); #else pNetif = netif_find( "ge0" ); if (pNetif != NULL) { sprintf (buff,"%u.%u.%u.%u",ip4_addr1_16(&pNetif->gw.addr), ip4_addr2_16(&pNetif->gw.addr), ip4_addr3_16(&pNetif->gw.addr), ip4_addr4_16(&pNetif->gw.addr)); strcpy(pBuff,buff); if ( strcmp(buff,zero_ip) == 0 ) { vTaskDelay(1000); /* Try ge1 interface on other MCH */ pNetif = netif_find( "ge1" ); if (pNetif != NULL) { sprintf (buff,"%u.%u.%u.%u",ip4_addr1_16(&pNetif->gw.addr), ip4_addr2_16(&pNetif->gw.addr), ip4_addr3_16(&pNetif->gw.addr), ip4_addr4_16(&pNetif->gw.addr)); strcpy(pBuff,buff); } else { strcpy(buff, "0.0.0.0"); strcpy(pBuff,buff); } } } else { strcpy(buff, "0.0.0.0"); strcpy(pBuff,buff); } #endif #ifdef INCLUDE_MAIN_DEBUG DBLOG( "Soak Master IP: %s\n", buff ); #endif }
int main( int argc, char* argv[] ) { if( !bSystem::init( argc, argv ) ) return -1; DBLOG( ">> Debug version\n" ); try { bSystem::video_sys.setup( GetConfig.screen_w, GetConfig.screen_h, GetConfig.depth, GetConfig.full_screen ); bSystem::draw_sys.create(); bSystem::font_sys.init(); bSystem::statemachine_sys.go_to( BS_SIMULATION ); while( bSystem::sdl_sys.update() ) { bSystem::mainloop_sys.update(); bSystem::video_sys.buffers(); } } catch( bException & e ) { std::cout << e.format() << std::endl; } catch( ... ) { std::cout << "!! Unknown exception occured!" << std::endl; } bSystem::font_sys.release(); bSystem::draw_sys.release(); bSystem::video_sys.release(); bSystem::release(); DBLOG( ">> Finished (debug trace written to \"debug_log.txt\")\n" ); return 0; }
/***************************************************************************** * startSth: Create and start the SM client and STH task. * This is done for development purposes only. * * RETURNS: None */ void startSth( void ) { static char buff[20]; xTaskHandle xHandle; #ifndef INCLUDE_USM_IP_ADDRESS struct netif *pNetif; #endif vTaskDelay(2000); #ifdef INCLUDE_USM_IP_ADDRESS strcpy(buff, USM_IP_ADDRESS); #else pNetif = netif_find( "ge0" ); if (pNetif != NULL) { sprintf (buff,"%u.%u.%u.%u",ip4_addr1_16(&pNetif->gw.addr), ip4_addr2_16(&pNetif->gw.addr), ip4_addr3_16(&pNetif->gw.addr), ip4_addr4_16(&pNetif->gw.addr)); } else { /* Try ge1 interface on other MCH */ pNetif = netif_find( "ge1" ); if (pNetif != NULL) { sprintf (buff,"%u.%u.%u.%u",ip4_addr1_16(&pNetif->gw.addr), ip4_addr2_16(&pNetif->gw.addr), ip4_addr3_16(&pNetif->gw.addr), ip4_addr4_16(&pNetif->gw.addr)); } else { strcpy(buff, "0.0.0.0"); } } #endif #ifdef INCLUDE_MAIN_DEBUG DBLOG( "Soak Master IP: %s\n", buff ); #endif #ifdef INCLUDE_LWIP_SMC startSmClient( buff ); #endif vTaskDelay(1000); xTaskCreate( 0, sthTask, "sth", mainCUTEBIT_TASK_STACKSIZE, NULL, mainCUTEBIT_TASK_PRIORITY, &xHandle ); }
static int file_sync_bitmap(struct file *f) { assert(f != NULL); int result; result = lseek(f->f_fd, SEEK_SET, 0); if (result) { result = DBELSEEK; DBLOG(result); goto done; } TRY(result, io_write(f->f_fd, bitmap_getdata(f->f_page_bitmap), PAGESIZE * FILE_BITMAP_PAGES), done); result = lseek(f->f_fd, SEEK_SET, 0); if (result) { result = DBELSEEK; DBLOG(result); goto done; } done: return result; }
/***************************************************************************** * vTaskCodePeriodic: Demo Periodic Task * * RETURNS: None */ void vTaskCodePeriodic( void * pvParameters ) { UINT32 count = 0; UINT32 taskNum; portSHORT cpuNo; portTickType delayTicks; char *pName; #ifdef INCLUDE_DEBUG_VGA int currentLine; char achBuffer[80]; #endif pName = ((TASKPARAM*)(pvParameters))->taskName; #ifdef INCLUDE_DEBUG_VGA currentLine = atomic32Inc( (UINT32 *) &startLine ); vgaClearLine( currentLine ); #endif cpuNo = sPortGetCurrentCPU(); taskNum = uxTaskNumGet( cpuNo, NULL ); #ifdef INCLUDE_MAIN_DEBUG DBLOG( "CPU:%d Starting T%02u: %s\n", cpuNo, taskNum, pName ); #endif for(;;) { atomic32Inc( (UINT32 *) &count ); // random delay, 1 - 1024 ticks delayTicks = (rand() & 0x03ff) + 1; #ifdef INCLUDE_DEBUG_VGA sprintf( achBuffer, "CPU:%d T%02u: %s Count: %u Delay ticks: %04lu", cpuNo, taskNum, pName, count, delayTicks ); vgaPutsXY( 1, currentLine, achBuffer ); #endif vTaskDelay( delayTicks ); } }
/* 主要功能:回滚事务 */ int CppMySQL3DB::rollback() { if(!mysql_real_query(_db_ptr, "ROLLBACK", (unsigned long)strlen("ROLLBACK") ) ) return 0; else { //执行查询失败 //--zhangmiao begin:11/28/2012 string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param:\"ROLLBACK\" \n" ); strError = errmsg(); strError += buffer; DBLOG( (int &)ERROR_ROLL_BACK_TRANSACTION , strError); //--zhangmiao end:11/28/2012 return -1; } }
/* 执行非返回结果查询 */ int CppMySQL3DB::execSQL(const char* sql) { if( !mysql_real_query( _db_ptr, sql, strlen(sql) ) ) { //得到受影响的行数 return (int)mysql_affected_rows(_db_ptr) ; } else { //执行查询失败 //--zhangmiao begin:11/28/2012 string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param: sql=(%s)\n" , sql ); strError = errmsg(); strError += buffer; DBLOG( (int &)ERROR_EXEC_TABLE , strError); //--zhangmiao end:11/28/2012 return -1; } }
/* 主要功能:开始事务 */ int CppMySQL3DB::startTransaction() { if(!mysql_real_query(_db_ptr, "START TRANSACTION" , (unsigned long)strlen("START TRANSACTION") )) { return 0; } else { //执行查询失败 //--zhangmiao begin:11/28/2012 string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param: START TRANSACTION\n" ); strError = errmsg(); strError += buffer; DBLOG( (int &)ERROR_START_TRANSACTION , strError); //--zhangmiao end:11/28/2012 return -1; } }
/* 主要功能:提交事务 */ int CppMySQL3DB::commit() { if(!mysql_real_query( _db_ptr, "COMMIT", (unsigned long)strlen("COMMIT") ) ) { return 0; } else { //执行查询失败 //--zhangmiao begin:11/28/2012 string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param:\"COMMIT\" \n" ); strError = errmsg(); strError += buffer; DBLOG( (int &)ERROR_COMMIT_TRANSACTION , strError); //--zhangmiao end:11/28/2012 return -1; } }
Result iStoragePfnInit(IStorage **ispp, u32 *pfns, u32 size) { IStorage *isp; u32 chunk_cnt; chunk_cnt = (size + VM_PAGE_SIZE - 1) / VM_PAGE_SIZE; isp = _iStorageAlloc(chunk_cnt); if ( !isp ) { return -1; } DBLOG("Chunk cnt %d\n", chunk_cnt); isp->is_pfns = pfns; isp->is_size = size; isp->is_chunk_len = VM_PAGE_SIZE; *ispp = isp; return 0; }
/* 处理返回多行的查询,返回影响的行数 */ CppMySQLQuery& CppMySQL3DB::querySQL(const char *sql,int &iResult) { //wzp 2012-09-11 modify; /* if ( !mysql_real_query( _db_ptr, sql, strlen(sql) ) ) { _db_query._mysql_res = mysql_store_result( _db_ptr ); // _db_query._row = mysql_fetch_row( _db_query._mysql_res ); // _db_query._row_count = mysql_num_rows( _db_query._mysql_res ); // //得到字段数量 // _db_query._field_count = mysql_num_fields( _db_query._mysql_res ); } return _db_query;*/ iResult = mysql_real_query( _db_ptr, sql, strlen(sql)); if(iResult == 0) { //wzp add in 2012-9-24 if(_db_query._mysql_res != NULL) { mysql_free_result(_db_query._mysql_res); _db_query._mysql_res = NULL; } //wzp add end; _db_query._mysql_res = mysql_store_result( _db_ptr ); } //--zhangmiao begin:11/28/2012 else { string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param: sql=(%s)\n" , sql ); strError = errmsg(); strError += buffer; DBLOG((int &)ERROR_QUERY_TABLE,strError); } //--zhangmiao end:11/28/2012 return _db_query; }
static Result _iStorageIO(IStorage *isp, u32 *pOut, u8 *buf_out, const u8 *buf_in, u32 size, bool isRead) { u32 bytes; u32 cnt; u32 chunk; u32 chunk_off; u32 cpy_cnt; u32 chunk_avail; // Sanity check if ( isRead && (isp->is_flags & IS_FLG_NULL) ) { return -1; } bytes = (isp->is_pos + size > isp->is_size) ? isp->is_size - isp->is_pos : size; // this loop can be optimized for( cnt = bytes ; cnt ; cnt -= cpy_cnt ) { chunk = isp->is_pos / isp->is_chunk_len; chunk_off = isp->is_pos % isp->is_chunk_len; chunk_avail = isp->is_chunk_len - chunk_off; cpy_cnt = (cnt > chunk_avail) ? chunk_avail : cnt; // If this is a pfn map, map in the page if ( isp->is_pfns ) { if ( pfn_map((void **)&isp->is_chunks[chunk], isp->is_pfns[chunk]) ) { DBLOG("Failed pfn map!\n"); return -1; } } if ( !(isp->is_flags & IS_FLG_NULL) && (isp->is_chunks[chunk] == 0) ) { DBLOG_N("Invalid chunk pointer - chunk %d", chunk); return -1; } if ( isRead ) { memcpy(buf_out, isp->is_chunks[chunk]+chunk_off, cpy_cnt); buf_out += cpy_cnt; } else if ( !(isp->is_flags & IS_FLG_NULL) ) { memcpy(isp->is_chunks[chunk]+chunk_off, buf_in, cpy_cnt); buf_in += cpy_cnt; } if ( isp->is_pfns ) { pfn_unmap(isp->is_pfns[chunk], 0); isp->is_chunks[chunk] = NULL; } isp->is_pos += cpy_cnt; } *pOut = bytes; return 0; }
struct csv_resultarray * csv_parse(int fd) { int result; struct csv_resultarray *results = NULL; result = lseek(fd, 0, SEEK_SET); if (result) { result = DBELSEEK; DBLOG(result); goto done; } FILE *file; TRYNULL(result, DBEIONOFILE, file, fdopen(fd, "r"), done); TRYNULL(result, DBENOMEM, results, csv_resultarray_create(), cleanup_file); char buf[BUFSIZE]; bzero(buf, BUFSIZE); char c; unsigned ix = 0; while ((c = fgetc(file)) != EOF) { if (c == '\n' || c == ',') { buf[ix] = '\0'; struct csv_result *header; TRYNULL(result, DBENOMEM, header, malloc(sizeof(struct csv_result)), free_csv_resultarray); TRYNULL(result, DBENOMEM, header->csv_vals, intarray_create(), free_csv_resultarray); TRY(result, csv_resultarray_add(results, header, NULL), free_csv_resultarray); strcpy(header->csv_colname, buf); ix = 0; bzero(buf, BUFSIZE); if (c == '\n') { break; } } else { buf[ix++] = c; } } if (c == EOF) { result = DBEIOEARLYEOF; DBLOG(result); goto free_csv_resultarray; } // loop until we have no more rows ix = 0; unsigned colnum = 0; while ((c = fgetc(file)) != EOF) { if (c == '\n' || c == ',') { buf[ix] = '\0'; int val = atoi(buf); struct csv_result *header = csv_resultarray_get(results, colnum); TRY(result, intarray_add(header->csv_vals, (void *) val, NULL), free_csv_resultarray); ix = 0; bzero(buf, BUFSIZE); if (c == '\n') { colnum = 0; } else { colnum++; } } else { buf[ix++] = c; } } // success goto cleanup_file; free_csv_resultarray: csv_destroy(results); results = NULL; cleanup_file: assert(fclose(file) == 0); done: return results; }
/***************************************************************************** * c_entry: this is our main() function, called from boot_prot.S * * RETURNS: None */ __attribute__((regparm(0))) void c_entry (void) { xTaskHandle xHandle; UINT8 i=0,bFlag = 0; UINT16 port, baud = 0; NV_RW_Data nvdata; #ifdef INCLUDE_DEBUG_VGA char achBuffer[80]; #endif #if 0 /* Not used, HAL no longer present */ /* * Register the local service provider now, as code will be using BIT * services for PCI accesses. */ cctRegisterServiceProvider (cctServiceProvider); #endif /* * Key sub-system initialisation */ sysMmuInitialize (); /* Initialise the local page table management */ sysInitMalloc (K_HEAP, U_HEAP); /* Initialise the heap management */ #ifdef INCLUDE_EXCEPTION_DEBUG dbgInstallExceptionHandlers(); #endif #ifdef INCLUDE_DBGLOG dbgLogInit(); #endif /*Initialise the mutexes so that we can start using the public functions*/ for(i=0; i < MAX_CUTEBIT_MUTEX; i++) { globalMutexPool[i]=xSemaphoreCreateMutex(); if( globalMutexPool[i] == NULL ) { /*We should not get here, die...*/ while(1); } } /* * Search and parse BIOS_INFO and EXTENDED_INFO structures */ board_service(SERVICE__BRD_GET_BIOS_INFO, NULL, &dBiosInfo_addr); board_service(SERVICE__BRD_GET_EXTENDED_INFO, NULL, NULL); /* * Open/close the debug channel and sign-on - we can't use vDebugWrite() this * early, so make direct calls to sysDebug... */ if(bStartupDebugMode()) { sysDebugWriteString ("\n[Debugging Enabled]\n"); if(sysIsDebugopen()) { if(board_service(SERVICE__BRD_GET_FORCE_DEBUG_OFF, NULL, NULL) == E__OK) { sysDebugWriteString ("[Debugging Forced Off]\n"); sysDebugClose(); } } } else if( board_service(SERVICE__BRD_GET_FORCE_DEBUG_ON, NULL, NULL) == E__OK ) { sysDebugWriteString ("[Debugging Forced On]\n"); bForceStartupDebugMode(); sysDebugOpen(); } sysDebugFlush (); #ifdef INCLUDE_DEBUG_VGA vgaDisplayInit(); vgaSetCursor( CURSOR_OFF ); #endif sysDebugWriteString ("Starting HW Initialization\n"); board_service(SERVICE__BRD_HARDWARE_INIT, NULL, NULL); /* board-specific H/W initialisation */ if(board_service(SERVICE__BRD_GET_CONSOLE_PORT, NULL, &port) == E__OK) { baud = bGetBaudRate(); //baud = 0; //hard coded by Rajan. Need to remove after debug sysSccInit (port, baud); #ifdef INCLUDE_DEBUG_VGA sprintf( achBuffer, "Console open, port: 0x%x baud: %u\n", port, baud ); vgaPutsXY( 0, startLine++, achBuffer ); #endif } if(board_service(SERVICE__BRD_GET_DEBUG_PORT, NULL, &port) == E__OK) { //#ifdef commented by Rajan. Need to uncomment after debug //#ifdef INCLUDE_DEBUG_PORT_INIT baud = bGetBaudRate(); baud = 0; //hard coded by Rajan. Need to remove after debug sysSccInit (port, baud); //#endif #ifdef INCLUDE_DEBUG_VGA sprintf( achBuffer, "Debug %s, port: 0x%x baud: %u\n", (sysIsDebugopen()? "open":"closed"), port, baud ); vgaPutsXY( 0, startLine++, achBuffer ); #endif } #ifdef INCLUDE_MAIN_DEBUG { UINT32 temp = 0; board_service(SERVICE__BRD_GET_MAX_DRAM_BELOW_4GB, NULL, &temp); DBLOG( "Max DRAM below 4GB: 0x%08x\n", temp ); } #endif #if defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE) #if defined(VPX) vpxPreInit(); #endif #if defined(CPCI) board_service(SERVICE__BRD_CHECK_CPCI_IS_SYSCON,NULL,&bFlag); cpciPreInit(bFlag); #endif board_service(SERVICE__BRD_CONFIGURE_VXS_NT_PORTS, NULL, NULL); #endif #if defined (SRIO) sysDebugWriteString ("Initializing: SRIO\n"); for (i = 1 ; i < MAX_TSI721_DEVS; i++) { srioPreInit (i); } #endif #ifndef CPCI if (!bFlag) vDelay(2000);// delay added, so pmc160 will show up! #endif sysDebugWriteString ("Initializing: PCI\n"); sysPciInitialize (); /* (re)scan PCI and allocate resources */ sysDebugWriteString ("Rajan--> Step1\n"); #if defined(MAKE_CUTE) || defined (MAKE_BIT_CUTE) #if defined (VME) && defined (INCLUDE_LWIP_SMC) // pci bus enumeration must have been run InitialiseVMEDevice(); #endif #endif sysDebugWriteString ("Rajan--> Step2\n"); #ifdef INCLUDE_DEBUG_VGA vgaPutsXY( 0, startLine, "FreeRTOS starting....\n\n" ); startLine += 2; #endif board_service(SERVICE__BRD_POST_SCAN_INIT, NULL, NULL); // post scan H/W initialisations board_service(SERVICE__BRD_ENABLE_SMIC_LPC_IOWINDOW, NULL, NULL); /* board-specific smic Initialization */ /* * Having got this far, clear the load error that we've been holding in CMOS */ nvdata.dNvToken = NV__TEST_NUMBER; nvdata.dData = 0; board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata); nvdata.dNvToken = NV__ERROR_CODE; nvdata.dData = E__BOARD_HANG; board_service(SERVICE__BRD_NV_WRITE, NULL, &nvdata); #ifdef INCLUDE_MAIN_DEBUG DBLOG( "CUTE/BIT Kernel heap: 0x%08x-0x%08x\n", (UINT32)K_HEAP, ((UINT32)K_HEAP + HEAP_SIZE - 1) ); DBLOG( "CUTE/BIT User heap : 0x%08x-0x%08x\n", (UINT32)U_HEAP, ((UINT32)U_HEAP + HEAP_SIZE - 1) ); xPortGetFreeHeapSize(); #endif /* Initialise task data */ vTaskDataInit( bCpuCount ); /* Initialise PCI shared interrupt handling */ pciIntInit(); #ifdef INCLUDE_MAIN_DEBUG pciListDevs( 0 ); #endif /* Create and start the network */ sysDebugWriteString ("Initializing: Network\n"); networkInit(); #if defined(SRIO) sysDebugWriteString ("Initializing: TSI721\n"); for (i = 1 ; i < MAX_TSI721_DEVS; i++) { tsi721_init(i); } rio_init_mports(); #endif // some boards may not reset the RTC cleanly board_service(SERVICE__BRD_INIT_RTC, NULL, NULL); #ifdef INCLUDE_DEMO_TASKS randMutex = xSemaphoreCreateMutex(); if (randMutex == NULL) { sysDebugWriteString ("Error - Failed to create rand mutex\n"); } else { for (i = 0; i < bCpuConfigured; i++) { tParam[i].taskNum = i + 1; sprintf( tParam[i].taskName, "Demo%u", tParam[i].taskNum ); xTaskCreate( i, vTaskCodePeriodic, tParam[i].taskName, mainDEMO_STACK_SIZE, &tParam[i], mainDEMO_TASK_PRIORITY, &xHandle ); } tParam[i].taskNum = i + 1; sprintf( tParam[i].taskName, "BKGRD" ); xTaskCreate( 0, vTaskCodeBackground, tParam[i].taskName, mainDEMO_STACK_SIZE, &tParam[i], mainDEMO_TASK_PRIORITY+1, &xHandle ); } #endif sysDebugWriteString ("Creating CUTE task\n"); xTaskCreate( 0, startCuteBit, "CuteBitTask", mainCUTEBIT_TASK_STACKSIZE, NULL, mainCUTEBIT_TASK_PRIORITY, &xHandle ); #ifdef INCLUDE_MAIN_DEBUG sysDebugWriteString ("\n[Starting FreeRtos Scheduler]\n"); sysDebugFlush (); #endif sysInvalidateTLB(); /* Start the FreeRTOS Scheduler, does not return */ vTaskStartScheduler(); } /* c_entry () */
int CppMySQL3DB::open(const char* host, const char* user, const char* passwd, const char* db, unsigned int port /*= 0*/, unsigned long client_flag /*= 0*/) { int ret = -1; _db_ptr = mysql_init(NULL); if( NULL == _db_ptr ) goto EXT; //如果连接失败,返回NULL。对于成功的连接,返回值与第1个参数的值相同。 if ( NULL == mysql_real_connect( _db_ptr, host, user, passwd, db,port, NULL, client_flag) ) goto EXT; /* 设置数据库默认字符集 */ if ( mysql_set_character_set( _db_ptr, "utf8" ) != 0 ) { fprintf ( stderr , "错误, %s/n" , mysql_error( _db_ptr) ) ; } //选择制定的数据库失败 //0表示成功,非0值表示出现错误。 if ( mysql_select_db( _db_ptr, db ) != 0 ) { mysql_close(_db_ptr); _db_ptr = NULL; goto EXT; } ret = 0; EXT: //初始化mysql结构失败 if ( ret == -1 && _db_ptr != NULL ) { //--zhangmiao begin:11/28/2012 string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param: host(%s),user(%s),passwd(%s),DB(%s),port(%d),client_flag(%lu)\n" ,host ,user, passwd, db, port, client_flag ); strError = errmsg(); strError += buffer; DBLOG((int &)ERROR_OPEN_DATABASE,strError); //printf("%s\n",strError.c_str()); //--zhangmiao end:11/28/2012 mysql_close( _db_ptr ); _db_ptr = NULL; } //--zhangmiao begin:11/28/2012 else if ( ret == -1 && _db_ptr == NULL ) { string strError; char buffer[BUFSIZE]=""; sprintf( buffer , "mysql param: host(%s),user(%s),passwd(%s),DB(%s),port(%d),client_flag(%lu)\n" ,host ,user, passwd, db, port, client_flag ); strError = errmsg(); strError += buffer; DBLOG((int &)ERROR_OPEN_DATABASE,strError); //printf("%s\n",strError.c_str()); } //--zhangmiao end:11/28/2012 return ret; }
bool AudioFileReader::openFile(const std::string& filename) { // close file if one is opened if (m_sndfile) { if (verboseFlag) cerr << "WARNING: close old audio file when opening " << filename << endl; closeFile(); } memset(&m_sfinfo, 0, sizeof(SF_INFO)); m_sndfile = sf_open(filename.c_str(), SFM_READ, &m_sfinfo); if (!m_sndfile) { cerr << "ERROR: cannot open audio file " << filename << ": " << sf_strerror(m_sndfile) << endl; return false; } if (m_sfinfo.channels > 1) { if (m_sfinfo.channels > 2) { cerr << "ERROR: AudioFileReader cannot handle audio files with more than 2 channels !" << endl; closeFile(); return false; } DBLOG_IF(m_sfinfo.channels > 1, "Warning: AudioFileReader will convert stereo " "audio file to mono doing mean of channels"); } if (m_resample && (m_sampleRate!=m_sfinfo.samplerate)) { int fsin = m_sfinfo.samplerate; m_filter = SmarcPFilterCache::getPFilter(fsin,m_sampleRate); if (!m_filter) return false; m_state = smarc_init_pstate(m_filter); m_resampleBufferSize = smarc_get_output_buffer_size(m_filter,m_bufferSize); m_resampleBuffer = new double[m_resampleBufferSize]; if (m_resampleBufferSize>(2*m_bufferSize)) { delete [] m_readBuffer; m_readBuffer = new double[m_resampleBufferSize]; } } sf_count_t startFrame = static_cast<sf_count_t>(m_startSecond * m_sampleRate); m_frameLeft = static_cast<sf_count_t>(m_limitSecond * m_sampleRate); if (startFrame <= -m_sfinfo.frames) { startFrame = 0; } int res = 0; if (startFrame !=0) { if (!m_sfinfo.seekable) { cerr << "ERROR: audio file " << filename << " is not seekable!" << endl; return false; } if (startFrame > 0) { res = sf_seek(m_sndfile, startFrame, SEEK_SET); } else { res = sf_seek(m_sndfile, startFrame, SEEK_END); } } if (res == -1) { cerr << "ERROR: cannot seek start in audio file !" << endl; return false; } DBLOG("AudioFileReader::openFile startFrame: %lld, m_frameLeft: %lld", startFrame, m_frameLeft); return true; }