locationmanager/geoconverter/src/cgeoconverter.cpp
branchRCL_3
changeset 19 b73252188534
equal deleted inserted replaced
18:63c982fb92f2 19:b73252188534
       
     1 /*
       
     2 * Copyright (c) 2009 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:  A class for creating country and city tags for media files
       
    15 *
       
    16 */
       
    17 
       
    18 //#include "locationmanagerdebug.h"
       
    19 #include "cgeoconverter.h"
       
    20 #include "locationmanagerdebug.h"
       
    21 
       
    22 
       
    23 
       
    24 // --------------------------------------------------------------------------
       
    25 // CGeoConverter::NewL
       
    26 // --------------------------------------------------------------------------
       
    27 //
       
    28 EXPORT_C CGeoConverter* CGeoConverter::NewL( MGeoConverterObserver& aObserver )
       
    29     {
       
    30     LOG("CGeoConverter::NewL");
       
    31     CGeoConverter* self = new( ELeave ) CGeoConverter( aObserver );
       
    32     CleanupStack::PushL( self );
       
    33     self->ConstructL();
       
    34     CleanupStack::Pop(); // self
       
    35     return self;
       
    36     }
       
    37 
       
    38 // --------------------------------------------------------------------------
       
    39 // CGeoConverter::CGeoConverter()
       
    40 // --------------------------------------------------------------------------
       
    41 //    
       
    42 CGeoConverter::CGeoConverter( MGeoConverterObserver& aObserver )
       
    43     :iObserver( aObserver ) 
       
    44 #ifdef LOC_GEOTAGGING_CELLID    
       
    45     ,iLocConverter(NULL),
       
    46     iLocInfo(NULL),
       
    47     iGsmCellInfo(NULL),
       
    48     iWcdmaCellInfo(NULL)
       
    49 #endif
       
    50     {
       
    51     }
       
    52 
       
    53 // --------------------------------------------------------------------------
       
    54 // CGeoConverter::~CGeoConverter
       
    55 // --------------------------------------------------------------------------
       
    56 //  
       
    57 EXPORT_C CGeoConverter::~CGeoConverter()
       
    58     {
       
    59     LOG("CGeoConverter::~CGeoConverter, begin");
       
    60 #ifdef LOC_GEOTAGGING_CELLID    
       
    61     delete iGsmCellInfo;
       
    62     iGsmCellInfo = NULL;    
       
    63     delete iWcdmaCellInfo;
       
    64     iWcdmaCellInfo = NULL;
       
    65     delete iLocInfo;
       
    66     iLocInfo = NULL;
       
    67     delete iLocConverter;
       
    68     iLocConverter = NULL;
       
    69 #endif    
       
    70     LOG("CGeoConverter::~CGeoConverter, end");
       
    71     }
       
    72 
       
    73 // --------------------------------------------------------------------------
       
    74 // CGeoConverter::OnConversionComplete()
       
    75 // --------------------------------------------------------------------------
       
    76 //  
       
    77 void CGeoConverter::OnConversionComplete( TInt aStatusCode )
       
    78     {
       
    79     LOG("CGeoConverter::OnConversionComplete, begin");
       
    80 #ifdef LOC_GEOTAGGING_CELLID    
       
    81     //16. Retrieve position estimate that is updated by Location Monitor server
       
    82     //after a conversion operation is completed successfully.
       
    83     RLbsAreaInfoBaseArray posInfoList;
       
    84     TLocality position;
       
    85     
       
    86     
       
    87     LOG1("Status Code - %d",aStatusCode);
       
    88     
       
    89     if( KErrNone == aStatusCode )
       
    90         {
       
    91         TRAP_IGNORE(iLocInfo->GetAreaInfoL( posInfoList, CLbsLocationInfo::ELbsPosInfo );)
       
    92         
       
    93         //Get geo-coordinates. 
       
    94         
       
    95         LOG1("PposInfoList Count - %d",posInfoList.Count());
       
    96         if ( posInfoList.Count() )
       
    97             {
       
    98             static_cast<CLbsPositionInfo*>(posInfoList[0])->GetLocality(position);
       
    99             }
       
   100         else
       
   101             {
       
   102             aStatusCode = KErrNotFound;
       
   103             }     
       
   104         }
       
   105     TRAPD(err,iObserver.ConversionCompletedL( aStatusCode, position);)
       
   106     if(err != KErrNone)
       
   107     	{
       
   108 		iObserver.HandleConversionError(err);
       
   109     	}
       
   110     posInfoList.Close();
       
   111 #endif    
       
   112     LOG("CGeoConverter::OnConversionComplete, end");
       
   113     }
       
   114 
       
   115 // --------------------------------------------------------------------------
       
   116 // CGeoConverter::ConstructL()
       
   117 // --------------------------------------------------------------------------
       
   118 //  
       
   119 void CGeoConverter::ConstructL()
       
   120     {
       
   121     LOG("CGeoConverter::ConstructL, begin");
       
   122 #ifdef LOC_GEOTAGGING_CELLID    
       
   123     iLocInfo = CLbsLocationInfo::NewL();
       
   124     TUid pluginUid = TUid::Uid( 0x20027011 );   
       
   125     LOG("CGeoConverter::ConstructL");
       
   126     iLocConverter = CLbsLocationInfoConverter::NewL( *this, pluginUid );
       
   127 #endif    
       
   128     LOG("CGeoConverter::ConstructL, end");
       
   129     }
       
   130 
       
   131 // --------------------------------------------------------------------------
       
   132 // CGeoConverter::ConvertL()
       
   133 // --------------------------------------------------------------------------
       
   134 //  
       
   135 EXPORT_C void CGeoConverter::ConvertL( const CTelephony::TNetworkInfoV1& aNetworkInfo )
       
   136     {
       
   137     LOG("CGeoConverter::ConvertL, begin");
       
   138 #ifdef LOC_GEOTAGGING_CELLID    
       
   139     
       
   140     //Set mobile country code
       
   141     TLex lexer( aNetworkInfo.iCountryCode );
       
   142     TUint countryCode = 0;
       
   143     
       
   144     User::LeaveIfError( lexer.Val( countryCode, EDecimal) );
       
   145     //Set mobile network code
       
   146     lexer = aNetworkInfo.iNetworkId;
       
   147     TUint networkCode = 0;
       
   148     User::LeaveIfError( lexer.Val( networkCode, EDecimal) );
       
   149     LOG1("Network mode - %d", aNetworkInfo.iMode);
       
   150     CLbsAreaInfoBase* areaInfoBase = NULL;
       
   151     switch(aNetworkInfo.iAccess)
       
   152         {
       
   153         case CTelephony::ENetworkAccessGsm:
       
   154         case CTelephony::ENetworkAccessGsmCompact:
       
   155             {
       
   156             LOG("2G network.");
       
   157             if(iGsmCellInfo == NULL)
       
   158                 {
       
   159                 iGsmCellInfo = CLbsGsmCellInfo::NewL();
       
   160                 }
       
   161             iGsmCellInfo->SetMobileCountryCode( countryCode );
       
   162             
       
   163             iGsmCellInfo->SetMobileNetworkCode( networkCode );
       
   164             //Set cell id 
       
   165             iGsmCellInfo->SetCellId( aNetworkInfo.iCellId ); 
       
   166 
       
   167             if(aNetworkInfo.iAreaKnown)
       
   168                 {
       
   169                 //Set location area code
       
   170                 iGsmCellInfo->SetLocationAreaCode( aNetworkInfo.iLocationAreaCode );
       
   171                 }            
       
   172         
       
   173             areaInfoBase = iGsmCellInfo;
       
   174             }        
       
   175             break;
       
   176         case CTelephony::ENetworkAccessUtran:
       
   177             {
       
   178             LOG("3G network.");
       
   179             if(iWcdmaCellInfo == NULL)
       
   180                 {
       
   181                 iWcdmaCellInfo = CLbsWcdmaCellInfo::NewL();
       
   182                 }
       
   183             iWcdmaCellInfo->SetMobileCountryCode(countryCode);
       
   184             iWcdmaCellInfo->SetMobileNetworkCode(networkCode);
       
   185             iWcdmaCellInfo->SetUniqueCellId(aNetworkInfo.iCellId);
       
   186             areaInfoBase = iWcdmaCellInfo;
       
   187             }
       
   188             break;
       
   189         default:
       
   190             LOG("Unknown network mode");
       
   191             User::Leave(KErrNotSupported);
       
   192         }
       
   193     //Add the cell information to the location info class. This class
       
   194     //would be sent to the Location Monitor server that would perform the
       
   195     //requested conversion and update the position estimate
       
   196     if(areaInfoBase != NULL) // self check
       
   197         {
       
   198         // reset previous one.. to clear the local info.
       
   199         iLocInfo->ResetAreaInfo(CLbsLocationInfo::ELbsAreaInfoAll);
       
   200         iLocInfo->AddAreaInfoL( areaInfoBase ); 
       
   201         //ownership is transferred.
       
   202         iWcdmaCellInfo = NULL;
       
   203         iGsmCellInfo = NULL;
       
   204         //Request conversion of GSM cell information to corresponding coordinate information
       
   205         iLocConverter->ConvertLocationInfoL( *iLocInfo, ELbsConversionSilent, 
       
   206                                                 ELbsConversionOutputPosition  );
       
   207         }
       
   208 #endif    
       
   209     LOG("CGeoConverter::ConvertL, end");
       
   210     }
       
   211 
       
   212 // End of file
       
   213