Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Applied patch #3015678: Stage plugin interfaces: Unsubscribe from mod…

…el only once
  • Loading branch information...
commit 241008d8a57e865594f7d2104e99eb1cdef3ac0a 1 parent 8990e97
Rich Mattes authored committed
View
4 libstage/model.cc
@@ -708,7 +708,7 @@ void Model::Subscribe( void )
world->total_subs++;
world->dirty = true; // need redraw
- //printf( "subscribe to %s %d\n", token, subs );
+ //printf( "subscribe to %s %d\n", Token(), subs );
// if this is the first sub, call startup
if( subs == 1 )
@@ -721,7 +721,7 @@ void Model::Unsubscribe( void )
world->total_subs--;
world->dirty = true; // need redraw
- //printf( "unsubscribe from %s %d\n", token, subs );
+ //printf( "unsubscribe from %s %d\n", Token(), subs );
// if this is the last sub, call shutdown
if( subs == 0 )
View
20 libstageplugin/p_driver.cc
@@ -228,7 +228,7 @@ InterfaceModel::InterfaceModel( player_devaddr_t addr,
ConfigFile* cf,
int section,
const std::string& type )
- : Interface( addr, driver, cf, section )
+ : Interface( addr, driver, cf, section ), mod( NULL ), subscribed( false )
{
char* model_name = (char*)cf->ReadString(section, "model", NULL );
@@ -263,6 +263,24 @@ InterfaceModel::InterfaceModel( player_devaddr_t addr,
printf( "\"%s\"\n", this->mod->Token() );
}
+void InterfaceModel::Subscribe()
+{
+ if( !subscribed && this->mod )
+ {
+ this->mod->Subscribe();
+ subscribed = true;
+ }
+}
+
+void InterfaceModel::Unsubscribe()
+{
+ if( subscribed )
+ {
+ this->mod->Unsubscribe();
+ subscribed = false;
+ }
+}
+
// Constructor. Retrieve options from the configuration file and do any
// pre-Setup() setup.
View
12 libstageplugin/p_driver.h
@@ -104,12 +104,16 @@ class InterfaceModel
int section,
const std::string& type );
- Stg::Model* mod;
+ virtual ~InterfaceModel( void ){ Unsubscribe(); };
- virtual ~InterfaceModel( void ){ /* TODO: clean up*/ };
+ virtual void Subscribe( void );
+ virtual void Unsubscribe( void );
- virtual void Subscribe( void ){ this->mod->Subscribe(); };
- virtual void Unsubscribe( void ){ this->mod->Unsubscribe(); };
+ protected:
+ Stg::Model* mod;
+
+ private:
+ bool subscribed;
};
Please sign in to comment.
Something went wrong with that request. Please try again.