^
- Code: Select all
class Messenger
{
public:
void addObserver(const Poco::AbstractObserver& observer)
{
nc.addObserver(observer);
}
void SendMessage()
{
nc.postNotification(new Notification);
}
private:
NotificationCenter nc;
};
^
And my plugin registers as an Observer on startup
^
- Code: Select all
class View : public SimplePlugin
{
public:
void Init( Messenger* inst)
{
inst->addObserver(Poco::NObserver
(*this,&View::HandleMessage));
}
void HandleMessage( const Poco::AutoPtr& note )
{
}
};
^
And here's the application code
^
- Code: Select all
int main(int argc, char** argv)
{
std::string path = "../Plugins/SimplePlugin";
path.append(SharedLibrary::suffix());
ClassLoadercl;
cl.loadLibrary(path);
SimplePlugin* plugin = cl.classFor("View").create();
{
SingletonHoldermessenger;
plugin->Init( messenger.get() );
messenger.get()->SendMessage();
Thread::sleep(100);
}
delete plugin;
cl.unloadLibrary(path);
return 0;
}
^
The plugin does get the Notification that's sent but the when the Messenger goes out of scope there's a crash in the NotificationCenter destructor as it deletes the ObserverList.
Can someone explain why that is happening?
I'm a bit of a newbie swimming over his head so I expect it some ignorance on my part but I don't understand what I'm doing wrong.
Thanks!
-Steve





