wlan_bearer/wlanengine/wlan_common/wlanengine_common_3.1/src/core_traffic_stream_list.cpp
changeset 0 c40eb8fe8501
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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 the License "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:  Implementation of core_traffic_stream_list_c class.
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 10 %
       
    20 */
       
    21 
       
    22 #include "core_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_traffic_stream_list_c::core_traffic_stream_list_c() :
       
    33     ts_list_m( )
       
    34     {
       
    35     DEBUG( "core_traffic_stream_list_c::core_traffic_stream_list_c()" );
       
    36     }
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // ---------------------------------------------------------------------------
       
    40 //
       
    41 core_traffic_stream_list_c::~core_traffic_stream_list_c()
       
    42     {
       
    43     DEBUG( "core_traffic_stream_list_c::~core_traffic_stream_list_c()" );
       
    44 
       
    45     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
    46         {
       
    47         delete iter->traffic_stream;
       
    48         }
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 u32_t core_traffic_stream_list_c::count() const
       
    55     {
       
    56     return ts_list_m.count();
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 core_traffic_stream_c* core_traffic_stream_list_c::first()
       
    63     {
       
    64     entry_s* iter = ts_list_m.first();
       
    65     if ( iter )
       
    66         {
       
    67         return iter->traffic_stream;
       
    68         }
       
    69 
       
    70     return NULL;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 core_traffic_stream_c* core_traffic_stream_list_c::next()
       
    77     {
       
    78     entry_s* iter = ts_list_m.next();
       
    79     if ( iter )
       
    80         {
       
    81         return iter->traffic_stream;
       
    82         }
       
    83 
       
    84     return NULL;
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // ---------------------------------------------------------------------------
       
    89 //
       
    90 core_traffic_stream_c* core_traffic_stream_list_c::current() const
       
    91     {
       
    92     entry_s* iter = ts_list_m.current();
       
    93     if ( iter )
       
    94         {
       
    95         return iter->traffic_stream;
       
    96         }
       
    97 
       
    98     return NULL;
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 core_error_e core_traffic_stream_list_c::update_traffic_stream(
       
   105     const core_traffic_stream_c& traffic_stream )
       
   106     {
       
   107     DEBUG1( "core_traffic_stream_list_c::update_traffic_stream() - searching an entry with TID %u",
       
   108         traffic_stream.tid() );
       
   109 
       
   110     entry_s* iter = ts_list_m.first();
       
   111     while( iter )
       
   112         {
       
   113         if ( iter->traffic_stream->tid() == traffic_stream.tid() )
       
   114             {
       
   115             DEBUG( "core_traffic_stream_list_c::update_traffic_stream() - entry with matching TID found, replacing entry" );
       
   116             *iter->traffic_stream = traffic_stream;
       
   117 
       
   118             return core_error_ok;
       
   119             }
       
   120 
       
   121         iter = ts_list_m.next();
       
   122         }
       
   123 
       
   124     DEBUG( "core_traffic_stream_list_c::update_traffic_stream() - no entry matching the TID found, adding a new entry" );
       
   125 
       
   126     entry_s* entry = new entry_s;
       
   127     if ( entry )
       
   128         {
       
   129         entry->traffic_stream = new core_traffic_stream_c(
       
   130             traffic_stream.tid(),
       
   131             traffic_stream.user_priority() );
       
   132         if ( entry->traffic_stream )
       
   133             {
       
   134             *entry->traffic_stream = traffic_stream;
       
   135 
       
   136             ts_list_m.append( entry );
       
   137             }
       
   138         else
       
   139             {
       
   140             DEBUG( "core_traffic_stream_list_c::update_traffic_stream() - unable to create core_traffic_stream_c" );
       
   141             delete entry;
       
   142 
       
   143             return core_error_no_memory;
       
   144             }
       
   145         }
       
   146     else
       
   147         {
       
   148         DEBUG( "core_traffic_stream_list_c::update_traffic_stream() - unable to create entry_s" );
       
   149 
       
   150         return core_error_no_memory;
       
   151         }
       
   152 
       
   153     return core_error_ok;         
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 void core_traffic_stream_list_c::remove_traffic_stream_by_tid(
       
   160     u8_t tid )
       
   161     {
       
   162     DEBUG1( "core_traffic_stream_list_c::remove_traffic_stream_by_tid() - removing an entry with TID %u", tid );
       
   163 
       
   164     entry_s* iter = ts_list_m.first();
       
   165     while( iter )
       
   166         {
       
   167         if ( iter->traffic_stream->tid() == tid )
       
   168             {
       
   169             DEBUG( "core_traffic_stream_list_c::remove_traffic_stream_by_tid() - matching entry found" );
       
   170 
       
   171             ts_list_m.remove( iter );
       
   172             iter = NULL;
       
   173             }
       
   174         else
       
   175             {
       
   176             iter = ts_list_m.next();
       
   177             }
       
   178         }
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // ---------------------------------------------------------------------------
       
   183 //
       
   184 void core_traffic_stream_list_c::print_contents()
       
   185     {
       
   186     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   187         {
       
   188         DEBUG1( "core_traffic_stream_list_c::print_contents() - TID: %u",
       
   189             iter->traffic_stream->tid() );
       
   190         DEBUG1( "core_traffic_stream_list_c::print_contents() - UP: %u",
       
   191             iter->traffic_stream->user_priority() );
       
   192         switch( iter->traffic_stream->direction() )
       
   193             {
       
   194             case core_traffic_stream_direction_uplink:
       
   195                 DEBUG( "core_traffic_stream_list_c::print_contents() - direction: uplink" );
       
   196                 break;
       
   197             case core_traffic_stream_direction_downlink:
       
   198                 DEBUG( "core_traffic_stream_list_c::print_contents() - direction: downlink" );
       
   199                 break;
       
   200             case core_traffic_stream_direction_bidirectional:
       
   201                 DEBUG( "core_traffic_stream_list_c::print_contents() - direction: bi-directional" );
       
   202                 break;
       
   203             }
       
   204         switch ( iter->traffic_stream->status() )
       
   205             {
       
   206             case core_traffic_stream_status_undefined:
       
   207                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_undefined" );
       
   208                 break;
       
   209             case core_traffic_stream_status_active:
       
   210                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_active" );
       
   211                 break;
       
   212             case core_traffic_stream_status_inactive_not_required:
       
   213                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_not_required" );
       
   214                 break;
       
   215             case core_traffic_stream_status_inactive_deleted_by_ap:
       
   216                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_deleted_by_ap" );
       
   217                 break;
       
   218             case core_traffic_stream_status_inactive_no_bandwidth:
       
   219                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_no_bandwidth" );
       
   220                 break;
       
   221             case core_traffic_stream_status_inactive_invalid_parameters:
       
   222                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_invalid_parameters" );
       
   223                 break;
       
   224             case core_traffic_stream_status_inactive_other:
       
   225                 DEBUG( "core_traffic_stream_list_c::print_contents() - status: core_traffic_stream_status_inactive_other" );
       
   226                 break;
       
   227             }
       
   228         DEBUG( "core_traffic_stream_list_c::print_contents()" );
       
   229         }
       
   230     }
       
   231 
       
   232 // ---------------------------------------------------------------------------
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 medium_time_s core_traffic_stream_list_c::admitted_medium_time()
       
   236     {
       
   237     medium_time_s medium_time( MEDIUM_TIME_NOT_DEFINED );
       
   238 
       
   239     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   240         {
       
   241         u16_t ts_medium_time(
       
   242             iter->traffic_stream->medium_time() );       
       
   243         if( iter->traffic_stream->direction() == core_traffic_stream_direction_bidirectional )
       
   244             {
       
   245             /**
       
   246              * The admitted medium time of a bi-directional stream has to be
       
   247              * multiplied by two because it contains both an uplink and
       
   248              * a downlink component.
       
   249              */
       
   250             ts_medium_time *= 2;
       
   251             }
       
   252 
       
   253         medium_time.up[iter->traffic_stream->user_priority()] += ts_medium_time;
       
   254         medium_time.ac[iter->traffic_stream->access_class()] += ts_medium_time;
       
   255         }
       
   256 
       
   257     return medium_time;
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 bool_t core_traffic_stream_list_c::is_traffic_stream_for_access_class(
       
   264     core_access_class_e access_class )
       
   265     {
       
   266     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   267         {
       
   268         if ( core_tools_c::convert_user_priority_to_ac( iter->traffic_stream->user_priority() ) ==
       
   269              access_class )
       
   270             {
       
   271             return true_t;
       
   272             }
       
   273         }
       
   274 
       
   275     return false_t;
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 bool_t core_traffic_stream_list_c::is_traffic_stream_for_tid(
       
   282     u8_t tid )
       
   283     {
       
   284     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   285         {
       
   286         if( iter->traffic_stream->tid() == tid )
       
   287             {
       
   288             return true_t;
       
   289             }
       
   290         }
       
   291 
       
   292     return false_t;
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void core_traffic_stream_list_c::set_traffic_stream_status(
       
   299     core_traffic_stream_status_e status )
       
   300     {
       
   301     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   302         {
       
   303         iter->traffic_stream->set_status( status );
       
   304         }
       
   305     }
       
   306 
       
   307 // ---------------------------------------------------------------------------
       
   308 // ---------------------------------------------------------------------------
       
   309 //
       
   310 u8_t core_traffic_stream_list_c::next_tid()
       
   311     {
       
   312     bool_t tid_array[MAX_TRAFFIC_STREAM_TID] =
       
   313         { false_t, false_t, false_t, false_t, false_t,false_t,false_t,false_t };
       
   314     for( entry_s* iter = ts_list_m.first(); iter; iter = ts_list_m.next() )
       
   315         {
       
   316         tid_array[iter->traffic_stream->tid()] = true_t;
       
   317         }
       
   318     u8_t tid( 0 );
       
   319     while( tid < MAX_TRAFFIC_STREAM_TID )
       
   320         {
       
   321         if( !tid_array[tid] )
       
   322             {
       
   323             return tid;
       
   324             }
       
   325         else
       
   326             {
       
   327             ++tid;
       
   328             }
       
   329         }
       
   330 
       
   331     return MAX_TRAFFIC_STREAM_TID;
       
   332     }