locationmanager/server/src/clocationmanagerserver.cpp
changeset 45 a93990e5815e
parent 36 aa5a574040a4
equal deleted inserted replaced
36:aa5a574040a4 45:a93990e5815e
    31 #include "mdesession.h"
    31 #include "mdesession.h"
    32 #include "mdenamespacedef.h"
    32 #include "mdenamespacedef.h"
    33 #include "mdeobjectdef.h"
    33 #include "mdeobjectdef.h"
    34 #include "mdepropertydef.h"
    34 #include "mdepropertydef.h"
    35 #include "mdcserializationbuffer.h"
    35 #include "mdcserializationbuffer.h"
    36 #ifdef LOC_REVERSEGEOCODE
       
    37 #include "clocationgeotagtimerao.h"
    36 #include "clocationgeotagtimerao.h"
    38 #endif //LOC_REVERSEGEOCODE
       
    39 #include "nwregistrationstatushandler.h"
    37 #include "nwregistrationstatushandler.h"
    40 
    38 
    41 using namespace MdeConstants;
    39 using namespace MdeConstants;
    42 using namespace CommsDat;
    40 using namespace CommsDat;
    43 
    41 
    76     TInt ret( KErrNoMemory );
    74     TInt ret( KErrNoMemory );
    77     if( cleanup )
    75     if( cleanup )
    78         {
    76         {
    79         TRAP( ret, RunServerL() );
    77         TRAP( ret, RunServerL() );
    80         delete cleanup;
    78         delete cleanup;
       
    79         cleanup = NULL;
    81         }
    80         }
    82     return ret;
    81     return ret;
    83     }
    82     }
    84 
    83 
    85 // --------------------------------------------------------------------------
    84 // --------------------------------------------------------------------------
    99 // CLocationManagerServer::CLocationManagerServer()
    98 // CLocationManagerServer::CLocationManagerServer()
   100 // C++ constructor.
    99 // C++ constructor.
   101 // --------------------------------------------------------------------------
   100 // --------------------------------------------------------------------------
   102 //
   101 //
   103 CLocationManagerServer::CLocationManagerServer() 
   102 CLocationManagerServer::CLocationManagerServer() 
   104     : CPolicyServer( CActive::EPriorityStandard, 
   103     : CPolicyServer( KLocManagerSessionPriority, 
   105                      KLocationManagerPolicy, 
   104                      KLocationManagerPolicy, 
   106                      ESharableSessions ),
   105                      ESharableSessions ),
   107                      iASW(NULL),
   106                      iASW(NULL),
   108                      iTimer( NULL ),
   107                      iTimer( NULL ),
   109 			         iSessionReady( EFalse ),
   108 			         iSessionReady( EFalse ),
   114                      iRemoveLocation( EFalse ),
   113                      iRemoveLocation( EFalse ),
   115                      iWaitForPositioningStopTimeout ( EFalse ),
   114                      iWaitForPositioningStopTimeout ( EFalse ),
   116                      iTelServerIsOpen(EFalse),
   115                      iTelServerIsOpen(EFalse),
   117                      iPhoneIsOpen(EFalse),
   116                      iPhoneIsOpen(EFalse),
   118                      iNwRegistrationStatusHandler(NULL),
   117                      iNwRegistrationStatusHandler(NULL),
   119                      iHomeNwInfoAvailableFlag(EFalse)
   118                      iHomeNwInfoAvailableFlag(EFalse),
       
   119                      iGeoTagTimer(NULL)
   120 #ifdef LOC_REVERSEGEOCODE
   120 #ifdef LOC_REVERSEGEOCODE
   121                      ,iGeoTagTimer(NULL)
       
   122 					 ,iGeoTaggingPendingReqObj(NULL)
   121 					 ,iGeoTaggingPendingReqObj(NULL)
   123 					 ,iEcomSession(NULL)
   122 					 ,iEcomSession(NULL)
   124 #endif //LOC_REVERSEGEOCODE
   123 #endif //LOC_REVERSEGEOCODE
   125     {
   124     {
   126     }
   125     }
   133 void CLocationManagerServer::ConstructL()
   132 void CLocationManagerServer::ConstructL()
   134     {
   133     {
   135     LOG ("CLocationManagerServer::ConstructL() begin");
   134     LOG ("CLocationManagerServer::ConstructL() begin");
   136     
   135     
   137     StartL( KLocServerName );
   136     StartL( KLocServerName );
   138     
   137 
       
   138     // initialize etel
       
   139     InitialisePhoneL();
       
   140     
       
   141 #ifdef LOC_REVERSEGEOCODE
       
   142     iEcomSession = &(REComSession::OpenL());
       
   143 #endif //LOC_REVERSEGEOCODE
       
   144 
       
   145     iASW = new (ELeave) CActiveSchedulerWait();
       
   146     
       
   147     iNwRegistrationStatusHandler = CNwRegistrationStatusHandler::NewL(iPhone);
       
   148     
       
   149     iLocationRecord = CLocationRecord::NewL(*this, iPhone);
       
   150     iTrackLog = CTrackLog::NewL();
       
   151     iMdeSession = CMdESession::NewL( *this );   
       
   152 
       
   153     iLocationRecord->SetObserver( this );
       
   154     
       
   155     iLocationRecord->SetAddObserver( iTrackLog );
       
   156     
       
   157     iTrackLog->AddGpxObserver( this );
       
   158     
       
   159     CRepository* repository = CRepository::NewLC( KRepositoryUid );
       
   160     TInt err = repository->Get( KLocationTrailShutdownTimer, iLocManStopDelay );
       
   161     
       
   162     LOG1("iLocManStopDelay:%d", iLocManStopDelay);
       
   163     
       
   164     if ( err != KErrNone )
       
   165         {
       
   166         LOG1("iLocManStopDelay err:%d", err);
       
   167         iLocManStopDelay = KLocationTrailShutdownDelay;
       
   168         }
       
   169 
       
   170     err = repository->Get( KLocationTrailRemapShutdownTimer, iLocManStopRemapDelay );
       
   171     CleanupStack::PopAndDestroy( repository );
       
   172     
       
   173     LOG1("iLocManStopRemapDelay:%d", iLocManStopRemapDelay);
       
   174     
       
   175     if ( err != KErrNone )
       
   176         {
       
   177         LOG1("iLocManStopRemapDelay err:%d", err);
       
   178         iLocManStopRemapDelay = KLocationTrailRemapShutdownDelay;
       
   179         }
       
   180 
       
   181     if( !iSessionReady )
       
   182         {
       
   183         iASW->Start();      
       
   184         }
       
   185 
       
   186     delete iASW;
       
   187     iASW = NULL;   
       
   188 
       
   189     if( iSessionReady )
       
   190         {
       
   191         LOG("Session is ready to give service");
       
   192         //Create the instance of the geotagging timer object
       
   193         // Create timer, if n/w or reverse geo code based feature flag is enabled
       
   194 #if defined(LOC_REVERSEGEOCODE) || defined(LOC_GEOTAGGING_CELLID)
       
   195         iGeoTagTimer = CLocationGeoTagTimerAO::NewL(*iMdeSession, *this);
       
   196         //Schedule a task for geotagging every day at 3.00 AM
       
   197         iGeoTagTimer->StartTimer();
       
   198 #endif        
       
   199         }
       
   200     else
       
   201         {
       
   202         LOG("Unable to open MDE session. Closing..");
       
   203         User::Leave( KErrCouldNotConnect );
       
   204         }
       
   205         
   139     RProcess process;
   206     RProcess process;
   140     process.SetPriority( EPriorityBackground );
   207     process.SetPriority( EPriorityBackground );
   141     process.Close();
   208     process.Close();
   142 
   209     
   143     // initialize etel
   210     LOG ("CLocationManagerServer::ConstructL() end");
   144     InitialisePhoneL();
   211     }
   145     
   212 
       
   213 // --------------------------------------------------------------------------
       
   214 // CLocationManagerServer::~CLocationManagerServer()
       
   215 // C++ destructor.
       
   216 // --------------------------------------------------------------------------
       
   217 //
       
   218 CLocationManagerServer::~CLocationManagerServer()
       
   219     {
       
   220 	LOG("CLocationManagerServer::~CLocationManagerServer ,begin");
       
   221 #if defined(LOC_REVERSEGEOCODE) || defined(LOC_GEOTAGGING_CELLID)
       
   222     delete iGeoTagTimer;
       
   223     iGeoTagTimer = NULL;
       
   224 #endif    
   146 #ifdef LOC_REVERSEGEOCODE
   225 #ifdef LOC_REVERSEGEOCODE
   147     iEcomSession = &(REComSession::OpenL());
   226     delete iGeoTaggingPendingReqObj;
       
   227     iGeoTaggingPendingReqObj = NULL;
   148 #endif //LOC_REVERSEGEOCODE
   228 #endif //LOC_REVERSEGEOCODE
   149 
   229     
   150     iASW = new (ELeave) CActiveSchedulerWait();
   230     delete iLocationRecord;    
   151     
   231     iLocationRecord = NULL;
   152     iNwRegistrationStatusHandler = CNwRegistrationStatusHandler::NewL(iPhone);
   232     delete iTrackLog;    
   153     
   233     iTrackLog = NULL;
   154     iMdeSession = CMdESession::NewL( *this );
   234     delete iTimer;
   155     iLocationRecord = CLocationRecord::NewL(*this, iPhone);
   235     iTimer = NULL;
   156     iTrackLog = CTrackLog::NewL();
   236     delete iRelationQuery;
   157     
   237     iRelationQuery = NULL;
   158     iASW->Start();
       
   159     delete iASW;
   238     delete iASW;
   160     iASW = NULL;
   239     iASW = NULL;
   161     if(iSessionReady)
       
   162         {
       
   163         LOG("Session is ready to give service");
       
   164         
       
   165         iLocationRecord->SetObserver( this );
       
   166         
       
   167         iLocationRecord->SetAddObserver( iTrackLog );
       
   168         
       
   169         iTrackLog->AddGpxObserver( this );
       
   170         
       
   171         CRepository* repository = CRepository::NewLC( KRepositoryUid );
       
   172     	TInt err = repository->Get( KLocationTrailShutdownTimer, iLocManStopDelay );
       
   173     	
       
   174         LOG1("CLocationManagerServer::ConstructL, iLocManStopDelay:%d", iLocManStopDelay);
       
   175         
       
   176         if ( err != KErrNone )
       
   177         	{
       
   178             LOG1("CLocationManagerServer::ConstructL, iLocManStopDelay err:%d", err);
       
   179             iLocManStopDelay = KLocationTrailShutdownDelay;
       
   180         	}
       
   181 
       
   182         err = repository->Get( KLocationTrailRemapShutdownTimer, iLocManStopRemapDelay );
       
   183         CleanupStack::PopAndDestroy( repository );
       
   184         
       
   185         LOG1("CLocationManagerServer::ConstructL, iLocManStopRemapDelay:%d", iLocManStopRemapDelay);
       
   186         
       
   187         if ( err != KErrNone )
       
   188             {
       
   189             LOG1("CLocationManagerServer::ConstructL, iLocManStopRemapDelay err:%d", err);
       
   190             iLocManStopRemapDelay = KLocationTrailRemapShutdownDelay;
       
   191             }
       
   192         
       
   193 #ifdef LOC_REVERSEGEOCODE
       
   194         //Create the instance of the geotagging timer object
       
   195         iGeoTagTimer = CLocationGeoTagTimerAO::NewL(*iMdeSession, *this);
       
   196         //Schedule a task for geotagging every day at 3.00 AM
       
   197         iGeoTagTimer->StartTimer();
       
   198 #endif //LOC_REVERSEGEOCODE
       
   199         }
       
   200     else
       
   201         {
       
   202         LOG("Unable to open MDE session. Closing..");
       
   203         User::Leave(KErrCouldNotConnect);
       
   204         }
       
   205     LOG ("CLocationManagerServer::ConstructL() end");
       
   206     }
       
   207 
       
   208 // --------------------------------------------------------------------------
       
   209 // CLocationManagerServer::~CLocationManagerServer()
       
   210 // C++ destructor.
       
   211 // --------------------------------------------------------------------------
       
   212 //
       
   213 CLocationManagerServer::~CLocationManagerServer()
       
   214     {
       
   215 	LOG("CLocationManagerServer::~CLocationManagerServer ,begin");
       
   216 
       
   217 #ifdef LOC_REVERSEGEOCODE
       
   218     delete iGeoTagTimer;
       
   219     delete iGeoTaggingPendingReqObj;
       
   220 #endif //LOC_REVERSEGEOCODE
       
   221     
       
   222     delete iLocationRecord;    
       
   223     delete iTrackLog;    
       
   224     delete iTimer;
       
   225     delete iASW;
       
   226     delete iMdeSession;
   240     delete iMdeSession;
       
   241     iMdeSession = NULL;
   227     delete iNwRegistrationStatusHandler;
   242     delete iNwRegistrationStatusHandler;
       
   243     iNwRegistrationStatusHandler = NULL;
   228     iTargetObjectIds.Close();
   244     iTargetObjectIds.Close();
   229     CancelRequests(iNotifReqs);
   245     CancelRequests(iNotifReqs);
   230     iNotifReqs.Close();
   246     iNotifReqs.Close();
   231     CancelRequests(iLocationReqs);
   247     CancelRequests(iLocationReqs);
   232     iLocationReqs.Close();
   248     iLocationReqs.Close();
   472 // CLocationManagerServer::RemoveSession
   488 // CLocationManagerServer::RemoveSession
   473 // --------------------------------------------------------------------------
   489 // --------------------------------------------------------------------------
   474 //    
   490 //    
   475 void CLocationManagerServer::RemoveSession()
   491 void CLocationManagerServer::RemoveSession()
   476     {
   492     {
       
   493     LOG1( "CLocationManagerServer::RemoveSession. Session count - %d", iSessionCount);
   477     iSessionCount--;
   494     iSessionCount--;
   478     if ( !iSessionCount 
   495     StopServer();
   479         && iLocationRecord 
       
   480         && !iLocationRecord->TaggingInProgress())
       
   481         {
       
   482         // Nothing in progress. shutdown the server
       
   483         CActiveScheduler::Stop();
       
   484         }
       
   485     }    
   496     }    
   486 
   497 
   487 // --------------------------------------------------------------------------
   498 // --------------------------------------------------------------------------
   488 // CLocationManagerServer::StartGPSPositioningL
   499 // CLocationManagerServer::StartGPSPositioningL
   489 // --------------------------------------------------------------------------
   500 // --------------------------------------------------------------------------
  1103 						{
  1114 						{
  1104 						aError = KErrNotFound;
  1115 						aError = KErrNotFound;
  1105 						}
  1116 						}
  1106 					iCopyReqs[i].iMessage.Complete( aError );
  1117 					iCopyReqs[i].iMessage.Complete( aError );
  1107 					delete iCopyReqs[i].iQuery;
  1118 					delete iCopyReqs[i].iQuery;
       
  1119 					iCopyReqs[i].iQuery = NULL;
  1108 					iCopyReqs.Remove( i );
  1120 					iCopyReqs.Remove( i );
  1109 					break;
  1121 					break;
  1110 					}
  1122 					}
  1111 				}
  1123 				}
  1112 			}
  1124 			}
  1149     	{
  1161     	{
  1150     	if ( iCopyReqs[i].iQuery == &aQuery )
  1162     	if ( iCopyReqs[i].iQuery == &aQuery )
  1151     		{
  1163     		{
  1152     		iCopyReqs[i].iMessage.Complete( KErrNone );
  1164     		iCopyReqs[i].iMessage.Complete( KErrNone );
  1153     		delete iCopyReqs[i].iQuery;
  1165     		delete iCopyReqs[i].iQuery;
       
  1166     		iCopyReqs[i].iQuery = NULL;
  1154     		iCopyReqs.Remove( i );
  1167     		iCopyReqs.Remove( i );
  1155     		break;
  1168     		break;
  1156     		}
  1169     		}
  1157     	}
  1170     	}
  1158 	}
  1171 	}
  1655 		LOG("Completing the request");
  1668 		LOG("Completing the request");
  1656 		iGeoTaggingMessage.Complete(aError);
  1669 		iGeoTaggingMessage.Complete(aError);
  1657 		iGeoTaggingMessage = RMessage2 ();
  1670 		iGeoTaggingMessage = RMessage2 ();
  1658     	}
  1671     	}
  1659 #endif //LOC_REVERSEGEOCODE
  1672 #endif //LOC_REVERSEGEOCODE
       
  1673     StopServer();
       
  1674 	LOG("CLocationManagerServer::GeoTaggingCompleted ,end");
       
  1675     }
       
  1676 
       
  1677 
       
  1678 // --------------------------------------------------------------------------
       
  1679 // CLocationManagerServer::StopServer
       
  1680 // --------------------------------------------------------------------------
       
  1681 //
       
  1682 
       
  1683 void CLocationManagerServer::StopServer()
       
  1684     {    
       
  1685     LOG("CLocationManagerServer::StopServer ,begin");
  1660     // once geo tagging completed, check whether, we can terminate the server
  1686     // once geo tagging completed, check whether, we can terminate the server
       
  1687     // dont't stop this process if
       
  1688     // 1. when client are connected.
       
  1689     // 2. 3AM timer is going on.
       
  1690     // 3. Tagging is in progress.
  1661     if ( !iSessionCount 
  1691     if ( !iSessionCount 
       
  1692 #if defined(LOC_REVERSEGEOCODE) || defined(LOC_GEOTAGGING_CELLID)
       
  1693         && iGeoTagTimer == NULL
       
  1694 #endif        
  1662         && iLocationRecord 
  1695         && iLocationRecord 
  1663         && !iLocationRecord->TaggingInProgress())
  1696         && !iLocationRecord->TaggingInProgress())
  1664         {
  1697         {
  1665         // Nothing in progress. shutdown the server
  1698         // Nothing in progress. shutdown the server
       
  1699         LOG("Stop the schedular");
  1666         CActiveScheduler::Stop();
  1700         CActiveScheduler::Stop();
  1667         }
  1701         }
  1668 	LOG("CLocationManagerServer::GeoTaggingCompleted ,end");
  1702 	LOG("CLocationManagerServer::StopServer ,end");
  1669     }
  1703     }
  1670 
       
  1671 
  1704 
  1672 // --------------------------------------------------------------------------
  1705 // --------------------------------------------------------------------------
  1673 // CLocationManagerServer::PendingGeoTagReqComplete
  1706 // CLocationManagerServer::PendingGeoTagReqComplete
  1674 // --------------------------------------------------------------------------
  1707 // --------------------------------------------------------------------------
  1675 //
  1708 //
  1786         iGeoTaggingMessage = RMessage2 ();
  1819         iGeoTaggingMessage = RMessage2 ();
  1787         iLocationRecord->CancelGeoTagging();
  1820         iLocationRecord->CancelGeoTagging();
  1788         }
  1821         }
  1789     aMessage.Complete(KErrNone);
  1822     aMessage.Complete(KErrNone);
  1790 #else
  1823 #else
  1791         aMessage.Complete(KErrNotSupported);
  1824     aMessage.Complete(KErrNotSupported);
  1792 #endif //LOC_REVERSEGEOCODE
  1825 #endif //LOC_REVERSEGEOCODE
  1793     }
  1826     }
  1794 
  1827 
  1795 
  1828 
  1796 // --------------------------------------------------------------------------
  1829 // --------------------------------------------------------------------------