More http post end points filled
This commit is contained in:
@@ -266,6 +266,18 @@ HttpControlServer::HttpResponse HttpControlServer::ServePost(const HttpRequest&
|
||||
if (!IsKnownPostEndpoint(request.path))
|
||||
return TextResponse("404 Not Found", "Not Found");
|
||||
|
||||
if (request.path == "/api/layers/add" && mCallbacks.addLayer)
|
||||
{
|
||||
const ControlActionResult result = mCallbacks.addLayer(request.body);
|
||||
return JsonResponse(result.ok ? "200 OK" : "400 Bad Request", ActionResponse(result.ok, result.error));
|
||||
}
|
||||
|
||||
if (request.path == "/api/layers/remove" && mCallbacks.removeLayer)
|
||||
{
|
||||
const ControlActionResult result = mCallbacks.removeLayer(request.body);
|
||||
return JsonResponse(result.ok ? "200 OK" : "400 Bad Request", ActionResponse(result.ok, result.error));
|
||||
}
|
||||
|
||||
return {
|
||||
"400 Bad Request",
|
||||
"application/json",
|
||||
|
||||
@@ -19,9 +19,17 @@ struct HttpControlServerConfig
|
||||
std::chrono::milliseconds idleSleep = std::chrono::milliseconds(10);
|
||||
};
|
||||
|
||||
struct ControlActionResult
|
||||
{
|
||||
bool ok = false;
|
||||
std::string error;
|
||||
};
|
||||
|
||||
struct HttpControlServerCallbacks
|
||||
{
|
||||
std::function<std::string()> getStateJson;
|
||||
std::function<ControlActionResult(const std::string&)> addLayer;
|
||||
std::function<ControlActionResult(const std::string&)> removeLayer;
|
||||
};
|
||||
|
||||
class UniqueSocket
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "../app/AppConfig.h"
|
||||
#include "../app/AppConfigProvider.h"
|
||||
#include "../json/JsonWriter.h"
|
||||
#include "../runtime/RuntimeLayerModel.h"
|
||||
#include "../runtime/SupportedShaderCatalog.h"
|
||||
#include "../telemetry/CadenceTelemetryJson.h"
|
||||
|
||||
@@ -19,10 +20,8 @@ struct RuntimeStateJsonInput
|
||||
unsigned short serverPort = 0;
|
||||
bool videoOutputEnabled = false;
|
||||
std::string videoOutputStatus;
|
||||
const std::vector<SupportedShaderSummary>& shaders;
|
||||
bool runtimeCompileSucceeded = true;
|
||||
std::string runtimeCompileMessage;
|
||||
const ShaderPackage* activeShaderPackage = nullptr;
|
||||
const SupportedShaderCatalog& shaderCatalog;
|
||||
const RuntimeLayerModelSnapshot& runtimeLayers;
|
||||
};
|
||||
|
||||
inline void WriteVideoIoStatusJson(JsonWriter& writer, const RuntimeStateJsonInput& input)
|
||||
@@ -112,6 +111,17 @@ inline void WriteFeedbackJson(JsonWriter& writer, const FeedbackSettings& feedba
|
||||
writer.EndObject();
|
||||
}
|
||||
|
||||
inline const char* RuntimeLayerBuildStateName(RuntimeLayerBuildState state)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case RuntimeLayerBuildState::Pending: return "pending";
|
||||
case RuntimeLayerBuildState::Ready: return "ready";
|
||||
case RuntimeLayerBuildState::Failed: return "failed";
|
||||
}
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
inline void WriteParameterDefinitionJson(JsonWriter& writer, const ShaderParameterDefinition& parameter)
|
||||
{
|
||||
writer.BeginObject();
|
||||
@@ -164,22 +174,34 @@ inline void WriteParameterDefinitionJson(JsonWriter& writer, const ShaderParamet
|
||||
inline void WriteLayersJson(JsonWriter& writer, const RuntimeStateJsonInput& input)
|
||||
{
|
||||
writer.BeginArray();
|
||||
if (input.activeShaderPackage)
|
||||
for (const RuntimeLayerReadModel& layer : input.runtimeLayers.displayLayers)
|
||||
{
|
||||
const ShaderPackage& shaderPackage = *input.activeShaderPackage;
|
||||
const ShaderPackage* shaderPackage = input.shaderCatalog.FindPackage(layer.shaderId);
|
||||
writer.BeginObject();
|
||||
writer.KeyString("id", "runtime-layer-1");
|
||||
writer.KeyString("shaderId", shaderPackage.id);
|
||||
writer.KeyString("shaderName", shaderPackage.displayName.empty() ? shaderPackage.id : shaderPackage.displayName);
|
||||
writer.KeyBool("bypass", false);
|
||||
writer.KeyString("id", layer.id);
|
||||
writer.KeyString("shaderId", layer.shaderId);
|
||||
writer.KeyString("shaderName", layer.shaderName);
|
||||
writer.KeyBool("bypass", layer.bypass);
|
||||
writer.KeyString("buildState", RuntimeLayerBuildStateName(layer.buildState));
|
||||
writer.KeyBool("renderReady", layer.renderReady);
|
||||
writer.KeyString("message", layer.message);
|
||||
writer.Key("temporal");
|
||||
WriteTemporalJson(writer, shaderPackage.temporal);
|
||||
if (shaderPackage)
|
||||
WriteTemporalJson(writer, shaderPackage->temporal);
|
||||
else
|
||||
WriteTemporalJson(writer, TemporalSettings());
|
||||
writer.Key("feedback");
|
||||
WriteFeedbackJson(writer, shaderPackage.feedback);
|
||||
if (shaderPackage)
|
||||
WriteFeedbackJson(writer, shaderPackage->feedback);
|
||||
else
|
||||
WriteFeedbackJson(writer, FeedbackSettings());
|
||||
writer.Key("parameters");
|
||||
writer.BeginArray();
|
||||
for (const ShaderParameterDefinition& parameter : shaderPackage.parameters)
|
||||
WriteParameterDefinitionJson(writer, parameter);
|
||||
if (shaderPackage)
|
||||
{
|
||||
for (const ShaderParameterDefinition& parameter : shaderPackage->parameters)
|
||||
WriteParameterDefinitionJson(writer, parameter);
|
||||
}
|
||||
writer.EndArray();
|
||||
writer.EndObject();
|
||||
}
|
||||
@@ -209,9 +231,9 @@ inline std::string RuntimeStateToJson(const RuntimeStateJsonInput& input)
|
||||
|
||||
writer.Key("runtime");
|
||||
writer.BeginObject();
|
||||
writer.KeyUInt("layerCount", input.activeShaderPackage ? 1 : 0);
|
||||
writer.KeyBool("compileSucceeded", input.runtimeCompileSucceeded);
|
||||
writer.KeyString("compileMessage", input.runtimeCompileMessage);
|
||||
writer.KeyUInt("layerCount", static_cast<uint64_t>(input.runtimeLayers.displayLayers.size()));
|
||||
writer.KeyBool("compileSucceeded", input.runtimeLayers.compileSucceeded);
|
||||
writer.KeyString("compileMessage", input.runtimeLayers.compileMessage);
|
||||
writer.EndObject();
|
||||
|
||||
writer.Key("video");
|
||||
@@ -250,7 +272,7 @@ inline std::string RuntimeStateToJson(const RuntimeStateJsonInput& input)
|
||||
writer.KeyNull("runtimeEvents");
|
||||
writer.Key("shaders");
|
||||
writer.BeginArray();
|
||||
for (const SupportedShaderSummary& shader : input.shaders)
|
||||
for (const SupportedShaderSummary& shader : input.shaderCatalog.Shaders())
|
||||
{
|
||||
writer.BeginObject();
|
||||
writer.KeyString("id", shader.id);
|
||||
|
||||
Reference in New Issue
Block a user