locationrequestmgmt/locationserver/src/EPos_Global.cpp
changeset 0 9cfd9a3ee49c
equal deleted inserted replaced
-1:000000000000 0:9cfd9a3ee49c
       
     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 
       
    17 
       
    18 // INCLUDE FILES
       
    19 #include <e32base.h>
       
    20 #include <lbs.h>
       
    21 #include <lbserrors.h>
       
    22 
       
    23 #include "EPos_Global.h"
       
    24 
       
    25 // ================= DEBUG TRACES =======================
       
    26 
       
    27 #ifdef _DEBUG
       
    28 
       
    29 #include <lbs/epos_cpostrace.h>
       
    30 _LIT(KTraceFileName, "EPos_Global.cpp");
       
    31 
       
    32 CPosTrace* theTrace = NULL;
       
    33 
       
    34 void Global::SetupTraceL()
       
    35     {
       
    36     if (!theTrace)
       
    37         {
       
    38         theTrace = CPosTrace::NewL();
       
    39         }
       
    40     }
       
    41 
       
    42 void Global::TearDownTrace()
       
    43     {
       
    44     delete theTrace;
       
    45     theTrace = NULL;
       
    46     }
       
    47 
       
    48 void Global::Trace(const TDesC& aDescription, const TDesC& aFilename, const TInt aLineNumber)
       
    49     {
       
    50     if (theTrace)
       
    51         {
       
    52         // to epos log
       
    53         TInt err;
       
    54         TRAP(err, theTrace->TraceL(aDescription, aFilename, aLineNumber));
       
    55         
       
    56         // same to epocwind.out
       
    57         _LIT(KPosTraceLogFormat , "EPos: Server: %S");
       
    58         RDebug::Print(KPosTraceLogFormat, &aDescription);
       
    59         }
       
    60         
       
    61     }
       
    62     
       
    63 #endif
       
    64 
       
    65 // ================= LOCAL FUNCTIONS =======================
       
    66 
       
    67 TInt DataSizeL(const RMessage2& aMessage, const TInt aClientBufferParam)
       
    68     {
       
    69     TInt dataSize = aMessage.GetDesLength(aClientBufferParam);
       
    70     if (dataSize < 0)
       
    71         {
       
    72         aMessage.Panic(KPosClientFault, EPositionBadDescriptor);
       
    73         User::Leave(KErrNoMemory);
       
    74         }
       
    75     return dataSize;
       
    76     }
       
    77 
       
    78 void LeaveIfFalseL(const TBool aCondition, const TInt aReason)
       
    79     {
       
    80     if (!aCondition)
       
    81         {
       
    82         User::Leave(aReason);
       
    83         }
       
    84     }
       
    85 
       
    86 // ================= MEMBER FUNCTIONS =======================
       
    87 
       
    88 /**
       
    89  * Read and kill the client if it leaves. If the returned error code 
       
    90  * is negative, the RMessage must not be completed. Complete after 
       
    91  * client is paniced crashes the server with USER 70.
       
    92  *
       
    93  * @param aMessage Message instance
       
    94  * @param aPtr Pointer to read from
       
    95  * @param aDes Descriptor to read to
       
    96  * @param aOffset offset to start read
       
    97  * @return Error code
       
    98  */
       
    99 TInt Global::Read(const RMessage2& aMessage, const TInt aParam, TDes8& aDes, TInt aOffset)
       
   100 	{
       
   101     TInt ret = aMessage.Read(aParam, aDes, aOffset);
       
   102     if (ret != KErrNone)
       
   103         {
       
   104         aMessage.Panic(KPosClientFault, EPositionBadDescriptor);
       
   105         }
       
   106     return ret;
       
   107     }
       
   108 
       
   109 /**
       
   110  * Read and kill the client if it leaves. If the returned error code 
       
   111  * is negative, the RMessage must not be completed. Complete after 
       
   112  * client is paniced crashes the server with USER 70.
       
   113  *
       
   114  * @param aMessage Message instance
       
   115  * @param aPtr Pointer to read from
       
   116  * @param aDes Descriptor to read to
       
   117  * @param aOffset offset to start read
       
   118  * @return Error code
       
   119  */
       
   120 TInt Global::Read(const RMessage2& aMessage, const TInt aParam, TDes16& aDes, TInt aOffset)
       
   121     {
       
   122 	TInt ret = aMessage.Read(aParam, aDes, aOffset);
       
   123     if (ret != KErrNone)
       
   124         {
       
   125         aMessage.Panic(KPosClientFault, EPositionBadDescriptor);
       
   126         }
       
   127     return ret;
       
   128     }
       
   129 
       
   130 /**
       
   131  * Write and kill the client if it leaves. If the returned error code 
       
   132  * is negative, the RMessage must not be completed. Complete after 
       
   133  * client is paniced crashes the server with USER 70.
       
   134  *
       
   135  * @param aMessage Message instance
       
   136  * @param aPtr Pointer to write to
       
   137  * @param aDes Descriptor to write from
       
   138  * @param aOffset offset to start write
       
   139  * @return Error code
       
   140  */
       
   141 TInt Global::Write(const RMessage2& aMessage, const TInt aParam, const TDesC8& aDes, TInt aOffset)
       
   142 	{
       
   143 	TInt ret = aMessage.Write(aParam, aDes, aOffset);
       
   144 	if (ret != KErrNone)
       
   145         {
       
   146         aMessage.Panic(KPosClientFault, EPositionBadDescriptor);
       
   147         }
       
   148     return ret;
       
   149 	}
       
   150 
       
   151 /**
       
   152  * Copies an 8-bit buffer from the address space of the client and puts 
       
   153  * the result in the returned argument. If the method leaves it the 
       
   154  * client may have been paniced and in that case it is forbidden to
       
   155  * complete the RMessage. If a client is paniced can be verified by the
       
   156  * call chain:
       
   157  * aMessage.Client().ExitType()
       
   158  *
       
   159  * @param aMessage the message from the client.
       
   160  * @param aClientBuffer a pointer to an 8-bit descriptor located in the 
       
   161  *        address space of the client.
       
   162  * @return a copy of the client buffer.
       
   163  */
       
   164 HBufC8* Global::CopyClientBuffer8LC(const RMessage2& aMessage, const TInt aClientBufferParam)
       
   165     {
       
   166     // Create an empty server side buffer that will contain client data
       
   167     TInt dataSize = DataSizeL(aMessage, aClientBufferParam);
       
   168     HBufC8* buffer = HBufC8::NewLC(dataSize);
       
   169 
       
   170     // Populate server side buffer with client data
       
   171     TPtr8 ptrToBuf = buffer->Des();
       
   172     User::LeaveIfError(Global::Read(aMessage, aClientBufferParam, ptrToBuf));
       
   173     return buffer;
       
   174     }
       
   175 
       
   176 /**
       
   177  * Copies a 16-bit buffer from the address space of the client and puts 
       
   178  * the result in the returned argument. If the method leaves it the  
       
   179  * client may have been paniced and in that case it is forbidden to 
       
   180  * complete the RMessage. If a client is paniced can be verified by the 
       
   181  * call chain:
       
   182  * aMessage.Client().ExitType()
       
   183  *
       
   184  * @param aMessage the message from the client.
       
   185  * @param aClientBuffer a pointer to a 16-bit descriptor located in the 
       
   186  *        address space of the client.
       
   187  * @return a copy of the client buffer.
       
   188  */
       
   189 HBufC* Global::CopyClientBufferLC(const RMessage2& aMessage, const TInt aClientBufferParam)
       
   190     {
       
   191     // Create an empty server side buffer that will contain client data
       
   192     TInt dataSize = DataSizeL(aMessage, aClientBufferParam);
       
   193     HBufC* buffer = HBufC::NewLC(dataSize);
       
   194 
       
   195     // Populate server side buffer with client data
       
   196     TPtr ptrToBuf = buffer->Des();
       
   197     User::LeaveIfError(Global::Read(aMessage, aClientBufferParam, ptrToBuf));
       
   198     return buffer;
       
   199     }
       
   200 
       
   201 /**
       
   202  * Checks that buffer size from client's message is the same
       
   203  * as position data class size specified in the class.
       
   204  *
       
   205  * @param aClass Position data class.
       
   206  * @param aBuffer Buffer containing position data class.
       
   207  * Leaves with KErrArgument if buffer is wrong.
       
   208  */
       
   209 void Global::ValidatePositionClassBufferL(const TPositionClassTypeBase& aClass, const TDes8& aBuffer)
       
   210     {
       
   211 DEBUG_TRACE("ValidatePositionClassBufferL in", __LINE__);
       
   212     LeaveIfFalseL(aBuffer.MaxSize() >= sizeof(TPositionClassTypeBase), KErrArgument);
       
   213     LeaveIfFalseL(aBuffer.MaxSize() >= aClass.PositionClassSize(), KErrArgument);
       
   214 DEBUG_TRACE("ValidatePositionClassBufferL out", __LINE__);
       
   215     }
       
   216 
       
   217 /**
       
   218  * Checks that class type specified in class is supported
       
   219  *
       
   220  * @param aClass Position data class.
       
   221  * @param aTypeExpected Position data class type as expected.
       
   222  * @param aResult Leave code if type is wrong. Default is KErrNotSupported.
       
   223  */
       
   224 void Global::ValidatePositionClassTypeL(const TPositionClassTypeBase& aClass, const TInt aTypeExpected, const TInt aResult)
       
   225     {
       
   226 DEBUG_TRACE("ValidatePositionClassTypeL in", __LINE__);
       
   227     if (aClass.PositionClassType() != aTypeExpected)
       
   228         {
       
   229         User::Leave(aResult);
       
   230         }
       
   231 DEBUG_TRACE("ValidatePositionClassTypeL out", __LINE__);
       
   232     }
       
   233 
       
   234 //  End of File