locationmanager/server/src/clocationgeotagtimerao.cpp
branchRCL_3
changeset 19 b73252188534
equal deleted inserted replaced
18:63c982fb92f2 19:b73252188534
       
     1 /*
       
     2 * Copyright (c) 2009-2010 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:  Implements geotagging 3AM timer
       
    15 *
       
    16 */
       
    17 
       
    18 #include "clocationgeotagtimerao.h"
       
    19 #include <aknappui.h>
       
    20 #include <aknnotewrappers.h>
       
    21 #include <avkon.hrh>
       
    22 #include "locationmanagerdebug.h"
       
    23 
       
    24 
       
    25 
       
    26 //Time at which the geotagging should be triggered( 3.00 AM )
       
    27 const TInt GEOTAGGING_TIME_IN_HOURS = 3;
       
    28 //Hour specified in minutes
       
    29 const TInt HOUR_VALUE_IN_MINUTES = 60;
       
    30 //Hour specified in seconds
       
    31 const TInt HOUR_VALUE_IN_SECONDS = 3600;
       
    32 
       
    33 // --------------------------------------------------------------------------
       
    34 // CLocationGeoTagTimerAO::CLocationGeoTagTimerAO
       
    35 // --------------------------------------------------------------------------
       
    36 //
       
    37 CLocationGeoTagTimerAO::CLocationGeoTagTimerAO(CMdESession& aMdeSession,
       
    38         MGeoTaggerObserver& aObserver):
       
    39             CTimer(EPriorityStandard ),
       
    40             iGeoTagger(NULL),
       
    41             iMdeSession(aMdeSession),
       
    42             iObserver(aObserver)
       
    43 {
       
    44 
       
    45 }
       
    46 
       
    47 // --------------------------------------------------------------------------
       
    48 // CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO
       
    49 // --------------------------------------------------------------------------
       
    50 //
       
    51 CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO()
       
    52     {
       
    53     LOG ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), begin");
       
    54     if(iGeoTagger)
       
    55         {
       
    56         delete iGeoTagger;
       
    57         iGeoTagger = NULL;
       
    58         }
       
    59     LOG ("CLocationGeoTagTimerAO::~CLocationGeoTagTimerAO(), end");
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CLocationGeoTagTimerAO::NewL
       
    64 // --------------------------------------------------------------------------
       
    65 //
       
    66 CLocationGeoTagTimerAO* CLocationGeoTagTimerAO::NewL(CMdESession& aMdeSession,
       
    67                                 MGeoTaggerObserver& aObserver)
       
    68     {
       
    69     CLocationGeoTagTimerAO* self = 
       
    70             new( ELeave ) CLocationGeoTagTimerAO(aMdeSession, aObserver);
       
    71        CleanupStack::PushL( self );
       
    72        self->ConstructL();
       
    73        CleanupStack::Pop(); //self
       
    74        
       
    75        return self;
       
    76     }
       
    77 
       
    78 
       
    79 // --------------------------------------------------------------------------
       
    80 // CLocationGeoTagTimerAO::ConstructL
       
    81 // --------------------------------------------------------------------------
       
    82 //
       
    83 void CLocationGeoTagTimerAO::ConstructL()
       
    84     {
       
    85     LOG ("CLocationGeoTagTimerAO::ConstructL(), begin");
       
    86 	CActiveScheduler::Add(this);
       
    87     CTimer::ConstructL();
       
    88     LOG ("CLocationGeoTagTimerAO::ConstructL(), end");
       
    89     }
       
    90 
       
    91 // --------------------------------------------------------------------------
       
    92 // CLocationGeoTagTimerAO::StartTimer
       
    93 // --------------------------------------------------------------------------
       
    94 //
       
    95 void CLocationGeoTagTimerAO::StartTimer()
       
    96     {
       
    97     LOG ("CLocationGeoTagTimerAO::StartTimer(), begin");
       
    98     if(!IsActive())
       
    99         {
       
   100         TTime hometime;
       
   101         hometime.HomeTime();
       
   102         
       
   103         //Get the current time in Hour,Minute, Second
       
   104         TDateTime  currentDateTime = hometime.DateTime();
       
   105         TInt currentHr = currentDateTime.Hour(); 
       
   106         TInt currentMin = currentDateTime.Minute();
       
   107         TInt currentSec = currentDateTime.Second();
       
   108         
       
   109         //3 AM in seconds
       
   110         TInt targetTimeInSeconds = GEOTAGGING_TIME_IN_HOURS * HOUR_VALUE_IN_SECONDS;
       
   111         TInt timeDifference = 0;
       
   112         
       
   113         //Find the time difference in seconds between current time to 3.00 AM 
       
   114         //Either on same day or next day.
       
   115         if ( currentHr < GEOTAGGING_TIME_IN_HOURS )
       
   116         {
       
   117            timeDifference = targetTimeInSeconds - 
       
   118                     ( ( currentHr * HOUR_VALUE_IN_SECONDS  ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec );
       
   119         }
       
   120         else
       
   121         {
       
   122            timeDifference = ( 24 * HOUR_VALUE_IN_SECONDS - ( 
       
   123                     ( currentHr * HOUR_VALUE_IN_SECONDS ) + ( currentMin * HOUR_VALUE_IN_MINUTES ) + currentSec ) )  +
       
   124                     targetTimeInSeconds ;
       
   125         }
       
   126         
       
   127         //Add the time difference to current time to set the target time ( 3.00 AM )
       
   128         TTimeIntervalSeconds interval( timeDifference );
       
   129         TTime timeToSet;
       
   130         timeToSet.HomeTime();
       
   131         timeToSet+= interval;
       
   132         
       
   133         
       
   134          At( timeToSet );
       
   135         }
       
   136      LOG ("CLocationGeoTagTimerAO::StartTimer(), end");
       
   137      }
       
   138 
       
   139 
       
   140 // --------------------------------------------------------------------------
       
   141 // CLocationGeoTagTimerAO::RunL
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CLocationGeoTagTimerAO::RunL( )
       
   145     {
       
   146     LOG ("CLocationGeoTagTimerAO::RunL(), begin");
       
   147     TInt status = iStatus.Int();
       
   148     LOG1 ("Timedout error - %d", status);
       
   149    
       
   150     switch( status )
       
   151         {
       
   152         case KErrNone:
       
   153             {
       
   154             //Trigger the reverse geocoding and start the timer again
       
   155             //Create the instance of geotagger class
       
   156             if(iGeoTagger != NULL)
       
   157                 {
       
   158                 delete iGeoTagger;
       
   159                 iGeoTagger = NULL;
       
   160                 }
       
   161             iGeoTagger = CGeoTagger::NewL( this, NULL );
       
   162             iGeoTagger->CreateGeoTagsL();
       
   163             LOG ("Started 3:00 AM geotagging.");
       
   164             break;
       
   165             }
       
   166         default:
       
   167             StartTimer();
       
   168             break;      
       
   169        }
       
   170     LOG ("CLocationGeoTagTimerAO::RunL(), end");
       
   171     }
       
   172     
       
   173 // --------------------------------------------------------------------------
       
   174 // CLocationGeoTagTimerAO::GeoTaggingCompleted
       
   175 // --------------------------------------------------------------------------
       
   176 //
       
   177 void CLocationGeoTagTimerAO::GeoTaggingCompleted(  const TInt aError )
       
   178     {    
       
   179     LOG ("CLocationGeoTagTimerAO::GeoTaggingCompleted(), begin");
       
   180     StartTimer();
       
   181     iObserver.GeoTaggingCompleted(aError);
       
   182     LOG ("CLocationGeoTagTimerAO::GeoTaggingCompleted(), end");
       
   183     }
       
   184 
       
   185 // --------------------------------------------------------------------------
       
   186 // CLocationGeoTagTimerAO::PendingGeoTagReqComplete
       
   187 // --------------------------------------------------------------------------
       
   188 //
       
   189 void CLocationGeoTagTimerAO::PendingGeoTagReqComplete(  const TInt aError )
       
   190     {    
       
   191     LOG ("CLocationGeoTagTimerAO::PendingGeoTagReqComplete()");
       
   192     // do nothing.
       
   193     iObserver.PendingGeoTagReqComplete(aError);
       
   194     }
       
   195 
       
   196 // ----------------------------------------------------------------------------
       
   197 // CLocationGeoTagTimerAO::GetCurrentRegisterNw()
       
   198 // ---------------------------------------------------------------------------- 
       
   199 RMobilePhone::TMobilePhoneNetworkInfoV2& CLocationGeoTagTimerAO::GetCurrentRegisterNw()
       
   200     {
       
   201     LOG( "CLocationGeoTagTimerAO::GetCurrentRegisterNw ,begin" );
       
   202     return iObserver.GetCurrentRegisterNw();
       
   203     }
       
   204 
       
   205 
       
   206 // ----------------------------------------------------------------------------
       
   207 // CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork()
       
   208 // ---------------------------------------------------------------------------- 
       
   209 TBool CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork()
       
   210     {
       
   211     LOG( "CLocationGeoTagTimerAO::IsRegisteredAtHomeNetwork" );
       
   212     return iObserver.IsRegisteredAtHomeNetwork();
       
   213     }
       
   214 
       
   215 // ----------------------------------------------------------------------------
       
   216 // CLocationGeoTagTimerAO::GetHomeNetworkInfo()
       
   217 // ----------------------------------------------------------------------------
       
   218 const RMobilePhone::TMobilePhoneNetworkInfoV1& 
       
   219         CLocationGeoTagTimerAO::GetHomeNetworkInfo(TBool& aHomeNwInfoAvailableFlag)
       
   220     {
       
   221     LOG( "CLocationGeoTagTimerAO::GetHomeNetworkInfo" );
       
   222     return iObserver.GetHomeNetworkInfo(aHomeNwInfoAvailableFlag);
       
   223     }
       
   224 
       
   225 // End of file
       
   226