telephonyserverplugins/common_tsy/commontsy/src/mmutility/CResponseTimer.cpp
changeset 0 3553901f7fa8
child 24 6638e7f4bd8f
child 42 3adadc800673
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 
       
    18 //  INCLUDE FILES
       
    19 #include "CResponseTimer.h"
       
    20 #include "cmmphonetsy.h"
       
    21 #include "CResponseTimerStore.h"
       
    22 #include "MmTsy_timeoutdefs.h"
       
    23 #include <ctsy/tflogger.h>
       
    24 
       
    25 #ifdef REQHANDLE_TIMER
       
    26 
       
    27 // ======== MEMBER FUNCTIONS ========
       
    28 
       
    29 CResponseTimer* CResponseTimer::NewL( 
       
    30     CMmPhoneTsy* aPhone ) //a Pointer to a phone        
       
    31     {
       
    32     CResponseTimer* runner = new (ELeave) CResponseTimer;
       
    33     CleanupStack::PushL( runner );
       
    34     //save pointer to phone
       
    35     runner->iPhone = aPhone;
       
    36     //initialize the beat Counter
       
    37     runner->iBeatCounter = 0;
       
    38     //2nd phase construction
       
    39     runner->ConstructL();
       
    40     CleanupStack::Pop();
       
    41 
       
    42     return runner;
       
    43     }
       
    44 
       
    45 CResponseTimer::CResponseTimer()
       
    46     {
       
    47     }
       
    48 
       
    49 void CResponseTimer::ConstructL()
       
    50     {
       
    51      // neutral priority, 0
       
    52     iTimer = CHeartbeat::NewL( CActive::EPriorityStandard ); 
       
    53     }
       
    54 
       
    55 CResponseTimer::~CResponseTimer()
       
    56     {
       
    57     if ( iTimer )
       
    58         {
       
    59         //stop calling Beat...
       
    60         iTimer->Cancel();
       
    61         }
       
    62 
       
    63     delete iTimer;
       
    64     }
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // CResponseTimer::Start
       
    68 // Starts timer.
       
    69 // (other items were commented in a header).
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CResponseTimer::Start()
       
    73     {
       
    74     //Check if active 
       
    75     if ( !iTimer->IsActive() ) 
       
    76         {
       
    77         //Timer tick is on the second 
       
    78         iTimer->Start( ETwelveOClock, this );
       
    79         } 
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CResponseTimer::Stop
       
    84 // Stops timer.
       
    85 // (other items were commented in a header).
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CResponseTimer::Stop()
       
    89     {
       
    90     //Check if active 
       
    91     if ( iTimer->IsActive () ) 
       
    92         { 
       
    93         //Cancel beat method calling 
       
    94         iTimer->Cancel(); 
       
    95         } 
       
    96     }
       
    97 
       
    98 // ---------------------------------------------------------------------------
       
    99 // CResponseTimer::Beat
       
   100 // Beat is called once every second.
       
   101 // (other items were commented in a header).
       
   102 // ---------------------------------------------------------------------------
       
   103 //
       
   104 void CResponseTimer::Beat()
       
   105     {
       
   106     //Update the timer time
       
   107     iBeatCounter++;
       
   108 
       
   109     //check if the time limit is reached for any entry
       
   110     for ( TInt index = 0; 
       
   111           index < iPhone->GetTimeStampStore()->NumberOfEntries();
       
   112           index++ )
       
   113         {
       
   114         CResponseTimerStore::CTableEntry *aEntry = 
       
   115             iPhone->GetTimeStampStore()->GetEntry( index );
       
   116         //if the entry is expired, complete and delete it
       
   117         if ( aEntry->GetTimeStamp() <= iBeatCounter )
       
   118             {   
       
   119 TFLOGSTRING2("TSY: Request completed due timer expiration, IPC: %d", aEntry->GetIPC() ); 
       
   120             
       
   121             //call completion of the request due expired timer 
       
   122             iPhone->TimerExpired( aEntry->GetUserObject(),
       
   123                                   aEntry->GetHandleType(),
       
   124                                   aEntry->GetIPC() );
       
   125             }
       
   126         else //aEntry.timeStamp > iBeatCounter
       
   127             {
       
   128             //break cause table is ordered.
       
   129             break;
       
   130             }
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // CResponseTimer::Synchronize
       
   136 // Pure virtual class in base class. Called when synchronization
       
   137 // is lost. The iBeatCounter is increased.
       
   138 // (other items were commented in a header).
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 void CResponseTimer::Synchronize()
       
   142     {
       
   143     if(iBeatCounter > 0)
       
   144         {
       
   145         iBeatCounter++;
       
   146         }
       
   147     }
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // CResponseTimer::GetBeatCounter
       
   151 // Returns the the value of the iBeatCounter attribute.
       
   152 // (other items were commented in a header).
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 TUint32 CResponseTimer::GetBeatCounter()
       
   156     {
       
   157     return iBeatCounter;
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // CResponseTimer::ResetBeatCounter
       
   162 // Resets the value of iBeatCounter to 0.
       
   163 // (other items were commented in a header).
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 void CResponseTimer::ResetBeatCounter()
       
   167     {
       
   168     //set the beat counter to 0
       
   169     iBeatCounter = 0;
       
   170     }
       
   171 
       
   172 #endif //REQHANDLE_TIMER
       
   173 
       
   174 //  End of File
       
   175 
       
   176 
       
   177 
       
   178