コード例 #1
0
ファイル: globals.c プロジェクト: traplol/little-lang
static int GlobalsInitSingletonValues(void) {
    int result;
    result = ValueMakeSingleton(&g_TheTrueValue, &g_TheBooleanTypeInfo);
    RETURN_ON_FAIL(result);

    result = ValueMakeSingleton(&g_TheFalseValue, &g_TheBooleanTypeInfo);
    RETURN_ON_FAIL(result);

    result = ValueMakeSingleton(&g_TheNilValue, &g_TheBaseObjectTypeInfo);
    RETURN_ON_FAIL(result);

    return R_OK;
}
コード例 #2
0
GS_VOID CPokeMiniEmulatorDlg::UpdateSoundBuffer()
{
    GS_UINT dataCount = m_pSystem->SoundDataCount();
    RETURN_ON_FAIL(dataCount > m_soundBufferThreshold);

    DWORD status = 0;
    m_pDirectSoundBuffer->GetStatus(&status);

    // Try to restore
    if (status & DSBSTATUS_BUFFERLOST)
    {
        while (DSERR_BUFFERLOST == m_pDirectSoundBuffer->Restore())
        {
            Sleep(10);
        }
    }

    LPVOID pBuffer1 = GS_NULL;
    DWORD bufferSize1 = 0;
    LPVOID pBuffer2 = GS_NULL;
    DWORD bufferSize2 = 0;
    m_pDirectSoundBuffer->Lock(0, dataCount, &pBuffer1, &bufferSize1, &pBuffer2, &bufferSize2, DSBLOCK_FROMWRITECURSOR);
    m_pSystem->OutputSound((GS_BYTE *)pBuffer1, bufferSize1);
    m_pSystem->OutputSound((GS_BYTE *)pBuffer2, bufferSize2);
    m_pDirectSoundBuffer->Unlock(pBuffer1, bufferSize1, pBuffer2, bufferSize2);
}
コード例 #3
0
ファイル: globals.c プロジェクト: traplol/little-lang
int GlobalsDenit(void) {
    int result;
    if (!__globalValuesInitialized) {
        return R_OperationFailed;
    }
    g_TheUberScope.Child = NULL;
    
    result = SymbolTableFree(g_TheGlobalScope);
    RETURN_ON_FAIL(result);

    result = TypeInfoFree(&g_TheBaseObjectTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheFunctionTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheBuiltinFnTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheIntegerTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheRealTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheStringTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeInfoFree(&g_TheBooleanTypeInfo);
    return result;
}
コード例 #4
0
ファイル: globals.c プロジェクト: traplol/little-lang
int GlobalsInit(void) {
    int result;
    if (__globalValuesInitialized) {
        return R_GlobalsAlreadyInitted;
    }
    result = GlobalsInitGlobalScope();
    RETURN_ON_FAIL(result);

    result = GlobalsInitTypeInfos();
    RETURN_ON_FAIL(result);

    result = GlobalsInitSingletonValues();
    RETURN_ON_FAIL(result);

    result = GlobalsInitGlobalTypeInfo();
    RETURN_ON_FAIL(result);

    __globalValuesInitialized = 1;
    return R_OK;
}
コード例 #5
0
ファイル: globals.c プロジェクト: traplol/little-lang
static int GlobalsInitGlobalTypeInfo(void) {
    int result;
    result = TypeTableMake(&g_TheGlobalTypeTable, 53);
    RETURN_ON_FAIL(result);

    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheBaseObjectTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheFunctionTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheBuiltinFnTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheIntegerTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheRealTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheStringTypeInfo);
    RETURN_ON_FAIL(result);
    result = TypeTableInsert(&g_TheGlobalTypeTable, &g_TheBooleanTypeInfo);
    RETURN_ON_FAIL(result);
    return R_OK;
}
コード例 #6
0
bool CFirewallOpener::DoAction(const EFOCAction eAction, const CICSRuleInfo& riPortRule){
	if ( !Init() )
		return false;
	//TODO lets see if we can find a reliable method to find out the internet standard connection set by the user

	bool bSuccess = true;
	bool bPartialSucceeded = false;
	bool bFoundAtLeastOneConn = false;

	INetSharingEveryConnectionCollectionPtr NSECCP;
	IEnumVARIANTPtr varEnum;
    IUnknownPtr pUnk;
    RETURN_ON_FAIL(m_pINetSM->get_EnumEveryConnection(&NSECCP));
    RETURN_ON_FAIL(NSECCP->get__NewEnum(&pUnk));
	RETURN_ON_FAIL(pUnk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&varEnum));
	
	_variant_t var;
	while (S_OK == varEnum->Next(1, &var, NULL)) {
		INetConnectionPtr NCP;		
		if (V_VT(&var) == VT_UNKNOWN
			&& SUCCEEDED(V_UNKNOWN(&var)->QueryInterface(__uuidof(INetConnection),(void**)&NCP))) 
		{
			INetConnectionPropsPtr pNCP;
			if ( !SUCCEEDED(m_pINetSM->get_NetConnectionProps (NCP, &pNCP)) )
				continue;	
			DWORD dwCharacteristics = 0;
			pNCP->get_Characteristics(&dwCharacteristics);
			if (dwCharacteristics & (NCCF_FIREWALLED)) {
				NETCON_MEDIATYPE MediaType = NCM_NONE;
				pNCP->get_MediaType (&MediaType);
				if ((MediaType != NCM_SHAREDACCESSHOST_LAN) && (MediaType != NCM_SHAREDACCESSHOST_RAS) ){
					INetSharingConfigurationPtr pNSC;
					if ( !SUCCEEDED(m_pINetSM->get_INetSharingConfigurationForINetConnection (NCP, &pNSC)) )
						continue;
					VARIANT_BOOL varbool = VARIANT_FALSE;
					pNSC->get_InternetFirewallEnabled(&varbool);
					if (varbool == VARIANT_FALSE)
						continue;
					bFoundAtLeastOneConn = true;
					switch(eAction){
							case FOC_ADDRULE:{
								bool bResult;
								// we do not want to overwrite an existing rule
								if (FindRule(FOC_FINDRULEBYPORT, riPortRule, pNSC, NULL)){
									bResult = true;
								}
								else
									bResult = AddRule(riPortRule, pNSC, pNCP);
								bSuccess = bSuccess && bResult;
								if (bResult && !bPartialSucceeded)
									m_liAddedRules.Add(riPortRule); // keep track of added rules
								bPartialSucceeded = bPartialSucceeded || bResult;
								break;
							}
							case FOC_FWCONNECTIONEXISTS:
								return true;
							case FOC_DELETERULEBYNAME:
							case FOC_DELETERULEEXCACT:
								bSuccess = bSuccess && FindRule(eAction, riPortRule, pNSC, NULL);
								break;
							case FOC_FINDRULEBYNAME:
								if (FindRule(FOC_FINDRULEBYNAME, riPortRule, pNSC, NULL))
									return true;
								else
									bSuccess = false;
								break;
							case FOC_FINDRULEBYPORT:
								if (FindRule(FOC_FINDRULEBYPORT, riPortRule, pNSC, NULL))
									return true;
								else
									bSuccess = false;
								break;
							default:
								ASSERT ( false );
					}
				}
			}
		}
		var.Clear();
	}
	return bSuccess && bFoundAtLeastOneConn;
}
コード例 #7
0
bool CFirewallOpener::FindRule(const EFOCAction eAction, const CICSRuleInfo& riPortRule, const INetSharingConfigurationPtr pNSC, INetSharingPortMappingPropsPtr* outNSPMP){
	INetSharingPortMappingCollectionPtr pNSPMC;
    RETURN_ON_FAIL(pNSC->get_EnumPortMappings (ICSSC_DEFAULT, &pNSPMC));
       
	INetSharingPortMappingPtr pNSPM;
    IEnumVARIANTPtr varEnum;
    IUnknownPtr pUnk;
    RETURN_ON_FAIL(pNSPMC->get__NewEnum(&pUnk));
    RETURN_ON_FAIL(pUnk->QueryInterface(__uuidof(IEnumVARIANT), (void**)&varEnum));
	_variant_t var;
	while (S_OK == varEnum->Next(1, &var, NULL)) {
		INetSharingPortMappingPropsPtr pNSPMP;
		if (V_VT(&var) == VT_DISPATCH
			&& SUCCEEDED(V_DISPATCH(&var)->QueryInterface(__uuidof(INetSharingPortMapping),(void**)&pNSPM)) 
			&& SUCCEEDED(pNSPM->get_Properties (&pNSPMP)))
		{
			UCHAR ucProt = 0;
			long uExternal = 0;
			CComBSTR bstrName;
			pNSPMP->get_IPProtocol (&ucProt);
			pNSPMP->get_ExternalPort (&uExternal);
			pNSPMP->get_Name(&bstrName);
			switch(eAction){
				case FOC_FINDRULEBYPORT:
					if (riPortRule.m_nPortNumber == uExternal && riPortRule.m_byProtocol == ucProt){
						if (outNSPMP != NULL)
							*outNSPMP = pNSPM;
						return true;
					}
					break;
				case FOC_FINDRULEBYNAME:
					if (riPortRule.m_strRuleName == CString(bstrName)){
						if (outNSPMP != NULL)
							*outNSPMP = pNSPM;
						return true;
					}
					break;
				case FOC_DELETERULEEXCACT:
					if (riPortRule.m_strRuleName == CString(bstrName)
						&& riPortRule.m_nPortNumber == uExternal && riPortRule.m_byProtocol == ucProt)
					{
						RETURN_ON_FAIL(pNSC->RemovePortMapping(pNSPM));
						theApp.QueueDebugLogLine(false,_T("Rule removed"));
					}
					break;
				case FOC_DELETERULEBYNAME:
					if (riPortRule.m_strRuleName == CString(bstrName)){
						RETURN_ON_FAIL(pNSC->RemovePortMapping(pNSPM));
						theApp.QueueDebugLogLine(false,_T("Rule removed"));
					}
					break;
				default:
					ASSERT( false );
			}
		}
		var.Clear();
	}

	switch(eAction){
		case FOC_DELETERULEBYNAME:
		case FOC_DELETERULEEXCACT:
			return true;
		case FOC_FINDRULEBYPORT:
		case FOC_FINDRULEBYNAME:
		default:
			return false;
	}
}
コード例 #8
0
void AudioClient::checkPeakValues() {
    // prepare the windows environment
    CoInitialize(NULL);

    // if disabled, clean up active clients
    if (!_enablePeakValues) {
        activeClients.clear();
        return;
    }

    // lock the devices so the _inputDevices list is static
    std::unique_lock<std::mutex> lock(_deviceMutex);
    HRESULT result;

    // initialize the payload
    QList<float> peakValueList;
    for (int i = 0; i < _inputDevices.size(); ++i) {
        peakValueList.push_back(0.0f);
    }

    std::shared_ptr<IMMDeviceEnumerator> enumerator;
    {
        IMMDeviceEnumerator* pEnumerator;
        result = CoCreateInstance(
            __uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER,
            __uuidof(IMMDeviceEnumerator), (void**)&pEnumerator);
        RETURN_ON_FAIL(result);
        enumerator = std::shared_ptr<IMMDeviceEnumerator>(pEnumerator, &release<IMMDeviceEnumerator>);
    }

    std::shared_ptr<IMMDeviceCollection> endpoints;
    {
        IMMDeviceCollection* pEndpoints;
        result = enumerator->EnumAudioEndpoints(eCapture, DEVICE_STATE_ACTIVE, &pEndpoints);
        RETURN_ON_FAIL(result);
        endpoints = std::shared_ptr<IMMDeviceCollection>(pEndpoints, &release<IMMDeviceCollection>);
    }

    UINT count;
    {
        result = endpoints->GetCount(&count);
        RETURN_ON_FAIL(result);
    }

    IMMDevice* pDevice;
    std::shared_ptr<IMMDevice> device;
    IAudioMeterInformation* pMeterInfo;
    std::shared_ptr<IAudioMeterInformation> meterInfo;
    IAudioClient* pAudioClient;
    std::shared_ptr<IAudioClient> audioClient;
    DWORD hardwareSupport;
    LPWSTR pDeviceId = NULL;
    LPWAVEFORMATEX format;
    float peakValue;
    QString deviceName;
    int deviceIndex;
    for (UINT i = 0; i < count; ++i) {
        result = endpoints->Item(i, &pDevice);
        CONTINUE_ON_FAIL(result);
        device = std::shared_ptr<IMMDevice>(pDevice, &release<IMMDevice>);

        // if the device isn't listed through Qt, skip it
        deviceName = ::getWinDeviceName(pDevice);
        deviceIndex = 0;
        for (;  deviceIndex < _inputDevices.size(); ++deviceIndex) {
            if (deviceName == _inputDevices[deviceIndex].deviceName()) {
                break;
            }
        }
        if (deviceIndex >= _inputDevices.size()) {
            continue;
        }

        //continue;

        result = device->Activate(__uuidof(IAudioMeterInformation), CLSCTX_ALL, NULL, (void**)&pMeterInfo);
        CONTINUE_ON_FAIL(result);
        meterInfo = std::shared_ptr<IAudioMeterInformation>(pMeterInfo, &release<IAudioMeterInformation>);

        //continue;

        hardwareSupport;
        result = meterInfo->QueryHardwareSupport(&hardwareSupport);
        CONTINUE_ON_FAIL(result);

        //continue;

        // if the device has no hardware support (USB)...
        if (!(hardwareSupport & ENDPOINT_HARDWARE_SUPPORT_METER)) {
            result = device->GetId(&pDeviceId);
            CONTINUE_ON_FAIL(result);
            std::wstring deviceId(pDeviceId);
            CoTaskMemFree(pDeviceId);

            //continue;

            // ...and no active client...
            if (activeClients.find(deviceId) == activeClients.end()) {
                result = device->Activate(__uuidof(IAudioClient), CLSCTX_ALL, NULL, (void**)&pAudioClient);
                CONTINUE_ON_FAIL(result);
                audioClient = std::shared_ptr<IAudioClient>(pAudioClient, &release<IAudioClient>);

                //continue;

                // ...activate a client
                audioClient->GetMixFormat(&format);
                audioClient->Initialize(AUDCLNT_SHAREMODE_SHARED, 0, 0, 0, format, NULL);
                audioClient->Start();

                //continue;

                activeClients[deviceId] = audioClient;
            }
        }

        // get the peak value and put it in the payload
        meterInfo->GetPeakValue(&peakValue);
        peakValueList[deviceIndex] = peakValue;
    }

    emit peakValueListChanged(peakValueList);
}