Changeset 7e470da for perlwrap.pm
- Timestamp:
- Nov 1, 2006, 1:00:20 AM (18 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perlwrap.pm
rd03091c r7e470da 281 281 ##################################################################### 282 282 ##################################################################### 283 ################################################################################ 284 package owl; 285 286 # Arrays of function pointers to be called at specific times. 287 our @onStartSubs = (); 288 our @onReceiveMsg = undef; 289 our @onMainLoop = undef; 290 our @onGetBuddyList = undef; 291 292 ################################################################################ 293 # Mainloop hook and threading. 294 ################################################################################ 295 296 use threads; 297 use 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. 303 our $shutdown : shared; 304 $shutdown = 0; 305 our $reload : shared; 306 $reload = 0; 307 308 sub owl::mainloop_hook 309 { 310 foreach (@onMainLoop) 311 { 312 &$_(); 313 } 314 return; 315 } 316 317 ################################################################################ 318 # Startup and Shutdown code 319 ################################################################################ 320 sub 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 327 sub 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. 339 sub 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 ################################################################################ 357 sub reload_hook (@) 358 { 359 360 @onStartSubs = (); 361 onStart(); 362 return 1; 363 } 364 365 sub 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 384 sub 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 394 sub loadModules () 395 { 396 my @modules; 397 foreach 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 402 foreach my $mod (@modules) { 403 do "$dir/$mod"; 404 } 405 closedir(MODULES); 406 } 407 } 408 sub 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 422 sub 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 435 sub owl::get_blist 436 { 437 my $m = shift; 438 foreach (@onGetBuddyList) 439 { 440 &$_($m); 441 } 442 } 283 443 284 444 # switch to package main when we're done 285 445 package main; 446 # alias the hooks 447 foreach my $hook qw (onStartSubs 448 onReceiveMsg 449 onMainLoop 450 onGetBuddyList ) { 451 *{"main::".$hook} = \*{"owl::".$hook}; 452 } 286 453 287 454 # load the config file
Note: See TracChangeset
for help on using the changeset viewer.