[3329] in BarnOwl Developers
[PATCH 4/5] Added a hook for wakeup/user input.
daemon@ATHENA.MIT.EDU (Jason Gross)
Sun Jan 13 14:09:00 2013
From: Jason Gross <jgross@MIT.EDU>
To: barnowl-dev@mit.edu
Cc: Jason Gross <jgross@mit.edu>
Date: Sun, 13 Jan 2013 14:07:53 -0500
In-Reply-To: <1358104074-23031-1-git-send-email-jgross@mit.edu>
I wanted to add a hook that got called on all user-input, but any
non-trivial use of that hook incurred too much overhead (about 7 ms per
paragraph for entry into perl, and another 100 ms or so per paragraph
for execution of the hook; tests run on pasting lorem ipusm, on
linerva).
This hook is called at most once a second (approximately).
---
global.c | 9 +++++++++
owl.c | 1 +
owl.h | 1 +
perl/lib/BarnOwl/Hooks.pm | 10 ++++++++++
4 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/global.c b/global.c
index 3783e6c..d57d9c9 100644
--- a/global.c
+++ b/global.c
@@ -53,6 +53,7 @@ void owl_global_init(owl_global *g) {
owl_regex_init(&g->search_re);
g->starttime=time(NULL); /* assumes we call init only a start time */
g->lastinputtime=g->starttime;
+ g->last_wakeup_time = g->starttime;
g->newmsgproc_pid=0;
owl_global_set_config_format(g, 0);
@@ -481,6 +482,14 @@ time_t owl_global_get_idletime(const owl_global *g) {
return(time(NULL)-g->lastinputtime);
}
+void owl_global_wakeup(owl_global *g)
+{
+ if (time(NULL) - g->last_wakeup_time >= 1) {
+ g_free(owl_perlconfig_execute("BarnOwl::Hooks::_wakeup()"));
+ g->last_wakeup_time = time(NULL);
+ }
+}
+
/* viewwin */
owl_viewwin *owl_global_get_viewwin(owl_global *g) {
diff --git a/owl.c b/owl.c
index e74926e..7747a8d 100644
--- a/owl.c
+++ b/owl.c
@@ -286,6 +286,7 @@ void owl_process_input_char(owl_input j)
int ret;
owl_global_set_lastinputtime(&g, time(NULL));
+ owl_global_wakeup(&g);
ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
if (ret!=0 && ret!=1) {
owl_function_makemsg("Unable to handle keypress");
diff --git a/owl.h b/owl.h
index c6ec236..bb891df 100644
--- a/owl.h
+++ b/owl.h
@@ -568,6 +568,7 @@ typedef struct _owl_global {
int debug;
time_t starttime;
time_t lastinputtime;
+ time_t last_wakeup_time;
char *startupargs;
int nextmsgid;
owl_colorpair_mgr cpmgr;
diff --git a/perl/lib/BarnOwl/Hooks.pm b/perl/lib/BarnOwl/Hooks.pm
index 28c29ce..1a4d931 100644
--- a/perl/lib/BarnOwl/Hooks.pm
+++ b/perl/lib/BarnOwl/Hooks.pm
@@ -35,6 +35,10 @@ argument if this is a reload, and false if this is a true startup
Called before BarnOwl shutdown
+=item $wakeup
+
+Called, at most once per second, on user input
+
=item $receiveMessage
Called with a C<BarnOwl::Message> object every time BarnOwl receives a
@@ -87,6 +91,7 @@ with zephyr formatting parsed. The format should be
use Exporter;
our @EXPORT_OK = qw($startup $shutdown
+ $wakeup
$receiveMessage $newMessage
$mainLoop $getBuddyList
$awayOn $awayOff $getIsAway
@@ -98,6 +103,7 @@ use BarnOwl::MainLoopCompatHook;
our $startup = BarnOwl::Hook->new;
our $shutdown = BarnOwl::Hook->new;
+our $wakeup = BarnOwl::Hook->new;
our $receiveMessage = BarnOwl::Hook->new;
our $newMessage = BarnOwl::Hook->new;
our $mainLoop = BarnOwl::MainLoopCompatHook->new;
@@ -193,6 +199,10 @@ sub _shutdown {
BarnOwl::shutdown() if *BarnOwl::shutdown{CODE};
}
+sub _wakeup {
+ $wakeup->run;
+}
+
sub _receive_msg {
my $m = shift;
--
1.7.2.5