|
6 | 6 | #include <cosim/error.hpp>
|
7 | 7 | #include <cosim/exception.hpp>
|
8 | 8 | #include <cosim/proxy/remote_slave.hpp>
|
| 9 | +#include <proxyfmu/thrift/defs_types.h> |
9 | 10 |
|
10 | 11 | #include <utility>
|
11 | 12 |
|
@@ -204,45 +205,60 @@ void cosim::proxy::remote_slave::set_string_variables(gsl::span<const cosim::val
|
204 | 205 |
|
205 | 206 | cosim::slave::state_index cosim::proxy::remote_slave::save_state()
|
206 | 207 | {
|
207 |
| - throw error( |
208 |
| - make_error_code(errc::unsupported_feature), |
209 |
| - "Proxyfmu does not support state saving"); |
| 208 | + return slave_->save_state(); |
210 | 209 | }
|
211 | 210 |
|
212 |
| -void cosim::proxy::remote_slave::save_state(state_index) |
| 211 | +void cosim::proxy::remote_slave::save_state(state_index idx) |
213 | 212 | {
|
214 |
| - throw error( |
215 |
| - make_error_code(errc::unsupported_feature), |
216 |
| - "Proxyfmu does not support state saving"); |
| 213 | + slave_->save_state(idx); |
217 | 214 | }
|
218 | 215 |
|
219 |
| -void cosim::proxy::remote_slave::restore_state(state_index) |
| 216 | +void cosim::proxy::remote_slave::restore_state(state_index idx) |
220 | 217 | {
|
221 |
| - throw error( |
222 |
| - make_error_code(errc::unsupported_feature), |
223 |
| - "Proxyfmu does not support state saving"); |
| 218 | + slave_->restore_state(idx); |
224 | 219 | }
|
225 | 220 |
|
226 |
| -void cosim::proxy::remote_slave::release_state(state_index) |
| 221 | +void cosim::proxy::remote_slave::release_state(state_index idx) |
227 | 222 | {
|
228 |
| - throw error( |
229 |
| - make_error_code(errc::unsupported_feature), |
230 |
| - "Proxyfmu does not support state saving"); |
| 223 | + slave_->release_state(idx); |
231 | 224 | }
|
232 | 225 |
|
233 |
| -cosim::serialization::node cosim::proxy::remote_slave::export_state(state_index) const |
| 226 | +cosim::serialization::node cosim::proxy::remote_slave::export_state(state_index idx) const |
234 | 227 | {
|
235 |
| - throw error( |
236 |
| - make_error_code(errc::unsupported_feature), |
237 |
| - "Proxyfmu does not support state serialization"); |
| 228 | + proxyfmu::thrift::ExportedState state; |
| 229 | + slave_->export_state(idx, state); |
| 230 | + |
| 231 | + // Create the exported state |
| 232 | + serialization::node exportedState; |
| 233 | + exportedState.put("scheme_version", state.schemeVersion); |
| 234 | + exportedState.put("fmu_uuid", state.uuid); |
| 235 | + |
| 236 | + std::vector<std::byte> vec; |
| 237 | + std::transform(state.fmuState.begin(), state.fmuState.end(), std::back_inserter(vec), |
| 238 | + [](unsigned char c) { return std::byte(c); }); |
| 239 | + |
| 240 | + exportedState.put("serialized_fmu_state", vec); |
| 241 | + exportedState.put("setup_complete", state.setupComplete); |
| 242 | + exportedState.put("simulation_started", state.simStarted); |
| 243 | + return exportedState; |
238 | 244 | }
|
239 | 245 |
|
240 | 246 | cosim::slave::state_index cosim::proxy::remote_slave::import_state(
|
241 |
| - const cosim::serialization::node&) |
| 247 | + const cosim::serialization::node& node) |
242 | 248 | {
|
243 |
| - throw error( |
244 |
| - make_error_code(errc::unsupported_feature), |
245 |
| - "Proxyfmu does not support state serialization"); |
| 249 | + proxyfmu::thrift::ExportedState state; |
| 250 | + state.schemeVersion = node.get<std::int32_t>("scheme_version"); |
| 251 | + state.uuid = node.get<std::string>("fmu_uuid"); |
| 252 | + |
| 253 | + const auto& serializedFMUState = std::get<std::vector<std::byte>>( |
| 254 | + node.get_child("serialized_fmu_state").data()); |
| 255 | + state.fmuState.reserve(serializedFMUState.size()); |
| 256 | + std::transform(serializedFMUState.begin(), serializedFMUState.end(), std::back_inserter(state.fmuState), |
| 257 | + [](std::byte b) { return static_cast<unsigned char>(b); }); |
| 258 | + |
| 259 | + state.setupComplete = node.get<bool>("setup_complete"); |
| 260 | + state.simStarted = node.get<bool>("simulation_started"); |
| 261 | + return slave_->import_state(state); |
246 | 262 | }
|
247 | 263 |
|
248 | 264 | cosim::proxy::remote_slave::~remote_slave()
|
|
0 commit comments