diff -r 641f389e9157 -r a71299154b21 authenticationservices/authenticationserver/source/common/authserverutil.h --- a/authenticationservices/authenticationserver/source/common/authserverutil.h Tue Aug 31 17:00:08 2010 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,153 +0,0 @@ -/* -* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). -* All rights reserved. -* This component and the accompanying materials are made available -* under the terms of the License "Eclipse Public License v1.0" -* which accompanies this distribution, and is available -* at the URL "http://www.eclipse.org/legal/epl-v10.html". -* -* Initial Contributors: -* Nokia Corporation - initial contribution. -* -* Contributors: -* -* Description: -* AuthServerUtil a utility class used by Authentication Server -* implemented as static functions -* -*/ - - -/** - @file - @internalComponent - @released -*/ - -#ifndef __AUTHSERVERUTIL_H__ -#define __AUTHSERVERUTIL_H__ - -#include -#include -#include "arrayutils.h" - -namespace AuthServer -{ - -class AuthServerUtil - { -public: - // IPC helper methods - template - static HBufC8* FlattenDataArrayLC(const RArray& aArray); - template - static void SendDataArrayL(const RMessage2& aMessage, const RArray& aArray, TInt aIpcIndx); - - template - static HBufC8* FlattenDataPointerArrayLC(const RPointerArray& aPointerArray); - template - static void SendDataPointerArrayL(const RMessage2& aMessage, const RPointerArray& aPointerArray, TInt aIpcIndx); - }; - -// Templated function definitions must appear in the header file - -template -HBufC8* AuthServerUtil::FlattenDataArrayLC(const RArray& aArray) - { - // dynamic buffer since we don't know in advance the size required - CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize); - CleanupStack::PushL(tempBuffer); - - RBufWriteStream stream(*tempBuffer); - CleanupClosePushL(stream); - - // externalise the array of objects - ExternalizeArrayL(aArray, stream); - stream.CommitL(); - - // Now, create an HBufC8 from the stream buf's length, and copy - // the stream buffer into this descriptor - HBufC8* buffer = HBufC8::NewL(tempBuffer->Size()); - TPtr8 ptr(buffer->Des()); - tempBuffer->Read(0, ptr, tempBuffer->Size()); - CleanupStack::PopAndDestroy(2, tempBuffer); // tempBuffer, stream - - CleanupStack::PushL(buffer); - return buffer; - } - -template -void AuthServerUtil::SendDataArrayL(const RMessage2& aMessage, - const RArray& aArray, - TInt aIpcIndx) - { - HBufC8* buffer = FlattenDataArrayLC(aArray); - TPtr8 pbuffer(buffer->Des()); - - if (aMessage.GetDesMaxLengthL(aIpcIndx) < buffer->Size()) - { - TInt bufferSize = buffer->Size(); - TPckgC bufferSizePackage(bufferSize); - aMessage.WriteL(aIpcIndx, bufferSizePackage); - aMessage.Complete(KErrOverflow); - } - else - { - aMessage.WriteL(aIpcIndx, *buffer); - aMessage.Complete(KErrNone); - } - - CleanupStack::PopAndDestroy(buffer); - } - -template -HBufC8* AuthServerUtil::FlattenDataPointerArrayLC(const RPointerArray& aPointerArray) - { - // dynamic buffer since we don't know in advance the size required - CBufFlat* tempBuffer = CBufFlat::NewL(KDefaultBufferSize); - CleanupStack::PushL(tempBuffer); - - RBufWriteStream stream(*tempBuffer); - CleanupClosePushL(stream); - - // externalise the pointer array - ExternalizePointerArrayL(aPointerArray, stream); - stream.CommitL(); - - // Create an HBufC8 from the stream buf's length, and copy - // the stream buffer into this descriptor - HBufC8* buffer = HBufC8::NewL(tempBuffer->Size()); - TPtr8 ptr(buffer->Des()); - tempBuffer->Read(0, ptr, tempBuffer->Size()); - CleanupStack::PopAndDestroy(2, tempBuffer); // tempBuffer, stream, - - CleanupStack::PushL(buffer); - return buffer; - } - -template -void AuthServerUtil::SendDataPointerArrayL(const RMessage2& aMessage, - const RPointerArray& aPointerArray, - TInt aIpcIndx) - { - HBufC8* buffer = FlattenDataPointerArrayLC(aPointerArray); - TPtr8 pbuffer(buffer->Des()); - - if (aMessage.GetDesMaxLengthL(aIpcIndx) < buffer->Size()) - { - TInt bufferSize = buffer->Size(); - TPckgC bufferSizePackage(bufferSize); - aMessage.WriteL(aIpcIndx, bufferSizePackage); - aMessage.Complete(KErrOverflow); - } - else - { - aMessage.WriteL(aIpcIndx, *buffer); - aMessage.Complete(KErrNone); - } - - CleanupStack::PopAndDestroy(buffer); - } - -} // namespace -#endif //__AUTHSERVERUTIL_H__