lbs/internal/lbstestserver/src/messageutils.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2006-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "messageutils.h"
       
    17 
       
    18 _LIT(KServerMessageUtilsWrite16, "RMessageWrite16");
       
    19 _LIT(KServerMessageUtilsWrite8, "RMessageWrite8");
       
    20 _LIT(KServerMessageUtilsRead16, "RMessageRead16");
       
    21 _LIT(KServerMessageUtilsRead8, "RMessageRead8");
       
    22 
       
    23 /** 
       
    24 write data in buffer to message by index
       
    25 
       
    26 @param aMessage A reference to RMessage2 object
       
    27 @param aIndex Index of message object
       
    28 @param aBuf 16 bits data buffer to write to message object
       
    29 @return Symbian standard error code
       
    30 @internalTechnology
       
    31 @released
       
    32  */
       
    33 TInt MessageUtils::Write(const RMessage2& aMessage, const TInt aIndex, const TDesC16& aBuf)
       
    34 	{
       
    35 	TInt err = aMessage.Write(aIndex, aBuf); // assume a zero offset in the client side buffer
       
    36 	if(err)
       
    37 		{
       
    38 		PanicClient(aMessage, KServerMessageUtilsWrite16, err);
       
    39 		}
       
    40 	// also return the error code so that a server can cleanup is required...
       
    41 	return err;
       
    42 	}
       
    43 	
       
    44 /** 
       
    45 write data in buffer to message by index
       
    46 
       
    47 @param aMessage A reference to RMessage2 object
       
    48 @param aIndex Index of message object
       
    49 @param aBuf 8 bits data buffer to write to message object
       
    50 @return Symbian standard error code
       
    51 @internalTechnology
       
    52 @released
       
    53  */
       
    54  TInt MessageUtils::Write(const RMessage2& aMessage, const TInt aIndex, const TDesC8& aBuf)
       
    55 	{
       
    56 	TInt err = aMessage.Write(aIndex, aBuf); // assume a zero offset in the client side buffer
       
    57 	if(err)
       
    58 		{
       
    59 		PanicClient(aMessage, KServerMessageUtilsWrite8, err);
       
    60 		}
       
    61 	// also return the error code so that a server can cleanup is required...
       
    62 	return err;
       
    63 	}
       
    64 
       
    65 /** 
       
    66 read data to buffer from message by index
       
    67 
       
    68 @param aMessage A reference to RMessage2 object
       
    69 @param aIndex Index of message object
       
    70 @param aBuf 16 bits data buffer to store data from message object
       
    71 @return Symbian standard error code
       
    72 @internalTechnology
       
    73 @released
       
    74  */	
       
    75 TInt MessageUtils::Read(const RMessage2& aMessage, const TInt aIndex, TDes16& aBuf)
       
    76 	{
       
    77 	TInt err = aMessage.Read(aIndex, aBuf); // assume a zero offset in the buffer
       
    78 	if(err)
       
    79 		{
       
    80 		PanicClient(aMessage, KServerMessageUtilsRead16, err);
       
    81 		}
       
    82 	// also return the error code so that a server can cleanup is required...
       
    83 	return err;
       
    84 	}
       
    85 
       
    86 /** 
       
    87 read data to buffer from message by index
       
    88 
       
    89 @param aMessage A reference to RMessage2 object
       
    90 @param aIndex Index of message object
       
    91 @param aBuf 8 bits data buffer to store data from message object
       
    92 @return Symbian standard error code
       
    93 @internalTechnology
       
    94 @released
       
    95  */	
       
    96 TInt MessageUtils::Read(const RMessage2& aMessage, const TInt aIndex, TDes8& aBuf)
       
    97 	{
       
    98 	TInt err = aMessage.Read(aIndex, aBuf); // assume a zero offset in the buffer
       
    99 	if(err)
       
   100 		{
       
   101 		PanicClient(aMessage, KServerMessageUtilsRead8, err);
       
   102 		}	
       
   103 	// also return the error code so that a server can cleanup is required...
       
   104 	return err;
       
   105 	}
       
   106 	
       
   107 /** 
       
   108 Complete the message by sending a panic to client
       
   109 
       
   110 @param aMessage A reference to RMessage2 object
       
   111 @param aCat Panic category
       
   112 @param aReason Reason to panic the client
       
   113 @internalTechnology
       
   114 @released
       
   115  */	
       
   116 void MessageUtils::PanicClient(const RMessage2& aMessage, const TDesC& aCat, const TInt aReason)
       
   117 	{
       
   118 	aMessage.Panic(aCat, aReason); // will also complete the RMessage
       
   119 	}
       
   120