Changeset ffc4df6
- Timestamp:
- Oct 27, 2009, 12:41:17 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 18fdd5f9
- Parents:
- df0138f
- git-author:
- Alejandro R. Sedeño <asedeno@mit.edu> (10/24/09 14:56:01)
- git-committer:
- Alejandro R. Sedeño <asedeno@mit.edu> (10/27/09 00:41:17)
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl.pm
r3c428d4 rffc4df6 13 13 error debug 14 14 create_style getnumcolors wordwrap 15 add_dispath remove_dispatch 15 add_dispatch remove_dispatch 16 add_io_dispatch remove_io_dispatch 16 17 new_command 17 18 new_variable_int new_variable_bool new_variable_string … … 62 63 Returns the current message as a C<BarnOwl::Message> subclass, or 63 64 undef if there is no message selected 64 65 65 =head2 getnumcols 66 66 … … 160 160 read from C<FD>. 161 161 162 C<add_dispatch> has been deprecated in favor of C<add_io_dispatch>, 163 and is now a wrapper for it called with C<mode> set to C<'r'>. 164 165 =cut 166 167 sub add_dispatch { 168 my $fd = shift; 169 my $cb = shift; 170 add_io_dispatch($fd, 'r', $cb); 171 } 172 162 173 =head2 remove_dispatch FD 163 174 164 175 Remove a file descriptor previously registered via C<add_dispatch> 176 177 C<remove_dispatch> has been deprecated in favor of 178 C<remove_io_dispatch>. 179 180 =cut 181 182 *remove_dispatch = \&remove_io_dispatch; 183 184 =head2 add_io_dispatch FD MODE CB 185 186 Adds a file descriptor to C<BarnOwl>'s internal C<select()> 187 loop. <MODE> can be 'r', 'w', or 'rw'. C<CALLBACK> will be invoked 188 whenever C<FD> becomes ready, as specified by <MODE>. 189 190 Only one callback can be registered per FD. If a new callback is 191 registered, the old one is removed. 192 193 =cut 194 195 sub add_io_dispatch { 196 my $fd = shift; 197 my $modeStr = shift; 198 my $cb = shift; 199 my $mode = 0; 200 201 $mode |= 0x1 if ($modeStr =~ /r/i); # Read 202 $mode |= 0x2 if ($modeStr =~ /w/i); # Write 203 if ($mode) { 204 $mode |= 0x4; # Exceptional 205 BarnOwl::Internal::add_io_dispatch($fd, $mode, $cb); 206 } else { 207 die("Invalid I/O Dispatch mode: $modeStr"); 208 } 209 } 210 211 =head2 remove_io_dispatch FD 212 213 Remove a file descriptor previously registered via C<add_io_dispatch> 165 214 166 215 =head2 create_style NAME OBJECT -
perlconfig.c
rdf0138f rffc4df6 504 504 } 505 505 506 void owl_perlconfig_dispatch_free(owl_dispatch *d)507 {508 SvREFCNT_dec(d->data);509 owl_free(d);510 }511 512 506 void owl_perlconfig_io_dispatch_destroy(const owl_io_dispatch *d) 513 507 { … … 560 554 } 561 555 562 void owl_perlconfig_dispatch(owl_dispatch *d)563 {564 SV *cb = d->data;565 dSP;566 if(cb == NULL) {567 owl_function_error("Perl callback is NULL!");568 return;569 }570 571 ENTER;572 SAVETMPS;573 574 PUSHMARK(SP);575 PUTBACK;576 577 call_sv(cb, G_DISCARD|G_KEEPERR|G_EVAL);578 579 if(SvTRUE(ERRSV)) {580 owl_function_error("%s", SvPV_nolen(ERRSV));581 }582 583 FREETMPS;584 LEAVE;585 }586 587 556 void owl_perlconfig_io_dispatch(const owl_io_dispatch *d, void *data) 588 557 { -
perlglue.xs
rbdbec0a rffc4df6 318 318 319 319 void 320 add_dispatch(fd, cb)320 remove_io_dispatch(fd) 321 321 int fd 322 SV * cb 323 CODE: 324 owl_select_add_perl_dispatch(fd, SvREFCNT_inc(cb)); 325 326 void 327 remove_dispatch(fd) 328 int fd 329 CODE: 330 owl_select_remove_perl_dispatch(fd); 331 322 CODE: 323 owl_select_remove_perl_io_dispatch(fd); 332 324 333 325 AV* … … 509 501 ival); 510 502 503 void 504 add_io_dispatch(fd, mode, cb) 505 int fd 506 int mode 507 SV * cb 508 CODE: 509 owl_select_add_perl_io_dispatch(fd, mode, SvREFCNT_inc(cb)); 510 511 511 IV 512 512 add_timer(after, interval, cb) -
select.c
rdf0138f rffc4df6 156 156 { 157 157 return owl_list_get_size(owl_global_get_dispatchlist(&g)); 158 }159 160 int owl_select_add_perl_dispatch(int fd, SV *cb)161 {162 int elt;163 owl_dispatch *d;164 elt = owl_select_find_dispatch(fd);165 if (elt != -1) {166 d = owl_list_get_element(owl_global_get_dispatchlist(&g), elt);167 if (d->cfunc != owl_perlconfig_dispatch) {168 /* don't mess with non-perl dispatch functions from here. */169 return 1;170 }171 }172 173 d = owl_malloc(sizeof(owl_dispatch));174 d->fd = fd;175 d->cfunc = owl_perlconfig_dispatch;176 d->destroy = owl_perlconfig_dispatch_free;177 d->data = cb;178 owl_select_add_dispatch(d);179 return 0;180 }181 182 int owl_select_remove_perl_dispatch(int fd)183 {184 int elt;185 owl_dispatch *d;186 187 elt = owl_select_find_dispatch(fd);188 if (elt != -1) {189 d = owl_list_get_element(owl_global_get_dispatchlist(&g), elt);190 if (d->cfunc == owl_perlconfig_dispatch) {191 owl_select_remove_dispatch_at(elt);192 return 0;193 }194 }195 return 1;196 158 } 197 159
Note: See TracChangeset
for help on using the changeset viewer.