messagingfw/msgsrvnstore/server/src/MCLIENT.CPP
changeset 62 db3f5fa34ec7
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <s32std.h>
       
    17 #include <s32mem.h>
       
    18 
       
    19 
       
    20 #include "MSVIPC.H"
       
    21 #include "MSERVER.H"
       
    22 #include "MSVREGIP.H"
       
    23 
       
    24 #include "MCLIENT.H"
       
    25 #include "MCLENTRY.H"
       
    26 #include "MSVPANIC.H"
       
    27 #include "MSVAPI.H"
       
    28 #include "MsvSecurityCapabilitySet.h"
       
    29 #include <mmsvstoremanager.h>
       
    30 #include <tmsvsystemprogress.h>
       
    31 #include <tnonoperationmtmdata.h>
       
    32 
       
    33 _LIT(KMsvServerExe, "msexe.exe");
       
    34 
       
    35 #if defined _UNICODE
       
    36 const TUid KMsvMsexExeUid={0x1000484B};
       
    37 #else
       
    38 const TUid KMsvMsexExeUid={0x1000484A};
       
    39 #endif
       
    40 
       
    41 const TInt KMsvRetryTimeout=100000;
       
    42 const TInt KMsvRetryCount=10;
       
    43 
       
    44 static TInt StartServer()
       
    45 	{
       
    46 	const TUidType serverUid(KNullUid, KNullUid, KMsvMsexExeUid);
       
    47 	RProcess server;
       
    48 	TInt r = server.Create(KMsvServerExe, KNullDesC, serverUid);
       
    49 
       
    50 	if( r != KErrNone )
       
    51 		return r;
       
    52 	
       
    53 	TRequestStatus status;
       
    54 	server.Rendezvous(status);
       
    55 	if( status != KRequestPending )
       
    56 		server.Kill(0); // abort start-up
       
    57 	else
       
    58 		server.Resume();	// wait for server start-up.
       
    59 	User::WaitForRequest(status);
       
    60 	
       
    61 	// If the server panics on start-up, then exit reason may still be zero,
       
    62 	// which is not distinguishable from KErrNone.		
       
    63 	r = (server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int();
       
    64 	server.Close();
       
    65 	return r;	
       
    66 	}
       
    67 
       
    68 //********************************
       
    69 //RMsvServerSession
       
    70 //**********************************
       
    71 
       
    72 /**
       
    73 Constructor.
       
    74 
       
    75 @capability None
       
    76 */
       
    77 EXPORT_C RMsvServerSession::RMsvServerSession()
       
    78 : iBuffer(NULL)
       
    79 	{}
       
    80 
       
    81 
       
    82 /**
       
    83 Destructor.
       
    84 
       
    85 @capability None
       
    86 */
       
    87 EXPORT_C RMsvServerSession::~RMsvServerSession()
       
    88 	{
       
    89 	delete iBuffer;
       
    90 	}
       
    91 
       
    92 #if defined (__EPOC32__)
       
    93 /**
       
    94 Connect to the messaging server, and starts it if is not already running.
       
    95  
       
    96 The default number of message slots is 14.
       
    97 
       
    98 @param aFs File server handle
       
    99 @return System wide error codes
       
   100 
       
   101 @capability None
       
   102 */
       
   103 EXPORT_C TInt RMsvServerSession::Connect(RFs& aFs)
       
   104 #else
       
   105 EXPORT_C TInt RMsvServerSession::Connect(RFs& /*aFs*/)
       
   106 #endif
       
   107 	{
       
   108 	if (iBuffer==NULL)
       
   109 		{
       
   110 		iBuffer = HBufC8::New(KMsvSessionBufferLength);
       
   111 		if (iBuffer==NULL)
       
   112 			return KErrNoMemory;
       
   113 		}
       
   114 
       
   115 
       
   116 	TInt retry = KMsvRetryCount;
       
   117 	FOREVER
       
   118 		{
       
   119 		TInt r = CreateSession(KMsvServerName, Version(), KMsvNumberOfSlots);
       
   120 	 	if( r != KErrNotFound && r != KErrServerTerminated && r != KErrServerBusy )
       
   121 			return r;
       
   122 		if( --retry == 0 )
       
   123 			return r;
       
   124 		if( r == KErrServerBusy )
       
   125 			User::After(KMsvRetryTimeout);
       
   126 		r = StartServer();
       
   127 		if( r != KErrNone && r != KErrAlreadyExists )
       
   128 			return r;		
       
   129 		}
       
   130 
       
   131 	}
       
   132 
       
   133 	
       
   134 /**
       
   135 Gets the version number of the server.
       
   136 
       
   137 @return Version number
       
   138 
       
   139 @capability None
       
   140 */
       
   141 EXPORT_C TVersion RMsvServerSession::Version(void) const
       
   142 	{
       
   143 	return(TVersion(KMsvServerMajorVersionNumber,KMsvServerMinorVersionNumber,KMsvServerBuildVersionNumber));
       
   144 	}
       
   145 
       
   146 
       
   147 /** 
       
   148 Makes a request for session event notifications.
       
   149 
       
   150 @param aChange Packaged notification information (a TMsvNotifBuffer object)
       
   151 @param aSequence notification sequence number (a packaged TUint) 
       
   152 @param aRequestStatus Asynchronous request status
       
   153 
       
   154 @capability None
       
   155 */
       
   156 EXPORT_C void RMsvServerSession::QueueSessionEventRequest(TDes8& aChange, TDes8& aSequence, TRequestStatus& aRequestStatus)
       
   157 	{
       
   158 	SendReceive(EMsvNotifySessionEvent, TIpcArgs(&aChange,&aSequence), aRequestStatus);
       
   159 	}
       
   160 
       
   161 /**
       
   162 Cancels a request for session event notifications.
       
   163 
       
   164 @return System wide error codes
       
   165 
       
   166 @capability None
       
   167 */
       
   168 EXPORT_C TInt RMsvServerSession::CancelSessionEventRequest()
       
   169 	{
       
   170 	return SendReceive(EMsvCancelSessionEventNotification);
       
   171 	}
       
   172 
       
   173 
       
   174 /**
       
   175 Set a session as an observer only.
       
   176 
       
   177 @return System wide error codes
       
   178 
       
   179 @capability None
       
   180 */
       
   181 TInt RMsvServerSession::SetSessionAsObserver()
       
   182 	{
       
   183 	return SendReceive(EMsvSetSessionAsObserver);
       
   184 	}
       
   185 
       
   186 void RMsvServerSession::SendEntryDataL(TMsvOp aOperationId, const TMsvEntry& aEntry)
       
   187 //
       
   188 // Sends the entry data in a synchronous call
       
   189 //
       
   190 	{
       
   191 	// package up the entry into a packed entry
       
   192 	TMsvPackedEntry packedEntry(iBuffer);
       
   193 	TInt error = packedEntry.PackEntry(aEntry);
       
   194 	while(error!=KErrNone)
       
   195 		{
       
   196 		// increase the size of the buffer and try again
       
   197 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   198 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
   199 		error = packedEntry.PackEntry(aEntry);
       
   200 		}
       
   201 
       
   202 	// pass data to the server
       
   203 	User::LeaveIfError(SendReceive(EMsvOperationData, TIpcArgs(aOperationId,iBuffer)));
       
   204 	}
       
   205 
       
   206 void RMsvServerSession::SendOperationDataL(TMsvOp aOperationId, const CMsvEntrySelection& aSelection, TInt aParameter1, TInt aParameter2)
       
   207 //
       
   208 // Sends the operation data in a synchronous call
       
   209 //
       
   210 	{
       
   211 	PackOperationDataL(aSelection, aParameter1, aParameter2);
       
   212 
       
   213 	// package up the entry into a packed entry
       
   214 	User::LeaveIfError(SendReceive(EMsvOperationData, TIpcArgs(aOperationId,iBuffer)));
       
   215 	}
       
   216 
       
   217 void RMsvServerSession::PackOperationDataL(const CMsvEntrySelection& aSelection, TInt aParameter1, TInt aParameter2)
       
   218 	{
       
   219 	TMsvPackedOperation packedOperation(iBuffer);
       
   220 	TInt error = packedOperation.Pack(aSelection, aParameter1, aParameter2);
       
   221 	while(error!=KErrNone)
       
   222 		{
       
   223 		// increase the size of the buffer and try again
       
   224 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   225 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
   226 		error = packedOperation.Pack(aSelection, aParameter1, aParameter2);
       
   227 		}
       
   228 	}
       
   229 
       
   230 void RMsvServerSession::SendCommandDataL(TMsvOp aOperationId, const CMsvEntrySelection& aSelection, TInt aCommand, const TDesC8& aParameter)
       
   231 //
       
   232 // Sends the operation data in a synchronous call
       
   233 //
       
   234 	{
       
   235 	TMsvPackedOperation packedOperation(iBuffer);
       
   236 	TInt error = packedOperation.Pack(aSelection, aCommand);
       
   237 	while(error!=KErrNone)
       
   238 		{
       
   239 		// increase the size of the buffer and try again
       
   240 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
   241 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
   242 		error = packedOperation.Pack(aSelection, aCommand);
       
   243 		}
       
   244 
       
   245 	// package up the entry into a packed entry
       
   246 	User::LeaveIfError(SendReceive(EMsvCommandData, TIpcArgs(aOperationId,iBuffer,&aParameter)));
       
   247 	}
       
   248 
       
   249 
       
   250 
       
   251 /**
       
   252 Creates an entry in the message server index (asynchronously) with the supplied owner ID.
       
   253 
       
   254 @param aEntry Entry to create
       
   255 @param aOperationId Operation identifier
       
   256 @param aOwnerId The ID of the owning process
       
   257 @param aRequestStatus Asynchronous request status
       
   258 
       
   259 @capability None A client with no capabilities can create an entry only if the entry is    
       
   260 under a local service, is in an unprotected folder, is not a service entry, and, if part of 
       
   261 an existing message, if that message is owned by the client.  
       
   262 
       
   263 @capability WriteDeviceData Required if the entry is a service. 
       
   264 
       
   265 @capability ReadUserData Required in some circumstances: see the note below.   
       
   266 
       
   267 @capability WriteUserData Required in some circumstances: see the note below.
       
   268 
       
   269 @capability Note The capabilities required to create an entry that is not a service vary depending on the 
       
   270 following conditions:  
       
   271 
       
   272 -# Entry to be created is part of an existing message: 
       
   273 	-# Entry is under the local service:
       
   274 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   275 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   276 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   277 		-# Entry is in an unprotected folder and the existing entry is not owned by the client: ReadUserData + WriteUserData
       
   278 		-# Entry is in an unprotected folder and the existing entry is owned by the client: no capabilities
       
   279 	-# Entry is under a remote service:
       
   280 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   281 		-# The Outbox is unprotected and the existing entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   282 		-# The Outbox is unprotected and the existing entry is not owned by the client: ReadUserData + WriteUserData + 
       
   283 		MTM-specified capabilities (of the MTM for the remote service)
       
   284 -# Entry to be created is not part of an existing message: 
       
   285 	-# Entry is under the local service:
       
   286 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   287 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   288 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   289 		-# Entry is in an unprotected folder: no capabilities
       
   290 	-# Entry is under a remote service:
       
   291 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   292 		-# The Outbox is unprotected: MTM-specified capabilities (of the MTM for the remote service) 
       
   293 
       
   294 @internalComponent
       
   295 */
       
   296 EXPORT_C void RMsvServerSession::CreateEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId, TRequestStatus& aRequestStatus)
       
   297 //
       
   298 // Creates an entry in the index for aEntry.
       
   299 //
       
   300 	{
       
   301 	TestSlotAvailableL();
       
   302 	SendEntryDataL(aOperationId, aEntry);
       
   303 	aRequestStatus=KRequestPending;
       
   304 	SendReceive(EMsvCreateEntry, TIpcArgs(aOperationId, aOwnerId), aRequestStatus);
       
   305 	}
       
   306 
       
   307 
       
   308 
       
   309 /**
       
   310 Creates an entry in the message server index (synchronously).
       
   311 
       
   312 @param aEntry Entry to create
       
   313 @param aOperationId Operation identifier
       
   314 @param aOwnerId The ID of the owning process
       
   315 
       
   316 @capability None A client with no capabilities can create an entry only if the entry is    
       
   317 under a local service, is in an unprotected folder, is not a service entry, and, if part of 
       
   318 an existing message, if that message is owned by the client.  
       
   319 
       
   320 @capability WriteDeviceData Required if the entry is a service. 
       
   321 
       
   322 @capability ReadUserData Required in some circumstances: see the note below.   
       
   323 
       
   324 @capability WriteUserData Required in some circumstances: see the note below.
       
   325 
       
   326 @capability Note The capabilities required to create an entry that is not a service vary depending on the 
       
   327 following conditions:  
       
   328 
       
   329 -# Entry to be created is part of an existing message: 
       
   330 	-# Entry is under the local service:
       
   331 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   332 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   333 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   334 		-# Entry is in an unprotected folder and the existing entry is not owned by the client: ReadUserData + WriteUserData
       
   335 		-# Entry is in an unprotected folder and the existing entry is owned by the client: no capabilities
       
   336 	-# Entry is under a remote service:
       
   337 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   338 		-# The Outbox is unprotected and the existing entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   339 		-# The Outbox is unprotected and the existing entry is not owned by the client: ReadUserData + WriteUserData + 
       
   340 		MTM-specified capabilities (of the MTM for the remote service)
       
   341 -# Entry to be created is not part of an existing message: 
       
   342 	-# Entry is under the local service:
       
   343 		-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   344 		-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   345 		-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   346 		-# Entry is in an unprotected folder: no capabilities
       
   347 	-# Entry is under a remote service:
       
   348 		-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   349 		-# The Outbox is unprotected: MTM-specified capabilities (of the MTM for the remote service) 
       
   350 
       
   351 @internalComponent
       
   352 */
       
   353 EXPORT_C void RMsvServerSession::CreateEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId)
       
   354 //
       
   355 // Creates an entry in the index for aEntry.
       
   356 //
       
   357 	{
       
   358 	TestSlotAvailableL();
       
   359 	SendEntryDataL(aOperationId, aEntry);
       
   360 	User::LeaveIfError(SendReceive(EMsvCreateEntry,TIpcArgs(aOperationId, aOwnerId)));
       
   361 	}
       
   362 
       
   363 
       
   364 	
       
   365 /**
       
   366 Changes the contents of a message server entry (asynchronously).
       
   367 
       
   368 @param aEntry Entry to change
       
   369 @param aOperationId Operation identifier
       
   370 @param aOwnerId The ID of the owning process
       
   371 @param aRequestStatus Asynchronous request status
       
   372 
       
   373 @capability None A client with no capabilities can access an entry only if the entry is    
       
   374 under a local service, is owned by the client, is in an unprotected folder,  
       
   375 and is not a service entry. 
       
   376 
       
   377 @capability WriteDeviceData Required if the entry is a service. 
       
   378 
       
   379 @capability ReadUserData Required in some circumstances: see the note below.   
       
   380 
       
   381 @capability WriteUserData Required in some circumstances: see the note below.
       
   382 
       
   383 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   384 following conditions:  
       
   385 
       
   386 - Entry is under the local service:
       
   387 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   388 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   389 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   390 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   391 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   392 
       
   393 - Entry is under a remote service:
       
   394 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   395 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   396 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   397 	MTM-specified capabilities (of the MTM for the remote service)
       
   398 
       
   399 @internalComponent
       
   400 */
       
   401 EXPORT_C void RMsvServerSession::ChangeEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId, TRequestStatus& aRequestStatus)
       
   402 //
       
   403 // Changes the content of an entry
       
   404 //
       
   405 	{
       
   406 	TestSlotAvailableL();
       
   407 	SendEntryDataL(aOperationId, aEntry);
       
   408 	aRequestStatus=KRequestPending;
       
   409 	SendReceive(EMsvChangeEntry, TIpcArgs(aOperationId, aOwnerId), aRequestStatus);
       
   410 	}
       
   411 
       
   412 
       
   413 
       
   414 
       
   415 /**
       
   416 Changes the contents of a message server entry (synchronously).
       
   417 
       
   418 @param aEntry Entry to create
       
   419 @param aOwnerId The ID of the owning process
       
   420 @param aOperationId Operation identifier
       
   421 
       
   422 @capability None A client with no capabilities can access an entry only if the entry is    
       
   423 under a local service, is owned by the client, is in an unprotected folder,  
       
   424 and is not a service entry. 
       
   425 
       
   426 @capability WriteDeviceData Required if the entry is a service. 
       
   427 
       
   428 @capability ReadUserData Required in some circumstances: see the note below.   
       
   429 
       
   430 @capability WriteUserData Required in some circumstances: see the note below.
       
   431 
       
   432 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   433 following conditions:  
       
   434 
       
   435 - Entry is under the local service:
       
   436 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   437 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   438 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   439 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   440 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   441 
       
   442 - Entry is under a remote service:
       
   443 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   444 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   445 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   446 	MTM-specified capabilities (of the MTM for the remote service)
       
   447 
       
   448 @internalComponent
       
   449 */
       
   450 EXPORT_C void RMsvServerSession::ChangeEntryL(const TMsvEntry& aEntry, TMsvOp aOperationId, TSecureId aOwnerId)
       
   451 //
       
   452 // Changes the content of an entry
       
   453 //
       
   454 	{
       
   455 	TestSlotAvailableL();
       
   456 	SendEntryDataL(aOperationId, aEntry);
       
   457 	User::LeaveIfError(SendReceive(EMsvChangeEntry, TIpcArgs(aOperationId, aOwnerId)));
       
   458 	}
       
   459 
       
   460 /**
       
   461 Update the specified Changes to selection of TMsvId (asynchronously).
       
   462 
       
   463 @param aSelection The IDs of the entry to Change. 
       
   464 @param aMark The read/Unread value.  
       
   465 @param aOperationId Operation identifier
       
   466 @param aOwnerId The ID of the owning process
       
   467 @param aRequestStatus Asynchronous request status
       
   468 
       
   469 */
       
   470 
       
   471 void RMsvServerSession::ChangeEntriesL(const CMsvEntrySelection& aSelection, TBool aMark ,TMsvOp aOperationId, TSecureId aOwnerId, TRequestStatus& aRequestStatus)
       
   472     {
       
   473      TestSlotAvailableL();
       
   474      TInt markvalue = (TInt)aMark;
       
   475      SendOperationDataL(aOperationId, aSelection, markvalue);
       
   476      aRequestStatus=KRequestPending;
       
   477      SendReceive(EMsvChangeEntries, TIpcArgs(aOperationId, aOwnerId), aRequestStatus);
       
   478     }
       
   479 
       
   480 /**
       
   481 Gets the index entry with the specified unique id.
       
   482 @param aId ID of the entry to get
       
   483 @param aService On return, the ID of the service to which the entry belongs
       
   484 @param aEntry On return, the index entry with the specified ID
       
   485 @return System wide error code
       
   486 
       
   487 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   488 
       
   489 @capability ReadUserData This is required to access any entry where the condition 
       
   490 described for no capabilities does not apply.
       
   491 */
       
   492 EXPORT_C TInt RMsvServerSession::GetEntry(TMsvId aId, TMsvId& aService, TMsvEntry& aEntry)
       
   493 	{
       
   494     // pass the buffer and its max length to receive the data through
       
   495     TPtr8 ptr=iBuffer->Des();
       
   496     TInt maxLength = iBuffer->Des().MaxLength();
       
   497     
       
   498 	// signal the server
       
   499     TInt error = SendReceive(EMsvGetEntry,TIpcArgs(aId, &ptr, maxLength));
       
   500     while(error == KErrOverflow)
       
   501         {
       
   502         // increase the size of the buffer and try again
       
   503         iBuffer->Des().SetLength(0);
       
   504         // TRAP here and return if leaving with error
       
   505         TRAP(error, iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength));
       
   506         if( error != KErrNone)
       
   507 			{
       
   508             break;
       
   509 			}
       
   510         // pass the buffer to receive the data through
       
   511         TPtr8 ptr=iBuffer->Des();
       
   512         maxLength = iBuffer->Des().MaxLength();
       
   513         error = SendReceive(EMsvGetEntry,TIpcArgs(aId,&ptr,maxLength));
       
   514         }
       
   515 
       
   516     if( error == KErrNone)
       
   517         {
       
   518         TMsvPackedEntry packedEntry(iBuffer);
       
   519         // Unpack the entry and servie id from same buffer
       
   520         packedEntry.UnpackEntryAndService(aEntry, aService);
       
   521         }
       
   522 
       
   523     return error;
       
   524 	}
       
   525 
       
   526 /**
       
   527 Gets the children of the index entry with the specified unique id.
       
   528 
       
   529 @param aId ID of the entry to get
       
   530 @param aEntries On return, the entry's children. If an error is returned, aEntries is unchanged.
       
   531 @param aOrdering Sorting and grouping rules for the returned entries
       
   532 @return System wide error code
       
   533 
       
   534 @capability None Only children that the client owns are returned. 
       
   535 
       
   536 @capability ReadUserData All children of the entry are returned
       
   537 */
       
   538 EXPORT_C TInt RMsvServerSession::GetChildren(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
   539 	{
       
   540 	TInt origCount=aEntries.Count();
       
   541 	TRAPD(leave, DoGetChildrenL(aId, aEntries, aOrdering));
       
   542 	if (leave!=KErrNone)
       
   543 		{
       
   544 		TInt count=aEntries.Count();
       
   545 		while (count>origCount)
       
   546 			{
       
   547 			delete aEntries.At(--count);
       
   548 			aEntries.Delete(count);
       
   549 			}
       
   550 		}
       
   551 	return leave;
       
   552 	}
       
   553 
       
   554 
       
   555 void RMsvServerSession::DoGetChildrenL(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
   556 //
       
   557 // Gets the children of the index entry with the Unique id aId.
       
   558 //
       
   559 	{
       
   560 	// package up the Id into a children details class
       
   561 	TPckgBuf<TMsvChildrenDetails> details;
       
   562 	details().iParentId = aId;
       
   563 	// pass the sort order
       
   564 	TPckgC<TMsvSelectionOrdering> package2(aOrdering);
       
   565 	// pass the buffer to receive the data through
       
   566 	TPtr8 ptr=iBuffer->Des();
       
   567 	// signal the server
       
   568 	TInt error = SendReceive(EMsvGetChildren, TIpcArgs(&details,&package2,&ptr));
       
   569 		
       
   570 	if (error!=KErrNone && error!=KErrOverflow)
       
   571 		User::Leave(error);
       
   572 
       
   573 	// unpack the entries from the buffer
       
   574 	TMsvPackedEntryArray packedEntryArray(iBuffer);
       
   575 	for (TInt count=0; count<details().iNumberChildrenInArray; count++)
       
   576 		{
       
   577 		TMsvEntry entry;
       
   578 		User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
   579 		CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
   580 		aEntries.AppendL(cEntry);
       
   581 		CleanupStack::Pop(); // cEntry
       
   582 		}
       
   583 	
       
   584 	// if there are more entries - get them
       
   585 	if (error==KErrOverflow)
       
   586 		DoGetRemainingChildrenL(details, aEntries);
       
   587 	}
       
   588 
       
   589 void RMsvServerSession::DoGetRemainingChildrenL(TPckgBuf<TMsvChildrenDetails>& aDetails, CArrayPtrFlat<CMsvClientEntry>& aEntries)
       
   590 //
       
   591 // Gets the remaining children 
       
   592 //
       
   593 	{
       
   594 	TInt error=KErrOverflow;
       
   595 	while (error==KErrOverflow)
       
   596 		{
       
   597 		// package up the Id into a children details class & pass the buffer to receive the data through
       
   598 		TPtr8 ptr=iBuffer->Des();
       
   599 		// get some more entries
       
   600 		error = SendReceive(EMsvGetRemainingChildren,TIpcArgs(&aDetails,NULL,&ptr));
       
   601 		if (error!=KErrNone && error!=KErrOverflow)
       
   602 			User::Leave(error);
       
   603 
       
   604 		if (aDetails().iNumberChildrenInArray == 0)
       
   605 			{
       
   606 			if (error == KErrOverflow)
       
   607 				{
       
   608 				// The buffer isn't big enough for the current entry
       
   609 				// we must resize the buffer or we're in an infinite loop
       
   610 				iBuffer->Des().SetLength(0);
       
   611 				iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
   612 				}
       
   613 			}
       
   614 		else
       
   615 			{
       
   616 			// unpack the entries from the buffer
       
   617 			TMsvPackedEntryArray packedEntryArray(iBuffer);
       
   618 			for (TInt count=0; count<aDetails().iNumberChildrenInArray; count++)
       
   619 				{
       
   620 				TMsvEntry entry;
       
   621 				User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
   622 				CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
   623 				aEntries.AppendL(cEntry);
       
   624 				CleanupStack::Pop(); // cEntry
       
   625 				}
       
   626 			}
       
   627 		}
       
   628 	}
       
   629 
       
   630 
       
   631 
       
   632 /**
       
   633 Delete the specified message server entries (asynchronously).
       
   634 
       
   635 @param aSelection Entries to delete
       
   636 @param aOperationId Operation identifier
       
   637 @param aRequestStatus Asynchronous request status
       
   638 
       
   639 @capability None A client with no capabilities can access an entry only if the entry is    
       
   640 under a local service, is owned by the client, is in an unprotected folder,  
       
   641 and is not a service entry. 
       
   642 
       
   643 @capability WriteDeviceData Required if the entry is a service. 
       
   644 
       
   645 @capability ReadUserData Required in some circumstances: see the note below.   
       
   646 
       
   647 @capability WriteUserData Required in some circumstances: see the note below.
       
   648 
       
   649 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   650 following conditions:  
       
   651 
       
   652 - Entry is under the local service:
       
   653 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   654 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   655 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   656 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   657 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   658 
       
   659 - Entry is under a remote service:
       
   660 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   661 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   662 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   663 	MTM-specified capabilities (of the MTM for the remote service)
       
   664 */
       
   665 EXPORT_C void RMsvServerSession::DeleteEntriesL(const CMsvEntrySelection& aSelection, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
   666 	{
       
   667 	TestSlotAvailableL();
       
   668 	// send the data to the server
       
   669 	SendOperationDataL(aOperationId, aSelection);
       
   670 	// start the operation
       
   671 	aRequestStatus=KRequestPending;
       
   672 	SendReceive(EMsvDeleteEntries, TIpcArgs(aOperationId), aRequestStatus);
       
   673 	}
       
   674 
       
   675 
       
   676 /**
       
   677 Delete the specified message server entries (synchronously).
       
   678 
       
   679 @param aSelection Entries to delete
       
   680 @param aOperationId Operation identifier
       
   681 
       
   682 @capability None A client with no capabilities can access an entry only if the entry is    
       
   683 under a local service, is owned by the client, is in an unprotected folder,  
       
   684 and is not a service entry. 
       
   685 
       
   686 @capability WriteDeviceData Required if the entry is a service. 
       
   687 
       
   688 @capability ReadUserData Required in some circumstances: see the note below.   
       
   689 
       
   690 @capability WriteUserData Required in some circumstances: see the note below.
       
   691 
       
   692 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   693 following conditions:  
       
   694 
       
   695 - Entry is under the local service:
       
   696 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   697 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   698 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   699 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   700 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   701 
       
   702 - Entry is under a remote service:
       
   703 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   704 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   705 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   706 	MTM-specified capabilities (of the MTM for the remote service)
       
   707 */
       
   708 EXPORT_C void RMsvServerSession::DeleteEntriesL(const CMsvEntrySelection& aSelection, TMsvOp aOperationId)
       
   709 	{
       
   710 	TestSlotAvailableL();
       
   711 	// send the data to the server
       
   712 	SendOperationDataL(aOperationId, aSelection);
       
   713 	User::LeaveIfError(SendReceive(EMsvDeleteEntries, TIpcArgs(aOperationId)));
       
   714 	}
       
   715 
       
   716 /**
       
   717 Locks a message server entry.
       
   718 
       
   719 This prevents it from being accessed by other clients. 
       
   720 
       
   721 This function is intended only for test purposes.
       
   722 
       
   723 @param aId ID of the entry to lock
       
   724 @return System wide error code
       
   725 @see RMsvServerSession::ReleaseEntry
       
   726 
       
   727 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
   728 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
   729 Protected Server, Network Control, Network Services, Local Services and Read 
       
   730 User Data). When the macro is not defined, the function is not policed. 
       
   731 */
       
   732 EXPORT_C TInt RMsvServerSession::LockEntry(TMsvId aId)
       
   733 	{
       
   734 	return SendReceive(EMsvLockEntry, TIpcArgs(aId));
       
   735 	}
       
   736 
       
   737 
       
   738 /**
       
   739 Releases the lock on an entry.
       
   740 
       
   741 This function is intended only for test purposes.
       
   742 
       
   743 @param aId ID of the locked entry to release
       
   744 @return System wide error code
       
   745 @see RMsvServerSession::LockEntry
       
   746 
       
   747 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
   748 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
   749 Protected Server, Network Control, Network Services, Local Services and Read 
       
   750 User Data). When the macro is not defined, the function is not policed. 
       
   751 */
       
   752 EXPORT_C TInt RMsvServerSession::ReleaseEntry(TMsvId aId)
       
   753 	{
       
   754 	return SendReceive(EMsvReleaseEntry, TIpcArgs(aId));
       
   755 	}
       
   756 
       
   757 
       
   758 /**
       
   759 Tests if a client can read from a specified message store.
       
   760 A locked store cannot be read from.
       
   761 
       
   762 @param aId ID of the entry that owns the store
       
   763 @return KErrNone if the store can be read from; another system wide error code if not.
       
   764 
       
   765 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   766 
       
   767 @capability ReadUserData This is required to access any entry where the condition 
       
   768 described for no capabilities does not apply.
       
   769 */
       
   770 EXPORT_C TInt RMsvServerSession::ReadStore(TMsvId aId)
       
   771 	{
       
   772 	// package an TInt to get the id back
       
   773 	return SendReceive(EMsvReadStore, TIpcArgs(aId));
       
   774 	}
       
   775 
       
   776 
       
   777 /**
       
   778 Locks a store for writing.
       
   779 
       
   780 @param aId ID of the entry that owns the store
       
   781 @return System wide error code
       
   782 @see RMsvServerSession::ReleaseStore
       
   783 
       
   784 @capability None A client with no capabilities can access an entry only if the entry is    
       
   785 under a local service, is owned by the client, is in an unprotected folder,  
       
   786 and is not a service entry. 
       
   787 
       
   788 @capability WriteDeviceData Required if the entry is a service. 
       
   789 
       
   790 @capability ReadUserData Required in some circumstances: see the note below.   
       
   791 
       
   792 @capability WriteUserData Required in some circumstances: see the note below.
       
   793 
       
   794 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   795 following conditions:  
       
   796 
       
   797 - Entry is under the local service:
       
   798 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   799 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   800 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   801 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   802 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   803 
       
   804 - Entry is under a remote service:
       
   805 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   806 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   807 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   808 	MTM-specified capabilities (of the MTM for the remote service)
       
   809 */
       
   810 EXPORT_C TInt RMsvServerSession::LockStore(TMsvId aId)
       
   811 	{
       
   812 	// package an TInt to get the id back
       
   813 	return SendReceive(EMsvLockStore, TIpcArgs(aId));
       
   814 	}
       
   815 
       
   816 /**
       
   817 Releases the lock on a store.
       
   818 
       
   819 @param aId ID of the entry that owns the store
       
   820 @return System wide error code
       
   821 @see RMsvServerSession::LockStore
       
   822 
       
   823 @capability None A client with no capabilities can access an entry only if the entry is    
       
   824 under a local service, is owned by the client, is in an unprotected folder,  
       
   825 and is not a service entry. 
       
   826 
       
   827 @capability WriteDeviceData Required if the entry is a service. 
       
   828 
       
   829 @capability ReadUserData Required in some circumstances: see the note below.   
       
   830 
       
   831 @capability WriteUserData Required in some circumstances: see the note below.
       
   832 
       
   833 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
   834 following conditions:  
       
   835 
       
   836 - Entry is under the local service:
       
   837 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
   838 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
   839 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
   840 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
   841 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
   842 
       
   843 - Entry is under a remote service:
       
   844 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
   845 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
   846 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
   847 	MTM-specified capabilities (of the MTM for the remote service)
       
   848 */
       
   849 EXPORT_C TInt RMsvServerSession::ReleaseStore(TMsvId aId)
       
   850 	{
       
   851 	return SendReceive(EMsvReleaseStore, TIpcArgs(aId));
       
   852 	}
       
   853 
       
   854 
       
   855 /**
       
   856 Decrements the number of readers on a store.
       
   857 
       
   858 @param aId ID of the entry that owns the store
       
   859 @return System wide error code
       
   860 
       
   861 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
   862 
       
   863 @capability ReadUserData This is required to access any entry where the condition 
       
   864 described for no capabilities does not apply.
       
   865 */
       
   866 TInt RMsvServerSession::DecStoreReaderCount(TMsvId aId)
       
   867 	{
       
   868 	return SendReceive(EMsvDecStoreReaderCount,TIpcArgs(aId));
       
   869 	}
       
   870 
       
   871 
       
   872 /**
       
   873 Closes the message server.
       
   874 
       
   875 The function results in the session sending a shutdown session notification 
       
   876 (TMsvSessionEvent::EMsvCloseSession) to all current sessions. The Message 
       
   877 Server closes when all sessions have been closed.
       
   878  
       
   879 @capability WriteDeviceData
       
   880 */
       
   881 EXPORT_C void RMsvServerSession::CloseMessageServer()
       
   882 	{
       
   883 	SendReceive(EMsvCloseServer);
       
   884 	}
       
   885 
       
   886 
       
   887 /**
       
   888 Gets registry information for the MTMs for a specified MTM DLL type (client, server, UI, UI data).  
       
   889 
       
   890 @param aMtmDllTypeUid UID of the MTM DLL type
       
   891 @param aRegisteredMtmDllArray On return, an array of registry information for the MTMs of the specified type.
       
   892 @param aTimeoutMicroSeconds32 
       
   893 @return System wide error code
       
   894 
       
   895 @capability None
       
   896 */
       
   897 EXPORT_C TInt RMsvServerSession::FillRegisteredMtmDllArray(TUid aMtmDllTypeUid,CRegisteredMtmDllArray& aRegisteredMtmDllArray,TTimeIntervalMicroSeconds32 aTimeoutMicroSeconds32)
       
   898 	{
       
   899 	// pass the buffer to receive the data through
       
   900 	TPtr8 ptr=iBuffer->Des();
       
   901 	// signal the server
       
   902 	TInt error = SendReceive(EMsvFillRegisteredMtmDllArray,TIpcArgs(aMtmDllTypeUid.iUid, &ptr));
       
   903 	if (error==KErrNone)
       
   904 		{
       
   905 		RDesReadStream readStream(*iBuffer);
       
   906 		TRAP(error, TMsvPackedRegisteredMtmDllArray::UnpackRegisteredMtmDllArrayL(readStream, aRegisteredMtmDllArray, aTimeoutMicroSeconds32, *this));
       
   907 		}
       
   908 
       
   909 	return error;
       
   910 	}
       
   911 
       
   912 /**
       
   913 Installs a new MTM group.
       
   914  
       
   915 @param aFullName The full path name of the MTM group file
       
   916 @return System wide error code
       
   917 
       
   918 @capability WriteDeviceData
       
   919 */
       
   920 EXPORT_C TInt RMsvServerSession::InstallMtmGroup(const TDesC& aFullName)
       
   921 	{
       
   922 	return SendReceive(EMsvInstallMtmGroup,TIpcArgs(&aFullName));
       
   923 	}
       
   924 
       
   925 /**
       
   926 Uninstalls an MTM group.
       
   927  
       
   928 @param aFullName The full path name of the MTM group file
       
   929 @return System wide error code
       
   930 
       
   931 @capability WriteDeviceData
       
   932 */
       
   933 EXPORT_C TInt RMsvServerSession::DeInstallMtmGroup(const TDesC& aFullName)
       
   934 	{
       
   935 	return SendReceive(EMsvDeInstallMtmGroup,TIpcArgs(&aFullName));
       
   936 	}
       
   937 
       
   938 /**
       
   939 Increments the usage reference count for a specified MTM group. 
       
   940 
       
   941 @param aMtmTypeUid MTM group UID
       
   942 @return System wide error code
       
   943 @see RMsvServerSession::ReleaseMtmGroup
       
   944 
       
   945 @capability None
       
   946 */
       
   947 EXPORT_C TInt RMsvServerSession::UseMtmGroup(TUid aMtmTypeUid)
       
   948 	{
       
   949 	// package up the Id of the entry required
       
   950 	return SendReceive(EMsvUseMtmGroup,TIpcArgs(aMtmTypeUid.iUid));
       
   951 	}
       
   952 
       
   953 /**
       
   954 Decrements the usage reference count for a specified MTM group.
       
   955 
       
   956 @param aMtmTypeUid MTM group UID
       
   957 @return System wide error code
       
   958 
       
   959 @capability None
       
   960 */
       
   961 EXPORT_C TInt RMsvServerSession::ReleaseMtmGroup(TUid aMtmTypeUid)
       
   962 	{
       
   963 	// package up the Id of the entry required
       
   964 	return SendReceive(EMsvReleaseMtmGroup,TIpcArgs(aMtmTypeUid.iUid));
       
   965 	}
       
   966 
       
   967 /**
       
   968 Gets the registration data for an MTM group.
       
   969 
       
   970 @param aMtmTypeUid MTM group UID
       
   971 @return Registration data for the specified MTM group
       
   972 @leave System wide error code
       
   973 
       
   974 @capability None
       
   975 */
       
   976 EXPORT_C CMtmGroupData* RMsvServerSession::GetMtmGroupDataL(TUid aMtmTypeUid)
       
   977 	{
       
   978 	TPtr8 ptr=iBuffer->Des();
       
   979 	// package up the Id of the entry required and pass the buffer to receive the data through
       
   980 	User::LeaveIfError(SendReceive(EMsvGetMtmGroupData,TIpcArgs(aMtmTypeUid.iUid,&ptr)));
       
   981 	RDesReadStream readStream(*iBuffer);
       
   982 	return CMtmGroupData::NewL(readStream);
       
   983 	}
       
   984 
       
   985 
       
   986 /**
       
   987 Gets capabilities required to use the specified MTM.
       
   988 
       
   989 @param aMtmTypeUid MTM UID
       
   990 @param aCapSet On return, capabilities required to use the specified MTM.
       
   991 
       
   992 @capability None
       
   993 */
       
   994 void RMsvServerSession::GetMtmRequiredCapabilitiesL(TUid aMtmTypeUid, TCapabilitySet& aCapSet) const
       
   995 	{
       
   996 	TPtr8 ptr=iBuffer->Des();
       
   997 	User::LeaveIfError(SendReceive(EMsvGetMtmRequiredCapabilities, TIpcArgs(aMtmTypeUid.iUid, &ptr)));
       
   998 	RDesReadStream readStream(*iBuffer);
       
   999 	MsvSecurityCapabilitySetUtils::InternalizeL(readStream,aCapSet);
       
  1000 	}
       
  1001 	
       
  1002 
       
  1003 /**
       
  1004 Cancels a specified operation.
       
  1005 
       
  1006 @param aId Operation identifier
       
  1007 @param aProgress On return, progress information for the operation
       
  1008 @return System wide error code
       
  1009 
       
  1010 @capability None
       
  1011 */
       
  1012 EXPORT_C TInt RMsvServerSession::CancelOperation(TMsvOp aId, TDes8& aProgress)
       
  1013 	{
       
  1014 	TInt ret = SendReceive(EMsvCancelOperation, TIpcArgs(aId,&aProgress));
       
  1015 	if (ret>0)
       
  1016 		{
       
  1017 		aProgress.SetLength(ret);
       
  1018 		ret=KErrNone;
       
  1019 		}
       
  1020 	else
       
  1021 		{
       
  1022 		aProgress.SetLength(0);
       
  1023 		if (ret==KErrNotReady)
       
  1024 			ret=KErrNone;
       
  1025 		}
       
  1026 	return ret;
       
  1027 	}
       
  1028 
       
  1029 
       
  1030 /**
       
  1031 Gets progress information for an operation.
       
  1032 
       
  1033 @param aId Operation identifier
       
  1034 @param aProgress On return, progress information for the operation
       
  1035 @return System wide error code
       
  1036 
       
  1037 @capability None
       
  1038 */
       
  1039 EXPORT_C TInt RMsvServerSession::OperationProgress(TMsvOp aId, TDes8& aProgress)
       
  1040 	{
       
  1041 	TInt ret = SendReceive(EMsvOperationProgress, TIpcArgs(aId,&aProgress));
       
  1042 	if (ret>0)
       
  1043 		{
       
  1044 		aProgress.SetLength(ret);
       
  1045 		ret=KErrNone;
       
  1046 		}
       
  1047 	else
       
  1048 		aProgress.SetLength(0);
       
  1049 	return ret;
       
  1050 	}
       
  1051 
       
  1052 /**
       
  1053 Obtains the progress information that is defined by and understood by the system as well as client MTM's
       
  1054 
       
  1055 @param aId Operation identifier
       
  1056 @param aProgress On return, progress information for the operation
       
  1057 @return System wide error code
       
  1058 
       
  1059 @capability None
       
  1060 */
       
  1061 EXPORT_C TInt RMsvServerSession::OperationSystemProgress(TMsvOp aId, TMsvSystemProgress& aProgress)
       
  1062 	{
       
  1063 	TPckg<TMsvSystemProgress> sysProgressPkg(aProgress);
       
  1064 	return SendReceive(EMsvOperationSystemProgress, TIpcArgs(aId,&sysProgressPkg));
       
  1065 	}
       
  1066 
       
  1067 /**
       
  1068 Obtains the final progress information for an operation.
       
  1069 The associated server side objects are then deleted.
       
  1070 
       
  1071 @param aId Operation identifier
       
  1072 @param aProgress On return, progress information for the operation
       
  1073 @return System wide error code
       
  1074 
       
  1075 @capability None
       
  1076 */
       
  1077 EXPORT_C TInt RMsvServerSession::OperationCompletion(TMsvOp aId, TDes8& aProgress)
       
  1078 	{
       
  1079 	TInt ret = SendReceive(EMsvOperationCompletion, TIpcArgs(aId,&aProgress));
       
  1080 	if (ret>0)
       
  1081 		{
       
  1082 		aProgress.SetLength(ret);
       
  1083 		ret=KErrNone;
       
  1084 		}
       
  1085 	else
       
  1086 		aProgress.SetLength(0);
       
  1087 	return ret;
       
  1088 	}
       
  1089 
       
  1090 
       
  1091 /**
       
  1092 Moves the specified message server entries (asynchronously).
       
  1093 
       
  1094 @param aSelection The IDs of the entry to move. On return, contains the children that could not be fully moved. 
       
  1095 @param aTarget The ID of the new parent 
       
  1096 @param aOperationId Operation identifier
       
  1097 @param aRequestStatus Asynchronous request status
       
  1098 
       
  1099 @capability None A client with no capabilities can move an entry only if both source and target entries
       
  1100 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1101 
       
  1102 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1103 
       
  1104 @capability WriteUserData Required in some circumstances: see the note below.
       
  1105 
       
  1106 @capability Note The function tests that the caller has capabilities to modify the 
       
  1107 the source entry (see RMsvServerSession::ChangeEntryL) and to create under the target
       
  1108 entry (see RMsvServerSession::CreateEntryL).
       
  1109 */
       
  1110 EXPORT_C void RMsvServerSession::MoveEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1111 	{
       
  1112 	TestSlotAvailableL();
       
  1113 	// send the data to the server
       
  1114 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1115 	// start the operation
       
  1116 	aRequestStatus=KRequestPending;
       
  1117 	SendReceive(EMsvMoveEntries, TIpcArgs(aOperationId), aRequestStatus);
       
  1118 	}
       
  1119 
       
  1120 /**
       
  1121 Moves the specified message server entries (synchronously).
       
  1122 
       
  1123 @param aSelection The IDs of the entry to move. On return, contains the children that could not be fully moved. 
       
  1124 @param aTarget The ID of the new parent entry
       
  1125 @param aOperationId Operation identifier
       
  1126 
       
  1127 @capability None A client with no capabilities can move an entry only if both source and target entries
       
  1128 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1129 
       
  1130 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1131 
       
  1132 @capability WriteUserData Required in some circumstances: see the note below.
       
  1133 
       
  1134 @capability Note The function tests that the caller has capabilities to modify the 
       
  1135 the source entry (see RMsvServerSession::ChangeEntryL) and to create under the target
       
  1136 entry (see RMsvServerSession::CreateEntryL).
       
  1137 */
       
  1138 EXPORT_C void RMsvServerSession::MoveEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId)
       
  1139 	{
       
  1140 	TestSlotAvailableL();
       
  1141 	// send the data to the server
       
  1142 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1143 	// start the operation
       
  1144 	User::LeaveIfError(SendReceive(EMsvMoveEntries, TIpcArgs(aOperationId)));
       
  1145 	}
       
  1146 
       
  1147 /**
       
  1148 Copies the specified message server entries (synchronously).
       
  1149 
       
  1150 @param aSelection The IDs of the source entries to copy. On return, contains the children that could not be fully copied. 
       
  1151 @param aTarget The ID of the destination parent entry
       
  1152 @param aOperationId Operation identifier
       
  1153 
       
  1154 @capability None A client with no capabilities can copy an entry only if both source and target entries
       
  1155 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1156 
       
  1157 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1158 
       
  1159 @capability WriteUserData Required in some circumstances: see the note below.
       
  1160 
       
  1161 @capability Note The function tests that the caller has capabilities to create under the 
       
  1162 target entry (see RMsvServerSession::CreateEntryL).
       
  1163 */
       
  1164 EXPORT_C void RMsvServerSession::CopyEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId)
       
  1165 	{
       
  1166 	TestSlotAvailableL();
       
  1167 	// send the data to the server
       
  1168 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1169 	// start the operation
       
  1170 	User::LeaveIfError(SendReceive(EMsvCopyEntries, TIpcArgs(aOperationId)));
       
  1171 	}
       
  1172 
       
  1173 
       
  1174 /**
       
  1175 Copies the specified message server entries (asynchronously).
       
  1176 
       
  1177 @param aSelection The IDs of the source entries to copy. On return, contains the children that could not be fully copied. 
       
  1178 @param aTarget The ID of the destination parent entry
       
  1179 @param aOperationId Operation identifier
       
  1180 @param aRequestStatus Asynchronous request status
       
  1181 
       
  1182 @capability None A client with no capabilities can copy an entry only if both source and target entries
       
  1183 are under a local service, are owned by the client, and are in an unprotected folder.
       
  1184 
       
  1185 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1186 
       
  1187 @capability WriteUserData Required in some circumstances: see the note below.
       
  1188 
       
  1189 @capability Note The function tests that the caller has capabilities to create under the 
       
  1190 target entry (see RMsvServerSession::CreateEntryL).
       
  1191 */
       
  1192 EXPORT_C void RMsvServerSession::CopyEntriesL(const CMsvEntrySelection& aSelection, TMsvId aTarget, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1193 	{
       
  1194 	TestSlotAvailableL();
       
  1195 	// send the data to the server
       
  1196 	SendOperationDataL(aOperationId, aSelection, aTarget);
       
  1197 	// start the operation
       
  1198 	aRequestStatus=KRequestPending;
       
  1199 	SendReceive(EMsvCopyEntries, TIpcArgs(aOperationId), aRequestStatus);
       
  1200 	}
       
  1201 
       
  1202 
       
  1203 /**
       
  1204 Passes an MTM-specific operation to the associated server-side MTM by means of the Message Server (asynchronously). 
       
  1205 
       
  1206 @param aSelection A selection of entries that may be relevant to the operation 
       
  1207 @param aCommandId The command ID. The interpretation of the command is MTM-specific. 
       
  1208 @param aParameter A descriptor containing operation-specific parameters 
       
  1209 @param aOperationId Operation identifier
       
  1210 @param aRequestStatus Asynchronous request status
       
  1211 
       
  1212 @capability ReadUserData    
       
  1213 @capability WriteUserData
       
  1214 @capability Note A client application needs to have any additional capabilities that are specified by 
       
  1215 the MTM for the message type, as well as ReadUserData and WriteUserData. 
       
  1216 
       
  1217 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1218 */
       
  1219 EXPORT_C void RMsvServerSession::TransferCommandL(const CMsvEntrySelection& aSelection, TInt aCommandId, const TDesC8& aParameter, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1220 	{
       
  1221 	TestSlotAvailableL();
       
  1222 	// send the operation data to the server
       
  1223 	SendCommandDataL(aOperationId, aSelection, aCommandId, aParameter);
       
  1224 	// start the operation
       
  1225 	aRequestStatus=KRequestPending;
       
  1226 	SendReceive(EMsvMtmCommand, TIpcArgs(aOperationId), aRequestStatus);
       
  1227 	}
       
  1228 
       
  1229 /**
       
  1230 Passes an MTM-specific operation to the associated server-side MTM by means of the Message Server (synchronously). 
       
  1231 
       
  1232 @param aSelection A selection of entries that may be relevant to the operation 
       
  1233 @param aCommandId The command ID. The interpretation of the command is MTM-specific. 
       
  1234 @param aParameter A descriptor containing operation-specific parameters 
       
  1235 @param aOperationId Operation identifier
       
  1236 
       
  1237 @capability ReadUserData    
       
  1238 @capability WriteUserData
       
  1239 @capability Note A client application needs to have any additional capabilities that are specified by 
       
  1240 the MTM for the message type, as well as ReadUserData and WriteUserData. 
       
  1241 
       
  1242 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1243 */
       
  1244 EXPORT_C TInt RMsvServerSession::TransferCommandL(const CMsvEntrySelection& aSelection, TInt aCommandId, const TDesC8& aParameter, TMsvOp aOperationId)
       
  1245 	{
       
  1246 	TestSlotAvailableL();
       
  1247 	// send the operation data to the server
       
  1248 	SendCommandDataL(aOperationId, aSelection, aCommandId, aParameter);
       
  1249 	// start the operation
       
  1250 	return SendReceive(EMsvMtmCommand, TIpcArgs(aOperationId));
       
  1251 	}
       
  1252 
       
  1253 
       
  1254 /**
       
  1255 Gets the MTM that would perform an operation using two specified entries.
       
  1256 
       
  1257 @param aId1 ID of first entry
       
  1258 @param aId2 ID of second entry
       
  1259 @param aMtm On return, the UID of the MTM that would be used 
       
  1260 @param aService On return, the ID of the service that would be used 
       
  1261 @return System wide error code
       
  1262 
       
  1263 @capability None
       
  1264 */
       
  1265 EXPORT_C TInt RMsvServerSession::OperationMtmL(TMsvId aId1, TMsvId aId2, TUid& aMtm, TMsvId& aService)
       
  1266 	{
       
  1267 	TPckg<TUid> uid(aMtm);
       
  1268 	TPckg<TMsvId> service(aService);
       
  1269 	return SendReceive(EMsvOperationMtm, TIpcArgs(aId1,aId2,&uid,&service));
       
  1270 	}
       
  1271 
       
  1272 
       
  1273 /**
       
  1274 Stops any operations that a Server-side MTM for the specified service is running, 
       
  1275 and then unloads the Server-side MTM.
       
  1276 
       
  1277 The current operation and any queued operations are cancelled.
       
  1278  
       
  1279 @param aServiceId ID of the service
       
  1280 @return System wide error code
       
  1281 
       
  1282 @capability Note A client application needs to have any capabilities that are specified by 
       
  1283 the MTM.
       
  1284 
       
  1285 @see RMsvServerSession::GetMTMRequiredCapabilitiesL
       
  1286 */
       
  1287 EXPORT_C TInt RMsvServerSession::StopService(TMsvId aServiceId)
       
  1288 	{
       
  1289 	return SendReceive(EMsvStopService, TIpcArgs(aServiceId));
       
  1290 	}
       
  1291 
       
  1292 
       
  1293 /**
       
  1294 Tests if a Server-side MTM for a particular service is loaded by the Message 
       
  1295 Server.
       
  1296 
       
  1297 The Server-side MTM does not have to be executing a command: it may be 
       
  1298 waiting for another command.
       
  1299 
       
  1300 @param aServiceId The ID of the relevant service 
       
  1301 @return ETrue if the Server-side MTM for the service is loaded, otherwise EFalse 
       
  1302 
       
  1303 @capability None
       
  1304 */
       
  1305 EXPORT_C TBool RMsvServerSession::ServiceActive(TMsvId aServiceId)
       
  1306 	{
       
  1307 	return SendReceive(EMsvServiceActive, TIpcArgs(aServiceId)); 
       
  1308 	}
       
  1309 
       
  1310 /** 
       
  1311 Gets the current progress information from the Server-side MTM for the specified 
       
  1312 service.
       
  1313 
       
  1314 It is typically used by User Interface MTMs. The format of the progress information 
       
  1315 returned in the aProgress buffer is MTM-specific.
       
  1316 
       
  1317 Calling this function results in the Message Server calling CBaseServerMtm::Progress() 
       
  1318 on the relevant Server-side MTM. 
       
  1319 
       
  1320 Note that the progress information is independent of which message client 
       
  1321 application started the current operation. 
       
  1322 
       
  1323 @param aServiceId The ID of the service from which to get the progress information 
       
  1324 @param aProgress On return, a descriptor holding progress information. It is 
       
  1325 the caller's responsibility to ensure the descriptor is large enough for this information. 
       
  1326 @return KErrNone: success; KErrNotFound: The service is not active (the relevant Server-side MTM is not loaded 
       
  1327 by the Message Server); KErrOverflow: The descriptor was too small for the progress information
       
  1328 
       
  1329 @capability None
       
  1330 */
       
  1331 EXPORT_C TInt RMsvServerSession::ServiceProgress(TMsvId aServiceId, TDes8& aProgress)
       
  1332 	{
       
  1333 	TInt ret = SendReceive(EMsvServiceProgress, TIpcArgs(aServiceId,&aProgress));
       
  1334 	if (ret>0)
       
  1335 		{
       
  1336 		aProgress.SetLength(ret);
       
  1337 		ret=KErrNone;
       
  1338 		}
       
  1339 	else
       
  1340 		aProgress.SetLength(0);
       
  1341 	return ret;
       
  1342 	}
       
  1343 
       
  1344 /** 
       
  1345 Deletes the specified entry from the Message Server. 
       
  1346 
       
  1347 The call is guaranteed not to fail. If the entry cannot be deleted immediately, 
       
  1348 it will be deleted later.
       
  1349 
       
  1350 @param aId The ID of the entry to remove 
       
  1351 
       
  1352 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1353 under a local service, is owned by the client, is in an unprotected folder,  
       
  1354 and is not a service entry. 
       
  1355 
       
  1356 @capability WriteDeviceData Required if the entry is a service. 
       
  1357 
       
  1358 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1359 
       
  1360 @capability WriteUserData Required in some circumstances: see the note below.
       
  1361 
       
  1362 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1363 following conditions:  
       
  1364 
       
  1365 - Entry is under the local service:
       
  1366 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1367 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1368 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1369 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1370 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1371 
       
  1372 - Entry is under a remote service:
       
  1373 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1374 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1375 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1376 	MTM-specified capabilities (of the MTM for the remote service)
       
  1377 */
       
  1378 EXPORT_C void RMsvServerSession::RemoveEntry(TMsvId aId)
       
  1379 	{
       
  1380 	SendReceive(EMsvRemoveEntry, TIpcArgs(aId));
       
  1381 	}
       
  1382 
       
  1383 /**
       
  1384 Gets the path of the folder in which the Message Server data is stored.
       
  1385 
       
  1386 @param aDirectory Descriptor to hold returned path 
       
  1387 @return System wide error code
       
  1388 */
       
  1389 EXPORT_C TInt RMsvServerSession::GetMessageDirectory(TDes& aDirectory)
       
  1390 	{
       
  1391 	return SendReceive(EMsvGetMessageDirectory, TIpcArgs(&aDirectory));
       
  1392 	}
       
  1393 
       
  1394 /**
       
  1395 Gets the drive on which the Message Server data is stored.
       
  1396 
       
  1397 @return Drive, as a TDriveNumber value
       
  1398 
       
  1399 @capability None
       
  1400 */
       
  1401 TInt RMsvServerSession::GetMessageDrive()
       
  1402 	{
       
  1403 	return SendReceive(EMsvGetMessageDrive);
       
  1404 	}
       
  1405 
       
  1406 
       
  1407 void RMsvServerSession::TestSlotAvailableL()
       
  1408 //
       
  1409 //
       
  1410 //
       
  1411 	{
       
  1412 	User::LeaveIfError(SendReceive(EMsvSlotAvailable));
       
  1413 	}
       
  1414 
       
  1415 
       
  1416 /**
       
  1417 Set failure condition to simulate (for test purposes).
       
  1418 @param aType 
       
  1419 @param aArg1 
       
  1420 @param aArg2 
       
  1421 @param aArg3 
       
  1422 
       
  1423 @capability Note When the __REMOVE_MESSAGING_API_V1__ macro is defined, the
       
  1424 function is policed against the capabilities of the message server (Read/Write Device Data, 
       
  1425 Protected Server, Network Control, Network Services, Local Services and Read 
       
  1426 User Data). When the macro is not defined, the function is not policed. 
       
  1427 */
       
  1428 EXPORT_C void RMsvServerSession::SetFailure(TInt aType, TInt aArg1, TInt aArg2, TInt aArg3)
       
  1429 	{
       
  1430 	SendReceive(EMsvSetFailure,TIpcArgs(aType,aArg1,aArg2,aArg3));
       
  1431 	}
       
  1432 
       
  1433 /** Sets or clears multiple fields in a selection of entries.
       
  1434 
       
  1435 Fields to change are specified using a bitmask of TMsvAttribute values. 
       
  1436 @param aSelection The entries to change
       
  1437 @param aSetAttributes A bitmask of the fields to set
       
  1438 @param aClearAttributes A bitmask of the fields to clear
       
  1439 @see TMsvAttribute 
       
  1440 
       
  1441 @capability WriteUserData 
       
  1442 
       
  1443 @capability Note Clients with no capabilities that own entries in an unprotected folder cannot use this IPC call. 
       
  1444 Instead, they must change attributes by using ChangeEntryL on each entry.
       
  1445 */
       
  1446 EXPORT_C void RMsvServerSession::ChangeAttributesL(const CMsvEntrySelection& aSelection, TUint aSetAttributes, TUint aClearAttributes)
       
  1447 	{
       
  1448 	PackOperationDataL(aSelection, aSetAttributes, aClearAttributes);
       
  1449 	User::LeaveIfError(SendReceive(EMsvChangeAttributes,TIpcArgs(iBuffer)));
       
  1450 	}
       
  1451 
       
  1452 /**
       
  1453 Gets a filtered list of children of a specified message entry.
       
  1454 @param aId Message entry of which to get children
       
  1455 @param aFilter Filter by which various message entries can be excluded
       
  1456 @param aSelection On return, a list of message entry IDs
       
  1457 
       
  1458 @capability None Only children that the client owns are returned. 
       
  1459 
       
  1460 @capability ReadUserData All children of the entry are returned
       
  1461 */
       
  1462 EXPORT_C void RMsvServerSession::GetChildIdsL(TMsvId aId, const CMsvEntryFilter& aFilter, CMsvEntrySelection& aSelection)
       
  1463 	{
       
  1464 	TMsvPackedEntryFilter package(iBuffer);
       
  1465 	User::LeaveIfError(package.PackFilter(aFilter));
       
  1466 
       
  1467 	TPtr8 ptr=iBuffer->Des();
       
  1468 
       
  1469 	TInt error = SendReceive(EMsvGetChildIds,TIpcArgs(&ptr,aId));
       
  1470 
       
  1471 	while(error == KErrOverflow)
       
  1472 		{
       
  1473 		// increase the size of the buffer and try again
       
  1474 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  1475 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  1476 		TMsvPackedEntryFilter package1(iBuffer);
       
  1477 		User::LeaveIfError(package1.PackFilter(aFilter));
       
  1478 		TPtr8 ptr2=iBuffer->Des();
       
  1479 		error = SendReceive(EMsvGetChildIds,TIpcArgs(&ptr2,aId));
       
  1480 		}	
       
  1481 	User::LeaveIfError(error);
       
  1482 	TInt temp1(0); 
       
  1483 	TInt temp2(0);
       
  1484 	TMsvPackedOperation op(iBuffer);
       
  1485 	op.UnpackL(aSelection, temp1, temp2);
       
  1486 	}
       
  1487 
       
  1488 
       
  1489 
       
  1490 
       
  1491 /** 
       
  1492 Load the Message Server index from the specified drive.
       
  1493 
       
  1494 Progress information is provided by a TMsvIndexLoadProgress object.
       
  1495 
       
  1496 If an error occurs, the index is unchanged.
       
  1497 
       
  1498 @param aDrive The drive holding the Message Server index, specified 
       
  1499 by a TDriveNumber value
       
  1500 @param aOperationId Operation identifier
       
  1501 @param aRequestStatus Asynchronous completion status 
       
  1502 @leave KErrServerBusy Cannot change drive because there are outstanding Message 
       
  1503 Server operations.
       
  1504 
       
  1505 @capability WriteDeviceData
       
  1506 */
       
  1507 void RMsvServerSession::ChangeDriveL(TInt aDrive, TMsvOp aOperationId, TRequestStatus& aRequestStatus)
       
  1508 	{
       
  1509 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1510 	TestSlotAvailableL();
       
  1511 
       
  1512 	// start the operation
       
  1513 	aRequestStatus = KRequestPending;
       
  1514 	SendReceive(EMsvChangeDrive, TIpcArgs(aOperationId,TInt(aDrive)), aRequestStatus);
       
  1515 	}
       
  1516 	
       
  1517 	
       
  1518 /** 
       
  1519 Copy the Message Store to the specified drive.
       
  1520 
       
  1521 Progress information is provided by a TMsvCopyProgress object.
       
  1522 
       
  1523 If an error occurs, copying is stopped.
       
  1524 
       
  1525 @param aDrive The drive holding the Message Server index, specified 
       
  1526 by a TDriveUnit value
       
  1527 @param aOperationId Operation identifier
       
  1528 @param aStatus Asynchronous completion status 
       
  1529 @leave KErrServerBusy Cannot copy store because there are outstanding Message 
       
  1530 Server operations.
       
  1531 
       
  1532 @capability WriteDeviceData*/
       
  1533 
       
  1534 void RMsvServerSession::CopyStoreL(const TDriveUnit& aDrive, TMsvOp aOperationId, TRequestStatus& aStatus)                     
       
  1535 	{
       
  1536 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1537 	TestSlotAvailableL();
       
  1538 
       
  1539 	// start the operation
       
  1540 	SendReceive(EMsvCopyStore, TIpcArgs(aOperationId,TInt(aDrive)), aStatus);
       
  1541 	}
       
  1542 
       
  1543 	
       
  1544 /** 
       
  1545 Delete the Message Store to the specified drive.
       
  1546 
       
  1547 Progress information is provided by a TMsvDeleteProgress object.
       
  1548 
       
  1549 If an error occurs, deleting is stopped.
       
  1550 
       
  1551 @param aDrive The drive holding the Message Server index, specified 
       
  1552 by a TDriveUnit value
       
  1553 @param aOperationId Operation identifier
       
  1554 @param aStatus Asynchronous completion status 
       
  1555 @leave KErrServerBusy Cannot delete store because there are outstanding Message 
       
  1556 Server operations.
       
  1557 
       
  1558 @capability WriteDeviceData
       
  1559 */
       
  1560 void RMsvServerSession::DeleteStoreL(const TDriveUnit& aDrive, TMsvOp aOperationId, TRequestStatus& aStatus)                     
       
  1561 	{
       
  1562 	__ASSERT_ALWAYS(RFs::IsValidDrive(aDrive), PanicServer(EMsvInvalidDrive));
       
  1563 	TestSlotAvailableL();
       
  1564 
       
  1565 	// start the operation
       
  1566 	SendReceive(EMsvDeleteStore, TIpcArgs(aOperationId,TInt(aDrive)), aStatus);
       
  1567 	}
       
  1568 	
       
  1569 	
       
  1570 
       
  1571 /**
       
  1572 Gets the number of outstanding operations.
       
  1573 
       
  1574 @return The number of outstanding operations 
       
  1575 
       
  1576 @capability None
       
  1577 */
       
  1578 TInt RMsvServerSession::OutstandingOperationsL()
       
  1579 	{
       
  1580 	TInt count;
       
  1581 	TPckg<TBool> package(count);
       
  1582 
       
  1583 	User::LeaveIfError(SendReceive(EMsvOutstandingOperations, TIpcArgs(&package)));
       
  1584 	return count;
       
  1585 	}
       
  1586 
       
  1587 /**
       
  1588 Get the notification sequence number.
       
  1589 
       
  1590 @return Notification sequence number
       
  1591 
       
  1592 @capability None
       
  1593 */
       
  1594 TUint32 RMsvServerSession::NotifySequenceL()
       
  1595 	{
       
  1596 	TUint32 sequence;
       
  1597 	TPckg<TUint32> package(sequence);
       
  1598 
       
  1599 	User::LeaveIfError(SendReceive(EMsvGetNotifySequence, TIpcArgs(&package)));
       
  1600 	return sequence;
       
  1601 	}
       
  1602 
       
  1603 
       
  1604 /**
       
  1605 Sets whether the session's observer should be notified of events related to 
       
  1606 changes in message server entries.
       
  1607 
       
  1608 If the flag is set to true, the session observer will be notified of all events types. 
       
  1609 If it is set to false, the observer will not be notified of events of types EMsvEntriesCreated, 
       
  1610 EMsvEntriesChanged, EMsvEntriesDeleted, or EMsvEntriesMoved. (Event types are enumerated in  
       
  1611 MMsvSessionObserver::TMsvSessionEvent.) 
       
  1612 
       
  1613 @param aReceive Event request flag
       
  1614 @return System wide error code
       
  1615 @see MMsvSessionObserver::TMsvSessionEvent
       
  1616 
       
  1617 @capability None
       
  1618 */
       
  1619 EXPORT_C TInt RMsvServerSession::SetReceiveEntryEvents(TBool aReceive)
       
  1620 	{
       
  1621 	// Send the uid type in message and Make request
       
  1622 	return SendReceive(EMsvSetReceiveEntyEvents, TIpcArgs(aReceive));
       
  1623 	}
       
  1624 
       
  1625 // from MMsvStoreManager
       
  1626 /** 
       
  1627 Creates a new attachment file in the message store for the message entry specified.
       
  1628 This function allows clients to create a new empty file and stream data to it. 
       
  1629 The empty attachment file is passed back to the client using an opened file handle 
       
  1630 to the file in the message store.
       
  1631 
       
  1632 @param aEntryId Entry to create the attachment for
       
  1633 @param aFileName The attachment filename
       
  1634 @param aFile On return, open file handle to the new attachment file . Ownership is transferred. The caller must close the file handle .
       
  1635 @return True if the file created was named as specified, otherwise false 
       
  1636 
       
  1637 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1638 under a local service, is owned by the client, is in an unprotected folder,  
       
  1639 and is not a service entry. 
       
  1640 
       
  1641 @capability WriteDeviceData Required if the entry is a service. 
       
  1642 
       
  1643 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1644 
       
  1645 @capability WriteUserData Required in some circumstances: see the note below.
       
  1646 
       
  1647 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1648 following conditions:  
       
  1649 
       
  1650 - Entry is under the local service:
       
  1651 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1652 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1653 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1654 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1655 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1656 
       
  1657 - Entry is under a remote service:
       
  1658 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1659 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1660 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1661 	MTM-specified capabilities (of the MTM for the remote service)
       
  1662 */
       
  1663 EXPORT_C TBool RMsvServerSession::CreateAttachmentForWriteL(TMsvId aEntryId, TDes& aFileName, RFile& aFile)
       
  1664 	{
       
  1665 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1666 	TPckg<TBool> pckgFileNameChanged(EFalse);  // intitialise
       
  1667 	// session handle (RFs)received from TransferToClient() in server			
       
  1668 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvCreateAttachmentForWrite,TIpcArgs(aEntryId,&aFileName,&pckgSubSessionHandle,&pckgFileNameChanged)));
       
  1669 	
       
  1670 	// Adopt the file handle from server
       
  1671 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1672 
       
  1673 	return pckgFileNameChanged();
       
  1674 	}
       
  1675 
       
  1676 /** 
       
  1677 Allows clients to replace an existing attachment file and allows clients to stream data to it.
       
  1678 
       
  1679 Replaces an existing attachment file in the message store for the message entry specified by the aEntryId 
       
  1680 parameter. The attachment filename is set to the filename indicated by the aFilename parameter. 
       
  1681 If an attachment with the supplied name does not exist, a new file is created. The empty attachment
       
  1682 file is passed back to the client using an opened file handle to the file in the message store.
       
  1683 
       
  1684 @param aEntryId The entry for which an attachment needs to be created in the message store
       
  1685 @param aFilename The name of the attachment file to be created
       
  1686 @param aFile On return, The created file handle for the attachment file.Ownership is transferred . The caller must close the file handle .
       
  1687 
       
  1688 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1689 under a local service, is owned by the client, is in an unprotected folder,  
       
  1690 and is not a service entry. 
       
  1691 
       
  1692 @capability WriteDeviceData Required if the entry is a service. 
       
  1693 
       
  1694 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1695 
       
  1696 @capability WriteUserData Required in some circumstances: see the note below.
       
  1697 
       
  1698 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1699 following conditions:  
       
  1700 
       
  1701 - Entry is under the local service:
       
  1702 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1703 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1704 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1705 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1706 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1707 
       
  1708 - Entry is under a remote service:
       
  1709 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1710 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1711 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1712 	MTM-specified capabilities (of the MTM for the remote service)
       
  1713 */	
       
  1714 EXPORT_C void RMsvServerSession::ReplaceAttachmentForWriteL(TMsvId aEntryId, TDes& aFileName, RFile& aFile)
       
  1715 	{
       
  1716 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1717 
       
  1718 	// session handle (RFs)received from TransferToClient() in server			
       
  1719 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvReplaceAttachmentForWrite,TIpcArgs(aEntryId,&aFileName,&pckgSubSessionHandle)));
       
  1720 	
       
  1721 	// Adopt the file handle from server
       
  1722 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1723 	}
       
  1724 
       
  1725 /** 
       
  1726 Opens an existing attachment file in the message store for the message entry specified.
       
  1727 This function allows clients to view attachment files.
       
  1728 
       
  1729 @param aEntryId Entry that has the attachment
       
  1730 @param aFilePath The attachment filename
       
  1731 @param aFile On return, open file handle to the attachment file. Ownership is transferred . The caller must close the file handle .
       
  1732 
       
  1733 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
  1734 
       
  1735 @capability ReadUserData This is required to access any entry where the condition 
       
  1736 described for no capabilities does not apply.
       
  1737 */
       
  1738 EXPORT_C void RMsvServerSession::OpenAttachmentL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
  1739 	{
       
  1740 	TPckg<TInt> pckgSubSessionHandle(0);   // initialise
       
  1741 	// session handle (RFs)received from TransferToClient() in server			
       
  1742 	TInt sessionHandle = SendReceive(EMsvOpenAttachment,TIpcArgs(aEntryId,&aFilePath,&pckgSubSessionHandle));
       
  1743 	
       
  1744 	// Adopt the file handle from server
       
  1745 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1746 	}
       
  1747 
       
  1748 	
       
  1749 /** 
       
  1750 Opens an existing attachment file in the message store for the message entry specified.
       
  1751 This function allows clients to edit attachment files.
       
  1752 
       
  1753 @param aEntryId Entry that has the attachment
       
  1754 @param aFilePath The attachment filename
       
  1755 @param aFile On return, open file handle to the attachment file .Ownership is transferred . The caller must close the file handle .
       
  1756 
       
  1757 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1758 under a local service, is owned by the client, is in an unprotected folder,  
       
  1759 and is not a service entry.
       
  1760 
       
  1761 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1762 
       
  1763 @capability WriteUserData Required in some circumstances: see the note below.
       
  1764 
       
  1765 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1766 following conditions:  
       
  1767 
       
  1768 - Entry is under the local service:
       
  1769 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1770 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1771 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1772 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1773 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1774 
       
  1775 - Entry is under a remote service:
       
  1776 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1777 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1778 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1779 	MTM-specified capabilities (of the MTM for the remote service)
       
  1780 */
       
  1781 EXPORT_C void RMsvServerSession::OpenAttachmentForWriteL(TMsvId aEntryId, const TDesC& aFilePath, RFile& aFile)
       
  1782 	{
       
  1783 	TPckg<TInt> pckgSubSessionHandle(0);   // initialise
       
  1784 	// session handle (RFs)received from TransferToClient() in server			
       
  1785 	TInt sessionHandle = SendReceive(EMsvOpenAttachmentForWrite,TIpcArgs(aEntryId,&aFilePath,&pckgSubSessionHandle));
       
  1786 	
       
  1787 	// Adopt the file handle from server
       
  1788 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  1789 	}
       
  1790 
       
  1791 /** 
       
  1792 Deletes an existing attachment file in the message store.
       
  1793 
       
  1794 @param aEntryId Entry that has the attachment
       
  1795 @param aFilePath The attachment filename
       
  1796 
       
  1797 @return System wide error code 
       
  1798 
       
  1799 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1800 under a local service, is owned by the client, is in an unprotected folder,  
       
  1801 and is not a service entry. 
       
  1802 
       
  1803 @capability WriteDeviceData Required if the entry is a service. 
       
  1804 
       
  1805 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1806 
       
  1807 @capability WriteUserData Required in some circumstances: see the note below.
       
  1808 
       
  1809 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1810 following conditions:  
       
  1811 
       
  1812 - Entry is under the local service:
       
  1813 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1814 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1815 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1816 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1817 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1818 
       
  1819 - Entry is under a remote service:
       
  1820 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1821 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1822 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1823 	MTM-specified capabilities (of the MTM for the remote service)
       
  1824 */
       
  1825 EXPORT_C TInt RMsvServerSession::DeleteAttachment(TMsvId aEntryId, const TDesC& aFilePath)
       
  1826 	{
       
  1827 	return SendReceive(EMsvDeleteAttachment,TIpcArgs(aEntryId,&aFilePath));
       
  1828 	}
       
  1829 
       
  1830 /** 
       
  1831 Renames an existing attachment file.
       
  1832 
       
  1833 Renames an existing attachment file in the message store associated with the
       
  1834 message entry specified by the aEntryId parameter. The attachment is 
       
  1835 identified by the file path specified by the aOldFilePath parameter and renamed to
       
  1836 the name supplied in the aNewName paramter.
       
  1837 
       
  1838 @param aEntryId The entry whose attachment needs to be renamed from the message store
       
  1839 @param aOldFilePath The name and path of the attachment file to be renamed.
       
  1840 @param aNewName The new name of the attachment file.
       
  1841 @return KErrNone if successful, otherwise any of the system wide error codes.
       
  1842 
       
  1843 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1844 under a local service, is owned by the client, is in an unprotected folder,  
       
  1845 and is not a service entry. 
       
  1846 
       
  1847 @capability WriteDeviceData Required if the entry is a service. 
       
  1848 
       
  1849 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1850 
       
  1851 @capability WriteUserData Required in some circumstances: see the note below.
       
  1852 
       
  1853 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1854 following conditions:  
       
  1855 
       
  1856 - Entry is under the local service:
       
  1857 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1858 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1859 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1860 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1861 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1862 
       
  1863 - Entry is under a remote service:
       
  1864 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1865 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1866 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1867 	MTM-specified capabilities (of the MTM for the remote service)
       
  1868 */	
       
  1869 EXPORT_C TInt RMsvServerSession::RenameAttachment(TMsvId aEntryId, const TDesC& aOldFilePath, const TDesC& aNewName)
       
  1870 	{
       
  1871 	return SendReceive(EMsvRenameAttachment,TIpcArgs(aEntryId, &aOldFilePath, &aNewName));
       
  1872 	}
       
  1873 
       
  1874 /** 
       
  1875 Checks if the attachment filename specified exists in the store.
       
  1876 
       
  1877 @param aFilePath The complete attachment file path specification
       
  1878 
       
  1879 @capability None
       
  1880 
       
  1881 @return ETrue if the attachment exists, otherwise EFalse
       
  1882 */
       
  1883 EXPORT_C TBool RMsvServerSession::FileExistsL(const TDesC& aFilePath)
       
  1884 	{
       
  1885 	TInt err = SendReceive(EMsvFileExists, TIpcArgs(&aFilePath));
       
  1886 	if( err == KErrNotFound )
       
  1887 		{
       
  1888 		return EFalse;
       
  1889 		}
       
  1890 		
       
  1891 	User::LeaveIfError(err);
       
  1892 	return ETrue;
       
  1893 	}
       
  1894 
       
  1895 /** 
       
  1896 Get the file path where the attachments for a particular entry are stored.
       
  1897 
       
  1898 @param aEntryId The message entry Id.
       
  1899 @param aFilePath On return this will contain the filepath for the attachments.
       
  1900 
       
  1901 @capability None
       
  1902 */
       
  1903 EXPORT_C void RMsvServerSession::AttachmentFilePathL(TMsvId aEntryId, TDes& aFilePath)
       
  1904 	{
       
  1905 	User::LeaveIfError(SendReceive(EMsvGetAttachmentFilePath, TIpcArgs(aEntryId, &aFilePath)));
       
  1906 	}
       
  1907 
       
  1908 /** 
       
  1909 Opens for reading a message store file for the message entry specified.
       
  1910 
       
  1911 @param aEntryId Entry that has the store
       
  1912 @param aFile On return, open file handle to the store.Ownership is transferred . The caller must close the file handle .
       
  1913 
       
  1914 @capability None A client with no capabilities can access an entry only if owns that entry. 
       
  1915 
       
  1916 @capability ReadUserData This is required to access any entry where the condition 
       
  1917 described for no capabilities does not apply.
       
  1918 */
       
  1919 EXPORT_C TInt RMsvServerSession::OpenFileStoreForRead(TMsvId aEntryId, RFile& aFile)
       
  1920 	{
       
  1921 	TPckg<TInt> pckgSubSessionHandle(0);  // initialise
       
  1922 
       
  1923 	// session handle (RFs) received from TransferToClient() in server	
       
  1924 	TInt sessionHandle = SendReceive(EMsvOpenFileStoreForRead,TIpcArgs(aEntryId,&pckgSubSessionHandle));
       
  1925 	if( sessionHandle < KErrNone )
       
  1926 		return sessionHandle;
       
  1927 	
       
  1928 	// Adopt the file handle from server
       
  1929 	return aFile.AdoptFromServer(sessionHandle ,pckgSubSessionHandle());
       
  1930 	}
       
  1931 
       
  1932 /** 
       
  1933 Opens a temporary store file for the message entry specified.
       
  1934 
       
  1935 The function returns an open read-write file handle with an exclusive share to the temporary store file. 
       
  1936 This method, along with ReplaceFileStoreL, allows the message store classes to write data to the store 
       
  1937 file for a particular message entry.
       
  1938 
       
  1939 @param aEntryId Entry with which to associate the store
       
  1940 @param aFile On return, open file handle to the store. Ownership is transferred . The caller must close the file handle .
       
  1941 
       
  1942 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1943 under a local service, is owned by the client, is in an unprotected folder,  
       
  1944 and is not a service entry. 
       
  1945 
       
  1946 @capability WriteDeviceData Required if the entry is a service. 
       
  1947 
       
  1948 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1949 
       
  1950 @capability WriteUserData Required in some circumstances: see the note below.
       
  1951 
       
  1952 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1953 following conditions:  
       
  1954 
       
  1955 - Entry is under the local service:
       
  1956 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1957 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  1958 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  1959 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  1960 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  1961 
       
  1962 - Entry is under a remote service:
       
  1963 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  1964 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  1965 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  1966 	MTM-specified capabilities (of the MTM for the remote service)
       
  1967 */
       
  1968 EXPORT_C void RMsvServerSession::OpenTempStoreFileL(TMsvId aEntryId, RFile& aFile)
       
  1969 	{
       
  1970 	TPckg<TInt> pckgSubSessionHandle(0);  // intitialise
       
  1971 	
       
  1972 	// session handle (RFs) received from TransferToClient() in server
       
  1973 	TInt sessionHandle = SendReceive(EMsvOpenTempStoreFile,TIpcArgs(aEntryId,&pckgSubSessionHandle));
       
  1974 	
       
  1975 	// Adopt the file handle from server
       
  1976 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle ,pckgSubSessionHandle()));
       
  1977 	}
       
  1978 	
       
  1979 /** 
       
  1980 Replaces the current store file with the temporary store file, created from OpenTempStoreFileL, for the specified message entry.
       
  1981 
       
  1982 @param aEntryId Entry associated with the store
       
  1983 
       
  1984 @capability None A client with no capabilities can access an entry only if the entry is    
       
  1985 under a local service, is owned by the client, is in an unprotected folder,  
       
  1986 and is not a service entry. 
       
  1987 
       
  1988 @capability WriteDeviceData Required if the entry is a service. 
       
  1989 
       
  1990 @capability ReadUserData Required in some circumstances: see the note below.   
       
  1991 
       
  1992 @capability WriteUserData Required in some circumstances: see the note below.
       
  1993 
       
  1994 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  1995 following conditions:  
       
  1996 
       
  1997 - Entry is under the local service:
       
  1998 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  1999 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  2000 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  2001 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  2002 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  2003 
       
  2004 - Entry is under a remote service:
       
  2005 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  2006 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  2007 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  2008 	MTM-specified capabilities (of the MTM for the remote service)
       
  2009 */
       
  2010 EXPORT_C void RMsvServerSession::ReplaceFileStoreL(TMsvId aEntryId)
       
  2011 	{
       
  2012 	User::LeaveIfError(SendReceive(EMsvReplaceFileStore,TIpcArgs(aEntryId)));
       
  2013 	}
       
  2014 
       
  2015 /** 
       
  2016 Deletes the store file associated with the specified message entry.
       
  2017 
       
  2018 @capability None A client with no capabilities can access an entry only if the entry is    
       
  2019 under a local service, is owned by the client, is in an unprotected folder,  
       
  2020 and is not a service entry. 
       
  2021 
       
  2022 @capability WriteDeviceData Required if the entry is a service. 
       
  2023 
       
  2024 @capability ReadUserData Required in some circumstances: see the note below.   
       
  2025 
       
  2026 @capability WriteUserData Required in some circumstances: see the note below.
       
  2027 
       
  2028 @capability Note The capabilities required to access an entry that is not a service vary depending on the 
       
  2029 following conditions:  
       
  2030 
       
  2031 - Entry is under the local service:
       
  2032 	-# Entry is in the Outbox and the Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities
       
  2033 	-# Entry is in the Outbox and the Outbox is unprotected: MTM-specified capabilities
       
  2034 	-# Entry is in a protected folder: ReadUserData + WriteUserData
       
  2035 	-# Entry is in an unprotected folder and the entry is not owned by the client: ReadUserData + WriteUserData
       
  2036 	-# Entry is in an unprotected folder and the entry is owned by the client: no capabilities
       
  2037 
       
  2038 - Entry is under a remote service:
       
  2039 	-# The Outbox is protected: ReadUserData + WriteUserData + MTM-specified capabilities (of the MTM for the remote service)
       
  2040 	-# The Outbox is unprotected and the entry is owned by the client: MTM-specified capabilities (of the MTM for the remote service) 
       
  2041 	-# The Outbox is unprotected and the entry is not owned by the client: ReadUserData + WriteUserData + 
       
  2042 	MTM-specified capabilities (of the MTM for the remote service)
       
  2043 */
       
  2044 EXPORT_C void RMsvServerSession::DeleteFileStoreL(TMsvId aEntryId)
       
  2045 	{
       
  2046 	User::LeaveIfError(SendReceive(EMsvDeleteFileStore,TIpcArgs(aEntryId)));
       
  2047 	}
       
  2048 
       
  2049 /** 
       
  2050 Tests if a store file exists for the specified message entry.
       
  2051 
       
  2052 @param aEntryId Entry associated with the store
       
  2053 
       
  2054 @return ETrue if the store file exists, otherwise EFalse.
       
  2055 
       
  2056 @capability None
       
  2057 */
       
  2058 EXPORT_C TBool RMsvServerSession::FileStoreExistsL(TMsvId aEntryId) const
       
  2059 	{
       
  2060 	return SendReceive(EMsvFileStoreExists,TIpcArgs(aEntryId));
       
  2061 	}
       
  2062 
       
  2063 /** 
       
  2064 Checks a flag in the message server that is set when the server
       
  2065 deletes a corrupt index file. Then clears the flag.
       
  2066 	
       
  2067 It is intended to allow the message centre UI to check whether
       
  2068 a corrupt index has been deleted on startup. If it has the UI
       
  2069 may inform the user about the loss of their messages.
       
  2070     
       
  2071 @return ETrue if a corrupt index flag was present indicating that
       
  2072 a corrupt index file has been deleted since the last time this
       
  2073 function was called.
       
  2074  
       
  2075 @capability None
       
  2076 */
       
  2077 TBool RMsvServerSession::GetAndClearIndexCorruptFlagL()
       
  2078 	{
       
  2079 	TInt result=User::LeaveIfError(SendReceive(EMsvGetAndClearIndexCorruptFlag));
       
  2080 	return result==0 ? EFalse : ETrue;
       
  2081 	}
       
  2082 	
       
  2083 /** Checks if the specified drive has a Message Server index on it.
       
  2084 
       
  2085 @param aDrive Drive to check
       
  2086 @return True if aDrive has a Message Server index, otherwise false
       
  2087 @capability None
       
  2088 */
       
  2089 TBool RMsvServerSession::DriveContainsStoreL(TDriveUnit aDrive)
       
  2090 	{
       
  2091 	TInt result=User::LeaveIfError(SendReceive(EMsvDriveContainsStore,TIpcArgs(aDrive)));
       
  2092 	return result==0 ? EFalse : ETrue;
       
  2093 	}
       
  2094 
       
  2095 /** Checks to see if the currently selected drive contains the correct mail store.
       
  2096 
       
  2097 If the message store is present on an external drive, we have to check if the same drive is 
       
  2098 mounted or not before storing the mail.
       
  2099 
       
  2100 @return ETrue if the same drive is mounted. otherwise returns EFalse
       
  2101 @capability None
       
  2102 */
       
  2103 EXPORT_C TBool RMsvServerSession::MessageStoreDrivePresentL()
       
  2104 	{
       
  2105 	TInt result = User::LeaveIfError(SendReceive(EMsvMessageStoreDrivePresent));	
       
  2106 	return result== 0 ? EFalse : ETrue;
       
  2107 	}
       
  2108 
       
  2109 EXPORT_C TBool RMsvServerSession::CreateShareProtectedAttachmentForWriteL(TMsvId /*aEntryId*/, TDes& /*aFilename*/, RFile& /*aFile*/)
       
  2110 	{
       
  2111 	User::Leave(KErrNotSupported);
       
  2112 	//Avoid complier errors and warnings...
       
  2113 	return EFalse;
       
  2114 	}
       
  2115 
       
  2116 /** 
       
  2117 Get the file path where the plain body text for a particular entry will be stored.
       
  2118 @param aBodyTextId 	The TMsvId of the body text entry.
       
  2119 @param aFilePath 	On return this will contain the filepath for the plainbody text.
       
  2120 @capability None
       
  2121 */
       
  2122 EXPORT_C void RMsvServerSession::BodyTextFilePathL(TMsvId aBodyTextId, TDes& aFilePath)
       
  2123  	{
       
  2124  	User::LeaveIfError(SendReceive(EMsvGetBodyTextFilePath, TIpcArgs(aBodyTextId, &aFilePath)));
       
  2125 	}
       
  2126 
       
  2127 /** 
       
  2128 Open the bodytext file whose path is given in aFileName.
       
  2129 @param aFile	 	 The RFile reference that is to be opened.
       
  2130 @param aBodyTextId	 The TMsvId of the body text entry.
       
  2131 @capability ReadUserData
       
  2132 */
       
  2133 EXPORT_C void RMsvServerSession::OpenBodyTextFileForReadL(RFile& aFile, TMsvId aBodyTextId, const TDesC& aFilePath)
       
  2134 	{
       
  2135 	TPckg<TInt> pckgSubSessionHandle(0);
       
  2136 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvOpenTextFileForRead, TIpcArgs(aBodyTextId,  &aFilePath, &pckgSubSessionHandle)));
       
  2137 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  2138 	}
       
  2139 
       
  2140 /** 
       
  2141 Create a plainbody text file whose path is given in aFilePath.
       
  2142 @param aFile 	  	The RFile reference that is to be opened.
       
  2143 @param aBodyTextId  The TMsvId of the body text entry.
       
  2144 @capability WriteUserData
       
  2145 */
       
  2146 EXPORT_C void RMsvServerSession::CreatePlainTextFileL(RFile& aFile, TMsvId aBodyTextId)
       
  2147 	{
       
  2148 	TPckg<TInt> pckgSubSessionHandle(0);
       
  2149 	TInt sessionHandle = User::LeaveIfError(SendReceive(EMsvCreatePlainTextFile, TIpcArgs(aBodyTextId, &pckgSubSessionHandle)));
       
  2150 	User::LeaveIfError(aFile.AdoptFromServer(sessionHandle,pckgSubSessionHandle()));
       
  2151 	}
       
  2152 
       
  2153 /** 
       
  2154 Deletes  a plainbody text file whose path is given in aFilePath.
       
  2155 @param aBodyTextId	 The TMsvId of the body text entry.
       
  2156 @capability WriteUserData
       
  2157 */
       
  2158 EXPORT_C void RMsvServerSession::DeletePlainTextFileL(TMsvId aBodyTextId)
       
  2159 	{
       
  2160 	User::LeaveIfError(SendReceive(EMsvDeletePlainTextFile, TIpcArgs(aBodyTextId)));
       
  2161 	}
       
  2162 
       
  2163 /** 
       
  2164 Replaces  a plainbody text file whose Id is given in aBodyTextId.
       
  2165 @param aBodyTextId 	  The TMsvId of the body text entry.
       
  2166 @capability WriteUserData
       
  2167 */	
       
  2168 EXPORT_C void RMsvServerSession::ReplacePlainTextFileL(TMsvId aBodyTextId)
       
  2169 	{
       
  2170 	User::LeaveIfError(SendReceive(EMsvReplacePlainTextFile,TIpcArgs(aBodyTextId)));
       
  2171 	}
       
  2172 
       
  2173 
       
  2174 
       
  2175 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
       
  2176 /**
       
  2177  * GetChildrenAll()
       
  2178  *
       
  2179  * @param TMsvId:                ID of the parent entry.
       
  2180  * @param TMsvSelectionOrdering: Sorting and grouping rules for the returned entries.
       
  2181  * @param CArrayPtrFlat<CMsvClientEntry>: On return, the entry's children. If an error is returned, aEntries is unchanged.
       
  2182  * @return TInt:                 System wide error code
       
  2183  *
       
  2184  * @capability None Only children that the client owns are returned. 
       
  2185  * @capability ReadUserData All children of the entry are returned
       
  2186  *
       
  2187  * Gets the children of a parent entry specified as first argument.
       
  2188  * If the passed parent is a standard folder the function will fetch 
       
  2189  * entries from all drives currently present in the preferred drive list.
       
  2190  */
       
  2191 EXPORT_C TInt RMsvServerSession::GetChildrenAll(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
  2192 	{
       
  2193 	TInt origCount = aEntries.Count();
       
  2194 	TInt leave = KErrNone;
       
  2195 	
       
  2196 	TRAP(leave, DoGetChildrenAllL(aId, aEntries, aOrdering));
       
  2197 	if(KErrNone != leave)
       
  2198 		{
       
  2199 		TInt count=aEntries.Count();
       
  2200 		while(count > origCount)
       
  2201 			{
       
  2202 			delete aEntries.At(--count);
       
  2203 			aEntries.Delete(count);
       
  2204 			}
       
  2205 		}
       
  2206 	return leave;
       
  2207 	}
       
  2208 
       
  2209 
       
  2210 void RMsvServerSession::DoGetChildrenAllL(TMsvId aId, CArrayPtrFlat<CMsvClientEntry>& aEntries, const TMsvSelectionOrdering& aOrdering)
       
  2211 //
       
  2212 // Gets the children of the index entry with the Unique id aId.
       
  2213 //
       
  2214 	{
       
  2215 	// package up the Id into a children details class
       
  2216 	TPckgBuf<TMsvChildrenDetails> details;
       
  2217 	details().iParentId = aId;
       
  2218 	// pass the sort order
       
  2219 	TPckgC<TMsvSelectionOrdering> package2(aOrdering);
       
  2220 	// pass the buffer to receive the data through
       
  2221 	TPtr8 ptr=iBuffer->Des();
       
  2222 	
       
  2223 	// signal the server
       
  2224 	TInt error = SendReceive(EMsvGetChildrenALL, TIpcArgs(&details,&package2,&ptr));
       
  2225 
       
  2226 	if (error!=KErrNone && error!=KErrOverflow)
       
  2227 		User::Leave(error);
       
  2228 
       
  2229 	// unpack the entries from the buffer
       
  2230 	TMsvPackedEntryArray packedEntryArray(iBuffer);
       
  2231 	for (TInt count=0; count<details().iNumberChildrenInArray; count++)
       
  2232 		{
       
  2233 		TMsvEntry entry;
       
  2234 		User::LeaveIfError(packedEntryArray.UnpackEntry(count, entry));
       
  2235 		CMsvClientEntry* cEntry = CMsvClientEntry::NewLC(entry, EMsvClientChild);
       
  2236 		aEntries.AppendL(cEntry);
       
  2237 		CleanupStack::Pop(); // cEntry
       
  2238 		}
       
  2239 	
       
  2240 	// if there are more entries - get them
       
  2241 	if (error==KErrOverflow)
       
  2242 		DoGetRemainingChildrenL(details, aEntries);
       
  2243 	}
       
  2244 	
       
  2245 	
       
  2246 	
       
  2247 
       
  2248 /** 
       
  2249  * GetChildIdsAllL()
       
  2250  *
       
  2251  * @param TMsvId:          ID of the parent entry.
       
  2252  * @param CMsvEntryFilter: Filter by which various message entries can be excluded.
       
  2253  * @return aSelection:     A list of message entry IDs
       
  2254  *
       
  2255  * @capability None Only children that the client owns are returned. 
       
  2256  * @capability ReadUserData All children of the entry are returned
       
  2257  *
       
  2258  * Gets the children of a parent entry specified as first argument.
       
  2259  * If the passed parent is a standard folder the function will fetch 
       
  2260  * entries from all drives currently present in the preferred drive list.
       
  2261  */
       
  2262 EXPORT_C void RMsvServerSession::GetChildIdsAllL(TMsvId aId, const CMsvEntryFilter& aFilter, CMsvEntrySelection& aSelection)
       
  2263 	{
       
  2264 	TMsvPackedEntryFilter package(iBuffer);
       
  2265 	User::LeaveIfError(package.PackFilter(aFilter));
       
  2266 
       
  2267 	TPtr8 ptr=iBuffer->Des();
       
  2268 
       
  2269 	TInt error = SendReceive(EMsvGetChildIdsALL, TIpcArgs(&ptr, aId));
       
  2270 	while(error == KErrOverflow)
       
  2271 		{
       
  2272 		// increase the size of the buffer and try again
       
  2273 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2274 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2275 		TMsvPackedEntryFilter package1(iBuffer);
       
  2276 		User::LeaveIfError(package1.PackFilter(aFilter));
       
  2277 		TPtr8 ptr2=iBuffer->Des();
       
  2278 		error = SendReceive(EMsvGetChildIdsALL,TIpcArgs(&ptr2,aId));
       
  2279 		}
       
  2280 		
       
  2281 	User::LeaveIfError(error);
       
  2282 	TInt temp1(0); 
       
  2283 	TInt temp2(0);
       
  2284 	TMsvPackedOperation op(iBuffer);
       
  2285 	op.UnpackL(aSelection, temp1, temp2);
       
  2286 	}
       
  2287 
       
  2288 
       
  2289 
       
  2290 
       
  2291 /**
       
  2292  * CurrentDriveInfo()
       
  2293  *
       
  2294  * @return TDriveNumber: Drive number of the current drive
       
  2295  *						 in the preferred drive list.
       
  2296  * @return TUint	   : Priority of the drive.
       
  2297  *
       
  2298  * Code changes for PREQ 557.
       
  2299  * The function returns the current drive of message server.
       
  2300  */ 
       
  2301 EXPORT_C void RMsvServerSession::CurrentDriveInfoL(TDriveNumber& aDriveNumber, TUint& aPriority)
       
  2302 	{
       
  2303 	TPckg<TDriveNumber> driveNum(aDriveNumber);
       
  2304 	TPckg<TUint> priority(aPriority);
       
  2305 		
       
  2306 	User::LeaveIfError(SendReceive(EMsvGetCurrentDriveInfo, TIpcArgs(&driveNum, &priority)));
       
  2307 	}
       
  2308 
       
  2309 
       
  2310 
       
  2311 /**
       
  2312  * DriveList()
       
  2313  *
       
  2314  * @return RArray<TDriveNumber>: List of drive number present in 
       
  2315  *         the preferred drive list arranged in decrementing order
       
  2316  *         of their priority.
       
  2317  *
       
  2318  * Code changes for PREQ 557.
       
  2319  */
       
  2320 EXPORT_C void RMsvServerSession::DriveListL(RArray<TDriveNumber>& aDriveList)
       
  2321 	{
       
  2322 	TPtr8 ptr = iBuffer->Des();	
       
  2323 	User::LeaveIfError(SendReceive(EMsvGetDriveList, TIpcArgs(&ptr)));
       
  2324 
       
  2325 	// Unpack the entries from the buffer.
       
  2326 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  2327 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  2328 	}
       
  2329 
       
  2330 
       
  2331 
       
  2332 
       
  2333 /**
       
  2334  * AvailableDriveListL()
       
  2335  *
       
  2336  * @return RArray<TDriveNumber>: List of drive number of available
       
  2337  *         drives present in the preferred drive list arranged in 
       
  2338  *         decrementing order of their priority.
       
  2339  *
       
  2340  * Code changes for PREQ 557.
       
  2341  * NOTE: A drive number is available only if it has a valid 
       
  2342  * (readable and of correct version) message store in it.
       
  2343  */
       
  2344 EXPORT_C void RMsvServerSession::AvailableDriveListL(RArray<TDriveNumber>& aDriveList)
       
  2345 	{
       
  2346 	TPtr8 ptr = iBuffer->Des();	
       
  2347 	User::LeaveIfError(SendReceive(EMsvGetAvailableDriveList, TIpcArgs(&ptr)));
       
  2348 	
       
  2349 	// Unpack the entries from the buffer.
       
  2350 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  2351 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  2352 	}
       
  2353 
       
  2354 
       
  2355 
       
  2356 
       
  2357 /**
       
  2358  * AddDriveL()
       
  2359  *
       
  2360  * @param  TDriveNumber: Drive number of the drive
       
  2361  *						 to be added.
       
  2362  * @param TUint        : Priority of the drive.
       
  2363  * @return TUint       : New priority of the added drive.
       
  2364  *
       
  2365  * Code changes for PREQ 557.
       
  2366  * The function adds the passed drive in the preferred drive list.
       
  2367  * The location of the drive in the list is specified by the priority 
       
  2368  * of the drive as specified in the second argument. 
       
  2369  *
       
  2370  * - If the priority value of the drive is more than the number of 
       
  2371  * elements in the preferred drive list, the function appends the drive 
       
  2372  * at the end of the list. The new priority of the drive is returned as 
       
  2373  * the second argument.
       
  2374  * - If the priority of the new drive is higher than the current drive 
       
  2375  * of message server, and if the new drive has a media in it, the message 
       
  2376  * server will perform implicit changeDrive and sends a notification to 
       
  2377  * all registered client processes about the change.
       
  2378  * - If the drive does not contain a valid version of message store the 
       
  2379  * function updates the drive status to EMsvMessageStoreNotSupported and 
       
  2380  * sends appropriate notification to the client process. The drive's content 
       
  2381  * will not be visible to any of the client processes.
       
  2382  * - If the message store/message index database in the media is corrupt, 
       
  2383  * the server will delete the message store and create a fresh message store
       
  2384  * and related files in the media.
       
  2385  * - If the number of drive already present in the preferred list is eight,
       
  2386  * the function will return appropriate error message. 
       
  2387  * - In all cases mentioned above, if the drive is successfully added to the 
       
  2388  * preferred drive list the function will also update the central repository 
       
  2389  * with the new preferred drive list.
       
  2390  */ 
       
  2391 EXPORT_C void RMsvServerSession::AddDriveL(TDriveNumber aDriveNumber, TUint& aPriority)
       
  2392 	{
       
  2393 	TUint newPriority = aPriority;
       
  2394 	TPckg<TUint> priorityPkg(newPriority);
       
  2395 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2396 		{
       
  2397 		User::Leave(KErrArgument);
       
  2398 		}
       
  2399 	User::LeaveIfError(SendReceive(EMsvAddDriveToDriveList, TIpcArgs(aDriveNumber, aPriority, &priorityPkg)));
       
  2400 	aPriority = newPriority;
       
  2401 	}
       
  2402 
       
  2403 
       
  2404 
       
  2405 /**
       
  2406  * RemoveDriveL()
       
  2407  *
       
  2408  * @param  TDriveNumber: Drive number of the drive
       
  2409  *						 to be removed.
       
  2410  *
       
  2411  * Code changes for PREQ 557.
       
  2412  * The function removes the drive from the preferred
       
  2413  * drive list. If the current drive is being removed, 
       
  2414  * the next available drive in the preferred drive list 
       
  2415  * becomes the current drive. The device internal drive 
       
  2416  * cannot be removed from the preferred drive list. 
       
  2417  * Appropriate notification will be sent to the client 
       
  2418  * process if there is a change in the current drive. 
       
  2419  * The function will also update the central repository 
       
  2420  * accordingly.
       
  2421  */ 
       
  2422  EXPORT_C void RMsvServerSession::RemoveDriveL(TDriveNumber aDriveNumber)
       
  2423  	{
       
  2424 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2425 		{
       
  2426 		User::Leave(KErrArgument);
       
  2427 		}
       
  2428 	User::LeaveIfError(SendReceive(EMsvRemoveDriveFromDriveList, TIpcArgs(aDriveNumber)));
       
  2429  	}
       
  2430  	
       
  2431  	
       
  2432  	
       
  2433  /**
       
  2434  * UpdateDrivePriorityL()
       
  2435  *
       
  2436  * @param  TDriveNumber: Drive number of the drive
       
  2437  *						 to be updated.
       
  2438  * @param  TUint       : Priority of the drive.
       
  2439  * @return TUint       : New priority of the drive.
       
  2440  *
       
  2441  * Code changes for PREQ 557.
       
  2442  * The function updates the priority of the drive 
       
  2443  * already present in the preferred drive list. If 
       
  2444  * the priority being mentioned is greater than the 
       
  2445  * number of drive present in the list, the drive 
       
  2446  * will be added at the end of the preferred drive list. 
       
  2447  * The function will then return the new priority of 
       
  2448  * the drive. If updating a priority makes a non-current 
       
  2449  * drive the current drive or vice-versa, the function 
       
  2450  * will implicitly perform changeDrive() and send the 
       
  2451  * notification to all registered client. It will return
       
  2452  * error if the said drive is not already present in the 
       
  2453  * preferred drive list.
       
  2454  */ 
       
  2455 EXPORT_C void RMsvServerSession::UpdateDrivePriorityL(TDriveNumber aDriveNumber, TUint& aPriority)
       
  2456 	{
       
  2457 	TUint newPriority = aPriority;
       
  2458 	TPckg<TUint> priorityPkg(newPriority);
       
  2459 	if(!RFs::IsValidDrive(aDriveNumber))
       
  2460 		{
       
  2461 		User::Leave(KErrArgument);
       
  2462 		}
       
  2463 	User::LeaveIfError(SendReceive(EMsvUpdateDrivePriority, TIpcArgs(aDriveNumber, aPriority, &priorityPkg)));
       
  2464 	aPriority = newPriority;
       
  2465 	}
       
  2466 	
       
  2467 
       
  2468 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2469 void RMsvServerSession::ResetRepositoryL()
       
  2470 	{
       
  2471 	User::LeaveIfError(SendReceive(EMsvResetRepository));
       
  2472 	}
       
  2473 #endif 	// #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2474 #endif  // #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)	
       
  2475 
       
  2476 
       
  2477 
       
  2478 /**
       
  2479 Gets data from a server MTM that is not related to any operation being performed on
       
  2480 that MTM.
       
  2481 
       
  2482 @param aServiceId The ID of the service from which to get the data
       
  2483 @param aType The type of MTM data to get.
       
  2484 @param aMtmData A packaged buffer to store the data
       
  2485 
       
  2486 @return KErrNone if successful or one of the system wide error codes
       
  2487 */
       
  2488 TInt RMsvServerSession::GetNonOperationMtmData(TMsvId aServiceId, const TNonOperationMtmDataType& aMtmDataType, TDes8& aMtmData)
       
  2489 	{
       
  2490 	return SendReceive(EMsvGetNonOperationMtmData, TIpcArgs(aServiceId, aMtmDataType, &aMtmData));
       
  2491 	}
       
  2492 
       
  2493 
       
  2494 /** 
       
  2495 SearchSort Request on Header and/or Body part
       
  2496 @param aQuery SearchSortQuery object
       
  2497 @param aOperationId Opertion Id
       
  2498 @param aMarkQuery TBool for QueryId, whether needs to mark at server side or not
       
  2499 @param aRequestStatus TRequestStatus status
       
  2500 @capability WriteUserData
       
  2501 */	
       
  2502 void RMsvServerSession::SearchSortRequestOnHeaderBodyL(const CMsvSearchSortQuery* aQuery, TMsvOp aOperationId, TBool aMarkQuery, TRequestStatus& aRequestStatus)
       
  2503 	{
       
  2504 	TestSlotAvailableL();
       
  2505 	TMsvPackQuery packedQuery(iBuffer);
       
  2506 	TInt error = packedQuery.PackQuery(aQuery);
       
  2507 	while(error!=KErrNone)
       
  2508 		{
       
  2509 		// increase the size of the buffer and try again
       
  2510 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2511 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2512 		error = packedQuery.PackQuery(aQuery);
       
  2513 		}
       
  2514 	// pass data to the server
       
  2515 	SendReceive(EMsvSearchSortOperation, TIpcArgs(aOperationId, iBuffer, aMarkQuery), aRequestStatus);
       
  2516 	}
       
  2517 
       
  2518 
       
  2519 /** 
       
  2520 Get results for given QueryId
       
  2521 @param aQueryId queryId from client
       
  2522 @param aOperationId Opertion Id
       
  2523 @param aIterator Whether results should be send in iterator
       
  2524 @param aRequestStatus TRequestStatus status
       
  2525 @capability ReadUserData
       
  2526 */
       
  2527 void RMsvServerSession::GetResultsForQueryId(TInt& aQueryId, TMsvOp aOperationId, TInt aIterator, TRequestStatus& aRequestStatus)
       
  2528 	{
       
  2529 	SendReceive(EMsvSearchSortQueryId, TIpcArgs(aOperationId, aQueryId, aIterator), aRequestStatus);
       
  2530 	}
       
  2531 
       
  2532 
       
  2533 /** 
       
  2534 Search Sort Request on TMsvEntry
       
  2535 @param aQuery SearchSortQuery object
       
  2536 @param aOperationId Opertion Id
       
  2537 @param aMarkQuery TBool for QueryId, whether needs to mark at server side or not
       
  2538 @param aIterator Whether results should be send in iterator
       
  2539 @param aRequestStatus TRequestStatus status
       
  2540 @capability ReadUserData
       
  2541 */	
       
  2542 void RMsvServerSession::SearchSortRequestOnEntryL(const CMsvSearchSortQuery* aQuery, TMsvOp aOperationId, TBool aMarkQuery, TInt aIterator, TRequestStatus& aRequestStatus)
       
  2543 	{
       
  2544 	TestSlotAvailableL();
       
  2545 	// package up the query into a query entry
       
  2546 	TMsvPackQuery packedQuery(iBuffer);
       
  2547 	TInt error = packedQuery.PackQuery(aQuery);
       
  2548 	while(error!=KErrNone)
       
  2549 		{
       
  2550 		// increase the size of the buffer and try again
       
  2551 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2552 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2553 		error = packedQuery.PackQuery(aQuery);
       
  2554 		}
       
  2555 	SendReceive(EMsvSearchSortOnIndexEntry, TIpcArgs(aOperationId, iBuffer, aMarkQuery, aIterator), aRequestStatus);
       
  2556 	}
       
  2557 	
       
  2558 /** 
       
  2559 Get search sort results as TMsvId
       
  2560 @param aId RArray of TMsvId's sent by server
       
  2561 @capability ReadUserData
       
  2562 */
       
  2563 void RMsvServerSession::GetResultAsIdL(RArray<TMsvId>& aId)
       
  2564 	{
       
  2565 	TBool resultType=ETrue; // result as TMsvId
       
  2566 	
       
  2567 	// pass the buffer to receive the data through
       
  2568 	TPtr8 ptr=iBuffer->Des();
       
  2569 	// signal the server
       
  2570 	TInt error = SendReceive(EMsvGetResult,TIpcArgs(&resultType, &ptr));
       
  2571 	while(error == KErrOverflow)
       
  2572 		{
       
  2573 		// increase the size of the buffer and try again
       
  2574 		iBuffer->Des().SetLength(0);
       
  2575 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2576 		// pass the buffer to receive the data through
       
  2577 		TPtr8 ptr=iBuffer->Des();
       
  2578 		error = SendReceive(EMsvGetResult,TIpcArgs(&resultType, &ptr));
       
  2579 		}
       
  2580 	User::LeaveIfError(error);
       
  2581 	
       
  2582 	// unpack the entries from the buffer
       
  2583 	TMsvPackedIdOperation packedIdOperation(iBuffer);
       
  2584 	packedIdOperation.UnpackL(aId);
       
  2585 	}
       
  2586 
       
  2587 
       
  2588 /** 
       
  2589 Get search sort Request QueryId
       
  2590 @param aQueryId get aQueryId from server
       
  2591 @capability ReadUserData
       
  2592 */
       
  2593 void RMsvServerSession::GetSearchSortRequestQueryIdL(TInt& aQueryId)
       
  2594 	{
       
  2595 	TPckg<TInt> queryId(aQueryId); 
       
  2596 	User::LeaveIfError(SendReceive(EMsvGetQueryId,TIpcArgs(&queryId)));
       
  2597 	}
       
  2598 
       
  2599 
       
  2600 /** 
       
  2601 Unmark the QueryId it was marked at server side
       
  2602 @param aQueryId Unmark the aQueryId at server
       
  2603 @capability WriteUserData
       
  2604 */
       
  2605 void RMsvServerSession::UnmarkSearchSortRequestQueryIdL(TInt aQueryId)
       
  2606 	{
       
  2607 	User::LeaveIfError(SendReceive(EMsvUnmarQueryId,TIpcArgs(&aQueryId)));
       
  2608 	}
       
  2609 
       
  2610 
       
  2611 /** 
       
  2612 Sending TMsvId along with Sort filed to server, so that it will update the data in search-sort cache. 
       
  2613 @param aOperationId Opertion Id
       
  2614 @param aTMsvIdWithSortField RArray of TMsvId along with Sort filed.
       
  2615 @param aRequestStatus TRequestStatus status
       
  2616 @capability WriteUserData
       
  2617 */
       
  2618 void RMsvServerSession::SendResultantListL(TMsvOp aOperationId, RArray<TMsvIdWithSortField> aTMsvIdWithSortField, TRequestStatus& aRequestStatus)	
       
  2619 	{
       
  2620 	TestSlotAvailableL();
       
  2621 	
       
  2622 	// need to pack TMsvId and TMessagePart (i.e TMsvId and Sort field)
       
  2623 	TMsvPackedIdAndMessagePart packIdAndMessagePart;
       
  2624 	
       
  2625 	// calculate size of the TTMsvIdWithMessagePart
       
  2626 	TInt bufferSize = packIdAndMessagePart.Size(aTMsvIdWithSortField);
       
  2627 	
       
  2628 	// if size lessthan KMsvSessionBufferLength, allocate KMsvSessionBufferLength to sync with iBuffer initial allocation.
       
  2629 	if(bufferSize < KMsvSessionBufferLength)
       
  2630 		{
       
  2631 		bufferSize = KMsvSessionBufferLength;
       
  2632 		}
       
  2633 		
       
  2634 	// allocate the buffer
       
  2635 	CBufFlat* flat = CBufFlat::NewL(bufferSize);
       
  2636 	CleanupStack::PushL(flat);
       
  2637 	flat->ExpandL(0, bufferSize);
       
  2638 	
       
  2639 	RBufWriteStream writeStream(*flat);
       
  2640 	CleanupClosePushL (writeStream);
       
  2641 	
       
  2642 	// Externalize the data availbe in TTMsvIdWithMessagePart
       
  2643 	packIdAndMessagePart.ExternalizeL(writeStream, aTMsvIdWithSortField);
       
  2644 	TPtr8 ptr8 = flat->Ptr(0);
       
  2645 	
       
  2646 	// delete memory allocated for iBuffer
       
  2647 	if(iBuffer != NULL)
       
  2648 		{
       
  2649 		delete iBuffer;
       
  2650 		iBuffer = NULL;
       
  2651 		}
       
  2652 
       
  2653 	//Convert CBufFlat into a HBufC8
       
  2654 	iBuffer = ptr8.AllocL();
       
  2655 	
       
  2656 	// send to server
       
  2657 	SendReceive(EMsvIdWithSortFiled, TIpcArgs(aOperationId, iBuffer), aRequestStatus);
       
  2658 	CleanupStack::PopAndDestroy(2, flat);
       
  2659 	}
       
  2660 	
       
  2661 /** 
       
  2662 Sending result to server, this needs be sorted along with existing partial query.
       
  2663 @param aOperationId Opertion Id
       
  2664 @param aIdArray RArray of TMsvId 
       
  2665 @param aRequestStatus TRequestStatus status
       
  2666 @capability WriteUserData
       
  2667 */
       
  2668 void RMsvServerSession::SendNewResultsToServerForSortL(TMsvOp aOperationId, RArray<TMsvId>& aIdArray, TRequestStatus& aRequestStatus)
       
  2669 	{
       
  2670 	TestSlotAvailableL();
       
  2671 	TMsvPackedIdOperation op(iBuffer);
       
  2672 	TInt error = op.Pack(aIdArray);
       
  2673 	while (error != KErrNone)
       
  2674 		{
       
  2675 		// increase the size of the buffer and try again
       
  2676 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2677 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2678 		error = op.Pack(aIdArray);
       
  2679 		}
       
  2680 	SendReceive(EMsvUpdateAndSort, TIpcArgs(aOperationId, iBuffer), aRequestStatus);
       
  2681 	}
       
  2682 
       
  2683 /** 
       
  2684 Get list TMsvId from the server.
       
  2685 The list of TMsvId's may be 
       
  2686     case i)   Final Result
       
  2687     case ii)  Partial Result
       
  2688     case iii) New Query, needs search on Header and/or Body
       
  2689 @param aId RArray of TMsvId's (for case i & ii)
       
  2690 @param aResultStatus Result status, it will tell what kind of result it is..
       
  2691 @capability ReadUserData
       
  2692 */	
       
  2693 void RMsvServerSession::GetResultAsIdL(RArray<TMsvId>& aId, TInt &aResultStatus)
       
  2694 	{
       
  2695 	// pass the buffer to receive the data through
       
  2696 
       
  2697 	TPtr8 ptr=iBuffer->Des();
       
  2698 	TPckg<TInt> resultStatus(aResultStatus);
       
  2699 		
       
  2700 	// signal the server
       
  2701 	TInt error = SendReceive(EMsvGetIdsOrResult,TIpcArgs(&ptr, &resultStatus));
       
  2702 	while(error == KErrOverflow)
       
  2703 		{
       
  2704 		// increase the size of the buffer and try again
       
  2705 		iBuffer->Des().SetLength(0);
       
  2706 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2707 		
       
  2708 		// pass the buffer to receive the data through
       
  2709 		TPtr8 ptr=iBuffer->Des();
       
  2710 		error = SendReceive(EMsvGetIdsOrResult,TIpcArgs(&ptr, &resultStatus));
       
  2711 		}
       
  2712 	User::LeaveIfError(error);
       
  2713 	
       
  2714 	// unpack aId from the buffer
       
  2715 	TMsvPackedIdOperation packedIdOperation(iBuffer);
       
  2716 	packedIdOperation.UnpackL(aId);
       
  2717 	}
       
  2718 	
       
  2719 /** 
       
  2720 Get next TMsvEntry from server
       
  2721 @param aEntry next result as TMsvEntry
       
  2722 @capability ReadUserData
       
  2723 */
       
  2724 void RMsvServerSession::GetNextEntryL(TMsvEntry& aEntry, TInt& aCount)
       
  2725 	{
       
  2726 	TPckg<TInt> count(aCount);
       
  2727 	// pass the buffer to receive the data through
       
  2728 	TPtr8 ptr=iBuffer->Des();
       
  2729 	// signal the server
       
  2730 	TInt error = SendReceive(EMsvGetNextEntry,TIpcArgs(&ptr, &count));
       
  2731 	while(error == KErrOverflow)
       
  2732 		{
       
  2733 		// increase the size of the buffer and try again
       
  2734 		iBuffer->Des().SetLength(0);
       
  2735 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2736 		// pass the buffer to receive the data through
       
  2737 		TPtr8 ptr=iBuffer->Des();
       
  2738 		error = SendReceive(EMsvGetNextEntry,TIpcArgs(&ptr, &count));
       
  2739 		}
       
  2740 	User::LeaveIfError(error);
       
  2741 	TMsvPackedEntry packedEntry(iBuffer);
       
  2742 	packedEntry.UnpackEntry(aEntry);
       
  2743 	}
       
  2744 	
       
  2745 
       
  2746 /** 
       
  2747 Get next TMsvId from server
       
  2748 @param aId next result as TMsvId
       
  2749 @capability ReadUserData
       
  2750 */
       
  2751 void RMsvServerSession::GetNextIdL(TMsvId& aId, TInt& aCount)
       
  2752 	{
       
  2753 	TPckg<TMsvId> tmsvId(aId);
       
  2754 	TPckg<TInt> count(aCount);
       
  2755 	
       
  2756 	TInt error = SendReceive(EMsvGetNextId,TIpcArgs(&tmsvId, &count));
       
  2757 	User::LeaveIfError(error);
       
  2758 	}
       
  2759 
       
  2760 /** 
       
  2761 Get Result count from server
       
  2762 @param aCount Result count
       
  2763 @capability ReadUserData
       
  2764 */
       
  2765 void RMsvServerSession::GetResultCountL(TInt& aCount)
       
  2766 	{
       
  2767 	TPckg<TInt> count(aCount);
       
  2768 	// get result count from server
       
  2769 	User::LeaveIfError(SendReceive(EMsvGetResultCount,TIpcArgs(&count)));
       
  2770 	}
       
  2771 
       
  2772 /** 
       
  2773 Get Search sort request from server
       
  2774 This Query is requied in case partial result for the QueryId
       
  2775 @param aQuery Search Sort Query object
       
  2776 @param aOpId Opertion Id
       
  2777 @capability ReadUserData
       
  2778 */
       
  2779 void RMsvServerSession::GetQueryFromServerL(TMsvOp aOperationId, TInt aQueryId, CMsvSearchSortQuery* aQuery)
       
  2780 	{
       
  2781 	// pass the buffer to receive the query data
       
  2782 	TPtr8 ptr=iBuffer->Des();
       
  2783 	// signal the server
       
  2784 	TInt error = SendReceive(EMsvQueryData,TIpcArgs(aOperationId, aQueryId, &ptr));
       
  2785 	while(error == KErrOverflow)
       
  2786 		{
       
  2787 		// increase the size of the buffer and try again
       
  2788 		iBuffer->Des().SetLength(0);
       
  2789 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength);
       
  2790 		// pass the buffer to receive the data through
       
  2791 		TPtr8 ptr=iBuffer->Des();
       
  2792 		error = SendReceive(EMsvQueryData,TIpcArgs(aOperationId, aQueryId, &ptr));
       
  2793 		}
       
  2794 	User::LeaveIfError(error);
       
  2795 	
       
  2796 	TMsvPackQuery packedQuery(iBuffer);
       
  2797 	packedQuery.UnpackQuery(aQuery);	
       
  2798 	}
       
  2799 
       
  2800 /** 
       
  2801 Get Progress information from the server for a given Request.
       
  2802 @param aOperationProgress Operation progress
       
  2803 @param aOpId Opertion Id
       
  2804 @capability ReadUserData
       
  2805 */	
       
  2806 void RMsvServerSession::SearchSortOperationProgressL(TMsvOp aOperationId, TInt aOperationProgress)
       
  2807 	{
       
  2808 	TPckg<TInt> progressInfo(aOperationProgress);
       
  2809 	User::LeaveIfError(SendReceive(EMsvGetSearchSortProgress,TIpcArgs(aOperationId, &progressInfo)));
       
  2810 	}
       
  2811 
       
  2812 /** 
       
  2813 Cancel current saerch sort Request.
       
  2814 @param aOpId Opertion Id
       
  2815 @capability ReadUserData
       
  2816 */	
       
  2817 int RMsvServerSession::CancelSearchSortOperation(TMsvOp aOperationId)
       
  2818 	{
       
  2819 	TInt error = SendReceive(EMsvCancelSearchSortOp,TIpcArgs(aOperationId));
       
  2820 	return error;
       
  2821 	}
       
  2822 
       
  2823 
       
  2824 #if (defined SYMBIAN_MSGS_ENHANCED_REMOVABLE_MEDIA_SUPPORT)
       
  2825 #if (defined SYMBIAN_MESSAGESTORE_UNIT_TESTCODE)
       
  2826 /**
       
  2827 Print cache structure in a log file.
       
  2828 */
       
  2829 EXPORT_C void RMsvServerSession::PrintCache()
       
  2830 	{
       
  2831 	SendReceive(EMsvPrintCache);
       
  2832 	}
       
  2833 #endif
       
  2834 #endif
       
  2835 
       
  2836 
       
  2837 
       
  2838 
       
  2839 #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)
       
  2840 
       
  2841 /**
       
  2842  * CreateStoreL()
       
  2843  * 
       
  2844  * A headerStore is associated with a mtm type and stores message header
       
  2845  * data. Message server creates a separate store for each MTM type. A 
       
  2846  * header-entry in the headerStore is essentially a list of UID-Data entries.
       
  2847  * For example an email header-entry can have CImHeader, MIME header and 
       
  2848  * encoded header stored as a separate UID-Data entry in the header store.
       
  2849  * By default a UID-Data entry will have a "Default" field which store the
       
  2850  * content of 'Data'. Moreover one such UID-Data pair can also specify mutiple
       
  2851  * fields such that it can store individual portion of data in such fields 
       
  2852  * separately. 
       
  2853  * 
       
  2854  * @param TUid: MtmId of the header store.
       
  2855  * @param RPointerArray<aFieldDetails>: Structure of the Data fields in a UID-Data pair.
       
  2856  * The store by default add a 'Details' field to store the content of data.
       
  2857  * @return None.
       
  2858  *
       
  2859  * @leave: All System wide error code.
       
  2860  *
       
  2861  * @capability WriteDeviceData
       
  2862  */
       
  2863 void RMsvServerSession::CreateStoreL(const TUid& aMtmId, const RPointerArray<CFieldPair>& aFieldDetails)
       
  2864 	{
       
  2865 	TMsvPackedHeaderStructure packedHeaderStruct(iBuffer);
       
  2866 	TInt error = packedHeaderStruct.Pack(aFieldDetails);
       
  2867 	while(error!=KErrNone)
       
  2868 		{
       
  2869 		// increase the size of the buffer and try again
       
  2870 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2871 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  2872 		error = packedHeaderStruct.Pack(aFieldDetails);
       
  2873 		}
       
  2874 
       
  2875 	// package up the entry into a packed entry
       
  2876 	User::LeaveIfError(SendReceive(EMsvCreateStore, TIpcArgs(aMtmId.iUid, iBuffer)));
       
  2877 	}
       
  2878 
       
  2879 
       
  2880 
       
  2881 
       
  2882 
       
  2883 /**
       
  2884  * DoesStoreExistsL()
       
  2885  * 
       
  2886  * The function checks the existence of a header store
       
  2887  * for a given MTM Id. The function can be called to 
       
  2888  * check if the header store already exist before creating
       
  2889  * the store.
       
  2890  *
       
  2891  * @param TUid: Mtm UID of the store.
       
  2892  * @return TBool: ETrue, if the store exists, else EFalse.
       
  2893  *
       
  2894  * @capability ReadDeviceData 
       
  2895  */
       
  2896 TBool RMsvServerSession::DoesStoreExistsL(const TUid& aMtmId)
       
  2897 	{
       
  2898 	TPckg<TBool> isStoreExists = EFalse;
       
  2899 	User::LeaveIfError(SendReceive(EMsvCheckStoreExists, TIpcArgs(aMtmId.iUid, &isStoreExists)));
       
  2900 	return isStoreExists();
       
  2901 	}
       
  2902 
       
  2903 
       
  2904 
       
  2905 
       
  2906 
       
  2907 
       
  2908 /**
       
  2909  * LastErrorMessageL()
       
  2910  * 
       
  2911  * The function returns the detail error message 
       
  2912  * received while creating the header store.
       
  2913  *
       
  2914  * @param HBufC*: Error message text.
       
  2915  * @return None.
       
  2916  * @leave: All system wide error code.
       
  2917  */
       
  2918 void RMsvServerSession::LastErrorMessageL(HBufC*& aErrorMsg)
       
  2919 	{
       
  2920 	TPtr8 ptr8 = iBuffer->Des();
       
  2921 	User::LeaveIfError(SendReceive(EMsvLastErrorMessage, TIpcArgs(&ptr8)));
       
  2922 
       
  2923 	TInt* ptr = (TInt*) CONST_CAST(TUint8*, iBuffer->Ptr());
       
  2924 	TInt textSize = *ptr++;
       
  2925 	
       
  2926 	TPtrC16 ptrBuf;
       
  2927 	const TText* textPtr = (TText*)ptr;
       
  2928 	ptrBuf.Set(textPtr, (textSize/2));	
       
  2929 	
       
  2930 	aErrorMsg = ptrBuf.AllocL();
       
  2931 	}
       
  2932 
       
  2933 
       
  2934 
       
  2935 
       
  2936 
       
  2937 
       
  2938 
       
  2939 /**
       
  2940  * CreateHeaderEntryL()
       
  2941  * 
       
  2942  * This function creates a new message header in the header-store. A message header is
       
  2943  * essentially a list of UID-Data entry. At most one entry in the list must have 
       
  2944  * values for all the fields created in the header store. Rest all entries should have
       
  2945  * values for only default field 'Details'.
       
  2946  *
       
  2947  * @param TUid: MtmId to identify the header table.
       
  2948  * @param TMsvId: Metadata Entry Id.
       
  2949  * @param RPointerArray<CHeaderFields>: Header details.
       
  2950  * @return None.
       
  2951  * @leave KErrAlreadyExists, if entry already exists.
       
  2952  * @leave KErrArgument, if incorrect arguments and system wide leave code.
       
  2953  *
       
  2954  * @capability WriteUserData
       
  2955  */	
       
  2956 EXPORT_C void RMsvServerSession::CreateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
  2957 	{
       
  2958 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  2959 	TInt error = packedHeaderData.Pack(aFieldPairList);
       
  2960 	while(error!=KErrNone)
       
  2961 		{
       
  2962 		// increase the size of the buffer and try again
       
  2963 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  2964 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  2965 		error = packedHeaderData.Pack(aFieldPairList);
       
  2966 		}
       
  2967 
       
  2968 	User::LeaveIfError(SendReceive(EMsvCreateHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, iBuffer)));
       
  2969 	}
       
  2970 
       
  2971 
       
  2972 
       
  2973 
       
  2974 
       
  2975 /**
       
  2976  * LoadHeaderEntryL()
       
  2977  *
       
  2978  * This function loads the header entry from the header-store
       
  2979  * and returns to the client.
       
  2980  *
       
  2981  * @param TUid: MtmId to identify the header table.
       
  2982  * @param TMsvId: Metadata Entry Id.
       
  2983  * @param RPointerArray<CHeaderFields>: Header entry details.
       
  2984  * @return None.
       
  2985  * @leave KErrNotFound: If entry not found. 
       
  2986  *
       
  2987  * @capability ReadUserData
       
  2988  */	
       
  2989  EXPORT_C void RMsvServerSession::LoadHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, RPointerArray<CHeaderFields>& aFieldPairList)
       
  2990 	{
       
  2991 	TPtr8 ptr = iBuffer->Des();	
       
  2992 	User::LeaveIfError(SendReceive(EMsvLoadHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, &ptr)));
       
  2993 	
       
  2994 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  2995 	TRAPD(error, packedHeaderData.UnpackL(aFieldPairList));	
       
  2996 	while(error!=KErrNone)
       
  2997 		{
       
  2998 		// increase the size of the buffer and try again
       
  2999 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  3000 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  3001 		TRAP(error, packedHeaderData.UnpackL(aFieldPairList));
       
  3002 		}
       
  3003 	}
       
  3004 	
       
  3005 	
       
  3006 	
       
  3007 	
       
  3008 	
       
  3009 
       
  3010 /**
       
  3011  * DeleteHeaderEntryL()
       
  3012  *
       
  3013  * This function deletes the header entry from the header-store.
       
  3014  *
       
  3015  * @param aMtmId: MtmId to identify the header table.
       
  3016  * @param aEntryId: Entry Id.
       
  3017  * @return None.
       
  3018  * @leave KErrNotFound: If entry not found. 
       
  3019  *
       
  3020  * @capability WriteUserData
       
  3021  */		
       
  3022 EXPORT_C void RMsvServerSession::DeleteHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId)
       
  3023 	{
       
  3024 	User::LeaveIfError(SendReceive(EMsvDeleteHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId)));
       
  3025 	}
       
  3026 
       
  3027 
       
  3028 
       
  3029 
       
  3030 
       
  3031 /**
       
  3032  * UpdateHeaderEntryL()
       
  3033  *
       
  3034  * This function udpates the header entry in the header-store. A header entry is 
       
  3035  * essentially a list of UID-String combination which is stored as a separate 
       
  3036  * element in the passed header structure. 
       
  3037  *
       
  3038  * If the number of UID-String element in the passed header structure is more
       
  3039  * than what is present in the DB, the function inserts the new UID-String entry
       
  3040  * in the header store. And if the few entries are missing from the passed header 
       
  3041  * structure the function deletes the extra entry from the header store.
       
  3042  *
       
  3043  * @param TUid: MtmId to identify the header table.
       
  3044  * @param TMsvId: Entry Id.
       
  3045  * @param RPointerArray<CHeaderFields>: Header entry details.
       
  3046  * @return None.
       
  3047  * @leave KErrNotFound, if entry to be updated not found and all system wide leave code.
       
  3048  *
       
  3049  * @capability WriteUserData
       
  3050  */	
       
  3051 EXPORT_C void RMsvServerSession::UpdateHeaderEntryL(const TUid& aMtmId, TMsvId aEntryId, const RPointerArray<CHeaderFields>& aFieldPairList)
       
  3052 	{
       
  3053 	TMsvPackedHeaderData packedHeaderData(iBuffer);
       
  3054 	TInt error = packedHeaderData.Pack(aFieldPairList);
       
  3055 	while(error!=KErrNone)
       
  3056 		{
       
  3057 		// increase the size of the buffer and try again
       
  3058 		iBuffer->Des().SetLength(0); // to avoid copying contents
       
  3059 		iBuffer = iBuffer->ReAllocL(iBuffer->Des().MaxSize() + KMsvSessionBufferLength); 
       
  3060 		error = packedHeaderData.Pack(aFieldPairList);
       
  3061 		}
       
  3062 
       
  3063 	User::LeaveIfError(SendReceive(EMsvUpdateHeaderEntry, TIpcArgs(aMtmId.iUid, aEntryId, iBuffer)));
       
  3064 	}
       
  3065 	
       
  3066 
       
  3067 
       
  3068 
       
  3069 
       
  3070 
       
  3071 /**
       
  3072  * DoesAnyStoreExists()
       
  3073  *
       
  3074  * This function checks if the store (header/body) exists 
       
  3075  * for a given metadata entry.
       
  3076  */	
       
  3077 EXPORT_C TBool RMsvServerSession::DoesAnyStoreExists(TMsvId aId, TUid aMtmId)
       
  3078 	{
       
  3079 	return SendReceive(EMsvCheckAnyStoreExists, TIpcArgs(aId, aMtmId.iUid));
       
  3080 	}
       
  3081 
       
  3082 
       
  3083 
       
  3084 
       
  3085 /**
       
  3086  * DoesHeaderTableExist()
       
  3087  *
       
  3088  * This function checks if the header table exists
       
  3089  * for a given MTM type.
       
  3090  */	
       
  3091 EXPORT_C TBool RMsvServerSession::DoesHeaderTableExist(const TUid& aMtmId)
       
  3092 	{
       
  3093 	return SendReceive(EMsvCheckHeaderTableExist, TIpcArgs(aMtmId.iUid));
       
  3094 	}
       
  3095 	
       
  3096 
       
  3097 /********************************Converter API's***************************/
       
  3098 /*
       
  3099  GetConvertibleDriveListL()
       
  3100  Fetches a list of unsupported drives. Any drive is rendered unsupported
       
  3101  if the message store version is less than current message store version.
       
  3102  
       
  3103  @param aDriveList: RArray containing unsupported drive numbers.
       
  3104  @return None 
       
  3105  */
       
  3106 void RMsvServerSession::GetConvertibleDriveListL(RArray<TDriveNumber>& aDriveList)
       
  3107 	{
       
  3108 	TPtr8 ptr = iBuffer->Des();	
       
  3109 	User::LeaveIfError(SendReceive(EMsvGetConvertibleDriveList, TIpcArgs(&ptr)));	
       
  3110 	// Unpack the entries from the buffer.
       
  3111 	TMsvPackedDriveIdOperation packedDriveIdOperation(iBuffer);
       
  3112 	packedDriveIdOperation.UnpackL(aDriveList);	
       
  3113 	}
       
  3114 
       
  3115 /*
       
  3116  ConvertMessageStore()
       
  3117  Starts message store conversion on a drive asynchronously.
       
  3118  The message store to be converted is identified by the drive number
       
  3119  Message store conversion is an asynchronous operation and the client gets
       
  3120  notified by TRequestStatus variable.Message store conversion starts only when
       
  3121  the drive meets different validation criteria.
       
  3122    
       
  3123  
       
  3124  @param aDrive: Drive number.
       
  3125  @param aRequestStatus: Indicates the completion status of a request made to a service provider..
       
  3126  @return None 
       
  3127  */
       
  3128 void RMsvServerSession::ConvertMessageStore(TDriveNumber aDrive,TRequestStatus& aRequestStatus)
       
  3129 	{
       
  3130 	aRequestStatus=KRequestPending;
       
  3131 	SendReceive(EMsvConvertMessageStore, TIpcArgs(aDrive), aRequestStatus);
       
  3132 	}
       
  3133 
       
  3134 /*
       
  3135  GetConversionStatusL()
       
  3136  Gets the conversion status for the specified drive
       
  3137  
       
  3138  @param aDrive: Drive number.
       
  3139  @return None 
       
  3140  */
       
  3141 void RMsvServerSession::GetConversionStatusL(TDriveNumber aDrive)
       
  3142 	{
       
  3143 	User::LeaveIfError(SendReceive(EMsvGetConversionStatus, TIpcArgs(aDrive)));
       
  3144 	}
       
  3145 
       
  3146 /*
       
  3147  CancelConversion()
       
  3148  Cancels conversion for the specified drive.
       
  3149  
       
  3150  @param aDrive: Drive number.
       
  3151  @return TInt: System wide error codes
       
  3152  */	
       
  3153 TInt RMsvServerSession::CancelConversion(TDriveNumber aDrive)
       
  3154 	{
       
  3155 	return SendReceive(EMsvCancelConversionRequest, TIpcArgs(aDrive));
       
  3156 	}
       
  3157 #endif			// #if (defined SYMBIAN_MESSAGESTORE_HEADER_BODY_USING_SQLDB)