commsfwsupport/commselements/nodemessages/src/nm_interfaces.cpp
branchRCL_3
changeset 26 b564fb5fd78b
parent 25 9d7ce34704c8
equal deleted inserted replaced
25:9d7ce34704c8 26:b564fb5fd78b
    21 #include "nm_interfaces.h"
    21 #include "nm_interfaces.h"
    22 #include <elements/nm_transport.h>
    22 #include <elements/nm_transport.h>
    23 #include <elements/nm_address_internal.h>
    23 #include <elements/nm_address_internal.h>
    24 #include "nm_signals.h"
    24 #include "nm_signals.h"
    25 
    25 
    26 
       
    27 #ifdef _DEBUG
    26 #ifdef _DEBUG
    28 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    27 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
    29 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    28 // (if it could happen through user error then you should give it an explicit, documented, category + code)
    30 _LIT(KSpecAssert_ElemNodeMessIntC, "ElemNodeMessIntC");
    29 _LIT(KSpecAssert_ElemNodeMessIntC, "ElemNodeMessIntC");
    31 #endif
    30 #endif
   138 	{
   137 	{
   139 	RClientInterface::Close();
   138 	RClientInterface::Close();
   140 	iClientType = TClientType::NullType();
   139 	iClientType = TClientType::NullType();
   141 	if(iPreAlloc!=NULL)
   140 	if(iPreAlloc!=NULL)
   142 		{
   141 		{
   143 		delete iPreAlloc->iPreAllocatedActivityChunk;
   142 		delete iPreAlloc;
       
   143 		iPreAlloc = NULL;
   144 		}
   144 		}
   145 	delete iPreAlloc;
       
   146 	iPreAlloc = NULL;
       
   147 	}
   145 	}
   148 
   146 
   149 EXPORT_C void RNodeInterface::PostMessage(const TRuntimeCtxId& aPostFrom, const TNodeId::TRemainder& aPostTo, const TSignalBase& aMessage) const
   147 EXPORT_C void RNodeInterface::PostMessage(const TRuntimeCtxId& aPostFrom, const TNodeId::TRemainder& aPostTo, const TSignalBase& aMessage) const
   150 	{
   148 	{
   151 	TUint8 postTo[__Align8(TRuntimeCtxId::KMaxInlineAddressSize)];
   149 	TUint8 postTo[__Align8(TRuntimeCtxId::KMaxInlineAddressSize)];
   169 */
   167 */
   170 	{
   168 	{
   171 	if(iPreAlloc!=NULL)
   169 	if(iPreAlloc!=NULL)
   172 		// Memory already allocated for this client
   170 		// Memory already allocated for this client
   173 		{
   171 		{
   174 		__ASSERT_DEBUG(iPreAlloc->iPreAllocatedActivityChunk != NULL, User::Panic(KSpecAssert_ElemNodeMessIntC, 5));
   172 		// If iPreAlloc is not NULL then it should be usable. Ensure that the memory chunk has been suitable allocated
   175 		return;
   173 		__ASSERT_DEBUG(iPreAlloc->iPreAllocatedActivityChunk != NULL, User::Panic(KSpecAssert_ElemNodeMessIntC, 2));
       
   174 		if(iPreAlloc->iPreAllocSize >= aAllocSize)
       
   175 			// Memory already preallocated of a sufficient size - this could happen if clients are re-added
       
   176 			{
       
   177 			return;
       
   178 			}
       
   179 		else
       
   180 			// Memory preallocated is too small. Free up the space and then attempt to reallocate
       
   181 			{
       
   182 			// Code path should never enter here as PreAllocL should not be called once the iPreAlloc memory space is allocated.
       
   183 			// However on the chance of production device entering here attempt to clear the preallocated space and reallocate a more suitable amount.
       
   184             __ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ElemNodeMessIntC, 3)); 
       
   185 			delete iPreAlloc;
       
   186 			iPreAlloc = NULL;
       
   187 			}
   176 		}
   188 		}
   177 	iPreAlloc = new (ELeave) TPreAllocStore();
   189 	TPreAllocStore* preAlloc = new (ELeave) TPreAllocStore();
   178 	iPreAlloc->iPreAllocatedActivityChunk = User::AllocL(aAllocSize);
   190 	CleanupStack::PushL(preAlloc);
       
   191 	preAlloc->iPreAllocatedActivityChunk = User::AllocL(aAllocSize);
       
   192 	CleanupStack::Pop(preAlloc);
       
   193 	iPreAlloc = preAlloc;
   179 	iPreAlloc->iPreAllocSize = aAllocSize;
   194 	iPreAlloc->iPreAllocSize = aAllocSize;
   180 	}
   195 	}
   181 
   196 
   182 EXPORT_C TAny* RNodeInterface::ClaimPreallocatedSpace(TUint aSize)
   197 EXPORT_C TAny* RNodeInterface::ClaimPreallocatedSpace(TUint aSize)
   183 /**	Finds a pointer of the requested size from the preallocation array (see PreallocActivitySpaceL) and returns it
   198 /**	Finds a pointer of the requested size from the preallocation array (see PreallocActivitySpaceL) and returns it
   186 */
   201 */
   187 	{
   202 	{
   188 	if(!(iPreAlloc && aSize <= iPreAlloc->iPreAllocSize))
   203 	if(!(iPreAlloc && aSize <= iPreAlloc->iPreAllocSize))
   189 		{
   204 		{
   190 		// By this stage the PreAllocL must have been triggered and memory space must have been allocated.
   205 		// By this stage the PreAllocL must have been triggered and memory space must have been allocated.
   191 		__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ElemNodeMessIntC, 3));
   206 		__ASSERT_DEBUG(EFalse, User::Panic(KSpecAssert_ElemNodeMessIntC, 4));
   192 		delete iPreAlloc->iPreAllocatedActivityChunk;
   207 		TRAPD(err,PreAllocL(aSize));
   193 		iPreAlloc->iPreAllocatedActivityChunk = User::AllocL(aSize);
   208 		__ASSERT_ALWAYS(err, User::Panic(KMessagesPanic, EPreAllocationFailedPanic));
   194 		}
   209 		}
   195 	TAny* preallocatedSpace = (RNodeInterface*)iPreAlloc->iPreAllocatedActivityChunk;
   210 	TAny* preallocatedSpace = (RNodeInterface*)iPreAlloc->iPreAllocatedActivityChunk;
   196 	iPreAlloc->iPreAllocatedActivityChunk=NULL;
   211 	// Release ownership of the memory area
       
   212 	iPreAlloc->iPreAllocatedActivityChunk = NULL;
       
   213 	delete iPreAlloc;
       
   214 	iPreAlloc = NULL;
   197 	return preallocatedSpace;
   215 	return preallocatedSpace;
   198 	}
   216 	}
   199 
   217 
   200 /******************************************************************************************************
   218 /******************************************************************************************************
   201 *
   219 *
   250 	return KErrArgument;
   268 	return KErrArgument;
   251 	}
   269 	}
   252 
   270 
   253 EXPORT_C void RRequestOriginator::Open(RRequestOriginator& aOriginalRequest)
   271 EXPORT_C void RRequestOriginator::Open(RRequestOriginator& aOriginalRequest)
   254 	{
   272 	{
   255 	__ASSERT_DEBUG(aOriginalRequest.IsOpen(), User::Panic(KSpecAssert_ElemNodeMessIntC, 4));
   273 	__ASSERT_DEBUG(aOriginalRequest.IsOpen(), User::Panic(KSpecAssert_ElemNodeMessIntC, 1));
   256 	iNode = aOriginalRequest.iNode;
   274 	iNode = aOriginalRequest.iNode;
   257 	iRemainder = aOriginalRequest.iRemainder;
   275 	iRemainder = aOriginalRequest.iRemainder;
   258 	aOriginalRequest.Close();
   276 	aOriginalRequest.Close();
   259 	}
   277 	}
   260 
   278