devicediagnosticsfw/diagpluginbase/src/diagresultdetailbasic.cpp
changeset 32 5d0ec111abfc
parent 27 2c8580950a26
child 35 0deca9b72b62
equal deleted inserted replaced
27:2c8580950a26 32:5d0ec111abfc
     1 /*
       
     2 * Copyright (c) 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 definition of CDiagResultDetailBasic
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // CLASS DECLARATION
       
    20 #include "diagresultdetailbasicitem.h"  // CDiagResultDetailBasicItem
       
    21 
       
    22 // SYSTEM INCLUDE FILES
       
    23 #include <DiagResultDetailBasic.h>
       
    24 #include <s32mem.h>                     // RBufReadStream / RBufWriteStream
       
    25 
       
    26 // USER INCLUDE FILES
       
    27 #include "diagpluginbase.pan"           // panic codes
       
    28 
       
    29 
       
    30 // CONSTANTS
       
    31 static const TInt KDiagResultDetailBasicBufferSize = 1024;
       
    32 
       
    33 // ======== LOCAL FUNCTIONS ========
       
    34 // ---------------------------------------------------------------------------
       
    35 // Compares two items by order field id
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 static TInt CompareItemById( const CDiagResultDetailBasicItem& aFirst,
       
    39                              const CDiagResultDetailBasicItem& aSecond )
       
    40     {
       
    41     return aFirst.FieldId() - aSecond.FieldId();
       
    42     }
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 // ---------------------------------------------------------------------------
       
    46 // CDiagResultDetailBasic::CDiagResultDetailBasic()
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CDiagResultDetailBasic::CDiagResultDetailBasic( 
       
    50         CDiagResultsDatabaseItem::TResult aResult )
       
    51     :   iResult( aResult )
       
    52     {
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CDiagResultDetailBasic::~CDiagResultDetailBasic()
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 EXPORT_C CDiagResultDetailBasic::~CDiagResultDetailBasic()
       
    60     {
       
    61     iFields.ResetAndDestroy();
       
    62     iFields.Close();
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CDiagResultDetailBasic::BaseConstructL
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 EXPORT_C void CDiagResultDetailBasic::BaseConstructL( RReadStream& aReadStream )
       
    70     {
       
    71     InternalizeL( aReadStream );
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CDiagResultDetailBasic::BaseConstructL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 EXPORT_C void CDiagResultDetailBasic::BaseConstructL( const CBufFlat& aBuf )
       
    79     {
       
    80     // if empty buffer, do nothing.
       
    81     if ( aBuf.Size() == 0 )
       
    82         {
       
    83         return;
       
    84         }
       
    85 
       
    86     RBufReadStream readStream;
       
    87 
       
    88     readStream.Open( aBuf, 0 );
       
    89 
       
    90     InternalizeL( readStream );
       
    91 
       
    92     readStream.Close();
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CDiagResultDetailBasic::SetResult()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 EXPORT_C void CDiagResultDetailBasic::SetResult( 
       
   100         CDiagResultsDatabaseItem::TResult aResult )
       
   101     {
       
   102     iResult = aResult;
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CDiagResultDetailBasic::SetValueL
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 EXPORT_C void CDiagResultDetailBasic::SetValueL( TInt aFieldId,
       
   110                                                  const TDesC8& aFieldName,
       
   111                                                  TInt aValue )
       
   112     {
       
   113     CDiagResultDetailBasicItem* newItem = CDiagResultDetailBasicItem::NewL( 
       
   114         aFieldId,
       
   115         aFieldName,
       
   116         aValue );
       
   117 
       
   118     // no need to call clean up stack since ownership is
       
   119     // transferred.
       
   120     SetItemL( newItem );
       
   121     newItem = NULL;
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CDiagResultDetailBasic::SetValueL
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C void CDiagResultDetailBasic::SetValueL( TInt aFieldId,
       
   130                                                  const TDesC8& aFieldName,
       
   131                                                  const TDesC8& aValue )
       
   132                 
       
   133     {
       
   134     CDiagResultDetailBasicItem* newItem = CDiagResultDetailBasicItem::NewL( 
       
   135         aFieldId,
       
   136         aFieldName,
       
   137         aValue );
       
   138     
       
   139     // no need to call clean up stack since ownership is
       
   140     // transferred.
       
   141     SetItemL( newItem );
       
   142     newItem = NULL;
       
   143     }
       
   144 
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CDiagResultDetailBasic::SetValueL
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C void CDiagResultDetailBasic::SetValueL( TInt aFieldId,
       
   151                                                  const TDesC8& aFieldName,
       
   152                                                  const TDesC16& aValue )
       
   153                 
       
   154     {
       
   155     CDiagResultDetailBasicItem* newItem = CDiagResultDetailBasicItem::NewL( 
       
   156         aFieldId,
       
   157         aFieldName,
       
   158         aValue );
       
   159     
       
   160     // no need to call clean up stack since ownership is
       
   161     // transferred.
       
   162     SetItemL( newItem );
       
   163     newItem = NULL;
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 // CDiagResultDetailBasic::GetValue
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 EXPORT_C TInt CDiagResultDetailBasic::GetValue( TInt aFieldId,
       
   172                                                 TInt& aValue ) const
       
   173     {
       
   174     TInt itemIndex = FindItem( aFieldId );
       
   175 
       
   176     if ( itemIndex < 0 )
       
   177         {
       
   178         // item not found
       
   179         return KErrNotFound;
       
   180         }
       
   181 
       
   182     return iFields[itemIndex]->GetValue( aValue );
       
   183     }
       
   184 
       
   185 // ---------------------------------------------------------------------------
       
   186 // CDiagResultDetailBasic::GetValueL
       
   187 // ---------------------------------------------------------------------------
       
   188 //
       
   189 EXPORT_C TInt CDiagResultDetailBasic::GetValue( TInt aFieldId,
       
   190                                                 TPtrC8& aValue ) const
       
   191     {
       
   192     TInt itemIndex = FindItem( aFieldId );
       
   193 
       
   194     if ( itemIndex < 0 )
       
   195         {
       
   196         // item not found
       
   197         return KErrNotFound;
       
   198         }
       
   199     
       
   200     return iFields[itemIndex]->GetValue( aValue );
       
   201     }
       
   202 
       
   203 // ---------------------------------------------------------------------------
       
   204 // CDiagResultDetailBasic::GetValueL
       
   205 // ---------------------------------------------------------------------------
       
   206 //
       
   207 EXPORT_C TInt CDiagResultDetailBasic::GetValue( TInt aFieldId,
       
   208                                                 TPtrC16& aValue ) const
       
   209     {
       
   210     TInt itemIndex = FindItem( aFieldId );
       
   211 
       
   212     if ( itemIndex < 0 )
       
   213         {
       
   214         // item not found
       
   215         return KErrNotFound;
       
   216         }
       
   217     
       
   218     return iFields[itemIndex]->GetValue( aValue );
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // CDiagResultDetailBasic::InternalizeL
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CDiagResultDetailBasic::InternalizeL( RReadStream& aReadStream )
       
   226     {
       
   227     iFields.ResetAndDestroy();
       
   228 
       
   229     // Make sure that we are dealing with the correct version of data format.
       
   230     TUint32 version = aReadStream.ReadUint32L();
       
   231 
       
   232     if ( version != ( TUint32 )KDiagResultDetailBasicVersion )
       
   233         {
       
   234         User::Leave( KErrCorrupt );
       
   235         }
       
   236 
       
   237     // Read the number of items in the list.
       
   238     TUint32 count = aReadStream.ReadUint32L();
       
   239 
       
   240     // Read each item
       
   241     for ( TUint i = 0; i < count; i++ )
       
   242         {
       
   243         CDiagResultDetailBasicItem* newItem = 
       
   244             CDiagResultDetailBasicItem::NewL( aReadStream );
       
   245 
       
   246         SetItemL( newItem ); // ownership passed.
       
   247         }
       
   248     }
       
   249 
       
   250 
       
   251 // ---------------------------------------------------------------------------
       
   252 // CDiagResultDetailBasic::ExternalizeL
       
   253 // ---------------------------------------------------------------------------
       
   254 //
       
   255 EXPORT_C void CDiagResultDetailBasic::ExternalizeL(
       
   256         RWriteStream& aWriteStream ) const
       
   257     {
       
   258     // write only if there is something to write..
       
   259     if ( iFields.Count() > 0 )
       
   260         {
       
   261         aWriteStream.WriteUint32L( KDiagResultDetailBasicVersion );
       
   262         aWriteStream.WriteUint32L( iFields.Count() );
       
   263 
       
   264         for ( TInt i = 0; i < iFields.Count(); i++ )
       
   265             {
       
   266             iFields[i]->ExternalizeL( aWriteStream );
       
   267             }
       
   268         }
       
   269     }
       
   270 
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CDiagResultDetailBasic::ExternalizeToBufferL
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 EXPORT_C CBufFlat* CDiagResultDetailBasic::ExternalizeToBufferL() const
       
   277     {
       
   278     CBufFlat* buffer = CBufFlat::NewL( KDiagResultDetailBasicBufferSize );
       
   279 
       
   280     CleanupStack::PushL( buffer );
       
   281 
       
   282     RBufWriteStream bufStream;
       
   283     bufStream.Open( *buffer );
       
   284 
       
   285     ExternalizeL( bufStream );
       
   286 
       
   287     bufStream.CommitL();
       
   288     bufStream.Close();
       
   289 
       
   290     CleanupStack::Pop( buffer );
       
   291 
       
   292     return buffer;
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // CDiagResultDetailBasic::GetSupportedOutput
       
   298 // ---------------------------------------------------------------------------
       
   299 //
       
   300 EXPORT_C void CDiagResultDetailBasic::GetSupportedOutput(
       
   301         RArray<TOutputFormat>& /* aOutputList */ ) const
       
   302     {
       
   303     }
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // CDiagResultDetailBasic::IsOutputSupported
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 EXPORT_C TBool CDiagResultDetailBasic::IsOutputSupported(
       
   310         MDiagResultDetail::TOutputFormat /* aOutputFormat */ ) const
       
   311     {
       
   312     return EFalse;
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CDiagResultDetailBasic::GetOutputL
       
   317 // ---------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C void CDiagResultDetailBasic::GetOutputL(
       
   320         MDiagResultDetail::TOutputFormat /* aOutputFormat */,
       
   321         RBuf& /* aBuffer */ ) const
       
   322     {
       
   323     User::Leave( KErrNotSupported );
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // CDiagResultDetailBasic::CreateIconL
       
   328 // ---------------------------------------------------------------------------
       
   329 //
       
   330 EXPORT_C CGulIcon* CDiagResultDetailBasic::CreateIconL() const
       
   331     {
       
   332     User::Leave( KErrNotSupported );
       
   333     return NULL;
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CDiagResultDetailBasic::SetItemL
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CDiagResultDetailBasic::SetItemL( CDiagResultDetailBasicItem* aNewItem )
       
   341     {
       
   342     // Check if an item with same field id already exists.
       
   343     TInt itemIndex = FindItem( aNewItem->FieldId() );
       
   344     
       
   345     if ( itemIndex >= 0 )
       
   346         {
       
   347         // duplicate found. Remove old one.
       
   348         CDiagResultDetailBasicItem* oldItem = iFields[itemIndex];
       
   349         iFields.Remove( itemIndex );
       
   350         delete oldItem;
       
   351         }
       
   352 
       
   353     CleanupStack::PushL( aNewItem );
       
   354     TLinearOrder<CDiagResultDetailBasicItem> order( *CompareItemById );
       
   355 
       
   356     // if a duplicate item is still found, leave.
       
   357     User::LeaveIfError( iFields.InsertInOrder( aNewItem, order ) );
       
   358     CleanupStack::Pop( aNewItem );
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CDiagResultDetailBasic::FindItem
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 TInt CDiagResultDetailBasic::FindItem( TInt aFieldId ) const
       
   366     {
       
   367     for ( TInt i = 0; i < iFields.Count(); i++ )
       
   368         {
       
   369         if ( iFields[i]->FieldId() == aFieldId )
       
   370             {
       
   371             return i;
       
   372             }
       
   373         }
       
   374     return -1;
       
   375     }
       
   376 
       
   377 // End of File
       
   378