Mineserver Community

Mineserver => Development => Topic started by: deoxxa on December 16, 2010, 06:32:22 am

Title: Callback System
Post by: deoxxa on December 16, 2010, 06:32:22 am
I wrote a small callback library over the past few days and implemented it in Mineserver this morning. This is the start of a plugin system, now all that is needed is hooks in relevant places and functionality to load external .so/.dll files and it's ready to go. What I need from the collective Mineserver hackers is input on hook locations and parameters. When individual hooks are implemented, they won't be able to be changed without breaking compatibility with existing code that uses them so we'll need to get their definitions right the first time.

So with this, I'd like to discuss potential locations for hooks and their arguments. The number of hooks shouldn't be considered limited, so don't try to squeeze too much functionality into them. Basically if a callback pointed to by a hook will be unable to function without first splitting its execution in some way, it might be better to split the hook into two separate hooks.

There's a small example of how the hooks function in chat.cpp (https://github.com/fador/mineserver/blob/master/src/chat.cpp). The hooks themselves will be defined in plugin.h (https://github.com/fador/mineserver/blob/master/src/plugin.h), which is right now being transitioned from the current delegate system to the new one.
Title: Re: Callback System
Post by: xoft on February 10, 2011, 10:36:17 pm
I think the various hooks should be typedeffed, or even wrapped in a #define or a specific function, so that one can write:
Code: [Select]
PlayerCharPostHook(user->nick.c_str(), rawTime, msg.c_str());
or at least
Code: [Select]
(PlayerCharPostHookType(Mineserver::get()->plugin()->getHook("PlayerChatPost")))->doAll(user->nick.c_str(), rawTime, msg.c_str());
instead of
Code: [Select]
(static_cast<Hook3<bool,const char*,time_t,const char*>*>(Mineserver::get()->plugin()->getHook("PlayerChatPost")))->doAll(user->nick.c_str(), rawTime, msg.c_str());
Title: Re: Callback System
Post by: xoft on February 19, 2011, 05:54:41 pm
A simple fast question: is any code (plugin or base server) allowed to cache values from calls to getHook()? I think some frequently called hooks may benefit from such a thing - use a pre-stored value rather than do a string search every time the hook is about to be called - may increase performance.