Changeset 35

Show
Ignore:
Timestamp:
04/26/07 11:36:47 (2 years ago)
Author:
root
Message:

recompute_queues optimizations and some perl tidyup

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/op_server.pl

    r34 r35  
    15071507            my $contextoboton = $key; 
    15081508            if ( $contextoboton =~ m/\@/ ) { 
    1509                 (undef, $contextoboton) = split( /\@/, $contextoboton, 2 ); 
     1509                ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15101510                $contextoboton =~ tr/a-z/A-Z/; 
    15111511            } 
     
    15251525            my $contextoboton = $key; 
    15261526            if ( $contextoboton =~ m/\@/ ) { 
    1527                 (undef, $contextoboton) = split( /\@/, $contextoboton, 2 ); 
     1527                ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15281528                $contextoboton =~ tr/a-z/A-Z/; 
    15291529            } 
     
    15621562                my $contextoboton = $key; 
    15631563                if ( $contextoboton =~ m/\@/ ) { 
    1564                     (undef, $contextoboton) = split( /\@/, $contextoboton, 2 ); 
     1564                    ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15651565                    $contextoboton =~ tr/a-z/A-Z/; 
    15661566                } 
     
    15811581                my $contextoboton = $key; 
    15821582                if ( $contextoboton =~ m/\@/ ) { 
    1583                     (undef, $contextoboton) = split( /\@/, $contextoboton, 2 ); 
     1583                    ( undef, $contextoboton ) = split( /\@/, $contextoboton, 2 ); 
    15841584                    $contextoboton =~ tr/a-z/A-Z/; 
    15851585                } 
     
    18691869    } 
    18701870    if ( $elemento =~ /^(?i:mISDN)(?!.*XXXY)/ ) { 
    1871             $elemento .= "-XXXY"; 
     1871        $elemento .= "-XXXY"; 
    18721872    } 
    18731873    elsif ( $elemento =~ /^SRX/i ) { 
     
    19161916sub erase_instances_for_trunk_buttons { 
    19171917 
    1918     my $canalid          = shift; 
    1919     my $canal            = shift; 
    1920     my $server           = shift; 
     1918    my $canalid = shift; 
     1919    my $canal   = shift; 
     1920    my $server  = shift; 
    19211921    my $canalglobal; 
    19221922    my $heading = "** ERASE_INSTANCE_TRUNK"; 
     
    19251925    $solocanal =~ s/[^\w]//g; 
    19261926 
    1927     $canalid          = "$server^$canalid"; 
     1927    $canalid = "$server^$canalid"; 
    19281928    $canalid =~ s/(.*)<(.*)>/$1/g;    #discards ZOMBIE or MASQ 
    19291929 
     
    19461946        $canalid = $server . "^" . $canal . "-" . $solocanal; 
    19471947    } 
    1948        foreach my $key1 ( keys(%instancias) ) { 
     1948    foreach my $key1 ( keys(%instancias) ) { 
    19491949        delete $instancias{$key1}{$canalid}; 
    19501950        log_debug( "$heading Erasing $canalid from instanacias!", 128 ) if DEBUG; 
     
    23172317 
    23182318    my $uniqueid = find_uniqueid( $canalsesion, $server ); 
    2319     if ( $uniqueid ) { 
     2319    if ($uniqueid) { 
    23202320        if ( defined( $datos{$uniqueid}{CallerID} ) ) { 
    23212321            $calleridnum = $datos{$uniqueid}{CallerID}; 
     
    33903390                # in op_buttons.cfg. 
    33913391                $canal = $extension_transfer_reverse{$ext_transf_key}; 
    3392                 ($canal, undef) = split( /&/, $canal); 
     3392                ( $canal, undef ) = split( /&/, $canal ); 
    33933393                if ( $canal =~ /\^/ ) { 
    3394                     (undef, $canal) = split( /\^/, $canal ); 
     3394                    ( undef, $canal ) = split( /\^/, $canal ); 
    33953395                } 
    33963396            } 
     
    51975197 
    51985198    my $cuantos = $#return + 1; 
    5199        if (DEBUG) { 
     5199    if (DEBUG) { 
    52005200        log_debug( "$heading returns $cuantos", 16 ); 
    52015201        log_debug( "$heading END SUB returns $_", 32 ) foreach (@return); 
     
    56985698                                            "$heading Y es distinto al ultimo estado $laststatus{$interno} ne $estadoboton{$interno}", 256 ) 
    56995699                                          if DEBUG; 
    5700                                     }  
     5700                                    } 
    57015701 
    57025702                                    # Conserva el callerid anterior 
     
    60386038                                        if ( $quehace2 ne "" ) { 
    60396039                                            push @respuestas, "$interno|$quehace2|$dos"; 
    6040                                                log_debug( "$heading pushing respuestas $interno|$quehace2|$dos", 256 ) if DEBUG; 
    6041                                         }  
     6040                                            log_debug( "$heading pushing respuestas $interno|$quehace2|$dos", 256 ) if DEBUG; 
     6041                                        } 
    60426042                                    } 
    60436043                                } 
     
    60546054                            } 
    60556055                            if ( $quehace2 eq "settimer" ) { 
    6056                                 my $tiempo = $dos; 
    6057                                 my $timer_type   = ""; 
     6056                                my $tiempo     = $dos; 
     6057                                my $timer_type = ""; 
    60586058                                if ( $tiempo =~ /\@/ ) { 
    60596059                                    ( $tiempo, $timer_type ) = split( /\@/, $tiempo ); 
     
    69476947    $elementname =~ s/\d//g; 
    69486948 
    6949     if ( $datosflash =~ /_level0\.casilla/ ) { 
    6950         $datosflash =~ s/_level0\.casilla(\d+)/$1/g; 
    6951     } 
    6952     if ( $datosflash =~ /_level0\.rectangulo/ ) { 
    6953         $datosflash =~ s/_level0\.rectangulo(\d+).*/$1/g; 
    6954     } 
     6949    $datosflash =~ s/_level0\.casilla(\d+)/$1/g; 
     6950    $datosflash =~ s/_level0\.rectangulo(\d+).*/$1/g; 
    69556951 
    69566952    log_debug( "$heading datosflash before context $datosflash", 128 ) if DEBUG; 
     
    86248620    if ( $encriptado =~ /key\|0/ ) { 
    86258621        $but_no = '0'; 
    8626         $encriptado =~ m/(.*)\|(.*)\|(.*)/; 
    8627         $cmd  = $2; 
    8628         $data = $1; 
    8629  
     8622        ( $data, $cmd ) = split( /\|/, $encriptado ); 
    86308623    } 
    86318624    else { 
    86328625        $but_no = $status; 
    8633         $but_no =~ s/(\d+)(.*)\|(.*)/$1/g; 
     8626        $but_no =~ s/(\d+).*\|.*/$1/g; 
    86348627        $contexto = $status; 
    86358628        $contexto =~ s/([^\|]*).*/$1/g; 
    8636         $contexto =~ m/(.*)\@(.*)/; 
    8637  
    8638         if ( defined($2) ) { 
    8639             $contexto = $2; 
    8640         } 
    8641         else { 
    8642             $contexto = ""; 
    8643         } 
    8644         $status =~ m/(.*)\|(.*)\|(.*)/; 
    8645         $cmd  = $2; 
    8646         $data = $3; 
     8629        $contexto =~ m/.*\@(.*)/; 
     8630        $contexto = $1 ? $1 : ""; 
     8631        ( undef, $cmd, $data ) = split( /\|/, $status ); 
    86478632 
    86488633        if ( $contexto ne "" && $cmd ne "restrict" ) { 
     
    87538738} 
    87548739 
     8740sub construct_cmd { 
     8741    my $cola    = shift; 
     8742    my $canalid = shift; 
     8743    return $cola->{$canalid}{QUEUE} . "=" 
     8744      . $cola->{$canalid}{POSITION} 
     8745      . "|$_[0]|$_[1]|" 
     8746      . $cola->{$canalid}{QUEUE} . "-" 
     8747      . $cola->{$canalid}{SERVER} 
     8748      . "|$canalid"; 
     8749} 
     8750 
    87558751sub recompute_queues { 
    87568752    my $canalid = shift; 
    8757     my @return_corto; 
    8758     my @return_ocupado; 
     8753    my @corto; 
     8754    my @ocupado; 
    87598755    my $maxtime = 0; 
     8756    my $save_id; 
     8757    my $time = time(); 
    87608758 
    87618759    #print_recomputequeues(); 
     
    87708768 
    87718769    if ( $queue_hide == 1 ) { 
    8772         push @return_corto, 
    8773           $cola->{$canalid}{QUEUE} . "=" 
    8774           . $cola->{$canalid}{POSITION} 
    8775           . "|setalpha|000|" 
    8776           . $cola->{$canalid}{QUEUE} . "-" 
    8777           . $cola->{$canalid}{SERVER} 
    8778           . "|$canalid"; 
    8779     } 
    8780     push @return_corto, 
    8781       $cola->{$canalid}{QUEUE} . "=" 
    8782       . $cola->{$canalid}{POSITION} 
    8783       . "|corto||" 
    8784       . $cola->{$canalid}{QUEUE} . "-" 
    8785       . $cola->{$canalid}{SERVER} 
    8786       . "|$canalid"; 
     8770        push @corto, construct_cmd( $cola, $canalid, "setalpha", "000" ); 
     8771    } 
     8772    push @corto, construct_cmd( $cola, $canalid, "corto", "" ); 
     8773 
    87878774    delete $cola->{$canalid}; 
    8788     my $save_id; 
    87898775 
    87908776    foreach my $id ( keys %{$cola} ) { 
    8791         if ( !defined( $cola->{$id}{QUEUE} ) ) { 
     8777        unless ( $cola->{$id}{QUEUE} ) { 
    87928778            delete( $cola->{$id} ); 
    87938779            next; 
    87948780        } 
    87958781 
    8796         #foreach ( keys %{ $cola->{$id} } ) { 
    8797         #    print "key de cola $_\n"; 
    8798         #} 
    87998782        if ( $queue_to_recompute eq $cola->{$id}{QUEUE} ) { 
    88008783            $save_id = $id; 
    8801             my $diftime = time() - $cola->{$id}{TIME}; 
     8784            my $diftime = $time - $cola->{$id}{TIME}; 
    88028785            if ( $diftime > $maxtime ) { 
    88038786                $maxtime = $diftime; 
     
    88078790                my $clidtext = $cola->{$id}{CLIDNAME} . " " . $cola->{$id}{CLID}; 
    88088791                if ( $queue_hide == 1 ) { 
    8809                     push @return_corto, 
    8810                       $cola->{$id}{QUEUE} . "=" 
    8811                       . $cola->{$id}{POSITION} 
    8812                       . "|setalpha|000|" 
    8813                       . $cola->{$id}{QUEUE} . "-" 
    8814                       . $cola->{$id}{SERVER} . "|$id"; 
    8815                 } 
    8816                 push @return_corto, 
    8817                   $cola->{$id}{QUEUE} . "=" 
    8818                   . $cola->{$id}{POSITION} 
    8819                   . "|corto||" 
    8820                   . $cola->{$id}{QUEUE} . "-" 
    8821                   . $cola->{$id}{SERVER} . "|$id"; 
     8792                    push @corto, construct_cmd( $cola, $id, "setalpha", "000" ); 
     8793                } 
     8794                push @corto, construct_cmd( $cola, $id, "corto", "" ); 
    88228795                $cola->{$id}{POSITION}--; 
    8823                 push @return_ocupado, 
    8824                   $cola->{$id}{QUEUE} . "=" 
    8825                   . $cola->{$id}{POSITION} 
    8826                   . "|settimer|$diftime|" 
    8827                   . $cola->{$id}{QUEUE} . "-" 
    8828                   . $cola->{$id}{SERVER} . "|$id"; 
    8829                 push @return_ocupado, 
    8830                   $cola->{$id}{QUEUE} . "=" 
    8831                   . $cola->{$id}{POSITION} 
    8832                   . "|ocupado|[$clidtext]|" 
    8833                   . $cola->{$id}{QUEUE} . "-" 
    8834                   . $cola->{$id}{SERVER} . "|$id"; 
    8835                 push @return_ocupado, $cola->{$id}{QUEUE} . "|ocupado|[$clidtext]|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
    8836                 push @return_ocupado, 
    8837                   $cola->{$id}{QUEUE} . "|settimer|0\@STOP|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
     8796                push @ocupado, construct_cmd( $cola, $id, "settimer", $diftime ); 
     8797                push @ocupado, construct_cmd( $cola, $id, "ocupado",  "[$clidtext]" ); 
     8798                push @ocupado, $cola->{$id}{QUEUE} . "|ocupado|[$clidtext]|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
     8799                push @ocupado, $cola->{$id}{QUEUE} . "|settimer|0\@STOP|" . $cola->{$id}{QUEUE} . "-" . $cola->{$id}{SERVER} . "|$id"; 
    88388800            } 
    88398801        } 
    88408802    } 
    88418803    if ( defined($save_id) ) { 
    8842         push @return_ocupado, 
     8804        push @ocupado, 
    88438805          $cola->{$save_id}{QUEUE} . "|settimer|$maxtime\@UP|" . $cola->{$save_id}{QUEUE} . "-" . $cola->{$save_id}{SERVER} . "|$save_id"; 
    88448806    } 
     
    88488810 
    88498811    delete $cola->{$canalid}; 
    8850     @return_ocupado = unique(@return_ocupado); 
    8851  
    8852     if (@return_corto) { 
    8853         my @todos = (); 
    8854         push @todos, @return_corto; 
    8855         push @todos, @return_ocupado; 
    8856         return @todos; 
    8857     } 
    8858  
    8859     # TEST|corto|&waitingonqueue,0,&|TEST-0|SIP/16-ea0c 
     8812    @ocupado = unique(@ocupado); 
     8813 
     8814    if (@corto) { 
     8815        return ( @corto, @ocupado ); 
     8816    } 
     8817 
    88608818} 
    88618819