locationtriggering/ltserver/ltserverlogic/src/lbtstratergycontainer.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     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 is responsible for loading,upgrading and holding 
       
    15 *				 the stratergy ecom plugin
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <ecom.h>
       
    23 #include <implementationinformation.h>
       
    24 #include <e32property.h>
       
    25 #include "lbtstratergycontainer.h"
       
    26 #include "lbtstatuspskeys.h"
       
    27 #include "lbtstrategybase.h"
       
    28 #include "lbttriggeringsupervisionobserver.h"
       
    29 #include "lbtlogger.h"
       
    30 
       
    31 // ======== LOCAL FUNCTIONS =========
       
    32 // static cleanup function
       
    33 static void RImpleInfoPtrArrayCleanup( TAny* aArray )
       
    34 	{
       
    35 	static_cast<RImplInfoPtrArray*>( aArray )->ResetAndDestroy();
       
    36 	}
       
    37 
       
    38 // ======== MEMBER FUNCTIONS ========
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CLbtStratergyContainer::NewL
       
    42 // Symbian Two - phase constructor
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CLbtStratergyContainer* CLbtStratergyContainer::NewL()
       
    46 	{
       
    47 	FUNC_ENTER("CLbtStratergyContainer::NewL");
       
    48 	CLbtStratergyContainer* self = new ( ELeave ) CLbtStratergyContainer;
       
    49     CleanupStack::PushL( self );
       
    50     self->ConstructL();    
       
    51     CleanupStack::Pop();
       
    52     return self;
       
    53 	}
       
    54 
       
    55 // ---------------------------------------------------------------------------
       
    56 // CLbtStratergyContainer::ConstructL
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 void CLbtStratergyContainer::ConstructL()
       
    60 	{
       
    61 	FUNC_ENTER("CLbtStratergyContainer::ConstructL");
       
    62 	iEComSession = &(REComSession::OpenL());
       
    63 	iStratergy = NULL;
       
    64 	
       
    65 	User::LeaveIfError( iProperty.Attach(KPSUidLbtStatusInformation, 
       
    66                                          KLbtLocationTriggeringSupervisionStatus,
       
    67                                          EOwnerThread) );
       
    68   }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CLbtStratergyContainer::~CLbtStratergyContainer
       
    72 // ---------------------------------------------------------------------------
       
    73 //
       
    74 CLbtStratergyContainer::~CLbtStratergyContainer()
       
    75 	{
       
    76 	FUNC_ENTER("CLbtStratergyContainer::~CLbtStratergyContainer");
       
    77 	delete iStratergy;
       
    78 	Cancel();
       
    79 	if(iEComSession)
       
    80 		{
       
    81 		iEComSession->Close();
       
    82 		}
       
    83 	
       
    84     // This has to be called to free resources by
       
    85     // ECom Framework. Failing this call memory is leaked
       
    86 	REComSession::FinalClose();
       
    87 	iProperty.Close();
       
    88 	}
       
    89 	
       
    90 // ---------------------------------------------------------------------------
       
    91 // CLbtStratergyContainer::CLbtStratergyContainer
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 CLbtStratergyContainer::CLbtStratergyContainer()
       
    95     : CActive(EPriorityStandard)
       
    96 	{
       
    97 	FUNC_ENTER("CLbtStratergyContainer::CLbtStratergyContainer");
       
    98 	CActiveScheduler::Add(this);
       
    99 	}
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CLbtStratergyContainer::LoadStratergyL
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 void CLbtStratergyContainer::LoadStratergyL(MLbtTriggeringSupervisionObserver* aPtr)
       
   106 	{
       
   107 	FUNC_ENTER("CLbtStratergyContainer::LoadStratergyL");
       
   108 	RImplInfoPtrArray implArray;
       
   109 	REComSession::ListImplementationsL(KLocAcquisitionStrategyInterfaceUid, implArray);	
       
   110 	if(implArray.Count() != 1)
       
   111 		{
       
   112 		implArray.ResetAndDestroy();
       
   113 		// Leave if there are more than one or no 
       
   114 		// implementation of stratergy
       
   115 		User::Leave(KErrNotFound);
       
   116 		}
       
   117 	TCleanupItem arrayCleanup( RImpleInfoPtrArrayCleanup, &implArray );
       
   118 	CleanupStack::PushL(arrayCleanup);
       
   119 	CImplementationInformation* info = implArray[0];
       
   120 	iStratergy = CLbtStrategyBase::NewL(aPtr);
       
   121 	iVersion = info->Version();
       
   122 	CleanupStack::PopAndDestroy(); // implArray
       
   123 	
       
   124 	iProperty.Set(KPSUidLbtStatusInformation, 
       
   125                   KLbtLocationTriggeringSupervisionStatus, 
       
   126                   ELbtLocationTriggeringSupervisionSuccessful);
       
   127                                      
       
   128   // request ecom framework for ecom change notification
       
   129 	iEComSession->NotifyOnChange(iStatus);	
       
   130 	SetActive();
       
   131 	}
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // CLbtStratergyContainer::Stratergy
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 CLbtStrategyBase* CLbtStratergyContainer::Stratergy()
       
   138 	{
       
   139 	FUNC_ENTER("CLbtStratergyContainer::Stratergy");
       
   140 	return iStratergy;
       
   141 	}
       
   142 
       
   143 // ---------------------------------------------------------------------------
       
   144 // CLbtStratergyContainer::RunL
       
   145 // ---------------------------------------------------------------------------
       
   146 //
       
   147 void CLbtStratergyContainer::RunL()
       
   148 	{
       
   149 	FUNC_ENTER("CLbtStratergyContainer::RunL");
       
   150 	// request ecom framework for notification
       
   151 	iEComSession->NotifyOnChange(iStatus);
       
   152 	SetActive();
       
   153 	
       
   154 	RImplInfoPtrArray implArray;
       
   155 	REComSession::ListImplementationsL(KLocAcquisitionStrategyInterfaceUid, implArray);
       
   156 	CleanupClosePushL(implArray);
       
   157 
       
   158 	CImplementationInformation* info = implArray[0];
       
   159 	
       
   160 	// If stratergy is already loaded, and if its
       
   161 	// dll has changed then reload it
       
   162 	if(info->Version() != iVersion && iStratergy )
       
   163 	    {
       
   164 	    // this will unload stratergy
       
   165 	    delete iStratergy;
       
   166 	    iStratergy = NULL;
       
   167 	    // Load the dll again
       
   168 	    iStratergy = CLbtStrategyBase::NewL(this);
       
   169 	    iVersion = info->Version();
       
   170         }
       
   171     CleanupStack::PopAndDestroy(); // implArray
       
   172 	}
       
   173 
       
   174 // ---------------------------------------------------------------------------
       
   175 // CLbtStratergyContainer::RunError
       
   176 // ---------------------------------------------------------------------------
       
   177 //
       
   178 TInt CLbtStratergyContainer::RunError(TInt /*aError*/)
       
   179 	{
       
   180 	FUNC_ENTER("CLbtStratergyContainer::RunError");
       
   181 	return KErrNone;
       
   182 	}
       
   183 
       
   184 // ---------------------------------------------------------------------------
       
   185 // CLbtStratergyContainer::DoCancel
       
   186 // ---------------------------------------------------------------------------
       
   187 //
       
   188 void CLbtStratergyContainer::DoCancel()
       
   189 	{
       
   190 	FUNC_ENTER("CLbtStratergyContainer::DoCancel");
       
   191 	if(iEComSession)
       
   192 		{
       
   193 		// cancel request for ecom notification
       
   194 		// Note that although this takes a iStatus parameter, this is a
       
   195 		// synchronous call.
       
   196 		iEComSession->CancelNotifyOnChange(iStatus);
       
   197 		}
       
   198 	}
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // CLbtStratergyContainer::UnloadStratergy
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void CLbtStratergyContainer::UnloadStratergy()
       
   205     {
       
   206     FUNC_ENTER("CLbtStratergyContainer::UnloadStratergy");
       
   207     // Deleting the interface will unload 
       
   208     // Stratergy
       
   209     delete iStratergy;
       
   210     iStratergy = NULL;
       
   211     
       
   212     iProperty.Set(KPSUidLbtStatusInformation, 
       
   213                   KLbtLocationTriggeringSupervisionStatus, 
       
   214                   ELbtLocationTriggeringSupervisionNotActive);
       
   215                                      
       
   216     // Cancel ECom upgrade notification
       
   217     Cancel();
       
   218     }
       
   219 
       
   220 // end of file