metadataengine/client/inc/mdeenginesession.h
changeset 0 c53acadfccc6
child 2 b73a2e62868f
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2005-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:  This is Metadata engine client session file
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __MDEENGINESESSION_H__
       
    20 #define __MDEENGINESESSION_H__
       
    21 
       
    22 // INCLUDE FILES
       
    23 #include <e32std.h>
       
    24 #include <e32base.h>
       
    25 #include <badesca.h>
       
    26 
       
    27 #include "mdscommoninternal.h"
       
    28 #include "mdequery.h"
       
    29 #include "mdeharvestersession.h"
       
    30 
       
    31 // CONSTANTS
       
    32 // Number of message slots to reserve for this client server session.
       
    33 // 27 = 1 asynchronous find + max.25 pending notifier hooks + 1 extra
       
    34 const TUint KMetadataMessageSlots = 27;
       
    35 
       
    36 const TUid KServerUid3 = { 0x0765EEC3 }; // Server UID
       
    37 
       
    38 _LIT( KMdSServerFilename, "MdSServer" );
       
    39 
       
    40 #ifdef __WINS__
       
    41 static const TUint KServerMinHeapSize = 0x10000;
       
    42 static const TUint KServerMaxHeapSize = 0x400000; // ~4 megs
       
    43 #endif
       
    44 
       
    45 // FORWARD DECLARATIONS
       
    46 class CMdESessionImpl;
       
    47 class CMdESchemaItem;
       
    48 class CMdEInstanceItem;
       
    49 class CMdEQuery;
       
    50 class CMdEQueryCriteriaSerialization;
       
    51 class CMdCSerializationBuffer;
       
    52 class TMdEObject;
       
    53 
       
    54 // CLASS DECLARATION
       
    55 /**
       
    56 * RMdEEngineSession
       
    57 *  This class provides the client-side interface to the server session
       
    58 */
       
    59 class RMdEEngineSession : public RSessionBase
       
    60     {
       
    61     public: // Constructors and destructors
       
    62 
       
    63         /**
       
    64         * RMdEEngineSession.
       
    65         * Constructs the object.
       
    66         */
       
    67         RMdEEngineSession(CMdESessionImpl& aSession);
       
    68 
       
    69     public: // New functions
       
    70 
       
    71         /**
       
    72         * Open server.
       
    73         * Connects to the server.
       
    74         * @return Error code.
       
    75         */
       
    76         void OpenL(TRequestStatus& aStatus);
       
    77         
       
    78         /**
       
    79         * Cancel server opening.
       
    80         * Cancels server opening.
       
    81         * @return Error code.
       
    82         */
       
    83        void OpenCancel(TRequestStatus& aStatus);
       
    84 
       
    85         /**
       
    86         * Connect session to server.
       
    87         * Create a session.
       
    88         * @return Error code.
       
    89         */
       
    90         void ConnectL();
       
    91 
       
    92         /**
       
    93         * Shut down session
       
    94         * Performs session shutdown activities in server end
       
    95         * @return Error code.
       
    96         */
       
    97         TInt Shutdown();
       
    98 
       
    99         /**
       
   100         * Version.
       
   101         * Gets the version number.
       
   102         * @return The version.
       
   103         */
       
   104         TVersion Version() const;
       
   105 
       
   106         /**
       
   107          * Adds an event definition to the database.
       
   108          * @param aNameSpaceId id of the namespace to add the definition into
       
   109          * @param aName name of the event
       
   110          */
       
   111 		void DoAddEventDefL(const TDefId aNameSpaceId, const TDesC &aName );
       
   112 
       
   113 		/**
       
   114 		 * Adds a relation definition to the database.
       
   115 		 * @param aNameSpaceId id of the namespace to add the definition into
       
   116 		 * @param aName name of the relation
       
   117 		 */
       
   118 		void DoAddRelationDefL(const TDefId aNameSpaceId, const TDesC &aName );
       
   119 
       
   120 		/**
       
   121 		 * Adds items to the database.
       
   122 		 * @param aSerializedBuffer items serialized in a buffer
       
   123 		 * @param aResultBuffer on return contains serialized results
       
   124 		 */
       
   125         void DoAddItemsL( const CMdCSerializationBuffer& aSerializedBuffer, CMdCSerializationBuffer& aResultBuffer );
       
   126 
       
   127         /**
       
   128 		 * Adds items to the database asynchronously.
       
   129 		 * @param aSerializedBuffer items serialized in a buffer
       
   130 		 * @param aResultBuffer on return contains serialized results
       
   131 		 * @param aStatus the asynchronous response status
       
   132 		 */
       
   133         void DoAddItemsAsync( const CMdCSerializationBuffer& aSerializedBuffer, CMdCSerializationBuffer& aResultBuffer, TRequestStatus& aStatus );
       
   134 
       
   135         /**
       
   136 		 * Removes items from the database.
       
   137 		 * @param aRemoveId item ids serialized in a buffer
       
   138 		 * @param aSuccessfulId on return contains ids of successfully remove items in a serialization buffer.
       
   139 		 */
       
   140         void DoRemoveItemsL( const CMdCSerializationBuffer& aRemoveId, CMdCSerializationBuffer& aSuccessfulId );
       
   141 
       
   142         /**
       
   143 		 * Removes items from the database asynchronously.
       
   144 		 * @param aRemoveId item ids serialized in a buffer
       
   145 		 * @param aSuccessfulId on return contains ids of successfully remove items in a serialization buffer.
       
   146 		 * @param aStatus the asynchronous response status
       
   147 		 */
       
   148         void DoRemoveItemsAsync( const CMdCSerializationBuffer& aRemoveId, CMdCSerializationBuffer& aSuccessfulId, TRequestStatus& aStatus );
       
   149 
       
   150         /**
       
   151          * Updates items in the database.
       
   152          * @param aSerializedBuffer serialized buffer of updated items
       
   153          * @param aResultBuffer on return contains serialized results
       
   154          */
       
   155         void DoUpdateItemsL( const CMdCSerializationBuffer& aSerializedBuffer, CMdCSerializationBuffer& aResultBuffer );
       
   156 
       
   157         /**
       
   158          * Updates items in the database asynchronously.
       
   159          * @param aSerializedBuffer serialized buffer of updated items
       
   160          * @param aResultBuffer on return contains serialized results
       
   161          * @param aStatus the asynchronous response status
       
   162          */
       
   163         void DoUpdateItemsAsync( const CMdCSerializationBuffer& aSerializedBuffer, CMdCSerializationBuffer& aResultBuffer, TRequestStatus& aStatus );
       
   164 
       
   165         /**
       
   166          * Finds objects synchronously.
       
   167          * @param aQuery the query
       
   168          * @param aSerializationBuffer query criterias serialiazed in a buffer
       
   169          * @param aLocktype how the object should be locked during the query
       
   170          * @param aNotifyCount count indicating how often the client should be notified
       
   171          */
       
   172         CMdCSerializationBuffer* DoFindSyncLC( 
       
   173         	const CMdEQuery* aQuery, 
       
   174         	const CMdEQueryCriteriaSerialization& aSerializationBuffer,
       
   175             TMdCQueryLockType aLocktype,TUint32 aNotifyCount);
       
   176             
       
   177         /**
       
   178         * Finds objects asynchronously
       
   179         * @param 
       
   180         * @param 
       
   181         * @param 
       
   182         * @param aAsyncStatus the asynchronous response status
       
   183         */
       
   184         void DoFindAsync(
       
   185         	TUint32 aQueryId, 
       
   186             const CMdEQueryCriteriaSerialization& aSerializationBuffer,
       
   187             TPckgBuf<TInt>* aSizeBuf,
       
   188             TRequestStatus& aAsyncStatus, 
       
   189             TUint32 aNotifyCount = KMdEQueryDefaultMaxCount);
       
   190 
       
   191         /**
       
   192         * Continues a step in an existing asynchronous find
       
   193         * @param 
       
   194         * @param 
       
   195         * @param aAsyncStatus the asynchronous response status
       
   196         */
       
   197         void DoFindContinue( 
       
   198         	const CMdEQuery* aQuery, 
       
   199             TPckgBuf<TInt>* aSizeBuf,
       
   200             TRequestStatus& aAsyncStatus );
       
   201 
       
   202         /**
       
   203         * Cancels ongoing find
       
   204         */
       
   205         void DoFindCancelL( const CMdEQuery* aQuery );
       
   206 
       
   207         /**
       
   208         * Registers for notifications
       
   209         */
       
   210         void DoRegisterL( TInt aId,
       
   211             TUint32 aType,
       
   212             CMdCSerializationBuffer& aBuffer,
       
   213             TDefId aNamespaceDefId );
       
   214 
       
   215         /**
       
   216         * Continues registration for more notifications
       
   217         */
       
   218         void DoListen( TInt aId,
       
   219             TPckgBuf<TInt>* aSizeBuf,
       
   220             TRequestStatus& aAsyncStatus );
       
   221 
       
   222         /**
       
   223         * Unregisters observer for no more notifications
       
   224         */
       
   225         void DoUnregisterL( TInt aId );
       
   226 
       
   227         /**
       
   228         * DoLoadSchemaL.
       
   229         * Gets find results to client 
       
   230         * @param aHandle handle to shared memory chunk
       
   231         */
       
   232         void DoLoadSchemaL( TInt& aHandle );
       
   233 
       
   234         /**
       
   235         * DoGetDataL.
       
   236         * Gets data to client.
       
   237         * @param aQuery the query ID
       
   238         * @param aSize number of bytes to reserve for hierarchy
       
   239         * @param aRelatedCommand command related to which the data is obtained.
       
   240         * @param aExtraData an optional id specifying the identity of the data to obtain.
       
   241         */
       
   242 		void DoGetDataL( const CMdEQuery* aQuery, 
       
   243 			CMdCSerializationBuffer* aResultBuffer, 
       
   244 			TUint32 aRelatedCommand, TUint32 aExtraData = 0 );
       
   245         /**
       
   246         * DoGetDataL.
       
   247         * Gets data from the server for a notifier AO
       
   248         * @param aBuffer The data buffer to read to from the server
       
   249         * @param aId The id of the observer requesting the data
       
   250         */
       
   251 		void DoGetDataL( CMdCSerializationBuffer& aBuffer, TUint32 aId );
       
   252 
       
   253 		void DoCheckObjectL( CMdCSerializationBuffer& aObjectBuffer, 
       
   254 				const TDesC& aUri, TDefId aNamespaceDefId );
       
   255 
       
   256 		void DoCheckObjectL( CMdCSerializationBuffer& aObjectBuffer, 
       
   257 				TItemId aId, TDefId aNamespaceDefId );
       
   258 
       
   259 		void DoCheckObjectL( CMdCSerializationBuffer& aObjectsBuffer, 
       
   260 				const CMdCSerializationBuffer& aObjectIdsBuffer, 
       
   261 				TDefId aNamespaceDefId );
       
   262 
       
   263         /**
       
   264         * Commits changes to objects to database
       
   265         * @param aCodedObjects objects in coded form
       
   266         */
       
   267         void DoCommitObjectsL( const CMdCSerializationBuffer& aCodedObjects );
       
   268 
       
   269         /**
       
   270         * Cancels changes to object to database
       
   271         * @param aCodedId id of locked object in coded form
       
   272         */
       
   273         void DoCancelObjectL( CMdCSerializationBuffer& aRemoveId );
       
   274 
       
   275         /**
       
   276          * Imports schema from a file.
       
   277          * @param aFilename schema file name
       
   278          */
       
   279         void DoImportSchemaL( const TDesC& aFileName );
       
   280     
       
   281         /**
       
   282          * Imports metadata from a file.
       
   283          * @param aFilename metadata file name
       
   284          */
       
   285         TInt DoImportMetadataL( const TDesC& aFileName );
       
   286 
       
   287         /**
       
   288          * Imports metadata from a file asynchronously.
       
   289          * @param aFilename metadata file name
       
   290          * @param aResult packaged error code
       
   291          * @param aStatus asynchronous request status
       
   292          */
       
   293         void DoImportMetadata( const TDesC& aFileName, TPckgBuf<TInt>& aResult, TRequestStatus& aStatus );
       
   294 
       
   295         /**
       
   296          * Exports metadata into a file.
       
   297          * @param aFilename metadata file name
       
   298          * @param aItems items to export in a serialized buffer
       
   299          */
       
   300         void DoExportMetadataL( const TDesC& aFileName, const CMdCSerializationBuffer& aItems );
       
   301 
       
   302         /**
       
   303          * Exports metadata into a file asynchronously.
       
   304          * @param aFilename metadata file name
       
   305          * @param aItems items to export in a serialized buffer
       
   306          * @param aStatus asynchronous request status
       
   307          */
       
   308         void DoExportMetadataL( const TDesC& aFileName, const CMdCSerializationBuffer& aItems,
       
   309 								TRequestStatus& aStatus);
       
   310 
       
   311         /**
       
   312     	 * Add memory card with given media ID and current time. If memory card 
       
   313     	 * already exist only time is updated to current time.
       
   314     	 * @param memory card's media ID
       
   315     	 */
       
   316 		void DoAddMemoryCard(TUint32 aMediaId);
       
   317 
       
   318 		/**
       
   319 		 * Get latest memory card's media ID.
       
   320 		 * @param returned memory card's media ID
       
   321 		 * @return EFalse if there is no any memory cards added
       
   322 		 */
       
   323 		TBool DoGetMemoryCard(TUint32& aMediaId);
       
   324 		
       
   325 	    /**
       
   326 		 * Check if there is memory card with given media ID.
       
   327 		 * @param memory card's media ID
       
   328 		 * @param returned boolean if memory card exists or not
       
   329 		 * @return EFalse if there was error
       
   330 		 */
       
   331 		TBool DoCheckMemoryCard(TUint32 aMediaId, TBool& aExist);
       
   332 
       
   333 		/**
       
   334 		 * Set media's media ID, drive and present state.
       
   335 		 * 
       
   336 		 * @param media's media ID
       
   337 		 * @param media's drive
       
   338 		 * @param media's present state
       
   339 		 */
       
   340 		void DoSetMediaL(TUint32 aMediaId, TChar aDrive, TBool aPresentState);
       
   341 
       
   342 		/**
       
   343 		 * Get media's drive and present state by media ID.
       
   344 		 * 
       
   345 		 * @param aMediaId media's media ID
       
   346 		 * @param aDrive returned media's drive
       
   347 		 * @param aPresent returned media's present state
       
   348 		 * @return EFalse if there is no media with matching media ID in DB
       
   349 		 */
       
   350 		TBool DoGetMediaL(TUint32 aMediaId, TChar& aDrive, 
       
   351 				TBool& aPresentState);
       
   352 
       
   353 	    /**
       
   354 		 * Get present medias' media IDs and drives.
       
   355 		 * 
       
   356 		 * @param aMedias returned present medias' media IDs and drives
       
   357 		 */
       
   358 		void DoGetPresentMediasL(RArray<TMdEMediaInfo>& aMedias);
       
   359 		
       
   360 		/**
       
   361 	     * Set file to present state.
       
   362 	     *
       
   363 	     * @param aMediaId file's media ID
       
   364 	     * @param aUri file's URI
       
   365 	     * @param aFileInfo file's modified date and byte size
       
   366 	     *
       
   367 	     * @return ETrue if file existed and changing to present state was 
       
   368 	     *               successful
       
   369 	     */
       
   370 		TBool DoSetFileToPresent(TUint32 aMediaId, const TDesC& aUri, 
       
   371 				TMdSFileInfo& aFileInfo);
       
   372 
       
   373 		/**
       
   374 		 * Set files to present state.
       
   375 		 * 
       
   376 		 * @param aMediaIdAndCount files' media ID and file count
       
   377 		 * @param aUris serialized files' URIs
       
   378 		 * @param aFileInfos serialized files' modified dates and byte sizes
       
   379 		 * @param aResults serialized values from TFilePresentStates
       
   380 		 * 
       
   381 		 * @return Error code
       
   382 		 */
       
   383 		TInt DoSetFilesToPresent(TMdSMediaIdAndCount aMediaIdAndCount, 
       
   384 				const TDes8& aUris, const TDes8& aFileInfos, TDes8& aResults);		
       
   385 		
       
   386 		
       
   387 		/**
       
   388 		 * Set all files, which media ID is given, to not present state.
       
   389 		 *
       
   390 		 * @param aMediaId media ID
       
   391 		 * @param aStartUp is start up or normal unmount
       
   392 		 */		
       
   393 		void DoSetFilesToNotPresent(TUint32 aMediaId, TBool aStartUp);
       
   394 
       
   395 		/**
       
   396 	     * Remove all objects, which are in not present state, with given media ID
       
   397 	     * 
       
   398 		 * @param aMediaId media ID
       
   399 		 * @param aStartUp is start up or normal mount
       
   400 	     */
       
   401 		void DoRemoveFilesNotPresent(TUint32 aMediaId, TBool aStartUp);
       
   402 
       
   403 		/**
       
   404 		 * Get schema version's major and minor version.
       
   405 		 *
       
   406 		 * @param aMajorVersion returned major version
       
   407 		 * @param aMinorVersion returned minor version
       
   408 		 */
       
   409 		void DoGetSchemaVersionL(TInt& aMajorVersion, TInt& aMinorVersion);
       
   410 
       
   411 		/**
       
   412 		 * Set object to "present" state by GUID.
       
   413 		 *
       
   414 		 * @param aGuidHigh Guid's high part
       
   415 		 * @param aGuidLow Guid's low part
       
   416 		 * 
       
   417 		 * @leave KErrNotFound MdE can't find object in "not present" state 
       
   418 		 *                     with matching GUID
       
   419 		 * 
       
   420 		 */
       
   421 		void DoSetObjectToPresentByGuidL( 
       
   422 				const TInt64& aGuidHigh, const TInt64& aGuidLow );
       
   423 		
       
   424 		/**
       
   425 		 * Set global harvester prioritization chunk to MdE Server. There can 
       
   426 		 * be only one chunk and observer at once. If MdE Server already 
       
   427 		 * contains active observer, old observer completes with KErrAbort, 
       
   428 		 * chunk is always changed to this new one. Observer is added using 
       
   429 		 * DoAddHarvestingPrioritizationObserver.
       
   430          * @param aHandle the handle of global chunk that will receive object 
       
   431          *                URIs which need to be prioritize
       
   432          */
       
   433 		void DoSetHarvestingPrioritizationChunkL( RHandleBase aHandle );
       
   434 
       
   435 		/**
       
   436 		 * Add harvester prioritization observer to MdE Server. There can be 
       
   437 		 * only one chunk and observer at once. If MdE Server already contains 
       
   438 		 * active observer, aStatus completes with KErrAlreadyExists. When MdE 
       
   439 		 * Server needs prioritize object, aStatus completes with KErrNone.
       
   440          * @param aStatus the asynchronous response status which is changed 
       
   441          *                when there is object URIs to be prioritize
       
   442 		 */
       
   443 		void DoAddHarvestingPrioritizationObserver( TRequestStatus& aStatus );
       
   444 
       
   445 		/**
       
   446 		 * Cancel harvester prioritization observer from MdE Server. 
       
   447 		 * @return If MdE Server doesn't have outstanding observer method 
       
   448 		 *         returns KErrNotFound, otherwise KErrNone is returned.
       
   449 		 */
       
   450 		TInt DoCancelHarvestingPrioritizationObserver();
       
   451 		
       
   452 		/**
       
   453 		 * Change path of objects.
       
   454 		 * 
       
   455 		 * @param aOldPath old path
       
   456 		 * @param aNewPath new path
       
   457 	     * @param aStatus the asynchronous response status which is changed when 
       
   458 	     *                URIs are changed
       
   459 		 */
       
   460 		void DoChangePath( const TDesC& aOldPath, const TDesC& aNewPath,
       
   461 				TRequestStatus& aStatus );
       
   462 		
       
   463 		/**
       
   464 		 * Change C-drive media id to MdS_Medias table and update it to all objects.
       
   465 		 */
       
   466 		void DoChangeCDriveMediaId();
       
   467 		
       
   468 		/**
       
   469 		 * Set "binary composing to file" pending flag to objects
       
   470 		 *
       
   471 		 * @param aObjectId object IDs
       
   472 		 */
       
   473 		void DoSetPendingL( const RArray<TItemId>& aObjectIds );
       
   474 
       
   475 		/**
       
   476 		 * Reset "binary composing to file" pending flag from objects
       
   477 		 *
       
   478 		 * @param aObjectId object IDs
       
   479 		 */
       
   480 		void DoResetPendingL( const RArray<TItemId>& aObjectIds );
       
   481 
       
   482 		/**
       
   483 		 * Get count of objects with "binary composing to file" pending flag
       
   484 		 *
       
   485 		 * @param aObjectDef object definition which limits what objects are
       
   486 		 *                   returned or NULL when all objects are returned
       
   487 		 * 
       
   488 		 * @return count of objects
       
   489 		 */
       
   490 		TInt DoGetPendingCount( const CMdEObjectDef* aObjectDef );
       
   491 		
       
   492 		/**
       
   493 		 * Get IDs from objects with "binary composing to file" pending flag
       
   494 		 *
       
   495 		 * @param aObjectDef object definition which limits what objects are
       
   496 		 *                   returned or NULL when all objects are returned
       
   497 		 * @param aObjectIdCount count of returned object IDs
       
   498 		 * @param aObjectIdBuffer serialized buffer of returned object IDs
       
   499 		 * 
       
   500 		 * @return If returned value is > 0, buffer is not large enough for 
       
   501 		 * 		    objects ID from DB, otherwise error code is returned.
       
   502 		 */
       
   503 		TInt DoGetPending( const CMdEObjectDef* aObjectDef, 
       
   504 				TInt& aObjectIdCount, 
       
   505 				CMdCSerializationBuffer& aObjectIdBuffer );
       
   506 		
       
   507 		/**
       
   508 		 * Resets DB
       
   509 		 * only for internal purpose and DEBUG ONLY!!
       
   510 		 */
       
   511 		void DoResetDBL();
       
   512 		
       
   513 		/**
       
   514 		 * Check if there was error in client-server communication and notify
       
   515 		 * session if needed.
       
   516 		 */
       
   517 		void NotifySessionError( TInt aError );
       
   518 		
       
   519     private: // Data
       
   520     	CMdESessionImpl& iSession;
       
   521     
       
   522 		RProcess iServerProcess;
       
   523 
       
   524 		TBool iIsSessionOpen;
       
   525 		TBool iIsSessionProcessOpen;
       
   526     };
       
   527 
       
   528 #endif // __MDEENGINESESSION_H__