wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_virtual_traffic_stream_list.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0""
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class for storing virtual traffic streams.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 1 %
       
    20 */
       
    21 
       
    22 #include "core_virtual_traffic_stream_list.h"
       
    23 #include "core_tools.h"
       
    24 #include "core_am_tools.h"
       
    25 #include "am_debug.h"
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // ---------------------------------------------------------------------------
       
    31 //
       
    32 core_virtual_traffic_stream_list_c::core_virtual_traffic_stream_list_c() :
       
    33     ts_list_m( ),
       
    34     next_stream_id_m( 0 )
       
    35     {
       
    36     DEBUG( "core_virtual_traffic_stream_list_c::core_virtual_traffic_stream_list_c()" );
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 core_virtual_traffic_stream_list_c::~core_virtual_traffic_stream_list_c()
       
    43     {
       
    44     DEBUG( "core_virtual_traffic_stream_list_c::~core_virtual_traffic_stream_list_c()" );
       
    45 
       
    46     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
    47         {
       
    48         delete iter->traffic_stream;
       
    49         }
       
    50     }
       
    51 
       
    52 // ---------------------------------------------------------------------------
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 u32_t core_virtual_traffic_stream_list_c::count() const
       
    56     {
       
    57     return ts_list_m.count();
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 core_error_e core_virtual_traffic_stream_list_c::add_traffic_stream(
       
    64     const core_virtual_traffic_stream_c& stream )
       
    65     {
       
    66     entry_s* entry = new entry_s;
       
    67     if( entry )
       
    68         {        
       
    69         entry->traffic_stream = new core_virtual_traffic_stream_c(
       
    70             stream.requested_tid(),
       
    71             stream.tid(),
       
    72             stream.user_priority(),
       
    73             stream.is_automatic_stream(),
       
    74             stream.params(),
       
    75             stream.id(),
       
    76             stream.status() );
       
    77         if( entry->traffic_stream )
       
    78             {
       
    79             ts_list_m.append( entry );
       
    80             }
       
    81         else
       
    82             {
       
    83             DEBUG( "core_virtual_traffic_stream_list_c::add_traffic_stream() - unable to create core_virtual_traffic_stream_c" );
       
    84 
       
    85             delete entry;
       
    86             entry = NULL;
       
    87 
       
    88             return core_error_no_memory;
       
    89             }
       
    90         }
       
    91     else
       
    92         {
       
    93         DEBUG( "core_virtual_traffic_stream_list_c::update_traffic_stream() - unable to create entry_s" );
       
    94 
       
    95         return core_error_no_memory;
       
    96         }
       
    97 
       
    98     return core_error_ok;         
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 core_error_e core_virtual_traffic_stream_list_c::add_traffic_stream(
       
   105     u8_t requested_tid,
       
   106     u8_t tid,
       
   107     u8_t user_priority,
       
   108     bool_t is_automatic_stream,
       
   109     const core_traffic_stream_params_s& params,
       
   110     u32_t& stream_id,
       
   111     core_traffic_stream_status_e stream_status )
       
   112     {
       
   113     entry_s* entry = new entry_s;
       
   114     if( entry )
       
   115         {
       
   116         stream_id = next_stream_id_m++;
       
   117         entry->traffic_stream = new core_virtual_traffic_stream_c(
       
   118             requested_tid,
       
   119             tid,
       
   120             user_priority,
       
   121             is_automatic_stream,
       
   122             params,
       
   123             stream_id,
       
   124             stream_status );
       
   125         if( entry->traffic_stream )
       
   126             {
       
   127             ts_list_m.append( entry );
       
   128             }
       
   129         else
       
   130             {
       
   131             DEBUG( "core_virtual_traffic_stream_list_c::add_traffic_stream() - unable to create core_virtual_traffic_stream_c" );
       
   132 
       
   133             delete entry;
       
   134             entry = NULL;
       
   135 
       
   136             return core_error_no_memory;
       
   137             }
       
   138         }
       
   139     else
       
   140         {
       
   141         DEBUG( "core_virtual_traffic_stream_list_c::update_traffic_stream() - unable to create entry_s" );
       
   142 
       
   143         return core_error_no_memory;
       
   144         }
       
   145 
       
   146     return core_error_ok;         
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // ---------------------------------------------------------------------------
       
   151 //
       
   152 void core_virtual_traffic_stream_list_c::remove_traffic_stream_by_tid(
       
   153     u8_t tid )
       
   154     {
       
   155     DEBUG1( "core_virtual_traffic_stream_list_c::remove_traffic_stream_by_tid() - removing an entry with TID %u",
       
   156         tid );
       
   157 
       
   158     core_type_list_iterator_c<entry_s> ts_iter( ts_list_m );
       
   159     for( entry_s* iter = ts_iter.first(); iter; iter = ts_iter.next() )
       
   160         {
       
   161         if( iter->traffic_stream->tid() == tid )
       
   162             {
       
   163             DEBUG( "core_virtual_traffic_stream_list_c::remove_traffic_stream_by_tid() - matching entry found" );
       
   164 
       
   165             ts_iter.remove();
       
   166             }
       
   167         }
       
   168     }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // ---------------------------------------------------------------------------
       
   172 //
       
   173 void core_virtual_traffic_stream_list_c::remove_traffic_stream_by_id(
       
   174     u32_t stream_id )
       
   175     {
       
   176     DEBUG1( "core_virtual_traffic_stream_list_c::remove_traffic_stream_by_tid() - removing an entry with stream ID %u",
       
   177         stream_id );
       
   178 
       
   179     core_type_list_iterator_c<entry_s> ts_iter( ts_list_m );
       
   180     for( entry_s* iter = ts_iter.first(); iter; iter = ts_iter.next() )
       
   181         {
       
   182         if( iter->traffic_stream->id() == stream_id )
       
   183             {
       
   184             DEBUG( "core_virtual_traffic_stream_list_c::remove_traffic_stream_by_tid() - matching entry found" );
       
   185 
       
   186             ts_iter.remove();
       
   187             }
       
   188         }   
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------------------------
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 core_access_class_traffic_mode_e core_virtual_traffic_stream_list_c::traffic_mode_by_ac(
       
   195     core_access_class_e access_class )
       
   196     {
       
   197     core_type_list_iterator_c<entry_s> ts_iter( ts_list_m );
       
   198     for( entry_s* iter = ts_iter.first(); iter; iter = ts_iter.next() )
       
   199         {
       
   200         if( iter->traffic_stream->access_class() == access_class &&
       
   201             !iter->traffic_stream->is_automatic_stream() )
       
   202             {
       
   203             return core_access_class_traffic_mode_manual;
       
   204             }
       
   205         }   
       
   206 
       
   207     return core_access_class_traffic_mode_automatic;
       
   208     }
       
   209 
       
   210 // ---------------------------------------------------------------------------
       
   211 // ---------------------------------------------------------------------------
       
   212 //
       
   213 void core_virtual_traffic_stream_list_c::print_contents()
       
   214     {
       
   215     core_type_list_iterator_c<entry_s> ts_iter( ts_list_m );
       
   216     for( entry_s* iter = ts_iter.first(); iter; iter = ts_iter.next() )
       
   217         {
       
   218         DEBUG1( "core_virtual_traffic_stream_list_c::print_contents() - stream ID: %u",
       
   219             iter->traffic_stream->id() );
       
   220         DEBUG1( "core_virtual_traffic_stream_list_c::print_contents() - requested TID: %u",
       
   221             iter->traffic_stream->requested_tid() );
       
   222         DEBUG1( "core_virtual_traffic_stream_list_c::print_contents() - current TID: %u",
       
   223             iter->traffic_stream->tid() );
       
   224         DEBUG1( "core_virtual_traffic_stream_list_c::print_contents() - UP: %u",
       
   225             iter->traffic_stream->user_priority() );
       
   226         if( iter->traffic_stream->is_automatic_stream() )
       
   227             {
       
   228             DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - automatic: yes" );
       
   229             }
       
   230         else
       
   231             {
       
   232             DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - automatic: no" );
       
   233             }
       
   234         switch( iter->traffic_stream->params().direction )
       
   235             {
       
   236             case core_traffic_stream_direction_uplink:
       
   237                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - direction: uplink" );
       
   238                 break;
       
   239             case core_traffic_stream_direction_downlink:
       
   240                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - direction: downlink" );
       
   241                 break;
       
   242             case core_traffic_stream_direction_bidirectional:
       
   243                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - direction: bi-directional" );
       
   244                 break;
       
   245             }
       
   246         switch ( iter->traffic_stream->status() )
       
   247             {
       
   248             case core_traffic_stream_status_undefined:
       
   249                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_undefined" );
       
   250                 break;            
       
   251             case core_traffic_stream_status_active:
       
   252                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_active" );
       
   253                 break;
       
   254             case core_traffic_stream_status_inactive_not_required:
       
   255                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_not_required" );
       
   256                 break;
       
   257             case core_traffic_stream_status_inactive_deleted_by_ap:
       
   258                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_deleted_by_ap" );
       
   259                 break;
       
   260             case core_traffic_stream_status_inactive_no_bandwidth:
       
   261                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_no_bandwidth" );
       
   262                 break;
       
   263             case core_traffic_stream_status_inactive_invalid_parameters:
       
   264                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_invalid_parameters" );
       
   265                 break;
       
   266             case core_traffic_stream_status_inactive_other:
       
   267                 DEBUG( "core_virtual_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_other" );
       
   268                 break;
       
   269             }
       
   270         DEBUG( "core_virtual_traffic_stream_list_c::print_contents()" );
       
   271         }
       
   272     }
       
   273 
       
   274 
       
   275 // ---------------------------------------------------------------------------
       
   276 // ---------------------------------------------------------------------------
       
   277 //
       
   278 u8_t core_virtual_traffic_stream_list_c::next_tid()
       
   279     {
       
   280     bool_t tid_array[MAX_TRAFFIC_STREAM_TID] =
       
   281         { false_t, false_t, false_t, false_t, false_t,false_t,false_t,false_t };
       
   282     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   283         {
       
   284         if( iter->traffic_stream->requested_tid() != TRAFFIC_STREAM_TID_NONE )
       
   285             {
       
   286             /**
       
   287              * Both active and inactive streams that were requested
       
   288              * with a certain TID.
       
   289              */            
       
   290             tid_array[iter->traffic_stream->requested_tid()] = true_t;            
       
   291             }
       
   292         else if( iter->traffic_stream->tid() != TRAFFIC_STREAM_TID_NONE ) 
       
   293             {
       
   294             /**
       
   295              * Active streams.
       
   296              */
       
   297             tid_array[iter->traffic_stream->tid()] = true_t;            
       
   298             }
       
   299         }
       
   300     u8_t tid( 0 );
       
   301     while( tid < MAX_TRAFFIC_STREAM_TID )
       
   302         {
       
   303         if( !tid_array[tid] )
       
   304             {
       
   305             return tid;
       
   306             }
       
   307         else
       
   308             {
       
   309             ++tid;
       
   310             }
       
   311         }
       
   312 
       
   313     return MAX_TRAFFIC_STREAM_TID;
       
   314     }