connectionmonitoring/connectionmonitorui/src/ConnectionArray.cpp
branchRCL_3
changeset 57 05bc53fe583b
parent 55 fc7b30ed2058
child 58 83ca720e2b9a
equal deleted inserted replaced
55:fc7b30ed2058 57:05bc53fe583b
     1 /*
       
     2 * Copyright (c) 2002 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:  Contains and handles CConnectionInfo instances
       
    15 *     
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "ConnectionArray.h"
       
    23 #include "ConnectionMonitorUiLogger.h"
       
    24 
       
    25 // CONSTANTS
       
    26 /**
       
    27 * Count of allowed connections.
       
    28 */
       
    29 const TUint KConnArrayGranuality = KConnMonMaxClientUids;   
       
    30 
       
    31 
       
    32 // ================= MEMBER FUNCTIONS =======================
       
    33 // ---------------------------------------------------------
       
    34 // CConnectionArray::~CConnectionArray
       
    35 // ---------------------------------------------------------
       
    36 //
       
    37 CConnectionArray::~CConnectionArray()
       
    38     {
       
    39     if ( iConnectionArray )
       
    40         {
       
    41         iConnectionArray->ResetAndDestroy();
       
    42         }
       
    43     delete iConnectionArray;
       
    44     }
       
    45 
       
    46 
       
    47 // ---------------------------------------------------------
       
    48 // CConnectionArray::CConnectionArray
       
    49 // ---------------------------------------------------------
       
    50 //
       
    51 CConnectionArray::CConnectionArray()
       
    52     {
       
    53     }
       
    54 
       
    55 
       
    56 // ---------------------------------------------------------
       
    57 // CConnectionArray::ConstructL
       
    58 // ---------------------------------------------------------
       
    59 //
       
    60 void CConnectionArray::ConstructL()
       
    61     {
       
    62     iConnectionArray = new ( ELeave ) 
       
    63                     CArrayPtrFlat<CConnectionInfoBase>( KConnArrayGranuality );
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------
       
    68 // CConnectionArray::MdcaCount
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 TInt  CConnectionArray::MdcaCount() const
       
    72     {
       
    73     return iConnectionArray->Count();
       
    74     }
       
    75 
       
    76 
       
    77 // ---------------------------------------------------------
       
    78 // CConnectionArray::MdcaPoint
       
    79 // ---------------------------------------------------------
       
    80 //
       
    81 TPtrC CConnectionArray::MdcaPoint( TInt aIndex ) const
       
    82     {
       
    83     return ( *iConnectionArray )[aIndex]->GetConnectionListBoxItemText();
       
    84     }
       
    85 
       
    86 
       
    87 // ---------------------------------------------------------
       
    88 // CConnectionArray::DeepCopyL
       
    89 // ---------------------------------------------------------
       
    90 //
       
    91 CConnectionArray* CConnectionArray::DeepCopyL()
       
    92 	{
       
    93 	CConnectionArray* temp = new ( ELeave ) CConnectionArray();
       
    94 	CleanupStack::PushL( temp );
       
    95     temp->ConstructL();
       
    96     TInt count = iConnectionArray->Count();
       
    97     CConnectionInfoBase* tempConnInfo = NULL;
       
    98     for ( TInt i = 0; i < count; ++i )
       
    99 	    {
       
   100 	    tempConnInfo = ( *iConnectionArray )[i]->DeepCopyL();
       
   101 		CleanupStack::PushL( tempConnInfo );	    
       
   102 	    temp->AppendL( tempConnInfo );
       
   103 		CleanupStack::Pop( tempConnInfo );	    
       
   104 	    }
       
   105 	CleanupStack::Pop( temp );
       
   106 	return temp;
       
   107 	}
       
   108 
       
   109 // ---------------------------------------------------------
       
   110 // CConnectionArray::GetArrayIndex
       
   111 // ---------------------------------------------------------
       
   112 //
       
   113 TInt CConnectionArray::GetArrayIndex( TUint aConnectionId ) const
       
   114     {
       
   115     CMUILOGGER_WRITE_F( "GetArrayIndex: %d", aConnectionId );
       
   116     TBool found( EFalse );
       
   117     TInt index( 0 );
       
   118     TInt count = iConnectionArray->Count();
       
   119     TUint connectionId( 0 );
       
   120 
       
   121     while ( ( index <  count ) && !found  )
       
   122         {
       
   123         connectionId = ( *iConnectionArray )[index]->GetConnectionId();
       
   124         if ( connectionId == aConnectionId )
       
   125             {
       
   126             found = ETrue;
       
   127             }
       
   128         else
       
   129             {
       
   130             ++index;            
       
   131             }
       
   132         }
       
   133 
       
   134     CMUILOGGER_WRITE_F( "Found: %d", found );
       
   135 
       
   136     return ( found ? index : KErrNotFound );
       
   137     }
       
   138 
       
   139 
       
   140 // ---------------------------------------------------------
       
   141 // CConnectionArray::GetArrayIndex
       
   142 // ---------------------------------------------------------
       
   143 //
       
   144 TInt CConnectionArray::GetArrayIndex( CConnectionInfoBase* aConnection ) const
       
   145     {
       
   146     CMUILOGGER_WRITE_F( "GetArrayIndex: %d", 
       
   147                        aConnection->GetConnectionId() );
       
   148     TBool found( EFalse );
       
   149     TInt index( 0 );
       
   150     TInt count = iConnectionArray->Count();
       
   151 
       
   152     while ( ( index <  count ) && !found  )
       
   153         {
       
   154         if ( ( *iConnectionArray )[index] == aConnection )
       
   155             {
       
   156             found = ETrue;
       
   157             }
       
   158         else
       
   159             {
       
   160             ++index;            
       
   161             }        
       
   162         }
       
   163 
       
   164     CMUILOGGER_WRITE_F( "Found: %d", found );
       
   165 
       
   166     return ( found ? index : KErrNotFound );        
       
   167     }
       
   168 
       
   169 
       
   170 // ---------------------------------------------------------
       
   171 // CConnectionArray::AppendL
       
   172 // ---------------------------------------------------------
       
   173 //
       
   174 void CConnectionArray::AppendL( CConnectionInfoBase* aConnection )
       
   175     {
       
   176     CMUILOGGER_ENTERFN( "CConnectionArray::AppendL" );
       
   177     if ( aConnection )
       
   178         {
       
   179         TUint connectionId = aConnection->GetConnectionId();
       
   180         TInt index = GetArrayIndex( connectionId );
       
   181 
       
   182         if ( index == KErrNotFound )
       
   183             {
       
   184             if ( aConnection->GetStatus() != EConnectionClosed &&
       
   185                 aConnection->GetStatus() != EConnectionUninitialized )
       
   186                 {
       
   187                 iConnectionArray->AppendL( aConnection );
       
   188                 }
       
   189             }
       
   190         }
       
   191 
       
   192     CMUILOGGER_LEAVEFN( "CConnectionArray::AppendL" );
       
   193     }
       
   194 
       
   195 
       
   196 // ---------------------------------------------------------
       
   197 // CConnectionArray::Delete
       
   198 // ---------------------------------------------------------
       
   199 //
       
   200 void CConnectionArray::Delete( TUint aConnectionId )
       
   201     {
       
   202     CMUILOGGER_WRITE_F( "Deleting connection: %d", aConnectionId );
       
   203     TInt count = iConnectionArray->Count();
       
   204     TUint connectionId( 0 );
       
   205     TBool deleted( EFalse );
       
   206     for ( TInt i = 0; (i < count) && !deleted; ++i )
       
   207         {
       
   208         connectionId = ( *iConnectionArray )[i]->GetConnectionId();
       
   209         if ( connectionId == aConnectionId )
       
   210             {
       
   211             delete ( *iConnectionArray )[i];
       
   212             iConnectionArray->Delete( i );
       
   213             iConnectionArray->Compress();
       
   214             deleted = ETrue;
       
   215             }
       
   216         }
       
   217     CMUILOGGER_WRITE_F( "Found and deleted: %b", deleted );
       
   218     }
       
   219 
       
   220 
       
   221 // ---------------------------------------------------------
       
   222 // CConnectionArray::Delete
       
   223 // ---------------------------------------------------------
       
   224 //
       
   225 void CConnectionArray::Delete( CConnectionInfoBase* aConnection )
       
   226     {
       
   227     CMUILOGGER_WRITE_F( "Deleting connection: %d", 
       
   228                         aConnection->GetConnectionId() );
       
   229     TInt count = iConnectionArray->Count();
       
   230     TBool deleted( EFalse );
       
   231     for ( TInt i = 0; (i < count) && !deleted; ++i )
       
   232         {
       
   233         if ( ( *iConnectionArray )[i] == aConnection )
       
   234             {
       
   235             delete ( *iConnectionArray )[i];
       
   236             iConnectionArray->Delete( i );
       
   237             iConnectionArray->Compress();
       
   238             deleted = ETrue;
       
   239             }
       
   240         }
       
   241     CMUILOGGER_WRITE_F( "Found and deleted: %b", deleted );
       
   242     }
       
   243 
       
   244 
       
   245 // ---------------------------------------------------------
       
   246 // CConnectionArray::Reset
       
   247 // ---------------------------------------------------------
       
   248 //
       
   249 void CConnectionArray::Reset()
       
   250     {
       
   251     iConnectionArray->ResetAndDestroy();
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------
       
   255 // CConnectionArray::operator[]
       
   256 // ---------------------------------------------------------
       
   257 //
       
   258 CConnectionInfoBase* CConnectionArray::operator[]( TUint aIndex ) const
       
   259     {
       
   260     return ( *iConnectionArray )[aIndex];
       
   261     }
       
   262     
       
   263 // ---------------------------------------------------------
       
   264 // CConnectionArray::At
       
   265 // ---------------------------------------------------------
       
   266 //
       
   267 CConnectionInfoBase* CConnectionArray::At( TInt aIndex ) const
       
   268     {
       
   269     CMUILOGGER_ENTERFN( "CConnectionArray::At()" );
       
   270     CConnectionInfoBase* temp( NULL );
       
   271     TInt count = iConnectionArray->Count();
       
   272     CMUILOGGER_WRITE_F( "count %d", count );
       
   273     
       
   274     if ( count  && ( aIndex < count ) )
       
   275         {
       
   276         temp = ( *iConnectionArray )[aIndex];
       
   277         }
       
   278     
       
   279     CMUILOGGER_LEAVEFN( "CConnectionArray::At()" );
       
   280     return temp;
       
   281     }    
       
   282 
       
   283 // ---------------------------------------------------------
       
   284 // CConnectionArray::NumberOfActiveConnections
       
   285 // ---------------------------------------------------------
       
   286 //
       
   287 TInt CConnectionArray::NumberOfActiveConnections() const 
       
   288     {
       
   289     TInt count( 0 );
       
   290 
       
   291     CMUILOGGER_WRITE_F(
       
   292          "NumberOfActiveConnections: all in array: [%d]\n",
       
   293          MdcaCount() );
       
   294 
       
   295     // we need to count all and only the open connection
       
   296     for ( TInt i = 0; i < MdcaCount(); ++i )
       
   297         {
       
   298          if ( ( *iConnectionArray )[i]->IsAlive() )
       
   299              {
       
   300              ++count;
       
   301              }
       
   302         }
       
   303 
       
   304     CMUILOGGER_WRITE_F( "Active connections: [%d]\n", count );
       
   305     return count;
       
   306     }    
       
   307 
       
   308 // ---------------------------------------------------------
       
   309 // CConnectionArray::NumberOfSuspendedConnections
       
   310 // ---------------------------------------------------------
       
   311 //
       
   312 TInt CConnectionArray::NumberOfSuspendedConnections() const 
       
   313     {
       
   314     TInt count( 0 );
       
   315     
       
   316     CMUILOGGER_WRITE_F(
       
   317          "Number of all connection in array: [%d]\n", MdcaCount() );
       
   318 
       
   319     // we need to count all and only the open connection
       
   320     for ( TInt i = 0; i < MdcaCount(); ++i )
       
   321         {
       
   322          if ( ( *iConnectionArray )[i]->IsSuspended() )
       
   323              {
       
   324              ++count;
       
   325              }
       
   326         }
       
   327     
       
   328     CMUILOGGER_WRITE_F( "Suspended connections: [%d]\n", count );
       
   329     return count;
       
   330     }
       
   331 
       
   332 
       
   333 // End of File