sensorservices/sensorserver/inc/server/sensrvtransactionqueue.h
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2006 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 "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:  Transaction queue implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SENSRVTRANSACTIONQUEUE_H
       
    20 #define SENSRVTRANSACTIONQUEUE_H
       
    21 
       
    22 #include <e32base.h>
       
    23 
       
    24 class CSensrvTransaction;
       
    25 class CSensrvSession;
       
    26 
       
    27 /**
       
    28  * Simple to use transaction queue.
       
    29  *
       
    30  * @since S60 5.0
       
    31  */
       
    32 class CSensrvTransactionQueue : public CBase
       
    33     {
       
    34     public:
       
    35         
       
    36         /**
       
    37         * Removal type specifies what should be done to removed transaction.
       
    38         */
       
    39         enum TRemovalType
       
    40             {
       
    41             ERemovalTypeUndefined, ///< Only valid removal type for non-owning queues
       
    42             ERemovalTypeComplete,  ///< Completes and deletes transaction
       
    43             ERemovalTypeCancel,    ///< Completes with KErrCancel and deletes transaction
       
    44             ERemovalTypeTransfer   ///< Transaction is just removed, not deleted or completed
       
    45             };
       
    46         
       
    47         /**
       
    48         * Linkable transaction pointer.
       
    49         */
       
    50         class TLinkableTransactionPtr
       
    51             {
       
    52             public:
       
    53                 TLinkableTransactionPtr()
       
    54                     {
       
    55                     }
       
    56 
       
    57                 /**
       
    58                 * Link item for queueing transaction pointers
       
    59                 */
       
    60                 TSglQueLink iLink;
       
    61                 
       
    62                 /**
       
    63                 * Transaction pointer
       
    64                 * Not owned.
       
    65                 */
       
    66                 CSensrvTransaction* iTransaction;
       
    67             };
       
    68 
       
    69 
       
    70         /**
       
    71         * Two phase constructor.
       
    72         *
       
    73         * @since S60 5.0
       
    74         * @param aOwned Indicates if queue owns transactions or is
       
    75         *        it used simply to store the pointers.
       
    76         *        If transactions are owned, deleting queue will
       
    77         *        also delete all transactions.
       
    78         * @return New CSensrvTransactionQueue instance
       
    79         * @exception KErrNoMemory Out of memory.
       
    80         */
       
    81         static CSensrvTransactionQueue* NewL(TBool aOwned);
       
    82 
       
    83         /**
       
    84         * Destructor.
       
    85         */
       
    86         virtual ~CSensrvTransactionQueue();
       
    87 
       
    88         /**
       
    89         * Adds transaction to the the queue
       
    90         *
       
    91         * @since S60 5.0
       
    92         * @param aTransaction The transaction to be added.
       
    93         * @param aLast If ETrue, transaction is added to the end of
       
    94         *        the queue, otherwise it is added to the beginning.
       
    95         * @return KErrNoMemory: Out of memory.
       
    96         *         KErrArgument: NULL transaction.
       
    97         */
       
    98         TInt Add(CSensrvTransaction* aTransaction, TBool aLast = ETrue);
       
    99 
       
   100         /**
       
   101         * Removes specified transaction from queue, if it is there.
       
   102         * If queue owns the transactions, the removed transaction
       
   103         * may be completed and deleted, depending on removal type. 
       
   104         *
       
   105         * @since S60 5.0
       
   106         * @param aTransaction The transaction to be removed.
       
   107         * @param aRemovalType Determines removal type.
       
   108         * @see TRemovalType
       
   109         */
       
   110         void Remove(CSensrvTransaction* aTransaction,
       
   111                     TRemovalType aRemovalType = ERemovalTypeUndefined);
       
   112 
       
   113         /**
       
   114         * Removes all transactions initiated by specified session
       
   115         * from queue.
       
   116         * If queue owns the transactions, the transactions
       
   117         * are completed with KErrCancel and are deleted. Otherwise 
       
   118         * does not delete or complete transactions.
       
   119         *
       
   120         * @since S60 5.0
       
   121         * @param aSession The session to match.
       
   122         */
       
   123         void Remove(CSensrvSession* aSession);
       
   124 
       
   125         /**
       
   126         * Removes all transactions with timestamp older than
       
   127         * specified cutoff time. 
       
   128         *
       
   129         * @since S60 5.0
       
   130         * @param aCutoffTime Transactions older that this time
       
   131         *        will be removed.
       
   132         * @return Number of transactions removed.
       
   133         */
       
   134         TInt RemoveObsolete(const TTime& aCutoffTime);
       
   135 
       
   136         /**
       
   137         * Removes all transactions.
       
   138         *
       
   139         * @since S60 5.0
       
   140         */
       
   141         void RemoveAll();
       
   142 
       
   143         /**
       
   144         * Gets pointer to first transaction in queue.
       
   145         * Transaction stays in the queue.
       
   146         *
       
   147         * @since S60 5.0
       
   148         * @return Pointer to first transaction in queue or NULL if empty.
       
   149         */
       
   150         CSensrvTransaction* First();
       
   151         
       
   152         /**
       
   153         * Checks if queue is empty
       
   154         *
       
   155         * @since S60 5.0
       
   156         * @return ETrue if queue is empty.
       
   157         */
       
   158         inline TBool IsEmpty() {return iTransactionPtrList.IsEmpty(); };
       
   159         
       
   160 
       
   161     private:
       
   162 
       
   163         /**
       
   164         * C++ constructor
       
   165         *
       
   166         * @since S60 5.0
       
   167         * @param aOwner Indicates if queue owns transactions or is
       
   168         *        it used simply to store the pointers.
       
   169         *        Deleting queue will delete all transactions if transactions
       
   170         *        are owned.
       
   171         */
       
   172         CSensrvTransactionQueue(TBool aOwned);
       
   173 
       
   174         /**
       
   175         * 2nd phase of construction
       
   176         *
       
   177         * @since S60 5.0
       
   178         */
       
   179         void ConstructL();
       
   180 
       
   181         /**
       
   182         * Gets pointer to the TLinkableTransactionPtr in queue
       
   183         * corresponding to specified transaction.
       
   184         * Transaction stays in the queue.
       
   185         *
       
   186         * @since S60 5.0
       
   187         * @param aTransaction The transaction to be found.
       
   188         * @return Pointer to TLinkableTransactionPtr or NULL if not found.
       
   189         */
       
   190         TLinkableTransactionPtr* FindTransactionPtr(CSensrvTransaction* aTransaction);  
       
   191         
       
   192         /**
       
   193         * Removes linkable transaction pointer and deletes it. 
       
   194         * If transactions are owned, they are completed with KErrCancel
       
   195         * or whatever error code they currently have.
       
   196         *
       
   197         * @since S60 5.0
       
   198         * @param aPtr Linkable transaction pointer to remove 
       
   199         * @param aRemovalType Determines removal type.
       
   200         * @see TRemovalType
       
   201         */
       
   202         void RemovePtr(TLinkableTransactionPtr* aPtr, TRemovalType aRemovalType);
       
   203              
       
   204 
       
   205     private:
       
   206     
       
   207         /**
       
   208         * Holds transaction pointers of transactions.
       
   209         * Queued pointer objects are owned.
       
   210         */
       
   211         TSglQue<TLinkableTransactionPtr> iTransactionPtrList;
       
   212 
       
   213         /**
       
   214         * Iterator for transaction queue
       
   215         */        
       
   216         TSglQueIter<TLinkableTransactionPtr> iTransactionPtrIter;
       
   217         
       
   218         /**
       
   219         * Indicates whether or not this queue owns the transactions it holds.
       
   220         */
       
   221         TBool iOwned;
       
   222         
       
   223         /**
       
   224         * Heap where the queue resides. 
       
   225         * Transactions must reside in the same heap.
       
   226         * Not own.
       
   227         */
       
   228         RHeap* iHeap;
       
   229     };
       
   230 
       
   231 
       
   232 
       
   233 #endif // SENSRVTRANSACTIONQUEUE_H