Changeset 7f792c1


Ignore:
Timestamp:
Jan 22, 2007, 12:20:17 AM (14 years ago)
Author:
Alejandro R. Sedeño <asedeno@mit.edu>
Branches:
master, barnowl_perlaim, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
6837096
Parents:
585bdc3
Message:
* Added idle-time tracking in C.
* Exposed idle-time tracking to perl.
* Updated jabber.pl to set away after 5 minutes, xa after 15 minutes.
* Flipped around the jabber connection manager's hash to index by jid first.
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • global.c

    r8fa9562 r7f792c1  
    6969  g->searchstring=NULL;
    7070  g->starttime=time(NULL); /* assumes we call init only a start time */
     71  g->lastinputtime=g->starttime;
    7172  g->newmsgproc_pid=0;
    7273 
     
    438439}
    439440
     441time_t owl_global_get_lastinputtime(owl_global *g) {
     442  return(g->lastinputtime);
     443}
     444
     445void owl_global_update_lastinputtime(owl_global *g) {
     446  g->lastinputtime = time(NULL);
     447}
     448
     449time_t owl_global_get_idletime(owl_global *g) {
     450  return(time(NULL)-g->lastinputtime);
     451}
     452
    440453void owl_global_get_runtime_string(owl_global *g, char *buff) {
    441454  time_t diff;
  • owl.c

    r8fa9562 r7f792c1  
    661661      usleep(10);
    662662    } else {
     663      owl_global_update_lastinputtime(&g);
    663664      /* find and activate the current keymap.
    664665       * TODO: this should really get fixed by activating
  • owl.h

    r8fa9562 r7f792c1  
    557557  void *perl;
    558558  int debug;
    559   int starttime;
     559  time_t starttime;
     560  time_t lastinputtime;
    560561  char *startupargs;
    561562  int userclue;
  • perl/modules/jabber.pl

    r575877f r7f792c1  
    132132    my $client = BarnOwl::Jabber::Connection->new;
    133133
    134     $self->{Client}->{$jidStr} = $client;
    135     $self->{Roster}->{$jidStr} = $client->Roster();
     134    $self->{$jidStr}->{Client} = $client;
     135    $self->{$jidStr}->{Roster} = $client->Roster();
     136    $self->{$jidStr}->{Status} = "available";
    136137    return $client;
    137138}
     
    140141    my $self = shift;
    141142    my $jidStr = shift;
    142     return 0 unless exists $self->{Client}->{$jidStr};
    143 
    144     $self->{Client}->{$jidStr}->Disconnect();
    145     delete $self->{Roster}->{$jidStr};
    146     delete $self->{Client}->{$jidStr};
     143    return 0 unless exists $self->{$jidStr}->{Client};
     144
     145    $self->{$jidStr}->{Client}->Disconnect();
     146    delete $self->{$jidStr};
    147147
    148148    return 1;
     
    151151sub connected {
    152152    my $self = shift;
    153     return scalar keys %{ $self->{Client} };
     153    return scalar keys %{ $self };
    154154}
    155155
    156156sub getJids {
    157157    my $self = shift;
    158     return keys %{ $self->{Client} };
     158    return keys %{ $self };
    159159}
    160160
     
    162162    my $self = shift;
    163163    my $jidStr = shift;
    164     return exists $self->{Client}->{$jidStr};
     164    return exists $self->{$jidStr};
    165165}
    166166
     
    168168    my $self = shift;
    169169    my $sid = shift || "";
    170     foreach my $j ( keys %{ $self->{Client} } ) {
    171         return 1 if ($self->{Client}->{$j}->{SESSION}->{id} eq $sid);
     170    foreach my $c ( values %{ $self } ) {
     171        return 1 if ($c->{Client}->{SESSION}->{id} eq $sid);
    172172    }
    173173    return 0;
     
    177177    my $self = shift;
    178178    my $sid = shift;
    179     foreach my $c (values %{ $self->{Client} }) {
    180         return $c if $c->{SESSION}->{id} eq $sid;
     179    foreach my $c (values %{ $self }) {
     180        return $c->{Client} if $c->{Client}->{SESSION}->{id} eq $sid;
    181181    }
    182182    return undef;
     
    186186    my $self = shift;
    187187    my $jidStr = shift;
    188     return $self->{Client}->{$jidStr};
     188    return $self->{$jidStr}->{Client};
    189189}
    190190
     
    192192    my $self = shift;
    193193    my $sid = shift;
    194     foreach my $j ( $self->getJids ) {
    195         return $self->{Roster}->{$j}
    196           if $self->{Client}->{$j}->{SESSION}->{id} eq $sid;
     194    foreach my $c (values %{ $self }) {
     195        return $c->{Roster}
     196          if $c->{Client}->{SESSION}->{id} eq $sid;
    197197    }
    198198    return undef;
     
    202202    my $self = shift;
    203203    my $jidStr = shift;
    204     return $self->{Roster}->{$jidStr};
    205     return undef;
     204    return $self->{$jidStr}->{Roster};
    206205}
    207206################################################################################
     
    217216        push @::onMainLoop,     sub { BarnOwl::Jabber::onMainLoop(@_) };
    218217        push @::onGetBuddyList, sub { BarnOwl::Jabber::onGetBuddyList(@_) };
     218        $vars{show} = '';
    219219    } else {
    220220        # Our owl doesn't support queue_message. Unfortunately, this
     
    229229    return if ( !$conn->connected() );
    230230
     231    $vars{status_changed} = 0;
     232    my $idletime = owl::getidletime();
     233    if ($idletime >= 900 && $vars{show} eq 'away') {
     234        $vars{show} = 'xa';
     235        $vars{status} = 'Auto extended-away after 15 minutes idle.';
     236        $vars{status_changed} = 1;
     237    } elsif ($idletime >= 300 && $vars{show} eq '') {
     238        $vars{show} = 'away';
     239        $vars{status} = 'Auto away after 5 minutes idle.';
     240        $vars{status_changed} = 1;
     241    } elsif ($idletime == 0 && $vars{show} ne '') {
     242        $vars{show} = '';
     243        $vars{status} = '';
     244        $vars{status_changed} = 1;
     245    }
     246
    231247    foreach my $jid ( $conn->getJids() ) {
    232248        my $client = $conn->getConnectionFromJidStr($jid);
     
    240256            do_logout($jid);
    241257            return;
     258        }
     259        if ($vars{status_changed}) {
     260            my $p = new Net::XMPP::Presence;
     261            $p->SetShow($vars{show}) if $vars{show};
     262            $p->SetStatus($vars{status}) if $vars{status};
     263            $client->Send($p);
    242264        }
    243265    }
  • perlglue.xs

    r8203afd r7f792c1  
    3737        CODE:
    3838                RETVAL = owl_global_get_cols(&g);
     39        OUTPUT:
     40                RETVAL
     41               
     42time_t
     43getidletime()
     44        CODE:
     45                RETVAL = owl_global_get_idletime(&g);
    3946        OUTPUT:
    4047                RETVAL
Note: See TracChangeset for help on using the changeset viewer.