diff -r 000000000000 -r 0e4a32b9112d omxil_generic/omxilcomplib/src/primsgqueue.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/omxil_generic/omxilcomplib/src/primsgqueue.inl Wed Aug 25 12:40:50 2010 +0300 @@ -0,0 +1,156 @@ +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// + + +/** + @file + @internalComponent +*/ + + +template +inline RPriMsgQueue::TFrontQueueElement::TFrontQueueElement( + const TAny* apInfo) + : + ipInfo(apInfo) + { + iLink.iPriority = 0; + } + +template +inline RPriMsgQueue::TFrontQueueElement::TFrontQueueElement( + const TAny* apInfo, TInt aPriority) + : + ipInfo(apInfo) + { + iLink.iPriority = aPriority; + } + +template +inline TInt RPriMsgQueue::CreateLocal(TInt aSize, TOwnerType aOwner) + { + iFrontQueue.SetOffset(_FOFF(TFrontQueueElement, iLink)); + return iBackQueue.CreateLocal(aSize, sizeof(T), aOwner); + } + +template +inline TInt RPriMsgQueue::Handle() const + { + return iBackQueue.Handle(); + } + +template +inline TInt RPriMsgQueue::Send(const T& aMsg) + { + ASSERT(aMsg); + return iBackQueue.Send(&aMsg, sizeof(T)); + } + +template +inline TInt RPriMsgQueue::Receive(T& aMsg) + { + TInt err = DrainBackQueue(); + if (KErrNone == err) + { + if (iFrontQueue.IsEmpty()) + { + return KErrUnderflow; + } + + TFrontQueueElement* pElement = iFrontQueue.First(); + __ASSERT_DEBUG(pElement != 0, + User::Panic(RPriMsgQueuePanicCategory, 1)); + pElement->iLink.Deque(); + aMsg = reinterpret_cast(const_cast(pElement->ipInfo)); + delete pElement; + } + + return err; + + } + +template +inline void RPriMsgQueue::Close() + { + + // Back queue should be empty by now, but just in case... + + // Here we expect a pointer type!... + T pElement; + while (iBackQueue.Receive(&pElement, sizeof(T)) == KErrNone) + { + delete pElement; + pElement = 0; + } + iBackQueue.Close(); + + // Front queue should be empty by now, but just in case... + TFrontQueueElement* pFQElement = 0; + while (!iFrontQueue.IsEmpty()) + { + pFQElement = iFrontQueue.First(); + __ASSERT_DEBUG(pFQElement != 0, + User::Panic(RPriMsgQueuePanicCategory, 1)); + pFQElement->iLink.Deque(); + pElement = reinterpret_cast(const_cast(pFQElement->ipInfo)); + delete pElement; + delete pFQElement; + } + + } + +template +inline void RPriMsgQueue::NotifyDataAvailable(TRequestStatus& aStatus) + { + iBackQueue.NotifyDataAvailable(aStatus); + } + +template +inline void RPriMsgQueue::CancelDataAvailable() + { + iBackQueue.CancelDataAvailable(); + } + +template +TInt RPriMsgQueue::DrainBackQueue() + { + + // Here we expect a pointer type!... + T pElement; + while (iBackQueue.Receive(&pElement, sizeof(T)) == KErrNone) + { + TFrontQueueElement* pElem = + new TFrontQueueElement(pElement, pElement->Priority()); + + // This double attempt at allocation is done in order to allow OOM + // tests to pass, as there is no way to report an error to the client + // if we lose a RegisterCallbacks message in an OOM situation + if (!pElem) + { + pElem = new TFrontQueueElement(pElement, pElement->Priority()); + } + + if (!pElem) + { + // This command will get lost, but at least it won't be leaked + delete pElement; + return KErrNoMemory; + } + iFrontQueue.Add(*pElem); + } + + return KErrNone; + + }