cmmanager/cmmgr/cmmserver/inc/cmmdestinationinstance.h
branchRCL_3
changeset 58 83ca720e2b9a
parent 57 05bc53fe583b
child 62 bb1f80fb7db2
equal deleted inserted replaced
57:05bc53fe583b 58:83ca720e2b9a
     1 /*
       
     2 * Copyright (c) 2009-2010 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 * Session side object representing a destination.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef CMMDESTINATIONINSTANCE_H_
       
    21 #define CMMDESTINATIONINSTANCE_H_
       
    22 
       
    23 #include <e32base.h>
       
    24 #include <metadatabase.h>
       
    25 #include <cmmanagerdef.h>
       
    26 
       
    27 #include "cmmserverdefs.h"
       
    28 
       
    29 class CCmmSession;
       
    30 class CCmmCache;
       
    31 class CCmmConnMethodInstance;
       
    32 class TCmmIdStruct;
       
    33 class TCmmConnMethodItem;
       
    34 class CCDSNAPMetadataRecord;
       
    35 
       
    36 
       
    37 /**
       
    38  * Session side object representing a destination. Keeps track of any changes
       
    39  * the client makes before they are updated to database.
       
    40  */
       
    41 NONSHARABLE_CLASS( CCmmDestinationInstance ) : public CObject
       
    42     {
       
    43 public:
       
    44     /**
       
    45      * NewL.
       
    46      */
       
    47     static CCmmDestinationInstance* NewL( CCmmSession* aCmmSession, CCmmCache* aCache );
       
    48 
       
    49     /**
       
    50      * NewLC.
       
    51      */
       
    52     static CCmmDestinationInstance* NewLC( CCmmSession* aCmmSession, CCmmCache* aCache );
       
    53 
       
    54     /**
       
    55      * Destructor.
       
    56      */
       
    57     ~CCmmDestinationInstance();
       
    58 
       
    59 private:
       
    60     /**
       
    61      * Constructor.
       
    62      *
       
    63      * @param aCache CmmCache.
       
    64      */
       
    65     CCmmDestinationInstance( CCmmSession* aCmmSession, CCmmCache* aCache );
       
    66 
       
    67     /**
       
    68      * Second phase constructor.
       
    69      */
       
    70     void ConstructL();
       
    71 
       
    72 public:
       
    73     void SetId( const TUint32 aId );
       
    74     TUint32 GetId() const;
       
    75 
       
    76     /**
       
    77      * Sets a new status value.
       
    78      */
       
    79     void SetStatus( const TCmmDestinationStatus& aStatus );
       
    80 
       
    81     /**
       
    82      * Gets the current status of this destination instance.
       
    83      */
       
    84     TCmmDestinationStatus GetStatus() const;
       
    85 
       
    86     /**
       
    87      * Get handle ID.
       
    88      */
       
    89     TInt GetHandle() const;
       
    90 
       
    91     /**
       
    92      * Set handle ID.
       
    93      */
       
    94     void SetHandle( const TInt aHandle );
       
    95 
       
    96     /**
       
    97      * Set the record status for all records.
       
    98      */
       
    99     void SetStatusForAllRecords( const TCmmRecordStatus& aStatus );
       
   100 
       
   101     TUint32 GetElementIdL();
       
   102     TUint32 GetRecordTagFromApRecordL();
       
   103 
       
   104     TInt SetRecordPointer(
       
   105             const TCmmDbRecords& aDestRecord,
       
   106             CommsDat::CCDRecordBase* aRecordPointer );
       
   107     TInt GetRecordPointer(
       
   108             const TCmmDbRecords& aDestRecord,
       
   109             CommsDat::CCDRecordBase*& aRecordPointer );
       
   110 
       
   111     /**
       
   112      * Save the contents of this destination into database. All connection
       
   113      * methods including embedded destination, that the client has open handles
       
   114      * to, are also updated.
       
   115      */
       
   116     void UpdateL();
       
   117 
       
   118     TDesC& GetDestinationNameL();
       
   119     HBufC* GetLocalisedDestinationNameL();
       
   120     void SetDestinationNameL( const TDesC& aDestinationName );
       
   121 
       
   122     /**
       
   123      * Get the destination icon.
       
   124      */
       
   125     HBufC* GetDestinationIconL();
       
   126     void SetDestinationIconL( const TDesC& aDestinationIcon );
       
   127 
       
   128     void GetMetadataL(
       
   129             const CMManager::TSnapMetadataField& aMetadataField,
       
   130             TUint32& aMetadata );
       
   131     void SetMetadataL(
       
   132             const CMManager::TSnapMetadataField& aMetadataField,
       
   133             const TUint32 aMetadata );
       
   134 
       
   135     void GetProtectionL( CMManager::TProtectionLevel& aProtectionLevel );
       
   136     void SetProtectionL( CMManager::TProtectionLevel aProtectionLevel );
       
   137 
       
   138     /**
       
   139      * Return true if protection level has been changed. 
       
   140      */
       
   141     TBool ProtectionChanged();
       
   142 
       
   143     /**
       
   144      * Return the previous valid protection level of this connection method
       
   145      * instance.
       
   146      */
       
   147     CMManager::TProtectionLevel LastProtectionLevel();
       
   148 
       
   149     /**
       
   150      * Return the protection level currently set into this destination instance.
       
   151      */
       
   152     CMManager::TProtectionLevel CurrentProtectionLevelL();
       
   153 
       
   154     /**
       
   155      * Adds a connection method into this destination. Returns the index in
       
   156      * the connection method array where the connection method was added.
       
   157      */
       
   158     TInt AddConnMethodL(
       
   159             CCmmConnMethodInstance& aConnMethodInstance );
       
   160 
       
   161     /**
       
   162      * Adds an embedded destination into this destination. Returns the index in
       
   163      * the connection method array where the connection method was added.
       
   164      */
       
   165     TInt AddEmbeddedDestinationL(
       
   166             const CCmmDestinationInstance& aEmbeddedDestinationInstance );
       
   167 
       
   168     /**
       
   169      * Delete a connection method that belongs to this destination. If the
       
   170      * connection method belongs to any other destination, it is only removed
       
   171      * from this destination and not deleted. Does not call update.
       
   172      */
       
   173     void DeleteConnMethodFromDestinationL(
       
   174             const CCmmConnMethodInstance& aConnMethodInstance );
       
   175 
       
   176     /**
       
   177      * Remove a connection method from this destination. If the second
       
   178      * attribute aTestIfConnected is false, the test to check if connection
       
   179      * method is in use is skipped. This is to avoid a duplicate check, so it
       
   180      * should have been already tested by the caller.
       
   181      */
       
   182     void RemoveConnMethodFromDestinationL(
       
   183             const CCmmConnMethodInstance& aConnMethodInstance,
       
   184             const TBool aTestIfConnected = ETrue );
       
   185 
       
   186     /**
       
   187      * Modifies the priority of a connection method inside this destination.
       
   188      */
       
   189     void ModifyConnMethodPriorityL(
       
   190             CCmmConnMethodInstance& aConnMethodInstance,
       
   191             TUint aIndex );
       
   192 
       
   193     /**
       
   194      * Finds a connection method instance that belongs to the same session and
       
   195      * matches the provided ID. Return NULL if no match is found.
       
   196      */
       
   197     CCmmConnMethodInstance* FindConnMethodInstanceFromSessionById(
       
   198             const TUint32 aConnMethodId ) const;
       
   199 
       
   200     /**
       
   201      * Finds a destination instance that belongs to the same session and matches
       
   202      * the provided ID. Return NULL if no match is found.
       
   203      */
       
   204     CCmmDestinationInstance* FindDestinationInstanceFromSessionById(
       
   205             const TUint32 aDestinationId ) const;
       
   206 
       
   207     /**
       
   208      * Check from all open destination handles in the same session if the given
       
   209      * connection method is inside any of them. The given destination is
       
   210      * skipped.
       
   211      */
       
   212     TBool ConnMethodInOtherDestinationInSession(
       
   213             const TUint32 aConnMethodId,
       
   214             const TUint32 aDestinationId ) const;
       
   215 
       
   216     /**
       
   217      * Check if the given connection method is in this destination. Include
       
   218      * embedded destinations.
       
   219      */
       
   220     TBool ValidConnMethodIdInDestinationIncludeEmbedded(
       
   221             const TUint32 aConnMethodId ) const;
       
   222 
       
   223     /**
       
   224      * Check if the given connection method is inside this destination and if
       
   225      * it is in a 'locked' status. A locked connection method can't be deleted
       
   226      * nor removed from the destination. A connection method becomes locked
       
   227      * if it is the only remaining connection method in a destination and a
       
   228      * virtual IAP points into that destination.
       
   229      */
       
   230     TBool ConnMethodInDestinationButLocked( const TUint32 aConnMethodId ) const;
       
   231 
       
   232     /**
       
   233      * Counts how many connection methods that require priority information are
       
   234      * currently in this destination. This excludes any virtual IAPs that point
       
   235      * to a destination or any embedded destinations from the count. Assumes
       
   236      * the connection method array is in order so all wildcard priority IAPs
       
   237      * are at the end of the list.
       
   238      */
       
   239     TUint NumberOfConnMethodsWithPriority() const;
       
   240 
       
   241     /**
       
   242      * Check if this destination has an embedded destination. Checks the
       
   243      * current (possibly unsaved) status of this destination handle, not the
       
   244      * current status in database.
       
   245      */
       
   246     TBool HasEmbedded() const;
       
   247 
       
   248     /**
       
   249      * Check if this destination has an embedded destination with the specified
       
   250      * ID. Checks the current (possibly unsaved) status of this destination
       
   251      * handle, not the current status in database.
       
   252      */
       
   253     TBool HasEmbeddedWithId( const TUint32 aDestinationId ) const;
       
   254 
       
   255     /**
       
   256      * After update/delete to database, refresh temporary ID to real ID if
       
   257      * necessary and refresh status information for any related handles for
       
   258      * all client sessions.
       
   259      */
       
   260     void RefreshHandlesForAllSessions( const TCmmIdStruct& aIdStruct );
       
   261 
       
   262     /**
       
   263      * If the destination contains a connection method with matching temporary
       
   264      * ID, updates the ID to real ID. This is done after the connection method
       
   265      * has been successfully saved into the database.
       
   266      */
       
   267     void RefreshConnMethodId( const TCmmIdStruct& aIdStruct );
       
   268 
       
   269     /**
       
   270      * Called after this destination has been updated and database transaction
       
   271      * has completed successfully. Sets the internal state of this destination
       
   272      * instance to reflect the new valid state.
       
   273      */
       
   274     void UpdateSuccessful();
       
   275 
       
   276 private:
       
   277     TBool AllMandatoryRecordsContainData() const;
       
   278 
       
   279     /**
       
   280      * Loads a requested type of record from database if it is not yet loaded.
       
   281      */
       
   282     void LoadRecordIfMissingL( TCmmDbRecords aRecordType );
       
   283 
       
   284     void LoadAllRecordsL();
       
   285     void SetMetadataInternetL( const TUint32 aMetadata );
       
   286     void SetMetadataHighlight( const TUint32 aMetadata );
       
   287     void SetMetadataHiddenAgentL( const TUint32 aMetadata );
       
   288     void SetMetadataLocalizationL( const TUint32 aMetadata );
       
   289     void SetMetadataPurposeL( const TUint32 aMetadata );
       
   290 
       
   291     /**
       
   292      * Checks the current metadata for this destination, and verifies there is
       
   293      * no other conflicting destinations in the database.
       
   294      */
       
   295     TBool ConflictingMetadataFoundL();
       
   296 
       
   297 public:
       
   298     // Array of connection method items that belong to this destination. Loaded
       
   299     // and maintained in priority order.
       
   300     RArray<TCmmConnMethodItem> iConnMethodItemArray; // Owned.
       
   301 
       
   302     // Array of connection method IDs that should be deleted if UpdateL() is
       
   303     // called for this destination instance.
       
   304     RArray<TUint32> iConnMethodsToBeDeleted; // Owned.
       
   305 
       
   306 private:
       
   307     // Session that owns this instance.
       
   308     CCmmSession* iCmmSession; // Not owned.
       
   309 
       
   310     // Database cache.
       
   311     CCmmCache* iCache; // Not owned.
       
   312 
       
   313     // The network record.
       
   314     CommsDat::CCDNetworkRecord* iNetworkRecord; // Owned.
       
   315 
       
   316     // The access point record.
       
   317     CommsDat::CCDAccessPointRecord* iDestApRecord; // Owned.
       
   318 
       
   319     // The metadata record.
       
   320     CCDSNAPMetadataRecord* iMetadataRecord; // Owned.
       
   321 
       
   322     // Status flags for each record.
       
   323     TCmmRecordStatus iNetworkRecordStatus;
       
   324     TCmmRecordStatus iDestApRecordStatus;
       
   325     TCmmRecordStatus iMetadataRecordStatus;
       
   326 
       
   327     // Destination handle status.
       
   328     TCmmDestinationStatus iStatus;
       
   329 
       
   330     // Destination ID. If real ID is not available, contains a temporary ID.
       
   331     TUint32 iId;
       
   332 
       
   333     // Subsession handle ID.
       
   334     TInt iHandle;
       
   335 
       
   336     // True if protection value has been changed. Reset to false on update.
       
   337     TBool iProtectionChanged;
       
   338 
       
   339     // The previous valid protection level of this connection method instance.
       
   340     // Set correctly only if iProtectionChanged is true.
       
   341     CMManager::TProtectionLevel iLastProtectionLevel;
       
   342 
       
   343     // The protection level currently set into this destination instance.
       
   344     CMManager::TProtectionLevel iCurrentProtectionLevel;
       
   345     };
       
   346 
       
   347 #endif // CMMDESTINATIONINSTANCE_H_
       
   348 
       
   349 // End of file