Skip to content

Commit

Permalink
Fix broken cse_local_slave_create #381 (#387)
Browse files Browse the repository at this point in the history
* Fix broken cse_local_slave_create #381
  • Loading branch information
markaren authored Sep 27, 2019
1 parent 7e731dc commit 1216875
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 21 deletions.
4 changes: 3 additions & 1 deletion include/cse.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,14 @@ typedef struct cse_slave_s cse_slave;
*
* \param [in] fmuPath
* Path to FMU.
* \param [in] instanceName
* Unique name of the instance.
*
* \returns
* A pointer to an object which holds the local slave object,
* or NULL on error.
*/
cse_slave* cse_local_slave_create(const char* fmuPath);
cse_slave* cse_local_slave_create(const char* fmuPath, const char* instanceName);

/**
* Destroys a local slave.
Expand Down
14 changes: 8 additions & 6 deletions src/c/cse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,21 @@ int cse_slave_get_variables(cse_execution* execution, cse_slave_index slave, cse
struct cse_slave_s
{
std::string address;
std::string name;
std::string modelName;
std::string instanceName;
std::string source;
std::shared_ptr<cse::slave> instance;
};

cse_slave* cse_local_slave_create(const char* fmuPath)
cse_slave* cse_local_slave_create(const char* fmuPath, const char* instanceName)
{
try {
const auto importer = cse::fmi::importer::create();
const auto fmu = importer->import(fmuPath);
auto slave = std::make_unique<cse_slave>();
slave->name = fmu->model_description()->name;
slave->instance = fmu->instantiate_slave(slave->name);
slave->modelName = fmu->model_description()->name;
slave->instanceName = std::string(instanceName);
slave->instance = fmu->instantiate_slave(slave->instanceName);
// slave address not in use yet. Should be something else than a string.
slave->address = "local";
slave->source = fmuPath;
Expand Down Expand Up @@ -393,8 +395,8 @@ cse_slave_index cse_execution_add_slave(
cse_slave* slave)
{
try {
auto index = execution->cpp_execution->add_slave(cse::make_background_thread_slave(slave->instance), slave->name);
execution->simulators[slave->name] = cse::simulator_map_entry{index, slave->source, slave->instance->model_description()};
auto index = execution->cpp_execution->add_slave(cse::make_background_thread_slave(slave->instance), slave->instanceName);
execution->simulators[slave->instanceName] = cse::simulator_map_entry{index, slave->source, slave->instance->model_description()};
return index;
} catch (...) {
handle_current_exception();
Expand Down
4 changes: 2 additions & 2 deletions test/c/connections_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave1 = cse_local_slave_create(fmuPath);
slave1 = cse_local_slave_create(fmuPath, "slave1");
if (!slave1) { goto Lerror; }

slave2 = cse_local_slave_create(fmuPath);
slave2 = cse_local_slave_create(fmuPath, "slave2");
if (!slave2) { goto Lerror; }

observer = cse_last_value_observer_create();
Expand Down
2 changes: 1 addition & 1 deletion test/c/custom_real_time_factor_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main() {
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave1 = cse_local_slave_create(fmuPath1);
slave1 = cse_local_slave_create(fmuPath1, "slave1");
if (!slave1) { goto Lerror; }

int idx1 = cse_execution_add_slave(execution, slave1);
Expand Down
4 changes: 2 additions & 2 deletions test/c/multiple_fmus_execution_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave1 = cse_local_slave_create(fmuPath);
slave1 = cse_local_slave_create(fmuPath, "slave1");
if (!slave1) { goto Lerror; }

slave2 = cse_local_slave_create(fmuPath);
slave2 = cse_local_slave_create(fmuPath, "slave2");
if (!slave2) { goto Lerror; }

observer1 = cse_last_value_observer_create();
Expand Down
2 changes: 1 addition & 1 deletion test/c/observer_can_buffer_samples.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave = cse_local_slave_create(fmuPath);
slave = cse_local_slave_create(fmuPath, "slave");
if (!slave) { goto Lerror; }

observer = cse_time_series_observer_create();
Expand Down
2 changes: 1 addition & 1 deletion test/c/observer_initial_samples_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave = cse_local_slave_create(fmuPath);
slave = cse_local_slave_create(fmuPath, "slave");
if (!slave) { goto Lerror; }

observer = cse_last_value_observer_create();
Expand Down
4 changes: 2 additions & 2 deletions test/c/observer_multiple_slaves_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave1 = cse_local_slave_create(fmuPath);
slave1 = cse_local_slave_create(fmuPath, "slave1");
if (!slave1) { goto Lerror; }
slave2 = cse_local_slave_create(fmuPath);
slave2 = cse_local_slave_create(fmuPath, "slave2");
if (!slave2) { goto Lerror; }

observer = cse_last_value_observer_create();
Expand Down
4 changes: 2 additions & 2 deletions test/c/real_time_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave1 = cse_local_slave_create(fmuPath1);
slave1 = cse_local_slave_create(fmuPath1, "slave1");
if (!slave1) { goto Lerror; }

slave2 = cse_local_slave_create(fmuPath2);
slave2 = cse_local_slave_create(fmuPath2, "slave2");
if (!slave2) { goto Lerror; }

int idx1 = cse_execution_add_slave(execution, slave1);
Expand Down
2 changes: 1 addition & 1 deletion test/c/single_fmu_execution_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave = cse_local_slave_create(fmuPath);
slave = cse_local_slave_create(fmuPath, "slave");
if (!slave) { goto Lerror; }

observer = cse_last_value_observer_create();
Expand Down
2 changes: 1 addition & 1 deletion test/c/time_series_observer_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave = cse_local_slave_create(fmuPath);
slave = cse_local_slave_create(fmuPath, "slave");
if (!slave) { goto Lerror; }

observer = cse_time_series_observer_create();
Expand Down
2 changes: 1 addition & 1 deletion test/c/variable_metadata_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main()
execution = cse_execution_create(0, nanoStepSize);
if (!execution) { goto Lerror; }

slave = cse_local_slave_create(fmuPath);
slave = cse_local_slave_create(fmuPath, "slave");
if (!slave) { goto Lerror; }

cse_slave_index slaveIndex = cse_execution_add_slave(execution, slave);
Expand Down

0 comments on commit 1216875

Please sign in to comment.