Show
Ignore:
Timestamp:
01/28/07 09:36:11 (17 years ago)
Author:
pieterpalmers
Message:

mostly whitespace fixes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/streaming-rework/tests/test-sytmonitor.cpp

    r360 r383  
    11/*************************************************************************** 
    2   Copyright (C) 2005 by Pieter Palmers   * 
     2Copyright (C) 2005 by Pieter Palmers   * 
    33                                                                        * 
    4   This program is free software; you can redistribute it and/or modify  * 
    5   it under the terms of the GNU General Public License as published by  * 
    6   the Free Software Foundation; either version 2 of the License, or     * 
    7   (at your option) any later version.                                   * 
     4This program is free software; you can redistribute it and/or modify  * 
     5it under the terms of the GNU General Public License as published by  * 
     6the Free Software Foundation; either version 2 of the License, or     * 
     7(at your option) any later version.                                   * 
    88                                                                        * 
    9   This program is distributed in the hope that it will be useful,       * 
    10   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
    11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
    12   GNU General Public License for more details.                          * 
     9This program is distributed in the hope that it will be useful,       * 
     10but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
     11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         * 
     12GNU General Public License for more details.                          * 
    1313                                                                        * 
    14   You should have received a copy of the GNU General Public License     * 
    15   along with this program; if not, write to the                         * 
    16   Free Software Foundation, Inc.,                                       * 
    17   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
    18  ***************************************************************************/ 
     14You should have received a copy of the GNU General Public License     * 
     15along with this program; if not, write to the                         * 
     16Free Software Foundation, Inc.,                                       * 
     1759 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             * 
     18***************************************************************************/ 
    1919 
    2020#ifdef HAVE_CONFIG_H 
     
    9292 
    9393    switch (key) { 
    94        case 'p': 
    95            if (arg) { 
     94        case 'p': 
     95            if (arg) { 
    9696            arguments->port = strtol( arg, &tail, 0 ); 
    9797            if ( errno ) { 
     
    9999                return ARGP_ERR_UNKNOWN; 
    100100            } 
    101            } else { 
     101            } else { 
    102102            if ( errno ) { 
    103103                fprintf( stderr, "Could not parse 'port' argumen\n" ); 
    104104                return ARGP_ERR_UNKNOWN; 
    105105            } 
    106            } 
    107            break; 
    108        case 'R': 
     106            } 
     107            break; 
     108        case 'R': 
    109109        arguments->realtime = true; 
    110            break;          
    111        case 'r': 
    112            if (arg) { 
     110            break;         
     111        case 'r': 
     112            if (arg) { 
    113113            arguments->rtprio = strtol( arg, &tail, 0 ); 
    114114            if ( errno ) { 
     
    116116                return ARGP_ERR_UNKNOWN; 
    117117            } 
    118            } 
    119            break;                  
    120        case ARGP_KEY_ARG: 
    121            if (state->arg_num >= 128) { 
     118            } 
     119            break;                 
     120        case ARGP_KEY_ARG: 
     121            if (state->arg_num >= 128) { 
    122122            // Too many arguments. 
    123123            argp_usage( state ); 
    124            } 
    125             
    126            if(sscanf( arg, "%d,%d",  
    127               &arguments->args[state->arg_num].port,  
    128               &arguments->args[state->arg_num].channel) != 2) { 
    129            fprintf( stderr,  "Could not parse port-channel specification ('%s')\n", arg); 
    130                
    131            } else { 
     124            } 
     125             
     126            if(sscanf( arg, "%d,%d",  
     127            &arguments->args[state->arg_num].port,  
     128            &arguments->args[state->arg_num].channel) != 2) { 
     129        fprintf( stderr,  "Could not parse port-channel specification ('%s')\n", arg); 
     130             
     131            } else { 
    132132            printf("Adding Port %d, Channel %d to list...\n", 
    133                arguments->args[state->arg_num].port, 
    134                arguments->args[state->arg_num].channel); 
    135               arguments->nb_combos++; 
    136            } 
    137            break; 
    138        case ARGP_KEY_END: 
    139            if (state->arg_num < 1) { 
     133            arguments->args[state->arg_num].port, 
     134            arguments->args[state->arg_num].channel); 
     135            arguments->nb_combos++; 
     136            } 
     137            break; 
     138        case ARGP_KEY_END: 
     139            if (state->arg_num < 1) { 
    140140            // Not enough arguments. 
    141141            argp_usage( state ); 
    142            } 
    143            break; 
    144        default: 
    145            return ARGP_ERR_UNKNOWN; 
     142            } 
     143            break; 
     144        default: 
     145            return ARGP_ERR_UNKNOWN; 
    146146    } 
    147147    return 0; 
     
    154154static void sighandler (int sig) 
    155155{ 
    156        run = 0; 
     156        run = 0; 
    157157} 
    158158 
     
    162162        int target_channel_1=0; 
    163163        int target_channel_2=0; 
    164        bool run_realtime=false; 
    165        int realtime_prio=20; 
    166        int nb_iter; 
    167        int i; 
    168        struct sched_param params; 
    169          
    170        IsoHandlerManager *m_isoManager=NULL; 
     164    bool run_realtime=false; 
     165    int realtime_prio=20; 
     166    int nb_iter; 
     167    int i; 
     168    struct sched_param params; 
     169     
     170    IsoHandlerManager *m_isoManager=NULL; 
    171171    PosixThread * m_isoManagerThread=NULL; 
    172172     
    173173    SytMonitor *monitors[128]; 
    174174    int stream_offset_ticks[128]; 
    175         
     175     
    176176    struct arguments arguments; 
    177177 
     
    193193     
    194194     
    195        run=1; 
    196          
    197        run_realtime=arguments.realtime; 
    198        realtime_prio=arguments.rtprio; 
    199  
    200        signal (SIGINT, sighandler); 
    201        signal (SIGPIPE, sighandler); 
    202  
    203        debugOutput(DEBUG_LEVEL_NORMAL, "Freebob SYT monitor\n"); 
    204          
    205        m_isoManager=new IsoHandlerManager(); 
    206          
    207        if(!m_isoManager) { 
    208                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create IsoHandlerManager\n"); 
    209                goto finish; 
    210        
    211          
    212        m_isoManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    213                  
     195        run=1; 
     196         
     197        run_realtime=arguments.realtime; 
     198        realtime_prio=arguments.rtprio; 
     199 
     200        signal (SIGINT, sighandler); 
     201        signal (SIGPIPE, sighandler); 
     202 
     203        debugOutput(DEBUG_LEVEL_NORMAL, "Freebob SYT monitor\n"); 
     204         
     205        m_isoManager=new IsoHandlerManager(); 
     206         
     207        if(!m_isoManager) { 
     208                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create IsoHandlerManager\n"); 
     209                goto finish; 
     210       
     211         
     212        m_isoManager->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     213                 
    214214    // the thread to execute the manager 
    215        m_isoManagerThread=new PosixThread( 
    216              m_isoManager,  
    217              run_realtime, realtime_prio, 
    218              PTHREAD_CANCEL_DEFERRED); 
    219               
    220        if(!m_isoManagerThread) { 
    221                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create iso manager thread\n"); 
    222                goto finish; 
    223        
    224          
    225        // register monitors 
    226        for (i=0;i<arguments.nb_combos;i++) { 
    227         debugOutput(DEBUG_LEVEL_NORMAL, "Registering SytMonitor %d\n",i); 
    228          
    229         // add a stream to the manager so that it has something to do 
    230         monitors[i]=new SytMonitor(arguments.args[i].port); 
    231          
    232         if (!monitors[i]) { 
    233             debugOutput(DEBUG_LEVEL_NORMAL, "Could not create SytMonitor %d\n", i); 
    234             goto finish; 
    235         }      
    236          
    237         monitors[i]->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
    238          
    239         if (!monitors[i]->init()) { 
    240             debugOutput(DEBUG_LEVEL_NORMAL, "Could not init SytMonitor %d\n", i); 
    241             goto finish; 
    242        
    243          
    244         monitors[i]->setChannel(arguments.args[i].channel); 
    245          
    246         if(!m_isoManager->registerStream(monitors[i])) { 
     215        m_isoManagerThread=new PosixThread( 
     216            m_isoManager,  
     217            run_realtime, realtime_prio, 
     218            PTHREAD_CANCEL_DEFERRED); 
     219             
     220        if(!m_isoManagerThread) { 
     221                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create iso manager thread\n"); 
     222                goto finish; 
     223       
     224         
     225        // register monitors 
     226        for (i=0;i<arguments.nb_combos;i++) { 
     227            debugOutput(DEBUG_LEVEL_NORMAL, "Registering SytMonitor %d\n",i); 
     228         
     229            // add a stream to the manager so that it has something to do 
     230            monitors[i]=new SytMonitor(arguments.args[i].port); 
     231             
     232            if (!monitors[i]) { 
     233                debugOutput(DEBUG_LEVEL_NORMAL, "Could not create SytMonitor %d\n", i); 
     234                goto finish; 
     235            }  
     236         
     237            monitors[i]->setVerboseLevel(DEBUG_LEVEL_VERBOSE); 
     238         
     239            if (!monitors[i]->init()) { 
     240                debugOutput(DEBUG_LEVEL_NORMAL, "Could not init SytMonitor %d\n", i); 
     241                goto finish; 
     242           
     243         
     244            monitors[i]->setChannel(arguments.args[i].channel); 
     245             
     246            if(!m_isoManager->registerStream(monitors[i])) { 
    247247            debugOutput(DEBUG_LEVEL_NORMAL, "Could not register SytMonitor %d\n", i); 
    248             goto finish; 
    249        
     248                goto finish; 
     249           
    250250    } 
    251  
    252  
    253        debugOutput(DEBUG_LEVEL_NORMAL,   "Preparing IsoHandlerManager...\n"); 
    254        if (!m_isoManager->prepare()) { 
    255                debugOutput(DEBUG_LEVEL_NORMAL, "Could not prepare isoManager\n"); 
    256                goto finish; 
    257        
    258  
    259        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting ISO manager sync update thread...\n"); 
     251             
     252 
     253        debugOutput(DEBUG_LEVEL_NORMAL,   "Preparing IsoHandlerManager...\n"); 
     254        if (!m_isoManager->prepare()) { 
     255                debugOutput(DEBUG_LEVEL_NORMAL, "Could not prepare isoManager\n"); 
     256                goto finish; 
     257       
     258 
     259        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting ISO manager sync update thread...\n"); 
    260260 
    261261        // start the runner thread 
    262262        m_isoManagerThread->Start(); 
    263263 
    264        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting IsoHandlers...\n"); 
    265        if (!m_isoManager->startHandlers(0)) { 
    266                debugOutput(DEBUG_LEVEL_NORMAL, "Could not start handlers...\n"); 
    267                goto finish; 
    268        
    269          
    270     if (arguments.realtime) { 
    271         // get rt priority for this thread too. 
    272         params.sched_priority = arguments.rtprio + 1; 
    273         if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &params)) { 
    274             debugWarning("Couldn't set realtime prio for main thread..."); 
    275        
    276    
    277      
    278     // do the actual work 
    279     nb_iter=0; 
    280        while(run) { 
     264        debugOutput(DEBUG_LEVEL_NORMAL,   "Starting IsoHandlers...\n"); 
     265        if (!m_isoManager->startHandlers(0)) { 
     266                debugOutput(DEBUG_LEVEL_NORMAL, "Could not start handlers...\n"); 
     267                goto finish; 
     268       
     269         
     270        if (arguments.realtime) { 
     271            // get rt priority for this thread too. 
     272            params.sched_priority = arguments.rtprio + 1; 
     273            if (pthread_setschedparam(pthread_self(), SCHED_FIFO, &params)) { 
     274                debugWarning("Couldn't set realtime prio for main thread..."); 
     275           
     276       
     277     
     278        // do the actual work 
     279        nb_iter=0; 
     280        while(run) { 
    281281        debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"--- Iterate ---\n"); 
    282282         
     
    325325 
    326326                        if(cif.cycle==master_cif.cycle 
    327                            && cif.seconds==master_cif.seconds) { // this is the one 
     327                        && cif.seconds==master_cif.seconds) { // this is the one 
    328328                            debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"  GOOD : [%2d: %04us %04uc, %04X]\n", 
    329329                                i,cif.seconds, cif.cycle,cif.syt); 
     
    339339                                    cif.pres_ticks += TICKS_PER_SECOND*128; 
    340340                                } 
    341                                // average out the offset 
     341                            // average out the offset 
    342342                                int err=(((long)master_cif.pres_ticks) - ((long)cif.pres_ticks)); 
    343343                                 
     
    383383                            if ((cif.seconds < master_cif.seconds) ||  
    384384                                ((cif.seconds == master_cif.seconds)  
    385                                 && (cif.cycle < master_cif.cycle))) { 
     385                                && (cif.cycle < master_cif.cycle))) { 
    386386                                 
    387387                                debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"  LAGS : [%2d: %04us %04uc, %04X]\n", 
     
    419419        } 
    420420         
    421         // show info every x iterations 
     421            // show info every x iterations 
    422422        if ((nb_iter++ % 4000)==0) { 
    423             m_isoManager->dumpInfo(); 
    424             for (i=0;i<arguments.nb_combos;i++) { 
    425                 monitors[i]->dumpInfo(); 
     423                m_isoManager->dumpInfo(); 
     424                for (i=0;i<arguments.nb_combos;i++) { 
     425                    monitors[i]->dumpInfo(); 
    426426                debugOutput(DEBUG_LEVEL_NORMAL,"    ==> Stream offset: %10d ticks\n",stream_offset_ticks[i]); 
    427            
    428        
    429        
    430  
    431        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping handlers...\n"); 
    432        if(!m_isoManager->stopHandlers()) { 
    433           debugOutput(DEBUG_LEVEL_NORMAL, "Could not stop ISO handlers\n"); 
    434           goto finish; 
    435        
    436          
    437        // stop the sync thread 
    438        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping ISO manager sync update thread...\n"); 
    439        m_isoManagerThread->Stop(); 
    440          
    441        // unregister monitors 
    442        for (i=0;i<arguments.nb_combos;i++) { 
     427               
     428           
     429       
     430 
     431        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping handlers...\n"); 
     432        if(!m_isoManager->stopHandlers()) { 
     433            debugOutput(DEBUG_LEVEL_NORMAL, "Could not stop ISO handlers\n"); 
     434            goto finish; 
     435       
     436         
     437        // stop the sync thread 
     438        debugOutput(DEBUG_LEVEL_NORMAL,   "Stopping ISO manager sync update thread...\n"); 
     439        m_isoManagerThread->Stop(); 
     440         
     441        // unregister monitors 
     442        for (i=0;i<arguments.nb_combos;i++) { 
    443443        debugOutput(DEBUG_LEVEL_NORMAL, "Unregistering SytMonitor %d\n",i); 
    444          
     444         
    445445        if(!m_isoManager->unregisterStream(monitors[i])) { 
    446446            debugOutput(DEBUG_LEVEL_NORMAL, "Could not unregister SytMonitor %d\n",i); 
    447447            goto finish; 
    448            } 
    449            delete monitors[i]; 
     448            } 
     449            delete monitors[i]; 
    450450    } 
    451          
    452        delete m_isoManagerThread; 
     451         
     452        delete m_isoManagerThread; 
    453453    delete m_isoManager; 
    454454 
    455455finish: 
    456         debugOutput(DEBUG_LEVEL_NORMAL, "Bye...\n"); 
    457  
    458     delete DebugModuleManager::instance(); 
    459          
    460   return EXIT_SUCCESS; 
     456        debugOutput(DEBUG_LEVEL_NORMAL, "Bye...\n"); 
     457     delete DebugModuleManager::instance(); 
     458          
     459return EXIT_SUCCESS; 
    461460}