ncdengine/provider/server/src/ncdreport.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-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:   CNcdReport implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdreport.h"
       
    20 #include "catalogsdebug.h"
       
    21 #include "ncdpanics.h"
       
    22 #include "ncdnodeidentifier.h"
       
    23 #include "catalogsutils.h"
       
    24 #include "ncdreportmanager.h"
       
    25 #include "catalogsconnectionmethod.h"
       
    26 
       
    27 
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 // ---------------------------------------------------------------------------
       
    31 CNcdReport::~CNcdReport()
       
    32     {
       
    33     DLTRACEIN((""));
       
    34 
       
    35     delete iMetadataId;
       
    36     iTimeStamps.Reset();
       
    37     delete iAttributes;
       
    38     }
       
    39 
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 // ---------------------------------------------------------------------------
       
    44 void CNcdReport::ExternalizeL( RWriteStream& aStream )
       
    45     {
       
    46     DLTRACEIN((""));
       
    47     
       
    48     ExternalizeEnumL( iType, aStream );
       
    49     
       
    50     ExternalizeEnumL( iStatus.iStatus, aStream );
       
    51     aStream.WriteInt32L( iStatus.iErrorCode );
       
    52     
       
    53     aStream.WriteInt32L( iReportId );
       
    54     
       
    55     iMetadataId->ExternalizeL( aStream );
       
    56     
       
    57     iAccessPoint.ExternalizeL( aStream );
       
    58     
       
    59     DLTRACE(("Externalizing timestamps"));
       
    60     DASSERT( iTimeStamps.Count() == ENcdReportTimeInternal );
       
    61     for ( TInt i = 0; i < ENcdReportTimeInternal; ++i )
       
    62         {
       
    63         aStream << iTimeStamps[i];
       
    64         }
       
    65     iAttributes->ExternalizeL( aStream );
       
    66     DLTRACEOUT(("Externalization successful"));
       
    67     }
       
    68     
       
    69     
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 // ---------------------------------------------------------------------------
       
    74 void CNcdReport::InternalizeL( RReadStream& aStream )
       
    75     {
       
    76     DLTRACEIN((""));
       
    77     
       
    78     // iType is internalized by the report manager    
       
    79     InternalizeEnumL( iStatus.iStatus, aStream );
       
    80     iStatus.iErrorCode = aStream.ReadInt32L();
       
    81     
       
    82     iReportId = aStream.ReadInt32L();
       
    83     
       
    84     delete iMetadataId;
       
    85     iMetadataId = NULL;
       
    86     
       
    87     iMetadataId = CNcdNodeIdentifier::NewL( aStream );
       
    88         
       
    89     iAccessPoint.InternalizeL( aStream );    
       
    90         
       
    91     ResetTimeStampsL();
       
    92     DLTRACE(("Internalizing timestamps"));
       
    93     DASSERT( iTimeStamps.Count() == ENcdReportTimeInternal );
       
    94     for ( TInt i = 0; i < ENcdReportTimeInternal; ++i )
       
    95         {
       
    96         aStream >> iTimeStamps[i];
       
    97         }
       
    98     
       
    99     delete iAttributes;
       
   100     iAttributes = NULL;
       
   101     iAttributes = CNcdAttributes::NewL( 
       
   102         aStream, 
       
   103         ENcdReportAttributeInternal );
       
   104         
       
   105     DLTRACEOUT(("Internalization successful"));
       
   106     }
       
   107 
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Report type getter
       
   111 // ---------------------------------------------------------------------------
       
   112 const TNcdReportType& CNcdReport::ReportType() const
       
   113     {
       
   114     return iType;
       
   115     }
       
   116 
       
   117 
       
   118 // ---------------------------------------------------------------------------
       
   119 // Report id setter
       
   120 // ---------------------------------------------------------------------------
       
   121 void CNcdReport::SetReportId( const TNcdReportId& aReportId )
       
   122     {
       
   123     DLTRACEIN(("aReportId: %d", aReportId ));
       
   124     iReportId = aReportId;
       
   125     }
       
   126     
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // Report id getter
       
   130 // ---------------------------------------------------------------------------
       
   131 const TNcdReportId& CNcdReport::ReportId() const
       
   132     {
       
   133     return iReportId;    
       
   134     }
       
   135 
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // Attribute getter
       
   139 // ---------------------------------------------------------------------------
       
   140 CNcdAttributes& CNcdReport::Attributes()
       
   141     {
       
   142     DLTRACEIN((""));
       
   143     return *iAttributes;    
       
   144     }
       
   145 
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // Attribute getter
       
   149 // ---------------------------------------------------------------------------
       
   150 const CNcdAttributes& CNcdReport::Attributes() const
       
   151     {
       
   152     DLTRACEIN((""));
       
   153     return *iAttributes;    
       
   154     }
       
   155 
       
   156 
       
   157 // ---------------------------------------------------------------------------
       
   158 //
       
   159 // ---------------------------------------------------------------------------
       
   160 const TNcdReportStatusInfo& CNcdReport::Status() const
       
   161     {
       
   162     DLTRACEIN(("iStatus: %d", iStatus.iStatus));
       
   163     return iStatus;
       
   164     }
       
   165 
       
   166 
       
   167 // ---------------------------------------------------------------------------
       
   168 //
       
   169 // ---------------------------------------------------------------------------
       
   170 TInt CNcdReport::SetStatus( const TNcdReportStatusInfo& aStatus )
       
   171     {
       
   172     DLTRACEIN(("aStatus: %d", aStatus.iStatus));
       
   173     iStatus = aStatus;
       
   174     return KErrNone;
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 // ---------------------------------------------------------------------------
       
   180 TBool CNcdReport::Match( 
       
   181     const CNcdNodeIdentifier& aMetadataId,
       
   182     const TDesC& aGenericId,
       
   183     const TDesC& aReportUri,
       
   184     const TNcdReportType& aReportType ) const
       
   185     {
       
   186     return aMetadataId.Equals( *iMetadataId ) &&
       
   187         ( aGenericId == iAttributes->AttributeString16( 
       
   188             ENcdReportAttributeGenericId ) ) &&
       
   189         ( aReportUri == iAttributes->AttributeString16(
       
   190             ENcdReportAttributeReportUri ) &&
       
   191         ( aReportType == ReportType() ) );
       
   192     }
       
   193 
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // Linear order for reports
       
   197 // ---------------------------------------------------------------------------
       
   198 TInt CNcdReport::Compare( 
       
   199     const CNcdReport& aFirst,
       
   200     const CNcdReport& aSecond )
       
   201     {
       
   202     // Ordering is done so that reports that can be bundled together are
       
   203     // as close as possible
       
   204     
       
   205     // Zero means that items equal.
       
   206     TInt comp( 0 );
       
   207     
       
   208     // First compare that nodes are of the same type
       
   209     comp = aFirst.ReportType() - aSecond.ReportType();
       
   210     
       
   211     if ( comp == 0 )
       
   212         {
       
   213         // Compare report URIs    
       
   214         comp = aFirst.Attributes().AttributeString16( 
       
   215             ENcdReportAttributeReportUri).Compare( 
       
   216                 aSecond.Attributes().AttributeString16(
       
   217                         ENcdReportAttributeReportUri ) );
       
   218                 
       
   219         if ( comp == 0 ) 
       
   220             {
       
   221             // Compare generic IDs
       
   222             comp = aFirst.Attributes().AttributeString16( 
       
   223                 ENcdReportAttributeGenericId ).Compare( 
       
   224                     aSecond.Attributes().AttributeString16(
       
   225                         ENcdReportAttributeGenericId ) );
       
   226             if ( comp == 0 ) 
       
   227                 {
       
   228                 // Compare metadata's
       
   229                 comp = CNcdNodeIdentifier::Compare( 
       
   230                     aFirst.MetadataId(),
       
   231                     aSecond.MetadataId() );        
       
   232                 }
       
   233             }        
       
   234         }
       
   235     return comp;
       
   236     }
       
   237     
       
   238 
       
   239 // ---------------------------------------------------------------------------
       
   240 // Access point setter
       
   241 // ---------------------------------------------------------------------------
       
   242 void CNcdReport::SetAccessPoint( const TCatalogsConnectionMethod& aAp )
       
   243     {
       
   244     DLTRACEIN((""));    
       
   245     iAccessPoint = aAp;
       
   246     DLMETHOD( iAccessPoint );
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // Access point getter
       
   251 // ---------------------------------------------------------------------------
       
   252 const TCatalogsConnectionMethod& CNcdReport::ConnectionMethod() const
       
   253     {
       
   254     DLTRACEIN((""));   
       
   255     DLMETHOD( iAccessPoint );
       
   256     return iAccessPoint;        
       
   257     }
       
   258     
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 // ---------------------------------------------------------------------------
       
   263 const CNcdNodeIdentifier& CNcdReport::MetadataId() const
       
   264     {
       
   265     return *iMetadataId;
       
   266     }
       
   267     
       
   268 
       
   269 // ---------------------------------------------------------------------------
       
   270 // TimeStamp setter
       
   271 // ---------------------------------------------------------------------------
       
   272 void CNcdReport::SetTimeStamp( 
       
   273     const TNcdReportTimeStamps& aTimeStamp,
       
   274     const TTime& aTime )
       
   275     {
       
   276     DLTRACEIN(("aTimeStamp: %d, time: %Ld", aTimeStamp, aTime.Int64() ));    
       
   277     DASSERT( aTimeStamp < iTimeStamps.Count() );
       
   278     iTimeStamps[aTimeStamp] = aTime.Int64();
       
   279     }
       
   280     
       
   281 
       
   282 // ---------------------------------------------------------------------------
       
   283 // TimeStamp getter
       
   284 // ---------------------------------------------------------------------------
       
   285 const TInt64& CNcdReport::TimeStamp( 
       
   286     const TNcdReportTimeStamps& aTimeStamp ) const
       
   287     {
       
   288     DLTRACEIN(("aTimeStamp: %d", aTimeStamp));    
       
   289 
       
   290     DASSERT( aTimeStamp < iTimeStamps.Count() );
       
   291     DLTRACEOUT(("Time: %Ld", iTimeStamps[aTimeStamp] ));
       
   292     return iTimeStamps[aTimeStamp];
       
   293     }
       
   294 
       
   295 
       
   296 // ---------------------------------------------------------------------------
       
   297 // Reset the timestamp array
       
   298 // ---------------------------------------------------------------------------
       
   299 void CNcdReport::ResetTimeStampsL()
       
   300     {
       
   301     DLTRACEIN((""));
       
   302     iTimeStamps.Reset();
       
   303     iTimeStamps.ReserveL( ENcdReportTimeInternal );
       
   304     
       
   305     TInt64 zero = 0;
       
   306     for ( TInt i = 0; i < ENcdReportTimeInternal; ++i )
       
   307         {
       
   308         iTimeStamps.Append( zero );
       
   309         }
       
   310     DLTRACEOUT(("Time stamps reseted"));
       
   311     }
       
   312 
       
   313 // ---------------------------------------------------------------------------
       
   314 // Transaction getter
       
   315 // ---------------------------------------------------------------------------
       
   316 const MCatalogsHttpOperation* CNcdReport::ReportTransaction() const
       
   317     {
       
   318     return iReportTransaction;
       
   319     }
       
   320 
       
   321 
       
   322 // ---------------------------------------------------------------------------
       
   323 // Transaction setter
       
   324 // ---------------------------------------------------------------------------
       
   325 void CNcdReport::SetReportTransaction( 
       
   326     MCatalogsHttpOperation* aTransaction)
       
   327     {
       
   328     iReportTransaction = aTransaction;
       
   329     }
       
   330 
       
   331 
       
   332 // ---------------------------------------------------------------------------
       
   333 // Sets time stamp to current time
       
   334 // ---------------------------------------------------------------------------
       
   335 void CNcdReport::SetCurrentTime( const TNcdReportTimeStamps& aTime )
       
   336     {
       
   337     DLTRACEIN(("aTime: %d", aTime));
       
   338         
       
   339     TTime time;
       
   340     time.UniversalTime();
       
   341     SetTimeStamp( aTime, time );
       
   342     }
       
   343 
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // Calculates difference between given times in seconds
       
   347 // ---------------------------------------------------------------------------
       
   348 TInt CNcdReport::DurationInSecondsL( 
       
   349     const TNcdReportTimeStamps& aStart,
       
   350     const TNcdReportTimeStamps& aEnd ) const
       
   351     {
       
   352     DLTRACEIN((""));
       
   353     TTime start( TimeStamp( aStart ) );
       
   354     TTime end( TimeStamp( aEnd ) );
       
   355     TTimeIntervalSeconds duration;
       
   356     
       
   357     User::LeaveIfError( end.SecondsFrom( start, duration ) );
       
   358     DLTRACEOUT(("Duration: %d", duration.Int() ));
       
   359     return duration.Int();
       
   360     }
       
   361 
       
   362 
       
   363 // ---------------------------------------------------------------------------
       
   364 // Default implementation for CanBundle
       
   365 // ---------------------------------------------------------------------------
       
   366 TBool CNcdReport::CanBundle() const
       
   367     {
       
   368     DLTRACEIN((""));
       
   369     return EFalse;
       
   370     }
       
   371 
       
   372 
       
   373 // ---------------------------------------------------------------------------
       
   374 // Add report data
       
   375 // ---------------------------------------------------------------------------
       
   376 void CNcdReport::AddReportDataL( 
       
   377     CNcdRequestInstallation& /* aRequest */ ) const
       
   378     {
       
   379     DLTRACEIN((""));
       
   380     User::Leave( KErrNotSupported );    
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // PRIVATE METHODS
       
   385 // ---------------------------------------------------------------------------
       
   386 
       
   387 
       
   388 // ---------------------------------------------------------------------------
       
   389 // Constructor
       
   390 // ---------------------------------------------------------------------------
       
   391 CNcdReport::CNcdReport( 
       
   392     TNcdReportType aType, 
       
   393     CNcdReportManager& aReportManager,
       
   394     const TNcdReportStatusInfo& aStatus )
       
   395     : iType( aType ), 
       
   396       iReportManager( aReportManager ),
       
   397       iStatus( aStatus ),
       
   398       iReportId( KNcdReportNotSupported )
       
   399     {
       
   400     }
       
   401 
       
   402 
       
   403 // ---------------------------------------------------------------------------
       
   404 // ConstructL
       
   405 // ---------------------------------------------------------------------------
       
   406 void CNcdReport::BaseConstructL( 
       
   407     const CNcdNodeIdentifier& aMetadataId )
       
   408     {
       
   409     DLTRACEIN((""));
       
   410     
       
   411     iMetadataId = CNcdNodeIdentifier::NewL( aMetadataId );
       
   412     ResetTimeStampsL();
       
   413     iAttributes = CNcdAttributes::NewL( ENcdReportAttributeInternal );
       
   414         
       
   415     DLTRACEOUT((""));
       
   416     }
       
   417 
       
   418 
       
   419 // ---------------------------------------------------------------------------
       
   420 // ReportManager
       
   421 // ---------------------------------------------------------------------------
       
   422 const CNcdReportManager& CNcdReport::ReportManager() const
       
   423     {
       
   424     return iReportManager;
       
   425     }
       
   426 
       
   427 // ---------------------------------------------------------------------------
       
   428 // ReportManager
       
   429 // ---------------------------------------------------------------------------
       
   430 CNcdReportManager& CNcdReport::ReportManager()
       
   431     {
       
   432     return iReportManager;
       
   433     }
       
   434