connectivitymodules/SeCon/services/csc/src/caplist.cpp
branchRCL_3
changeset 20 4a793f564d72
equal deleted inserted replaced
19:0aa8cc770c8a 20:4a793f564d72
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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:  CCapList implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "caplist.h"
       
    22 #include "caputils.h"
       
    23 #include "capparser.h"
       
    24 #include "capability.h"
       
    25 #include "debug.h"
       
    26 
       
    27 // ============================= MEMBER FUNCTIONS ===============================
       
    28 
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // CCapList::NewL()
       
    32 // Two-phase constructor.
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 CCapList* CCapList::NewL()
       
    36     {
       
    37     CCapList* self = new(ELeave) CCapList();
       
    38     CleanupStack::PushL( self );
       
    39     self->ConstructL();
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 // -----------------------------------------------------------------------------
       
    45 // CCapList::~CCapList()
       
    46 // Gets phone serial number from etel.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CCapList::~CCapList()
       
    50     {
       
    51     delete iList;
       
    52     }
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CCapList::CCapList()
       
    56 // Constructor
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CCapList::CCapList()
       
    60     {
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CCapList::ConstructL()
       
    65 // Initializes the member data
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CCapList::ConstructL()
       
    69     {
       
    70     iList = CStringList::NewL();
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CCapList::List()
       
    75 // Returns the list
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CStringList* CCapList::List()
       
    79     {
       
    80     __ASSERT_DEBUG(iList, CapUtil::Panic(KErrGeneral));
       
    81     return iList;
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCapList::FindFromMark(TInt aId, TInt aType)
       
    86 // Find from mark
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 TInt CCapList::FindFromMark(TInt aId, TInt aType)
       
    90     {
       
    91     TInt mark = List()->Mark();
       
    92     TInt count= List()->Count();
       
    93     
       
    94     if ( mark >= count )
       
    95         {
       
    96         return KErrNotFound;
       
    97         }       
       
    98 
       
    99     TInt index=Find(aId, aType, mark);
       
   100     if ( index == KErrNotFound )
       
   101         {
       
   102         return KErrNotFound;
       
   103         }
       
   104         
       
   105 
       
   106     __ASSERT_DEBUG(index>=mark, CapUtil::Panic(KErrGeneral));
       
   107 
       
   108     List()->SetMark(index+1);
       
   109     return index;
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CCapList::FindServiceHeader()
       
   114 // Finds service xml-file identification header. This header must be the first 
       
   115 // line in every service file.
       
   116 // -----------------------------------------------------------------------------
       
   117 //
       
   118 TBool CCapList::FindServiceHeader()
       
   119     {
       
   120     TRACE_FUNC_ENTRY;
       
   121     if (List()->Count()<1)
       
   122         {
       
   123         LOGGER_WRITE( "CCapList::FindServiceHeader() : returned EFalse" );
       
   124         return EFalse;
       
   125         }
       
   126 
       
   127     TBuf<KBufSize> buf;
       
   128     TPtrC ptr=List()->ReadPtr(0);
       
   129     CapUtil::StrCopy(buf, ptr);
       
   130     buf.Trim();
       
   131     if (buf.Compare(KServiceHeader)==0)
       
   132         {
       
   133         LOGGER_WRITE( "CCapList::FindServiceHeader() : returned ETrue" );
       
   134         return ETrue;
       
   135         }       
       
   136     else
       
   137         {
       
   138         LOGGER_WRITE( "CCapList::FindServiceHeader() : returned EFalse" );
       
   139         return EFalse;
       
   140         }
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CCapList::FindServiceL(CStringList* aList)
       
   145 // Find service
       
   146 // -----------------------------------------------------------------------------
       
   147 //
       
   148 TBool CCapList::FindServiceL(CStringList* aList)
       
   149     {
       
   150     TRACE_FUNC_ENTRY;
       
   151     aList->Reset();
       
   152     List()->SetMark(0);
       
   153 
       
   154     if (!FindServiceHeader())
       
   155         {
       
   156         LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned EFalse" );
       
   157         return EFalse;
       
   158         }
       
   159         
       
   160 
       
   161     for (;;)
       
   162         {
       
   163         TInt start=FindFromMark(EService, TXmlParser::EElementBegin);
       
   164         TInt stop=FindFromMark(EService, TXmlParser::EElementEnd);
       
   165         
       
   166         if (start==KErrNotFound || stop==KErrNotFound || start>=stop)
       
   167             {
       
   168             break;
       
   169             }
       
   170                     
       
   171         aList->CopyL(List(), start, stop);
       
   172         }
       
   173 
       
   174     if (aList->Count()>0)
       
   175         {
       
   176         LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned ETrue" );
       
   177         return ETrue;
       
   178         }
       
   179     
       
   180     LOGGER_WRITE( "CCapList::FindServiceL(CStringList* aList) : returned EFalse" );   
       
   181     return EFalse;
       
   182     }
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 // CCapList::Find(TInt aId, TInt aType, TInt aIndex)
       
   186 // Find element
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 TInt CCapList::Find(TInt aId, TInt aType, TInt aIndex)
       
   190     {
       
   191     TInt count=List()->Count();
       
   192     if (aIndex<0 || aIndex>=count)
       
   193         {
       
   194         CapUtil::Panic(KErrArgument);
       
   195         }
       
   196         
       
   197     for (TInt i=aIndex; i<count; i++)
       
   198         {
       
   199         TPtrC ptr=List()->ReadPtr(i);
       
   200 
       
   201         TInt id=0;
       
   202         TInt type=0;
       
   203         
       
   204         CapParser::ParseElement(ptr, id, type);
       
   205         if (type==TXmlParser::EElementUnknown)
       
   206             {
       
   207             continue;  // invalid capability element
       
   208             }
       
   209 
       
   210         if (id==aId && aType==type)
       
   211             {
       
   212             return i;
       
   213             }
       
   214         }
       
   215     return KErrNotFound;
       
   216     }
       
   217 
       
   218 
       
   219 // End of files