ncdengine/provider/server/inc/ncdsubscriptionimpl.h
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:   Contains CNcdSubscription class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef NCD_SUBSCRIPTION_IMPL_H
       
    20 #define NCD_SUBSCRIPTION_IMPL_H
       
    21 
       
    22 
       
    23 // For streams
       
    24 #include <s32mem.h>
       
    25 
       
    26 #include "catalogscommunicable.h"
       
    27 #include "ncdstoragedataitem.h"
       
    28 #include "ncdnodeclassids.h"
       
    29 #include "ncdsubscription.h"
       
    30 
       
    31 class MNcdPreminetProtocolSubscription;
       
    32 class CNcdPurchaseOptionImpl;
       
    33 class CNcdSubscriptionGroup;
       
    34 
       
    35 /**
       
    36  *  This server side class contains the data and the functionality
       
    37  *  that the proxy objects will use to internalize itself.
       
    38  *
       
    39  *  This object should be added to the session. So, it will be usable
       
    40  *  in the proxy side by using the handle gotten during addition. 
       
    41  *  The handle is used to identify to what object the proxy directs 
       
    42  *  the function call.  When objects are added to sessions, 
       
    43  *  multiple handles may be gotten for the same object if addition is 
       
    44  *  done multiple times.
       
    45  *
       
    46  *  @lib ?library
       
    47  *  @since S60 ?S60_version *** for example, S60 v3.0
       
    48  */
       
    49 class CNcdSubscription : public CCatalogsCommunicable,
       
    50                          public MNcdStorageDataItem
       
    51     {
       
    52 
       
    53 public:
       
    54     /**
       
    55      * NewL
       
    56      *
       
    57      * @param aParentGroup The parent subscription group.
       
    58      * @return CNcdSubscription* Pointer to the created object 
       
    59      * of this class.
       
    60      */
       
    61     static CNcdSubscription* NewL( CNcdSubscriptionGroup& aParentGroup);
       
    62 
       
    63     /**
       
    64      * NewLC
       
    65      *
       
    66      * @param aParentGroup The parent subscription group.
       
    67      * @return CNcdSubscription* Pointer to the created object 
       
    68      * of this class.
       
    69      */
       
    70     static CNcdSubscription* NewLC( CNcdSubscriptionGroup& aParentGroup);
       
    71 
       
    72     /**
       
    73      * Destructor
       
    74      *
       
    75      * @note Because this is CCatalogsCommunicable function the
       
    76      * session that owns this object should delete this class object.
       
    77      * So, instead of directly deleting this object from some other
       
    78      * class. Close-method should be used instead.
       
    79      */
       
    80     virtual ~CNcdSubscription();
       
    81 
       
    82     /**
       
    83      * Function to query name of the subscription.
       
    84      *
       
    85      * @return Name of the subscription.
       
    86      */    
       
    87     const TDesC& SubscriptionName() const;
       
    88     
       
    89     /**
       
    90      * Function to set a new name for the subscription.
       
    91      *
       
    92      * @param aNewName New name for the subscription.
       
    93      */    
       
    94     void SetSubscriptionNameL( const TDesC& aNewName );
       
    95 
       
    96     /**
       
    97      * Function to query purchaseoption that identifies subscription
       
    98      * from other subscriptions of same dataentity. 
       
    99      *
       
   100      * @return Purchaseoption that identifies this subscription.
       
   101      */
       
   102     const TDesC& PurchaseOptionId() const;
       
   103 
       
   104     
       
   105     /**
       
   106      * Returns the parent subscription group of this subscription.
       
   107      *
       
   108      * @return The parent group.
       
   109      */
       
   110     CNcdSubscriptionGroup& ParentGroup() const;
       
   111 
       
   112     /**
       
   113      * Return the type of the subscription.
       
   114      *
       
   115      * @return The subscription type.
       
   116      */
       
   117     MNcdSubscription::TType SubscriptionType() const;
       
   118 
       
   119     /**
       
   120      * This function is called when the owner of this object
       
   121      * wants to internalize the content according to the
       
   122      * purchaseoption used to buy this subscription.
       
   123      *
       
   124      * @note Assumed to be used after purchase of a new subscription.
       
   125      *       Some data acquired earlier, for example by using
       
   126      *       InternalizeL with protocol parameter, is lost if this
       
   127      *       function is called. That is why this function should
       
   128      *       be called first.
       
   129      * 
       
   130      * @param aData Data from purchaseoption that is used to initialize
       
   131      *              this subscription.
       
   132      *
       
   133      * @exception KErrArgument Given purchaseoption does not
       
   134      *                         contain subscription information.
       
   135      * @exception Leave System wide error code.
       
   136      */
       
   137     void InternalizeL( const CNcdPurchaseOptionImpl& aData );
       
   138 
       
   139 
       
   140     /**
       
   141      * This function is called when the owner of this object
       
   142      * wants to internalize the content according to the
       
   143      * updated subscription data that has been received from
       
   144      * the parser.
       
   145      *
       
   146      * @note This function cannot be used to internalize fully
       
   147      *       subsription object because the protocol-object does
       
   148      *       not contain all info. At the moment such info is
       
   149      *       the name of the subscription that does not exist
       
   150      *       in the protocol element.
       
   151      * 
       
   152      * @param aData The data is set in the protocol parser and can
       
   153      *              be used to initialize this class object.
       
   154      */
       
   155     void InternalizeL( MNcdPreminetProtocolSubscription& aData );
       
   156 
       
   157 
       
   158     /**
       
   159      * This function is called to set internal flag of the subscription
       
   160      * to inform whether the subscription has been recently updated or
       
   161      * not.
       
   162      *
       
   163      * @param aNewState New state for the recently updated flag.
       
   164      *
       
   165      */
       
   166     void SetRecentlyUpdated( TBool aNewState );
       
   167 
       
   168     /**
       
   169      * This function returns the information whether the subscription
       
   170      * has been recently updated or not.
       
   171      *
       
   172      * @return aNewState New state for the recently updated flag.
       
   173      */    
       
   174     TBool RecentlyUpdated() const;
       
   175     
       
   176     
       
   177 public: // MNcdStorageDataItem 
       
   178 
       
   179     // These functions are used to get the data from and to insert the data
       
   180     // into the database using by the given stream.
       
   181 
       
   182     /**
       
   183      * @see MNcdStorageDataItem::ExternalizeL
       
   184      */
       
   185     virtual void ExternalizeL( RWriteStream& aStream );
       
   186 
       
   187 
       
   188     /**
       
   189      * @see MNcdStorageDataItem::InternalizeL
       
   190      */
       
   191     virtual void InternalizeL( RReadStream& aStream );
       
   192 
       
   193 
       
   194 
       
   195 public: // CCatalogsCommunicable
       
   196 
       
   197     /**
       
   198      * @see CCatalogsCommunicable::ReceiveMessage
       
   199      */
       
   200     virtual void ReceiveMessage( MCatalogsBaseMessage* aMessage,
       
   201                                  TInt aFunctionNumber );
       
   202 
       
   203     /**
       
   204      * @see CCatalogsCommunicable::CounterPartLost
       
   205      */
       
   206     virtual void CounterPartLost( const MCatalogsSession& aSession );
       
   207 
       
   208 
       
   209 protected:
       
   210 
       
   211     /**
       
   212      * Constructor
       
   213      * Is set in the NewLC function.
       
   214      *
       
   215      * @param aParentGroup The parent subscription group.
       
   216      */
       
   217     CNcdSubscription( CNcdSubscriptionGroup& aParentGroup );
       
   218 
       
   219     /**
       
   220      * ConstructL
       
   221      */
       
   222     virtual void ConstructL();
       
   223     
       
   224 
       
   225     // These functions are called from the ReceiveMessage when
       
   226     // the given function id has matched to the function.
       
   227 
       
   228     /**
       
   229      * This function is called when the proxy wants to get the
       
   230      * data from the serverside. This function calls the
       
   231      * InternalizeDataForRequestL which may be overloaded in the
       
   232      * child classes
       
   233      * @param aMessage Contains data from the proxy and can be used
       
   234      * to send data back to proxy
       
   235      */
       
   236     void InternalizeRequestL( MCatalogsBaseMessage& aMessage );
       
   237         
       
   238     /**
       
   239      * This function writes the object data to the stream. 
       
   240      * The stream content will be sent to the proxy that requested the data.
       
   241      * Child classes should add their own data after this parent data.
       
   242      * @param aStream The data content of this class object will be written
       
   243      * into this stream.
       
   244      */
       
   245     virtual void ExternalizeDataForRequestL( RWriteStream& aStream );
       
   246 
       
   247     /**
       
   248      * This function is called from the proxy side. When the proxy
       
   249      * is deleted.
       
   250      * @param aMessage Contains data from the proxy and can be used
       
   251      * to send data back to proxy
       
   252      */
       
   253     void ReleaseRequest( MCatalogsBaseMessage& aMessage ) const;
       
   254 
       
   255 
       
   256 private:
       
   257 
       
   258     // Prevent these two if they are not implemented
       
   259     CNcdSubscription( const CNcdSubscription& aObject );
       
   260     CNcdSubscription& operator =( const CNcdSubscription& aObject );
       
   261 
       
   262 
       
   263     /**
       
   264      * Called when this subscription should be used to
       
   265      * buy given purchaseoption.
       
   266      *
       
   267      * @since S60 ?S60_version
       
   268      * @param aData Purchase option which was used to do the
       
   269      *              purchase.
       
   270      * @exception Leave KErrArgument if the purchase option
       
   271      *            does not have needed info.
       
   272      */ 
       
   273     void UseL( const CNcdPurchaseOptionImpl& aData );
       
   274     
       
   275     /**
       
   276      * Called when this subscription should be upgraded
       
   277      * according to given purchase option.
       
   278      *
       
   279      * @since S60 ?S60_version
       
   280      * @param aData Purchase option which was used to do the
       
   281      *              purchase of upgrade.
       
   282      * @exception Leave KErrArgument if the purchase option
       
   283      *            does not have needed info.
       
   284      */ 
       
   285     void UpgradeL( const CNcdPurchaseOptionImpl& aData );
       
   286 
       
   287     /**
       
   288      * Externalizes data of this class into stream. Does not
       
   289      * externalize objects owned by this class.
       
   290      *
       
   291      * @since S60 ?S60_version
       
   292      * @param aStream The data content of this class object will be written
       
   293      *                into this stream.
       
   294      */ 
       
   295     void ExternalizeOwnDataL( RWriteStream& aStream );
       
   296 
       
   297     /**
       
   298      * Deletes all allocated member variables that can be
       
   299      * reconstructed from a subscriptions protocol object.
       
   300      * Sets related pointers to NULL.
       
   301      *
       
   302      * @since S60 ?S60_version
       
   303      */ 
       
   304     void ResetProtocolMemberVariables();
       
   305 
       
   306 
       
   307     /**
       
   308      * Deletes all allocated member variables and sets the pointers
       
   309      * to NULL.
       
   310      *
       
   311      * @since S60 ?S60_version
       
   312      */    
       
   313     void ResetMemberVariables();
       
   314 
       
   315 private: // data
       
   316 
       
   317     // The message is set when ReceiveMessage is called. The message
       
   318     // is used in the CounterPartLost-function that informs the message
       
   319     // if the session has been lost.
       
   320     MCatalogsBaseMessage* iMessage;
       
   321     
       
   322     /*
       
   323      * Internal flag of the subscription to inform whether the
       
   324      * subscription has been recently updated or not. This has
       
   325      * to be set by user.
       
   326      */    
       
   327     TBool iRecentlyUpdated;
       
   328     
       
   329     /**
       
   330      * Name of the subscription.
       
   331      * Own.
       
   332      */     
       
   333     HBufC* iName;
       
   334     
       
   335     /**
       
   336      * Time of expiration.
       
   337      * Own.
       
   338      */    
       
   339     HBufC* iExpiredOn;
       
   340     
       
   341     
       
   342     /**
       
   343      * Tells whether subscription is cancelled. In other words
       
   344      * usubscribed.
       
   345      */    
       
   346     TBool iCancelled;
       
   347     
       
   348     
       
   349     /**
       
   350      * Type of the subscription.
       
   351      */  
       
   352     MNcdSubscription::TType iSubscriptionType;
       
   353 
       
   354 
       
   355 
       
   356     /**
       
   357      * Tells if validity time is used in this subscription.
       
   358      */     
       
   359     TBool iValidityTimeSet;
       
   360     /**
       
   361      * Tells time until this subscription is valid.
       
   362      */
       
   363     TTime iValidUntil;
       
   364     
       
   365     /**
       
   366      * Total validity time that subscription had in the
       
   367      * beginning. Notice that like other values this value can
       
   368      * also grow for example because of upgrades. This value
       
   369      * has to be stored also because in case of renew (when
       
   370      * subscription is for example periodic) we have
       
   371      * to know how much to increase the current validity.
       
   372      */    
       
   373     TInt iTotalValidityDelta;
       
   374 
       
   375 
       
   376     /**
       
   377      * Tells if credit limit is used in this subscription.
       
   378      */
       
   379     TBool iCreditLimitSet;
       
   380     /**
       
   381      * Credits that are available using the subscription.
       
   382      */ 
       
   383     TReal32 iCreditsLeft;
       
   384     /**
       
   385      * Total credits that were available in the beginning of the
       
   386      * subscription.
       
   387      */ 
       
   388     TReal32 iTotalCredits;
       
   389 
       
   390 
       
   391     /**
       
   392      * Tells if download limit is used in this subscription.
       
   393      */
       
   394     TBool iDownloadLimitSet;    
       
   395     /**
       
   396      * Downloads that are available using the subscription.
       
   397      */ 
       
   398     TInt iDownloadsLeft;
       
   399     /**
       
   400      * Total downloads that were available in the beginning of the
       
   401      * subscription.
       
   402      */    
       
   403     TInt iTotalDownloads;
       
   404     
       
   405     
       
   406     /**
       
   407      * Id of the purchase option where this subscription was
       
   408      * bought from.
       
   409      * Own. 
       
   410      */
       
   411     HBufC* iPurchaseOptionId;
       
   412         
       
   413     /**
       
   414      * The parent subscription group.
       
   415      */
       
   416     CNcdSubscriptionGroup& iParentGroup;
       
   417     };
       
   418     
       
   419 #endif // NCD_SUBSCRIPTION_IMPL_H