Skip to content

Commit

Permalink
Merge pull request #36 from robbr48/fetch_interface_sinks
Browse files Browse the repository at this point in the history
Fetch interface feature should work for multiple connections and sinks
  • Loading branch information
robbr48 authored Jan 9, 2018
2 parents 3104bb4 + 9def82c commit 495c0c7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
3 changes: 3 additions & 0 deletions common/Interfaces/TLMInterfaceSignal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ void TLMInterfaceSignal::GetTimeData(TLMTimeDataSignal& Instance, std::deque<TLM
// We always assume no waves initially.
Instance.Value = 0.0;
Instance.time = TLMPlugin::TIME_WITHOUT_DATA;

if( Params.mode > 0.0 ) waitForShutdownFlg = true;
return;
}

Expand Down Expand Up @@ -128,6 +130,7 @@ void TLMInterfaceSignal::GetTimeData(TLMTimeDataSignal& Instance, std::deque<TLM
}
}
}
if( Params.mode > 0.0 ) waitForShutdownFlg = true;
}


Expand Down
36 changes: 18 additions & 18 deletions common/Plugin/PluginImplementer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ TLMPlugin* TLMPlugin::CreateInstance() {
return PluginImplementerInstance;
}

void PluginImplementer::InterfaceReadyForTakedown(std::string IfcName) {
++nIfcWaitingForTakedown;

TLMErrorLog::Debug("Interface "+IfcName+" is ready for takedown.");

if(nIfcWaitingForTakedown >= Interfaces.size()) {
AwaitClosePermission();
exit(0);
}
}

void PluginImplementer::AwaitClosePermission()
{
TLMErrorLog::Info("Awaiting close permission...");
Expand Down Expand Up @@ -337,6 +348,10 @@ void PluginImplementer::GetValueSignal(int interfaceID, double time, double *val

// evaluate the reaction force from the TLM connection
ifc->GetValue(time, value);

if(ifc->waitForShutdown()) {
InterfaceReadyForTakedown(ifc->GetName());
}
}

//This function is for backwards compatibility, remove when position variables has been removed from all wrappers
Expand Down Expand Up @@ -439,12 +454,7 @@ void PluginImplementer::SetMotion3D(int forceID,
// needed anything ?
#endif

TLMErrorLog::Info(string("Takedown due to finished interface data request."));

// If we got here, we have a shutdown request from all interfaces
//abort(); // Some systems don't handle exit() very well, let's try abort();
// abort creates core dump!
exit(0);
InterfaceReadyForTakedown(ifc->GetName());
}
}

Expand Down Expand Up @@ -479,12 +489,7 @@ void PluginImplementer::SetValueSignal(int valueID,
// needed anything ?
#endif

TLMErrorLog::Info(string("Takedown due to finished interface data request."));

// If we got here, we have a shutdown request from all interfaces
//abort(); // Some systems don't handle exit() very well, let's try abort();
// abort creates core dump!
exit(0);
InterfaceReadyForTakedown(ifc->GetName());
}
}

Expand Down Expand Up @@ -520,12 +525,7 @@ void PluginImplementer::SetMotion1D(int forceID,
// needed anything ?
#endif

TLMErrorLog::Info(string("Takedown due to finished interface data request."));

// If we got here, we have a shutdown request from all interfaces
//abort(); // Some systems don't handle exit() very well, let's try abort();
// abort creates core dump!
exit(0);
InterfaceReadyForTakedown(ifc->GetName());
}
}

Expand Down
4 changes: 4 additions & 0 deletions common/Plugin/PluginImplementer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class PluginImplementer: public TLMPlugin {
double maxStep,
std::string ServerName);

void InterfaceReadyForTakedown(std::string IfcName);

void AwaitClosePermission();

//! Register TLM interface sends a registration request to TLMManager
Expand Down Expand Up @@ -181,6 +183,8 @@ class PluginImplementer: public TLMPlugin {
//! Maximum solver time step
double MaxStep;

size_t nIfcWaitingForTakedown = 0;

};

#endif

0 comments on commit 495c0c7

Please sign in to comment.