Changeset b7bb454


Ignore:
Timestamp:
Dec 6, 2008, 5:39:49 PM (12 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
7ce4003
Parents:
3ea31b6
git-author:
Nelson Elhage <nelhage@mit.edu> (12/06/08 17:36:19)
git-committer:
Nelson Elhage <nelhage@mit.edu> (12/06/08 17:39:49)
Message:
Make owl_timer have a callback and integrate into the select() loop.

Soon we should add support for registering timers from perl, and then
we can eventually remove the perl mainloop hook.
Files:
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • Makefile.in

    r3381399 rb7bb454  
    2525     regex.c history.c view.c dict.c variable.c filterelement.c pair.c \
    2626     keypress.c keymap.c keybinding.c cmd.c context.c zcrypt.c \
    27      aim.c buddy.c buddylist.c timer.c style.c errqueue.c \
     27     aim.c buddy.c buddylist.c style.c errqueue.c \
    2828     zbuddylist.c muxevents.c popexec.c obarray.c select.c wcwidth.c \
    2929     glib_compat.c
  • aim.c

    r554a2b8 rb7bb454  
    130130}
    131131
     132void owl_aim_send_nop(owl_timer *t, void *data) {
     133    if(owl_global_is_doaimevents(&g)) {
     134        aim_session_t *sess = owl_global_get_aimsess(&g);
     135        aim_flap_nop(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS));
     136    }
     137}
     138
    132139
    133140int owl_aim_login(char *screenname, char *password)
     
    194201  owl_function_debugmsg("owl_aim_login: connecting");
    195202
     203  g.aim_nop_timer = owl_select_add_timer(30, 30, owl_aim_send_nop, NULL);
     204
    196205  return(0);
     206}
     207
     208void owl_aim_unset_ignorelogin(owl_timer *t, void *data) {      /* noproto */
     209    owl_global_unset_ignore_aimlogin(&g);
    197210}
    198211
     
    212225
    213226  /* start the ingorelogin timer */
    214   owl_timer_reset_newstart(owl_global_get_aim_login_timer(&g),
    215                            owl_global_get_aim_ignorelogin_timer(&g));
    216 
    217  
     227  owl_global_set_ignore_aimlogin(&g);
     228  owl_select_add_timer(owl_global_get_aim_ignorelogin_timer(&g),
     229                       0, owl_aim_unset_ignorelogin, NULL);
     230
    218231  /* aim_ssi_setpresence(owl_global_get_aimsess(&g), 0x00000400); */
    219232  /* aim_bos_setidle(owl_global_get_aimsess(&g), owl_global_get_bosconn(&g), 5000); */
     
    228241  owl_global_set_aimnologgedin(&g);
    229242  owl_global_set_no_doaimevents(&g);
     243  owl_select_remove_timer(g.aim_nop_timer);
    230244}
    231245
     
    246260  owl_global_set_aimnologgedin(&g);
    247261  owl_global_set_no_doaimevents(&g);
     262  owl_select_remove_timer(g.aim_nop_timer);
    248263}
    249264
     
    422437  tv.tv_usec = 0;
    423438  waitingconn = aim_select(aimsess, &tv, &selstat);
    424 
    425   if (owl_global_is_aimnop_time(&g)) {
    426     aim_flap_nop(aimsess, aim_getconn_type(aimsess, AIM_CONN_TYPE_BOS));
    427     owl_global_aimnop_sent(&g);
    428   }
    429439
    430440  if (selstat == -1) {
     
    23152325  if (owl_global_is_doaimevents(&g)) {
    23162326    owl_aim_process_events();
    2317 
    2318     if (owl_global_is_aimloggedin(&g)) {
    2319       if (owl_timer_is_expired(owl_global_get_aim_buddyinfo_timer(&g))) {
    2320         /* owl_buddylist_request_idletimes(owl_global_get_buddylist(&g)); */
    2321         owl_timer_reset(owl_global_get_aim_buddyinfo_timer(&g));
    2322       }
    2323     }
    23242327  }
    23252328}
  • buddylist.c

    r257a22f rb7bb454  
    5151
    5252    /* are we ingoring login messages for a while? */
    53     if (!owl_timer_is_expired(owl_global_get_aim_login_timer(&g))) return;
     53    if (owl_global_is_ignore_aimlogin(&g)) return;
    5454
    5555    /* if not, create the login message */
  • global.c

    r2b237308 rb7bb454  
    100100  g->aim_screenname_for_filters=NULL;
    101101  g->aim_loggedin=0;
    102   owl_timer_create_countdown(&(g->aim_noop_timer), 30);
    103   owl_timer_create_countdown(&(g->aim_ignorelogin_timer), 0);
    104   owl_timer_create_countdown(&(g->aim_buddyinfo_timer), 60);
    105102  owl_buddylist_init(&(g->buddylist));
    106    
     103
    107104  g->havezephyr=0;
    108105  g->haveaim=0;
     106  g->ignoreaimlogin=0;
    109107  owl_global_set_no_doaimevents(g);
    110108
     
    113111
    114112  owl_zbuddylist_create(&(g->zbuddies));
    115   owl_timer_create_countdown(&(g->zephyr_buddycheck_timer), 60*3);
    116113
    117114  owl_obarray_init(&(g->obarray));
     
    119116  owl_message_init_fmtext_cache();
    120117  owl_list_create(&(g->dispatchlist));
     118  g->timerlist = g_sequence_new(NULL);
    121119}
    122120
     
    814812}
    815813
    816 int owl_global_is_aimnop_time(owl_global *g)
    817 {
    818   if (owl_timer_is_expired(&(g->aim_noop_timer))) return(1);
    819   return(0);
    820 }
    821 
    822 void owl_global_aimnop_sent(owl_global *g)
    823 {
    824   owl_timer_reset(&(g->aim_noop_timer));
    825 }
    826 
    827 owl_timer *owl_global_get_aim_login_timer(owl_global *g)
    828 {
    829   return(&(g->aim_ignorelogin_timer));
    830 }
    831 
    832814/* message queue */
    833815
     
    902884}
    903885
     886void owl_global_set_ignore_aimlogin(owl_global *g)
     887{
     888    g->ignoreaimlogin = 1;
     889}
     890
     891void owl_global_unset_ignore_aimlogin(owl_global *g)
     892{
     893    g->ignoreaimlogin = 0;
     894}
     895
     896int owl_global_is_ignore_aimlogin(owl_global *g)
     897{
     898    return g->ignoreaimlogin;
     899}
     900
    904901void owl_global_set_havezephyr(owl_global *g)
    905902{
     
    911908  if (g->havezephyr) return(1);
    912909  return(0);
    913 }
    914 
    915 owl_timer *owl_global_get_aim_buddyinfo_timer(owl_global *g)
    916 {
    917   return(&(g->aim_buddyinfo_timer));
    918910}
    919911
     
    944936}
    945937
    946 owl_timer *owl_global_get_zephyr_buddycheck_timer(owl_global *g)
    947 {
    948   return(&(g->zephyr_buddycheck_timer));
    949 }
    950938
    951939owl_zbuddylist *owl_global_get_zephyr_buddylist(owl_global *g)
     
    968956  return &(g->dispatchlist);
    969957}
     958
     959GSequence *owl_global_get_timerlist(owl_global *g)
     960{
     961    return g->timerlist;
     962}
  • owl.c

    r6eaf35b rb7bb454  
    394394  nexttime=time(NULL);
    395395
     396
     397  owl_select_add_timer(180, 180, owl_zephyr_buddycheck_timer, NULL);
     398
     399  /* If we ever deprecate the mainloop hook, remove this. */
     400  owl_select_add_timer(0, 1, owl_perlconfig_mainloop, NULL);
     401
     402
    396403#ifdef HAVE_LIBZEPHYR
    397404  /* Check for any zephyrs that have come in while we've done init. */
     
    413420
    414421    followlast=owl_global_should_followlast(&g);
    415    
    416     owl_perlconfig_mainloop();
    417422
    418423    /* little hack */
     
    439444      if(owl_process_message(m))
    440445        newmsgs = 1;
    441     }
    442 
    443     /* is it time to check zbuddies? */
    444     if (owl_global_is_pseudologins(&g)) {
    445       if (owl_timer_is_expired(owl_global_get_zephyr_buddycheck_timer(&g))) {
    446         owl_function_debugmsg("Doing zephyr buddy check");
    447         owl_function_zephyr_buddy_check(1);
    448         owl_timer_reset(owl_global_get_zephyr_buddycheck_timer(&g));
    449       }
    450446    }
    451447
     
    780776
    781777#endif /* OWL_STDERR_REDIR */
     778
     779void owl_zephyr_buddycheck_timer(owl_timer *t, void *data)
     780{
     781    owl_function_debugmsg("Doing zephyr buddy check");
     782    owl_function_zephyr_buddy_check(1);
     783}
  • owl.h

    rde1c8a5 rb7bb454  
    505505
    506506typedef struct _owl_timer {
    507   int direction;
    508   time_t starttime;
    509   int start;
     507  time_t time;
     508  int interval;
     509  void (*callback)(struct _owl_timer *, void *);
     510  void *data;
    510511} owl_timer;
    511512
     
    583584  owl_timer aim_noop_timer;
    584585  owl_timer aim_ignorelogin_timer;
    585   owl_timer aim_buddyinfo_timer;
    586586  int aim_loggedin;         /* true if currently logged into AIM */
    587587  int aim_doprocessing;     /* true if we should process AIM events (like pending login) */
     
    594594  int havezephyr;
    595595  int haveaim;
     596  int ignoreaimlogin;
    596597  int got_err_signal;       /* 1 if we got an unexpected signal */
    597598  siginfo_t err_signal_info;
     
    601602  owl_obarray obarray;
    602603  owl_list dispatchlist;
     604  GSequence *timerlist;
     605  owl_timer *aim_nop_timer;
    603606} owl_global;
    604607
  • select.c

    r2f69081 rb7bb454  
    22
    33static const char fileIdent[] = "$Id: select.c 894 2008-01-17 07:13:44Z asedeno $";
     4
     5int _owl_select_timer_cmp(owl_timer *t1, owl_timer *t2, void *data) {
     6    return t1->time - t2->time;
     7}
     8
     9int _owl_select_timer_eq(owl_timer *t1, owl_timer *t2, void *data) {
     10    return t1 == t2;
     11}
     12
     13owl_timer *owl_select_add_timer(int after, int interval, void (*cb)(struct _owl_timer *, void *), void *data)
     14{
     15    owl_timer *t = owl_malloc(sizeof(owl_timer));
     16    GSequence *timers = owl_global_get_timerlist(&g);
     17
     18    t->time = time(NULL) + after;
     19    t->interval = interval;
     20    t->callback = cb;
     21    t->data = data;
     22
     23    g_sequence_insert_sorted(timers, t,
     24                             (GCompareDataFunc)_owl_select_timer_cmp, NULL);
     25    return t;
     26}
     27
     28void owl_select_remove_timer(owl_timer *t)
     29{
     30    GSequenceIter *it = g_sequence_search(owl_global_get_timerlist(&g),
     31                                          t, (GCompareDataFunc)_owl_select_timer_eq, NULL);
     32    if(!g_sequence_iter_is_end(it) &&
     33       g_sequence_get(it) == t) {
     34        owl_free(t);
     35        g_sequence_remove(it);
     36    }
     37}
     38
     39void owl_select_process_timers(struct timeval *timeout)
     40{
     41    time_t now = time(NULL);
     42    GSequenceIter *it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
     43
     44    while(!g_sequence_iter_is_end(it)) {
     45        owl_timer *t = g_sequence_get(it);
     46        int remove = 0;
     47
     48        if(t->time > now)
     49            break;
     50
     51        /* Reschedule if appropriate */
     52        if(t->interval > 0) {
     53            t->time = now + t->interval;
     54            g_sequence_sort_changed(it, (GCompareDataFunc)_owl_select_timer_cmp, NULL);
     55        } else {
     56            g_sequence_remove(it);
     57            remove = 1;
     58        }
     59
     60        /* Do the callback */
     61        t->callback(t, t->data);
     62
     63        if (remove) {
     64            owl_free(t);
     65        }
     66        it = g_sequence_get_begin_iter(owl_global_get_timerlist(&g));
     67    }
     68
     69    if(g_sequence_iter_is_end(it)) {
     70        timeout->tv_sec = 60;
     71    } else {
     72        owl_timer *t = g_sequence_get(it);
     73        timeout->tv_sec = t->time - now;
     74    }
     75
     76    timeout->tv_usec = 0;
     77}
    478
    579/* Returns the index of the dispatch for the file descriptor. */
     
    182256  struct timeval timeout;
    183257
    184   timeout.tv_sec = 1;
    185   timeout.tv_usec = 0;
     258  owl_select_process_timers(&timeout);
    186259
    187260  max_fd = owl_select_dispatch_prepare_fd_sets(&r, &e);
Note: See TracChangeset for help on using the changeset viewer.