devicediagnosticsfw/diagresultsdb/server/src/diagresultsdbtestrecordhandle.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 0 b497e44ab2fc
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
       
     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 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "diagresultsdbtestrecordhandle.h"
       
    20 #include "diagresultsdbrecordengineparam.h"
       
    21 
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // Constructor. 
       
    25 // ---------------------------------------------------------------------------
       
    26 // 
       
    27 CDiagResultsDbTestRecordHandle::CDiagResultsDbTestRecordHandle(
       
    28                                TStreamId aRecordUid, 
       
    29 	                           TUid aDbUid,
       
    30 	                           CDiagResultsDbRecordEngineParam* aEngineParam )
       
    31 	{
       
    32 	iRecordId = aRecordUid;
       
    33     RecordInfo().iRecordId = TUid::Uid(aRecordUid.Value());
       
    34 	RecordInfo().iDbUid = aDbUid;
       
    35 	iEngineParam = aEngineParam;
       
    36 	}
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // Constructor. 
       
    40 // ---------------------------------------------------------------------------
       
    41 // 
       
    42 CDiagResultsDbTestRecordHandle::CDiagResultsDbTestRecordHandle()
       
    43 	{
       
    44 	}
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // Return record ID.
       
    48 // ---------------------------------------------------------------------------
       
    49 // 
       
    50 TStreamId CDiagResultsDbTestRecordHandle::RecordId() const
       
    51     {
       
    52     return iRecordId;
       
    53     }
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // NewL.
       
    57 // ---------------------------------------------------------------------------
       
    58 // 
       
    59 CDiagResultsDbTestRecordHandle* CDiagResultsDbTestRecordHandle::NewL(
       
    60                                TStreamId aRecordUid, 
       
    61 	                           TUid aDbUid,
       
    62 	                           CDiagResultsDbRecordEngineParam* aEngineParam )
       
    63 	{
       
    64 	CDiagResultsDbTestRecordHandle* testrecord =	
       
    65 	    new (ELeave) CDiagResultsDbTestRecordHandle( 
       
    66 	                                            aRecordUid, 
       
    67 	                                            aDbUid,
       
    68 	                                            aEngineParam );
       
    69 	CleanupStack::PushL( testrecord );
       
    70 	testrecord->ConstructL();
       
    71 	CleanupStack::Pop();
       
    72 	return testrecord;
       
    73 	}
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // NewL.
       
    77 // ---------------------------------------------------------------------------
       
    78 // 
       
    79 CDiagResultsDbTestRecordHandle* CDiagResultsDbTestRecordHandle::NewL( RReadStream& aStream )
       
    80     {
       
    81     
       
    82     CDiagResultsDbTestRecordHandle* testrecord =	
       
    83 	    new (ELeave) CDiagResultsDbTestRecordHandle( );
       
    84 	CleanupStack::PushL( testrecord );
       
    85 	testrecord->ConstructL( aStream );
       
    86 	CleanupStack::Pop();
       
    87 	return testrecord;
       
    88     }
       
    89     
       
    90 
       
    91 // ---------------------------------------------------------------------------
       
    92 // ConstructL
       
    93 // ---------------------------------------------------------------------------
       
    94 //    
       
    95 void CDiagResultsDbTestRecordHandle::ConstructL( RReadStream& aStream )
       
    96     {
       
    97     InternalizeL ( aStream );
       
    98     }
       
    99    
       
   100    
       
   101 // ---------------------------------------------------------------------------
       
   102 // ConstructL. Set test record overview's DRM and home times.
       
   103 // ---------------------------------------------------------------------------
       
   104 // 
       
   105 void CDiagResultsDbTestRecordHandle::ConstructL()
       
   106 	{
       
   107 	//Time when this test record was created.
       
   108 	iTestRecordInfo.iDrmStartTime = 
       
   109 	                            TDiagResultsDatabaseTestRecordInfo::DRMTimeL();
       
   110 	iTestRecordInfo.iStartTime.HomeTime();
       
   111 	}
       
   112 
       
   113 
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Destructor. 
       
   117 // ---------------------------------------------------------------------------
       
   118 // 
       
   119 CDiagResultsDbTestRecordHandle::~CDiagResultsDbTestRecordHandle()
       
   120     {
       
   121     iHandleArray.Close();
       
   122     
       
   123     delete iEngineParam;
       
   124     iEngineParam = NULL;
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // Return record info.
       
   129 // ---------------------------------------------------------------------------
       
   130 //    
       
   131 TDiagResultsDatabaseTestRecordInfo& CDiagResultsDbTestRecordHandle::RecordInfo()
       
   132     {
       
   133     return iTestRecordInfo;
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Add one result handle into the record.
       
   139 // We can use aItem to search the item from the store.
       
   140 // ---------------------------------------------------------------------------
       
   141 //  
       
   142 void CDiagResultsDbTestRecordHandle::AddL( TTestResultHandle& aItem )
       
   143     {
       
   144     iTestRecordInfo.iTestCount++;
       
   145     iHandleArray.AppendL( aItem );
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // Return matching streamId.
       
   151 // ---------------------------------------------------------------------------
       
   152 //        
       
   153 const TStreamId& CDiagResultsDbTestRecordHandle::operator[] (TInt aIndex) const
       
   154     {
       
   155     return iHandleArray[aIndex].iStreamId;
       
   156     }
       
   157    
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // Get handle to a test result.
       
   161 // ---------------------------------------------------------------------------
       
   162 //     
       
   163 CDiagResultsDbTestRecordHandle::TTestResultHandle 
       
   164                         CDiagResultsDbTestRecordHandle::Get( TInt aIndex ) const
       
   165     {
       
   166     return iHandleArray[aIndex];
       
   167     }   
       
   168    
       
   169 // ---------------------------------------------------------------------------
       
   170 // Convert plug-in uid into stream id.
       
   171 // ---------------------------------------------------------------------------
       
   172 //  
       
   173  TInt CDiagResultsDbTestRecordHandle::MatchingStreamId( TUid aTestUid, TStreamId& aStreamId ) const
       
   174     {
       
   175      
       
   176     for ( TInt i=0; i < iHandleArray.Count(); ++i )
       
   177         {
       
   178         if ( iHandleArray[i].iTestUid == aTestUid )
       
   179             {
       
   180             aStreamId = iHandleArray[i].iStreamId;
       
   181             return KErrNone;
       
   182             }
       
   183         }    
       
   184     
       
   185     aStreamId = 0;
       
   186     return KErrNotFound;    
       
   187     }   
       
   188     
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // Returns count.
       
   192 // ---------------------------------------------------------------------------
       
   193 //     
       
   194 TInt CDiagResultsDbTestRecordHandle::Count() const
       
   195     {
       
   196     return iHandleArray.Count();
       
   197     }
       
   198    
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // Return the index of uid.
       
   202 // ---------------------------------------------------------------------------
       
   203 //       
       
   204 TInt CDiagResultsDbTestRecordHandle::FindIndex ( TUid aTestUid ) const
       
   205     {
       
   206     
       
   207     for ( TInt i=0; i < iHandleArray.Count(); ++i )
       
   208         {
       
   209         if ( iHandleArray[i].iTestUid == aTestUid )
       
   210             {
       
   211             return i;
       
   212             }
       
   213         }
       
   214         
       
   215     return KErrNotFound;
       
   216     }    
       
   217 
       
   218 // ---------------------------------------------------------------------------
       
   219 // Check does the uid exists in the array.
       
   220 // ---------------------------------------------------------------------------
       
   221 //     
       
   222 TBool CDiagResultsDbTestRecordHandle::Find ( TUid aTestUid ) const
       
   223     {
       
   224     
       
   225     for ( TInt i=0; i < iHandleArray.Count(); ++i )
       
   226         {
       
   227         if ( iHandleArray[i].iTestUid == aTestUid )
       
   228             {
       
   229             return ETrue;
       
   230             }
       
   231         }
       
   232         
       
   233     return EFalse;
       
   234     }      
       
   235    
       
   236    
       
   237 // ---------------------------------------------------------------------------
       
   238 // Remove result handle from the array.
       
   239 // ---------------------------------------------------------------------------
       
   240 //    
       
   241 void CDiagResultsDbTestRecordHandle::RemoveL( TStreamId& aItem )
       
   242     {
       
   243     
       
   244     for (TInt i=0; i < iHandleArray.Count(); ++i)
       
   245         {
       
   246         if ( iHandleArray[i].iStreamId == aItem )
       
   247             {
       
   248             iHandleArray.Remove( i );
       
   249             break;
       
   250             }
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // Remove result handle from the array.
       
   257 // ---------------------------------------------------------------------------
       
   258 //    
       
   259 void  CDiagResultsDbTestRecordHandle::RemoveL( TUid aItemUid )
       
   260     {
       
   261      for (TInt i=0; i < iHandleArray.Count(); ++i)
       
   262         {
       
   263         if ( iHandleArray[i].iTestUid == aItemUid )
       
   264             {
       
   265             iHandleArray.Remove( i );
       
   266             break;
       
   267             }
       
   268         }
       
   269     }
       
   270 
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // Update one result handle. This can be done when one stream(test result)
       
   274 // is moved into the last results buffer.
       
   275 // ---------------------------------------------------------------------------
       
   276 //  
       
   277 void CDiagResultsDbTestRecordHandle::UpdateL( TTestResultHandle& aResultHandle )
       
   278     {
       
   279     TInt index = FindIndex( aResultHandle.iTestUid );
       
   280     
       
   281     if ( index != KErrNone )
       
   282         {
       
   283         User::Leave( KErrNotFound );
       
   284         }
       
   285         
       
   286     iHandleArray[index] = aResultHandle;    
       
   287     }
       
   288 
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // Simple Get.
       
   292 // ---------------------------------------------------------------------------
       
   293 //  
       
   294 const CDiagResultsDbRecordEngineParam& CDiagResultsDbTestRecordHandle::GetEngineParam() const
       
   295     {
       
   296     return *iEngineParam;
       
   297     }
       
   298   
       
   299   
       
   300 // ---------------------------------------------------------------------------
       
   301 // Externalize Handle into a stream. Typically this is used when
       
   302 // handle is externalized into the store.
       
   303 // ---------------------------------------------------------------------------
       
   304 //   
       
   305 void CDiagResultsDbTestRecordHandle::ExternalizeL( RWriteStream& aStream ) const
       
   306     {
       
   307     iRecordId.ExternalizeL( aStream );
       
   308     iTestRecordInfo.ExternalizeL( aStream );
       
   309     
       
   310     TInt count =  Count();
       
   311     aStream.WriteInt16L( count );
       
   312     
       
   313     for (TInt i = 0; i < count; ++i)
       
   314         {
       
   315         // Write the streamId
       
   316         iHandleArray[i].iStreamId.ExternalizeL( aStream ); 
       
   317         // Write the plug-uid
       
   318         aStream.WriteInt32L( iHandleArray[i].iTestUid.iUid ); 
       
   319         }
       
   320         
       
   321     iEngineParam->ExternalizeL(aStream);
       
   322     } 
       
   323 
       
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // Internalize from a stream. Typically this is used when handle is read
       
   327 // from the store.
       
   328 // ---------------------------------------------------------------------------
       
   329 //     
       
   330 void CDiagResultsDbTestRecordHandle::InternalizeL( RReadStream& aStream )
       
   331     {
       
   332     iRecordId.InternalizeL( aStream );
       
   333     iTestRecordInfo.InternalizeL( aStream );
       
   334     
       
   335     TInt count = aStream.ReadInt16L();
       
   336     
       
   337     for (TInt i = 0; i < count; ++i)
       
   338         {
       
   339         TTestResultHandle handle;
       
   340         handle.iStreamId.InternalizeL( aStream );
       
   341         handle.iTestUid.iUid = aStream.ReadInt32L();
       
   342         iHandleArray.Append( handle );
       
   343         }
       
   344     
       
   345     iEngineParam = CDiagResultsDbRecordEngineParam::NewL ( aStream );
       
   346     
       
   347     }
       
   348             
       
   349