Developer forums (C::B DEVELOPMENT STRICTLY!) > Development
Feedback needed for change in plugins' event handling
mandrav:
We are considering changing the way C::B events are forwarded to plugins for processing so as to cut down the number of events flowing around.
In case you hadn't noticed it, with the current system, a single event might end up many times in the event handler of one plugin. This is what we 're trying to solve.
The proposed approach looks like this:
* A new function is added: PluginManager::RegisterEventSink(const wxEventType evtType, void(cbPlugin::*handler)(CodeBlocksEvent&))
* Plugins remove the old entries from their event tables and use the above function in OnAttach() to register their event handlers
The above process needs minimum code changes in both the SDK as well as the plugins. Basically, from the plugin writer's point of view, we just move the event handling registration from the plugin's event table to its OnAttach() method. Really a minimum change.
By going with the above change, we can guarantee that each registered event handler will be called exactly once for each event entering the queue.
We also minimize the overhead because a normal wxEvent handled by the event table will have to enter the event processing queue and be delivered where it is needed. With this change, we 're talking about a single loop over only the registered handlers and that's it.
We should be able to gain in speed and responsiveness.
One more great advantage is that by using this approach, we could even get feedback from the event handlers because the event is passed along synchronously. Which means after we return from a call to an event handler, we could examine the event for raised flags, changed contents etc.
We 'd like to have feedback on this proposal. Please share your views :)
thomas:
It's important to point out that we're talking of CodeBlocksEvents here, i.e. not of wxWidgets GUI or timer events, for example.
The latter might cause serious issues with the GUI hanging for half a second or things like that, if run synchronously.
My solution to the problem would have been to implement something like callbacks (rather this-pointer calls, actually) and kicking events for this matter alltogether. While that would probably be more efficient, it would require a lot of code changes, so Yiannis' solution is likely preferrable.
mandrav:
--- Quote from: thomas on July 05, 2007, 02:25:56 pm ---It's important to point out that we're talking of CodeBlocksEvents here, i.e. not of wxWidgets GUI or timer events, for example.
The latter might cause serious issues with the GUI hanging for half a second or things like that, if run synchronously.
--- End quote ---
Correct.
--- Quote from: thomas on July 05, 2007, 02:25:56 pm ---My solution to the problem would have been to implement something like callbacks (rather this-pointer calls, actually) and kicking events for this matter alltogether. While that would probably be more efficient, it would require a lot of code changes, so Yiannis' solution is likely preferrable.
--- End quote ---
Well, this-pointer calls will be used so we 're really talking about the same thing :).
JGM:
--- Quote from: mandrav on July 05, 2007, 02:18:20 pm ---The proposed approach looks like this:
* A new function is added: PluginManager::RegisterEventSink(const wxEventType evtType, void(cbPlugin::*handler)(CodeBlocksEvent&))
--- End quote ---
Could you give a concrete example of how the code will look like on the attach function, with an actual event?
mandrav:
--- Quote from: JGM on July 05, 2007, 02:50:06 pm ---
--- Quote from: mandrav on July 05, 2007, 02:18:20 pm ---The proposed approach looks like this:
* A new function is added: PluginManager::RegisterEventSink(const wxEventType evtType, void(cbPlugin::*handler)(CodeBlocksEvent&))
--- End quote ---
Could you give a concrete example of how the code will look like on the attach function, with an actual event?
--- End quote ---
Old sample code:
--- Code: ---BEGIN_EVENT_TABLE(SomePlugin, cbPlugin)
...
EVT_EDITOR_SAVE(SomePlugin::OnSave)
...
END_EVENT_TABLE()
--- End code ---
New sample code:
--- Code: ---BEGIN_EVENT_TABLE(SomePlugin, cbPlugin)
...
// remove EVT_EDITOR_SAVE entry
...
END_EVENT_TABLE()
void SomePlugin::OnAttach()
{
...
PluginManager* pm = Manager::Get()->GetPluginManager();
pm->RegisterEventSink(cbEVT_EDITOR_SAVE, &SomePlugin::OnSave);
...
}
--- End code ---
That's more or less what needs to change in plugins. Let me stress once more that we 're only talking about Code::Blocks events here...
Navigation
[0] Message Index
[#] Next page
Go to full version