For$
<!-- begin site header -->
<div id=

Author Topic: Callback System  (Read 7561 times)

deoxxa

  • Administrator
  • Newbie
  • *****
  • Posts: 28
    • View Profile
Callback System
« 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. The hooks themselves will be defined in plugin.h, which is right now being transitioned from the current delegate system to the new one.

xoft

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Callback System
« Reply #1 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());

xoft

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Callback System
« Reply #2 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.