connectionutilities/ConnectionDialogs/cconndlg/src/sortsnaputils.cpp
changeset 20 9c97ad6591ae
parent 18 fcbbe021d614
child 21 b8e8e15e80f2
child 23 7ec726f93df1
child 28 860702281757
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
     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:  Implementation of class TSortSnapUtils.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "sortsnaputils.h"
       
    21 #include "ConnectionDialogsLogger.h"
       
    22 
       
    23 // ================= MEMBER FUNCTIONS =======================
       
    24 //
       
    25 // ---------------------------------------------------------
       
    26 // TSortSnapUtils::TSortSnapUtils
       
    27 // ---------------------------------------------------------
       
    28 //
       
    29 TSortSnapUtils::TSortSnapUtils( RMPM& aMPM ):
       
    30 iSnapCount( 0 ),
       
    31 iSSUState( EUninitialised ),
       
    32 iMPM( aMPM )
       
    33     {
       
    34     CLOG_ENTERFN( "TSortSnapUtils::TSortSnapUtils" );
       
    35     CLOG_LEAVEFN( "TSortSnapUtils::TSortSnapUtils" );
       
    36     }
       
    37 
       
    38 
       
    39 // ---------------------------------------------------------
       
    40 // TSortSnapUtils::~TSortSnapUtils
       
    41 // ---------------------------------------------------------
       
    42 //
       
    43 TSortSnapUtils::~TSortSnapUtils()
       
    44     {
       
    45     CLOG_ENTERFN( "TSortSnapUtils::~TSortSnapUtils" );
       
    46     CLOG_LEAVEFN( "TSortSnapUtils::~TSortSnapUtils" );
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------
       
    50 // TSortSnapUtils::InitDestIdArray
       
    51 // ---------------------------------------------------------
       
    52 //
       
    53 void TSortSnapUtils::InitDestIdArray()
       
    54     {
       
    55     CLOG_ENTERFN( "TSortSnapUtils::InitDestIdArray" );
       
    56     switch (iSSUState)
       
    57         {
       
    58         case EUseMPM:
       
    59             {
       
    60             // we already know that MPM is used
       
    61             CLOG_WRITE( "using MPM, no need to re-read from P&S " );
       
    62             break;
       
    63             }
       
    64         case EUninitialised:
       
    65         case EUsePubSub:
       
    66         default:
       
    67             {
       
    68             iSnapCount = 0;
       
    69             TMpmSnapPubSubFormat snapData;
       
    70             TPtr8 e( reinterpret_cast< TUint8* >( &snapData ), 
       
    71                      sizeof( snapData ) );
       
    72             for (TInt i = 0 ; i < KMPMSortSnapMaxKey; i++ )
       
    73                 {
       
    74                 TInt err = RProperty::Get( KMPMSortSnapCategory, 
       
    75                                            i, 
       
    76                                            e );
       
    77                CLOG_WRITEF( _L( "RProperty::Get returned: %d" ), err );
       
    78                CLOG_WRITEF( _L( "Snap Id: %d" ), snapData.iSnap );
       
    79                CLOG_WRITEF( _L( "Snap Number: %d" ), iSnapCount );
       
    80 
       
    81                 if (err == KErrNone)                            
       
    82                     {
       
    83                     iSnapIdArray[iSnapCount] = snapData.iSnap;
       
    84                     iSnapCount++;
       
    85                     }
       
    86                 }
       
    87             //determine what method to use:
       
    88             // we always have at least one snap element
       
    89             // in P&S
       
    90             // if we are called from MPM                
       
    91             if (iSnapCount)
       
    92                 {
       
    93                 CLOG_WRITE( "iSSUState = EUsePubSub " );
       
    94                 iSSUState = EUsePubSub;       
       
    95                 }
       
    96              else
       
    97                 {
       
    98                 CLOG_WRITE( "iSSUState = EUseMPM " );
       
    99                 iSSUState = EUseMPM;       
       
   100                 }
       
   101             }
       
   102         }
       
   103     CLOG_LEAVEFN( "TSortSnapUtils::InitDestIdArray" );
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------
       
   107 // TSortSnapUtils::GetDestIdArrayL
       
   108 // ---------------------------------------------------------
       
   109 //
       
   110 void TSortSnapUtils::GetDestIdArrayL( RCmManagerExt& aCmManagerExt, RArray<TUint32>& aDestArray )
       
   111     {
       
   112     CLOG_ENTERFN( "TSortSnapUtils::GetDestIdArrayL" );
       
   113     aDestArray.Reset();
       
   114     InitDestIdArray(); // re-read the values, set iSSUState
       
   115     switch (iSSUState)
       
   116         {
       
   117         case EUsePubSub:
       
   118             {
       
   119             CLOG_WRITE( "Using P&S " );
       
   120             // append from 1, do not append uncategorised destination!
       
   121             for ( TInt i = 1 ; i < iSnapCount; i++ )
       
   122                 {
       
   123                 aDestArray.Append( iSnapIdArray[i] );
       
   124                 CLOG_WRITEF( _L( "Appending to array: Snap Id: %d" ), iSnapIdArray[i] );                
       
   125                 }
       
   126             break;
       
   127             }
       
   128         case EUseMPM:
       
   129             {
       
   130             CLOG_WRITE( "Using MPM " );
       
   131             aCmManagerExt.AllDestinationsL( aDestArray );
       
   132             break;
       
   133             }
       
   134         case EUninitialised:
       
   135         default:
       
   136             {
       
   137             //should not ever happen, as we initialise at the beginning of the 
       
   138             // function
       
   139             User::Leave( KErrNotReady );
       
   140             }
       
   141         }
       
   142     CLOG_LEAVEFN( "TSortSnapUtils::GetDestIdArrayL" );
       
   143     }
       
   144 
       
   145 // ---------------------------------------------------------
       
   146 // TSortSnapUtils::GetSortSnapDataL()
       
   147 // ---------------------------------------------------------
       
   148 //
       
   149 TInt TSortSnapUtils::GetSortSnapData( TUint32 aSnapId, TMpmSnapBuffer& aSnapBuffer )
       
   150     {
       
   151     CLOG_ENTERFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   152     
       
   153     if (iSSUState ==  EUninitialised)
       
   154         {
       
   155         InitDestIdArray();
       
   156         }
       
   157     
       
   158     switch (iSSUState)
       
   159         {
       
   160         case EUsePubSub:
       
   161             {
       
   162             CLOG_WRITE( "Using P&S " );
       
   163             TMpmSnapPubSubFormat snapData;
       
   164             TPtr8 e( reinterpret_cast< TUint8* >( &snapData ), 
       
   165             sizeof( snapData ) );
       
   166             // initialize snap to invalid value
       
   167             snapData.iSnap = (TUint32) KErrNotFound;
       
   168             for ( TInt i = 0 ; i < iSnapCount; i++ )
       
   169                 {
       
   170                 if ( aSnapId == iSnapIdArray[i] )
       
   171                     {
       
   172                     
       
   173                     TInt err = RProperty::Get( KMPMSortSnapCategory, 
       
   174                                                i, 
       
   175                                                e );
       
   176                     CLOG_WRITEF( _L( "RProperty::Get returned: %d" ), err );
       
   177 
       
   178                     if (err == KErrNone)                            
       
   179                         {
       
   180                         if ( aSnapId == snapData.iSnap )
       
   181                             {
       
   182                             aSnapBuffer = snapData.iSortedIaps;
       
   183                             
       
   184                             CLOG_WRITEF( _L( "Found: Snap id: %d" ), snapData.iSnap );
       
   185                             CLOG_WRITEF( _L( "Iap count: %d" ), snapData.iSortedIaps.iCount );
       
   186                             
       
   187                             CLOG_LEAVEFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   188                             return KErrNone;
       
   189                             }
       
   190                         }
       
   191                     else
       
   192                         {
       
   193                         CLOG_LEAVEFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   194                         return err;
       
   195                         }
       
   196                     }
       
   197                 }
       
   198             break;    
       
   199             }
       
   200         case EUseMPM:
       
   201             {
       
   202             CLOG_WRITE( "Using MPM " );
       
   203             TInt errConnect = iMPM.Connect();
       
   204             CLOG_WRITEF( _L( "errConnect = %d" ), errConnect );
       
   205             if ( errConnect == KErrNone )
       
   206                 {
       
   207                 TInt err = iMPM.SortSNAP( aSnapId, aSnapBuffer ); 
       
   208                 iMPM.Close();
       
   209                 CLOG_LEAVEFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   210                 return err;       
       
   211                 }
       
   212             else
       
   213                 {
       
   214                 CLOG_LEAVEFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   215                 return errConnect;
       
   216                 }
       
   217             }
       
   218         case EUninitialised:
       
   219         default:
       
   220             {
       
   221             //should not ever happen, as we initialise at the beginning of the 
       
   222             // function            
       
   223             CLOG_LEAVEFN( "TSortSnapUtils::GetSortSnapDataL" );
       
   224             return KErrNotReady;
       
   225             }
       
   226         }
       
   227     return KErrNone;
       
   228     }
       
   229