messagingfw/msgsrvnstore/server/src/TMsvPackedNotifierRequest.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 2005-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 <tmsvpackednotifierrequest.h>
       
    17 #include "MSVPANIC.H"
       
    18 
       
    19 const TInt KTSecInfoNumTInts = sizeof(TSecurityInfo)/sizeof(TInt);
       
    20 
       
    21 
       
    22 EXPORT_C TMsvPackedNotifierRequest::TMsvPackedNotifierRequest(HBufC8*& aBuffer)
       
    23 : iBuffer(aBuffer)
       
    24 	{
       
    25 	}
       
    26 
       
    27 EXPORT_C TInt TMsvPackedNotifierRequest::Pack(const CMsvEntrySelection& aSelection, const TSecurityInfo& aSecurityInfo)
       
    28 	{
       
    29 	// check the buffer is large enough for the CMsvSelection array and the TSecurityInfo object
       
    30 	// note the extra +1 is to package the CMsvSelection array count
       
    31 	TInt requiredSize = ((aSelection.Count()+KTSecInfoNumTInts+1)*sizeof(TInt));
       
    32 	if (requiredSize>iBuffer->Des().MaxSize())
       
    33 		{
       
    34 		return KErrOverflow;
       
    35 		}
       
    36 
       
    37 	// set the buffer (contents) length
       
    38 	iBuffer->Des().SetLength(requiredSize);
       
    39 
       
    40 	// get pointer to start of iBuffer data 
       
    41 	TInt* ptr = (TInt*) const_cast<TUint8*> (iBuffer->Ptr());
       
    42 	
       
    43 	// pack MSvSelection array size and contents
       
    44 	*ptr++ = aSelection.Count();
       
    45 	for (TInt count=0; count<aSelection.Count(); ++count)
       
    46 		{
       
    47 		*ptr++ = aSelection.At(count);
       
    48 		}
       
    49 		
       
    50 	// get pointer to security info object
       
    51 	TInt* secPtr = (TInt*) const_cast<TSecurityInfo*> (&aSecurityInfo);
       
    52 
       
    53 	// pack TSecurityInfo size and copy into buffer
       
    54 	for (TInt count=0; count<KTSecInfoNumTInts; ++count)
       
    55 		{
       
    56 		*ptr++ = *secPtr++;
       
    57 		}
       
    58 
       
    59 	return KErrNone;
       
    60 	}
       
    61 
       
    62 
       
    63 EXPORT_C void TMsvPackedNotifierRequest::UnpackL(const TDesC8& aBuffer, CMsvEntrySelection& aSelection, TSecurityInfo& aSecurityInfo)
       
    64 	{
       
    65     __ASSERT_DEBUG(aSelection.Count()==0, PanicServer(EMsvOperationUnpackSelectionNotEmpty));	
       
    66 	TInt* ptr = (TInt*) const_cast<TUint8*> (aBuffer.Ptr());
       
    67 
       
    68 	// extract the CMsvEntrySelection object
       
    69 	TInt count = *ptr++;
       
    70 	while (count--)
       
    71 		{
       
    72 		aSelection.AppendL(*ptr++);
       
    73 		}
       
    74 
       
    75 	// extract the TSecurityInfo object
       
    76 	TInt* secPtr = (TInt*) const_cast<TSecurityInfo*> (&aSecurityInfo);
       
    77 	count = KTSecInfoNumTInts;
       
    78 	while (count--)
       
    79 		{
       
    80 		*secPtr++ = *ptr++;
       
    81 		}
       
    82 	}