commsfwutils/commsbufs/mbufmgr/src/mb_thread.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-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 #include <mb_thread.h>
       
    17 #include <e32debug.h>
       
    18 #include <es_mbuf.h>
       
    19 #include <es_commsbuf.h>
       
    20 #include <comms-infras/commsbufpondop.h>
       
    21 
       
    22 using namespace CommsFW;
       
    23 
       
    24 EXPORT_C TInt RCFThread::Create(const TDesC& aName, TThreadFunction aOtherThreadFunction,
       
    25 						TInt aStackSize, RHeap* aHeap, TAny* aModuleArgs)
       
    26 /**
       
    27 Derived implementation of RThread::Create, which processes some specific
       
    28 data for the new thread before calling the RThread::Create.
       
    29 @param aName Name of the new thread.
       
    30 @param aOtherThreadFunction Main thread-function.
       
    31 @param aStackSize Initial size of the thread stack.
       
    32 @param aHeap The heap for the thread.
       
    33 @param aModuleArgs Pointer given as argument to aOtherThreadFunction.
       
    34 @see RThread
       
    35 @see TThreadFunction
       
    36 @see RHeap
       
    37 @publishedPartner
       
    38 @released
       
    39 */
       
    40 	{
       
    41    	iStartupInfo.iCommsBufPond = TCommsBufPondTLSOp::Get();
       
    42    	__CFLOG_STMT( iStartupInfo.iCFLogIf = CCFLogIf::Context());
       
    43 	if(iStartupInfo.iCommsBufPond.IsNull())
       
    44 		return KErrNotFound;
       
    45 	// Check to make sure the logger is available.
       
    46 	#ifdef __CFLOG_ACTIVE
       
    47 		if( !iStartupInfo.iCFLogIf )
       
    48 			{
       
    49 			RDebug::Print( _L( "RCFThread::Create - the log interface was not found.  This normally means that the logging version of commsfw.dll has been mixed with a stub version of cflog.dll.  See CommsDebugUtility How-To Document FAQ section for details on enabling logging in a release build." ) );
       
    50 
       
    51 			return KErrNotFound;
       
    52 			}
       
    53 	#endif
       
    54 	
       
    55    	iStartupInfo.iOtherThreadFunction = aOtherThreadFunction;
       
    56    	iStartupInfo.iModuleArgs = aModuleArgs;
       
    57    	return RThread::Create(aName, RCFThreadFunction, aStackSize, aHeap, &iStartupInfo);
       
    58    	};
       
    59 
       
    60 EXPORT_C TInt RCFThread::Create(const TDesC& aName, TThreadFunction aOtherThreadFunction,
       
    61 				TInt aStackSize, TInt aMinHeapSize, TInt aMaxHeapSize, TAny* aModuleArgs) 
       
    62 /**
       
    63 Derived implementation of RThread::Create, which processes some specific
       
    64 data for the new thread before calling the RThread::Create
       
    65 @param aName Name of the new thread.
       
    66 @param aOtherThreadFunction Main thread-function.
       
    67 @param aStackSize Initial size of the thread stack.
       
    68 @param aMinHeapSize Minimum size of the heap that will be created for the thread.
       
    69 @param aMaxHeapSize Maximum size of the heap that will be created for the thread.
       
    70 @param aModuleArgs Pointer given as argument to aOtherThreadFunction.
       
    71 @see RThread
       
    72 @see TThreadFunction
       
    73 @publishedPartner
       
    74 @released
       
    75 */
       
    76 	{
       
    77    	iStartupInfo.iCommsBufPond = TCommsBufPondTLSOp::Get();
       
    78    	__CFLOG_STMT( iStartupInfo.iCFLogIf = CCFLogIf::Context());
       
    79 	if(iStartupInfo.iCommsBufPond.IsNull())
       
    80 		return KErrNotFound;
       
    81 	// Check to make sure the logger is available.
       
    82 	#ifdef __CFLOG_ACTIVE
       
    83 		if( !iStartupInfo.iCFLogIf )
       
    84 			{
       
    85 			RDebug::Print( _L( "RCFThread::Create - the log interface was not found.  This normally means that the logging version of commsfw.dll has been mixed with a stub version of cflog.dll.  See CommsDebugUtility How-To Document FAQ section for details on enabling logging in a release build." ) );
       
    86 
       
    87 			return KErrNotFound;
       
    88 			}
       
    89 	#endif
       
    90 
       
    91    	iStartupInfo.iOtherThreadFunction = aOtherThreadFunction;
       
    92    	iStartupInfo.iModuleArgs = aModuleArgs;
       
    93    	return RThread::Create(aName, RCFThreadFunction, aStackSize, aMinHeapSize, aMaxHeapSize, &iStartupInfo);
       
    94    	};
       
    95 
       
    96 TInt RCFThread::RCFThreadFunction(TAny* aStartupInfo )
       
    97 /**
       
    98 Intermediate function which masquerades as the main thread function in order to 
       
    99 perform some specific actions for the new thread in the correct context before
       
   100 calling the new thread's actual main thread function
       
   101 @param aStartupInfo structure containing pointers to MBufMger and CFlog.
       
   102 @see RCFThread::ThreadStartupInfo 
       
   103 @internalComponent
       
   104 */
       
   105 	{
       
   106 	ThreadStartupInfo* startInfo = reinterpret_cast<ThreadStartupInfo*>(aStartupInfo);
       
   107 	TCommsBufPondTLSOp tls(startInfo->iCommsBufPond);
       
   108 	tls.Set();
       
   109    	__CFLOG_STMT( startInfo->iCFLogIf->SetContext();)
       
   110 	__CFLOG_OPEN;
       
   111    	TInt result = startInfo->iOtherThreadFunction(startInfo->iModuleArgs);
       
   112 	__CFLOG_CLOSE;
       
   113    	return result;
       
   114    	};
       
   115