devicediagnosticsfw/diagresultsdb/client/src/diagresultsdatabaseItem.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 CDiagResultsDatabaseItem
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32std.h> 
       
    20 
       
    21 #include "diagresultsdatabaseitem.h"
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // NewL.Used when creating the object from a stream that contains the
       
    25 // serialized object.
       
    26 // ---------------------------------------------------------------------------
       
    27 //  
       
    28 EXPORT_C CDiagResultsDatabaseItem* CDiagResultsDatabaseItem::NewL ( 
       
    29                                                         RReadStream& aStream )
       
    30     {
       
    31     CDiagResultsDatabaseItem* self = new( ELeave ) CDiagResultsDatabaseItem();
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL( aStream );
       
    34     CleanupStack::Pop();
       
    35     return self;
       
    36     }
       
    37     
       
    38 // ---------------------------------------------------------------------------
       
    39 // NewL. 
       
    40 // ---------------------------------------------------------------------------
       
    41 //        
       
    42 EXPORT_C CDiagResultsDatabaseItem* CDiagResultsDatabaseItem::NewL (
       
    43                                         TUid            aTestUid,
       
    44                                         TBool           aDependencyExecution,
       
    45                                         TResult         aResult,
       
    46                                         TTime           aStartTime,
       
    47                                         TTime           aEndTime,
       
    48                                         CBufFlat*       aDetailsData )
       
    49     {
       
    50     
       
    51     CDiagResultsDatabaseItem* self = new( ELeave ) CDiagResultsDatabaseItem( 
       
    52                                     aTestUid, aDependencyExecution, aResult, 
       
    53                                     aStartTime, aEndTime, aDetailsData );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // NewLC.
       
    59 // ---------------------------------------------------------------------------
       
    60 //   
       
    61 EXPORT_C CDiagResultsDatabaseItem* CDiagResultsDatabaseItem::NewLC (
       
    62                                         TUid            aTestUid,
       
    63                                         TBool           aDependencyExecution,
       
    64                                         TResult         aResult,
       
    65                                         TTime           aStartTime,
       
    66                                         TTime           aEndTime,
       
    67                                         CBufFlat*       aDetailsData )
       
    68     {
       
    69     CDiagResultsDatabaseItem* self = new( ELeave ) CDiagResultsDatabaseItem( 
       
    70                                         aTestUid, aDependencyExecution, aResult, 
       
    71                                         aStartTime, aEndTime, aDetailsData );
       
    72     CleanupStack::PushL( self );
       
    73     return self;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // NewL. Copy constructor
       
    78 // ---------------------------------------------------------------------------
       
    79 //   
       
    80 EXPORT_C CDiagResultsDatabaseItem* CDiagResultsDatabaseItem::NewL (
       
    81         const CDiagResultsDatabaseItem& aOriginal )
       
    82     {
       
    83     const CBufFlat* detailData = aOriginal.DetailsData();
       
    84 
       
    85     CBufFlat* detailDataCopy = NULL;
       
    86 
       
    87     if ( detailData )
       
    88         {
       
    89         detailDataCopy = CBufFlat::NewL( detailData->Size() );
       
    90         CleanupStack::PushL( detailDataCopy );
       
    91 
       
    92         TPtr8 ptr = detailDataCopy->Ptr( 0 );
       
    93         detailData->Read( 0, ptr );
       
    94         }
       
    95 
       
    96     CDiagResultsDatabaseItem* self = CDiagResultsDatabaseItem::NewL(
       
    97         aOriginal.TestUid(),
       
    98         aOriginal.WasDependency(),
       
    99         aOriginal.TestResult(),
       
   100         aOriginal.TimeStarted(),
       
   101         aOriginal.TimeCompleted(),
       
   102         detailDataCopy );
       
   103 
       
   104     if ( detailDataCopy )
       
   105         {
       
   106         CleanupStack::Pop( detailDataCopy );
       
   107         }
       
   108 
       
   109     return self;
       
   110     }
       
   111 
       
   112 // ConstructL.
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 void CDiagResultsDatabaseItem::ConstructL ( RReadStream& aStream )
       
   116     {
       
   117     InternalizeL( aStream );
       
   118     }
       
   119 
       
   120 // ---------------------------------------------------------------------------
       
   121 // Destructor.
       
   122 // ---------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C CDiagResultsDatabaseItem::~CDiagResultsDatabaseItem()
       
   125     {
       
   126     if ( iDetailsData )
       
   127         {
       
   128         iDetailsData->Reset();
       
   129         }
       
   130         
       
   131     delete iDetailsData;
       
   132     iDetailsData = NULL;
       
   133     }
       
   134 
       
   135 // ---------------------------------------------------------------------------
       
   136 // C++ default constructor.
       
   137 // ---------------------------------------------------------------------------
       
   138 //    
       
   139 CDiagResultsDatabaseItem::CDiagResultsDatabaseItem()
       
   140     {
       
   141     
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Getter.
       
   146 // ---------------------------------------------------------------------------
       
   147 // 
       
   148 EXPORT_C TUid CDiagResultsDatabaseItem::TestUid() const
       
   149     {
       
   150     return iTestUid;
       
   151     }
       
   152     
       
   153 // ---------------------------------------------------------------------------
       
   154 // Getter.
       
   155 // ---------------------------------------------------------------------------
       
   156 //
       
   157 EXPORT_C TBool CDiagResultsDatabaseItem::WasDependency() const
       
   158     {
       
   159     return iDependencyExecution;
       
   160     }
       
   161     
       
   162 // ---------------------------------------------------------------------------
       
   163 // Getter.
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 EXPORT_C CDiagResultsDatabaseItem::TResult 
       
   167                    CDiagResultsDatabaseItem::TestResult() const
       
   168     {
       
   169     return iResult;
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // Getter.
       
   174 // ---------------------------------------------------------------------------
       
   175 // 
       
   176 EXPORT_C TTime CDiagResultsDatabaseItem::TimeStarted() const
       
   177     {
       
   178     return iStartTime;
       
   179     }
       
   180 
       
   181 // ---------------------------------------------------------------------------
       
   182 // Getter.
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 EXPORT_C TTime CDiagResultsDatabaseItem::TimeCompleted() const
       
   186     {
       
   187     return iEndTime;
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Getter.
       
   192 // ---------------------------------------------------------------------------
       
   193 //  
       
   194 EXPORT_C const CBufFlat* CDiagResultsDatabaseItem::DetailsData() const
       
   195     {
       
   196     return iDetailsData;
       
   197     }
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // Externalize the object into writestream.
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 EXPORT_C void CDiagResultsDatabaseItem::ExternalizeL(
       
   204                                              RWriteStream& aStream ) const
       
   205     {
       
   206     aStream.WriteInt32L ( iTestUid.iUid );
       
   207     aStream.WriteUint8L ( iDependencyExecution );
       
   208     aStream.WriteInt16L ( iResult );
       
   209     
       
   210     WriteTimeToStreamL( aStream, iStartTime );
       
   211     WriteTimeToStreamL( aStream, iEndTime );
       
   212     
       
   213     if ( iDetailsData == NULL )
       
   214         {
       
   215         aStream.WriteUint32L ( 0 );
       
   216         }
       
   217     else 
       
   218         {
       
   219         aStream.WriteUint32L ( iDetailsData->Size() );
       
   220     
       
   221         if ( iDetailsData->Size() > 0 )
       
   222             {
       
   223             aStream.WriteL( iDetailsData->Ptr(0), iDetailsData->Size() );    
       
   224             }
       
   225         }
       
   226     }
       
   227 
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // Bytes are calculated from ExternalizeL method. (216 bits = 27 bytes).
       
   231 // 32 + 8 + 16 + 64 + 64 + 32 = 216 bits.
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C TInt CDiagResultsDatabaseItem::Size() const
       
   235     {
       
   236     if ( iDetailsData == NULL )
       
   237         {
       
   238         return 27;
       
   239         }
       
   240     
       
   241     return (27 + iDetailsData->Size() );
       
   242     }
       
   243 
       
   244 // ---------------------------------------------------------------------------
       
   245 // Internalize the object from a stream.
       
   246 // ---------------------------------------------------------------------------
       
   247 //
       
   248 EXPORT_C void CDiagResultsDatabaseItem::InternalizeL( RReadStream& aStream )
       
   249     {
       
   250     iTestUid = TUid::Uid( aStream.ReadInt32L () );
       
   251     iDependencyExecution = aStream.ReadUint8L(); 
       
   252     iResult = (TResult ) aStream.ReadInt16L();
       
   253     
       
   254     ReadTimeFromStreamL( aStream, iStartTime );
       
   255     ReadTimeFromStreamL( aStream, iEndTime );
       
   256     
       
   257     TInt size = aStream.ReadUint32L();
       
   258     
       
   259     if ( size == 0 )
       
   260         {
       
   261         iDetailsData = NULL;
       
   262         }
       
   263     else 
       
   264         {
       
   265         iDetailsData = CBufFlat::NewL( 50 );
       
   266         iDetailsData->ResizeL( size );
       
   267         }
       
   268     
       
   269     
       
   270     if ( size > 0 )
       
   271         {
       
   272         TPtr8 ptr = iDetailsData->Ptr(0);
       
   273         aStream.ReadL( ptr, size);    
       
   274         }
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // Helper function.
       
   279 // ---------------------------------------------------------------------------
       
   280 //    
       
   281 void CDiagResultsDatabaseItem::WriteTimeToStreamL( 
       
   282                                             RWriteStream& aStream, 
       
   283                                             const TTime& aTime ) const
       
   284     {
       
   285     TInt64 time = aTime.Int64(); 
       
   286  
       
   287     TInt32 low_time = I64LOW( time );
       
   288     TInt32 high_time = I64HIGH( time );
       
   289  
       
   290     aStream.WriteInt32L( low_time );
       
   291     aStream.WriteInt32L( high_time );
       
   292     }    
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // Helper function.
       
   296 // ---------------------------------------------------------------------------
       
   297 //
       
   298 void CDiagResultsDatabaseItem::ReadTimeFromStreamL( 
       
   299                                            RReadStream& aStream, 
       
   300                                            TTime& aTime ) 
       
   301     {
       
   302     TInt32 low_time = aStream.ReadInt32L();
       
   303     TInt32 high_time = aStream.ReadInt32L();
       
   304     
       
   305     TInt64 readTime = MAKE_TINT64(high_time,low_time);
       
   306     
       
   307     aTime = TTime(readTime);
       
   308     }  
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // Constructor that sets the values.
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 CDiagResultsDatabaseItem::CDiagResultsDatabaseItem (
       
   315                         TUid            aTestUid,
       
   316                         TBool           aDependencyExecution,
       
   317                         TResult         aResult,
       
   318                         TTime           aStartTime,
       
   319                         TTime           aEndTime,
       
   320                         CBufFlat*       aDetailsData )
       
   321     {
       
   322     iTestUid = aTestUid;
       
   323     iDependencyExecution = aDependencyExecution;
       
   324     iResult = aResult;
       
   325     iStartTime = aStartTime;
       
   326     iEndTime = aEndTime;
       
   327     iDetailsData = aDetailsData;
       
   328     }
       
   329     
       
   330   
       
   331     
       
   332