Skip to content

Instantly share code, notes, and snippets.

@Batname
Last active April 19, 2022 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Batname/6ea1109a074ed23d13c03aad35101fac to your computer and use it in GitHub Desktop.
Save Batname/6ea1109a074ed23d13c03aad35101fac to your computer and use it in GitHub Desktop.
// 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);
// And after set the property value it should call the controller to execute the behaviour
// URCControllerContainer::OnModifyPropertyValue
// which is calling the Controller->ExecuteBehaviours();
}
// for testing you can use postman
// https://learning.postman.com/docs/sending-requests/requests/
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);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment