messagingappbase/ncnlist/src/NcnOutboxSender.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 /*
       
     2 * Copyright (c) 2004 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:   Implements class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include    "NcnCRHandler.h"
       
    22 #include    <CoreApplicationUIsSDKCRKeys.h>
       
    23 
       
    24 #include    <SenduiMtmUids.h>           // mtm uids
       
    25 #include    <msvuids.h>                 // Entry Uids
       
    26 #include    <mtmuibas.h>                // CBaseMtmUi
       
    27 #include    "NcnOutboxSendOperation.h"
       
    28 #include    "NcnOutboxSender.h"
       
    29 #include    "NcnModelBase.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 const TInt KNcnListBar0( 0 );
       
    35 
       
    36 // ================= MEMBER FUNCTIONS =======================
       
    37 
       
    38 // ----------------------------------------------------
       
    39 //  CNcnOutboxSender::NewL
       
    40 // ----------------------------------------------------
       
    41 //
       
    42 CNcnOutboxSender* CNcnOutboxSender::NewL(
       
    43     CNcnModelBase*  aModel,
       
    44     CMsvSession&    aMsvSession )
       
    45     {
       
    46     // Create instance of the outboxsender object
       
    47     CNcnOutboxSender* self =
       
    48         new (ELeave) CNcnOutboxSender( aModel, aMsvSession );
       
    49 
       
    50     // Push to cleanupstack for constructphase
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL();
       
    53     CleanupStack::Pop();
       
    54 
       
    55     // Return the object
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ----------------------------------------------------
       
    60 //  CNcnOutboxSender::CNcnOutboxSender
       
    61 // ----------------------------------------------------
       
    62 //
       
    63 CNcnOutboxSender::CNcnOutboxSender(
       
    64     CNcnModelBase*  aModel,
       
    65     CMsvSession&    aMsvSession )
       
    66     :
       
    67     iNcnModel( aModel ), iMsvSession( aMsvSession )
       
    68     {
       
    69     }
       
    70 
       
    71 // ----------------------------------------------------
       
    72 //  CNcnOutboxSender::~CNcnOutboxSender
       
    73 // ----------------------------------------------------
       
    74 //
       
    75 CNcnOutboxSender::~CNcnOutboxSender()
       
    76     {
       
    77     // Stop and delete the sending operation
       
    78     delete iRunningOperation;
       
    79 
       
    80     // Check if notification is set
       
    81     if( iFlags & EUserSettingsNotifierSet )
       
    82         {
       
    83         // Remove the notification from list
       
    84         if( iNotifyHandler )
       
    85             {            
       
    86             iNotifyHandler->StopListening();
       
    87 		    delete iNotifyHandler;
       
    88             }
       
    89 		
       
    90 		delete iSession;
       
    91         }
       
    92 
       
    93     // Remove the address
       
    94     iNcnModel = NULL;
       
    95     }
       
    96 
       
    97 // ----------------------------------------------------
       
    98 //  CNcnOutboxSender::ConstructL
       
    99 // ----------------------------------------------------
       
   100 //
       
   101 void CNcnOutboxSender::ConstructL()
       
   102     {
       
   103 	iNetworkBars = KNcnListBar0;
       
   104 
       
   105 	iSession = CRepository::NewL( KCRUidCoreApplicationUIs );
       
   106 	iNotifyHandler = CCenRepNotifyHandler::NewL( *this, *iSession, CCenRepNotifyHandler::EIntKey, KCoreAppUIsNetworkConnectionAllowed );
       
   107 	iNotifyHandler->StartListeningL();
       
   108 
       
   109 	// Turn flag on for possible error handling cases
       
   110     iFlags |= EUserSettingsNotifierSet;
       
   111 
       
   112 	CheckBootPhaseL();
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------
       
   116 //  CNcnOutboxSender::StartSendingL
       
   117 // ----------------------------------------------------
       
   118 //
       
   119 void CNcnOutboxSender::StartSendingL()
       
   120     {
       
   121     // Check if the sending is already in progress
       
   122     if( !IsSending() )
       
   123         {
       
   124         // Create instance of Single Operation Watcher
       
   125         CMsvSingleOpWatcher* singleOpWatcher =
       
   126             CMsvSingleOpWatcher::NewL(*this);
       
   127 
       
   128         // Push to cleanup stack while creating sending operation
       
   129         CleanupStack::PushL( singleOpWatcher );
       
   130         CMsvOperation* op =
       
   131             CNcnOutboxSendOperation::NewL(
       
   132                 iMsvSession, singleOpWatcher->iStatus );
       
   133         CleanupStack::Pop( singleOpWatcher );
       
   134 
       
   135         // Set operation
       
   136         singleOpWatcher->SetOperation( op ); // takes immediately ownership
       
   137         iRunningOperation = singleOpWatcher;
       
   138         }
       
   139     }
       
   140 
       
   141 
       
   142 // ----------------------------------------------------
       
   143 //  CNcnOutboxSender::CancelSending
       
   144 // ----------------------------------------------------
       
   145 //
       
   146 void CNcnOutboxSender::CancelSending()
       
   147     {
       
   148     // Remove the running operation
       
   149     delete iRunningOperation;
       
   150     iRunningOperation = NULL;
       
   151     }
       
   152 
       
   153 // ----------------------------------------------------
       
   154 //  CNcnOutboxSender::IsSending
       
   155 // ----------------------------------------------------
       
   156 //
       
   157 TBool CNcnOutboxSender::IsSending() const
       
   158     {
       
   159     return ( iRunningOperation != NULL );
       
   160     }
       
   161 
       
   162 // ----------------------------------------------------
       
   163 //  CNcnOutboxSender::OpCompleted
       
   164 // ----------------------------------------------------
       
   165 //
       
   166 void CNcnOutboxSender::OpCompleted(
       
   167     CMsvSingleOpWatcher& /*aOpWatcher*/,
       
   168     TInt /*aCompletionCode*/ )
       
   169     {
       
   170     // Clear flag
       
   171     iFlags &= ~EOffllineSendingNeeded;
       
   172 
       
   173     // Errors can be ignored since we try to send only once and
       
   174     // if it fails then it is up to the user...
       
   175     delete iRunningOperation;
       
   176     iRunningOperation = NULL;
       
   177     }
       
   178 
       
   179 // ----------------------------------------------------
       
   180 //  CNcnOutboxSender::HandleNotifyInt
       
   181 // ----------------------------------------------------
       
   182 //
       
   183 void CNcnOutboxSender::HandleNotifyInt(
       
   184     const TUint32 aID,
       
   185     const TInt    aNewValue )
       
   186     {
       
   187     NCN_RDEBUG(_L("CNcnOutboxSender::HandleNotifyInt"));
       
   188 	// Check if key is for offline-connecton
       
   189 	if( aID == KCoreAppUIsNetworkConnectionAllowed )
       
   190         {
       
   191         NCN_RDEBUG(_L("CNcnOutboxSender::HandleNotifyInt KCoreAppUIsNetworkConnectionAllowed"));
       
   192         // Check if connection is established
       
   193         if( aNewValue == ECoreAppUIsNetworkConnectionAllowed )
       
   194             {
       
   195 			NCN_RDEBUG(_L("CNcnOutboxSender::HandleNotifyInt ECoreAppUIsNetworkConnectionAllowed 1"));
       
   196             // Phone switched on again!
       
   197             iFlags |= EOffllineSendingNeeded;
       
   198             
       
   199             NCN_RDEBUG_INT(_L("CNcnOutboxSender::HandleNotifyInt iNetworkBars = %d"), iNetworkBars );
       
   200 			if ( iNetworkBars > KNcnListBar0 )
       
   201 				{
       
   202 				NCN_RDEBUG_INT(_L("CNcnOutboxSender::HandleNotifyInt sending now, iNetworkBars = %d"), iNetworkBars );
       
   203 				TRAP_IGNORE( StartSendingL() );
       
   204 				}
       
   205             }
       
   206         else
       
   207             {
       
   208 			NCN_RDEBUG(_L("CNcnOutboxSender::HandleNotifyInt ECoreAppUIsNetworkConnectionAllowed 0"));
       
   209             // Clear flag
       
   210             iFlags &= ~EOffllineSendingNeeded;
       
   211 
       
   212             // Stop sending
       
   213             CancelSending();
       
   214 
       
   215 			// Set the coverage to 0 in case it didn't come from network in time
       
   216 			iNetworkBars = KNcnListBar0;
       
   217             }
       
   218         }
       
   219 	}
       
   220 
       
   221 // ----------------------------------------------------
       
   222 //  CNcnOutboxSender::HandleNotifyGeneric
       
   223 // ----------------------------------------------------
       
   224 //
       
   225 void CNcnOutboxSender::HandleNotifyGeneric( const TUint32 /*aID*/ )
       
   226     {
       
   227 	//NO OPERATION
       
   228 	}
       
   229 
       
   230 // ----------------------------------------------------
       
   231 //  CNcnOutboxSender::HandleNotifyError
       
   232 // ----------------------------------------------------
       
   233 //
       
   234 void CNcnOutboxSender::HandleNotifyError(
       
   235     const TUint32 /*aID*/,
       
   236     const TInt    /*aError*/,
       
   237 	CCenRepNotifyHandler* /*aHandler*/ )
       
   238     {
       
   239 	//NO OPERATION
       
   240 	}
       
   241 
       
   242 // ----------------------------------------------------
       
   243 //  CNcnOutboxSender::CheckAndStartSendingL
       
   244 // ----------------------------------------------------
       
   245 //
       
   246 void CNcnOutboxSender::CheckAndStartSendingL( const TInt& aNetworkBars )
       
   247     {
       
   248 	NCN_RDEBUG_INT(_L("CNcnOutboxSender::CheckAndStartSendingL aNetworkBars = %d"), aNetworkBars );
       
   249 	iNetworkBars = aNetworkBars;
       
   250     // Check if sending is needed and network is available
       
   251 	if ( iFlags & EOffllineSendingNeeded &&
       
   252         aNetworkBars > KNcnListBar0 )
       
   253         {
       
   254 		NCN_RDEBUG_INT(_L("CNcnOutboxSender::CheckAndStartSendingL sending now, iNetworkBars = %d"), iNetworkBars );
       
   255         // Start sending
       
   256         StartSendingL();
       
   257 		}
       
   258 	else
       
   259 		{
       
   260 		NCN_RDEBUG_INT(_L("CNcnOutboxSender::CheckAndStartSendingL not sending, iNetworkBars = %d"), iNetworkBars );
       
   261 		}
       
   262     }
       
   263 
       
   264 // ----------------------------------------------------
       
   265 //  CNcnOutboxSender::CheckBootPhaseL
       
   266 // ----------------------------------------------------
       
   267 //
       
   268 void CNcnOutboxSender::CheckBootPhaseL()
       
   269 	{
       
   270     TInt connection;
       
   271 
       
   272 	TInt err = iSession->Get( KCoreAppUIsNetworkConnectionAllowed, connection );
       
   273 
       
   274 	if( err == KErrNone )
       
   275         {
       
   276         // Check if connection is established
       
   277         if( connection )
       
   278             {
       
   279 			NCN_RDEBUG(_L("CNcnOutboxSender::CheckBootPhaseL KGSNetworkConnectionAllowed 1"));
       
   280             // Phone switched on again!            
       
   281             iFlags |= EOffllineSendingNeeded; 
       
   282 			
       
   283 			if ( iNetworkBars > KNcnListBar0 )
       
   284 				{
       
   285 				NCN_RDEBUG_INT(_L("CNcnOutboxSender::CheckBootPhaseL sending now, iNetworkBars = %d"), iNetworkBars );
       
   286 				StartSendingL();
       
   287 				}
       
   288 			}
       
   289 		}
       
   290 	else
       
   291 		{
       
   292 		NCN_RDEBUG(_L("CNcnOutboxSender::CheckBootPhaseL Cannot access shared data"));
       
   293 		}
       
   294 	}
       
   295 
       
   296 // End of file