commsfwutils/commsbufs/inc/commsbuf.inl
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 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 inline TCommsBuf::TCommsBuf()
       
    17 {
       
    18 }
       
    19 
       
    20 #ifndef __KERNEL_MODE__
       
    21 
       
    22 inline TCommsBuf::TCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aHandle, TInt aPool) :
       
    23 	iFrontCanary(KCanaryDefault),
       
    24 	iLength(aBufSize),
       
    25 	iOffset(aRawDataOffset),
       
    26 	iPool(aPool),
       
    27 	iHandle(aHandle),
       
    28 	iRawDataOffset(aRawDataOffset),
       
    29 	iRawSize(aBufSize),
       
    30 	iNext(NULL),
       
    31 	iBackCanary(KCanaryDefault)
       
    32 	{
       
    33 	iType = 0,
       
    34 	iReservedBytes[0] = 0;
       
    35 	iReservedBytes[1] = 0;
       
    36 	iReservedBytes[2] = 0;
       
    37 	iReservedWords[0] = 0;
       
    38 	iReservedWords[1] = 0;
       
    39 	iReservedWords[2] = 0;
       
    40 	iReservedWords[3] = 0;
       
    41 	iReservedWords[4] = 0;
       
    42 	}
       
    43 
       
    44 inline TCommsBuf::TCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aPool) :
       
    45 	iFrontCanary(KCanaryDefault),
       
    46 	iLength(aBufSize),
       
    47 	iOffset(aRawDataOffset),
       
    48 	iPool(aPool),
       
    49 	iHandle(0),
       
    50 	iRawDataOffset(aRawDataOffset),
       
    51 	iRawSize(aBufSize),
       
    52 	iNext(NULL),
       
    53 	iBackCanary(KCanaryDefault)
       
    54 	{
       
    55 	iType = 0,
       
    56 	iReservedBytes[0] = 0;
       
    57 	iReservedBytes[1] = 0;
       
    58 	iReservedBytes[2] = 0;
       
    59 	iReservedWords[0] = 0;
       
    60 	iReservedWords[1] = 0;
       
    61 	iReservedWords[2] = 0;
       
    62 	iReservedWords[3] = 0;
       
    63 	iReservedWords[4] = 0;
       
    64 	}
       
    65 
       
    66 inline TAny* RCommsBuf::operator new(TUint /* aSize */, const TUint8* aPtr) __NO_THROW
       
    67 	{
       
    68 	__ASSERT_COMPILE(sizeof(RCommsBuf) == TCommsBuf::KCommsBufMetadataSize);
       
    69 	return (TUint8*)aPtr;
       
    70 	}
       
    71 
       
    72 inline void RCommsBuf::operator delete(TAny* /* aPtr */, const TUint8*) __NO_THROW
       
    73 	{		
       
    74 	}
       
    75 
       
    76 inline RCommsBuf::RCommsBuf()
       
    77 	{
       
    78 	}
       
    79 
       
    80 inline RCommsBuf::RCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aHandle, TInt aPool)
       
    81 : iCommsBufMetaData(aRawDataOffset, aBufSize, aHandle, aPool)
       
    82 	{
       
    83 	}
       
    84 
       
    85 inline RCommsBuf::RCommsBuf(TInt aRawDataOffset, TUint aBufSize, TInt aPool)
       
    86 : iCommsBufMetaData(aRawDataOffset, aBufSize, aPool)
       
    87 	{		
       
    88 	}
       
    89 
       
    90 
       
    91 inline TPtrC8 RCommsBuf::DesC8() const
       
    92 /**
       
    93 Creates and returns a non-modifiable pointer descriptor representing the contained data
       
    94 
       
    95 @return non-modifiable pointer descriptor
       
    96 */
       
    97 	{
       
    98 	__ASSERT_COMMSBUF();
       
    99 	return TPtrC8((TUint8*)(this) + iCommsBufMetaData.iOffset, iCommsBufMetaData.iLength);
       
   100 	}
       
   101 
       
   102 inline const TUint8* RCommsBuf::RawBase() const
       
   103 /**
       
   104 Returns a const ponter to the start of the data represented by the RCommsBuf
       
   105 
       
   106  @return A const pointer
       
   107 */
       
   108 	{
       
   109 	__ASSERT_COMMSBUF();
       
   110 	return ((TUint8*)this + iCommsBufMetaData.iRawDataOffset);
       
   111 	}
       
   112 
       
   113 inline TUint8* RCommsBuf::RawBase()
       
   114 /**
       
   115 Returns a ponter to the start of the data represented by the RCommsBuf
       
   116 
       
   117  @return A pointer
       
   118 */
       
   119 	{
       
   120 	__ASSERT_COMMSBUF();
       
   121 	return ((TUint8*)this + iCommsBufMetaData.iRawDataOffset);
       
   122 	}
       
   123 
       
   124 inline TInt RCommsBuf::RawSize() const
       
   125 /**
       
   126 Returns the raw size of the RCommsBuf data
       
   127 
       
   128   @return the size of the RCommsBuf data
       
   129 */
       
   130 	{
       
   131 	return iCommsBufMetaData.iRawSize;
       
   132 	}
       
   133 
       
   134 inline const TUint8* RCommsBuf::Ptr() const
       
   135 /**
       
   136 Returns a const pointer to the actual location of the data start. 
       
   137 Actual data start location may differ from the start of the data 
       
   138 
       
   139 @see RCommsBuf::RawBase
       
   140 @return A const pointer
       
   141 */
       
   142 	{
       
   143 	__ASSERT_COMMSBUF();
       
   144 	return ((TUint8*)(this) + iCommsBufMetaData.iOffset);
       
   145 	}
       
   146 
       
   147 inline TUint8* RCommsBuf::Ptr()
       
   148 /**
       
   149 Returns a pointer to the actual location of the data start. 
       
   150 
       
   151 @see RCommsBuf::RawBase
       
   152 @return A pointer
       
   153 */
       
   154 	{
       
   155 	__ASSERT_COMMSBUF();
       
   156     return ((TUint8*)(this) + iCommsBufMetaData.iOffset);
       
   157 	}
       
   158 
       
   159 
       
   160 inline TInt	RCommsBuf::Length() const
       
   161 /**
       
   162 Returns the length of the RCommsBuf data
       
   163 
       
   164   @return the length of the RCommsBuf data
       
   165 */
       
   166 	{
       
   167 	return iCommsBufMetaData.iLength;
       
   168 	}
       
   169 
       
   170 inline TInt RCommsBuf::Offset() const
       
   171 /**
       
   172 Returns the offset of the RCommsBuf data
       
   173 
       
   174   @return the offset of the RCommsBuf data
       
   175 */
       
   176 	{
       
   177 	return iCommsBufMetaData.iOffset - iCommsBufMetaData.iRawDataOffset;
       
   178 	}
       
   179 
       
   180 inline void RCommsBuf::SetOffset(TInt aOffset)
       
   181 /**
       
   182 Sets the RCommsBuf data offset
       
   183 
       
   184 @param aOffset  An offset
       
   185  */
       
   186 	{
       
   187 	__ASSERT_ALWAYS((aOffset >= 0) && ((aOffset + iCommsBufMetaData.iLength) <= iCommsBufMetaData.iRawSize), CommsBuf::Panic(EMBuf_NegativeOffset));
       
   188 	iCommsBufMetaData.iOffset = iCommsBufMetaData.iRawDataOffset + aOffset;
       
   189 	}
       
   190 
       
   191 inline TUint8 RCommsBuf::operator[] (TInt aPos) const
       
   192 	{
       
   193 	__ASSERT_COMMSBUF();
       
   194     __ASSERT_ALWAYS(aPos >= 0 && aPos < Length(), CommsBuf::Panic(EMBuf_IndexOutofRange));
       
   195 	return (Ptr()[aPos]);
       
   196 	}
       
   197 
       
   198 inline TUint8& RCommsBuf::operator[] (TInt aPos)
       
   199 	{
       
   200 	__ASSERT_COMMSBUF();
       
   201     __ASSERT_ALWAYS(aPos >= 0 && aPos < Length(), CommsBuf::Panic(EMBuf_IndexOutofRange));
       
   202 	return (((TUint8*)Ptr())[aPos]);
       
   203 	}
       
   204 
       
   205 inline void RCommsBuf::Reset()
       
   206 /**
       
   207 Resets the length and offset of the RCommsBuf data
       
   208 */
       
   209 	{
       
   210 	iCommsBufMetaData.iLength = 0;
       
   211 	iCommsBufMetaData.iOffset = iCommsBufMetaData.iRawDataOffset;
       
   212 	}
       
   213 
       
   214 
       
   215 inline TInt RCommsBuf::AppendLimit() const
       
   216 /**
       
   217 Returns the length of the bytes that can be appended
       
   218 */
       
   219 	{
       
   220     return iCommsBufMetaData.iRawDataOffset + iCommsBufMetaData.iRawSize - iCommsBufMetaData.iOffset - iCommsBufMetaData.iLength;
       
   221 	}
       
   222 
       
   223 inline TInt RCommsBuf::PrependLimit() const
       
   224 /**
       
   225 Returns the length of the data that can be prepended
       
   226 */
       
   227 	{
       
   228 	return iCommsBufMetaData.iOffset - iCommsBufMetaData.iRawDataOffset;
       
   229 	}
       
   230 
       
   231 inline void RCommsBuf::SetDataRange(TInt aOffset, TInt aLength)
       
   232 /**
       
   233 Sets the offset and length of the data
       
   234 
       
   235 @param aOffset An offset
       
   236 @param aLength A length
       
   237 */
       
   238 	{
       
   239 	__ASSERT_ALWAYS((aOffset >= 0) && (aLength >= 0) && ((aOffset + aLength) <= iCommsBufMetaData.iRawSize), CommsBuf::Panic(EMBuf_NegativeOffset));
       
   240 	iCommsBufMetaData.iOffset = iCommsBufMetaData.iRawDataOffset + aOffset;
       
   241 	iCommsBufMetaData.iLength = aLength;
       
   242 	}
       
   243 
       
   244 inline void RCommsBuf::AdjustDataStart(TInt aDelta)
       
   245 /**
       
   246 Adjust the RCommsBuf data offset and length with the given delta value.
       
   247 ie; the data offset is incremented by the given delta value and the data 
       
   248 length is decremented by the given delta value
       
   249 */
       
   250 	{
       
   251 	iCommsBufMetaData.iOffset += aDelta;
       
   252 	iCommsBufMetaData.iLength -= aDelta;
       
   253 	__ASSERT_ALWAYS((iCommsBufMetaData.iOffset >= iCommsBufMetaData.iRawDataOffset) && (iCommsBufMetaData.iLength >= 0), CommsBuf::Panic(EMBuf_InvalidLengthOrOffset));
       
   254 	}
       
   255 
       
   256 inline void RCommsBuf::AdjustDataEnd(TInt aDelta)
       
   257 /**
       
   258 Adjust the RCommsBuf data length with the given delta value. 
       
   259 ie; the data length is incremented by the given value
       
   260 */
       
   261 	{
       
   262 	iCommsBufMetaData.iLength += aDelta;
       
   263 	__ASSERT_ALWAYS((iCommsBufMetaData.iLength >= 0) && ((Offset() + iCommsBufMetaData.iLength) <= iCommsBufMetaData.iRawSize), CommsBuf::Panic(EMBuf_InvalidLengthOrOffset));
       
   264 	}
       
   265 
       
   266 inline void RCommsBuf::SetNext(RCommsBuf* aBuf)
       
   267 	{
       
   268 	iCommsBufMetaData.iNext = aBuf;		
       
   269 	}
       
   270 
       
   271 inline RCommsBuf* RCommsBuf::Next()
       
   272 	{
       
   273 	return iCommsBufMetaData.iNext;		
       
   274 	}
       
   275 
       
   276 inline const RCommsBuf* RCommsBuf::Next() const
       
   277 	{
       
   278 	return iCommsBufMetaData.iNext;	
       
   279 	}
       
   280 
       
   281 inline CCommsBufPool* RCommsBuf::Pool() const	
       
   282 	{
       
   283 	return reinterpret_cast<CCommsBufPool*>(iCommsBufMetaData.iPool);
       
   284 	}
       
   285 
       
   286 inline TInt RCommsBuf::Handle() const
       
   287 	{
       
   288 	return iCommsBufMetaData.iHandle;
       
   289 	}
       
   290 
       
   291 inline void RCommsBuf::AssertCommsBufInvariants() const
       
   292     {
       
   293     __ASSERT_ALWAYS(iCommsBufMetaData.iFrontCanary == TCommsBuf::KCanaryDefault && iCommsBufMetaData.iBackCanary == TCommsBuf::KCanaryDefault, CommsBuf::Panic(EMBuf_CorruptMBuf));
       
   294     }
       
   295 
       
   296 
       
   297 RCommsBufAccessor::RCommsBufAccessor(const RCommsBuf& aCommsBuf) : iCommsBuf(aCommsBuf)
       
   298 	{
       
   299 	}
       
   300 
       
   301 TInt RCommsBufAccessor::Handle() const
       
   302 	{
       
   303 	return iCommsBuf.Handle();
       
   304 	}
       
   305 
       
   306 
       
   307 #endif // __KERNEL_MODE__
       
   308 
       
   309 
       
   310