16 #include "tinyhttp/http.h" 34 virtual void execute()
override;
45 template <
typename T, miniJson::JsonType json_type>
70 control.comm().broadcast(
_value);
71 control.setControllableValueByName<T>(
name(),
value());
82 template <
typename T, miniJson::JsonType json_type>
90 const std::string &
type,
91 const miniJson::Json & json_value)
100 template <
typename T, miniJson::JsonType json_type>
109 const std::string &
type,
110 const miniJson::Json & json_value)
117 const auto from_json_type = json_value.getType();
118 if (from_json_type != miniJson::JsonType::kArray)
122 const auto & array_value = json_value.toArray();
123 std::vector<T>
value(array_value.size());
125 value[i] = getScalarJSONValue<T, json_type>(array_value[i]);
133 template <
typename T, miniJson::JsonType json_type>
141 template <
typename T, miniJson::JsonType json_type>
173 template <
typename T, miniJson::JsonType json_type>
177 const auto from_json_type = json_value.getType();
178 if (from_json_type != json_type)
183 if constexpr (json_type == miniJson::JsonType::kBool)
184 return json_value.toBool();
185 else if constexpr (json_type == miniJson::JsonType::kNumber)
186 return json_value.toDouble();
187 else if constexpr (json_type == miniJson::JsonType::kString)
188 return json_value.toString();
189 ::mooseError(
"WebServerControl::getScalarJSONValue(): Not configured for parsing type ",
std::atomic< bool > _currently_waiting
Whether or not the Control is currently waiting.
static char registerScalarType(const std::string type_name)
Registers a scalar parameter type to be controlled.
const std::string & name() const
Starts a webserver that an external process can connect to in order to send JSON messages to control ...
void startServer()
Internal method for starting the server.
Class that stores a scalar controllable value to be set.
WebServerControl(const InputParameters ¶meters)
The base class for a value that is produced by this registry.
Common exception for parsing related errors in converting JSON to a value.
T _value
The underlying value.
static char registerVectorType(const std::string type_name)
Registers a vector parameter type to be controlled.
A static registry used to register and build values of different types for the WebServerControl.
const std::string & type() const
Base class for a controllable value with a given type and name.
std::vector< std::unique_ptr< ValueBase > > _controlled_values
The values received to control; filled on rank 0 from the server and then broadcast.
TypedValueBase(const std::string &name, const std::string &type)
VectorValue(const std::string &name, const std::string &type)
std::mutex _controlled_values_mutex
Mutex to prevent threaded writes to _controlled_values.
static T getScalarJSONValue(const miniJson::Json &json_value)
Class that stores a vector controllable value to be set.
ScalarValue(const std::string &name, const std::string &type, const miniJson::Json &json_value)
static std::string stringifyJSONType(const miniJson::JsonType &json_type)
TypedValueBase(const std::string &name, const std::string &type, const T &value)
std::unique_ptr< std::thread > _server_thread
The server thread.
Base class for Control objects.
virtual void execute() override
Execute the control.
virtual void setControllableValue(WebServerControl &control) override final
Sets the controllable value given the name and type via the controllable interface in control...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
ScalarValue(const std::string &name, const std::string &type)
static InputParameters validParams()
static char add(const std::string &type_name)
Registers a type with string name type_name and the given derived type.
static std::vector< T > getVectorJSONValue(const miniJson::Json &json_value)
auto index_range(const T &sizable)
bool currentlyWaiting() const
std::unique_ptr< HttpServer > _server
The server.
VectorValue(const std::string &name, const std::string &type, const miniJson::Json &json_value)