sensorservices/sensorserver/src/server/sensrvtimer.cpp
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:  Generic sensor server timer
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "sensrvdefines.h"
       
    20 #include "sensrvtimer.h"
       
    21 #include "sensrvtrace.h"
       
    22 
       
    23 // -----------------------------------------------------------------------------
       
    24 // Two-phased constructor.
       
    25 // -----------------------------------------------------------------------------
       
    26 //
       
    27 CSensrvTimer* CSensrvTimer::NewL(MSensrvTimerCallback& aCallback,
       
    28                                  const TTimeIntervalMicroSeconds32& aMaxTime,
       
    29                                  TInt aTimerId)
       
    30     {
       
    31     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::NewL(0x%x, %d, %d)" ), &aCallback, aMaxTime.Int(), aTimerId ) );
       
    32 
       
    33     CSensrvTimer* self = new (ELeave) CSensrvTimer(aCallback, aMaxTime, aTimerId);
       
    34     CleanupStack::PushL(self);
       
    35     self->ConstructL(); // Base call, needed or will KERN-EXEC 0 at ::After()
       
    36     CleanupStack::Pop(self); 
       
    37 
       
    38     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::NewL - return 0x%x" ), self ) );
       
    39 
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // Constructor with callback class as a parameter.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CSensrvTimer::CSensrvTimer(MSensrvTimerCallback& aCallback, 
       
    48                            const TTimeIntervalMicroSeconds32& aMaxTime,
       
    49                            TInt aTimerId)
       
    50         : CTimer(EPriorityHigh), 
       
    51           iCallback(aCallback),
       
    52           iMaximumTime(aMaxTime),
       
    53           iTimerId(aTimerId)
       
    54     {
       
    55     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::CSensrvTimer()" ) ) );
       
    56 
       
    57     // Nothing to do
       
    58     
       
    59     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::CSensrvTimer - return" ) ) );
       
    60     }
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // Destructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CSensrvTimer::~CSensrvTimer()
       
    67     {
       
    68     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::~CSensrvTimer()" ) ) );
       
    69     
       
    70     Cancel();
       
    71     
       
    72     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::~CSensrvTimer - return" ) ) );
       
    73     }
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // Start the timer to complete after the specified number of microseconds.
       
    77 // If the duration is zero, then timer is set to predefined maximum value.
       
    78 // -----------------------------------------------------------------------------
       
    79 //
       
    80 void CSensrvTimer::Set(const TTimeIntervalMicroSeconds32& aInterval)
       
    81     {
       
    82     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::Set(%d)" ), aInterval.Int() ) );
       
    83 
       
    84     if (CActiveScheduler::Current())
       
    85         {
       
    86         if (!IsAdded())
       
    87             {
       
    88             CActiveScheduler::Add(this);
       
    89             }
       
    90         
       
    91         // If the timer is already running, cancel it... 
       
    92         if (IsActive())
       
    93             {
       
    94             Cancel();
       
    95             }
       
    96             
       
    97         // ...and set the new timer. If timer has specified maximum time, enforce that.
       
    98         if ( iMaximumTime.Int() != 0 && (0 == aInterval.Int() || aInterval > iMaximumTime) ) 
       
    99             {
       
   100             // Maximum time has been specified, and interval parameter is such that 
       
   101             // it should be enforced
       
   102             After(iMaximumTime);
       
   103             
       
   104             COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::Set - Using Maximum time %d" ), iMaximumTime.Int() ) );
       
   105             }
       
   106         else if ( iMaximumTime.Int() == 0 && aInterval.Int() == 0 )
       
   107             {
       
   108             // No maximum time specified and interval calls for infinite duration.
       
   109             // --> Do not set the timer at all.
       
   110             }
       
   111         else
       
   112             {    
       
   113             // Otherwise just set the time to specified interval.
       
   114             After(aInterval);
       
   115             }
       
   116         }
       
   117     else
       
   118         {
       
   119         COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::Set - Scheduler not active, set ignored" ) ) );
       
   120         // If there are loaded plugins when shutting down the server, timer setting does occur
       
   121         }    
       
   122 
       
   123     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::Set - return" ) ) );
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // RunL() function will be run after the specified system time expires,
       
   128 // i.e. time is set by After() method,
       
   129 // -----------------------------------------------------------------------------
       
   130 void CSensrvTimer::RunL()
       
   131     {
       
   132     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::RunL()" )) );
       
   133 
       
   134     iCallback.TimerFired(iTimerId);
       
   135 
       
   136     COMPONENT_TRACE( ( _L( "Sensor Server - CSensrvTimer::RunL - return" ) ) );
       
   137     }
       
   138 
       
   139 //  End of File