os/security/contentmgmt/referencedrmagent/contentiterator/contentiteratordata.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/referencedrmagent/contentiterator/contentiteratordata.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,136 @@
1.4 +/*
1.5 +* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "contentiteratordata.h"
1.23 +
1.24 +using namespace ContentAccess;
1.25 +
1.26 +CContentIteratorData* CContentIteratorData::NewL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
1.27 + {
1.28 + CContentIteratorData* self = new (ELeave) CContentIteratorData();
1.29 + CleanupStack::PushL(self);
1.30 + self->ConstructL(aSearchPath, aRecursive, aMimeType);
1.31 + CleanupStack::Pop(self);
1.32 + return self;
1.33 + }
1.34 +
1.35 +CContentIteratorData::CContentIteratorData()
1.36 + {
1.37 + }
1.38 +
1.39 +CContentIteratorData::~CContentIteratorData()
1.40 + {
1.41 + // release semaphore
1.42 + iThreadSemaphore.Signal();
1.43 +
1.44 + iDataLockSemaphore.Close();
1.45 + iThreadSemaphore.Close();
1.46 + }
1.47 +
1.48 +void CContentIteratorData::ConstructL(const TDesC& aSearchPath, TBool aRecursive, const TDesC8& aMimeType)
1.49 + {
1.50 + // Remember search parameters, the CContentIterator::ThreadEntry()
1.51 + // will ask for these later
1.52 + iPath.Copy(aSearchPath);
1.53 + iRecursive = aRecursive;
1.54 + iMimeType.Copy(aMimeType);
1.55 +
1.56 +
1.57 + // Create semaphores
1.58 + User::LeaveIfError(iDataLockSemaphore.CreateLocal(1, EOwnerProcess));
1.59 + User::LeaveIfError(iThreadSemaphore.CreateLocal(1, EOwnerProcess));
1.60 +
1.61 + // Grab semaphore so CContentIterator::ThreadEntry function can't enter the loop yet
1.62 + iThreadSemaphore.Wait();
1.63 + }
1.64 +
1.65 +
1.66 +void CContentIteratorData::Lock()
1.67 + {
1.68 + iDataLockSemaphore.Wait();
1.69 + }
1.70 +
1.71 +void CContentIteratorData::Unlock()
1.72 + {
1.73 + iDataLockSemaphore.Signal();
1.74 + }
1.75 +
1.76 +void CContentIteratorData::CompleteClientRequest(TInt aError)
1.77 + {
1.78 + RThread clientThread;
1.79 + clientThread.Open(iClientThreadId);
1.80 + clientThread.RequestComplete(iClientRequest, aError);
1.81 + clientThread.Close();
1.82 + }
1.83 +
1.84 +
1.85 +void CContentIteratorData::SetClientRequest(TThreadId& aClientThreadId, TRequestStatus& aStatus)
1.86 + {
1.87 + // Remember the thread and TRequestStatus that must be completed later
1.88 + iClientThreadId = aClientThreadId;
1.89 + iClientRequest = &aStatus;
1.90 + }
1.91 +
1.92 +void CContentIteratorData::RunThreadFunction(TFileIteratorOperation aFunction)
1.93 + {
1.94 + // Unblock the CContentIterator::ThreadEntry() function and allow it to run
1.95 + iFunction = aFunction;
1.96 + iThreadSemaphore.Signal();
1.97 + }
1.98 +
1.99 +TFileIteratorOperation CContentIteratorData::ThreadWait()
1.100 + {
1.101 + // Called by CContentIterator::ThreadEntry() to block execution until RunThreadFunction() is called
1.102 + iThreadSemaphore.Wait();
1.103 + return iFunction;
1.104 + }
1.105 +
1.106 +
1.107 +void CContentIteratorData::SetData(const TDesC& aPath, const TDesC& aUniqueId, const TDesC& aName, const TDesC8& aMimeType)
1.108 + {
1.109 + // Set the results found in the search
1.110 + iPath.Copy(aPath);
1.111 + iMimeType.Copy(aMimeType);
1.112 + iUniqueId.Copy(aUniqueId);
1.113 + iName.Copy(aName);
1.114 + }
1.115 +
1.116 +const TDesC& CContentIteratorData::Path() const
1.117 + {
1.118 + return iPath;
1.119 + }
1.120 +
1.121 +const TDesC8& CContentIteratorData::MimeType() const
1.122 + {
1.123 + return iMimeType;
1.124 + }
1.125 +
1.126 +const TDesC& CContentIteratorData::UniqueId() const
1.127 + {
1.128 + return iUniqueId;
1.129 + }
1.130 +
1.131 +const TDesC& CContentIteratorData::Name() const
1.132 + {
1.133 + return iName;
1.134 + }
1.135 +
1.136 +TBool CContentIteratorData::IsRecursive() const
1.137 + {
1.138 + return iRecursive;
1.139 + }