cmmanager/cmmgr/cmmserver/inc/cmmdestinationinstance.h
changeset 20 9c97ad6591ae
child 23 7ec726f93df1
equal deleted inserted replaced
18:fcbbe021d614 20:9c97ad6591ae
       
     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     void GetMetadataL(
       
   123             const CMManager::TSnapMetadataField& aMetadataField,
       
   124             TUint32& aMetadata );
       
   125     void SetMetadataL(
       
   126             const CMManager::TSnapMetadataField& aMetadataField,
       
   127             const TUint32& aMetadata );
       
   128 
       
   129     void GetProtectionL( CMManager::TProtectionLevel& aProtectionLevel );
       
   130     void SetProtectionL( CMManager::TProtectionLevel aProtectionLevel );
       
   131 
       
   132     /**
       
   133      * Return true if protection level has been changed. 
       
   134      */
       
   135     TBool ProtectionChanged();
       
   136 
       
   137     /**
       
   138      * Return the previous valid protection level of this connection method
       
   139      * instance.
       
   140      */
       
   141     CMManager::TProtectionLevel LastProtectionLevel();
       
   142 
       
   143     /**
       
   144      * Return the protection level currently set into this destination instance.
       
   145      */
       
   146     CMManager::TProtectionLevel CurrentProtectionLevel();
       
   147 
       
   148     /**
       
   149      * Adds a connection method into this destination. Returns the index in
       
   150      * the connection method array where the connection method was added.
       
   151      */
       
   152     TInt AddConnMethodL(
       
   153             const CCmmConnMethodInstance& aConnMethodInstance );
       
   154 
       
   155     /**
       
   156      * Adds an embedded destination into this destination. Returns the index in
       
   157      * the connection method array where the connection method was added.
       
   158      */
       
   159     TInt AddEmbeddedDestinationL(
       
   160             const CCmmDestinationInstance& aEmbeddedDestinationInstance );
       
   161 
       
   162     /**
       
   163      * Delete a connection method that belongs to this destination. If the
       
   164      * connection method belongs to any other destination, it is only removed
       
   165      * from this destination and not deleted. Does not call update.
       
   166      */
       
   167     void DeleteConnMethodFromDestinationL(
       
   168             const CCmmConnMethodInstance& aConnMethodInstance );
       
   169 
       
   170     /**
       
   171      * Remove a connection method from this destination. If the second
       
   172      * attribute aTestIfConnected is false, the test to check if connection
       
   173      * method is in use is skipped. This is to avoid a duplicate check, so it
       
   174      * should have been already tested by the caller.
       
   175      */
       
   176     void RemoveConnMethodFromDestinationL(
       
   177             const CCmmConnMethodInstance& aConnMethodInstance,
       
   178             const TBool& aTestIfConnected = ETrue );
       
   179 
       
   180     /**
       
   181      * Modifies the priority of a connection method inside this destination.
       
   182      */
       
   183     void ModifyConnMethodPriorityL(
       
   184             const CCmmConnMethodInstance& aConnMethodInstance,
       
   185             TUint aIndex );
       
   186 
       
   187     /**
       
   188      * Finds a connection method instance that belongs to the same session and
       
   189      * matches the provided ID. Return NULL if no match is found.
       
   190      */
       
   191     CCmmConnMethodInstance* FindConnMethodInstanceFromSessionById(
       
   192             const TUint32& aConnMethodId ) const;
       
   193 
       
   194     /**
       
   195      * Finds a destination instance that belongs to the same session and matches
       
   196      * the provided ID. Return NULL if no match is found.
       
   197      */
       
   198     CCmmDestinationInstance* FindDestinationInstanceFromSessionById(
       
   199             const TUint32& aDestinationId ) const;
       
   200 
       
   201     /**
       
   202      * Check from all open destination handles in the same session if the given
       
   203      * connection method is inside any of them. The given destination is
       
   204      * skipped.
       
   205      */
       
   206     TBool ConnMethodInOtherDestinationInSession(
       
   207             const TUint32& aConnMethodId,
       
   208             const TUint32& aDestinationId ) const;
       
   209 
       
   210     /**
       
   211      * Check if the given connection method is in this destination. Include
       
   212      * embedded destinations.
       
   213      */
       
   214     TBool ValidConnMethodIdInDestinationIncludeEmbedded(
       
   215             const TUint32& aConnMethodId ) const;
       
   216 
       
   217     /**
       
   218      * Check if the given connection method is inside this destination and if
       
   219      * it is in a 'locked' status. A locked connection method can't be deleted
       
   220      * nor removed from the destination. A connection method becomes locked
       
   221      * if it is the only remaining connection method in a destination and a
       
   222      * virtual IAP points into that destination.
       
   223      */
       
   224     TBool ConnMethodInDestinationButLocked( const TUint32& aConnMethodId ) const;
       
   225 
       
   226     /**
       
   227      * Counts how many connection methods that require priority information are
       
   228      * currently in this destination. This excludes any virtual IAPs that point
       
   229      * to a destination or any embedded destinations from the count. Assumes
       
   230      * the connection method array is in order so all wildcard priority IAPs
       
   231      * are at the end of the list.
       
   232      */
       
   233     TUint NumberOfConnMethodsWithPriority() const;
       
   234 
       
   235     /**
       
   236      * Check if this destination has an embedded destination. Checks the
       
   237      * current (possibly unsaved) status of this destination handle, not the
       
   238      * current status in database.
       
   239      */
       
   240     TBool HasEmbedded() const;
       
   241 
       
   242     /**
       
   243      * Check if this destination has an embedded destination with the specified
       
   244      * ID. Checks the current (possibly unsaved) status of this destination
       
   245      * handle, not the current status in database.
       
   246      */
       
   247     TBool HasEmbeddedWithId( const TUint32& aDestinationId ) const;
       
   248 
       
   249     /**
       
   250      * After update/delete to database, refresh temporary ID to real ID if
       
   251      * necessary and refresh status information for any related handles for
       
   252      * all client sessions.
       
   253      */
       
   254     void RefreshHandlesForAllSessions( const TCmmIdStruct& aIdStruct );
       
   255 
       
   256     /**
       
   257      * If the destination contains a connection method with matching temporary
       
   258      * ID, updates the ID to real ID. This is done after the connection method
       
   259      * has been successfully saved into the database.
       
   260      */
       
   261     void RefreshConnMethodId( const TCmmIdStruct& aIdStruct );
       
   262 
       
   263     /**
       
   264      * Called after this destination has been updated and database transaction
       
   265      * has completed successfully. Sets the internal state of this destination
       
   266      * instance to reflect the new valid state.
       
   267      */
       
   268     void UpdateSuccessful();
       
   269 
       
   270 private:
       
   271     TBool AllMandatoryRecordsContainData() const;
       
   272     void RefreshRecordL( TCmmDbRecords aRecordType );
       
   273     void LoadAllRecordsL();
       
   274     void SetMetadataInternetL( const TUint32& aMetadata );
       
   275     void SetMetadataHighlight( const TUint32& aMetadata );
       
   276     void SetMetadataHiddenAgentL( const TUint32& aMetadata );
       
   277     void SetMetadataLocalizationL( const TUint32& aMetadata );
       
   278     void SetMetadataPurposeL( const TUint32& aMetadata );
       
   279 
       
   280     /**
       
   281      * Checks the current metadata for this destination, and verifies there is
       
   282      * no other conflicting destinations in the database.
       
   283      */
       
   284     TBool ConflictingMetadataFoundL();
       
   285 
       
   286 public:
       
   287     // Array of connection method items that belong to this destination. Loaded
       
   288     // and maintained in priority order.
       
   289     RArray<TCmmConnMethodItem> iConnMethodItemArray; // Owned.
       
   290 
       
   291     // Array of connection method IDs that should be deleted if UpdateL() is
       
   292     // called for this destination instance.
       
   293     RArray<TUint32> iConnMethodsToBeDeleted; // Owned.
       
   294 
       
   295 private:
       
   296     // Session that owns this instance.
       
   297     CCmmSession* iCmmSession; // Not owned.
       
   298 
       
   299     // Database cache.
       
   300     CCmmCache* iCache; // Not owned.
       
   301 
       
   302     // The network record.
       
   303     CommsDat::CCDNetworkRecord* iNetworkRecord; // Owned.
       
   304 
       
   305     // The access point record.
       
   306     CommsDat::CCDAccessPointRecord* iDestApRecord; // Owned.
       
   307 
       
   308     // The metadata record.
       
   309     CCDSNAPMetadataRecord* iMetadataRecord; // Owned.
       
   310 
       
   311     // Status flags for each record.
       
   312     TCmmRecordStatus iNetworkRecordStatus;
       
   313     TCmmRecordStatus iDestApRecordStatus;
       
   314     TCmmRecordStatus iMetadataRecordStatus;
       
   315 
       
   316     // Destination handle status.
       
   317     TCmmDestinationStatus iStatus;
       
   318 
       
   319     // Destination ID. If real ID is not available, contains a temporary ID.
       
   320     TUint32 iId;
       
   321 
       
   322     // Subsession handle ID.
       
   323     TInt iHandle;
       
   324 
       
   325     // True if protection value has been changed. Reset to false on update.
       
   326     TBool iProtectionChanged;
       
   327 
       
   328     // The previous valid protection level of this connection method instance.
       
   329     // Set correctly only if iProtectionChanged is true.
       
   330     CMManager::TProtectionLevel iLastProtectionLevel;
       
   331 
       
   332     // The protection level currently set into this destination instance.
       
   333     CMManager::TProtectionLevel iCurrentProtectionLevel;
       
   334     };
       
   335 
       
   336 #endif // CMMDESTINATIONINSTANCE_H_
       
   337 
       
   338 // End of file