예제 #1
0
파일: device.cpp 프로젝트: MHesham/bsp
_Use_decl_annotations_
VOID
OnIoDeviceControl(
    WDFQUEUE    Queue,
    WDFREQUEST  Request,
    size_t      OutputBufferLength,
    size_t      InputBufferLength,
    ULONG       IoControlCode
)
/*++

Routine Description:

    This event handled device control calls.

Arguments:

    Queue - Handle of the queue object associated with the request
    Request - Handle of the request object
    OutputBufferLength - length of the request's output buffer
    InputBufferLength - length of the request's input buffer
    IoControlCode - the driver-defined or system-defined I/O control code

Return Value:

    None

--*/
{
    UNREFERENCED_PARAMETER(OutputBufferLength);
    UNREFERENCED_PARAMETER(InputBufferLength);

    WDFDEVICE device;
    PDEVICE_CONTEXT deviceContext;
    NTSTATUS status = STATUS_SUCCESS;

    device = WdfIoQueueGetDevice(Queue);
    deviceContext = GetContext(device);

    //
    // Validate the IO code and exexute on it.
    //

    switch (IoControlCode)
    {
    case IOCTL_BCM_PWM_SET_CLOCKCONFIG:
        status = ValidateAndSetClockConfig(device, Request);
        break;

    case IOCTL_BCM_PWM_GET_CLOCKCONFIG:
        status = GetClockConfig(device, Request);
        break;

    case IOCTL_BCM_PWM_SET_CHANNELCONFIG:
        status = ValidateAndSetChannelConfig(device, Request);
        break;

    case IOCTL_BCM_PWM_GET_CHANNELCONFIG:
        status = GetChannelConfig(device, Request);
        break;

    case IOCTL_BCM_PWM_SET_DUTY_REGISTER:
        status = ValidateAndSetDutyRegister(device, Request);
        break;

    case IOCTL_BCM_PWM_GET_DUTY_REGISTER:
        status = GetDutyRegister(device, Request);
        break;

    case IOCTL_BCM_PWM_START:
        status = ValidateAndStartChannel(device, Request);
        break;

    case IOCTL_BCM_PWM_STOP:
        status = ValidateAndStopChannel(device, Request);
        break;

    case IOCTL_BCM_PWM_AQUIRE_AUDIO:
        status = AquireAudio(device);
        break;

    case IOCTL_BCM_PWM_RELEASE_AUDIO:
        status = ReleaseAudio(device);
        break;

    case IOCTL_BCM_PWM_INITIALIZE_AUDIO:
        status = InitializeAudio(device, Request);
        break;

    case IOCTL_BCM_PWM_REGISTER_AUDIO_NOTIFICATION:
        status = RegisterAudioNotification(device, Request);
        break;

    case IOCTL_BCM_PWM_UNREGISTER_AUDIO_NOTIFICATION:
        status = UnregisterAudioNotification(device, Request);
        break;

    case IOCTL_BCM_PWM_START_AUDIO:
        status = StartAudio(device);
        break;

    case IOCTL_BCM_PWM_PAUSE_AUDIO:
        status = PauseAudio(device);
        break;

    case IOCTL_BCM_PWM_RESUME_AUDIO:
        status = ResumeAudio(device);
        break;

    case IOCTL_BCM_PWM_STOP_AUDIO:
        status = StopAudio(device);
        break;

    default:
        status = STATUS_INVALID_DEVICE_REQUEST;
        TraceEvents(TRACE_LEVEL_ERROR, TRACE_IOCTL, "Unexpected IO code in request. Request: 0x%08x, Code: 0x%08x", (ULONG)Request, IoControlCode);
        break;
    }

    WdfRequestComplete(Request, status);
}
예제 #2
0
void FAppEventManager::Tick()
{
	while (!Queue.IsEmpty())
	{
		bool bDestroyWindow = false;

		FAppEventData Event = DequeueAppEvent();

		switch (Event.State)
		{
		case APP_EVENT_STATE_WINDOW_CREATED:
			check(FirstInitialized);
			bCreateWindow = true;
			PendingWindow = (ANativeWindow*)Event.Data;
			break;
		case APP_EVENT_STATE_WINDOW_RESIZED:
			bWindowChanged = true;
			break;
		case APP_EVENT_STATE_WINDOW_CHANGED:
			bWindowChanged = true;
			break;
		case APP_EVENT_STATE_SAVE_STATE:
			bSaveState = true; //todo android: handle save state.
			break;
		case APP_EVENT_STATE_WINDOW_DESTROYED:
			if (GEngine->HMDDevice.IsValid() && GEngine->HMDDevice->IsHMDConnected())
			{
				// delay the destruction until after the renderer teardown on GearVR
				bDestroyWindow = true;
			}
			else
			{
				FAndroidAppEntry::DestroyWindow();
				FPlatformMisc::SetHardwareWindow(NULL);
			}
			bHaveWindow = false;
			break;
		case APP_EVENT_STATE_ON_START:
			//doing nothing here
			break;
		case APP_EVENT_STATE_ON_DESTROY:
			FCoreDelegates::ApplicationWillTerminateDelegate.Broadcast();
			GIsRequestingExit = true; //destroy immediately. Game will shutdown.
			break;
		case APP_EVENT_STATE_ON_STOP:
			bHaveGame = false;
			break;
		case APP_EVENT_STATE_ON_PAUSE:
			bHaveGame = false;
			break;
		case APP_EVENT_STATE_ON_RESUME:
			bHaveGame = true;
			break;

		// window focus events that follow their own  heirarchy, and might or might not respect App main events heirarchy

		case APP_EVENT_STATE_WINDOW_GAINED_FOCUS: 
			bWindowInFocus = true;
			break;
		case APP_EVENT_STATE_WINDOW_LOST_FOCUS:
			bWindowInFocus = false;
			break;

		default:
			UE_LOG(LogAndroidEvents, Display, TEXT("Application Event : %u  not handled. "), Event.State);
		}

		if (bCreateWindow)
		{
			// wait until activity is in focus.
			if (bWindowInFocus) 
			{
				ExecWindowCreated();
				bCreateWindow = false;
				bHaveWindow = true;
			}
		}

		if (bWindowChanged)
		{
			// wait until window is valid and created. 
			if(FPlatformMisc::GetHardwareWindow() != NULL)
			{
				if(GEngine && GEngine->GameViewport && GEngine->GameViewport->ViewportFrame)
				{
					ExecWindowChanged();
					bWindowChanged = false;
					bHaveWindow = true;
				}
			}
		}

		if (!bRunning && bHaveWindow && bHaveGame)
		{
			ResumeRendering();
			ResumeAudio();

			// broadcast events after the rendering thread has resumed
			FCoreDelegates::ApplicationHasEnteredForegroundDelegate.Broadcast();
			FCoreDelegates::ApplicationHasReactivatedDelegate.Broadcast();

			bRunning = true;
		}
		else if (bRunning && (!bHaveWindow || !bHaveGame))
		{
			// broadcast events before rendering thred suspends
			FCoreDelegates::ApplicationWillDeactivateDelegate.Broadcast();
			FCoreDelegates::ApplicationWillEnterBackgroundDelegate.Broadcast();

			PauseRendering();
			PauseAudio();

			bRunning = false;
		}

		if (bDestroyWindow)
		{
			FAndroidAppEntry::DestroyWindow();
			FPlatformMisc::SetHardwareWindow(NULL);
			bDestroyWindow = false;
		}
	}

	if (!bRunning && FirstInitialized)
	{
		EventHandlerEvent->Wait();
	}
}