ncdengine/provider/server/src/ncdserversubscribablecontent.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ncdserversubscribablecontent.h"
       
    20 #include "ncd_pp_dataentitycontent.h"
       
    21 #include "catalogsutils.h"
       
    22 
       
    23 CNcdServerSubscribableContent::CNcdServerSubscribableContent()
       
    24     {
       
    25     }
       
    26 
       
    27 void CNcdServerSubscribableContent::ConstructL()
       
    28     {
       
    29     ResetMemberVariables();
       
    30     }
       
    31 
       
    32 CNcdServerSubscribableContent* CNcdServerSubscribableContent::NewL()
       
    33     {
       
    34     CNcdServerSubscribableContent* self = NewLC();
       
    35     CleanupStack::Pop( self );
       
    36     return self;
       
    37     }
       
    38 
       
    39 CNcdServerSubscribableContent* CNcdServerSubscribableContent::NewLC()
       
    40     {
       
    41     CNcdServerSubscribableContent* self =
       
    42         new (ELeave) CNcdServerSubscribableContent;
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     return self;
       
    46     }
       
    47 
       
    48 CNcdServerSubscribableContent::~CNcdServerSubscribableContent()
       
    49     {
       
    50     ResetMemberVariables();
       
    51     }
       
    52 
       
    53 
       
    54 void CNcdServerSubscribableContent::InternalizeL(
       
    55     const MNcdPreminetProtocolDataEntityContent& aData )
       
    56     {
       
    57     // Current time saved in the beginning for later use.
       
    58     // Done as soon as possible so it won't be too long
       
    59     // after message is received from the server and delta
       
    60     // values are hopefully still valid.
       
    61     TTime now;
       
    62     now.HomeTime();
       
    63 
       
    64     ResetMemberVariables();
       
    65 
       
    66 
       
    67     TInt validUntilDelta = aData.ValidUntilDelta();
       
    68     // If validuntil is zero, it is determined to mean
       
    69     // that the validuntil was not received and is not in use
       
    70     if ( validUntilDelta > 0 )
       
    71         {
       
    72         iValidUntilSet = ETrue;
       
    73         }
       
    74     
       
    75     
       
    76     // validUntilDelta is in minutes so we use TTimeIntervalMinutes
       
    77     // to reprsent the interval
       
    78     TTimeIntervalMinutes validUntilInterval( validUntilDelta );        
       
    79     iValidUntil = now + validUntilInterval;
       
    80 
       
    81     
       
    82     TNcdSubscriptionType tmpType = aData.SubscriptionType();
       
    83     DASSERT( tmpType != ENotSubscribable );
       
    84     
       
    85     switch( tmpType )
       
    86         {
       
    87         case EPeriodic:
       
    88             iSubscriptionType = MNcdSubscription::EPeriodic;
       
    89             break;
       
    90 
       
    91         case EAutomaticContinous:
       
    92             iSubscriptionType = MNcdSubscription::EAutomaticContinous;
       
    93             break;
       
    94 
       
    95         default:
       
    96             DASSERT( false ); // Should not end up here
       
    97             break;
       
    98         }
       
    99 
       
   100     
       
   101     iChildSeparatelyPurchasable = aData.ChildSeparatelyPurchasable();
       
   102     }
       
   103 
       
   104 void CNcdServerSubscribableContent::ExternalizeL( RWriteStream& aStream )
       
   105     {
       
   106     const TInt64& intValidUntil = iValidUntil.Int64();
       
   107     aStream << intValidUntil;
       
   108     aStream.WriteInt32L( iValidUntilSet );
       
   109 
       
   110     aStream.WriteInt32L( iSubscriptionType );    
       
   111     aStream.WriteInt32L( iChildSeparatelyPurchasable );
       
   112     }
       
   113 
       
   114 void CNcdServerSubscribableContent::InternalizeL( RReadStream& aStream )
       
   115     {
       
   116     ResetMemberVariables();
       
   117     
       
   118     TInt64 intValidUntil( 0 );
       
   119     aStream >> intValidUntil;
       
   120     iValidUntil = intValidUntil;
       
   121     iValidUntilSet = aStream.ReadInt32L();    
       
   122     
       
   123     iSubscriptionType = 
       
   124         static_cast<MNcdSubscription::TType>(aStream.ReadInt32L());
       
   125         
       
   126     iChildSeparatelyPurchasable = aStream.ReadInt32L();
       
   127     }
       
   128 
       
   129 
       
   130 MNcdSubscription::TType
       
   131     CNcdServerSubscribableContent::SubscriptionType() const
       
   132     {
       
   133     return iSubscriptionType;
       
   134     }
       
   135 
       
   136     
       
   137 void CNcdServerSubscribableContent::ResetMemberVariables()
       
   138     {
       
   139     iValidUntil = 0;
       
   140     iValidUntilSet = EFalse;
       
   141     
       
   142     // It does not matter so much which type of the subscription is used
       
   143     // as the initial value. Probably if it is of any type that is incorrect
       
   144     // things are not looking great.
       
   145     
       
   146     iChildSeparatelyPurchasable = ETrue;    
       
   147     }