Example Application Guide

 

geoprofileshandler.cpp

00001 /*
00002 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
00003 * All rights reserved.
00004 * This component and the accompanying materials are made available
00005 * under the terms of the License "Eclipse Public License v1.0"
00006 * which accompanies this distribution, and is available
00007 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
00008 *
00009 * Initial Contributors:
00010 * Nokia Corporation - initial contribution.
00011 *
00012 * Contributors:
00013 *
00014 * Description:  Framework Function definitions for Geo-Profiles.
00015 *
00016 */
00017 
00018 
00019 // System Includes
00020 #include <e32base.h>        // Basic framework functions
00021 #include <lbtcommon.h>
00022 #include <lbtserver.h> 
00023 #include <lbt.h>
00024 #include <lbttriggerinfo.h>
00025 #include <lbtstartuptrigger.h>
00026 #include <s32mem.h>
00027 #include <ProEngFactory.h>
00028 #include <mproengengine.h>
00029 #include <mproengprofilenamearray.h>
00030 #include <flogger.h>
00031 #include <e32svr.h>
00032 #include <f32file.h>
00033 #include <bautils.h>
00034 
00035 // User Includes
00036 #include "geoprofileshandler.h"
00037 
00038 // Constant Definitions
00039 _LIT( KTxtApplication, "EvtHandlerUI" );
00040 
00041 /// Folder where the log resides
00042 _LIT( KGeoProfilesLogFolder, "epos" );
00043 
00044 /// The name of the log file
00045 _LIT( KGeoProfilesLogFileName, "GeoProfilesHandler.txt" );
00046 
00047 /// The format in which the time is formatted in log
00048 _LIT( KGeoProfilesLogTimeFormat, "%02d.%02d:%02d:%06d ");
00049 
00050 /// The length of the string produced by KLocLogTimeFormat
00051 const TInt KGeoProfilesLogTimeFormatLength = 16;
00052 
00053 /// How many characters a log line can contain
00054 const TInt KGeoProfilesLogLineLength = 256;
00055 
00056 // ----------------------------------------------------------------------------
00057 // GLDEF_C       TInt E32Main()
00058 // ----------------------------------------------------------------------------
00059 //
00060 GLDEF_C  TInt E32Main()
00061         {       
00062         // __UHEAP_MARK;
00063         // Cretae a Cleanup stack
00064         CTrapCleanup* cleanup = CTrapCleanup::New();
00065         
00066         // Call the initialization implementation
00067     TRAPD( error, callImplementationL());
00068     
00069         __ASSERT_ALWAYS( !error, User::Panic( KTxtApplication, error ));
00070         
00071         // Destroy the cleanup stack handle
00072         delete cleanup;
00073         // __UHEAP_MARKEND;
00074         return KErrNone;
00075         }
00076 
00077 // ----------------------------------------------------------------------------
00078 // LOCAL_C void callImplementationL()
00079 // ----------------------------------------------------------------------------
00080 //
00081 LOCAL_C void callImplementationL()
00082     {
00083     // Create and Install Active Scheduler
00084         CActiveScheduler* scheduler = new( ELeave ) CActiveScheduler;
00085         User::LeaveIfNull( scheduler );         
00086         CleanupStack::PushL( scheduler );
00087         CActiveScheduler::Install( scheduler );
00088                  
00089         TRAP_IGNORE( HandleEventL());
00090                         
00091         // Delete active scheduler
00092         CleanupStack::PopAndDestroy( scheduler );           
00093     }
00094 
00095 // ----------------------------------------------------------------------------
00096 // void HandleEventL()
00097 // ----------------------------------------------------------------------------
00098 //
00099 void HandleEventL()
00100         {                               
00101         TInt profileId = GetProfileIdofFiredTriggerL();
00102         ActivateProfileL( profileId );  
00103   }
00104 
00105 // ----------------------------------------------------------------------------
00106 // TInt GetProfileIdofFiredTriggerL
00107 // ----------------------------------------------------------------------------
00108 //
00109 TInt GetProfileIdofFiredTriggerL()
00110     {
00111     TInt profileId = KErrNotFound;
00112     
00113         // Open LBT server session
00114         RLbtServer      server;
00115     server.Connect();
00116     CleanupClosePushL( server );
00117     
00118     // Open LBT handle
00119     RLbt lbt;
00120     lbt.Open( server );
00121     CleanupClosePushL( lbt );
00122     
00123     // Obtain the list of fired triggers
00124     RArray < TLbtTriggerFireInfo >  triggerInfoList;    
00125     lbt.GetFiredTriggersL( triggerInfoList );
00126     
00127     if ( triggerInfoList.Count())
00128         {
00129         CLbtTriggerInfo* triggerInfo = lbt.GetTriggerLC( triggerInfoList[0].iTriggerId );
00130         CLbtTriggerEntry* triggerEntry = triggerInfo->TriggerEntry();
00131         CLbtStartupTrigger* startupTrigger = static_cast<CLbtStartupTrigger*>( triggerEntry );
00132         TPtrC cmdLine = startupTrigger->CommandLine();
00133         
00134         // Read only the Profile ID
00135         TLex lexer( cmdLine );
00136         User::LeaveIfError( lexer.Val( profileId ));
00137         
00138         CleanupStack::PopAndDestroy(triggerInfo );
00139         }
00140     triggerInfoList.Reset();
00141     triggerInfoList.Close();
00142     CleanupStack::PopAndDestroy( 2 );    
00143     
00144     return profileId;    
00145     }
00146 
00147 // ----------------------------------------------------------------------------
00148 // void ActivateProfileL
00149 // ----------------------------------------------------------------------------
00150 //
00151 void ActivateProfileL( TInt aProfileId )
00152     {    
00153     // Obtain the list of profiles
00154     MProEngEngine* profileEng = NULL;
00155     profileEng = ProEngFactory::NewEngineL();
00156     TRAP_IGNORE( profileEng->SetActiveProfileL( aProfileId ));    
00157     if ( profileEng )
00158         {
00159         profileEng->Release();
00160         }
00161     }

© Nokia 2009

Back to top