cbs/CbsServer/ServerSrc/Ccbsrecetel.cpp
changeset 46 2fa1fa551b0b
parent 42 35488577e233
child 48 78df25012fda
equal deleted inserted replaced
42:35488577e233 46:2fa1fa551b0b
     1 /*
       
     2 * Copyright (c) 2003 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 creates the ETEL receiver package subcomponents, handles
       
    15 *                incoming CBS messages and communicates with the server interface.
       
    16 *      
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 		/*****************************************************
       
    24 		*	Series 60 Customer / ETel
       
    25 		*	Series 60  ETel API
       
    26 		*****************************************************/
       
    27 #include <etelmm.h>
       
    28 #include <mmlist.h> // CMobilePhoneBroadcastIdList
       
    29 #include <mmtsy_names.h>
       
    30 
       
    31 #include "CbsServerConstants.h"
       
    32 #include "CbsServerPanic.h"
       
    33 #include "CCbsDbImp.H"
       
    34 #include "CCbsDbImpTopicList.h"
       
    35 #include "CCbsDbImpSettings.H"
       
    36 #include "CCbsRecCollector.h"
       
    37 #include "CCbsRecDecoder.h"
       
    38 #include "CCbsRecEtel.h"
       
    39 #include "CCbsRecEtelMonitor.h"
       
    40 #include "CCbsRecNetworkListener.h"
       
    41 #include "CCbsRecMessage.h"
       
    42 #include "CCbsReceiverHelper.h"
       
    43 #include "CbsUtils.h"
       
    44 
       
    45 #include "CCbsEtelMessaging.h"
       
    46 #include "MCbsEtelMessaging.h"
       
    47 #include "MCbsMcnSubscriptionsProvider.h"
       
    48 #include "CCbsSetFilterSettingHandler.h"
       
    49 
       
    50 #include "CCbsRecWcdmaMessage.h"
       
    51 #include "CCbsMessageFactory.h"
       
    52 #include "CCbsLivecastHandler.h"
       
    53 #include "CbsLogger.h"
       
    54 
       
    55 #include <centralrepository.h>  // for local variation
       
    56 #include "cbsinternalcrkeys.h"  // for local variation
       
    57 #include "cbsvariant.hrh"       // for local variation
       
    58 
       
    59 
       
    60 // ================= MEMBER FUNCTIONS =======================
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CCbsRecEtel::CCbsRecEtel
       
    64 // C++ default constructor can NOT contain any code, that
       
    65 // might leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 		/*****************************************************
       
    69 		*	Series 60 Customer / ETel
       
    70 		*	Series 60  ETel API
       
    71 		*****************************************************/
       
    72 CCbsRecEtel::CCbsRecEtel()
       
    73     : iReception( RMobileBroadcastMessaging::EBroadcastAcceptAll ), 
       
    74       iCellInfoReceived( EFalse ),
       
    75       iReceptionEnabled( EFalse ),
       
    76       iLimitedReception( EFalse ),
       
    77       iStartTime( 0 ),
       
    78       iEndTime( 0 ),
       
    79       iHomeZoneReceived( EFalse ),
       
    80       iNewSimTopicsAdded( EFalse )
       
    81     {
       
    82     }
       
    83 
       
    84 // -----------------------------------------------------------------------------
       
    85 // CCbsRecEtel::ConstructL
       
    86 // Symbian 2nd phase constructor can leave.
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void CCbsRecEtel::ConstructL()
       
    90     {
       
    91     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::ConstructL()");
       
    92 
       
    93     iSubscriptionProviders = new ( ELeave ) 
       
    94         CArrayFixFlat< MCbsMcnSubscriptionsProvider* >( 1 );
       
    95 
       
    96     iDecoder = CCbsRecDecoder::NewL();
       
    97     
       
    98     // Establish a session with the ETel server. 
       
    99     ConnectToEtelL();
       
   100 
       
   101     // Create a listener to monitor network state changes,
       
   102     iNetworkListener = CCbsRecNetworkListener::NewL( iGsmPhone );
       
   103 
       
   104     // Construct the command handlers
       
   105     iFilterSettingHandler = CCbsSetFilterSettingHandler::NewL( *this, *iMessaging );
       
   106 
       
   107     // Create the message factory
       
   108     iFactory = CCbsMessageFactory::NewL( *this );    
       
   109     
       
   110     // Message page collector
       
   111     iCollector = CCbsRecCollector::NewL( *iFactory );
       
   112 
       
   113     // LC message handler
       
   114     iLivecastHandler = CCbsLivecastHandler::NewL( *this );
       
   115 
       
   116     // Message monitor
       
   117     iEtelMonitor = CCbsRecEtelMonitor::NewL( *this, *iMessaging, *iFactory, *iLivecastHandler );    
       
   118     
       
   119     // Fetch local variation bits from CenRep    
       
   120     CRepository* repository = CRepository::NewL( KCRUidCbsVariation );    
       
   121     TInt err = repository->Get( KCbsVariationFlags, iLVBits );  
       
   122     if ( err )
       
   123         {
       
   124         iLVBits = 0;
       
   125         }  
       
   126     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::ConstructL(): CenRep error: %d", err );   
       
   127     delete repository;
       
   128 
       
   129     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::ConstructL()");
       
   130     }
       
   131 
       
   132 // -----------------------------------------------------------------------------
       
   133 // CCbsRecEtel::NewL
       
   134 // Two-phased constructor.
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 CCbsRecEtel* CCbsRecEtel::NewL()
       
   138     {
       
   139     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::NewL()");
       
   140 
       
   141     CCbsRecEtel* self = new ( ELeave ) CCbsRecEtel;
       
   142     CleanupStack::PushL( self );
       
   143     self->ConstructL();
       
   144     CleanupStack::Pop();
       
   145 
       
   146     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::NewL()");
       
   147     return self;
       
   148     }
       
   149     
       
   150 // Destructor 
       
   151 		/*****************************************************
       
   152 		*	Series 60 Customer / ETel
       
   153 		*	Series 60  ETel API
       
   154 		*****************************************************/
       
   155 CCbsRecEtel::~CCbsRecEtel()
       
   156     {
       
   157     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::~CCbsRecEtel()");
       
   158     
       
   159     // Disable CB reception, ignore result    
       
   160     TRAP_IGNORE( SetReceptionStatusL( 
       
   161         RMobileBroadcastMessaging::EBroadcastAcceptNone ) );
       
   162     
       
   163     delete iNetworkListener;
       
   164     delete iEtelMonitor;
       
   165     delete iFilterSettingHandler;
       
   166     delete iLivecastHandler;
       
   167 
       
   168     if ( iMessaging )
       
   169         {
       
   170         iMessaging->Close(); // owned by CCbsEtelFactory
       
   171         }        
       
   172     delete iMessaging;
       
   173     
       
   174     delete iCollector;
       
   175     delete iDecoder;    
       
   176     delete iFactory;
       
   177     delete iSubscriptionProviders;
       
   178 
       
   179     iCustomPhone.Close();
       
   180     iGsmPhone.Close();
       
   181     iEtelServer.Close();
       
   182         
       
   183     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::~CCbsRecEtel()");
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CCbsRecEtel::HandleMessageReceivedL
       
   188 // Handles a received CBS message page. 
       
   189 //  
       
   190 // The message have
       
   191 // to be decoded, uncompressed and collected only if
       
   192 // certain conditions hold. These are checked first.
       
   193 //
       
   194 // The handling sequence is as follows:    
       
   195 // 1.  If the reception is off, reject this message.
       
   196 // 2.  If the user has set a time limit for receiving messages,
       
   197 //     check if the current time is such that the message
       
   198 //     should not be received.
       
   199 // 3.  Check whether message's language has been subscribed.
       
   200 //     Reject the message if not. If message id a Class 0 message,
       
   201 //     do not reject, since the msg should be shown.
       
   202 // 4.  If the topic detection is enabled and this message
       
   203 //     is of an unknown topic, add the new topic and
       
   204 //     reject this message (since the new topic cannot
       
   205 //     be subscribed at this point).
       
   206 // 5.  If the same message exists in the database, this
       
   207 //     message is ignored.
       
   208 // 6.  The decoder decodes the page.
       
   209 // 7.  If the message is multipaged, it is given to 
       
   210 //     the message collector.
       
   211 // 8.  A complete message is forwarded to CCbsReceiverHelper,
       
   212 //     which either stores the message into the database
       
   213 //     or handles it as an index message.
       
   214 //
       
   215 // This function is called from CCbsRecEtelMonitor::RunL().
       
   216 //
       
   217 // Note: Message reception status check may be unnecessary,
       
   218 //       if the ETel Monitor instance handles the check.
       
   219 //
       
   220 // Note: Message subscription check is necessary here.
       
   221 //       UI client's subscriptions might differ from MCN client's
       
   222 //       subscriptions.
       
   223 //
       
   224 // Note: Language cannot be read from the header if the
       
   225 //       language information is stored in the content of
       
   226 //       the message. This is particulary troublesome, if 
       
   227 //       the message is compressed. 
       
   228 // (other items were commented in a header).
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 void CCbsRecEtel::HandleMessageReceivedL( 
       
   232     CCbsMessage* aMessage )
       
   233     {
       
   234     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::HandleMessageReceivedL()");
       
   235     
       
   236     CleanupStack::PushL( aMessage ); // take ownership
       
   237        
       
   238     // Decode a message. Language indication prefix, if any, is also
       
   239     // removed here. A leave occurs if the message is compressed.
       
   240     iDecoder->DecodeL( *aMessage );
       
   241 
       
   242     // Add network information to message.
       
   243     TInt error = AddNetworkInfo( *aMessage );
       
   244 
       
   245     // If the message is a cell info, extract the information.
       
   246     if ( aMessage->TopicNumber() == KCellInfoTopic )
       
   247         {
       
   248         if ( KErrNone == error )
       
   249             {
       
   250             ExtractCellInformation( *aMessage );
       
   251             }
       
   252         else
       
   253             {
       
   254             iCellInfoReceived = EFalse;
       
   255             }
       
   256         }
       
   257     else if ( aMessage->TopicNumber() == KHomeZoneTopic )
       
   258         {
       
   259         if ( KErrNone == error )
       
   260             {
       
   261             ExtractHomeZoneInformation( *aMessage );
       
   262             }
       
   263         else
       
   264             {
       
   265             iHomeZoneReceived = EFalse;
       
   266             }
       
   267         }
       
   268 
       
   269     // Route the message to all MCN client session-objects.
       
   270     RouteMessageL( *aMessage );
       
   271 
       
   272     // 1. If the reception is off, reject this message.
       
   273     // 2. If the time of the day is such that the user has decided
       
   274     //    not to receive any messages, reject this message.
       
   275     // 3. Check whether message's language has been subscribed
       
   276     // 4. Check if the topic of this message is not in the topic list
       
   277     //    and the topic detection is enabled.
       
   278     // 5. Check if the topic of this message has been subscribed.
       
   279     // 6. Check if this message already exists in the database.    
       
   280     
       
   281     // This variable must be local, since if the common reception status
       
   282     // is used, this check can mess it up.
       
   283     TBool uiReceptionEnabled( EFalse );
       
   284     iInterface->Database().SettingsL().GetReceptionStatus( uiReceptionEnabled );
       
   285 
       
   286     if ( !uiReceptionEnabled ||
       
   287         ( iInterface->LanguageOfMessageSubscribedL( *aMessage ) == EFalse &&
       
   288         aMessage->RequiresImmediateDisplay() == EFalse ) ||
       
   289         iInterface->CheckForNewTopicL( *aMessage ) ||
       
   290         iInterface->CheckForSubscriptionAndExistenceL( *aMessage ) == EFalse )
       
   291         {
       
   292         CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): Rejecting msg, PopAndDestroy().");
       
   293         CleanupStack::PopAndDestroy( aMessage );
       
   294         }  
       
   295     else
       
   296         {
       
   297         // Check if this message is multipaged and if it is, 
       
   298         // give it to the message collector. If it isn't,
       
   299         // forward the message to the receiver helper
       
   300         if ( aMessage->TotalPages() > 1 )
       
   301             {
       
   302             CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): Multipaged msg, total pages: %d.", aMessage->TotalPages() );
       
   303             
       
   304             // Ensure that the network info is available. 
       
   305             // If not, reject the message, because info is required to collect
       
   306             // pages of a multipaged message.
       
   307             if ( KErrNone != error )
       
   308                 {
       
   309                 CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): AddNetworkInfo error: %d, PopAndDestroy().", error );
       
   310                 CleanupStack::PopAndDestroy( aMessage );
       
   311                 }
       
   312             else
       
   313                 {
       
   314                 // Ownership of aMessage transferred to iCollector with
       
   315                 // aMessage left on the cleanup stack.
       
   316                 CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): Calling iCollector->CollectL()...");                
       
   317                 CCbsMessage* completedMsg = iCollector->CollectL( aMessage, ECbsMessageTypeUnspecified );
       
   318                 CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): iCollector->CollectL() finished OK.");
       
   319                 
       
   320                 if ( completedMsg )
       
   321                     {
       
   322                     // Message pages combined => Handle like a single-paged msg.
       
   323                     // Result code ignored.
       
   324                     CleanupStack::PushL( completedMsg );
       
   325                     CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): MULTIPAGED: Calling iInterface->HandleReceivedMessageL()...");
       
   326                     iInterface->HandleReceivedMessageL( *completedMsg );
       
   327                     CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): MULTIPAGED: iInterface->HandleReceivedMessageL() finished OK.");
       
   328                     CleanupStack::PopAndDestroy( completedMsg );
       
   329                     }
       
   330                 }            
       
   331             }
       
   332         else
       
   333             {
       
   334             // single page    
       
   335             CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): SINGLEPAGED: Calling iInterface->HandleReceivedMessageL()...");
       
   336             iInterface->HandleReceivedMessageL( *aMessage );
       
   337             CBSLOGSTRING("CBSSERVER: CCbsRecEtel::HandleMessageReceivedL(): SINGLEPAGED: iInterface->HandleReceivedMessageL() finished OK.");
       
   338             CleanupStack::PopAndDestroy( aMessage );
       
   339             }
       
   340         }
       
   341     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::HandleMessageReceivedL()");                                
       
   342     }
       
   343 
       
   344 // -----------------------------------------------------------------------------
       
   345 // CCbsRecEtel::AddNetworkInfo
       
   346 // This method blocks if no current network info is 
       
   347 // available and the call to retrieve information blocks.
       
   348 //  
       
   349 // Augments aMessage with current network information (i.e., PLMN, LAC
       
   350 // and Cell ID). Does nothing if the network listener iListener
       
   351 // is unavailable.
       
   352 // (other items were commented in a header).
       
   353 // -----------------------------------------------------------------------------
       
   354 //
       
   355 		/*****************************************************
       
   356 		*	Series 60 Customer / ETel
       
   357 		*	Series 60  ETel API
       
   358 		*****************************************************/
       
   359 TInt CCbsRecEtel::AddNetworkInfo( 
       
   360     CCbsMessage& aMessage ) const
       
   361     {
       
   362     TInt result( KErrNone );
       
   363 
       
   364     RMobilePhone::TMobilePhoneNetworkInfoV1 info;
       
   365     RMobilePhone::TMobilePhoneLocationAreaV1 area;
       
   366 
       
   367     result = iNetworkListener->GetCurrentNetworkInfo( info, area );
       
   368     
       
   369     if ( result == KErrNone )
       
   370         {
       
   371         aMessage.SetNetworkInfo( info, area );
       
   372         }
       
   373 
       
   374     return result;
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // CCbsRecEtel::SetInterface
       
   379 // Sets the interface to which all accepted messages are given.
       
   380 // (other items were commented in a header).
       
   381 // -----------------------------------------------------------------------------
       
   382 //
       
   383 void CCbsRecEtel::SetInterface( 
       
   384     CCbsReceiverHelper* aInterface )
       
   385     {
       
   386     __ASSERT_DEBUG( aInterface != 0, User::Panic( _L( "InterfaceNull" ), 0 ) );
       
   387     iInterface = aInterface;
       
   388     }
       
   389 
       
   390 // -----------------------------------------------------------------------------
       
   391 // CCbsRecEtel::AddSubscriptionProviderL
       
   392 // MCN client sessions register to CCbsRecEtel using this function.
       
   393 // 
       
   394 // When topic subscriptions are gathered during execution of
       
   395 // ApplyStateChangesL(), subscriptions of each registered subscription
       
   396 // provider are added to the CBMI list that determines which
       
   397 // topics are received.
       
   398 // (other items were commented in a header).
       
   399 // -----------------------------------------------------------------------------
       
   400 //
       
   401 void CCbsRecEtel::AddSubscriptionProviderL( 
       
   402     MCbsMcnSubscriptionsProvider* aProvider )
       
   403     {
       
   404     __TEST_INVARIANT;
       
   405     if ( !aProvider )
       
   406         {
       
   407         User::Leave( KErrArgument );
       
   408         }
       
   409 
       
   410     iSubscriptionProviders->AppendL( aProvider );
       
   411 
       
   412     __TEST_INVARIANT;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // CCbsRecEtel::RemoveSubscriptionProviderL
       
   417 // Removes a MCN topic subscription provider.
       
   418 // (other items were commented in a header).
       
   419 // -----------------------------------------------------------------------------
       
   420 //
       
   421 void CCbsRecEtel::RemoveSubscriptionProviderL(
       
   422     const MCbsMcnSubscriptionsProvider* aProvider )
       
   423     {
       
   424     __TEST_INVARIANT;
       
   425     if ( !aProvider )
       
   426         {
       
   427         User::Leave( KErrArgument );
       
   428         }
       
   429 
       
   430     TInt count( iSubscriptionProviders->Count() );
       
   431     for ( TInt i( 0 ); i < count; i++ )
       
   432         {
       
   433         if ( iSubscriptionProviders->At( i ) == aProvider )
       
   434             {
       
   435             iSubscriptionProviders->Delete( i );
       
   436             ApplyStateChangesL();
       
   437             __TEST_INVARIANT;
       
   438             return;
       
   439             }
       
   440         }
       
   441 
       
   442 #ifdef _DEBUG
       
   443     CbsServerPanic( EMcnProviderNotFound );
       
   444 #endif
       
   445     }
       
   446 
       
   447 // -----------------------------------------------------------------------------
       
   448 // CCbsRecEtel::ApplyStateChangesL
       
   449 // Retrieves current subscriptions and settings from DB.
       
   450 // 
       
   451 // Reception should be enabled if:
       
   452 // 1) User has enabled it or
       
   453 // 2) There are MCN clients with outstanding message routing
       
   454 // requests or
       
   455 // 3) New topics were found from SIM card and they were added to Topic list
       
   456 //
       
   457 // If the reception is enabled, all topics and languages
       
   458 // are subscribed from ETel. Filtering is done in CbsServer
       
   459 // on receival of a CB message (see HandleMessageReceivedL()).
       
   460 // (other items were commented in a header).
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 		/*****************************************************
       
   464 		*	Series 60 Customer / ETel
       
   465 		*	Series 60  ETel API
       
   466 		*****************************************************/
       
   467 void CCbsRecEtel::ApplyStateChangesL()
       
   468     {
       
   469 	CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::ApplyStateChangesL()");
       
   470 
       
   471     // Determine reception status: If any MCN client requests messages or new
       
   472     // SIM Topics have just been addded, then reception should be enabled. 
       
   473     // Otherwise UI client reception setting is used.
       
   474     TUint numberOfMcnSubscriptions( NumberOfMcnSubscriptions() );
       
   475     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): numberOfMcnSubscriptions: %d", numberOfMcnSubscriptions );
       
   476 
       
   477     TBool receptionStatus( EFalse );
       
   478     TInt errorCode( KErrNone );
       
   479     TRAP( errorCode, iInterface->Database().SettingsL().GetReceptionStatus( receptionStatus ) );
       
   480     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): Database reception status: %d", receptionStatus );
       
   481 
       
   482     TBool receptionEnabled( EFalse );
       
   483     
       
   484     // Variated feature    
       
   485     if ( iLVBits & KCbsLVFlagTopicSubscription )
       
   486         {
       
   487         receptionEnabled = ( receptionStatus || numberOfMcnSubscriptions > 0 || iNewSimTopicsAdded );
       
   488         }
       
   489     else
       
   490         {
       
   491         receptionEnabled = ( receptionStatus || numberOfMcnSubscriptions > 0 );
       
   492         }
       
   493     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): Should reception be enabled: %d", receptionEnabled );
       
   494 
       
   495     // Check if the reception status should be changed
       
   496     if ( receptionEnabled != iReceptionEnabled )
       
   497         {
       
   498         CBSLOGSTRING("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): Changing reception status.");
       
   499 
       
   500         if ( !receptionEnabled )
       
   501             {
       
   502             // Set reception off
       
   503             SetReceptionStatusL( RMobileBroadcastMessaging::EBroadcastAcceptNone );
       
   504             CBSLOGSTRING("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): Changing reception status, status set OFF.");
       
   505             }
       
   506         else
       
   507             {
       
   508             // Set reception on
       
   509             SetReceptionStatusL( RMobileBroadcastMessaging::EBroadcastAcceptAll );
       
   510             CBSLOGSTRING("CBSSERVER: CCbsRecEtel::ApplyStateChangesL(): Changing reception status, status set ON.");
       
   511             }
       
   512         }
       
   513 	CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::ApplyStateChangesL()");
       
   514     }
       
   515 
       
   516 // -----------------------------------------------------------------------------
       
   517 // CCbsRecEtel::GetCurrentMessage
       
   518 // Returns the current information message.
       
   519 // The information is retrieved from the last cell information or HomeZone
       
   520 // message.
       
   521 // (other items were commented in a header).
       
   522 // -----------------------------------------------------------------------------
       
   523 //
       
   524 TInt CCbsRecEtel::GetCurrentMessage( 
       
   525     TDes& aInfoMessage,
       
   526     TInt aTopicNumber )
       
   527     {
       
   528     // Handle the cell info message (topic 50)
       
   529     if ( aTopicNumber == KCellInfoTopic && iCellInfoReceived )
       
   530         {
       
   531         RMobilePhone::TMobilePhoneNetworkInfoV1 networkInfo;
       
   532         RMobilePhone::TMobilePhoneLocationAreaV1 area;
       
   533 
       
   534         iNetworkListener->GetCurrentNetworkInfo( networkInfo, area );
       
   535 
       
   536         if ( iCellInfoLAC == area.iLocationAreaCode &&
       
   537              iCellInfoCellId == area.iCellId &&
       
   538              iCellInfoPLMN.iCountryCode == networkInfo.iCountryCode &&
       
   539              iCellInfoPLMN.iNetworkId == networkInfo.iNetworkId )
       
   540             {
       
   541             aInfoMessage.Copy( iCurrentCellInfoMessage );
       
   542             return KErrNone;
       
   543             }
       
   544         iCellInfoReceived = EFalse;
       
   545         }
       
   546     // Handle the HomeZone message (topic 221)
       
   547     else if ( aTopicNumber == KHomeZoneTopic && iHomeZoneReceived )
       
   548         {
       
   549         RMobilePhone::TMobilePhoneNetworkInfoV1 networkInfo;
       
   550         RMobilePhone::TMobilePhoneLocationAreaV1 area;
       
   551 
       
   552         iNetworkListener->GetCurrentNetworkInfo( networkInfo, area );
       
   553 
       
   554         if ( iHomeZoneLAC == area.iLocationAreaCode &&
       
   555              iHomeZoneCellId == area.iCellId &&
       
   556              iHomeZonePLMN.iCountryCode == networkInfo.iCountryCode &&
       
   557              iHomeZonePLMN.iNetworkId == networkInfo.iNetworkId )
       
   558             {
       
   559             aInfoMessage.Copy( iCurrentHomeZoneMessage );
       
   560             return KErrNone;
       
   561             }
       
   562         iHomeZoneReceived = EFalse;
       
   563         }
       
   564 
       
   565     return KErrNotFound;            
       
   566     }
       
   567 
       
   568 // ---------------------------------------------------------
       
   569 // LoadSimTopicsL() 
       
   570 // Loads topics from SIM, if any exists. Saves them into DB.
       
   571 // ---------------------------------------------------------
       
   572 		/*****************************************************
       
   573 		*	Series 60 Customer / ETel
       
   574 		*	Series 60  ETel API
       
   575 		*****************************************************/
       
   576 TInt CCbsRecEtel::LoadSimTopicsL()
       
   577     {
       
   578     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::LoadSimTopicsL()");
       
   579     
       
   580     TInt result( iCustomPhone.StartSimCbTopicBrowsing() );
       
   581     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::LoadSimTopicsL(): StartSimCbTopicBrowsing() returned: %d.", result);
       
   582 
       
   583     if ( result != KErrNone )
       
   584         {
       
   585         CBSLOGSTRING2("CBSSERVER: <<< CCbsRecEtel::LoadSimTopicsL(), returning %d.", result);
       
   586         return result;
       
   587         }
       
   588 
       
   589     // Retrieve topics one at time from SIM and store them into DB.
       
   590     RMmCustomAPI::TSimCbTopic topic;
       
   591     TInt error( KErrNone );
       
   592     while ( ( error = iCustomPhone.GetNextSimCbTopic( topic ) ) == KErrNone )
       
   593         {
       
   594         CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::LoadSimTopicsL(): GetNextSimCbTopic() returned KErrNone. (%d)", error );
       
   595         TRAPD( result, iInterface->AddSimTopicL( topic.iNumber, topic.iName ) );
       
   596         
       
   597         // Indicate that at least one new SIM Topic was added to Topic list
       
   598         if ( !result )
       
   599             {
       
   600             // Variated feature
       
   601             if ( iLVBits & KCbsLVFlagTopicSubscription )
       
   602                 {
       
   603                 iNewSimTopicsAdded = ETrue;
       
   604                 CBSLOGSTRING("CBSSERVER: CCbsRecEtel::LoadSimTopicsL(), iNewSimTopicsAdded = ETRUE" );
       
   605                 }            
       
   606             }
       
   607         }
       
   608     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::LoadSimTopicsL(), GetNextSimCbTopic error: %d.", error);
       
   609     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::LoadSimTopicsL(), AddSimTopicL result: %d.", result);
       
   610     
       
   611     // To prevent ARMV5 compiler warning
       
   612     if ( error )
       
   613         {
       
   614         error = KErrNone;    
       
   615         }        
       
   616 
       
   617 	CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::LoadSimTopicsL(), returning KErrNone.");
       
   618     return KErrNone;
       
   619     }
       
   620 
       
   621 // ---------------------------------------------------------
       
   622 // DeleteSimTopicL
       
   623 // Delete the SIM topic. If the SIM topic does not exist, 
       
   624 // ignore, because that's what we actually want.
       
   625 // ---------------------------------------------------------
       
   626 		/*****************************************************
       
   627 		*	Series 60 Customer / ETel
       
   628 		*	Series 60  ETel API
       
   629 		*****************************************************/
       
   630 void CCbsRecEtel::DeleteSimTopicL( const TUint16 aNumber, const TBool aDeleteAll ) 
       
   631     {
       
   632     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::DeleteSimTopicL()");
       
   633     
       
   634     TInt number( aNumber );
       
   635 
       
   636     // All other errors than KErrNotFound are thrown.
       
   637     TInt ret( iCustomPhone.DeleteSimCbTopic( number ) );
       
   638     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::DeleteSimTopicL(): DeleteSimCbTopic() returned: %d.", ret);
       
   639     
       
   640 #ifdef __WINS__
       
   641     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::DeleteSimTopicL(): DeleteSimCbTopic() returned: %d", ret );
       
   642 #else
       
   643     if ( ret != KErrNotFound )
       
   644         {
       
   645         CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::DeleteSimTopicL(): DeleteSimCbTopic() returned: %d", ret );
       
   646         User::LeaveIfError( ret );
       
   647         }
       
   648 
       
   649 #endif
       
   650     // Delete one by one from cache only if we are deleting just one topic from the SIM card
       
   651     if ( !aDeleteAll )
       
   652         {
       
   653         // Delete from local array    
       
   654         iInterface->DeleteFromSimTopicCache( aNumber );
       
   655         }    
       
   656         
       
   657     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::DeleteSimTopicL()");
       
   658     }
       
   659 
       
   660 // ---------------------------------------------------------
       
   661 // CCbsRecEtel::DeleteAllSimTopicsL
       
   662 // Deletes all topics from the SIM card.
       
   663 // (other items were commented in a header).
       
   664 // ---------------------------------------------------------
       
   665 		/*****************************************************
       
   666 		*	Series 60 Customer / ETel
       
   667 		*	Series 60  ETel API
       
   668 		*****************************************************/
       
   669 
       
   670 void CCbsRecEtel::DeleteAllSimTopicsL()
       
   671     {
       
   672     CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::DeleteAllSimTopicsL()");
       
   673     
       
   674     TInt count = iInterface->SimTopics().Count();
       
   675     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::DeleteAllSimTopicsL(): SIM Topic count: %d", count );    
       
   676     
       
   677     for ( TInt i( 0 ); i < count; i++ )
       
   678         {
       
   679         TInt topicNum = iInterface->SimTopics().At( i );
       
   680         CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::DeleteAllSimTopicsL(): SIM Topic number: %d", topicNum );    
       
   681         DeleteSimTopicL( topicNum, ETrue );
       
   682         }
       
   683     
       
   684     // Delete all topics from the cache
       
   685     iInterface->SimTopics().Reset();
       
   686             
       
   687     CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::DeleteAllSimTopicsL()");
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CCbsRecEtel::ConnectToEtelL
       
   692 // Establishes a connection with the EPOC Telephony Server server.
       
   693 // Also opens the necessary EPOC Telephony Server resources such as RPhone and
       
   694 // RAdvGsmSmsMessaging sessions.
       
   695 // (other items were commented in a header).
       
   696 // -----------------------------------------------------------------------------
       
   697 //
       
   698 		/*****************************************************
       
   699 		*	Series 60 Customer / ETel
       
   700 		*	Series 60  ETel API
       
   701 		*****************************************************/
       
   702 
       
   703 		/*****************************************************
       
   704 		*	Series 60 Customer / TSY
       
   705 		*	Needs customer TSY implementation
       
   706 		*****************************************************/
       
   707 void CCbsRecEtel::ConnectToEtelL()
       
   708     {
       
   709     TInt result( KErrNone );
       
   710 
       
   711     // Connect to ETel
       
   712     User::LeaveIfError( iEtelServer.Connect() );
       
   713 
       
   714     // Load Phone TSY module
       
   715     result = iEtelServer.LoadPhoneModule( KMmTsyModuleName );
       
   716     if ( result != KErrNone )
       
   717         {
       
   718         User::Leave( result );
       
   719         }
       
   720 
       
   721     // This function retrieves the total number of phones supported by all 
       
   722 	// the currently loaded EPOC Telephony Server (TSY) modules.
       
   723     TInt phoneCount( 0 );
       
   724     User::LeaveIfError( iEtelServer.EnumeratePhones( phoneCount ) );
       
   725 
       
   726     // This function retrieves information associated with the specified phone
       
   727 	RTelServer::TPhoneInfo phoneInfo;	
       
   728 	while ( phoneCount-- )
       
   729 		{
       
   730         User::LeaveIfError( iEtelServer.GetPhoneInfo( phoneCount, 
       
   731             phoneInfo ) );
       
   732 
       
   733         if ( phoneInfo.iName == KMmTsyPhoneName )
       
   734             {
       
   735             phoneCount = 0;
       
   736             }
       
   737 		}
       
   738 
       
   739     // Open GSM phone
       
   740     result = iGsmPhone.Open( iEtelServer, phoneInfo.iName );    
       
   741     if ( result != KErrNone )
       
   742         {
       
   743         User::Leave( result );
       
   744         }
       
   745 
       
   746     // Create an EPOC Telephony Server messaging instance
       
   747     iMessaging = CCbsEtelMessaging::NewL();
       
   748 
       
   749     // Open SMS Messaging
       
   750     result = iMessaging->Open( iGsmPhone );
       
   751     if ( result != KErrNone )
       
   752         {
       
   753         User::Leave( result );
       
   754         }
       
   755 
       
   756     // Opens a custom phone subsession by name
       
   757     result = iCustomPhone.Open( iGsmPhone );
       
   758     if ( result != KErrNone )
       
   759         {
       
   760         User::Leave( result );
       
   761         }
       
   762     }
       
   763 
       
   764 // -----------------------------------------------------------------------------
       
   765 // CCbsRecEtel::SetReceptionStatusL
       
   766 // Sets the requested CB reception status aStatus to ME.
       
   767 // (other items were commented in a header).
       
   768 // -----------------------------------------------------------------------------
       
   769 //
       
   770 		/*****************************************************
       
   771 		*	Series 60 Customer / ETel
       
   772 		*	Series 60  ETel API
       
   773 		*****************************************************/
       
   774 void CCbsRecEtel::SetReceptionStatusL(
       
   775     RMobileBroadcastMessaging::TMobilePhoneBroadcastFilter aSetting )
       
   776     {    
       
   777     if ( iEtelMonitor )
       
   778         {
       
   779         if ( aSetting == RMobileBroadcastMessaging::EBroadcastAcceptNone )
       
   780             {            
       
   781             iEtelMonitor->Cancel();
       
   782             }
       
   783         else
       
   784             {
       
   785             iEtelMonitor->IssueRequest();
       
   786             }
       
   787         }
       
   788 
       
   789     if ( iMessaging )
       
   790         {        
       
   791         iFilterSettingHandler->SetFilterSetting( aSetting );
       
   792         }
       
   793 
       
   794     iReceptionEnabled = ( aSetting == RMobileBroadcastMessaging::EBroadcastAcceptAll );
       
   795     
       
   796     // Variated feature
       
   797     if ( iLVBits & KCbsLVFlagTopicSubscription )
       
   798         {
       
   799         // Set reception setting on also for UI, 
       
   800         // if new topics were added from the SIM card
       
   801         if ( iNewSimTopicsAdded )
       
   802             {
       
   803             iInterface->Database().SettingsL().SetReceptionStatusL( ETrue );
       
   804             iNewSimTopicsAdded = EFalse;
       
   805             }
       
   806         }    
       
   807     }  
       
   808 
       
   809 // -----------------------------------------------------------------------------
       
   810 // CCbsRecEtel::NumberOfMcnSubscriptions
       
   811 // Returns the total number of topic subscriptions made by
       
   812 // MCN clients registered to the server.
       
   813 // (other items were commented in a header).
       
   814 // -----------------------------------------------------------------------------
       
   815 //
       
   816 TUint CCbsRecEtel::NumberOfMcnSubscriptions() const
       
   817     {
       
   818     TUint count( 0 );
       
   819     TInt mcnClientCount( iSubscriptionProviders->Count() );
       
   820     for ( TInt i( 0 ); i < mcnClientCount; i++ )
       
   821         {
       
   822         count += iSubscriptionProviders->At( i )->NumberOfSubscriptions();
       
   823         }
       
   824     return count;
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // CCbsRecEtel::RouteMessageL
       
   829 // Passes the given CB message to each registered subscriptions
       
   830 // provider  
       
   831 // a subscription provider is a MCN client wishing
       
   832 // CB message routing service
       
   833 // (other items were commented in a header).
       
   834 // -----------------------------------------------------------------------------
       
   835 //
       
   836 void CCbsRecEtel::RouteMessageL( 
       
   837     const CCbsMessage& aMessage )
       
   838     {
       
   839 	CBSLOGSTRING("CBSSERVER: >>> CCbsRecEtel::RouteMessageL()");
       
   840 
       
   841     TInt count( iSubscriptionProviders->Count() );    
       
   842     CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::RouteMessageL(): Provider count: %d", count);
       
   843 
       
   844     for ( TInt i( 0 ); i < count; i++ )
       
   845         {
       
   846         CBSLOGSTRING2("CBSSERVER: CCbsRecEtel::RouteMessageL(): Routing to provider: %d", i );
       
   847         iSubscriptionProviders->At( i )->RouteMessageL( aMessage );
       
   848         }
       
   849 
       
   850 	CBSLOGSTRING("CBSSERVER: <<< CCbsRecEtel::RouteMessageL()");
       
   851     }
       
   852 
       
   853 // -----------------------------------------------------------------------------
       
   854 // CCbsRecEtel::ExtractCellInformation
       
   855 // Copies Current cell information (district info, MCN)
       
   856 // into receiver's cache.
       
   857 // 
       
   858 // This way MCN clients can be provided the current
       
   859 // cell information message even without message routing service.
       
   860 // 
       
   861 // The given message is assumed to be a valid cell information
       
   862 // message (CB message of topic 050).
       
   863 // (other items were commented in a header).
       
   864 // -----------------------------------------------------------------------------
       
   865 //
       
   866 void CCbsRecEtel::ExtractCellInformation( 
       
   867     const CCbsMessage& aMessage )
       
   868     {
       
   869 
       
   870     iCurrentCellInfoMessage.Copy( aMessage.Contents() );
       
   871     aMessage.GetPLMN( iCellInfoPLMN );
       
   872     iCellInfoLAC = aMessage.LAC();
       
   873     iCellInfoCellId = aMessage.CellId();
       
   874 
       
   875     iCellInfoReceived = ETrue;
       
   876     }
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 // CCbsRecEtel::ExtractHomeZoneInformation
       
   880 // Copies Current HomeZone information into receiver's cache.
       
   881 // 
       
   882 // This way MCN clients can be provided the current HomeZone
       
   883 // message even without message routing service.
       
   884 // 
       
   885 // The given message is assumed to be a valid HomeZone
       
   886 // message (CB message of topic 221).
       
   887 // (other items were commented in a header).
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 void CCbsRecEtel::ExtractHomeZoneInformation( 
       
   891     const CCbsMessage& aMessage )
       
   892     {
       
   893     iCurrentHomeZoneMessage.Copy( aMessage.Contents() );
       
   894     aMessage.GetPLMN( iHomeZonePLMN );
       
   895     iHomeZoneLAC = aMessage.LAC();
       
   896     iHomeZoneCellId = aMessage.CellId();
       
   897 
       
   898     iHomeZoneReceived = ETrue;
       
   899     }
       
   900 
       
   901 // -----------------------------------------------------------------------------
       
   902 // CCbsRecEtel::Collector
       
   903 // Returns the message collector reference.
       
   904 // (other items were commented in a header).
       
   905 // -----------------------------------------------------------------------------
       
   906 //
       
   907 CCbsRecCollector& CCbsRecEtel::Collector()
       
   908     {
       
   909     return *iCollector;
       
   910     }
       
   911 
       
   912 // -----------------------------------------------------------------------------
       
   913 // CCbsRecEtel::Interface
       
   914 // Returns the receiver helper reference.
       
   915 // (other items were commented in a header).
       
   916 // -----------------------------------------------------------------------------
       
   917 //    
       
   918 CCbsReceiverHelper& CCbsRecEtel::Interface() const
       
   919     {
       
   920     return *iInterface;
       
   921     }
       
   922 
       
   923 // -----------------------------------------------------------------------------
       
   924 // CCbsRecEtel::__DbgTestInvariant
       
   925 // Checks that the object is in a valid state, and panics if it is not.
       
   926 // (other items were commented in a header).
       
   927 // -----------------------------------------------------------------------------
       
   928 //
       
   929 void CCbsRecEtel::__DbgTestInvariant() const
       
   930     {
       
   931 #if defined (_DEBUG)
       
   932     if ( iSubscriptionProviders == NULL ||
       
   933         iEtelMonitor == NULL || iMessaging == NULL || iInterface == NULL ||
       
   934         iDecoder == NULL || iCollector ==NULL || iNetworkListener == NULL )
       
   935         {
       
   936         User::Invariant();
       
   937         }    
       
   938 #endif // _DEBUG
       
   939     }
       
   940 
       
   941 // ================= OTHER EXPORTED FUNCTIONS ==============
       
   942 //  End of File