LONG_PTR D5DArchive::Callback (int nMsg, int nParam1, LONG_PTR nParam2) { if ( m_pfnCallback ) return m_pfnCallback (m_hCallback, nMsg, nParam1, nParam2); return FALSE; }
void CLogFile::PrintToFile(const char * szString) { // Lock the mutex m_mutex.TryLock(1); // If we have a callback and it is enabled call it if(m_bUseCallback && m_pfnCallback) m_pfnCallback(szString); // Is the log file open? if(m_fLogFile) { // Log the message if(m_bUseTimeStamp) fprintf(m_fLogFile, "%s\n", szString); else fprintf(m_fLogFile, "%s\n", szString); // Flush the log file buffer fflush(m_fLogFile); } // Unlock the mutex m_mutex.Unlock(); }
void AtMonitor::DoCallback(unsigned int nErrCode) { if (m_pfnCallback) { m_pfnCallback(nErrCode); } m_nStatus = nErrCode; m_nMonitor = 0; m_pfnCallback = NULL; m_pCondition = NULL; ::ReleaseSemaphore(m_hStatusSemaphore, 1, NULL); }
//////////////////////////////////////////////////////////////////////////// // // @mfunc | CVisRefCntMemBlock | ~CVisRefCntMemBlock | // // Destructor called when this object is destroyed. If this // object allocated memory in its constructor, that memory // will be freed when the destructor is called. The destructor // is virtual so that other classes can be derived from this // class. // //////////////////////////////////////////////////////////////////////////// CVisRefCntMemBlock::~CVisRefCntMemBlock(void) { #ifdef _DEBUG if (m_pbData != 0) { // Decrement the count of blocks of this type. if ((m_evismemblock != evismemblockAllocFileMapping) && (m_evismemblock != evismemblockAllocGlobalAlloc) #ifdef VIS_MEMBLOCK_USE_IMALLOC && (m_evismemblock != evismemblockAllocIMalloc) #endif // VIS_MEMBLOCK_USE_IMALLOC && (m_evismemblock != evismemblockAllocNewDouble)) { -- s_cBlockExternal; s_cbExternalTotal -= m_cbData; } else { assert((m_evismemblock > 0) && (m_evismemblock <= cMemBlockAllocators)); -- s_cBlockAlloc[m_evismemblock]; s_cbAllocTotal[m_evismemblock] -= m_cbData; } // Ref count may not be zero if delete is used to destroy this // object. s_cAddRefTotal -= m_cRef; // Remove this memory block to the globals list of all memory blocks // currently in use. HANDLE hMutex = CreateMutex(0, FALSE, "CVisRefCntMemBlockDebugMutex"); assert(hMutex != 0); VisWaitForSingleObject(hMutex, INFINITE); CVisRefCntMemBlock *pRefCntMemBlockPrev = 0; CVisRefCntMemBlock *pRefCntMemBlock = s_pRefCntMemBlockFirst; while ((pRefCntMemBlock != this) && (pRefCntMemBlock != 0)) { pRefCntMemBlockPrev = pRefCntMemBlock; pRefCntMemBlock = pRefCntMemBlock->m_pRefCntMemBlockNext; } if (pRefCntMemBlock != 0) { if (pRefCntMemBlockPrev == 0) { s_pRefCntMemBlockFirst = m_pRefCntMemBlockNext; m_pRefCntMemBlockNext = 0; } else { pRefCntMemBlockPrev->m_pRefCntMemBlockNext = m_pRefCntMemBlockNext; m_pRefCntMemBlockNext = 0; } } ReleaseMutex(hMutex); CloseHandle(hMutex); } #endif // _DEBUG if (m_evismemblock == evismemblockAllocFileMapping) { // Free memory allocated using CreateFileMapping. assert(m_pbData != 0); UnmapViewOfFile(m_pbData); CloseHandle(m_hFileMapping); m_hFileMapping = 0; } else if (m_evismemblock == evismemblockAllocNewDouble) { // Free memory allocated using operator new. delete [] (double *) m_pbData; } else if (m_evismemblock == evismemblockAllocGlobalAlloc) { // Free memory allocated using GlobalAlloc. GlobalFree(m_pbData); } #ifdef VIS_MEMBLOCK_USE_IMALLOC else if (m_evismemblock == evismemblockAllocIMalloc) { // Allocate memory using the OLE task allocator. CoTaskMemFree(m_pbData); } #endif // VIS_MEMBLOCK_USE_IMALLOC else if (m_evismemblock == evismemblockAllocDirectDrawSurface) { // Release memory allocated using DirectDrawSurface assert(m_pvUser != 0); IDirectDrawSurface* pDDS = (IDirectDrawSurface *)m_pvUser; pDDS->Release(); } else if (m_pfnCallback != 0) { m_pfnCallback(m_pbData, m_pvUser); } m_pbData = 0; }
void CGpioControl::RunMonitoring() { #ifdef __TI_AM335X__ int nEvent; int i = 0; unsigned int nValue = 0; struct epoll_event *events; char buf[64]; int bufsize=sizeof(buf); GPIOENTRY *pGpio; events = (struct epoll_event *)malloc(sizeof(*events) * INPUT_GPIO_MAX ); for(;!m_bExitPending;) { nEvent = epoll_wait( m_nEpfd ,events , INPUT_GPIO_MAX , 3000000); for(i =0 ; i < nEvent ; i++) { pGpio = (GPIOENTRY*)events[i].data.ptr ; memset(buf, 0, bufsize); lseek(pGpio->fd, 0, SEEK_SET); if ( read(pGpio->fd, buf, bufsize) ) { nValue = strtol(buf, (char**)NULL, 10); //if (nValue) nValue = 1; if (pGpio->nValue != nValue) { if (m_bEnableHooker && (m_pfnCallback != NULL)) { pGpio->nValue = nValue ; m_Locker.Lock(); m_pfnCallback(pGpio->mask, nValue, m_pParam, m_pArgment); m_Locker.Unlock(); } } } } USLEEP(3000000); } nEvent = epoll_wait( m_nEpfd ,events , INPUT_GPIO_MAX , 1000000); for(i =0 ; i < nEvent ; i++) { pGpio = (GPIOENTRY*)events[i].data.ptr ; epoll_ctl(m_nEpfd, EPOLL_CTL_DEL , pGpio->fd, events); free(events[i].data.ptr); close(pGpio->fd); } free(events); #else struct timeval timeout; fd_set rset; int fd, n; int dcd, low, pwr, ring; int heater, door, charge; BYTE oldDCD, oldPWR, oldBAT, oldRING; BYTE oldHEATER, oldDOOR, oldCHARGE; fd = m_nFD; m_gpioLocker.Lock(); oldDCD = ioctl(fd, GPIO_IOCTL_IN, GP_GSM_DCD_INPUT); oldPWR = ioctl(fd, GPIO_IOCTL_IN, GP_PWR_FAIL_INPUT); oldBAT = ioctl(fd, GPIO_IOCTL_IN, GP_LOW_BATT_INPUT); oldRING = ioctl(fd, GPIO_IOCTL_IN, GP_GSM_RI_INPUT); oldDOOR = ioctl(fd, GPIO_IOCTL_IN, GP_DOOR_OPEN_INPUT); oldHEATER = ioctl(fd, GPIO_IOCTL_IN, GP_TEMP_OS_INPUT); oldCHARGE = ioctl(fd, GPIO_IOCTL_IN, GP_BATT_CHG_STATUS_INPUT); m_gpioLocker.Unlock(); for(;!m_bExitPending;) { FD_ZERO(&rset); FD_SET(fd, &rset); timeout.tv_sec = 3; timeout.tv_usec = 0; n = select(fd+1, &rset, NULL, NULL, &timeout); if (n == -1) break; if (FD_ISSET(fd, &rset)) { m_gpioLocker.Lock(); dcd = ioctl(fd, GPIO_IOCTL_IN, GP_GSM_DCD_INPUT); pwr = ioctl(fd, GPIO_IOCTL_IN, GP_PWR_FAIL_INPUT); low = ioctl(fd, GPIO_IOCTL_IN, GP_LOW_BATT_INPUT); ring = ioctl(fd, GPIO_IOCTL_IN, GP_GSM_RI_INPUT); door = ioctl(fd, GPIO_IOCTL_IN, GP_DOOR_OPEN_INPUT); heater = ioctl(fd, GPIO_IOCTL_IN, GP_TEMP_OS_INPUT); charge = ioctl(fd, GPIO_IOCTL_IN, GP_BATT_CHG_STATUS_INPUT); m_gpioLocker.Unlock(); // DCD Check if (dcd != oldDCD) { XDEBUG("GPIO: ------ Mobile DCD %s ------\r\n", dcd == 0 ? "Active" : "Normal"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_DCD, dcd, m_pParam, m_pArgment); m_Locker.Unlock(); oldDCD = dcd; } if (pwr != oldPWR) { // 100ms 후에도 Power Fail인지 검사한다. usleep(100000); pwr = ioctl(fd, GPIO_IOCTL_IN, GP_PWR_FAIL_INPUT); if (pwr != oldPWR) { XDEBUG("GPIO: ------ Power %s signal ------\r\n", pwr == 0 ? "UP" : "DOWN"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_PWR, pwr, m_pParam, m_pArgment); m_Locker.Unlock(); oldPWR = pwr; // Power restore if (pwr == 0) { // Battery Charging XDEBUG("GPIO: ------ Toggle battery charge ------\r\n"); ioctl(fd, GPIO_IOCTL_OUT, GPIOLOW(GP_BATT_CHG_EN_OUT)); // BATT CHARGE DISABLE usleep(1000000); ioctl(fd, GPIO_IOCTL_OUT, GPIOHIGH(GP_BATT_CHG_EN_OUT)); // BATT CHARGE ENABLE } } } if (low != oldBAT) { // 100ms 후에도 Low Battery인지 검사한다. usleep(100000); low = ioctl(fd, GPIO_IOCTL_IN, GP_LOW_BATT_INPUT); if (low != oldBAT) { XDEBUG("GPIO: ------ Low Battery %s signal ------\n", low == 0 ? "Low" : "Normal"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_LOWBAT, low, m_pParam, m_pArgment); m_Locker.Unlock(); oldBAT = low; } } if (ring != oldRING) { XDEBUG("GPIO: ------ Mobile RING signal %s ------\n", ring == 0 ? "Active" : "Normal"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_RING, ring, m_pParam, m_pArgment); m_Locker.Unlock(); oldRING = ring; } // Heater if (heater != oldHEATER) { XDEBUG("GPIO: ------ Heater %s ------\r\n", heater == 0 ? "OFF" : "ON"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_HEATER, heater, m_pParam, m_pArgment); m_Locker.Unlock(); oldHEATER = heater; } // Door open if (door != oldDOOR) { XDEBUG("GPIO: ------ Door %s ------\r\n", door == 0 ? "OPEN" : "CLOSE"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_DOOR, door, m_pParam, m_pArgment); m_Locker.Unlock(); oldDOOR = door; } // Battery charge if (charge != oldCHARGE) { XDEBUG("GPIO: ------ Battery charge %s ------\r\n", charge == 0 ? "OFF" : "CHARGE"); m_Locker.Lock(); if (m_bEnableHooker && (m_pfnCallback != NULL)) m_pfnCallback(GPIONOTIFY_BATTERY_CHARG, dcd, m_pParam, m_pArgment); m_Locker.Unlock(); oldCHARGE = charge; } } } #endif }
void CExceptionHandler::WriteExceptionReport() #endif { // Get the current time and date time_t t = time(NULL); const struct tm * tm = localtime(&t); // Get the 'crashinfo' directory path String strPath(SharedUtility::GetAbsolutePath("crashinfo")); // Create the 'crashinfo' directory if needed if(!SharedUtility::Exists(strPath)) SharedUtility::CreateDirectory(strPath); // Append the client or server string to the path #ifdef _SERVER strPath.Append("\\Server"); #else strPath.Append("\\Client"); #endif // Append the operating system string to the path strPath.Append("-" OS_STRING); // Append the version, date and time to the path strPath.AppendF("-" MOD_VERSION_STRING "-%04d.%02d.%02d-%02d.%02d.%02d", (tm->tm_year + 1900), (tm->tm_mon + 1), tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); // Get the log file path String strLogPath("%s.log", strPath.Get()); // Open the log file FILE * fFile = fopen(strLogPath, "w"); // Did the log file open successfully? if(fFile) { String strReportData; // Write the unhandled exception report start notice to the log file fprintf(fFile, "-- Unhandled Exception Report Start --\n"); #ifdef WIN32 // Write the exception code and exception code string to the log file strReportData.AppendF("Exception code: 0x%p (%s)\n", ExceptionInfo->ExceptionRecord->ExceptionCode, ExceptionCodeToString(ExceptionInfo->ExceptionRecord->ExceptionCode)); // Write the exception address to the log file #ifndef _SERVER strReportData.AppendF("Exception address: 0x%p (Game base: 0x%p)\n", ExceptionInfo->ExceptionRecord->ExceptionAddress, CGame::GetBase()); strReportData.AppendF("Exception real-add: 0x%p / 0x%p\n", ((int)ExceptionInfo->ExceptionRecord->ExceptionAddress-CGame::GetBase()), (CGame::GetBase()-(int)ExceptionInfo->ExceptionRecord->ExceptionAddress)); #else strReportData.AppendF("Exception address: 0x%p\n", ExceptionInfo->ExceptionRecord->ExceptionAddress); #endif // Create a tool help 32 process snapshot HANDLE hModuleSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, GetCurrentProcessId()); if(hModuleSnapShot) { MODULEENTRY32 ModuleEntry; ModuleEntry.dwSize = sizeof(ModuleEntry); if(Module32First(hModuleSnapShot, &ModuleEntry)) { // Enumerate through all modules while(Module32Next(hModuleSnapShot, &ModuleEntry)) { // See if exception was within this module if((ExceptionInfo->ContextRecord->Eip >= (DWORD)ModuleEntry.modBaseAddr) && (ExceptionInfo->ContextRecord->Eip <= ((DWORD)ModuleEntry.modBaseAddr + ModuleEntry.modBaseSize))) { strReportData.AppendF("Exception module: %s (+0x%p)\n", ModuleEntry.szModule, (ExceptionInfo->ContextRecord->Eip - (DWORD)ModuleEntry.modBaseAddr)); break; } } } } // Write the registers segment header strReportData.AppendF("Exception registers: \n"); // If we have segments context information then write it to the log file if(ExceptionInfo->ContextRecord->ContextFlags & CONTEXT_SEGMENTS) { strReportData.AppendF("GS=0x%p FS=0x%p ES=0x%p DS=0x%p\n", ExceptionInfo->ContextRecord->SegGs, ExceptionInfo->ContextRecord->SegFs, ExceptionInfo->ContextRecord->SegEs, ExceptionInfo->ContextRecord->SegDs); } // If we have integer context information then write it to the log file if(ExceptionInfo->ContextRecord->ContextFlags & CONTEXT_INTEGER) { strReportData.AppendF("EDI=0x%p ESI=0x%p EBX=0x%p EDX=0x%p\n", ExceptionInfo->ContextRecord->Edi, ExceptionInfo->ContextRecord->Esi, ExceptionInfo->ContextRecord->Ebx, ExceptionInfo->ContextRecord->Edx); strReportData.AppendF("ECX=0x%p EAX=0x%p\n", ExceptionInfo->ContextRecord->Ecx, ExceptionInfo->ContextRecord->Eax); } // If we have control context information then write it to the log file if(ExceptionInfo->ContextRecord->ContextFlags & CONTEXT_CONTROL) { strReportData.AppendF("EBP=0x%p EIP=0x%p CS=0x%p EFLAGS=0x%p\n", ExceptionInfo->ContextRecord->Ebp, ExceptionInfo->ContextRecord->Eip, ExceptionInfo->ContextRecord->SegCs, ExceptionInfo->ContextRecord->EFlags); strReportData.AppendF("ESP=0x%p SS=0x%p\n", ExceptionInfo->ContextRecord->Esp, ExceptionInfo->ContextRecord->SegSs); } #else void * pArray[50]; int iSize = backtrace(pArray, 50); char ** szMessages = backtrace_symbols(pArray, iSize); for(int i = 0; i < iSize && (szMessages[i] != NULL); i++) strReportData.AppendF("[Backtrace %d]: %s\n", i, szMessages[i]); #endif // If we have a callback call it if(m_pfnCallback) m_pfnCallback(strReportData); // Print the report data to the log file fprintf(fFile, strReportData.Get()); // Write the unhandled exception report end notice to the log file fprintf(fFile, "--Unhandled Exception Report End --\n"); // Close the log file fclose(fFile); } else CLogFile::Printf("Failed to open the crash log file."); #ifdef WIN32 // Get the minidump file path String strMiniDumpPath("%s.dmp", strPath.Get()); // Open the minidump file HANDLE hFile = CreateFileA(strMiniDumpPath, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL , NULL); // Did the minidump file open successfully? if(hFile) { // Create the minidump exception information MINIDUMP_EXCEPTION_INFORMATION exceptionInfo; exceptionInfo.ThreadId = GetCurrentThreadId(); exceptionInfo.ExceptionPointers = ExceptionInfo; exceptionInfo.ClientPointers = FALSE; // Write the minidump to the minidump file if(!MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hFile, MiniDumpNormal, &exceptionInfo, NULL, NULL)) CLogFile::Printf("Failed to write the minidump file."); // Close the minidump file CloseHandle(hFile); } else CLogFile::Printf("Failed to open the minidump file."); #endif // Print a message in the log file CLogFile::Printf("IV:MP has crashed. Please see %s for more information.", strLogPath.Get()); }