stif/TestServer/src/Printqueue.cpp
branchRCL_3
changeset 59 8ad140f3dd41
parent 0 a03f92240627
equal deleted inserted replaced
49:7fdc9a71d314 59:8ad140f3dd41
       
     1 /*
       
     2 * Copyright (c) 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 "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: This module contains implementation of CPrintQueue 
       
    15 * class and TPrintQueueItem class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "PrintQueue.h"
       
    21 
       
    22 // EXTERNAL DATA STRUCTURES
       
    23 
       
    24 // EXTERNAL FUNCTION PROTOTYPES  
       
    25 
       
    26 // CONSTANTS
       
    27 
       
    28 // MACROS
       
    29 
       
    30 // LOCAL CONSTANTS AND MACROS
       
    31 
       
    32 // MODULE DATA STRUCTURES
       
    33 
       
    34 // LOCAL FUNCTION PROTOTYPES
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 
       
    38 // ==================== LOCAL FUNCTIONS =======================================
       
    39 
       
    40 // None
       
    41 
       
    42 // ================= MEMBER FUNCTIONS =========================================
       
    43 
       
    44 
       
    45 // Initialise the queue
       
    46 const TInt TPrintQueueItem::iOffset = _FOFF( TPrintQueueItem, iSlink );
       
    47 
       
    48 
       
    49 /*
       
    50 -------------------------------------------------------------------------------
       
    51 
       
    52     Class: CPrintQueue
       
    53 
       
    54     Method: NewL
       
    55 
       
    56     Description: Constructs a print queue.
       
    57       
       
    58     Parameters: None
       
    59 
       
    60     Return Values: CPrintQueue*                     Pointer to new queue
       
    61 
       
    62     Errors/Exceptions: Leaves if memory allocation fails.
       
    63 
       
    64     Status: Approved
       
    65     
       
    66 -------------------------------------------------------------------------------
       
    67 */
       
    68 CPrintQueue* CPrintQueue::NewL()
       
    69     {
       
    70 
       
    71     CPrintQueue* self = new( ELeave ) CPrintQueue;
       
    72     return self;
       
    73 
       
    74     }
       
    75 
       
    76 
       
    77 /*
       
    78 -------------------------------------------------------------------------------
       
    79 
       
    80     Class: CPrintQueue
       
    81 
       
    82     Method: CPrintQueue
       
    83 
       
    84     Description: Constructor.
       
    85     Initialises the queue and queue iterator.
       
    86 
       
    87     Parameters: None
       
    88 
       
    89     Return Values: None
       
    90 
       
    91     Errors/Exceptions: None
       
    92 
       
    93     Status: Approved
       
    94 
       
    95 -------------------------------------------------------------------------------
       
    96 */
       
    97 CPrintQueue::CPrintQueue():
       
    98      iQueue( TPrintQueueItem::iOffset ),
       
    99      iQueueIterator( iQueue )
       
   100     {
       
   101 
       
   102     iQueueLen = 0;
       
   103 
       
   104     }
       
   105 
       
   106 
       
   107 
       
   108 /*
       
   109 -------------------------------------------------------------------------------
       
   110 
       
   111     Class: CPrintQueue
       
   112 
       
   113     Method: ~CPrintQueue
       
   114 
       
   115     Description: Destructor.
       
   116 
       
   117     Deletes all items in queue. Function requires that it is called from
       
   118     the heap to where the items are constructed.
       
   119        
       
   120     Parameters: None
       
   121 
       
   122     Return Values: None
       
   123 
       
   124     Errors/Exceptions: None
       
   125 
       
   126     Status: Approved
       
   127     
       
   128 -------------------------------------------------------------------------------
       
   129 */
       
   130 CPrintQueue::~CPrintQueue()
       
   131     {
       
   132     
       
   133     TPrintQueueItem *item = NULL;
       
   134 
       
   135     // Delete items in queue
       
   136     while(( item = Pop() ) != NULL )
       
   137         {
       
   138         delete item;      // TPrintQueueItem destructor does't free the memory
       
   139         }
       
   140 
       
   141     }
       
   142 
       
   143 
       
   144 /*
       
   145 -------------------------------------------------------------------------------
       
   146 
       
   147     Class: CPrintQueue
       
   148 
       
   149     Method: Push
       
   150 
       
   151     Description:
       
   152 
       
   153     Push item to queue. If queue is full, does not add item to queue.
       
   154 
       
   155     Parameters: TPrintQueueItem& anItem       :in:  Item to push to queue
       
   156 
       
   157     Return Values: TInt                             KErrNoMemory if queue is full
       
   158                                                     KErrNone     otherwise
       
   159 
       
   160     Errors/Exceptions: None
       
   161 
       
   162     Status: Approved
       
   163 
       
   164 -------------------------------------------------------------------------------
       
   165 */
       
   166 TInt CPrintQueue::Push( TPrintQueueItem& anItem )
       
   167     {
       
   168 
       
   169     if( iQueueLen < KQueueMaxLen  )
       
   170         {
       
   171         iQueue.AddLast( anItem  );
       
   172         iQueueLen++;
       
   173 
       
   174         // Added successfully
       
   175         return KErrNone;
       
   176         }
       
   177     else
       
   178         {    
       
   179         // Do not add to queue
       
   180         return KErrNoMemory;
       
   181         }
       
   182 
       
   183     }
       
   184 
       
   185 /*
       
   186 -------------------------------------------------------------------------------
       
   187 
       
   188     Class: CPrintQueue
       
   189 
       
   190     Method: Pop
       
   191 
       
   192     Description: Removes first item from queue and returns that.
       
   193     if queue is empty, then return NULL.
       
   194 
       
   195     Parameters: None
       
   196 
       
   197     Return Values: TPrintQueueItem*                 Queue item or NULL.
       
   198 
       
   199     Errors/Exceptions: None
       
   200 
       
   201     Status: Approved
       
   202     
       
   203 -------------------------------------------------------------------------------
       
   204 */
       
   205 TPrintQueueItem* CPrintQueue::Pop()
       
   206     {
       
   207 
       
   208     TPrintQueueItem* firstItem = NULL;
       
   209     
       
   210     if( !iQueue.IsEmpty()  )
       
   211         {
       
   212         firstItem = iQueue.First();
       
   213         iQueue.Remove( *firstItem  );
       
   214         iQueueLen--;
       
   215         }
       
   216     
       
   217     return( firstItem  );
       
   218 
       
   219     }
       
   220 
       
   221 /*
       
   222 -------------------------------------------------------------------------------
       
   223 
       
   224     Class: CPrintQueue
       
   225 
       
   226     Method: Count
       
   227 
       
   228     Description: Returns the queue size.
       
   229     
       
   230     Parameters: None
       
   231 
       
   232     Return Values: TInt                             Count
       
   233 
       
   234     Errors/Exceptions: None
       
   235 
       
   236     Status: Approved
       
   237     
       
   238 -------------------------------------------------------------------------------
       
   239 */
       
   240 TInt CPrintQueue::Count()
       
   241     {
       
   242     
       
   243     return( iQueueLen  );
       
   244 
       
   245     }
       
   246 
       
   247 /*
       
   248 -------------------------------------------------------------------------------
       
   249 
       
   250     Class: TPrintQueueItem
       
   251 
       
   252     Method: TPrintQueueItem
       
   253 
       
   254     Description: Constructor
       
   255 
       
   256     C++ default constructor can NOT contain any code, that
       
   257     might leave.
       
   258     
       
   259     Parameters  const TInt aPriority          :in:  Priority
       
   260                 const TStifInfoName& aText1       :in:  Description field
       
   261                 const TName& aText2           :in:  Text field
       
   262 
       
   263     Return Values: None
       
   264 
       
   265     Errors/Exceptions: None
       
   266 
       
   267     Status: Approved
       
   268     
       
   269 -------------------------------------------------------------------------------
       
   270 */
       
   271 TPrintQueueItem::TPrintQueueItem( const TInt aPriority,
       
   272                                   const TStifInfoName& aText1,
       
   273                                   const TName& aText2 )
       
   274     {
       
   275 
       
   276     iPriority = aPriority;
       
   277     iData1 = aText1;
       
   278     iData2 = aText2;
       
   279 
       
   280     }
       
   281 
       
   282 // End of File