webservices/wsstar/wsstarpolicy/inc/senwspolicymanager.h
changeset 0 62f9d29f7211
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     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: Header declaration
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #ifndef SEN_WS_POLICY_MANAGER_H
       
    26 #define SEN_WS_POLICY_MANAGER_H
       
    27 
       
    28 // INCLUDES
       
    29 #include "msenwspolicymanager.h"
       
    30 
       
    31 #include <e32std.h>
       
    32 #include <flogger.h>    // RFileLogger
       
    33 
       
    34 #include <SenFragmentBase.h>
       
    35 #include <SenBaseFragment.h>
       
    36 #include <SenDomFragment.h>
       
    37 
       
    38 // FORWARD DECLARATIONS
       
    39 class MSenCoreServiceManager;
       
    40 class CSenWSPolicyIdentifier;
       
    41 class CSenWSPolicyProperties;
       
    42 class CSenParser;
       
    43 class CSenWSPolicyLoader;
       
    44 class CNormalizedPolicyConatiner;
       
    45 class CExpiredPolicy;
       
    46 class CConsumerContainer;
       
    47 // CLASS DECLARATION
       
    48 typedef RPointerArray<CNormalizedPolicyConatiner> RNormalizedArray;
       
    49 typedef RPointerArray<CExpiredPolicy> RExpiredPolicyArray;
       
    50 typedef RPointerArray<CConsumerContainer> RPolicyConsumerArray;
       
    51 
       
    52 class CSenWSPolicyManager: public CBase , public MSenWsPolicyManager
       
    53     {
       
    54     public:
       
    55         IMPORT_C static CSenWSPolicyManager* NewL(MSenCoreServiceManager& aManager);
       
    56 
       
    57         IMPORT_C static CSenWSPolicyManager* NewLC(MSenCoreServiceManager& aManager);
       
    58 
       
    59         IMPORT_C virtual ~CSenWSPolicyManager();
       
    60 
       
    61         IMPORT_C TInt RegisterWsPolicyL(CSenWSDescription* aPattern,
       
    62                                                             TInt& aErrorTo);
       
    63         
       
    64         IMPORT_C TInt UnRegisterWsPolicyL(CSenWSDescription* aPattern,
       
    65                                                     TInt& aErrorTo);
       
    66                                                                 
       
    67         //add a new Policy to existing SD whose endpoints are already registered by Register
       
    68         IMPORT_C TInt AddWsPolicyL(CSenWSDescription* aPattern, const TDesC8& aUri, 
       
    69                                                const TDesC8& aPolicy, TInt& aErrorTo);
       
    70                                                         
       
    71         //remove a policy from existing SD. The Metadataendpoint will not be removed
       
    72         IMPORT_C TInt RemoveWsPolicyL( CSenWSDescription* aPattern, 
       
    73                                                         const TDesC8& aUri, TInt& aErrorTo);    
       
    74 
       
    75 
       
    76         IMPORT_C CSenElement*  WsPolicyL( CSenWSDescription* aPattern, 
       
    77                                                         const TDesC8& aUri, TInt& aErrorTo);
       
    78 
       
    79         IMPORT_C TInt ExpiredPoliciesL(RExpiredPolicyArray& aArray,  TInt& aErrorTo);
       
    80         
       
    81         IMPORT_C TInt AddPolicyConsumerL(const TDesC8& aUri, const TDesC8& aConsumerId);
       
    82         
       
    83         IMPORT_C TInt RemovePolicyConsumerL(const TDesC8& aUri, const TDesC8& aConsumerId);
       
    84         
       
    85 
       
    86 
       
    87     //from MSenWsPolicyManager
       
    88         virtual TInt AddWsPolicy1L(CSenWSDescription* aPattern, const TDesC8& aUri,
       
    89                                                const TDesC8& aPolicy, TInt& aErrorTo);
       
    90 
       
    91         virtual TInt RemoveWsPolicy1L( CSenWSDescription* aPattern, 
       
    92                                                 const TDesC8& aUri, TInt& aErrorTo);
       
    93                                                                                                                                                                                                
       
    94         virtual TInt RegisterWsPolicy1L(CSenWSDescription* aPattern,
       
    95                                                     TInt& aErrorTo);
       
    96 
       
    97         virtual TInt UnRegisterWsPolicy1L(CSenWSDescription* aPattern,
       
    98                                                     TInt& aErrorTo);
       
    99                                                     
       
   100         virtual CSenElement*  WsPolicy1L( CSenWSDescription* aPattern, 
       
   101                                                 const TDesC8& aUri, TInt& aErrorTo);
       
   102 
       
   103         virtual CSenElement*  WsPolicy1L( CSenWSDescription* aPattern, 
       
   104                                                 TInt& aErrorTo);
       
   105 
       
   106         virtual CSenElement*  WsPolicy1L( const TDesC8& aProviderId, TInt& aErrorTo);
       
   107         
       
   108         virtual TInt AddPolicyConsumer1L(const TDesC8& aUri, const TDesC8& aConsumerId);
       
   109 
       
   110         virtual TInt RemovePolicyConsumer1L(const TDesC8& aUri, const TDesC8& aConsumerId);
       
   111 
       
   112 
       
   113     private:
       
   114 
       
   115         /**
       
   116         * C++ default constructor.
       
   117         */
       
   118         CSenWSPolicyManager(MSenCoreServiceManager& aManager);
       
   119 
       
   120         /**
       
   121         * By default Symbian 2nd phase constructor is private.
       
   122         */
       
   123         void ConstructL();
       
   124         CSenElement* PolicyFromUri(CSenWSDescription* aPolicy, const TDesC8& aUri);
       
   125         CSenElement* PolicyFromSDL(CSenWSDescription* aPolicy);  //codescannerwarnings
       
   126         CSenElement* PolicyByProviderId(const TDesC8& aProviderId, TInt&  aErrorTo);
       
   127         TInt IsContainerL(CSenInternalWsPolicy* aInternalPolicy);	//codescannerwarnings
       
   128         TInt CreatePolicyContainerL(CSenInternalWsPolicy* aInternalPolicy);  //codescannerwarnings
       
   129         TInt RefreshPolicyContainerL();  //codescannerwarnings
       
   130         TInt UpdatePolicyContainerL(CSenInternalWsPolicy* aInternalPolicy);
       
   131         TInt PolicyConsumerCountL(CSenInternalWsPolicy* aInternalPolicy); //codescannerwarnings
       
   132         TInt IsConsumerExist(const TDesC8& aEndpoint, const TDesC8& aConsumerId);
       
   133         RFileLogger* Log();
       
   134     private:
       
   135         MSenCoreServiceManager&     iManager;
       
   136         RFileLogger*                iLog;                   // not owned (no create/close)    
       
   137         CSenWSPolicyLoader* iPolicDataLoader;
       
   138         RNormalizedArray iPolicyArray;
       
   139         RPolicyConsumerArray iConsumerArray;
       
   140     
       
   141     };
       
   142 //Policy container holding the Normalized Policy
       
   143 class CNormalizedPolicyConatiner : public CBase
       
   144     {
       
   145     public:
       
   146         static CNormalizedPolicyConatiner* NewL(CSenInternalWsPolicy* aPolicy, const TDesC8& aUri);
       
   147 
       
   148         static CNormalizedPolicyConatiner* NewLC(CSenInternalWsPolicy* aPolicy, const TDesC8& aUri);
       
   149 
       
   150         virtual ~CNormalizedPolicyConatiner();
       
   151         
       
   152         TBool IsSameContainer(const TDesC8& aUri);
       
   153         TBool UpdateL(CSenInternalWsPolicy* aInternalPolicy);
       
   154         
       
   155         void CountInc();
       
   156         void CountDec();
       
   157         void SetConsumerCount(TInt aCount);
       
   158         TInt ConsumerCount();
       
   159         TPtrC8  Contract();
       
   160         TPtrC8  Endpoint();
       
   161         TPtrC8  ProviderId();        
       
   162         TPtrC8  URI();
       
   163         TTime  ValidUntil();
       
   164         CSenElement* Policy();
       
   165         
       
   166     private:
       
   167 
       
   168         /**
       
   169         * C++ default constructor.
       
   170         */
       
   171         CNormalizedPolicyConatiner();
       
   172 
       
   173         /**
       
   174         * By default Symbian 2nd phase constructor is private.
       
   175         */
       
   176         void ConstructL(CSenInternalWsPolicy* aPolicy, const TDesC8& aUri);    
       
   177     
       
   178     private:
       
   179         HBufC8* iContract;
       
   180         HBufC8* iEndpoint;
       
   181         HBufC8* iProviderId;
       
   182         HBufC8* iUri; //contents
       
   183         TTime iValidUntil; //contents
       
   184         TInt    iCount;
       
   185         CSenElement* iPolicy;    
       
   186     };
       
   187 //for loading and saving the DB    
       
   188 class CSenWSPolicyLoader : public CSenBaseFragment 
       
   189     {
       
   190     public: // Constructors and destructor
       
   191 
       
   192         /**
       
   193         * Two-phased constructor.
       
   194         */
       
   195         static CSenWSPolicyLoader* NewL(MSenCoreServiceManager& aManager);
       
   196 
       
   197         static CSenWSPolicyLoader* NewLC(MSenCoreServiceManager& aManager);
       
   198 
       
   199         virtual ~CSenWSPolicyLoader();
       
   200 
       
   201         /**
       
   202         * Load and parse Policies from the file.
       
   203         * Statuscodes:
       
   204         *   KErrNone                Ok
       
   205         *  Other codes are system error codes.
       
   206         * @return status code.
       
   207         */
       
   208         TInt LoadDBL();	//codescannerwarnings
       
   209 
       
   210         /**
       
   211         * Save Policies as an XML document into
       
   212         * the file.
       
   213         * Statuscodes:
       
   214         *   KErrNone                Ok
       
   215         *  Other codes are system error codes.
       
   216         * @return status code.
       
   217         */
       
   218         TInt SaveDB();
       
   219         TInt MergeToL();
       
   220         // From CSenBaseFragment
       
   221         /**
       
   222         * Callback function which implements the XML content handler interface.
       
   223         * @since Series60 3.0
       
   224         * @param aNsURI     The namespace URI of the new element
       
   225         * @param aLocalName The local name of the new element
       
   226         * @param aQName     The qualified name of the new element
       
   227         * @param aAttributes    The attributes of the new element
       
   228         */
       
   229         virtual void StartElementL(const TDesC8& aNsUri,
       
   230                                             const TDesC8& aLocalName,
       
   231                                             const TDesC8& aQName,
       
   232                                             const RAttributeArray& aAttributes);
       
   233 
       
   234         // From CSenBaseFragment 
       
   235         /**
       
   236         * Callback function which implement the XML content handler interface.
       
   237         * @since Series60 3.0
       
   238         * @param aNsUri     The namespace URI of the new element
       
   239         * @param aLocalName The local name of the new element
       
   240         * @param aQName     The qualified name of the new element
       
   241         */
       
   242         virtual void EndElementL(const TDesC8& aNsUri,
       
   243                                           const TDesC8& aLocalName,
       
   244                                       const TDesC8& aQName);
       
   245 
       
   246 //new Methods  
       
   247 
       
   248 		RSenWSPolicyPtr AddWsPolicyL(CSenInternalWsPolicy* apPolicy,
       
   249 		                                          TInt& aErrorTo);
       
   250                                                   
       
   251         TInt RegisterWsPolicyL(CSenWSDescription* aPattern,
       
   252                                                     TInt& aErrorTo);
       
   253         
       
   254                                                     
       
   255         
       
   256         TInt AddWsPolicyL(CSenWSDescription* aPattern, const TDesC8& aUri,
       
   257                                                const TDesC8& aPolicy, TInt& aErrorTo);
       
   258 
       
   259 
       
   260         TInt RemoveWsPolicyL( CSenWSDescription* aPattern, 
       
   261                                                 const TDesC8& aUri, TInt& aErrorTo);    
       
   262 
       
   263         CSenElement*  WsPolicyL( CSenWSDescription* aPattern, 
       
   264                                                 const TDesC8& aUri, TInt& aErrorTo);
       
   265                                                 
       
   266 
       
   267         TInt InternalWsPoliciesL(RSenWSPolicyArray& aPolicies);
       
   268         TInt UnRegisterWsPolicyL(CSenWSDescription* aPattern,
       
   269                                                     TInt& aErrorTo);
       
   270                                                        
       
   271 
       
   272 	protected:
       
   273 	    RFileLogger* Log();
       
   274 
       
   275     private:
       
   276 
       
   277         /**
       
   278         * C++ default constructor.
       
   279         */
       
   280         CSenWSPolicyLoader(MSenCoreServiceManager& aManager);
       
   281 
       
   282         /**
       
   283         * By default Symbian 2nd phase constructor is private.
       
   284         */
       
   285         void ConstructL();
       
   286 
       
   287         // New functions
       
   288 
       
   289         /**
       
   290         * Initialize this SenPolicyManager by parsing
       
   291         * the given file with the given XMLReader.
       
   292         * The file is expected to contain valid XML that
       
   293         * follows the example given above.
       
   294         * @param file
       
   295         * @param reader
       
   296         */
       
   297         void LoadFromL(const TDesC& aFile);
       
   298 
       
   299         /**
       
   300         * Save the current state of the SenPolicyManager as an XML
       
   301         * document into a file.
       
   302         * Status codes:
       
   303         *   KErrNone                Ok
       
   304         *   Other codes are system error codes.
       
   305         * @return status code.
       
   306         */
       
   307         TInt SaveToL( const TDesC& aFile );
       
   308 
       
   309 	    virtual TInt NextId();
       
   310 	    
       
   311 	    virtual void UpdateMaxId();
       
   312 	    CSenElement* CreatePolicyElementL(const TDesC8& aUri, const TDesC8& aPolicy);
       
   313 	    CSenElement* GetExpiryTagL(CSenElement& aPolicy);
       
   314 	    TInt EvaluateExpiryL(CSenElement* aExpiry, TTime& aExpiryTime);
       
   315 	    TInt ProcessNewPolicyL( const TDesC8& aUri, CSenElement& aPolicy);
       
   316         TInt InternalWsPolicyL(CSenWSDescription& aPattern,
       
   317 								  RSenWSPolicyArray& aPolicies);
       
   318         TInt InternalWsPolicyL(const TDesC8& aUri, RSenWSPolicyArray& aPolicies);
       
   319 
       
   320         TInt RegisterWsPolicyL(CSenInternalWsPolicy* aInternalPolicy,
       
   321                                                     TInt& aErrorTo);
       
   322         
       
   323         TInt AddWsPolicyL(const TDesC8& aUri, CSenElement* aPolicy, TInt& aErrorTo);
       
   324         TInt VerifyPolicyContentsL(CSenInternalWsPolicy* apInternalPolicy, TInt& aErrorTo); //codescannerwarnings
       
   325 								  
       
   326 
       
   327     private: // Data
       
   328         MSenCoreServiceManager&     iManager;
       
   329         RFileLogger*                iLog;                   // not owned (no create/close)    
       
   330 		RSenPolicyPtrArray      iPolicyArray;       // owned
       
   331 		
       
   332 		CSenBaseFragment*           ipPolicyContainer;  // owned
       
   333 		CSenWSPolicyIdentifier*   ipPolicyIdentifier; // owned
       
   334 		CSenInternalWsPolicy*     ipWSpolicy;           // owned
       
   335 		
       
   336 		TInt                        iMaxPolicyID;
       
   337     };
       
   338     
       
   339 //for Storing the Active consumer information
       
   340 class CConsumerContainer :public CBase
       
   341     {
       
   342     public:    
       
   343         static CConsumerContainer* NewL(const TDesC8& aUri, const TDesC8& aConsumerId);
       
   344         static CConsumerContainer* NewLC(const TDesC8& aUri, const TDesC8& aConsumerId);
       
   345         virtual ~CConsumerContainer();
       
   346         TPtrC8  Uri();
       
   347         TPtrC8  ConsumerId();
       
   348     private:
       
   349         CConsumerContainer();
       
   350         void ConstructL(const TDesC8& aUri, const TDesC8& aConsumerId);
       
   351 
       
   352         HBufC8* iConsumerId;
       
   353         HBufC8* iURI;
       
   354     };    
       
   355 //for getting the expired policies information    
       
   356 class CExpiredPolicy :public CBase
       
   357     {
       
   358     public:
       
   359         IMPORT_C static CExpiredPolicy* NewL(const TDesC8& aContract, const TDesC8& aEndpoint, 
       
   360                                             const TDesC8& aUri, const TDesC8& aProviderId);
       
   361         IMPORT_C static CExpiredPolicy* NewLC(const TDesC8& aContract, const TDesC8& aEndpoint, 
       
   362                                             const TDesC8& aUri, const TDesC8& aProviderId);
       
   363         IMPORT_C virtual ~CExpiredPolicy();
       
   364 
       
   365 
       
   366         IMPORT_C TPtrC8  Contract();
       
   367         IMPORT_C TPtrC8  Endpoint();
       
   368         TPtrC8  ProvideId();
       
   369         IMPORT_C TPtrC8  Uri();
       
   370         IMPORT_C TPtrC8  Contents();
       
   371 
       
   372         IMPORT_C TInt    SetContentsL(const TDesC8& aContent);
       
   373         
       
   374     private:
       
   375         CExpiredPolicy();
       
   376         void ConstructL(const TDesC8& aContract, const TDesC8& aEndpoint, const TDesC8& aUri, const TDesC8& aProviderId);
       
   377         
       
   378     private:
       
   379         HBufC8* iContract; //service contract
       
   380         HBufC8* iEndpoint; //service contract
       
   381         HBufC8* iProvideId; //service contract
       
   382         HBufC8* iURI; //uri to download
       
   383         HBufC8* iContents; //contents
       
   384     };
       
   385 #endif // SEN_WS_POLICY_MANAGER_H
       
   386 
       
   387 // End of File