rtsecuritymanager/rtsecuritymanagerutil/src/rtsecmgrmsg.cpp
changeset 0 99ef825efeca
child 18 a7062f7f0b79
equal deleted inserted replaced
-1:000000000000 0:99ef825efeca
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:       Defines rtsecmgr common client server message types
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 #include "rtsecmgrmsg.h"
       
    25 
       
    26 CRTSecMgrRegisterScriptMsg::CRTSecMgrRegisterScriptMsg(TPolicyID aPolicyID) :
       
    27 	iPolicyID(aPolicyID)
       
    28 	{
       
    29 	// No implementation required
       
    30 	}
       
    31 
       
    32 EXPORT_C CRTSecMgrRegisterScriptMsg::~CRTSecMgrRegisterScriptMsg()
       
    33 	{
       
    34 	if ( iHashMarker)
       
    35 		{
       
    36 		delete iHashMarker;
       
    37 		}
       
    38 	}
       
    39 
       
    40 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewLC(
       
    41 		TPolicyID aPolicyID, const TDesC& aHashValue)
       
    42 	{
       
    43 	CRTSecMgrRegisterScriptMsg* self = new (ELeave)CRTSecMgrRegisterScriptMsg(aPolicyID);
       
    44 	CleanupStack::PushL (self);
       
    45 	self->ConstructL (aHashValue);
       
    46 	return self;
       
    47 	}
       
    48 
       
    49 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewL(
       
    50 		TPolicyID aPolicyID, const TDesC& aHashValue)
       
    51 	{
       
    52 	CRTSecMgrRegisterScriptMsg* self=CRTSecMgrRegisterScriptMsg::NewLC (
       
    53 			aPolicyID, aHashValue);
       
    54 	CleanupStack::Pop (self); // self;
       
    55 	return self;
       
    56 	}
       
    57 
       
    58 // Creates a CRTSecMgrRegisterScriptMsg initialized with the contents of the
       
    59 // descriptor parameter
       
    60 EXPORT_C CRTSecMgrRegisterScriptMsg* CRTSecMgrRegisterScriptMsg::NewLC(const TDesC8& aStreamData)
       
    61 	{
       
    62 	// Reads descriptor data from a stream
       
    63 	// and creates a new CRTSecMgrRegisterScriptMsg object
       
    64 	CRTSecMgrRegisterScriptMsg* self = new (ELeave) CRTSecMgrRegisterScriptMsg();
       
    65 	CleanupStack::PushL (self);
       
    66 	
       
    67 	// Open a read stream for the descriptor
       
    68 	RDesReadStream stream(aStreamData);
       
    69 	CleanupClosePushL (stream);
       
    70 	self->InternalizeL (stream);
       
    71 	CleanupStack::PopAndDestroy (&stream); // finished with the stream
       
    72 	return (self);
       
    73 	}
       
    74 
       
    75 void CRTSecMgrRegisterScriptMsg::ConstructL(const TDesC& aHashValue)
       
    76 	{
       
    77 	if ( iHashMarker)
       
    78 		{
       
    79 		delete iHashMarker;
       
    80 		iHashMarker = NULL;
       
    81 		}
       
    82 
       
    83 	iHashMarker = aHashValue.AllocL ();
       
    84 	}
       
    85 
       
    86 // Creates and returns a heap descriptor which holds contents of ’this’
       
    87 EXPORT_C HBufC8* CRTSecMgrRegisterScriptMsg::PackMsgL() const
       
    88 	{
       
    89 	// Dynamic data buffer
       
    90 	CBufFlat* buf = CBufFlat::NewL(KMaxMsgLength);
       
    91 	CleanupStack::PushL(buf);
       
    92 	RBufWriteStream stream(*buf); // Stream over the buffer
       
    93 	CleanupClosePushL(stream);
       
    94 	ExternalizeL(stream);
       
    95 	CleanupStack::PopAndDestroy(&stream);
       
    96 	// Create a heap descriptor from the buffer
       
    97 	HBufC8* des = HBufC8::NewL(buf->Size());
       
    98 	TPtr8 ptr(des->Des());
       
    99 	buf->Read(0, ptr, buf->Size());
       
   100 	CleanupStack::PopAndDestroy(buf); // Finished with the buffer
       
   101 	return (des);
       
   102 	}
       
   103 
       
   104 // Writes ’this’ to aStream
       
   105 void CRTSecMgrRegisterScriptMsg::ExternalizeL(RWriteStream& aStream) const
       
   106 	{
       
   107 	if ( iHashMarker)
       
   108 		aStream << *iHashMarker;
       
   109 	else
       
   110 		aStream << KNullDesC8;
       
   111 	
       
   112 	aStream.WriteInt32L (iPolicyID); // Write iPolicyID to the stream
       
   113 	}
       
   114 
       
   115 // Initializes ’this’ with the contents of aStream
       
   116 void CRTSecMgrRegisterScriptMsg::InternalizeL(RReadStream& aStream)
       
   117 	{
       
   118 	iHashMarker = HBufC::NewL (aStream, KMaxHashValueDesLen);
       
   119 	iPolicyID = aStream.ReadInt32L (); // Read iPolicyID
       
   120 	}