wvuing/wvuieng/EngSrc/CCABlockingManager.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Blocking manager handles the blocking and granting
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CCABLOCKINGMANAGER_H
       
    20 #define CCABLOCKINGMANAGER_H
       
    21 
       
    22 // INCLUDES
       
    23 #include "MCABlocking.h"
       
    24 #include "MCAImpsImClient.h"
       
    25 #include "MCASettingsObserver.h"
       
    26 #include "MCASettings.h"
       
    27 #include "TStorageManagerGlobals.h"
       
    28 #include "PublicEngineDefinitions.h"
       
    29 #include "PrivateEngineDefinitions.h"
       
    30 #include "MCABackgroundTask.h"
       
    31 #include "mcastoredcontactsobserver.h"
       
    32 
       
    33 #include "ImpsImCli.h"
       
    34 
       
    35 #include <e32base.h>
       
    36 
       
    37 // FORWARD DECLARATIONS
       
    38 class CCARequestMapper;
       
    39 class MCAStoredContacts;
       
    40 class MCAImpsFactory;
       
    41 
       
    42 // CLASS DECLARATION
       
    43 
       
    44 /**
       
    45  *  Blocking manager handles the blocking and granting
       
    46  *  ( user ) operations.
       
    47  *
       
    48  *  @lib CAEngine.lib
       
    49  *  @since 1.2
       
    50  */
       
    51 class CCABlockingManager : public CBase,
       
    52             public MImpsBlockingHandler2,
       
    53             public MCABlocking,
       
    54             public MCASettingsObserver,
       
    55             public MCABackgroundTask,
       
    56             public MCAStoredContactsObserver
       
    57     {
       
    58 
       
    59     private: // internal enumerations
       
    60 
       
    61         // internal states for blocking manager
       
    62         enum TBlockingMgrState
       
    63             {
       
    64             // normal operation
       
    65             EStateNormal = 0,
       
    66 
       
    67             // deleting of grant list, response to request needs to
       
    68             // be handled differently
       
    69             EStateDeletingGrantList
       
    70             };
       
    71 
       
    72     public:
       
    73 
       
    74         /**
       
    75          * Static constructor.
       
    76          * @param aImpsImServer is the API to the blocking services.
       
    77          * @param aRequestMapper is the pointer to the request mapper.
       
    78          *        Used in mapping requests to responses.
       
    79          * @param aSettingsManager The settings API
       
    80          */
       
    81         IMPORT_C static CCABlockingManager* NewL(
       
    82             MCAImpsFactory* aIMPSFactory,
       
    83             CCARequestMapper* aRequestMapper,
       
    84             MCASettings* aSettingsManager
       
    85         );
       
    86 
       
    87         /**
       
    88         * Virtual Destructor.
       
    89         */
       
    90         IMPORT_C virtual ~CCABlockingManager();
       
    91 
       
    92     protected: // Inherited from MCABlocking
       
    93 
       
    94     	/**
       
    95          * From MCABlocking
       
    96          * @see MCABlocking::SetAppUiExitFlag.
       
    97          */    	
       
    98     	void SetAppUiExitFlag( TBool aFlag );
       
    99     	
       
   100     	/**
       
   101          * From MCABlocking
       
   102          * @see MCABlocking::GetBlockedListFromServerL.
       
   103          */
       
   104         TInt GetBlockedListFromServerL();
       
   105 
       
   106         /**
       
   107          * From MCABlocking
       
   108          * @see MCABlocking::BlockedList.
       
   109          */
       
   110         const CDesCArray* BlockedList();
       
   111 
       
   112         /**
       
   113          * From MCABlocking
       
   114          * @see MCABlocking::InsertL.
       
   115          */
       
   116         TInt InsertL( const CDesCArray* aBlockList,
       
   117                       const CDesCArray* aGrantList,
       
   118                       TBool aForceUpdate = EFalse );
       
   119 
       
   120         /**
       
   121          * From MCABlocking
       
   122          * @see MCABlocking::RemoveL.
       
   123          */
       
   124         TInt RemoveL( const CDesCArray* aBlockList,
       
   125                       const CDesCArray* aGrantList,
       
   126                       TBool aForceUpdate = EFalse );
       
   127 
       
   128         /**
       
   129          * From MCABlocking
       
   130          * @see MCABlocking::IsContactBlocked
       
   131          */
       
   132         TBool IsContactBlocked( const TDesC& aContact,
       
   133                                 TBool aUseGrant = EFalse ) const;
       
   134 
       
   135         /**
       
   136          * From MCABlocking
       
   137          * @see MCABlocking::ContactListChangedL
       
   138          */
       
   139         void ContactListChangeL( TBool aUpdateInProgress );
       
   140 
       
   141         /**
       
   142          * From MCABlocking
       
   143          * @see MCABlocking::SetTemporaryGrantL
       
   144          */
       
   145         TInt SetTemporaryGrantL( const TDesC& aContact, TBool aOn );
       
   146 
       
   147 
       
   148     protected:  // from MImpsBlockingHandler
       
   149 
       
   150         /**
       
   151          * Handle response to getblockedlist request.
       
   152          * @param aBlockedList list of blocked users.
       
   153          * @param aBlockedListInUse is blocked list use or not.
       
   154          * @param aGrantedList list of granted users.
       
   155          * @param aGrantedListInUse is granted list use or not.
       
   156          */
       
   157         virtual void GetBlockedListResponseL(
       
   158             const MDesCArray* aBlockedList,
       
   159             TBool aBlockedListInUse,
       
   160             const MDesCArray* aGrantedList,
       
   161             TBool aGrantedListInUse,
       
   162             TImpsCspIdentifier& aCspId );
       
   163 
       
   164         /**
       
   165          * Server call back for handling successful operation requests.
       
   166          * @param aOperationId to map responses to the requests.
       
   167          * @param aStatus error code. KErrNone if successful.
       
   168          */
       
   169         virtual void HandleCompleteL(
       
   170             TInt aOperationId,
       
   171             TImpsCspIdentifier& aCspId );
       
   172 
       
   173     protected: // From MCASettingsObserver
       
   174 
       
   175         /**
       
   176          * Handles setting changes.
       
   177          * @param aChangedSettingEnum specifies the changed setting.
       
   178          * @since 2.1
       
   179          */
       
   180         void HandleSettingsChangeL( TInt aChangedSettingEnum );
       
   181 
       
   182     protected: //From MCABackgroundTask
       
   183 
       
   184         /**
       
   185          * This is the place where Block/GrantList synchronisation is started
       
   186          * after getting online event
       
   187          * @param aSubTask is the number of subtask, its counting down
       
   188          * @see MCABackgroundTask::HandleBackgroundTaskL
       
   189          */
       
   190         void HandleBackgroundTaskL( TInt aSubTask );
       
   191 
       
   192     protected: // From MCAStoredContactsObserver
       
   193 
       
   194         /**
       
   195          * @see MCAStoredContactsObserver
       
   196          */
       
   197         void HandleContactDelete( const TDesC& aContactId );
       
   198 
       
   199         /**
       
   200          * @see MCAStoredContactsObserver
       
   201          */
       
   202         void HandleAddition( MCAContactList& aList, MCAStoredContact& aContact );
       
   203 
       
   204         /**
       
   205          * @see MCAStoredContactsObserver
       
   206          */
       
   207         void HandleChange( MCAContactList* aList,
       
   208                            MCAStoredContact* aContact,
       
   209                            TStorageManagerGlobals::TCAObserverEventType aEventType,
       
   210                            TBool aUserIdChanged );
       
   211 
       
   212     public:  // new methods
       
   213 
       
   214         /**
       
   215          * If network state changes, BlockingManager state should be updated
       
   216          * by calling this method.
       
   217          * @param aState New state.
       
   218          * @param aUseGrant ETrue if grant list can be used.
       
   219          */
       
   220         void HandleNetworkStateChange( TNetworkState aState,
       
   221                                        TBool aCanUseGrant );
       
   222 
       
   223     private: // new methods
       
   224 
       
   225         /**
       
   226          * Does the actual handling
       
   227          */
       
   228         virtual void DoGetBlockedListResponseL(
       
   229             const MDesCArray* aBlockedList,
       
   230             TBool aBlockedListInUse,
       
   231             const MDesCArray* aGrantedList,
       
   232             TBool aGrantedListInUse );
       
   233 
       
   234         /**
       
   235          * Does the actual handling
       
   236          */
       
   237         virtual void DoHandleCompleteL(
       
   238             TInt aOperationId,
       
   239             TInt aStatus );
       
   240 
       
   241         /**
       
   242          * Evaluate current grantlist handling strategy
       
   243          * @return ETrue if grant list is in use
       
   244          */
       
   245         TBool GrantListInUse();
       
   246 
       
   247         /**
       
   248          * Clear the current grant list.  Used internally when
       
   249          * strategy is to allow nobody.
       
   250          */
       
   251         void ClearGrantListL( TBool aForceUpdate = EFalse );
       
   252 
       
   253         /**
       
   254          * Add given wv id to the internal block list
       
   255          * @param aId The wv id
       
   256          */
       
   257         void AddToBlockListL( const TDesC& aId );
       
   258 
       
   259         /**
       
   260          * Remove given wv id from the internal block list
       
   261          * @param aId The wv id
       
   262          */
       
   263         void RemoveFromBlockList( const TDesC& aId );
       
   264 
       
   265         /**
       
   266          * Check if given wv id is in the internal block list
       
   267          * @param aId The wv id
       
   268          * @return ETrue if the contact is in the list (is blocked)
       
   269          */
       
   270         TBool InternallyBlocked( const TDesC& aId ) const;
       
   271 
       
   272         /**
       
   273          * Add all friends to the internal grant list
       
   274          * @param aDoNotIncludeList, List of items which we do not want to
       
   275          *                           include from contact list.
       
   276          */
       
   277         void GrantFriendsL( CDesCArray* aDoNotIncludeList = NULL );
       
   278 
       
   279         /**
       
   280          * Insert or remove to grant or block list.
       
   281          * Leaves with KErrArgument if aRequest is not EBlockRequest
       
   282          * or EUnBlockRequest.
       
   283          * @param aInsertBlockList WV IDs to be inserted to blocklist.
       
   284          * @param aRemoveBlockList WV IDs to be removed from blocklist.
       
   285          * @param aInsertGrantList WV IDs to be inserted to grantlist.
       
   286          * @param aRemoveGrantList WV IDs to be removed from grantlist.
       
   287          * @param aAdditionalData A pointer to an array which is set to
       
   288          *                        CCARequest as additional data.
       
   289          * @param aRequest Request type, either block or unblock request.
       
   290          * @return error code.
       
   291          */
       
   292         TInt DoBlockRequestL( const CDesCArray* aInsertBlockList,
       
   293                               const CDesCArray* aRemoveBlockList,
       
   294                               const CDesCArray* aInsertGrantList,
       
   295                               const CDesCArray* aRemoveGrantList,
       
   296                               const CDesCArray* aAdditionalData,
       
   297                               TOperationRequests aRequest );
       
   298 
       
   299         /**
       
   300          *  Checks if contacts is granted or not
       
   301          *  @since 2.1
       
   302          *  @param aContactId, contact which is checked
       
   303          *  @return ETrue if granted, EFalse if not.
       
   304          */
       
   305         TBool IsContactGranted( const TDesC& aContact ) const;
       
   306 
       
   307         /**
       
   308         * Creates the CDesCArray from the source.
       
   309         * Ownership is transferred to caller!
       
   310         * @since 2.1
       
   311         * @param aSource Array to be copied
       
   312         * @return Array containing the same elements as source array
       
   313         */
       
   314         static CDesCArray* CloneArrayLC( const MDesCArray& aSource );
       
   315 
       
   316         /**
       
   317          * Creates the CDesCArray containing the items from arrayDiff that
       
   318          * are not on arrayTest
       
   319          * Ownership is transferred to caller!
       
   320          * @since 2.1
       
   321          * @param aArrayDiff Array whose differences are copied
       
   322          * @param aArrayTest Array to be tested on
       
   323          * @return Array containing the differences
       
   324          */
       
   325         static CDesCArray* CreateNeutralDiffLC( const MDesCArray& aArrayDiff,
       
   326                                                 const MDesCArray& aArrayTest );
       
   327 
       
   328 
       
   329 
       
   330         /**
       
   331          *  Check if InsertL/RemoveL should be processed or not.
       
   332          *  @since 2.1
       
   333          *  @param aBlockList, List of wvids to block
       
   334          *  @param aGrantList, List of wvids to grant
       
   335          *  @param aForceUpdate Force update (ETrue) or not
       
   336          *  @return ETrue, if update is needed.
       
   337          */
       
   338         TBool NeedUpdate( const CDesCArray* aBlockList,
       
   339                           const CDesCArray* aGrantList,
       
   340                           TBool aForceUpdate );
       
   341 
       
   342         /**
       
   343          *  Add contacts to granted list.
       
   344          *  @param aInsertArray. Array of contacts to be
       
   345          *                       inserted to granted list.
       
   346          */
       
   347         void AddToGrantedListL( const MDesCArray& aInsertArray );
       
   348 
       
   349         /**
       
   350          *  Remove contacts from granted list and modify removeArray
       
   351          *  @param aRemoveArray Array of contacts to be removed.
       
   352          *                      Remove those contacts from aRemoveArray which
       
   353          *                      are not meant to be deleted. For example:
       
   354          *                      Those which are still in other lists.
       
   355          */
       
   356         void RemoveFromGrantedList( CDesCArray& aRemoveArray );
       
   357 
       
   358     private:    // constructors and destructors
       
   359 
       
   360         /**
       
   361          * Default constructor.
       
   362          * @param aStorage is the pointer to the storage side. Used in updating
       
   363          *        flags etc.
       
   364          * @param aImpsImServer is the API to the server side.
       
   365          * @param aRequestMapper is the pointer to the request mapper.
       
   366          *        Used in mapping requests to responses.
       
   367          */
       
   368         CCABlockingManager(
       
   369             MCAImpsFactory* aIMPSFactory,
       
   370             CCARequestMapper* aRequestMapper,
       
   371             MCASettings* aSettingsManager );
       
   372 
       
   373         /**
       
   374          * ConstructL method.
       
   375          */
       
   376         void ConstructL();
       
   377 
       
   378     private: // Data
       
   379 
       
   380         // Doesn't own. Pointer to the IMPS interface factory.
       
   381         MCAImpsFactory* iImpsFactory;
       
   382 
       
   383         // Doesn't own. Pointer to the request mapper.
       
   384         CCARequestMapper* iRequestMapper;
       
   385 
       
   386         // doesn't own, pointer to settings API
       
   387         MCASettings* iSettingsManager;
       
   388 
       
   389         // Owns. List of blocked users, returned via BlockedList
       
   390         CDesCArrayFlat* iBlockedList;
       
   391 
       
   392         // Owns. List of granted users, returned via BlockedList
       
   393         CDesCArrayFlat* iGrantedList;
       
   394 
       
   395         // Maps the GetBlockedListFromServerL to GetBlockedListResponseL.
       
   396         TInt iGetBlockedListOpId;
       
   397 
       
   398         // Flag to tell if background tasks are run or not.
       
   399         TBool iBackgroundTaskReady;
       
   400 
       
   401         // handle to contacts list interface
       
   402         MCAStoredContacts* iStoredContacts; // not owned
       
   403 
       
   404         // the used granting strategy
       
   405         MCASettings::TCASettingValues iStrategy;
       
   406 
       
   407         // internal state
       
   408         TBlockingMgrState iMgrState;
       
   409 
       
   410         // Is our list valid
       
   411         TBool iBlocklistIsValid;
       
   412 
       
   413         // Can Grant list be used.
       
   414         TBool iCanUseGrant;
       
   415 
       
   416         //
       
   417         TBool iUpdateInProgress;
       
   418 
       
   419         TBool iLoggedIn;
       
   420         
       
   421         TBool iAppUiExit;
       
   422     };
       
   423 
       
   424 #endif // CCABLOCKINGMANAGER_H