[NeoStats-Devel] [Commits] r2693 - in trunk: modules/perltest src
[email protected] Tue, 9 Aug 2005 17:25:07 +1000
| Newsgroups | gmane.comp.neostats.devel |
|---|---|
| Message-ID | <[email protected]> |
Author: Fish
Date: Tue Aug 9 15:25:02 2005
New Revision: 2693
Modified:
trunk/modules/perltest/test.pl
trunk/src/NeoStats.pm
trunk/src/neostats.pm.h
trunk/src/perl.c
trunk/src/timer.c
Log:
Timers for perl modules
Modified: trunk/modules/perltest/test.pl
==============================================================================
--- trunk/modules/perltest/test.pl (original)
+++ trunk/modules/perltest/test.pl Tue Aug 9 15:25:02 2005
@@ -357,6 +357,14 @@
NeoStats::AddCmd($bot, $cmd, 'cmd_cb_test');
NeoStats::debug(NeoStats::DelCmd($bot, $cmd->{cmd}));
NeoStats::ChanAlert($bot, "Loaded up and ready to rock and role");
+
+ NeoStats::AddTimer(NeoStats::TIMER_TYPE_INTERVAL, "Test Timer", 10, "timer_cb");
+
+}
+
+sub timer_cb {
+ NeoStats::ChanAlert($bot, "Timer Alert");
+ return NeoStats::NS_SUCCESS;
}
sub cmd_cb_test {
Modified: trunk/src/NeoStats.pm
==============================================================================
--- trunk/src/NeoStats.pm (original)
+++ trunk/src/NeoStats.pm Tue Aug 9 15:25:02 2005
@@ -543,7 +543,7 @@
sub Akill {
if (@_ < 5) {
- NeoStats::debug("Invalid Number of arguments to SMO");
+ NeoStats::debug("Invalid Number of arguments to Akill");
return NeoStats::NS_FAILURE;
}
my $bot = shift;
@@ -556,7 +556,7 @@
sub Rakill {
if (@_ < 3) {
- NeoStats::debug("Invalid Number of arguments to SMO");
+ NeoStats::debug("Invalid Number of arguments to Rakill");
return NeoStats::NS_FAILURE;
}
my $bot = shift;
@@ -565,6 +565,29 @@
return NeoStats::Internal::Rakill($bot, $host, $ident);
}
+ sub AddTimer {
+ if (@_ < 4) {
+ NeoStats::debug("Invalid Number of arguments to AddTimer");
+ return NeoStats::NS_FAILURE;
+ }
+ my $type = shift;
+ my $name = shift;
+ my $interval = shift;
+ my $callback = shift;
+ my ($package) = caller;
+ $callback = NeoStats::Embed::fix_callback( $package, $callback );
+ return NeoStats::Internal::AddTimer($type, $name, $interval, $callback);
+ }
+
+ sub DelTimer {
+ if (@_ < 1) {
+ NeoStats::debug("Invalid Number of arguments to DelTimer");
+ return NeoStats::NS_FAILURE;
+ }
+ my $name = shift;
+ return NeoStats::Internal::DelTimer($name);
+ }
+
sub debug {
my $text = shift @_;
Modified: trunk/src/neostats.pm.h
==============================================================================
--- trunk/src/neostats.pm.h (original)
+++ trunk/src/neostats.pm.h Tue Aug 9 15:25:02 2005
@@ -543,7 +543,7 @@
"\n"
"sub Akill {\n"
"if (@_ < 5) {\n"
-"NeoStats::debug(\"Invalid Number of arguments to SMO\");\n"
+"NeoStats::debug(\"Invalid Number of arguments to Akill\");\n"
"return NeoStats::NS_FAILURE;\n"
"}\n"
"my $bot = shift;\n"
@@ -556,7 +556,7 @@
"\n"
"sub Rakill {\n"
"if (@_ < 3) {\n"
-"NeoStats::debug(\"Invalid Number of arguments to SMO\");\n"
+"NeoStats::debug(\"Invalid Number of arguments to Rakill\");\n"
"return NeoStats::NS_FAILURE;\n"
"}\n"
"my $bot = shift;\n"
@@ -565,6 +565,29 @@
"return NeoStats::Internal::Rakill($bot, $host, $ident);\n"
"}\n"
"\n"
+"sub AddTimer {\n"
+"if (@_ < 4) {\n"
+"NeoStats::debug(\"Invalid Number of arguments to AddTimer\");\n"
+"return NeoStats::NS_FAILURE;\n"
+"}\n"
+"my $type = shift;\n"
+"my $name = shift;\n"
+"my $interval = shift;\n"
+"my $callback = shift;\n"
+"my ($package) = caller;\n"
+"$callback = NeoStats::Embed::fix_callback( $package, $callback );\n"
+"return NeoStats::Internal::AddTimer($type, $name, $interval, $callback);\n"
+"}\n"
+"\n"
+"sub DelTimer {\n"
+"if (@_ < 1) {\n"
+"NeoStats::debug(\"Invalid Number of arguments to DelTimer\");\n"
+"return NeoStats::NS_FAILURE;\n"
+"}\n"
+"my $name = shift;\n"
+"return NeoStats::Internal::DelTimer($name);\n"
+"}\n"
+"\n"
"sub debug {\n"
"\n"
"my $text = shift @_;\n"
Modified: trunk/src/perl.c
==============================================================================
--- trunk/src/perl.c (original)
+++ trunk/src/perl.c Tue Aug 9 15:25:02 2005
@@ -305,6 +305,13 @@
return execute_perl(cmdparams->bot->moduleptr, sv_2mortal (newSVpv (cmdparams->cmd_ptr->moddata, 0)), 3, cmdparams->cmd_ptr->cmd, cmdparams->source->name, cmdparams->param);
}
+int
+perl_timer_cb( void *userptr) {
+ Module *mod;
+ mod = GET_CUR_MODULE();
+
+ return execute_perl(mod, sv_2mortal(newSVpv((char *)userptr, 0)), 0);
+}
/* encode a Client Structure into a perl Hash */
HV *perl_encode_client(Client *u) {
@@ -1341,6 +1348,38 @@
}
+
+static
+XS (XS_NeoStats_AddTimer)
+{
+ Module *mod;
+ dXSARGS;
+
+ mod = GET_CUR_MODULE();
+ if (items < 4) {
+ nlog(LOG_WARNING, "Usage: NeoStats:Internal:AddTimer(type, name, interval, callback)");
+ } else {
+ XSRETURN_UV(AddTimer(SvIV(ST(0)), perl_timer_cb, SvPV_nolen(ST(1)), SvIV(ST(2)), strndup(SvPV_nolen(ST(3)), sv_len(ST(3)))));
+ }
+ XSRETURN_UV(NS_FAILURE);
+}
+
+static
+XS (XS_NeoStats_DelTimer)
+{
+ Module *mod;
+ dXSARGS;
+
+ mod = GET_CUR_MODULE();
+ if (items < 1) {
+ nlog(LOG_WARNING, "Usage: NeoStats:Internal:DelTimer(name)");
+ } else {
+ XSRETURN_UV(DelTimer(SvPV_nolen(ST(0))));
+ }
+ XSRETURN_UV(NS_FAILURE);
+}
+
+
/* xs_init is the second argument perl_parse. As the name hints, it
initializes XS subroutines (see the perlembed manpage) */
static void
@@ -1391,6 +1430,8 @@
newXS ("NeoStats::Internal::SMO", XS_NeoStats_SMO, __FILE__);
newXS ("NeoStats::Internal::Akill", XS_NeoStats_Akill, __FILE__);
newXS ("NeoStats::Internal::Rakill", XS_NeoStats_Rakill, __FILE__);
+ newXS ("NeoStats::Internal::AddTimer", XS_NeoStats_AddTimer, __FILE__);
+ newXS ("NeoStats::Internal::DelTimer", XS_NeoStats_DelTimer, __FILE__);
stash = get_hv ("NeoStats::", TRUE);
if (stash == NULL) {
Modified: trunk/src/timer.c
==============================================================================
--- trunk/src/timer.c (original)
+++ trunk/src/timer.c Tue Aug 9 15:25:02 2005
@@ -229,6 +229,11 @@
dlog(DEBUG2, "DelTimer: removed timer %s for module %s", name, timer->moduleptr->info->name);
hash_delete (timerhash, tn);
hnode_destroy (tn);
+#ifdef USE_PERL
+ if (IS_PERL_MOD(timer->moduleptr)) {
+ ns_free(timer->userptr);
+ }
+#endif
ns_free (timer);
return NS_SUCCESS;
}