Changeset 12505e3


Ignore:
Timestamp:
Jun 21, 2011, 11:19:48 PM (13 years ago)
Author:
GitHub Merge Button <merge-button@github.com>
Parents:
937a00e9 (diff), f0d5ef5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge f0d5ef52c48abd4954c21397e5fba9605d8f713f into 937a00e96102f86412b6844575901e57be238546
Files:
2 deleted
25 edited

Legend:

Unmodified
Added
Removed
  • Makefile.am

    r3535a6e rdb4f7c3  
    4545     aim.c buddy.c buddylist.c style.c errqueue.c \
    4646     zbuddylist.c popexec.c select.c wcwidth.c \
    47      glib_compat.c mainpanel.c msgwin.c sepbar.c editcontext.c signal.c
     47     mainpanel.c msgwin.c sepbar.c editcontext.c signal.c
    4848
    4949NORMAL_SRCS = filterproc.c window.c windowcb.c
  • README

    r13ee8f2 r431fcd8  
    1919
    2020AnyEvent
     21Glib
    2122PAR
    2223Net::DNS
  • aim.c

    rdc1edbd r6dc3757  
    113113}
    114114
    115 void owl_aim_send_nop(owl_timer *t, void *data) {
    116     if(owl_global_is_doaimevents(&g)) {
    117         aim_session_t *sess = owl_global_get_aimsess(&g);
    118         aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS));
    119     }
     115gboolean owl_aim_send_nop(gpointer data) {
     116  owl_global *g = data;
     117  if (owl_global_is_doaimevents(g)) {
     118    aim_session_t *sess = owl_global_get_aimsess(g);
     119    aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS));
     120  }
     121  return TRUE;
    120122}
    121123
     
    183185  owl_function_debugmsg("owl_aim_login: connecting");
    184186
    185   g.aim_nop_timer = owl_select_add_timer("owl_aim_send_nop", 30, 30, owl_aim_send_nop, NULL, NULL);
     187  g.aim_nop_timer = g_timeout_add_seconds(30, owl_aim_send_nop, &g);
    186188
    187189  return(0);
    188190}
    189191
    190 static void owl_aim_unset_ignorelogin(owl_timer *t, void *data)
    191 {
    192     owl_global_unset_ignore_aimlogin(&g);
     192static gboolean owl_aim_unset_ignorelogin(void *data)
     193{
     194  owl_global *g = data;
     195  owl_global_unset_ignore_aimlogin(g);
     196  return FALSE;  /* only run once. */
    193197}
    194198
     
    209213  /* start the ingorelogin timer */
    210214  owl_global_set_ignore_aimlogin(&g);
    211   owl_select_add_timer("owl_aim_unset_ignorelogin",
    212                        owl_global_get_aim_ignorelogin_timer(&g),
    213                        0, owl_aim_unset_ignorelogin, NULL, NULL);
     215  g_timeout_add_seconds(owl_global_get_aim_ignorelogin_timer(&g),
     216                        owl_aim_unset_ignorelogin, &g);
    214217
    215218  /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */
     
    225228  owl_global_set_aimnologgedin(&g);
    226229  owl_global_set_no_doaimevents(&g);
    227   owl_select_remove_timer(g.aim_nop_timer);
     230  if (g.aim_nop_timer) {
     231    g_source_remove(g.aim_nop_timer);
     232    g.aim_nop_timer = 0;
     233  }
    228234}
    229235
     
    244250  owl_global_set_aimnologgedin(&g);
    245251  owl_global_set_no_doaimevents(&g);
    246   owl_select_remove_timer(g.aim_nop_timer);
     252  if (g.aim_nop_timer) {
     253    g_source_remove(g.aim_nop_timer);
     254    g.aim_nop_timer = 0;
     255  }
    247256}
    248257
  • commands.c

    r117c21c r12505e3  
    656656              "show subscriptions / show subs\n"
    657657              "show terminal\n"
    658               "show timers\n"
    659658              "show variables\n"
    660659              "show variable <variable>\n"
     
    22342233  } else if (!strcmp(argv[1], "styles")) {
    22352234    owl_function_show_styles();
    2236   } else if (!strcmp(argv[1], "timers")) {
    2237     owl_function_show_timers();
    22382235  } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) {
    22392236    owl_function_getsubs();
  • configure.ac

    r9d43dcc r12505e3  
    115115
    116116dnl Add CFLAGS and LIBS for glib-2.0
    117 PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.12 gobject-2.0 gthread-2.0])
     117PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.16 gobject-2.0 gthread-2.0])
    118118
    119119AC_MSG_NOTICE([Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}])
  • functions.c

    r259e60a8 rb9d22f7  
    9292  owl_function_popless_fmtext(&fm);
    9393  owl_list_cleanup(&l, g_free);
    94   owl_fmtext_cleanup(&fm);
    95 }
    96 
    97 static void _owl_function_timer_append_fmtext(gpointer data, gpointer user_data) {
    98   owl_fmtext *fm = user_data;
    99   owl_timer *timer = data;
    100   char *str = g_strdup_printf("- %s: in %d seconds",
    101                               timer->name ? timer->name : "(unnamed)",
    102                               (int)(timer->time - time(NULL)));
    103   owl_fmtext_append_normal(fm, str);
    104   g_free(str);
    105   if (timer->interval) {
    106     str = g_strdup_printf(", repeat every %d seconds", timer->interval);
    107     owl_fmtext_append_normal(fm, str);
    108     g_free(str);
    109   }
    110   owl_fmtext_append_normal(fm, "\n");
    111 }
    112 
    113 void owl_function_show_timers(void) {
    114   owl_fmtext fm;
    115   GList **timers;
    116 
    117   owl_fmtext_init_null(&fm);
    118   owl_fmtext_append_bold(&fm, "Active timers:\n");
    119 
    120   timers = owl_global_get_timerlist(&g);
    121   g_list_foreach(*timers, _owl_function_timer_append_fmtext, &fm);
    122 
    123   owl_function_popless_fmtext(&fm);
    12494  owl_fmtext_cleanup(&fm);
    12595}
  • global.c

    rf97c1a6 rc5c5686  
    105105
    106106  owl_message_init_fmtext_cache();
    107   owl_list_create(&(g->io_dispatch_list));
    108   g->timerlist = NULL;
    109107  g->kill_buffer = NULL;
    110108
     
    839837{
    840838  return(&(g->startup_tio));
    841 }
    842 
    843 owl_list *owl_global_get_io_dispatch_list(owl_global *g)
    844 {
    845   return &(g->io_dispatch_list);
    846 }
    847 
    848 GList **owl_global_get_timerlist(owl_global *g)
    849 {
    850   return &(g->timerlist);
    851839}
    852840
  • owl.c

    rcc305b5 rbdc53e0  
    302302}
    303303
    304 void owl_process_input(const owl_io_dispatch *d, void *data)
     304gboolean owl_process_input(GIOChannel *source, GIOCondition condition, void *data)
    305305{
     306  owl_global *g = data;
    306307  owl_input j;
    307308
    308309  while (1) {
    309     j.ch = wgetch(g.input_pad);
    310     if (j.ch == ERR) return;
     310    j.ch = wgetch(g->input_pad);
     311    if (j.ch == ERR) return TRUE;
    311312
    312313    j.uch = '\0';
     
    330331     
    331332      for (i = 1; i < bytes; i++) {
    332         int tmp = wgetch(g.input_pad);
     333        int tmp = wgetch(g->input_pad);
    333334        /* If what we got was not a byte, or not a continuation byte */
    334335        if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) {
     
    357358    owl_process_input_char(j);
    358359  }
     360  return TRUE;
    359361}
    360362
     
    448450
    449451/* Sends stderr (read from rfd) messages to the error console */
    450 void stderr_redirect_handler(const owl_io_dispatch *d, void *data)
     452gboolean stderr_redirect_handler(GIOChannel *source, GIOCondition condition, void *data)
    451453{
    452454  int navail, bread;
    453455  char buf[4096];
    454   int rfd = d->fd;
     456  int rfd = g_io_channel_unix_get_fd(source);
    455457  char *err;
    456458
    457   if (rfd<0) return;
     459  /* TODO: Use g_io_channel_read_line? We'd have to be careful about
     460   * blocking on the read. */
     461
     462  if (rfd<0) return TRUE;
    458463  if (-1 == ioctl(rfd, FIONREAD, &navail)) {
    459     return;
     464    return TRUE;
    460465  }
    461466  /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/
    462   if (navail <= 0) return;
     467  if (navail <= 0) return TRUE;
    463468  if (navail > sizeof(buf)-1) {
    464469    navail = sizeof(buf)-1;
     
    466471  bread = read(rfd, buf, navail);
    467472  if (bread == -1)
    468     return;
     473    return TRUE;
    469474
    470475  err = g_strdup_printf("[stderr]\n%.*s", bread, buf);
     
    472477  owl_function_log_err(err);
    473478  g_free(err);
     479  return TRUE;
    474480}
    475481
     
    485491  owl_options opts;
    486492  GSource *source;
    487 
    488   if (!GLIB_CHECK_VERSION (2, 12, 0))
    489     g_error ("GLib version 2.12.0 or above is needed.");
     493  GIOChannel *channel;
    490494
    491495  argc_copy = argc;
     
    513517
    514518  /* register STDIN dispatch; throw away return, we won't need it */
    515   owl_select_add_io_dispatch(STDIN_FILENO, OWL_IO_READ, &owl_process_input, NULL, NULL);
     519  channel = g_io_channel_unix_new(STDIN_FILENO);
     520  g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, &owl_process_input, &g);
     521  g_io_channel_unref(channel);
    516522  owl_zephyr_initialize();
    517523
     
    519525  /* Do this only after we've started curses up... */
    520526  owl_function_debugmsg("startup: doing stderr redirection");
    521   owl_select_add_io_dispatch(stderr_replace(), OWL_IO_READ, &stderr_redirect_handler, NULL, NULL);
     527  channel = g_io_channel_unix_new(stderr_replace());
     528  g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR, &stderr_redirect_handler, NULL);
     529  g_io_channel_unref(channel);
    522530#endif
    523531
  • owl.h

    r24a791f r12505e3  
    121121#define OWL_MESSAGE_DIRECTION_IN    1
    122122#define OWL_MESSAGE_DIRECTION_OUT   2
    123 
    124 #define OWL_IO_READ   1
    125 #define OWL_IO_WRITE  2
    126 #define OWL_IO_EXCEPT 4
    127123
    128124#define OWL_DIRECTION_NONE      0
     
    517513} owl_zbuddylist;
    518514
    519 typedef struct _owl_timer {
    520   time_t time;
    521   int interval;
    522   void (*callback)(struct _owl_timer *, void *);
    523   void (*destroy)(struct _owl_timer *);
    524   void *data;
    525   char *name;
    526 } owl_timer;
    527 
    528515typedef struct _owl_errqueue {
    529516  owl_list errlist;
     
    536523} owl_colorpair_mgr;
    537524
    538 typedef struct _owl_io_dispatch {
    539   int fd;                                     /* FD to watch for dispatch. */
    540   int mode;
    541   bool valid;
    542   int needs_gc;
    543   void (*callback)(const struct _owl_io_dispatch *, void *); /* C function to dispatch to. */
    544   void (*destroy)(const struct _owl_io_dispatch *);  /* Destructor */
    545   void *data;
    546   GPollFD pollfd;
    547 } owl_io_dispatch;
    548 
    549525typedef struct _owl_popexec {
    550526  int refcount;
     
    552528  int winactive;
    553529  pid_t pid;                    /* or 0 if it has terminated */
    554   const owl_io_dispatch *dispatch;
     530  guint io_watch;
    555531} owl_popexec;
    556532
     
    616592  int pseudologin_notify;
    617593  struct termios startup_tio;
    618   owl_list io_dispatch_list;
    619   GList *timerlist;
    620   owl_timer *aim_nop_timer;
     594  guint aim_nop_timer;
    621595  int load_initial_subs;
    622596  FILE *debug_file;
  • perl/lib/BarnOwl.pm

    rf2d71cfa rf21bc36  
    2929use lib(get_config_dir() . "/lib");
    3030
     31use Glib;
     32use AnyEvent;
     33
    3134use BarnOwl::Hook;
    3235use BarnOwl::Hooks;
     
    3841use BarnOwl::Completion;
    3942use BarnOwl::Help;
    40 use BarnOwl::AnyEvent;
    41 
    42 unshift @AnyEvent::REGISTRY, [BarnOwl => BarnOwl::AnyEvent::];
    43 require AnyEvent;
    4443
    4544use List::Util qw(max);
     
    167166read from C<FD>.
    168167
    169 C<add_dispatch> has been deprecated in favor of C<add_io_dispatch>,
    170 and is now a wrapper for it called with C<mode> set to C<'r'>.
     168C<add_dispatch> has been deprecated in favor of C<AnyEvent>, and is
     169now a wrapper for C<add_io_dispatch> called with C<mode> set to
     170C<'r'>.
    171171
    172172=cut
     
    182182Remove a file descriptor previously registered via C<add_dispatch>
    183183
    184 C<remove_dispatch> has been deprecated in favor of
    185 C<remove_io_dispatch>.
     184C<remove_dispatch> has been deprecated in favor of C<AnyEvent>.
    186185
    187186=cut
     
    198197registered, the old one is removed.
    199198
    200 =cut
     199C<add_io_dispatch> has been deprecated in favor of C<AnyEvent>.
     200
     201=cut
     202
     203our %_io_dispatches;
    201204
    202205sub add_io_dispatch {
     
    204207    my $modeStr = shift;
    205208    my $cb = shift;
    206     my $mode = 0;
    207 
    208     $mode |= 0x1 if ($modeStr =~ /r/i); # Read
    209     $mode |= 0x2 if ($modeStr =~ /w/i); # Write
    210     if ($mode) {
    211         $mode |= 0x4;                  # Exceptional
    212         BarnOwl::Internal::add_io_dispatch($fd, $mode, $cb);
     209    my @modes;
     210
     211    push @modes, 'r' if $modeStr =~ /r/i; # Read
     212    push @modes, 'w' if $modeStr =~ /w/i; # Write
     213    if (@modes) {
     214        BarnOwl::remove_io_dispatch($fd);
     215        for my $mode (@modes) {
     216            push @{$_io_dispatches{$fd}}, AnyEvent->io(fh => $fd,
     217                                                       poll => $mode,
     218                                                       cb => $cb);
     219        }
    213220    } else {
    214221        die("Invalid I/O Dispatch mode: $modeStr");
     
    219226
    220227Remove a file descriptor previously registered via C<add_io_dispatch>
     228
     229C<remove_io_dispatch> has been deprecated in favor of C<AnyEvent>.
     230
     231=cut
     232
     233sub remove_io_dispatch {
     234    my $fd = shift;
     235    undef $_ foreach @{$_io_dispatches{$fd}};
     236    delete $_io_dispatches{$fd};
     237}
    221238
    222239=head2 create_style NAME OBJECT
  • perl/lib/BarnOwl/Complete/Client.pm

    rc6adf17 rb9d22f7  
    3737    subs        => undef,
    3838    terminal    => undef,
    39     timers      => undef,
    4039    variables   => undef,
    4140    variable    => \&complete_variable,
  • perl/lib/BarnOwl/Timer.pm

    rc6adf17 r7df7be2  
    33
    44package BarnOwl::Timer;
     5
     6use AnyEvent;
    57
    68sub new {
     
    1315    my $self = {cb => $cb};
    1416
    15     my $name = $args->{name};
    16     $name = "(unnamed)" unless defined $name;
    17 
    1817    bless($self, $class);
    1918
    20     $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0,
    21                                                   $args->{interval} || 0,
    22                                                   $self,
    23                                                   $name);
     19    $self->{timer} = AnyEvent->timer(%$args);
    2420    return $self;
    2521}
     
    2723sub stop {
    2824    my $self = shift;
    29     if(defined($self->{timer})) {
    30         BarnOwl::Internal::remove_timer($self->{timer});
    31         undef $self->{timer};
    32     }
     25    undef $self->{timer};
    3326}
    3427
  • perlconfig.c

    r937a00e9 r12505e3  
    548548}
    549549
    550 void owl_perlconfig_io_dispatch_destroy(const owl_io_dispatch *d)
    551 {
    552   SvREFCNT_dec(d->data);
    553 }
    554 
    555550void owl_perlconfig_edit_callback(owl_editwin *e)
    556551{
     
    587582  SvREFCNT_dec(v);
    588583}
    589 
    590 void owl_perlconfig_io_dispatch(const owl_io_dispatch *d, void *data)
    591 {
    592   SV *cb = data;
    593   dSP;
    594   if(cb == NULL) {
    595     owl_function_error("Perl callback is NULL!");
    596     return;
    597   }
    598 
    599   ENTER;
    600   SAVETMPS;
    601 
    602   PUSHMARK(SP);
    603   PUTBACK;
    604 
    605   call_sv(cb, G_DISCARD|G_EVAL);
    606 
    607   if(SvTRUE(ERRSV)) {
    608     owl_function_error("%s", SvPV_nolen(ERRSV));
    609   }
    610 
    611   FREETMPS;
    612   LEAVE;
    613 }
    614 
    615 void owl_perlconfig_perl_timer(owl_timer *t, void *data)
    616 {
    617   dSP;
    618   SV *obj = data;
    619 
    620   if(!SvROK(obj)) {
    621     return;
    622   }
    623 
    624   ENTER;
    625   SAVETMPS;
    626 
    627   PUSHMARK(SP);
    628   XPUSHs(obj);
    629   PUTBACK;
    630 
    631   call_method("do_callback", G_DISCARD|G_EVAL);
    632 
    633   SPAGAIN;
    634 
    635   if (SvTRUE(ERRSV)) {
    636     owl_function_error("Error in callback: '%s'", SvPV_nolen(ERRSV));
    637     sv_setsv (ERRSV, &PL_sv_undef);
    638   }
    639 
    640   PUTBACK;
    641   FREETMPS;
    642   LEAVE;
    643 }
    644 
    645 void owl_perlconfig_perl_timer_destroy(owl_timer *t)
    646 {
    647   if(SvOK((SV*)t->data)) {
    648     SvREFCNT_dec((SV*)t->data);
    649   }
    650 }
  • perlglue.xs

    r3b8a563 rf21bc36  
    326326                g_free(rv);
    327327
    328 void
    329 remove_io_dispatch(fd)
    330         int fd
    331         CODE:
    332         owl_select_remove_perl_io_dispatch(fd);
    333 
    334328AV*
    335329all_filters()
     
    507501                                      ival);
    508502
    509 void
    510 add_io_dispatch(fd, mode, cb)
    511         int fd
    512         int mode
    513         SV * cb
    514         CODE:
    515         owl_select_add_perl_io_dispatch(fd, mode, newSVsv(cb));
    516 
    517 IV
    518 add_timer(after, interval, cb, name = NULL)
    519         int after
    520         int interval
    521         SV *cb
    522         const char *name
    523         PREINIT:
    524                 SV *ref;
    525                 owl_timer *t;
    526         CODE:
    527                 ref = sv_rvweaken(newSVsv(cb));
    528                 t = owl_select_add_timer(name,
    529                                          after,
    530                                          interval,
    531                                          owl_perlconfig_perl_timer,
    532                                          owl_perlconfig_perl_timer_destroy,
    533                                          ref);
    534                 owl_function_debugmsg("Created timer %s: %p", t->name ? t->name : "(unnamed)", t);
    535         RETVAL = (IV)t;
    536         OUTPUT:
    537                 RETVAL
    538 
    539 void
    540 remove_timer(timer)
    541         IV timer
    542         PREINIT:
    543                 owl_timer *t;
    544         CODE:
    545                 t = (owl_timer*)timer;
    546                 owl_function_debugmsg("Freeing timer %s: %p", t->name ? t->name : "(unnamed)", t);
    547                 owl_select_remove_timer(t);
    548 
    549503MODULE = BarnOwl                PACKAGE = BarnOwl::Editwin
    550504
  • popexec.c

    r47e0a6a rc66ec48  
    1616  int pipefds[2], child_write_fd, parent_read_fd;
    1717  pid_t pid;
     18  GIOChannel *channel;
    1819
    1920  if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) {
     
    5455    pe->pid=pid;
    5556    pe->winactive=1;
    56     pe->dispatch = owl_select_add_io_dispatch(parent_read_fd, OWL_IO_READ|OWL_IO_EXCEPT, &owl_popexec_inputhandler, &owl_popexec_delete_dispatch, pe);
     57    channel = g_io_channel_unix_new(parent_read_fd);
     58    g_io_channel_set_close_on_unref(channel, TRUE);
     59    pe->io_watch = g_io_add_watch_full(channel, G_PRIORITY_DEFAULT,
     60                                       G_IO_IN | G_IO_ERR | G_IO_HUP,
     61                                       owl_popexec_inputhandler, pe,
     62                                       (GDestroyNotify)owl_popexec_unref);
     63    g_io_channel_unref(channel);
    5764    pe->refcount++;
    5865  } else {
     
    7582}
    7683
    77 void owl_popexec_inputhandler(const owl_io_dispatch *d, void *data)
     84gboolean owl_popexec_inputhandler(GIOChannel *source, GIOCondition condition, void *data)
    7885{
    7986  owl_popexec *pe = data;
     
    8188  char *buf;
    8289  int status;
     90  int fd = g_io_channel_unix_get_fd(source);
    8391
    84   if (!pe) return;
     92  /* TODO: Reading from GIOChannel may be more convenient. */
     93
     94  if (!pe) return FALSE;
    8595
    8696  /* If pe->winactive is 0 then the vwin has closed.
     
    96106  /* the viewwin has closed */
    97107  if (!pe->pid && !pe->winactive) {
    98     owl_select_remove_io_dispatch(d);
    99     pe->dispatch = NULL;
    100     return;
     108    pe->io_watch = 0;
     109    return FALSE;
    101110  }
    102111
    103   if (0 != (rv_navail = ioctl(d->fd, FIONREAD, &navail))) {
     112  if (0 != (rv_navail = ioctl(fd, FIONREAD, &navail))) {
    104113    owl_function_debugmsg("ioctl error");
    105114  }
     
    113122      owl_viewwin_append_text(pe->vwin, "\n");
    114123    }
    115     owl_select_remove_io_dispatch(d);
    116     pe->dispatch = NULL;
    117     return;
     124    pe->io_watch = 0;
     125    return FALSE;
    118126  }
    119127
    120   if (d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {
     128  if (fd<0 || !pe->pid || !pe->winactive || rv_navail) {
    121129    owl_function_error("popexec should not have reached this point");
    122     return;
     130    return FALSE;
    123131  }
    124132
    125   if (navail<=0) return;
     133  if (navail<=0) return TRUE;
    126134  if (navail>1024) { navail = 1024; }
    127135  buf = g_new(char, navail+1);
    128136  owl_function_debugmsg("about to read %d", navail);
    129   bread = read(d->fd, buf, navail);
     137  bread = read(fd, buf, navail);
    130138  if (bread<0) {
    131139    perror("read");
     
    140148  }
    141149  g_free(buf);
    142  
    143 }
    144 
    145 void owl_popexec_delete_dispatch(const owl_io_dispatch *d)
    146 {
    147   owl_popexec *pe = d->data;
    148   close(d->fd);
    149   owl_popexec_unref(pe);
     150  return TRUE;
    150151}
    151152
     
    156157
    157158  pe->winactive = 0;
    158   if (pe->dispatch) {
    159     owl_select_remove_io_dispatch(pe->dispatch);
    160     pe->dispatch = NULL;
     159  if (pe->io_watch) {
     160    g_source_remove(pe->io_watch);
     161    pe->io_watch = 0;
    161162  }
    162163  if (pe->pid) {
  • select.c

    rf0781ba r12505e3  
    22
    33static GMainLoop *loop = NULL;
    4 static GMainContext *main_context;
    5 static int dispatch_active = 0;
    6 
    7 static GSource *owl_timer_source;
    8 static GSource *owl_io_dispatch_source;
    9 
    10 static int _owl_select_timer_cmp(const owl_timer *t1, const owl_timer *t2) {
    11   return t1->time - t2->time;
    12 }
    13 
    14 owl_timer *owl_select_add_timer(const char* name, int after, int interval, void (*cb)(owl_timer *, void *), void (*destroy)(owl_timer*), void *data)
    15 {
    16   owl_timer *t = g_new(owl_timer, 1);
    17   GList **timers = owl_global_get_timerlist(&g);
    18 
    19   t->time = time(NULL) + after;
    20   t->interval = interval;
    21   t->callback = cb;
    22   t->destroy = destroy;
    23   t->data = data;
    24   t->name = name ? g_strdup(name) : NULL;
    25 
    26   *timers = g_list_insert_sorted(*timers, t,
    27                                  (GCompareFunc)_owl_select_timer_cmp);
    28   return t;
    29 }
    30 
    31 void owl_select_remove_timer(owl_timer *t)
    32 {
    33   GList **timers = owl_global_get_timerlist(&g);
    34   if (t && g_list_find(*timers, t)) {
    35     *timers = g_list_remove(*timers, t);
    36     if(t->destroy) {
    37       t->destroy(t);
    38     }
    39     g_free(t->name);
    40     g_free(t);
    41   }
    42 }
    43 
    44 static gboolean owl_timer_prepare(GSource *source, int *timeout) {
    45   GList **timers = owl_global_get_timerlist(&g);
    46   GTimeVal now;
    47 
    48   /* TODO: In the far /far/ future, g_source_get_time is what the cool
    49    * kids use to get system monotonic time. */
    50   g_source_get_current_time(source, &now);
    51 
    52   /* FIXME: bother with millisecond accuracy now that we can? */
    53   if (*timers) {
    54     owl_timer *t = (*timers)->data;
    55     *timeout = t->time - now.tv_sec;
    56     if (*timeout <= 0) {
    57       *timeout = 0;
    58       return TRUE;
    59     }
    60     if (*timeout > 60 * 1000)
    61       *timeout = 60 * 1000;
    62   } else {
    63     *timeout = 60 * 1000;
    64   }
    65   return FALSE;
    66 }
    67 
    68 static gboolean owl_timer_check(GSource *source) {
    69   GList **timers = owl_global_get_timerlist(&g);
    70   GTimeVal now;
    71 
    72   /* TODO: In the far /far/ future, g_source_get_time is what the cool
    73    * kids use to get system monotonic time. */
    74   g_source_get_current_time(source, &now);
    75 
    76   /* FIXME: bother with millisecond accuracy now that we can? */
    77   if (*timers) {
    78     owl_timer *t = (*timers)->data;
    79     return t->time >= now.tv_sec;
    80   }
    81   return FALSE;
    82 }
    83 
    84 
    85 static gboolean owl_timer_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    86   GList **timers = owl_global_get_timerlist(&g);
    87   GTimeVal now;
    88 
    89   /* TODO: In the far /far/ future, g_source_get_time is what the cool
    90    * kids use to get system monotonic time. */
    91   g_source_get_current_time(source, &now);
    92 
    93   /* FIXME: bother with millisecond accuracy now that we can? */
    94   while(*timers) {
    95     owl_timer *t = (*timers)->data;
    96     int remove = 0;
    97 
    98     if(t->time > now.tv_sec)
    99       break;
    100 
    101     /* Reschedule if appropriate */
    102     if(t->interval > 0) {
    103       t->time = now.tv_sec + t->interval;
    104       *timers = g_list_remove(*timers, t);
    105       *timers = g_list_insert_sorted(*timers, t,
    106                                      (GCompareFunc)_owl_select_timer_cmp);
    107     } else {
    108       remove = 1;
    109     }
    110 
    111     /* Do the callback */
    112     t->callback(t, t->data);
    113     if(remove) {
    114       owl_select_remove_timer(t);
    115     }
    116   }
    117   return TRUE;
    118 }
    119 
    120 static GSourceFuncs owl_timer_funcs = {
    121   owl_timer_prepare,
    122   owl_timer_check,
    123   owl_timer_dispatch,
    124   NULL
    125 };
    126 
    127 /* Returns the valid owl_io_dispatch for a given file descriptor. */
    128 static owl_io_dispatch *owl_select_find_valid_io_dispatch_by_fd(const int fd)
    129 {
    130   int i, len;
    131   const owl_list *dl;
    132   owl_io_dispatch *d;
    133   dl = owl_global_get_io_dispatch_list(&g);
    134   len = owl_list_get_size(dl);
    135   for(i = 0; i < len; i++) {
    136     d = owl_list_get_element(dl, i);
    137     if (d->fd == fd && d->valid) return d;
    138   }
    139   return NULL;
    140 }
    141 
    142 static int owl_select_find_io_dispatch(const owl_io_dispatch *in)
    143 {
    144   int i, len;
    145   const owl_list *dl;
    146 
    147   if (in != NULL) {
    148     dl = owl_global_get_io_dispatch_list(&g);
    149     len = owl_list_get_size(dl);
    150     for(i = 0; i < len; i++) {
    151       const owl_io_dispatch *d = owl_list_get_element(dl, i);
    152       if (d == in) return i;
    153     }
    154   }
    155   return -1;
    156 }
    157 
    158 static void owl_select_invalidate_io_dispatch(owl_io_dispatch *d)
    159 {
    160   if (d == NULL || !d->valid)
    161     return;
    162   d->valid = false;
    163   g_source_remove_poll(owl_io_dispatch_source, &d->pollfd);
    164 }
    165 
    166 void owl_select_remove_io_dispatch(const owl_io_dispatch *in)
    167 {
    168   int elt;
    169   if (in != NULL) {
    170     elt = owl_select_find_io_dispatch(in);
    171     if (elt != -1) {
    172       owl_list *dl = owl_global_get_io_dispatch_list(&g);
    173       owl_io_dispatch *d = owl_list_get_element(dl, elt);
    174       if (dispatch_active)
    175         d->needs_gc = 1;
    176       else {
    177         owl_select_invalidate_io_dispatch(d);
    178         owl_list_remove_element(dl, elt);
    179         if (d->destroy)
    180           d->destroy(d);
    181         g_free(d);
    182       }
    183     }
    184   }
    185 }
    186 
    187 static void owl_select_io_dispatch_gc(void)
    188 {
    189   int i;
    190   owl_list *dl;
    191 
    192   dl = owl_global_get_io_dispatch_list(&g);
    193   /*
    194    * Count down so we aren't set off by removing items from the list
    195    * during the iteration.
    196    */
    197   for(i = owl_list_get_size(dl) - 1; i >= 0; i--) {
    198     owl_io_dispatch *d = owl_list_get_element(dl, i);
    199     if(d->needs_gc) {
    200       owl_select_remove_io_dispatch(d);
    201     }
    202   }
    203 }
    204 
    205 /* Each FD may have at most one valid dispatcher.
    206  * If a new dispatch is added for an FD, the old one is removed.
    207  * mode determines what types of events are watched for, and may be any combination of:
    208  * OWL_IO_READ, OWL_IO_WRITE, OWL_IO_EXCEPT
    209  */
    210 const owl_io_dispatch *owl_select_add_io_dispatch(int fd, int mode, void (*cb)(const owl_io_dispatch *, void *), void (*destroy)(const owl_io_dispatch *), void *data)
    211 {
    212   owl_io_dispatch *d = g_new(owl_io_dispatch, 1);
    213   owl_list *dl = owl_global_get_io_dispatch_list(&g);
    214   owl_io_dispatch *other;
    215 
    216   d->fd = fd;
    217   d->valid = true;
    218   d->needs_gc = 0;
    219   d->mode = mode;
    220   d->callback = cb;
    221   d->destroy = destroy;
    222   d->data = data;
    223 
    224   /* TODO: Allow changing fd and mode in the middle? Probably don't care... */
    225   d->pollfd.fd = fd;
    226   d->pollfd.events = 0;
    227   if (d->mode & OWL_IO_READ)
    228     d->pollfd.events |= G_IO_IN | G_IO_HUP | G_IO_ERR;
    229   if (d->mode & OWL_IO_WRITE)
    230     d->pollfd.events |= G_IO_OUT | G_IO_ERR;
    231   if (d->mode & OWL_IO_EXCEPT)
    232     d->pollfd.events |= G_IO_PRI | G_IO_ERR;
    233   g_source_add_poll(owl_io_dispatch_source, &d->pollfd);
    234 
    235 
    236   other = owl_select_find_valid_io_dispatch_by_fd(fd);
    237   if (other)
    238     owl_select_invalidate_io_dispatch(other);
    239   owl_list_append_element(dl, d);
    240 
    241   return d;
    242 }
    243 
    244 static gboolean owl_io_dispatch_prepare(GSource *source, int *timeout) {
    245   *timeout = -1;
    246   return FALSE;
    247 }
    248 
    249 static gboolean owl_io_dispatch_check(GSource *source) {
    250   int i, len;
    251   const owl_list *dl;
    252 
    253   dl = owl_global_get_io_dispatch_list(&g);
    254   len = owl_list_get_size(dl);
    255   for(i = 0; i < len; i++) {
    256     owl_io_dispatch *d = owl_list_get_element(dl, i);
    257     if (!d->valid) continue;
    258     if (d->pollfd.revents & G_IO_NVAL) {
    259       owl_function_debugmsg("Pruning defunct dispatch on fd %d.", d->fd);
    260       owl_select_invalidate_io_dispatch(d);
    261     }
    262     if (d->pollfd.revents & d->pollfd.events)
    263       return TRUE;
    264   }
    265   return FALSE;
    266 }
    267 
    268 static gboolean owl_io_dispatch_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) {
    269   int i, len;
    270   const owl_list *dl;
    271 
    272   dispatch_active = 1;
    273   dl = owl_global_get_io_dispatch_list(&g);
    274   len = owl_list_get_size(dl);
    275   for (i = 0; i < len; i++) {
    276     owl_io_dispatch *d = owl_list_get_element(dl, i);
    277     if (!d->valid) continue;
    278     if ((d->pollfd.revents & d->pollfd.events) && d->callback != NULL) {
    279       d->callback(d, d->data);
    280     }
    281   }
    282   dispatch_active = 0;
    283   owl_select_io_dispatch_gc();
    284 
    285   return TRUE;
    286 }
    287 
    288 static GSourceFuncs owl_io_dispatch_funcs = {
    289   owl_io_dispatch_prepare,
    290   owl_io_dispatch_check,
    291   owl_io_dispatch_dispatch,
    292   NULL
    293 };
    294 
    295 int owl_select_add_perl_io_dispatch(int fd, int mode, SV *cb)
    296 {
    297   const owl_io_dispatch *d = owl_select_find_valid_io_dispatch_by_fd(fd);
    298   if (d != NULL && d->callback != owl_perlconfig_io_dispatch) {
    299     /* Don't mess with non-perl dispatch functions from here. */
    300     return 1;
    301   }
    302   /* Also remove any invalidated perl dispatch functions that may have
    303    * stuck around. */
    304   owl_select_remove_perl_io_dispatch(fd);
    305   owl_select_add_io_dispatch(fd, mode, owl_perlconfig_io_dispatch, owl_perlconfig_io_dispatch_destroy, cb);
    306   return 0;
    307 }
    308 
    309 static owl_io_dispatch *owl_select_find_perl_io_dispatch(int fd)
    310 {
    311   int i, len;
    312   const owl_list *dl;
    313   owl_io_dispatch *d;
    314   dl = owl_global_get_io_dispatch_list(&g);
    315   len = owl_list_get_size(dl);
    316   for(i = 0; i < len; i++) {
    317     d = owl_list_get_element(dl, i);
    318     if (d->fd == fd && d->callback == owl_perlconfig_io_dispatch)
    319       return d;
    320   }
    321   return NULL;
    322 }
    323 
    324 int owl_select_remove_perl_io_dispatch(int fd)
    325 {
    326   owl_io_dispatch *d = owl_select_find_perl_io_dispatch(fd);
    327   if (d != NULL) {
    328     /* Only remove perl io dispatchers from here. */
    329     owl_select_remove_io_dispatch(d);
    330     return 0;
    331   }
    332   return 1;
    333 }
    3344
    3355void owl_select_init(void)
    3366{
    337   owl_timer_source = g_source_new(&owl_timer_funcs, sizeof(GSource));
    338   g_source_attach(owl_timer_source, NULL);
    339 
    340   owl_io_dispatch_source = g_source_new(&owl_io_dispatch_funcs, sizeof(GSource));
    341   g_source_attach(owl_io_dispatch_source, NULL);
    3427}
    3438
    3449void owl_select_run_loop(void)
    34510{
    346   main_context = g_main_context_default();
    347   loop = g_main_loop_new(main_context, FALSE);
     11  loop = g_main_loop_new(NULL, FALSE);
    34812  g_main_loop_run(loop);
    34913}
  • variable.c

    r9efc154 r12505e3  
    504504int owl_variable_pseudologins_set(owl_variable *v, const void *newval)
    505505{
    506   static owl_timer *timer = NULL;
     506  static guint timer = 0;
    507507  if (newval) {
    508508    if (*(const int*)newval == 1) {
    509509      owl_function_zephyr_buddy_check(0);
    510       if (timer == NULL) {
    511         timer = owl_select_add_timer("owl_zephyr_buddycheck_timer",
    512                                      180, 180, owl_zephyr_buddycheck_timer, NULL, NULL);
     510      if (timer == 0) {
     511        timer = g_timeout_add_seconds(180, owl_zephyr_buddycheck_timer, NULL);
    513512      }
    514513    } else {
    515       if (timer != NULL) {
    516         owl_select_remove_timer(timer);
    517         timer = NULL;
     514      if (timer != 0) {
     515        g_source_remove(timer);
     516        timer = 0;
    518517      }
    519518    }
  • zephyr.c

    rb848e30 rc66ec48  
    4848  struct sockaddr_in sin;
    4949  ZNotice_t req;
     50  GIOChannel *channel;
    5051
    5152  /*
     
    9192  }
    9293
    93   owl_select_add_io_dispatch(ZGetFD(), OWL_IO_READ|OWL_IO_EXCEPT, &owl_zephyr_finish_initialization, NULL, NULL);
    94 }
    95 
    96 void owl_zephyr_finish_initialization(const owl_io_dispatch *d, void *data) {
     94  channel = g_io_channel_unix_new(ZGetFD());
     95  g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP,
     96                 &owl_zephyr_finish_initialization, NULL);
     97  g_io_channel_unref(channel);
     98}
     99
     100gboolean owl_zephyr_finish_initialization(GIOChannel *source, GIOCondition condition, void *data) {
    97101  Code_t code;
    98102  char *perl;
    99103  GSource *event_source;
    100104
    101   owl_select_remove_io_dispatch(d);
    102 
    103105  ZClosePort();
    104106
    105107  if ((code = ZInitialize()) != ZERR_NONE) {
    106108    owl_function_error("Initializing Zephyr: %s", error_message(code));
    107     return;
     109    return FALSE;
    108110  }
    109111
    110112  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
    111113    owl_function_error("Initializing Zephyr: %s", error_message(code));
    112     return;
     114    return FALSE;
    113115  }
    114116
     
    143145  perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()");
    144146  g_free(perl);
     147  return FALSE;
    145148}
    146149
     
    14321435#endif
    14331436
    1434 void owl_zephyr_buddycheck_timer(owl_timer *t, void *data)
     1437gboolean owl_zephyr_buddycheck_timer(void *data)
    14351438{
    14361439  if (owl_global_is_pseudologins(&g)) {
     
    14401443    owl_function_debugmsg("Warning: owl_zephyr_buddycheck_timer call pointless; timer should have been disabled");
    14411444  }
     1445  return TRUE;
    14421446}
    14431447
     
    15101514  event_source = (owl_zephyr_event_source*) source;
    15111515  event_source->poll_fd.fd = fd;
    1512   event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_PRI | G_IO_ERR;
     1516  event_source->poll_fd.events = G_IO_IN | G_IO_HUP | G_IO_ERR;
    15131517  g_source_add_poll(source, &event_source->poll_fd);
    15141518
  • barnowl

    rde18326 rb14f8cb  
    77EXE="$0.bin"
    88
    9 if ! test -x "$EXE"; then
     9if test ! -x "$EXE"; then
    1010    echo "Cannot find barnowl.bin" >&2
    1111    exit 1
    1212fi
    1313
    14 export BARNOWL_DATA_DIR="$SRCDIR/perl/"
    15 export BARNOWL_BIN_DIR="$SRCDIR/"
     14BARNOWL_DATA_DIR="$SRCDIR/perl/"
     15BARNOWL_BIN_DIR="$SRCDIR/"
     16export BARNOWL_DATA_DIR
     17export BARNOWL_BIN_DIR
    1618exec "$EXE" "$@"
  • cmd.c

    r4c7c21f raad166a  
    55#include "owl.h"
    66
    7 extern const owl_cmd commands_to_init[];
    8 
    97/**************************************************************************/
    108/***************************** COMMAND DICT *******************************/
     
    1311int owl_cmddict_setup(owl_cmddict *cd) {
    1412  owl_cmddict_init(cd);
    15   if (0 != owl_cmddict_add_from_list(cd, commands_to_init)) return(-1);
    16   return(0);
     13  return owl_cmd_add_defaults(cd);
    1714}
    1815
  • libfaim/aim.h

    r63de71c rfe73d0c  
    1818
    1919#include "config.h"
    20 #ifdef HAVE_STDBOOL_H
    2120#include <stdbool.h>
    22 #else
    23 #ifndef HAVE__BOOL
    24 #define _Bool signed char
    25 #endif
    26 #define bool _Bool
    27 #define false 0
    28 #define true 1
    29 #define __bool_true_false_are_defined 1
    30 #endif  /* HAVE_STDBOOL_H */
    3121
    3222#include <stdio.h>
  • scripts/locker-build

    r0fd5bd5 r4f5e38f  
    102102    esac
    103103
    104     CFLAGS="-I$BARNOWL/include" \
    105         LDFLAGS="-L$BARNOWL/lib $opt_rpath$BARNOWL/lib" \
     104    CPPFLAGS="-I$BARNOWL/include -I/usr/athena/include" \
     105        LDFLAGS="-L$BARNOWL/lib -L/usr/athena/lib $opt_rpath$BARNOWL/lib" \
    106106        ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \
    107107        --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \
  • tester.c

    r4c7c21f r4e37d56  
    3232  char *perlerr;
    3333  int status = 0;
     34  SCREEN *screen;
    3435
    3536  if (argc <= 1) {
     
    4142  wnull = fopen("/dev/null", "w");
    4243  rnull = fopen("/dev/null", "r");
    43   newterm("xterm", wnull, rnull);
     44  screen = newterm("xterm", wnull, rnull);
    4445  /* initialize global structures */
    4546  owl_global_init(&g);
     
    9192  /* probably not necessary, but tear down the screen */
    9293  endwin();
     94  delscreen(screen);
    9395  fclose(rnull);
    9496  fclose(wnull);
     
    218220  owl_string_appendf_quoted(g, "%q foo %q%q %s %", "hello", "world is", "can't");
    219221  FAIL_UNLESS("owl_string_appendf",
    220               !strcmp(g_string_free(g, false),
    221                       "hello foo 'world is'\"can't\" %s %"));
     222              !strcmp(g->str, "hello foo 'world is'\"can't\" %s %"));
     223  g_string_free(g, true);
    222224
    223225  /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */
     
    230232  owl_list l;
    231233  int numfailed=0;
    232   char *av="aval", *bv="bval", *cv="cval", *dv="dval";
     234  char *av = g_strdup("aval"), *bv = g_strdup("bval"), *cv = g_strdup("cval"),
     235    *dv = g_strdup("dval");
    233236
    234237  printf("# BEGIN testing owl_dict\n");
     
    259262  owl_list_cleanup(&l, g_free);
    260263  owl_dict_cleanup(&d, NULL);
     264
     265  g_free(av);
     266  g_free(bv);
     267  g_free(cv);
     268  g_free(dv);
    261269
    262270  /*  if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */
  • window.h

    r4cc49bc rfe73d0c  
    55#include <glib-object.h>
    66
    7 #ifdef HAVE_STDBOOL_H
    87#include <stdbool.h>
    9 #else
    10 #ifndef HAVE__BOOL
    11 #define _Bool signed char
    12 #endif
    13 #define bool _Bool
    14 #define false 0
    15 #define true 1
    16 #define __bool_true_false_are_defined 1
    17 #endif  /* HAVE_STDBOOL_H */
    188
    199G_BEGIN_DECLS
  • zcrypt.c

    r3b8a563 r5b197f7  
    1111#include <unistd.h>
    1212#include <sys/types.h>
    13 #include <zephyr/zephyr.h>
    1413#include <glib.h>
    1514#include <string.h>
Note: See TracChangeset for help on using the changeset viewer.