コード例 #1
0
DWORD WINAPI WiredEthernetMonitorThread(LPVOID lpParams)
{
    HRESULT hr;
    PMONITOR_THREAD_PARAMS pMonitorThreadParams = (PMONITOR_THREAD_PARAMS)lpParams;
    PIP_ADAPTER_ADDRESSES pOriginalAddresses = NULL;
    ULONG originalAddressesSize = 0;
    PIP_ADAPTER_ADDRESSES pNewAddresses = NULL;
    ULONG newAddressesSize = 0;
    PIP_ADAPTER_ADDRESSES pCurrOriginalAddress = NULL;
    PIP_ADAPTER_ADDRESSES pCurrNewAddress = NULL;

    WriteLineToLog("WiredEtherMonitorThread: Started");

    hr = GetInternetAdapterAddresses(&pOriginalAddresses, &originalAddressesSize);
    if(HB_FAILED(hr)) {
        WriteLineToLog("WiredEtherMonitorThread: Failed to get original adapter addresses");
        goto cleanexit;
    }

    while(1) {
        hr = GetInternetAdapterAddresses(&pNewAddresses, &newAddressesSize);
        if(HB_FAILED(hr)) {
            WriteLineToLog("WiredEtherMonitorThread: Failed to get new adapter addresses");
            goto cleanexit;
        }
        
        pCurrOriginalAddress = pOriginalAddresses;
        pCurrNewAddress = pNewAddresses;
        while(pCurrOriginalAddress && pCurrNewAddress) {
            if(pCurrNewAddress->IfType == IF_TYPE_ETHERNET_CSMACD) {
                if((pCurrNewAddress->OperStatus == IfOperStatusDown) && (pCurrOriginalAddress->OperStatus == IfOperStatusUp)) {
                    WriteLineToLog("WiredEtherMonitorThread: Firing monitor event");
                    SetEvent(pMonitorThreadParams->hMonitorEvent);
                    goto cleanexit;
                }
                else {
                    ResetEvent(pMonitorThreadParams->hMonitorEvent);
                }
            }
            pCurrOriginalAddress = pCurrOriginalAddress->Next;
            pCurrNewAddress = pCurrNewAddress->Next;
        }
        
        switch (WaitForSingleObject(pMonitorThreadParams->hMonitorStopEvent, DEFAULT_SLEEP_TIME)) {
        case WAIT_OBJECT_0:
            goto cleanexit;
        case WAIT_TIMEOUT:
            continue;
        }
    }

cleanexit:
    WriteLineToLog("WiredEtherMonitorThread: Exiting");

    HB_SAFE_FREE(pOriginalAddresses);
    HB_SAFE_FREE(pNewAddresses);
    HB_SAFE_FREE(pMonitorThreadParams);
    
    return 0;
}
コード例 #2
0
ファイル: c_consolebuffer.cpp プロジェクト: Accusedbold/zdoom
void FConsoleBuffer::WriteContentToLog(FILE *LogFile)
{
	if (LogFile != NULL)
	{
		for (unsigned i = 0; i < mConsoleText.Size(); i++)
		{
			WriteLineToLog(LogFile, mConsoleText[i]);
		}
	}
}
コード例 #3
0
ファイル: PowerMonitor.cpp プロジェクト: bitland/yontma
DWORD WINAPI PowerMonitorThread(LPVOID lpParams)
{
    SYSTEM_POWER_STATUS PowerStatus;
    PMONITOR_THREAD_PARAMS pMonitorThreadParams = (PMONITOR_THREAD_PARAMS)lpParams;
    
    WriteLineToLog("PowerMonitorThread: Started");

    if(!GetSystemPowerStatus(&PowerStatus)) {
        WriteLineToLog("PowerMonitorThread: Error detecting initial power state.");
        goto cleanexit;
    }
    if(!PowerStatus.ACLineStatus) {
        WriteLineToLog("PowerMonitorThread: Machine was not connected to AC power at lock time.");
        goto cleanexit;
    }

    while(1) {
        if(!GetSystemPowerStatus(&PowerStatus)) {
            continue;
        }
        if(!PowerStatus.ACLineStatus) {
            WriteLineToLog("PowerMonitorThread: Firing monitor event");
            SetEvent(pMonitorThreadParams->hMonitorEvent);
            goto cleanexit;
        }
        else {
            ResetEvent(pMonitorThreadParams->hMonitorEvent);
        }
        switch (WaitForSingleObject(pMonitorThreadParams->hMonitorStopEvent, DEFAULT_SLEEP_TIME)) {
        case WAIT_OBJECT_0:
            goto cleanexit;
        case WAIT_TIMEOUT:
            continue;
        }
    }

cleanexit:
    WriteLineToLog("PowerMonitorThread: Exiting");
    HB_SAFE_FREE(pMonitorThreadParams);

    return 0;
}
コード例 #4
0
ファイル: c_consolebuffer.cpp プロジェクト: Accusedbold/zdoom
void FConsoleBuffer::AddText(int printlevel, const char *text, FILE *logfile)
{
	FString build = TEXTCOLOR_TAN;
	
	if (mAddType == REPLACELINE)
	{
		// Just wondering: Do we actually need this case? If so, it may need some work.
		mConsoleText.Pop();	// remove the line to be replaced
		mLastLineNeedsUpdate = true;
	}
	else if (mAddType == APPENDLINE)
	{
		mConsoleText.Pop(build);
		printlevel = -1;
		mLastLineNeedsUpdate = true;
	}
	
	if (printlevel >= 0 && printlevel != PRINT_HIGH)
	{
		if (printlevel == 200) build = TEXTCOLOR_GREEN;
		else if (printlevel < PRINTLEVELS) build.Format("%c%c", TEXTCOLOR_ESCAPE, PrintColors[printlevel]);
	}
	
	size_t textsize = strlen(text);
	
	if (text[textsize-1] == '\r')
	{
		textsize--;
		mAddType = REPLACELINE;
	}
	else if (text[textsize-1] == '\n')
	{
		textsize--;
		mAddType = NEWLINE;
	}
	else
	{
		mAddType = APPENDLINE;
	}

	// don't bother about linefeeds etc. inside the text, we'll let the formatter sort this out later.
	build.AppendCStrPart(text, textsize);
	mConsoleText.Push(build);
	if (logfile != NULL) WriteLineToLog(logfile, text);
}