Fork me on GitHub
  November 15, 2018, 12:00:51 pm
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Callback System  (Read 1973 times)
deoxxa
Administrator
Newbie
*****
Posts: 28


View Profile
« 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.
Logged
xoft
Newbie
*
Posts: 42


View Profile
« 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:
PlayerCharPostHook(user->nick.c_str(), rawTime, msg.c_str());
or at least
Code:
(PlayerCharPostHookType(Mineserver::get()->plugin()->getHook("PlayerChatPost")))->doAll(user->nick.c_str(), rawTime, msg.c_str());
instead of
Code:
(static_cast<Hook3<bool,const char*,time_t,const char*>*>(Mineserver::get()->plugin()->getHook("PlayerChatPost")))->doAll(user->nick.c_str(), rawTime, msg.c_str());
Logged
xoft
Newbie
*
Posts: 42


View Profile
« 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.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!