simpledatamodeladapter/inc/presencepluginxdmpresrules.h
changeset 0 c8caa15ef882
child 12 e6a66db4e9d0
equal deleted inserted replaced
-1:000000000000 0:c8caa15ef882
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  IETF SIMPLE Protocol implementation for XIMP Framework
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CPRESENCEPLUGINXDMPRESRULES_H
       
    20 #define CPRESENCEPLUGINXDMPRESRULES_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <ximpbase.h>
       
    24 
       
    25 #include "presenceplugincommon.h"
       
    26 #include "presencelogger.h"
       
    27 
       
    28 class CXdmEngine;
       
    29 class CXdmDocument;
       
    30 class CXdmDocumentNode;
       
    31 class TRequestStatus;
       
    32 class MPresRulesAsyncHandler;
       
    33 
       
    34 /**
       
    35  * CPresencePluginXdmPresRules
       
    36  *
       
    37  * Simple Engine Connection
       
    38  *
       
    39  * @lib presenceplugin.dll
       
    40  * @since S60 v3.2
       
    41  */
       
    42 NONSHARABLE_CLASS( CPresencePluginXdmPresRules ): public CActive
       
    43     {
       
    44     public: // Constructor and destructor
       
    45          
       
    46         /**
       
    47          * XDM presrules state
       
    48          */
       
    49         enum TPluginPresRulesXdmState
       
    50             {
       
    51  			EStateIdle,
       
    52             EGetXdmRules,
       
    53             EUpdateXdmRules,
       
    54             ECreateXdmPresrules
       
    55             };
       
    56             
       
    57         /**
       
    58          * Operation state for rules update
       
    59          */     
       
    60         enum TPluginPresRulesUpdateState
       
    61             {
       
    62             EStateNoOperation,
       
    63             EStateAddToWhiteList,
       
    64             EStateAddToBlockList,
       
    65             EStateRemoveFromWhiteList,
       
    66             EStateRemoveFromBlackList,
       
    67             EStateInitializeRules
       
    68             };
       
    69             
       
    70         /**
       
    71          * Current operation
       
    72          */
       
    73         enum TPluginPresRulesXdmOperation
       
    74             {
       
    75             ENoOperation,
       
    76             ECancelDocument,
       
    77             EXdmInit,   
       
    78             EXdmDeleteAll,
       
    79             EXdmCancel,
       
    80             EXdmGetRulesFromServer,
       
    81             EXdmInitialPresDoc,
       
    82             EXdmUpdateRules,
       
    83             EXdmUpdateRulesFromServer
       
    84             };
       
    85         
       
    86         /**
       
    87          * Two-phased constructor.
       
    88          *         
       
    89          * @param aXmdId xdm settings id
       
    90          * @param aLocalMode, local or server mode TRUE/FALSE
       
    91          */       
       
    92         static CPresencePluginXdmPresRules* NewL( const TInt aXmdId, TBool  );
       
    93 
       
    94         /**
       
    95          * Two-phased constructor.
       
    96          *         
       
    97          * @param aXmdId xdm settings id
       
    98          * @param aLocalMode, local or server mode TRUE/FALSE
       
    99          */ 
       
   100         static CPresencePluginXdmPresRules* NewLC( 
       
   101         		const TInt aSettingId,
       
   102         		TBool aLocalMode );
       
   103 
       
   104         /**
       
   105          * Standard C++ destructor
       
   106          */ 
       
   107         virtual ~CPresencePluginXdmPresRules( );
       
   108     
       
   109     public: // Own functions
       
   110         
       
   111         /**
       
   112          * Updates XDM rules into server
       
   113          *
       
   114          * @since S60 3.2
       
   115          * @param aHandler, MPresRulesAssyncHandler
       
   116          * @return TInt, Error code
       
   117          */
       
   118         TInt UpdateXdmRulesL( MPresRulesAsyncHandler* const aHandler );
       
   119         
       
   120         /** 
       
   121          * Add white list tag to presrules document
       
   122          *
       
   123          * @since S60 3.2
       
   124          * @param aRoot, xml document root
       
   125          * @return none
       
   126          */
       
   127         void AddWhiteListL( CXdmDocumentNode* aRoot );
       
   128          
       
   129         /** 
       
   130          * Add black list tag to presrules document
       
   131          *
       
   132          * @since S60 3.2
       
   133          * @param aRoot, xml document root
       
   134          * @return none
       
   135          */
       
   136         void AddBlackListL( CXdmDocumentNode* aRoot );
       
   137          
       
   138         /**
       
   139          * Get presence rules from server
       
   140          *
       
   141          * @since S60 3.2
       
   142          * @param aHandler, PresRules assync handler
       
   143          * @return TInt, error code
       
   144          */
       
   145         TInt GetXdmRulesL( MPresRulesAsyncHandler* const aHandler );
       
   146         
       
   147         /**
       
   148          * Making initial presence rules document
       
   149          *
       
   150          * @since S60 3.2
       
   151          * @param aHandler, PresRules assync handler
       
   152          * @return none
       
   153          */
       
   154         void MakeInitialRulesDocumentL( 
       
   155         		MPresRulesAsyncHandler* const aHandler );
       
   156             
       
   157         /**
       
   158          * Remove entiry from blocked rules
       
   159          *
       
   160          * @since S60 3.2
       
   161          * @param aUri, entity url
       
   162          * @aHandler, PresRules assync handler 
       
   163          * @return none
       
   164          */   
       
   165         void RemoveEntityBlockedRulesL( 
       
   166             const TDesC&  aUri,
       
   167             MPresRulesAsyncHandler* const aHandler );
       
   168             
       
   169         /**
       
   170          * Remove entity from presrules white list
       
   171          *
       
   172          * @since S60 3.2
       
   173          * @param aUri, entity url
       
   174          * @aHandler, PresRules assync handler 
       
   175          * @return none
       
   176          */
       
   177         void RemoveEntityFromWhiteListL( 
       
   178             const TDesC&  aUri,
       
   179             MPresRulesAsyncHandler* const aHandler );
       
   180                 
       
   181         /**
       
   182          * Add entity to presrules white list
       
   183          *
       
   184          * @since S60 3.2
       
   185          * @param aUri, entity url
       
   186          * @aHandler, PresRules assync handler 
       
   187          * @return none
       
   188          */
       
   189         void AddEntityToWhiteListL(
       
   190             const TDesC&  aUri,
       
   191             MPresRulesAsyncHandler* const aHandler );
       
   192 
       
   193         /**
       
   194          * Add entity to blocked rules
       
   195          *
       
   196          * @since S60 3.2
       
   197          * @param aUri, entity url
       
   198          * @aHandler, PresRules assync handler 
       
   199          * @return none
       
   200          */
       
   201         void AddEntityToBlockedRulesL( 
       
   202             const TDesC&  aUri,
       
   203             MPresRulesAsyncHandler* const aHandler );
       
   204                 
       
   205         /**
       
   206          * Remove one from rule list
       
   207          *
       
   208          * @since S60 3.2
       
   209          * @param aRule, presence rule name
       
   210          * @param aUri, entity url 
       
   211          * @return none
       
   212          */ 
       
   213         void RemoveOneFromRuleL(
       
   214             const TDesC& aRule,
       
   215             const TDesC&  aUri );
       
   216         
       
   217         /**
       
   218          * Add one to rule list
       
   219          *
       
   220          * @since S60 3.2
       
   221          * @param aRule, presence rule name
       
   222          * @param aUri, entity url 
       
   223          * @return none
       
   224          */ 
       
   225         void DoOneAddUserL(
       
   226             const TDesC& aList,
       
   227             const TDesC&  aUri );
       
   228           
       
   229         /**
       
   230          * Update presence document from server
       
   231          *
       
   232          * @since S60 3.2
       
   233          * @param none
       
   234          * @return TInt, error code
       
   235          */
       
   236         TInt UpdateFromServerL( MPresRulesAsyncHandler* const aHandler );
       
   237   
       
   238     private:
       
   239         
       
   240         /**
       
   241          * Standard C++ constructor
       
   242          * @param aXmdId, XDM settings id
       
   243          */  
       
   244         CPresencePluginXdmPresRules( const TInt aXmdId );
       
   245 
       
   246         /**
       
   247          * Performs the 2nd phase of construction.
       
   248          *
       
   249          * @param aXmdId, xdm settings id
       
   250          * @param aLocalMode, clinet localmode state
       
   251          */   
       
   252         void ConstructL( const TInt aXmdId, TBool aLocalMode );
       
   253     
       
   254     private: // own functions
       
   255     
       
   256         /**
       
   257          * GetRulesL
       
   258          *
       
   259          * @since S60 3.2
       
   260          * @param aRuleArray, rule array
       
   261          * @return TBool, rules found
       
   262          */        
       
   263         CXdmDocumentNode* GetRulesL( const TDesC& aRule,
       
   264             RPointerArray<CXdmDocumentNode>& aRuleArray );
       
   265     
       
   266         /**
       
   267          * Remove rule group from pres-rules document
       
   268          *
       
   269          * @since S60 3.2
       
   270          * @param aRule, presence rule name
       
   271          * @return none
       
   272          */
       
   273         void RemoveRuleGroupL( const TDesC& aRule );
       
   274         
       
   275         /**
       
   276          * Search list under parent
       
   277          *
       
   278          * @since S60 3.2        
       
   279          * @param aParent. document node
       
   280          * @param aName, name of search
       
   281          * @return none
       
   282          */        
       
   283         CXdmDocumentNode* SearchListUnderParentL(
       
   284             CXdmDocumentNode* aParent,
       
   285             const TDesC& aName );
       
   286     
       
   287         /**
       
   288          * Create root if need
       
   289          *
       
   290          * @since S60 3.2
       
   291          * @param none
       
   292          * @return none
       
   293          */
       
   294         void CreateRootIfNeededL();
       
   295        
       
   296         static void ResetAndDestroy1( TAny* aPointerArray );
       
   297         static void ResetAndDestroy2( TAny* aPointerArray );
       
   298         
       
   299         /**
       
   300          * Find rule from presrules xml
       
   301          *
       
   302          * @since S60 3.2
       
   303          * @param aRule, rule name
       
   304          * @return TBool
       
   305          */
       
   306         TBool FindRuleL( const TDesC& aRule, TBool aCreateRule );
       
   307                
       
   308         /**
       
   309          * Check if one already exist
       
   310          *
       
   311          * @since S60 3.2
       
   312          * @param aList, listname
       
   313          * @param aUri, entity url
       
   314          * @return TBool
       
   315          */
       
   316         TBool CheckIfOneExistL(
       
   317             const TDesC& aRule,
       
   318             const TDesC& aUri );
       
   319         
       
   320         /**
       
   321          * Compare uri to attribute without prefix. Returns ETrue if match.
       
   322          *
       
   323          * @since S60 5.0
       
   324          * @param aUri, entity url
       
   325          * @parram aAttribute url attribute
       
   326          * @return TBool
       
   327          */
       
   328         TBool CompareUriWithoutPrefixL( 
       
   329             const TDesC& aUri, const TDesC& aAttribute );
       
   330                 
       
   331     protected: // from base class CActive
       
   332 
       
   333         /**
       
   334          * Defined in a base class
       
   335          */
       
   336         void RunL();
       
   337 
       
   338         /**
       
   339          * Defined in a base class
       
   340          */
       
   341         TInt RunError( TInt aError );
       
   342 
       
   343         /**
       
   344          * Defined in a base class
       
   345          */
       
   346         void DoCancel();
       
   347 
       
   348     private: // Data
       
   349         
       
   350         /**
       
   351          * XDM Engine
       
   352          * Own.
       
   353          */
       
   354         CXdmEngine* iXdmEngine;
       
   355         
       
   356         /**
       
   357          * XDM Settings id
       
   358          * Own.        
       
   359          */
       
   360         TInt iSettingsId;
       
   361         
       
   362         /**
       
   363          * Presence rules document
       
   364          * Own
       
   365          */
       
   366         CXdmDocument* iPresRulesDoc;
       
   367         
       
   368         /**
       
   369          * Current state
       
   370          * Own.
       
   371          */
       
   372         TPluginPresRulesXdmState iXdmState;
       
   373         
       
   374         /**
       
   375          * TPluginPresRulesUpdateState
       
   376          * Own.
       
   377          */
       
   378         TPluginPresRulesUpdateState iRulesUpdateState;
       
   379          
       
   380         /**
       
   381          * client statutus.
       
   382          * Not own.
       
   383          */
       
   384         TRequestStatus* iClientStatus;
       
   385         
       
   386         /**
       
   387          * Whether Presence XDM is up-to-date
       
   388          * Own.
       
   389          */
       
   390         TBool iPresXdmOk;
       
   391        
       
   392         /**
       
   393          * Entity uri
       
   394          * own
       
   395          */
       
   396         HBufC*  iEntityUri;
       
   397         
       
   398         /**
       
   399          * Async request
       
   400          * Own. 
       
   401          */
       
   402         TPluginPresRulesXdmOperation iAsyncReq;
       
   403         
       
   404         /**
       
   405          * Async handler
       
   406          * Own.
       
   407          */
       
   408         MPresRulesAsyncHandler* iAsyncHandler;
       
   409         
       
   410         SIMPLE_UNIT_TEST( T_CPresencePluginXdmPresRules )
       
   411     };
       
   412 
       
   413 #endif // CPRESENCEPLUGINXDMPRESRULES_H