os/security/contentmgmt/referencedrmagent/contentiterator/contentiteratordata.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "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 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 #include "contentiteratordata.h"
    20 
    21 using namespace ContentAccess;
    22 
    23 CContentIteratorData* CContentIteratorData::NewL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
    24 	{
    25 	CContentIteratorData* self = new (ELeave) CContentIteratorData();
    26 	CleanupStack::PushL(self);
    27 	self->ConstructL(aSearchPath, aRecursive, aMimeType);
    28 	CleanupStack::Pop(self);
    29 	return self;
    30 	}
    31 	
    32 CContentIteratorData::CContentIteratorData()
    33 	{
    34 	}
    35 	
    36 CContentIteratorData::~CContentIteratorData()
    37 	{
    38 	// release semaphore 
    39 	iThreadSemaphore.Signal();
    40 	
    41 	iDataLockSemaphore.Close();
    42 	iThreadSemaphore.Close();
    43 	}
    44 
    45 void CContentIteratorData::ConstructL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
    46 	{
    47 	// Remember search parameters, the CContentIterator::ThreadEntry() 
    48 	// will ask for these later
    49 	iPath.Copy(aSearchPath);
    50 	iRecursive = aRecursive;
    51 	iMimeType.Copy(aMimeType);
    52 	
    53 	
    54 	// Create semaphores
    55 	User::LeaveIfError(iDataLockSemaphore.CreateLocal(1, EOwnerProcess));	
    56 	User::LeaveIfError(iThreadSemaphore.CreateLocal(1, EOwnerProcess));
    57 	
    58 	// Grab semaphore so CContentIterator::ThreadEntry function can't enter the loop yet
    59 	iThreadSemaphore.Wait();
    60 	}
    61 
    62 				
    63 void CContentIteratorData::Lock()
    64 	{
    65 	iDataLockSemaphore.Wait();
    66 	}
    67 
    68 void CContentIteratorData::Unlock()
    69 	{
    70 	iDataLockSemaphore.Signal();
    71 	}
    72 		
    73 void CContentIteratorData::CompleteClientRequest(TInt aError)
    74 	{
    75 	RThread clientThread;
    76 	clientThread.Open(iClientThreadId);
    77 	clientThread.RequestComplete(iClientRequest, aError);
    78 	clientThread.Close();
    79 	}
    80 	
    81 	
    82 void CContentIteratorData::SetClientRequest(TThreadId& aClientThreadId, TRequestStatus& aStatus)
    83 	{
    84 	// Remember the thread and TRequestStatus that must be completed later
    85 	iClientThreadId = aClientThreadId;
    86 	iClientRequest = &aStatus;
    87 	}
    88 	
    89 void CContentIteratorData::RunThreadFunction(TFileIteratorOperation aFunction)
    90 	{
    91 	// Unblock the CContentIterator::ThreadEntry() function and allow it to run
    92 	iFunction = aFunction;
    93 	iThreadSemaphore.Signal();
    94 	}
    95 
    96 TFileIteratorOperation CContentIteratorData::ThreadWait()
    97 	{
    98 	// Called by CContentIterator::ThreadEntry() to block execution until RunThreadFunction() is called
    99 	iThreadSemaphore.Wait();
   100 	return iFunction;
   101 	}
   102 
   103 		
   104 void CContentIteratorData::SetData(const TDesC& aPath, const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType)
   105 	{
   106 	// Set the results found in the search
   107 	iPath.Copy(aPath);
   108 	iMimeType.Copy(aMimeType);
   109 	iUniqueId.Copy(aUniqueId);
   110 	iName.Copy(aName);
   111 	}
   112 
   113 const TDesC& CContentIteratorData::Path() const
   114 	{
   115 	return iPath; 
   116 	}
   117 
   118 const TDesC8& CContentIteratorData::MimeType() const
   119 	{
   120 	return iMimeType; 
   121 	}
   122 	
   123 const TDesC& CContentIteratorData::UniqueId() const
   124 	{
   125 	return iUniqueId;
   126 	}
   127 
   128 const TDesC& CContentIteratorData::Name() const
   129 	{
   130 	return iName;
   131 	}
   132 	
   133 TBool CContentIteratorData::IsRecursive() const
   134 	{
   135 	return iRecursive;	
   136 	}