Changeset 7e470da


Ignore:
Timestamp:
Nov 1, 2006, 1:00:20 AM (17 years ago)
Author:
Sam Hartman <hartmans@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
3d18b30
Parents:
38ffdf9
git-author:
Sam Hartman <hartmans@mit.edu> (11/01/06 00:58:53)
git-committer:
Sam Hartman <hartmans@mit.edu> (11/01/06 01:00:20)
Message:
Move the module support system into perlwrap.pm
Add support for datadir modules.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • perlwrap.pm

    rd03091c r7e470da  
    281281#####################################################################
    282282#####################################################################
     283################################################################################
     284package owl;
     285
     286# Arrays of function pointers to be called at specific times.
     287our @onStartSubs = ();
     288our @onReceiveMsg = undef;
     289our @onMainLoop = undef;
     290our @onGetBuddyList = undef;
     291
     292################################################################################
     293# Mainloop hook and threading.
     294################################################################################
     295
     296use threads;
     297use threads::shared;
     298
     299# Shared thread shutdown flag.
     300# Consider adding a reload flag, so threads that should persist across reloads
     301# can distinguish the two events. We wouldn't want a reload to cause us to
     302# log out of and in to a perl-based IM session.
     303our $shutdown : shared;
     304$shutdown = 0;
     305our $reload : shared;
     306$reload = 0;
     307
     308sub owl::mainloop_hook
     309{
     310    foreach (@onMainLoop)
     311    {
     312        &$_();
     313    }
     314    return;
     315}
     316
     317################################################################################
     318# Startup and Shutdown code
     319################################################################################
     320sub owl::startup
     321{
     322# Modern versions of owl provides a great place to have startup stuff.
     323# Put things in ~/.owl/startup
     324    onStart();
     325}
     326
     327sub owl::shutdown
     328{
     329# Modern versions of owl provides a great place to have shutdown stuff.
     330# Put things in ~/.owl/shutdown
     331
     332# At this point I use owl::shutdown to tell any auxillary threads that they
     333# should terminate.
     334    $shutdown = 1;
     335    owl::mainloop_hook();
     336}
     337
     338#Run this on start and reload. Adds modules and runs their startup functions.
     339sub onStart
     340{
     341    reload_init();
     342    #So that the user's .owlconf can have startsubs, we don't clear
     343    #onStartSubs; reload does however
     344    @onReceiveMsg = ();
     345    @onMainLoop = ();
     346    @onGetBuddyList = ();
     347
     348    loadModules();
     349    foreach (@onStartSubs)
     350    {
     351        &$_();
     352    }
     353}
     354################################################################################
     355# Reload Code, taken from /afs/sipb/user/jdaniel/project/owl/perl
     356################################################################################
     357sub reload_hook (@)
     358{
     359   
     360  @onStartSubs = ();
     361    onStart();
     362    return 1;
     363}
     364
     365sub reload
     366{
     367    # Shutdown existing threads.
     368    $reload = 1;
     369    owl::mainloop_hook();
     370    $reload = 0;
     371    @onMainLoop = ();
     372   
     373    # Do reload
     374    if (do "$ENV{HOME}/.owlconf" && reload_hook(@_))
     375    {
     376        return "owlconf reloaded";
     377    }
     378    else
     379    {
     380        return "$ENV{HOME}/.owlconf load attempted, but error encountered:\n$@";
     381    }
     382}
     383
     384sub reload_init ()
     385{
     386    owl::command('alias reload perl reload');
     387    owl::command('bindkey global "C-x C-r" command reload');
     388}
     389
     390################################################################################
     391# Loads modules from ~/.owl/modules and owl's data directory
     392################################################################################
     393
     394sub loadModules ()
     395{
     396my @modules;
     397foreach my $dir (owl::get_data_dir()."/owl/modules", $ENV{HOME}."/.owl/modules") {
     398  opendir(MODULES, $dir);
     399  # source ./modules/*.pl
     400  @modules  =  grep(/\.pl$/, readdir(MODULES));
     401
     402foreach my $mod (@modules) {
     403  do "$dir/$mod";
     404}
     405closedir(MODULES);
     406}
     407}
     408sub queue_admin_msg
     409{
     410    my $err = shift;
     411    my $m = owl::Message->new(type => 'admin',
     412                              direction => 'none',
     413                              body => $err);
     414    owl::queue_message($m);
     415}
     416
     417
     418################################################################################
     419# Hooks into receive_msg()
     420################################################################################
     421
     422sub owl::receive_msg
     423{
     424    my $m = shift;
     425    foreach (@onReceiveMsg)
     426    {
     427        &$_($m);
     428    }
     429}
     430
     431################################################################################
     432# Hooks into get_blist()
     433################################################################################
     434
     435sub owl::get_blist
     436{
     437    my $m = shift;
     438    foreach (@onGetBuddyList)
     439    {
     440        &$_($m);
     441    }
     442}
    283443
    284444# switch to package main when we're done
    285445package main;
     446# alias the hooks
     447foreach my $hook  qw (onStartSubs
     448onReceiveMsg
     449onMainLoop
     450onGetBuddyList ) {
     451  *{"main::".$hook} = \*{"owl::".$hook};
     452}
    286453
    287454# load the config  file
Note: See TracChangeset for help on using the changeset viewer.