convergedcallengine/cce/src/cccedurationtimer.cpp
changeset 0 ff3b6d0fd310
child 19 7d48bed6ce0c
equal deleted inserted replaced
-1:000000000000 0:ff3b6d0fd310
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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 class implements duration timer for calls.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    "mccecallobserver.h"
       
    21 #include    "mcceconferencecallobserver.h"
       
    22 #include    "cccedurationtimer.h"
       
    23 #include    "cccelogger.h"
       
    24 
       
    25 // ================= MEMBER FUNCTIONS =======================
       
    26 
       
    27 // ---------------------------------------------------------
       
    28 // CCCEDurationTimer::CCCEDurationTimer
       
    29 // C++ default constructor can NOT contain any code, that
       
    30 // might leave.
       
    31 // ---------------------------------------------------------
       
    32 //
       
    33 CCCEDurationTimer::CCCEDurationTimer()
       
    34     {
       
    35     iObserver           = NULL;
       
    36     iConferenceCallObserver = NULL;
       
    37     iActive             = EFalse;
       
    38     iNumberOfBeats      = 0;
       
    39     iStartTime          = 0;
       
    40     iAirTimeDuration    = EFalse;
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------
       
    44 // CCCEDurationTimer::ConstructL
       
    45 // Symbian 2nd phase constructor can leave.
       
    46 // ---------------------------------------------------------
       
    47 //
       
    48 void CCCEDurationTimer::ConstructL()
       
    49     {
       
    50     iHeartbeat = CHeartbeat::NewL( CActive::EPriorityStandard );
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CCCEDurationTimer::NewL
       
    55 // Two-phased constructor.
       
    56 // -----------------------------------------------------------------------------
       
    57 //
       
    58 CCCEDurationTimer* CCCEDurationTimer::NewL()
       
    59     {
       
    60     CCCEDurationTimer* runner = new (ELeave) CCCEDurationTimer();
       
    61     CleanupStack::PushL( runner );
       
    62     runner->ConstructL();
       
    63     CleanupStack::Pop( runner );
       
    64 
       
    65     return runner;
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------
       
    69 // CCCEDurationTimer::~CCCEDurationTimer
       
    70 // Destructor.
       
    71 // ---------------------------------------------------------    
       
    72 //
       
    73 CCCEDurationTimer::~CCCEDurationTimer()
       
    74     {
       
    75     iObserver = NULL;
       
    76     iConferenceCallObserver = NULL;
       
    77     
       
    78     if ( iHeartbeat )
       
    79         {
       
    80         //stop calling Beat...
       
    81         iHeartbeat->Cancel();
       
    82         }
       
    83     delete iHeartbeat;
       
    84     }
       
    85 
       
    86 // ---------------------------------------------------------
       
    87 // CCCEDurationTimer::SetObserver
       
    88 // ---------------------------------------------------------    
       
    89 //
       
    90 void CCCEDurationTimer::SetObserver( MCCECallObserver* aObserver )
       
    91     {
       
    92     iObserver = aObserver;
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------
       
    96 // CCCEDurationTimer::SetObserver
       
    97 // ---------------------------------------------------------    
       
    98 //
       
    99 void CCCEDurationTimer::SetConferenceObserver( MCCEConferenceCallObserver* aObserver )
       
   100     {
       
   101     iConferenceCallObserver = aObserver;
       
   102     }
       
   103 
       
   104 // -----------------------------------------------------------------------------
       
   105 // CCCEDurationTimer::Start
       
   106 //    Overload to resetting iNumberOfBeats 
       
   107 //
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 void CCCEDurationTimer::Start()
       
   111     {
       
   112     Start(0);
       
   113    
       
   114     }
       
   115     
       
   116 // -----------------------------------------------------------------------------
       
   117 // CCCEDurationTimer::Start
       
   118 //    if timer is not already active
       
   119 //        set iStarTime to current time
       
   120 //        set iNumberOfBeats to aBeatsOffset
       
   121 //        start timer
       
   122 //        set value ETrue to iActive
       
   123 //
       
   124 // (other items were commented in a header).
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CCCEDurationTimer::Start(TInt aBeatsOffset)
       
   128     {
       
   129     //Check if active 
       
   130     if ( !iActive ) 
       
   131         {
       
   132         //Initialize iStartime
       
   133         iStartTime.HomeTime();
       
   134         //Clear number of beats
       
   135         iNumberOfBeats = aBeatsOffset;
       
   136         //Timer tick is on the second 
       
   137         iHeartbeat->Start( ETwelveOClock, this );
       
   138         //Set flag to indicate that timer is active
       
   139         iActive = ETrue;
       
   140         //Set flag to indicate that air time duration counter is not started
       
   141         iAirTimeDuration = EFalse;
       
   142         }
       
   143         
       
   144     }
       
   145 
       
   146 // -----------------------------------------------------------------------------
       
   147 // -----------------------------------------------------------------------------
       
   148 //	
       
   149 void CCCEDurationTimer::RestartAirTimeDuration(TInt aBeatsOffset)
       
   150     {
       
   151     //Check if active 
       
   152     if ( !iActive ) 
       
   153         {
       
   154         // Set number of beats
       
   155         iNumberOfBeats = aBeatsOffset;
       
   156         //Timer tick is on the second 
       
   157         iHeartbeat->Start( ETwelveOClock, this );
       
   158         //Set flag to indicate that timer is active
       
   159         iActive = ETrue;
       
   160         //Set flag to indicate that air time duration counter is started
       
   161         iAirTimeDuration = ETrue;
       
   162         }
       
   163     }
       
   164 	
       
   165 // -----------------------------------------------------------------------------
       
   166 // CCCEDurationTimer::StartAirTimeDuration
       
   167 //    if timer is not already active
       
   168 //        set iStarTime to current time
       
   169 //        start timer
       
   170 //        set value ETrue to iActive
       
   171 //        set value ETrue to iAirTimeDuration
       
   172 //
       
   173 // (other items were commented in a header).
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 void CCCEDurationTimer::StartAirTimeDuration()
       
   177     {
       
   178     //Check if active 
       
   179     if ( !iActive ) 
       
   180         { 
       
   181         //Initialize iStartime
       
   182         iStartTime.HomeTime();
       
   183         // Clear number of beats
       
   184         iNumberOfBeats = 0;
       
   185         //Timer tick is on the second 
       
   186         iHeartbeat->Start( ETwelveOClock, this );
       
   187         //Set flag to indicate that timer is active
       
   188         iActive = ETrue;
       
   189         //Set flag to indicate that air time duration counter is started
       
   190         iAirTimeDuration = ETrue;
       
   191         }
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // CCCEDurationTimer::StartTime
       
   196 // Returns current date and time object.
       
   197 // (other items were commented in a header).
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 TDateTime CCCEDurationTimer::StartTime()
       
   201     {
       
   202 	return iStartTime.DateTime();
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CCCEDurationTimer::Stop
       
   207 // Stops timer
       
   208 //
       
   209 //    store iActive in ret boolean
       
   210 //    if timer is active
       
   211 //        reset iStartTime
       
   212 //        stop timer.
       
   213 //        set value EFalse to iActive
       
   214 //    return ret
       
   215 // (other items were commented in a header).
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 TBool CCCEDurationTimer::Stop()
       
   219     {
       
   220     TBool ret = iActive;
       
   221 
       
   222     //Check if active 
       
   223     if ( iActive ) 
       
   224         { 
       
   225         //Reset iStartTime
       
   226         iStartTime = 0;
       
   227         //Cancel beat method calling 
       
   228         iHeartbeat->Cancel(); 
       
   229         //Set flag to indicate that timer is not active
       
   230         iActive = EFalse;
       
   231         }
       
   232 
       
   233     return ret;
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CCCEDurationTimer::Beat
       
   238 // Beat is called once every second. If iMmCall is not null
       
   239 //    (timer is used for calculating the duration of a call), the method
       
   240 //    CompleteNotifyCallDurationChange is called. The iNumberOfBeats is
       
   241 //    increased to count the amount of seconds passed from the starting
       
   242 //    of the timer.
       
   243 // (other items were commented in a header).
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 void CCCEDurationTimer::Beat()
       
   247     {
       
   248     iNumberOfBeats++;
       
   249 
       
   250     // If iOwner is NOT null, this timer is used to count call duration.
       
   251     if ( iObserver )
       
   252         {
       
   253         //complete notify duration change, 1 sec gone
       
   254         iObserver->CallDurationChanged( iNumberOfBeats );
       
   255         }
       
   256 
       
   257     // If iOwner is NOT null, this timer is used to count call duration.
       
   258     if ( iConferenceCallObserver )
       
   259         {
       
   260         //complete notify duration change, 1 sec gone
       
   261         iConferenceCallObserver->CallDurationChanged( iNumberOfBeats );
       
   262         }
       
   263     }
       
   264 
       
   265 // -----------------------------------------------------------------------------
       
   266 // CCCEDurationTimer::NumberOfBeats
       
   267 // Returns number of beats from the previous Start of the timer.
       
   268 // (other items were commented in a header).
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 
       
   272 TInt CCCEDurationTimer::NumberOfBeats() const
       
   273     {
       
   274     return iNumberOfBeats;
       
   275     }
       
   276     
       
   277 // -----------------------------------------------------------------------------
       
   278 // CCCEDurationTimer::Reset
       
   279 // Sets the number of beats to zero
       
   280 // (other items were commented in a header).
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CCCEDurationTimer::Reset() 
       
   284     {
       
   285     iNumberOfBeats = 0;
       
   286     }
       
   287 
       
   288 // -----------------------------------------------------------------------------
       
   289 // CCCEDurationTimer::Synchronize
       
   290 // This methods is called when synchronization is lost (the 
       
   291 // method Beat couldn't be called). It calculates the number
       
   292 // of seconds passed after the start of the timer and assigns 
       
   293 // it to iNumberOfBeats
       
   294 //
       
   295 //    if this is not air time duration counter
       
   296 //        initialize local variables
       
   297 //        get current home time
       
   298 //        increase value of number of beats by one because at least one beat is 
       
   299 //         missing
       
   300 //        calculate difference of current home time and timer start time in 
       
   301 //         seconds and save result in secondsFromStart
       
   302 //        if secondsFromStart is positive
       
   303 //            calculate difference of number of beats and secondsFromStart and 
       
   304 //             save result in timeDifference
       
   305 //            if timeDifference is less than 10
       
   306 //                correct the deviation and set secondsFromStart in number of 
       
   307 //                 beats
       
   308 // (other items were commented in a header).
       
   309 // -----------------------------------------------------------------------------
       
   310 //
       
   311 void CCCEDurationTimer::Synchronize()
       
   312     {
       
   313     const TInt tenSeconds = 10;
       
   314     
       
   315     //we can't synchronize if this is air time duration counter
       
   316     if ( !iAirTimeDuration )
       
   317         {
       
   318         TInt timeDifference( 0 );
       
   319         //get the correct time
       
   320         TTime currentTime;
       
   321         currentTime.HomeTime();
       
   322 
       
   323         TTimeIntervalSeconds secondsFromStart( 0 );
       
   324 
       
   325         //At least one beat is now missing
       
   326         iNumberOfBeats++;
       
   327 
       
   328         //calculate the amount of seconds that should be
       
   329         currentTime.SecondsFrom( iStartTime, secondsFromStart );
       
   330 
       
   331         //calculate difference of iNumberOfBeats and secondsFromStart
       
   332         if ( 0 <= secondsFromStart.Int() )
       
   333             {
       
   334             if ( secondsFromStart.Int() > iNumberOfBeats )
       
   335                 {
       
   336                 timeDifference = secondsFromStart.Int() - iNumberOfBeats;
       
   337                 }
       
   338             else if ( secondsFromStart.Int() < iNumberOfBeats )
       
   339                 {
       
   340                 timeDifference = iNumberOfBeats - secondsFromStart.Int();
       
   341                 }
       
   342 
       
   343             //correct the deviation only if time difference is less than 10 
       
   344             //seconds
       
   345             if ( timeDifference < tenSeconds )
       
   346                 {
       
   347                 iNumberOfBeats = secondsFromStart.Int();
       
   348                 }
       
   349             }
       
   350         }
       
   351     }
       
   352 
       
   353 //  End of File