Changeset 12505e3
- Timestamp:
- Jun 21, 2011, 11:19:48 PM (13 years ago)
- 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. - Files:
-
- 2 deleted
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
Makefile.am
r3535a6e rdb4f7c3 45 45 aim.c buddy.c buddylist.c style.c errqueue.c \ 46 46 zbuddylist.c popexec.c select.c wcwidth.c \ 47 glib_compat.cmainpanel.c msgwin.c sepbar.c editcontext.c signal.c47 mainpanel.c msgwin.c sepbar.c editcontext.c signal.c 48 48 49 49 NORMAL_SRCS = filterproc.c window.c windowcb.c -
README
r13ee8f2 r431fcd8 19 19 20 20 AnyEvent 21 Glib 21 22 PAR 22 23 Net::DNS -
aim.c
rdc1edbd r6dc3757 113 113 } 114 114 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 } 115 gboolean 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; 120 122 } 121 123 … … 183 185 owl_function_debugmsg("owl_aim_login: connecting"); 184 186 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); 186 188 187 189 return(0); 188 190 } 189 191 190 static void owl_aim_unset_ignorelogin(owl_timer *t, void *data) 191 { 192 owl_global_unset_ignore_aimlogin(&g); 192 static 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. */ 193 197 } 194 198 … … 209 213 /* start the ingorelogin timer */ 210 214 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); 214 217 215 218 /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */ … … 225 228 owl_global_set_aimnologgedin(&g); 226 229 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 } 228 234 } 229 235 … … 244 250 owl_global_set_aimnologgedin(&g); 245 251 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 } 247 256 } 248 257 -
commands.c
r117c21c r12505e3 656 656 "show subscriptions / show subs\n" 657 657 "show terminal\n" 658 "show timers\n"659 658 "show variables\n" 660 659 "show variable <variable>\n" … … 2234 2233 } else if (!strcmp(argv[1], "styles")) { 2235 2234 owl_function_show_styles(); 2236 } else if (!strcmp(argv[1], "timers")) {2237 owl_function_show_timers();2238 2235 } else if (!strcmp(argv[1], "subs") || !strcmp(argv[1], "subscriptions")) { 2239 2236 owl_function_getsubs(); -
configure.ac
r9d43dcc r12505e3 115 115 116 116 dnl Add CFLAGS and LIBS for glib-2.0 117 PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.1 2gobject-2.0 gthread-2.0])117 PKG_CHECK_MODULES(GLIB,[glib-2.0 >= 2.16 gobject-2.0 gthread-2.0]) 118 118 119 119 AC_MSG_NOTICE([Adding glib-2.0 CFLAGS ${GLIB_CFLAGS}]) -
functions.c
r259e60a8 rb9d22f7 92 92 owl_function_popless_fmtext(&fm); 93 93 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);124 94 owl_fmtext_cleanup(&fm); 125 95 } -
global.c
rf97c1a6 rc5c5686 105 105 106 106 owl_message_init_fmtext_cache(); 107 owl_list_create(&(g->io_dispatch_list));108 g->timerlist = NULL;109 107 g->kill_buffer = NULL; 110 108 … … 839 837 { 840 838 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);851 839 } 852 840 -
owl.c
rcc305b5 rbdc53e0 302 302 } 303 303 304 void owl_process_input(const owl_io_dispatch *d, void *data)304 gboolean owl_process_input(GIOChannel *source, GIOCondition condition, void *data) 305 305 { 306 owl_global *g = data; 306 307 owl_input j; 307 308 308 309 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; 311 312 312 313 j.uch = '\0'; … … 330 331 331 332 for (i = 1; i < bytes; i++) { 332 int tmp = wgetch(g .input_pad);333 int tmp = wgetch(g->input_pad); 333 334 /* If what we got was not a byte, or not a continuation byte */ 334 335 if (tmp > 0xff || !(tmp & 0x80 && ~tmp & 0x40)) { … … 357 358 owl_process_input_char(j); 358 359 } 360 return TRUE; 359 361 } 360 362 … … 448 450 449 451 /* Sends stderr (read from rfd) messages to the error console */ 450 void stderr_redirect_handler(const owl_io_dispatch *d, void *data)452 gboolean stderr_redirect_handler(GIOChannel *source, GIOCondition condition, void *data) 451 453 { 452 454 int navail, bread; 453 455 char buf[4096]; 454 int rfd = d->fd;456 int rfd = g_io_channel_unix_get_fd(source); 455 457 char *err; 456 458 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; 458 463 if (-1 == ioctl(rfd, FIONREAD, &navail)) { 459 return ;464 return TRUE; 460 465 } 461 466 /*owl_function_debugmsg("stderr_redirect: navail = %d\n", navail);*/ 462 if (navail <= 0) return ;467 if (navail <= 0) return TRUE; 463 468 if (navail > sizeof(buf)-1) { 464 469 navail = sizeof(buf)-1; … … 466 471 bread = read(rfd, buf, navail); 467 472 if (bread == -1) 468 return ;473 return TRUE; 469 474 470 475 err = g_strdup_printf("[stderr]\n%.*s", bread, buf); … … 472 477 owl_function_log_err(err); 473 478 g_free(err); 479 return TRUE; 474 480 } 475 481 … … 485 491 owl_options opts; 486 492 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; 490 494 491 495 argc_copy = argc; … … 513 517 514 518 /* 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); 516 522 owl_zephyr_initialize(); 517 523 … … 519 525 /* Do this only after we've started curses up... */ 520 526 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); 522 530 #endif 523 531 -
owl.h
r24a791f r12505e3 121 121 #define OWL_MESSAGE_DIRECTION_IN 1 122 122 #define OWL_MESSAGE_DIRECTION_OUT 2 123 124 #define OWL_IO_READ 1125 #define OWL_IO_WRITE 2126 #define OWL_IO_EXCEPT 4127 123 128 124 #define OWL_DIRECTION_NONE 0 … … 517 513 } owl_zbuddylist; 518 514 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 528 515 typedef struct _owl_errqueue { 529 516 owl_list errlist; … … 536 523 } owl_colorpair_mgr; 537 524 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 549 525 typedef struct _owl_popexec { 550 526 int refcount; … … 552 528 int winactive; 553 529 pid_t pid; /* or 0 if it has terminated */ 554 const owl_io_dispatch *dispatch;530 guint io_watch; 555 531 } owl_popexec; 556 532 … … 616 592 int pseudologin_notify; 617 593 struct termios startup_tio; 618 owl_list io_dispatch_list; 619 GList *timerlist; 620 owl_timer *aim_nop_timer; 594 guint aim_nop_timer; 621 595 int load_initial_subs; 622 596 FILE *debug_file; -
perl/lib/BarnOwl.pm
rf2d71cfa rf21bc36 29 29 use lib(get_config_dir() . "/lib"); 30 30 31 use Glib; 32 use AnyEvent; 33 31 34 use BarnOwl::Hook; 32 35 use BarnOwl::Hooks; … … 38 41 use BarnOwl::Completion; 39 42 use BarnOwl::Help; 40 use BarnOwl::AnyEvent;41 42 unshift @AnyEvent::REGISTRY, [BarnOwl => BarnOwl::AnyEvent::];43 require AnyEvent;44 43 45 44 use List::Util qw(max); … … 167 166 read from C<FD>. 168 167 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'>. 168 C<add_dispatch> has been deprecated in favor of C<AnyEvent>, and is 169 now a wrapper for C<add_io_dispatch> called with C<mode> set to 170 C<'r'>. 171 171 172 172 =cut … … 182 182 Remove a file descriptor previously registered via C<add_dispatch> 183 183 184 C<remove_dispatch> has been deprecated in favor of 185 C<remove_io_dispatch>. 184 C<remove_dispatch> has been deprecated in favor of C<AnyEvent>. 186 185 187 186 =cut … … 198 197 registered, the old one is removed. 199 198 200 =cut 199 C<add_io_dispatch> has been deprecated in favor of C<AnyEvent>. 200 201 =cut 202 203 our %_io_dispatches; 201 204 202 205 sub add_io_dispatch { … … 204 207 my $modeStr = shift; 205 208 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 } 213 220 } else { 214 221 die("Invalid I/O Dispatch mode: $modeStr"); … … 219 226 220 227 Remove a file descriptor previously registered via C<add_io_dispatch> 228 229 C<remove_io_dispatch> has been deprecated in favor of C<AnyEvent>. 230 231 =cut 232 233 sub remove_io_dispatch { 234 my $fd = shift; 235 undef $_ foreach @{$_io_dispatches{$fd}}; 236 delete $_io_dispatches{$fd}; 237 } 221 238 222 239 =head2 create_style NAME OBJECT -
perl/lib/BarnOwl/Complete/Client.pm
rc6adf17 rb9d22f7 37 37 subs => undef, 38 38 terminal => undef, 39 timers => undef,40 39 variables => undef, 41 40 variable => \&complete_variable, -
perl/lib/BarnOwl/Timer.pm
rc6adf17 r7df7be2 3 3 4 4 package BarnOwl::Timer; 5 6 use AnyEvent; 5 7 6 8 sub new { … … 13 15 my $self = {cb => $cb}; 14 16 15 my $name = $args->{name};16 $name = "(unnamed)" unless defined $name;17 18 17 bless($self, $class); 19 18 20 $self->{timer} = BarnOwl::Internal::add_timer($args->{after} || 0, 21 $args->{interval} || 0, 22 $self, 23 $name); 19 $self->{timer} = AnyEvent->timer(%$args); 24 20 return $self; 25 21 } … … 27 23 sub stop { 28 24 my $self = shift; 29 if(defined($self->{timer})) { 30 BarnOwl::Internal::remove_timer($self->{timer}); 31 undef $self->{timer}; 32 } 25 undef $self->{timer}; 33 26 } 34 27 -
perlconfig.c
r937a00e9 r12505e3 548 548 } 549 549 550 void owl_perlconfig_io_dispatch_destroy(const owl_io_dispatch *d)551 {552 SvREFCNT_dec(d->data);553 }554 555 550 void owl_perlconfig_edit_callback(owl_editwin *e) 556 551 { … … 587 582 SvREFCNT_dec(v); 588 583 } 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 326 326 g_free(rv); 327 327 328 void329 remove_io_dispatch(fd)330 int fd331 CODE:332 owl_select_remove_perl_io_dispatch(fd);333 334 328 AV* 335 329 all_filters() … … 507 501 ival); 508 502 509 void510 add_io_dispatch(fd, mode, cb)511 int fd512 int mode513 SV * cb514 CODE:515 owl_select_add_perl_io_dispatch(fd, mode, newSVsv(cb));516 517 IV518 add_timer(after, interval, cb, name = NULL)519 int after520 int interval521 SV *cb522 const char *name523 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 RETVAL538 539 void540 remove_timer(timer)541 IV timer542 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 549 503 MODULE = BarnOwl PACKAGE = BarnOwl::Editwin 550 504 -
popexec.c
r47e0a6a rc66ec48 16 16 int pipefds[2], child_write_fd, parent_read_fd; 17 17 pid_t pid; 18 GIOChannel *channel; 18 19 19 20 if (owl_global_get_popwin(&g) || owl_global_get_viewwin(&g)) { … … 54 55 pe->pid=pid; 55 56 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); 57 64 pe->refcount++; 58 65 } else { … … 75 82 } 76 83 77 void owl_popexec_inputhandler(const owl_io_dispatch *d, void *data)84 gboolean owl_popexec_inputhandler(GIOChannel *source, GIOCondition condition, void *data) 78 85 { 79 86 owl_popexec *pe = data; … … 81 88 char *buf; 82 89 int status; 90 int fd = g_io_channel_unix_get_fd(source); 83 91 84 if (!pe) return; 92 /* TODO: Reading from GIOChannel may be more convenient. */ 93 94 if (!pe) return FALSE; 85 95 86 96 /* If pe->winactive is 0 then the vwin has closed. … … 96 106 /* the viewwin has closed */ 97 107 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; 101 110 } 102 111 103 if (0 != (rv_navail = ioctl( d->fd, FIONREAD, &navail))) {112 if (0 != (rv_navail = ioctl(fd, FIONREAD, &navail))) { 104 113 owl_function_debugmsg("ioctl error"); 105 114 } … … 113 122 owl_viewwin_append_text(pe->vwin, "\n"); 114 123 } 115 owl_select_remove_io_dispatch(d); 116 pe->dispatch = NULL; 117 return; 124 pe->io_watch = 0; 125 return FALSE; 118 126 } 119 127 120 if ( d->fd<0 || !pe->pid || !pe->winactive || rv_navail) {128 if (fd<0 || !pe->pid || !pe->winactive || rv_navail) { 121 129 owl_function_error("popexec should not have reached this point"); 122 return ;130 return FALSE; 123 131 } 124 132 125 if (navail<=0) return ;133 if (navail<=0) return TRUE; 126 134 if (navail>1024) { navail = 1024; } 127 135 buf = g_new(char, navail+1); 128 136 owl_function_debugmsg("about to read %d", navail); 129 bread = read( d->fd, buf, navail);137 bread = read(fd, buf, navail); 130 138 if (bread<0) { 131 139 perror("read"); … … 140 148 } 141 149 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; 150 151 } 151 152 … … 156 157 157 158 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; 161 162 } 162 163 if (pe->pid) { -
select.c
rf0781ba r12505e3 2 2 3 3 static 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 cool49 * 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 cool73 * 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 cool90 * 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 NULL125 };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 list195 * 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_EXCEPT209 */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 NULL293 };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 have303 * 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 }334 4 335 5 void owl_select_init(void) 336 6 { 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);342 7 } 343 8 344 9 void owl_select_run_loop(void) 345 10 { 346 main_context = g_main_context_default(); 347 loop = g_main_loop_new(main_context, FALSE); 11 loop = g_main_loop_new(NULL, FALSE); 348 12 g_main_loop_run(loop); 349 13 } -
variable.c
r9efc154 r12505e3 504 504 int owl_variable_pseudologins_set(owl_variable *v, const void *newval) 505 505 { 506 static owl_timer *timer = NULL;506 static guint timer = 0; 507 507 if (newval) { 508 508 if (*(const int*)newval == 1) { 509 509 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); 513 512 } 514 513 } 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; 518 517 } 519 518 } -
zephyr.c
rb848e30 rc66ec48 48 48 struct sockaddr_in sin; 49 49 ZNotice_t req; 50 GIOChannel *channel; 50 51 51 52 /* … … 91 92 } 92 93 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 100 gboolean owl_zephyr_finish_initialization(GIOChannel *source, GIOCondition condition, void *data) { 97 101 Code_t code; 98 102 char *perl; 99 103 GSource *event_source; 100 104 101 owl_select_remove_io_dispatch(d);102 103 105 ZClosePort(); 104 106 105 107 if ((code = ZInitialize()) != ZERR_NONE) { 106 108 owl_function_error("Initializing Zephyr: %s", error_message(code)); 107 return ;109 return FALSE; 108 110 } 109 111 110 112 if ((code = ZOpenPort(NULL)) != ZERR_NONE) { 111 113 owl_function_error("Initializing Zephyr: %s", error_message(code)); 112 return ;114 return FALSE; 113 115 } 114 116 … … 143 145 perl = owl_perlconfig_execute("BarnOwl::Zephyr::_zephyr_startup()"); 144 146 g_free(perl); 147 return FALSE; 145 148 } 146 149 … … 1432 1435 #endif 1433 1436 1434 void owl_zephyr_buddycheck_timer(owl_timer *t,void *data)1437 gboolean owl_zephyr_buddycheck_timer(void *data) 1435 1438 { 1436 1439 if (owl_global_is_pseudologins(&g)) { … … 1440 1443 owl_function_debugmsg("Warning: owl_zephyr_buddycheck_timer call pointless; timer should have been disabled"); 1441 1444 } 1445 return TRUE; 1442 1446 } 1443 1447 … … 1510 1514 event_source = (owl_zephyr_event_source*) source; 1511 1515 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; 1513 1517 g_source_add_poll(source, &event_source->poll_fd); 1514 1518 -
barnowl
rde18326 rb14f8cb 7 7 EXE="$0.bin" 8 8 9 if ! test-x "$EXE"; then9 if test ! -x "$EXE"; then 10 10 echo "Cannot find barnowl.bin" >&2 11 11 exit 1 12 12 fi 13 13 14 export BARNOWL_DATA_DIR="$SRCDIR/perl/" 15 export BARNOWL_BIN_DIR="$SRCDIR/" 14 BARNOWL_DATA_DIR="$SRCDIR/perl/" 15 BARNOWL_BIN_DIR="$SRCDIR/" 16 export BARNOWL_DATA_DIR 17 export BARNOWL_BIN_DIR 16 18 exec "$EXE" "$@" -
cmd.c
r4c7c21f raad166a 5 5 #include "owl.h" 6 6 7 extern const owl_cmd commands_to_init[];8 9 7 /**************************************************************************/ 10 8 /***************************** COMMAND DICT *******************************/ … … 13 11 int owl_cmddict_setup(owl_cmddict *cd) { 14 12 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); 17 14 } 18 15 -
libfaim/aim.h
r63de71c rfe73d0c 18 18 19 19 #include "config.h" 20 #ifdef HAVE_STDBOOL_H21 20 #include <stdbool.h> 22 #else23 #ifndef HAVE__BOOL24 #define _Bool signed char25 #endif26 #define bool _Bool27 #define false 028 #define true 129 #define __bool_true_false_are_defined 130 #endif /* HAVE_STDBOOL_H */31 21 32 22 #include <stdio.h> -
scripts/locker-build
r0fd5bd5 r4f5e38f 102 102 esac 103 103 104 C FLAGS="-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" \ 106 106 ./configure --exec-prefix="/mit/barnowl/arch/$ATHENA_SYS" \ 107 107 --prefix="/mit/barnowl/builds/barnowl-$VERS" --mandir=/mit/barnowl/man \ -
tester.c
r4c7c21f r4e37d56 32 32 char *perlerr; 33 33 int status = 0; 34 SCREEN *screen; 34 35 35 36 if (argc <= 1) { … … 41 42 wnull = fopen("/dev/null", "w"); 42 43 rnull = fopen("/dev/null", "r"); 43 newterm("xterm", wnull, rnull);44 screen = newterm("xterm", wnull, rnull); 44 45 /* initialize global structures */ 45 46 owl_global_init(&g); … … 91 92 /* probably not necessary, but tear down the screen */ 92 93 endwin(); 94 delscreen(screen); 93 95 fclose(rnull); 94 96 fclose(wnull); … … 218 220 owl_string_appendf_quoted(g, "%q foo %q%q %s %", "hello", "world is", "can't"); 219 221 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); 222 224 223 225 /* if (numfailed) printf("*** WARNING: failures encountered with owl_util\n"); */ … … 230 232 owl_list l; 231 233 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"); 233 236 234 237 printf("# BEGIN testing owl_dict\n"); … … 259 262 owl_list_cleanup(&l, g_free); 260 263 owl_dict_cleanup(&d, NULL); 264 265 g_free(av); 266 g_free(bv); 267 g_free(cv); 268 g_free(dv); 261 269 262 270 /* if (numfailed) printf("*** WARNING: failures encountered with owl_dict\n"); */ -
window.h
r4cc49bc rfe73d0c 5 5 #include <glib-object.h> 6 6 7 #ifdef HAVE_STDBOOL_H8 7 #include <stdbool.h> 9 #else10 #ifndef HAVE__BOOL11 #define _Bool signed char12 #endif13 #define bool _Bool14 #define false 015 #define true 116 #define __bool_true_false_are_defined 117 #endif /* HAVE_STDBOOL_H */18 8 19 9 G_BEGIN_DECLS -
zcrypt.c
r3b8a563 r5b197f7 11 11 #include <unistd.h> 12 12 #include <sys/types.h> 13 #include <zephyr/zephyr.h>14 13 #include <glib.h> 15 14 #include <string.h>
Note: See TracChangeset
for help on using the changeset viewer.