Changeset 9c7a701


Ignore:
Timestamp:
Feb 15, 2008, 12:56:49 AM (17 years ago)
Author:
Alejandro R. Sedeño <asedeno@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:
18a54ee
Parents:
a6a4155
Message:
Initial select() changes.
stdin, zephyr, jabber, and irc are checked and have dispatch functions.
aim is hacked in -- not entirely pretty, but documented and isolated.
We still want timers.
Files:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    r5ff830a r9c7a701  
    2626     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    2727     aim.c buddy.c buddylist.c timer.c style.c stylefunc.c errqueue.c \
    28      zbuddylist.c muxevents.c popexec.c obarray.c
     28     zbuddylist.c muxevents.c popexec.c obarray.c select.c
    2929OWL_SRC = owl.c
    3030TESTER_SRC = tester.c
  • global.c

    reebef19 r9c7a701  
    117117
    118118  owl_message_init_fmtext_cache();
     119  owl_list_create(&(g->dispatchlist));
    119120}
    120121
     
    932933  return owl_obarray_insert(&(g->obarray), string);
    933934}
     935
     936owl_list *owl_global_get_dispatchlist(owl_global *g)
     937{
     938  return &(g->dispatchlist);
     939}
  • owl.c

    reebef19 r9c7a701  
    4646#include <sys/param.h>
    4747#include <sys/types.h>
     48#include <sys/time.h>
    4849#include <termios.h>
    4950#include <sys/stat.h>
     
    6061#endif
    6162
     63#define STDIN 0
     64
    6265static const char fileIdent[] = "$Id$";
    6366
     
    6972  owl_editwin *tw;
    7073  owl_popwin *pw;
    71   int j, ret, initialsubs, debug, argcsave, followlast;
     74  int ret, initialsubs, debug, argcsave, followlast;
    7275  int newmsgs, nexttimediff;
    7376  struct sigaction sigact;
     
    206209  owl_global_set_haveaim(&g);
    207210
     211  /* prepare stdin dispatch */
     212  {
     213    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     214    d->fd = STDIN;
     215    d->cfunc = &owl_process_input;
     216    d->pfunc = NULL;
     217    owl_select_add_dispatch(d);
     218  }
     219 
    208220#ifdef HAVE_LIBZEPHYR
    209221  /* zephyr init */
    210222  ret=owl_zephyr_initialize();
    211   if (!ret)
    212       owl_global_set_havezephyr(&g);
     223  if (!ret) {
     224    owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
     225    d->fd = ZGetFD();
     226    d->cfunc = &owl_zephyr_process_events;
     227    d->pfunc = NULL;
     228    owl_select_add_dispatch(d);
     229    owl_global_set_havezephyr(&g);
     230  }
     231
    213232#endif
    214233
     
    425444    followlast=owl_global_should_followlast(&g);
    426445   
    427     /* Do AIM stuff */
    428     if (owl_global_is_doaimevents(&g)) {
    429       owl_aim_process_events();
    430 
    431       if (owl_global_is_aimloggedin(&g)) {
    432         if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
    433           /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
    434           owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
    435         }
    436       }
    437     }
    438 
    439446    owl_perlconfig_mainloop();
    440447
     
    454461    }
    455462
    456     owl_zephyr_process_events();
    457    
    458463    /* Grab incoming messages. */
    459464    newmsgs=0;
     
    530535     * little bit, but otherwise do not.  This lets input be grabbed
    531536     * as quickly as possbile */
    532     j=wgetch(typwin);
    533     if (j==ERR) {
    534       usleep(10000);
    535     } else {
    536       owl_global_set_lastinputtime(&g, now);
    537       /* find and activate the current keymap.
    538        * TODO: this should really get fixed by activating
    539        * keymaps as we switch between windows...
    540        */
    541       if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
    542         owl_context_set_popless(owl_global_get_context(&g),
    543                                 owl_global_get_viewwin(&g));
    544         owl_function_activate_keymap("popless");
    545       } else if (owl_global_is_typwin_active(&g)
    546                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_ONELINE) {
    547         /*
    548           owl_context_set_editline(owl_global_get_context(&g), tw);
    549           owl_function_activate_keymap("editline");
    550         */
    551       } else if (owl_global_is_typwin_active(&g)
    552                  && owl_editwin_get_style(tw)==OWL_EDITWIN_STYLE_MULTILINE) {
    553         owl_context_set_editmulti(owl_global_get_context(&g), tw);
    554         owl_function_activate_keymap("editmulti");
    555       } else {
    556         owl_context_set_recv(owl_global_get_context(&g));
    557         owl_function_activate_keymap("recv");
    558       }
    559       /* now actually handle the keypress */
    560       ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
    561       if (ret!=0 && ret!=1) {
    562         owl_function_makemsg("Unable to handle keypress");
    563       }
    564     }
     537
     538    /* select on FDs we know about. */
     539    owl_select();
    565540
    566541    /* Log any error signals */
     
    680655}
    681656
     657void owl_process_aim()
     658{
     659  if (owl_global_is_doaimevents(&g)) {
     660    owl_aim_process_events();
     661   
     662    if (owl_global_is_aimloggedin(&g)) {
     663      if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
     664        /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
     665        owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
     666      }
     667    }
     668  }
     669}
     670
     671void owl_process_input()
     672{
     673  int ret, j;
     674  owl_popwin *pw;
     675  owl_editwin *tw;
     676
     677  j = wgetch(owl_global_get_curs_typwin(&g));
     678  if (j == ERR) return;
     679
     680  owl_global_set_lastinputtime(&g, time(NULL));
     681  pw=owl_global_get_popwin(&g);
     682  tw=owl_global_get_typwin(&g);
     683
     684  /* find and activate the current keymap.
     685   * TODO: this should really get fixed by activating
     686   * keymaps as we switch between windows...
     687   */
     688  if (pw && owl_popwin_is_active(pw) && owl_global_get_viewwin(&g)) {
     689    owl_context_set_popless(owl_global_get_context(&g),
     690                            owl_global_get_viewwin(&g));
     691    owl_function_activate_keymap("popless");
     692  } else if (owl_global_is_typwin_active(&g)
     693             && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_ONELINE) {
     694    /*
     695      owl_context_set_editline(owl_global_get_context(&g), tw);
     696      owl_function_activate_keymap("editline");
     697    */
     698  } else if (owl_global_is_typwin_active(&g)
     699             && owl_editwin_get_style(tw) == OWL_EDITWIN_STYLE_MULTILINE) {
     700    owl_context_set_editmulti(owl_global_get_context(&g), tw);
     701    owl_function_activate_keymap("editmulti");
     702  } else {
     703    owl_context_set_recv(owl_global_get_context(&g));
     704    owl_function_activate_keymap("recv");
     705  }
     706  /* now actually handle the keypress */
     707  ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j);
     708  if (ret != 0 && ret != 1) {
     709    owl_function_makemsg("Unable to handle keypress");
     710  }
     711}
     712
    682713void sig_handler(int sig, siginfo_t *si, void *data)
    683714{
     
    694725    owl_function_quit();
    695726  }
    696 
    697727}
    698728
  • owl.h

    r88dc766 r9c7a701  
    537537  owl_list strings;
    538538} owl_obarray;
     539
     540typedef struct _owl_dispatch {
     541  int fd;           /* FD to watch for dispatch. */
     542  void (*cfunc)();  /* C function to dispatch to. */
     543  SV *pfunc;        /* Perl function to dispatch to. */
     544} owl_dispatch;
    539545
    540546typedef struct _owl_global {
     
    608614  struct termios startup_tio;
    609615  owl_obarray obarray;
     616  owl_list dispatchlist;
    610617} owl_global;
    611618
  • perl/modules/IRC/lib/BarnOwl/Module/IRC.pm

    rcab045b r9c7a701  
    6969}
    7070
    71 sub mainloop_hook {
     71#sub mainloop_hook {
     72#    return unless defined $irc;
     73#    eval {
     74#        $irc->do_one_loop();
     75#    };
     76#    return;
     77#}
     78
     79sub OwlProcess {
    7280    return unless defined $irc;
    7381    eval {
     
    7684    return;
    7785}
     86
    7887
    7988sub register_handlers {
     
    109118$BarnOwl::Hooks::startup->add(\&startup);
    110119$BarnOwl::Hooks::shutdown->add(\&shutdown);
    111 $BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
     120#$BarnOwl::Hooks::mainLoop->add(\&mainloop_hook);
    112121
    113122################################################################################
     
    165174        BarnOwl::admin_message("IRC", "Connected to $alias as $nick");
    166175        $ircnets{$alias} = $conn;
     176        my $fd = $conn->getSocket()->fileno();
     177        BarnOwl::add_dispatch($fd, \&OwlProcess);
     178        $conn->{FD} = $fd;
    167179    } else {
    168180        die("IRC::Connection->connect failed: $!");
  • perl/modules/IRC/lib/BarnOwl/Module/IRC/Connection.pm

    r5ff830a r9c7a701  
    6969}
    7070
     71sub getSocket
     72{
     73    my $self = shift;
     74    return $self->conn->socket;
     75}
     76
    7177################################################################################
    7278############################### IRC callbacks ##################################
     
    168174    my $self = shift;
    169175    delete $BarnOwl::Module::IRC::ircnets{$self->alias};
    170 
     176    BarnOwl::remove_dispatch($self->{FD});
    171177    BarnOwl::admin_message('IRC',
    172178                           "[" . $self->alias . "] Disconnected from server");
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm

    r879e7e94 r9c7a701  
    116116            BarnOwl::error("Connection for $jid undefined -- error in reload?");
    117117        }
    118 
    119         my $status = $client->Process(0);
    120         if ( !defined($status) ) {
    121             BarnOwl::error("Jabber account $jid disconnected!");
    122             do_logout($jid);
    123         }
    124118        if ($::shutdown) {
    125119            do_logout($jid);
    126             return;
     120            next;
    127121        }
    128122        if ($vars{status_changed}) {
     
    387381                $conn->renameConnection($jidStr, $fullJid);
    388382                queue_admin_msg("Connected to jabber as $fullJid");
     383                # The remove_dispatch() method is called from the
     384                # ConnectionManager's removeConnection() method.
     385                BarnOwl::add_dispatch($client->getSocket()->fileno(), sub { $client->OwlProcess() });
    389386            }
    390387        }
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber/Connection.pm

    r892568b r9c7a701  
    110110
    111111
     112=head2 getSID
     113
     114Returns the StreamID for this connection.
     115
     116=cut
     117
     118sub getStreamID {
     119    my $self = shift;
     120    return $self->{SESSION}->{id} || "";
     121}
     122
     123=head2 getSocket
     124
     125Returns the IO::Socket for this connection.
     126
     127=cut
     128
     129sub getSocket {
     130    my $self = shift;
     131    my $sid = getStreamID($self);
     132    return $self->{STREAM}->{SIDS}->{$sid}->{sock} || -1;
     133}
     134
     135=head2 OwlProcess
     136
     137Non-blocking connection processing. For use in a select loop.
     138
     139=cut
     140
     141sub OwlProcess {
     142    my $self = shift;
     143    my $status = $self->Process(0);
     144    if ( !defined($status) ) {
     145        my $jid = $self->{SESSION}->{FULLJID};
     146        BarnOwl::error("Jabber account $jid disconnected!");
     147        do_logout($jid);
     148    }
     149}
     150
    112151=head1 SEE ALSO
    113152
  • perl/modules/Jabber/lib/BarnOwl/Module/Jabber/ConnectionManager.pm

    r7f33c18 r9c7a701  
    3737    return 0 unless exists $self->{$jidStr};
    3838
     39    BarnOwl::remove_dispatch($self->{$jidStr}->{Client}->getSocket()->fileno());
    3940    $self->{$jidStr}->{Client}->Disconnect()
    4041      if $self->{$jidStr}->{Client};
     
    5152    return 0 if $oldJidStr eq $newJidStr;
    5253
    53     $self->{$newJidStr} = $self->{$oldJidStr}; 
     54    $self->{$newJidStr} = $self->{$oldJidStr};
    5455    delete $self->{$oldJidStr};
    5556    return 1;
  • perlconfig.c

    raf1920fd r9c7a701  
    485485}
    486486
     487void owl_perlconfig_dispatch_free(owl_dispatch *d)
     488{
     489  SvREFCNT_dec(d->pfunc);
     490}
     491
    487492void owl_perlconfig_edit_callback(owl_editwin *e)
    488493{
     
    528533  return;
    529534}
     535
     536void owl_perlconfig_do_dispatch(owl_dispatch *d)
     537{
     538  SV *cb = d->pfunc;
     539  unsigned int n_a;
     540  dSP;
     541  if(cb == NULL) {
     542    owl_function_error("Perl callback is NULL!");
     543  }
     544
     545  ENTER;
     546  SAVETMPS;
     547
     548  PUSHMARK(SP);
     549  PUTBACK;
     550 
     551  call_sv(cb, G_DISCARD|G_KEEPERR|G_EVAL);
     552
     553  if(SvTRUE(ERRSV)) {
     554    owl_function_error("%s", SvPV(ERRSV, n_a));
     555  }
     556
     557  FREETMPS;
     558  LEAVE;
     559}
  • perlglue.xs

    r65fea01 r9c7a701  
    342342                                      desc,
    343343                                      ival);
     344
     345void
     346add_dispatch(fd, cb)
     347        int fd
     348        SV * cb
     349        CODE:
     350        SvREFCNT_inc(cb);
     351        owl_select_add_perl_dispatch(fd, cb);
     352
     353void
     354remove_dispatch(fd)
     355        int fd
     356        CODE:
     357        owl_select_remove_perl_dispatch(fd);
  • zephyr.c

    r247cbc9 r9c7a701  
    2929  return(0);
    3030}
    31 
    3231
    3332int owl_zephyr_shutdown()
Note: See TracChangeset for help on using the changeset viewer.