1
0
Fork 0

Improved fix for #204 and #222: JSBSim::unbind() needs to untie _all_ its properties

Extends and partially reverts commit 287cc74965
Previous fix did not consider properties outside the /fdm/jsbsim branch.
FGPropertyManager now keeps track of all its tied properties - and provides
a method to cleanly untie them again.
This commit is contained in:
ThorstenB 2011-02-05 17:49:26 +01:00
parent edfc06119a
commit ad8d46ba64
4 changed files with 32 additions and 22 deletions

View file

@ -101,8 +101,8 @@ CLASS DOCUMENTATION
file: file:
@code @code
fdmex = new FGFDMExec( ); fdmex = new FGFDMExec( ... );
result = fdmex->LoadModel( ); result = fdmex->LoadModel( ... );
@endcode @endcode
When an aircraft model is loaded, the config file is parsed and for each of the When an aircraft model is loaded, the config file is parsed and for each of the
@ -226,6 +226,9 @@ public:
/// Default destructor /// Default destructor
~FGFDMExec(); ~FGFDMExec();
/** Unbind all tied JSBSim properties. */
void unbind(void) {instance->unbind();}
/** This routine places a model into the runlist at the specified rate. The /** This routine places a model into the runlist at the specified rate. The
"rate" is not really a clock rate. It represents how many calls to the "rate" is not really a clock rate. It represents how many calls to the
FGFDMExec::Run() method must be made before the model is executed. A FGFDMExec::Run() method must be made before the model is executed. A

View file

@ -422,28 +422,9 @@ void FGJSBsim::init()
/******************************************************************************/ /******************************************************************************/
void checkTied ( FGPropertyManager *node )
{
int N = node->nChildren();
string name;
for (int i=0; i<N; i++) {
if (node->getChild(i)->nChildren() ) {
checkTied( (FGPropertyManager*)node->getChild(i) );
}
if ( node->getChild(i)->isTied() ) {
name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
node->Untie(name);
}
}
}
/******************************************************************************/
void FGJSBsim::unbind() void FGJSBsim::unbind()
{ {
SGPropertyNode* instance = globals->get_props()->getNode("/fdm/jsbsim"); fdmex->unbind();
checkTied((FGPropertyManager*)instance);
FGInterface::unbind(); FGInterface::unbind();
} }

View file

@ -49,6 +49,19 @@ COMMENTS, REFERENCES, and NOTES [use "class documentation" below for API docs]
namespace JSBSim { namespace JSBSim {
bool FGPropertyManager::suppress_warning = true; bool FGPropertyManager::suppress_warning = true;
std::vector<std::string> FGPropertyManager::tied_properties;
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void FGPropertyManager::unbind(void)
{
vector<string>::iterator it;
for (it = tied_properties.begin();it < tied_properties.end();it++)
{
Untie(*it);
}
tied_properties.clear();
}
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@ -301,6 +314,7 @@ void FGPropertyManager::Untie (const string &name)
void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault) void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
{ {
tied_properties.push_back(name);
if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault)) if (!tie(name.c_str(), SGRawValuePointer<bool>(pointer), useDefault))
cerr << "Failed to tie property " << name << " to a pointer" << endl; cerr << "Failed to tie property " << name << " to a pointer" << endl;
else if (debug_lvl & 0x20) else if (debug_lvl & 0x20)
@ -312,6 +326,7 @@ void FGPropertyManager::Tie (const string &name, bool *pointer, bool useDefault)
void FGPropertyManager::Tie (const string &name, int *pointer, void FGPropertyManager::Tie (const string &name, int *pointer,
bool useDefault ) bool useDefault )
{ {
tied_properties.push_back(name);
if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault)) if (!tie(name.c_str(), SGRawValuePointer<int>(pointer), useDefault))
cerr << "Failed to tie property " << name << " to a pointer" << endl; cerr << "Failed to tie property " << name << " to a pointer" << endl;
else if (debug_lvl & 0x20) else if (debug_lvl & 0x20)
@ -323,6 +338,7 @@ void FGPropertyManager::Tie (const string &name, int *pointer,
void FGPropertyManager::Tie (const string &name, long *pointer, void FGPropertyManager::Tie (const string &name, long *pointer,
bool useDefault ) bool useDefault )
{ {
tied_properties.push_back(name);
if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault)) if (!tie(name.c_str(), SGRawValuePointer<long>(pointer), useDefault))
cerr << "Failed to tie property " << name << " to a pointer" << endl; cerr << "Failed to tie property " << name << " to a pointer" << endl;
else if (debug_lvl & 0x20) else if (debug_lvl & 0x20)
@ -334,6 +350,7 @@ void FGPropertyManager::Tie (const string &name, long *pointer,
void FGPropertyManager::Tie (const string &name, float *pointer, void FGPropertyManager::Tie (const string &name, float *pointer,
bool useDefault ) bool useDefault )
{ {
tied_properties.push_back(name);
if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault)) if (!tie(name.c_str(), SGRawValuePointer<float>(pointer), useDefault))
cerr << "Failed to tie property " << name << " to a pointer" << endl; cerr << "Failed to tie property " << name << " to a pointer" << endl;
else if (debug_lvl & 0x20) else if (debug_lvl & 0x20)
@ -344,6 +361,7 @@ void FGPropertyManager::Tie (const string &name, float *pointer,
void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault) void FGPropertyManager::Tie (const string &name, double *pointer, bool useDefault)
{ {
tied_properties.push_back(name);
if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault)) if (!tie(name.c_str(), SGRawValuePointer<double>(pointer), useDefault))
cerr << "Failed to tie property " << name << " to a pointer" << endl; cerr << "Failed to tie property " << name << " to a pointer" << endl;
else if (debug_lvl & 0x20) else if (debug_lvl & 0x20)

View file

@ -77,6 +77,7 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
{ {
private: private:
static bool suppress_warning; static bool suppress_warning;
static std::vector<std::string> tied_properties;
public: public:
/// Constructor /// Constructor
FGPropertyManager(void) {suppress_warning = false;} FGPropertyManager(void) {suppress_warning = false;}
@ -399,6 +400,13 @@ class FGPropertyManager : public SGPropertyNode, public FGJSBBase
*/ */
void Untie (const std::string &name); void Untie (const std::string &name);
/**
* Unbind all properties bound by this manager to an external data source.
*
* Classes should use this function to release control of any
* properties they have bound using this property manager.
*/
void unbind (void);
// Templates cause ambiguity here // Templates cause ambiguity here