libraries/memoryaccess/DynamicDfcSupport.cpp
changeset 0 7f656887cf89
child 86 56b6ee983610
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // DynamicDfcSupport.cpp
       
     2 // 
       
     3 // Copyright (c) 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 #include "DynamicDfcSupport.h"
       
    13 
       
    14 #ifdef FSHELL_DYNAMICDFC_SUPPORT
       
    15 
       
    16 TInt TDynDfcQueWrapper::Create(TDynDfcQueWrapper*& aDfcQ, TInt aPriority, const TDesC& aBaseName)
       
    17 	{
       
    18 	TDynDfcQueWrapper* wrapper = new TDynDfcQueWrapper;
       
    19 	if (!wrapper) return KErrNoMemory;
       
    20 	TInt err = Kern::DynamicDfcQCreate(wrapper->iQueue, aPriority, aBaseName);
       
    21 	if (err)
       
    22 		{
       
    23 		delete wrapper;
       
    24 		}
       
    25 	else
       
    26 		{
       
    27 		aDfcQ = wrapper;
       
    28 		}
       
    29 	return err;
       
    30 	}
       
    31 
       
    32 void TDynDfcQueWrapper::Destroy()
       
    33 	{
       
    34 	delete this;
       
    35 	}
       
    36 
       
    37 TDynDfcQueWrapper::TDynDfcQueWrapper()
       
    38 	: iQueue(NULL)
       
    39 	{}
       
    40 
       
    41 TDynDfcQueWrapper::~TDynDfcQueWrapper()
       
    42 	{
       
    43 	iQueue->Destroy();
       
    44 	}
       
    45 
       
    46 #else
       
    47 
       
    48 TDynDfcQueWrapper::TDynDfcQueWrapper()
       
    49 	: iQueue(NULL), iKillDfc(ExitDfcThread, this, 7)
       
    50 	{}
       
    51 
       
    52 TInt TDynDfcQueWrapper::Create(TDynDfcQueWrapper*& aDfcQ, TInt aPriority, const TDesC& aBaseName)
       
    53 	{
       
    54 	TDynDfcQueWrapper* wrapper = new TDynDfcQueWrapper;
       
    55 	TInt nonce = 0;
       
    56 	TInt ret;
       
    57 	do
       
    58 		{
       
    59 		TBuf<64> buf;
       
    60 		buf.Copy(aBaseName);
       
    61 		buf.Append('-');
       
    62 		buf.AppendNum(nonce);
       
    63 		nonce++;
       
    64 		ret = Kern::DfcQCreate(wrapper->iQueue, aPriority, &buf);
       
    65 		} while (ret == KErrAlreadyExists);
       
    66 
       
    67 	if (ret == KErrNone)
       
    68 		{
       
    69 		wrapper->iKillDfc.SetDfcQ(wrapper->iQueue);
       
    70 		aDfcQ = wrapper;
       
    71 		}
       
    72 
       
    73 	return ret;
       
    74 	}
       
    75 
       
    76 void TDynDfcQueWrapper::Destroy()
       
    77 	{
       
    78 	iKillDfc.Enque(); 
       
    79 	}
       
    80 
       
    81 TDynDfcQueWrapper::~TDynDfcQueWrapper()
       
    82 	{
       
    83 	delete iQueue;
       
    84 	}
       
    85 
       
    86 void TDynDfcQueWrapper::ExitDfcThread(TAny* aSelf)
       
    87 	{
       
    88 	delete (TDynDfcQueWrapper*)aSelf;
       
    89 	Kern::Exit(KErrNone);
       
    90 	}
       
    91 
       
    92 #endif