Plugin API: minor change (adding parent frame) to support calling methods from hook. Also declare network time update argument to be const because good practice.

This commit is contained in:
Gilbert Clark 2014-09-04 20:41:44 -04:00
parent daae28c72e
commit 2446a942e0
5 changed files with 12 additions and 11 deletions

View file

@ -331,7 +331,7 @@ Val* BroFunc::Call(val_list* args, Frame* parent) const
if ( sample_logger ) if ( sample_logger )
sample_logger->FunctionSeen(this); sample_logger->FunctionSeen(this);
Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0); Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
if ( plugin_result ) if ( plugin_result )
return HandlePluginResult(plugin_result, args, Flavor()); return HandlePluginResult(plugin_result, args, Flavor());
@ -548,7 +548,7 @@ Val* BuiltinFunc::Call(val_list* args, Frame* parent) const
if ( sample_logger ) if ( sample_logger )
sample_logger->FunctionSeen(this); sample_logger->FunctionSeen(this);
Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, args), 0); Val* plugin_result = PLUGIN_HOOK_WITH_RESULT(HOOK_CALL_FUNCTION, HookCallFunction(this, parent, args), 0);
if ( plugin_result ) if ( plugin_result )
return HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION); return HandlePluginResult(plugin_result, args, FUNC_FLAVOR_FUNCTION);

View file

@ -559,13 +559,14 @@ int Manager::HookLoadFile(const string& file)
return rc; return rc;
} }
Val* Manager::HookCallFunction(const Func* func, val_list* vargs) const Val* Manager::HookCallFunction(const Func* func, Frame* parent, val_list* vargs) const
{ {
HookArgumentList args; HookArgumentList args;
if ( HavePluginForHook(META_HOOK_PRE) ) if ( HavePluginForHook(META_HOOK_PRE) )
{ {
args.push_back(HookArgument(func)); args.push_back(HookArgument(func));
args.push_back(HookArgument(parent));
args.push_back(HookArgument(vargs)); args.push_back(HookArgument(vargs));
MetaHookPre(HOOK_CALL_FUNCTION, args); MetaHookPre(HOOK_CALL_FUNCTION, args);
} }
@ -579,7 +580,7 @@ Val* Manager::HookCallFunction(const Func* func, val_list* vargs) const
{ {
Plugin* p = (*i).second; Plugin* p = (*i).second;
v = p->HookCallFunction(func, vargs); v = p->HookCallFunction(func, parent, vargs);
if ( v ) if ( v )
break; break;
@ -644,7 +645,7 @@ void Manager::HookDrainEvents() const
} }
void Manager::HookUpdateNetworkTime(double network_time) const void Manager::HookUpdateNetworkTime(const double network_time) const
{ {
HookArgumentList args; HookArgumentList args;

View file

@ -244,7 +244,7 @@ public:
* functions and events, it may be any Val and must be ignored). If no * functions and events, it may be any Val and must be ignored). If no
* plugin handled the call, the method returns null. * plugin handled the call, the method returns null.
*/ */
Val* HookCallFunction(const Func* func, val_list* args) const; Val* HookCallFunction(const Func* func, Frame *parent, val_list* args) const;
/** /**
* Hook that filters the queuing of an event. * Hook that filters the queuing of an event.
@ -261,7 +261,7 @@ public:
* *
* @param network_time The new network time. * @param network_time The new network time.
*/ */
void HookUpdateNetworkTime(double network_time) const; void HookUpdateNetworkTime(const double network_time) const;
/** /**
* Hook that informs plugins that the event queue is being drained. * Hook that informs plugins that the event queue is being drained.

View file

@ -271,7 +271,7 @@ int Plugin::HookLoadFile(const std::string& file, const std::string& ext)
return -1; return -1;
} }
Val* Plugin::HookCallFunction(const Func* func, val_list* args) Val* Plugin::HookCallFunction(const Func* func, Frame *parent, val_list* args)
{ {
return 0; return 0;
} }
@ -285,7 +285,7 @@ void Plugin::HookDrainEvents()
{ {
} }
void Plugin::HookUpdateNetworkTime(double network_time) void Plugin::HookUpdateNetworkTime(const double network_time)
{ {
} }

View file

@ -573,7 +573,7 @@ protected:
* ignored; best to use a \c TYPE_ANY). If the plugin did not handle * ignored; best to use a \c TYPE_ANY). If the plugin did not handle
* the call, it must return null. * the call, it must return null.
*/ */
virtual Val* HookCallFunction(const Func* func, val_list* args); virtual Val* HookCallFunction(const Func* func, Frame *parent, val_list* args);
/** /**
* Hook into raising events. Whenever the script interpreter is about * Hook into raising events. Whenever the script interpreter is about
@ -607,7 +607,7 @@ protected:
* *
* @param networkt_time The new network time. * @param networkt_time The new network time.
*/ */
virtual void HookUpdateNetworkTime(double network_time); virtual void HookUpdateNetworkTime(const double network_time);
/** /**
* Hook for destruction of objects registered with * Hook for destruction of objects registered with