Skip to content

Instantly share code, notes, and snippets.

@Batname
Last active April 19, 2022 12:49
Show Gist options
  • Select an option

  • Save Batname/6ea1109a074ed23d13c03aad35101fac to your computer and use it in GitHub Desktop.

Select an option

Save Batname/6ea1109a074ed23d13c03aad35101fac to your computer and use it in GitHub Desktop.

Revisions

  1. Batname revised this gist Apr 19, 2022. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions RemoteControlModule.cpp
    Original file line number Diff line number Diff line change
    @@ -32,4 +32,8 @@ bool FRemoteControlModule::SetPresetController(const FRCControllerReference& Con
    // Other logic
    // And filany desirialize, you need to implment
    bSuccess = FStructDeserializer::Deserialize(MutableObjectReference.ContainerAdress, *ContainerType, Backend, Policies);

    // And after set the property value it should call the controller to execute the behaviour
    // URCControllerContainer::OnModifyPropertyValue
    // which is calling the Controller->ExecuteBehaviours();
    }
  2. Batname revised this gist Apr 19, 2022. 2 changed files with 38 additions and 0 deletions.
    35 changes: 35 additions & 0 deletions RemoteControlModule.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    // check the example in bool FRemoteControlModule::SetObjectProperties

    bool FRemoteControlModule::SetPresetController(const FRCControllerReference& ControllerRef, IStructDeserializerBackend& Backend, ERCPayloadType InPayloadType, const TArray<uint8>& InPayload, ERCModifyOperation Operation)
    {
    // Logic

    // Check the Interceptor, it shoudl be implmented in Remote Control and nDisplay, but you can for first Prof of concept go without Interceptor
    // But keep this in mind for the future

    // Build interception command
    FString PropertyPathString = TFieldPath<FProperty>(ObjectAccess.Property.Get()).ToString();
    FRCIContollersMetadata ControllersMetadata(ObjectAccess.Object->GetPathName(), PropertyPathString, ObjectAccess.PropertyPathInfo.ToString(), ToExternal(ObjectAccess.Access), ToExternal(InPayloadType), ToExternal(Operation), InPayload);

    // Pass interception command data to all available interceptors
    bool bShouldIntercept = false;
    for (int32 InterceptorIdx = 0; InterceptorIdx < InterceptorsAmount; ++InterceptorIdx)
    {
    IRemoteControlInterceptionFeatureInterceptor* const Interceptor = static_cast<IRemoteControlInterceptionFeatureInterceptor*>(ModularFeatures.GetModularFeatureImplementation(InterceptorFeatureName, InterceptorIdx));
    if (Interceptor)
    {
    // Update response flag
    UE_LOG(LogRemoteControl, VeryVerbose, TEXT("Set Object Properties - Intercepted"));
    bShouldIntercept |= (Interceptor->SetPresetController(PropsMetadata) == ERCIResponse::Intercept);
    }
    }
    // Don't process the RC message if any of interceptors returned ERCIResponse::Intercept
    if (bShouldIntercept)
    {
    return true;
    }

    // Other logic
    // And filany desirialize, you need to implment
    bSuccess = FStructDeserializer::Deserialize(MutableObjectReference.ContainerAdress, *ContainerType, Backend, Policies);
    }
    3 changes: 3 additions & 0 deletions WebRemoteControl.cpp
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    // for testing you can use postman
    // https://learning.postman.com/docs/sending-requests/requests/

    void FWebRemoteControlModule::RegisterRoutes()
    {
    // routers before
  3. Batname created this gist Apr 19, 2022.
    56 changes: 56 additions & 0 deletions WebRemoteControl.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,56 @@
    void FWebRemoteControlModule::RegisterRoutes()
    {
    // routers before
    RegisterRoute({
    TEXT("Set a controller value on a preset."),
    FHttpPath(TEXT("/remote/preset/:preset/controller/:controller")),
    EHttpServerRequestVerbs::VERB_PUT,
    FRequestHandlerDelegate::CreateRaw(this, &FWebRemoteControlModule::HandlePresetSetControllerRoute)
    });

    RegisterRoute({
    TEXT("Get a controller value on a preset."),
    FHttpPath(TEXT("/remote/preset/:preset/controller/:controller")),
    EHttpServerRequestVerbs::VERB_GET,
    FRequestHandlerDelegate::CreateRaw(this, &FWebRemoteControlModule::HandlePresetGetControllerRoute)
    });

    // routers after
    }

    bool FWebRemoteControlModule::HandlePresetSetControllerRoute(const FHttpServerRequest& Request, const FHttpResultCallback& OnComplete)
    {
    TUniquePtr<FHttpServerResponse> Response = WebRemoteControlInternalUtils::CreateHttpResponse();

    if (!WebRemoteControlInternalUtils::ValidateContentType(Request, TEXT("application/json"), OnComplete))
    {
    return true;
    }

    FRCPresetSetPropertyRequest SetPropertyRequest;
    if (!WebRemoteControlInternalUtils::DeserializeRequest(Request, &OnComplete, SetPropertyRequest))
    {
    return true;
    }

    FResolvePresetFieldArgs Args;
    Args.PresetName = Request.PathParams.FindChecked(TEXT("preset"));
    Args.ControllerName = Request.PathParams.FindChecked(TEXT("controllername"));

    URemoteControlPreset* Preset = WebRemoteControl::GetPreset(*Args.PresetName);
    if (Preset == nullptr)
    {
    Response->Code = EHttpServerResponseCodes::NotFound;
    WebRemoteControlInternalUtils::CreateUTF8ErrorMessage(TEXT("Unable to resolve the preset."), Response->Body);
    OnComplete(MoveTemp(Response));
    return true;
    }

    URCController* Controller = Preset->ControllerContainer->GetControllerByName(""); // It should be implmented, I can add it your you can add it


    // other logic , check HandlePresetSetPropertyRoute

    // Set the controller values
    IRemoteControlModule::Get().SetPresetController(ControllerRef, Backend, ERCPayloadType::Json, NewPayload, SetControllerRequest.Operation);
    }