systemswstubs/examplecommonisc/IscDriver/src/IscSendQueue.cpp
changeset 43 e71858845f73
parent 40 b7e5ed8c1342
child 46 e1758cbb96ac
equal deleted inserted replaced
40:b7e5ed8c1342 43:e71858845f73
     1 /*
       
     2 * Copyright (c) 2005 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:  An example implementation for ISC Driver Reference
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <kernel.h>
       
    22 #include "IscSendQueue.h"
       
    23 #include "IscTrace.h"
       
    24 
       
    25 // EXTERNAL DATA STRUCTURES
       
    26 
       
    27 // EXTERNAL FUNCTION PROTOTYPES  
       
    28 
       
    29 // CONSTANTS
       
    30 const TInt KImpossibleChannelId( 255 );
       
    31 
       
    32 // MACROS
       
    33 
       
    34 // LOCAL CONSTANTS AND MACROS
       
    35 
       
    36 // MODULE DATA STRUCTURES
       
    37 
       
    38 // LOCAL FUNCTION PROTOTYPES
       
    39 
       
    40 // FORWARD DECLARATIONS
       
    41 
       
    42 
       
    43 // ============================ MEMBER FUNCTIONS ===============================
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // DIscSendQueue::DIscSendQueue
       
    47 // C++ default constructor can NOT contain any code, that
       
    48 // might leave.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 EXPORT_C DIscSendQueue::DIscSendQueue( TUint32** aQueue, TIscSendFrameInfo** aParameterQueue, TUint16 aSize )
       
    52          :iParameterQueue( aParameterQueue )
       
    53     {
       
    54     iHead  = 0;
       
    55     iTail  = 0;
       
    56     iCount = 0;
       
    57     iQueue = aQueue;
       
    58     iSize  = aSize;
       
    59     for ( TInt i( 0 ); i < aSize; i++ )
       
    60         {
       
    61         iParameterQueue[i]->iChannelId = KImpossibleChannelId;
       
    62         iParameterQueue[i]->iChannelPtr = NULL;
       
    63         iParameterQueue[i]->iFrameInfo = NULL;
       
    64         }
       
    65     E_TRACE( ( _T( "ISQ:ISQ %d 0x%x" ), iSize, iQueue ) );
       
    66     }
       
    67     
       
    68 // Destructor
       
    69 EXPORT_C DIscSendQueue::~DIscSendQueue()
       
    70     {
       
    71     iHead       = 0;
       
    72     iTail       = 0;
       
    73     iCount      = 0;
       
    74     iQueue      = NULL;
       
    75     iParameterQueue = NULL;
       
    76     iSize       = 0;
       
    77     }
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // DIscSendQueue::Add
       
    82 // Function to add element to queue
       
    83 // ( other items were commented in a header ).
       
    84 // -----------------------------------------------------------------------------
       
    85 //
       
    86 EXPORT_C TInt DIscSendQueue::Add( TAny* anEntry, TUint16 aId, DIscChannel* aChannelPtr, TAny* aFrameInfo )
       
    87     {
       
    88     E_TRACE( ( _T( "ISQ:A %d, 0x%x" ), iCount, iQueue ) );
       
    89 
       
    90     TInt irqLevel = DisableIrqs();
       
    91 
       
    92     if ( iCount == iSize || iSize == 0 )
       
    93         {
       
    94         RestoreIrqs( irqLevel );
       
    95         return KErrNoMemory;//EFalse;
       
    96         }
       
    97 
       
    98     /* place the buffer into the queue */
       
    99     iQueue[ iTail ] = ( TUint32* )( anEntry );
       
   100 
       
   101     TIscSendFrameInfo* tmp = iParameterQueue[ iTail ];
       
   102     // Set additional info for send frame
       
   103     tmp->iChannelId = aId;
       
   104     
       
   105     tmp->iChannelPtr = aChannelPtr;
       
   106 
       
   107     tmp->iFrameInfo = aFrameInfo;
       
   108 
       
   109     /* adjust tail pointer */
       
   110     iTail = ++iTail % iSize;
       
   111 
       
   112     /* remember the amount of the requests in the queue */
       
   113     iCount++;
       
   114 
       
   115     RestoreIrqs( irqLevel );
       
   116 
       
   117     return KErrNone;
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // DIscSendQueue::GetFirstFrameInfo
       
   122 // Returns a frist frame info from list.
       
   123 // (other items were commented in a header).
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C TIscSendFrameInfo* DIscSendQueue::GetFirstFrameInfo()
       
   127     {
       
   128     E_TRACE( ( _T( "ISQ:G(%d, 0x%x)" ), iCount, iQueue ) );
       
   129 
       
   130     TIscSendFrameInfo* result;
       
   131 
       
   132     TInt irqLevel = DisableIrqs();
       
   133 
       
   134     if ( iCount == 0 || iSize == 0 )
       
   135         {
       
   136         RestoreIrqs( irqLevel );
       
   137         return NULL;
       
   138         }
       
   139 
       
   140     result = iParameterQueue[ iHead ];
       
   141     
       
   142     RestoreIrqs( irqLevel );
       
   143 
       
   144     return result;
       
   145     }
       
   146