phonesrv_plat/cenrep_database_api/inc/cenrepdatabaseutil.h
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Utility class to central repository database.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_CENREPDATABASEUTIL_H
       
    22 #define C_CENREPDATABASEUTIL_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <cenrepdatabaseproperty.h>
       
    26 
       
    27 
       
    28 class CRepository;
       
    29 
       
    30 /**
       
    31  *  Utility class to accessing tables in central repository database
       
    32  * 
       
    33  *
       
    34  *  Support tables formatted in following way:
       
    35  * 
       
    36  *    //-----------------------------------------------------
       
    37  *    //| KColId  | KColProp1 | KColProp2 | ... | KColPropX |
       
    38  *    //|  (int)  |  (des)    |  (des)    |     |   (des)   |
       
    39  *    //-----------------------------------------------------
       
    40  *    //|   1     |  "Prop a" |  "Prop x" | ... |  "aaa"    |
       
    41  *    //|   7     |  "Prop b" |  "Prop y" | ... |  "bbb"    |
       
    42  *    //|   15    |  "Prop c" |  "Prop z" | ... |  "ccc"    |
       
    43  *    //|   0     |    ""     |    ""     | ... |    ""     |
       
    44  *    //|   0     |    ""     |    ""     | ... |    ""     |
       
    45  *    //|   ...   |    ...    |    ...    | ... |    ...    |
       
    46  *   //------------------------------------------------------
       
    47  *
       
    48  *
       
    49  *  @code
       
    50  *  @endcode
       
    51  *
       
    52  *  @lib cenrepdatabase.lib
       
    53  *  @since S60 v3.2 
       
    54  */
       
    55 NONSHARABLE_CLASS( CCenRepDatabaseUtil ) : public CBase
       
    56     {
       
    57     public:
       
    58 
       
    59         /**
       
    60          * Two-phased constructor.
       
    61          */
       
    62         IMPORT_C static CCenRepDatabaseUtil* NewL( TUid aUid, 
       
    63                                                  TUint32 aStartKey, 
       
    64                                                  TUint32 aColIncrement, 
       
    65                                                  TUint32 aColMask,
       
    66                                                  TUint32 aIdCounterKey,
       
    67                                                  TInt aColCount );
       
    68         /**
       
    69          * Two-phased constructor.
       
    70          */
       
    71         IMPORT_C static CCenRepDatabaseUtil* NewLC( TUid aUid, 
       
    72                                                   TUint32 aStartKey, 
       
    73                                                   TUint32 aColIncrement, 
       
    74                                                   TUint32 aColMask,
       
    75                                                   TUint32 aIdCounterKey,
       
    76                                                   TInt aColCount );
       
    77 
       
    78         /**
       
    79         * Destructor.
       
    80         */
       
    81         IMPORT_C virtual ~CCenRepDatabaseUtil();
       
    82         
       
    83     public: 
       
    84 	    /**
       
    85 	     * Start transaction in repository. 
       
    86 	     * Note. Function leaves two cleanup items to cleanupstack and those
       
    87 	     * are freed when CommitTransaction or RollbackTransaction is called.
       
    88 	     *
       
    89 	     * @since S60 v3.2
       
    90 	     */
       
    91 	    IMPORT_C void BeginTransactionL();
       
    92 
       
    93 	    /**
       
    94 	     * Commit changes in repository
       
    95 	     *
       
    96 	     * @since S60 v3.2
       
    97 	     * @return An error code
       
    98 	     */
       
    99 	    IMPORT_C TInt CommitTransaction();
       
   100 	    
       
   101 	    /**
       
   102 	     * Rollback changes in repository
       
   103 	     *
       
   104 	     * @since S60 v3.2
       
   105 	     */
       
   106 	    IMPORT_C void RollbackTransaction();
       
   107 	    
       
   108 	    /**
       
   109 	     * Store new entry to table.
       
   110 	     *
       
   111 	     * @since S60 v3.2
       
   112 	     * @param aEntryId Contains new ID when returns.
       
   113 	     * @param aArray Container for properties of this entry.
       
   114 	     */
       
   115 	    IMPORT_C void AddEntryL(  TInt& aEntryId, const RIpAppPropArray& aArray );
       
   116 
       
   117 	    /**
       
   118 	     * Search entry by entry ID. 
       
   119 	     *
       
   120 	     * @since S60 v3.2
       
   121 	     * @param aEntryId Id of requested entry
       
   122 	     * @param aArray on return, property array.
       
   123 	     * @return error code, KErrNotFound if unknown entry.
       
   124 	     */
       
   125 	    IMPORT_C TInt FindEntryL( TInt aEntryId, RIpAppPropArray& aArray );
       
   126 
       
   127 	    /**
       
   128 	     * Updates entry to central repository
       
   129 	     *
       
   130 	     * @since S60 v3.2
       
   131 	     * @param aEntryId Id of requested entry
       
   132 	     * @param aArray Updated properties of entry
       
   133 	     * @return error code, KErrNotFound if unknown entry.
       
   134 	     */
       
   135 	    IMPORT_C TInt UpdateEntryL( TInt aEntryId, 
       
   136 	                                const RIpAppPropArray& aArray );
       
   137 
       
   138 	    /**
       
   139 	     * Deletes settings entry from storage by entry ID.
       
   140 	     *
       
   141 	     * @since S60 v3.2
       
   142 	     * @param aEntryId Id of entry which is going to be deleted
       
   143 	     * @return error code, KErrNone if delete succeeded, otherwise system wide error code
       
   144 	     */
       
   145 	    IMPORT_C TInt DeleteEntryL( TInt aEntryId );
       
   146 
       
   147 	    /**
       
   148 	     * Search property of entry from storage.
       
   149 	     *
       
   150 	     * @since S60 v3.2
       
   151 	     * @param aEntryId The entry ID of requested entry
       
   152 	     * @param aPropertyName property name to be found
       
   153 	     * @param aProperty on return, requested property
       
   154 	     * @return error code, KErrNone if succeeded, otherwise system wide error code
       
   155 	     */
       
   156 	    IMPORT_C TInt FindPropertyL( TInt aEntryId, 
       
   157          	                         TUint32 aPropertyName,
       
   158 	                                 CCenRepDatabaseProperty& aProperty );
       
   159 
       
   160 	    /**
       
   161 	     * Add or update properties of entry in table.
       
   162 	     * Values of existing properties are overwritten.
       
   163 	     *
       
   164 	     * @since S60 v3.2
       
   165 	     * @param aEntryId The ID of updated entry
       
   166 	     * @param aArray new properties to be added or updated
       
   167          * @return error code, KErrNotFound if unknown entry.
       
   168 	     */
       
   169 	    IMPORT_C TInt AddOrUpdatePropertiesL( TInt aEntryId, 
       
   170 	                                          const RIpAppPropArray& aArray );
       
   171 
       
   172 
       
   173 	    /**
       
   174 	     * Delete properties of entry in table.
       
   175 	     *
       
   176 	     * @since S60 v3.2
       
   177 	     * @param aEntryId The entry ID of requested entry
       
   178 	     * @param aNameArray name of properties to be deleted
       
   179 	     * @return error code, KErrNotFound if unknown entry.
       
   180 	     */
       
   181 	    IMPORT_C TInt DeletePropertiesL( TInt aEntryId,
       
   182 	                                     const RArray<TUint32>& aNameArray );
       
   183 
       
   184 	    /**
       
   185 	     * Return count of entries in table.
       
   186 	     *
       
   187 	     * @since S60 v3.2
       
   188 	     * @return Count of stored settings.
       
   189 	     */
       
   190 	    IMPORT_C TInt EntryCountL( TInt& aCount );
       
   191 
       
   192 	    /**
       
   193 	     * Search all entry IDs from storage
       
   194 	     *
       
   195 	     * @since S60 v3.2
       
   196 	     * @param aEntryIds An array containing returned entry IDs
       
   197 	     * @return error code
       
   198 	     */
       
   199 	    IMPORT_C TInt FindEntryIdsL( RArray<TInt>& aEntryIds );
       
   200                                    
       
   201 	    /**
       
   202 	     * Find entry IDs with same properties
       
   203 	     *
       
   204 	     * @since S60 v3.2
       
   205 	     * @param aPropertyArray property array
       
   206 	     * @param aEntryIds on return, entry Ids with same properties
       
   207 	     * @return error code
       
   208 	     */
       
   209 	    IMPORT_C TInt FindEntryIdsFromPropertiesL( const RIpAppPropArray& aPropertyArray, 
       
   210 	                                               RArray<TInt>& aEntryIds );
       
   211 	    
       
   212         
       
   213     private:
       
   214 
       
   215         /**
       
   216          * C++ default constructor.
       
   217          */
       
   218         CCenRepDatabaseUtil( TUint32 aStartKey, 
       
   219                            TUint32 aColIncrement, 
       
   220                            TUint32 aColMask,
       
   221                            TUint32 aIdCounterKey,
       
   222                            TInt aColCount );
       
   223 
       
   224         /**
       
   225          * By default Symbian 2nd phase constructor is private.
       
   226          */
       
   227         void ConstructL( TUid aUid );
       
   228 
       
   229 	    /**
       
   230 	     * Release semaphore, this function is used in custom cleanup
       
   231 	     * 
       
   232 	     * @since S60 v3.2
       
   233 	     * @param aPtr Pointer to an object which is the target of the cleanup operation
       
   234 	     */
       
   235         static void ReleaseSemaphore( TAny* aPtr );
       
   236 
       
   237 	    /**
       
   238 	     * Release semaphore
       
   239 	     * 
       
   240 	     * @since S60 v3.2
       
   241 	     */
       
   242         void DoReleaseSemaphore();
       
   243 
       
   244 	    /**
       
   245 	     * Set new value for given key. Creates the key if it doesn't exists.
       
   246 	     *
       
   247 	     * @since S60 v3.2
       
   248 	     * @param aKey
       
   249 	     * @param aValue
       
   250 	     */
       
   251         template<class T> void SetOrCreateKeyL( TUint32 aKey, 
       
   252                                                 const T& aValue );
       
   253                                                 
       
   254 	    /**
       
   255 	     * Create new ID for entry.
       
   256 	     *
       
   257 	     * @since S60 v3.2
       
   258 	     * @param aNewId Contains new ID when return.
       
   259 	     */
       
   260         void CreateEntryIdL( TInt& aNewId );
       
   261         
       
   262 	    /**
       
   263 	     * Defines next available key for ID.
       
   264 	     *
       
   265 	     * @since S60 v3.2
       
   266 	     * @return New key for ID
       
   267 	     */
       
   268         TUint32 GetNewIdKeyL( );
       
   269         
       
   270 	    /**
       
   271 	     * Update given properties of entry.
       
   272 	     *
       
   273 	     * @since S60 v3.2
       
   274 	     * @param aIdKey
       
   275 	     * @param Array Contains updated properties and values
       
   276 	     */
       
   277         void UpdatePropertiesL( TUint32 aIdKey, const RIpAppPropArray& aArray );
       
   278         
       
   279 	    /**
       
   280 	     * Check if entry has given properties.
       
   281 	     *
       
   282 	     * @since S60 v3.2
       
   283 	     * @param aEntryId Id of entry.
       
   284 	     * @param aPropertyArray Properties to be checked.
       
   285              * @param aOk Result
       
   286 	     */
       
   287         void CheckEntryHasPropertiesL( TInt aEntryId, const RIpAppPropArray& aPropertyArray, TBool& aOk );
       
   288         
       
   289 	    /**
       
   290 	     * Custom cleanup for array.
       
   291 	     *
       
   292 	     * @since S60 v3.2
       
   293 	     * @param aPointer
       
   294 	     */
       
   295         static void CleanupPointerArray( TAny* aPointer );
       
   296         
       
   297         
       
   298     private: // data
       
   299     
       
   300 	    /**
       
   301 	     * Central Repository object.
       
   302 	     * Own.
       
   303 	     */
       
   304 	    CRepository* iRepository;
       
   305 	    
       
   306 	    /**
       
   307 	     * RSemaphore object.
       
   308 	     * Own.
       
   309 	     */
       
   310 	    RSemaphore iSemaphore;
       
   311 	    
       
   312 	    /**
       
   313 	     * Start key in first column( Id column )
       
   314 	     */
       
   315 	    TUint32 iStartKey;
       
   316 
       
   317 	    /**
       
   318 	     * Column increment
       
   319 	     */
       
   320 	    TUint32 iColIncrement;
       
   321 
       
   322 	    /**
       
   323 	     * Column mask
       
   324 	     */
       
   325 	    TUint32 iColMask;
       
   326 	    
       
   327 	    /**
       
   328 	     * Id counter key
       
   329 	     */
       
   330 	    TUint32 iIdCounterKey;
       
   331 	    
       
   332 	    /**
       
   333 	     * Column count
       
   334 	     */
       
   335 	    TInt iColCount;
       
   336 
       
   337     private: // For testing
       
   338         #ifdef TEST_EUNIT
       
   339             friend class UT_CCenRepDatabaseUtil;
       
   340         #endif
       
   341 
       
   342     };
       
   343 
       
   344 
       
   345 #endif // C_CENREPDATABASEUTIL_H